Steam Key Helper

try to take over the world!

当前为 2017-09-09 提交的版本,查看 最新版本

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