Advertisement
RohanPhuyal

(Auto)MSN SHOPPING SCRIPT CONSOLE[u/_IIIIIIII_IIIIIIIII_]

Jun 26th, 2023
2,138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 8.54 KB | Source Code | 0 0
  1. (async function(){
  2. // This script can do multiple things... by default it does points 1, 2, 3, 4 and 5 listed below;
  3. // 1. Authentication checks, Have to make sure you're getting those sweet points :)
  4. // 2. Brings the Shopping Game to the top of the page
  5. // 3. Forces the game to only have one answer option
  6. // 4. Modifies countdown timer to 0 seconds
  7. // 5. Updates visible user balance whenever points are awarded ( not sure why Microsoft didn't include this anyway... )
  8. // 6. Automatically load next game instantly, skipping the 'Play Again' button + countdown timer ( needs to be enabled below! )
  9.  
  10. // Change this variable to 'true' to bring the Shopping Game to the top of the page.
  11. var switchAreaSlot = true;
  12.  
  13. // Change this variable to 'true' to skip authentication check.
  14. var skipAuthCheck = false;
  15.  
  16. // Change this variable to 'true' to update visible user balance whenever points are awarded. ( 'skipAuthCheck' MUST be 'false' )
  17. var autoUpdateRewardsBalance = true;
  18.  
  19. // Change this variable to 'true' to skip the 'Play Again' button and countdown timer. ( a bit overpowered )
  20. var autoLoadNextGame = false;
  21.  
  22. // Change this variable to modify the countdown timer. ( it's in seconds )
  23. var newGameCountdownTime = 0;
  24.  
  25. // Basic query selectors to find 'msft-feed-layout', 'msn-shopping-game-pane' and 'ms-rewards' elements.
  26. var msftFeedLayout = document.querySelector("shopping-page-base")
  27.     ?.shadowRoot.querySelector("shopping-homepage")
  28.     ?.shadowRoot.querySelector("msft-feed-layout");
  29.  
  30. var msnShoppingGamePane = msftFeedLayout?.shadowRoot.querySelector("msn-shopping-game-pane");
  31.  
  32. var msRewards = document.querySelector("shopping-page-base")
  33.     ?.shadowRoot.querySelector("common-header")
  34.     ?.shadowRoot.querySelector("msn-verticals-header")
  35.     ?.shadowRoot.querySelector("fluent-design-system-provider")
  36.     ?.querySelector("ms-rewards");
  37.  
  38.  
  39. // Function to see if we are authenticated.
  40. async function rewardsConnectorAuthCheck(){
  41.     if(!msRewards)
  42.         return alert("'msRewards' not found, You may have ran the script too early?");
  43.  
  44.     var isRewardsUserUndefined = (msRewards?.rewardPoints == undefined);
  45.     var tokenStorage = localStorage.getItem("1s-tokens");
  46.     if(isRewardsUserUndefined){
  47.         if(tokenStorage){
  48.             alert("You're semi-authenticated, The page will now reload.\nYou will need to re-run the script when the page has reloaded.");
  49.             return document.location.reload();
  50.         }
  51.  
  52.         // Authentication
  53.         setTimeout(async () =>{
  54.             document.body.innerHTML = "<div style='margin: 10px;'><span>You're unauthenticated! A popup should appear.<br>When you login you will need to re-run the script when the page has reloaded.</span></div>";
  55.         }, 500);
  56.         msnShoppingGamePane.signInState = 3;
  57.         await msnShoppingGamePane.signIn();
  58.         await msnShoppingGamePane.fetchSignInState();
  59.         setTimeout(() => document.location.href = 'https://www.msn.com/shopping?ocid=windirect', 2000);
  60.     }
  61.     else {
  62.         if(tokenStorage){
  63.             window.userAccessToken = JSON.parse(tokenStorage).accessToken;
  64.             return true;
  65.         }
  66.         else {
  67.             alert("You're authenticated but unable to find '1s-tokens', The page will now reload.\nYou will need to re-run the script when the page has reloaded.");
  68.             return document.location.reload();
  69.         }
  70.     }
  71. }
  72.  
  73. // Function that modifies the game.
  74. function modifyGame(){
  75.     // Check if the shopping game was found.
  76.     if(msnShoppingGamePane != null)
  77.     {
  78.         // Switches msnShoppingGamePane slot with slot2, bringing it to the top of the page.
  79.         if(switchAreaSlot){
  80.             if(msnShoppingGamePane.style.gridArea != "slot2"){
  81.                 // msftFeedLayout.shadowRoot.children[1].style.gridArea = msnShoppingGamePane.style.gridArea;
  82.                 // msnShoppingGamePane.style.gridArea = "slot2";
  83.         msnShoppingGamePane.scrollIntoView({behavior: 'smooth'});
  84.             }
  85.         }
  86.  
  87.         // Override their 'reportRewardsActivity' function with our own function for better point tracking.
  88.         if(autoUpdateRewardsBalance){
  89.             var rewardsBalanceElement;
  90.             msnShoppingGamePane.reportRewardsActivity = async function(retryCount = 2){
  91.                 if(!rewardsBalanceElement)
  92.                     rewardsBalanceElement = msRewards?.shadowRoot?.querySelector("fluent-button")?.querySelector("span")?.querySelector("div");    
  93.                
  94.                 var retryOnFail = function(){
  95.                     if(retryCount == 0)
  96.                         alert("Failed reporting activity, You didn't get any points.");
  97.                     else
  98.                         setTimeout(() => msnShoppingGamePane.reportRewardsActivity(retryCount-1), 333);
  99.                 }
  100.            
  101.                 if(msRewards != null && autoUpdateRewardsBalance && rewardsBalanceElement && window.userAccessToken){
  102.                     await fetch("https://assets.msn.com/service/news/feed/segments/shopping?ocid=shopping-shophp-Peregrine&apikey=Xr2pbC1j5NMUwFF5YHTlhDDkcftEafmPoVP3pfA5eZ&timeOut=10000&cm=" + MeControl.Config.mkt.toLowerCase() + "&scn=MSNRPSAuth&$select=rewards|reportactivity|guessinggame&$filter=~5000&t=" + Date.now().toString(),{
  103.                         method: "GET",
  104.                         cache: "no-store",
  105.                         headers: {'Authorization': `Bearer ${window.userAccessToken}`}
  106.                     }).then(async (response) =>{
  107.                         if(response.status == 200){
  108.                             var reportActivityResponse = await response.json();    
  109.                             msnShoppingGamePane._rewardsBalance = JSON.parse(reportActivityResponse[0].data).Balance;
  110.                             rewardsBalanceElement.textContent = `\n${msnShoppingGamePane._rewardsBalance}\n\n`;
  111.                         }
  112.                         else retryOnFail();
  113.                     }).catch(() => {
  114.                         retryOnFail();
  115.                     });
  116.                 }
  117.             };
  118.         }
  119.        
  120.         // Modify the game settings countdown timer for new games.
  121.         msnShoppingGamePane.gameSettings.newGameCountdown = newGameCountdownTime;
  122.        
  123.         // Override their 'getGameResult' function with our own function which modifies the next game.
  124.         msnShoppingGamePane.getGameResult = function(e)
  125.         {
  126.             // Make sure a product card is selected or if 'e' is '-1' to reset the game.
  127.             if (e === msnShoppingGamePane.selectedCardIndex)
  128.             {
  129.                 // Modifies 'nextRoundShoppingEntities' to only contain 1 product.
  130.                 msnShoppingGamePane.nextRoundShoppingEntities = [msnShoppingGamePane.nextRoundShoppingEntities[0]];
  131.            
  132.                 // Remove the 10 daily limit. ( still limited to 100 points daily )
  133.                 localStorage.removeItem("gamesPerDay");
  134.                 msnShoppingGamePane.dailyLimitReached = false;
  135.                 if(msnShoppingGamePane.leaderboardRecord)
  136.                     msnShoppingGamePane.leaderboardRecord.dailyGuessingGamesPlayed = 0;
  137.      
  138.                 // This does multiple things...
  139.                 // Calls 'resetGame()' if 'e' is '-1'.
  140.                 // Checks if the game was won.
  141.                 // If the game was won it also checks if 'autoLoadNextGame' is 'true' and starts the next game if so.
  142.                 return e === -1 ? msnShoppingGamePane.resetGame() : msnShoppingGamePane.gameState === "win" ? (autoLoadNextGame ? msnShoppingGamePane.startNextGame() : "win") : "lose";
  143.             }
  144.         };
  145.  
  146.         //Calls the overridden 'getGameResult' function with the args '-1' to execute our code and reset the game.
  147.         msnShoppingGamePane.selectedCardIndex = -1;
  148.         msnShoppingGamePane.getGameResult(-1);
  149.     }
  150.     else alert("Unable to locate the shopping game!");
  151. }
  152.  
  153.  
  154. // This is the start...
  155. if(skipAuthCheck || await rewardsConnectorAuthCheck()){
  156.     modifyGame();
  157. }
  158. async function playAgainB(){
  159.     var playAgain=document.querySelector("shopping-page-base")
  160.   ?.shadowRoot.querySelector("shopping-homepage")
  161.   ?.shadowRoot.querySelector("msft-feed-layout")
  162.   ?.shadowRoot.querySelector("msn-shopping-game-pane")
  163.   ?.shadowRoot.querySelector(".shopping-game-pane-container")
  164.   ?.getElementsByClassName("game-panel-container")[0]
  165.   ?.getElementsByClassName("game-panel-header-2")[0]
  166.   ?.getElementsByClassName("game-panel-button")[0];
  167.   console.log(playAgain);
  168.   if(playAgain){
  169.     playAgain.click();
  170.   }
  171.   else{
  172.     return;
  173.   }
  174.   }
  175.   async function selectAuto(){
  176.     var selectButton = document.querySelector("shopping-page-base")
  177.         ?.shadowRoot.querySelector("shopping-homepage")
  178.         ?.shadowRoot.querySelector("msft-feed-layout")
  179.         ?.shadowRoot.querySelector("msn-shopping-game-pane")
  180.         ?.shadowRoot.querySelector("msft-stripe")
  181.         ?.querySelector("fluent-card")
  182.         ?.querySelector("msn-shopping-card").getElementsByClassName("shopping-select-overlay-button")[0];
  183.         if(selectButton){
  184.             selectButton.click();
  185.         }else{
  186.             return;
  187.         }
  188.   }
  189.   var playAgainInterval;
  190.   playAgainInterval = setInterval(async function () {
  191.    await playAgainB();
  192.    await selectAuto();
  193.   }, 1000);
  194. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement