Nidiox escribió:panchitoGC escribió:En el shopping probé varios, el único que me funciona es este:
javascript:void%20function(){function%20a(){for(var%20a=document.getElementsByTagName(%22script%22),b=[],c=0;c%3Ca.length;c++){const%20d=a[c].getAttribute(%22src%22);d%26%26d.endsWith(%22.js%22)%26%26b.push(d)}return%20b.findLast(a=%3Ea.includes(%22/common.%22))}async%20function%20b(){var%20b=a();if(!b)return%20null;var%20c=await%20fetch(b),d=c.ok%3Fawait%20c.text():null;return%20window.oneServiceApiKey=d%3Fd.includes(%22apiKey%22)%3Fd.split(%22apiKey:\%22%22)[1].split(%22\%22%22)[0]:null:null,window.oneServiceApiKey}function%20c(){var%20a=document.head.getAttribute(%22data-client-settings%22);return%20window.activityId=a%3FJSON.parse(a).aid.replace(/^(\w{8})(\w{4})(\w{4})(\w{4})(\w{12})$/,%22$1-$2-$3-$4-$5%22):MeControl.WebInline.guid(),window.activityId}async%20function%20d(){var%20a=await%20cookieStore.get(%22MUID%22);return%20window.muid=a%3F`m-${a.value}`:null,window.muid}async%20function%20e(){return(await%20d())%3F(await%20c())%3F!!(await%20b())||alert(%22Unable%20to%20retrieve%20'OneServiceApiKey'%22):alert(%22Unable%20to%20retrieve%20'ActivityId'%22):alert(%22Unable%20to%20retrieve%20'MUID'%22)}function%20f(){window.elementsCreated||(window.elementsCreated=0);var%20a=document.createElement(%22div%22);a.className=%22view-leaderboard%20stats-game-counter%22,a.style=`right:%20unset;%20left:%20${25+100*window.elementsCreated++}px;%20font-size:%2013px;background:%20linear-gradient(100.25deg,%20rgba(7,%20158,%20130,%200.9)%200%25,%20rgba(2,%20100,%20188,%200.9)%20100%25);color:%20white;font-weight:%20700;`;var%20b=o.gameContainerRef.getElementsByClassName(%22game-panel-container%22)[0];return%20b.appendChild(a),a}function%20g(){window.gameCounterElem||(window.gameCounter=0,window.gameCounterElem=f()),window.gameCounter++,window.gameCounterElem.textContent=`Game:%20${window.gameCounter}`}function%20h(a=0){window.rewardsBalanceElement||(window.rewardsBalanceElement=p%3F.querySelector(%22ms-rewards%22)%3F.shadowRoot%3F.querySelector(%22fluent-button%22)%3F.getElementsByClassName(%22reward-points%22)[0]),window.pointsCounterElem||(window.pointsBalancePrev=a-1,window.pointsBalance=a,window.pointsCounterElem=f(),window.pointsIncrementTimer=setInterval(()=%3E{window.pointsBalance%3Ewindow.pointsBalancePrev%26%26(window.pointsCounterElem.textContent=`Points:%20${++window.pointsBalancePrev}`,window.rewardsBalanceElement%26%26(window.rewardsBalanceElement.textContent=`\n${window.pointsBalancePrev}\n\n`))},50)),window.pointsBalance=a}async%20function%20i(){await%20fetch(%22https://assets.msn.com/service/News/Users/me/Rewards%3Fapikey=0QfOX3Vn51YCzitbLaRkTTBadtWpgTN8NZLW0C1SEM%26ocid=rewards-peregrine%26cm=en-gb%26it=web%26user=0%26scn=ANON%22,{headers:{Authorization:`Bearer%20${window.userAccessToken}`}}).then(async%20a=%3E{var%20b=await%20a.json();h(b.profile.rewardsPoints)})}async%20function%20j(){return%20await%20fetch(`https://assets.msn.com/service/news/feed/segments/shopping%3Focid=shopping-shophp-Peregrine%26apikey=${window.oneServiceApiKey}%26timeOut=10000%26cm=${MeControl.Config.mkt.toLowerCase()}%26scn=MSNRPSAuth%26user=${window.muid}%26$select=rewards|reportactivity|guessinggame|0|${window.gameHash}%26$filter=~5000%26activityid=${window.activityId}`,{method:%22GET%22,cache:%22no-store%22,headers:{Authorization:`Bearer%20${window.userAccessToken}`}})}function%20k(){o.displayedShoppingEntities=[o.displayedShoppingEntities[0]]}function%20l(){1%3Co.displayedShoppingEntities.length%26%26k(),localStorage.removeItem(%22gamesPerDay%22),o.dailyLimitReached=!1,o.leaderboardRecord%26%26(o.leaderboardRecord.dailyGuessingGamesPlayed=0),o.gameState=%22idle%22==o.gameState%3F%22active%22:o.gameState}async%20function%20m(){window.gameHash=o.displayedShoppingEntities[0].gameHash,null==o%3Falert(%22Unable%20to%20locate%20the%20shopping%20game!\nRefresh%20the%20page%20and%20try%20again.%22):(%22slot2%22!=o.style.gridArea%26%26(n.shadowRoot.children[1].style.gridArea=o.style.gridArea,o.style.gridArea=%22slot2%22,window.scrollTo(0,0)),!window.layoutColumnsChangedOG%26%26(window.layoutColumnsChangedOG=o.layoutColumnsChanged,o.layoutColumnsChanged=function(a,b){layoutColumnsChangedOG.call(o,[a,b]),o.style.gridArea=%22slot2%22}),!window.startCountdownOG%26%26(window.startCountdownOG=o.startCountdown,o.startCountdown=function(){window.startCountdownOG.call(o),setTimeout(()=%3E{g(),k()},1e3*o.gameSettings.newGameCountdown+1200)}),!1,o.gSCS=function(){return%20o.isGameFinished%3F%22--price-color:%2300AE56;--price-color-dark:%2300AE56%22:%22%22},o.getGameResult=async%20function(){if(o.isGameFinished)return%20o.gameState=%22win%22,l(),o.selectedCardIndex!=o.c_ai%26%26-1%3Co.selectedCardIndex%26%26(o.gameContainerRef.querySelector(%22fluent-card%22).parentElement.style=%22border:4px%20solid%20rgb(0,%20174,%2086)%22,o.selectedCardIndex=-1,o.confettiAnimate.play(),await%20j()),%22win%22===o.gameState%26%26!1%26%26setTimeout(i,1200),-1%3Co.selectedCardIndex%26%26(o.selectedCardIndex=-1,setTimeout(()=%3EArray.from(o.gameContainerRef.querySelectorAll(%22button%22)).find(a=%3Ea.textContent.toLowerCase().includes(%22play%20again%22))%3F.click(),25)),%22win%22},setInterval(l,100),g(),o.gameState=%22active%22)}var%20n=document.querySelector(%22shopping-page-base%22)%3F.shadowRoot.querySelector(%22shopping-homepage%22)%3F.shadowRoot.querySelector(%22cs-feed-layout%22),o=n%3F.shadowRoot.querySelector(%22msn-shopping-game-pane%22),p=document.querySelector(%22shopping-page-base%22)%3F.shadowRoot.querySelector(%22common-header%22)%3F.shadowRoot.querySelector(%22msn-verticals-header%22)%3F.shadowRoot.querySelector(%22fluent-design-system-provider%22);(function(){var%20a=document.location.href.includes(%22https://www.msn.com/%22)%26%26document.location.href.includes(%22/shopping%22);return!!a||alert(%22Invalid%20site%20detected.%20You%20need%20to%20be%20on%20https://www.msn.com/shopping%22)})()%26%26setTimeout(async()=%3E{(await%20e())%26%26m()},500)}();
Hola, en principio me ha funcionado, pero me he dado cuenta que de una ronda de 10 solo me han dado 20 ptos... a alguien mas le pasa?
Consegui un Script que me funciona. Pero lo tengo que aplicar sobre
https://www.msn.com/en-us/shopping ya que en la version british (
https://www.msn.com/en-gb/shopping) que es donde siempre lo hacia me da error.
(async function () {
var playAgain = null;
document.querySelector("shopping-page-base")
?.shadowRoot.querySelector("shopping-homepage")
?.shadowRoot.querySelector("cs-feed-layout")
?.shadowRoot.querySelector("msn-shopping-game-pane").setAttribute('gamestate', 'active');
var shoppingGame = document.querySelector("shopping-page-base")
?.shadowRoot.querySelector("shopping-homepage")
?.shadowRoot.querySelector("cs-feed-layout")
?.shadowRoot.querySelector("msn-shopping-game-pane")
?.shadowRoot.querySelector("msft-stripe");
shoppingGame.scrollIntoView({ behavior: "smooth" });
async function executeScript() {
console.log("Executing");
var pricesAll = []; // Array to store original prices
var discountAll = []; // Array to store discounts
var finalPrice = [];
var cheapestIndex; // Store the index of the cheapest item
async function pricesOfAll() {
console.log("pricesofAll()");
var prices = document
.querySelector("shopping-page-base")
?.shadowRoot.querySelector("shopping-homepage")
?.shadowRoot.querySelector("cs-feed-layout")
?.shadowRoot.querySelector("msn-shopping-game-pane").displayedShoppingEntities;
var loopTimes = prices.length;
for (let i = 0; i < loopTimes; i++) {
pricesAll.push(prices[i].priceInfo.originalPrice); // Add original price to pricesAll array
discountAll.push(prices[i].dealPercentage); // Add discount to discountAll array
}
}
async function calculateDiscount() {
console.log("calculateDiscount()");
for (let i = 0; i < pricesAll.length; i++) {
console.log("Price before removing sign: "+pricesAll[i]);
let initPrice = parseFloat(pricesAll[i].replace(/[^\d.]/g, ""));
console.log("Price after removing sign: "+initPrice);
console.log("Discount before removing sign: "+discountAll[i]);
let discountPercentage = parseFloat(discountAll[i].replace(/[^\d]/g, ""));
console.log("Discount after removing sign: "+discountPercentage);
let discountedPrice = (initPrice - ((initPrice * discountPercentage) / 100));
finalPrice.push(discountedPrice);
}
}
async function findCheapestIndex(finalPrice) {
var cheapestPrice = Math.min(...finalPrice); // Find the lowest value in the finalPrice array
var cheapIndex = finalPrice.indexOf(cheapestPrice); // Get the index of the lowest value
return cheapIndex;
}
async function highlightAndRemoveItems(correctIndex, items) {
for (let i = 0; i < items.length; i++) {
if (i === correctIndex) {
items[i].style.borderColor = "green";
} else {
items[i].style.display = "none";
}
}
}
async function playAgainFunc() {
// // Get the initial shadow DOM element
// const firstShadowRoot = document.querySelector("#root > div > div > fluent-design-system-provider > div > div:nth-child(4) > div > shopping-page-base").shadowRoot;
// // Traverse through the shadow DOM to find the desired elements
// const shoppingHomepage = firstShadowRoot.querySelector("div > div.shopping-page-content > shopping-homepage").shadowRoot;
// const csFeedLayout = shoppingHomepage.querySelector("div > cs-feed-layout").shadowRoot;
// const shoppingGamePane = csFeedLayout.querySelector("msn-shopping-game-pane").shadowRoot;
// const gamePanelContainer = shoppingGamePane.querySelector("div.shopping-game-pane-container > div.game-panel-container > div.game-panel-header-2");
const gamePanelContainer = document.querySelector("shopping-page-base")
?.shadowRoot.querySelector("shopping-homepage")
?.shadowRoot.querySelector("cs-feed-layout")
?.shadowRoot.querySelector("msn-shopping-game-pane")
?.shadowRoot.querySelector("div.shopping-game-pane-container > div.game-panel-container > div.game-panel-header-2");
if(gamePanelContainer){
// Search for a button with the text "Play Again" within the div
playAgain = gamePanelContainer.querySelectorAll("button")[0];
}
if (playAgain !== null) {
console.log("Terminating playAgainFunc(): playAgain button found!");
playAgain.click();
clearInterval(fixIntervalId);
playAgain=null;
pricesAll = [];
discountAll = [];
finalPrice = [];
cheapestIndex = null;
setTimeout(() => executeScript(), 9000);
}
}
await pricesOfAll();
await calculateDiscount();
cheapestIndex = await findCheapestIndex(finalPrice);
console.log("Original Price: " + pricesAll);
console.log("Discount%: " + discountAll);
console.log("Final Price: " + finalPrice);
console.log("Answer: " + cheapestIndex);
await highlightAndRemoveItems(cheapestIndex, shoppingGame.getElementsByClassName("shopping-game-card-outline"));
// Only schedule the setTimeout if playAgain is still null
var fixIntervalId = setInterval(async function () {
await playAgainFunc();
}, 100);
}
await executeScript();
})();