auto-task-v4

自动完成 Freeanywhere,Giveawaysu,GiveeClub,Givekey,Gleam,Indiedb,keyhub,OpiumPulses,Opquests,SweepWidget 等网站的任务。

当前为 2024-06-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name auto-task-v4
  3. // @namespace auto-task-v4
  4. // @version 4.4.0
  5. // @description 自动完成 Freeanywhere,Giveawaysu,GiveeClub,Givekey,Gleam,Indiedb,keyhub,OpiumPulses,Opquests,SweepWidget 等网站的任务。
  6. // @description:en Automatically complete the tasks of FreeAnyWhere, GiveawaySu, GiveeClub, Givekey, Gleam, Indiedb, keyhub, OpiumPulses, Opquests, SweepWidget websites.
  7. // @author HCLonely
  8. // @license MIT
  9. // @run-at document-start
  10. // @homepage https://auto-task-doc.js.org/
  11. // @supportURL https://github.com/HCLonely/auto-task-v4/issues
  12. // @icon https://auto-task-v4.hclonely.com/favicon.ico
  13.  
  14. // @include *://freeanywhere.net/*
  15. // @include *://giveaway.su/giveaway/view/*
  16. // @include *://givee.club/*/event/*
  17. // @include *://givekey.ru/giveaway/*
  18. // @include *://www.indiedb.com/giveaways*
  19. // @include *://key-hub.eu/giveaway/*
  20. // @include *://keylol.com/*
  21. // @include *://www.opiumpulses.com/giveaways
  22. // @include *://prys.revadike.com/giveaway/?id=*
  23. // @include *://opquests.com/quests/*
  24. // @include *://gleam.io/*
  25. // @include *://sweepwidget.com/view/*
  26. // @include *://discord.com/*
  27. // @include *://www.twitch.tv/*
  28. // @include *://www.youtube.com/*
  29. // @include *://*.reddit.com/*
  30. // @include *://twitter.com/settings/account?k*
  31. // @include *://x.com/settings/account*
  32. // @include https://auto-task-v4.hclonely.com/setting.html
  33. // @include https://auto-task-v4.hclonely.com/history.html
  34.  
  35. // @grant GM_setValue
  36. // @grant GM_getValue
  37. // @grant GM_listValues
  38. // @grant GM_deleteValue
  39. // @grant GM_addStyle
  40. // @grant GM_xmlhttpRequest
  41. // @grant GM_registerMenuCommand
  42. // @grant GM_info
  43. // @grant GM_openInTab
  44. // @grant GM_setClipboard
  45. // @grant GM_getResourceText
  46. // @grant GM_cookie
  47. // @grant unsafeWindow
  48. // @grant window.close
  49. // @grant window.localStorage
  50.  
  51. // @connect cdn.jsdelivr.net
  52. // @connect store.steampowered.com
  53. // @connect steamcommunity.com
  54. // @connect login.steampowered.com
  55. // @connect twitter.com
  56. // @connect x.com
  57. // @connect api.twitter.com
  58. // @connect youtube.com
  59. // @connect www.youtube.com
  60. // @connect facebook.com
  61. // @connect instagram.com
  62. // @connect vk.com
  63. // @connect twitch.tv
  64. // @connect www.twitch.tv
  65. // @connect gql.twitch.tv
  66. // @connect github.com
  67. // @connect discordapp.com
  68. // @connect discord.gg
  69. // @connect discord.com
  70. // @connect www.reddit.com
  71. // @connect oauth.reddit.com
  72. // @connect raw.githubusercontent.com
  73. // @connect t.me
  74. // @connect bit.ly
  75. // @connect giveaway.su
  76. // @connect google.com
  77. // @connect www.vloot.io
  78. // @connect givee.club
  79. // @connect gleam.io
  80. // @connect www.indiedb.com
  81. // @connect key-hub.eu
  82. // @connect opquests.com
  83. // @connect itch.io
  84. // @connect auto-task-v4.hclonely.com
  85. // @connect *
  86. // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js
  87. // @require https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js
  88. // @require https://cdn.jsdelivr.net/npm/regenerator-runtime@0.13.5/runtime.min.js
  89. // @require https://cdn.jsdelivr.net/npm/js-sha1@0.6.0/src/sha1.min.js
  90. // @require https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js
  91. // @resource style https://cdn.jsdelivr.net/npm/sweetalert2@11.3.5/dist/sweetalert2.min.css
  92. // @require https://cdn.jsdelivr.net/npm/keyboardjs@2.6.4/dist/keyboard.min.js
  93. // @require https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js
  94.  
  95. // @noframes
  96. // ==/UserScript==
  97.  
  98. console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
  99.  
  100. (function() {
  101. var __webpack_modules__ = {
  102. 108: function(__unused_webpack_module, exports) {
  103. !function(e, n) {
  104. true ? n(exports) : 0;
  105. }(this, function(e) {
  106. 'use strict';
  107. var t = function() {
  108. return (t = Object.assign || function(e) {
  109. for (var n, o = 1, t = arguments.length; o < t; o++) {
  110. for (var r in n = arguments[o]) {
  111. Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r]);
  112. }
  113. }
  114. return e;
  115. }).apply(this, arguments);
  116. };
  117. function r(e, n, o) {
  118. if (o || 2 === arguments.length) {
  119. for (var t, r = 0, i = n.length; r < i; r++) {
  120. !t && r in n || ((t = t || Array.prototype.slice.call(n, 0, r))[r] = n[r]);
  121. }
  122. }
  123. return e.concat(t || Array.prototype.slice.call(n));
  124. }
  125. function d(e) {
  126. return '[object Object]' === n(e);
  127. }
  128. function l(e, n) {
  129. var o = r(r([], n || [], !0), [ '_' ], !1).join('|');
  130. return e.replace(new RegExp('(('.concat(o, ')[a-z])+'), 'g'), function(e, n) {
  131. return n.replace(new RegExp(o), '').toLocaleUpperCase();
  132. });
  133. }
  134. var n = function(e) {
  135. return Object.prototype.toString.call(e);
  136. };
  137. var o = (i.prototype.init = function() {
  138. try {
  139. this.getSystemName(), this.getBrowserName();
  140. } catch (e) {
  141. console.warn('[UA formatter error] '.concat(e));
  142. }
  143. }, i.prototype.getEngine = function() {
  144. var e = this.agent;
  145. return -1 !== e.indexOf('Trident') ? 'Trident' : -1 !== e.indexOf('Firefox') ? 'Gecko' : -1 !== e.indexOf('Presto') ? 'Presto' : 'WebKit';
  146. }, i.prototype.getSystemName = function() {
  147. var e, n = (this.agent.match(/^[a-z]+\/\d+\.\d+\s?\(([a-z\d\s:;./_-]+)\)/i) || [])[1];
  148. try {
  149. var o = '';
  150. if (/Windows/i.test(n)) {
  151. var t = (n.match(/NT\s(\d+\.\d+)/) || [])[1];
  152. switch (this.info.os = 'Windows', t) {
  153. case '6.3':
  154. o = '8.1';
  155. break;
  156.  
  157. case '6.2':
  158. o = '8';
  159. break;
  160.  
  161. case '6.1':
  162. o = '7';
  163. break;
  164.  
  165. case '5.2':
  166. case '5.1':
  167. o = 'XP';
  168. break;
  169.  
  170. default:
  171. o = t;
  172. }
  173. return this.info.device = 'PC', void (this.info.osVersion = o);
  174. }
  175. if (/^Macintosh/i.test(n)) {
  176. return o = (n.match(/X\s((\d+(_|\.))+\d+)/) || [])[1], this.info.os = 'Macintosh',
  177. this.info.device = 'PC', void (this.info.osVersion = null !== (e = null == o ? void 0 : o.replace(/_/g, '.')) && void 0 !== e ? e : 'Unknown');
  178. }
  179. if (/^iPad/i.test(n)) {
  180. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPad', this.info.device = 'Tablet',
  181. void (this.info.osVersion = o.replace(/_/g, '.'));
  182. }
  183. if (/^iPhone/i.test(n)) {
  184. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPhone', this.info.device = 'Mobile',
  185. void (this.info.osVersion = o.replace(/_/g, '.'));
  186. }
  187. if (-1 !== n.indexOf('Android')) {
  188. var r = (n.match(/Android\s((\d+\.?)+\d?)/) || [])[1];
  189. return this.info.device = 'Mobile', this.info.os = 'Android', void (this.info.osVersion = r);
  190. }
  191. if (/Linux\s[a-z\d_]+/.test(n)) {
  192. return this.info.os = 'Linux', void (this.info.osVersion = 'Unknown');
  193. }
  194. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  195. } catch (e) {
  196. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  197. }
  198. }, i.prototype.getBrowserName = function() {
  199. var e = Object.keys(this.browserNameMap).map(function(e) {
  200. return new RegExp(''.concat(e, '(\\/|\\s)(\\d+\\.)+\\d+'));
  201. }), n = 1 < (n = (this.agent.match(/[a-z\d]+(\/|\s)(\d+\.)+\d+/gi) || []).filter(function(n) {
  202. return -1 !== e.findIndex(function(e) {
  203. return e.test(n);
  204. });
  205. })).length && !/^Safari/.test(n[n.length - 1]) ? n.reverse() : n;
  206. this.info = t(t({}, this.info), this._formatBrowserVersion(n[0]));
  207. }, i.prototype._formatBrowserVersion = function(e) {
  208. var n, o, t, r;
  209. try {
  210. for (var i = null !== (o = null === (n = e.match(/(?<name>[a-z\d]+)(\/|\s)(?<version>(\d+\.)+\d+)/i)) || void 0 === n ? void 0 : n.groups) && void 0 !== o ? o : {}, s = i.name, a = i.version, c = {}, f = 0, u = Object.entries(this.browserNameMap); f < u.length; f++) {
  211. var d = u[f], l = d[0], h = d[1];
  212. if (new RegExp(l).test(s)) {
  213. c = h;
  214. break;
  215. }
  216. }
  217. var p = {
  218. browserVersion: null != a ? a : 'Unknown',
  219. browser: null !== (t = c.en) && void 0 !== t ? t : 'Unknown',
  220. browserZH: null !== (r = (null == c ? void 0 : c.zh) || c.en) && void 0 !== r ? r : 'Unknown'
  221. };
  222. return 'Trident' === s && (p.browserVersion = {
  223. '4.0': 8,
  224. '5.0': 9,
  225. '6.0': 10,
  226. '7.0': 11
  227. }[a]), p;
  228. } catch (e) {
  229. return console.warn('[UA formatter error] '.concat(e)), {
  230. browser: 'Unknown',
  231. browserVersion: 'Unknown'
  232. };
  233. }
  234. }, i);
  235. function i(e) {
  236. this.agent = '', this.info = {
  237. browser: '',
  238. browserZH: '',
  239. browserVersion: '',
  240. os: '',
  241. osVersion: '',
  242. device: 'Unknown',
  243. engine: 'WebKit'
  244. }, this.browserNameMap = {
  245. MicroMessenger: {
  246. en: 'MicroMessenger',
  247. zh: '微信'
  248. },
  249. MetaSr: {
  250. en: 'MetaSr',
  251. zh: '搜狗浏览器'
  252. },
  253. 'QQ(Browser)?': {
  254. en: 'QQBrowser',
  255. zh: 'QQ浏览器'
  256. },
  257. UCBrowser: {
  258. en: 'UCBrowser',
  259. zh: 'UC浏览器'
  260. },
  261. '2345Explorer': {
  262. en: '2345Explorer',
  263. zh: '2345极速浏览器'
  264. },
  265. Mb2345Browser: {
  266. en: 'Mb2345Browser',
  267. zh: '2345手机浏览器'
  268. },
  269. Trident: {
  270. en: 'Internet Explorer'
  271. },
  272. 'Edge?': {
  273. en: 'Edge'
  274. },
  275. OPR: {
  276. en: 'Opera'
  277. },
  278. Vivaldi: {
  279. en: 'Vivaldi'
  280. },
  281. Firefox: {
  282. en: 'Firefox'
  283. },
  284. Chrome: {
  285. en: 'Chrome'
  286. },
  287. Safari: {
  288. en: 'Safari'
  289. }
  290. }, this.agent = e, this.init();
  291. var n = this.info, o = n.browser, e = n.browserVersion, n = n.osVersion;
  292. this.info = t(t({}, this.info), {
  293. engine: this.getEngine(),
  294. browserVersion: 'Safari' === o ? n : e
  295. });
  296. }
  297. function s() {
  298. this.cookies = {}, this.init();
  299. }
  300. var a = new (s.prototype.init = function() {
  301. var o = {};
  302. document.cookie.split(/;\s/).forEach(function(e) {
  303. var n = e.split(/=/), e = n[0], n = n[1];
  304. o[e] = n;
  305. }), this.cookies = o;
  306. }, s.prototype.getItem = function(e) {
  307. return this.cookies[e];
  308. }, s.prototype.getAllItems = function() {
  309. return this.cookies;
  310. }, s.prototype.setItem = function(e, n, o, t, r, i) {
  311. document.cookie = ''.concat(e, '=').concat(n).concat(o ? '; expires='.concat(o) : '').concat(t ? '; path='.concat(t) : '').concat(r ? '; domain='.concat(r) : '').concat(i ? '; secure' : '');
  312. }, s)();
  313. e.countDown = function e(n, o, t, r) {
  314. if (!window) {
  315. throw new Error('window is not defind.');
  316. }
  317. if (0 < n) {
  318. return r && r(), n--, window[o] = window.setTimeout(function() {
  319. e(n, o, t, r);
  320. }, 1e3), function() {
  321. return clearTimeout(window[o]);
  322. };
  323. }
  324. clearTimeout(window[o]), t && t();
  325. }, e.createRandomID = function(e) {
  326. void 0 === e && (e = 12);
  327. for (var n = [], o = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''), t = o.length, r = 0; r < e; r++) {
  328. n.push(o[Math.round(Math.random() * t)]);
  329. }
  330. return n.join('');
  331. }, e.dCookie = a, e.debounce = function(o, t, r) {
  332. var i;
  333. void 0 === t && (t = 0);
  334. var s = r = void 0 === r ? !1 : r;
  335. return function() {
  336. var e = this, n = arguments;
  337. s && (o.apply(this, arguments), s = !1), clearTimeout(i), i = setTimeout(function() {
  338. r ? s = !0 : o.apply(e, n);
  339. }, t);
  340. };
  341. }, e.deepCopy = function e(n) {
  342. if (d(n) || Array.isArray(n)) {
  343. var o, t = Array.isArray(n) ? [] : {};
  344. for (o in n) {
  345. t[o] = e(n[o]);
  346. }
  347. return t;
  348. }
  349. return n;
  350. }, e.formatQueryParams = function(e) {
  351. e = null === (e = /\?(?<params>(.*)=.+)/.exec(decodeURIComponent(e))) || void 0 === e ? void 0 : e.groups;
  352. if (!e) {
  353. return {};
  354. }
  355. for (var n = e.params.split('&'), t = {}, o = 0; o < n.length; o++) {
  356. n[o].replace(/([^?&]*)=([^?&]*)/, function(e, n, o) {
  357. return t[n] = o, e;
  358. });
  359. }
  360. return t;
  361. }, e.formatThousandth = function(e) {
  362. var n = ''.concat(e).split('.'), e = n[0], n = n[1], n = void 0 === n ? '' : n, e = e.replace(/\d{1,3}(?=(\d{3})+$)/g, '$&,');
  363. return ''.concat(e).concat(n ? '.'.concat(n) : '');
  364. }, e.generateTree = function e(n, o, t, r) {
  365. for (var i = [], s = 0; s < n.length; s++) {
  366. var a = n[s];
  367. a[t] === o && (i.push(a), a.children = e(n, a[null != r ? r : 'id'], t, r));
  368. }
  369. return i;
  370. }, e.isEmpty = function(e) {
  371. return Array.isArray(e) ? 0 === e.length : d(e) ? 0 === Object.keys(e).length : [ '[object Set]', '[object Map]' ].includes(n(e)) ? 0 === e.size : [ null, void 0, '' ].includes(e);
  372. }, e.isFunction = function(e) {
  373. return '[object Function]' === n(e);
  374. }, e.isImageUrl = function(e) {
  375. return /\.((png)|(jpe?g)|(gif)|(svg)|(webp))$/gi.test(e);
  376. }, e.isObject = d, e.isRegexp = function(e) {
  377. return '[object RegExp]' === n(e);
  378. }, e.objectKeyToCamelCase = function e(n, o, t) {
  379. if (Array.isArray(n)) {
  380. for (var r = [], i = 0; i < n.length; i++) {
  381. r[i] = e(o && n[i][o] ? n[i][o] : n[i], o, t);
  382. }
  383. } else if (d(n)) {
  384. r = {};
  385. for (var s = o && n[o] ? n[o] : n, a = 0, c = Object.entries(s); a < c.length; a++) {
  386. var f = (u = c[a])[0], u = u[1];
  387. Array.isArray(u) || d(s) ? r[l(f, t)] = e(u, o, t) : r[l(f, t)] = u;
  388. }
  389. } else {
  390. r = n;
  391. }
  392. return r;
  393. }, e.realType = n, e.searchParams = function(e, n) {
  394. return void 0 === e && (e = null === location || void 0 === location ? void 0 : location.search),
  395. new URLSearchParams(e).get(n);
  396. }, e.toLowerCamelCase = l, e.toUnderline = function(e) {
  397. return e.replace(/([A-Z])/g, function(e) {
  398. return '_'.concat(e.toLocaleLowerCase());
  399. });
  400. }, e.ua = function(e) {
  401. return void 0 === e && (e = navigator.userAgent), new o(e).info;
  402. }, Object.defineProperty(e, '__esModule', {
  403. value: !0
  404. });
  405. });
  406. },
  407. 221: function(module, __webpack_exports__, __webpack_require__) {
  408. 'use strict';
  409. __webpack_require__.d(__webpack_exports__, {
  410. Z: function() {
  411. return __WEBPACK_DEFAULT_EXPORT__;
  412. }
  413. });
  414. var _node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(398);
  415. var _node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = __webpack_require__.n(_node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__);
  416. var _node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
  417. var _node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default = __webpack_require__.n(_node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__);
  418. var ___CSS_LOADER_EXPORT___ = _node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default()(_node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default());
  419. ___CSS_LOADER_EXPORT___.push([ module.id, '.colorful-button,#auto-task-buttons a.auto-task-website-btn,.show-button-div a.auto-task-website-btn,body.auto-task-options .auto-task-form table button{position:relative;padding:5px 10px;text-align:center;color:#fff;text-decoration:none;background:linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);border-radius:30px;background-size:400%;text-transform:capitalize}.colorful-button:hover,#auto-task-buttons a.auto-task-website-btn:hover,.show-button-div a.auto-task-website-btn:hover,body.auto-task-options .auto-task-form table button:hover{animation:animate 8s linear infinite;cursor:pointer}.colorful-button:hover::before,#auto-task-buttons a.auto-task-website-btn:hover::before,.show-button-div a.auto-task-website-btn:hover::before,body.auto-task-options .auto-task-form table button:hover::before{filter:blur(10px);opacity:1}.colorful-button::before,#auto-task-buttons a.auto-task-website-btn::before,.show-button-div a.auto-task-website-btn::before,body.auto-task-options .auto-task-form table button::before{content:"";position:absolute;top:-5px;left:-5px;right:-5px;bottom:-5px;z-index:-1;background:linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);border-radius:40px;background-size:400%;opacity:-1;transition:.5s}@keyframes animate{0%{background-position:0%}100%{background-position:100%}}#auto-task-info{position:fixed;bottom:10px;right:10px;width:60%;max-width:500px;max-height:60%;overflow-y:auto;color:#000;background-color:#fff;padding-left:5px;z-index:999999999 !important;border:solid 2px #add8e6;border-radius:10px}#auto-task-info li{text-align:left}#auto-task-info li a.high-light{color:#00aeff;font-weight:bold}#auto-task-info .success{color:green}#auto-task-info .error{color:red}#auto-task-info .warning{color:blue}#auto-task-info .info{color:#ff0}#auto-task-info .update-text{color:green;border:solid 2px #8dcb69;margin:5px 10px 5px 20px;border-radius:10px;padding:5px 20px}.auto-task-keylol{display:inline-block;text-transform:capitalize;margin-left:10px;text-decoration:none !important;border:solid 1px;border-radius:5px;padding:0 2px}.auto-task-keylol[selected=selected]{background-color:blue !important;color:#fff !important}.auto-task-form table{font-family:verdana,arial,sans-serif;font-size:11px;color:#333;border-width:1px;border-color:#999;border-collapse:collapse;width:100%}.auto-task-form table thead td{border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9;font-weight:bold;background-color:#fff}.auto-task-form table tbody tr{background-color:#d4e3e5}.auto-task-form table tbody tr:hover{background-color:#ff6 !important}.auto-task-form table tbody tr th{background-color:#c3dde0;border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9;text-transform:capitalize}.auto-task-form table tbody tr td{border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9}.swal2-modal{width:70% !important;max-width:1000px !important}body.auto-task-options{padding-top:10px;text-align:center}body.auto-task-options .auto-task-form{width:80%;max-width:1000px;margin:0 auto;padding-bottom:20px}body.auto-task-options .auto-task-form table input.editOption{width:80%}body.auto-task-options .auto-task-form table #getTwitterUserId,body.auto-task-options .auto-task-form table #getYoutubeChannelId{margin-top:5px}body.auto-task-options .auto-task-form table button{z-index:1}body.auto-task-options .auto-task-form table input[type=text]{outline-style:none;border:1px solid #ccc;border-radius:3px;padding:5px 10px;font-size:14px}body.auto-task-options .auto-task-form table input[type=text]:focus{border-color:#66afe9;outline:0;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}body.auto-task-options .auto-task-form table label{position:relative;width:160px;height:80px;cursor:pointer;transform:scale(0.25);margin:-25% 0;top:-30px;display:inline-block}body.auto-task-options .auto-task-form table label input{position:relative;z-index:1;appearance:none}body.auto-task-options .auto-task-form table label input:checked~span{background:#05be05;box-shadow:0 15px 25px #05be0566}body.auto-task-options .auto-task-form table label input:checked~span i{left:84px}body.auto-task-options .auto-task-form table label input:checked~span i::before{background:#05be05;box-shadow:35px 0 0 #05be05}body.auto-task-options .auto-task-form table label input:checked~span i::after{bottom:12px;height:15px;border-bottom-left-radius:15px;border-bottom-right-radius:15px;background:#05be05}body.auto-task-options .auto-task-form table label span{position:absolute;top:0;left:0;width:100%;height:100%;background:#fe0000;border-radius:80px;transition:.5s;box-shadow:0 15px 25px #fe000066}body.auto-task-options .auto-task-form table label span i{position:absolute;top:4px;left:4px;width:72px;height:72px;background:#fff;border-radius:50%}body.auto-task-options .auto-task-form table label span i::before{content:"";position:absolute;top:22px;left:12px;width:12px;height:12px;border-radius:50%;background:#fe0000;box-shadow:35px 0 0 #fe0000;transition:.5s}body.auto-task-options .auto-task-form table label span i::after{content:"";position:absolute;bottom:15px;left:calc(50% - 15px);width:30px;height:6px;border-radius:6px;background:#fe0000;transition:.5s}body.auto-task-history{font-size:15px;font-weight:400;line-height:1.5}body.auto-task-history .container a{color:#007bff;text-decoration:none;background-color:transparent}body.auto-task-history .container .card{width:80%;max-width:800px;border-radius:10px;background:#7676761a;border-top:1px solid #ffffff80;-webkit-backdrop-filter:blur(20px);backdrop-filter:blur(20px);box-shadow:0 15px 25px #0000001a;margin:20px auto;position:relative;display:flex;flex-direction:column;word-wrap:break-word;-webkit-background-clip:border-box;background-clip:border-box;border:1px solid rgba(0,0,0,.125);border-radius:.25rem}body.auto-task-history .container .card .title{text-align:center;font-size:30px;font-weight:bold;margin:5px 0}body.auto-task-history .container .card .title a:hover{text-decoration:none;background:#93e1ff;border-radius:10px;padding:3px}body.auto-task-history .container .card ul{margin-bottom:25px}body.auto-task-history .container .card ul li{margin-bottom:5px;line-height:20px}body.auto-task-history .container .card ul a:hover{text-decoration:underline}body.auto-task-history .container .card .delete-task{right:10px;width:38px;height:35px;position:absolute;font-size:24px;cursor:pointer;border-radius:10px}body.auto-task-history .container .card .delete-task:hover{background:#fff}body.auto-task-history .container .card .time{right:5px;position:absolute;bottom:0;color:#e83e8c;font-family:\'SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace\';font-size:15px}#auto-task-buttons,.show-button-div{position:fixed;top:30px;right:15px;width:170px;z-index:999999999 !important;transform:scale(0.9)}#auto-task-buttons p,.show-button-div p{line-height:30px;height:40px;text-align:center;margin:5px !important}#auto-task-buttons a.auto-task-website-btn,.show-button-div a.auto-task-website-btn{width:150px;height:40px;line-height:30px;font-size:20px}.show-button-div{width:20px}.auto-task-capitalize{text-transform:capitalize !important}.swal2-file:focus,.swal2-input:focus,.swal2-textarea:focus{box-shadow:inset 0px 0px 4px 1px rgba(100,150,200,.5) !important}.swal2-checkbox-custom{align-items:center;justify-content:center;background:#fff;color:inherit;margin:1em auto}.swal2-checkbox-custom input{flex-shrink:0;margin:0 .4em}.giveaway-actions #getKey{display:none !important}.auto-task-giveaway-status{color:#fff;border-radius:10px;padding:0 5px;margin-left:5px}.auto-task-giveaway-status.active{background-color:#5cb85c}.auto-task-giveaway-status.not-active{background-color:#d9534f}', '' ]);
  420. const __WEBPACK_DEFAULT_EXPORT__ = ___CSS_LOADER_EXPORT___.toString();
  421. },
  422. 1: function(module) {
  423. 'use strict';
  424. module.exports = function(cssWithMappingToString) {
  425. var list = [];
  426. list.toString = function toString() {
  427. return this.map(function(item) {
  428. var content = '';
  429. var needLayer = typeof item[5] !== 'undefined';
  430. if (item[4]) {
  431. content += '@supports ('.concat(item[4], ') {');
  432. }
  433. if (item[2]) {
  434. content += '@media '.concat(item[2], ' {');
  435. }
  436. if (needLayer) {
  437. content += '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {');
  438. }
  439. content += cssWithMappingToString(item);
  440. if (needLayer) {
  441. content += '}';
  442. }
  443. if (item[2]) {
  444. content += '}';
  445. }
  446. if (item[4]) {
  447. content += '}';
  448. }
  449. return content;
  450. }).join('');
  451. };
  452. list.i = function i(modules, media, dedupe, supports, layer) {
  453. if (typeof modules === 'string') {
  454. modules = [ [ null, modules, undefined ] ];
  455. }
  456. var alreadyImportedModules = {};
  457. if (dedupe) {
  458. for (var k = 0; k < this.length; k++) {
  459. var id = this[k][0];
  460. if (id != null) {
  461. alreadyImportedModules[id] = true;
  462. }
  463. }
  464. }
  465. for (var _k = 0; _k < modules.length; _k++) {
  466. var item = [].concat(modules[_k]);
  467. if (dedupe && alreadyImportedModules[item[0]]) {
  468. continue;
  469. }
  470. if (typeof layer !== 'undefined') {
  471. if (typeof item[5] === 'undefined') {
  472. item[5] = layer;
  473. } else {
  474. item[1] = '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {').concat(item[1], '}');
  475. item[5] = layer;
  476. }
  477. }
  478. if (media) {
  479. if (!item[2]) {
  480. item[2] = media;
  481. } else {
  482. item[1] = '@media '.concat(item[2], ' {').concat(item[1], '}');
  483. item[2] = media;
  484. }
  485. }
  486. if (supports) {
  487. if (!item[4]) {
  488. item[4] = ''.concat(supports);
  489. } else {
  490. item[1] = '@supports ('.concat(item[4], ') {').concat(item[1], '}');
  491. item[4] = supports;
  492. }
  493. }
  494. list.push(item);
  495. }
  496. };
  497. return list;
  498. };
  499. },
  500. 398: function(module) {
  501. 'use strict';
  502. module.exports = function(i) {
  503. return i[1];
  504. };
  505. }
  506. };
  507. var __webpack_module_cache__ = {};
  508. function __webpack_require__(moduleId) {
  509. var cachedModule = __webpack_module_cache__[moduleId];
  510. if (cachedModule !== undefined) {
  511. return cachedModule.exports;
  512. }
  513. var module = __webpack_module_cache__[moduleId] = {
  514. id: moduleId,
  515. exports: {}
  516. };
  517. __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  518. return module.exports;
  519. }
  520. !function() {
  521. __webpack_require__.n = function(module) {
  522. var getter = module && module.__esModule ? function() {
  523. return module['default'];
  524. } : function() {
  525. return module;
  526. };
  527. __webpack_require__.d(getter, {
  528. a: getter
  529. });
  530. return getter;
  531. };
  532. }();
  533. !function() {
  534. __webpack_require__.d = function(exports, definition) {
  535. for (var key in definition) {
  536. if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  537. Object.defineProperty(exports, key, {
  538. enumerable: true,
  539. get: definition[key]
  540. });
  541. }
  542. }
  543. };
  544. }();
  545. !function() {
  546. __webpack_require__.o = function(obj, prop) {
  547. return Object.prototype.hasOwnProperty.call(obj, prop);
  548. };
  549. }();
  550. var __webpack_exports__ = {};
  551. !function() {
  552. 'use strict';
  553. const external_Swal_namespaceObject = Swal;
  554. var external_Swal_default = __webpack_require__.n(external_Swal_namespaceObject);
  555. const external_Cookies_namespaceObject = Cookies;
  556. var auto_task = __webpack_require__(221);
  557. var javascript_utils_umd_min = __webpack_require__(108);
  558. const httpRequest = async (options, times = 0) => {
  559. if (window.TRACE) {
  560. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  561. }
  562. try {
  563. const result = await new Promise(resolve => {
  564. if (options.dataType) {
  565. options.responseType = options.dataType;
  566. }
  567. const requestObj = {
  568. ...{
  569. timeout: 3e4,
  570. ontimeout(data) {
  571. resolve({
  572. result: 'Error',
  573. statusText: 'Timeout',
  574. status: 601,
  575. data: data,
  576. options: options
  577. });
  578. },
  579. onabort(data) {
  580. resolve({
  581. result: 'Error',
  582. statusText: 'Aborted',
  583. status: 602,
  584. data: data,
  585. options: options
  586. });
  587. },
  588. onerror(data) {
  589. resolve({
  590. result: 'Error',
  591. statusText: 'Error',
  592. status: 603,
  593. data: data,
  594. options: options
  595. });
  596. },
  597. onload(data) {
  598. if (options.responseType === 'json' && data?.response && typeof data.response !== 'object') {
  599. try {
  600. data.response = JSON.parse(data.responseText);
  601. } catch (error) {}
  602. }
  603. resolve({
  604. result: 'Success',
  605. statusText: 'Load',
  606. status: 600,
  607. data: data,
  608. options: options
  609. });
  610. }
  611. },
  612. ...options
  613. };
  614. GM_xmlhttpRequest(requestObj);
  615. });
  616. if (window.DEBUG) {
  617. console.log('%cAuto-Task[httpRequest]:', 'color:blue', JSON.stringify(result));
  618. }
  619. if (result.status !== 600 && times < 2) {
  620. return await httpRequest(options, times + 1);
  621. }
  622. return result;
  623. } catch (error) {
  624. console.log('%cAuto-Task[httpRequest]:', 'color:red', JSON.stringify({
  625. errorMsg: error,
  626. options: options
  627. }));
  628. throwError(error, 'httpRequest');
  629. return {
  630. result: 'JsError',
  631. statusText: 'Error',
  632. status: 604,
  633. error: error,
  634. options: options
  635. };
  636. }
  637. };
  638. const tools_httpRequest = httpRequest;
  639. const echoLog = ({
  640. type,
  641. text,
  642. html,
  643. id
  644. }) => {
  645. const emptyStatus = {
  646. success: () => emptyStatus,
  647. error: () => emptyStatus,
  648. warning: () => emptyStatus,
  649. info: () => emptyStatus,
  650. view: () => emptyStatus
  651. };
  652. try {
  653. let ele;
  654. if (type) {
  655. switch (type) {
  656. case 'joiningSteamGroup':
  657. case 'leavingSteamGroup':
  658. case 'gettingSteamGroupId':
  659. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/groups/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  660. break;
  661.  
  662. case 'joiningSteamOfficialGroup':
  663. case 'leavingSteamOfficialGroup':
  664. case 'gettingSteamOfficialGroupId':
  665. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/games/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  666. break;
  667.  
  668. case 'subscribingForum':
  669. case 'unsubscribingForum':
  670. case 'gettingForumId':
  671. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/app/${text}/discussions/" target="_blank">${text}</a>]...<font></font></li>`);
  672. break;
  673.  
  674. case 'followingCurator':
  675. case 'unfollowingCurator':
  676. case 'gettingCuratorId':
  677. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/${text?.includes('/') ? text : `curator/${text}`}" target="_blank">${text}</a>]...<font></font></li>`);
  678. break;
  679.  
  680. case 'addingToWishlist':
  681. case 'removingFromWishlist':
  682. case 'followingGame':
  683. case 'unfollowingGame':
  684. case 'gettingSubid':
  685. case 'addingFreeLicense':
  686. case 'requestingPlayTestAccess':
  687. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/app/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  688. break;
  689.  
  690. case 'addingFreeLicenseSubid':
  691. ele = $(`<li>${i18n('addingFreeLicense')}[<a href="https://steamdb.info/sub/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  692. break;
  693.  
  694. case 'favoritingWorkshop':
  695. case 'unfavoritingWorkshop':
  696. case 'gettingWorkshopAppId':
  697. case 'votingUpWorkshop':
  698. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/sharedfiles/filedetails/?id=${text}" target="_blank">
  699. ${text}</a>]...<font></font></li>`);
  700. break;
  701.  
  702. case 'gettingAnnouncementParams':
  703. case 'likingAnnouncement':
  704. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/news/app/${text}/view/${id}" target="_blank">
  705. ${id}</a>]...<font></font></li>`);
  706. break;
  707.  
  708. case 'joiningDiscordServer':
  709. case 'gettingDiscordGuild':
  710. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/invite/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  711. break;
  712.  
  713. case 'leavingDiscordServer':
  714. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/channels/@me/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  715. break;
  716.  
  717. case 'updateDiscordAuth':
  718. ele = $(`<li style="color:red;">${i18n('updateDiscordAuth')}</li>`);
  719. break;
  720.  
  721. case 'followingTwitchChannel':
  722. case 'unfollowingTwitchChannel':
  723. case 'gettingTwitchChannelId':
  724. ele = $(`<li>${i18n(type)}[<a href="https://www.twitch.tv/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  725. break;
  726.  
  727. case 'gettingInsUserId':
  728. case 'followingIns':
  729. case 'unfollowingIns':
  730. ele = $(`<li>${i18n(type)}[<a href="https://www.instagram.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  731. break;
  732.  
  733. case 'gettingTwitterUserId':
  734. case 'followingTwitterUser':
  735. case 'unfollowingTwitterUser':
  736. ele = $(`<li>${i18n(type)}[<a href="https://x.com/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  737. break;
  738.  
  739. case 'retweetting':
  740. case 'unretweetting':
  741. ele = $(`<li>${i18n(type)}${text}...<font></font></li>`);
  742. break;
  743.  
  744. case 'joiningReddit':
  745. case 'leavingReddit':
  746. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/r/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  747. break;
  748.  
  749. case 'followingRedditUser':
  750. case 'unfollowingRedditUser':
  751. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/user/${text?.replace('u_', '')}" target="_blank">
  752. ${text?.replace('u_', '')}</a>]...<font></font></li>`);
  753. break;
  754.  
  755. case 'followingYtbChannel':
  756. case 'unfollowingYtbChannel':
  757. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/channel/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  758. break;
  759.  
  760. case 'likingYtbVideo':
  761. case 'unlikingYtbVideo':
  762. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/watch?v=${text}" target="_blank">${text}</a>]...<font></font></li>`);
  763. break;
  764.  
  765. case 'gettingVkId':
  766. case 'joiningVkGroup':
  767. case 'leavingVkGroup':
  768. case 'joiningVkPublic':
  769. case 'leavingVkPublic':
  770. case 'sendingVkWall':
  771. case 'deletingVkWall':
  772. ele = $(`<li>${i18n(type)}[<a href="https://vk.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  773. break;
  774.  
  775. case 'visitingLink':
  776. ele = $(`<li>${i18n('visitingLink')}[<a href="${text}" target="_blank">${text}</a>]...<font></font></li>`);
  777. break;
  778.  
  779. case 'verifyingInsAuth':
  780. case 'text':
  781. ele = $(`<li>${i18n(text)}<font></font></li>`);
  782. break;
  783.  
  784. case 'html':
  785. ele = $(text || html);
  786. break;
  787.  
  788. case 'whiteList':
  789. ele = $(`<li><font class="warning">${i18n('skipTask')}[${text}(${id})](${i18n('whiteList')})</font></li>`);
  790. break;
  791.  
  792. case 'globalOptionsSkip':
  793. ele = $(`<li>${i18n('skipTaskOption')}<font class="warning">${text}</font></li>`);
  794. break;
  795.  
  796. default:
  797. ele = $(`<li>${i18n('unKnown')}:${type}(${text})...<font></font></li>`);
  798. break;
  799. }
  800. } else if (text) {
  801. ele = $(`<li>${i18n(text)}<font></font></li>`);
  802. } else if (html) {
  803. ele = $(html);
  804. } else {
  805. ele = $('<li><font></font></li>');
  806. }
  807. ele.addClass('card-text');
  808. $('#auto-task-info').append(ele);
  809. ele[0]?.scrollIntoView();
  810. const font = ele.find('font');
  811. const status = {
  812. font: font,
  813. success(text = 'Success', html = false) {
  814. this.font?.attr('class', '').addClass('success');
  815. html ? this.font?.html(text) : this.font?.text(text);
  816. return this;
  817. },
  818. error(text = 'Error', html = false) {
  819. this.font?.attr('class', '').addClass('error');
  820. html ? this.font?.html(text) : this.font?.text(text);
  821. return this;
  822. },
  823. warning(text = 'Warning', html = false) {
  824. this.font?.attr('class', '').addClass('warning');
  825. html ? this.font?.html(text) : this.font?.text(text);
  826. return this;
  827. },
  828. info(text = 'Info', html = false) {
  829. this.font?.attr('class', '').addClass('info');
  830. html ? this.font?.html(text) : this.font?.text(text);
  831. return this;
  832. },
  833. view() {
  834. this.font?.[0].scrollIntoView();
  835. return this;
  836. }
  837. };
  838. return status;
  839. } catch (error) {
  840. throwError(error, 'echoLog');
  841. return emptyStatus;
  842. }
  843. };
  844. const scripts_echoLog = echoLog;
  845. const unique = array => {
  846. try {
  847. return [ ...new Set(array) ];
  848. } catch (error) {
  849. throwError(error, 'unique');
  850. return [];
  851. }
  852. };
  853. const delay = (time = 1e3) => new Promise(resolve => {
  854. setTimeout(() => {
  855. resolve(true);
  856. }, time);
  857. });
  858. const getRedirectLink = async link => {
  859. try {
  860. if (!link) {
  861. return null;
  862. }
  863. const redirectLinksCache = GM_getValue('redirectLinks') || {};
  864. if (redirectLinksCache[link]) {
  865. redirectLinksCache[link];
  866. }
  867. return await tools_httpRequest({
  868. url: link,
  869. method: 'GET'
  870. }).then(({
  871. data
  872. }) => {
  873. if (data?.finalUrl) {
  874. redirectLinksCache[link] = data.finalUrl;
  875. GM_setValue('redirectLinks', redirectLinksCache);
  876. return data.finalUrl;
  877. }
  878. return null;
  879. });
  880. } catch (error) {
  881. throwError(error, 'getRedirectLink');
  882. return null;
  883. }
  884. };
  885. const visitLink = async (link, options) => {
  886. try {
  887. const logStatus = scripts_echoLog({
  888. type: 'visitLink',
  889. text: link
  890. });
  891. return await tools_httpRequest({
  892. url: link,
  893. method: 'GET',
  894. ...options
  895. }).then(({
  896. result,
  897. statusText,
  898. status
  899. }) => {
  900. if (result === 'Success') {
  901. logStatus.success();
  902. return true;
  903. }
  904. logStatus.error(`${result}:${statusText}(${status})`);
  905. return false;
  906. });
  907. } catch (error) {
  908. throwError(error, 'visitLink');
  909. return false;
  910. }
  911. };
  912. const getUrlQuery = url => {
  913. try {
  914. const query = {};
  915. if (url) {
  916. if (url.includes('?')) {
  917. url.split('?')[1].replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  918. query[key] = value;
  919. return str;
  920. });
  921. }
  922. } else {
  923. window.location.search.replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  924. query[key] = value;
  925. return str;
  926. });
  927. }
  928. return query;
  929. } catch (error) {
  930. throwError(error, 'getUrlQuery');
  931. return {};
  932. }
  933. };
  934. const getUuid = () => {
  935. const uuidUrl = URL.createObjectURL(new Blob()).toString();
  936. return uuidUrl.slice(uuidUrl.lastIndexOf('/') + 1);
  937. };
  938. const stringToColour = str => {
  939. try {
  940. let hash = 0;
  941. for (let i = 0; i < str.length; i++) {
  942. hash = str.charCodeAt(i) + ((hash << 5) - hash);
  943. }
  944. let colour = '#';
  945. for (let i = 0; i < 3; i++) {
  946. const value = hash >> i * 8 & 255;
  947. colour += `00${value.toString(16)}`.slice(-2);
  948. }
  949. return colour;
  950. } catch (error) {
  951. throwError(error, 'stringToColour');
  952. return '#fff';
  953. }
  954. };
  955. const defaultGlobalOptions = {
  956. doTask: {
  957. discord: {
  958. servers: true
  959. },
  960. instagram: {
  961. users: true
  962. },
  963. twitch: {
  964. channels: true
  965. },
  966. twitter: {
  967. users: true,
  968. retweets: true
  969. },
  970. vk: {
  971. names: true
  972. },
  973. youtube: {
  974. channels: true,
  975. likes: true
  976. },
  977. reddit: {
  978. reddits: true
  979. },
  980. steam: {
  981. groups: true,
  982. officialGroups: true,
  983. wishlists: true,
  984. follows: true,
  985. forums: true,
  986. workshops: true,
  987. curators: true,
  988. workshopVotes: true,
  989. announcements: true,
  990. licenses: true,
  991. playtests: true
  992. }
  993. },
  994. undoTask: {
  995. discord: {
  996. servers: true
  997. },
  998. instagram: {
  999. users: true
  1000. },
  1001. twitch: {
  1002. channels: true
  1003. },
  1004. twitter: {
  1005. users: true,
  1006. retweets: true
  1007. },
  1008. vk: {
  1009. names: true
  1010. },
  1011. youtube: {
  1012. channels: true,
  1013. likes: true
  1014. },
  1015. reddit: {
  1016. reddits: true
  1017. },
  1018. steam: {
  1019. groups: true,
  1020. officialGroups: true,
  1021. wishlists: true,
  1022. follows: true,
  1023. forums: true,
  1024. workshops: true,
  1025. curators: true
  1026. }
  1027. },
  1028. ASF: {
  1029. AsfEnabled: false,
  1030. AsfIpcUrl: '',
  1031. AsfIpcPassword: '',
  1032. AsfBotname: 'asf'
  1033. },
  1034. position: {
  1035. buttonSideX: 'right',
  1036. buttonSideY: 'top',
  1037. buttonDistance: '15,30',
  1038. showButtonSideX: 'right',
  1039. showButtonSideY: 'top',
  1040. showButtonDistance: '15,30',
  1041. logSideX: 'right',
  1042. logSideY: 'bottom',
  1043. logDistance: '10,10'
  1044. },
  1045. hotKey: {
  1046. doTaskKey: 'alt + d',
  1047. undoTaskKey: 'alt + u',
  1048. toggleLogKey: 'alt + l'
  1049. },
  1050. other: {
  1051. twitterVerifyId: '783214',
  1052. youtubeVerifyChannel: 'UCrXUsMBcfTVqwAS7DKg9C0Q',
  1053. autoUpdateSource: 'jsdelivr',
  1054. language: 'zh',
  1055. checkLogin: true,
  1056. checkLeftKey: true,
  1057. defaultShowButton: true,
  1058. defaultShowLog: true,
  1059. debug: false,
  1060. receivePreview: true
  1061. }
  1062. };
  1063. const userDefinedGlobalOptions = GM_getValue('globalOptions') || {};
  1064. const assignObject = (obj1, obj2) => {
  1065. try {
  1066. const newObj = {};
  1067. for (const [ key, value ] of Object.entries(obj1)) {
  1068. if (Object.prototype.toString.call(value) === '[object Object]' && Object.prototype.toString.call(obj2[key]) === '[object Object]') {
  1069. newObj[key] = assignObject(value, obj2[key]);
  1070. } else {
  1071. newObj[key] = obj2[key] ?? value;
  1072. }
  1073. }
  1074. return newObj;
  1075. } catch (error) {
  1076. throwError(error, 'assignObject');
  1077. return defaultGlobalOptions;
  1078. }
  1079. };
  1080. const globalOptions = assignObject(defaultGlobalOptions, userDefinedGlobalOptions);
  1081. const saveData = () => {
  1082. try {
  1083. const data = {};
  1084. $('#globalOptionsForm').serializeArray().map(value => {
  1085. data[value.name] = value.value;
  1086. return value;
  1087. });
  1088. $.makeArray($('#globalOptionsForm input')).map(element => {
  1089. const name = $(element).attr('name');
  1090. const keys = name.split('.');
  1091. if (keys.length === 3) {
  1092. globalOptions[keys[0]][keys[1]][keys[2]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1093. } else if (keys.length === 2) {
  1094. globalOptions[keys[0]][keys[1]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1095. }
  1096. return element;
  1097. });
  1098. GM_setValue('globalOptions', globalOptions);
  1099. external_Swal_default().fire({
  1100. title: i18n('changeGlobalOptionsSuccess'),
  1101. icon: 'success'
  1102. });
  1103. } catch (error) {
  1104. throwError(error, 'saveData');
  1105. }
  1106. };
  1107. const changeGlobalOptions = showType => {
  1108. try {
  1109. let globalOptionsForm = `<form id="globalOptionsForm" class="auto-task-form">
  1110. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  1111. for (const [ type, data1 ] of Object.entries(globalOptions)) {
  1112. for (const [ option, data2 ] of Object.entries(data1)) {
  1113. if ([ 'other', 'position', 'hotKey', 'ASF' ].includes(type)) {
  1114. if (typeof data2 === 'boolean') {
  1115. globalOptionsForm += `<tr style="background-color: ${stringToColour(type)}44">${Object.keys(data1).indexOf(option) === 0 ? `<th rowspan="${Object.keys(data1).length}">${i18n(type)}</th>` : ''}<td>${i18n(option)}</td><td><label><input type="checkbox" name="${type}.${option}"${data2 ? ' checked="checked"' : ''}/><span><i></i></span></label></td></tr>`;
  1116. } else {
  1117. globalOptionsForm += `<tr style="background-color: ${stringToColour(type)}44">${Object.keys(data1).indexOf(option) === 0 ? `<th rowspan="${Object.keys(data1).length}" style="background-color: ${stringToColour(type)}66">${i18n(type)}</th>` : ''}<td>${i18n(option)}</td><td><input class="editOption" type="text" name="${type}.${option}" value="${data2}"/></td></tr>`;
  1118. }
  1119. } else {
  1120. for (const [ socialType, data3 ] of Object.entries(data2)) {
  1121. globalOptionsForm += `<tr style="background-color: ${stringToColour(option)}66">${Object.keys(data1).indexOf(option) === 0 ? `<th rowspan="${Object.keys(data1).map(key => Object.keys(data1[key]).length).reduce((acr, cur) => acr + cur)}" style="background-color: ${stringToColour(type)}66">${i18n(type)}</th>` : ''}<td>${option}.${i18n(socialType)}</td><td><label><input type="checkbox" name="${type}.${option}.${socialType}"${data3 ? ' checked="checked"' : ''}/><span><i></i></span></label></td></tr>`;
  1122. }
  1123. }
  1124. }
  1125. }
  1126. globalOptionsForm += '</tbody></table></form>';
  1127. if (showType === 'swal') {
  1128. external_Swal_default().fire({
  1129. title: i18n('globalOptions'),
  1130. html: globalOptionsForm,
  1131. showConfirmButton: true,
  1132. confirmButtonText: i18n('save'),
  1133. showCancelButton: true,
  1134. cancelButtonText: i18n('close')
  1135. }).then(({
  1136. isConfirmed
  1137. }) => {
  1138. if (isConfirmed) {
  1139. saveData();
  1140. }
  1141. });
  1142. } else {
  1143. $('body').append(`<h2>${i18n('globalOptions')}</h2>${globalOptionsForm}`);
  1144. }
  1145. } catch (error) {
  1146. throwError(error, 'changeGlobalOptions');
  1147. }
  1148. };
  1149. const data = {
  1150. website: '网站',
  1151. type: '类型',
  1152. edit: '编辑',
  1153. whiteList: '白名单',
  1154. skipTask: '跳过撤销任务',
  1155. whiteListOptions: '白名单设置',
  1156. changeWhiteListOption: '设置白名单(%0)',
  1157. whiteListNotFound: '找不到此项白名单: %0',
  1158. changeWhiteListSuccess: '白名单修改成功,刷新生效!',
  1159. changeWebsiteOptions: '网站设置',
  1160. changeGlobalOptions: '全局设置',
  1161. ok: '是',
  1162. save: '保存',
  1163. close: '关闭',
  1164. return: '返回',
  1165. option: '选项',
  1166. value: '值',
  1167. websiteOptions: '当前网站设置',
  1168. changeWebsiteOptionsSuccess: '更改当前网站设置成功,刷新生效!',
  1169. changeGlobalOptionsSuccess: '更改全局设置成功,刷新生效!',
  1170. needLogin: '请先登录!',
  1171. getTasksInfo: '正在获取并处理任务信息...',
  1172. gettingKey: '正在获取Key...',
  1173. verifyingTask: '正在验证任务',
  1174. notice: '自动任务脚本提醒',
  1175. noKeysLeft: '此页面已经没有剩余key了,是否关闭?',
  1176. giveawayEnded: '此活动已结束,是否关闭?',
  1177. giveawayNotWork: '此活动因某些原因(已结束/暂停/未开始...)不可用(如果是脚本误判请及时反馈),是否关闭?',
  1178. confirm: '确定',
  1179. cancel: '取消',
  1180. unKnown: '未知',
  1181. unKnownTaskType: '未识别的任务',
  1182. doing: '正在做任务',
  1183. allTasksComplete: '所有任务已完成!',
  1184. getTaskIdFailed: '获取任务Id失败!',
  1185. initSuccess: '%0 初始化成功!',
  1186. initFailed: '%0 初始化失败!',
  1187. errorLink: '链接错误: %0',
  1188. needInit: '请先初始化',
  1189. verifyingAuth: '正在验证%0凭证...',
  1190. updatingAuth: '正在更新%0凭证...',
  1191. refreshingToken: '正在刷新%0凭证...',
  1192. settingToken: '正在设置%0凭证...',
  1193. initing: '正在初始化...',
  1194. getFailed: '获取%0失败!',
  1195. checkLoginFailed: '检测登录状态失败!',
  1196. checkLeftKeyFailed: '检测剩余Key失败!',
  1197. userId: '用户Id',
  1198. joiningGiveaway: '正在加入赠Key',
  1199. needJoinGiveaway: '需要先加入赠Key',
  1200. cannotUndo: '此网站不支持取消任务',
  1201. verifyAuth: '正在验证 %0 凭证...',
  1202. closePageNotice: '如果此页面没有自动关闭,请自行关闭本页面。',
  1203. errorReport: '检测到脚本报错,是否前往反馈BUG?',
  1204. visitingLink: '正在访问链接: ',
  1205. doTask: '做任务',
  1206. undoTask: '撤销任务',
  1207. verifyTask: '验证任务',
  1208. getKey: '获取Key',
  1209. selectAll: '全选',
  1210. selectNone: '全不选',
  1211. invertSelect: '反选',
  1212. doFreeTask: '加入免费赠品',
  1213. doPointTask: '加入点数赠品',
  1214. skipTaskOption: '设置中已配置跳过任务',
  1215. other: '其他',
  1216. globalOptions: '全局设置',
  1217. checkLogin: '登录检测</br>需要登录的网站自动登录,部分本网站支持',
  1218. checkLeftKey: '剩余Key检测</br>赠Key活动结束提示是否关闭,部分本网站支持',
  1219. twitterVerifyId: '通过尝试关注该账号验证Twitter凭证</br>默认为Twitter官方帐号 783214</br>不想关注官方账号可以改为自己的帐号',
  1220. youtubeVerifyChannel: '通过尝试订阅该频道验证YouTube凭证</br>默认为YouTube官方频道 UCrXUsMBcfTVqwAS7DKg9C0Q</br>不想关注官方频道可以改为自己的频道',
  1221. autoUpdateSource: '更新源</br>github: 需代理,实时更新</br>jsdelivr: 可不用代理,更新有延迟</br>standby: 备用</br>auto: 依次使用github, jsdelivr, standby源进行尝试更新',
  1222. saveGlobalOptions: '保存全局设置',
  1223. settingPage: '设置页面',
  1224. name: '名称',
  1225. version: '版本',
  1226. scriptManager: '脚本管理器',
  1227. script: '脚本',
  1228. environment: '环境',
  1229. os: '系统',
  1230. browser: '浏览器',
  1231. getId: '获取 %0 id',
  1232. getTwitterUserId: '获取Twitter用户id(获取id功能仅在设置页面可用)',
  1233. getYoutubeChannelId: '获取Youtube频道id(获取id功能仅在设置页面可用)',
  1234. showButton: '显示按钮',
  1235. hideButton: '隐藏按钮',
  1236. showLog: '显示日志',
  1237. hideLog: '隐藏日志',
  1238. defaultShowButton: '默认显示按钮',
  1239. defaultShowLog: '默认显示日志',
  1240. debug: '输出调试日志,不要开启此选项!',
  1241. receivePreview: '接收预览版更新',
  1242. position: '组件位置',
  1243. buttonSideX: '按钮区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1244. buttonSideY: '按钮区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1245. buttonDistance: '按钮区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1246. showButtonSideX: '显示按钮水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1247. showButtonSideY: '显示按钮垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1248. showButtonDistance: '显示按钮距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1249. logSideX: '日志区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1250. logSideY: '日志区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1251. logDistance: '日志区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1252. hotKey: '快捷键',
  1253. doTaskKey: '做任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1254. undoTaskKey: '撤销任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1255. toggleLogKey: '显示/隐藏日志快捷键</br>(实时预览功能仅在设置页面可用)',
  1256. tasksHistory: '任务历史',
  1257. clearHistory: '清空历史',
  1258. clearHistoryFinished: '已清空任务历史!',
  1259. deleteTask: '删除任务',
  1260. lastChangeTime: '最后一次修改时间',
  1261. clearTaskFinished: '删除以下任务完成!',
  1262. clearTaskFailed: '删除任务失败,没有找到任务名!',
  1263. syncData: '数据同步',
  1264. settingData: '正在上传数据...',
  1265. gettingData: '正在获取数据...',
  1266. help: '帮助',
  1267. fileName: '文件名',
  1268. upload2gist: '同步到Gist',
  1269. downloadFromGist: '从Gist同步',
  1270. saveAndTest: '保存配置并测试',
  1271. testSuccess: '测试成功!',
  1272. testFailed: '测试失败!',
  1273. saveAndTestNotice: '请先保存配置并测试!',
  1274. processingData: '正在处理数据...',
  1275. updatingData: '正在上传数据...',
  1276. syncDataSuccess: '同步数据成功!',
  1277. syncDataFailed: '同步数据失败,请在控制台查看错误信息!',
  1278. downloadingData: '正在下载数据...',
  1279. checkedNoData: '没有检测到远程数据,请确认配置是否正确!',
  1280. savingData: '正在保存数据...',
  1281. syncHistory: '同步任务历史',
  1282. checkUpdateFailed: '检测更新失败',
  1283. newVersionNotice: '检测到新版本V%0, <a class="high-light" href="%1" target="_blank">点此更新</a>',
  1284. language: '语言</br>目前仅支持zh: 中文, en: 英文',
  1285. gistOptions: 'Gist 设置',
  1286. swalNotice: '检测到您第一次安装V4版本脚本,请前往阅读用前必读内容!',
  1287. echoNotice: '检测到您第一次安装V4版本脚本,请<a class="high-light" href="%0" target="_blank">点此前往</a>阅读用前必读内容!',
  1288. noticeLink: 'https://auto-task-doc.js.org/guide/#用前必读',
  1289. toGithub: '前往Github反馈',
  1290. toKeylol: '前往其乐论坛反馈',
  1291. copySuccess: '错误信息已复制到剪切板,是否前往其乐论坛反馈?',
  1292. copyFailed: '请复制下方错误信息后前往Keylol论坛反馈!',
  1293. updateText: '%0 版本更新内容:',
  1294. Active: '进行中',
  1295. Ended: '已结束',
  1296. Banned: '已封禁',
  1297. Paused: '已暂停',
  1298. notStart: '未开始',
  1299. noRemoteData: '检测到远程无数据',
  1300. errorRemoteDataFormat: '远程数据格式错误',
  1301. updateHistory: '历史更新记录<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">点此查看</a>',
  1302. AsfEnabled: '使用ASF做Steam相关任务(需<a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a>插件)',
  1303. AsfIpcUrl: 'ASF IPC 地址',
  1304. AsfIpcPassword: 'ASF IPC 密码',
  1305. versionNotMatched: '脚本管理器版本过低,需TamperMonkey >= 5.2.0或TamperMonkey Beta >= 5.2.6196',
  1306. groups: '组',
  1307. officialGroups: '官方组',
  1308. wishlists: '愿望单',
  1309. follows: '游戏关注',
  1310. forums: '论坛',
  1311. workshops: '创意工坊收藏',
  1312. curators: '鉴赏家',
  1313. workshopVotes: '创意工坊点赞',
  1314. announcements: '社区通知',
  1315. steamCommunity: 'Steam社区',
  1316. steamStore: 'Steam商店',
  1317. licenses: '入库免费游戏',
  1318. playtests: '请求访问权限',
  1319. needLoginSteamStore: '请先<a href="https://store.steampowered.com/login/" target="_blank">登录Steam商店</a>',
  1320. needLoginSteamCommunity: '请先<a href="https://steamcommunity.com/login/home/" target="_blank">登录Steam社区</a>',
  1321. joiningSteamGroup: '正在加入Steam组',
  1322. leavingSteamGroup: '正在退出Steam组',
  1323. gettingSteamGroupId: '正在获取Steam组Id',
  1324. joiningSteamOfficialGroup: '正在加入Steam官方组',
  1325. leavingSteamOfficialGroup: '正在退出Steam官方组',
  1326. gettingSteamOfficialGroupId: '正在获取Steam官方组Id',
  1327. subscribingForum: '正在订阅Steam论坛',
  1328. unsubscribingForum: '正在取消订阅Steam论坛',
  1329. gettingForumId: '正在获取Steam论坛Id',
  1330. followingCurator: '正在关注Steam鉴赏家',
  1331. unfollowingCurator: '正在取关Steam鉴赏家',
  1332. gettingCuratorId: '正在获取Steam鉴赏家Id',
  1333. addingToWishlist: '正在添加游戏到Steam愿望单',
  1334. removingFromWishlist: '正在从Steam愿望单移除游戏',
  1335. followingGame: '正在关注Steam游戏',
  1336. unfollowingGame: '正在取关Steam游戏',
  1337. favoritingWorkshop: '正在收藏Steam创意工坊物品',
  1338. unfavoritingWorkshop: '正在取消收藏Steam创意工坊物品',
  1339. gettingWorkshopAppId: '正在获取Steam创意工坊物品Id',
  1340. votingUpWorkshop: '正在点赞Steam创意工坊物品',
  1341. gettingAnnouncementParams: '正在获取Steam通知信息',
  1342. likingAnnouncement: '正在点赞Steam通知',
  1343. changingArea: '正在更换Steam地区: %0...',
  1344. notNeededChangeArea: '当前地区不需要更换',
  1345. noAnotherArea: '请检测是否开启正确开启代理',
  1346. gettingAreaInfo: '正在获取Steam地区信息...',
  1347. changeAreaNotice: '疑似锁区游戏,尝试换区执行',
  1348. steamFinishNotice: 'Steam任务完成,尝试将购物车地区换回CN',
  1349. gettingSubid: '正在获取游戏subid',
  1350. addingFreeLicense: '正在入库',
  1351. missParams: '缺少参数',
  1352. gettingLicenses: '正在获取Licenses...',
  1353. requestingPlayTestAccess: '正在请求访问权限',
  1354. tryChangeAreaNotice: '此功能无法检测游戏是否限区,因此会尝试换区后再入库,换区失败也不影响后续入库',
  1355. initingASF: '正在初始化ASF...',
  1356. servers: '服务器',
  1357. joiningDiscordServer: '正在加入Discord服务器',
  1358. leavingDiscordServer: '正在退出Discord服务器',
  1359. gettingDiscordGuild: '正在获取Discord服务器Id',
  1360. getDiscordAuthFailed: '获取Discord凭证失败,请检测Discord帐号是否已登录',
  1361. discordImportantNotice: '重要提醒!!!',
  1362. discordImportantNoticeText: '由于Discord网站后台更新,目前使用此脚本加组后可能会导致Discord帐号被强制退出,且需要两步验证才能正常登录,请谨慎使用!!!',
  1363. continue: '继续',
  1364. skipDiscordTask: '跳过Discord任务',
  1365. continueAndDontRemindAgain: '继续且不再提醒',
  1366. users: '用户',
  1367. loginIns: '请先<a href="https://www.instagram.com/accounts/login/" target="_blank">登录Instagram</a>',
  1368. insBanned: '您的Instagram账户已被封禁',
  1369. verifyingInsAuth: '正在验证Instagram凭证...',
  1370. gettingInsUserId: '正在获取Instagram用户Id',
  1371. followingIns: '正在关注Instagram用户',
  1372. unfollowingIns: '正在取关Instagram用户',
  1373. reddits: '社区/用户',
  1374. loginReddit: '请先<a href="https://www.reddit.com/login/" target="_blank">登录Reddit</a>',
  1375. changingRedditVersion: '正在切换Reddit为新版页面...',
  1376. joiningReddit: '正在加入Reddit社区',
  1377. leavingReddit: '正在退出Reddit社区',
  1378. followingRedditUser: '正在关注Reddit用户',
  1379. unfollowingRedditUser: '正在取关Reddit用户',
  1380. channels: '频道',
  1381. followingTwitchChannel: '正在关注Twitch频道',
  1382. unfollowingTwitchChannel: '正在取关Twitch频道',
  1383. gettingTwitchChannelId: '正在获取Twitch频道Id',
  1384. checkingTwitchIntegrity: '正在检查Twitch完整性...',
  1385. twitterUser: '推特用户',
  1386. retweets: '转推',
  1387. gettingTwitterUserId: '正在获取推特用户Id',
  1388. followingTwitterUser: '正在关注推特用户',
  1389. unfollowingTwitterUser: '正在取关推特用户',
  1390. retweetting: '正在转推',
  1391. unretweetting: '正在撤销转推',
  1392. names: '组/社区/动态',
  1393. loginVk: '请先<a href="https://vk.com/login/" target="_blank">登录Vk</a>',
  1394. gettingVkId: '正在获取Vk任务Id',
  1395. joiningVkGroup: '正在加入Vk组',
  1396. leavingVkGroup: '正在退出Vk组',
  1397. joiningVkPublic: '正在加入Vk社区',
  1398. leavingVkPublic: '正在退出Vk社区',
  1399. sendingVkWall: '正在转发Vk动态',
  1400. deletingVkWall: '正在撤销转发Vk动态',
  1401. youtubeChannel: 'YouTube频道',
  1402. likes: '点赞',
  1403. loginYtb: '请先<a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">登录YouTube</a>',
  1404. tryUpdateYtbAuth: '请尝试<a href="https://www.youtube.com/#auth" target="_blank">更新YouTube凭证</a>',
  1405. gettingYtbToken: '正在获取YouTube Token...',
  1406. followingYtbChannel: '正在订阅YouTube频道',
  1407. unfollowingYtbChannel: '正在退订YouTube频道',
  1408. likingYtbVideo: '正在点赞YouTube视频',
  1409. unlikingYtbVideo: '正在取消点赞YouTube视频',
  1410. giveKeyNoticeBefore: '每次验证间隔15s',
  1411. giveKeyNoticeAfter: '如果没有key, 请在<a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>查看',
  1412. noPoints: '点数不够,跳过抽奖',
  1413. getNeedPointsFailed: '获取所需点数失败,跳过抽奖',
  1414. joiningLottery: '正在加入抽奖',
  1415. doingGleamTask: '正在做Gleam任务...',
  1416. gettingGleamLink: '正在获取Gleam任务链接...',
  1417. gleamTaskNotice: '如果此页面长时间未关闭,请完成任一任务后自行关闭!',
  1418. verifiedGleamTasks: '已尝试验证所有任务,验证失败的任务请尝试手动验证或完成!',
  1419. campaign: '检测到人机验证,请完成验证后重新验证任务!',
  1420. gsNotice: '为避免得到"0000-0000-0000"key, 已自动屏蔽"Grab Key"按钮,获取key时请关闭脚本!',
  1421. giveeClubVerifyNotice: '正在验证任务...',
  1422. giveeClubVerifyFinished: '请等待验证完成后自行加入赠Key',
  1423. doingKeyhubTask: '正在做Keyhub任务...',
  1424. SweepWidgetNotice: '正在处理并验证任务,每次验证任务有1~3s间隔防止触发验证过快警告...',
  1425. confirmingTask: '正在跳过警告页面...'
  1426. };
  1427. const zh_CN = data;
  1428. const en_US_data = {
  1429. website: 'Website',
  1430. type: 'Type',
  1431. edit: 'Edit',
  1432. whiteList: 'Whitelist',
  1433. skipTask: 'Skip undo task',
  1434. whiteListOptions: 'Whitelist options',
  1435. changeWhiteListOption: 'Whitelist option(%0)',
  1436. whiteListNotFound: 'Cannot find this whitelist: %0',
  1437. changeWhiteListSuccess: 'The whitelist is successfully modified, and the page refresh will take effect!',
  1438. changeWebsiteOptions: 'Website options',
  1439. changeGlobalOptions: 'Global options',
  1440. ok: 'OK',
  1441. save: 'Save',
  1442. close: 'Close',
  1443. return: 'Return',
  1444. option: 'Option',
  1445. value: 'Value',
  1446. websiteOptions: 'Current website settings',
  1447. changeWebsiteOptionsSuccess: 'The current website setting is changed successfully, and the page refresh will take effect!',
  1448. changeGlobalOptionsSuccess: 'The global setting is changed successfully, and the refresh will take effect!',
  1449. needLogin: 'Please log in first!',
  1450. getTasksInfo: 'Obtaining and processing task information...',
  1451. gettingKey: 'Getting Key...',
  1452. verifyingTask: 'Verifying task',
  1453. notice: 'Automatic task script notice',
  1454. noKeysLeft: 'There are no more keys left on this page. Do you want to close it?',
  1455. giveawayEnded: 'This event has ended, do you want to close it?',
  1456. giveawayNotWork: 'This activity is unavailable for some reasons (banned/ended/paused/not started...)' + ' (if it is a script misjudgment, please give us feedback in time), is it closed?',
  1457. confirm: 'Confirm',
  1458. cancel: 'Cancel',
  1459. unKnown: 'Unknown',
  1460. unKnownTaskType: 'Unrecognized task',
  1461. doing: 'Doing a task',
  1462. allTasksComplete: 'All tasks have been completed!',
  1463. getTaskIdFailed: 'Failed to obtain task Id!',
  1464. initSuccess: '%0 was initialized successfully!',
  1465. initFailed: '%0 initialization failed!',
  1466. errorLink: 'Link error: %0',
  1467. needInit: 'Please initialize first',
  1468. verifyingAuth: 'Verifying %0 token...',
  1469. updatingAuth: 'Update %0 token...',
  1470. initing: 'Initializing...',
  1471. getFailed: 'Failed to get %0!',
  1472. checkLoginFailed: 'Failed to detect login status!',
  1473. checkLeftKeyFailed: 'Failed to detect the remaining keys!',
  1474. userId: 'User Id',
  1475. joiningGiveaway: 'Joining giveaway',
  1476. needJoinGiveaway: 'Need to join the giveaway first',
  1477. cannotUndo: 'This website does not support canceling tasks',
  1478. verifyAuth: 'Verifying %0 token...',
  1479. closePageNotice: 'f this page does not close automatically, please close this page yourself.',
  1480. errorReport: 'A script error is detected, do you want to report the BUG?',
  1481. visitingLink: 'Visiting link: ',
  1482. doTask: 'DoTask',
  1483. undoTask: 'UndoTask',
  1484. verifyTask: 'Verify',
  1485. getKey: 'GetKey',
  1486. selectAll: 'SelectAll',
  1487. selectNone: 'SelectNone',
  1488. invertSelect: 'InvertSelect',
  1489. doFreeTask: 'FreeTask',
  1490. doPointTask: 'PointTask',
  1491. skipTaskOption: 'Skip task has been configured in the settings',
  1492. other: 'Other',
  1493. globalOptions: 'Global Options',
  1494. checkLogin: 'Login detection</br>Need to log in to the website automatically log in, part of this website supports.',
  1495. checkLeftKey: 'Key remaining detection</br>The end of the giveaway event prompts whether to close or not, part of this website supports.',
  1496. twitterVerifyId: 'Verify Twitter token by trying to follow the account.</br>The default is the official Twitter account 783214.</br>' + 'If you don\'t want to follow the official account, you can change it to your own account.',
  1497. youtubeVerifyChannel: 'Verify YouTube token by trying to subscribe to the channel.</br>' + 'The default is the official YouTube channel UCrXUsMBcfTVqwAS7DKg9C0Q.</br>' + 'If you don\'t want to follow the official channel, you can change it to your own channel.',
  1498. autoUpdateSource: 'The source to update</br>github: Fast update.</br>jsdelivr: Update is delayed.</br>' + 'standby: Standby source.</br>auto: Try to update using github, jsdelivr, standby sources in turn.',
  1499. saveGlobalOptions: 'SaveSettings',
  1500. settingPage: 'Setting Page',
  1501. name: 'Name',
  1502. version: 'Version',
  1503. scriptManager: 'Script Manager',
  1504. script: 'Script',
  1505. environment: 'Environment',
  1506. os: 'OS',
  1507. browser: 'Browser',
  1508. getId: 'Get %0 id',
  1509. getTwitterUserId: 'Get Twitter user id (Get id function is only available on the settings page).',
  1510. getYoutubeChannelId: 'Get Youtube channel id (Get id function is only available on the settings page).',
  1511. showButton: 'ShowButton',
  1512. hideButton: 'HideButton',
  1513. showLog: 'ShowLog',
  1514. hideLog: 'HideLog',
  1515. defaultShowButton: 'Default display button',
  1516. defaultShowLog: 'Display log by default',
  1517. debug: 'Output debug log, do not enable this option!',
  1518. receivePreview: 'Receive preview updates',
  1519. position: 'Component position',
  1520. buttonSideX: 'Horizontal positioning of the button area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1521. buttonSideY: 'The button area is positioned in the vertical direction (real-time preview function is only available on the settings page).' + '</br>top: top | bottom: bottom',
  1522. buttonDistance: 'The distance between the button area and the edge (the real-time preview function is only available on the setting page).' + '</br> Format: X distance, Y distance',
  1523. showButtonSideX: 'ShowButton horizontal positioning (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1524. showButtonSideY: 'ShowButton vertical positioning (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1525. showButtonDistance: 'The distance between the ShowButton and the edge (real-time preview function is only available on the setting page).' + '</br> Format: X distance, Y distance',
  1526. logSideX: 'Horizontal positioning of the log area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1527. logSideY: 'Vertical positioning of the log area (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1528. logDistance: 'The distance between the log area and the edge (the real-time preview function is only available on the setting page).' + '</br> Format: X distance, Y distance',
  1529. hotKey: 'Shortcut key',
  1530. doTaskKey: 'DoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1531. undoTaskKey: 'UndoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1532. toggleLogKey: 'ShowLog/HideLog shortcut keys</br> (real-time preview function is only available on the settings page).',
  1533. tasksHistory: 'TasksHistory',
  1534. clearHistory: 'Clear history',
  1535. clearHistoryFinished: 'The mission history has been cleared!',
  1536. deleteTask: 'Delete task',
  1537. lastChangeTime: 'Last Change Time',
  1538. clearTaskFinished: 'Delete the following tasks completed!',
  1539. clearTaskFailed: 'Failed to delete the task, the task name was not found!',
  1540. syncData: 'DataSync',
  1541. settingData: 'Uploading data...',
  1542. gettingData: 'Getting data...',
  1543. help: 'Help',
  1544. fileName: 'Filename',
  1545. upload2gist: 'Sync to Gist',
  1546. downloadFromGist: 'Sync from Gist',
  1547. saveAndTest: 'Save configuration and test',
  1548. testSuccess: 'Test success!',
  1549. testFailed: 'Test failed!',
  1550. saveAndTestNotice: 'Please save the configuration and test first!',
  1551. processingData: 'Processing data...',
  1552. updatingData: 'Uploading data...',
  1553. syncDataSuccess: 'Synchronized data successfully!',
  1554. syncDataFailed: 'Failed to synchronize data, please check the error message on the console!',
  1555. downloadingData: 'Downloading data...',
  1556. checkedNoData: 'No remote data is detected, please confirm whether the configuration is correct!',
  1557. savingData: 'Saving data...',
  1558. syncHistory: 'Synchronize tasks history',
  1559. checkUpdateFailed: 'Check update failed',
  1560. newVersionNotice: 'Checked a new version V%0, <a class="high-light" href="%1" target="_blank">click to update</a>',
  1561. language: 'Language</br> Currently only supports zh: Chinese, en: English',
  1562. gistOptions: 'Gist Settings',
  1563. swalNotice: 'It is detected that you are installing the V4 version script for the first time' + ', please go to read the READ ME FIRST content before use!',
  1564. echoNotice: 'It is detected that you are installing the V4 version script for the first time' + ', please <a class="high-light" href="%0" target="_blank">click here</a> to read the READ ME FIRST content before use!',
  1565. noticeLink: 'https://auto-task-doc.js.org/en/guide/#read-me-first',
  1566. toGithub: 'Feedback(Github)',
  1567. toKeylol: 'Feedback(Keylol)',
  1568. copySuccess: 'The error message has been copied to the clipboard. Do you want to go to the Keylol forum to give feedback?',
  1569. copyFailed: 'Please copy the error information below and report back to the Keylol forum!',
  1570. updateText: 'Updates in version %0:',
  1571. Active: 'Active',
  1572. Ended: 'Ended',
  1573. Banned: 'Banned',
  1574. Paused: 'Paused',
  1575. notStart: 'notStart',
  1576. noRemoteData: 'No data remotely',
  1577. errorRemoteDataFormat: 'Remote data has wrong format',
  1578. updateHistory: '<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">Click here</a>' + ' to view the historical update record.',
  1579. AsfEnabled: 'Use ASF to do Steam related tasks (requires <a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a> plugin)',
  1580. AsfIpcUrl: 'ASF IPC URL',
  1581. AsfIpcPassword: 'ASF IPC Password',
  1582. groups: 'Group',
  1583. officialGroups: 'Official Group',
  1584. wishlists: 'Wishlist',
  1585. follows: 'Follow Game',
  1586. forums: 'Forum',
  1587. workshops: 'Favorite Workshop',
  1588. curators: 'Curator',
  1589. workshopVotes: 'Voteup Workshop',
  1590. announcements: 'Announcement',
  1591. steamCommunity: 'Steam Community',
  1592. steamStore: 'Steam Store',
  1593. licenses: 'Add License',
  1594. playtests: 'Playtest Access',
  1595. needLoginSteamStore: 'Please <a href="https://store.steampowered.com/login/" target="_blank">log in to the Steam Store</a>',
  1596. needLoginSteamCommunity: 'Please <a href="https://steamcommunity.com/login/home/" target="_blank">log in to the Steam Community</a>',
  1597. joiningSteamGroup: 'Joining Steam Group',
  1598. leavingSteamGroup: 'Leaving Steam Group',
  1599. gettingSteamGroupId: 'Getting Steam Group Id',
  1600. joiningSteamOfficialGroup: 'Joining Steam Official Group',
  1601. leavingSteamOfficialGroup: 'Leaving Steam Official Group',
  1602. gettingSteamOfficialGroupId: 'Getting Steam Official Group Id',
  1603. subscribingForum: 'Subscribing the Steam Forum',
  1604. unsubscribingForum: 'Unsubscribing the Steam Forum',
  1605. gettingForumId: 'Getting Steam Forum Id',
  1606. followingCurator: 'Following Steam Curator',
  1607. unfollowingCurator: 'Unfollowing Steam Curator',
  1608. gettingCuratorId: 'Getting Steam Curator Id',
  1609. addingToWishlist: 'Adding the game to the Steam wishlist',
  1610. removingFromWishlist: 'Removing the game from the Steam wishlist',
  1611. followingGame: 'Following Steam games',
  1612. unfollowingGame: 'Unfollowing Steam games',
  1613. favoritingWorkshop: 'Favouring Steam Workshop Items',
  1614. unfavoritingWorkshop: 'Unfavoriting Steam Workshop Items',
  1615. gettingWorkshopAppId: 'Getting Steam Workshop Item Id',
  1616. votingUpWorkshop: 'Liking Steam workshop items',
  1617. gettingAnnouncementParams: 'Getting Steam announcement information',
  1618. likingAnnouncement: 'Liking Steam announcement',
  1619. changingArea: 'Changing Steam area: %0...',
  1620. notNeededChangeArea: 'The current area does not need to be changed',
  1621. noAnotherArea: 'Please check whether the proxy is turned on correctly',
  1622. gettingAreaInfo: 'Getting Steam area information...',
  1623. changeAreaNotice: 'Suspected of a locked zone game, try to change the zone to execute',
  1624. steamFinishNotice: 'Steam task completed, try to change the shopping cart area back to CN',
  1625. gettingSubid: 'Getting subid',
  1626. addingFreeLicense: 'Adding free license',
  1627. missParams: 'Missing parameters',
  1628. gettingLicenses: 'Getting licenses...',
  1629. requestingPlayTestAccess: 'Requesting play test access',
  1630. tryChangeAreaNotice: 'This function cannot detect whether the game is limited, so it will try to change the area before entering the library' + '. Failure to change the area will not affect the subsequent storage.',
  1631. versionNotMatched: 'The script manager version is too low, requiring TamperMonkey >= 5.2.0 or TamperMonkey Beta >= 5.2.6196',
  1632. initingASF: 'Initing ASF...',
  1633. servers: 'Server',
  1634. joiningDiscordServer: 'Joining Discord Server',
  1635. leavingDiscordServer: 'Leaving Discord Server',
  1636. gettingDiscordGuild: 'Getting Discord server Id',
  1637. getDiscordAuthFailed: 'Failed to get Discord token, please check whether the Discord account is logged in',
  1638. discordImportantNotice: 'Important Reminder! ! !',
  1639. discordImportantNoticeText: 'Due to the background update of the Discord website, currently using this script to join a group may cause the Discord account to be forcibly logged out, and two-step verification is required to log in normally, please use it with caution! ! !',
  1640. continue: 'Continue',
  1641. skipDiscordTask: 'Skip',
  1642. continueAndDontRemindAgain: 'Continue without Reminders',
  1643. users: 'User',
  1644. loginIns: 'Please <a href="https://www.instagram.com/accounts/login/" target="_blank">log in to Instagram</a>',
  1645. insBanned: 'Your Instagram account has been banned',
  1646. verifyingInsAuth: 'Verifying Instagram token...',
  1647. gettingInsUserId: 'Getting Instagram user Id',
  1648. followingIns: 'Following Instagram user',
  1649. unfollowingIns: 'Unfollowing Instagram user',
  1650. reddits: 'Reddit/User',
  1651. loginReddit: 'Please <a href="https://www.reddit.com/login/" target="_blank">log in to Reddit</a>',
  1652. changingRedditVersion: 'Switching Reddit to a new version page...',
  1653. joiningReddit: 'Joining the Reddit',
  1654. leavingReddit: 'Leaving the Reddit',
  1655. followingRedditUser: 'Following Reddit User',
  1656. unfollowingRedditUser: 'Unfollowing Reddit User',
  1657. channels: 'Channel',
  1658. followingTwitchChannel: 'Following Twitch Channel',
  1659. unfollowingTwitchChannel: 'Unfollowing Twitch Channel',
  1660. gettingTwitchChannelId: 'Getting Twitch Channel Id',
  1661. checkingTwitchIntegrity: 'Checking Twitch integrity...',
  1662. twitterUser: 'Twitter User',
  1663. retweets: 'Retweet',
  1664. gettingTwitterUserId: 'Getting Twitter User Id',
  1665. followingTwitterUser: 'Following Twitter User',
  1666. unfollowingTwitterUser: 'Unfollowing Twitter User',
  1667. retweetting: 'Retweetting',
  1668. unretweetting: 'Unretweetting',
  1669. names: 'Group/Public/Wall',
  1670. loginVk: 'Please <a href="https://vk.com/login/" target="_blank">log in to Vk</a>',
  1671. gettingVkId: 'Getting Vk task Id',
  1672. joiningVkGroup: 'Joining Vk Group',
  1673. leavingVkGroup: 'Leaving Vk Group',
  1674. joiningVkPublic: 'Joining Vk Public',
  1675. leavingVkPublic: 'Leaving Vk Public',
  1676. sendingVkWall: 'Sending Vk Wall',
  1677. deletingVkWall: 'Deleting Vk Wall',
  1678. youtubeChannel: 'YouTube Channel',
  1679. likes: 'Like',
  1680. loginYtb: 'Please <a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">log in to YouTube</a>',
  1681. tryUpdateYtbAuth: 'Please try to <a href="https://www.youtube.com/#auth" target="_blank">update YouTube token</a>',
  1682. gettingYtbToken: 'Getting YouTube Token...',
  1683. followingYtbChannel: 'Subscribing to YouTube channel',
  1684. unfollowingYtbChannel: 'Unsubscribing to YouTube channel',
  1685. likingYtbVideo: 'Liking YouTube video',
  1686. unlikingYtbVideo: 'Unliking YouTube video',
  1687. giveKeyNoticeBefore: 'Each verification interval is 15s',
  1688. giveKeyNoticeAfter: 'If there is no key, please check at <a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>',
  1689. noPoints: 'Not enough points, skip the lottery',
  1690. getNeedPointsFailed: 'ailed to obtain the required points, skip the lottery',
  1691. joiningLottery: 'Joining the lottery',
  1692. doingGleamTask: 'Doing Gleam Task...',
  1693. gettingGleamLink: 'Getting Gleam task link...',
  1694. gleamTaskNotice: 'If this page has not been closed for a long time, please close it yourself after completing any task!',
  1695. verifiedGleamTasks: 'Attempted to verify all tasks. If the verification fails, please try to verify manually or complete it!',
  1696. campaign: 'ReCAPTCHA detected, please complete it and re-verify the tasks!',
  1697. gsNotice: 'In order to avoid getting the "0000-0000-0000" key, the "Grab Key" button has been hidden,' + ' please close the script when obtaining the key!',
  1698. giveeClubVerifyNotice: 'Verifying task...',
  1699. giveeClubVerifyFinished: 'Wait for the verification to complete and join it by yourself',
  1700. doingKeyhubTask: 'Doing Keyhub Task...',
  1701. SweepWidgetNotice: 'The task is being processed and verified. ' + 'There is an interval of 1~3s for each verification task to prevent the triggering of too fast verification warning...',
  1702. confirmingTask: 'Confirming task...'
  1703. };
  1704. const en_US = en_US_data;
  1705. const languages = {
  1706. zh: zh_CN,
  1707. en: en_US
  1708. };
  1709. const language = [ 'zh', 'en' ].includes(globalOptions.other.language) ? globalOptions.other.language : 'en';
  1710. const I18n = (key, ...argvs) => {
  1711. if (!languages[language]?.[key]) {
  1712. return key;
  1713. }
  1714. return languages[language][key].replace(/%([\d]+)/g, (match, index) => argvs[parseInt(index, 10)]);
  1715. };
  1716. const i18n = I18n;
  1717. function throwError(error, name) {
  1718. if (window.TRACE) {
  1719. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  1720. }
  1721. external_Swal_default().fire({
  1722. title: i18n('errorReport'),
  1723. icon: 'error',
  1724. showCancelButton: true,
  1725. confirmButtonText: i18n('toGithub'),
  1726. showDenyButton: true,
  1727. denyButtonText: i18n('toKeylol'),
  1728. cancelButtonText: i18n('close')
  1729. }).then(({
  1730. isDenied,
  1731. isConfirmed
  1732. }) => {
  1733. if (isConfirmed) {
  1734. window.open(`https://github.com/HCLonely/auto-task-v4/issues/new?title=${encodeURIComponent(`[BUG] 脚本报错: ${name}`)}&labels=bug&template=bug_report.yml&website=${encodeURIComponent(window.location.href)}&browser=${encodeURIComponent(JSON.stringify((0,
  1735. javascript_utils_umd_min.ua)(), null, 4))}&manager=${encodeURIComponent(`${GM_info.scriptHandler} ${GM_info.version}`)}&user-script=${encodeURIComponent(GM_info.script.version)}&logs=${encodeURIComponent(error.stack || 'null')}&run-logs=${encodeURIComponent($.makeArray($('#auto-task-info>li')).map(element => element.innerText).join('\n'))}`, '_blank');
  1736. } else if (isDenied) {
  1737. const text = `错误链接: [url=${window.location.href}]${window.location.href}[/url]
  1738.  
  1739. 环境:
  1740.  
  1741. [code]${JSON.stringify((0, javascript_utils_umd_min.ua)(), null, 4)}[/code]
  1742.  
  1743. 脚本管理器: ${GM_info.scriptHandler} ${GM_info.version}
  1744. 脚本版本: ${GM_info.script.version}
  1745.  
  1746. 报错信息:
  1747. [code]${error.stack}[/code]
  1748.  
  1749. 执行日志:
  1750. [code]${$.makeArray($('#auto-task-info>li')).map(element => element.innerText).join('\n')}[/code]`;
  1751. GM_setClipboard(text);
  1752. external_Swal_default().fire({
  1753. title: i18n('copySuccess'),
  1754. icon: 'success',
  1755. confirmButtonText: i18n('ok')
  1756. }).then(() => {
  1757. window.open('https://keylol.com/forum.php?mod=post&action=reply&fid=319&tid=777450', '_blank');
  1758. });
  1759. }
  1760. });
  1761. console.log('%c%s', 'color:white;background:red', `Auto-Task[Error]: ${name}\n${error.stack}`);
  1762. }
  1763. class Social {
  1764. tasks;
  1765. getRealParams(name, links, doTask, link2param) {
  1766. try {
  1767. let realParams = [];
  1768. if (links.length > 0) {
  1769. realParams = [ ...realParams, ...links.map(link => link2param(link)).filter(link => link) ];
  1770. }
  1771. if (!doTask && this.tasks[name].length > 0) {
  1772. realParams = [ ...realParams, ...this.tasks[name] ];
  1773. }
  1774. return unique(realParams);
  1775. } catch (error) {
  1776. throwError(error, 'Social.getRealParams');
  1777. return [];
  1778. }
  1779. }
  1780. }
  1781. const social_Social = Social;
  1782. class Discord extends social_Social {
  1783. tasks;
  1784. whiteList;
  1785. #auth = GM_getValue('discordAuth') || {};
  1786. #cache = GM_getValue('discordCache') || {};
  1787. #initialized = false;
  1788. constructor() {
  1789. super();
  1790. const defaultTasksTemplate = {
  1791. servers: []
  1792. };
  1793. this.tasks = defaultTasksTemplate;
  1794. this.whiteList = {
  1795. ...defaultTasksTemplate,
  1796. ...GM_getValue('whiteList')?.discord || {}
  1797. };
  1798. }
  1799. async init(action) {
  1800. try {
  1801. if (!GM_getValue('dontRemindDiscordAgain')) {
  1802. const result = await external_Swal_default().fire({
  1803. title: i18n('discordImportantNotice'),
  1804. text: i18n('discordImportantNoticeText'),
  1805. showCancelButton: true,
  1806. showDenyButton: true,
  1807. confirmButtonText: i18n('continue'),
  1808. cancelButtonText: i18n('skipDiscordTask'),
  1809. denyButtonText: i18n('continueAndDontRemindAgain')
  1810. }).then(({
  1811. isConfirmed,
  1812. isDenied
  1813. }) => {
  1814. if (isConfirmed) {
  1815. return true;
  1816. }
  1817. if (isDenied) {
  1818. GM_setValue('dontRemindDiscordAgain', true);
  1819. return true;
  1820. }
  1821. return false;
  1822. });
  1823. if (!result) {
  1824. this.#initialized = false;
  1825. return 'skip';
  1826. }
  1827. }
  1828. if (GM_getValue('dontRemindDiscordAgain') || action === 'do' && !globalOptions.doTask.discord.servers || action === 'undo' && !globalOptions.undoTask.discord.servers) {
  1829. this.#initialized = false;
  1830. return 'skip';
  1831. }
  1832. if (this.#initialized) {
  1833. return true;
  1834. }
  1835. if (!this.#auth.auth) {
  1836. if (await this.#updateAuth()) {
  1837. this.#initialized = true;
  1838. return true;
  1839. }
  1840. return false;
  1841. }
  1842. const isVerified = await this.#verifyAuth();
  1843. if (isVerified) {
  1844. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1845. this.#initialized = true;
  1846. return true;
  1847. }
  1848. GM_setValue('discordAuth', {
  1849. auth: null
  1850. });
  1851. if (await this.#updateAuth()) {
  1852. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1853. this.#initialized = true;
  1854. return true;
  1855. }
  1856. scripts_echoLog({}).error(i18n('initFailed', 'Discord'));
  1857. return false;
  1858. } catch (error) {
  1859. throwError(error, 'Discord.init');
  1860. return false;
  1861. }
  1862. }
  1863. async #verifyAuth() {
  1864. try {
  1865. const logStatus = scripts_echoLog({
  1866. text: i18n('verifyingAuth', 'Discord')
  1867. });
  1868. const {
  1869. result,
  1870. statusText,
  1871. status,
  1872. data
  1873. } = await tools_httpRequest({
  1874. url: 'https://discord.com/api/v6/users/@me',
  1875. method: 'HEAD',
  1876. headers: {
  1877. authorization: this.#auth.auth
  1878. }
  1879. });
  1880. if (result === 'Success') {
  1881. if (data?.status === 200) {
  1882. logStatus.success();
  1883. return true;
  1884. }
  1885. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  1886. return false;
  1887. }
  1888. logStatus.error(`${result}:${statusText}(${status})`);
  1889. return false;
  1890. } catch (error) {
  1891. throwError(error, 'Discord.verifyAuth');
  1892. return false;
  1893. }
  1894. }
  1895. async #updateAuth() {
  1896. try {
  1897. const logStatus = scripts_echoLog({
  1898. text: i18n('updatingAuth', 'Discord')
  1899. });
  1900. return await new Promise(resolve => {
  1901. const newTab = GM_openInTab('https://discord.com/channels/@me#auth', {
  1902. active: true,
  1903. insert: true,
  1904. setParent: true
  1905. });
  1906. newTab.onclose = async () => {
  1907. const auth = GM_getValue('discordAuth')?.auth;
  1908. if (auth) {
  1909. this.#auth = {
  1910. auth: auth
  1911. };
  1912. logStatus.success();
  1913. resolve(await this.#verifyAuth());
  1914. } else {
  1915. logStatus.error('Error: Update discord auth failed!');
  1916. resolve(false);
  1917. }
  1918. };
  1919. });
  1920. } catch (error) {
  1921. throwError(error, 'Discord.updateAuth');
  1922. return false;
  1923. }
  1924. }
  1925. async #joinServer(inviteId) {
  1926. try {
  1927. const logStatus = scripts_echoLog({
  1928. type: 'joiningDiscordServer',
  1929. text: inviteId
  1930. });
  1931. const {
  1932. result,
  1933. statusText,
  1934. status,
  1935. data
  1936. } = await tools_httpRequest({
  1937. url: `https://discord.com/api/v9/invites/${inviteId}`,
  1938. method: 'POST',
  1939. dataType: 'json',
  1940. headers: {
  1941. authorization: this.#auth.auth,
  1942. origin: 'https://discord.com',
  1943. referer: `https://discord.com/invite/${inviteId}`
  1944. }
  1945. });
  1946. if (result === 'Success' && data?.status === 200) {
  1947. logStatus.success();
  1948. const guild = String(data.response?.guild?.id);
  1949. if (guild) {
  1950. this.#setCache(inviteId, guild);
  1951. this.tasks.servers = unique([ ...this.tasks.servers, inviteId ]);
  1952. }
  1953. return true;
  1954. }
  1955. logStatus.error(`${result}:${statusText}(${status})`);
  1956. return false;
  1957. } catch (error) {
  1958. throwError(error, 'Discord.joinServer');
  1959. return false;
  1960. }
  1961. }
  1962. async #leaveServer(inviteId) {
  1963. try {
  1964. if (this.whiteList.servers.includes(inviteId)) {
  1965. scripts_echoLog({
  1966. type: 'whiteList',
  1967. text: 'Discord.leaveServer',
  1968. id: inviteId
  1969. });
  1970. return true;
  1971. }
  1972. const guild = await this.#getGuild(inviteId);
  1973. if (!guild) {
  1974. return false;
  1975. }
  1976. const logStatus = scripts_echoLog({
  1977. type: 'leavingDiscordServer',
  1978. text: guild
  1979. });
  1980. const {
  1981. result,
  1982. statusText,
  1983. status,
  1984. data
  1985. } = await tools_httpRequest({
  1986. url: `https://discord.com/api/v9/users/@me/guilds/${guild}`,
  1987. method: 'DELETE',
  1988. headers: {
  1989. authorization: this.#auth.auth
  1990. }
  1991. });
  1992. if (result === 'Success' && data?.status === 204) {
  1993. logStatus.success();
  1994. return true;
  1995. }
  1996. logStatus.error(`${result}:${statusText}(${status})`);
  1997. return false;
  1998. } catch (error) {
  1999. throwError(error, 'Discord.leaveServer');
  2000. return false;
  2001. }
  2002. }
  2003. async #getGuild(inviteId) {
  2004. try {
  2005. const logStatus = scripts_echoLog({
  2006. type: 'gettingDiscordGuild',
  2007. text: inviteId
  2008. });
  2009. const guild = this.#cache[inviteId];
  2010. if (guild) {
  2011. logStatus.success();
  2012. return guild;
  2013. }
  2014. const {
  2015. result,
  2016. statusText,
  2017. status,
  2018. data
  2019. } = await tools_httpRequest({
  2020. url: `https://discord.com/api/v9/invites/${inviteId}`,
  2021. responseType: 'json',
  2022. method: 'GET'
  2023. });
  2024. if (result === 'Success' && data?.status === 200) {
  2025. const guild = data.response?.guild?.id;
  2026. if (guild) {
  2027. logStatus.success();
  2028. this.#setCache(inviteId, guild);
  2029. return guild;
  2030. }
  2031. logStatus.error(`${result}:${statusText}(${status})`);
  2032. return false;
  2033. }
  2034. logStatus.error(`${result}:${statusText}(${status})`);
  2035. return false;
  2036. } catch (error) {
  2037. throwError(error, 'Discord.getGuild');
  2038. return false;
  2039. }
  2040. }
  2041. async toggle({
  2042. doTask = true,
  2043. serverLinks = []
  2044. }) {
  2045. try {
  2046. if (!this.#initialized) {
  2047. scripts_echoLog({
  2048. text: i18n('needInit')
  2049. });
  2050. return false;
  2051. }
  2052. const prom = [];
  2053. if (doTask && !globalOptions.doTask.discord.servers || !doTask && !globalOptions.undoTask.discord.servers) {
  2054. scripts_echoLog({
  2055. type: 'globalOptionsSkip',
  2056. text: 'discord.servers'
  2057. });
  2058. } else {
  2059. const realServers = this.getRealParams('servers', serverLinks, doTask, link => link.match(/invite\/(.+)/)?.[1]);
  2060. if (realServers.length > 0) {
  2061. for (const server of realServers) {
  2062. if (doTask) {
  2063. prom.push(this.#joinServer(server));
  2064. } else {
  2065. prom.push(this.#leaveServer(server));
  2066. }
  2067. await delay(1e3);
  2068. }
  2069. }
  2070. }
  2071. return await Promise.all(prom).then(() => true);
  2072. } catch (error) {
  2073. throwError(error, 'Discord.toggleServers');
  2074. return false;
  2075. }
  2076. }
  2077. #setCache(inviteId, guild) {
  2078. try {
  2079. this.#cache[inviteId] = guild;
  2080. GM_setValue('discordCache', this.#cache);
  2081. } catch (error) {
  2082. throwError(error, 'Discord.setCache');
  2083. }
  2084. }
  2085. }
  2086. const social_Discord = Discord;
  2087. class Instagram extends social_Social {
  2088. tasks;
  2089. whiteList;
  2090. #cache = GM_getValue('instagramCache') || {};
  2091. #auth = {};
  2092. #initialized = false;
  2093. constructor() {
  2094. super();
  2095. const defaultTasksTemplate = {
  2096. users: []
  2097. };
  2098. this.tasks = defaultTasksTemplate;
  2099. this.whiteList = {
  2100. ...defaultTasksTemplate,
  2101. ...GM_getValue('whiteList')?.instagram || {}
  2102. };
  2103. }
  2104. async init() {
  2105. try {
  2106. if (this.#initialized) {
  2107. return true;
  2108. }
  2109. const isVerified = await this.#getUserInfo();
  2110. if (isVerified) {
  2111. scripts_echoLog({}).success(i18n('initSuccess', 'Instagram'));
  2112. this.#initialized = true;
  2113. return true;
  2114. }
  2115. scripts_echoLog({}).error(i18n('initFailed', 'Instagram'));
  2116. return false;
  2117. } catch (error) {
  2118. throwError(error, 'Instagram.init');
  2119. return false;
  2120. }
  2121. }
  2122. async #getUserInfo(name = 'instagram') {
  2123. try {
  2124. const logStatus = scripts_echoLog({
  2125. type: name === 'instagram' ? 'verifyingInsAuth' : 'gettingInsUserId',
  2126. text: name
  2127. });
  2128. const userId = this.#cache[name];
  2129. if (userId && name !== 'instagram') {
  2130. logStatus.success();
  2131. return userId;
  2132. }
  2133. const {
  2134. result,
  2135. statusText,
  2136. status,
  2137. data
  2138. } = await tools_httpRequest({
  2139. url: `https://www.instagram.com/${name}/`,
  2140. method: 'GET'
  2141. });
  2142. if (result === 'Success') {
  2143. if (data?.finalUrl.includes('accounts/login')) {
  2144. logStatus.error(`Error:${i18n('loginIns')}`, true);
  2145. return false;
  2146. } else if (data?.finalUrl.includes('www.instagram.com/challenge')) {
  2147. logStatus.error(`Error:${i18n('insBanned')}`);
  2148. return false;
  2149. }
  2150. if (data?.status === 200) {
  2151. const csrftoken = data.responseText.match(/"csrf_token":"(.+?)"/)?.[1];
  2152. const hash = data.responseText.match(/"rollout_hash":"(.+?)"/)?.[1];
  2153. if (name === 'instagram') {
  2154. if (csrftoken && hash) {
  2155. this.#auth = {
  2156. csrftoken: csrftoken,
  2157. hash: hash
  2158. };
  2159. return true;
  2160. }
  2161. return false;
  2162. }
  2163. const id = data.responseText.match(/"profilePage_([\d]+?)"/)?.[1];
  2164. if (id) {
  2165. this.#setCache(name, id);
  2166. logStatus.success();
  2167. return id;
  2168. }
  2169. logStatus.error('Error: Get ins data error!');
  2170. return false;
  2171. }
  2172. logStatus.error(`${result}:${statusText}(${status})`);
  2173. return false;
  2174. }
  2175. return false;
  2176. } catch (error) {
  2177. throwError(error, 'Instagram.getUserInfo');
  2178. return false;
  2179. }
  2180. }
  2181. async #followUser(name) {
  2182. try {
  2183. const id = await this.#getUserInfo(name);
  2184. if (!id) {
  2185. return false;
  2186. }
  2187. const logStatus = scripts_echoLog({
  2188. type: 'followingIns',
  2189. text: name
  2190. });
  2191. const {
  2192. result,
  2193. statusText,
  2194. status,
  2195. data
  2196. } = await tools_httpRequest({
  2197. url: `https://www.instagram.com/web/friendships/${id}/follow/`,
  2198. method: 'POST',
  2199. dataType: 'json',
  2200. headers: {
  2201. 'x-csrftoken': this.#auth.csrftoken,
  2202. origin: 'https://www.instagram.com',
  2203. referer: `https://www.instagram.com/${name}/`,
  2204. 'content-type': 'application/x-www-form-urlencoded',
  2205. 'sec-fetch-site': 'same-origin',
  2206. 'x-instagram-ajax': this.#auth.hash
  2207. }
  2208. });
  2209. if (result === 'Success') {
  2210. if (data?.status === 200 && data.response?.result === 'following') {
  2211. logStatus.success();
  2212. this.tasks.users = unique([ ...this.tasks.users, name ]);
  2213. return true;
  2214. }
  2215. logStatus.error(`Error:${data?.response?.feedback_message || `${data?.statusText}(${data?.status})`}`);
  2216. return false;
  2217. }
  2218. logStatus.error(`${result}:${statusText}(${status})`);
  2219. return false;
  2220. } catch (error) {
  2221. throwError(error, 'Instagram.followUser');
  2222. return false;
  2223. }
  2224. }
  2225. async #unfollowUser(name) {
  2226. try {
  2227. if (this.whiteList.users.includes(name)) {
  2228. scripts_echoLog({
  2229. type: 'whiteList',
  2230. text: 'Instagram.unfollowUser',
  2231. id: name
  2232. });
  2233. return true;
  2234. }
  2235. const id = await this.#getUserInfo(name);
  2236. if (!id) {
  2237. return false;
  2238. }
  2239. const logStatus = scripts_echoLog({
  2240. type: 'unfollowingIns',
  2241. text: name
  2242. });
  2243. const {
  2244. result,
  2245. statusText,
  2246. status,
  2247. data
  2248. } = await tools_httpRequest({
  2249. url: `https://www.instagram.com/web/friendships/${id}/unfollow/`,
  2250. method: 'POST',
  2251. dataType: 'json',
  2252. headers: {
  2253. 'x-csrftoken': this.#auth.csrftoken,
  2254. origin: 'https://www.instagram.com',
  2255. referer: `https://www.instagram.com/${name}/`,
  2256. 'content-type': 'application/x-www-form-urlencoded',
  2257. 'sec-fetch-site': 'same-origin',
  2258. 'x-instagram-ajax': this.#auth.hash
  2259. }
  2260. });
  2261. if (result === 'Success') {
  2262. if (data?.status === 200 && data.response?.status === 'ok') {
  2263. logStatus.success();
  2264. return true;
  2265. }
  2266. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2267. return false;
  2268. }
  2269. logStatus.error(`${result}:${statusText}(${status})`);
  2270. return false;
  2271. } catch (error) {
  2272. throwError(error, 'Instagram.unfollowUser');
  2273. return false;
  2274. }
  2275. }
  2276. async toggle({
  2277. doTask = true,
  2278. userLinks = []
  2279. }) {
  2280. try {
  2281. if (!this.#initialized) {
  2282. scripts_echoLog({
  2283. text: i18n('needInit')
  2284. });
  2285. return false;
  2286. }
  2287. const prom = [];
  2288. if (doTask && !globalOptions.doTask.instagram.users || !doTask && !globalOptions.undoTask.instagram.users) {
  2289. scripts_echoLog({
  2290. type: 'globalOptionsSkip',
  2291. text: 'instagram.users'
  2292. });
  2293. } else {
  2294. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1]);
  2295. if (realUsers.length > 0) {
  2296. for (const username of realUsers) {
  2297. if (doTask) {
  2298. prom.push(this.#followUser(username));
  2299. } else {
  2300. prom.push(this.#unfollowUser(username));
  2301. }
  2302. await delay(1e3);
  2303. }
  2304. }
  2305. }
  2306. return await Promise.all(prom).then(() => true);
  2307. } catch (error) {
  2308. throwError(error, 'Instagram.toggleUsers');
  2309. return false;
  2310. }
  2311. }
  2312. #setCache(name, id) {
  2313. try {
  2314. this.#cache[name] = id;
  2315. GM_setValue('instagramCache', this.#cache);
  2316. } catch (error) {
  2317. throwError(error, 'Instagram.setCache');
  2318. }
  2319. }
  2320. }
  2321. const social_Instagram = Instagram;
  2322. class Reddit extends social_Social {
  2323. tasks;
  2324. whiteList;
  2325. #auth;
  2326. #initialized = false;
  2327. constructor() {
  2328. super();
  2329. const defaultTasksTemplate = {
  2330. reddits: []
  2331. };
  2332. this.tasks = defaultTasksTemplate;
  2333. this.whiteList = {
  2334. ...defaultTasksTemplate,
  2335. ...GM_getValue('whiteList')?.reddit || {}
  2336. };
  2337. }
  2338. async init() {
  2339. try {
  2340. if (this.#initialized) {
  2341. return true;
  2342. }
  2343. const isVerified = await this.#updateAuth();
  2344. if (isVerified) {
  2345. scripts_echoLog({}).success(i18n('initSuccess', 'Reddit'));
  2346. this.#initialized = true;
  2347. return true;
  2348. }
  2349. scripts_echoLog({}).error(i18n('initFailed', 'Reddit'));
  2350. return false;
  2351. } catch (error) {
  2352. throwError(error, 'Reddit.init');
  2353. return false;
  2354. }
  2355. }
  2356. async #useBeta() {
  2357. try {
  2358. const logStatus = scripts_echoLog({
  2359. text: i18n('changingRedditVersion')
  2360. });
  2361. GM_setValue('redditAuth', null);
  2362. return await new Promise(resolve => {
  2363. const newTab = GM_openInTab('https://www.reddit.com/#auth', {
  2364. active: true,
  2365. insert: true,
  2366. setParent: true
  2367. });
  2368. newTab.onclose = async () => {
  2369. logStatus.success();
  2370. resolve(await this.#updateAuth(true));
  2371. };
  2372. });
  2373. } catch (error) {
  2374. throwError(error, 'Reddit.useBeta');
  2375. return false;
  2376. }
  2377. }
  2378. async #updateAuth(beta = false) {
  2379. try {
  2380. const logStatus = scripts_echoLog({
  2381. text: i18n('updatingAuth', 'Reddit')
  2382. });
  2383. const {
  2384. result,
  2385. statusText,
  2386. status,
  2387. data
  2388. } = await tools_httpRequest({
  2389. url: 'https://www.reddit.com/',
  2390. method: 'GET',
  2391. nochche: true,
  2392. headers: {
  2393. 'Cache-Control': 'no-cache'
  2394. }
  2395. });
  2396. if (result === 'Success') {
  2397. if (data?.responseText.includes('www.reddit.com/login/')) {
  2398. logStatus.error(`Error:${i18n('loginReddit')}`, true);
  2399. return false;
  2400. }
  2401. if (data?.status === 200) {
  2402. if (data.responseText.includes('redesign-beta-optin-btn') && !beta) {
  2403. return await this.#useBeta();
  2404. }
  2405. const accessToken = data.responseText.match(/"accessToken":"(.*?)","expires":"(.*?)"/)?.[1];
  2406. if (accessToken) {
  2407. this.#auth = {
  2408. token: accessToken
  2409. };
  2410. logStatus.success();
  2411. return true;
  2412. }
  2413. logStatus.error('Error: Parameter "accessToken" not found!');
  2414. return false;
  2415. }
  2416. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2417. return false;
  2418. }
  2419. logStatus.error(`${result}:${statusText}(${status})`);
  2420. return false;
  2421. } catch (error) {
  2422. throwError(error, 'Reddit.updateAuth');
  2423. return false;
  2424. }
  2425. }
  2426. async toggleTask({
  2427. name,
  2428. doTask = true
  2429. }) {
  2430. try {
  2431. if (!doTask && this.whiteList.reddits.includes(name)) {
  2432. scripts_echoLog({
  2433. type: 'whiteList',
  2434. text: 'Reddit.undoTask',
  2435. id: name
  2436. });
  2437. return true;
  2438. }
  2439. let type = doTask ? 'joiningReddit' : 'leavingReddit';
  2440. if (/^u_/.test(name)) {
  2441. type = doTask ? 'followingRedditUser' : 'unfollowingRedditUser';
  2442. }
  2443. const logStatus = scripts_echoLog({
  2444. type: type,
  2445. text: name
  2446. });
  2447. const {
  2448. result,
  2449. statusText,
  2450. status,
  2451. data
  2452. } = await tools_httpRequest({
  2453. url: 'https://oauth.reddit.com/api/subscribe?redditWebClient=desktop2x&app=desktop2x-client-production&raw_json=1&gilding_detail=1',
  2454. method: 'POST',
  2455. headers: {
  2456. authorization: `Bearer ${this.#auth.token}`,
  2457. 'content-type': 'application/x-www-form-urlencoded'
  2458. },
  2459. data: $.param({
  2460. action: doTask ? 'sub' : 'unsub',
  2461. sr_name: name,
  2462. api_type: 'json'
  2463. })
  2464. });
  2465. if (result === 'Success') {
  2466. if (data?.status === 200) {
  2467. logStatus.success();
  2468. if (doTask) {
  2469. this.tasks.reddits = unique([ ...this.tasks.reddits, name ]);
  2470. }
  2471. return true;
  2472. }
  2473. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2474. return false;
  2475. }
  2476. logStatus.error(`${result}:${statusText}(${status})`);
  2477. return false;
  2478. } catch (error) {
  2479. throwError(error, 'Reddit.toggleTask');
  2480. return false;
  2481. }
  2482. }
  2483. async toggle({
  2484. doTask = true,
  2485. redditLinks = []
  2486. }) {
  2487. try {
  2488. if (!this.#initialized) {
  2489. scripts_echoLog({
  2490. text: i18n('needInit')
  2491. });
  2492. return false;
  2493. }
  2494. const prom = [];
  2495. if (doTask && !globalOptions.doTask.reddit.reddits || !doTask && !globalOptions.undoTask.reddit.reddits) {
  2496. scripts_echoLog({
  2497. type: 'globalOptionsSkip',
  2498. text: 'reddit.reddits'
  2499. });
  2500. } else {
  2501. const realReddits = this.getRealParams('reddits', redditLinks, doTask, link => {
  2502. const name = link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1];
  2503. const userName = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1];
  2504. if (userName) {
  2505. return name || userName;
  2506. }
  2507. return name;
  2508. });
  2509. if (realReddits.length > 0) {
  2510. for (const name of realReddits) {
  2511. prom.push(this.toggleTask({
  2512. name: name,
  2513. doTask: doTask
  2514. }));
  2515. await delay(1e3);
  2516. }
  2517. }
  2518. }
  2519. return await Promise.all(prom).then(() => true);
  2520. } catch (error) {
  2521. throwError(error, 'Reddit.toggle');
  2522. return false;
  2523. }
  2524. }
  2525. }
  2526. const social_Reddit = Reddit;
  2527. class Twitch extends social_Social {
  2528. tasks;
  2529. whiteList;
  2530. #auth = GM_getValue('twitchAuth') || {};
  2531. #cache = GM_getValue('twitchCache') || {};
  2532. #initialized = false;
  2533. #integrityToken;
  2534. constructor() {
  2535. super();
  2536. const defaultTasksTemplate = {
  2537. channels: []
  2538. };
  2539. this.tasks = defaultTasksTemplate;
  2540. this.whiteList = {
  2541. ...defaultTasksTemplate,
  2542. ...GM_getValue('whiteList')?.twitch || {}
  2543. };
  2544. }
  2545. async init() {
  2546. try {
  2547. if (this.#initialized) {
  2548. return true;
  2549. }
  2550. if (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId) {
  2551. if (await this.#updateAuth()) {
  2552. this.#initialized = true;
  2553. return true;
  2554. }
  2555. return false;
  2556. }
  2557. const isVerified = await this.#verifyAuth(true);
  2558. if (isVerified) {
  2559. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2560. this.#initialized = true;
  2561. return true;
  2562. }
  2563. GM_setValue('twitchAuth', null);
  2564. if (await this.#updateAuth()) {
  2565. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2566. this.#initialized = true;
  2567. return true;
  2568. }
  2569. scripts_echoLog({}).error(i18n('initFailed', 'Twitch'));
  2570. return false;
  2571. } catch (error) {
  2572. throwError(error, 'Twitch.init');
  2573. return false;
  2574. }
  2575. }
  2576. async #verifyAuth(isFirst) {
  2577. try {
  2578. const logStatus = scripts_echoLog({
  2579. text: i18n('verifyingAuth', 'Twitch')
  2580. });
  2581. const {
  2582. result,
  2583. statusText,
  2584. status,
  2585. data
  2586. } = await tools_httpRequest({
  2587. url: 'https://gql.twitch.tv/gql',
  2588. method: 'POST',
  2589. dataType: 'json',
  2590. headers: {
  2591. Authorization: `OAuth ${this.#auth.authToken}`,
  2592. 'Client-Id': this.#auth.clientId
  2593. },
  2594. data: '[{"operationName":"FrontPageNew_User","variables":{"limit":1},"extensions":{"persistedQuery":{"version":1,' + '"sha256Hash":"64bd07a2cbaca80699d62636d966cf6395a5d14a1f0a14282067dcb28b13eb11"}}}]'
  2595. });
  2596. if (result === 'Success') {
  2597. if (data?.status === 200 && data.response?.[0]?.data?.currentUser) {
  2598. await this.#integrity(isFirst);
  2599. logStatus.success();
  2600. return true;
  2601. }
  2602. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2603. return false;
  2604. }
  2605. logStatus.error(`${result}:${statusText}(${status})`);
  2606. return false;
  2607. } catch (error) {
  2608. throwError(error, 'Twitch.verifyAuth');
  2609. return false;
  2610. }
  2611. }
  2612. async #integrity(isFirst = true, ct = '') {
  2613. try {
  2614. const logStatus = scripts_echoLog({
  2615. text: i18n('checkingTwitchIntegrity')
  2616. });
  2617. if (isFirst && (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId)) {
  2618. return await this.#updateAuth(false);
  2619. }
  2620. const {
  2621. result,
  2622. statusText,
  2623. status,
  2624. data
  2625. } = await tools_httpRequest({
  2626. url: 'https://gql.twitch.tv/integrity',
  2627. method: 'POST',
  2628. dataType: 'json',
  2629. anonymous: true,
  2630. headers: {
  2631. Origin: 'https://www.twitch.tv',
  2632. Referer: 'https://www.twitch.tv/',
  2633. Authorization: `OAuth ${this.#auth.authToken}`,
  2634. 'Client-Id': this.#auth.clientId,
  2635. 'Client-Version': this.#auth.clientVersion,
  2636. 'X-Device-Id': this.#auth.deviceId,
  2637. 'Client-Session-Id': this.#auth.clientSessionId,
  2638. 'x-kpsdk-ct': ct
  2639. }
  2640. });
  2641. if (result === 'Success') {
  2642. if (!ct && data?.responseHeaders?.['x-kpsdk-ct']) {
  2643. return await this.#integrity(isFirst, data.responseHeaders['x-kpsdk-ct']);
  2644. }
  2645. if (data?.status === 200 && data.response?.token) {
  2646. this.#integrityToken = data.response.token;
  2647. logStatus.success();
  2648. return true;
  2649. }
  2650. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2651. return false;
  2652. }
  2653. logStatus.error(`${result}:${statusText}(${status})`);
  2654. return false;
  2655. } catch (error) {
  2656. throwError(error, 'Twitch.integrity');
  2657. return false;
  2658. }
  2659. }
  2660. async #updateAuth(isFirst = true) {
  2661. try {
  2662. const logStatus = scripts_echoLog({
  2663. text: i18n('updatingAuth', 'Twitch')
  2664. });
  2665. return await new Promise(resolve => {
  2666. const newTab = GM_openInTab('https://www.twitch.tv/#auth', {
  2667. active: true,
  2668. insert: true,
  2669. setParent: true
  2670. });
  2671. newTab.onclose = async () => {
  2672. const auth = GM_getValue('twitchAuth');
  2673. if (auth) {
  2674. this.#auth = auth;
  2675. logStatus.success();
  2676. resolve(await this.#verifyAuth(isFirst));
  2677. } else {
  2678. logStatus.error('Error: Update twitch auth failed!');
  2679. resolve(false);
  2680. }
  2681. };
  2682. });
  2683. } catch (error) {
  2684. throwError(error, 'Twitch.updateAuth');
  2685. return false;
  2686. }
  2687. }
  2688. async #toggleChannel({
  2689. name,
  2690. doTask = true
  2691. }) {
  2692. try {
  2693. if (!doTask && this.whiteList.channels.includes(name)) {
  2694. scripts_echoLog({
  2695. type: 'whiteList',
  2696. text: 'Twitch.unfollowChannel',
  2697. id: name
  2698. });
  2699. return true;
  2700. }
  2701. const channelId = await this.#getChannelId(name);
  2702. if (!channelId) {
  2703. return false;
  2704. }
  2705. const logStatus = scripts_echoLog({
  2706. type: `${doTask ? '' : 'un'}followingTwitchChannel`,
  2707. text: name
  2708. });
  2709. const followData = `[{"operationName":"FollowButton_FollowUser","variables":{"input":{"disableNotifications":false,"targetID":"${channelId}` + '"}},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"800e7346bdf7e5278a3c1d3f21b2b56e2639928f86815677a7126b093b2fdd08"}}}]';
  2710. const unfollowData = `[{"operationName":"FollowButton_UnfollowUser","variables":{"input":{"targetID":"${channelId}"}},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"f7dae976ebf41c755ae2d758546bfd176b4eeb856656098bb40e0a672ca0d880"}}}]';
  2711. const {
  2712. result,
  2713. statusText,
  2714. status,
  2715. data
  2716. } = await tools_httpRequest({
  2717. url: 'https://gql.twitch.tv/gql',
  2718. method: 'POST',
  2719. dataType: 'json',
  2720. anonymous: true,
  2721. headers: {
  2722. Origin: 'https://www.twitch.tv',
  2723. Referer: 'https://www.twitch.tv/',
  2724. Authorization: `OAuth ${this.#auth.authToken}`,
  2725. 'Client-Id': this.#auth.clientId,
  2726. 'Client-Version': this.#auth.clientVersion,
  2727. 'X-Device-Id': this.#auth.deviceId,
  2728. 'Client-Session-Id': this.#auth.clientSessionId,
  2729. 'Client-Integrity': this.#integrityToken
  2730. },
  2731. data: doTask ? followData : unfollowData
  2732. });
  2733. if (result === 'Success') {
  2734. if (data?.status === 200 && data.response?.[0] && !data.response[0].errors) {
  2735. logStatus.success();
  2736. if (doTask) {
  2737. this.tasks.channels = unique([ ...this.tasks.channels, name ]);
  2738. }
  2739. return true;
  2740. }
  2741. logStatus.error(`Error:${data?.response?.[0].errors?.[0]?.message || `${data?.statusText}(${data?.status})`}`);
  2742. return false;
  2743. }
  2744. logStatus.error(`${result}:${statusText}(${status})`);
  2745. return false;
  2746. } catch (error) {
  2747. throwError(error, 'Twitch.toggleChannel');
  2748. return false;
  2749. }
  2750. }
  2751. async #getChannelId(name) {
  2752. try {
  2753. const logStatus = scripts_echoLog({
  2754. type: 'gettingTwitchChannelId',
  2755. text: name
  2756. });
  2757. const channelId = this.#cache[name];
  2758. if (channelId) {
  2759. logStatus.success();
  2760. return channelId;
  2761. }
  2762. const {
  2763. result,
  2764. statusText,
  2765. status,
  2766. data
  2767. } = await tools_httpRequest({
  2768. url: 'https://gql.twitch.tv/gql',
  2769. method: 'POST',
  2770. headers: {
  2771. Authorization: `OAuth ${this.#auth.authToken}`,
  2772. 'Client-Id': this.#auth.clientId
  2773. },
  2774. responseType: 'json',
  2775. data: `[{"operationName":"ActiveWatchParty","variables":{"channelLogin":"${name}"},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"4a8156c97b19e3a36e081cf6d6ddb5dbf9f9b02ae60e4d2ff26ed70aebc80a30"}}}]'
  2776. });
  2777. if (result === 'Success') {
  2778. if (data?.status === 200) {
  2779. const channelId = data.response?.[0]?.data?.user?.id;
  2780. if (channelId) {
  2781. this.#setCache(name, String(channelId));
  2782. logStatus.success();
  2783. return channelId;
  2784. }
  2785. logStatus.error(`Error:${data.statusText}(${data.status})`);
  2786. return false;
  2787. }
  2788. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2789. return false;
  2790. }
  2791. logStatus.error(`${result}:${statusText}(${status})`);
  2792. return false;
  2793. } catch (error) {
  2794. throwError(error, 'Twitch.getChannelId');
  2795. return false;
  2796. }
  2797. }
  2798. async toggle({
  2799. doTask = true,
  2800. channelLinks = []
  2801. }) {
  2802. try {
  2803. if (!this.#initialized) {
  2804. scripts_echoLog({
  2805. text: i18n('needInit')
  2806. });
  2807. return false;
  2808. }
  2809. const prom = [];
  2810. if (doTask && !globalOptions.doTask.twitch.channels || !doTask && !globalOptions.undoTask.twitch.channels) {
  2811. scripts_echoLog({
  2812. type: 'globalOptionsSkip',
  2813. text: 'twitch.channels'
  2814. });
  2815. } else {
  2816. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2]);
  2817. if (realChannels.length > 0) {
  2818. for (const channel of realChannels) {
  2819. prom.push(this.#toggleChannel({
  2820. name: channel,
  2821. doTask: doTask
  2822. }));
  2823. await delay(1e3);
  2824. }
  2825. }
  2826. }
  2827. return Promise.all(prom).then(() => true);
  2828. } catch (error) {
  2829. throwError(error, 'Twitch.toggle');
  2830. return false;
  2831. }
  2832. }
  2833. #setCache(name, id) {
  2834. try {
  2835. this.#cache[name] = id;
  2836. GM_setValue('twitchCache', this.#cache);
  2837. } catch (error) {
  2838. throwError(error, 'Twitch.setCache');
  2839. }
  2840. }
  2841. }
  2842. const social_Twitch = Twitch;
  2843. class Twitter extends social_Social {
  2844. tasks;
  2845. whiteList;
  2846. #verifyId = globalOptions.other.twitterVerifyId;
  2847. #auth = GM_getValue('twitterAuth') || {};
  2848. #cache = GM_getValue('twitterCache') || {};
  2849. #initialized = false;
  2850. constructor() {
  2851. super();
  2852. const defaultTasksTemplate = {
  2853. users: [],
  2854. retweets: [],
  2855. likes: []
  2856. };
  2857. this.tasks = defaultTasksTemplate;
  2858. this.whiteList = {
  2859. ...defaultTasksTemplate,
  2860. ...GM_getValue('whiteList')?.twitter || {}
  2861. };
  2862. }
  2863. async init() {
  2864. try {
  2865. if (this.#initialized) {
  2866. return true;
  2867. }
  2868. if (!this.#auth.ct0) {
  2869. if (await this.#updateAuth()) {
  2870. this.#initialized = true;
  2871. return true;
  2872. }
  2873. return false;
  2874. }
  2875. const isVerified = await this.#verifyAuth();
  2876. if (isVerified) {
  2877. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2878. this.#initialized = true;
  2879. return true;
  2880. }
  2881. GM_setValue('twitterAuth', null);
  2882. if (await this.#updateAuth()) {
  2883. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2884. this.#initialized = true;
  2885. return true;
  2886. }
  2887. scripts_echoLog({}).error(i18n('initFailed', 'Twitter'));
  2888. return false;
  2889. } catch (error) {
  2890. throwError(error, 'Twitter.init');
  2891. return false;
  2892. }
  2893. }
  2894. async #verifyAuth() {
  2895. try {
  2896. return await this.#toggleUser({
  2897. name: 'verify',
  2898. doTask: true,
  2899. verify: true
  2900. });
  2901. } catch (error) {
  2902. throwError(error, 'Twitter.verifyAuth');
  2903. return false;
  2904. }
  2905. }
  2906. async #updateAuth() {
  2907. try {
  2908. const logStatus = scripts_echoLog({
  2909. text: i18n('updatingAuth', 'Twitter')
  2910. });
  2911. return await new Promise(resolve => {
  2912. GM_cookie.list({
  2913. url: 'https://x.com/settings/account'
  2914. }, async (cookies, error) => {
  2915. if (!error) {
  2916. const [ ct0, isLogin ] = cookies.map(cookie => [ 'ct0', 'twid' ].includes(cookie.name) ? cookie.value : null).filter(cookie => cookie);
  2917. if (isLogin && ct0) {
  2918. GM_setValue('twitterAuth', {
  2919. ct0: ct0
  2920. });
  2921. this.#auth = {
  2922. ct0: ct0
  2923. };
  2924. logStatus.success();
  2925. resolve(await this.#verifyAuth());
  2926. } else {
  2927. logStatus.error(i18n('needLogin'));
  2928. resolve(false);
  2929. }
  2930. } else {
  2931. logStatus.error('Error: Update twitter auth failed!');
  2932. resolve(false);
  2933. }
  2934. });
  2935. });
  2936. } catch (error) {
  2937. throwError(error, 'Twitter.updateToken');
  2938. return false;
  2939. }
  2940. }
  2941. async #toggleUser({
  2942. name,
  2943. doTask = true,
  2944. verify = false
  2945. }) {
  2946. try {
  2947. if (!doTask && !verify && this.whiteList.users.includes(name)) {
  2948. scripts_echoLog({
  2949. type: 'whiteList',
  2950. text: 'Twitter.unfollowUser',
  2951. id: name
  2952. });
  2953. return true;
  2954. }
  2955. const userId = verify ? this.#verifyId : await this.userName2id(name);
  2956. if (!userId) {
  2957. return false;
  2958. }
  2959. const logStatus = verify ? scripts_echoLog({
  2960. text: i18n('verifyingAuth', 'Twitter')
  2961. }) : scripts_echoLog({
  2962. type: `${doTask ? '' : 'un'}followingTwitterUser`,
  2963. text: name
  2964. });
  2965. const {
  2966. result,
  2967. statusText,
  2968. status,
  2969. data
  2970. } = await tools_httpRequest({
  2971. url: `https://x.com/i/api/1.1/friendships/${doTask ? 'create' : 'destroy'}.json`,
  2972. method: 'POST',
  2973. headers: {
  2974. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  2975. 'Content-Type': 'application/x-www-form-urlencoded',
  2976. 'x-csrf-token': this.#auth.ct0
  2977. },
  2978. responseType: 'json',
  2979. data: $.param({
  2980. include_profile_interstitial_type: 1,
  2981. include_blocking: 1,
  2982. include_blocked_by: 1,
  2983. include_followed_by: 1,
  2984. include_want_retweets: 1,
  2985. include_mute_edge: 1,
  2986. include_can_dm: 1,
  2987. include_can_media_tag: 1,
  2988. skip_status: 1,
  2989. id: userId
  2990. })
  2991. });
  2992. if (result === 'Success') {
  2993. if (data?.status === 200) {
  2994. logStatus.success();
  2995. if (doTask && !verify) {
  2996. this.tasks.users = unique([ ...this.tasks.users, name ]);
  2997. }
  2998. return true;
  2999. }
  3000. if (verify && data?.status === 403 && data.response?.errors?.[0]?.code === 158) {
  3001. logStatus.success();
  3002. return true;
  3003. }
  3004. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3005. return false;
  3006. }
  3007. logStatus.error(`${result}:${statusText}(${status})`);
  3008. return false;
  3009. } catch (error) {
  3010. throwError(error, 'Twitter.toggleUser');
  3011. return false;
  3012. }
  3013. }
  3014. async userName2id(name) {
  3015. try {
  3016. const logStatus = scripts_echoLog({
  3017. type: 'gettingTwitterUserId',
  3018. text: name
  3019. });
  3020. const userId = this.#cache[name];
  3021. if (userId) {
  3022. logStatus.success();
  3023. return userId;
  3024. }
  3025. const {
  3026. result,
  3027. statusText,
  3028. status,
  3029. data
  3030. } = await tools_httpRequest({
  3031. url: 'https://x.com/i/api/graphql/mCbpQvZAw6zu_4PvuAUVVQ/UserByScreenName' + `?variables=%7B%22screen_name%22%3A%22${name}%22%2C%22withSafetyModeUserFields%22%3Atrue%2C%22withSuperFollowsUserFields%22%3Atrue%7D`,
  3032. method: 'GET',
  3033. headers: {
  3034. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3035. 'content-type': 'application/json',
  3036. referer: `https://x.com/${name}`,
  3037. 'x-csrf-token': this.#auth.ct0
  3038. },
  3039. responseType: 'json'
  3040. });
  3041. if (result === 'Success') {
  3042. if (data?.status === 200) {
  3043. let response = data.response || (typeof data.responseText === 'object' ? data.responseText : null);
  3044. if (!response) {
  3045. try {
  3046. response = JSON.parse(data.responseText);
  3047. } catch (error) {
  3048. response = null;
  3049. }
  3050. }
  3051. const userId = String(response?.data?.user?.result?.rest_id);
  3052. if (userId) {
  3053. this.#setCache(name, userId);
  3054. logStatus.success();
  3055. return userId;
  3056. }
  3057. logStatus.error(`Error:${data.statusText}(${data.status})`);
  3058. return false;
  3059. }
  3060. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3061. return false;
  3062. }
  3063. logStatus.error(`${result}:${statusText}(${status})`);
  3064. return false;
  3065. } catch (error) {
  3066. throwError(error, 'Twitter.getUserId');
  3067. return false;
  3068. }
  3069. }
  3070. async #toggleRetweet({
  3071. retweetId,
  3072. doTask = true
  3073. }) {
  3074. try {
  3075. if (!doTask && this.whiteList.retweets.includes(retweetId)) {
  3076. scripts_echoLog({
  3077. type: 'whiteList',
  3078. text: 'Twitter.unretweet',
  3079. id: retweetId
  3080. });
  3081. return true;
  3082. }
  3083. const logStatus = scripts_echoLog({
  3084. type: `${doTask ? '' : 'un'}retweetting`,
  3085. text: retweetId
  3086. });
  3087. const {
  3088. result,
  3089. statusText,
  3090. status,
  3091. data
  3092. } = await tools_httpRequest({
  3093. url: `https://x.com/i/api/1.1/statuses/${doTask ? '' : 'un'}retweet.json`,
  3094. method: 'POST',
  3095. headers: {
  3096. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3097. 'Content-Type': 'application/x-www-form-urlencoded',
  3098. 'x-csrf-token': this.#auth.ct0
  3099. },
  3100. data: $.param({
  3101. tweet_mode: 'extended',
  3102. id: retweetId
  3103. }),
  3104. responseType: 'json'
  3105. });
  3106. if (result === 'Success') {
  3107. if (data?.status === 200 || data?.status === 403 && data.response?.errors?.[0]?.code === 327) {
  3108. logStatus.success();
  3109. if (doTask) {
  3110. this.tasks.retweets = unique([ ...this.tasks.retweets, retweetId ]);
  3111. }
  3112. return true;
  3113. }
  3114. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3115. return false;
  3116. }
  3117. logStatus.error(`${result}:${statusText}(${status})`);
  3118. return false;
  3119. } catch (error) {
  3120. throwError(error, 'Twitter.toggleRetweet');
  3121. return false;
  3122. }
  3123. }
  3124. async toggle({
  3125. doTask = true,
  3126. userLinks = [],
  3127. retweetLinks = []
  3128. }) {
  3129. try {
  3130. if (!this.#initialized) {
  3131. scripts_echoLog({
  3132. text: i18n('needInit')
  3133. });
  3134. return false;
  3135. }
  3136. const prom = [];
  3137. if (doTask && !globalOptions.doTask.twitter.users || !doTask && !globalOptions.undoTask.twitter.users) {
  3138. scripts_echoLog({
  3139. type: 'globalOptionsSkip',
  3140. text: 'twitter.users'
  3141. });
  3142. } else {
  3143. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/x\.com\/(.+)/)?.[1]);
  3144. if (realUsers.length > 0) {
  3145. for (const user of realUsers) {
  3146. prom.push(this.#toggleUser({
  3147. name: user,
  3148. doTask: doTask
  3149. }));
  3150. await delay(1e3);
  3151. }
  3152. }
  3153. }
  3154. if (doTask && !globalOptions.doTask.twitter.retweets || !doTask && !globalOptions.undoTask.twitter.retweets) {
  3155. scripts_echoLog({
  3156. type: 'globalOptionsSkip',
  3157. text: 'twitter.retweets'
  3158. });
  3159. } else {
  3160. const realRetweets = this.getRealParams('retweets', retweetLinks, doTask, link => link.match(/https:\/\/x\.com\/.*?\/status\/([\d]+)/)?.[1]);
  3161. if (realRetweets.length > 0) {
  3162. for (const retweet of realRetweets) {
  3163. prom.push(this.#toggleRetweet({
  3164. retweetId: retweet,
  3165. doTask: doTask
  3166. }));
  3167. await delay(1e3);
  3168. }
  3169. }
  3170. }
  3171. return Promise.all(prom).then(() => true);
  3172. } catch (error) {
  3173. throwError(error, 'Twitter.toggle');
  3174. return false;
  3175. }
  3176. }
  3177. #setCache(name, id) {
  3178. try {
  3179. this.#cache[name] = id;
  3180. GM_setValue('twitterCache', this.#cache);
  3181. } catch (error) {
  3182. throwError(error, 'Twitter.setCache');
  3183. }
  3184. }
  3185. }
  3186. const social_Twitter = Twitter;
  3187. class Vk extends social_Social {
  3188. tasks;
  3189. whiteList;
  3190. #username = '';
  3191. #cache = GM_getValue('vkCache') || {};
  3192. #initialized = false;
  3193. constructor() {
  3194. super();
  3195. const defaultTasksTemplate = {
  3196. names: []
  3197. };
  3198. this.tasks = defaultTasksTemplate;
  3199. this.whiteList = {
  3200. ...defaultTasksTemplate,
  3201. ...GM_getValue('whiteList')?.vk || {}
  3202. };
  3203. }
  3204. async init() {
  3205. try {
  3206. if (this.#initialized) {
  3207. return true;
  3208. }
  3209. const isVerified = await this.#verifyAuth();
  3210. if (isVerified) {
  3211. scripts_echoLog({}).success(i18n('initSuccess', 'Vk'));
  3212. this.#initialized = true;
  3213. return true;
  3214. }
  3215. scripts_echoLog({}).error(i18n('initFailed', 'Vk'));
  3216. return false;
  3217. } catch (error) {
  3218. throwError(error, 'Vk.init');
  3219. return false;
  3220. }
  3221. }
  3222. async #verifyAuth() {
  3223. try {
  3224. const logStatus = scripts_echoLog({
  3225. text: i18n('verifyAuth', 'Vk')
  3226. });
  3227. const {
  3228. result,
  3229. statusText,
  3230. status,
  3231. data
  3232. } = await tools_httpRequest({
  3233. url: 'https://vk.com/im',
  3234. method: 'GET'
  3235. });
  3236. if (result === 'Success') {
  3237. if (data?.finalUrl.includes('vk.com/login')) {
  3238. logStatus.error(`Error:${i18n('loginVk')}`, true);
  3239. return false;
  3240. }
  3241. if (data?.status === 200) {
  3242. this.#username = data.responseText.match(/TopNavBtn__profileLink" href="\/(.*?)"/)?.[1] || '';
  3243. logStatus.success();
  3244. return true;
  3245. }
  3246. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3247. return false;
  3248. }
  3249. logStatus.error(`${result}:${statusText}(${status})`);
  3250. return false;
  3251. } catch (error) {
  3252. throwError(error, 'Vk.verifyAuth');
  3253. return false;
  3254. }
  3255. }
  3256. async #toggleGroup(name, dataParam, doTask = true) {
  3257. try {
  3258. const logStatus = scripts_echoLog({
  3259. type: doTask ? 'joiningVkGroup' : 'leavingVkGroup',
  3260. text: name
  3261. });
  3262. if (dataParam.groupAct === 'enter' && !doTask || dataParam.groupAct === 'leave' && doTask) {
  3263. logStatus.success();
  3264. return true;
  3265. }
  3266. const reqData = {
  3267. act: doTask ? 'enter' : 'leave',
  3268. al: 1,
  3269. gid: dataParam.groupId,
  3270. hash: dataParam.groupHash
  3271. };
  3272. if (doTask) {
  3273. reqData.context = '_';
  3274. }
  3275. const {
  3276. result,
  3277. statusText,
  3278. status,
  3279. data
  3280. } = await tools_httpRequest({
  3281. url: 'https://vk.com/al_groups.php',
  3282. method: 'POST',
  3283. headers: {
  3284. origin: 'https://vk.com',
  3285. referer: `https://vk.com/${name}`,
  3286. 'content-type': 'application/x-www-form-urlencoded'
  3287. },
  3288. data: $.param(reqData)
  3289. });
  3290. if (result === 'Success') {
  3291. if (data?.status === 200) {
  3292. logStatus.success();
  3293. if (doTask) {
  3294. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3295. }
  3296. return true;
  3297. }
  3298. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3299. return false;
  3300. }
  3301. logStatus.error(`${result}:${statusText}(${status})`);
  3302. return false;
  3303. } catch (error) {
  3304. throwError(error, 'Vk.toggleGroup');
  3305. return false;
  3306. }
  3307. }
  3308. async #togglePublic(name, dataParam, doTask = true) {
  3309. try {
  3310. const logStatus = scripts_echoLog({
  3311. type: doTask ? 'joiningVkPublic' : 'leavingVkPublic',
  3312. text: name
  3313. });
  3314. if (dataParam.publicJoined && doTask || !dataParam.publicJoined && !doTask) {
  3315. logStatus.success();
  3316. return true;
  3317. }
  3318. const {
  3319. result,
  3320. statusText,
  3321. status,
  3322. data
  3323. } = await tools_httpRequest({
  3324. url: 'https://vk.com/al_public.php',
  3325. method: 'POST',
  3326. headers: {
  3327. origin: 'https://vk.com',
  3328. referer: `https://vk.com/${name}`,
  3329. 'content-type': 'application/x-www-form-urlencoded'
  3330. },
  3331. data: $.param({
  3332. act: doTask ? 'a_enter' : 'a_leave',
  3333. al: 1,
  3334. pid: dataParam.publicPid,
  3335. hash: dataParam.publicHash
  3336. })
  3337. });
  3338. if (result === 'Success') {
  3339. if (data?.status === 200) {
  3340. logStatus.success();
  3341. if (doTask) {
  3342. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3343. }
  3344. return true;
  3345. }
  3346. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3347. return false;
  3348. }
  3349. logStatus.error(`${result}:${statusText}(${status})`);
  3350. return false;
  3351. } catch (error) {
  3352. throwError(error, 'Vk.togglePublic');
  3353. return false;
  3354. }
  3355. }
  3356. async #sendWall(name) {
  3357. try {
  3358. const logStatus = scripts_echoLog({
  3359. type: 'sendingVkWall',
  3360. text: name
  3361. });
  3362. const {
  3363. result,
  3364. statusText,
  3365. status,
  3366. data
  3367. } = await tools_httpRequest({
  3368. url: 'https://vk.com/like.php',
  3369. method: 'POST',
  3370. headers: {
  3371. origin: 'https://vk.com',
  3372. referer: `https://vk.com/${name}`,
  3373. 'content-type': 'application/x-www-form-urlencoded'
  3374. },
  3375. data: $.param({
  3376. act: 'publish_box',
  3377. al: 1,
  3378. object: name
  3379. })
  3380. });
  3381. if (result === 'Success') {
  3382. if (data?.status === 200) {
  3383. const hash = data.responseText.match(/shHash:[\s]*'(.*?)'/)?.[1];
  3384. if (hash) {
  3385. const {
  3386. result: resultR,
  3387. statusText: statusTextR,
  3388. status: statusR,
  3389. data: dataR
  3390. } = await tools_httpRequest({
  3391. url: 'https://vk.com/like.php',
  3392. method: 'POST',
  3393. headers: {
  3394. origin: 'https://vk.com',
  3395. referer: `https://vk.com/${name}`,
  3396. 'content-type': 'application/x-www-form-urlencoded'
  3397. },
  3398. data: $.param({
  3399. Message: '',
  3400. act: 'a_do_publish',
  3401. al: 1,
  3402. close_comments: 0,
  3403. friends_only: 0,
  3404. from: 'box',
  3405. hash: hash,
  3406. list: '',
  3407. mark_as_ads: 0,
  3408. mute_notifications: 0,
  3409. object: name,
  3410. ret_data: 1,
  3411. to: 0
  3412. })
  3413. });
  3414. if (resultR === 'Success') {
  3415. if (dataR?.status === 200) {
  3416. const jsonData = JSON.parse(dataR.responseText?.replace('\x3c!--', '') || '{}');
  3417. if (jsonData?.payload?.[1]?.[1]?.share_my === true) {
  3418. logStatus.success();
  3419. const postId = String(jsonData?.payload?.[1]?.[1]?.post_id);
  3420. const ownerId = String(jsonData?.payload?.[1]?.[1]?.owner_id);
  3421. if (postId && ownerId) {
  3422. this.#setCache(name, `${ownerId}_${postId}`);
  3423. }
  3424. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3425. return true;
  3426. }
  3427. }
  3428. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  3429. return false;
  3430. }
  3431. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  3432. return false;
  3433. }
  3434. logStatus.error('Error: Get "hash" failed');
  3435. return false;
  3436. }
  3437. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3438. return false;
  3439. }
  3440. logStatus.error(`${result}:${statusText}(${status})`);
  3441. return false;
  3442. } catch (error) {
  3443. throwError(error, 'Vk.sendWall');
  3444. return false;
  3445. }
  3446. }
  3447. async #deleteWall(name, dataParams) {
  3448. try {
  3449. const logStatus = scripts_echoLog({
  3450. type: 'deletingVkWall',
  3451. text: name
  3452. });
  3453. const {
  3454. result,
  3455. statusText,
  3456. status,
  3457. data
  3458. } = await tools_httpRequest({
  3459. url: 'https://vk.com/al_wall.php?act=delete',
  3460. method: 'POST',
  3461. headers: {
  3462. origin: 'https://vk.com',
  3463. referer: `https://vk.com/${this.#username}?w=wall${this.#cache[name]}%2Fall`,
  3464. 'content-type': 'application/x-www-form-urlencoded'
  3465. },
  3466. data: $.param({
  3467. act: 'delete',
  3468. al: 1,
  3469. confirm: 0,
  3470. from: 'wkview',
  3471. hash: dataParams.wallHash,
  3472. post: this.#cache[name]
  3473. })
  3474. });
  3475. if (result === 'Success') {
  3476. if (data?.status === 200) {
  3477. const jsonData = JSON.parse(data.responseText?.replace('\x3c!--', '') || '{}');
  3478. if (jsonData?.payload?.[1]?.[1]) {
  3479. logStatus.success();
  3480. return true;
  3481. }
  3482. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3483. return false;
  3484. }
  3485. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3486. return false;
  3487. }
  3488. logStatus.error(`${result}:${statusText}(${status})`);
  3489. return false;
  3490. } catch (error) {
  3491. throwError(error, 'Vk.deleteWall');
  3492. return false;
  3493. }
  3494. }
  3495. async #getId(name, doTask) {
  3496. try {
  3497. let url = `https://vk.com/${name}`;
  3498. if (/^wall-/.test(name)) {
  3499. if (doTask) {
  3500. return {
  3501. type: 'sendWall'
  3502. };
  3503. }
  3504. if (!this.#cache[name]) {
  3505. return {
  3506. type: 'unSupport'
  3507. };
  3508. }
  3509. url = `https://vk.com/${this.#username}?w=wall${this.#cache[name]}`;
  3510. }
  3511. const logStatus = scripts_echoLog({
  3512. type: 'gettingVkId',
  3513. text: name
  3514. });
  3515. const {
  3516. result,
  3517. statusText,
  3518. status,
  3519. data
  3520. } = await tools_httpRequest({
  3521. url: url,
  3522. method: 'GET'
  3523. });
  3524. if (result === 'Success') {
  3525. if (data?.status === 200) {
  3526. const [ , groupAct, groupId, , groupHash ] = data.responseText.match(/Groups.(enter|leave)\(.*?,.*?([\d]+?), (&#39;|')(.*?)(&#39;|')/) || [];
  3527. const publicHash = data.responseText.match(/"enterHash":"(.*?)"/)?.[1];
  3528. const publicPid = data.responseText.match(/"public_id":([\d]+?),/)?.[1];
  3529. const publicJoined = !data.responseText.includes('Public.subscribe');
  3530. if (groupAct && groupId && groupHash) {
  3531. logStatus.success();
  3532. return {
  3533. groupAct: groupAct,
  3534. groupId: groupId,
  3535. groupHash: groupHash,
  3536. type: 'group'
  3537. };
  3538. } else if (publicHash && publicPid) {
  3539. logStatus.success();
  3540. return {
  3541. publicHash: publicHash,
  3542. publicPid: publicPid,
  3543. publicJoined: publicJoined,
  3544. type: 'public'
  3545. };
  3546. } else if (data.responseText.includes('wall.deletePost') && !doTask) {
  3547. const wallHash = data.responseText.match(/wall\.deletePost\(this, '.*?', '(.*?)'\)/)?.[1];
  3548. if (wallHash) {
  3549. logStatus.success();
  3550. return {
  3551. type: 'deleteWall',
  3552. wallHash: wallHash
  3553. };
  3554. }
  3555. } else if (name.includes('wall') && doTask) {
  3556. logStatus.success();
  3557. return {
  3558. type: 'sendWall'
  3559. };
  3560. }
  3561. logStatus.error('Error: Parameters not found!');
  3562. return false;
  3563. }
  3564. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3565. return false;
  3566. }
  3567. logStatus.error(`${result}:${statusText}(${status})`);
  3568. return false;
  3569. } catch (error) {
  3570. throwError(error, 'Vk.getId');
  3571. return false;
  3572. }
  3573. }
  3574. async #toggleVk({
  3575. name,
  3576. doTask = true
  3577. }) {
  3578. try {
  3579. if (!doTask && this.whiteList.names.includes(name)) {
  3580. scripts_echoLog({
  3581. type: 'whiteList',
  3582. text: 'Vk.undoTask',
  3583. id: name
  3584. });
  3585. return true;
  3586. }
  3587. const formatName = name.replace(/\/$/, '');
  3588. const data = await this.#getId(formatName, doTask);
  3589. if (!data) {
  3590. return false;
  3591. }
  3592. switch (data.type) {
  3593. case 'group':
  3594. return await this.#toggleGroup(formatName, data, doTask);
  3595.  
  3596. case 'public':
  3597. return await this.#togglePublic(formatName, data, doTask);
  3598.  
  3599. case 'sendWall':
  3600. return doTask ? await this.#sendWall(formatName) : true;
  3601.  
  3602. case 'deleteWall':
  3603. return doTask ? true : await this.#deleteWall(formatName, data);
  3604.  
  3605. default:
  3606. return false;
  3607. }
  3608. } catch (error) {
  3609. throwError(error, 'Vk.toggleVk');
  3610. return false;
  3611. }
  3612. }
  3613. async toggle({
  3614. doTask = true,
  3615. nameLinks = []
  3616. }) {
  3617. try {
  3618. if (!this.#initialized) {
  3619. scripts_echoLog({
  3620. text: i18n('needInit')
  3621. });
  3622. return false;
  3623. }
  3624. const prom = [];
  3625. if (doTask && !globalOptions.doTask.vk.names || !doTask && !globalOptions.undoTask.vk.names) {
  3626. scripts_echoLog({
  3627. type: 'globalOptionsSkip',
  3628. text: 'vk.names'
  3629. });
  3630. } else {
  3631. const realNames = this.getRealParams('names', nameLinks, doTask, link => link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1]);
  3632. if (realNames.length > 0) {
  3633. for (const name of realNames) {
  3634. prom.push(this.#toggleVk({
  3635. name: name,
  3636. doTask: doTask
  3637. }));
  3638. await delay(1e3);
  3639. }
  3640. }
  3641. }
  3642. return Promise.all(prom).then(() => true);
  3643. } catch (error) {
  3644. throwError(error, 'Vk.toggle');
  3645. return false;
  3646. }
  3647. }
  3648. #setCache(name, postId) {
  3649. try {
  3650. this.#cache[name] = postId;
  3651. GM_setValue('vkCache', this.#cache);
  3652. } catch (error) {
  3653. throwError(error, 'Vk.setCache');
  3654. }
  3655. }
  3656. }
  3657. const social_Vk = Vk;
  3658. const getInfo = async function(link, type) {
  3659. try {
  3660. const logStatus = scripts_echoLog({
  3661. text: i18n('gettingYtbToken')
  3662. });
  3663. const {
  3664. result,
  3665. statusText,
  3666. status,
  3667. data
  3668. } = await tools_httpRequest({
  3669. url: link,
  3670. method: 'GET'
  3671. });
  3672. if (result === 'Success') {
  3673. if (data?.status === 200) {
  3674. if (data.responseText.includes('accounts.google.com/ServiceLogin?service=youtube')) {
  3675. logStatus.error(`Error:${i18n('loginYtb')}`, true);
  3676. return {
  3677. needLogin: true
  3678. };
  3679. }
  3680. const apiKey = data.responseText.match(/"INNERTUBE_API_KEY":"(.*?)"/)?.[1];
  3681. const context = (data.responseText.match(/\(\{"INNERTUBE_CONTEXT":([\w\W]*?)\}\)/) || data.responseText.match(/"INNERTUBE_CONTEXT":([\w\W]*?\}),"INNERTUBE/))?.[1] || '{}';
  3682. const {
  3683. client,
  3684. request
  3685. } = JSON.parse(context);
  3686. if (apiKey && client && request) {
  3687. client.hl = 'en';
  3688. if (type === 'channel') {
  3689. const channelId = data.responseText.match(/"channelId":"(.+?)"/)?.[1];
  3690. if (channelId) {
  3691. logStatus.success();
  3692. return {
  3693. params: {
  3694. apiKey: apiKey,
  3695. client: client,
  3696. request: request,
  3697. channelId: channelId
  3698. }
  3699. };
  3700. }
  3701. logStatus.error('Error: Get "channelId" failed!');
  3702. return {};
  3703. } else if (type === 'likeVideo') {
  3704. const videoId = data.responseText.match(/<link rel="shortlinkUrl" href="https:\/\/youtu\.be\/(.*?)">/)?.[1];
  3705. const likeParams = data.responseText.match(/"likeParams":"(.*?)"/)?.[1];
  3706. if (videoId) {
  3707. logStatus.success();
  3708. return {
  3709. params: {
  3710. apiKey: apiKey,
  3711. client: client,
  3712. request: request,
  3713. videoId: videoId,
  3714. likeParams: likeParams
  3715. }
  3716. };
  3717. }
  3718. logStatus.error('Error: Get "videoId" failed!');
  3719. return {};
  3720. }
  3721. logStatus.error('Error: Unknown type');
  3722. return {};
  3723. }
  3724. logStatus.error('Error: Parameter "apiKey" not found!');
  3725. return {};
  3726. }
  3727. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3728. return {};
  3729. }
  3730. logStatus.error(`${result}:${statusText}(${status})`);
  3731. return {};
  3732. } catch (error) {
  3733. throwError(error, 'Youtube.getInfo');
  3734. return {};
  3735. }
  3736. };
  3737. class Youtube extends social_Social {
  3738. tasks;
  3739. whiteList;
  3740. #auth = GM_getValue('youtubeAuth') || {};
  3741. #initialized = false;
  3742. #verifyChannel = `https://www.youtube.com/channel/${globalOptions.other.youtubeVerifyChannel}`;
  3743. constructor() {
  3744. super();
  3745. const defaultTasksTemplate = {
  3746. channels: [],
  3747. likes: []
  3748. };
  3749. this.tasks = defaultTasksTemplate;
  3750. this.whiteList = {
  3751. ...defaultTasksTemplate,
  3752. ...GM_getValue('whiteList')?.youtube || {}
  3753. };
  3754. }
  3755. async init() {
  3756. try {
  3757. if (this.#initialized) {
  3758. return true;
  3759. }
  3760. if (!this.#auth.PAPISID) {
  3761. if (await this.#updateAuth()) {
  3762. this.#initialized = true;
  3763. return true;
  3764. }
  3765. return false;
  3766. }
  3767. const isVerified = await this.#verifyAuth();
  3768. if (isVerified) {
  3769. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3770. this.#initialized = true;
  3771. return true;
  3772. }
  3773. GM_setValue('youtubeAuth', null);
  3774. if (await this.#updateAuth()) {
  3775. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3776. this.#initialized = true;
  3777. return true;
  3778. }
  3779. scripts_echoLog({}).error(i18n('initFailed', 'Youtube'));
  3780. return false;
  3781. } catch (error) {
  3782. throwError(error, 'Youtube.init');
  3783. return false;
  3784. }
  3785. }
  3786. async #verifyAuth() {
  3787. try {
  3788. return await this.#toggleChannel({
  3789. link: this.#verifyChannel,
  3790. doTask: true,
  3791. verify: true
  3792. });
  3793. } catch (error) {
  3794. throwError(error, 'Youtube.verifyAuth');
  3795. return false;
  3796. }
  3797. }
  3798. async #updateAuth() {
  3799. try {
  3800. const logStatus = scripts_echoLog({
  3801. text: i18n('updatingAuth', 'Youtube')
  3802. });
  3803. return await new Promise(resolve => {
  3804. GM_cookie.list({
  3805. url: 'https://www.youtube.com/@YouTube'
  3806. }, async (cookies, error) => {
  3807. if (!error) {
  3808. const PAPISID = cookies.find(cookie => cookie.name === '__Secure-3PAPISID')?.value;
  3809. if (PAPISID) {
  3810. GM_setValue('youtubeAuth', {
  3811. PAPISID: PAPISID
  3812. });
  3813. this.#auth = {
  3814. PAPISID: PAPISID
  3815. };
  3816. logStatus.success();
  3817. resolve(await this.#verifyAuth());
  3818. } else {
  3819. logStatus.error(i18n('needLogin'));
  3820. resolve(false);
  3821. }
  3822. } else {
  3823. logStatus.error('Error: Update youtube auth failed!');
  3824. resolve(false);
  3825. }
  3826. });
  3827. });
  3828. } catch (error) {
  3829. throwError(error, 'Youtube.updateAuth');
  3830. return false;
  3831. }
  3832. }
  3833. #getInfo(link, type) {
  3834. return getInfo(link, type);
  3835. }
  3836. async #toggleChannel({
  3837. link,
  3838. doTask = true,
  3839. verify = false
  3840. }) {
  3841. try {
  3842. const {
  3843. params,
  3844. needLogin
  3845. } = await this.#getInfo(link, 'channel');
  3846. const {
  3847. apiKey,
  3848. client,
  3849. request,
  3850. channelId
  3851. } = params || {};
  3852. if (needLogin) {
  3853. scripts_echoLog({
  3854. html: i18n('loginYtb')
  3855. });
  3856. return false;
  3857. }
  3858. if (!(apiKey && client && request && channelId)) {
  3859. scripts_echoLog({
  3860. text: '"getYtbToken" failed'
  3861. });
  3862. return false;
  3863. }
  3864. if (!doTask && !verify && this.whiteList.channels.includes(channelId)) {
  3865. scripts_echoLog({
  3866. type: 'whiteList',
  3867. text: 'Youtube.unfollowChannel',
  3868. id: channelId
  3869. });
  3870. return true;
  3871. }
  3872. const logStatus = verify ? scripts_echoLog({
  3873. text: i18n('verifyingAuth', 'Youtube')
  3874. }) : scripts_echoLog({
  3875. type: doTask ? 'followingYtbChannel' : 'unfollowingYtbChannel',
  3876. text: channelId
  3877. });
  3878. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3879. const {
  3880. result,
  3881. statusText,
  3882. status,
  3883. data
  3884. } = await tools_httpRequest({
  3885. url: `https://www.youtube.com/youtubei/v1/subscription/${doTask ? '' : 'un'}subscribe?key=${apiKey}&prettyPrint=false`,
  3886. method: 'POST',
  3887. headers: {
  3888. origin: 'https://www.youtube.com',
  3889. referer: `https://www.youtube.com/channel/${channelId}`,
  3890. 'content-type': 'application/json',
  3891. 'x-goog-authuser': '0',
  3892. 'x-goog-visitor-id': client?.visitorData,
  3893. 'x-origin': 'https://www.youtube.com',
  3894. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  3895. },
  3896. data: JSON.stringify({
  3897. context: {
  3898. client: client,
  3899. request: {
  3900. sessionId: request?.sessionId,
  3901. internalExperimentFlags: [],
  3902. consistencyTokenJars: []
  3903. },
  3904. user: {}
  3905. },
  3906. channelIds: [ channelId ],
  3907. params: doTask ? 'EgIIAhgA' : 'CgIIAhgA'
  3908. })
  3909. });
  3910. if (result === 'Success') {
  3911. if (data?.status === 200) {
  3912. if (doTask && (/"subscribed":true/.test(data.responseText) || data.responseText.includes('The subscription already exists')) || !doTask && /"subscribed":false/.test(data.responseText)) {
  3913. logStatus.success();
  3914. if (doTask && !verify) {
  3915. this.tasks.channels = unique([ ...this.tasks.channels, link ]);
  3916. }
  3917. return true;
  3918. }
  3919. if (verify && data.responseText.includes('You may not subscribe to yourself')) {
  3920. logStatus.success();
  3921. return true;
  3922. }
  3923. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  3924. return false;
  3925. }
  3926. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3927. return false;
  3928. }
  3929. logStatus.error(`${result}:${statusText}(${status})`);
  3930. return false;
  3931. } catch (error) {
  3932. throwError(error, 'Youtube.toggleChannel');
  3933. return false;
  3934. }
  3935. }
  3936. async #toggleLikeVideo({
  3937. link,
  3938. doTask = true
  3939. }) {
  3940. try {
  3941. const {
  3942. params,
  3943. needLogin
  3944. } = await this.#getInfo(link, 'likeVideo');
  3945. const {
  3946. apiKey,
  3947. client,
  3948. request,
  3949. videoId,
  3950. likeParams
  3951. } = params || {};
  3952. if (needLogin) {
  3953. scripts_echoLog({
  3954. html: `${i18n('loginYtb')}`
  3955. });
  3956. return false;
  3957. }
  3958. if (!(apiKey && client && request && videoId && likeParams)) {
  3959. scripts_echoLog({
  3960. text: '"getYtbToken" failed'
  3961. });
  3962. return false;
  3963. }
  3964. if (!doTask && this.whiteList.likes.includes(videoId)) {
  3965. scripts_echoLog({
  3966. type: 'whiteList',
  3967. text: 'Youtube.unlikeVideo',
  3968. id: videoId
  3969. });
  3970. return true;
  3971. }
  3972. const logStatus = scripts_echoLog({
  3973. type: doTask ? 'likingYtbVideo' : 'unlikingYtbVideo',
  3974. text: videoId
  3975. });
  3976. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3977. const likeVideoData = {
  3978. context: {
  3979. client: client,
  3980. request: {
  3981. sessionId: request.sessionId,
  3982. internalExperimentFlags: [],
  3983. consistencyTokenJars: []
  3984. },
  3985. user: {}
  3986. },
  3987. target: {
  3988. videoId: videoId
  3989. }
  3990. };
  3991. if (doTask) {
  3992. if (likeParams) {
  3993. likeVideoData.params = likeParams;
  3994. } else {
  3995. logStatus.error('Empty likeParams');
  3996. return false;
  3997. }
  3998. }
  3999. const {
  4000. result,
  4001. statusText,
  4002. status,
  4003. data
  4004. } = await tools_httpRequest({
  4005. url: `https://www.youtube.com/youtubei/v1/like/${doTask ? '' : 'remove'}like?key=${apiKey}`,
  4006. method: 'POST',
  4007. headers: {
  4008. origin: 'https://www.youtube.com',
  4009. referer: `https://www.youtube.com/watch?v=${videoId}`,
  4010. 'content-type': 'application/json',
  4011. 'x-goog-authuser': '0',
  4012. 'x-goog-visitor-id': client.visitorData,
  4013. 'x-origin': 'https://www.youtube.com',
  4014. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  4015. },
  4016. data: JSON.stringify(likeVideoData)
  4017. });
  4018. if (result === 'Success') {
  4019. if (data?.status === 200) {
  4020. if (doTask && data.responseText.includes('Added to Liked videos') || !doTask && (data.responseText.includes('Removed from Liked videos') || data.responseText.includes('Dislike removed'))) {
  4021. logStatus.success();
  4022. if (doTask) {
  4023. this.tasks.likes = unique([ ...this.tasks.likes, link ]);
  4024. }
  4025. return true;
  4026. }
  4027. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  4028. return false;
  4029. }
  4030. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4031. return false;
  4032. }
  4033. logStatus.error(`${result}:${statusText}(${status})`);
  4034. return false;
  4035. } catch (error) {
  4036. throwError(error, 'Youtube.toggleLikeVideo');
  4037. return false;
  4038. }
  4039. }
  4040. async toggle({
  4041. doTask = true,
  4042. channelLinks = [],
  4043. videoLinks = []
  4044. }) {
  4045. try {
  4046. if (!this.#initialized) {
  4047. scripts_echoLog({
  4048. text: i18n('needInit')
  4049. });
  4050. return false;
  4051. }
  4052. const prom = [];
  4053. if (doTask && !globalOptions.doTask.youtube.channels || !doTask && !globalOptions.undoTask.youtube.channels) {
  4054. scripts_echoLog({
  4055. type: 'globalOptionsSkip',
  4056. text: 'youtube.channels'
  4057. });
  4058. } else {
  4059. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => {
  4060. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4061. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4062. }
  4063. return link;
  4064. });
  4065. if (realChannels.length > 0) {
  4066. for (const channel of realChannels) {
  4067. prom.push(this.#toggleChannel({
  4068. link: channel,
  4069. doTask: doTask
  4070. }));
  4071. await delay(1e3);
  4072. }
  4073. }
  4074. }
  4075. if (doTask && !globalOptions.doTask.youtube.likes || !doTask && !globalOptions.undoTask.youtube.likes) {
  4076. scripts_echoLog({
  4077. type: 'globalOptionsSkip',
  4078. text: 'youtube.likes'
  4079. });
  4080. } else {
  4081. const realLikes = this.getRealParams('likes', videoLinks, doTask, link => {
  4082. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4083. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4084. }
  4085. return link;
  4086. });
  4087. if (realLikes.length > 0) {
  4088. for (const video of realLikes) {
  4089. prom.push(this.#toggleLikeVideo({
  4090. link: video,
  4091. doTask: doTask
  4092. }));
  4093. await delay(1e3);
  4094. }
  4095. }
  4096. }
  4097. return Promise.all(prom).then(() => true);
  4098. } catch (error) {
  4099. throwError(error, 'Youtube.toggle');
  4100. return false;
  4101. }
  4102. }
  4103. }
  4104. class SteamASF {
  4105. #asfOptions;
  4106. #botName = 'asf';
  4107. #groupInfo;
  4108. async init() {
  4109. try {
  4110. const asfCommandsUrl = new URL('/Api/Command/', globalOptions.ASF.AsfIpcUrl);
  4111. this.#asfOptions = {
  4112. url: asfCommandsUrl.href,
  4113. method: 'POST',
  4114. responseType: 'json',
  4115. headers: {
  4116. accept: 'application/json',
  4117. 'Content-Type': 'application/json',
  4118. Host: asfCommandsUrl.host,
  4119. Origin: asfCommandsUrl.origin,
  4120. Referer: asfCommandsUrl.href,
  4121. Authentication: globalOptions.ASF.AsfIpcPassword
  4122. }
  4123. };
  4124. if (globalOptions.ASF.AsfBotname) {
  4125. this.#botName = globalOptions.ASF.AsfBotname;
  4126. }
  4127. const logStatus = scripts_echoLog({
  4128. text: i18n('initingASF')
  4129. });
  4130. const {
  4131. result,
  4132. statusText,
  4133. status,
  4134. data
  4135. } = await tools_httpRequest({
  4136. ...this.#asfOptions,
  4137. data: '{"Command":"!stats"}'
  4138. });
  4139. if (result === 'Success') {
  4140. if (data?.response?.Success === true && data.response.Message === 'OK' && data.response.Result) {
  4141. logStatus.success();
  4142. return true;
  4143. }
  4144. if (data?.response?.Result || data?.response?.Message) {
  4145. logStatus.error(data?.response?.Result || data.response.Message);
  4146. return false;
  4147. }
  4148. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4149. return false;
  4150. }
  4151. logStatus.error(`${result}:${statusText}(${status})`);
  4152. return false;
  4153. } catch (error) {
  4154. throwError(error, 'SteamASF.init');
  4155. return false;
  4156. }
  4157. }
  4158. async joinGroup(groupName) {
  4159. try {
  4160. const logStatus = scripts_echoLog({
  4161. type: 'joiningSteamGroup',
  4162. text: groupName
  4163. });
  4164. const {
  4165. result,
  4166. statusText,
  4167. status,
  4168. data
  4169. } = await tools_httpRequest({
  4170. ...this.#asfOptions,
  4171. data: JSON.stringify({
  4172. Command: `!JOINGROUP ${this.#botName} ${groupName}`
  4173. })
  4174. });
  4175. if (result === 'Success') {
  4176. if (data?.status === 200 && [ '已加入', '已申请', 'Joined', 'Applied', 'Присоединился', 'costs' ].find(text => data.response?.Result?.includes(text))) {
  4177. logStatus.success();
  4178. return true;
  4179. }
  4180. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4181. return false;
  4182. }
  4183. logStatus.error(`${result}:${statusText}(${status})`);
  4184. return false;
  4185. } catch (error) {
  4186. throwError(error, 'SteamASF.joinGroup');
  4187. return false;
  4188. }
  4189. }
  4190. async leaveGroup(groupName) {
  4191. try {
  4192. if (!this.#groupInfo) {
  4193. if (!await this.#getGroupId()) {
  4194. return false;
  4195. }
  4196. }
  4197. const groupId = await this.#groupInfo[groupName];
  4198. if (!groupId) {
  4199. return false;
  4200. }
  4201. const logStatus = scripts_echoLog({
  4202. type: 'leavingSteamGroup',
  4203. text: groupName
  4204. });
  4205. const {
  4206. result,
  4207. statusText,
  4208. status,
  4209. data
  4210. } = await tools_httpRequest({
  4211. ...this.#asfOptions,
  4212. data: JSON.stringify({
  4213. Command: `!LEAVEGROUP ${this.#botName} ${groupId}`
  4214. })
  4215. });
  4216. if (result === 'Success') {
  4217. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4218. logStatus.success();
  4219. return true;
  4220. }
  4221. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4222. return false;
  4223. }
  4224. logStatus.error(`${result}:${statusText}(${status})`);
  4225. return false;
  4226. } catch (error) {
  4227. throwError(error, 'SteamASF.leaveGroup');
  4228. return false;
  4229. }
  4230. }
  4231. async #getGroupId() {
  4232. try {
  4233. const logStatus = scripts_echoLog({
  4234. type: 'gettingSteamGroupId',
  4235. text: 'All'
  4236. });
  4237. const {
  4238. result,
  4239. statusText,
  4240. status,
  4241. data
  4242. } = await tools_httpRequest({
  4243. ...this.#asfOptions,
  4244. data: JSON.stringify({
  4245. Command: `!GROUPLIST ${this.#botName}`
  4246. })
  4247. });
  4248. if (result === 'Success') {
  4249. if (data?.status === 200 && data.response?.Result?.includes('|')) {
  4250. this.#groupInfo = Object.fromEntries(data.response.Result.split('\n').map(line => {
  4251. const [ , name, id ] = line.trim().split('|');
  4252. if (name && id) {
  4253. return [ name, id ];
  4254. }
  4255. return null;
  4256. }).filter(ele => ele));
  4257. logStatus.success();
  4258. return true;
  4259. }
  4260. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4261. return false;
  4262. }
  4263. logStatus.error(`${result}:${statusText}(${status})`);
  4264. return false;
  4265. } catch (error) {
  4266. throwError(error, 'SteamASF.getGroupID');
  4267. return false;
  4268. }
  4269. }
  4270. async addToWishlist(gameId) {
  4271. try {
  4272. const logStatus = scripts_echoLog({
  4273. type: 'addingToWishlist',
  4274. text: gameId
  4275. });
  4276. const {
  4277. result,
  4278. statusText,
  4279. status,
  4280. data
  4281. } = await tools_httpRequest({
  4282. ...this.#asfOptions,
  4283. data: JSON.stringify({
  4284. Command: `!ADDWISHLIST ${this.#botName} ${gameId}`
  4285. })
  4286. });
  4287. if (result === 'Success') {
  4288. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4289. logStatus.success();
  4290. return true;
  4291. }
  4292. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4293. return false;
  4294. }
  4295. logStatus.error(`${result}:${statusText}(${status})`);
  4296. return false;
  4297. } catch (error) {
  4298. throwError(error, 'SteamASF.addToWishlist');
  4299. return false;
  4300. }
  4301. }
  4302. async removeFromWishlist(gameId) {
  4303. try {
  4304. const logStatus = scripts_echoLog({
  4305. type: 'removingFromWishlist',
  4306. text: gameId
  4307. });
  4308. const {
  4309. result,
  4310. statusText,
  4311. status,
  4312. data
  4313. } = await tools_httpRequest({
  4314. ...this.#asfOptions,
  4315. data: JSON.stringify({
  4316. Command: `!REMOVEWISHLIST ${this.#botName} ${gameId}`
  4317. })
  4318. });
  4319. if (result === 'Success') {
  4320. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4321. logStatus.success();
  4322. return true;
  4323. }
  4324. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4325. return false;
  4326. }
  4327. logStatus.error(`${result}:${statusText}(${status})`);
  4328. return false;
  4329. } catch (error) {
  4330. throwError(error, 'SteamASF.removeFromWishlist');
  4331. return false;
  4332. }
  4333. }
  4334. async toggleFollowGame(gameId, doTask) {
  4335. try {
  4336. const logStatus = scripts_echoLog({
  4337. type: `${doTask ? '' : 'un'}followingGame`,
  4338. text: gameId
  4339. });
  4340. const {
  4341. result,
  4342. statusText,
  4343. status,
  4344. data
  4345. } = await tools_httpRequest({
  4346. ...this.#asfOptions,
  4347. data: JSON.stringify({
  4348. Command: `!${doTask ? '' : 'UN'}FOLLOWGAME ${this.#botName} ${gameId}`
  4349. })
  4350. });
  4351. if (result === 'Success') {
  4352. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4353. logStatus.success();
  4354. return true;
  4355. }
  4356. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4357. return false;
  4358. }
  4359. logStatus.error(`${result}:${statusText}(${status})`);
  4360. return false;
  4361. } catch (error) {
  4362. throwError(error, 'SteamASF.toggleFollowGame');
  4363. return false;
  4364. }
  4365. }
  4366. async toggleCurator(curatorId, doTask = true) {
  4367. try {
  4368. const logStatus = scripts_echoLog({
  4369. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  4370. text: curatorId
  4371. });
  4372. const {
  4373. result,
  4374. statusText,
  4375. status,
  4376. data
  4377. } = await tools_httpRequest({
  4378. ...this.#asfOptions,
  4379. data: JSON.stringify({
  4380. Command: `!${doTask ? '' : 'UN'}FOLLOWCURATOR ${this.#botName} ${curatorId}`
  4381. })
  4382. });
  4383. if (result === 'Success') {
  4384. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4385. logStatus.success();
  4386. return true;
  4387. }
  4388. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4389. return false;
  4390. }
  4391. logStatus.error(`${result}:${statusText}(${status})`);
  4392. return false;
  4393. } catch (error) {
  4394. throwError(error, 'Steam.toggleCurator');
  4395. return false;
  4396. }
  4397. }
  4398. async addLicense(id) {
  4399. try {
  4400. const [ type, ids ] = id.split('-');
  4401. if (type === 'appid') {
  4402. const logStatus = scripts_echoLog({
  4403. type: 'addingFreeLicense',
  4404. text: ids
  4405. });
  4406. const {
  4407. result,
  4408. statusText,
  4409. status,
  4410. data
  4411. } = await tools_httpRequest({
  4412. ...this.#asfOptions,
  4413. data: JSON.stringify({
  4414. Command: `!addlicense ${this.#botName} app/${ids}`
  4415. })
  4416. });
  4417. if (result === 'Success') {
  4418. if (data?.status === 200 && [ 'AlreadyPurchased', 'OK' ].find(text => data.response?.Result?.includes(text))) {
  4419. logStatus.success();
  4420. return true;
  4421. }
  4422. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4423. return false;
  4424. }
  4425. logStatus.error(`${result}:${statusText}(${status})`);
  4426. return false;
  4427. } else if (type === 'subid') {
  4428. const idsArr = ids.split(',');
  4429. const logStatus = scripts_echoLog({
  4430. type: 'addingFreeLicenseSubid',
  4431. text: ids
  4432. });
  4433. const {
  4434. result,
  4435. statusText,
  4436. status,
  4437. data
  4438. } = await tools_httpRequest({
  4439. ...this.#asfOptions,
  4440. data: JSON.stringify({
  4441. Command: `!addlicense ${this.#botName} ${idsArr.map(id => `sub/${id}`).join(',')}`
  4442. })
  4443. });
  4444. if (result === 'Success') {
  4445. if (data?.status === 200 && data.response?.Result) {
  4446. const resultLines = data.response.Result.split('\n');
  4447. idsArr.forEach(subid => {
  4448. const targetLine = resultLines.find(text => text.includes(subid));
  4449. if (targetLine && [ '成功', 'Success', 'Успех' ].find(text => targetLine.includes(text))) {
  4450. scripts_echoLog({}).success(targetLine);
  4451. } else {
  4452. scripts_echoLog({}).error(targetLine);
  4453. }
  4454. });
  4455. return true;
  4456. }
  4457. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4458. return false;
  4459. }
  4460. logStatus.error(`${result}:${statusText}(${status})`);
  4461. return false;
  4462. }
  4463. return false;
  4464. } catch (error) {
  4465. throwError(error, 'SteamASF.addLicense');
  4466. return false;
  4467. }
  4468. }
  4469. async requestPlayTestAccess(id) {
  4470. try {
  4471. const logStatus = scripts_echoLog({
  4472. type: 'requestingPlayTestAccess',
  4473. text: id
  4474. });
  4475. const {
  4476. result,
  4477. statusText,
  4478. status,
  4479. data
  4480. } = await tools_httpRequest({
  4481. ...this.#asfOptions,
  4482. data: JSON.stringify({
  4483. Command: `!REQUESTACCESS ${this.#botName} ${id}`
  4484. })
  4485. });
  4486. if (result === 'Success') {
  4487. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4488. logStatus.success();
  4489. return true;
  4490. }
  4491. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4492. return false;
  4493. }
  4494. logStatus.error(`${result}:${statusText}(${status})`);
  4495. return false;
  4496. } catch (error) {
  4497. throwError(error, 'Steam.requestPlayTestAccess');
  4498. return false;
  4499. }
  4500. }
  4501. }
  4502. const social_SteamASF = SteamASF;
  4503. class Steam extends social_Social {
  4504. tasks;
  4505. whiteList;
  4506. #cache = {
  4507. ...{
  4508. group: {},
  4509. officialGroup: {},
  4510. forum: {},
  4511. workshop: {},
  4512. curator: {}
  4513. },
  4514. ...GM_getValue('steamCache')
  4515. };
  4516. #auth = {};
  4517. #storeInitialized = false;
  4518. #communityInitialized = false;
  4519. #area = 'CN';
  4520. #areaStatus = 'end';
  4521. #ASF;
  4522. constructor() {
  4523. super();
  4524. const defaultTasksTemplate = {
  4525. groups: [],
  4526. officialGroups: [],
  4527. wishlists: [],
  4528. follows: [],
  4529. forums: [],
  4530. workshops: [],
  4531. workshopVotes: [],
  4532. curators: [],
  4533. curatorLikes: [],
  4534. announcements: [],
  4535. licenses: [],
  4536. playtests: []
  4537. };
  4538. this.tasks = defaultTasksTemplate;
  4539. this.whiteList = {
  4540. ...defaultTasksTemplate,
  4541. ...GM_getValue('whiteList')?.steam || {}
  4542. };
  4543. }
  4544. async init(type = 'all') {
  4545. try {
  4546. if (globalOptions.ASF.AsfEnabled && globalOptions.ASF.AsfIpcUrl && globalOptions.ASF.AsfIpcPassword) {
  4547. this.#ASF = new social_SteamASF();
  4548. if (await this.#ASF.init()) {
  4549. this.#storeInitialized = true;
  4550. this.#communityInitialized = true;
  4551. return true;
  4552. }
  4553. return false;
  4554. }
  4555. if (type === 'store') {
  4556. if (this.#storeInitialized) {
  4557. return true;
  4558. }
  4559. this.#storeInitialized = await this.#updateStoreAuth();
  4560. if (!this.#storeInitialized) {
  4561. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4562. return false;
  4563. }
  4564. scripts_echoLog({}).success(i18n('initSuccess', 'SteamStore'));
  4565. return true;
  4566. }
  4567. if (type === 'community') {
  4568. if (this.#communityInitialized) {
  4569. return true;
  4570. }
  4571. this.#communityInitialized = await this.#updateCommunityAuth();
  4572. if (!this.#communityInitialized) {
  4573. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4574. return false;
  4575. }
  4576. scripts_echoLog({}).success(i18n('initSuccess', 'SteamCommunity'));
  4577. return true;
  4578. }
  4579. this.#storeInitialized = await this.#updateStoreAuth();
  4580. this.#communityInitialized = await this.#updateCommunityAuth();
  4581. if (this.#storeInitialized && this.#communityInitialized) {
  4582. scripts_echoLog({}).success(i18n('initSuccess', 'Steam'));
  4583. return true;
  4584. }
  4585. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4586. return false;
  4587. } catch (error) {
  4588. throwError(error, 'Steam.init');
  4589. return false;
  4590. }
  4591. }
  4592. async #refreshStoreToken() {
  4593. try {
  4594. const logStatus = scripts_echoLog({
  4595. text: i18n('refreshingToken', i18n('steamStore'))
  4596. });
  4597. const formData = new FormData();
  4598. formData.append('redir', 'https://store.steampowered.com/');
  4599. const {
  4600. result,
  4601. statusText,
  4602. status,
  4603. data
  4604. } = await tools_httpRequest({
  4605. url: 'https://login.steampowered.com/jwt/ajaxrefresh',
  4606. method: 'POST',
  4607. responseType: 'json',
  4608. headers: {
  4609. Host: 'login.steampowered.com',
  4610. Origin: 'https://store.steampowered.com',
  4611. Referer: 'https://store.steampowered.com/'
  4612. },
  4613. data: formData
  4614. });
  4615. if (result === 'Success') {
  4616. if (data?.response?.success) {
  4617. if (await this.#setStoreToken(data.response)) {
  4618. logStatus.success();
  4619. return true;
  4620. }
  4621. logStatus.error('Error');
  4622. return false;
  4623. }
  4624. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4625. return false;
  4626. }
  4627. logStatus.error(`${result}:${statusText}(${status})`);
  4628. return false;
  4629. } catch (error) {
  4630. throwError(error, 'Steam.refreshStoreToken');
  4631. return false;
  4632. }
  4633. }
  4634. async #setStoreToken(param) {
  4635. try {
  4636. const logStatus = scripts_echoLog({
  4637. text: i18n('settingToken', i18n('steamStore'))
  4638. });
  4639. const formData = new FormData();
  4640. formData.append('steamID', param.steamID);
  4641. formData.append('nonce', param.nonce);
  4642. formData.append('redir', param.redir);
  4643. formData.append('auth', param.auth);
  4644. const {
  4645. result,
  4646. statusText,
  4647. status,
  4648. data
  4649. } = await tools_httpRequest({
  4650. url: 'https://store.steampowered.com/login/settoken',
  4651. method: 'POST',
  4652. headers: {
  4653. Accept: 'application/json, text/plain, */*',
  4654. Host: 'store.steampowered.com',
  4655. Origin: 'https://store.steampowered.com',
  4656. Referer: 'https://store.steampowered.com/login'
  4657. },
  4658. data: formData
  4659. });
  4660. if (result === 'Success') {
  4661. if (data?.status === 200) {
  4662. logStatus.success();
  4663. return true;
  4664. }
  4665. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4666. return false;
  4667. }
  4668. logStatus.error(`${result}:${statusText}(${status})`);
  4669. return false;
  4670. } catch (error) {
  4671. throwError(error, 'Steam.setStoreToken');
  4672. return false;
  4673. }
  4674. }
  4675. async #updateStoreAuth() {
  4676. try {
  4677. const logStatus = scripts_echoLog({
  4678. text: i18n('updatingAuth', i18n('steamStore'))
  4679. });
  4680. const {
  4681. result,
  4682. statusText,
  4683. status,
  4684. data
  4685. } = await tools_httpRequest({
  4686. url: 'https://store.steampowered.com/',
  4687. method: 'GET',
  4688. headers: {
  4689. Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
  4690. 'Cache-Control': 'max-age=0',
  4691. 'Sec-Fetch-Dest': 'document',
  4692. 'Sec-Fetch-Mode': 'navigate',
  4693. 'Upgrade-Insecure-Requests': '1'
  4694. }
  4695. });
  4696. if (result === 'Success') {
  4697. if (data?.status === 200) {
  4698. if (!data.responseText.includes('data-miniprofile=')) {
  4699. await this.#refreshStoreToken();
  4700. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4701. return false;
  4702. }
  4703. const storeSessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4704. if (storeSessionID) {
  4705. this.#auth.storeSessionID = storeSessionID;
  4706. logStatus.success();
  4707. return true;
  4708. }
  4709. logStatus.error('Error: Get "sessionID" failed');
  4710. return false;
  4711. }
  4712. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4713. return false;
  4714. }
  4715. logStatus.error(`${result}:${statusText}(${status})`);
  4716. return false;
  4717. } catch (error) {
  4718. throwError(error, 'Steam.updateStoreAuth');
  4719. return false;
  4720. }
  4721. }
  4722. async #updateCommunityAuth() {
  4723. try {
  4724. const logStatus = scripts_echoLog({
  4725. text: i18n('updatingAuth', i18n('steamCommunity'))
  4726. });
  4727. const {
  4728. result,
  4729. statusText,
  4730. status,
  4731. data
  4732. } = await tools_httpRequest({
  4733. url: 'https://steamcommunity.com/my',
  4734. method: 'GET',
  4735. headers: {
  4736. Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
  4737. 'Cache-Control': 'max-age=0',
  4738. 'Sec-Fetch-Dest': 'document',
  4739. 'Sec-Fetch-Mode': 'navigate',
  4740. 'Upgrade-Insecure-Requests': '1'
  4741. }
  4742. });
  4743. if (result === 'Success') {
  4744. if (data?.status === 200) {
  4745. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4746. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4747. return false;
  4748. }
  4749. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4750. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4751. const userName = data.responseText.match(/steamcommunity.com\/id\/(.+?)\/friends\//)?.[1];
  4752. if (steam64Id) {
  4753. this.#auth.steam64Id = steam64Id;
  4754. }
  4755. if (userName) {
  4756. this.#auth.userName = userName;
  4757. }
  4758. if (communitySessionID) {
  4759. this.#auth.communitySessionID = communitySessionID;
  4760. logStatus.success();
  4761. return true;
  4762. }
  4763. logStatus.error('Error: Get "sessionID" failed');
  4764. return false;
  4765. }
  4766. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4767. return false;
  4768. }
  4769. logStatus.error(`${result}:${statusText}(${status})`);
  4770. return false;
  4771. } catch (error) {
  4772. throwError(error, 'Steam.updateCommunityAuth');
  4773. return false;
  4774. }
  4775. }
  4776. async #getAreaInfo() {
  4777. try {
  4778. const logStatus = scripts_echoLog({
  4779. text: i18n('gettingAreaInfo')
  4780. });
  4781. const {
  4782. result,
  4783. statusText,
  4784. status,
  4785. data
  4786. } = await tools_httpRequest({
  4787. url: 'https://store.steampowered.com/cart/',
  4788. method: 'GET'
  4789. });
  4790. if (result === 'Success') {
  4791. if (data?.status === 200) {
  4792. const cartConfigRaw = data.responseText.match(/data-cart_config="(.*?)"/)?.[1];
  4793. const temp = document.createElement('div');
  4794. temp.innerHTML = cartConfigRaw || '{}';
  4795. const cartConfigStr = temp.textContent || temp.innerText;
  4796. let cartConfig;
  4797. try {
  4798. cartConfig = JSON.parse(cartConfigStr);
  4799. } catch (error) {
  4800. logStatus.error('Error: get country info filed');
  4801. console.error(error);
  4802. return {};
  4803. }
  4804. if (!cartConfig.rgUserCountryOptions) {
  4805. logStatus.warning('Warning: Area cannot be changed');
  4806. return {};
  4807. }
  4808. const userInfoRaw = data.responseText.match(/data-userinfo="(.*?)"/)?.[1];
  4809. const temp1 = document.createElement('div');
  4810. temp1.innerHTML = userInfoRaw || '{}';
  4811. const userInfoStr = temp1.textContent || temp1.innerText;
  4812. let userInfo;
  4813. try {
  4814. userInfo = JSON.parse(userInfoStr);
  4815. } catch (error) {
  4816. logStatus.error('Error: get country info filed');
  4817. console.error(error);
  4818. return {};
  4819. }
  4820. const currentArea = userInfo.country_code;
  4821. const areas = Object.keys(cartConfig.rgUserCountryOptions).filter(area => area !== 'help');
  4822. if (currentArea && areas.length > 0) {
  4823. this.#area = currentArea;
  4824. logStatus.success();
  4825. return {
  4826. currentArea: currentArea,
  4827. areas: areas
  4828. };
  4829. }
  4830. logStatus.error('Error: get country info filed');
  4831. return {};
  4832. }
  4833. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4834. return {};
  4835. }
  4836. logStatus.error(`${result}:${statusText}(${status})`);
  4837. return {};
  4838. } catch (error) {
  4839. throwError(error, 'Steam.getAreaInfo');
  4840. return {};
  4841. }
  4842. }
  4843. async #changeArea(area) {
  4844. try {
  4845. if (this.#areaStatus === 'waiting') {
  4846. await new Promise(resolve => {
  4847. const checker = setInterval(() => {
  4848. if (this.#areaStatus !== 'waiting') {
  4849. clearInterval(checker);
  4850. resolve(true);
  4851. }
  4852. });
  4853. });
  4854. }
  4855. if (this.#area === area || !area && this.#area !== 'CN') {
  4856. return true;
  4857. }
  4858. this.#areaStatus = 'waiting';
  4859. let aimedArea = area;
  4860. if (!aimedArea) {
  4861. const {
  4862. currentArea,
  4863. areas
  4864. } = await this.#getAreaInfo();
  4865. if (!currentArea || !areas) {
  4866. this.#areaStatus = 'error';
  4867. return false;
  4868. }
  4869. if (currentArea !== 'CN') {
  4870. this.#areaStatus = 'skip';
  4871. scripts_echoLog({
  4872. text: 'notNeededChangeArea'
  4873. });
  4874. return 'skip';
  4875. }
  4876. const anotherArea = areas.filter(area => area && area !== 'CN');
  4877. if (!anotherArea || anotherArea.length === 0) {
  4878. this.#areaStatus = 'noAnotherArea';
  4879. scripts_echoLog({
  4880. text: 'noAnotherArea'
  4881. });
  4882. return false;
  4883. }
  4884. [ aimedArea ] = anotherArea;
  4885. }
  4886. const logStatus = scripts_echoLog({
  4887. text: i18n('changingArea', aimedArea)
  4888. });
  4889. const {
  4890. result,
  4891. statusText,
  4892. status,
  4893. data
  4894. } = await tools_httpRequest({
  4895. url: 'https://store.steampowered.com/country/setcountry',
  4896. method: 'POST',
  4897. headers: {
  4898. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  4899. },
  4900. data: $.param({
  4901. cc: aimedArea,
  4902. sessionid: this.#auth.storeSessionID
  4903. })
  4904. });
  4905. if (result === 'Success') {
  4906. if (data?.status === 200 && data.responseText === 'true') {
  4907. const {
  4908. currentArea
  4909. } = await this.#getAreaInfo();
  4910. if (currentArea === aimedArea) {
  4911. this.#areaStatus = 'success';
  4912. logStatus.success();
  4913. return currentArea;
  4914. }
  4915. this.#areaStatus = 'error';
  4916. logStatus.error('Error: change country filed');
  4917. return 'CN';
  4918. }
  4919. this.#areaStatus = 'error';
  4920. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4921. return 'CN';
  4922. }
  4923. this.#areaStatus = 'error';
  4924. logStatus.error(`${result}:${statusText}(${status})`);
  4925. return 'CN';
  4926. } catch (error) {
  4927. this.#areaStatus = 'error';
  4928. throwError(error, 'Steam.changeArea');
  4929. return false;
  4930. }
  4931. }
  4932. async #joinGroup(groupName) {
  4933. try {
  4934. if (this.#ASF) {
  4935. if (await this.#ASF.joinGroup(groupName)) {
  4936. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  4937. return true;
  4938. }
  4939. return false;
  4940. }
  4941. const logStatus = scripts_echoLog({
  4942. type: 'joiningSteamGroup',
  4943. text: groupName
  4944. });
  4945. const {
  4946. result,
  4947. statusText,
  4948. status,
  4949. data
  4950. } = await tools_httpRequest({
  4951. url: `https://steamcommunity.com/groups/${groupName}`,
  4952. method: 'POST',
  4953. headers: {
  4954. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  4955. },
  4956. data: $.param({
  4957. action: 'join',
  4958. sessionID: this.#auth.communitySessionID
  4959. })
  4960. });
  4961. if (result === 'Success') {
  4962. if (data?.status === 200 && !data.responseText.includes('grouppage_join_area')) {
  4963. logStatus.success();
  4964. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  4965. return true;
  4966. }
  4967. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4968. return false;
  4969. }
  4970. logStatus.error(`${result}:${statusText}(${status})`);
  4971. return false;
  4972. } catch (error) {
  4973. throwError(error, 'Steam.joinGroup');
  4974. return false;
  4975. }
  4976. }
  4977. async #leaveGroup(groupName) {
  4978. try {
  4979. if (this.whiteList.groups.includes(groupName)) {
  4980. scripts_echoLog({
  4981. type: 'whiteList',
  4982. text: 'Steam.leaveGroup',
  4983. id: groupName
  4984. });
  4985. return true;
  4986. }
  4987. if (this.#ASF) {
  4988. return await this.#ASF.leaveGroup(groupName);
  4989. }
  4990. const groupId = await this.#getGroupId(groupName);
  4991. if (!groupId) {
  4992. return false;
  4993. }
  4994. const logStatus = scripts_echoLog({
  4995. type: 'leavingSteamGroup',
  4996. text: groupName
  4997. });
  4998. const {
  4999. result,
  5000. statusText,
  5001. status,
  5002. data
  5003. } = await tools_httpRequest({
  5004. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5005. method: 'POST',
  5006. headers: {
  5007. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5008. },
  5009. data: $.param({
  5010. sessionID: this.#auth.communitySessionID,
  5011. action: 'leaveGroup',
  5012. groupId: groupId
  5013. })
  5014. });
  5015. if (result === 'Success') {
  5016. if (data?.status === 200 && data.finalUrl.includes('groups') && $(data.responseText.replace(/<img.*?>/g, '').toLowerCase()).find(`a[href='https://steamcommunity.com/groups/${groupName.toLowerCase()}']`).length === 0) {
  5017. logStatus.success();
  5018. return true;
  5019. }
  5020. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5021. return false;
  5022. }
  5023. logStatus.error(`${result}:${statusText}(${status})`);
  5024. return false;
  5025. } catch (error) {
  5026. throwError(error, 'Steam.leaveGroup');
  5027. return false;
  5028. }
  5029. }
  5030. async #getGroupId(groupName) {
  5031. try {
  5032. const logStatus = scripts_echoLog({
  5033. type: 'gettingSteamGroupId',
  5034. text: groupName
  5035. });
  5036. const groupId = this.#cache.group[groupName];
  5037. if (groupId) {
  5038. logStatus.success();
  5039. return groupId;
  5040. }
  5041. const {
  5042. result,
  5043. statusText,
  5044. status,
  5045. data
  5046. } = await tools_httpRequest({
  5047. url: `https://steamcommunity.com/groups/${groupName}`,
  5048. method: 'GET',
  5049. headers: {
  5050. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5051. }
  5052. });
  5053. if (result === 'Success') {
  5054. if (data?.status === 200) {
  5055. const groupId = data.responseText.match(/OpenGroupChat\( '([0-9]+)'/)?.[1];
  5056. if (groupId) {
  5057. this.#setCache('group', groupName, groupId);
  5058. logStatus.success();
  5059. return groupId;
  5060. }
  5061. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5062. return false;
  5063. }
  5064. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5065. return false;
  5066. }
  5067. logStatus.error(`${result}:${statusText}(${status})`);
  5068. return false;
  5069. } catch (error) {
  5070. throwError(error, 'Steam.getGroupID');
  5071. return false;
  5072. }
  5073. }
  5074. async #joinOfficialGroup(gameId) {
  5075. try {
  5076. if (this.#ASF) {
  5077. if (await this.#ASF.joinGroup(gameId)) {
  5078. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5079. return true;
  5080. }
  5081. return false;
  5082. }
  5083. const logStatus = scripts_echoLog({
  5084. type: 'joiningSteamOfficialGroup',
  5085. text: gameId
  5086. });
  5087. const {
  5088. result,
  5089. statusText,
  5090. status,
  5091. data
  5092. } = await tools_httpRequest({
  5093. url: `https://steamcommunity.com/games/${gameId}?action=join&sessionID=${this.#auth.communitySessionID}`,
  5094. method: 'GET',
  5095. headers: {
  5096. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5097. }
  5098. });
  5099. if (result === 'Success') {
  5100. if (data?.status === 200 && !data.responseText.includes('id="publicGroupJoin"')) {
  5101. logStatus.success();
  5102. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5103. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5104. if (groupId) {
  5105. this.#setCache('officialGroup', gameId, groupId);
  5106. }
  5107. return true;
  5108. }
  5109. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5110. return false;
  5111. }
  5112. logStatus.error(`${result}:${statusText}(${status})`);
  5113. return false;
  5114. } catch (error) {
  5115. throwError(error, 'Steam.joinOfficialGroup');
  5116. return false;
  5117. }
  5118. }
  5119. async #leaveOfficialGroup(gameId) {
  5120. try {
  5121. if (this.whiteList.officialGroups.includes(gameId)) {
  5122. scripts_echoLog({
  5123. type: 'whiteList',
  5124. text: 'Steam.leaveOfficialGroup',
  5125. id: gameId
  5126. });
  5127. return true;
  5128. }
  5129. if (this.#ASF) {
  5130. return await this.#ASF.leaveGroup(gameId);
  5131. }
  5132. const groupId = await this.#getOfficialGroupId(gameId);
  5133. if (!groupId) {
  5134. return false;
  5135. }
  5136. const logStatus = scripts_echoLog({
  5137. type: 'leavingSteamOfficialGroup',
  5138. text: gameId
  5139. });
  5140. const {
  5141. result,
  5142. statusText,
  5143. status,
  5144. data
  5145. } = await tools_httpRequest({
  5146. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5147. method: 'POST',
  5148. headers: {
  5149. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5150. },
  5151. data: $.param({
  5152. sessionID: this.#auth.communitySessionID,
  5153. action: 'leaveGroup',
  5154. groupId: groupId
  5155. })
  5156. });
  5157. if (result === 'Success') {
  5158. if (data?.status === 200) {
  5159. const {
  5160. result: resultR,
  5161. statusText: statusTextR,
  5162. status: statusR,
  5163. data: dataR
  5164. } = await tools_httpRequest({
  5165. url: `https://steamcommunity.com/games/${gameId}`,
  5166. method: 'GET',
  5167. headers: {
  5168. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5169. }
  5170. });
  5171. if (resultR === 'Success') {
  5172. if (dataR?.status === 200 && dataR.responseText.includes('id="publicGroupJoin"')) {
  5173. logStatus.success();
  5174. return true;
  5175. }
  5176. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5177. return false;
  5178. }
  5179. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5180. return false;
  5181. }
  5182. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5183. return false;
  5184. }
  5185. logStatus.error(`${result}:${statusText}(${status})`);
  5186. return false;
  5187. } catch (error) {
  5188. throwError(error, 'Steam.leaveOfficialGroup');
  5189. return false;
  5190. }
  5191. }
  5192. async #getOfficialGroupId(gameId) {
  5193. try {
  5194. const logStatus = scripts_echoLog({
  5195. type: 'gettingSteamOfficialGroupId',
  5196. text: gameId
  5197. });
  5198. const groupId = this.#cache.officialGroup[gameId];
  5199. if (groupId) {
  5200. logStatus.success();
  5201. return groupId;
  5202. }
  5203. const {
  5204. result,
  5205. statusText,
  5206. status,
  5207. data
  5208. } = await tools_httpRequest({
  5209. url: `https://steamcommunity.com/games/${gameId}`,
  5210. method: 'GET',
  5211. headers: {
  5212. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5213. }
  5214. });
  5215. if (result === 'Success') {
  5216. if (data?.status === 200) {
  5217. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5218. if (groupId) {
  5219. this.#setCache('officialGroup', gameId, groupId);
  5220. logStatus.success();
  5221. return groupId;
  5222. }
  5223. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5224. return false;
  5225. }
  5226. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5227. return false;
  5228. }
  5229. logStatus.error(`${result}:${statusText}(${status})`);
  5230. return false;
  5231. } catch (error) {
  5232. throwError(error, 'Steam.getGroupID');
  5233. return false;
  5234. }
  5235. }
  5236. async #addToWishlist(gameId) {
  5237. try {
  5238. if (this.#ASF) {
  5239. if (await this.#ASF.addToWishlist(gameId)) {
  5240. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5241. return true;
  5242. }
  5243. return false;
  5244. }
  5245. const logStatus = scripts_echoLog({
  5246. type: 'addingToWishlist',
  5247. text: gameId
  5248. });
  5249. const {
  5250. result,
  5251. data
  5252. } = await tools_httpRequest({
  5253. url: 'https://store.steampowered.com/api/addtowishlist',
  5254. method: 'POST',
  5255. headers: {
  5256. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5257. },
  5258. data: $.param({
  5259. sessionid: this.#auth.storeSessionID,
  5260. appid: gameId
  5261. }),
  5262. dataType: 'json'
  5263. });
  5264. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5265. logStatus.success();
  5266. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5267. return true;
  5268. }
  5269. const {
  5270. result: resultR,
  5271. statusText: statusTextR,
  5272. status: statusR,
  5273. data: dataR
  5274. } = await tools_httpRequest({
  5275. url: `https://store.steampowered.com/app/${gameId}`,
  5276. method: 'GET'
  5277. });
  5278. if (resultR === 'Success') {
  5279. if (dataR?.status === 200) {
  5280. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5281. logStatus.warning(i18n('changeAreaNotice'));
  5282. if (!await this.#changeArea()) {
  5283. return false;
  5284. }
  5285. return await this.#addToWishlist(gameId);
  5286. }
  5287. if (dataR.responseText.includes('class="queue_actions_ctn"') && dataR.responseText.includes('class="already_in_library"')) {
  5288. logStatus.success();
  5289. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5290. return true;
  5291. } else if (dataR.responseText.includes('class="queue_actions_ctn"') && dataR.responseText.includes('id="add_to_wishlist_area_success" style="display: none;') || !dataR.responseText.includes('class="queue_actions_ctn"')) {
  5292. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5293. return false;
  5294. }
  5295. logStatus.success();
  5296. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5297. return true;
  5298. }
  5299. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5300. return false;
  5301. }
  5302. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5303. return false;
  5304. } catch (error) {
  5305. throwError(error, 'Steam.addToWishlist');
  5306. return false;
  5307. }
  5308. }
  5309. async #removeFromWishlist(gameId) {
  5310. try {
  5311. if (this.whiteList.wishlists.includes(gameId)) {
  5312. scripts_echoLog({
  5313. type: 'whiteList',
  5314. text: 'Steam.removeFromWishlist',
  5315. id: gameId
  5316. });
  5317. return true;
  5318. }
  5319. if (this.#ASF) {
  5320. return await this.#ASF.removeFromWishlist(gameId);
  5321. }
  5322. const logStatus = scripts_echoLog({
  5323. type: 'removingFromWishlist',
  5324. text: gameId
  5325. });
  5326. const {
  5327. result,
  5328. data
  5329. } = await tools_httpRequest({
  5330. url: 'https://store.steampowered.com/api/removefromwishlist',
  5331. method: 'POST',
  5332. headers: {
  5333. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5334. },
  5335. data: $.param({
  5336. sessionid: this.#auth.storeSessionID,
  5337. appid: gameId
  5338. }),
  5339. dataType: 'json'
  5340. });
  5341. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5342. logStatus.success();
  5343. return true;
  5344. }
  5345. const {
  5346. result: resultR,
  5347. statusText: statusTextR,
  5348. status: statusR,
  5349. data: dataR
  5350. } = await tools_httpRequest({
  5351. url: `https://store.steampowered.com/app/${gameId}`,
  5352. method: 'GET'
  5353. });
  5354. if (resultR === 'Success') {
  5355. if (dataR?.status === 200) {
  5356. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5357. logStatus.warning(i18n('changeAreaNotice'));
  5358. const result = await this.#changeArea();
  5359. if (!result || result === 'CN' || result === 'skip') {
  5360. return false;
  5361. }
  5362. return await this.#removeFromWishlist(gameId);
  5363. }
  5364. if (dataR.responseText.includes('class="queue_actions_ctn"') && (dataR.responseText.includes('ds_owned_flag ds_flag') || dataR.responseText.includes('add_to_wishlist_area'))) {
  5365. logStatus.success();
  5366. return true;
  5367. }
  5368. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5369. return false;
  5370. }
  5371. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5372. return false;
  5373. }
  5374. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5375. return false;
  5376. } catch (error) {
  5377. throwError(error, 'Steam.removeFromWishlist');
  5378. return false;
  5379. }
  5380. }
  5381. async #toggleFollowGame(gameId, doTask) {
  5382. try {
  5383. if (!doTask && this.whiteList.follows.includes(gameId)) {
  5384. scripts_echoLog({
  5385. type: 'whiteList',
  5386. text: 'Steam.unfollowGame',
  5387. id: gameId
  5388. });
  5389. return true;
  5390. }
  5391. if (this.#ASF) {
  5392. if (await this.#ASF.toggleFollowGame(gameId, doTask)) {
  5393. if (doTask) {
  5394. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5395. }
  5396. return true;
  5397. }
  5398. return false;
  5399. }
  5400. const logStatus = scripts_echoLog({
  5401. type: `${doTask ? '' : 'un'}followingGame`,
  5402. text: gameId
  5403. });
  5404. const requestData = {
  5405. sessionid: this.#auth.storeSessionID,
  5406. appid: gameId
  5407. };
  5408. if (!doTask) {
  5409. requestData.unfollow = '1';
  5410. }
  5411. const {
  5412. result,
  5413. data
  5414. } = await tools_httpRequest({
  5415. url: 'https://store.steampowered.com/explore/followgame/',
  5416. method: 'POST',
  5417. headers: {
  5418. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5419. },
  5420. data: $.param(requestData)
  5421. });
  5422. if (result === 'Success' && data?.status === 200 && data.responseText === 'true') {
  5423. logStatus.success();
  5424. return true;
  5425. }
  5426. const followed = await this.#isFollowedGame(gameId);
  5427. if (this.#area === 'CN' && followed === 'areaLocked') {
  5428. logStatus.warning(i18n('changeAreaNotice'));
  5429. if (!await this.#changeArea()) {
  5430. return false;
  5431. }
  5432. return await this.#removeFromWishlist(gameId);
  5433. }
  5434. if (doTask === followed) {
  5435. logStatus.success();
  5436. if (doTask) {
  5437. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5438. }
  5439. return true;
  5440. }
  5441. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5442. return false;
  5443. } catch (error) {
  5444. throwError(error, 'Steam.toggleFollowGame');
  5445. return false;
  5446. }
  5447. }
  5448. async #isFollowedGame(gameId) {
  5449. try {
  5450. const {
  5451. result,
  5452. data
  5453. } = await tools_httpRequest({
  5454. url: `https://store.steampowered.com/app/${gameId}`,
  5455. method: 'GET'
  5456. });
  5457. if (result === 'Success') {
  5458. if (data?.status === 200) {
  5459. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  5460. return 'areaLocked';
  5461. }
  5462. if ($(data.responseText.replace(/<img.*?>/g, '')).find('.queue_control_button.queue_btn_follow>.btnv6_blue_hoverfade.btn_medium.queue_btn_active').css('display') !== 'none') {
  5463. return true;
  5464. }
  5465. return false;
  5466. }
  5467. return false;
  5468. }
  5469. return false;
  5470. } catch (error) {
  5471. throwError(error, 'Steam.isFollowedGame');
  5472. return false;
  5473. }
  5474. }
  5475. async #toggleForum(gameId, doTask = true) {
  5476. try {
  5477. if (!doTask && this.whiteList.forums.includes(gameId)) {
  5478. scripts_echoLog({
  5479. type: 'whiteList',
  5480. text: 'Steam.unsubscribeForum',
  5481. id: gameId
  5482. });
  5483. return true;
  5484. }
  5485. const forumId = await this.#getForumId(gameId);
  5486. if (!forumId) {
  5487. return false;
  5488. }
  5489. const logStatus = scripts_echoLog({
  5490. type: `${doTask ? '' : 'un'}subscribingForum`,
  5491. text: gameId
  5492. });
  5493. const [ id, feature ] = forumId.split('_');
  5494. const {
  5495. result,
  5496. statusText,
  5497. status,
  5498. data
  5499. } = await tools_httpRequest({
  5500. url: `https://steamcommunity.com/forum/${id}/General/${doTask ? '' : 'un'}subscribe/${feature || '0'}/`,
  5501. method: 'POST',
  5502. responseType: 'json',
  5503. headers: {
  5504. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5505. },
  5506. data: $.param({
  5507. sessionid: this.#auth.communitySessionID
  5508. })
  5509. });
  5510. if (result === 'Success') {
  5511. if (data?.status === 200 && (data.response?.success === 1 || data.response?.success === 29)) {
  5512. if (doTask) {
  5513. this.tasks.forums = unique([ ...this.tasks.forums, gameId ]);
  5514. }
  5515. logStatus.success();
  5516. return true;
  5517. }
  5518. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5519. return true;
  5520. }
  5521. logStatus.error(`${result}:${statusText}(${status})`);
  5522. return true;
  5523. } catch (error) {
  5524. throwError(error, 'Steam.toggleForum');
  5525. return true;
  5526. }
  5527. }
  5528. async #getForumId(gameId) {
  5529. try {
  5530. const logStatus = scripts_echoLog({
  5531. type: 'gettingForumId',
  5532. text: gameId
  5533. });
  5534. const forumId = this.#cache.forum[gameId];
  5535. if (forumId) {
  5536. logStatus.success();
  5537. return forumId;
  5538. }
  5539. const {
  5540. result,
  5541. statusText,
  5542. status,
  5543. data
  5544. } = await tools_httpRequest({
  5545. url: `https://steamcommunity.com/app/${gameId}/discussions/`,
  5546. method: 'GET'
  5547. });
  5548. if (result === 'Success') {
  5549. if (data?.status === 200) {
  5550. const forumId = data.responseText?.match(/General_([\d]+(_[\d]+)?)/)?.[1];
  5551. if (forumId) {
  5552. this.#setCache('forum', gameId, forumId);
  5553. logStatus.success();
  5554. return forumId;
  5555. }
  5556. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5557. return false;
  5558. }
  5559. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5560. return false;
  5561. }
  5562. logStatus.error(`${result}:${statusText}(${status})`);
  5563. return false;
  5564. } catch (error) {
  5565. throwError(error, 'Steam.getForumId');
  5566. return false;
  5567. }
  5568. }
  5569. async #toggleFavoriteWorkshop(id, doTask = true) {
  5570. try {
  5571. if (!doTask && this.whiteList.workshops.includes(id)) {
  5572. scripts_echoLog({
  5573. type: 'whiteList',
  5574. text: 'Steam.unfavoriteWorkshop',
  5575. id: id
  5576. });
  5577. return true;
  5578. }
  5579. const appid = await this.#getWorkshopAppId(id);
  5580. if (!appid) {
  5581. return false;
  5582. }
  5583. const logStatus = scripts_echoLog({
  5584. type: doTask ? 'favoritingWorkshop' : 'unfavoritingWorkshop',
  5585. text: id
  5586. });
  5587. const {
  5588. result,
  5589. statusText,
  5590. status,
  5591. data
  5592. } = await tools_httpRequest({
  5593. url: `https://steamcommunity.com/sharedfiles/${doTask ? '' : 'un'}favorite`,
  5594. method: 'POST',
  5595. headers: {
  5596. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5597. },
  5598. data: $.param({
  5599. id: id,
  5600. appid: appid,
  5601. sessionid: this.#auth.communitySessionID
  5602. })
  5603. });
  5604. if (result === 'Success') {
  5605. if (data?.status === 200 && !data.responseText) {
  5606. if (doTask) {
  5607. this.tasks.workshops = unique([ ...this.tasks.workshops, id ]);
  5608. }
  5609. logStatus.success();
  5610. return true;
  5611. }
  5612. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5613. return false;
  5614. }
  5615. logStatus.error(`${result}:${statusText}(${status})`);
  5616. return false;
  5617. } catch (error) {
  5618. throwError(error, 'Steam.toggleFavoriteWorkshop');
  5619. return false;
  5620. }
  5621. }
  5622. async #getWorkshopAppId(id) {
  5623. try {
  5624. const logStatus = scripts_echoLog({
  5625. type: 'gettingWorkshopAppId',
  5626. text: id
  5627. });
  5628. const appId = this.#cache.workshop[id];
  5629. if (appId) {
  5630. logStatus.success();
  5631. return appId;
  5632. }
  5633. const {
  5634. result,
  5635. statusText,
  5636. status,
  5637. data
  5638. } = await tools_httpRequest({
  5639. url: `https://steamcommunity.com/sharedfiles/filedetails/?id=${id}`,
  5640. method: 'GET'
  5641. });
  5642. if (result === 'Success') {
  5643. if (data?.status === 200) {
  5644. const appId = data.responseText.match(/<input type="hidden" name="appid" value="([\d]+?)" \/>/)?.[1];
  5645. if (appId) {
  5646. this.#setCache('workshop', id, appId);
  5647. logStatus.success();
  5648. return appId;
  5649. }
  5650. logStatus.error('Error: getWorkshopAppId failed');
  5651. return false;
  5652. }
  5653. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5654. return false;
  5655. }
  5656. logStatus.error(`${result}:${statusText}(${status})`);
  5657. return false;
  5658. } catch (error) {
  5659. throwError(error, 'Steam.getWorkshopAppId');
  5660. return false;
  5661. }
  5662. }
  5663. async #voteUpWorkshop(id) {
  5664. try {
  5665. const logStatus = scripts_echoLog({
  5666. type: 'votingUpWorkshop',
  5667. text: id
  5668. });
  5669. const {
  5670. result,
  5671. statusText,
  5672. status,
  5673. data
  5674. } = await tools_httpRequest({
  5675. url: 'https://steamcommunity.com/sharedfiles/voteup',
  5676. method: 'POST',
  5677. responseType: 'json',
  5678. headers: {
  5679. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5680. },
  5681. data: $.param({
  5682. id: id,
  5683. sessionid: this.#auth.communitySessionID
  5684. })
  5685. });
  5686. if (result === 'Success') {
  5687. if (data?.status === 200 && data.response?.success === 1) {
  5688. logStatus.success();
  5689. return true;
  5690. }
  5691. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5692. return true;
  5693. }
  5694. logStatus.error(`${result}:${statusText}(${status})`);
  5695. return true;
  5696. } catch (error) {
  5697. throwError(error, 'Steam.voteupWorkshop');
  5698. return true;
  5699. }
  5700. }
  5701. async #toggleCurator(curatorId, doTask = true) {
  5702. try {
  5703. if (!doTask && this.whiteList.curators.includes(curatorId)) {
  5704. scripts_echoLog({
  5705. type: 'whiteList',
  5706. text: 'Steam.unfollowCurator',
  5707. id: curatorId
  5708. });
  5709. return true;
  5710. }
  5711. if (this.#ASF) {
  5712. return await this.#ASF.toggleCurator(curatorId, doTask);
  5713. }
  5714. const logStatus = scripts_echoLog({
  5715. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  5716. text: curatorId
  5717. });
  5718. const {
  5719. result,
  5720. statusText,
  5721. status,
  5722. data
  5723. } = await tools_httpRequest({
  5724. url: 'https://store.steampowered.com/curators/ajaxfollow',
  5725. method: 'POST',
  5726. headers: {
  5727. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5728. },
  5729. data: $.param({
  5730. clanid: curatorId,
  5731. sessionid: this.#auth.storeSessionID,
  5732. follow: doTask
  5733. }),
  5734. dataType: 'json'
  5735. });
  5736. if (result === 'Success') {
  5737. if (data?.status === 200 && data.response?.success?.success === 1) {
  5738. logStatus.success();
  5739. return true;
  5740. }
  5741. logStatus.error(`Error:${data?.statusText}(${data?.response?.success}` || `${data?.status})`);
  5742. return false;
  5743. }
  5744. logStatus.error(`${result}:${statusText}(${status})`);
  5745. return false;
  5746. } catch (error) {
  5747. throwError(error, 'Steam.toggleCurator');
  5748. return false;
  5749. }
  5750. }
  5751. async getCuratorId(path, name) {
  5752. try {
  5753. const logStatus = scripts_echoLog({
  5754. type: 'gettingCuratorId',
  5755. text: `${path}/${name}`
  5756. });
  5757. const curatorId = this.#cache.curator[`${path}/${name}`];
  5758. if (curatorId) {
  5759. logStatus.success();
  5760. return curatorId;
  5761. }
  5762. const {
  5763. result,
  5764. statusText,
  5765. status,
  5766. data
  5767. } = await tools_httpRequest({
  5768. url: `https://store.steampowered.com/${path}/${name}`,
  5769. method: 'GET',
  5770. headers: {
  5771. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5772. }
  5773. });
  5774. if (result === 'Success') {
  5775. if (data?.status === 200) {
  5776. const curatorId = data.responseText.match(/g_pagingData.*?"clanid":([\d]+)/)?.[1];
  5777. if (curatorId) {
  5778. this.#setCache('curator', `${path}/${name}`, curatorId);
  5779. logStatus.success();
  5780. return curatorId;
  5781. }
  5782. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5783. return false;
  5784. }
  5785. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5786. return false;
  5787. }
  5788. logStatus.error(`${result}:${statusText}(${status})`);
  5789. return false;
  5790. } catch (error) {
  5791. throwError(error, 'Steam.getCuratorID');
  5792. return false;
  5793. }
  5794. }
  5795. async #toggleCuratorLike(link, doTask = true) {
  5796. try {
  5797. const [ path, name ] = link.split('/');
  5798. if (!(path && name)) {
  5799. scripts_echoLog({
  5800. text: i18n('errorLink', link)
  5801. });
  5802. return false;
  5803. }
  5804. const curatorId = await this.getCuratorId(path, name);
  5805. if (curatorId) {
  5806. return await this.#toggleCurator(curatorId, doTask);
  5807. }
  5808. return false;
  5809. } catch (error) {
  5810. throwError(error, 'Steam.toggleCuratorLike');
  5811. return false;
  5812. }
  5813. }
  5814. async #getAnnouncementParams(appId, viewId) {
  5815. try {
  5816. const logStatus = scripts_echoLog({
  5817. type: 'gettingAnnouncementParams',
  5818. text: appId,
  5819. id: viewId
  5820. });
  5821. const {
  5822. result,
  5823. statusText,
  5824. status,
  5825. data
  5826. } = await tools_httpRequest({
  5827. url: `https://store.steampowered.com/events/ajaxgetpartnerevent?appid=${appId}&announcement_gid=${viewId}&lang_list=6_0&last_modified_time=0&origin=https:%2F%2Fstore.steampowered.com&for_edit=false`,
  5828. method: 'GET',
  5829. responseType: 'json',
  5830. headers: {
  5831. Host: 'store.steampowered.com',
  5832. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  5833. }
  5834. });
  5835. if (result === 'Success') {
  5836. if (data?.status === 200 && data?.response?.success === 1) {
  5837. const {
  5838. clanid,
  5839. gid
  5840. } = data.response.event?.announcement_body || {};
  5841. if (clanid) {
  5842. logStatus.success();
  5843. return {
  5844. clanId: clanid,
  5845. gid: gid
  5846. };
  5847. }
  5848. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5849. return {};
  5850. }
  5851. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5852. return {};
  5853. }
  5854. logStatus.error(`${result}:${statusText}(${status})`);
  5855. return {};
  5856. } catch (error) {
  5857. throwError(error, 'Steam.likeAnnouncement');
  5858. return {};
  5859. }
  5860. }
  5861. async #likeAnnouncement(id) {
  5862. try {
  5863. const [ appId, viewId ] = id.split('/');
  5864. if (!(appId && viewId)) {
  5865. scripts_echoLog({}).error(`${i18n('missParams')}(id)`);
  5866. return false;
  5867. }
  5868. const {
  5869. clanId,
  5870. gid
  5871. } = await this.#getAnnouncementParams(appId, viewId);
  5872. if (!clanId) {
  5873. return false;
  5874. }
  5875. const logStatus = scripts_echoLog({
  5876. type: 'likingAnnouncement',
  5877. text: appId,
  5878. id: viewId
  5879. });
  5880. const {
  5881. result,
  5882. statusText,
  5883. status,
  5884. data
  5885. } = await tools_httpRequest({
  5886. url: `https://store.steampowered.com/updated/ajaxrateupdate/${gid || viewId}`,
  5887. method: 'POST',
  5888. headers: {
  5889. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  5890. Host: 'store.steampowered.com',
  5891. Origin: 'https://store.steampowered.com',
  5892. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  5893. },
  5894. data: $.param({
  5895. sessionid: this.#auth.storeSessionID,
  5896. voteup: 1,
  5897. clanid: clanId,
  5898. ajax: 1
  5899. }),
  5900. dataType: 'json'
  5901. });
  5902. if (result === 'Success') {
  5903. if (data?.status === 200 && data.response.success === 1) {
  5904. logStatus.success();
  5905. return true;
  5906. }
  5907. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5908. return false;
  5909. }
  5910. logStatus.error(`${result}:${statusText}(${status})`);
  5911. return false;
  5912. } catch (error) {
  5913. throwError(error, 'Steam.likeAnnouncement');
  5914. return false;
  5915. }
  5916. }
  5917. async #appid2subid(id) {
  5918. try {
  5919. const logStatus = scripts_echoLog({
  5920. type: 'gettingSubid',
  5921. text: id
  5922. });
  5923. const {
  5924. result,
  5925. statusText,
  5926. status,
  5927. data
  5928. } = await tools_httpRequest({
  5929. url: `https://store.steampowered.com/app/${id}`,
  5930. method: 'GET',
  5931. headers: {
  5932. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5933. }
  5934. });
  5935. if (result === 'Success') {
  5936. if (data?.status === 200) {
  5937. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  5938. logStatus.warning(i18n('changeAreaNotice'));
  5939. const result = await this.#changeArea();
  5940. if (!result || result === 'CN' || result === 'skip') {
  5941. return false;
  5942. }
  5943. return await this.#appid2subid(id);
  5944. }
  5945. const subid = data.responseText.match(/name="subid" value="([\d]+?)"/)?.[1];
  5946. if (subid) {
  5947. logStatus.success();
  5948. return subid;
  5949. }
  5950. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5951. return false;
  5952. }
  5953. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5954. return false;
  5955. }
  5956. logStatus.error(`${result}:${statusText}(${status})`);
  5957. return false;
  5958. } catch (error) {
  5959. throwError(error, 'Steam.appid2subid');
  5960. return false;
  5961. }
  5962. }
  5963. async #getLicenses() {
  5964. try {
  5965. const logStatus = scripts_echoLog({
  5966. text: i18n('gettingLicenses')
  5967. });
  5968. const {
  5969. result,
  5970. statusText,
  5971. status,
  5972. data
  5973. } = await tools_httpRequest({
  5974. url: `https://store.steampowered.com/dynamicstore/userdata/?t=${new Date().getTime()}`,
  5975. method: 'GET',
  5976. responseType: 'json'
  5977. });
  5978. if (result === 'Success') {
  5979. if (data?.status === 200) {
  5980. logStatus.success();
  5981. return data.response?.rgOwnedPackages;
  5982. }
  5983. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5984. return false;
  5985. }
  5986. logStatus.error(`${result}:${statusText}(${status})`);
  5987. return false;
  5988. } catch (error) {
  5989. throwError(error, 'Steam.getLicenses');
  5990. return false;
  5991. }
  5992. }
  5993. async #addLicense(id) {
  5994. try {
  5995. if (this.#ASF) {
  5996. return await this.#ASF.addLicense(id);
  5997. }
  5998. const [ type, ids ] = id.split('-');
  5999. if (type === 'appid') {
  6000. const subid = await this.#appid2subid(ids);
  6001. if (!subid) {
  6002. return false;
  6003. }
  6004. const logStatus = scripts_echoLog({
  6005. type: 'addingFreeLicense',
  6006. text: ids
  6007. });
  6008. if (!await this.#addFreeLicense(subid, logStatus)) {
  6009. return false;
  6010. }
  6011. const {
  6012. result,
  6013. statusText,
  6014. status,
  6015. data
  6016. } = await tools_httpRequest({
  6017. url: `https://store.steampowered.com/app/${ids}`,
  6018. method: 'GET'
  6019. });
  6020. if (result === 'Success') {
  6021. if (data?.status === 200) {
  6022. if (data.responseText.includes('ds_owned_flag ds_flag') || data.responseText.includes('class="already_in_library"')) {
  6023. logStatus.success();
  6024. return true;
  6025. }
  6026. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6027. return false;
  6028. }
  6029. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6030. return false;
  6031. }
  6032. logStatus.error(`${result}:${statusText}(${status})`);
  6033. return false;
  6034. } else if (type === 'subid') {
  6035. if (this.#area === 'CN') {
  6036. scripts_echoLog({}).success(i18n('tryChangeAreaNotice'));
  6037. await this.#changeArea();
  6038. }
  6039. const logStatusArr = {};
  6040. const idsArr = ids.split(',');
  6041. for (const subid of idsArr) {
  6042. const logStatus = scripts_echoLog({
  6043. type: 'addingFreeLicenseSubid',
  6044. text: subid
  6045. });
  6046. if (!await this.#addFreeLicense(subid, logStatus)) {
  6047. return false;
  6048. }
  6049. logStatusArr[subid] = logStatus;
  6050. }
  6051. const licenses = await this.#getLicenses();
  6052. if (!licenses) {
  6053. return false;
  6054. }
  6055. for (const subid of idsArr) {
  6056. if (licenses.includes(parseInt(subid, 10))) {
  6057. logStatusArr[subid].success();
  6058. } else {
  6059. logStatusArr[subid].error();
  6060. }
  6061. }
  6062. return true;
  6063. }
  6064. return false;
  6065. } catch (error) {
  6066. throwError(error, 'Steam.addLicense');
  6067. return false;
  6068. }
  6069. }
  6070. async #addFreeLicense(id, logStatusPre) {
  6071. try {
  6072. const logStatus = logStatusPre || scripts_echoLog({
  6073. type: 'addingFreeLicenseSubid',
  6074. text: id
  6075. });
  6076. const {
  6077. result,
  6078. statusText,
  6079. status,
  6080. data
  6081. } = await tools_httpRequest({
  6082. url: 'https://store.steampowered.com/checkout/addfreelicense',
  6083. method: 'POST',
  6084. headers: {
  6085. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6086. Host: 'store.steampowered.com',
  6087. Origin: 'https://store.steampowered.com',
  6088. Referer: 'https://store.steampowered.com/account/licenses/'
  6089. },
  6090. data: $.param({
  6091. action: 'add_to_cart',
  6092. sessionid: this.#auth.storeSessionID,
  6093. subid: id
  6094. }),
  6095. dataType: 'json'
  6096. });
  6097. if (result === 'Success') {
  6098. if (data?.status === 200) {
  6099. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6100. logStatus.warning(i18n('changeAreaNotice'));
  6101. const result = await this.#changeArea();
  6102. if (!result || result === 'CN') {
  6103. return false;
  6104. }
  6105. return await this.#addFreeLicense(id);
  6106. }
  6107. logStatus.success();
  6108. return true;
  6109. }
  6110. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6111. return false;
  6112. }
  6113. logStatus.error(`${result}:${statusText}(${status})`);
  6114. return false;
  6115. } catch (error) {
  6116. throwError(error, 'Steam.addFreeLicense');
  6117. return false;
  6118. }
  6119. }
  6120. async #requestPlayTestAccess(id) {
  6121. try {
  6122. if (this.#ASF) {
  6123. return await this.#ASF.requestPlayTestAccess(id);
  6124. }
  6125. const logStatus = scripts_echoLog({
  6126. type: 'requestingPlayTestAccess',
  6127. text: id
  6128. });
  6129. const {
  6130. result,
  6131. statusText,
  6132. status,
  6133. data
  6134. } = await tools_httpRequest({
  6135. url: `https://store.steampowered.com/ajaxrequestplaytestaccess/${id}`,
  6136. method: 'POST',
  6137. headers: {
  6138. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6139. Host: 'store.steampowered.com',
  6140. Origin: 'https://store.steampowered.com',
  6141. Referer: `https://store.steampowered.com/app/${id}`
  6142. },
  6143. data: $.param({
  6144. sessionid: this.#auth.storeSessionID
  6145. }),
  6146. dataType: 'json'
  6147. });
  6148. if (result === 'Success') {
  6149. if (data?.status === 200 && data?.response?.success === 1) {
  6150. logStatus.success();
  6151. return true;
  6152. }
  6153. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6154. return false;
  6155. }
  6156. logStatus.error(`${result}:${statusText}(${status})`);
  6157. return false;
  6158. } catch (error) {
  6159. throwError(error, 'Steam.requestPlayTestAccess');
  6160. return false;
  6161. }
  6162. }
  6163. async toggle({
  6164. doTask = true,
  6165. groupLinks = [],
  6166. officialGroupLinks = [],
  6167. wishlistLinks = [],
  6168. followLinks = [],
  6169. forumLinks = [],
  6170. workshopLinks = [],
  6171. workshopVoteLinks = [],
  6172. curatorLinks = [],
  6173. curatorLikeLinks = [],
  6174. announcementLinks = [],
  6175. licenseLinks = [],
  6176. playtestLinks = []
  6177. }) {
  6178. try {
  6179. if ([ ...groupLinks, ...officialGroupLinks, ...forumLinks, ...workshopLinks, ...workshopVoteLinks ].length > 0 && !this.#communityInitialized) {
  6180. scripts_echoLog({
  6181. text: i18n('needInit')
  6182. });
  6183. return false;
  6184. }
  6185. if ([ ...wishlistLinks, ...followLinks, ...curatorLinks, ...curatorLikeLinks, ...announcementLinks, ...licenseLinks, ...playtestLinks ].length > 0 && !this.#storeInitialized) {
  6186. scripts_echoLog({
  6187. text: i18n('needInit')
  6188. });
  6189. return false;
  6190. }
  6191. const prom = [];
  6192. if (doTask && !globalOptions.doTask.steam.groups || !doTask && !globalOptions.undoTask.steam.groups) {
  6193. scripts_echoLog({
  6194. type: 'globalOptionsSkip',
  6195. text: 'steam.groups'
  6196. });
  6197. } else {
  6198. const realGroups = this.getRealParams('groups', groupLinks, doTask, link => link.match(/groups\/(.+)\/?/)?.[1]);
  6199. if (realGroups.length > 0) {
  6200. for (const group of realGroups) {
  6201. if (doTask) {
  6202. prom.push(this.#joinGroup(group));
  6203. } else {
  6204. prom.push(this.#leaveGroup(group));
  6205. }
  6206. await delay(1e3);
  6207. }
  6208. }
  6209. }
  6210. if (doTask && !globalOptions.doTask.steam.officialGroups || !doTask && !globalOptions.undoTask.steam.officialGroups) {
  6211. scripts_echoLog({
  6212. type: 'globalOptionsSkip',
  6213. text: 'steam.officialGroups'
  6214. });
  6215. } else {
  6216. const realOfficialGroups = this.getRealParams('officialGroups', officialGroupLinks, doTask, link => link.match(/games\/(.+)\/?/)?.[1]);
  6217. if (realOfficialGroups.length > 0) {
  6218. for (const officialGroup of realOfficialGroups) {
  6219. if (doTask) {
  6220. prom.push(this.#joinOfficialGroup(officialGroup));
  6221. } else {
  6222. prom.push(this.#leaveOfficialGroup(officialGroup));
  6223. }
  6224. await delay(1e3);
  6225. }
  6226. }
  6227. }
  6228. if (doTask && !globalOptions.doTask.steam.wishlists || !doTask && !globalOptions.undoTask.steam.wishlists) {
  6229. scripts_echoLog({
  6230. type: 'globalOptionsSkip',
  6231. text: 'steam.wishlists'
  6232. });
  6233. } else {
  6234. const realWishlists = this.getRealParams('wishlists', wishlistLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6235. if (realWishlists.length > 0) {
  6236. for (const game of realWishlists) {
  6237. if (doTask) {
  6238. prom.push(this.#addToWishlist(game));
  6239. } else {
  6240. prom.push(this.#removeFromWishlist(game));
  6241. }
  6242. await delay(1e3);
  6243. }
  6244. }
  6245. }
  6246. if (doTask && !globalOptions.doTask.steam.follows || !doTask && !globalOptions.undoTask.steam.follows) {
  6247. scripts_echoLog({
  6248. type: 'globalOptionsSkip',
  6249. text: 'steam.follows'
  6250. });
  6251. } else {
  6252. const realFollows = this.getRealParams('follows', followLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6253. if (realFollows.length > 0) {
  6254. for (const game of realFollows) {
  6255. prom.push(this.#toggleFollowGame(game, doTask));
  6256. await delay(1e3);
  6257. }
  6258. }
  6259. }
  6260. if (doTask && !globalOptions.doTask.steam.forums || !doTask && !globalOptions.undoTask.steam.forums) {
  6261. scripts_echoLog({
  6262. type: 'globalOptionsSkip',
  6263. text: 'steam.forums'
  6264. });
  6265. } else {
  6266. const realForums = this.getRealParams('forums', forumLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6267. if (realForums.length > 0) {
  6268. for (const forum of realForums) {
  6269. prom.push(this.#toggleForum(forum, doTask));
  6270. await delay(1e3);
  6271. }
  6272. }
  6273. }
  6274. if (doTask && !globalOptions.doTask.steam.workshops || !doTask && !globalOptions.undoTask.steam.workshops) {
  6275. scripts_echoLog({
  6276. type: 'globalOptionsSkip',
  6277. text: 'steam.workshops'
  6278. });
  6279. } else {
  6280. const realWorkshops = this.getRealParams('workshops', workshopLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6281. if (realWorkshops.length > 0) {
  6282. for (const workshop of realWorkshops) {
  6283. prom.push(this.#toggleFavoriteWorkshop(workshop, doTask));
  6284. await delay(1e3);
  6285. }
  6286. }
  6287. }
  6288. if (doTask && !globalOptions.doTask.steam.workshopVotes) {
  6289. scripts_echoLog({
  6290. type: 'globalOptionsSkip',
  6291. text: 'steam.workshopVotes'
  6292. });
  6293. } else {
  6294. const realworkshopVotes = this.getRealParams('workshopVotes', workshopVoteLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6295. if (doTask && realworkshopVotes.length > 0) {
  6296. for (const workshop of realworkshopVotes) {
  6297. prom.push(this.#voteUpWorkshop(workshop));
  6298. await delay(1e3);
  6299. }
  6300. }
  6301. }
  6302. if (doTask && !globalOptions.doTask.steam.curators || !doTask && !globalOptions.undoTask.steam.curators) {
  6303. scripts_echoLog({
  6304. type: 'globalOptionsSkip',
  6305. text: 'steam.curators'
  6306. });
  6307. } else {
  6308. const realCurators = this.getRealParams('curators', curatorLinks, doTask, link => link.match(/curator\/([\d]+)/)?.[1]);
  6309. const realCuratorLikes = this.getRealParams('curatorLikes', curatorLikeLinks, doTask, link => link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3).join('/'));
  6310. if (realCurators.length > 0) {
  6311. for (const curator of realCurators) {
  6312. prom.push(this.#toggleCurator(curator, doTask));
  6313. await delay(1e3);
  6314. }
  6315. }
  6316. if (realCuratorLikes.length > 0) {
  6317. for (const curatorLike of realCuratorLikes) {
  6318. prom.push(this.#toggleCuratorLike(curatorLike, doTask));
  6319. await delay(1e3);
  6320. }
  6321. }
  6322. }
  6323. if (doTask && !globalOptions.doTask.steam.announcements) {
  6324. scripts_echoLog({
  6325. type: 'globalOptionsSkip',
  6326. text: 'steam.announcements'
  6327. });
  6328. } else {
  6329. const realAnnouncements = this.getRealParams('announcements', announcementLinks, doTask, link => {
  6330. if (link.includes('store.steampowered.com')) {
  6331. return link.match(/store\.steampowered\.com\/news\/app\/([\d]+)\/view\/([\d]+)/)?.slice(1, 3).join('/');
  6332. }
  6333. return link.match(/steamcommunity\.com\/games\/([\d]+)\/announcements\/detail\/([\d]+)/)?.slice(1, 3).join('/');
  6334. });
  6335. if (doTask && realAnnouncements.length > 0) {
  6336. for (const id of realAnnouncements) {
  6337. prom.push(this.#likeAnnouncement(id));
  6338. await delay(1e3);
  6339. }
  6340. }
  6341. }
  6342. if (doTask && !globalOptions.doTask.steam.licenses) {
  6343. scripts_echoLog({
  6344. type: 'globalOptionsSkip',
  6345. text: 'steam.licenses'
  6346. });
  6347. } else if (doTask && globalOptions.doTask.steam.licenses && licenseLinks.length > 0) {
  6348. for (const id of licenseLinks) {
  6349. prom.push(this.#addLicense(id));
  6350. await delay(1e3);
  6351. }
  6352. }
  6353. if (doTask && !globalOptions.doTask.steam.playtests) {
  6354. scripts_echoLog({
  6355. type: 'globalOptionsSkip',
  6356. text: 'steam.playtests'
  6357. });
  6358. } else {
  6359. const realPlaytests = this.getRealParams('playtests', playtestLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6360. if (doTask && globalOptions.doTask.steam.playtests && realPlaytests.length > 0) {
  6361. for (const id of realPlaytests) {
  6362. prom.push(this.#requestPlayTestAccess(id));
  6363. await delay(1e3);
  6364. }
  6365. }
  6366. }
  6367. return Promise.all(prom).then(async () => {
  6368. if (this.#area !== 'CN') {
  6369. scripts_echoLog({}).warning(i18n('steamFinishNotice'));
  6370. await this.#changeArea('CN');
  6371. }
  6372. return true;
  6373. });
  6374. } catch (error) {
  6375. throwError(error, 'Steam.toggle');
  6376. return false;
  6377. }
  6378. }
  6379. #setCache(type, name, id) {
  6380. try {
  6381. this.#cache[type][name] = id;
  6382. GM_setValue('steamCache', this.#cache);
  6383. } catch (error) {
  6384. throwError(error, 'Steam.setCache');
  6385. }
  6386. }
  6387. }
  6388. const social_Steam = Steam;
  6389. class Website {
  6390. undoneTasks;
  6391. socialTasks;
  6392. giveawayId;
  6393. socialInitialized = {
  6394. discord: false,
  6395. instagram: false,
  6396. reddit: false,
  6397. twitch: false,
  6398. twitter: false,
  6399. vk: false,
  6400. youtube: false,
  6401. steamStore: false,
  6402. steamCommunity: false
  6403. };
  6404. initialized = false;
  6405. social = {};
  6406. async #bind(name, init) {
  6407. try {
  6408. return {
  6409. name: name,
  6410. result: await init
  6411. };
  6412. } catch (error) {
  6413. throwError(error, 'Website.bind');
  6414. return {
  6415. name: name,
  6416. result: false
  6417. };
  6418. }
  6419. }
  6420. async initSocial(action) {
  6421. try {
  6422. const pro = [];
  6423. const tasks = action === 'do' ? this.undoneTasks : this.socialTasks;
  6424. if (tasks.discord) {
  6425. const hasDiscord = Object.values(tasks.discord).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6426. if (hasDiscord && (!this.socialInitialized.discord || !this.social.discord)) {
  6427. this.social.discord = new social_Discord();
  6428. pro.push(this.#bind('discord', this.social.discord.init(action)));
  6429. }
  6430. }
  6431. if (tasks.instagram) {
  6432. const hasInstagram = Object.values(tasks.instagram).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6433. if (hasInstagram && (!this.socialInitialized.instagram || !this.social.instagram)) {
  6434. this.social.instagram = new social_Instagram();
  6435. pro.push(this.#bind('instagram', this.social.instagram.init()));
  6436. }
  6437. }
  6438. if (tasks.reddit) {
  6439. const hasReddit = Object.values(tasks.reddit).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6440. if (hasReddit && (!this.socialInitialized.reddit || !this.social.reddit)) {
  6441. this.social.reddit = new social_Reddit();
  6442. pro.push(this.#bind('reddit', this.social.reddit.init()));
  6443. }
  6444. }
  6445. if (tasks.twitch) {
  6446. const hasTwitch = Object.values(tasks.twitch).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6447. if (hasTwitch && (!this.socialInitialized.twitch || !this.social.twitch)) {
  6448. this.social.twitch = new social_Twitch();
  6449. pro.push(this.#bind('twitch', this.social.twitch.init()));
  6450. }
  6451. }
  6452. if (tasks.twitter) {
  6453. const hasTwitter = Object.values(tasks.twitter).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6454. if (hasTwitter && (!this.socialInitialized.twitter || !this.social.twitter)) {
  6455. this.social.twitter = new social_Twitter();
  6456. pro.push(this.#bind('twitter', this.social.twitter.init()));
  6457. }
  6458. }
  6459. if (tasks.vk) {
  6460. const hasVk = Object.values(tasks.vk).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6461. if (hasVk && (!this.socialInitialized.vk || !this.social.vk)) {
  6462. this.social.vk = new social_Vk();
  6463. pro.push(this.#bind('vk', this.social.vk.init()));
  6464. }
  6465. }
  6466. if (tasks.youtube) {
  6467. const hasYoutube = Object.values(tasks.youtube).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6468. if (hasYoutube && (!this.socialInitialized.youtube || !this.social.youtube)) {
  6469. this.social.youtube = new Youtube();
  6470. pro.push(this.#bind('youtube', this.social.youtube.init()));
  6471. }
  6472. }
  6473. if (tasks.steam) {
  6474. const steamLength = Object.values(tasks.steam).reduce((total, arr) => [ ...total, ...arr ]).length;
  6475. if (steamLength > 0) {
  6476. if (!this.social.steam) {
  6477. this.social.steam = new social_Steam();
  6478. }
  6479. const steamCommunityLength = Object.keys(tasks.steam).map(type => [ 'groupLinks', 'officialGroupLinks', 'forumLinks', 'workshopLinks', 'workshopVoteLinks' ].includes(type) ? tasks.steam?.[type]?.length || 0 : 0).reduce((total, number) => total + number, 0);
  6480. if (steamLength - steamCommunityLength > 0 && !this.socialInitialized.steamStore) {
  6481. pro.push(this.#bind('steamStore', this.social.steam.init('store')));
  6482. }
  6483. if (steamCommunityLength > 0 && !this.socialInitialized.steamCommunity) {
  6484. pro.push(this.#bind('steamCommunity', this.social.steam.init('community')));
  6485. }
  6486. }
  6487. }
  6488. if (tasks.links && tasks.links.length > 0) {
  6489. this.social.visitLink = visitLink;
  6490. }
  6491. return await Promise.all(pro).then(result => {
  6492. let checked = true;
  6493. for (const data of result) {
  6494. if (data.result) {
  6495. this.socialInitialized[data.name] = data.result;
  6496. } else {
  6497. checked = false;
  6498. }
  6499. }
  6500. return checked;
  6501. });
  6502. } catch (error) {
  6503. throwError(error, 'Website.initSocial');
  6504. return false;
  6505. }
  6506. }
  6507. uniqueTasks(allTasks) {
  6508. const result = {};
  6509. for (const [ social, types ] of Object.entries(allTasks)) {
  6510. result[social] = {};
  6511. for (const [ type, tasks ] of Object.entries(types)) {
  6512. result[social][type] = unique(tasks);
  6513. }
  6514. }
  6515. return result;
  6516. }
  6517. async toggleTask(action) {
  6518. try {
  6519. if (!this.initialized && !this.init()) {
  6520. return false;
  6521. }
  6522. if (!await this.classifyTask(action)) {
  6523. return false;
  6524. }
  6525. if (!await this.initSocial(action)) {
  6526. return false;
  6527. }
  6528. const pro = [];
  6529. const doTask = action === 'do';
  6530. const tasks = doTask ? this.undoneTasks : this.socialTasks;
  6531. if (this.socialInitialized.discord !== 'skip' && this.social.discord) {
  6532. pro.push(this.social.discord.toggle({
  6533. doTask: doTask,
  6534. ...tasks.discord
  6535. }));
  6536. }
  6537. if (this.social.instagram) {
  6538. pro.push(this.social.instagram.toggle({
  6539. doTask: doTask,
  6540. ...tasks.instagram
  6541. }));
  6542. }
  6543. if (this.social.reddit) {
  6544. pro.push(this.social.reddit.toggle({
  6545. doTask: doTask,
  6546. ...tasks.reddit
  6547. }));
  6548. }
  6549. if (this.social.twitch) {
  6550. pro.push(this.social.twitch.toggle({
  6551. doTask: doTask,
  6552. ...tasks.twitch
  6553. }));
  6554. }
  6555. if (this.social.twitter) {
  6556. pro.push(this.social.twitter.toggle({
  6557. doTask: doTask,
  6558. ...tasks.twitter
  6559. }));
  6560. }
  6561. if (this.social.vk) {
  6562. pro.push(this.social.vk.toggle({
  6563. doTask: doTask,
  6564. ...tasks.vk
  6565. }));
  6566. }
  6567. if (this.social.youtube) {
  6568. pro.push(this.social.youtube.toggle({
  6569. doTask: doTask,
  6570. ...tasks.youtube
  6571. }));
  6572. }
  6573. if (this.social.steam) {
  6574. pro.push(this.social.steam.toggle({
  6575. doTask: doTask,
  6576. ...tasks.steam
  6577. }));
  6578. }
  6579. if (this.social.visitLink && tasks.links && doTask) {
  6580. for (const link of tasks.links) {
  6581. pro.push(this.social.visitLink(link));
  6582. }
  6583. }
  6584. if (doTask && tasks.extra && this.extraDoTask) {
  6585. const hasExtra = Object.values(tasks.extra).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6586. if (hasExtra) {
  6587. pro.push(this.extraDoTask(tasks.extra));
  6588. }
  6589. }
  6590. await Promise.all(pro);
  6591. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6592. return true;
  6593. } catch (error) {
  6594. throwError(error, 'Website.toggleTask');
  6595. return false;
  6596. }
  6597. }
  6598. async doTask() {
  6599. try {
  6600. return await this.toggleTask('do');
  6601. } catch (error) {
  6602. throwError(error, 'Website.doTask');
  6603. return false;
  6604. }
  6605. }
  6606. async undoTask() {
  6607. try {
  6608. return await this.toggleTask('undo');
  6609. } catch (error) {
  6610. throwError(error, 'Website.undoTask');
  6611. return false;
  6612. }
  6613. }
  6614. }
  6615. const website_Website = Website;
  6616. const defaultTasksTemplate = {
  6617. steam: {
  6618. groupLinks: [],
  6619. wishlistLinks: [],
  6620. curatorLinks: [],
  6621. followLinks: []
  6622. },
  6623. vk: {
  6624. nameLinks: []
  6625. }
  6626. };
  6627. const defaultTasks = JSON.stringify(defaultTasksTemplate);
  6628. class FreeAnyWhere extends website_Website {
  6629. name = 'FreeAnyWhere';
  6630. tasks = [];
  6631. socialTasks = JSON.parse(defaultTasks);
  6632. undoneTasks = JSON.parse(defaultTasks);
  6633. buttons = [ 'doTask', 'undoTask', 'verifyTask', 'getKey' ];
  6634. static test() {
  6635. return window.location.host === 'freeanywhere.net';
  6636. }
  6637. async init() {
  6638. try {
  6639. const logStatus = scripts_echoLog({
  6640. text: i18n('initing')
  6641. });
  6642. if ($('a[href="#/login"]').length > 0) {
  6643. window.open('/#/login', '_self');
  6644. logStatus.warning(i18n('needLogin'));
  6645. return false;
  6646. }
  6647. if (window.location.href.includes('/login')) {
  6648. logStatus.warning(i18n('needLogin'));
  6649. return false;
  6650. }
  6651. if (!/^https?:\/\/freeanywhere\.net\/#\/giveaway\/[\d]+/.test(window.location.href)) {
  6652. const id = window.location.href.match(/https?:\/\/freeanywhere\.net\/.*?#\/giveaway\/([\d]+)/)?.[1];
  6653. if (!id) {
  6654. logStatus.error(i18n('getFailed', 'Id'));
  6655. return false;
  6656. }
  6657. window.location.href = `https://freeanywhere.net/#/giveaway/${id}`;
  6658. }
  6659. if (!this.#getGiveawayId()) {
  6660. return false;
  6661. }
  6662. if (!await this.#checkLeftKey()) {
  6663. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  6664. }
  6665. this.initialized = true;
  6666. logStatus.success();
  6667. return true;
  6668. } catch (error) {
  6669. throwError(error, 'Freeanywhere.init');
  6670. return false;
  6671. }
  6672. }
  6673. async classifyTask(action) {
  6674. try {
  6675. const logStatus = scripts_echoLog({
  6676. text: i18n('getTasksInfo')
  6677. });
  6678. if (action === 'undo') {
  6679. this.socialTasks = GM_getValue(`fawTasks-${this.giveawayId}`)?.tasks || JSON.parse(defaultTasks);
  6680. }
  6681. const {
  6682. result,
  6683. statusText,
  6684. status,
  6685. data
  6686. } = await tools_httpRequest({
  6687. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/?format=json`,
  6688. method: 'GET',
  6689. headers: {
  6690. authorization: `Token ${window.localStorage.getItem('token')}`,
  6691. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  6692. },
  6693. responseType: 'json'
  6694. });
  6695. if (result === 'Success') {
  6696. const tasks = data?.response?.challenges;
  6697. if (tasks) {
  6698. if (action === 'verify') {
  6699. this.tasks = [];
  6700. }
  6701. for (const task of tasks) {
  6702. const type = task.challenge;
  6703. const social = task.challenge_provider;
  6704. const taskInfo = {
  6705. id: task.id,
  6706. title: task.title
  6707. };
  6708. if (action === 'verify' && !task.is_success) {
  6709. this.tasks.push(taskInfo);
  6710. continue;
  6711. }
  6712. switch (social) {
  6713. case 'steam':
  6714. taskInfo.social = 'steam';
  6715. switch (type) {
  6716. case 'WL':
  6717. if (action === 'undo') {
  6718. this.socialTasks.steam.wishlistLinks.push(task.link);
  6719. }
  6720. if (action === 'do' && !task.is_success) {
  6721. this.undoneTasks.steam.wishlistLinks.push(task.link);
  6722. }
  6723. break;
  6724.  
  6725. case 'JTG':
  6726. if (action === 'undo') {
  6727. this.socialTasks.steam.groupLinks.push(task.link);
  6728. }
  6729. if (action === 'do' && !task.is_success) {
  6730. this.undoneTasks.steam.groupLinks.push(task.link);
  6731. }
  6732. break;
  6733.  
  6734. case 'STC':
  6735. if (action === 'undo') {
  6736. this.socialTasks.steam.curatorLinks.push(task.link);
  6737. }
  6738. if (action === 'do' && !task.is_success) {
  6739. this.undoneTasks.steam.curatorLinks.push(task.link);
  6740. }
  6741. break;
  6742.  
  6743. case 'GF':
  6744. if (action === 'undo') {
  6745. this.socialTasks.steam.followLinks.push(task.link);
  6746. }
  6747. if (action === 'do' && !task.is_success) {
  6748. this.undoneTasks.steam.followLinks.push(task.link);
  6749. }
  6750. break;
  6751. }
  6752. break;
  6753.  
  6754. case 'vk-oauth2':
  6755. if (action === 'undo') {
  6756. this.socialTasks.vk.nameLinks.push(task.link);
  6757. }
  6758. if (action === 'do' && !task.is_success) {
  6759. this.undoneTasks.vk.nameLinks.push(task.link);
  6760. }
  6761. break;
  6762.  
  6763. case 'website':
  6764. break;
  6765.  
  6766. default:
  6767. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${social}`);
  6768. break;
  6769. }
  6770. }
  6771. logStatus.success();
  6772. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  6773. this.socialTasks = this.uniqueTasks(this.socialTasks);
  6774. if (window.DEBUG) {
  6775. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  6776. }
  6777. GM_setValue(`fawTasks-${this.giveawayId}`, {
  6778. tasks: this.socialTasks,
  6779. time: new Date().getTime()
  6780. });
  6781. return true;
  6782. }
  6783. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6784. return false;
  6785. }
  6786. logStatus.error(`${result}:${statusText}(${status})`);
  6787. return false;
  6788. } catch (error) {
  6789. throwError(error, 'Freeanywhere.classifyTask');
  6790. return false;
  6791. }
  6792. }
  6793. async verifyTask() {
  6794. try {
  6795. if (!this.initialized && !this.init()) {
  6796. return false;
  6797. }
  6798. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  6799. return false;
  6800. }
  6801. const pro = [];
  6802. for (const task of this.tasks) {
  6803. pro.push(this.#verify(task));
  6804. await delay(1e3);
  6805. }
  6806. await Promise.all(pro);
  6807. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6808. return !!await this.getKey(true);
  6809. } catch (error) {
  6810. throwError(error, 'Freeanywhere.verifyTask');
  6811. return false;
  6812. }
  6813. }
  6814. async getKey(initialized) {
  6815. try {
  6816. if (!initialized && !this.initialized && !this.init()) {
  6817. return false;
  6818. }
  6819. const logStatus = scripts_echoLog({
  6820. text: i18n('gettingKey')
  6821. });
  6822. const {
  6823. result,
  6824. statusText,
  6825. status,
  6826. data
  6827. } = await tools_httpRequest({
  6828. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/reward/?format=json`,
  6829. method: 'GET',
  6830. dataType: 'json',
  6831. headers: {
  6832. authorization: `Token ${window.localStorage.getItem('token')}`
  6833. }
  6834. });
  6835. if (result === 'Success') {
  6836. if (data?.response?.reward) {
  6837. logStatus.success();
  6838. scripts_echoLog({}).success(data.response.reward);
  6839. return data.response.reward;
  6840. }
  6841. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6842. return false;
  6843. }
  6844. logStatus.error(`${result}:${statusText}(${status})`);
  6845. return false;
  6846. } catch (error) {
  6847. throwError(error, 'FreeAnyWhere.getGiveawayId');
  6848. return false;
  6849. }
  6850. }
  6851. #getGiveawayId() {
  6852. try {
  6853. const giveawayId = window.location.href.match(/\/giveaway\/([\d]+)/)?.[1];
  6854. if (giveawayId) {
  6855. this.giveawayId = giveawayId;
  6856. return true;
  6857. }
  6858. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  6859. return false;
  6860. } catch (error) {
  6861. throwError(error, 'FreeAnyWhere.getGiveawayId');
  6862. }
  6863. }
  6864. async #verify(task) {
  6865. try {
  6866. const logStatus = scripts_echoLog({
  6867. html: `<li>${i18n('verifyingTask')}${task.title.trim()}...<font></font></li>`
  6868. });
  6869. const {
  6870. result,
  6871. statusText,
  6872. status,
  6873. data
  6874. } = await tools_httpRequest({
  6875. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/challenge-status/${task.id}/?format=json`,
  6876. method: 'GET',
  6877. dataType: 'json',
  6878. headers: {
  6879. authorization: `Token ${window.localStorage.getItem('token')}`,
  6880. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  6881. }
  6882. });
  6883. if (result === 'Success') {
  6884. if (data?.response?.status) {
  6885. logStatus.success();
  6886. return true;
  6887. }
  6888. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6889. return false;
  6890. }
  6891. logStatus.error(`${result}:${statusText}(${status})`);
  6892. return false;
  6893. } catch (error) {
  6894. throwError(error, 'Freeanywhere.verify');
  6895. return false;
  6896. }
  6897. }
  6898. async #checkLeftKey() {
  6899. try {
  6900. if (!globalOptions.other.checkLeftKey) {
  6901. return true;
  6902. }
  6903. const {
  6904. data
  6905. } = await tools_httpRequest({
  6906. url: 'https://freeanywhere.net/api/v1/widget/?format=json',
  6907. method: 'GET',
  6908. dataType: 'json',
  6909. headers: {
  6910. authorization: `Token ${window.localStorage.getItem('token')}`
  6911. }
  6912. });
  6913. if (data?.response?.giveaways.find(giveaway => `${giveaway?.id}` === this.giveawayId)) {
  6914. return true;
  6915. }
  6916. await external_Swal_default().fire({
  6917. icon: 'warning',
  6918. title: i18n('notice'),
  6919. text: i18n('noKeysLeft'),
  6920. confirmButtonText: i18n('confirm'),
  6921. cancelButtonText: i18n('cancel'),
  6922. showCancelButton: true
  6923. }).then(({
  6924. value
  6925. }) => {
  6926. if (value) {
  6927. window.close();
  6928. }
  6929. });
  6930. return true;
  6931. } catch (error) {
  6932. throwError(error, 'Giveawaysu.checkLeftKey');
  6933. return false;
  6934. }
  6935. }
  6936. }
  6937. const Freeanywhere = FreeAnyWhere;
  6938. const Giveawaysu_defaultTasks = {
  6939. steam: {
  6940. groupLinks: [],
  6941. wishlistLinks: [],
  6942. curatorLinks: [],
  6943. curatorLikeLinks: [],
  6944. followLinks: [],
  6945. forumLinks: [],
  6946. announcementLinks: [],
  6947. workshopVoteLinks: [],
  6948. playtestLinks: []
  6949. },
  6950. discord: {
  6951. serverLinks: []
  6952. },
  6953. instagram: {
  6954. userLinks: []
  6955. },
  6956. vk: {
  6957. nameLinks: []
  6958. },
  6959. twitch: {
  6960. channelLinks: []
  6961. },
  6962. reddit: {
  6963. redditLinks: []
  6964. },
  6965. youtube: {
  6966. channelLinks: [],
  6967. likeLinks: []
  6968. },
  6969. twitter: {
  6970. userLinks: [],
  6971. retweetLinks: []
  6972. }
  6973. };
  6974. class GiveawaySu extends website_Website {
  6975. name = 'GiveawaySu';
  6976. socialTasks = Giveawaysu_defaultTasks;
  6977. undoneTasks = Giveawaysu_defaultTasks;
  6978. buttons = [ 'doTask', 'undoTask' ];
  6979. static test() {
  6980. return /^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(window.location.href);
  6981. }
  6982. async after() {
  6983. try {
  6984. if (!this.#checkLogin()) {
  6985. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  6986. }
  6987. if (!await this.#checkLeftKey()) {
  6988. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  6989. }
  6990. scripts_echoLog({}).warning(i18n('gsNotice'));
  6991. } catch (error) {
  6992. throwError(error, 'Giveawaysu.after');
  6993. }
  6994. }
  6995. init() {
  6996. try {
  6997. const logStatus = scripts_echoLog({
  6998. text: i18n('initing')
  6999. });
  7000. if ($('a.steam-login').length > 0) {
  7001. window.open('/steam/redirect', '_self');
  7002. logStatus.warning(i18n('needLogin'));
  7003. return false;
  7004. }
  7005. if (!this.#getGiveawayId()) {
  7006. return false;
  7007. }
  7008. this.initialized = true;
  7009. logStatus.success();
  7010. return true;
  7011. } catch (error) {
  7012. throwError(error, 'Giveawaysu.init');
  7013. return false;
  7014. }
  7015. }
  7016. async classifyTask(action) {
  7017. try {
  7018. const logStatus = scripts_echoLog({
  7019. text: i18n('getTasksInfo')
  7020. });
  7021. if (action === 'undo') {
  7022. this.socialTasks = GM_getValue(`gasTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  7023. return true;
  7024. }
  7025. const pro = [];
  7026. const tasks = $('#actions tr');
  7027. if ($('div.bind-discord').is(':visible')) {
  7028. $('div.bind-discord a')[0].click();
  7029. }
  7030. if ($('div.bind-twitch').is(':visible')) {
  7031. $('div.bind-twitch a')[0].click();
  7032. }
  7033. for (const task of tasks) {
  7034. pro.push(new Promise(resolve => {
  7035. const td = $(task).find('td:not(".hidden")');
  7036. const colorfulTask = td.eq(1).find('a:not([data-trigger="link"])');
  7037. const colorlessTask = td.eq(2).find('a:not([data-trigger="link"])');
  7038. const taskDes = colorfulTask.length > 0 ? colorfulTask : colorlessTask;
  7039. const taskIcon = td.eq(0).find('i').attr('class') || '';
  7040. const taskName = taskDes.text().trim();
  7041. if (taskIcon.includes('ban') || /disable adblock/gi.test(taskName)) {
  7042. return resolve(true);
  7043. }
  7044. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  7045. if (!taskLink) {
  7046. return resolve(false);
  7047. }
  7048. if (taskIcon.includes('steam') && /join/gi.test(taskName)) {
  7049. this.undoneTasks.steam.groupLinks.push(taskLink);
  7050. } else if (/like.*announcement/gi.test(taskName)) {
  7051. this.undoneTasks.steam.announcementLinks.push(taskLink);
  7052. } else if (/(follow|subscribe).*curator/gim.test(taskName) && /^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  7053. this.undoneTasks.steam.curatorLinks.push(taskLink);
  7054. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  7055. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  7056. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  7057. this.undoneTasks.steam.forumLinks.push(taskLink);
  7058. } else if (taskIcon.includes('thumbs-up') && /^https?:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=[\d]+/.test(taskLink)) {
  7059. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7060. } else if (taskIcon.includes('plus') && /request.*playtest/gim.test(taskName)) {
  7061. this.undoneTasks.steam.playtestLinks.push(taskLink);
  7062. } else if (taskIcon.includes('discord') || /join.*discord/gim.test(taskName)) {
  7063. this.undoneTasks.discord.serverLinks.push(taskLink);
  7064. } else if (taskIcon.includes('instagram') || /follow.*instagram/gim.test(taskName)) {
  7065. this.undoneTasks.instagram.userLinks.push(taskLink);
  7066. } else if (taskIcon.includes('twitch') || /follow.*twitch.*channel/gim.test(taskName)) {
  7067. this.undoneTasks.twitch.channelLinks.push(taskLink);
  7068. } else if (taskIcon.includes('reddit') || /subscribe.*subreddit/gim.test(taskName) || /follow.*reddit/gim.test(taskName)) {
  7069. this.undoneTasks.reddit.redditLinks.push(taskLink);
  7070. } else if (/watch.*art/gim.test(taskName)) {
  7071. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7072. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  7073. this.undoneTasks.youtube.channelLinks.push(taskLink);
  7074. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  7075. this.undoneTasks.youtube.likeLinks.push(taskLink);
  7076. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  7077. this.undoneTasks.vk.nameLinks.push(taskLink);
  7078. } else {
  7079. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  7080. if (/wishlist.*game|add.*wishlist/gim.test(taskName)) {
  7081. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  7082. }
  7083. if (/follow.*button/gim.test(taskName)) {
  7084. this.undoneTasks.steam.followLinks.push(taskLink);
  7085. }
  7086. }
  7087. }
  7088. resolve(true);
  7089. }).catch(error => {
  7090. throwError(error, 'Giveawaysu.classifyTask->getRedirectLink');
  7091. return false;
  7092. });
  7093. }));
  7094. }
  7095. await Promise.all(pro);
  7096. logStatus.success();
  7097. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7098. this.socialTasks = this.undoneTasks;
  7099. if (window.DEBUG) {
  7100. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7101. }
  7102. GM_setValue(`gasTasks-${this.giveawayId}`, {
  7103. tasks: this.socialTasks,
  7104. time: new Date().getTime()
  7105. });
  7106. return true;
  7107. } catch (error) {
  7108. throwError(error, 'Giveawaysu.classifyTask');
  7109. return false;
  7110. }
  7111. }
  7112. #checkLogin() {
  7113. try {
  7114. if (!globalOptions.other.checkLogin) {
  7115. return true;
  7116. }
  7117. if ($('a.steam-login').length > 0) {
  7118. window.open('/steam/redirect', '_self');
  7119. }
  7120. return true;
  7121. } catch (error) {
  7122. throwError(error, 'Giveawaysu.checkLogin');
  7123. return false;
  7124. }
  7125. }
  7126. async #checkLeftKey() {
  7127. try {
  7128. if (!globalOptions.other.checkLeftKey) {
  7129. return true;
  7130. }
  7131. if ($('.giveaway-ended').length > 0 && $('.giveaway-key').length === 0) {
  7132. await external_Swal_default().fire({
  7133. icon: 'warning',
  7134. title: i18n('notice'),
  7135. text: i18n('noKeysLeft'),
  7136. confirmButtonText: i18n('confirm'),
  7137. cancelButtonText: i18n('cancel'),
  7138. showCancelButton: true
  7139. }).then(({
  7140. value
  7141. }) => {
  7142. if (value) {
  7143. window.close();
  7144. }
  7145. });
  7146. }
  7147. return true;
  7148. } catch (error) {
  7149. throwError(error, 'Giveawaysu.checkLeftKey');
  7150. return false;
  7151. }
  7152. }
  7153. #getGiveawayId() {
  7154. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  7155. if (giveawayId) {
  7156. this.giveawayId = giveawayId;
  7157. return true;
  7158. }
  7159. scripts_echoLog({
  7160. text: i18n('getFailed', 'GiveawayId')
  7161. });
  7162. return false;
  7163. }
  7164. }
  7165. class Indiedb {
  7166. name = 'Indiedb';
  7167. buttons = [ 'doTask' ];
  7168. static test() {
  7169. return window.location.host === 'www.indiedb.com';
  7170. }
  7171. async after() {
  7172. try {
  7173. if (!this.#checkLogin()) {
  7174. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7175. }
  7176. if (!await this.#checkLeftKey()) {
  7177. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7178. }
  7179. } catch (error) {
  7180. throwError(error, 'Indiedb.after');
  7181. }
  7182. }
  7183. async doTask() {
  7184. try {
  7185. if (!await this.#join()) {
  7186. return false;
  7187. }
  7188. return await this.#do();
  7189. } catch (error) {
  7190. throwError(error, 'Indiedb.doTask');
  7191. return false;
  7192. }
  7193. }
  7194. async #join() {
  7195. try {
  7196. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7197. scripts_echoLog({}).error(i18n('needLogin'));
  7198. return false;
  7199. }
  7200. const currentoption = $('a.buttonenter.buttongiveaway');
  7201. if (/join giveaway/gim.test(currentoption.text())) {
  7202. const logStatus = scripts_echoLog({
  7203. text: `${i18n('joiningGiveaway')}...`
  7204. });
  7205. const {
  7206. result,
  7207. statusText,
  7208. status,
  7209. data
  7210. } = await tools_httpRequest({
  7211. url: currentoption.attr('href'),
  7212. method: 'POST',
  7213. data: 'ajax=t',
  7214. dataType: 'json',
  7215. headers: {
  7216. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  7217. accept: 'application/json, text/javascript, */*; q=0.01',
  7218. origin: window.location.origin
  7219. }
  7220. });
  7221. if (result === 'Success') {
  7222. if (data?.status === 200) {
  7223. if (data.response?.success) {
  7224. currentoption.addClass('buttonentered').text('Success - Giveaway joined');
  7225. $('#giveawaysjoined').slideDown();
  7226. $('#giveawaysrecommend').slideDown();
  7227. logStatus.success(`Success${data.response?.text ? `:${data.response?.text}` : ''}`);
  7228. return true;
  7229. }
  7230. logStatus.error(`Error${data.response?.text ? `:${data.response?.text}` : ''}`);
  7231. return false;
  7232. }
  7233. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7234. return false;
  7235. }
  7236. logStatus.error(`${result}:${statusText}(${status})`);
  7237. return false;
  7238. } else if (/success/gim.test($('a.buttonenter.buttongiveaway').text())) {
  7239. return true;
  7240. }
  7241. scripts_echoLog({}).warning(i18n('needJoinGiveaway'));
  7242. return false;
  7243. } catch (error) {
  7244. throwError(error, 'Indiedb.init');
  7245. return false;
  7246. }
  7247. }
  7248. async #do() {
  7249. try {
  7250. const id = $('script').map((index, script) => {
  7251. if (/\$\(document\)/gim.test(script.innerHTML)) {
  7252. return [ script.innerHTML.match(/"\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0], script.innerHTML.match(/"\/newsletter\/ajax\/subscribeprofile\/optin\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0] ];
  7253. }
  7254. return null;
  7255. });
  7256. if (id.length === 2) {
  7257. const pro = [];
  7258. const tasks = $('#giveawaysjoined a[class*=promo]');
  7259. for (const task of tasks) {
  7260. const promo = $(task);
  7261. if (!promo.hasClass('buttonentered')) {
  7262. const status = scripts_echoLog({
  7263. text: `${i18n('doing')}:${promo.parents('p').text()}...`
  7264. });
  7265. if (/facebookpromo|twitterpromo|visitpromo/gim.test(task.className)) {
  7266. let text = '';
  7267. if (promo.hasClass('facebookpromo')) {
  7268. text = 'facebookpromo';
  7269. } else if (promo.hasClass('twitterpromo')) {
  7270. text = 'twitterpromo';
  7271. } else {
  7272. text = 'visitpromo';
  7273. }
  7274. pro.push(new Promise(resolve => {
  7275. $.ajax({
  7276. type: 'POST',
  7277. url: urlPath(`/giveaways/ajax/${text}/${id[0]}`),
  7278. timeout: 6e4,
  7279. dataType: 'json',
  7280. data: {
  7281. ajax: 't'
  7282. },
  7283. error(response, error, exception) {
  7284. if (window.DEBUG) {
  7285. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7286. response: response,
  7287. error: error,
  7288. exception: exception
  7289. });
  7290. }
  7291. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7292. resolve(true);
  7293. },
  7294. success(response) {
  7295. if (response.success) {
  7296. status.success(`Success:${response.text}`);
  7297. promo.addClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7298. resolve(true);
  7299. } else {
  7300. status.error(`Error:${response.text}`);
  7301. resolve(true);
  7302. }
  7303. }
  7304. });
  7305. }));
  7306. } else if (promo.hasClass('emailoptinpromo')) {
  7307. pro.push(new Promise(resolve => {
  7308. $.ajax({
  7309. type: 'POST',
  7310. url: urlPath(`/newsletter/ajax/subscribeprofile/optin/${id[1]}`),
  7311. timeout: 6e4,
  7312. dataType: 'json',
  7313. data: {
  7314. ajax: 't',
  7315. emailsystoggle: 4
  7316. },
  7317. error(response, error, exception) {
  7318. if (window.DEBUG) {
  7319. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7320. response: response,
  7321. error: error,
  7322. exception: exception
  7323. });
  7324. }
  7325. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7326. resolve(true);
  7327. },
  7328. success(response) {
  7329. if (response.success) {
  7330. status.success(`Success:${response.text}`);
  7331. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7332. resolve(true);
  7333. } else {
  7334. status.error(`Error:${response.text}`);
  7335. resolve(true);
  7336. }
  7337. }
  7338. });
  7339. }));
  7340. } else if (promo.hasClass('watchingpromo')) {
  7341. pro.push(new Promise(resolve => {
  7342. const data = getUrlQuery(promo.attr('href'));
  7343. data.ajax = 't';
  7344. $.ajax({
  7345. type: 'POST',
  7346. url: urlPath(promo.attr('href')?.split(/[?#]/)[0]),
  7347. timeout: 6e4,
  7348. dataType: 'json',
  7349. data: data,
  7350. error(response, error, exception) {
  7351. if (window.DEBUG) {
  7352. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7353. response: response,
  7354. error: error,
  7355. exception: exception
  7356. });
  7357. }
  7358. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7359. resolve(true);
  7360. },
  7361. success(response) {
  7362. if (response.success) {
  7363. status.success(`Success:${response.text}`);
  7364. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7365. resolve(true);
  7366. } else {
  7367. status.error(`Error:${response.text}`);
  7368. resolve(true);
  7369. }
  7370. }
  7371. });
  7372. }));
  7373. } else if (!/the-challenge-of-adblock/gim.test(promo.attr('href'))) {
  7374. pro.push(new Promise(resolve => {
  7375. $.ajax({
  7376. type: 'POST',
  7377. url: urlPath(promo.attr('href')),
  7378. timeout: 6e4,
  7379. dataType: 'json',
  7380. data: {
  7381. ajax: 't'
  7382. },
  7383. error(response, error, exception) {
  7384. if (window.DEBUG) {
  7385. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7386. response: response,
  7387. error: error,
  7388. exception: exception
  7389. });
  7390. }
  7391. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7392. resolve(true);
  7393. },
  7394. success(response) {
  7395. if (response.success) {
  7396. status.success(`Success:${response.text}`);
  7397. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7398. resolve(true);
  7399. } else {
  7400. status.error(`Error:${response.text}`);
  7401. resolve(true);
  7402. }
  7403. }
  7404. });
  7405. }));
  7406. } else {
  7407. status.error(`Error:${i18n('unKnownTaskType')}`);
  7408. }
  7409. }
  7410. }
  7411. await Promise.all(pro);
  7412. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7413. return true;
  7414. }
  7415. scripts_echoLog({}).error(i18n('getFailed', 'TaskId'));
  7416. return false;
  7417. } catch (error) {
  7418. throwError(error, 'Indiedb.classifyTask');
  7419. return false;
  7420. }
  7421. }
  7422. #checkLogin() {
  7423. try {
  7424. if (!globalOptions.other.checkLogin) {
  7425. return true;
  7426. }
  7427. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7428. window.open('/members/login', '_self');
  7429. }
  7430. return true;
  7431. } catch (error) {
  7432. throwError(error, 'Indiedb.checkLogin');
  7433. return false;
  7434. }
  7435. }
  7436. async #checkLeftKey() {
  7437. try {
  7438. if (!globalOptions.other.checkLeftKey) {
  7439. return true;
  7440. }
  7441. if ($('a.buttonenter:contains("next time"),a.buttonenter:contains("Giveaway is closed")').length > 0) {
  7442. await external_Swal_default().fire({
  7443. icon: 'warning',
  7444. title: i18n('notice'),
  7445. text: i18n('giveawayEnded'),
  7446. confirmButtonText: i18n('confirm'),
  7447. cancelButtonText: i18n('cancel'),
  7448. showCancelButton: true
  7449. }).then(({
  7450. value
  7451. }) => {
  7452. if (value) {
  7453. window.close();
  7454. }
  7455. });
  7456. }
  7457. return true;
  7458. } catch (error) {
  7459. throwError(error, 'Indiedb.checkLeftKey');
  7460. return false;
  7461. }
  7462. }
  7463. }
  7464. const website_Indiedb = Indiedb;
  7465. const Keyhub_defaultTasksTemplate = {
  7466. steam: {
  7467. groupLinks: [],
  7468. officialGroupLinks: [],
  7469. wishlistLinks: [],
  7470. curatorLinks: []
  7471. },
  7472. discord: {
  7473. serverLinks: []
  7474. },
  7475. extra: {
  7476. videoTasks: []
  7477. },
  7478. links: []
  7479. };
  7480. const Keyhub_defaultTasks = JSON.stringify(Keyhub_defaultTasksTemplate);
  7481. class Keyhub extends website_Website {
  7482. name = 'Keyhub';
  7483. socialTasks = JSON.parse(Keyhub_defaultTasks);
  7484. undoneTasks = JSON.parse(Keyhub_defaultTasks);
  7485. buttons = [ 'doTask', 'undoTask' ];
  7486. static test() {
  7487. return window.location.host === 'key-hub.eu';
  7488. }
  7489. async after() {
  7490. try {
  7491. if (!this.#checkLogin()) {
  7492. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7493. }
  7494. if (!await this.#checkLeftKey()) {
  7495. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7496. }
  7497. $('.NSFW').hide();
  7498. } catch (error) {
  7499. throwError(error, 'Keyhub.after');
  7500. }
  7501. }
  7502. init() {
  7503. try {
  7504. const logStatus = scripts_echoLog({
  7505. text: i18n('initing')
  7506. });
  7507. if ($('a[href*="/connect/steam"]').length > 0) {
  7508. window.open('/connect/steam', '_self');
  7509. logStatus.warning(i18n('needLogin'));
  7510. return false;
  7511. }
  7512. if (!this.#getGiveawayId()) {
  7513. return false;
  7514. }
  7515. $('#VPNoverlay').hide();
  7516. $('#mainArticleSection').show();
  7517. this.initialized = true;
  7518. logStatus.success();
  7519. return true;
  7520. } catch (error) {
  7521. throwError(error, 'Keyhub.init');
  7522. return false;
  7523. }
  7524. }
  7525. async classifyTask(action) {
  7526. try {
  7527. const logStatus = scripts_echoLog({
  7528. text: i18n('getTasksInfo')
  7529. });
  7530. if (action === 'undo') {
  7531. this.socialTasks = GM_getValue(`khTasks-${this.giveawayId}`)?.tasks || JSON.parse(Keyhub_defaultTasks);
  7532. }
  7533. const tasks = $('.task:not(".googleads")').filter((index, element) => action === 'do' ? $(element).find('i.fa-check-circle:visible').length === 0 : true).find('a');
  7534. for (const task of tasks) {
  7535. let link = $(task).attr('href');
  7536. const taskDes = $(task).text().trim();
  7537. if (!link) {
  7538. continue;
  7539. }
  7540. if (/\/away\?data=/.test(link) || /steamcommunity\.com\/gid\//.test(link)) {
  7541. link = await getRedirectLink(link) || link;
  7542. }
  7543. if (/https?:\/\/key-hub\.eu\/connect\/discord/.test(link)) {
  7544. window.open(link, '_blank');
  7545. } else if (/steamcommunity\.com\/groups\//.test(link)) {
  7546. if (action === 'undo') {
  7547. this.socialTasks.steam.groupLinks.push(link);
  7548. }
  7549. if (action === 'do') {
  7550. this.undoneTasks.steam.groupLinks.push(link);
  7551. }
  7552. } else if (/steamcommunity\.com\/games\/[\d]+/.test(link)) {
  7553. if (action === 'undo') {
  7554. this.socialTasks.steam.officialGroupLinks.push(link);
  7555. }
  7556. if (action === 'do') {
  7557. this.undoneTasks.steam.officialGroupLinks.push(link);
  7558. }
  7559. } else if (/store\.steampowered\.com\/app\//.test(link) && /wishlist/gim.test(taskDes)) {
  7560. if (action === 'undo') {
  7561. this.socialTasks.steam.wishlistLinks.push(link);
  7562. }
  7563. if (action === 'do') {
  7564. this.undoneTasks.steam.wishlistLinks.push(link);
  7565. }
  7566. } else if (/store\.steampowered\.com\/curator\//.test(link)) {
  7567. if (action === 'undo') {
  7568. this.socialTasks.steam.curatorLinks.push(link);
  7569. }
  7570. if (action === 'do') {
  7571. this.undoneTasks.steam.curatorLinks.push(link);
  7572. }
  7573. } else if (/^https?:\/\/discord\.com\/invite\//.test(link)) {
  7574. if (action === 'undo') {
  7575. this.socialTasks.discord.serverLinks.push(link);
  7576. }
  7577. if (action === 'do') {
  7578. this.undoneTasks.discord.serverLinks.push(link);
  7579. }
  7580. } else if (/^javascript:videoTask.+/.test(link)) {
  7581. if (action === 'do') {
  7582. const taskData = link.match(/javascript:videoTask\('.+?','(.+?)'/)?.[1];
  7583. if (taskData) {
  7584. this.undoneTasks.extra.videoTasks.push(taskData);
  7585. }
  7586. }
  7587. } else if (/^https?:\/\/www\.instagram\.com\/.*/.test(link) || /^https?:\/\/twitter\.com\/.*/.test(link) || /^https?:\/\/www\.twitch\.tv\/.*/.test(link) || /^https?:\/\/www\.facebook\.com\/.*/.test(link) || /^https?:\/\/www\.youtube\.com\/.*/.test(link) || /^https?:\/\/store\.steampowered\.com\/developer\//.test(link) || /^https?:\/\/.*?\.itch\.io\/.*/.test(link) || /^https?:\/\/key-hub\.eu.*/.test(link) || /^https?:\/\/store\.steampowered\.com\/app\/.*/.test(link) || /^https?:\/\/qr\.streamelements\.com\/.*/.test(link) || /^https?:\/\/store\.steampowered\.com\/news\/app\/.*/.test(link)) {} else {
  7588. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  7589. }
  7590. }
  7591. logStatus.success();
  7592. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7593. this.socialTasks = this.uniqueTasks(this.socialTasks);
  7594. if (window.DEBUG) {
  7595. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7596. }
  7597. GM_setValue(`khTasks-${this.giveawayId}`, {
  7598. tasks: this.socialTasks,
  7599. time: new Date().getTime()
  7600. });
  7601. return true;
  7602. } catch (error) {
  7603. throwError(error, 'Keyhub.classifyTask');
  7604. return false;
  7605. }
  7606. }
  7607. async #doScriptTask(data) {
  7608. try {
  7609. const logStatus = scripts_echoLog({
  7610. text: i18n('doingKeyhubTask')
  7611. });
  7612. const {
  7613. result,
  7614. statusText,
  7615. status,
  7616. data: response
  7617. } = await tools_httpRequest({
  7618. url: `/away?data=${data}`,
  7619. method: 'GET',
  7620. headers: {
  7621. origin: 'https://key-hub.eu',
  7622. referer: 'https://key-hub.eu/'
  7623. }
  7624. });
  7625. if (result === 'Success') {
  7626. if (response?.status === 200) {
  7627. logStatus.success();
  7628. return true;
  7629. }
  7630. logStatus.error(`Error:${response?.statusText}(${response?.status})`);
  7631. return false;
  7632. }
  7633. logStatus.error(`${result}:${statusText}(${status})`);
  7634. return false;
  7635. } catch (error) {
  7636. throwError(error, 'Keyhub.doScriptTask');
  7637. return false;
  7638. }
  7639. }
  7640. async extraDoTask({
  7641. videoTasks
  7642. }) {
  7643. try {
  7644. const pro = [];
  7645. for (const data of videoTasks) {
  7646. pro.push(this.#doScriptTask(data));
  7647. }
  7648. return Promise.all(pro).then(() => true);
  7649. } catch (error) {
  7650. throwError(error, 'Keyhub.extraDoTask');
  7651. return false;
  7652. }
  7653. }
  7654. #getGiveawayId() {
  7655. try {
  7656. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  7657. if (giveawayId) {
  7658. this.giveawayId = giveawayId;
  7659. return true;
  7660. }
  7661. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7662. return false;
  7663. } catch (error) {
  7664. throwError(error, 'Keyhub.getGiveawayId');
  7665. return false;
  7666. }
  7667. }
  7668. async #checkLeftKey() {
  7669. try {
  7670. if (!globalOptions.other.checkLeftKey) {
  7671. return true;
  7672. }
  7673. const leftKey = $('#keysleft').text().trim();
  7674. if (leftKey === '0') {
  7675. await external_Swal_default().fire({
  7676. icon: 'warning',
  7677. title: i18n('notice'),
  7678. text: i18n('noKeysLeft'),
  7679. confirmButtonText: i18n('confirm'),
  7680. cancelButtonText: i18n('cancel'),
  7681. showCancelButton: true
  7682. }).then(({
  7683. value
  7684. }) => {
  7685. if (value) {
  7686. window.close();
  7687. }
  7688. });
  7689. }
  7690. return true;
  7691. } catch (error) {
  7692. throwError(error, 'Keyhub.checkLeftKey');
  7693. return false;
  7694. }
  7695. }
  7696. #checkLogin() {
  7697. try {
  7698. if (!globalOptions.other.checkLogin) {
  7699. return true;
  7700. }
  7701. if ($('a[href*="/connect/steam"]').length > 0) {
  7702. window.open('/connect/steam', '_self');
  7703. }
  7704. return true;
  7705. } catch (error) {
  7706. throwError(error, 'Keyhub.checkLogin');
  7707. return false;
  7708. }
  7709. }
  7710. }
  7711. const website_Keyhub = Keyhub;
  7712. const Givekey_defaultTasksTemplate = {
  7713. steam: {
  7714. groupLinks: [],
  7715. wishlistLinks: [],
  7716. curatorLinks: [],
  7717. curatorLikeLinks: []
  7718. },
  7719. twitter: {
  7720. userLinks: []
  7721. },
  7722. vk: {
  7723. nameLinks: []
  7724. },
  7725. discord: {
  7726. serverLinks: []
  7727. }
  7728. };
  7729. const Givekey_defaultTasks = JSON.stringify(Givekey_defaultTasksTemplate);
  7730. class Givekey extends website_Website {
  7731. name = 'Givekey';
  7732. tasks = [];
  7733. socialTasks = JSON.parse(Givekey_defaultTasks);
  7734. undoneTasks = JSON.parse(Givekey_defaultTasks);
  7735. userId;
  7736. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  7737. static test() {
  7738. return window.location.host === 'givekey.ru';
  7739. }
  7740. async after() {
  7741. try {
  7742. await new Promise(resolve => {
  7743. const checker = setInterval(() => {
  7744. if ($('#navbarDropdown').length > 0) {
  7745. clearInterval(checker);
  7746. resolve(true);
  7747. }
  7748. });
  7749. });
  7750. if (!await this.#checkLeftKey()) {
  7751. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7752. }
  7753. } catch (error) {
  7754. throwError(error, 'Givekey.after');
  7755. return false;
  7756. }
  7757. }
  7758. init() {
  7759. try {
  7760. const logStatus = scripts_echoLog({
  7761. text: i18n('initing')
  7762. });
  7763. if ($('a[href*="/auth/steam"]').length > 0) {
  7764. window.open('/auth/steam', '_self');
  7765. logStatus.warning(i18n('needLogin'));
  7766. return false;
  7767. }
  7768. if (!this.#getGiveawayId()) {
  7769. return false;
  7770. }
  7771. const userId = $('meta[name="user-id"]').attr('content');
  7772. if (!userId) {
  7773. logStatus.error(i18n('getFailed', i18n('userId')));
  7774. return false;
  7775. }
  7776. this.userId = userId;
  7777. this.initialized = true;
  7778. logStatus.success();
  7779. return true;
  7780. } catch (error) {
  7781. throwError(error, 'Givekey.init');
  7782. return false;
  7783. }
  7784. }
  7785. async classifyTask(action) {
  7786. try {
  7787. const logStatus = scripts_echoLog({
  7788. text: i18n('getTasksInfo')
  7789. });
  7790. if (action === 'undo') {
  7791. this.socialTasks = GM_getValue(`gkTasks-${this.giveawayId}`)?.tasks || JSON.parse(Givekey_defaultTasks);
  7792. }
  7793. const tasks = $('.card-body:has("button") .row');
  7794. for (const task of tasks) {
  7795. const taskEle = $(task);
  7796. const isSuccess = /Complete/i.test(taskEle.find('button').text().trim());
  7797. if (isSuccess && action !== 'undo') {
  7798. continue;
  7799. }
  7800. const checkButton = taskEle.find('#task_check');
  7801. const taskId = checkButton.attr('data-id');
  7802. if (taskId) {
  7803. this.tasks.push(taskId);
  7804. }
  7805. if (action === 'verify') {
  7806. continue;
  7807. }
  7808. let href = taskEle.find('a').attr('href') || null;
  7809. const text = taskEle.find('a').text().trim();
  7810. const icon = taskEle.find('i');
  7811. if (!href || !text) {
  7812. continue;
  7813. }
  7814. if (/^https?:\/\/givekey\.ru\/giveaway\/[\d]+\/execution_task/.test(href)) {
  7815. href = await getRedirectLink(href);
  7816. }
  7817. if (!href) {
  7818. continue;
  7819. }
  7820. if (/^https?:\/\/vk\.com\//.test(href)) {
  7821. this.socialTasks.vk.nameLinks.push(href);
  7822. if (action === 'do' && !isSuccess) {
  7823. this.undoneTasks.vk.nameLinks.push(href);
  7824. }
  7825. } else if (/^https?:\/\/steamcommunity\.com\/groups/.test(href)) {
  7826. this.socialTasks.steam.groupLinks.push(href);
  7827. if (action === 'do' && !isSuccess) {
  7828. this.undoneTasks.steam.groupLinks.push(href);
  7829. }
  7830. } else if (/^https?:\/\/store\.steampowered\.com\/app\//.test(href)) {
  7831. this.socialTasks.steam.wishlistLinks.push(href);
  7832. if (action === 'do' && !isSuccess) {
  7833. this.undoneTasks.steam.wishlistLinks.push(href);
  7834. }
  7835. } else if (/Subscribe/gi.test(text) && icon.hasClass('fa-steam-square')) {
  7836. if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(href)) {
  7837. this.socialTasks.steam.curatorLinks.push(href);
  7838. if (action === 'do' && !isSuccess) {
  7839. this.undoneTasks.steam.curatorLinks.push(href);
  7840. }
  7841. } else {
  7842. this.socialTasks.steam.curatorLikeLinks.push(href);
  7843. if (action === 'do' && !isSuccess) {
  7844. this.undoneTasks.steam.curatorLikeLinks.push(href);
  7845. }
  7846. }
  7847. } else if (/^https?:\/\/twitter\.com\//.test(href) && /Subscribe/gi.test(text)) {
  7848. this.socialTasks.twitter.userLinks.push(href);
  7849. if (action === 'do' && !isSuccess) {
  7850. this.undoneTasks.twitter.userLinks.push(href);
  7851. }
  7852. } else if (icon.hasClass('fa-discord') || /^https?:\/\/discord\.com\/invite\//.test(href)) {
  7853. this.socialTasks.discord.serverLinks.push(href);
  7854. if (action === 'do' && !isSuccess) {
  7855. this.undoneTasks.discord.serverLinks.push(href);
  7856. }
  7857. } else {
  7858. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${text}(${href})`);
  7859. }
  7860. }
  7861. logStatus.success();
  7862. this.tasks = unique(this.tasks);
  7863. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7864. this.socialTasks = this.uniqueTasks(this.socialTasks);
  7865. if (window.DEBUG) {
  7866. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7867. }
  7868. GM_setValue(`gkTasks-${this.giveawayId}`, {
  7869. tasks: this.socialTasks,
  7870. time: new Date().getTime()
  7871. });
  7872. return true;
  7873. } catch (error) {
  7874. throwError(error, 'Givekey.classifyTask');
  7875. return false;
  7876. }
  7877. }
  7878. async verifyTask() {
  7879. try {
  7880. if (!this.initialized && !this.init()) {
  7881. return false;
  7882. }
  7883. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  7884. return false;
  7885. }
  7886. scripts_echoLog({}).warning(i18n('giveKeyNoticeBefore'));
  7887. const taskLength = this.tasks.length;
  7888. for (let i = 0; i < taskLength; i++) {
  7889. await this.#verify(this.tasks[i]);
  7890. if (i < taskLength - 1) {
  7891. await delay(15e3);
  7892. }
  7893. }
  7894. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7895. scripts_echoLog({
  7896. html: `<li><font class="warning">${i18n('giveKeyNoticeAfter')}</font></li>`
  7897. });
  7898. return true;
  7899. } catch (error) {
  7900. throwError(error, 'Givekey.verifyTask');
  7901. return false;
  7902. }
  7903. }
  7904. async #verify(task) {
  7905. try {
  7906. const logStatus = scripts_echoLog({
  7907. html: `<li>${i18n('verifyingTask')}${task}...<font></font></li>`
  7908. });
  7909. return await new Promise(resolve => {
  7910. $.ajax({
  7911. url: 'https://givekey.ru/giveaway/task',
  7912. method: 'POST',
  7913. data: `id=${task}&user_id=${this.userId}`,
  7914. dataType: 'json',
  7915. headers: {
  7916. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  7917. },
  7918. success: data => {
  7919. if (data.btn) {
  7920. $(`button[data-id=${this.userId}]`).html(data.btn);
  7921. }
  7922. if (data.status === 'ok') {
  7923. $(`.task_check_${data.id}`).html(`<button class="btn btn-success mb-2 btn-block" disabled>${data.btn}</button>`);
  7924. logStatus.success();
  7925. resolve(true);
  7926. } else if (data.status === 'end') {
  7927. logStatus.success();
  7928. scripts_echoLog({}).success(data.key);
  7929. resolve(true);
  7930. } else {
  7931. logStatus.error(`Error:${data.msg}`);
  7932. resolve(false);
  7933. }
  7934. },
  7935. error: xhr => {
  7936. logStatus.error(`Error:${xhr.statusText}(${xhr.status})`);
  7937. resolve(false);
  7938. }
  7939. });
  7940. });
  7941. } catch (error) {
  7942. throwError(error, 'Givekey.verify');
  7943. return false;
  7944. }
  7945. }
  7946. #getGiveawayId() {
  7947. try {
  7948. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  7949. if (giveawayId) {
  7950. this.giveawayId = giveawayId;
  7951. return true;
  7952. }
  7953. scripts_echoLog({
  7954. text: i18n('getFailed', 'GiveawayId')
  7955. });
  7956. return false;
  7957. } catch (error) {
  7958. throwError(error, 'Givekey.getGiveawayId');
  7959. return false;
  7960. }
  7961. }
  7962. async #checkLeftKey() {
  7963. try {
  7964. if (!globalOptions.other.checkLeftKey) {
  7965. return true;
  7966. }
  7967. if (!$('#keys_count').text()) {
  7968. await external_Swal_default().fire({
  7969. icon: 'warning',
  7970. title: i18n('notice'),
  7971. text: i18n('noKeysLeft'),
  7972. confirmButtonText: i18n('confirm'),
  7973. cancelButtonText: i18n('cancel'),
  7974. showCancelButton: true
  7975. }).then(({
  7976. value
  7977. }) => {
  7978. if (value) {
  7979. window.close();
  7980. }
  7981. });
  7982. }
  7983. return true;
  7984. } catch (error) {
  7985. throwError(error, 'Givekey.checkLeftKey');
  7986. return false;
  7987. }
  7988. }
  7989. }
  7990. const website_Givekey = Givekey;
  7991. const GiveawaySu_defaultTasks = {
  7992. steam: {
  7993. groupLinks: [],
  7994. wishlistLinks: [],
  7995. curatorLinks: [],
  7996. curatorLikeLinks: [],
  7997. followLinks: [],
  7998. forumLinks: [],
  7999. announcementLinks: [],
  8000. workshopVoteLinks: [],
  8001. playtestLinks: []
  8002. },
  8003. discord: {
  8004. serverLinks: []
  8005. },
  8006. instagram: {
  8007. userLinks: []
  8008. },
  8009. vk: {
  8010. nameLinks: []
  8011. },
  8012. twitch: {
  8013. channelLinks: []
  8014. },
  8015. reddit: {
  8016. redditLinks: []
  8017. },
  8018. youtube: {
  8019. channelLinks: [],
  8020. likeLinks: []
  8021. },
  8022. twitter: {
  8023. userLinks: [],
  8024. retweetLinks: []
  8025. }
  8026. };
  8027. class GiveawaySu_GiveawaySu extends website_Website {
  8028. name = 'GiveawaySu';
  8029. socialTasks = GiveawaySu_defaultTasks;
  8030. undoneTasks = GiveawaySu_defaultTasks;
  8031. buttons = [ 'doTask', 'undoTask' ];
  8032. static test() {
  8033. return /^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(window.location.href);
  8034. }
  8035. async after() {
  8036. try {
  8037. if (!this.#checkLogin()) {
  8038. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8039. }
  8040. if (!await this.#checkLeftKey()) {
  8041. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  8042. }
  8043. scripts_echoLog({}).warning(i18n('gsNotice'));
  8044. } catch (error) {
  8045. throwError(error, 'Giveawaysu.after');
  8046. }
  8047. }
  8048. init() {
  8049. try {
  8050. const logStatus = scripts_echoLog({
  8051. text: i18n('initing')
  8052. });
  8053. if ($('a.steam-login').length > 0) {
  8054. window.open('/steam/redirect', '_self');
  8055. logStatus.warning(i18n('needLogin'));
  8056. return false;
  8057. }
  8058. if (!this.#getGiveawayId()) {
  8059. return false;
  8060. }
  8061. this.initialized = true;
  8062. logStatus.success();
  8063. return true;
  8064. } catch (error) {
  8065. throwError(error, 'Giveawaysu.init');
  8066. return false;
  8067. }
  8068. }
  8069. async classifyTask(action) {
  8070. try {
  8071. const logStatus = scripts_echoLog({
  8072. text: i18n('getTasksInfo')
  8073. });
  8074. if (action === 'undo') {
  8075. this.socialTasks = GM_getValue(`gasTasks-${this.giveawayId}`)?.tasks || GiveawaySu_defaultTasks;
  8076. return true;
  8077. }
  8078. const pro = [];
  8079. const tasks = $('#actions tr');
  8080. if ($('div.bind-discord').is(':visible')) {
  8081. $('div.bind-discord a')[0].click();
  8082. }
  8083. if ($('div.bind-twitch').is(':visible')) {
  8084. $('div.bind-twitch a')[0].click();
  8085. }
  8086. for (const task of tasks) {
  8087. pro.push(new Promise(resolve => {
  8088. const td = $(task).find('td:not(".hidden")');
  8089. const colorfulTask = td.eq(1).find('a:not([data-trigger="link"])');
  8090. const colorlessTask = td.eq(2).find('a:not([data-trigger="link"])');
  8091. const taskDes = colorfulTask.length > 0 ? colorfulTask : colorlessTask;
  8092. const taskIcon = td.eq(0).find('i').attr('class') || '';
  8093. const taskName = taskDes.text().trim();
  8094. if (taskIcon.includes('ban') || /disable adblock/gi.test(taskName)) {
  8095. return resolve(true);
  8096. }
  8097. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  8098. if (!taskLink) {
  8099. return resolve(false);
  8100. }
  8101. if (taskIcon.includes('steam') && /join/gi.test(taskName)) {
  8102. this.undoneTasks.steam.groupLinks.push(taskLink);
  8103. } else if (/like.*announcement/gi.test(taskName)) {
  8104. this.undoneTasks.steam.announcementLinks.push(taskLink);
  8105. } else if (/(follow|subscribe).*curator/gim.test(taskName) && /^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  8106. this.undoneTasks.steam.curatorLinks.push(taskLink);
  8107. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  8108. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  8109. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  8110. this.undoneTasks.steam.forumLinks.push(taskLink);
  8111. } else if (taskIcon.includes('thumbs-up') && /^https?:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=[\d]+/.test(taskLink)) {
  8112. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8113. } else if (taskIcon.includes('plus') && /request.*playtest/gim.test(taskName)) {
  8114. this.undoneTasks.steam.playtestLinks.push(taskLink);
  8115. } else if (taskIcon.includes('discord') || /join.*discord/gim.test(taskName)) {
  8116. this.undoneTasks.discord.serverLinks.push(taskLink);
  8117. } else if (taskIcon.includes('instagram') || /follow.*instagram/gim.test(taskName)) {
  8118. this.undoneTasks.instagram.userLinks.push(taskLink);
  8119. } else if (taskIcon.includes('twitch') || /follow.*twitch.*channel/gim.test(taskName)) {
  8120. this.undoneTasks.twitch.channelLinks.push(taskLink);
  8121. } else if (taskIcon.includes('reddit') || /subscribe.*subreddit/gim.test(taskName) || /follow.*reddit/gim.test(taskName)) {
  8122. this.undoneTasks.reddit.redditLinks.push(taskLink);
  8123. } else if (/watch.*art/gim.test(taskName)) {
  8124. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8125. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  8126. this.undoneTasks.youtube.channelLinks.push(taskLink);
  8127. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  8128. this.undoneTasks.youtube.likeLinks.push(taskLink);
  8129. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  8130. this.undoneTasks.vk.nameLinks.push(taskLink);
  8131. } else {
  8132. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  8133. if (/wishlist.*game|add.*wishlist/gim.test(taskName)) {
  8134. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  8135. }
  8136. if (/follow.*button/gim.test(taskName)) {
  8137. this.undoneTasks.steam.followLinks.push(taskLink);
  8138. }
  8139. }
  8140. }
  8141. resolve(true);
  8142. }).catch(error => {
  8143. throwError(error, 'Giveawaysu.classifyTask->getRedirectLink');
  8144. return false;
  8145. });
  8146. }));
  8147. }
  8148. await Promise.all(pro);
  8149. logStatus.success();
  8150. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8151. this.socialTasks = this.undoneTasks;
  8152. if (window.DEBUG) {
  8153. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8154. }
  8155. GM_setValue(`gasTasks-${this.giveawayId}`, {
  8156. tasks: this.socialTasks,
  8157. time: new Date().getTime()
  8158. });
  8159. return true;
  8160. } catch (error) {
  8161. throwError(error, 'Giveawaysu.classifyTask');
  8162. return false;
  8163. }
  8164. }
  8165. #checkLogin() {
  8166. try {
  8167. if (!globalOptions.other.checkLogin) {
  8168. return true;
  8169. }
  8170. if ($('a.steam-login').length > 0) {
  8171. window.open('/steam/redirect', '_self');
  8172. }
  8173. return true;
  8174. } catch (error) {
  8175. throwError(error, 'Giveawaysu.checkLogin');
  8176. return false;
  8177. }
  8178. }
  8179. async #checkLeftKey() {
  8180. try {
  8181. if (!globalOptions.other.checkLeftKey) {
  8182. return true;
  8183. }
  8184. if ($('.giveaway-ended').length > 0 && $('.giveaway-key').length === 0) {
  8185. await external_Swal_default().fire({
  8186. icon: 'warning',
  8187. title: i18n('notice'),
  8188. text: i18n('noKeysLeft'),
  8189. confirmButtonText: i18n('confirm'),
  8190. cancelButtonText: i18n('cancel'),
  8191. showCancelButton: true
  8192. }).then(({
  8193. value
  8194. }) => {
  8195. if (value) {
  8196. window.close();
  8197. }
  8198. });
  8199. }
  8200. return true;
  8201. } catch (error) {
  8202. throwError(error, 'Giveawaysu.checkLeftKey');
  8203. return false;
  8204. }
  8205. }
  8206. #getGiveawayId() {
  8207. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  8208. if (giveawayId) {
  8209. this.giveawayId = giveawayId;
  8210. return true;
  8211. }
  8212. scripts_echoLog({
  8213. text: i18n('getFailed', 'GiveawayId')
  8214. });
  8215. return false;
  8216. }
  8217. }
  8218. class GiveeClub extends GiveawaySu_GiveawaySu {
  8219. name = 'GiveeClub';
  8220. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  8221. static test() {
  8222. return /^https?:\/\/givee\.club\/.*?\/event\/[\d]+/.test(window.location.href);
  8223. }
  8224. async after() {
  8225. try {
  8226. if (!this.#checkLogin()) {
  8227. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8228. }
  8229. if (!await this.#checkLeftKey()) {
  8230. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  8231. }
  8232. } catch (error) {
  8233. throwError(error, 'GiveeClub.after');
  8234. }
  8235. }
  8236. init() {
  8237. try {
  8238. const logStatus = scripts_echoLog({
  8239. text: i18n('initing')
  8240. });
  8241. if (!this.#checkLogin()) {
  8242. logStatus.warning(i18n('needLogin'));
  8243. return false;
  8244. }
  8245. if (!this.#getGiveawayId()) {
  8246. return false;
  8247. }
  8248. this.initialized = true;
  8249. logStatus.success();
  8250. return true;
  8251. } catch (error) {
  8252. throwError(error, 'GiveeClub.init');
  8253. return false;
  8254. }
  8255. }
  8256. async classifyTask(action) {
  8257. try {
  8258. const logStatus = scripts_echoLog({
  8259. text: i18n('getTasksInfo')
  8260. });
  8261. if (action === 'undo') {
  8262. this.socialTasks = GM_getValue(`gcTasks-${this.giveawayId}`)?.tasks || GiveawaySu_defaultTasks;
  8263. return true;
  8264. }
  8265. const pro = [];
  8266. const tasks = $('.event-actions tr');
  8267. for (const task of tasks) {
  8268. pro.push(new Promise(resolve => {
  8269. const taskDes = $(task).find('.event-action-label a');
  8270. const taskIcon = $(task).find('.event-action-icon i').attr('class') || '';
  8271. const taskName = taskDes.text().trim();
  8272. const taskType = $(task).find('button[data-type]')?.attr('data-type');
  8273. const taskFinished = $(task).find('.event-action-buttons .btn-success')?.length;
  8274. if (taskIcon.includes('ban') || /AdBlock/i.test(taskName) || taskIcon.includes('envelope') || taskFinished) {
  8275. return resolve(true);
  8276. }
  8277. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  8278. if (!taskLink) {
  8279. return resolve(false);
  8280. }
  8281. if (taskType === 'steam.group.join' && /^https?:\/\/steamcommunity\.com\/groups/.test(taskLink)) {
  8282. this.undoneTasks.steam.groupLinks.push(taskLink);
  8283. } else if (/like.*announcement/gi.test(taskName)) {
  8284. this.undoneTasks.steam.announcementLinks.push(taskLink);
  8285. } else if (taskType === 'steam.game.wishlist' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8286. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  8287. } else if (taskType === 'steam.game.wishlist' && taskDes.attr('data-steam-wishlist-appid')) {
  8288. this.undoneTasks.steam.wishlistLinks.push(`https://store.steampowered.com/app/${taskDes.attr('data-steam-wishlist-appid')}`);
  8289. } else if (taskType === 'steam.game.follow' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8290. this.undoneTasks.steam.followLinks.push(taskLink);
  8291. } else if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  8292. this.undoneTasks.steam.curatorLinks.push(taskLink);
  8293. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  8294. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  8295. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  8296. this.undoneTasks.steam.forumLinks.push(taskLink);
  8297. } else if (taskIcon.includes('discord')) {
  8298. this.undoneTasks.discord.serverLinks.push(taskLink);
  8299. } else if (taskIcon.includes('instagram')) {
  8300. this.undoneTasks.instagram.userLinks.push(taskLink);
  8301. } else if (taskIcon.includes('twitch')) {
  8302. this.undoneTasks.twitch.channelLinks.push(taskLink);
  8303. } else if (taskIcon.includes('reddit')) {
  8304. this.undoneTasks.reddit.redditLinks.push(taskLink);
  8305. } else if (/watch.*art/gim.test(taskName)) {
  8306. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8307. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  8308. this.undoneTasks.youtube.channelLinks.push(taskLink);
  8309. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  8310. this.undoneTasks.youtube.likeLinks.push(taskLink);
  8311. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  8312. this.undoneTasks.vk.nameLinks.push(taskLink);
  8313. } else if (taskIcon.includes('twitter')) {
  8314. if (/https?:\/\/twitter\.com\/[^/]+\/?$/gim.test(taskLink)) {
  8315. this.undoneTasks.twitter.userLinks.push(taskLink);
  8316. } else if (/https?:\/\/twitter\.com\/[^/]+?\/status\/[\d]+/gim.test(taskLink)) {
  8317. this.undoneTasks.twitter.retweetLinks.push(taskLink);
  8318. }
  8319. } else {
  8320. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  8321. if (/follow.*button/gim.test(taskName)) {
  8322. this.undoneTasks.steam.followLinks.push(taskLink);
  8323. }
  8324. }
  8325. }
  8326. resolve(true);
  8327. }).catch(error => {
  8328. throwError(error, 'GiveeClub.classifyTask->getRedirectLink');
  8329. return false;
  8330. });
  8331. }));
  8332. }
  8333. await Promise.all(pro);
  8334. logStatus.success();
  8335. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8336. this.socialTasks = this.undoneTasks;
  8337. if (window.DEBUG) {
  8338. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8339. }
  8340. GM_setValue(`gcTasks-${this.giveawayId}`, {
  8341. tasks: this.socialTasks,
  8342. time: new Date().getTime()
  8343. });
  8344. return true;
  8345. } catch (error) {
  8346. throwError(error, 'GiveeClub.classifyTask');
  8347. return false;
  8348. }
  8349. }
  8350. async verifyTask() {
  8351. try {
  8352. const logStatus = scripts_echoLog({
  8353. text: i18n('giveeClubVerifyNotice')
  8354. });
  8355. const taskButtons = $('.event-actions tr button').has('i.glyphicon-refresh').not('[data-type="user.adblock"]');
  8356. for (const button of taskButtons) {
  8357. button.click();
  8358. if ($(button).attr('data-type') !== 'steam.game.wishlist') {
  8359. await delay(1e3);
  8360. }
  8361. }
  8362. logStatus.warning(i18n('giveeClubVerifyFinished'));
  8363. return true;
  8364. } catch (error) {
  8365. throwError(error, 'Givekey.verifyTask');
  8366. return false;
  8367. }
  8368. }
  8369. #checkLogin() {
  8370. try {
  8371. if (!globalOptions.other.checkLogin) {
  8372. return true;
  8373. }
  8374. if ($('a[href*="/account/auth"]').length > 0) {
  8375. window.open($('a[href*="/account/auth"]').attr('href'), '_self');
  8376. }
  8377. return true;
  8378. } catch (error) {
  8379. throwError(error, 'GiveeClub.checkLogin');
  8380. return false;
  8381. }
  8382. }
  8383. #getGiveawayId() {
  8384. const giveawayId = window.location.href.match(/\/event\/([\d]+)/)?.[1];
  8385. if (giveawayId) {
  8386. this.giveawayId = giveawayId;
  8387. return true;
  8388. }
  8389. scripts_echoLog({
  8390. text: i18n('getFailed', 'GiveawayId')
  8391. });
  8392. return false;
  8393. }
  8394. async #checkLeftKey() {
  8395. try {
  8396. if (!globalOptions.other.checkLeftKey) {
  8397. return true;
  8398. }
  8399. if ($('.event-ended').length > 0 && $('.event-winner').length === 0) {
  8400. await external_Swal_default().fire({
  8401. icon: 'warning',
  8402. title: i18n('notice'),
  8403. text: i18n('giveawayEnded'),
  8404. confirmButtonText: i18n('confirm'),
  8405. cancelButtonText: i18n('cancel'),
  8406. showCancelButton: true
  8407. }).then(({
  8408. value
  8409. }) => {
  8410. if (value) {
  8411. window.close();
  8412. }
  8413. });
  8414. }
  8415. return true;
  8416. } catch (error) {
  8417. throwError(error, 'Giveawaysu.checkLeftKey');
  8418. return false;
  8419. }
  8420. }
  8421. }
  8422. const website_GiveeClub = GiveeClub;
  8423. const defaultOptions = {
  8424. maxPoint: '99999999'
  8425. };
  8426. class OpiumPulses {
  8427. name = 'OpiumPulses';
  8428. options = {
  8429. ...defaultOptions,
  8430. ...GM_getValue('OpiumPulsesOptions')
  8431. };
  8432. maxPoints = 99999999;
  8433. myPoints = 0;
  8434. buttons = [ 'doFreeTask', 'doPointTask' ];
  8435. static test() {
  8436. return window.location.host === 'www.opiumpulses.com';
  8437. }
  8438. async after() {
  8439. try {
  8440. if (!this.#checkLogin()) {
  8441. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8442. }
  8443. this.maxPoints = parseInt(this.options.maxPoint, 10);
  8444. } catch (error) {
  8445. throwError(error, 'OpiumPulses.after');
  8446. }
  8447. }
  8448. async doFreeTask() {
  8449. try {
  8450. this.#toggleTask('FREE');
  8451. } catch (error) {
  8452. throwError(error, 'OpiumPulses.doFreeTask');
  8453. }
  8454. }
  8455. async doPointTask() {
  8456. try {
  8457. this.myPoints = parseInt($('.page-header__nav-func-user-nav-items.points-items').text().match(/[\d]+/gim)?.[0] || '0', 10);
  8458. this.#toggleTask('points');
  8459. } catch (error) {
  8460. throwError(error, 'OpiumPulses.doPointTask');
  8461. }
  8462. }
  8463. async #toggleTask(type) {
  8464. try {
  8465. const items = $(`.giveaways-page-item:contains('${type}'):not(:contains('ENTERED'))`);
  8466. for (const item of items) {
  8467. const needPoints = parseInt($(item).find('.giveaways-page-item-header-points').text().match(/[\d]+/gim)?.[0] || '999999', 10);
  8468. const name = $(item).find('.giveaways-page-item-footer-name').text().trim();
  8469. if (type === 'points' && needPoints > this.myPoints) {
  8470. scripts_echoLog({}).warning(`${i18n('noPoints')}: ${name}`);
  8471. } else if (type === 'points' && !needPoints) {
  8472. scripts_echoLog({}).warning(`${i18n('getNeedPointsFailed')}: ${name}`);
  8473. } else if (!(type === 'points' && needPoints > this.maxPoints)) {
  8474. const logStatus = scripts_echoLog({
  8475. text: `${i18n('joiningLottery')}<a href="${$(item).find('a.giveaways-page-item-img-btn-more').attr('href')}" target="_blank">${name}</a>...`
  8476. });
  8477. const aElement = $(item).find('a.giveaways-page-item-img-btn-enter:contains(\'enter\')');
  8478. if (aElement?.attr('onclick')?.includes('checkUser')) {
  8479. const giveawayId = aElement.attr('onclick')?.match(/[\d]+/)?.[0];
  8480. if (giveawayId) {
  8481. checkUser(giveawayId);
  8482. }
  8483. }
  8484. if (!aElement.attr('href')) {
  8485. logStatus.error('Error: No "href".');
  8486. continue;
  8487. }
  8488. const {
  8489. result,
  8490. statusText,
  8491. status,
  8492. data
  8493. } = await tools_httpRequest({
  8494. url: aElement.attr('href'),
  8495. method: 'GET'
  8496. });
  8497. if (result === 'Success') {
  8498. if (data?.responseText && /You've entered this giveaway/gim.test(data.responseText)) {
  8499. logStatus.success();
  8500. const points = data.responseText.match(/Points:[\s]*?([\d]+)/)?.[1];
  8501. if (type === 'points' && points) {
  8502. this.myPoints = parseInt(points, 10);
  8503. }
  8504. } else {
  8505. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  8506. }
  8507. } else {
  8508. logStatus.error(`${result}:${statusText}(${status})`);
  8509. }
  8510. }
  8511. }
  8512. scripts_echoLog({
  8513. text: '-----END-----'
  8514. });
  8515. } catch (error) {
  8516. throwError(error, 'OpiumPulses.toggleTask');
  8517. }
  8518. }
  8519. init() {
  8520. return true;
  8521. }
  8522. classifyTask() {
  8523. return true;
  8524. }
  8525. #checkLogin() {
  8526. try {
  8527. if (!globalOptions.other.checkLogin) {
  8528. return true;
  8529. }
  8530. if ($('a[href*="/site/login"]').length > 1) {
  8531. window.open('/site/login', '_self');
  8532. }
  8533. return true;
  8534. } catch (error) {
  8535. throwError(error, 'OpiumPulses.checkLogin');
  8536. return false;
  8537. }
  8538. }
  8539. }
  8540. const website_OpiumPulses = OpiumPulses;
  8541. const external_dayjs_namespaceObject = dayjs;
  8542. var external_dayjs_default = __webpack_require__.n(external_dayjs_namespaceObject);
  8543. const leftKeyChecker = {
  8544. async classify(link) {
  8545. try {
  8546. if (/^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(link)) {
  8547. return await this.giveawaySu(link);
  8548. }
  8549. if (/^https?:\/\/givee\.club\/[\w]+?\/event\/[\d]+/.test(link)) {
  8550. return await this.giveeClub(link);
  8551. }
  8552. if (/^https?:\/\/gleam\.io\/.+?\/.+/.test(link)) {
  8553. return await this.gleam(link);
  8554. }
  8555. if (/^https?:\/\/www\.indiedb\.com\/giveaways\/.+/.test(link)) {
  8556. return await this.indieDb(link);
  8557. }
  8558. if (/^https?:\/\/key-hub\.eu\/giveaway\/[\d]+/.test(link)) {
  8559. return await this.keyhub(link);
  8560. }
  8561. if (/^https?:\/\/opquests\.com\/quests\/[\d]+/.test(link)) {
  8562. return await this.opquests(link);
  8563. }
  8564. if (/^https?:\/\/itch\.io\/s\/[\d]+?\/.*/.test(link)) {
  8565. return await this.itch(link);
  8566. }
  8567. return false;
  8568. } catch (error) {
  8569. throwError(error, 'leftKeyChecker.classify');
  8570. return false;
  8571. }
  8572. },
  8573. async giveawaySu(link) {
  8574. try {
  8575. const {
  8576. result,
  8577. data
  8578. } = await tools_httpRequest({
  8579. url: link,
  8580. method: 'GET'
  8581. });
  8582. if (result === 'Success' && data?.status === 200) {
  8583. if (data.responseText.includes('class="steam-login"')) {
  8584. return false;
  8585. }
  8586. if (data.responseText.includes('class="giveaway-ended"')) {
  8587. return 'Ended';
  8588. }
  8589. return 'Active';
  8590. }
  8591. return false;
  8592. } catch (error) {
  8593. throwError(error, 'leftKeyChecker.giveawaySu');
  8594. return false;
  8595. }
  8596. },
  8597. async giveeClub(link) {
  8598. try {
  8599. const {
  8600. result,
  8601. data
  8602. } = await tools_httpRequest({
  8603. url: link,
  8604. method: 'GET'
  8605. });
  8606. if (result === 'Success' && data?.status === 200) {
  8607. if (data.responseText.includes('class="event-winner"')) {
  8608. return 'Won';
  8609. }
  8610. if (data.responseText.includes('class="event-ended"')) {
  8611. return 'Ended';
  8612. }
  8613. return 'Active';
  8614. }
  8615. return false;
  8616. } catch (error) {
  8617. throwError(error, 'leftKeyChecker.giveeClub');
  8618. return false;
  8619. }
  8620. },
  8621. async gleam(link) {
  8622. try {
  8623. const {
  8624. result,
  8625. data
  8626. } = await tools_httpRequest({
  8627. url: link,
  8628. method: 'GET'
  8629. });
  8630. if (result === 'Success' && data?.status === 200) {
  8631. if (/incentives&quot;:{&quot;[\d]+?&quot;:\[&quot;.+?&quot;\]/.test(data.responseText)) {
  8632. return 'Won';
  8633. }
  8634. const campaignDiv = data.responseText.match(/<div class='popup-blocks-container'[\w\W]+?'>/)?.[0];
  8635. if (!campaignDiv) {
  8636. return false;
  8637. }
  8638. const campaignString = $(campaignDiv).attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  8639. if (!campaignString) {
  8640. return false;
  8641. }
  8642. const {
  8643. campaign
  8644. } = JSON.parse(campaignString);
  8645. if (campaign.banned) {
  8646. return 'Banned';
  8647. }
  8648. if (campaign.finished) {
  8649. return 'Ended';
  8650. }
  8651. if (campaign.paused) {
  8652. return 'Paused';
  8653. }
  8654. if (new Date().getTime() < campaign.starts_at * 1e3) {
  8655. return 'NotStart';
  8656. }
  8657. return 'Active';
  8658. }
  8659. return false;
  8660. } catch (error) {
  8661. throwError(error, 'leftKeyChecker.gleam');
  8662. return false;
  8663. }
  8664. },
  8665. async indieDb(link) {
  8666. try {
  8667. const {
  8668. result,
  8669. data
  8670. } = await tools_httpRequest({
  8671. url: link,
  8672. method: 'GET'
  8673. });
  8674. if (result === 'Success' && data?.status === 200) {
  8675. if (data.responseText.includes('Congrats you WON')) {
  8676. return 'Won';
  8677. }
  8678. if (data.responseText.includes('Giveaway is closed') || data.responseText.includes('next time')) {
  8679. return 'Ended';
  8680. }
  8681. return 'Active';
  8682. }
  8683. return false;
  8684. } catch (error) {
  8685. throwError(error, 'leftKeyChecker.indieDb');
  8686. return false;
  8687. }
  8688. },
  8689. async keyhub(link) {
  8690. try {
  8691. const {
  8692. result,
  8693. data
  8694. } = await tools_httpRequest({
  8695. url: link,
  8696. method: 'GET'
  8697. });
  8698. if (result === 'Success' && data?.status === 200) {
  8699. const keysleft = data.responseText.match(/<span id="keysleft">([\d]+?)<\/span>/)?.[1];
  8700. if (!keysleft) {
  8701. return false;
  8702. }
  8703. if (keysleft === '0') {
  8704. return 'Ended';
  8705. }
  8706. return `Active(${keysleft})`;
  8707. }
  8708. return false;
  8709. } catch (error) {
  8710. throwError(error, 'leftKeyChecker.keyhub');
  8711. return false;
  8712. }
  8713. },
  8714. async opquests(link) {
  8715. try {
  8716. const {
  8717. result,
  8718. data
  8719. } = await tools_httpRequest({
  8720. url: link,
  8721. method: 'GET'
  8722. });
  8723. if (result === 'Success' && data?.status === 200) {
  8724. const keysleft = data.responseText.match(/<div class="">[\s]*?([\d]+?)[\s]*?of/)?.[1];
  8725. if (!keysleft) {
  8726. return false;
  8727. }
  8728. if (keysleft === '0') {
  8729. return 'Ended';
  8730. }
  8731. return `Active(${keysleft})`;
  8732. } else if (data?.status === 404) {
  8733. return 'Ended';
  8734. }
  8735. return false;
  8736. } catch (error) {
  8737. throwError(error, 'leftKeyChecker.opquests');
  8738. return false;
  8739. }
  8740. },
  8741. async itch(link) {
  8742. try {
  8743. const {
  8744. result,
  8745. data
  8746. } = await tools_httpRequest({
  8747. url: link,
  8748. method: 'GET'
  8749. });
  8750. if (result === 'Success' && data?.status === 200) {
  8751. const endDate = data.responseText.match(/{"start_date":"[0-9A-Z-:]+?".*?"end_date":"([0-9A-Z-:]+?)".*?}/)?.[1];
  8752. if (!endDate) {
  8753. return false;
  8754. }
  8755. if (new Date().getTime() > new Date(endDate).getTime()) {
  8756. return 'Ended';
  8757. }
  8758. return `Active(${external_dayjs_default()(endDate).format('YYYY-MM-DD HH:mm:ss')})`;
  8759. }
  8760. return false;
  8761. } catch (error) {
  8762. throwError(error, 'leftKeyChecker.opquests');
  8763. return false;
  8764. }
  8765. }
  8766. };
  8767. const website_leftKeyChecker = leftKeyChecker;
  8768. const Keylol_defaultTasksTemplate = {
  8769. steam: {
  8770. groupLinks: [],
  8771. wishlistLinks: [],
  8772. curatorLinks: [],
  8773. curatorLikeLinks: [],
  8774. followLinks: [],
  8775. forumLinks: [],
  8776. announcementLinks: [],
  8777. workshopVoteLinks: [],
  8778. licenseLinks: []
  8779. },
  8780. discord: {
  8781. serverLinks: []
  8782. },
  8783. instagram: {
  8784. userLinks: []
  8785. },
  8786. vk: {
  8787. nameLinks: []
  8788. },
  8789. twitch: {
  8790. channelLinks: []
  8791. },
  8792. reddit: {
  8793. redditLinks: []
  8794. },
  8795. twitter: {
  8796. userLinks: [],
  8797. retweetLinks: []
  8798. },
  8799. youtube: {
  8800. channelLinks: [],
  8801. likeLinks: []
  8802. }
  8803. };
  8804. const Keylol_defaultTasks = JSON.stringify(Keylol_defaultTasksTemplate);
  8805. class Keylol extends website_Website {
  8806. name = 'Keylol';
  8807. socialTasks = JSON.parse(Keylol_defaultTasks);
  8808. undoneTasks = JSON.parse(Keylol_defaultTasks);
  8809. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect' ];
  8810. static test() {
  8811. return window.location.host === 'keylol.com' && (!!$('.subforum_left_title_left_up a').eq(3).attr('href')?.includes('319') || !!$('.subforum_left_title_left_up a').eq(3).attr('href')?.includes('234'));
  8812. }
  8813. init() {
  8814. return true;
  8815. }
  8816. after() {
  8817. try {
  8818. const selector = this.name === 'Keylol' ? '#postlist>div[id^="post_"]:first' : 'div.container';
  8819. const mainPost = $(selector);
  8820. const discordLinks = mainPost.find('a[href*="discord.com"]:visible');
  8821. const redditLinks = mainPost.find('a[href*="reddit.com"]:visible');
  8822. const insLinks = mainPost.find('a[href*="instagram.com"]:visible');
  8823. const twitterLinks = mainPost.find('a[href*="twitter.com"]:visible,a[href*="x.com"]:visible');
  8824. const twitchLinks = mainPost.find('a[href*="twitch.tv"]:visible');
  8825. const vkLinks = mainPost.find('a[href*="vk.com"]:visible');
  8826. const steamStoreLinks = mainPost.find('a[href*="store.steampowered.com"]:visible');
  8827. const steamCommunityLinks = mainPost.find('a[href*="steamcommunity.com"]:visible');
  8828. const ytbLinks = mainPost.find('a[href*="youtube.com"]:visible');
  8829. if (discordLinks.length > 0) {
  8830. for (const discordLink of discordLinks) {
  8831. const link = $(discordLink).attr('href');
  8832. if (!(link && /^https?:\/\/discord\.com\/invite\/.+/.test(link))) {
  8833. continue;
  8834. }
  8835. this.#addBtn(discordLink, 'discord', 'serverLinks', link);
  8836. }
  8837. }
  8838. if (redditLinks.length > 0) {
  8839. for (const redditLink of redditLinks) {
  8840. const link = $(redditLink).attr('href');
  8841. if (!(link && /^https?:\/\/www\.reddit\.com\/(r|user)\/.+/.test(link))) {
  8842. continue;
  8843. }
  8844. this.#addBtn(redditLink, 'reddit', 'redditLinks', link);
  8845. }
  8846. }
  8847. if (insLinks.length > 0) {
  8848. for (const insLink of insLinks) {
  8849. const link = $(insLink).attr('href');
  8850. if (!(link && /^https:\/\/www\.instagram\.com\/.+/.test(link))) {
  8851. continue;
  8852. }
  8853. this.#addBtn(insLink, 'instagram', 'userLinks', link);
  8854. }
  8855. }
  8856. if (twitterLinks.length > 0) {
  8857. for (const twitterLink of twitterLinks) {
  8858. const link = $(twitterLink).attr('href');
  8859. if (!(link && /^https:\/\/twitter\.com\/.+/.test(link))) {
  8860. continue;
  8861. }
  8862. if (/https:\/\/twitter\.com\/.*?\/status\/[\d]+/.test(link)) {
  8863. this.#addBtn(twitterLink, 'twitter', 'retweetLinks', link);
  8864. } else {
  8865. this.#addBtn(twitterLink, 'twitter', 'userLinks', link);
  8866. }
  8867. }
  8868. }
  8869. if (twitchLinks.length > 0) {
  8870. for (const twitchLink of twitchLinks) {
  8871. const link = $(twitchLink).attr('href');
  8872. if (!(link && /^https:\/\/(www\.)?twitch\.tv\/.+/.test(link))) {
  8873. continue;
  8874. }
  8875. this.#addBtn(twitchLink, 'twitch', 'channelLinks', link);
  8876. }
  8877. }
  8878. if (vkLinks.length > 0) {
  8879. for (const vkLink of vkLinks) {
  8880. const link = $(vkLink).attr('href');
  8881. if (!(link && /^https:\/\/vk\.com\/.+/.test(link))) {
  8882. continue;
  8883. }
  8884. this.#addBtn(vkLink, 'vk', 'nameLinks', link);
  8885. }
  8886. }
  8887. if (steamStoreLinks.length > 0) {
  8888. for (const steamStoreLink of steamStoreLinks) {
  8889. const link = $(steamStoreLink).attr('href');
  8890. if (!link) {
  8891. continue;
  8892. }
  8893. if (/curator\/[\d]+/.test(link)) {
  8894. this.#addBtn(steamStoreLink, 'steam', 'curatorLinks', link);
  8895. } else if (/(publisher|developer|franchise)\/.+/.test(link)) {
  8896. this.#addBtn(steamStoreLink, 'steam', 'curatorLikeLinks', link);
  8897. } else if (/news(hub)?\/app\/[\d]+\/view\/[\d]+/.test(link)) {
  8898. this.#addBtn(steamStoreLink, 'steam', 'announcementLinks', link);
  8899. } else if (/app\/[\d]+/.test(link)) {
  8900. this.#addBtn(steamStoreLink, 'steam', 'followLinks', link);
  8901. this.#addBtn(steamStoreLink, 'steam', 'wishlistLinks', link);
  8902. }
  8903. }
  8904. }
  8905. if (steamCommunityLinks.length > 0) {
  8906. for (const steamCommunityLink of steamCommunityLinks) {
  8907. const link = $(steamCommunityLink).attr('href');
  8908. if (!link) {
  8909. continue;
  8910. }
  8911. if (/groups\/.+/.test(link)) {
  8912. this.#addBtn(steamCommunityLink, 'steam', 'groupLinks', link);
  8913. } else if (/announcements\/detail\/[\d]+/.test(link)) {
  8914. this.#addBtn(steamCommunityLink, 'steam', 'announcementLinks', link);
  8915. }
  8916. }
  8917. }
  8918. if (ytbLinks.length > 0) {
  8919. for (const ytbLink of ytbLinks) {
  8920. const link = $(ytbLink).attr('href');
  8921. if (!link) {
  8922. continue;
  8923. }
  8924. this.#addBtn(ytbLink, 'youtube', 'channelLinks', link);
  8925. this.#addBtn(ytbLink, 'youtube', 'likeLinks', link);
  8926. }
  8927. }
  8928. const giveawayLinks = mainPost.find('a[href*="giveaway.su/giveaway/view/"]:visible,a[href*="givee.club/"]:visible,a[href*="gleam.io/"]:visible,a[href*="www.indiedb.com/giveaways/"]:visible,a[href*="key-hub.eu/giveaway/"]:visible,a[href*="opquests.com/quests/"]:visible,a[href*="itch.io/s/"]:visible');
  8929. if (giveawayLinks.length > 0) {
  8930. for (const giveawayLink of giveawayLinks) {
  8931. const link = $(giveawayLink).attr('href');
  8932. if (!link) {
  8933. continue;
  8934. }
  8935. website_leftKeyChecker.classify(link).then(status => {
  8936. if (!status) {
  8937. return;
  8938. }
  8939. if (/^Active/.test(status)) {
  8940. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status active" title="${i18n('Active')}">${status}</font>`);
  8941. return;
  8942. }
  8943. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status not-active" title="${i18n(status)}">${status}</font>`);
  8944. }).catch(error => {
  8945. throwError(error, 'keylol.after -> leftKeyChecker');
  8946. });
  8947. }
  8948. }
  8949. if (this.name === 'Keylol') {
  8950. const asfLinks = mainPost.find('a[href^="#asf"]:visible');
  8951. if (asfLinks.length > 0) {
  8952. for (const asfLink of asfLinks) {
  8953. const link = $(asfLink).attr('href');
  8954. if (!link) {
  8955. continue;
  8956. }
  8957. this.#addBtn($(`a[href="${link}"]`).after('<span style="color: #ccc; margin: 0 -5px 0 5px"> | </span>').next()[0], 'steam', 'licenseLinks', `appid-${link.replace('#asf', '')}`);
  8958. }
  8959. }
  8960. const subLinks = mainPost.find('a[href*="steamdb.info/sub/"]:visible');
  8961. if (subLinks.length > 0) {
  8962. for (const subLink of subLinks) {
  8963. const link = $(subLink).attr('href');
  8964. if (!link) {
  8965. continue;
  8966. }
  8967. const subid = link.match(/^https:\/\/steamdb\.info\/sub\/([\d]+)/)?.[1];
  8968. if (!subid) {
  8969. continue;
  8970. }
  8971. this.#addBtn(subLink, 'steam', 'licenseLinks', `subid-${subid}`);
  8972. }
  8973. }
  8974. const asfLinks2 = mainPost.find('.blockcode:contains("addlicense"):visible');
  8975. if (asfLinks2.length > 0) {
  8976. for (const asfLink of asfLinks2) {
  8977. const subid = asfLink.innerText.match(/[\d]+/g);
  8978. if (!subid || subid.length === 0) {
  8979. continue;
  8980. }
  8981. this.#addBtn($(asfLink).children('em')[0], 'steam', 'licenseLinks', `subid-${subid.join(',')}`);
  8982. }
  8983. }
  8984. }
  8985. } catch (error) {
  8986. throwError(error, 'keylol.after');
  8987. }
  8988. }
  8989. classifyTask(action) {
  8990. try {
  8991. this.socialTasks = JSON.parse(Keylol_defaultTasks);
  8992. this.undoneTasks = JSON.parse(Keylol_defaultTasks);
  8993. const selectedBtns = $('.auto-task-keylol[selected="selected"]:visible');
  8994. for (const btn of selectedBtns) {
  8995. const button = $(btn);
  8996. const social = button.attr('data-social');
  8997. const type = button.attr('data-type');
  8998. const link = button.attr('data-link');
  8999. if (!(social && type && link)) {
  9000. continue;
  9001. }
  9002. if (action === 'do') {
  9003. this.undoneTasks[social][type].push(link);
  9004. }
  9005. if (action === 'undo') {
  9006. this.socialTasks[social][type].push(link);
  9007. }
  9008. }
  9009. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9010. this.socialTasks = this.uniqueTasks(this.socialTasks);
  9011. if (window.DEBUG) {
  9012. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9013. }
  9014. return true;
  9015. } catch (error) {
  9016. throwError(error, 'Keylol.classifyTask');
  9017. return false;
  9018. }
  9019. }
  9020. selectAll() {
  9021. try {
  9022. $('.auto-task-keylol:visible').attr('selected', 'selected');
  9023. } catch (error) {
  9024. throwError(error, 'Keylol.selectAll');
  9025. }
  9026. }
  9027. selectNone() {
  9028. try {
  9029. $('.auto-task-keylol:visible').removeAttr('selected');
  9030. } catch (error) {
  9031. throwError(error, 'Keylol.selectNone');
  9032. }
  9033. }
  9034. invertSelect() {
  9035. try {
  9036. $('.auto-task-keylol:visible').each((index, element) => {
  9037. element.getAttribute('selected') ? element.removeAttribute('selected') : element.setAttribute('selected', 'selected');
  9038. });
  9039. } catch (error) {
  9040. throwError(error, 'Keylol.invertSelect');
  9041. }
  9042. }
  9043. #addBtn(before, social, linkType, link) {
  9044. try {
  9045. $(before).after('<a href="javascript:void(0);" class="auto-task-keylol" target="_self"' + ' onclick="this.getAttribute(\'selected\') ? this.removeAttribute(\'selected\') : this.setAttribute(\'selected\', \'selected\')"' + ` data-social="${social}" data-type="${linkType}" data-link="${link}">${linkType.replace('Links', '')}</a>`);
  9046. } catch (error) {
  9047. throwError(error, 'keylol.addBtn');
  9048. }
  9049. }
  9050. }
  9051. const website_Keylol = Keylol;
  9052. const Opquests_defaultTasks = {
  9053. steam: {
  9054. groupLinks: [],
  9055. wishlistLinks: [],
  9056. followLinks: [],
  9057. curatorLikeLinks: []
  9058. }
  9059. };
  9060. class Opquests extends website_Website {
  9061. name = 'Opquests';
  9062. undoneTasks = {
  9063. ...Opquests_defaultTasks
  9064. };
  9065. buttons = [ 'doTask', 'getKey' ];
  9066. static test() {
  9067. return window.location.host === 'opquests.com';
  9068. }
  9069. async after() {
  9070. try {
  9071. if (!this.#checkLogin()) {
  9072. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9073. }
  9074. } catch (error) {
  9075. throwError(error, 'Opquests.after');
  9076. }
  9077. }
  9078. init() {
  9079. try {
  9080. const logStatus = scripts_echoLog({
  9081. text: i18n('initing')
  9082. });
  9083. if ($('a[href*="/auth/redirect"]').length > 0) {
  9084. window.open('/auth/redirect', '_self');
  9085. logStatus.warning(i18n('needLogin'));
  9086. return false;
  9087. }
  9088. if (!this.#getGiveawayId()) {
  9089. return false;
  9090. }
  9091. this.initialized = true;
  9092. logStatus.success();
  9093. return true;
  9094. } catch (error) {
  9095. throwError(error, 'Opquests.init');
  9096. return false;
  9097. }
  9098. }
  9099. async classifyTask(action) {
  9100. try {
  9101. if (action === 'undo') {
  9102. scripts_echoLog({
  9103. text: i18n('cannotUndo')
  9104. });
  9105. return false;
  9106. }
  9107. const logStatus = scripts_echoLog({
  9108. text: i18n('getTasksInfo')
  9109. });
  9110. const tasks = $('.w-full:contains("Validate") .items-center');
  9111. for (const task of tasks) {
  9112. const link = $(task).find('a:contains("Open")').attr('href');
  9113. const taskDes = $(task).find('div').eq(1).text().trim();
  9114. if (!link) {
  9115. continue;
  9116. }
  9117. if (/steamcommunity\.com\/groups\//.test(link)) {
  9118. this.undoneTasks.steam.groupLinks.push(link);
  9119. } else if (/store\.steampowered\.com\/app\//.test(link)) {
  9120. if (/wishlist/gim.test(taskDes)) {
  9121. this.undoneTasks.steam.wishlistLinks.push(link);
  9122. } else if (/follow/gim.test(taskDes)) {
  9123. this.undoneTasks.steam.followLinks.push(link);
  9124. }
  9125. } else if (/store\.steampowered\.com\/(publisher|developer|curator)\//.test(link) && /follow/gim.test(taskDes)) {
  9126. this.undoneTasks.steam.curatorLikeLinks.push(link);
  9127. } else {
  9128. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  9129. }
  9130. }
  9131. logStatus.success();
  9132. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9133. if (window.DEBUG) {
  9134. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9135. }
  9136. return true;
  9137. } catch (error) {
  9138. throwError(error, 'Opquests.classifyTask');
  9139. return false;
  9140. }
  9141. }
  9142. async verifyTask() {
  9143. try {
  9144. if (!this.initialized) {
  9145. this.init();
  9146. }
  9147. const tasks = $.makeArray($('div.w-full').find('.items-center').has('button.submit-loader')).map(ele => ({
  9148. token: $(ele).find('input[name="_token"]').val(),
  9149. taskId: $(ele).find('input[name="task_id"]').val(),
  9150. title: $(ele).find('span.text-sm').text().trim()
  9151. }));
  9152. await this.#confirm();
  9153. for (const task of tasks) {
  9154. await this.#verify(task);
  9155. await delay(1e3);
  9156. }
  9157. scripts_echoLog({}).success(i18n('allTasksComplete'));
  9158. if (await this.getKey()) {
  9159. return true;
  9160. }
  9161. window.location.reload();
  9162. return false;
  9163. } catch (error) {
  9164. throwError(error, 'Opquests.verifyTask');
  9165. return false;
  9166. }
  9167. }
  9168. async #confirm() {
  9169. try {
  9170. const logStatus = scripts_echoLog({
  9171. html: `<li>${i18n('confirmingTask')}...<font></font></li>`
  9172. });
  9173. const {
  9174. result,
  9175. statusText,
  9176. status,
  9177. data
  9178. } = await tools_httpRequest({
  9179. url: `https://opquests.com/quests/${this.giveawayId}?confirm=1`,
  9180. method: 'GET',
  9181. nochche: true,
  9182. headers: {
  9183. origin: 'https://opquests.com',
  9184. referer: `https://opquests.com/warning?id=${this.giveawayId}`
  9185. }
  9186. });
  9187. if (result === 'Success') {
  9188. if (data?.status === 200) {
  9189. logStatus.success();
  9190. return true;
  9191. }
  9192. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9193. return false;
  9194. }
  9195. logStatus.error(`${result}:${statusText}(${status})`);
  9196. return false;
  9197. } catch (error) {
  9198. throwError(error, 'Opquests.confirm');
  9199. return false;
  9200. }
  9201. }
  9202. async #verify(task) {
  9203. try {
  9204. const logStatus = scripts_echoLog({
  9205. html: `<li>${i18n('verifyingTask')}${task.title.trim()}...<font></font></li>`
  9206. });
  9207. const {
  9208. result,
  9209. statusText,
  9210. status,
  9211. data
  9212. } = await tools_httpRequest({
  9213. url: 'https://opquests.com/entries',
  9214. method: 'POST',
  9215. dataType: 'json',
  9216. nochche: true,
  9217. headers: {
  9218. origin: 'https://opquests.com',
  9219. pragma: 'no-cache',
  9220. referer: `${window.location.href.split('?')[0]}?confirm=1`,
  9221. 'content-type': 'application/x-www-form-urlencoded'
  9222. },
  9223. data: `_token=${task.token}&task_id=${task.taskId}`
  9224. });
  9225. if (result === 'Success') {
  9226. if (data?.responseText?.includes('Successfully completed task') || data?.responseText?.includes('unlocked the key')) {
  9227. logStatus.success();
  9228. return true;
  9229. }
  9230. const key = $(data?.responseText || '').find('button[data-clipboard-text]:contains("Copy")').attr('data-clipboard-text')?.trim();
  9231. if (key) {
  9232. logStatus.success();
  9233. scripts_echoLog({}).success(key);
  9234. return true;
  9235. }
  9236. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9237. return false;
  9238. }
  9239. logStatus.error(`${result}:${statusText}(${status})`);
  9240. return false;
  9241. } catch (error) {
  9242. throwError(error, 'Opquests.verify');
  9243. return false;
  9244. }
  9245. }
  9246. async getKey(isButton) {
  9247. try {
  9248. const logStatus = scripts_echoLog({
  9249. text: i18n('gettingKey')
  9250. });
  9251. const {
  9252. result,
  9253. statusText,
  9254. status,
  9255. data
  9256. } = await tools_httpRequest({
  9257. url: 'https://opquests.com/keys',
  9258. method: 'GET'
  9259. });
  9260. if (result === 'Success') {
  9261. if (data?.responseText) {
  9262. const key = $(data?.responseText).find(`div.items-center:contains("${$('h1.font-bold').text().trim().replace(' Quest', '')}")`).find('div.font-bold').next().text();
  9263. if (!key) {
  9264. logStatus.error('Error: Key was not found');
  9265. if (isButton) {
  9266. window.open('https://opquests.com/keys', '_self');
  9267. }
  9268. return false;
  9269. }
  9270. logStatus.success();
  9271. scripts_echoLog({}).success(key);
  9272. return true;
  9273. }
  9274. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9275. return false;
  9276. }
  9277. logStatus.error(`${result}:${statusText}(${status})`);
  9278. return false;
  9279. } catch (error) {
  9280. throwError(error, 'Opquests.getGiveawayId');
  9281. return false;
  9282. }
  9283. }
  9284. #getGiveawayId() {
  9285. try {
  9286. const giveawayId = window.location.href.match(/quests\/([\d]+)/)?.[1];
  9287. if (giveawayId) {
  9288. this.giveawayId = giveawayId;
  9289. return true;
  9290. }
  9291. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  9292. return false;
  9293. } catch (error) {
  9294. throwError(error, 'Opquests.getGiveawayId');
  9295. return false;
  9296. }
  9297. }
  9298. #checkLogin() {
  9299. try {
  9300. if (!globalOptions.other.checkLogin) {
  9301. return true;
  9302. }
  9303. if ($('a[href*="/auth/redirect"]').length > 0) {
  9304. window.open('/auth/redirect', '_self');
  9305. }
  9306. return true;
  9307. } catch (error) {
  9308. throwError(error, 'Opquests.checkLogin');
  9309. return false;
  9310. }
  9311. }
  9312. }
  9313. const website_Opquests = Opquests;
  9314. const Gleam_defaultTasksTemplate = {
  9315. steam: {
  9316. groupLinks: [],
  9317. wishlistLinks: [],
  9318. followLinks: [],
  9319. curatorLinks: [],
  9320. curatorLikeLinks: []
  9321. },
  9322. twitter: {
  9323. userLinks: [],
  9324. retweetLinks: []
  9325. },
  9326. twitch: {
  9327. channelLinks: []
  9328. },
  9329. discord: {
  9330. serverLinks: []
  9331. },
  9332. youtube: {
  9333. channelLinks: []
  9334. },
  9335. extra: {
  9336. gleam: []
  9337. }
  9338. };
  9339. const Gleam_defaultTasks = JSON.stringify(Gleam_defaultTasksTemplate);
  9340. const Gleam_defaultOptions = {
  9341. vlootUsername: '',
  9342. gameroundUsername: ''
  9343. };
  9344. class Gleam extends website_Website {
  9345. name = 'Gleam';
  9346. undoneTasks = JSON.parse(Gleam_defaultTasks);
  9347. socialTasks = JSON.parse(Gleam_defaultTasks);
  9348. options = {
  9349. ...Gleam_defaultOptions,
  9350. ...GM_getValue('GleamOptions')
  9351. };
  9352. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  9353. static test() {
  9354. return window.location.host === 'gleam.io';
  9355. }
  9356. async after() {
  9357. try {
  9358. if (window.location.search.includes('8b07d23f4bfa65f9')) {
  9359. const checkComplete = setInterval(() => {
  9360. if ($('.entry-content .entry-method i.fa-check').length > 0) {
  9361. clearInterval(checkComplete);
  9362. window.close();
  9363. }
  9364. });
  9365. for (const task of $('.entry-content .entry-method')) {
  9366. const taskInfo = $(task).find('.user-links');
  9367. const expandInfo = $(task).find('.expandable');
  9368. const aElements = expandInfo.find('a.btn,a:contains(Continue),button:contains(Continue)');
  9369. if (aElements.length > 0) {
  9370. for (const element of aElements) {
  9371. const $element = $(element);
  9372. const href = $element.attr('href');
  9373. $element.removeAttr('href')[0].click();
  9374. $element.attr('href', href);
  9375. await delay(1e3);
  9376. }
  9377. }
  9378. taskInfo[0].click();
  9379. await delay(1e3);
  9380. }
  9381. scripts_echoLog({}).warning(i18n('gleamTaskNotice'));
  9382. } else if (!await this.#checkLeftKey()) {
  9383. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  9384. }
  9385. } catch (error) {
  9386. throwError(error, 'Gleam.after');
  9387. return false;
  9388. }
  9389. }
  9390. init() {
  9391. try {
  9392. const logStatus = scripts_echoLog({
  9393. text: i18n('initing')
  9394. });
  9395. if (!this.#getGiveawayId()) {
  9396. return false;
  9397. }
  9398. this.initialized = true;
  9399. logStatus.success();
  9400. return true;
  9401. } catch (error) {
  9402. throwError(error, 'Gleam.init');
  9403. return false;
  9404. }
  9405. }
  9406. async classifyTask(action) {
  9407. try {
  9408. const logStatus = scripts_echoLog({
  9409. text: i18n('getTasksInfo')
  9410. });
  9411. if (action === 'undo') {
  9412. this.socialTasks = GM_getValue(`gleamTasks-${this.giveawayId}`)?.tasks || JSON.parse(Gleam_defaultTasks);
  9413. }
  9414. const tasks = $('.entry-content .entry-method');
  9415. for (const task of tasks) {
  9416. const $task = $(task);
  9417. if (action === 'do' && $task.find('i.fa-question').length === 0) {
  9418. continue;
  9419. }
  9420. const socialIcon = $task.find('.icon-wrapper i');
  9421. const taskInfo = $task.find('.user-links');
  9422. const taskText = taskInfo.text().trim();
  9423. const expandInfo = $task.find('.expandable');
  9424. const aElements = expandInfo.find('a.btn');
  9425. if (aElements.length > 0) {
  9426. for (const element of aElements) {
  9427. const $element = $(element);
  9428. const href = $element.attr('href');
  9429. $element.removeAttr('href')[0].click();
  9430. $element.attr('href', href);
  9431. }
  9432. }
  9433. if (socialIcon.hasClass('fa-twitter')) {
  9434. const link = $task.find('a[href^="https://twitter.com/"],a[href^="https://x.com/"]').attr('href');
  9435. if (!link) {
  9436. continue;
  9437. }
  9438. if (/follow/gi.test(taskText)) {
  9439. if (action === 'undo') {
  9440. this.socialTasks.twitter.userLinks.push(link);
  9441. }
  9442. if (action === 'do') {
  9443. this.undoneTasks.twitter.userLinks.push(link);
  9444. }
  9445. } else if (/retweet/gim.test(taskText)) {
  9446. if (action === 'undo') {
  9447. this.socialTasks.twitter.retweetLinks.push(link);
  9448. }
  9449. if (action === 'do') {
  9450. this.undoneTasks.twitter.retweetLinks.push(link);
  9451. }
  9452. }
  9453. } else if (socialIcon.hasClass('fa-twitch')) {
  9454. if (/follow/gim.test(taskText)) {
  9455. const link = $task.find('a[href^="https://twitch.tv/"]').attr('href');
  9456. if (!link) {
  9457. continue;
  9458. }
  9459. if (action === 'undo') {
  9460. this.socialTasks.twitch.channelLinks.push(link);
  9461. }
  9462. if (action === 'do') {
  9463. this.undoneTasks.twitch.channelLinks.push(link);
  9464. }
  9465. }
  9466. } else if (socialIcon.hasClass('fa-discord')) {
  9467. if (/join/gim.test(taskText)) {
  9468. let link = $task.find('a[href^="https://discord.com/invite/"]').attr('href');
  9469. if (!link) {
  9470. const ggLink = $task.find('a[href^="https://discord.gg/"]').attr('href')?.match(/discord\.gg\/([^/]+)/)?.[1];
  9471. if (!ggLink) {
  9472. continue;
  9473. }
  9474. link = `https://discord.com/invite/${ggLink}`;
  9475. }
  9476. if (action === 'undo') {
  9477. this.socialTasks.discord.serverLinks.push(link);
  9478. }
  9479. if (action === 'do') {
  9480. this.undoneTasks.discord.serverLinks.push(link);
  9481. }
  9482. }
  9483. } else if (socialIcon.hasClass('fa-external-link-square-alt')) {
  9484. continue;
  9485. } else if (socialIcon.hasClass('fa-youtube')) {
  9486. if (/subscribe/gim.test(taskText)) {
  9487. const link = $task.find('a[href^="https://www.youtube.com/channel/"]').attr('href');
  9488. if (!link) {
  9489. continue;
  9490. }
  9491. if (action === 'undo') {
  9492. this.socialTasks.youtube.channelLinks.push(link);
  9493. }
  9494. if (action === 'do') {
  9495. this.undoneTasks.youtube.channelLinks.push(link);
  9496. }
  9497. }
  9498. } else if (socialIcon.attr('class')?.includes('steam')) {
  9499. if (/join.*group/gi.test(taskText)) {
  9500. const link = $task.find('a[href^="https://steamcommunity.com/groups/"]').attr('href');
  9501. if (!link) {
  9502. continue;
  9503. }
  9504. if (action === 'undo') {
  9505. this.socialTasks.steam.groupLinks.push(link);
  9506. }
  9507. if (action === 'do') {
  9508. this.undoneTasks.steam.groupLinks.push(link);
  9509. }
  9510. } else if (/follow.*curator/gi.test(taskText)) {
  9511. const link = $task.find('a[href^="https://store.steampowered.com/curator/"]').attr('href');
  9512. if (!link) {
  9513. continue;
  9514. }
  9515. if (action === 'undo') {
  9516. this.socialTasks.steam.curatorLinks.push(link);
  9517. }
  9518. if (action === 'do') {
  9519. this.undoneTasks.steam.curatorLinks.push(link);
  9520. }
  9521. }
  9522. } else if (socialIcon.hasClass('fa-shield') && taskText.includes('vloot.io') || socialIcon.hasClass('fa-tiktok')) {
  9523. const continueBtn = expandInfo.find('span:contains(Continue),button:contains(Continue)');
  9524. for (const button of continueBtn) {
  9525. button.click();
  9526. await delay(500);
  9527. expandInfo.find('input').val(this.options.vlootUsername);
  9528. }
  9529. } else if (socialIcon.hasClass('fa-gamepad-alt') && taskText.includes('Gameround')) {
  9530. const continueBtn = expandInfo.find('span:contains(Continue),button:contains(Continue)');
  9531. for (const button of continueBtn) {
  9532. button.click();
  9533. await delay(500);
  9534. expandInfo.find('input').val(this.options.gameroundUsername);
  9535. }
  9536. } else if (socialIcon.hasClass('fa-bullhorn') && /Complete/gi.test(taskText)) {
  9537. if (action !== 'do') {
  9538. continue;
  9539. }
  9540. const gleamLink = await this.#getGleamLink(taskText);
  9541. if (!gleamLink) {
  9542. continue;
  9543. }
  9544. this.undoneTasks.extra.gleam.push(gleamLink);
  9545. } else if (socialIcon.hasClass('fa-question') || socialIcon.hasClass('fa-reddit') || socialIcon.hasClass('fa-instagram') || socialIcon.hasClass('fa-facebook-f') || socialIcon.hasClass('fa-telegram-plane') || socialIcon.hasClass('fa-telegram') || socialIcon.hasClass('fa-vk') || socialIcon.hasClass('fa-envelope') || socialIcon.hasClass('fa-gift') || socialIcon.hasClass('fa-square-up-right') || socialIcon.hasClass('fa-gamepad-modern') || socialIcon.hasClass('fa-shield') && taskText.includes('one of our giveaways') || socialIcon.hasClass('fa-shield') && taskText.includes('Check out')) {} else {
  9546. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskText}`);
  9547. }
  9548. }
  9549. logStatus.success();
  9550. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9551. this.socialTasks = this.uniqueTasks(this.socialTasks);
  9552. if (window.DEBUG) {
  9553. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9554. }
  9555. GM_setValue(`gleamTasks-${this.giveawayId}`, {
  9556. tasks: this.socialTasks,
  9557. time: new Date().getTime()
  9558. });
  9559. return true;
  9560. } catch (error) {
  9561. throwError(error, 'Gleam.classifyTask');
  9562. return false;
  9563. }
  9564. }
  9565. async extraDoTask({
  9566. gleam
  9567. }) {
  9568. try {
  9569. const pro = [];
  9570. for (const link of gleam) {
  9571. pro.push(this.#doGleamTask(link));
  9572. }
  9573. return Promise.all(pro).then(() => true);
  9574. } catch (error) {
  9575. throwError(error, 'Gleam.extraDoTask');
  9576. return false;
  9577. }
  9578. }
  9579. async verifyTask() {
  9580. try {
  9581. scripts_echoLog({
  9582. text: `${i18n('verifyingTask')}...`
  9583. });
  9584. const tasks = $('.entry-content .entry-method');
  9585. unsafeWindow._OxA = '_OxA';
  9586. for (const task of tasks) {
  9587. if ($('[campaign-key="campaign.key"]').length > 0) {
  9588. return scripts_echoLog({
  9589. text: i18n('campaign')
  9590. });
  9591. }
  9592. const $task = $(task);
  9593. if ($task.find('i.fa-question').length === 0) {
  9594. continue;
  9595. }
  9596. const taskInfo = $task.find('.user-links');
  9597. taskInfo[0].click();
  9598. unsafeWindow.$hookTimer?.setSpeed(1e3);
  9599. await delay(3e3);
  9600. unsafeWindow.$hookTimer?.setSpeed(1);
  9601. await this.#checkSync();
  9602. const continueBtn = $task.find('.expandable').find('span:contains(Continue),button:contains(Continue)');
  9603. for (const button of continueBtn) {
  9604. button.click();
  9605. await delay(500);
  9606. await this.#checkSync();
  9607. }
  9608. }
  9609. scripts_echoLog({
  9610. text: i18n('verifiedGleamTasks')
  9611. });
  9612. } catch (error) {
  9613. throwError(error, 'Gleam.verifyTask');
  9614. return false;
  9615. }
  9616. }
  9617. async #checkSync() {
  9618. try {
  9619. return await new Promise(resolve => {
  9620. const checker = setInterval(() => {
  9621. if ($('.entry-content .entry-method i.fa-sync').length === 0) {
  9622. clearInterval(checker);
  9623. resolve(true);
  9624. }
  9625. }, 500);
  9626. });
  9627. } catch (error) {
  9628. throwError(error, 'Gleam.checkSync');
  9629. return false;
  9630. }
  9631. }
  9632. async #doGleamTask(link) {
  9633. try {
  9634. const logStatus = scripts_echoLog({
  9635. text: i18n('doingGleamTask')
  9636. });
  9637. return await new Promise(resolve => {
  9638. GM_openInTab(`${link}?8b07d23f4bfa65f9`, {
  9639. active: true,
  9640. insert: true,
  9641. setParent: true
  9642. }).onclose = () => {
  9643. logStatus.success();
  9644. resolve(true);
  9645. };
  9646. });
  9647. } catch (error) {
  9648. throwError(error, 'Gleam.doGleamTask');
  9649. return false;
  9650. }
  9651. }
  9652. #getGiveawayId() {
  9653. try {
  9654. const giveawayId = window.location.pathname;
  9655. if (giveawayId) {
  9656. this.giveawayId = giveawayId;
  9657. return true;
  9658. }
  9659. scripts_echoLog({
  9660. text: i18n('getFailed', 'GiveawayId')
  9661. });
  9662. return false;
  9663. } catch (error) {
  9664. throwError(error, 'Gleam.getGiveawayId');
  9665. return false;
  9666. }
  9667. }
  9668. async #getGleamLink(title) {
  9669. try {
  9670. const logStatus = scripts_echoLog({
  9671. text: i18n('gettingGleamLink')
  9672. });
  9673. const {
  9674. result,
  9675. statusText,
  9676. status,
  9677. data
  9678. } = await tools_httpRequest({
  9679. url: 'https://www.vloot.io/api/v1/giveaways',
  9680. method: 'GET',
  9681. responseType: 'json'
  9682. });
  9683. if (result === 'Success') {
  9684. if (data?.status === 200 && data?.response?.Success === true && data?.response?.Data) {
  9685. const {
  9686. link
  9687. } = data.response.Data.find(giveaway => title.replace(/[\s]/g, '').toLowerCase().includes(giveaway.title.replace(/[\s]/g, '').toLowerCase())) || {};
  9688. if (link) {
  9689. logStatus.success();
  9690. return link;
  9691. }
  9692. logStatus.error(`Error:${i18n('getLinkFailed')}`);
  9693. return false;
  9694. }
  9695. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9696. return false;
  9697. }
  9698. logStatus.error(`${result}:${statusText}(${status})`);
  9699. return false;
  9700. } catch (error) {
  9701. throwError(error, 'Gleam.getGleamLink');
  9702. return false;
  9703. }
  9704. }
  9705. async #checkLeftKey() {
  9706. try {
  9707. if (!globalOptions.other.checkLeftKey) {
  9708. return true;
  9709. }
  9710. const campaignString = $('div.popup-blocks-container').attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  9711. if (!campaignString) {
  9712. return false;
  9713. }
  9714. const {
  9715. campaign,
  9716. incentive
  9717. } = JSON.parse(campaignString);
  9718. const controllerString = $('div.campaign.reward').attr('ng-init')?.match(/initContestant\(([\w\W]+?)\);/)?.[1];
  9719. let ownedKey = false;
  9720. if (controllerString) {
  9721. if (JSON.parse(controllerString).contestant?.claims?.incentives?.[incentive.id]?.length) {
  9722. ownedKey = true;
  9723. }
  9724. }
  9725. if (campaign.banned || campaign.finished && !ownedKey || campaign.paused || new Date().getTime() < campaign.starts_at * 1e3) {
  9726. await external_Swal_default().fire({
  9727. icon: 'warning',
  9728. title: i18n('notice'),
  9729. text: i18n('giveawayNotWork'),
  9730. confirmButtonText: i18n('confirm'),
  9731. cancelButtonText: i18n('cancel'),
  9732. showCancelButton: true
  9733. }).then(({
  9734. value
  9735. }) => {
  9736. if (value) {
  9737. window.close();
  9738. }
  9739. });
  9740. }
  9741. return true;
  9742. } catch (error) {
  9743. throwError(error, 'Gleam.checkLeftKey');
  9744. return false;
  9745. }
  9746. }
  9747. }
  9748. const website_Gleam = Gleam;
  9749. const SweepWidget_defaultOptions = {
  9750. username: '',
  9751. email: ''
  9752. };
  9753. class SweepWidget extends website_Website {
  9754. name = 'SweepWidget';
  9755. options = {
  9756. ...SweepWidget_defaultOptions,
  9757. ...GM_getValue('SweepWidgetOptions')
  9758. };
  9759. buttons = [ 'doTask' ];
  9760. static test() {
  9761. return /^https?:\/\/sweepwidget\.com\/view\/[\d]+/.test(window.location.href);
  9762. }
  9763. async after() {
  9764. try {
  9765. if (!this.#checkLogin()) {
  9766. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9767. }
  9768. } catch (error) {
  9769. throwError(error, 'SweepWidget.after');
  9770. }
  9771. }
  9772. init() {
  9773. try {
  9774. const logStatus = scripts_echoLog({
  9775. text: i18n('initing')
  9776. });
  9777. if (!this.#checkLogin()) {
  9778. logStatus.warning(i18n('needLogin'));
  9779. return false;
  9780. }
  9781. if (!this.#getGiveawayId()) {
  9782. return false;
  9783. }
  9784. this.initialized = true;
  9785. logStatus.success();
  9786. return true;
  9787. } catch (error) {
  9788. throwError(error, 'SweepWidget.init');
  9789. return false;
  9790. }
  9791. }
  9792. classifyTask() {
  9793. return true;
  9794. }
  9795. async doTask() {
  9796. try {
  9797. if ($('#unlock_rewards_main_wrapper').length === 0) {
  9798. if ($('input[name="sw__login_name"]:visible').length > 0) {
  9799. $('input[name="sw__login_name"]').val(this.options.username);
  9800. }
  9801. if ($('input[name="sw__login_email"]:visible').length > 0) {
  9802. $('input[name="sw__login_email"]').val(this.options.email);
  9803. }
  9804. if ($('#sw_login_button:visible').length > 0) {
  9805. $('#sw_login_button')[0].click();
  9806. }
  9807. if (!await this.#checkEnter()) {
  9808. return false;
  9809. }
  9810. }
  9811. const logStatus = scripts_echoLog({
  9812. text: i18n('SweepWidgetNotice')
  9813. });
  9814. const tasks = $('#sw_inner_entry_methods_l2_wrapper>div.sw_entry');
  9815. for (const task of tasks) {
  9816. const $task = $(task);
  9817. if ($task.find('i.fa-check:visible').length > 0) {
  9818. continue;
  9819. }
  9820. const title = $task.find('.sw_text_inner');
  9821. title[0].click();
  9822. const aElement = $task.find('a.sw_link');
  9823. const link = aElement.attr('href');
  9824. aElement.attr('href', '#a').attr('target', '_self');
  9825. aElement[0]?.click();
  9826. await delay(300);
  9827. aElement.attr('href', link).attr('target', '_blank');
  9828. $task.find('input[type="text"]').val('test');
  9829. const verifyBtn = $task.find('input.sw_verify');
  9830. if (verifyBtn.prop('disabled') === true) {
  9831. title[0].click();
  9832. await delay(300);
  9833. title[0].click();
  9834. await delay(300);
  9835. }
  9836. $task.find('input.sw_verify').removeAttr('disabled')[0]?.click();
  9837. await this.#checkFinish($task);
  9838. await delay(parseInt(`${Math.random() * (3e3 - 1e3 + 1) + 1e3}`, 10));
  9839. }
  9840. logStatus.success();
  9841. return true;
  9842. } catch (error) {
  9843. throwError(error, 'SweepWidget.doTask');
  9844. return false;
  9845. }
  9846. }
  9847. #checkLogin() {
  9848. try {
  9849. if ($('#twitter_login_button').length > 0) {
  9850. $('#twitter_login_button')[0].click();
  9851. }
  9852. return true;
  9853. } catch (error) {
  9854. throwError(error, 'SweepWidget.checkLogin');
  9855. return false;
  9856. }
  9857. }
  9858. #getGiveawayId() {
  9859. try {
  9860. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  9861. if (giveawayId) {
  9862. this.giveawayId = giveawayId;
  9863. return true;
  9864. }
  9865. scripts_echoLog({
  9866. text: i18n('getFailed', 'GiveawayId')
  9867. });
  9868. return false;
  9869. } catch (error) {
  9870. throwError(error, 'SweepWidget.getGiveawayId');
  9871. return false;
  9872. }
  9873. }
  9874. async #checkEnter() {
  9875. try {
  9876. return new Promise(resolve => {
  9877. const checker = setInterval(() => {
  9878. if ($('#unlock_rewards_main_wrapper').length > 0) {
  9879. clearInterval(checker);
  9880. resolve(true);
  9881. }
  9882. });
  9883. });
  9884. } catch (error) {
  9885. throwError(error, 'SweepWidget.checkEnter');
  9886. return false;
  9887. }
  9888. }
  9889. async #checkFinish($task) {
  9890. try {
  9891. return new Promise(resolve => {
  9892. const checker = setInterval(() => {
  9893. if ($task.find('i.fa-check:visible').length > 0 || $task.find('.sw_entry_input:visible').length === 0) {
  9894. clearInterval(checker);
  9895. resolve(true);
  9896. }
  9897. });
  9898. });
  9899. } catch (error) {
  9900. throwError(error, 'SweepWidget.checkFinish');
  9901. return false;
  9902. }
  9903. }
  9904. }
  9905. const website_SweepWidget = SweepWidget;
  9906. const defaultWhiteList = {
  9907. discord: {
  9908. servers: []
  9909. },
  9910. instagram: {
  9911. users: []
  9912. },
  9913. twitch: {
  9914. channels: []
  9915. },
  9916. twitter: {
  9917. users: [],
  9918. retweets: [],
  9919. likes: []
  9920. },
  9921. vk: {
  9922. names: []
  9923. },
  9924. youtube: {
  9925. channels: [],
  9926. likes: []
  9927. },
  9928. reddit: {
  9929. reddits: []
  9930. },
  9931. steam: {
  9932. groups: [],
  9933. officialGroups: [],
  9934. wishlists: [],
  9935. follows: [],
  9936. forums: [],
  9937. workshops: [],
  9938. curators: [],
  9939. workshopVotes: [],
  9940. curatorLikes: [],
  9941. announcements: [],
  9942. licenses: [],
  9943. playtests: []
  9944. }
  9945. };
  9946. const link2id = async function(type) {
  9947. try {
  9948. const link = $('#socialLink').val();
  9949. let id = '';
  9950. switch (type) {
  9951. case 'discord.servers':
  9952. id = link.match(/invite\/(.+)/)?.[1] || '';
  9953. break;
  9954.  
  9955. case 'instagram.users':
  9956. id = link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1] || '';
  9957. break;
  9958.  
  9959. case 'twitch.channels':
  9960. id = link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2] || '';
  9961. break;
  9962.  
  9963. case 'twitter.users':
  9964. id = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || '';
  9965. break;
  9966.  
  9967. case 'twitter.retweets':
  9968. id = link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1] || '';
  9969. break;
  9970.  
  9971. case 'vk.names':
  9972. id = link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1] || '';
  9973. break;
  9974.  
  9975. case 'youtube.channels':
  9976. id = (await getInfo(link, 'channel'))?.params?.channelId || '';
  9977. break;
  9978.  
  9979. case 'youtube.likes':
  9980. id = (await getInfo(link, 'likeVideo'))?.params?.videoId || '';
  9981. break;
  9982.  
  9983. case 'reddit.reddits':
  9984. id = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1] || link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1] || '';
  9985. break;
  9986.  
  9987. case 'steam.groups':
  9988. id = link.match(/groups\/(.+)\/?/)?.[1] || '';
  9989. break;
  9990.  
  9991. case 'steam.wishlists':
  9992. case 'steam.follows':
  9993. case 'steam.forums':
  9994. id = link.match(/app\/([\d]+)/)?.[1] || '';
  9995. break;
  9996.  
  9997. case 'steam.workshops':
  9998. id = link.match(/\?id=([\d]+)/)?.[1] || '';
  9999. break;
  10000.  
  10001. case 'steam.curators':
  10002. {
  10003. if (link.includes('curator')) {
  10004. id = link.match(/curator\/([\d]+)/)?.[1] || '';
  10005. } else {
  10006. const param = link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3);
  10007. if (!param || param.length !== 2) {
  10008. break;
  10009. }
  10010. const steam = new social_Steam();
  10011. if (await steam.init()) {
  10012. id = await steam.getCuratorId(param[0], param[1]) || '';
  10013. }
  10014. }
  10015. }
  10016. break;
  10017. }
  10018. return id;
  10019. } catch (error) {
  10020. throwError(error, 'link2id');
  10021. return i18n('getFailed', 'id');
  10022. }
  10023. };
  10024. const disabledType = {
  10025. steam: [ 'workshopVotes', 'curatorLikes', 'announcements' ],
  10026. twitter: [ 'likes' ]
  10027. };
  10028. const assignWhiteList = whiteList => {
  10029. try {
  10030. const newWhiteList = {};
  10031. for (const [ key, value ] of Object.entries(defaultWhiteList)) {
  10032. newWhiteList[key] = {
  10033. ...value,
  10034. ...whiteList[key]
  10035. };
  10036. }
  10037. return newWhiteList;
  10038. } catch (error) {
  10039. throwError(error, 'assignWhiteList');
  10040. return defaultWhiteList;
  10041. }
  10042. };
  10043. const whiteListOptions = function(showType) {
  10044. try {
  10045. const whiteList = assignWhiteList(GM_getValue('whiteList') || {});
  10046. let whiteListOptionsForm = `<form id="whiteListForm" class="auto-task-form">
  10047. <table class="auto-task-table"><thead><tr><td>${i18n('website')}</td><td>${i18n('type')}</td><td>${i18n('edit')}</td></tr></thead><tbody>`;
  10048. for (const [ social, types ] of Object.entries(whiteList)) {
  10049. whiteListOptionsForm += Object.keys(types).map((type, index) => disabledType[social]?.includes(type) ? '' : `<tr style="background-color: ${stringToColour(social)}66">${index === 0 ? `<th rowspan="${Object.keys(types).length - (disabledType[social] || []).length}" style="background-color: ${stringToColour(social)}66">${social}</th>` : ''}<td>${i18n(type)}</td><td><button type="button" class="editWhiteList" data-value="${social}.${type}">${i18n('edit')}</button></td></tr>`).join('');
  10050. }
  10051. whiteListOptionsForm += '</tbody></table></form>';
  10052. if (showType === 'swal') {
  10053. external_Swal_default().fire({
  10054. title: i18n('whiteListOptions'),
  10055. html: whiteListOptionsForm,
  10056. showConfirmButton: false,
  10057. showCloseButton: true
  10058. });
  10059. } else {
  10060. $('body').append(`<h2>${i18n('whiteList')}</h2>${whiteListOptionsForm}`);
  10061. }
  10062. $('.editWhiteList').on('click', function() {
  10063. const value = $(this).attr('data-value');
  10064. if (!value) {
  10065. return;
  10066. }
  10067. const [ social, type ] = value.split('.');
  10068. if (!whiteList?.[social]?.[type]) {
  10069. scripts_echoLog({}).warning(i18n('whiteListNotFound', value));
  10070. return;
  10071. }
  10072. external_Swal_default().fire({
  10073. title: i18n('changeWhiteListOption', value),
  10074. input: 'textarea',
  10075. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10076. <button id="link2id" data-type="${value}" class="swal2-confirm swal2-styled">获取id</button>
  10077. <p style="margin-bottom:0 !important;">在下方填写白名单,每行一个</p>`,
  10078. inputValue: whiteList[social][type].join('\n'),
  10079. showConfirmButton: true,
  10080. confirmButtonText: i18n('save'),
  10081. showCancelButton: true,
  10082. cancelButtonText: i18n('close'),
  10083. showDenyButton: true,
  10084. denyButtonText: i18n('return')
  10085. }).then(({
  10086. isDenied,
  10087. isConfirmed,
  10088. value
  10089. }) => {
  10090. if (isDenied) {
  10091. if (showType === 'swal') {
  10092. whiteListOptions(showType);
  10093. }
  10094. return;
  10095. } else if (isConfirmed) {
  10096. whiteList[social][type] = value.split('\n');
  10097. GM_setValue('whiteList', whiteList);
  10098. external_Swal_default().fire({
  10099. title: i18n('changeWhiteListSuccess'),
  10100. icon: 'success'
  10101. });
  10102. }
  10103. });
  10104. $('#link2id').on('click', async function() {
  10105. const type = $(this).attr('data-type');
  10106. $('#socialLink').val(await link2id(type));
  10107. });
  10108. });
  10109. } catch (error) {
  10110. throwError(error, 'whiteListOptions');
  10111. }
  10112. };
  10113. const whiteList = whiteListOptions;
  10114. const setGistData = async (token, gistId, fileName, content) => {
  10115. try {
  10116. const logStatus = scripts_echoLog({
  10117. text: i18n('settingData')
  10118. });
  10119. const contentData = JSON.stringify({
  10120. files: {
  10121. [fileName]: {
  10122. content: JSON.stringify(content)
  10123. }
  10124. }
  10125. });
  10126. const {
  10127. result,
  10128. statusText,
  10129. status,
  10130. data
  10131. } = await tools_httpRequest({
  10132. url: `https://api.github.com/gists/${gistId}`,
  10133. headers: {
  10134. Accept: 'application/vnd.github.v3+json',
  10135. Authorization: `token ${token}`
  10136. },
  10137. data: contentData,
  10138. responseType: 'json',
  10139. method: 'POST',
  10140. timeout: 3e4
  10141. });
  10142. if (result === 'Success') {
  10143. if (data?.status === 200 && data.response.files?.[fileName]?.content === JSON.stringify(content)) {
  10144. logStatus.success();
  10145. return true;
  10146. }
  10147. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10148. return false;
  10149. }
  10150. logStatus.error(`${result}:${statusText}(${status})`);
  10151. return false;
  10152. } catch (error) {
  10153. throwError(error, 'setGistData');
  10154. return false;
  10155. }
  10156. };
  10157. const getGistData = async (token, gistId, fileName, test = false) => {
  10158. try {
  10159. const logStatus = scripts_echoLog({
  10160. text: i18n('gettingData')
  10161. });
  10162. const {
  10163. result,
  10164. statusText,
  10165. status,
  10166. data
  10167. } = await tools_httpRequest({
  10168. url: `https://api.github.com/gists/${gistId}`,
  10169. headers: {
  10170. Accept: 'application/vnd.github.v3+json',
  10171. Authorization: `token ${token}`
  10172. },
  10173. responseType: 'json',
  10174. method: 'GET',
  10175. timeout: 3e4
  10176. });
  10177. if (result === 'Success') {
  10178. if (data?.status === 200) {
  10179. const content = data.response?.files?.[fileName]?.content;
  10180. let formatedContent;
  10181. if (!content) {
  10182. logStatus.error(`Error:${i18n('noRemoteData')}`);
  10183. return false;
  10184. }
  10185. if (test) {
  10186. logStatus.success();
  10187. return true;
  10188. }
  10189. try {
  10190. formatedContent = JSON.parse(content);
  10191. } catch (error) {
  10192. logStatus.error(`Error:${i18n('errorRemoteDataFormat')}`);
  10193. return false;
  10194. }
  10195. logStatus.success();
  10196. return formatedContent;
  10197. }
  10198. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10199. return false;
  10200. }
  10201. logStatus.error(`${result}:${statusText}(${status})`);
  10202. return false;
  10203. } catch (error) {
  10204. throwError(error, 'getGistData');
  10205. return false;
  10206. }
  10207. };
  10208. const syncOptions = () => {
  10209. try {
  10210. const {
  10211. TOKEN,
  10212. GIST_ID,
  10213. FILE_NAME,
  10214. SYNC_HISTORY
  10215. } = GM_getValue('gistOptions') || {
  10216. TOKEN: '',
  10217. GIST_ID: '',
  10218. FILE_NAME: '',
  10219. SYNC_HISTORY: true
  10220. };
  10221. external_Swal_default().fire({
  10222. title: i18n('gistOptions'),
  10223. html: `<p>Github Token<input id="github-token" class="swal2-input" placeholder="Github Token" value="${TOKEN}"></p>` + `<p>Gist ID<input id="gist-id" class="swal2-input" placeholder="Gist ID" value="${GIST_ID}"></p>` + `<p>${i18n('fileName')}<input id="file-name" class="swal2-input" placeholder="${i18n('fileName')}" value="${FILE_NAME}"></p>` + '<p><label for="sync-history" class="swal2-checkbox-custom" style="display: flex;">' + `<input id="sync-history" type="checkbox"${SYNC_HISTORY ? ' checked="checked"' : ''}/>` + `<span class="swal2-label">${i18n('syncHistory')}</span></label></p>` + `<p><button id="upload-data" type="button" class="swal2-confirm swal2-styled" style="display: inline-block;">
  10224. ${i18n('upload2gist')}</button>` + `<button id="download-data" type="button" class="swal2-confirm swal2-styled" style="display: inline-block;">
  10225. ${i18n('downloadFromGist')}</button></p>`,
  10226. focusConfirm: false,
  10227. showLoaderOnConfirm: true,
  10228. footer: `<a href="https://auto-task-doc.js.org/guide/#%E6%95%B0%E6%8D%AE%E5%90%8C%E6%AD%A5" target="_blank">${i18n('help')}</a>`,
  10229. preConfirm: async () => {
  10230. const token = $('#github-token').val();
  10231. const gistId = $('#gist-id').val();
  10232. const fileName = $('#file-name').val();
  10233. const syncHistory = $('#sync-history').prop('checked');
  10234. GM_setValue('gistOptions', {
  10235. TOKEN: token,
  10236. GIST_ID: gistId,
  10237. FILE_NAME: fileName,
  10238. SYNC_HISTORY: syncHistory
  10239. });
  10240. return await getGistData(token, gistId, fileName, true);
  10241. },
  10242. allowOutsideClick: () => !external_Swal_default().isLoading(),
  10243. confirmButtonText: i18n('saveAndTest'),
  10244. showCancelButton: true,
  10245. cancelButtonText: i18n('close')
  10246. }).then(({
  10247. value
  10248. }) => {
  10249. if (value) {
  10250. external_Swal_default().fire({
  10251. icon: 'success',
  10252. title: i18n('testSuccess')
  10253. }).then(syncOptions);
  10254. } else if (value !== undefined) {
  10255. external_Swal_default().fire({
  10256. icon: 'error',
  10257. title: i18n('testFailed')
  10258. }).then(syncOptions);
  10259. }
  10260. });
  10261. $('#upload-data').on('click', async () => {
  10262. const {
  10263. TOKEN,
  10264. GIST_ID,
  10265. FILE_NAME
  10266. } = GM_getValue('gistOptions') || {};
  10267. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10268. return external_Swal_default().fire({
  10269. icon: 'error',
  10270. title: i18n('saveAndTestNotice')
  10271. }).then(syncOptions);
  10272. }
  10273. external_Swal_default().fire({
  10274. icon: 'info',
  10275. title: i18n('processingData')
  10276. });
  10277. const data = {};
  10278. const names = GM_listValues();
  10279. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10280. for (const name of names) {
  10281. if (name === 'gistOptions' || /^[\w]+?Auth$/.test(name)) {
  10282. continue;
  10283. }
  10284. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10285. continue;
  10286. }
  10287. data[name] = GM_getValue(name);
  10288. }
  10289. external_Swal_default().update({
  10290. icon: 'info',
  10291. title: i18n('updatingData')
  10292. });
  10293. if (await setGistData(TOKEN, GIST_ID, FILE_NAME, data)) {
  10294. external_Swal_default().fire({
  10295. icon: 'success',
  10296. title: i18n('syncDataSuccess')
  10297. });
  10298. } else {
  10299. external_Swal_default().fire({
  10300. icon: 'error',
  10301. title: i18n('syncDataFailed')
  10302. });
  10303. }
  10304. });
  10305. $('#download-data').on('click', async () => {
  10306. const {
  10307. TOKEN,
  10308. GIST_ID,
  10309. FILE_NAME
  10310. } = GM_getValue('gistOptions') || {};
  10311. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10312. return external_Swal_default().fire({
  10313. icon: 'error',
  10314. title: i18n('saveAndTestNotice')
  10315. }).then(syncOptions);
  10316. }
  10317. external_Swal_default().fire({
  10318. icon: 'info',
  10319. title: i18n('downloadingData')
  10320. });
  10321. const data = await getGistData(TOKEN, GIST_ID, FILE_NAME);
  10322. if (!data) {
  10323. return external_Swal_default().fire({
  10324. icon: 'error',
  10325. title: i18n('checkedNoData')
  10326. }).then(syncOptions);
  10327. }
  10328. external_Swal_default().update({
  10329. icon: 'info',
  10330. title: i18n('savingData')
  10331. });
  10332. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10333. for (const [ name, value ] of Object.entries(data)) {
  10334. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10335. continue;
  10336. }
  10337. GM_setValue(name, value);
  10338. }
  10339. external_Swal_default().fire({
  10340. icon: 'success',
  10341. title: i18n('syncDataSuccess')
  10342. });
  10343. });
  10344. } catch (error) {
  10345. throwError(error, 'syncOptions');
  10346. }
  10347. };
  10348. const dataSync = syncOptions;
  10349. class Setting {
  10350. name = 'Setting';
  10351. buttons = [ 'saveGlobalOptions', 'syncData', 'tasksHistory' ];
  10352. syncData = dataSync;
  10353. tasksHistory() {
  10354. window.open('https://auto-task-v4.hclonely.com/history.html', '_blank');
  10355. }
  10356. static test() {
  10357. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/setting.html';
  10358. }
  10359. before() {
  10360. $('body').html('').addClass('auto-task-options');
  10361. }
  10362. after() {
  10363. try {
  10364. this.#environment();
  10365. changeGlobalOptions('page');
  10366. whiteList('page');
  10367. $('input[name="other.twitterVerifyId"]').after(`<button id="getTwitterUserId" type="button">${i18n('getTwitterUserId')}</button>`);
  10368. $('#getTwitterUserId').on('click', () => {
  10369. this.#getId('twitterUser');
  10370. });
  10371. $('input[name="other.youtubeVerifyChannel"]').after(`<button id="getYoutubeChannelId" type="button">${i18n('getYoutubeChannelId')}</button>`);
  10372. $('#getYoutubeChannelId').on('click', () => {
  10373. this.#getId('youtubeChannel');
  10374. });
  10375. $('input[name^="position"]').on('input', function() {
  10376. const type = $(this).attr('name').replace('position.', '');
  10377. const xLabel = 'rightleft';
  10378. const yLabel = 'topbottpm';
  10379. switch (type) {
  10380. case 'buttonSideX':
  10381. case 'buttonSideY':
  10382. case 'buttonDistance':
  10383. {
  10384. const distance = $('input[name="position.buttonDistance"]').val();
  10385. const sideX = $('input[name="position.buttonSideX"]').val();
  10386. const sideY = $('input[name="position.buttonSideY"]').val();
  10387. if (![ 'right', 'left' ].includes(sideX)) {
  10388. break;
  10389. }
  10390. if (![ 'top', 'bottom' ].includes(sideY)) {
  10391. break;
  10392. }
  10393. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10394. break;
  10395. }
  10396. const distanceArr = distance.split(',');
  10397. $('#auto-task-buttons').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10398. break;
  10399. }
  10400.  
  10401. case 'showButtonSideX':
  10402. case 'showButtonSideY':
  10403. case 'showButtonDistance':
  10404. {
  10405. const distance = $('input[name="position.showButtonDistance"]').val();
  10406. const sideX = $('input[name="position.showButtonSideX"]').val();
  10407. const sideY = $('input[name="position.showButtonSideY"]').val();
  10408. if (![ 'right', 'left' ].includes(sideX)) {
  10409. break;
  10410. }
  10411. if (![ 'top', 'bottom' ].includes(sideY)) {
  10412. break;
  10413. }
  10414. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10415. break;
  10416. }
  10417. const distanceArr = distance.split(',');
  10418. $('div.show-button-div').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10419. break;
  10420. }
  10421.  
  10422. case 'logSideX':
  10423. case 'logSideY':
  10424. case 'logDistance':
  10425. {
  10426. const distance = $('input[name="position.logDistance"]').val();
  10427. const sideX = $('input[name="position.logSideX"]').val();
  10428. const sideY = $('input[name="position.logSideY"]').val();
  10429. if (![ 'right', 'left' ].includes(sideX)) {
  10430. break;
  10431. }
  10432. if (![ 'top', 'bottom' ].includes(sideY)) {
  10433. break;
  10434. }
  10435. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10436. break;
  10437. }
  10438. const distanceArr = distance.split(',');
  10439. $('#auto-task-info').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10440. break;
  10441. }
  10442.  
  10443. default:
  10444. break;
  10445. }
  10446. });
  10447. $('input[name^="hotKey"]').attr('readonly', 'readonly').off('keydown').on('keydown', function(event) {
  10448. let functionKey = '';
  10449. if (event.altKey) {
  10450. functionKey += 'alt + ';
  10451. } else if (event.ctrlKey) {
  10452. functionKey += 'ctrl + ';
  10453. } else if (event.shiftKey) {
  10454. functionKey += 'shift + ';
  10455. }
  10456. $(this).val(functionKey + (event.key.length === 1 ? event.key.toLowerCase() : ''));
  10457. });
  10458. } catch (error) {
  10459. throwError(error, 'Setting.after');
  10460. }
  10461. }
  10462. saveGlobalOptions() {
  10463. saveData();
  10464. }
  10465. #getId(social) {
  10466. try {
  10467. external_Swal_default().fire({
  10468. title: i18n('getId', i18n(social)),
  10469. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10470. <button id="link2id" data-type="${social}" class="swal2-confirm swal2-styled">获取id</button>`,
  10471. showCancelButton: true,
  10472. cancelButtonText: i18n('close'),
  10473. showConfirmButton: false
  10474. });
  10475. $('#link2id').on('click', async function() {
  10476. const link = $('#socialLink').val();
  10477. if (!link) {
  10478. return;
  10479. }
  10480. const type = $(this).attr('data-type');
  10481. if (type === 'twitterUser') {
  10482. const name = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || link;
  10483. $('#socialLink').val(await new social_Twitter().userName2id(name) || '');
  10484. } else if (type === 'youtubeChannel') {
  10485. const name = /^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www.youtube.com\/.*/.test(link) ? link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1] : link;
  10486. $('#socialLink').val((await getInfo(name, 'channel'))?.params?.channelId || '');
  10487. }
  10488. });
  10489. } catch (error) {
  10490. throwError(error, 'Setting.getId');
  10491. }
  10492. }
  10493. #environment() {
  10494. try {
  10495. const userAgent = (0, javascript_utils_umd_min.ua)();
  10496. const environmentForm = `<form id="environmentForm" class="auto-task-form">
  10497. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('name')}</td><td>${i18n('version')}</td></tr></thead><tbody>
  10498. <tr><td>${i18n('os')}</td><td>${userAgent.os}</td><td>${userAgent.osVersion}</td></tr>
  10499. <tr><td>${i18n('browser')}</td><td>${userAgent.browserZH}</td><td>${userAgent.browserVersion}</td></tr>
  10500. <tr><td>${i18n('scriptManager')}</td><td>${GM_info.scriptHandler}</td><td>${GM_info.version}</td></tr>
  10501. <tr><td>${i18n('script')}</td><td>${GM_info.script.name}</td><td>${GM_info.script.version}</td></tr>
  10502. </tbody></table></form>`;
  10503. $('body').append(`<h2>${i18n('environment')}</h2>${environmentForm}`);
  10504. } catch (error) {
  10505. throwError(error, 'Setting.environment');
  10506. }
  10507. }
  10508. }
  10509. const website_Setting = Setting;
  10510. class History extends website_Keylol {
  10511. name = 'History';
  10512. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect', 'clearHistory' ];
  10513. static test() {
  10514. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/history.html';
  10515. }
  10516. before() {
  10517. try {
  10518. $('body').html('<div class="container"></div>').addClass('auto-task-history');
  10519. const data = GM_listValues() || [];
  10520. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10521. for (const item of tasksHistory) {
  10522. this.#addItem(item);
  10523. }
  10524. } catch (error) {
  10525. throwError(error, 'History.before');
  10526. }
  10527. }
  10528. clearHistory() {
  10529. try {
  10530. const data = GM_listValues() || [];
  10531. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10532. for (const item of tasksHistory) {
  10533. GM_deleteValue(item);
  10534. }
  10535. external_Swal_default().fire({
  10536. title: i18n('clearHistoryFinished'),
  10537. icon: 'success'
  10538. });
  10539. } catch (error) {
  10540. throwError(error, 'History.after');
  10541. }
  10542. }
  10543. #addItem(item) {
  10544. try {
  10545. const tasksData = GM_getValue(item);
  10546. if (!tasksData?.tasks) {
  10547. return;
  10548. }
  10549. let html = '';
  10550. let title = '';
  10551. let link = '';
  10552. const [ website, id ] = item.split('-');
  10553. switch (website) {
  10554. case 'fawTasks':
  10555. title = `Freeanywhere[${id}]`;
  10556. link = `https://freeanywhere.net/#/giveaway/${id}`;
  10557. break;
  10558.  
  10559. case 'gasTasks':
  10560. title = `Giveawaysu[${id}]`;
  10561. link = `https://giveaway.su/giveaway/view/${id}`;
  10562. break;
  10563.  
  10564. case 'gcTasks':
  10565. title = `GiveeClub[${id}]`;
  10566. link = `https://givee.club/event/${id}`;
  10567. break;
  10568.  
  10569. case 'gkTasks':
  10570. title = `Givekey[${id}]`;
  10571. link = `https://givekey.ru/giveaway/${id}`;
  10572. break;
  10573.  
  10574. case 'gleamTasks':
  10575. title = `Gleam[${id}]`;
  10576. link = `https://gleam.io${id}`;
  10577. break;
  10578.  
  10579. case 'khTasks':
  10580. title = `keyhub[${id}]`;
  10581. link = `https://key-hub.eu/giveaway/${id}`;
  10582. break;
  10583.  
  10584. case 'prysTasks':
  10585. title = `Prys[${id}]`;
  10586. link = `https://prys.revadike.com/giveaway/?id=${id}`;
  10587. break;
  10588.  
  10589. default:
  10590. return;
  10591. }
  10592. for (const [ social, types ] of Object.entries(tasksData.tasks)) {
  10593. for (const [ type, tasks ] of Object.entries(types)) {
  10594. for (const task of tasks) {
  10595. html += `<li><font class="auto-task-capitalize">${social}.${i18n(type.replace('Link', ''))}: </font><a href="${task}" target="_blank">${task.length > 55 ? `${task.slice(0, 55)}...` : task}</a></li>`;
  10596. }
  10597. }
  10598. }
  10599. $('.container').append(`<div class="card" data-name="${item}"><div class="title"><a href="${link}" target="_blank">${title}</a><span class="delete-task" data-name="${item}" title="${i18n('deleteTask')}"><svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2734" width="32" height="32"><path d="M607.897867 768.043004c-17.717453 0-31.994625-14.277171-31.994625-31.994625L575.903242 383.935495c0-17.717453 14.277171-31.994625 31.994625-31.994625s31.994625 14.277171 31.994625 31.994625l0 351.94087C639.892491 753.593818 625.61532 768.043004 607.897867 768.043004z" p-id="2735" fill="#d81e06"></path><path d="M415.930119 768.043004c-17.717453 0-31.994625-14.277171-31.994625-31.994625L383.935495 383.935495c0-17.717453 14.277171-31.994625 31.994625-31.994625 17.717453 0 31.994625 14.277171 31.994625 31.994625l0 351.94087C447.924744 753.593818 433.647573 768.043004 415.930119 768.043004z" p-id="2736" fill="#d81e06"></path><path d="M928.016126 223.962372l-159.973123 0L768.043004 159.973123c0-52.980346-42.659499-95.983874-95.295817-95.983874L351.94087 63.989249c-52.980346 0-95.983874 43.003528-95.983874 95.983874l0 63.989249-159.973123 0c-17.717453 0-31.994625 14.277171-31.994625 31.994625s14.277171 31.994625 31.994625 31.994625l832.032253 0c17.717453 0 31.994625-14.277171 31.994625-31.994625S945.73358 223.962372 928.016126 223.962372zM319.946246 159.973123c0-17.545439 14.449185-31.994625 31.994625-31.994625l320.806316 0c17.545439 0 31.306568 14.105157 31.306568 31.994625l0 63.989249L319.946246 223.962372 319.946246 159.973123 319.946246 159.973123z" p-id="2737" fill="#d81e06"></path><path d="M736.048379 960.010751 288.123635 960.010751c-52.980346 0-95.983874-43.003528-95.983874-95.983874L192.139761 383.591466c0-17.717453 14.277171-31.994625 31.994625-31.994625s31.994625 14.277171 31.994625 31.994625l0 480.435411c0 17.717453 14.449185 31.994625 31.994625 31.994625l448.096758 0c17.717453 0 31.994625-14.277171 31.994625-31.994625L768.215018 384.795565c0-17.717453 14.277171-31.994625 31.994625-31.994625s31.994625 14.277171 31.994625 31.994625l0 479.231312C832.032253 916.835209 789.028725 960.010751 736.048379 960.010751z" p-id="2738" fill="#d81e06"></path></svg></span></div><ul>${html}</ul><span class="time">${i18n('lastChangeTime')}: ${external_dayjs_namespaceObject(tasksData.time).format('YYYY-MM-DD HH:mm:ss')}</span></div>`);
  10600. $('span.delete-task').on('click', function() {
  10601. const itemName = $(this).attr('data-name');
  10602. if (itemName) {
  10603. GM_deleteValue(itemName);
  10604. $(`div.card[data-name="${itemName}"]`).remove();
  10605. external_Swal_default().fire({
  10606. title: i18n('clearTaskFinished'),
  10607. text: itemName,
  10608. icon: 'success'
  10609. });
  10610. } else {
  10611. external_Swal_default().fire({
  10612. title: i18n('clearTaskFailed'),
  10613. icon: 'error'
  10614. });
  10615. }
  10616. });
  10617. } catch (error) {
  10618. throwError(error, 'History.addItem');
  10619. }
  10620. }
  10621. }
  10622. const website_History = History;
  10623. const Websites = [ Freeanywhere, GiveawaySu, website_Indiedb, website_Keyhub, website_Givekey, website_GiveeClub, website_OpiumPulses, website_Keylol, website_Opquests, website_Gleam, website_SweepWidget, website_Setting, website_History ];
  10624. const websiteOptions = function(website, options) {
  10625. try {
  10626. let websiteOptionsForm = `<form id="websiteOptionsForm" class="auto-task-form">
  10627. <table class="auto-task-table"><thead><tr><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  10628. for (const [ option, value ] of Object.entries(options)) {
  10629. websiteOptionsForm += `<tr><td>${option}</td><td><input class="editOption" type="text" name="${option}" value="${value}"/></td></tr>`;
  10630. }
  10631. websiteOptionsForm += '</tbody></table></form>';
  10632. external_Swal_default().fire({
  10633. title: i18n('websiteOptions'),
  10634. html: websiteOptionsForm,
  10635. showConfirmButton: true,
  10636. confirmButtonText: i18n('save'),
  10637. showCancelButton: true,
  10638. cancelButtonText: i18n('close')
  10639. }).then(({
  10640. isConfirmed
  10641. }) => {
  10642. if (isConfirmed) {
  10643. $('#websiteOptionsForm').serializeArray().map(value => {
  10644. options[value.name] = value.value;
  10645. return value;
  10646. });
  10647. GM_setValue(`${website}Options`, options);
  10648. external_Swal_default().fire({
  10649. title: i18n('changeWebsiteOptionsSuccess'),
  10650. icon: 'success'
  10651. });
  10652. }
  10653. });
  10654. } catch (error) {
  10655. throwError(error, 'websiteOptions');
  10656. }
  10657. };
  10658. const options = websiteOptions;
  10659. const external_keyboardJS_namespaceObject = keyboardJS;
  10660. var external_keyboardJS_default = __webpack_require__.n(external_keyboardJS_namespaceObject);
  10661. const checkUpdate = async (updateLink, auto) => {
  10662. try {
  10663. const checkUrl = `${updateLink}package.json?time=${new Date().getTime()}`;
  10664. const {
  10665. result,
  10666. statusText,
  10667. status,
  10668. data
  10669. } = await tools_httpRequest({
  10670. url: checkUrl,
  10671. responseType: 'json',
  10672. method: 'GET',
  10673. timeout: 3e4
  10674. });
  10675. if (result === 'Success') {
  10676. if (data?.response?.version) {
  10677. return data.response;
  10678. }
  10679. if (!auto) {
  10680. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${data?.statusText}(${data?.status})]`);
  10681. }
  10682. return false;
  10683. }
  10684. if (!auto) {
  10685. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${result}:${statusText}(${status})]`);
  10686. }
  10687. return false;
  10688. } catch (error) {
  10689. throwError(error, 'checkUpdate');
  10690. return false;
  10691. }
  10692. };
  10693. const hasNewVersion = (currentVersion, remoteVersion) => {
  10694. try {
  10695. const [ currentRealVersion ] = currentVersion.split('-');
  10696. const [ remoteRealVersion, isPreview ] = remoteVersion.split('-');
  10697. if (isPreview && !globalOptions.other.receivePreview) {
  10698. return false;
  10699. }
  10700. const [ currentVersion1, currentVersion2, currentVersion3 ] = currentRealVersion.split('.').map(value => parseInt(value, 10));
  10701. const [ remoteVersion1, remoteVersion2, remoteVersion3 ] = remoteRealVersion.split('.').map(value => parseInt(value, 10));
  10702. if (remoteVersion1 > currentVersion1) {
  10703. return true;
  10704. }
  10705. if (remoteVersion1 < currentVersion1) {
  10706. return false;
  10707. }
  10708. if (remoteVersion2 > currentVersion2) {
  10709. return true;
  10710. }
  10711. if (remoteVersion2 < currentVersion2) {
  10712. return false;
  10713. }
  10714. if (remoteVersion3 > currentVersion3) {
  10715. return true;
  10716. }
  10717. return false;
  10718. } catch (error) {
  10719. throwError(error, 'compareVersion');
  10720. return false;
  10721. }
  10722. };
  10723. const updateChecker = async () => {
  10724. try {
  10725. const currentVersion = GM_info.script.version;
  10726. const updateSource = globalOptions.other.autoUpdateSource.toLowerCase();
  10727. const updateLinks = {
  10728. github: 'https://github.com/HCLonely/auto-task-new/raw/main/',
  10729. jsdelivr: 'https://cdn.jsdelivr.net/gh/HCLonely/auto-task-v4@main/',
  10730. standby: 'https://auto-task-v4.hclonely.com/'
  10731. };
  10732. let version;
  10733. let updateLink = '';
  10734. let packageData;
  10735. if ([ 'github', 'jsdelivr', 'standby' ].includes(updateSource)) {
  10736. updateLink = updateLinks[updateSource];
  10737. packageData = await checkUpdate(updateLink, false);
  10738. } else {
  10739. updateLink = updateLinks.github;
  10740. packageData = await checkUpdate(updateLink, true);
  10741. if (!packageData) {
  10742. updateLink = updateLinks.jsdelivr;
  10743. packageData = await checkUpdate(updateLink, true);
  10744. if (!packageData) {
  10745. updateLink = updateLinks.standby;
  10746. packageData = await checkUpdate(updateLink, true);
  10747. }
  10748. }
  10749. }
  10750. if (packageData) {
  10751. version = packageData.version || currentVersion;
  10752. } else {
  10753. version = currentVersion;
  10754. scripts_echoLog({}).error(i18n('checkUpdateFailed'));
  10755. }
  10756. if (packageData && hasNewVersion(currentVersion, version)) {
  10757. scripts_echoLog({
  10758. html: `<li><font>${i18n('newVersionNotice', version, `${updateLink}dist/${GM_info.script.name}.user.js`)}</font></li>`
  10759. });
  10760. scripts_echoLog({
  10761. html: `<li>${i18n('updateText', version)}</li><ol class="update-text">${packageData.change?.map(change => `<li>${change}</li>`).join('')}<li>${i18n('updateHistory')}</li></ol>`
  10762. });
  10763. }
  10764. } catch (error) {
  10765. throwError(error, 'updateChecker');
  10766. }
  10767. };
  10768. const scripts_updateChecker = updateChecker;
  10769. window.STYLE = GM_addStyle(auto_task.Z + GM_getResourceText('style'));
  10770. window.DEBUG = !!globalOptions.other.debug;
  10771. window.TRACE = !!globalOptions.other.debug && typeof console.trace === 'function';
  10772. const loadScript = async () => {
  10773. if (window.location.hostname === 'www.twitch.tv' && window.location.hash === '#auth') {
  10774. const authToken = external_Cookies_namespaceObject.get('auth-token');
  10775. const isLogin = !!external_Cookies_namespaceObject.get('login');
  10776. if (isLogin) {
  10777. GM_setValue('twitchAuth', {
  10778. authToken: authToken,
  10779. clientVersion: __twilightBuildID,
  10780. clientId: commonOptions?.headers?.['Client-ID'],
  10781. deviceId: commonOptions?.headers?.['Device-ID'],
  10782. clientSessionId: window.localStorage.local_storage_app_session_id.replace(/"/g, '')
  10783. });
  10784. window.close();
  10785. external_Swal_default().fire('', i18n('closePageNotice'));
  10786. } else {
  10787. external_Swal_default().fire('', i18n('needLogin'));
  10788. }
  10789. return;
  10790. }
  10791. if (window.location.hostname === 'www.reddit.com' && (window.location.hash === '#auth' || GM_getValue('redditAuth') === '#auth')) {
  10792. const betaButton = $('#redesign-beta-optin-btn');
  10793. if (betaButton.length > 0) {
  10794. GM_setValue('redditAuth', '#auth');
  10795. return betaButton[0].click();
  10796. }
  10797. GM_setValue('redditAuth', null);
  10798. window.close();
  10799. external_Swal_default().fire('', i18n('closePageNotice'));
  10800. return;
  10801. }
  10802. let website;
  10803. for (const Website of Websites) {
  10804. if (Website.test()) {
  10805. website = new Website();
  10806. break;
  10807. }
  10808. }
  10809. if (!website) {
  10810. console.log('%c%s', 'color:#ff0000', 'Auto-Task[Warning]: 脚本停止加载,当前网站不支持!');
  10811. return;
  10812. }
  10813. if (website?.before) {
  10814. await website?.before();
  10815. }
  10816. $('body').append(`<div id="auto-task-info" style="display:${globalOptions.other.defaultShowLog ? 'block' : 'none'};${globalOptions.position.logSideX}:${globalOptions.position.logDistance.split(',')[0]}px;${globalOptions.position.logSideY}:${globalOptions.position.logDistance.split(',')[1]}px;"></div><div id="auto-task-buttons" style="display:${globalOptions.other.defaultShowButton ? 'block' : 'none'};${globalOptions.position.buttonSideX}:${globalOptions.position.buttonDistance.split(',')[0]}px;${globalOptions.position.buttonSideY}:${globalOptions.position.buttonDistance.split(',')[1]}px;"></div><div class="show-button-div" style="display:${globalOptions.other.defaultShowButton ? 'none' : 'block'};${globalOptions.position.showButtonSideX}:${globalOptions.position.showButtonDistance.split(',')[0]}px;${globalOptions.position.showButtonSideY}:${globalOptions.position.showButtonDistance.split(',')[1]}px;"><a class="auto-task-website-btn" href="javascript:void(0);" target="_self" title="${i18n('showButton')}"></a></div>`);
  10817. $('div.show-button-div').on('click', () => {
  10818. $('#auto-task-buttons').show();
  10819. $('div.show-button-div').hide();
  10820. });
  10821. const toggleLog = () => {
  10822. const $this = $('#toggle-log');
  10823. const status = $this.attr('data-status');
  10824. if (status === 'show') {
  10825. $('#auto-task-info').hide();
  10826. $this.attr('data-status', 'hide').text(i18n('showLog'));
  10827. } else {
  10828. $('#auto-task-info').show();
  10829. $this.attr('data-status', 'show').text(i18n('hideLog'));
  10830. }
  10831. };
  10832. external_keyboardJS_default().bind(globalOptions.hotKey.doTaskKey, () => {
  10833. if (website.doTask) {
  10834. website.doTask();
  10835. }
  10836. });
  10837. external_keyboardJS_default().bind(globalOptions.hotKey.undoTaskKey, () => {
  10838. if (website.undoTask) {
  10839. website.doTask();
  10840. }
  10841. });
  10842. external_keyboardJS_default().bind(globalOptions.hotKey.toggleLogKey, toggleLog);
  10843. if (website?.after) {
  10844. await website?.after();
  10845. }
  10846. if (website?.buttons && $('#auto-task-buttons').children().length === 0) {
  10847. $('#auto-task-buttons').addClass(`${website.name}-buttons`);
  10848. for (const button of website.buttons) {
  10849. if (website[button]) {
  10850. const btnElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">${i18n(button)}</a></p>`);
  10851. btnElement.find('a.auto-task-website-btn').on('click', () => {
  10852. website[button]();
  10853. });
  10854. $('#auto-task-buttons').append(btnElement);
  10855. }
  10856. }
  10857. }
  10858. const hideButtonElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">
  10859. ${i18n('hideButton')}</a></p>`);
  10860. hideButtonElement.find('a.auto-task-website-btn').on('click', () => {
  10861. $('#auto-task-buttons').hide();
  10862. $('div.show-button-div').show();
  10863. });
  10864. const toggleLogElement = $(`<p><a id="toggle-log" class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self" data-status="${globalOptions.other.defaultShowLog ? 'show' : 'hide'}">
  10865. ${globalOptions.other.defaultShowLog ? i18n('hideLog') : i18n('showLog')}</a></p>`);
  10866. toggleLogElement.find('a.auto-task-website-btn').on('click', toggleLog);
  10867. $('#auto-task-buttons').append(hideButtonElement).append(toggleLogElement);
  10868. if (website?.options) {
  10869. GM_registerMenuCommand(i18n('changeWebsiteOptions'), () => {
  10870. options(website.name, website.options);
  10871. });
  10872. }
  10873. if (website.name !== 'Setting') {
  10874. GM_registerMenuCommand(i18n('changeGlobalOptions'), () => {
  10875. changeGlobalOptions('swal');
  10876. });
  10877. GM_registerMenuCommand(i18n('settingPage'), () => {
  10878. window.open('https://auto-task-v4.hclonely.com/setting.html', '_blank');
  10879. });
  10880. }
  10881. console.log('%c%s', 'color:#1bbe1a', 'Auto-Task[Load]: 脚本加载完成');
  10882. const [ v1, v2 ] = GM_info.version.split('.');
  10883. if (!(parseInt(v1, 10) >= 5 && parseInt(v2, 10) >= 2)) {
  10884. scripts_echoLog({}).error(i18n('versionNotMatched'));
  10885. }
  10886. if (!GM_getValue('notice')) {
  10887. external_Swal_default().fire({
  10888. title: i18n('swalNotice'),
  10889. icon: 'warning'
  10890. }).then(() => {
  10891. window.open(i18n('noticeLink'), '_blank');
  10892. GM_setValue('notice', new Date().getTime());
  10893. });
  10894. scripts_echoLog({
  10895. html: `<li><font class="warning">${i18n('echoNotice', i18n('noticeLink'))}</font></li>`
  10896. }).font?.find('a').on('click', () => {
  10897. GM_setValue('notice', new Date().getTime());
  10898. });
  10899. }
  10900. scripts_updateChecker();
  10901. };
  10902. if (window.location.hostname === 'discord.com') {
  10903. const LocalStorage = window.localStorage;
  10904. if (window.location.hash === '#auth') {
  10905. window.localStorage.removeItem = () => true;
  10906. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10907. if (discordAuth && discordAuth.length > 0) {
  10908. GM_setValue('discordAuth', {
  10909. auth: discordAuth
  10910. });
  10911. window.close();
  10912. external_Swal_default().fire('', i18n('closePageNotice'));
  10913. } else {
  10914. external_Swal_default().fire({
  10915. text: i18n('getDiscordAuthFailed'),
  10916. icon: 'error'
  10917. });
  10918. }
  10919. } else {
  10920. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10921. if (discordAuth && discordAuth.length > 0) {
  10922. GM_setValue('discordAuth', {
  10923. auth: discordAuth
  10924. });
  10925. }
  10926. }
  10927. } else if (window.location.hostname === 'opquests.com') {
  10928. loadScript();
  10929. } else {
  10930. if (window.location.hostname === 'key-hub.eu') {
  10931. unsafeWindow.keyhubtracker = 1;
  10932. unsafeWindow.gaData = {};
  10933. }
  10934. $(loadScript);
  10935. }
  10936. }();
  10937. })();