Steam Key Helper

try to take over the world!

  1. // ==UserScript==
  2. // @name Steam Key Helper
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.0.0
  5. // @description try to take over the world!
  6. // @icon http://store.steampowered.com/favicon.ico
  7. // @author Bisumaruko
  8. // @include http*://*
  9. // @exclude http*://*dailyindiegame.com/account_createtrade.html
  10. // @exclude http*://steam.depar.me/*
  11. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js
  12. // @require https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/jquery.mark.min.js
  13. // @require https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.0.6/sweetalert2.min.js
  14. // @resource SweetAlert2CSS https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.0.6/sweetalert2.min.css
  15. // @connect store.steampowered.com
  16. // @grant GM_xmlhttpRequest
  17. // @grant GM_setValue
  18. // @grant GM_getValue
  19. // @grant GM_addStyle
  20. // @grant GM_getResourceText
  21. // @run-at document-start
  22. // @noframes
  23. // ==/UserScript==
  24.  
  25. /* global swal, g_AccountID, g_sessionID, g_oSuggestParams */
  26.  
  27. // setup jQuery
  28. const $ = jQuery.noConflict(true);
  29.  
  30. // inject CSS
  31. GM_addStyle(`
  32. ${GM_getResourceText('SweetAlert2CSS')}
  33.  
  34. .hide { display: none; }
  35. .SKH_processed { color: #57bae8; cursor: pointer; }
  36. .SKH_processed:hover { text-decoration: underline; }
  37. .SKH_activated { text-decoration: line-through; }
  38. .SKH_panel {
  39. width: 60px;
  40. height: 60px;
  41. position: fixed;
  42. top: 50%;
  43. right: 20px;
  44. transform: translateY(-50%);
  45. background-color: rgb(87, 186, 232);
  46. opacity: 0.5;
  47. text-align: center;
  48. }
  49. .SKH_panel:hover { opacity: 1; }
  50. .SKH_panel .switch {
  51. position: relative;
  52. display: inline-block;
  53. width: 40px;
  54. height: 24px;
  55. margin-top: 5px;
  56. }
  57. .SKH_panel .switch input { display: none; }
  58. .SKH_panel .slider {
  59. position: absolute;
  60. cursor: pointer;
  61. top: 0;
  62. left: 0;
  63. right: 0;
  64. bottom: 0;
  65. background-color: #ccc;
  66. transition: 0.4s;
  67. }
  68. .SKH_panel .slider:before {
  69. position: absolute;
  70. content: "";
  71. height: 20px;
  72. width: 20px;
  73. left: 2px;
  74. bottom: 2px;
  75. background-color: white;
  76. transition: 0.4s;
  77. }
  78. .SKH_panel input:checked + .slider { background-color: #2196F3; }
  79. .SKH_panel input:focus + .slider { box-shadow: 0 0 1px #2196F3; }
  80. .SKH_panel input:checked + .slider:before { transform: translateX(16px); }
  81. .SKH_panel > span { display: inline-block; cursor: pointer; color: white; }
  82. .SKH_panel > button {
  83. width: 20px;
  84. height: 20px;
  85. position: absolute;
  86. bottom: 0;
  87. padding: 2px;
  88. background-color: transparent;
  89. background-size: 18px;
  90. background-repeat: no-repeat;
  91. background-origin: padding-box;
  92. background-position: 50% 50%;
  93. border: none;
  94. outline: none;
  95. box-sizing: border-box;
  96. cursor: pointer;
  97. }
  98. .SKH_panel > .hidePanel {
  99. left: 0;
  100. background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjxzdmcgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMzIgMzIiIGhlaWdodD0iMzJweCIgaWQ9InN2ZzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB3aWR0aD0iMzJweCIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIiB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOmlua3NjYXBlPSJodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy9uYW1lc3BhY2VzL2lua3NjYXBlIiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiIHhtbG5zOnNvZGlwb2RpPSJodHRwOi8vc29kaXBvZGkuc291cmNlZm9yZ2UubmV0L0RURC9zb2RpcG9kaS0wLmR0ZCIgeG1sbnM6c3ZnPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgaWQ9ImJhY2tncm91bmQiPjxyZWN0IGZpbGw9Im5vbmUiIGhlaWdodD0iMzIiIHdpZHRoPSIzMiIvPjwvZz48ZyBpZD0iY2FuY2VsIj48cG9seWdvbiBwb2ludHM9IjIsMjYgNiwzMCAxNiwyMCAyNiwzMCAzMCwyNiAyMCwxNiAzMCw2IDI2LDIgMTYsMTIgNiwyIDIsNiAxMiwxNiAgIi8+PC9nPjwvc3ZnPg==);
  101. filter: opacity(60%);
  102. }
  103. .SKH_panel > .disable {
  104. left: 20px;
  105. background-size: contain;
  106. background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjwhRE9DVFlQRSBzdmcgIFBVQkxJQyAnLS8vVzNDLy9EVEQgU1ZHIDEuMC8vRU4nICAnaHR0cDovL3d3dy53My5vcmcvVFIvMjAwMS9SRUMtU1ZHLTIwMDEwOTA0L0RURC9zdmcxMC5kdGQnPjxzdmcgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMjQgMjQiIGlkPSJMYXllcl8xIiB2ZXJzaW9uPSIxLjAiIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+PGc+PHBhdGggZD0iTTEyLDRjNC40LDAsOCwzLjYsOCw4cy0zLjYsOC04LDhzLTgtMy42LTgtOFM3LjYsNCwxMiw0IE0xMiwyQzYuNSwyLDIsNi41LDIsMTJjMCw1LjUsNC41LDEwLDEwLDEwczEwLTQuNSwxMC0xMCAgIEMyMiw2LjUsMTcuNSwyLDEyLDJMMTIsMnoiLz48L2c+PGxpbmUgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiIHN0cm9rZS13aWR0aD0iMiIgeDE9IjE4LjIiIHgyPSI1LjgiIHkxPSIxOC4yIiB5Mj0iNS44Ii8+PC9zdmc+);
  107. filter: opacity(60%);
  108. }
  109. .SKH_panel > .settings {
  110. left: 40px;
  111. background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjwhRE9DVFlQRSBzdmcgIFBVQkxJQyAnLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4nICAnaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkJz48c3ZnIGhlaWdodD0iMzJweCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMzIgMzI7IiB2ZXJzaW9uPSIxLjEiIHZpZXdCb3g9IjAgMCAzMiAzMiIgd2lkdGg9IjMycHgiIHhtbDpzcGFjZT0icHJlc2VydmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxnIGlkPSJMYXllcl8xIi8+PGcgaWQ9ImNvZyI+PHBhdGggZD0iTTMyLDE3Ljk2OXYtNGwtNC43ODEtMS45OTJjLTAuMTMzLTAuMzc1LTAuMjczLTAuNzM4LTAuNDQ1LTEuMDk0bDEuOTMtNC44MDVMMjUuODc1LDMuMjUgICBsLTQuNzYyLDEuOTYxYy0wLjM2My0wLjE3Ni0wLjczNC0wLjMyNC0xLjExNy0wLjQ2MUwxNy45NjksMGgtNGwtMS45NzcsNC43MzRjLTAuMzk4LDAuMTQxLTAuNzgxLDAuMjg5LTEuMTYsMC40NjlsLTQuNzU0LTEuOTEgICBMMy4yNSw2LjEyMWwxLjkzOCw0LjcxMUM1LDExLjIxOSw0Ljg0OCwxMS42MTMsNC43MDMsMTIuMDJMMCwxNC4wMzF2NGw0LjcwNywxLjk2MWMwLjE0NSwwLjQwNiwwLjMwMSwwLjgwMSwwLjQ4OCwxLjE4OCAgIGwtMS45MDIsNC43NDJsMi44MjgsMi44MjhsNC43MjMtMS45NDVjMC4zNzksMC4xOCwwLjc2NiwwLjMyNCwxLjE2NCwwLjQ2MUwxNC4wMzEsMzJoNGwxLjk4LTQuNzU4ICAgYzAuMzc5LTAuMTQxLDAuNzU0LTAuMjg5LDEuMTEzLTAuNDYxbDQuNzk3LDEuOTIybDIuODI4LTIuODI4bC0xLjk2OS00Ljc3M2MwLjE2OC0wLjM1OSwwLjMwNS0wLjcyMywwLjQzOC0xLjA5NEwzMiwxNy45Njl6ICAgIE0xNS45NjksMjJjLTMuMzEyLDAtNi0yLjY4OC02LTZzMi42ODgtNiw2LTZzNiwyLjY4OCw2LDZTMTkuMjgxLDIyLDE1Ljk2OSwyMnoiIHN0eWxlPSJmaWxsOiM0RTRFNTA7Ii8+PC9nPjwvc3ZnPg==);
  112. }
  113.  
  114. .SKH_settings .name { text-align: right; vertical-align: top; white-space: nowrap; }
  115. .SKH_settings .value { text-align: left; }
  116. .SKH_settings .value > * { height: 30px; margin: 0 20px 10px; }
  117. .SKH_settings .switch { position: relative; display: inline-block; width: 60px; }
  118. .SKH_settings .switch input { display: none; }
  119. .SKH_settings .slider {
  120. position: absolute;
  121. cursor: pointer;
  122. top: 0;
  123. left: 0;
  124. right: 0;
  125. bottom: 0;
  126. background-color: #ccc;
  127. transition: 0.4s;
  128. }
  129. .SKH_settings .slider:before {
  130. position: absolute;
  131. content: "";
  132. height: 26px;
  133. width: 26px;
  134. left: 2px;
  135. bottom: 2px;
  136. background-color: white;
  137. transition: 0.4s;
  138. }
  139. .SKH_settings input:checked + .slider { background-color: #2196F3; }
  140. .SKH_settings input:focus + .slider { box-shadow: 0 0 1px #2196F3; }
  141. .SKH_settings input:checked + .slider:before { transform: translateX(30px); }
  142. .SKH_settings input[type=text] { width: 200px; }
  143. .SKH_settings input[type=number] { width: 60px; height: 30px; box-sizing: border-box; }
  144. .SKH_settings textarea { width: 200px; min-width: 200px; height: 60px; min-height: 60px; }
  145. .SKH_settings label + p { display: none; transition: display 1s; }
  146. .SKH_settings label ~ *:last-child { display: block; transition: display 1s; }
  147. .SKH_settings .toggleOn label + p { display: block; }
  148. .SKH_settings .toggleOn label ~ *:last-child { display: none; }
  149. `);
  150.  
  151. // load config
  152. const eol = "\n";
  153. const has = Object.prototype.hasOwnProperty;
  154.  
  155. const regKey = /(?:(?:([A-Z0-9])(?!\1{4})){5}-){2,5}[A-Z0-9]{5}/g;
  156. let activating = false;
  157.  
  158. const activated = JSON.parse(GM_getValue('SKH_activated') || '[]');
  159. const currentActivated = [];
  160. const config = {
  161. data: JSON.parse(GM_getValue('SKH_config') || '{}'),
  162. save() {
  163. GM_setValue('SKH_config', JSON.stringify(this.data));
  164. },
  165. set(key, value, callback = null) {
  166. this.data[key] = value;
  167. this.save();
  168.  
  169. if (typeof callback === 'function') callback();
  170. },
  171. get(key) {
  172. return has.call(this.data, key) ? this.data[key] : null;
  173. },
  174. push(key, value) {
  175. if (Array.isArray(this.data[key])) {
  176. this.data[key].push(value);
  177. this.save();
  178. }
  179. },
  180. splice(key, start, count) {
  181. if (Array.isArray(this.data[key])) {
  182. this.data[key].splice(start, count);
  183. this.save();
  184. }
  185. },
  186. init() {
  187. if (!has.call(this.data, 'autoUpdateSessionID')) this.data.autoUpdateSessionID = true;
  188. if (!has.call(this.data, 'autoClosePopup')) this.data.autoClosePopup = false;
  189. if (!has.call(this.data, 'autoClosePopupTimer')) this.data.autoClosePopupTimer = 3;
  190. if (!has.call(this.data, 'autoReplyActivated')) this.data.autoReplyActivated = false;
  191. if (!has.call(this.data, 'enabledForever')) this.data.enabledForever = true;
  192. if (!has.call(this.data, 'enabled')) this.data.enabled = [];
  193. if (!has.call(this.data, 'disabled')) this.data.disabled = [];
  194. if (!has.call(this.data, 'hideForever')) this.data.hideForever = false;
  195. if (!has.call(this.data, 'hide')) this.data.hide = [];
  196. if (!has.call(this.data, 'off')) this.data.off = [];
  197. }
  198. };
  199.  
  200. config.init();
  201.  
  202. // text
  203. const i18n = {
  204. tchinese: {
  205. name: '繁體中文',
  206. updateSuccessTitle: '更新成功!',
  207. updateSuccess: '成功更新Steam sessionID',
  208. errorTitle: '糟糕!',
  209. errorUnexpected: '發生未知錯誤,請稍後再試',
  210. errorInvalidKey: '序號錯誤',
  211. errorUsedKey: '序號已被使用',
  212. errorRateLimited: '啟動受限',
  213. errorCountryRestricted: '地區限制',
  214. errorAlreadyOwned: '產品已擁有',
  215. errorMissingBaseGame: '未擁有主程式',
  216. errorPS3Required: '需要PS3 啟動',
  217. errorGiftWallet: '偵測到禮物卡/錢包序號',
  218. errorFailedRequest: '處理資料發生錯誤,請稍後再試',
  219. errorFailedRequestNeedUpdate: '請求發生錯誤,請稍後再試<br>或者嘗試更新SessionID',
  220. errorActivated: '你已啟動過這序號',
  221. successTitle: '啟動成功!',
  222. processingTitle: '喵~',
  223. processingMsg: '啟動序號中,請稍後',
  224. notLoggedInTitle: '未登入',
  225. notLoggedInMsg: '請登入Steam 以讓腳本紀錄SessionID',
  226. missingTitle: '未發現SessionID',
  227. missingMsg: '請問要更新SessionID 嗎?',
  228. titlehidePanel: '在這網站隱藏懸浮框',
  229. titleDisable: '在這網站禁止腳本',
  230. titleSettings: '開啟設定',
  231. settingsTitle: '設定',
  232. settingsAutoUpdateSessionID: '自動更新SessionID',
  233. settingsSessionID: '我的sessionID',
  234. settingsLanguage: '語言',
  235. settingsAutoClosePopup: '自動關閉彈窗',
  236. settingsTimerDisabled: '不關閉彈窗',
  237. settingsTimerSecond: '秒',
  238. settingsAutoReplyActivated: '自動回覆啟動序號',
  239. settingsEnabledForever: '全域運行腳本',
  240. settingsEnabled: '在這些網站運行腳本',
  241. settingsDisabled: '在這些網站禁止腳本',
  242. settingsHideForever: '全域隱藏懸浮',
  243. settingsHide: '在這些網站隱藏懸浮',
  244. settingsOff: '在這些網站暫停腳本',
  245. placeholderEnabled: '如不全域運行腳本此欄不得為空',
  246. activatedReply: '感謝大佬!已拿%KEYS%'
  247. },
  248. schinese: {
  249. name: '简体中文',
  250. updateSuccessTitle: '更新成功',
  251. updateSuccess: '成功更新Steam sessionID',
  252. errorTitle: '糟糕!',
  253. errorUnexpected: '发生未知错误,请稍后再试',
  254. errorInvalidKey: '激活码错误',
  255. errorUsedKey: '激活码已被使用',
  256. errorRateLimited: '激活受限',
  257. errorCountryRestricted: '地区限制',
  258. errorAlreadyOwned: '产品已拥有',
  259. errorMissingBaseGame: '未拥有游戏本体',
  260. errorPS3Required: '需要PS3 激活',
  261. errorGiftWallet: '侦测到礼物卡/钱包激活码',
  262. errorFailedRequest: '处理资料发生错误,请稍后再试',
  263. errorFailedRequestNeedUpdate: '请求发生错误,请稍后再试<br>或者尝试更新SessionID',
  264. errorActivated: '你已激活过这激活码',
  265. successTitle: '激活成功!',
  266. processingTitle: '喵~',
  267. processingMsg: '激活中,请稍后',
  268. notLoggedInTitle: '未登入',
  269. notLoggedInMsg: '请登入Steam 以让脚本记录SessionID',
  270. missingTitle: '未发现SessionID',
  271. missingMsg: '请问要更新SessionID 吗?',
  272. titlehidePanel: '在这网站隐藏悬浮',
  273. titleDisable: '在这网站禁止脚本',
  274. titleSettings: '打开设置',
  275. settingsTitle: '设置',
  276. settingsAutoUpdateSessionID: '自动更新SessionID',
  277. settingsSessionID: '我的sessionID',
  278. settingsLanguage: '语言',
  279. settingsAutoClosePopup: '自动关闭弹窗',
  280. settingsTimerDisabled: '不关闭弹窗',
  281. settingsTimerSecond: '秒',
  282. settingsAutoReplyActivated: '自动回复激活KEY',
  283. settingsEnabledForever: '全域运行脚本',
  284. settingsEnabled: '在这些网站运行脚本',
  285. settingsDisabled: '在这些网站禁止脚本',
  286. settingsHideForever: '全域隐藏悬浮',
  287. settingsHide: '在这些网站隐藏悬浮',
  288. settingsOff: '在这些网站暂停脚本',
  289. placeholderEnabled: '如不全域运行脚本此栏不得为空',
  290. activatedReply: '感谢大佬!已激活%KEYS%'
  291. },
  292. english: {
  293. name: 'English',
  294. updateSuccessTitle: 'Update Successful!',
  295. updateSuccess: 'Steam sessionID is successfully updated',
  296. errorTitle: 'Opps!',
  297. errorUnexpected: 'An unexpected error has occured, please try again later',
  298. errorInvalidKey: 'Invalid Key',
  299. errorUsedKey: 'Used Key',
  300. errorRateLimited: 'Rate Limited',
  301. errorCountryRestricted: 'Country Restricted',
  302. errorAlreadyOwned: 'Product Already Owned',
  303. errorMissingBaseGame: 'Missing Base Game',
  304. errorPS3Required: 'PS3 Activation Required',
  305. errorGiftWallet: 'Gift Card/Wallet Code Detected',
  306. errorFailedRequest: 'Result parse failed, please try again',
  307. errorFailedRequestNeedUpdate: 'Request failed, please try again<br>or update sessionID',
  308. errorActivated: 'You have activated this key before',
  309. successTitle: 'Activation Successful!',
  310. processingTitle: 'Nyaa~',
  311. processingMsg: 'Activating key, please wait',
  312. notLoggedInTitle: 'Not Logged-In',
  313. notLoggedInMsg: 'Please login to Steam so sessionID can be saved',
  314. missingTitle: 'Missing SessionID',
  315. missingMsg: 'Do you want to update your Steam sessionID?',
  316. titlehidePanel: 'Hide floating panel on this site',
  317. titleDisable: 'Disable script on this site',
  318. titleSettings: 'Open settings panel',
  319. settingsTitle: 'Settings',
  320. settingsAutoUpdateSessionID: 'Auto Update SessionID',
  321. settingsSessionID: 'Your sessionID',
  322. settingsLanguage: 'Language',
  323. settingsAutoClosePopup: 'Close popup in',
  324. settingsTimerDisabled: 'Don\'t close popup',
  325. settingsTimerSecond: 'second',
  326. settingsAutoReplyActivated: 'Auto Reply Activated Keys',
  327. settingsEnabledForever: 'Enable scrip all the time',
  328. settingsEnabled: 'Enable script on',
  329. settingsDisabled: 'Disable script on',
  330. settingsHideForever: 'Hide floating panel all the time',
  331. settingsHide: 'Hide floating panel on',
  332. settingsOff: 'Turn off script on',
  333. placeholderEnabled: 'Must not be empty if script not enabled all the time',
  334. activatedReply: 'Thank you for the keys! Activated %KEYS%'
  335. }
  336. };
  337. let text = has.call(i18n, config.get('language')) ? i18n[config.get('language')] : i18n.english;
  338.  
  339. // functions
  340. const getSessionID = () => {
  341. GM_xmlhttpRequest({
  342. method: 'GET',
  343. url: 'https://store.steampowered.com/',
  344. onload: res => {
  345. if (res.status === 200) {
  346. const accountID = res.response.match(/g_AccountID = (\d+)/).pop();
  347. const sessionID = res.response.match(/g_sessionID = "(\w+)"/).pop();
  348.  
  349. if (accountID > 0) config.set('sessionID', sessionID);else {
  350. swal({
  351. title: text.notLoggedInTitle,
  352. text: text.notLoggedInMsg,
  353. type: 'error',
  354. showCancelButton: true
  355. }).then(() => {
  356. window.open('https://store.steampowered.com/');
  357. });
  358. }
  359. }
  360. }
  361. });
  362. };
  363. const settings = () => {
  364. const panelHTML = `
  365. <div class="SKH_settings">
  366. <table>
  367. <tr>
  368. <td class="name">${text.settingsAutoUpdateSessionID}</td>
  369. <td class="value">
  370. <label class="switch">
  371. <input type="checkbox" class="autoUpdateSessionID">
  372. <span class="slider"></span>
  373. </label>
  374. </td>
  375. </tr>
  376. <tr>
  377. <td class="name">${text.settingsSessionID}</td>
  378. <td class="value">
  379. <input type="text" class="sessionID" value="${config.get('sessionID')}" disabled>
  380. </td>
  381. </tr>
  382. <tr>
  383. <td class="name">${text.settingsLanguage}</td>
  384. <td class="value">
  385. <select class="language"></select>
  386. </td>
  387. </tr>
  388. <tr>
  389. <td class="name">${text.settingsAutoClosePopup}</td>
  390. <td class="value">
  391. <label class="switch">
  392. <input type="checkbox" class="autoClosePopup">
  393. <span class="slider"></span>
  394. </label>
  395. <p><input type="number" class="autoClosePopupTimer" min="0" value="${config.get('autoClosePopupTimer')}"> ${text.settingsTimerSecond}</p>
  396. <p class="timerDisabledText">${text.settingsTimerDisabled}</p>
  397. </td>
  398. </tr>
  399. <tr>
  400. <td class="name">${text.settingsAutoReplyActivated}</td>
  401. <td class="value">
  402. <label class="switch">
  403. <input type="checkbox" class="autoReplyActivated">
  404. <span class="slider"></span>
  405. </label>
  406. </td>
  407. </tr>
  408. <tr>
  409. <td class="name">${text.settingsEnabled}</td>
  410. <td class="value">
  411. <label class="switch">
  412. <input type="checkbox" class="enabledForever">
  413. <span class="slider"></span>
  414. </label>
  415. <p class="enabledForeverText">${text.settingsEnabledForever}</p>
  416. <textarea class="enabledList" placeholder="${text.placeholderEnabled}"></textarea>
  417. </td>
  418. </tr>
  419. <tr>
  420. <td class="name">${text.settingsDisabled}</td>
  421. <td class="value">
  422. <textarea class="disabledList"></textarea>
  423. </td>
  424. </tr>
  425. <tr>
  426. <td class="name">${text.settingsHide}</td>
  427. <td class="value">
  428. <label class="switch">
  429. <input type="checkbox" class="hideForever">
  430. <span class="slider"></span>
  431. </label>
  432. <p class="hideForeverText">${text.settingsHideForever}</p>
  433. <textarea class="hideList"></textarea>
  434. </td>
  435. </tr>
  436. <tr>
  437. <td class="name">${text.settingsOff}</td>
  438. <td class="value">
  439. <textarea class="offList"></textarea>
  440. </td>
  441. </tr>
  442. </table>
  443. </div>
  444. `;
  445. const panelHandler = () => {
  446. // apply settings
  447. const $panel = $(swal.getContent());
  448. const $sessionID = $panel.find('.sessionID');
  449. const $language = $panel.find('.language');
  450.  
  451. // toggles
  452. $panel.find('input[type="checkbox"]').each((index, input) => {
  453. const $input = $(input);
  454.  
  455. $input.change(e => {
  456. swal.showLoading();
  457.  
  458. const setting = e.delegateTarget.className;
  459. const state = e.delegateTarget.checked;
  460.  
  461. config.set(setting, state);
  462. $(e.delegateTarget).closest('td').toggleClass('toggleOn', state);
  463.  
  464. if (setting === 'autoUpdateSessionID') $sessionID.attr('disabled', state);
  465.  
  466. setTimeout(swal.hideLoading, 500);
  467. });
  468. $input.prop('checked', !!config.get(input.className)).trigger('change');
  469. });
  470.  
  471. // sessionID input
  472. $sessionID.prop('disabled', config.get('autoUpdateSessionID'));
  473. $sessionID.change(() => {
  474. swal.showLoading();
  475.  
  476. config.set('sessionID', $sessionID.val().trim());
  477.  
  478. setTimeout(swal.hideLoading, 500);
  479. });
  480.  
  481. // language
  482. Object.keys(i18n).forEach(language => {
  483. $language.append(new Option(i18n[language].name, language));
  484. });
  485. $panel.find(`option[value=${config.get('language')}]`).prop('selected', true);
  486. $language.change(() => {
  487. swal.showLoading();
  488.  
  489. const newLanguage = $language.val();
  490. config.set('language', newLanguage);
  491.  
  492. text = has.call(i18n, newLanguage) ? i18n[newLanguage] : i18n.english;
  493.  
  494. setTimeout(swal.hideLoading, 500);
  495. });
  496.  
  497. // timer
  498. $panel.find('.autoClosePopupTimer').change(e => {
  499. const second = parseInt(e.delegateTarget.value, 10);
  500.  
  501. config.set('autoClosePopupTimer', Number.isInteger(second) ? second : 3);
  502. });
  503.  
  504. // websites list
  505. ['enabled', 'disabled', 'hide', 'off'].forEach(list => {
  506. const $list = $panel.find(`.${list}List`);
  507.  
  508. $list.val(config.get(list).join(eol));
  509. $list.change(() => {
  510. swal.showLoading();
  511.  
  512. const hostList = $list.val().split(eol).map(x => x.trim()).filter(x => x.length);
  513.  
  514. config.set(list, hostList);
  515. if (list === 'enabled') {
  516. const state = !!$panel.find('.enabledForever:checked').length;
  517.  
  518. // script is not enabled all the time and empty enabled website
  519. if (!state && hostList.length === 0) config.set('enabledForever', true);
  520. }
  521.  
  522. setTimeout(swal.hideLoading, 500);
  523. });
  524. });
  525. };
  526.  
  527. swal({
  528. title: text.settingsTitle,
  529. html: panelHTML,
  530. onBeforeOpen: panelHandler
  531. });
  532. };
  533. const insertPanel = callback => {
  534. const $panel = $('<div class="SKH_panel"></div>');
  535.  
  536. // add toggle switch
  537. $panel.append($(`
  538. <label class="switch">
  539. <input type="checkbox">
  540. <span class="slider"></span>
  541. </label>
  542. `).change(() => {
  543. const host = location.hostname;
  544. const toggle = !!$('.SKH_panel input:checked').length;
  545. const index = config.get('off').indexOf(host);
  546.  
  547. if (toggle && index > -1) config.splice('off', index, 1);else if (!toggle && index === -1) config.push('off', host);
  548. }));
  549.  
  550. // add hide button
  551. $panel.append($(`<button class="hidePanel" title="${text.titlehidePanel}"> </button>`).click(() => {
  552. config.push('hide', location.hostname);
  553. $panel.remove();
  554. }));
  555.  
  556. // add disabled button
  557. $panel.append($(`<button class="disable" title="${text.titleDisable}"> </button>`).click(() => {
  558. config.push('disabled', location.hostname);
  559. $panel.remove();
  560. }));
  561.  
  562. // add settings button
  563. $panel.append($(`<button class="settings" class="${text.titleSettings}"> </button>`).click(settings));
  564.  
  565. $('body').append($panel);
  566.  
  567. callback();
  568.  
  569. // hide panel after 5 seconds
  570. setTimeout(() => {
  571. $panel.hide();
  572. }, 5000);
  573. };
  574. const getResultMsg = result => {
  575. const msg = {
  576. title: text.errorTitle,
  577. html: text.errorUnexpected,
  578. type: 'error'
  579. };
  580. const errors = {
  581. 14: text.errorInvalidKey,
  582. 15: text.errorUsedKey,
  583. 53: text.errorRateLimited,
  584. 13: text.errorCountryRestricted,
  585. 9: text.errorAlreadyOwned,
  586. 24: text.errorMissingBaseGame,
  587. 36: text.errorPS3Required,
  588. 50: text.errorGiftWallet
  589. };
  590.  
  591. if (result.success === 1) {
  592. msg.title = text.successTitle;
  593. msg.html = '';
  594. msg.type = 'success';
  595. } else if (result.success === 2) {
  596. const errorCode = result.purchase_result_details;
  597. if (has.call(errors, errorCode)) msg.html = errors[errorCode];
  598. }
  599.  
  600. const details = [];
  601. result.purchase_receipt_info.line_items.forEach(item => {
  602. const detail = [`<b>${item.line_item_description}</b>`];
  603. if (item.packageid > 0) detail.push(`sub: <a target="_blank" href="https://steamdb.info/sub/${item.packageid}/">${item.packageid}</a>`);
  604. if (item.appid > 0) detail.push(`app: <a target="_blank" href="https://steamdb.info/sub/${item.appid}/">${item.appid}</a>`);
  605.  
  606. details.push(detail.join(', '));
  607. });
  608.  
  609. if (details.length > 0) msg.html += `<br>${details.join('<br>')}`;
  610.  
  611. return msg;
  612. };
  613. const activateKey = key => {
  614. if ($('.SKH_panel input:checked').length > 0 && !activating) {
  615. activating = true;
  616.  
  617. swal(text.processingTitle, text.processingMsg);
  618. swal.showLoading();
  619.  
  620. const timer = config.get('autoClosePopup') ? config.get('autoClosePopupTimer') * 1000 : null;
  621. if (activated.includes(key)) {
  622. swal.close();
  623. if (timer !== 0) {
  624. swal({
  625. title: text.errorTitle,
  626. text: text.errorActivated,
  627. type: 'error',
  628. timer
  629. }).catch(swal.noop);
  630. }
  631.  
  632. activating = false;
  633. } else {
  634. GM_xmlhttpRequest({
  635. method: 'POST',
  636. url: 'https://store.steampowered.com/account/ajaxregisterkey/',
  637. headers: {
  638. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  639. Origin: 'https://store.steampowered.com',
  640. Referer: 'https://store.steampowered.com/account/registerkey'
  641. },
  642. data: `product_key=${key}&sessionid=${config.get('sessionID')}`,
  643. onload: res => {
  644. swal.close();
  645. if (res.status === 200) {
  646. try {
  647. const result = JSON.parse(res.response);
  648. const msg = getResultMsg(result);
  649.  
  650. if (timer !== 0) {
  651. swal({
  652. title: msg.title,
  653. html: msg.html,
  654. type: msg.type,
  655. timer
  656. }).catch(swal.noop);
  657. }
  658.  
  659. // update activated
  660. if (!activated.includes(key)) {
  661. const failCode = result.purchase_result_details;
  662. if (result.success === 1 || [14, 15, 9].includes(failCode)) {
  663. activated.push(key);
  664. GM_setValue('SKH_activated', JSON.stringify(activated));
  665. $(`span:contains(${key}), [value=${key}]`).addClass('SKH_activated');
  666. }
  667. }
  668.  
  669. // insert activated in this session
  670. if (result.success === 1) currentActivated.push(key);
  671. } catch (e) {
  672. swal(text.errorTitle, text.errorFailedRequest, 'error');
  673. }
  674. } else {
  675. const errorMsg = [];
  676.  
  677. errorMsg.push('<pre class="SKH_errorMsg">');
  678. errorMsg.push(`sessionID: ${config.get('sessionID') + eol}`);
  679. errorMsg.push(`autoUpdate: ${config.get('autoUpdateSessionID') + eol}`);
  680. errorMsg.push(`status: ${res.status + eol}`);
  681. errorMsg.push(`response: ${res.response + eol}`);
  682. errorMsg.push('</pre>');
  683.  
  684. swal({
  685. title: text.errorTitle,
  686. html: text.errorFailedRequestNeedUpdate + eol + errorMsg.join(''),
  687. type: 'error'
  688. });
  689. getSessionID();
  690. }
  691.  
  692. activating = false;
  693. }
  694. });
  695. }
  696. }
  697. };
  698. const scanInput = (i, input) => {
  699. if (input.type === 'text' && regKey.test(input.value)) {
  700. const $input = $(input);
  701. const key = input.value.trim();
  702.  
  703. if (activated.includes(key)) $input.addClass('SKH_activated');
  704.  
  705. $input.prop('disabled', false);
  706. $input.click(() => {
  707. activateKey(key);
  708. });
  709. }
  710. };
  711. const init = () => {
  712. // save sessionID
  713. if (location.hostname === 'store.steampowered.com') {
  714. if (g_AccountID > 0) {
  715. const currentID = config.get('sessionID');
  716. const sessionID = g_sessionID || '';
  717. const language = g_oSuggestParams.l || 'english';
  718.  
  719. if (!config.get('language')) config.set('language', language);
  720. if (sessionID.length > 0) {
  721. const update = config.get('autoUpdateSessionID') && currentID !== sessionID;
  722.  
  723. if (!currentID || update) {
  724. config.set('sessionID', sessionID, () => {
  725. swal({
  726. title: text.updateSuccessTitle,
  727. text: text.updateSuccess,
  728. type: 'success',
  729. timer: 3000
  730. });
  731. });
  732. }
  733. }
  734. }
  735. /* else {
  736. swal(text.notLoggedInTitle, text.notLoggedInMsg, 'error');
  737. }
  738. */
  739. } else {
  740. // check sessionID
  741. if (!config.get('sessionID')) getSessionID();
  742.  
  743. const host = location.hostname;
  744. let run = true;
  745.  
  746. if (!config.get('enabledForever') && !config.get('enabled').includes(host)) run = false;
  747. if (config.get('disabled').includes(host)) run = false;
  748.  
  749. if (run) {
  750. const markOptions = {
  751. element: 'span',
  752. exclude: ['.SKH_processed'],
  753. each: marked => {
  754. const $marked = $(marked);
  755. const key = $marked.text();
  756.  
  757. // checked if activated before
  758. if (activated.includes(key)) $marked.addClass('SKH_activated');
  759.  
  760. // bind click event
  761. $marked.click(e => {
  762. e.preventDefault();
  763. activateKey(key);
  764. });
  765.  
  766. // append class
  767. $marked.addClass('SKH_processed');
  768. }
  769. };
  770.  
  771. // hide floating panel
  772. if (config.get('hideForever') || config.get('hide').includes(host)) {
  773. GM_addStyle('.SKH_panel { display: none; }');
  774. }
  775.  
  776. // insert floating panel
  777. insertPanel(() => {
  778. // toggle on / off
  779. $('.SKH_panel input').prop('checked', !config.get('off').includes(host));
  780. });
  781.  
  782. // start scanning
  783. $('body').markRegExp(regKey, markOptions);
  784. $('input[type="text"]').each(scanInput);
  785.  
  786. // auto reply activated keys on SteamCN
  787. if (config.get('autoReplyActivated')) {
  788. $(window).on('unload', () => {
  789. if (currentActivated.length > 0) {
  790. $('#vmessage').val(text.activatedReply.replace('%KEYS%', currentActivated.join()));
  791. $('#vreplysubmit').click();
  792. }
  793. });
  794. }
  795.  
  796. // monitor
  797. new MutationObserver(mutations => {
  798. mutations.forEach(mutation => {
  799. // monitor added nodes
  800. Array.from(mutation.addedNodes).forEach(addedNode => {
  801. if (addedNode.nodeType === 1) {
  802. $(addedNode).each(scanInput).markRegExp(regKey, markOptions);
  803. } else if (addedNode.nodeType === 3) {
  804. $(addedNode.parentNode).markRegExp(regKey, markOptions);
  805. }
  806. });
  807.  
  808. // monitor text change
  809. if (mutation.type === 'characterData') {
  810. $(mutation.target.parentNode).markRegExp(regKey, markOptions);
  811. }
  812. });
  813. }).observe(document.body, {
  814. childList: true,
  815. subtree: true,
  816. characterData: true
  817. });
  818. }
  819. }
  820. };
  821.  
  822. $(window).on('load', init);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址