Greasy Fork is available in English.

Steam 免费游戏永久入库脚本

steamdb.info屏蔽周末临时免费 Steam 免费游戏永久入库脚本

  1. // ==UserScript==
  2. // @name Steam 免费游戏永久入库脚本
  3. // @namespace https://greasyfork.org/zh-CN/scripts/401598
  4. // @version 0.3.2
  5. // @description steamdb.info屏蔽周末临时免费 Steam 免费游戏永久入库脚本
  6. // @author Boys
  7. // @match *://steamdb.info/*
  8. // @match *://store.steampowered.com/*
  9. // @icon https://store.steampowered.com/favicon.ico
  10. // @note 2020年5月12日 修复了一些的问题
  11. // @grant GM_registerMenuCommand
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @run-at document-end
  15. // ==/UserScript==
  16. (function () {
  17. // 注册上下文菜单
  18. GM_registerMenuCommand("打开Free Promotions", function () {
  19. window.open("https://steamdb.info/upcoming/free/", "_blank");
  20. });
  21. GM_registerMenuCommand("打开Steam licenses", function () {
  22. window.open("https://store.steampowered.com/account/licenses/", "_blank");
  23. });
  24. })();
  25. // 数组为空的判断
  26. Array.prototype.notempty = function () {
  27. let arr = [];
  28. this.map(function (val, index) {
  29. if (val !== "" && val != undefined) {
  30. arr.push(val);
  31. };
  32. });
  33. return arr;
  34. };
  35. // 等待元素出现
  36. jQuery.fn.wait = function (func, times, interval,funf) {
  37. var _times = times || -1, //默认永远等待
  38. _interval = interval || 20, //20毫秒每次
  39. _self = this,
  40. _selector = this.selector, //选择器
  41. _iIntervalID; //定时器id
  42. if( this.length ){ //如果已经获取到了,就直接执行函数
  43. func && func.call(this);
  44. } else {
  45. _iIntervalID = setInterval(function() {
  46. if(!_times) { //是0就执行等待超时失败的处理函数并退出
  47. funf && funf.call(this);
  48. clearInterval(_iIntervalID);
  49. };
  50. _times <= 0 || _times--; //如果是正数就 --
  51. _self = $(_selector); //再次选择
  52. if( _self.length ) { //判断是否取到
  53. func && func.call(_self);
  54. clearInterval(_iIntervalID);
  55. };
  56. }, _interval);
  57. };
  58. return this;
  59. };
  60. jQuery(function($) {
  61. 'use strict';
  62. function load_licenses(res) {
  63. if (typeof res == "undefined" || res == null || res.replace(/\s*/g, "") == "" || !res) return;
  64. if (location.hostname !== 'store.steampowered.com') {
  65. alert('Run this code on theSteamStore!');
  66. return;
  67. } else if (typeof jQuery !== 'function') {
  68. ShowAlertDialog('Fail', 'This page has no jQuery, try homepage.');
  69. return;
  70. } else if (document.getElementById('header_notification_area') === null) {
  71. ShowAlertDialog('Fail', 'You have to be logged in.');
  72. return;
  73. };
  74. let freePackages = res.replace(/\s*/g, "").split(",").notempty();
  75. let ownedPackages = {};
  76. $('.account_table a').each(function (i, el) {
  77. const match = el.href.match(/javascript:RemoveFreeLicense\( ([0-9]+), '/);
  78. if (match !== null) {
  79. ownedPackages[+match[1]] = true;
  80. };
  81. });
  82. let loaded = 0,
  83. packages = 0,
  84. total = freePackages.length,
  85. modal = ShowBlockingWaitDialog('努力执行中...', '请耐心等待,如果有错误请无视,请耐心等待脚本加载完毕');
  86. for (let i = 0; i < total; i++) {
  87. packages = freePackages[i];
  88. if (ownedPackages[packages]) {
  89. loaded++;
  90. continue;
  91. };
  92. jQuery.post('//store.steampowered.com/checkout/addfreelicense', {
  93. action: 'add_to_cart',
  94. sessionid: g_sessionID,
  95. subid: packages
  96. }).always(function () {
  97. loaded++;
  98. modal.Dismiss();
  99. if (loaded >= total) {
  100. GM_setValue("steam_db_free_info_store_ok", true);
  101. console.log("[信息] set steam_db_free_info_store_ok=" + true);
  102. ShowAlertDialog('任务执行完成', '请刷新网页查看....');
  103. // location.reload();
  104. } else {
  105. modal = ShowBlockingWaitDialog('执行中...', '加载至 <b>' + loaded + '</b>/' + total + '.');
  106. };
  107. });//always-end
  108. };//for-end
  109. };//load_licenses-end
  110. function flashing_prompt(count, time) {
  111. let timeout
  112. function clear() {
  113. --count
  114. if (count === 0) {
  115. clearInterval(timeout)
  116. }
  117. }
  118. function exec() {
  119. $("#dark-mode-toggle .dark-mode-slider").click()
  120. clear();
  121. }
  122. timeout = setInterval(() => {
  123. exec();
  124. }, time)
  125. };//flashing_prompt-end
  126. function exec() {
  127. $("td").each(function () { // 移除周末临时免费
  128. if ($(this).text() == "Weekend") $(this).parent().remove();
  129. })
  130. let v = "";
  131. $(".timeago:even").each(function (index, value, array) {
  132. if ($(this).text().indexOf("ago") == -1)
  133. return false;
  134. else
  135. v += $(this).parent().attr("data-subid") + ",";
  136. })
  137. if (GM_getValue("steam_db_free_info_store_ok") != true) flashing_prompt(10, 500);
  138. let oldValue = GM_getValue("steam_db_free_info_store")
  139. console.log("[信息] get steam_db_free_info_store=" + oldValue);
  140. if (oldValue === v) return;
  141. let freePackages = v.replace(/\s*/g, "").split(",").notempty();
  142. if (freePackages.forEach(function (value, index, array) {
  143. if (oldValue == "undefined" || oldValue == null) return false;
  144. if (value == "undefined" || value == null) return false;
  145. if (oldValue.indexOf(value) == -1) return false;
  146. })) return;
  147. flashing_prompt(10, 500);
  148. GM_setValue("steam_db_free_info_store", v);
  149. GM_setValue("steam_db_free_info_store_ok", false);
  150. console.log("[信息] set steam_db_free_info_store=" + v);
  151. console.log("[信息] set steam_db_free_info_store_ok=" + false);
  152. };
  153. let local = window.location.href;
  154. if (local.indexOf("steamdb.info/upcoming/free") != -1) {
  155. $(".dark-mode-slider").wait(function() { //等待class='dark-mode-slider'的元素加载完成
  156. exec();
  157. },200,20,function() {
  158. console.log("[信息] 等待页面加载完成超时,请刷新网页后重试");
  159. });
  160. return;
  161. };
  162. if (local.indexOf("store.steampowered.com/account/licenses") != -1) {
  163. $("#footer").wait(function(){
  164. let res = GM_getValue("steam_db_free_info_store");
  165. let v = GM_getValue("steam_db_free_info_store_ok");
  166. console.log("[信息] get steam_db_free_info_store=" + res);
  167. console.log("[信息] get steam_db_free_info_store_ok=" + v);
  168. if (v == true) return;
  169. load_licenses(res);
  170. },200,20,function() {
  171. console.log("[信息] 等待页面加载完成超时,请刷新网页后重试");
  172. });
  173. return;
  174. };
  175. });