Steam Key Helper

try to take over the world!

目前为 2017-09-05 提交的版本。查看 最新版本

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