JaiminB

Steam Discovery Queue Auto-Skipper

Jun 24th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @author      PotcFdk
  3. // @name        Steam Discovery Queue Auto-Skipper
  4. // @namespace   https://github.com/PotcFdk/SteamDiscoveryQueueAutoSkipper
  5. // @description Auto-clicks the "Next in Queue" button in Steam Discovery Queues.
  6. // @include     http://store.steampowered.com/app/*
  7. // @include     https://store.steampowered.com/app/*
  8. // @include     http://store.steampowered.com/agecheck/app/*
  9. // @include     https://store.steampowered.com/agecheck/app/*
  10. // @include     http://store.steampowered.com/explore*
  11. // @include     https://store.steampowered.com/explore*
  12. // @version     0.6.1
  13. // @grant       none
  14. // @downloadURL https://raw.githubusercontent.com/PotcFdk/SteamDiscoveryQueueAutoSkipper/master/SteamDiscoveryQueueAutoSkipper.user.js
  15. // @updateURL   https://raw.githubusercontent.com/PotcFdk/SteamDiscoveryQueueAutoSkipper/master/SteamDiscoveryQueueAutoSkipper.meta.js
  16. // ==/UserScript==
  17.  
  18. /*
  19.     Steam Discovery Queue Auto-Skipper - Copyright (c) PotcFdk, 2015 - 2018
  20.  
  21.     Licensed under the Apache License, Version 2.0 (the "License");
  22.     you may not use this file except in compliance with the License.
  23.     You may obtain a copy of the License at
  24.  
  25.     http://www.apache.org/licenses/LICENSE-2.0
  26.  
  27.     Unless required by applicable law or agreed to in writing, software
  28.     distributed under the License is distributed on an "AS IS" BASIS,
  29.     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  30.     See the License for the specific language governing permissions and
  31.     limitations under the License.
  32. */
  33.  
  34. // Handle error pages
  35.  
  36. var page = document.getElementsByTagName("BODY")[0].innerHTML;
  37.  
  38. if (page.length < 100
  39.     || page.includes ("An error occurred while processing your request")
  40.     || page.includes ("The Steam Store is experiencing some heavy load right now"))
  41. {
  42.     location.reload();
  43. }
  44.  
  45. // Click helper
  46.  
  47. function click (obj)
  48. {
  49.     var evObj = new MouseEvent ('click');
  50.     obj.dispatchEvent (evObj);
  51.  
  52.     window.addEventListener ('load', function() {
  53.         click (obj);
  54.     });
  55. }
  56.  
  57. // Main queue-skipper
  58.  
  59. function handleQueuePage()
  60. {
  61.     var btn = document.getElementsByClassName ("btn_next_in_queue")[0];
  62.  
  63.     if (btn)
  64.     {
  65.         var btn_text = btn.getElementsByTagName ("span")[0];
  66.         var btn_subtext = document.getElementsByClassName ("queue_sub_text")[0];
  67.         if (btn_text)
  68.         {
  69.             if (btn_subtext)
  70.             {
  71.                 btn_text.textContent = "Loading next item...";
  72.                 btn_text.appendChild (document.createElement ("br"));
  73.                 btn_text.appendChild (btn_subtext);
  74.             }
  75.             else
  76.             {
  77.                 btn_text.textContent = "Finishing Queue...";
  78.             }
  79.         }
  80.     }
  81.  
  82.     function nextInQueueButton()
  83.     {
  84.         if (btn)
  85.         {
  86.             click (btn);
  87.         }
  88.     }
  89.  
  90.     var ajax_failures = 0;
  91.  
  92.     function ajax()
  93.     {
  94.         var next_in_queue_form = document.getElementById ("next_in_queue_form");
  95.         var xhr = new XMLHttpRequest();
  96.         xhr.responseType = "document";
  97.         xhr.onreadystatechange = function()
  98.         {
  99.             if (xhr.readyState == 4 && xhr.status == 200)
  100.             {
  101.                 var _2_next_in_queue_form = xhr.response.getElementById ("next_in_queue_form");
  102.                 if (_2_next_in_queue_form && _2_next_in_queue_form.length)
  103.                 {
  104.                     next_in_queue_form.parentNode.innerHTML = _2_next_in_queue_form.parentNode.innerHTML;
  105.                     handleQueuePage();
  106.                 }
  107.                 else
  108.                 {
  109.                     location.href = next_in_queue_form.getAttribute ("action");
  110.                 }
  111.             }
  112.             else if (xhr.readyState == 4)
  113.             {
  114.                 if (ajax_failures++ < 3)
  115.                 {
  116.                     console.log ("Failed AJAX (HTTP status " + xhr.status + "). Retrying (" + ajax_failures + "/3)...");
  117.                     ajax();
  118.                 }
  119.                 else
  120.                 {
  121.                     console.log ("Failed AJAX (HTTP status " + xhr.status + "). Retrying using the classic button click method...");
  122.                     nextInQueueButton();
  123.                 }
  124.             }
  125.         };
  126.         xhr.open("POST", next_in_queue_form.getAttribute("action"), true);
  127.  
  128.         var form = new FormData();
  129.         form.append ("sessionid", next_in_queue_form.sessionid.value);
  130.         form.append ("appid_to_clear_from_queue", next_in_queue_form.appid_to_clear_from_queue.value);
  131.         form.append ("snr", next_in_queue_form.snr.value);
  132.  
  133.         xhr.send (form);
  134.     }
  135.  
  136.     ajax();
  137. }
  138.  
  139. if (document.getElementsByClassName ("btn_next_in_queue").length)
  140. {
  141.     handleQueuePage();
  142. }
  143.  
  144. // Automate agegate #1
  145.  
  146. var app_agegate = document.getElementById ("app_agegate");
  147. if (app_agegate)
  148. {
  149.     var btn_medium = app_agegate.getElementsByClassName ("btn_medium");
  150.     if (btn_medium)
  151.     {
  152.         for (i = 0; i < btn_medium.length; i++)
  153.         {
  154.             if (btn_medium[i].getAttribute("onclick").includes("HideAgeGate"))
  155.             {
  156.                 click (btn_medium[i]);
  157.             }
  158.         }
  159.     }
  160. }
  161.  
  162. // Automate agegate #2
  163.  
  164. var ageYear = document.getElementById ("ageYear");
  165. if (ageYear)
  166. {
  167.     ageYear.value = 1985;
  168.     if (DoAgeGateSubmit)
  169.     {
  170.         DoAgeGateSubmit();
  171.     }
  172. }
  173.  
  174.  
  175. var refresh_queue_btn = document.getElementById ("refresh_queue_btn");
  176. var _subtext = document.getElementsByClassName('subtext')[0];
  177. if (_subtext) {
  178.     var queue_count_subtext = _subtext.innerHTML;
  179.     var queue_count = parseInt(queue_count_subtext.replace(/[^0-9\.]/g, ''), 10);
  180.     if (isNaN(queue_count))
  181.     {
  182.         var language = document.documentElement.getAttribute("lang");
  183.         switch(language)
  184.         {
  185.             case "de":
  186.                 queue_count = queue_count_subtext.includes(" eine ") ? 1 : 0;
  187.                 break;
  188.             case "fr":
  189.                 queue_count = queue_count_subtext.includes(" une ") ? 1 : 0;
  190.                 break;
  191.             case "it":
  192.                 queue_count = queue_count_subtext.includes(" un'altra ") ? 1 : 0;
  193.                 break;
  194.             case "pl":
  195.                 queue_count = queue_count_subtext.includes(" jedną ") ? 1 : 0;
  196.                 break;
  197.             case "ru":
  198.             case "uk":
  199.                 queue_count = queue_count_subtext.includes(" одну ") ? 1 : 0;
  200.                 break;
  201.             default:
  202.                 queue_count = 0;
  203.         }
  204.     }
  205. }
  206.  
  207. if (refresh_queue_btn && (queue_count >= 1))
  208. {
  209.     click (refresh_queue_btn);
  210. }
Add Comment
Please, Sign In to add comment