Greasy Fork 还支持 简体中文。

Bundle Helper

Add tools for many bundle sites.

目前為 2016-01-10 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Bundle Helper
  3. // @namespace iFantz7E.BundleHelper
  4. // @version 0.02
  5. // @description Add tools for many bundle sites.
  6. // @match https://www.hrkgame.com/randomkeyshop/make-bundle/
  7. // @run-at document-start
  8. // @grant GM_addStyle
  9. // @grant GM_xmlhttpRequest
  10. // @icon http://store.steampowered.com/favicon.ico
  11. // @copyright 2016, 7-elephant
  12. // ==/UserScript==
  13.  
  14. (function ()
  15. {
  16. GM_addStyle(
  17. " .bh_button { "
  18. + " border-radius: 2px; border: medium none; padding: 10px; display: inline-block; cursor: pointer; "
  19. + " text-decoration: none !important; color: #67C1F5 !important; "
  20. + " background: rgba(103, 193, 245, 1) none repeat scroll 0% 0%; } "
  21. + " .bh_owned { background-color: #5c7836 !important; } "
  22. );
  23. function attachOnLoad(callback)
  24. {
  25. window.addEventListener("load", function (e)
  26. {
  27. callback();
  28. });
  29. }
  30.  
  31. function attachOnReady(callback)
  32. {
  33. document.addEventListener("DOMContentLoaded", function (e)
  34. {
  35. callback();
  36. });
  37. }
  38.  
  39. function insertBeforeElement(newNode, referenceNode)
  40. {
  41. referenceNode.parentNode.insertBefore(newNode, referenceNode);
  42. }
  43.  
  44. function insertAfterElement(newNode, referenceNode)
  45. {
  46. referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  47. }
  48.  
  49. function reload()
  50. {
  51. window.location = window.location.href;
  52. }
  53.  
  54. function getQueryByName(name, url)
  55. {
  56. if (url == null)
  57. url = location.search;
  58. name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  59. var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
  60. var results = regex.exec(url);
  61. return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  62. }
  63.  
  64. function main()
  65. {
  66. // Add load button
  67. {
  68. var divButton = document.createElement("div");
  69. divButton.classList.add("bh_button");
  70. divButton.id = "bh_loadAll";
  71. divButton.setAttribute("style", "position: fixed; right: 20px; bottom: 80px; z-index:3;");
  72. divButton.innerHTML = "<a href='#' onclick=' \
  73. var idx = setInterval(function() \
  74. { \
  75. var eleLoad = document.querySelector(\".loadmore\"); \
  76. if (eleLoad != null) \
  77. { \
  78. window.scrollTo(0,document.body.scrollHeight); \
  79. } \
  80. else \
  81. { \
  82. clearInterval(idx); \
  83. } \
  84. }, 500); \
  85. this.parentElement.style.display=\"none\"; \
  86. return false;'>Load All</a>";
  87. document.body.appendChild(divButton);
  88. }
  89. // Add mark button
  90. {
  91. var divButton = document.createElement("div");
  92. divButton.classList.add("bh_button");
  93. divButton.id = "bh_markOwned";
  94. divButton.setAttribute("style", "position: fixed; right: 20px; bottom: 20px; z-index:3;");
  95. var eleA = document.createElement("a");
  96. eleA.setAttribute("href", "#");
  97. eleA.setAttribute("onclick", "return false;");
  98. eleA.textContent = "Mark Owned";
  99. eleA.addEventListener("click", function()
  100. {
  101. var apps = [];
  102. var eleApps = document.querySelectorAll(".add-to-cart-product[href^='http://store.steampowered.com/app/']");
  103. console.log("Apps: " + eleApps.length);
  104. for (var i = 0; i < eleApps.length; i++)
  105. {
  106. var app = /[0-9]+/.exec(eleApps[i].getAttribute("href"));
  107. if (app != null)
  108. {
  109. apps.push(app[0]);
  110. }
  111. }
  112. apps = apps.filter(function(elem, index, self)
  113. {
  114. return index == self.indexOf(elem);
  115. });
  116. var appAll = apps.join(",");
  117. GM_xmlhttpRequest(
  118. {
  119. method: "GET",
  120. headers:
  121. {
  122. "Cache-Control": "max-age=0"
  123. },
  124. url: "http://store.steampowered.com/api/appuserdetails/?appids=" + appAll,
  125. onload: function(response)
  126. {
  127. var dataRes = JSON.parse(response.responseText);
  128. //console.log("Response: " + Object.keys(dataRes).length);
  129. var countOwned = 0;
  130. var eleApps = document.querySelectorAll(".add-to-cart-product[href^='http://store.steampowered.com/app/']");
  131. for (var i = 0; i < eleApps.length; i++)
  132. {
  133. var app = /[0-9]+/.exec(eleApps[i].getAttribute("href"));
  134. if (app != null)
  135. {
  136. if (typeof dataRes[app] !== "undefined")
  137. {
  138. if (dataRes[app].success)
  139. {
  140. if (dataRes[app].data.is_owned)
  141. {
  142. var eleLabel = eleApps[i].nextElementSibling;
  143. eleLabel.classList.add("bh_owned");
  144. countOwned++;
  145. }
  146. else
  147. {
  148. console.log("App: not owned - " + app);
  149. }
  150. }
  151. else
  152. {
  153. console.log("App: not success - " + app);
  154. }
  155. }
  156. }
  157. }
  158. console.log("Apps: owned - " + countOwned);
  159. } // End onload
  160. });
  161. });
  162. divButton.appendChild(eleA);
  163. document.body.appendChild(divButton);
  164. }
  165. }
  166.  
  167. attachOnReady(main);
  168. })();