RohanPhuyal

[CONSOLE] ALL REGION

Aug 30th, 2023 (edited)
1,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 5.01 KB | Source Code | 0 0
  1. (async function () {
  2.     var playAgain = null;
  3.     document.querySelector("shopping-page-base")
  4.         ?.shadowRoot.querySelector("shopping-homepage")
  5.         ?.shadowRoot.querySelector("cs-feed-layout")
  6.         ?.shadowRoot.querySelector("msn-shopping-game-pane").setAttribute('gamestate', 'active');
  7.  
  8.     var shoppingGame = document.querySelector("shopping-page-base")
  9.         ?.shadowRoot.querySelector("shopping-homepage")
  10.         ?.shadowRoot.querySelector("cs-feed-layout")
  11.         ?.shadowRoot.querySelector("msn-shopping-game-pane")
  12.         ?.shadowRoot.querySelector("msft-stripe");
  13.     shoppingGame.scrollIntoView({ behavior: "smooth" });
  14.  
  15.     async function executeScript() {
  16.         console.log("Executing");
  17.         var pricesAll = []; // Array to store original prices
  18.         var discountAll = []; // Array to store discounts
  19.         var finalPrice = [];
  20.         var cheapestIndex; // Store the index of the cheapest item
  21.  
  22.  
  23.         async function pricesOfAll() {
  24.             console.log("pricesofAll()");
  25.             var prices = document
  26.                 .querySelector("shopping-page-base")
  27.                 ?.shadowRoot.querySelector("shopping-homepage")
  28.                 ?.shadowRoot.querySelector("cs-feed-layout")
  29.                 ?.shadowRoot.querySelector("msn-shopping-game-pane").displayedShoppingEntities;
  30.  
  31.             var loopTimes = prices.length;
  32.             for (let i = 0; i < loopTimes; i++) {
  33.                 pricesAll.push(prices[i].priceInfo.originalPrice); // Add original price to pricesAll array
  34.                 discountAll.push(prices[i].dealPercentage); // Add discount to discountAll array
  35.             }
  36.         }
  37.  
  38.         async function calculateDiscount() {
  39.             console.log("calculateDiscount()");
  40.             for (let i = 0; i < pricesAll.length; i++) {
  41.                 console.log("Price before removing sign: "+pricesAll[i]);
  42.                 let initPrice = parseFloat(pricesAll[i].replace(/[^\d.]/g, ""));
  43.                 console.log("Price after removing sign: "+initPrice);
  44.                 console.log("Discount before removing sign: "+discountAll[i]);
  45.                 let discountPercentage = parseFloat(discountAll[i].replace(/[^\d]/g, ""));
  46.                 console.log("Discount after removing sign: "+discountPercentage);
  47.                 let discountedPrice = (initPrice - ((initPrice * discountPercentage) / 100));
  48.                 finalPrice.push(discountedPrice);
  49.             }
  50.         }
  51.         async function findCheapestIndex(finalPrice) {
  52.             var cheapestPrice = Math.min(...finalPrice); // Find the lowest value in the finalPrice array
  53.             var cheapIndex = finalPrice.indexOf(cheapestPrice); // Get the index of the lowest value
  54.             return cheapIndex;
  55.         }
  56.  
  57.         async function highlightAndRemoveItems(correctIndex, items) {
  58.             for (let i = 0; i < items.length; i++) {
  59.                 if (i === correctIndex) {
  60.                     items[i].style.borderColor = "green";
  61.                 } else {
  62.                     items[i].style.display = "none";
  63.                 }
  64.             }
  65.         }
  66.         async function playAgainFunc() {
  67.             const gamePanelContainer = document.querySelector("shopping-page-base")
  68.                 ?.shadowRoot.querySelector("shopping-homepage")
  69.                 ?.shadowRoot.querySelector("cs-feed-layout")
  70.                 ?.shadowRoot.querySelector("msn-shopping-game-pane")
  71.                 ?.shadowRoot.querySelector("div.shopping-game-pane-container > div.game-panel-container > div.game-panel-header-2");
  72.        
  73.             if (gamePanelContainer) {
  74.                 const playAgainButtons = gamePanelContainer.querySelectorAll("button");
  75.        
  76.                 playAgain = Array.from(playAgainButtons).find(button => button.textContent.toLowerCase().includes("play again"));
  77.        
  78.                 if (playAgain !== null) {
  79.                     console.log("Terminating playAgainFunc(): playAgain button found!");
  80.                     playAgain.click();
  81.                     clearInterval(fixIntervalId);
  82.                     playAgain = null;
  83.                     pricesAll = [];
  84.                     discountAll = [];
  85.                     finalPrice = [];
  86.                     cheapestIndex = null;
  87.                     setTimeout(() => executeScript(), 9000);
  88.                 }
  89.             }
  90.         }
  91.        
  92.         await pricesOfAll();
  93.         await calculateDiscount();
  94.         cheapestIndex = await findCheapestIndex(finalPrice);
  95.         console.log("Original Price: " + pricesAll);
  96.         console.log("Discount%: " + discountAll);
  97.         console.log("Final Price: " + finalPrice);
  98.         console.log("Answer: " + cheapestIndex);
  99.         await highlightAndRemoveItems(cheapestIndex, shoppingGame.getElementsByClassName("shopping-game-card-outline"));
  100.         // Only schedule the setTimeout if playAgain is still null
  101.         var fixIntervalId = setInterval(async function () {
  102.             await playAgainFunc();
  103.         }, 100);
  104.     }
  105.         await executeScript();
  106. })();
Advertisement
Add Comment
Please, Sign In to add comment