Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (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 compareValues() {
- for (let i = 0; i < finalPrice.length; i++) {
- for (let j = i + 1; j < finalPrice.length; j++) {
- const diff = Math.abs(finalPrice[i] - finalPrice[j]);
- if (diff < 0.09) {
- alert("Values differ by less than 0.09. Reload...");
- window.location.reload();
- return; // Terminate the function
- }
- }
- }
- console.log("All values are at least 0.89 different from each other.");
- }
- async function findCheapestIndex(finalPrice) {
- await compareValues();
- 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() {
- 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) {
- const playAgainButtons = gamePanelContainer.querySelectorAll("button");
- playAgain = Array.from(playAgainButtons).find(button => button.textContent.toLowerCase().includes("play again"));
- 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();
- })();
Advertisement
Add Comment
Please, Sign In to add comment