auto-task-v4

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

当前为 2024-11-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name auto-task-v4
  3. // @namespace auto-task-v4
  4. // @version 4.5.3
  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 *://steamcommunity.com/*
  33. // @include *://store.steampowered.com/*
  34. // @include https://auto-task-v4.hclonely.com/setting.html
  35. // @include https://auto-task-v4.hclonely.com/history.html
  36.  
  37. // @grant GM_setValue
  38. // @grant GM_getValue
  39. // @grant GM_listValues
  40. // @grant GM_deleteValue
  41. // @grant GM_addStyle
  42. // @grant GM_xmlhttpRequest
  43. // @grant GM_registerMenuCommand
  44. // @grant GM_info
  45. // @grant GM_openInTab
  46. // @grant GM_setClipboard
  47. // @grant GM_getResourceText
  48. // @grant GM_cookie
  49. // @grant GM_addValueChangeListener
  50. // @grant GM_removeValueChangeListener
  51. // @grant unsafeWindow
  52. // @grant window.close
  53. // @grant window.localStorage
  54. // @grant window.focus
  55.  
  56. // @connect cdn.jsdelivr.net
  57. // @connect store.steampowered.com
  58. // @connect steamcommunity.com
  59. // @connect login.steampowered.com
  60. // @connect twitter.com
  61. // @connect x.com
  62. // @connect api.twitter.com
  63. // @connect youtube.com
  64. // @connect www.youtube.com
  65. // @connect facebook.com
  66. // @connect instagram.com
  67. // @connect vk.com
  68. // @connect twitch.tv
  69. // @connect www.twitch.tv
  70. // @connect gql.twitch.tv
  71. // @connect github.com
  72. // @connect discordapp.com
  73. // @connect discord.gg
  74. // @connect discord.com
  75. // @connect www.reddit.com
  76. // @connect oauth.reddit.com
  77. // @connect raw.githubusercontent.com
  78. // @connect t.me
  79. // @connect bit.ly
  80. // @connect giveaway.su
  81. // @connect google.com
  82. // @connect www.vloot.io
  83. // @connect givee.club
  84. // @connect gleam.io
  85. // @connect www.indiedb.com
  86. // @connect key-hub.eu
  87. // @connect opquests.com
  88. // @connect itch.io
  89. // @connect auto-task-v4.hclonely.com
  90. // @connect *
  91. // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js
  92. // @require https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js
  93. // @require https://cdn.jsdelivr.net/npm/regenerator-runtime@0.13.5/runtime.min.js
  94. // @require https://cdn.jsdelivr.net/npm/js-sha1@0.6.0/src/sha1.min.js
  95. // @require https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js
  96. // @resource style https://cdn.jsdelivr.net/npm/sweetalert2@11.3.5/dist/sweetalert2.min.css
  97. // @require https://cdn.jsdelivr.net/npm/keyboardjs@2.6.4/dist/keyboard.min.js
  98. // @require https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js
  99.  
  100. // @noframes
  101. // ==/UserScript==
  102.  
  103. console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
  104. (function() {
  105. var __webpack_modules__ = {
  106. 991: function(__unused_webpack_module, exports) {
  107. !function(e, n) {
  108. true ? n(exports) : 0;
  109. }(this, function(e) {
  110. 'use strict';
  111. var t = function() {
  112. return (t = Object.assign || function(e) {
  113. for (var n, o = 1, t = arguments.length; o < t; o++) {
  114. for (var r in n = arguments[o]) {
  115. Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r]);
  116. }
  117. }
  118. return e;
  119. }).apply(this, arguments);
  120. };
  121. function r(e, n, o) {
  122. if (o || 2 === arguments.length) {
  123. for (var t, r = 0, i = n.length; r < i; r++) {
  124. !t && r in n || ((t = t || Array.prototype.slice.call(n, 0, r))[r] = n[r]);
  125. }
  126. }
  127. return e.concat(t || Array.prototype.slice.call(n));
  128. }
  129. function d(e) {
  130. return '[object Object]' === n(e);
  131. }
  132. function l(e, n) {
  133. var o = r(r([], n || [], !0), [ '_' ], !1).join('|');
  134. return e.replace(new RegExp('(('.concat(o, ')[a-z])+'), 'g'), function(e, n) {
  135. return n.replace(new RegExp(o), '').toLocaleUpperCase();
  136. });
  137. }
  138. var n = function(e) {
  139. return Object.prototype.toString.call(e);
  140. };
  141. var o = (i.prototype.init = function() {
  142. try {
  143. this.getSystemName(), this.getBrowserName();
  144. } catch (e) {
  145. console.warn('[UA formatter error] '.concat(e));
  146. }
  147. }, i.prototype.getEngine = function() {
  148. var e = this.agent;
  149. return -1 !== e.indexOf('Trident') ? 'Trident' : -1 !== e.indexOf('Firefox') ? 'Gecko' : -1 !== e.indexOf('Presto') ? 'Presto' : 'WebKit';
  150. }, i.prototype.getSystemName = function() {
  151. var e, n = (this.agent.match(/^[a-z]+\/\d+\.\d+\s?\(([a-z\d\s:;./_-]+)\)/i) || [])[1];
  152. try {
  153. var o = '';
  154. if (/Windows/i.test(n)) {
  155. var t = (n.match(/NT\s(\d+\.\d+)/) || [])[1];
  156. switch (this.info.os = 'Windows', t) {
  157. case '6.3':
  158. o = '8.1';
  159. break;
  160.  
  161. case '6.2':
  162. o = '8';
  163. break;
  164.  
  165. case '6.1':
  166. o = '7';
  167. break;
  168.  
  169. case '5.2':
  170. case '5.1':
  171. o = 'XP';
  172. break;
  173.  
  174. default:
  175. o = t;
  176. }
  177. return this.info.device = 'PC', void (this.info.osVersion = o);
  178. }
  179. if (/^Macintosh/i.test(n)) {
  180. return o = (n.match(/X\s((\d+(_|\.))+\d+)/) || [])[1], this.info.os = 'Macintosh',
  181. this.info.device = 'PC', void (this.info.osVersion = null !== (e = null == o ? void 0 : o.replace(/_/g, '.')) && void 0 !== e ? e : 'Unknown');
  182. }
  183. if (/^iPad/i.test(n)) {
  184. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPad',
  185. this.info.device = 'Tablet', void (this.info.osVersion = o.replace(/_/g, '.'));
  186. }
  187. if (/^iPhone/i.test(n)) {
  188. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPhone',
  189. this.info.device = 'Mobile', void (this.info.osVersion = o.replace(/_/g, '.'));
  190. }
  191. if (-1 !== n.indexOf('Android')) {
  192. var r = (n.match(/Android\s((\d+\.?)+\d?)/) || [])[1];
  193. return this.info.device = 'Mobile', this.info.os = 'Android', void (this.info.osVersion = r);
  194. }
  195. if (/Linux\s[a-z\d_]+/.test(n)) {
  196. return this.info.os = 'Linux', void (this.info.osVersion = 'Unknown');
  197. }
  198. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  199. } catch (e) {
  200. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  201. }
  202. }, i.prototype.getBrowserName = function() {
  203. var e = Object.keys(this.browserNameMap).map(function(e) {
  204. return new RegExp(''.concat(e, '(\\/|\\s)(\\d+\\.)+\\d+'));
  205. }), n = 1 < (n = (this.agent.match(/[a-z\d]+(\/|\s)(\d+\.)+\d+/gi) || []).filter(function(n) {
  206. return -1 !== e.findIndex(function(e) {
  207. return e.test(n);
  208. });
  209. })).length && !/^Safari/.test(n[n.length - 1]) ? n.reverse() : n;
  210. this.info = t(t({}, this.info), this._formatBrowserVersion(n[0]));
  211. }, i.prototype._formatBrowserVersion = function(e) {
  212. var n, o, t, r;
  213. try {
  214. 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++) {
  215. var d = u[f], l = d[0], h = d[1];
  216. if (new RegExp(l).test(s)) {
  217. c = h;
  218. break;
  219. }
  220. }
  221. var p = {
  222. browserVersion: null != a ? a : 'Unknown',
  223. browser: null !== (t = c.en) && void 0 !== t ? t : 'Unknown',
  224. browserZH: null !== (r = (null == c ? void 0 : c.zh) || c.en) && void 0 !== r ? r : 'Unknown'
  225. };
  226. return 'Trident' === s && (p.browserVersion = {
  227. '4.0': 8,
  228. '5.0': 9,
  229. '6.0': 10,
  230. '7.0': 11
  231. }[a]), p;
  232. } catch (e) {
  233. return console.warn('[UA formatter error] '.concat(e)), {
  234. browser: 'Unknown',
  235. browserVersion: 'Unknown'
  236. };
  237. }
  238. }, i);
  239. function i(e) {
  240. this.agent = '', this.info = {
  241. browser: '',
  242. browserZH: '',
  243. browserVersion: '',
  244. os: '',
  245. osVersion: '',
  246. device: 'Unknown',
  247. engine: 'WebKit'
  248. }, this.browserNameMap = {
  249. MicroMessenger: {
  250. en: 'MicroMessenger',
  251. zh: '微信'
  252. },
  253. MetaSr: {
  254. en: 'MetaSr',
  255. zh: '搜狗浏览器'
  256. },
  257. 'QQ(Browser)?': {
  258. en: 'QQBrowser',
  259. zh: 'QQ浏览器'
  260. },
  261. UCBrowser: {
  262. en: 'UCBrowser',
  263. zh: 'UC浏览器'
  264. },
  265. '2345Explorer': {
  266. en: '2345Explorer',
  267. zh: '2345极速浏览器'
  268. },
  269. Mb2345Browser: {
  270. en: 'Mb2345Browser',
  271. zh: '2345手机浏览器'
  272. },
  273. Trident: {
  274. en: 'Internet Explorer'
  275. },
  276. 'Edge?': {
  277. en: 'Edge'
  278. },
  279. OPR: {
  280. en: 'Opera'
  281. },
  282. Vivaldi: {
  283. en: 'Vivaldi'
  284. },
  285. Firefox: {
  286. en: 'Firefox'
  287. },
  288. Chrome: {
  289. en: 'Chrome'
  290. },
  291. Safari: {
  292. en: 'Safari'
  293. }
  294. }, this.agent = e, this.init();
  295. var n = this.info, o = n.browser, e = n.browserVersion, n = n.osVersion;
  296. this.info = t(t({}, this.info), {
  297. engine: this.getEngine(),
  298. browserVersion: 'Safari' === o ? n : e
  299. });
  300. }
  301. function s() {
  302. this.cookies = {}, this.init();
  303. }
  304. var a = new (s.prototype.init = function() {
  305. var o = {};
  306. document.cookie.split(/;\s/).forEach(function(e) {
  307. var n = e.split(/=/), e = n[0], n = n[1];
  308. o[e] = n;
  309. }), this.cookies = o;
  310. }, s.prototype.getItem = function(e) {
  311. return this.cookies[e];
  312. }, s.prototype.getAllItems = function() {
  313. return this.cookies;
  314. }, s.prototype.setItem = function(e, n, o, t, r, i) {
  315. document.cookie = ''.concat(e, '=').concat(n).concat(o ? '; expires='.concat(o) : '').concat(t ? '; path='.concat(t) : '').concat(r ? '; domain='.concat(r) : '').concat(i ? '; secure' : '');
  316. }, s)();
  317. e.countDown = function e(n, o, t, r) {
  318. if (!window) {
  319. throw new Error('window is not defind.');
  320. }
  321. if (0 < n) {
  322. return r && r(), n--, window[o] = window.setTimeout(function() {
  323. e(n, o, t, r);
  324. }, 1e3), function() {
  325. return clearTimeout(window[o]);
  326. };
  327. }
  328. clearTimeout(window[o]), t && t();
  329. }, e.createRandomID = function(e) {
  330. void 0 === e && (e = 12);
  331. for (var n = [], o = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''), t = o.length, r = 0; r < e; r++) {
  332. n.push(o[Math.round(Math.random() * t)]);
  333. }
  334. return n.join('');
  335. }, e.dCookie = a, e.debounce = function(o, t, r) {
  336. var i;
  337. void 0 === t && (t = 0);
  338. var s = r = void 0 === r ? !1 : r;
  339. return function() {
  340. var e = this, n = arguments;
  341. s && (o.apply(this, arguments), s = !1), clearTimeout(i), i = setTimeout(function() {
  342. r ? s = !0 : o.apply(e, n);
  343. }, t);
  344. };
  345. }, e.deepCopy = function e(n) {
  346. if (d(n) || Array.isArray(n)) {
  347. var o, t = Array.isArray(n) ? [] : {};
  348. for (o in n) {
  349. t[o] = e(n[o]);
  350. }
  351. return t;
  352. }
  353. return n;
  354. }, e.formatQueryParams = function(e) {
  355. e = null === (e = /\?(?<params>(.*)=.+)/.exec(decodeURIComponent(e))) || void 0 === e ? void 0 : e.groups;
  356. if (!e) {
  357. return {};
  358. }
  359. for (var n = e.params.split('&'), t = {}, o = 0; o < n.length; o++) {
  360. n[o].replace(/([^?&]*)=([^?&]*)/, function(e, n, o) {
  361. return t[n] = o, e;
  362. });
  363. }
  364. return t;
  365. }, e.formatThousandth = function(e) {
  366. 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, '$&,');
  367. return ''.concat(e).concat(n ? '.'.concat(n) : '');
  368. }, e.generateTree = function e(n, o, t, r) {
  369. for (var i = [], s = 0; s < n.length; s++) {
  370. var a = n[s];
  371. a[t] === o && (i.push(a), a.children = e(n, a[null != r ? r : 'id'], t, r));
  372. }
  373. return i;
  374. }, e.isEmpty = function(e) {
  375. 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);
  376. }, e.isFunction = function(e) {
  377. return '[object Function]' === n(e);
  378. }, e.isImageUrl = function(e) {
  379. return /\.((png)|(jpe?g)|(gif)|(svg)|(webp))$/gi.test(e);
  380. }, e.isObject = d, e.isRegexp = function(e) {
  381. return '[object RegExp]' === n(e);
  382. }, e.objectKeyToCamelCase = function e(n, o, t) {
  383. if (Array.isArray(n)) {
  384. for (var r = [], i = 0; i < n.length; i++) {
  385. r[i] = e(o && n[i][o] ? n[i][o] : n[i], o, t);
  386. }
  387. } else if (d(n)) {
  388. r = {};
  389. for (var s = o && n[o] ? n[o] : n, a = 0, c = Object.entries(s); a < c.length; a++) {
  390. var f = (u = c[a])[0], u = u[1];
  391. Array.isArray(u) || d(s) ? r[l(f, t)] = e(u, o, t) : r[l(f, t)] = u;
  392. }
  393. } else {
  394. r = n;
  395. }
  396. return r;
  397. }, e.realType = n, e.searchParams = function(e, n) {
  398. return void 0 === e && (e = null === location || void 0 === location ? void 0 : location.search),
  399. new URLSearchParams(e).get(n);
  400. }, e.toLowerCamelCase = l, e.toUnderline = function(e) {
  401. return e.replace(/([A-Z])/g, function(e) {
  402. return '_'.concat(e.toLocaleLowerCase());
  403. });
  404. }, e.ua = function(e) {
  405. return void 0 === e && (e = navigator.userAgent), new o(e).info;
  406. }, Object.defineProperty(e, '__esModule', {
  407. value: !0
  408. });
  409. });
  410. },
  411. 675: function(module, __webpack_exports__, __webpack_require__) {
  412. 'use strict';
  413. __webpack_require__.d(__webpack_exports__, {
  414. A: function() {
  415. return __WEBPACK_DEFAULT_EXPORT__;
  416. }
  417. });
  418. var _node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(601);
  419. var _node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = __webpack_require__.n(_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__);
  420. var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(314);
  421. var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default = __webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__);
  422. var ___CSS_LOADER_EXPORT___ = _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default()(_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default());
  423. ___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{transform:scale(1.05);box-shadow:0 6px 20px rgba(0,0,0,.3);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}#auto-task-info{z-index:999999999 !important}#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;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{text-decoration:none !important}.auto-task-keylol{display:inline-block;text-transform:capitalize;margin-left:10px;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 rgba(5,190,5,.4)}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 rgba(254,0,0,.4)}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:rgba(0,0,0,0)}body.auto-task-history .container .card{width:80%;max-width:800px;border-radius:10px;background:rgba(118,118,118,.1019607843);border-top:1px solid rgba(255,255,255,.5019607843);-webkit-backdrop-filter:blur(20px);backdrop-filter:blur(20px);box-shadow:0 15px 25px rgba(0,0,0,.1019607843);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{z-index:999999999 !important}#auto-task-buttons,.show-button-div{position:fixed;top:30px;right:15px;width:124px;transform:scale(0.85)}#auto-task-buttons p,.show-button-div p{margin:5px !important}#auto-task-buttons p,.show-button-div p{line-height:30px;height:40px;text-align:center}#auto-task-buttons a.auto-task-website-btn,.show-button-div a.auto-task-website-btn{width:105px;line-height:27px;font-size:20px;display:block}.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}`, '' ]);
  424. const __WEBPACK_DEFAULT_EXPORT__ = ___CSS_LOADER_EXPORT___.toString();
  425. },
  426. 314: function(module) {
  427. 'use strict';
  428. module.exports = function(cssWithMappingToString) {
  429. var list = [];
  430. list.toString = function toString() {
  431. return this.map(function(item) {
  432. var content = '';
  433. var needLayer = typeof item[5] !== 'undefined';
  434. if (item[4]) {
  435. content += '@supports ('.concat(item[4], ') {');
  436. }
  437. if (item[2]) {
  438. content += '@media '.concat(item[2], ' {');
  439. }
  440. if (needLayer) {
  441. content += '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {');
  442. }
  443. content += cssWithMappingToString(item);
  444. if (needLayer) {
  445. content += '}';
  446. }
  447. if (item[2]) {
  448. content += '}';
  449. }
  450. if (item[4]) {
  451. content += '}';
  452. }
  453. return content;
  454. }).join('');
  455. };
  456. list.i = function i(modules, media, dedupe, supports, layer) {
  457. if (typeof modules === 'string') {
  458. modules = [ [ null, modules, undefined ] ];
  459. }
  460. var alreadyImportedModules = {};
  461. if (dedupe) {
  462. for (var k = 0; k < this.length; k++) {
  463. var id = this[k][0];
  464. if (id != null) {
  465. alreadyImportedModules[id] = true;
  466. }
  467. }
  468. }
  469. for (var _k = 0; _k < modules.length; _k++) {
  470. var item = [].concat(modules[_k]);
  471. if (dedupe && alreadyImportedModules[item[0]]) {
  472. continue;
  473. }
  474. if (typeof layer !== 'undefined') {
  475. if (typeof item[5] === 'undefined') {
  476. item[5] = layer;
  477. } else {
  478. item[1] = '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {').concat(item[1], '}');
  479. item[5] = layer;
  480. }
  481. }
  482. if (media) {
  483. if (!item[2]) {
  484. item[2] = media;
  485. } else {
  486. item[1] = '@media '.concat(item[2], ' {').concat(item[1], '}');
  487. item[2] = media;
  488. }
  489. }
  490. if (supports) {
  491. if (!item[4]) {
  492. item[4] = ''.concat(supports);
  493. } else {
  494. item[1] = '@supports ('.concat(item[4], ') {').concat(item[1], '}');
  495. item[4] = supports;
  496. }
  497. }
  498. list.push(item);
  499. }
  500. };
  501. return list;
  502. };
  503. },
  504. 601: function(module) {
  505. 'use strict';
  506. module.exports = function(i) {
  507. return i[1];
  508. };
  509. }
  510. };
  511. var __webpack_module_cache__ = {};
  512. function __webpack_require__(moduleId) {
  513. var cachedModule = __webpack_module_cache__[moduleId];
  514. if (cachedModule !== undefined) {
  515. return cachedModule.exports;
  516. }
  517. var module = __webpack_module_cache__[moduleId] = {
  518. id: moduleId,
  519. exports: {}
  520. };
  521. __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  522. return module.exports;
  523. }
  524. !function() {
  525. __webpack_require__.n = function(module) {
  526. var getter = module && module.__esModule ? function() {
  527. return module['default'];
  528. } : function() {
  529. return module;
  530. };
  531. __webpack_require__.d(getter, {
  532. a: getter
  533. });
  534. return getter;
  535. };
  536. }();
  537. !function() {
  538. __webpack_require__.d = function(exports, definition) {
  539. for (var key in definition) {
  540. if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  541. Object.defineProperty(exports, key, {
  542. enumerable: true,
  543. get: definition[key]
  544. });
  545. }
  546. }
  547. };
  548. }();
  549. !function() {
  550. __webpack_require__.o = function(obj, prop) {
  551. return Object.prototype.hasOwnProperty.call(obj, prop);
  552. };
  553. }();
  554. var __webpack_exports__ = {};
  555. !function() {
  556. 'use strict';
  557. const external_Swal_namespaceObject = Swal;
  558. var external_Swal_default = __webpack_require__.n(external_Swal_namespaceObject);
  559. const external_Cookies_namespaceObject = Cookies;
  560. var external_Cookies_default = __webpack_require__.n(external_Cookies_namespaceObject);
  561. var auto_task = __webpack_require__(675);
  562. var javascript_utils_umd_min = __webpack_require__(991);
  563. const getFinalUrl = (responseHeaders, finalUrl) => {
  564. const realFinalUrl = responseHeaders?.split('\n')?.find(header => header.includes('location') ? header.replace('loctation:', '').trim() : null);
  565. return realFinalUrl || finalUrl;
  566. };
  567. const httpRequest = async (options, times = 0) => {
  568. if (window.TRACE) {
  569. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  570. }
  571. try {
  572. const result = await new Promise(resolve => {
  573. if (options.dataType) {
  574. options.responseType = options.dataType;
  575. }
  576. const requestObj = {
  577. ...{
  578. timeout: 3e4,
  579. ontimeout(data) {
  580. resolve({
  581. result: 'Error',
  582. statusText: 'Timeout',
  583. status: 601,
  584. data: data,
  585. options: options
  586. });
  587. },
  588. onabort(data) {
  589. resolve({
  590. result: 'Error',
  591. statusText: 'Aborted',
  592. status: 602,
  593. data: data,
  594. options: options
  595. });
  596. },
  597. onerror(data) {
  598. resolve({
  599. result: 'Error',
  600. statusText: 'Error',
  601. status: 603,
  602. data: data,
  603. options: options
  604. });
  605. },
  606. onload(data) {
  607. data.finalUrl = getFinalUrl(data.responseHeaders, data.finalUrl);
  608. if (options.responseType === 'json' && data?.response && typeof data.response !== 'object') {
  609. try {
  610. data.response = JSON.parse(data.responseText);
  611. } catch (error) {}
  612. }
  613. resolve({
  614. result: 'Success',
  615. statusText: 'Load',
  616. status: 600,
  617. data: data,
  618. options: options
  619. });
  620. }
  621. },
  622. ...options
  623. };
  624. GM_xmlhttpRequest(requestObj);
  625. });
  626. if (window.DEBUG) {
  627. console.log('%cAuto-Task[httpRequest]:', 'color:blue', JSON.stringify(result));
  628. }
  629. if (result.status !== 600 && times < 2) {
  630. return await httpRequest(options, times + 1);
  631. }
  632. return result;
  633. } catch (error) {
  634. console.log('%cAuto-Task[httpRequest]:', 'color:red', JSON.stringify({
  635. errorMsg: error,
  636. options: options
  637. }));
  638. throwError(error, 'httpRequest');
  639. return {
  640. result: 'JsError',
  641. statusText: 'Error',
  642. status: 604,
  643. error: error,
  644. options: options
  645. };
  646. }
  647. };
  648. const tools_httpRequest = httpRequest;
  649. const echoLog = ({
  650. type,
  651. text,
  652. html,
  653. id
  654. }) => {
  655. const emptyStatus = {
  656. success: () => emptyStatus,
  657. error: () => emptyStatus,
  658. warning: () => emptyStatus,
  659. info: () => emptyStatus,
  660. view: () => emptyStatus
  661. };
  662. try {
  663. let ele;
  664. if (type) {
  665. switch (type) {
  666. case 'joiningSteamGroup':
  667. case 'leavingSteamGroup':
  668. case 'gettingSteamGroupId':
  669. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/groups/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  670. break;
  671.  
  672. case 'joiningSteamOfficialGroup':
  673. case 'leavingSteamOfficialGroup':
  674. case 'gettingSteamOfficialGroupId':
  675. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/games/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  676. break;
  677.  
  678. case 'subscribingForum':
  679. case 'unsubscribingForum':
  680. case 'gettingForumId':
  681. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/app/${text}/discussions/" target="_blank">${text}</a>]...<font></font></li>`);
  682. break;
  683.  
  684. case 'followingCurator':
  685. case 'unfollowingCurator':
  686. case 'gettingCuratorId':
  687. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/${text?.includes('/') ? text : `curator/${text}`}" target="_blank">${text}</a>]...<font></font></li>`);
  688. break;
  689.  
  690. case 'addingToWishlist':
  691. case 'removingFromWishlist':
  692. case 'followingGame':
  693. case 'unfollowingGame':
  694. case 'gettingSubid':
  695. case 'addingFreeLicense':
  696. case 'requestingPlayTestAccess':
  697. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/app/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  698. break;
  699.  
  700. case 'addingFreeLicenseSubid':
  701. ele = $(`<li>${i18n('addingFreeLicense')}[<a href="https://steamdb.info/sub/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  702. break;
  703.  
  704. case 'favoritingWorkshop':
  705. case 'unfavoritingWorkshop':
  706. case 'gettingWorkshopAppId':
  707. case 'votingUpWorkshop':
  708. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/sharedfiles/filedetails/?id=${text}" target="_blank">
  709. ${text}</a>]...<font></font></li>`);
  710. break;
  711.  
  712. case 'gettingAnnouncementParams':
  713. case 'likingAnnouncement':
  714. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/news/app/${text}/view/${id}" target="_blank">
  715. ${id}</a>]...<font></font></li>`);
  716. break;
  717.  
  718. case 'joiningDiscordServer':
  719. case 'gettingDiscordGuild':
  720. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/invite/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  721. break;
  722.  
  723. case 'leavingDiscordServer':
  724. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/channels/@me/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  725. break;
  726.  
  727. case 'updateDiscordAuth':
  728. ele = $(`<li style="color:red;">${i18n('updateDiscordAuth')}</li>`);
  729. break;
  730.  
  731. case 'followingTwitchChannel':
  732. case 'unfollowingTwitchChannel':
  733. case 'gettingTwitchChannelId':
  734. ele = $(`<li>${i18n(type)}[<a href="https://www.twitch.tv/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  735. break;
  736.  
  737. case 'gettingInsUserId':
  738. case 'followingIns':
  739. case 'unfollowingIns':
  740. ele = $(`<li>${i18n(type)}[<a href="https://www.instagram.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  741. break;
  742.  
  743. case 'gettingTwitterUserId':
  744. case 'followingTwitterUser':
  745. case 'unfollowingTwitterUser':
  746. ele = $(`<li>${i18n(type)}[<a href="https://x.com/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  747. break;
  748.  
  749. case 'retweetting':
  750. case 'unretweetting':
  751. ele = $(`<li>${i18n(type)}${text}...<font></font></li>`);
  752. break;
  753.  
  754. case 'joiningReddit':
  755. case 'leavingReddit':
  756. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/r/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  757. break;
  758.  
  759. case 'followingRedditUser':
  760. case 'unfollowingRedditUser':
  761. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/user/${text?.replace('u_', '')}" target="_blank">
  762. ${text?.replace('u_', '')}</a>]...<font></font></li>`);
  763. break;
  764.  
  765. case 'followingYtbChannel':
  766. case 'unfollowingYtbChannel':
  767. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/channel/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  768. break;
  769.  
  770. case 'likingYtbVideo':
  771. case 'unlikingYtbVideo':
  772. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/watch?v=${text}" target="_blank">${text}</a>]...<font></font></li>`);
  773. break;
  774.  
  775. case 'gettingVkId':
  776. case 'joiningVkGroup':
  777. case 'leavingVkGroup':
  778. case 'joiningVkPublic':
  779. case 'leavingVkPublic':
  780. case 'sendingVkWall':
  781. case 'deletingVkWall':
  782. ele = $(`<li>${i18n(type)}[<a href="https://vk.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  783. break;
  784.  
  785. case 'visitingLink':
  786. ele = $(`<li>${i18n('visitingLink')}[<a href="${text}" target="_blank">${text}</a>]...<font></font></li>`);
  787. break;
  788.  
  789. case 'verifyingInsAuth':
  790. case 'text':
  791. ele = $(`<li>${i18n(text)}<font></font></li>`);
  792. break;
  793.  
  794. case 'html':
  795. ele = $(text || html);
  796. break;
  797.  
  798. case 'whiteList':
  799. ele = $(`<li><font class="warning">${i18n('skipTask')}[${text}(${id})](${i18n('whiteList')})</font></li>`);
  800. break;
  801.  
  802. case 'globalOptionsSkip':
  803. ele = $(`<li>${i18n('skipTaskOption')}<font class="warning">${text}</font></li>`);
  804. break;
  805.  
  806. default:
  807. ele = $(`<li>${i18n('unKnown')}:${type}(${text})...<font></font></li>`);
  808. break;
  809. }
  810. } else if (text) {
  811. ele = $(`<li>${i18n(text)}<font></font></li>`);
  812. } else if (html) {
  813. ele = $(html);
  814. } else {
  815. ele = $('<li><font></font></li>');
  816. }
  817. ele.addClass('card-text');
  818. $('#auto-task-info').append(ele);
  819. ele[0]?.scrollIntoView();
  820. const font = ele.find('font');
  821. const status = {
  822. font: font,
  823. success(text = 'Success', html = false) {
  824. this.font?.attr('class', '').addClass('success');
  825. html ? this.font?.html(text) : this.font?.text(text);
  826. return this;
  827. },
  828. error(text = 'Error', html = false) {
  829. this.font?.attr('class', '').addClass('error');
  830. html ? this.font?.html(text) : this.font?.text(text);
  831. return this;
  832. },
  833. warning(text = 'Warning', html = false) {
  834. this.font?.attr('class', '').addClass('warning');
  835. html ? this.font?.html(text) : this.font?.text(text);
  836. return this;
  837. },
  838. info(text = 'Info', html = false) {
  839. this.font?.attr('class', '').addClass('info');
  840. html ? this.font?.html(text) : this.font?.text(text);
  841. return this;
  842. },
  843. view() {
  844. this.font?.[0].scrollIntoView();
  845. return this;
  846. }
  847. };
  848. return status;
  849. } catch (error) {
  850. throwError(error, 'echoLog');
  851. return emptyStatus;
  852. }
  853. };
  854. const scripts_echoLog = echoLog;
  855. const unique = array => {
  856. try {
  857. return [ ...new Set(array) ];
  858. } catch (error) {
  859. throwError(error, 'unique');
  860. return [];
  861. }
  862. };
  863. const delay = (time = 1e3) => new Promise(resolve => {
  864. setTimeout(() => {
  865. resolve(true);
  866. }, time);
  867. });
  868. const getRedirectLink = async link => {
  869. try {
  870. if (!link) {
  871. return null;
  872. }
  873. const redirectLinksCache = GM_getValue('redirectLinks') || {};
  874. if (redirectLinksCache[link]) {
  875. redirectLinksCache[link];
  876. }
  877. return await tools_httpRequest({
  878. url: link,
  879. method: 'GET'
  880. }).then(({
  881. data
  882. }) => {
  883. if (data?.finalUrl) {
  884. redirectLinksCache[link] = data.finalUrl;
  885. GM_setValue('redirectLinks', redirectLinksCache);
  886. return data.finalUrl;
  887. }
  888. return null;
  889. });
  890. } catch (error) {
  891. throwError(error, 'getRedirectLink');
  892. return null;
  893. }
  894. };
  895. const visitLink = async (link, options) => {
  896. try {
  897. const logStatus = scripts_echoLog({
  898. type: 'visitLink',
  899. text: link
  900. });
  901. return await tools_httpRequest({
  902. url: link,
  903. method: 'GET',
  904. ...options
  905. }).then(({
  906. result,
  907. statusText,
  908. status
  909. }) => {
  910. if (result === 'Success') {
  911. logStatus.success();
  912. return true;
  913. }
  914. logStatus.error(`${result}:${statusText}(${status})`);
  915. return false;
  916. });
  917. } catch (error) {
  918. throwError(error, 'visitLink');
  919. return false;
  920. }
  921. };
  922. const getUrlQuery = url => {
  923. try {
  924. const query = {};
  925. if (url) {
  926. if (url.includes('?')) {
  927. url.split('?')[1].replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  928. query[key] = value;
  929. return str;
  930. });
  931. }
  932. } else {
  933. window.location.search.replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  934. query[key] = value;
  935. return str;
  936. });
  937. }
  938. return query;
  939. } catch (error) {
  940. throwError(error, 'getUrlQuery');
  941. return {};
  942. }
  943. };
  944. const getUuid = () => {
  945. const uuidUrl = URL.createObjectURL(new Blob()).toString();
  946. return uuidUrl.slice(uuidUrl.lastIndexOf('/') + 1);
  947. };
  948. const stringToColour = str => {
  949. try {
  950. let hash = 0;
  951. for (let i = 0; i < str.length; i++) {
  952. hash = str.charCodeAt(i) + ((hash << 5) - hash);
  953. }
  954. let colour = '#';
  955. for (let i = 0; i < 3; i++) {
  956. const value = hash >> i * 8 & 255;
  957. colour += `00${value.toString(16)}`.slice(-2);
  958. }
  959. return colour;
  960. } catch (error) {
  961. throwError(error, 'stringToColour');
  962. return '#fff';
  963. }
  964. };
  965. const defaultGlobalOptions = {
  966. doTask: {
  967. discord: {
  968. servers: true
  969. },
  970. instagram: {
  971. users: true
  972. },
  973. twitch: {
  974. channels: true
  975. },
  976. twitter: {
  977. users: true,
  978. retweets: true
  979. },
  980. vk: {
  981. names: true
  982. },
  983. youtube: {
  984. channels: true,
  985. likes: true
  986. },
  987. reddit: {
  988. reddits: true
  989. },
  990. steam: {
  991. groups: true,
  992. officialGroups: true,
  993. wishlists: true,
  994. follows: true,
  995. forums: true,
  996. workshops: true,
  997. curators: true,
  998. workshopVotes: true,
  999. announcements: true,
  1000. licenses: true,
  1001. playtests: true
  1002. }
  1003. },
  1004. undoTask: {
  1005. discord: {
  1006. servers: true
  1007. },
  1008. instagram: {
  1009. users: true
  1010. },
  1011. twitch: {
  1012. channels: true
  1013. },
  1014. twitter: {
  1015. users: true,
  1016. retweets: true
  1017. },
  1018. vk: {
  1019. names: true
  1020. },
  1021. youtube: {
  1022. channels: true,
  1023. likes: true
  1024. },
  1025. reddit: {
  1026. reddits: true
  1027. },
  1028. steam: {
  1029. groups: true,
  1030. officialGroups: true,
  1031. wishlists: true,
  1032. follows: true,
  1033. forums: true,
  1034. workshops: true,
  1035. curators: true
  1036. }
  1037. },
  1038. ASF: {
  1039. AsfEnabled: false,
  1040. AsfIpcUrl: '',
  1041. AsfIpcPassword: '',
  1042. AsfBotname: 'asf'
  1043. },
  1044. position: {
  1045. buttonSideX: 'right',
  1046. buttonSideY: 'top',
  1047. buttonDistance: '15,30',
  1048. showButtonSideX: 'right',
  1049. showButtonSideY: 'top',
  1050. showButtonDistance: '15,30',
  1051. logSideX: 'right',
  1052. logSideY: 'bottom',
  1053. logDistance: '10,10'
  1054. },
  1055. hotKey: {
  1056. doTaskKey: 'alt + d',
  1057. undoTaskKey: 'alt + u',
  1058. toggleLogKey: 'alt + l'
  1059. },
  1060. other: {
  1061. twitterVerifyId: '783214',
  1062. youtubeVerifyChannel: 'UCrXUsMBcfTVqwAS7DKg9C0Q',
  1063. autoUpdateSource: 'jsdelivr',
  1064. language: 'zh',
  1065. checkLogin: true,
  1066. checkLeftKey: true,
  1067. defaultShowButton: true,
  1068. defaultShowLog: true,
  1069. debug: false,
  1070. receivePreview: true
  1071. }
  1072. };
  1073. const userDefinedGlobalOptions = GM_getValue('globalOptions') || {};
  1074. const assignObject = (obj1, obj2) => {
  1075. try {
  1076. const newObj = {};
  1077. for (const [ key, value ] of Object.entries(obj1)) {
  1078. if (Object.prototype.toString.call(value) === '[object Object]' && Object.prototype.toString.call(obj2[key]) === '[object Object]') {
  1079. newObj[key] = assignObject(value, obj2[key]);
  1080. } else {
  1081. newObj[key] = obj2[key] ?? value;
  1082. }
  1083. }
  1084. return newObj;
  1085. } catch (error) {
  1086. throwError(error, 'assignObject');
  1087. return defaultGlobalOptions;
  1088. }
  1089. };
  1090. const globalOptions = assignObject(defaultGlobalOptions, userDefinedGlobalOptions);
  1091. const saveData = () => {
  1092. try {
  1093. const data = {};
  1094. $('#globalOptionsForm').serializeArray().map(value => {
  1095. data[value.name] = value.value;
  1096. return value;
  1097. });
  1098. $.makeArray($('#globalOptionsForm input')).map(element => {
  1099. const name = $(element).attr('name');
  1100. const keys = name.split('.');
  1101. if (keys.length === 3) {
  1102. globalOptions[keys[0]][keys[1]][keys[2]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1103. } else if (keys.length === 2) {
  1104. globalOptions[keys[0]][keys[1]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1105. }
  1106. return element;
  1107. });
  1108. GM_setValue('globalOptions', globalOptions);
  1109. external_Swal_default().fire({
  1110. title: i18n('changeGlobalOptionsSuccess'),
  1111. icon: 'success'
  1112. });
  1113. } catch (error) {
  1114. throwError(error, 'saveData');
  1115. }
  1116. };
  1117. const changeGlobalOptions = showType => {
  1118. try {
  1119. let globalOptionsForm = `<form id="globalOptionsForm" class="auto-task-form">
  1120. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  1121. for (const [ type, data1 ] of Object.entries(globalOptions)) {
  1122. for (const [ option, data2 ] of Object.entries(data1)) {
  1123. if ([ 'other', 'position', 'hotKey', 'ASF' ].includes(type)) {
  1124. if (typeof data2 === 'boolean') {
  1125. 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>`;
  1126. } else {
  1127. 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>`;
  1128. }
  1129. } else {
  1130. for (const [ socialType, data3 ] of Object.entries(data2)) {
  1131. 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>`;
  1132. }
  1133. }
  1134. }
  1135. }
  1136. globalOptionsForm += '</tbody></table></form>';
  1137. if (showType === 'swal') {
  1138. external_Swal_default().fire({
  1139. title: i18n('globalOptions'),
  1140. html: globalOptionsForm,
  1141. showConfirmButton: true,
  1142. confirmButtonText: i18n('save'),
  1143. showCancelButton: true,
  1144. cancelButtonText: i18n('close')
  1145. }).then(({
  1146. isConfirmed
  1147. }) => {
  1148. if (isConfirmed) {
  1149. saveData();
  1150. }
  1151. });
  1152. } else {
  1153. $('body').append(`<h2>${i18n('globalOptions')}</h2>${globalOptionsForm}`);
  1154. }
  1155. } catch (error) {
  1156. throwError(error, 'changeGlobalOptions');
  1157. }
  1158. };
  1159. const data = {
  1160. website: '网站',
  1161. type: '类型',
  1162. edit: '编辑',
  1163. whiteList: '白名单',
  1164. skipTask: '跳过撤销任务',
  1165. whiteListOptions: '白名单设置',
  1166. changeWhiteListOption: '设置白名单(%0)',
  1167. whiteListNotFound: '找不到此项白名单: %0',
  1168. changeWhiteListSuccess: '白名单修改成功,刷新生效!',
  1169. changeWebsiteOptions: '网站设置',
  1170. changeGlobalOptions: '全局设置',
  1171. ok: '是',
  1172. save: '保存',
  1173. close: '关闭',
  1174. return: '返回',
  1175. option: '选项',
  1176. value: '值',
  1177. websiteOptions: '当前网站设置',
  1178. changeWebsiteOptionsSuccess: '更改当前网站设置成功,刷新生效!',
  1179. changeGlobalOptionsSuccess: '更改全局设置成功,刷新生效!',
  1180. needLogin: '请先登录!',
  1181. getTasksInfo: '正在获取并处理任务信息...',
  1182. gettingKey: '正在获取Key...',
  1183. verifyingTask: '正在验证任务',
  1184. notice: '自动任务脚本提醒',
  1185. noKeysLeft: '此页面已经没有剩余key了,是否关闭?',
  1186. giveawayEnded: '此活动已结束,是否关闭?',
  1187. giveawayNotWork: '此活动因某些原因(已结束/暂停/未开始...)不可用(如果是脚本误判请及时反馈),是否关闭?',
  1188. confirm: '确定',
  1189. cancel: '取消',
  1190. unKnown: '未知',
  1191. unKnownTaskType: '未识别的任务',
  1192. doing: '正在做任务',
  1193. allTasksComplete: '所有任务已完成!',
  1194. getTaskIdFailed: '获取任务Id失败!',
  1195. initSuccess: '%0 初始化成功!',
  1196. initFailed: '%0 初始化失败!',
  1197. errorLink: '链接错误: %0',
  1198. needInit: '请先初始化',
  1199. verifyingAuth: '正在验证%0凭证...',
  1200. updatingAuth: '正在更新%0凭证...',
  1201. refreshingToken: '正在刷新%0凭证...',
  1202. settingToken: '正在设置%0凭证...',
  1203. steamStoreTab: 'Steam商店(弹窗)',
  1204. steamCommunityTab: 'Steam社区(弹窗)',
  1205. initing: '正在初始化...',
  1206. getFailed: '获取%0失败!',
  1207. checkLoginFailed: '检测登录状态失败!',
  1208. checkLeftKeyFailed: '检测剩余Key失败!',
  1209. userId: '用户Id',
  1210. joiningGiveaway: '正在加入赠Key',
  1211. needJoinGiveaway: '需要先加入赠Key',
  1212. cannotUndo: '此网站不支持取消任务',
  1213. verifyAuth: '正在验证 %0 凭证...',
  1214. closePageNotice: '如果此页面没有自动关闭,请自行关闭本页面。',
  1215. errorReport: '检测到脚本报错,是否前往反馈BUG?',
  1216. visitingLink: '正在访问链接: ',
  1217. doTask: '做任务',
  1218. undoTask: '撤销任务',
  1219. verifyTask: '验证任务',
  1220. getKey: '获取Key',
  1221. selectAll: '全选',
  1222. selectNone: '全不选',
  1223. invertSelect: '反选',
  1224. doFreeTask: '加入免费赠品',
  1225. doPointTask: '加入点数赠品',
  1226. skipTaskOption: '设置中已配置跳过任务',
  1227. other: '其他',
  1228. globalOptions: '全局设置',
  1229. checkLogin: '登录检测</br>需要登录的网站自动登录,部分网站支持',
  1230. checkLeftKey: '剩余Key检测</br>赠Key活动结束提示是否关闭,部分网站支持',
  1231. twitterVerifyId: '通过尝试关注该账号验证Twitter凭证</br>默认为Twitter官方帐号 783214</br>不想关注官方账号可以改为自己的帐号',
  1232. youtubeVerifyChannel: '通过尝试订阅该频道验证YouTube凭证</br>默认为YouTube官方频道 UCrXUsMBcfTVqwAS7DKg9C0Q</br>不想关注官方频道可以改为自己的频道',
  1233. autoUpdateSource: '更新源</br>github: 需代理,实时更新</br>jsdelivr: 可不用代理,更新有延迟</br>standby: 备用</br>auto: 依次使用github, jsdelivr, standby源进行尝试更新',
  1234. saveGlobalOptions: '保存设置',
  1235. settingPage: '设置页面',
  1236. name: '名称',
  1237. version: '版本',
  1238. scriptManager: '脚本管理器',
  1239. script: '脚本',
  1240. environment: '环境',
  1241. os: '系统',
  1242. browser: '浏览器',
  1243. getId: '获取 %0 id',
  1244. getTwitterUserId: '获取Twitter用户id(获取id功能仅在设置页面可用)',
  1245. getYoutubeChannelId: '获取Youtube频道id(获取id功能仅在设置页面可用)',
  1246. showButton: '显示按钮',
  1247. hideButton: '隐藏按钮',
  1248. showLog: '显示日志',
  1249. hideLog: '隐藏日志',
  1250. defaultShowButton: '默认显示按钮',
  1251. defaultShowLog: '默认显示日志',
  1252. debug: '输出调试日志,不要开启此选项!',
  1253. receivePreview: '接收预览版更新',
  1254. position: '组件位置',
  1255. buttonSideX: '按钮区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1256. buttonSideY: '按钮区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1257. buttonDistance: '按钮区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1258. showButtonSideX: '显示按钮水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1259. showButtonSideY: '显示按钮垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1260. showButtonDistance: '显示按钮距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1261. logSideX: '日志区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1262. logSideY: '日志区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1263. logDistance: '日志区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1264. hotKey: '快捷键',
  1265. doTaskKey: '做任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1266. undoTaskKey: '撤销任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1267. toggleLogKey: '显示/隐藏日志快捷键</br>(实时预览功能仅在设置页面可用)',
  1268. tasksHistory: '任务历史',
  1269. clearHistory: '清空历史',
  1270. clearHistoryFinished: '已清空任务历史!',
  1271. deleteTask: '删除任务',
  1272. lastChangeTime: '最后一次修改时间',
  1273. clearTaskFinished: '删除以下任务完成!',
  1274. clearTaskFailed: '删除任务失败,没有找到任务名!',
  1275. syncData: '数据同步',
  1276. settingData: '正在上传数据...',
  1277. gettingData: '正在获取数据...',
  1278. help: '帮助',
  1279. fileName: '文件名',
  1280. upload2gist: '同步到Gist',
  1281. downloadFromGist: '从Gist同步',
  1282. saveAndTest: '保存配置并测试',
  1283. testSuccess: '测试成功!',
  1284. testFailed: '测试失败!',
  1285. saveAndTestNotice: '请先保存配置并测试!',
  1286. processingData: '正在处理数据...',
  1287. updatingData: '正在上传数据...',
  1288. syncDataSuccess: '同步数据成功!',
  1289. syncDataFailed: '同步数据失败,请在控制台查看错误信息!',
  1290. downloadingData: '正在下载数据...',
  1291. checkedNoData: '没有检测到远程数据,请确认配置是否正确!',
  1292. savingData: '正在保存数据...',
  1293. syncHistory: '同步任务历史',
  1294. checkUpdateFailed: '检测更新失败',
  1295. newVersionNotice: '检测到新版本V%0, <a class="high-light" href="%1" target="_blank">点此更新</a>',
  1296. language: '语言</br>目前仅支持zh: 中文, en: 英文',
  1297. gistOptions: 'Gist 设置',
  1298. swalNotice: '检测到您第一次安装V4版本脚本,请前往阅读用前必读内容!',
  1299. echoNotice: '检测到您第一次安装V4版本脚本,请<a class="high-light" href="%0" target="_blank">点此前往</a>阅读用前必读内容!',
  1300. noticeLink: 'https://auto-task-doc.js.org/guide/#用前必读',
  1301. toGithub: '前往Github反馈',
  1302. toKeylol: '前往其乐论坛反馈',
  1303. copySuccess: '错误信息已复制到剪切板,是否前往其乐论坛反馈?',
  1304. copyFailed: '请复制下方错误信息后前往Keylol论坛反馈!',
  1305. updateText: '%0 版本更新内容:',
  1306. Active: '进行中',
  1307. Ended: '已结束',
  1308. Banned: '已封禁',
  1309. Paused: '已暂停',
  1310. notStart: '未开始',
  1311. noRemoteData: '检测到远程无数据',
  1312. errorRemoteDataFormat: '远程数据格式错误',
  1313. updateHistory: '历史更新记录<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">点此查看</a>',
  1314. AsfEnabled: '使用ASF做Steam相关任务(需<a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a>插件)',
  1315. AsfIpcUrl: 'ASF IPC 地址',
  1316. AsfIpcPassword: 'ASF IPC 密码',
  1317. versionNotMatched: '脚本管理器版本过低,需TamperMonkey >= 5.2.0或TamperMonkey Beta >= 5.2.6196',
  1318. groups: '组',
  1319. officialGroups: '官方组',
  1320. wishlists: '愿望单',
  1321. follows: '游戏关注',
  1322. forums: '论坛',
  1323. workshops: '创意工坊收藏',
  1324. curators: '鉴赏家',
  1325. workshopVotes: '创意工坊点赞',
  1326. announcements: '社区通知',
  1327. steamCommunity: 'Steam社区',
  1328. steamStore: 'Steam商店',
  1329. licenses: '入库免费游戏',
  1330. playtests: '请求访问权限',
  1331. needLoginSteamStore: '请先<a href="https://store.steampowered.com/login/" target="_blank">登录Steam商店</a>',
  1332. needLoginSteamCommunity: '请先<a href="https://steamcommunity.com/login/home/" target="_blank">登录Steam社区</a>',
  1333. joiningSteamGroup: '正在加入Steam组',
  1334. leavingSteamGroup: '正在退出Steam组',
  1335. gettingSteamGroupId: '正在获取Steam组Id',
  1336. joiningSteamOfficialGroup: '正在加入Steam官方组',
  1337. leavingSteamOfficialGroup: '正在退出Steam官方组',
  1338. gettingSteamOfficialGroupId: '正在获取Steam官方组Id',
  1339. subscribingForum: '正在订阅Steam论坛',
  1340. unsubscribingForum: '正在取消订阅Steam论坛',
  1341. gettingForumId: '正在获取Steam论坛Id',
  1342. followingCurator: '正在关注Steam鉴赏家',
  1343. unfollowingCurator: '正在取关Steam鉴赏家',
  1344. gettingCuratorId: '正在获取Steam鉴赏家Id',
  1345. addingToWishlist: '正在添加游戏到Steam愿望单',
  1346. removingFromWishlist: '正在从Steam愿望单移除游戏',
  1347. followingGame: '正在关注Steam游戏',
  1348. unfollowingGame: '正在取关Steam游戏',
  1349. favoritingWorkshop: '正在收藏Steam创意工坊物品',
  1350. unfavoritingWorkshop: '正在取消收藏Steam创意工坊物品',
  1351. gettingWorkshopAppId: '正在获取Steam创意工坊物品Id',
  1352. votingUpWorkshop: '正在点赞Steam创意工坊物品',
  1353. gettingAnnouncementParams: '正在获取Steam通知信息',
  1354. likingAnnouncement: '正在点赞Steam通知',
  1355. changingArea: '正在更换Steam地区: %0...',
  1356. notNeededChangeArea: '当前地区不需要更换',
  1357. noAnotherArea: '请检测是否开启正确开启代理',
  1358. gettingAreaInfo: '正在获取Steam地区信息...',
  1359. changeAreaNotice: '疑似锁区游戏,尝试换区执行',
  1360. steamFinishNotice: 'Steam任务完成,尝试将购物车地区换回CN',
  1361. gettingSubid: '正在获取游戏subid',
  1362. addingFreeLicense: '正在入库',
  1363. missParams: '缺少参数',
  1364. gettingLicenses: '正在获取Licenses...',
  1365. requestingPlayTestAccess: '正在请求访问权限',
  1366. tryChangeAreaNotice: '此功能无法检测游戏是否限区,因此会尝试换区后再入库,换区失败也不影响后续入库',
  1367. gettingUserLink: '正在获取Steam用户社区链接...',
  1368. retry: '重试',
  1369. owned: '已拥有',
  1370. redirect: '重定向',
  1371. initingASF: '正在初始化ASF...',
  1372. servers: '服务器',
  1373. joiningDiscordServer: '正在加入Discord服务器',
  1374. leavingDiscordServer: '正在退出Discord服务器',
  1375. gettingDiscordGuild: '正在获取Discord服务器Id',
  1376. getDiscordAuthFailed: '获取Discord凭证失败,请检测Discord帐号是否已登录',
  1377. discordImportantNotice: '重要提醒!!!',
  1378. discordImportantNoticeText: '由于Discord网站后台更新,目前使用此脚本加组后可能会导致Discord帐号被强制退出,且需要两步验证才能正常登录,请谨慎使用!!!',
  1379. continue: '继续',
  1380. skipDiscordTask: '跳过Discord任务',
  1381. continueAndDontRemindAgain: '继续且不再提醒',
  1382. users: '用户',
  1383. loginIns: '请先<a href="https://www.instagram.com/accounts/login/" target="_blank">登录Instagram</a>',
  1384. insBanned: '您的Instagram账户已被封禁',
  1385. verifyingInsAuth: '正在验证Instagram凭证...',
  1386. gettingInsUserId: '正在获取Instagram用户Id',
  1387. followingIns: '正在关注Instagram用户',
  1388. unfollowingIns: '正在取关Instagram用户',
  1389. reddits: '社区/用户',
  1390. loginReddit: '请先<a href="https://www.reddit.com/login/" target="_blank">登录Reddit</a>',
  1391. changingRedditVersion: '正在切换Reddit为新版页面...',
  1392. joiningReddit: '正在加入Reddit社区',
  1393. leavingReddit: '正在退出Reddit社区',
  1394. followingRedditUser: '正在关注Reddit用户',
  1395. unfollowingRedditUser: '正在取关Reddit用户',
  1396. channels: '频道',
  1397. followingTwitchChannel: '正在关注Twitch频道',
  1398. unfollowingTwitchChannel: '正在取关Twitch频道',
  1399. gettingTwitchChannelId: '正在获取Twitch频道Id',
  1400. checkingTwitchIntegrity: '正在检查Twitch完整性...',
  1401. twitterUser: '推特用户',
  1402. retweets: '转推',
  1403. gettingTwitterUserId: '正在获取推特用户Id',
  1404. followingTwitterUser: '正在关注推特用户',
  1405. unfollowingTwitterUser: '正在取关推特用户',
  1406. retweetting: '正在转推',
  1407. unretweetting: '正在撤销转推',
  1408. names: '组/社区/动态',
  1409. loginVk: '请先<a href="https://vk.com/login/" target="_blank">登录Vk</a>',
  1410. gettingVkId: '正在获取Vk任务Id',
  1411. joiningVkGroup: '正在加入Vk组',
  1412. leavingVkGroup: '正在退出Vk组',
  1413. joiningVkPublic: '正在加入Vk社区',
  1414. leavingVkPublic: '正在退出Vk社区',
  1415. sendingVkWall: '正在转发Vk动态',
  1416. deletingVkWall: '正在撤销转发Vk动态',
  1417. youtubeChannel: 'YouTube频道',
  1418. likes: '点赞',
  1419. loginYtb: '请先<a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">登录YouTube</a>',
  1420. tryUpdateYtbAuth: '请尝试<a href="https://www.youtube.com/#auth" target="_blank">更新YouTube凭证</a>',
  1421. gettingYtbToken: '正在获取YouTube Token...',
  1422. followingYtbChannel: '正在订阅YouTube频道',
  1423. unfollowingYtbChannel: '正在退订YouTube频道',
  1424. likingYtbVideo: '正在点赞YouTube视频',
  1425. unlikingYtbVideo: '正在取消点赞YouTube视频',
  1426. giveKeyNoticeBefore: '每次验证间隔15s',
  1427. giveKeyNoticeAfter: '如果没有key, 请在<a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>查看',
  1428. noPoints: '点数不够,跳过抽奖',
  1429. getNeedPointsFailed: '获取所需点数失败,跳过抽奖',
  1430. joiningLottery: '正在加入抽奖',
  1431. doingGleamTask: '正在做Gleam任务...',
  1432. gettingGleamLink: '正在获取Gleam任务链接...',
  1433. gleamTaskNotice: '如果此页面长时间未关闭,请完成任一任务后自行关闭!',
  1434. verifiedGleamTasks: '已尝试验证所有任务,验证失败的任务请尝试手动验证或完成!',
  1435. campaign: '检测到人机验证,请完成验证后重新验证任务!',
  1436. gsNotice: '为避免得到"0000-0000-0000"key, 已自动屏蔽"Grab Key"按钮,获取key时请关闭脚本!',
  1437. giveeClubVerifyNotice: '正在验证任务...',
  1438. giveeClubVerifyFinished: '请等待验证完成后自行加入赠Key',
  1439. doingKeyhubTask: '正在做Keyhub任务...',
  1440. SweepWidgetNotice: '正在处理并验证任务,每次验证任务有1~3s间隔防止触发验证过快警告...',
  1441. tasksNotCompleted: '任务未完成',
  1442. confirmingTask: '正在跳过警告页面...'
  1443. };
  1444. const zh_CN = data;
  1445. const en_US_data = {
  1446. website: 'Website',
  1447. type: 'Type',
  1448. edit: 'Edit',
  1449. whiteList: 'Whitelist',
  1450. skipTask: 'Skip undo task',
  1451. whiteListOptions: 'Whitelist options',
  1452. changeWhiteListOption: 'Whitelist option(%0)',
  1453. whiteListNotFound: 'Cannot find this whitelist: %0',
  1454. changeWhiteListSuccess: 'The whitelist is successfully modified, and the page refresh will take effect!',
  1455. changeWebsiteOptions: 'Website options',
  1456. changeGlobalOptions: 'Global options',
  1457. ok: 'OK',
  1458. save: 'Save',
  1459. close: 'Close',
  1460. return: 'Return',
  1461. option: 'Option',
  1462. value: 'Value',
  1463. websiteOptions: 'Current website settings',
  1464. changeWebsiteOptionsSuccess: 'The current website setting is changed successfully, and the page refresh will take effect!',
  1465. changeGlobalOptionsSuccess: 'The global setting is changed successfully, and the refresh will take effect!',
  1466. needLogin: 'Please log in first!',
  1467. getTasksInfo: 'Obtaining and processing task information...',
  1468. gettingKey: 'Getting Key...',
  1469. verifyingTask: 'Verifying task',
  1470. notice: 'Automatic task script notice',
  1471. noKeysLeft: 'There are no more keys left on this page. Do you want to close it?',
  1472. giveawayEnded: 'This event has ended, do you want to close it?',
  1473. 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?',
  1474. confirm: 'Confirm',
  1475. cancel: 'Cancel',
  1476. unKnown: 'Unknown',
  1477. unKnownTaskType: 'Unrecognized task',
  1478. doing: 'Doing a task',
  1479. allTasksComplete: 'All tasks have been completed!',
  1480. getTaskIdFailed: 'Failed to obtain task Id!',
  1481. initSuccess: '%0 was initialized successfully!',
  1482. initFailed: '%0 initialization failed!',
  1483. errorLink: 'Link error: %0',
  1484. needInit: 'Please initialize first',
  1485. verifyingAuth: 'Verifying %0 token...',
  1486. updatingAuth: 'Update %0 token...',
  1487. refreshingToken: 'Refreshing %0 token...',
  1488. settingToken: 'Setting %0 token...',
  1489. steamStoreTab: 'Steam store (new tab)',
  1490. steamCommunityTab: 'Steam community(new tab)',
  1491. initing: 'Initializing...',
  1492. getFailed: 'Failed to get %0!',
  1493. checkLoginFailed: 'Failed to detect login status!',
  1494. checkLeftKeyFailed: 'Failed to detect the remaining keys!',
  1495. userId: 'User Id',
  1496. joiningGiveaway: 'Joining giveaway',
  1497. needJoinGiveaway: 'Need to join the giveaway first',
  1498. cannotUndo: 'This website does not support canceling tasks',
  1499. verifyAuth: 'Verifying %0 token...',
  1500. closePageNotice: 'f this page does not close automatically, please close this page yourself.',
  1501. errorReport: 'A script error is detected, do you want to report the BUG?',
  1502. visitingLink: 'Visiting link: ',
  1503. doTask: 'DoTask',
  1504. undoTask: 'UndoTask',
  1505. verifyTask: 'Verify',
  1506. getKey: 'GetKey',
  1507. selectAll: 'SelectAll',
  1508. selectNone: 'SelectNone',
  1509. invertSelect: 'InvertSelect',
  1510. doFreeTask: 'FreeTask',
  1511. doPointTask: 'PointTask',
  1512. skipTaskOption: 'Skip task has been configured in the settings',
  1513. other: 'Other',
  1514. globalOptions: 'Global Options',
  1515. checkLogin: 'Login detection</br>Need to log in to the website automatically log in, part of this website supports.',
  1516. checkLeftKey: 'Key remaining detection</br>The end of the giveaway event prompts whether to close or not, part of this website supports.',
  1517. 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.',
  1518. 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.',
  1519. 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.',
  1520. saveGlobalOptions: 'SaveSettings',
  1521. settingPage: 'Setting Page',
  1522. name: 'Name',
  1523. version: 'Version',
  1524. scriptManager: 'Script Manager',
  1525. script: 'Script',
  1526. environment: 'Environment',
  1527. os: 'OS',
  1528. browser: 'Browser',
  1529. getId: 'Get %0 id',
  1530. getTwitterUserId: 'Get Twitter user id (Get id function is only available on the settings page).',
  1531. getYoutubeChannelId: 'Get Youtube channel id (Get id function is only available on the settings page).',
  1532. showButton: 'ShowButton',
  1533. hideButton: 'HideButton',
  1534. showLog: 'ShowLog',
  1535. hideLog: 'HideLog',
  1536. defaultShowButton: 'Default display button',
  1537. defaultShowLog: 'Display log by default',
  1538. debug: 'Output debug log, do not enable this option!',
  1539. receivePreview: 'Receive preview updates',
  1540. position: 'Component position',
  1541. buttonSideX: 'Horizontal positioning of the button area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1542. 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',
  1543. 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',
  1544. showButtonSideX: 'ShowButton horizontal positioning (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1545. showButtonSideY: 'ShowButton vertical positioning (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1546. 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',
  1547. logSideX: 'Horizontal positioning of the log area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1548. logSideY: 'Vertical positioning of the log area (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1549. 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',
  1550. hotKey: 'Shortcut key',
  1551. doTaskKey: 'DoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1552. undoTaskKey: 'UndoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1553. toggleLogKey: 'ShowLog/HideLog shortcut keys</br> (real-time preview function is only available on the settings page).',
  1554. tasksHistory: 'TasksHistory',
  1555. clearHistory: 'Clear history',
  1556. clearHistoryFinished: 'The mission history has been cleared!',
  1557. deleteTask: 'Delete task',
  1558. lastChangeTime: 'Last Change Time',
  1559. clearTaskFinished: 'Delete the following tasks completed!',
  1560. clearTaskFailed: 'Failed to delete the task, the task name was not found!',
  1561. syncData: 'DataSync',
  1562. settingData: 'Uploading data...',
  1563. gettingData: 'Getting data...',
  1564. help: 'Help',
  1565. fileName: 'Filename',
  1566. upload2gist: 'Sync to Gist',
  1567. downloadFromGist: 'Sync from Gist',
  1568. saveAndTest: 'Save configuration and test',
  1569. testSuccess: 'Test success!',
  1570. testFailed: 'Test failed!',
  1571. saveAndTestNotice: 'Please save the configuration and test first!',
  1572. processingData: 'Processing data...',
  1573. updatingData: 'Uploading data...',
  1574. syncDataSuccess: 'Synchronized data successfully!',
  1575. syncDataFailed: 'Failed to synchronize data, please check the error message on the console!',
  1576. downloadingData: 'Downloading data...',
  1577. checkedNoData: 'No remote data is detected, please confirm whether the configuration is correct!',
  1578. savingData: 'Saving data...',
  1579. syncHistory: 'Synchronize tasks history',
  1580. checkUpdateFailed: 'Check update failed',
  1581. newVersionNotice: 'Checked a new version V%0, <a class="high-light" href="%1" target="_blank">click to update</a>',
  1582. language: 'Language</br> Currently only supports zh: Chinese, en: English',
  1583. gistOptions: 'Gist Settings',
  1584. 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!',
  1585. 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!',
  1586. noticeLink: 'https://auto-task-doc.js.org/en/guide/#read-me-first',
  1587. toGithub: 'Feedback(Github)',
  1588. toKeylol: 'Feedback(Keylol)',
  1589. copySuccess: 'The error message has been copied to the clipboard. Do you want to go to the Keylol forum to give feedback?',
  1590. copyFailed: 'Please copy the error information below and report back to the Keylol forum!',
  1591. updateText: 'Updates in version %0:',
  1592. Active: 'Active',
  1593. Ended: 'Ended',
  1594. Banned: 'Banned',
  1595. Paused: 'Paused',
  1596. notStart: 'notStart',
  1597. noRemoteData: 'No data remotely',
  1598. errorRemoteDataFormat: 'Remote data has wrong format',
  1599. updateHistory: '<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">Click here</a>' + ' to view the historical update record.',
  1600. AsfEnabled: 'Use ASF to do Steam related tasks (requires <a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a> plugin)',
  1601. AsfIpcUrl: 'ASF IPC URL',
  1602. AsfIpcPassword: 'ASF IPC Password',
  1603. groups: 'Group',
  1604. officialGroups: 'Official Group',
  1605. wishlists: 'Wishlist',
  1606. follows: 'Follow Game',
  1607. forums: 'Forum',
  1608. workshops: 'Favorite Workshop',
  1609. curators: 'Curator',
  1610. workshopVotes: 'Voteup Workshop',
  1611. announcements: 'Announcement',
  1612. steamCommunity: 'Steam Community',
  1613. steamStore: 'Steam Store',
  1614. licenses: 'Add License',
  1615. playtests: 'Playtest Access',
  1616. needLoginSteamStore: 'Please <a href="https://store.steampowered.com/login/" target="_blank">log in to the Steam Store</a>',
  1617. needLoginSteamCommunity: 'Please <a href="https://steamcommunity.com/login/home/" target="_blank">log in to the Steam Community</a>',
  1618. joiningSteamGroup: 'Joining Steam Group',
  1619. leavingSteamGroup: 'Leaving Steam Group',
  1620. gettingSteamGroupId: 'Getting Steam Group Id',
  1621. joiningSteamOfficialGroup: 'Joining Steam Official Group',
  1622. leavingSteamOfficialGroup: 'Leaving Steam Official Group',
  1623. gettingSteamOfficialGroupId: 'Getting Steam Official Group Id',
  1624. subscribingForum: 'Subscribing the Steam Forum',
  1625. unsubscribingForum: 'Unsubscribing the Steam Forum',
  1626. gettingForumId: 'Getting Steam Forum Id',
  1627. followingCurator: 'Following Steam Curator',
  1628. unfollowingCurator: 'Unfollowing Steam Curator',
  1629. gettingCuratorId: 'Getting Steam Curator Id',
  1630. addingToWishlist: 'Adding the game to the Steam wishlist',
  1631. removingFromWishlist: 'Removing the game from the Steam wishlist',
  1632. followingGame: 'Following Steam games',
  1633. unfollowingGame: 'Unfollowing Steam games',
  1634. favoritingWorkshop: 'Favouring Steam Workshop Items',
  1635. unfavoritingWorkshop: 'Unfavoriting Steam Workshop Items',
  1636. gettingWorkshopAppId: 'Getting Steam Workshop Item Id',
  1637. votingUpWorkshop: 'Liking Steam workshop items',
  1638. gettingAnnouncementParams: 'Getting Steam announcement information',
  1639. likingAnnouncement: 'Liking Steam announcement',
  1640. changingArea: 'Changing Steam area: %0...',
  1641. notNeededChangeArea: 'The current area does not need to be changed',
  1642. noAnotherArea: 'Please check whether the proxy is turned on correctly',
  1643. gettingAreaInfo: 'Getting Steam area information...',
  1644. changeAreaNotice: 'Suspected of a locked zone game, try to change the zone to execute',
  1645. steamFinishNotice: 'Steam task completed, try to change the shopping cart area back to CN',
  1646. gettingSubid: 'Getting subid',
  1647. addingFreeLicense: 'Adding free license',
  1648. missParams: 'Missing parameters',
  1649. gettingLicenses: 'Getting licenses...',
  1650. requestingPlayTestAccess: 'Requesting play test access',
  1651. 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.',
  1652. versionNotMatched: 'The script manager version is too low, requiring TamperMonkey >= 5.2.0 or TamperMonkey Beta >= 5.2.6196',
  1653. gettingUserLink: 'Getting steam user community link...',
  1654. retry: 'Retry',
  1655. owned: 'Owned',
  1656. redirect: 'Redirect',
  1657. initingASF: 'Initing ASF...',
  1658. servers: 'Server',
  1659. joiningDiscordServer: 'Joining Discord Server',
  1660. leavingDiscordServer: 'Leaving Discord Server',
  1661. gettingDiscordGuild: 'Getting Discord server Id',
  1662. getDiscordAuthFailed: 'Failed to get Discord token, please check whether the Discord account is logged in',
  1663. discordImportantNotice: 'Important Reminder! ! !',
  1664. 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! ! !',
  1665. continue: 'Continue',
  1666. skipDiscordTask: 'Skip',
  1667. continueAndDontRemindAgain: 'Continue without Reminders',
  1668. users: 'User',
  1669. loginIns: 'Please <a href="https://www.instagram.com/accounts/login/" target="_blank">log in to Instagram</a>',
  1670. insBanned: 'Your Instagram account has been banned',
  1671. verifyingInsAuth: 'Verifying Instagram token...',
  1672. gettingInsUserId: 'Getting Instagram user Id',
  1673. followingIns: 'Following Instagram user',
  1674. unfollowingIns: 'Unfollowing Instagram user',
  1675. reddits: 'Reddit/User',
  1676. loginReddit: 'Please <a href="https://www.reddit.com/login/" target="_blank">log in to Reddit</a>',
  1677. changingRedditVersion: 'Switching Reddit to a new version page...',
  1678. joiningReddit: 'Joining the Reddit',
  1679. leavingReddit: 'Leaving the Reddit',
  1680. followingRedditUser: 'Following Reddit User',
  1681. unfollowingRedditUser: 'Unfollowing Reddit User',
  1682. channels: 'Channel',
  1683. followingTwitchChannel: 'Following Twitch Channel',
  1684. unfollowingTwitchChannel: 'Unfollowing Twitch Channel',
  1685. gettingTwitchChannelId: 'Getting Twitch Channel Id',
  1686. checkingTwitchIntegrity: 'Checking Twitch integrity...',
  1687. twitterUser: 'Twitter User',
  1688. retweets: 'Retweet',
  1689. gettingTwitterUserId: 'Getting Twitter User Id',
  1690. followingTwitterUser: 'Following Twitter User',
  1691. unfollowingTwitterUser: 'Unfollowing Twitter User',
  1692. retweetting: 'Retweetting',
  1693. unretweetting: 'Unretweetting',
  1694. names: 'Group/Public/Wall',
  1695. loginVk: 'Please <a href="https://vk.com/login/" target="_blank">log in to Vk</a>',
  1696. gettingVkId: 'Getting Vk task Id',
  1697. joiningVkGroup: 'Joining Vk Group',
  1698. leavingVkGroup: 'Leaving Vk Group',
  1699. joiningVkPublic: 'Joining Vk Public',
  1700. leavingVkPublic: 'Leaving Vk Public',
  1701. sendingVkWall: 'Sending Vk Wall',
  1702. deletingVkWall: 'Deleting Vk Wall',
  1703. youtubeChannel: 'YouTube Channel',
  1704. likes: 'Like',
  1705. loginYtb: 'Please <a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">log in to YouTube</a>',
  1706. tryUpdateYtbAuth: 'Please try to <a href="https://www.youtube.com/#auth" target="_blank">update YouTube token</a>',
  1707. gettingYtbToken: 'Getting YouTube Token...',
  1708. followingYtbChannel: 'Subscribing to YouTube channel',
  1709. unfollowingYtbChannel: 'Unsubscribing to YouTube channel',
  1710. likingYtbVideo: 'Liking YouTube video',
  1711. unlikingYtbVideo: 'Unliking YouTube video',
  1712. giveKeyNoticeBefore: 'Each verification interval is 15s',
  1713. giveKeyNoticeAfter: 'If there is no key, please check at <a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>',
  1714. noPoints: 'Not enough points, skip the lottery',
  1715. getNeedPointsFailed: 'ailed to obtain the required points, skip the lottery',
  1716. joiningLottery: 'Joining the lottery',
  1717. doingGleamTask: 'Doing Gleam Task...',
  1718. gettingGleamLink: 'Getting Gleam task link...',
  1719. gleamTaskNotice: 'If this page has not been closed for a long time, please close it yourself after completing any task!',
  1720. verifiedGleamTasks: 'Attempted to verify all tasks. If the verification fails, please try to verify manually or complete it!',
  1721. campaign: 'ReCAPTCHA detected, please complete it and re-verify the tasks!',
  1722. 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!',
  1723. giveeClubVerifyNotice: 'Verifying task...',
  1724. giveeClubVerifyFinished: 'Wait for the verification to complete and join it by yourself',
  1725. doingKeyhubTask: 'Doing Keyhub Task...',
  1726. 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...',
  1727. tasksNotCompleted: 'Tasks Not Completed',
  1728. confirmingTask: 'Confirming task...'
  1729. };
  1730. const en_US = en_US_data;
  1731. const languages = {
  1732. zh: zh_CN,
  1733. en: en_US
  1734. };
  1735. const language = [ 'zh', 'en' ].includes(globalOptions.other.language) ? globalOptions.other.language : 'en';
  1736. const I18n = (key, ...argvs) => {
  1737. if (!languages[language]?.[key]) {
  1738. return key;
  1739. }
  1740. return languages[language][key].replace(/%([\d]+)/g, (match, index) => argvs[parseInt(index, 10)]);
  1741. };
  1742. const i18n = I18n;
  1743. function throwError(error, name) {
  1744. if (window.TRACE) {
  1745. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  1746. }
  1747. external_Swal_default().fire({
  1748. title: i18n('errorReport'),
  1749. icon: 'error',
  1750. showCancelButton: true,
  1751. confirmButtonText: i18n('toGithub'),
  1752. showDenyButton: true,
  1753. denyButtonText: i18n('toKeylol'),
  1754. cancelButtonText: i18n('close')
  1755. }).then(({
  1756. isDenied,
  1757. isConfirmed
  1758. }) => {
  1759. if (isConfirmed) {
  1760. GM_openInTab(`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,
  1761. 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'))}`, {
  1762. active: true
  1763. });
  1764. } else if (isDenied) {
  1765. const text = `错误链接: [url=${window.location.href}]${window.location.href}[/url]
  1766.  
  1767. 环境:
  1768.  
  1769. [code]${JSON.stringify((0, javascript_utils_umd_min.ua)(), null, 4)}[/code]
  1770.  
  1771. 脚本管理器: ${GM_info.scriptHandler} ${GM_info.version}
  1772. 脚本版本: ${GM_info.script.version}
  1773.  
  1774. 报错信息:
  1775. [code]${error.stack}[/code]
  1776.  
  1777. 执行日志:
  1778. [code]${$.makeArray($('#auto-task-info>li')).map(element => element.innerText).join('\n')}[/code]`;
  1779. GM_setClipboard(text);
  1780. external_Swal_default().fire({
  1781. title: i18n('copySuccess'),
  1782. icon: 'success',
  1783. confirmButtonText: i18n('ok')
  1784. }).then(() => {
  1785. GM_openInTab('https://keylol.com/forum.php?mod=post&action=reply&fid=319&tid=777450', {
  1786. active: true
  1787. });
  1788. });
  1789. }
  1790. });
  1791. console.log('%c%s', 'color:white;background:red', `Auto-Task[Error]: ${name}\n${error.stack}`);
  1792. }
  1793. class Social {
  1794. tasks;
  1795. getRealParams(name, links, doTask, link2param) {
  1796. try {
  1797. let realParams = [];
  1798. if (links.length > 0) {
  1799. realParams = [ ...realParams, ...links.map(link => link2param(link)).filter(link => link) ];
  1800. }
  1801. if (!doTask && this.tasks[name].length > 0) {
  1802. realParams = [ ...realParams, ...this.tasks[name] ];
  1803. }
  1804. return unique(realParams);
  1805. } catch (error) {
  1806. throwError(error, 'Social.getRealParams');
  1807. return [];
  1808. }
  1809. }
  1810. }
  1811. const social_Social = Social;
  1812. class Discord extends social_Social {
  1813. tasks;
  1814. whiteList;
  1815. #auth = GM_getValue('discordAuth') || {};
  1816. #cache = GM_getValue('discordCache') || {};
  1817. #initialized = false;
  1818. constructor() {
  1819. super();
  1820. const defaultTasksTemplate = {
  1821. servers: []
  1822. };
  1823. this.tasks = defaultTasksTemplate;
  1824. this.whiteList = {
  1825. ...defaultTasksTemplate,
  1826. ...GM_getValue('whiteList')?.discord || {}
  1827. };
  1828. }
  1829. async init(action) {
  1830. try {
  1831. if (!GM_getValue('dontRemindDiscordAgain')) {
  1832. const result = await external_Swal_default().fire({
  1833. title: i18n('discordImportantNotice'),
  1834. text: i18n('discordImportantNoticeText'),
  1835. showCancelButton: true,
  1836. showDenyButton: true,
  1837. confirmButtonText: i18n('continue'),
  1838. cancelButtonText: i18n('skipDiscordTask'),
  1839. denyButtonText: i18n('continueAndDontRemindAgain')
  1840. }).then(({
  1841. isConfirmed,
  1842. isDenied
  1843. }) => {
  1844. if (isConfirmed) {
  1845. return true;
  1846. }
  1847. if (isDenied) {
  1848. GM_setValue('dontRemindDiscordAgain', true);
  1849. return true;
  1850. }
  1851. return false;
  1852. });
  1853. if (!result) {
  1854. this.#initialized = false;
  1855. return 'skip';
  1856. }
  1857. }
  1858. if (GM_getValue('dontRemindDiscordAgain') || action === 'do' && !globalOptions.doTask.discord.servers || action === 'undo' && !globalOptions.undoTask.discord.servers) {
  1859. this.#initialized = false;
  1860. return 'skip';
  1861. }
  1862. if (this.#initialized) {
  1863. return true;
  1864. }
  1865. if (!this.#auth.auth) {
  1866. if (await this.#updateAuth()) {
  1867. this.#initialized = true;
  1868. return true;
  1869. }
  1870. return false;
  1871. }
  1872. const isVerified = await this.#verifyAuth();
  1873. if (isVerified) {
  1874. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1875. this.#initialized = true;
  1876. return true;
  1877. }
  1878. GM_setValue('discordAuth', {
  1879. auth: null
  1880. });
  1881. if (await this.#updateAuth()) {
  1882. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1883. this.#initialized = true;
  1884. return true;
  1885. }
  1886. scripts_echoLog({}).error(i18n('initFailed', 'Discord'));
  1887. return false;
  1888. } catch (error) {
  1889. throwError(error, 'Discord.init');
  1890. return false;
  1891. }
  1892. }
  1893. async #verifyAuth() {
  1894. try {
  1895. const logStatus = scripts_echoLog({
  1896. text: i18n('verifyingAuth', 'Discord')
  1897. });
  1898. const {
  1899. result,
  1900. statusText,
  1901. status,
  1902. data
  1903. } = await tools_httpRequest({
  1904. url: 'https://discord.com/api/v6/users/@me',
  1905. method: 'HEAD',
  1906. headers: {
  1907. authorization: this.#auth.auth
  1908. }
  1909. });
  1910. if (result === 'Success') {
  1911. if (data?.status === 200) {
  1912. logStatus.success();
  1913. return true;
  1914. }
  1915. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  1916. return false;
  1917. }
  1918. logStatus.error(`${result}:${statusText}(${status})`);
  1919. return false;
  1920. } catch (error) {
  1921. throwError(error, 'Discord.verifyAuth');
  1922. return false;
  1923. }
  1924. }
  1925. async #updateAuth() {
  1926. try {
  1927. const logStatus = scripts_echoLog({
  1928. text: i18n('updatingAuth', 'Discord')
  1929. });
  1930. return await new Promise(resolve => {
  1931. const newTab = GM_openInTab('https://discord.com/channels/@me', {
  1932. active: true,
  1933. insert: true,
  1934. setParent: true
  1935. });
  1936. newTab.name = 'ATv4_discordAuth';
  1937. newTab.onclose = async () => {
  1938. const auth = GM_getValue('discordAuth')?.auth;
  1939. if (auth) {
  1940. this.#auth = {
  1941. auth: auth
  1942. };
  1943. logStatus.success();
  1944. resolve(await this.#verifyAuth());
  1945. } else {
  1946. logStatus.error('Error: Update discord auth failed!');
  1947. resolve(false);
  1948. }
  1949. };
  1950. });
  1951. } catch (error) {
  1952. throwError(error, 'Discord.updateAuth');
  1953. return false;
  1954. }
  1955. }
  1956. async #joinServer(inviteId) {
  1957. try {
  1958. const logStatus = scripts_echoLog({
  1959. type: 'joiningDiscordServer',
  1960. text: inviteId
  1961. });
  1962. const {
  1963. result,
  1964. statusText,
  1965. status,
  1966. data
  1967. } = await tools_httpRequest({
  1968. url: `https://discord.com/api/v9/invites/${inviteId}`,
  1969. method: 'POST',
  1970. dataType: 'json',
  1971. headers: {
  1972. authorization: this.#auth.auth,
  1973. origin: 'https://discord.com',
  1974. referer: `https://discord.com/invite/${inviteId}`
  1975. }
  1976. });
  1977. if (result === 'Success' && data?.status === 200) {
  1978. logStatus.success();
  1979. const guild = String(data.response?.guild?.id);
  1980. if (guild) {
  1981. this.#setCache(inviteId, guild);
  1982. this.tasks.servers = unique([ ...this.tasks.servers, inviteId ]);
  1983. }
  1984. return true;
  1985. }
  1986. logStatus.error(`${result}:${statusText}(${status})`);
  1987. return false;
  1988. } catch (error) {
  1989. throwError(error, 'Discord.joinServer');
  1990. return false;
  1991. }
  1992. }
  1993. async #leaveServer(inviteId) {
  1994. try {
  1995. if (this.whiteList.servers.includes(inviteId)) {
  1996. scripts_echoLog({
  1997. type: 'whiteList',
  1998. text: 'Discord.leaveServer',
  1999. id: inviteId
  2000. });
  2001. return true;
  2002. }
  2003. const guild = await this.#getGuild(inviteId);
  2004. if (!guild) {
  2005. return false;
  2006. }
  2007. const logStatus = scripts_echoLog({
  2008. type: 'leavingDiscordServer',
  2009. text: guild
  2010. });
  2011. const {
  2012. result,
  2013. statusText,
  2014. status,
  2015. data
  2016. } = await tools_httpRequest({
  2017. url: `https://discord.com/api/v9/users/@me/guilds/${guild}`,
  2018. method: 'DELETE',
  2019. headers: {
  2020. authorization: this.#auth.auth
  2021. }
  2022. });
  2023. if (result === 'Success' && data?.status === 204) {
  2024. logStatus.success();
  2025. return true;
  2026. }
  2027. logStatus.error(`${result}:${statusText}(${status})`);
  2028. return false;
  2029. } catch (error) {
  2030. throwError(error, 'Discord.leaveServer');
  2031. return false;
  2032. }
  2033. }
  2034. async #getGuild(inviteId) {
  2035. try {
  2036. const logStatus = scripts_echoLog({
  2037. type: 'gettingDiscordGuild',
  2038. text: inviteId
  2039. });
  2040. const guild = this.#cache[inviteId];
  2041. if (guild) {
  2042. logStatus.success();
  2043. return guild;
  2044. }
  2045. const {
  2046. result,
  2047. statusText,
  2048. status,
  2049. data
  2050. } = await tools_httpRequest({
  2051. url: `https://discord.com/api/v9/invites/${inviteId}`,
  2052. responseType: 'json',
  2053. method: 'GET'
  2054. });
  2055. if (result === 'Success' && data?.status === 200) {
  2056. const guild = data.response?.guild?.id;
  2057. if (guild) {
  2058. logStatus.success();
  2059. this.#setCache(inviteId, guild);
  2060. return guild;
  2061. }
  2062. logStatus.error(`${result}:${statusText}(${status})`);
  2063. return false;
  2064. }
  2065. logStatus.error(`${result}:${statusText}(${status})`);
  2066. return false;
  2067. } catch (error) {
  2068. throwError(error, 'Discord.getGuild');
  2069. return false;
  2070. }
  2071. }
  2072. async toggle({
  2073. doTask = true,
  2074. serverLinks = []
  2075. }) {
  2076. try {
  2077. if (!this.#initialized) {
  2078. scripts_echoLog({
  2079. text: i18n('needInit')
  2080. });
  2081. return false;
  2082. }
  2083. const prom = [];
  2084. if (doTask && !globalOptions.doTask.discord.servers || !doTask && !globalOptions.undoTask.discord.servers) {
  2085. scripts_echoLog({
  2086. type: 'globalOptionsSkip',
  2087. text: 'discord.servers'
  2088. });
  2089. } else {
  2090. const realServers = this.getRealParams('servers', serverLinks, doTask, link => link.match(/invite\/(.+)/)?.[1]);
  2091. if (realServers.length > 0) {
  2092. for (const server of realServers) {
  2093. if (doTask) {
  2094. prom.push(this.#joinServer(server));
  2095. } else {
  2096. prom.push(this.#leaveServer(server));
  2097. }
  2098. await delay(1e3);
  2099. }
  2100. }
  2101. }
  2102. return await Promise.all(prom).then(() => true);
  2103. } catch (error) {
  2104. throwError(error, 'Discord.toggleServers');
  2105. return false;
  2106. }
  2107. }
  2108. #setCache(inviteId, guild) {
  2109. try {
  2110. this.#cache[inviteId] = guild;
  2111. GM_setValue('discordCache', this.#cache);
  2112. } catch (error) {
  2113. throwError(error, 'Discord.setCache');
  2114. }
  2115. }
  2116. }
  2117. const social_Discord = Discord;
  2118. class Instagram extends social_Social {
  2119. tasks;
  2120. whiteList;
  2121. #cache = GM_getValue('instagramCache') || {};
  2122. #auth = {};
  2123. #initialized = false;
  2124. constructor() {
  2125. super();
  2126. const defaultTasksTemplate = {
  2127. users: []
  2128. };
  2129. this.tasks = defaultTasksTemplate;
  2130. this.whiteList = {
  2131. ...defaultTasksTemplate,
  2132. ...GM_getValue('whiteList')?.instagram || {}
  2133. };
  2134. }
  2135. async init() {
  2136. try {
  2137. if (this.#initialized) {
  2138. return true;
  2139. }
  2140. const isVerified = await this.#getUserInfo();
  2141. if (isVerified) {
  2142. scripts_echoLog({}).success(i18n('initSuccess', 'Instagram'));
  2143. this.#initialized = true;
  2144. return true;
  2145. }
  2146. scripts_echoLog({}).error(i18n('initFailed', 'Instagram'));
  2147. return false;
  2148. } catch (error) {
  2149. throwError(error, 'Instagram.init');
  2150. return false;
  2151. }
  2152. }
  2153. async #getUserInfo(name = 'instagram') {
  2154. try {
  2155. const logStatus = scripts_echoLog({
  2156. type: name === 'instagram' ? 'verifyingInsAuth' : 'gettingInsUserId',
  2157. text: name
  2158. });
  2159. const userId = this.#cache[name];
  2160. if (userId && name !== 'instagram') {
  2161. logStatus.success();
  2162. return userId;
  2163. }
  2164. const {
  2165. result,
  2166. statusText,
  2167. status,
  2168. data
  2169. } = await tools_httpRequest({
  2170. url: `https://www.instagram.com/${name}/`,
  2171. method: 'GET'
  2172. });
  2173. if (result === 'Success') {
  2174. if (data?.finalUrl.includes('accounts/login')) {
  2175. logStatus.error(`Error:${i18n('loginIns')}`, true);
  2176. return false;
  2177. } else if (data?.finalUrl.includes('www.instagram.com/challenge')) {
  2178. logStatus.error(`Error:${i18n('insBanned')}`);
  2179. return false;
  2180. }
  2181. if (data?.status === 200) {
  2182. const csrftoken = data.responseText.match(/"csrf_token":"(.+?)"/)?.[1];
  2183. const hash = data.responseText.match(/"rollout_hash":"(.+?)"/)?.[1];
  2184. if (name === 'instagram') {
  2185. if (csrftoken && hash) {
  2186. this.#auth = {
  2187. csrftoken: csrftoken,
  2188. hash: hash
  2189. };
  2190. return true;
  2191. }
  2192. return false;
  2193. }
  2194. const id = data.responseText.match(/"profilePage_([\d]+?)"/)?.[1];
  2195. if (id) {
  2196. this.#setCache(name, id);
  2197. logStatus.success();
  2198. return id;
  2199. }
  2200. logStatus.error('Error: Get ins data error!');
  2201. return false;
  2202. }
  2203. logStatus.error(`${result}:${statusText}(${status})`);
  2204. return false;
  2205. }
  2206. return false;
  2207. } catch (error) {
  2208. throwError(error, 'Instagram.getUserInfo');
  2209. return false;
  2210. }
  2211. }
  2212. async #followUser(name) {
  2213. try {
  2214. const id = await this.#getUserInfo(name);
  2215. if (!id) {
  2216. return false;
  2217. }
  2218. const logStatus = scripts_echoLog({
  2219. type: 'followingIns',
  2220. text: name
  2221. });
  2222. const {
  2223. result,
  2224. statusText,
  2225. status,
  2226. data
  2227. } = await tools_httpRequest({
  2228. url: `https://www.instagram.com/web/friendships/${id}/follow/`,
  2229. method: 'POST',
  2230. dataType: 'json',
  2231. headers: {
  2232. 'x-csrftoken': this.#auth.csrftoken,
  2233. origin: 'https://www.instagram.com',
  2234. referer: `https://www.instagram.com/${name}/`,
  2235. 'content-type': 'application/x-www-form-urlencoded',
  2236. 'sec-fetch-site': 'same-origin',
  2237. 'x-instagram-ajax': this.#auth.hash
  2238. }
  2239. });
  2240. if (result === 'Success') {
  2241. if (data?.status === 200 && data.response?.result === 'following') {
  2242. logStatus.success();
  2243. this.tasks.users = unique([ ...this.tasks.users, name ]);
  2244. return true;
  2245. }
  2246. logStatus.error(`Error:${data?.response?.feedback_message || `${data?.statusText}(${data?.status})`}`);
  2247. return false;
  2248. }
  2249. logStatus.error(`${result}:${statusText}(${status})`);
  2250. return false;
  2251. } catch (error) {
  2252. throwError(error, 'Instagram.followUser');
  2253. return false;
  2254. }
  2255. }
  2256. async #unfollowUser(name) {
  2257. try {
  2258. if (this.whiteList.users.includes(name)) {
  2259. scripts_echoLog({
  2260. type: 'whiteList',
  2261. text: 'Instagram.unfollowUser',
  2262. id: name
  2263. });
  2264. return true;
  2265. }
  2266. const id = await this.#getUserInfo(name);
  2267. if (!id) {
  2268. return false;
  2269. }
  2270. const logStatus = scripts_echoLog({
  2271. type: 'unfollowingIns',
  2272. text: name
  2273. });
  2274. const {
  2275. result,
  2276. statusText,
  2277. status,
  2278. data
  2279. } = await tools_httpRequest({
  2280. url: `https://www.instagram.com/web/friendships/${id}/unfollow/`,
  2281. method: 'POST',
  2282. dataType: 'json',
  2283. headers: {
  2284. 'x-csrftoken': this.#auth.csrftoken,
  2285. origin: 'https://www.instagram.com',
  2286. referer: `https://www.instagram.com/${name}/`,
  2287. 'content-type': 'application/x-www-form-urlencoded',
  2288. 'sec-fetch-site': 'same-origin',
  2289. 'x-instagram-ajax': this.#auth.hash
  2290. }
  2291. });
  2292. if (result === 'Success') {
  2293. if (data?.status === 200 && data.response?.status === 'ok') {
  2294. logStatus.success();
  2295. return true;
  2296. }
  2297. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2298. return false;
  2299. }
  2300. logStatus.error(`${result}:${statusText}(${status})`);
  2301. return false;
  2302. } catch (error) {
  2303. throwError(error, 'Instagram.unfollowUser');
  2304. return false;
  2305. }
  2306. }
  2307. async toggle({
  2308. doTask = true,
  2309. userLinks = []
  2310. }) {
  2311. try {
  2312. if (!this.#initialized) {
  2313. scripts_echoLog({
  2314. text: i18n('needInit')
  2315. });
  2316. return false;
  2317. }
  2318. const prom = [];
  2319. if (doTask && !globalOptions.doTask.instagram.users || !doTask && !globalOptions.undoTask.instagram.users) {
  2320. scripts_echoLog({
  2321. type: 'globalOptionsSkip',
  2322. text: 'instagram.users'
  2323. });
  2324. } else {
  2325. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1]);
  2326. if (realUsers.length > 0) {
  2327. for (const username of realUsers) {
  2328. if (doTask) {
  2329. prom.push(this.#followUser(username));
  2330. } else {
  2331. prom.push(this.#unfollowUser(username));
  2332. }
  2333. await delay(1e3);
  2334. }
  2335. }
  2336. }
  2337. return await Promise.all(prom).then(() => true);
  2338. } catch (error) {
  2339. throwError(error, 'Instagram.toggleUsers');
  2340. return false;
  2341. }
  2342. }
  2343. #setCache(name, id) {
  2344. try {
  2345. this.#cache[name] = id;
  2346. GM_setValue('instagramCache', this.#cache);
  2347. } catch (error) {
  2348. throwError(error, 'Instagram.setCache');
  2349. }
  2350. }
  2351. }
  2352. const social_Instagram = Instagram;
  2353. class Reddit extends social_Social {
  2354. tasks;
  2355. whiteList;
  2356. #auth;
  2357. #initialized = false;
  2358. constructor() {
  2359. super();
  2360. const defaultTasksTemplate = {
  2361. reddits: []
  2362. };
  2363. this.tasks = defaultTasksTemplate;
  2364. this.whiteList = {
  2365. ...defaultTasksTemplate,
  2366. ...GM_getValue('whiteList')?.reddit || {}
  2367. };
  2368. }
  2369. async init() {
  2370. try {
  2371. if (this.#initialized) {
  2372. return true;
  2373. }
  2374. const isVerified = await this.#updateAuth();
  2375. if (isVerified) {
  2376. scripts_echoLog({}).success(i18n('initSuccess', 'Reddit'));
  2377. this.#initialized = true;
  2378. return true;
  2379. }
  2380. scripts_echoLog({}).error(i18n('initFailed', 'Reddit'));
  2381. return false;
  2382. } catch (error) {
  2383. throwError(error, 'Reddit.init');
  2384. return false;
  2385. }
  2386. }
  2387. async #useBeta() {
  2388. try {
  2389. const logStatus = scripts_echoLog({
  2390. text: i18n('changingRedditVersion')
  2391. });
  2392. return await new Promise(resolve => {
  2393. const newTab = GM_openInTab('https://www.reddit.com/', {
  2394. active: true,
  2395. insert: true,
  2396. setParent: true
  2397. });
  2398. newTab.name = 'ATv4_redditAuth';
  2399. newTab.onclose = async () => {
  2400. logStatus.success();
  2401. resolve(await this.#updateAuth(true));
  2402. };
  2403. });
  2404. } catch (error) {
  2405. throwError(error, 'Reddit.useBeta');
  2406. return false;
  2407. }
  2408. }
  2409. async #updateAuth(beta = false) {
  2410. try {
  2411. const logStatus = scripts_echoLog({
  2412. text: i18n('updatingAuth', 'Reddit')
  2413. });
  2414. const {
  2415. result,
  2416. statusText,
  2417. status,
  2418. data
  2419. } = await tools_httpRequest({
  2420. url: 'https://www.reddit.com/',
  2421. method: 'GET',
  2422. nochche: true,
  2423. headers: {
  2424. 'Cache-Control': 'no-cache'
  2425. }
  2426. });
  2427. if (result === 'Success') {
  2428. if (data?.responseText.includes('www.reddit.com/login/')) {
  2429. logStatus.error(`Error:${i18n('loginReddit')}`, true);
  2430. return false;
  2431. }
  2432. if (data?.status === 200) {
  2433. if (data.responseText.includes('redesign-beta-optin-btn') && !beta) {
  2434. return await this.#useBeta();
  2435. }
  2436. const accessToken = data.responseText.match(/"accessToken":"(.*?)","expires":"(.*?)"/)?.[1];
  2437. if (accessToken) {
  2438. this.#auth = {
  2439. token: accessToken
  2440. };
  2441. logStatus.success();
  2442. return true;
  2443. }
  2444. logStatus.error('Error: Parameter "accessToken" not found!');
  2445. return false;
  2446. }
  2447. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2448. return false;
  2449. }
  2450. logStatus.error(`${result}:${statusText}(${status})`);
  2451. return false;
  2452. } catch (error) {
  2453. throwError(error, 'Reddit.updateAuth');
  2454. return false;
  2455. }
  2456. }
  2457. async #toggleTask({
  2458. name,
  2459. doTask = true
  2460. }) {
  2461. try {
  2462. if (!doTask && this.whiteList.reddits.includes(name)) {
  2463. scripts_echoLog({
  2464. type: 'whiteList',
  2465. text: 'Reddit.undoTask',
  2466. id: name
  2467. });
  2468. return true;
  2469. }
  2470. let type = doTask ? 'joiningReddit' : 'leavingReddit';
  2471. if (/^u_/.test(name)) {
  2472. type = doTask ? 'followingRedditUser' : 'unfollowingRedditUser';
  2473. }
  2474. const logStatus = scripts_echoLog({
  2475. type: type,
  2476. text: name
  2477. });
  2478. const {
  2479. result,
  2480. statusText,
  2481. status,
  2482. data
  2483. } = await tools_httpRequest({
  2484. url: 'https://oauth.reddit.com/api/subscribe?redditWebClient=desktop2x&app=desktop2x-client-production&raw_json=1&gilding_detail=1',
  2485. method: 'POST',
  2486. headers: {
  2487. authorization: `Bearer ${this.#auth.token}`,
  2488. 'content-type': 'application/x-www-form-urlencoded'
  2489. },
  2490. data: $.param({
  2491. action: doTask ? 'sub' : 'unsub',
  2492. sr_name: name,
  2493. api_type: 'json'
  2494. })
  2495. });
  2496. if (result === 'Success') {
  2497. if (data?.status === 200) {
  2498. logStatus.success();
  2499. if (doTask) {
  2500. this.tasks.reddits = unique([ ...this.tasks.reddits, name ]);
  2501. }
  2502. return true;
  2503. }
  2504. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2505. return false;
  2506. }
  2507. logStatus.error(`${result}:${statusText}(${status})`);
  2508. return false;
  2509. } catch (error) {
  2510. throwError(error, 'Reddit.toggleTask');
  2511. return false;
  2512. }
  2513. }
  2514. async toggle({
  2515. doTask = true,
  2516. redditLinks = []
  2517. }) {
  2518. try {
  2519. if (!this.#initialized) {
  2520. scripts_echoLog({
  2521. text: i18n('needInit')
  2522. });
  2523. return false;
  2524. }
  2525. const prom = [];
  2526. if (doTask && !globalOptions.doTask.reddit.reddits || !doTask && !globalOptions.undoTask.reddit.reddits) {
  2527. scripts_echoLog({
  2528. type: 'globalOptionsSkip',
  2529. text: 'reddit.reddits'
  2530. });
  2531. } else {
  2532. const realReddits = this.getRealParams('reddits', redditLinks, doTask, link => {
  2533. const name = link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1];
  2534. const userName = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1];
  2535. if (userName) {
  2536. return name || userName;
  2537. }
  2538. return name;
  2539. });
  2540. if (realReddits.length > 0) {
  2541. for (const name of realReddits) {
  2542. prom.push(this.#toggleTask({
  2543. name: name,
  2544. doTask: doTask
  2545. }));
  2546. await delay(1e3);
  2547. }
  2548. }
  2549. }
  2550. return await Promise.all(prom).then(() => true);
  2551. } catch (error) {
  2552. throwError(error, 'Reddit.toggle');
  2553. return false;
  2554. }
  2555. }
  2556. }
  2557. const social_Reddit = Reddit;
  2558. class Twitch extends social_Social {
  2559. tasks;
  2560. whiteList;
  2561. #auth = GM_getValue('twitchAuth') || {};
  2562. #cache = GM_getValue('twitchCache') || {};
  2563. #initialized = false;
  2564. #integrityToken;
  2565. constructor() {
  2566. super();
  2567. const defaultTasksTemplate = {
  2568. channels: []
  2569. };
  2570. this.tasks = defaultTasksTemplate;
  2571. this.whiteList = {
  2572. ...defaultTasksTemplate,
  2573. ...GM_getValue('whiteList')?.twitch || {}
  2574. };
  2575. }
  2576. async init() {
  2577. try {
  2578. if (this.#initialized) {
  2579. return true;
  2580. }
  2581. if (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId) {
  2582. if (await this.#updateAuth()) {
  2583. this.#initialized = true;
  2584. return true;
  2585. }
  2586. return false;
  2587. }
  2588. const isVerified = await this.#verifyAuth(true);
  2589. if (isVerified) {
  2590. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2591. this.#initialized = true;
  2592. return true;
  2593. }
  2594. GM_setValue('twitchAuth', null);
  2595. if (await this.#updateAuth()) {
  2596. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2597. this.#initialized = true;
  2598. return true;
  2599. }
  2600. scripts_echoLog({}).error(i18n('initFailed', 'Twitch'));
  2601. return false;
  2602. } catch (error) {
  2603. throwError(error, 'Twitch.init');
  2604. return false;
  2605. }
  2606. }
  2607. async #verifyAuth(isFirst) {
  2608. try {
  2609. const logStatus = scripts_echoLog({
  2610. text: i18n('verifyingAuth', 'Twitch')
  2611. });
  2612. const {
  2613. result,
  2614. statusText,
  2615. status,
  2616. data
  2617. } = await tools_httpRequest({
  2618. url: 'https://gql.twitch.tv/gql',
  2619. method: 'POST',
  2620. dataType: 'json',
  2621. headers: {
  2622. Authorization: `OAuth ${this.#auth.authToken}`,
  2623. 'Client-Id': this.#auth.clientId
  2624. },
  2625. data: '[{"operationName":"FrontPageNew_User","variables":{"limit":1},"extensions":{"persistedQuery":{"version":1,' + '"sha256Hash":"64bd07a2cbaca80699d62636d966cf6395a5d14a1f0a14282067dcb28b13eb11"}}}]'
  2626. });
  2627. if (result === 'Success') {
  2628. if (data?.status === 200 && data.response?.[0]?.data?.currentUser) {
  2629. await this.#integrity(isFirst);
  2630. logStatus.success();
  2631. return true;
  2632. }
  2633. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2634. return false;
  2635. }
  2636. logStatus.error(`${result}:${statusText}(${status})`);
  2637. return false;
  2638. } catch (error) {
  2639. throwError(error, 'Twitch.verifyAuth');
  2640. return false;
  2641. }
  2642. }
  2643. async #integrity(isFirst = true, ct = '') {
  2644. try {
  2645. const logStatus = scripts_echoLog({
  2646. text: i18n('checkingTwitchIntegrity')
  2647. });
  2648. if (isFirst && (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId)) {
  2649. return await this.#updateAuth(false);
  2650. }
  2651. const {
  2652. result,
  2653. statusText,
  2654. status,
  2655. data
  2656. } = await tools_httpRequest({
  2657. url: 'https://gql.twitch.tv/integrity',
  2658. method: 'POST',
  2659. dataType: 'json',
  2660. anonymous: true,
  2661. headers: {
  2662. Origin: 'https://www.twitch.tv',
  2663. Referer: 'https://www.twitch.tv/',
  2664. Authorization: `OAuth ${this.#auth.authToken}`,
  2665. 'Client-Id': this.#auth.clientId,
  2666. 'Client-Version': this.#auth.clientVersion,
  2667. 'X-Device-Id': this.#auth.deviceId,
  2668. 'Client-Session-Id': this.#auth.clientSessionId,
  2669. 'x-kpsdk-ct': ct
  2670. }
  2671. });
  2672. if (result === 'Success') {
  2673. if (!ct && data?.responseHeaders?.['x-kpsdk-ct']) {
  2674. return await this.#integrity(isFirst, data.responseHeaders['x-kpsdk-ct']);
  2675. }
  2676. if (data?.status === 200 && data.response?.token) {
  2677. this.#integrityToken = data.response.token;
  2678. logStatus.success();
  2679. return true;
  2680. }
  2681. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2682. return false;
  2683. }
  2684. logStatus.error(`${result}:${statusText}(${status})`);
  2685. return false;
  2686. } catch (error) {
  2687. throwError(error, 'Twitch.integrity');
  2688. return false;
  2689. }
  2690. }
  2691. async #updateAuth(isFirst = true) {
  2692. try {
  2693. const logStatus = scripts_echoLog({
  2694. text: i18n('updatingAuth', 'Twitch')
  2695. });
  2696. return await new Promise(resolve => {
  2697. const newTab = GM_openInTab('https://www.twitch.tv/', {
  2698. active: true,
  2699. insert: true,
  2700. setParent: true
  2701. });
  2702. newTab.name = 'ATv4_twitchAuth';
  2703. newTab.onclose = async () => {
  2704. const auth = GM_getValue('twitchAuth');
  2705. if (auth) {
  2706. this.#auth = auth;
  2707. logStatus.success();
  2708. resolve(await this.#verifyAuth(isFirst));
  2709. } else {
  2710. logStatus.error('Error: Update twitch auth failed!');
  2711. resolve(false);
  2712. }
  2713. };
  2714. });
  2715. } catch (error) {
  2716. throwError(error, 'Twitch.updateAuth');
  2717. return false;
  2718. }
  2719. }
  2720. async #toggleChannel({
  2721. name,
  2722. doTask = true
  2723. }) {
  2724. try {
  2725. if (!doTask && this.whiteList.channels.includes(name)) {
  2726. scripts_echoLog({
  2727. type: 'whiteList',
  2728. text: 'Twitch.unfollowChannel',
  2729. id: name
  2730. });
  2731. return true;
  2732. }
  2733. const channelId = await this.#getChannelId(name);
  2734. if (!channelId) {
  2735. return false;
  2736. }
  2737. const logStatus = scripts_echoLog({
  2738. type: `${doTask ? '' : 'un'}followingTwitchChannel`,
  2739. text: name
  2740. });
  2741. const followData = `[{"operationName":"FollowButton_FollowUser","variables":{"input":{"disableNotifications":false,"targetID":"${channelId}` + '"}},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"800e7346bdf7e5278a3c1d3f21b2b56e2639928f86815677a7126b093b2fdd08"}}}]';
  2742. const unfollowData = `[{"operationName":"FollowButton_UnfollowUser","variables":{"input":{"targetID":"${channelId}"}},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"f7dae976ebf41c755ae2d758546bfd176b4eeb856656098bb40e0a672ca0d880"}}}]';
  2743. const {
  2744. result,
  2745. statusText,
  2746. status,
  2747. data
  2748. } = await tools_httpRequest({
  2749. url: 'https://gql.twitch.tv/gql',
  2750. method: 'POST',
  2751. dataType: 'json',
  2752. anonymous: true,
  2753. headers: {
  2754. Origin: 'https://www.twitch.tv',
  2755. Referer: 'https://www.twitch.tv/',
  2756. Authorization: `OAuth ${this.#auth.authToken}`,
  2757. 'Client-Id': this.#auth.clientId,
  2758. 'Client-Version': this.#auth.clientVersion,
  2759. 'X-Device-Id': this.#auth.deviceId,
  2760. 'Client-Session-Id': this.#auth.clientSessionId,
  2761. 'Client-Integrity': this.#integrityToken
  2762. },
  2763. data: doTask ? followData : unfollowData
  2764. });
  2765. if (result === 'Success') {
  2766. if (data?.status === 200 && data.response?.[0] && !data.response[0].errors) {
  2767. logStatus.success();
  2768. if (doTask) {
  2769. this.tasks.channels = unique([ ...this.tasks.channels, name ]);
  2770. }
  2771. return true;
  2772. }
  2773. logStatus.error(`Error:${data?.response?.[0].errors?.[0]?.message || `${data?.statusText}(${data?.status})`}`);
  2774. return false;
  2775. }
  2776. logStatus.error(`${result}:${statusText}(${status})`);
  2777. return false;
  2778. } catch (error) {
  2779. throwError(error, 'Twitch.toggleChannel');
  2780. return false;
  2781. }
  2782. }
  2783. async #getChannelId(name) {
  2784. try {
  2785. const logStatus = scripts_echoLog({
  2786. type: 'gettingTwitchChannelId',
  2787. text: name
  2788. });
  2789. const channelId = this.#cache[name];
  2790. if (channelId) {
  2791. logStatus.success();
  2792. return channelId;
  2793. }
  2794. const {
  2795. result,
  2796. statusText,
  2797. status,
  2798. data
  2799. } = await tools_httpRequest({
  2800. url: 'https://gql.twitch.tv/gql',
  2801. method: 'POST',
  2802. headers: {
  2803. Authorization: `OAuth ${this.#auth.authToken}`,
  2804. 'Client-Id': this.#auth.clientId
  2805. },
  2806. responseType: 'json',
  2807. data: `[{"operationName":"ActiveWatchParty","variables":{"channelLogin":"${name}"},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"4a8156c97b19e3a36e081cf6d6ddb5dbf9f9b02ae60e4d2ff26ed70aebc80a30"}}}]'
  2808. });
  2809. if (result === 'Success') {
  2810. if (data?.status === 200) {
  2811. const channelId = data.response?.[0]?.data?.user?.id;
  2812. if (channelId) {
  2813. this.#setCache(name, String(channelId));
  2814. logStatus.success();
  2815. return channelId;
  2816. }
  2817. logStatus.error(`Error:${data.statusText}(${data.status})`);
  2818. return false;
  2819. }
  2820. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2821. return false;
  2822. }
  2823. logStatus.error(`${result}:${statusText}(${status})`);
  2824. return false;
  2825. } catch (error) {
  2826. throwError(error, 'Twitch.getChannelId');
  2827. return false;
  2828. }
  2829. }
  2830. async toggle({
  2831. doTask = true,
  2832. channelLinks = []
  2833. }) {
  2834. try {
  2835. if (!this.#initialized) {
  2836. scripts_echoLog({
  2837. text: i18n('needInit')
  2838. });
  2839. return false;
  2840. }
  2841. const prom = [];
  2842. if (doTask && !globalOptions.doTask.twitch.channels || !doTask && !globalOptions.undoTask.twitch.channels) {
  2843. scripts_echoLog({
  2844. type: 'globalOptionsSkip',
  2845. text: 'twitch.channels'
  2846. });
  2847. } else {
  2848. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2]);
  2849. if (realChannels.length > 0) {
  2850. for (const channel of realChannels) {
  2851. prom.push(this.#toggleChannel({
  2852. name: channel,
  2853. doTask: doTask
  2854. }));
  2855. await delay(1e3);
  2856. }
  2857. }
  2858. }
  2859. return Promise.all(prom).then(() => true);
  2860. } catch (error) {
  2861. throwError(error, 'Twitch.toggle');
  2862. return false;
  2863. }
  2864. }
  2865. #setCache(name, id) {
  2866. try {
  2867. this.#cache[name] = id;
  2868. GM_setValue('twitchCache', this.#cache);
  2869. } catch (error) {
  2870. throwError(error, 'Twitch.setCache');
  2871. }
  2872. }
  2873. }
  2874. const social_Twitch = Twitch;
  2875. class Twitter extends social_Social {
  2876. tasks;
  2877. whiteList;
  2878. #verifyId = globalOptions.other.twitterVerifyId;
  2879. #auth = GM_getValue('twitterAuth') || {};
  2880. #cache = GM_getValue('twitterCache') || {};
  2881. #initialized = false;
  2882. constructor() {
  2883. super();
  2884. const defaultTasksTemplate = {
  2885. users: [],
  2886. retweets: [],
  2887. likes: []
  2888. };
  2889. this.tasks = defaultTasksTemplate;
  2890. this.whiteList = {
  2891. ...defaultTasksTemplate,
  2892. ...GM_getValue('whiteList')?.twitter || {}
  2893. };
  2894. }
  2895. async init() {
  2896. try {
  2897. if (this.#initialized) {
  2898. return true;
  2899. }
  2900. if (!this.#auth.ct0) {
  2901. if (await this.#updateAuth()) {
  2902. this.#initialized = true;
  2903. return true;
  2904. }
  2905. return false;
  2906. }
  2907. const isVerified = await this.#verifyAuth();
  2908. if (isVerified) {
  2909. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2910. this.#initialized = true;
  2911. return true;
  2912. }
  2913. GM_setValue('twitterAuth', null);
  2914. if (await this.#updateAuth()) {
  2915. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2916. this.#initialized = true;
  2917. return true;
  2918. }
  2919. scripts_echoLog({}).error(i18n('initFailed', 'Twitter'));
  2920. return false;
  2921. } catch (error) {
  2922. throwError(error, 'Twitter.init');
  2923. return false;
  2924. }
  2925. }
  2926. async #verifyAuth() {
  2927. try {
  2928. return await this.#toggleUser({
  2929. name: 'verify',
  2930. doTask: true,
  2931. verify: true
  2932. });
  2933. } catch (error) {
  2934. throwError(error, 'Twitter.verifyAuth');
  2935. return false;
  2936. }
  2937. }
  2938. async #updateAuth() {
  2939. try {
  2940. const logStatus = scripts_echoLog({
  2941. text: i18n('updatingAuth', 'Twitter')
  2942. });
  2943. return await new Promise(resolve => {
  2944. GM_cookie.list({
  2945. url: 'https://x.com/settings/account'
  2946. }, async (cookies, error) => {
  2947. if (!error) {
  2948. const [ ct0, isLogin ] = cookies.map(cookie => [ 'ct0', 'twid' ].includes(cookie.name) ? cookie.value : null).filter(cookie => cookie);
  2949. if (isLogin && ct0) {
  2950. GM_setValue('twitterAuth', {
  2951. ct0: ct0
  2952. });
  2953. this.#auth = {
  2954. ct0: ct0
  2955. };
  2956. logStatus.success();
  2957. resolve(await this.#verifyAuth());
  2958. } else {
  2959. logStatus.error(i18n('needLogin'));
  2960. resolve(false);
  2961. }
  2962. } else {
  2963. logStatus.error('Error: Update twitter auth failed!');
  2964. resolve(false);
  2965. }
  2966. });
  2967. });
  2968. } catch (error) {
  2969. throwError(error, 'Twitter.updateToken');
  2970. return false;
  2971. }
  2972. }
  2973. async #toggleUser({
  2974. name,
  2975. doTask = true,
  2976. verify = false
  2977. }) {
  2978. try {
  2979. if (!doTask && !verify && this.whiteList.users.includes(name)) {
  2980. scripts_echoLog({
  2981. type: 'whiteList',
  2982. text: 'Twitter.unfollowUser',
  2983. id: name
  2984. });
  2985. return true;
  2986. }
  2987. const userId = verify ? this.#verifyId : await this.userName2id(name);
  2988. if (!userId) {
  2989. return false;
  2990. }
  2991. const logStatus = verify ? scripts_echoLog({
  2992. text: i18n('verifyingAuth', 'Twitter')
  2993. }) : scripts_echoLog({
  2994. type: `${doTask ? '' : 'un'}followingTwitterUser`,
  2995. text: name
  2996. });
  2997. const {
  2998. result,
  2999. statusText,
  3000. status,
  3001. data
  3002. } = await tools_httpRequest({
  3003. url: `https://x.com/i/api/1.1/friendships/${doTask ? 'create' : 'destroy'}.json`,
  3004. method: 'POST',
  3005. headers: {
  3006. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3007. 'Content-Type': 'application/x-www-form-urlencoded',
  3008. 'x-csrf-token': this.#auth.ct0
  3009. },
  3010. responseType: 'json',
  3011. data: $.param({
  3012. include_profile_interstitial_type: 1,
  3013. include_blocking: 1,
  3014. include_blocked_by: 1,
  3015. include_followed_by: 1,
  3016. include_want_retweets: 1,
  3017. include_mute_edge: 1,
  3018. include_can_dm: 1,
  3019. include_can_media_tag: 1,
  3020. skip_status: 1,
  3021. id: userId
  3022. })
  3023. });
  3024. if (result === 'Success') {
  3025. if (data?.status === 200) {
  3026. logStatus.success();
  3027. if (doTask && !verify) {
  3028. this.tasks.users = unique([ ...this.tasks.users, name ]);
  3029. }
  3030. return true;
  3031. }
  3032. if (verify && data?.status === 403 && data.response?.errors?.[0]?.code === 158) {
  3033. logStatus.success();
  3034. return true;
  3035. }
  3036. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3037. return false;
  3038. }
  3039. logStatus.error(`${result}:${statusText}(${status})`);
  3040. return false;
  3041. } catch (error) {
  3042. throwError(error, 'Twitter.toggleUser');
  3043. return false;
  3044. }
  3045. }
  3046. async userName2id(name) {
  3047. try {
  3048. const logStatus = scripts_echoLog({
  3049. type: 'gettingTwitterUserId',
  3050. text: name
  3051. });
  3052. const userId = this.#cache[name];
  3053. if (userId) {
  3054. logStatus.success();
  3055. return userId;
  3056. }
  3057. const {
  3058. result,
  3059. statusText,
  3060. status,
  3061. data
  3062. } = await tools_httpRequest({
  3063. 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`,
  3064. method: 'GET',
  3065. headers: {
  3066. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3067. 'content-type': 'application/json',
  3068. referer: `https://x.com/${name}`,
  3069. 'x-csrf-token': this.#auth.ct0
  3070. },
  3071. responseType: 'json'
  3072. });
  3073. if (result === 'Success') {
  3074. if (data?.status === 200) {
  3075. let response = data.response || (typeof data.responseText === 'object' ? data.responseText : null);
  3076. if (!response) {
  3077. try {
  3078. response = JSON.parse(data.responseText);
  3079. } catch (error) {
  3080. response = null;
  3081. }
  3082. }
  3083. const userId = String(response?.data?.user?.result?.rest_id);
  3084. if (userId) {
  3085. this.#setCache(name, userId);
  3086. logStatus.success();
  3087. return userId;
  3088. }
  3089. logStatus.error(`Error:${data.statusText}(${data.status})`);
  3090. return false;
  3091. }
  3092. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3093. return false;
  3094. }
  3095. logStatus.error(`${result}:${statusText}(${status})`);
  3096. return false;
  3097. } catch (error) {
  3098. throwError(error, 'Twitter.getUserId');
  3099. return false;
  3100. }
  3101. }
  3102. async #toggleRetweet({
  3103. retweetId,
  3104. doTask = true
  3105. }) {
  3106. try {
  3107. if (!doTask && this.whiteList.retweets.includes(retweetId)) {
  3108. scripts_echoLog({
  3109. type: 'whiteList',
  3110. text: 'Twitter.unretweet',
  3111. id: retweetId
  3112. });
  3113. return true;
  3114. }
  3115. const logStatus = scripts_echoLog({
  3116. type: `${doTask ? '' : 'un'}retweetting`,
  3117. text: retweetId
  3118. });
  3119. const {
  3120. result,
  3121. statusText,
  3122. status,
  3123. data
  3124. } = await tools_httpRequest({
  3125. url: `https://x.com/i/api/graphql/${doTask ? 'ojPdsZsimiJrUGLR1sjUtA/CreateRetweet' : 'iQtK4dl5hBmXewYZuEOKVw/DeleteRetweet'}`,
  3126. method: 'POST',
  3127. headers: {
  3128. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3129. 'Content-Type': 'application/json',
  3130. 'x-csrf-token': this.#auth.ct0
  3131. },
  3132. data: `{"variables":{"tweet_id":"${retweetId}","dark_request":false},"queryId":"${doTask ? 'ojPdsZsimiJrUGLR1sjUtA' : 'iQtK4dl5hBmXewYZuEOKVw'}"}`,
  3133. responseType: 'json'
  3134. });
  3135. if (result === 'Success') {
  3136. if (data?.status === 200 || data?.status === 403 && data.response?.errors?.[0]?.code === 327) {
  3137. logStatus.success();
  3138. if (doTask) {
  3139. this.tasks.retweets = unique([ ...this.tasks.retweets, retweetId ]);
  3140. }
  3141. return true;
  3142. }
  3143. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3144. return false;
  3145. }
  3146. logStatus.error(`${result}:${statusText}(${status})`);
  3147. return false;
  3148. } catch (error) {
  3149. throwError(error, 'Twitter.toggleRetweet');
  3150. return false;
  3151. }
  3152. }
  3153. async toggle({
  3154. doTask = true,
  3155. userLinks = [],
  3156. retweetLinks = []
  3157. }) {
  3158. try {
  3159. if (!this.#initialized) {
  3160. scripts_echoLog({
  3161. text: i18n('needInit')
  3162. });
  3163. return false;
  3164. }
  3165. const prom = [];
  3166. if (doTask && !globalOptions.doTask.twitter.users || !doTask && !globalOptions.undoTask.twitter.users) {
  3167. scripts_echoLog({
  3168. type: 'globalOptionsSkip',
  3169. text: 'twitter.users'
  3170. });
  3171. } else {
  3172. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/x\.com\/(.+)/)?.[1] || link.match(/https:\/\/twitter\.com\/(.+)/)?.[1]);
  3173. if (realUsers.length > 0) {
  3174. for (const user of realUsers) {
  3175. prom.push(this.#toggleUser({
  3176. name: user,
  3177. doTask: doTask
  3178. }));
  3179. await delay(1e3);
  3180. }
  3181. }
  3182. }
  3183. if (doTask && !globalOptions.doTask.twitter.retweets || !doTask && !globalOptions.undoTask.twitter.retweets) {
  3184. scripts_echoLog({
  3185. type: 'globalOptionsSkip',
  3186. text: 'twitter.retweets'
  3187. });
  3188. } else {
  3189. const realRetweets = this.getRealParams('retweets', retweetLinks, doTask, link => link.match(/https:\/\/x\.com\/.*?\/status\/([\d]+)/)?.[1] || link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1]);
  3190. if (realRetweets.length > 0) {
  3191. for (const retweet of realRetweets) {
  3192. prom.push(this.#toggleRetweet({
  3193. retweetId: retweet,
  3194. doTask: doTask
  3195. }));
  3196. await delay(1e3);
  3197. }
  3198. }
  3199. }
  3200. return Promise.all(prom).then(() => true);
  3201. } catch (error) {
  3202. throwError(error, 'Twitter.toggle');
  3203. return false;
  3204. }
  3205. }
  3206. #setCache(name, id) {
  3207. try {
  3208. this.#cache[name] = id;
  3209. GM_setValue('twitterCache', this.#cache);
  3210. } catch (error) {
  3211. throwError(error, 'Twitter.setCache');
  3212. }
  3213. }
  3214. }
  3215. const social_Twitter = Twitter;
  3216. class Vk extends social_Social {
  3217. tasks;
  3218. whiteList;
  3219. #username = '';
  3220. #cache = GM_getValue('vkCache') || {};
  3221. #initialized = false;
  3222. constructor() {
  3223. super();
  3224. const defaultTasksTemplate = {
  3225. names: []
  3226. };
  3227. this.tasks = defaultTasksTemplate;
  3228. this.whiteList = {
  3229. ...defaultTasksTemplate,
  3230. ...GM_getValue('whiteList')?.vk || {}
  3231. };
  3232. }
  3233. async init() {
  3234. try {
  3235. if (this.#initialized) {
  3236. return true;
  3237. }
  3238. const isVerified = await this.#verifyAuth();
  3239. if (isVerified) {
  3240. scripts_echoLog({}).success(i18n('initSuccess', 'Vk'));
  3241. this.#initialized = true;
  3242. return true;
  3243. }
  3244. scripts_echoLog({}).error(i18n('initFailed', 'Vk'));
  3245. return false;
  3246. } catch (error) {
  3247. throwError(error, 'Vk.init');
  3248. return false;
  3249. }
  3250. }
  3251. async #verifyAuth() {
  3252. try {
  3253. const logStatus = scripts_echoLog({
  3254. text: i18n('verifyAuth', 'Vk')
  3255. });
  3256. const {
  3257. result,
  3258. statusText,
  3259. status,
  3260. data
  3261. } = await tools_httpRequest({
  3262. url: 'https://vk.com/im',
  3263. method: 'GET'
  3264. });
  3265. if (result === 'Success') {
  3266. if (data?.finalUrl.includes('vk.com/login')) {
  3267. logStatus.error(`Error:${i18n('loginVk')}`, true);
  3268. return false;
  3269. }
  3270. if (data?.status === 200) {
  3271. this.#username = data.responseText.match(/TopNavBtn__profileLink" href="\/(.*?)"/)?.[1] || '';
  3272. logStatus.success();
  3273. return true;
  3274. }
  3275. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3276. return false;
  3277. }
  3278. logStatus.error(`${result}:${statusText}(${status})`);
  3279. return false;
  3280. } catch (error) {
  3281. throwError(error, 'Vk.verifyAuth');
  3282. return false;
  3283. }
  3284. }
  3285. async #toggleGroup(name, dataParam, doTask = true) {
  3286. try {
  3287. const logStatus = scripts_echoLog({
  3288. type: doTask ? 'joiningVkGroup' : 'leavingVkGroup',
  3289. text: name
  3290. });
  3291. if (dataParam.groupAct === 'enter' && !doTask || dataParam.groupAct === 'leave' && doTask) {
  3292. logStatus.success();
  3293. return true;
  3294. }
  3295. const reqData = {
  3296. act: doTask ? 'enter' : 'leave',
  3297. al: 1,
  3298. gid: dataParam.groupId,
  3299. hash: dataParam.groupHash
  3300. };
  3301. if (doTask) {
  3302. reqData.context = '_';
  3303. }
  3304. const {
  3305. result,
  3306. statusText,
  3307. status,
  3308. data
  3309. } = await tools_httpRequest({
  3310. url: 'https://vk.com/al_groups.php',
  3311. method: 'POST',
  3312. headers: {
  3313. origin: 'https://vk.com',
  3314. referer: `https://vk.com/${name}`,
  3315. 'content-type': 'application/x-www-form-urlencoded'
  3316. },
  3317. data: $.param(reqData)
  3318. });
  3319. if (result === 'Success') {
  3320. if (data?.status === 200) {
  3321. logStatus.success();
  3322. if (doTask) {
  3323. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3324. }
  3325. return true;
  3326. }
  3327. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3328. return false;
  3329. }
  3330. logStatus.error(`${result}:${statusText}(${status})`);
  3331. return false;
  3332. } catch (error) {
  3333. throwError(error, 'Vk.toggleGroup');
  3334. return false;
  3335. }
  3336. }
  3337. async #togglePublic(name, dataParam, doTask = true) {
  3338. try {
  3339. const logStatus = scripts_echoLog({
  3340. type: doTask ? 'joiningVkPublic' : 'leavingVkPublic',
  3341. text: name
  3342. });
  3343. if (dataParam.publicJoined && doTask || !dataParam.publicJoined && !doTask) {
  3344. logStatus.success();
  3345. return true;
  3346. }
  3347. const {
  3348. result,
  3349. statusText,
  3350. status,
  3351. data
  3352. } = await tools_httpRequest({
  3353. url: 'https://vk.com/al_public.php',
  3354. method: 'POST',
  3355. headers: {
  3356. origin: 'https://vk.com',
  3357. referer: `https://vk.com/${name}`,
  3358. 'content-type': 'application/x-www-form-urlencoded'
  3359. },
  3360. data: $.param({
  3361. act: doTask ? 'a_enter' : 'a_leave',
  3362. al: 1,
  3363. pid: dataParam.publicPid,
  3364. hash: dataParam.publicHash
  3365. })
  3366. });
  3367. if (result === 'Success') {
  3368. if (data?.status === 200) {
  3369. logStatus.success();
  3370. if (doTask) {
  3371. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3372. }
  3373. return true;
  3374. }
  3375. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3376. return false;
  3377. }
  3378. logStatus.error(`${result}:${statusText}(${status})`);
  3379. return false;
  3380. } catch (error) {
  3381. throwError(error, 'Vk.togglePublic');
  3382. return false;
  3383. }
  3384. }
  3385. async #sendWall(name) {
  3386. try {
  3387. const logStatus = scripts_echoLog({
  3388. type: 'sendingVkWall',
  3389. text: name
  3390. });
  3391. const {
  3392. result,
  3393. statusText,
  3394. status,
  3395. data
  3396. } = await tools_httpRequest({
  3397. url: 'https://vk.com/like.php',
  3398. method: 'POST',
  3399. headers: {
  3400. origin: 'https://vk.com',
  3401. referer: `https://vk.com/${name}`,
  3402. 'content-type': 'application/x-www-form-urlencoded'
  3403. },
  3404. data: $.param({
  3405. act: 'publish_box',
  3406. al: 1,
  3407. object: name
  3408. })
  3409. });
  3410. if (result === 'Success') {
  3411. if (data?.status === 200) {
  3412. const hash = data.responseText.match(/shHash:[\s]*'(.*?)'/)?.[1];
  3413. if (hash) {
  3414. const {
  3415. result: resultR,
  3416. statusText: statusTextR,
  3417. status: statusR,
  3418. data: dataR
  3419. } = await tools_httpRequest({
  3420. url: 'https://vk.com/like.php',
  3421. method: 'POST',
  3422. headers: {
  3423. origin: 'https://vk.com',
  3424. referer: `https://vk.com/${name}`,
  3425. 'content-type': 'application/x-www-form-urlencoded'
  3426. },
  3427. data: $.param({
  3428. Message: '',
  3429. act: 'a_do_publish',
  3430. al: 1,
  3431. close_comments: 0,
  3432. friends_only: 0,
  3433. from: 'box',
  3434. hash: hash,
  3435. list: '',
  3436. mark_as_ads: 0,
  3437. mute_notifications: 0,
  3438. object: name,
  3439. ret_data: 1,
  3440. to: 0
  3441. })
  3442. });
  3443. if (resultR === 'Success') {
  3444. if (dataR?.status === 200) {
  3445. const jsonData = JSON.parse(dataR.responseText?.replace('\x3c!--', '') || '{}');
  3446. if (jsonData?.payload?.[1]?.[1]?.share_my === true) {
  3447. logStatus.success();
  3448. const postId = String(jsonData?.payload?.[1]?.[1]?.post_id);
  3449. const ownerId = String(jsonData?.payload?.[1]?.[1]?.owner_id);
  3450. if (postId && ownerId) {
  3451. this.#setCache(name, `${ownerId}_${postId}`);
  3452. }
  3453. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3454. return true;
  3455. }
  3456. }
  3457. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  3458. return false;
  3459. }
  3460. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  3461. return false;
  3462. }
  3463. logStatus.error('Error: Get "hash" failed');
  3464. return false;
  3465. }
  3466. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3467. return false;
  3468. }
  3469. logStatus.error(`${result}:${statusText}(${status})`);
  3470. return false;
  3471. } catch (error) {
  3472. throwError(error, 'Vk.sendWall');
  3473. return false;
  3474. }
  3475. }
  3476. async #deleteWall(name, dataParams) {
  3477. try {
  3478. const logStatus = scripts_echoLog({
  3479. type: 'deletingVkWall',
  3480. text: name
  3481. });
  3482. const {
  3483. result,
  3484. statusText,
  3485. status,
  3486. data
  3487. } = await tools_httpRequest({
  3488. url: 'https://vk.com/al_wall.php?act=delete',
  3489. method: 'POST',
  3490. headers: {
  3491. origin: 'https://vk.com',
  3492. referer: `https://vk.com/${this.#username}?w=wall${this.#cache[name]}%2Fall`,
  3493. 'content-type': 'application/x-www-form-urlencoded'
  3494. },
  3495. data: $.param({
  3496. act: 'delete',
  3497. al: 1,
  3498. confirm: 0,
  3499. from: 'wkview',
  3500. hash: dataParams.wallHash,
  3501. post: this.#cache[name]
  3502. })
  3503. });
  3504. if (result === 'Success') {
  3505. if (data?.status === 200) {
  3506. const jsonData = JSON.parse(data.responseText?.replace('\x3c!--', '') || '{}');
  3507. if (jsonData?.payload?.[1]?.[1]) {
  3508. logStatus.success();
  3509. return true;
  3510. }
  3511. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3512. return false;
  3513. }
  3514. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3515. return false;
  3516. }
  3517. logStatus.error(`${result}:${statusText}(${status})`);
  3518. return false;
  3519. } catch (error) {
  3520. throwError(error, 'Vk.deleteWall');
  3521. return false;
  3522. }
  3523. }
  3524. async #getId(name, doTask) {
  3525. try {
  3526. let url = `https://vk.com/${name}`;
  3527. if (/^wall-/.test(name)) {
  3528. if (doTask) {
  3529. return {
  3530. type: 'sendWall'
  3531. };
  3532. }
  3533. if (!this.#cache[name]) {
  3534. return {
  3535. type: 'unSupport'
  3536. };
  3537. }
  3538. url = `https://vk.com/${this.#username}?w=wall${this.#cache[name]}`;
  3539. }
  3540. const logStatus = scripts_echoLog({
  3541. type: 'gettingVkId',
  3542. text: name
  3543. });
  3544. const {
  3545. result,
  3546. statusText,
  3547. status,
  3548. data
  3549. } = await tools_httpRequest({
  3550. url: url,
  3551. method: 'GET'
  3552. });
  3553. if (result === 'Success') {
  3554. if (data?.status === 200) {
  3555. const [ , groupAct, groupId, , groupHash ] = data.responseText.match(/Groups.(enter|leave)\(.*?,.*?([\d]+?), (&#39;|')(.*?)(&#39;|')/) || [];
  3556. const publicHash = data.responseText.match(/"enterHash":"(.*?)"/)?.[1];
  3557. const publicPid = data.responseText.match(/"public_id":([\d]+?),/)?.[1];
  3558. const publicJoined = !data.responseText.includes('Public.subscribe');
  3559. if (groupAct && groupId && groupHash) {
  3560. logStatus.success();
  3561. return {
  3562. groupAct: groupAct,
  3563. groupId: groupId,
  3564. groupHash: groupHash,
  3565. type: 'group'
  3566. };
  3567. } else if (publicHash && publicPid) {
  3568. logStatus.success();
  3569. return {
  3570. publicHash: publicHash,
  3571. publicPid: publicPid,
  3572. publicJoined: publicJoined,
  3573. type: 'public'
  3574. };
  3575. } else if (data.responseText.includes('wall.deletePost') && !doTask) {
  3576. const wallHash = data.responseText.match(/wall\.deletePost\(this, '.*?', '(.*?)'\)/)?.[1];
  3577. if (wallHash) {
  3578. logStatus.success();
  3579. return {
  3580. type: 'deleteWall',
  3581. wallHash: wallHash
  3582. };
  3583. }
  3584. } else if (name.includes('wall') && doTask) {
  3585. logStatus.success();
  3586. return {
  3587. type: 'sendWall'
  3588. };
  3589. }
  3590. logStatus.error('Error: Parameters not found!');
  3591. return false;
  3592. }
  3593. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3594. return false;
  3595. }
  3596. logStatus.error(`${result}:${statusText}(${status})`);
  3597. return false;
  3598. } catch (error) {
  3599. throwError(error, 'Vk.getId');
  3600. return false;
  3601. }
  3602. }
  3603. async #toggleVk({
  3604. name,
  3605. doTask = true
  3606. }) {
  3607. try {
  3608. if (!doTask && this.whiteList.names.includes(name)) {
  3609. scripts_echoLog({
  3610. type: 'whiteList',
  3611. text: 'Vk.undoTask',
  3612. id: name
  3613. });
  3614. return true;
  3615. }
  3616. const formatName = name.replace(/\/$/, '');
  3617. const data = await this.#getId(formatName, doTask);
  3618. if (!data) {
  3619. return false;
  3620. }
  3621. switch (data.type) {
  3622. case 'group':
  3623. return await this.#toggleGroup(formatName, data, doTask);
  3624.  
  3625. case 'public':
  3626. return await this.#togglePublic(formatName, data, doTask);
  3627.  
  3628. case 'sendWall':
  3629. return doTask ? await this.#sendWall(formatName) : true;
  3630.  
  3631. case 'deleteWall':
  3632. return doTask ? true : await this.#deleteWall(formatName, data);
  3633.  
  3634. default:
  3635. return false;
  3636. }
  3637. } catch (error) {
  3638. throwError(error, 'Vk.toggleVk');
  3639. return false;
  3640. }
  3641. }
  3642. async toggle({
  3643. doTask = true,
  3644. nameLinks = []
  3645. }) {
  3646. try {
  3647. if (!this.#initialized) {
  3648. scripts_echoLog({
  3649. text: i18n('needInit')
  3650. });
  3651. return false;
  3652. }
  3653. const prom = [];
  3654. if (doTask && !globalOptions.doTask.vk.names || !doTask && !globalOptions.undoTask.vk.names) {
  3655. scripts_echoLog({
  3656. type: 'globalOptionsSkip',
  3657. text: 'vk.names'
  3658. });
  3659. } else {
  3660. const realNames = this.getRealParams('names', nameLinks, doTask, link => link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1]);
  3661. if (realNames.length > 0) {
  3662. for (const name of realNames) {
  3663. prom.push(this.#toggleVk({
  3664. name: name,
  3665. doTask: doTask
  3666. }));
  3667. await delay(1e3);
  3668. }
  3669. }
  3670. }
  3671. return Promise.all(prom).then(() => true);
  3672. } catch (error) {
  3673. throwError(error, 'Vk.toggle');
  3674. return false;
  3675. }
  3676. }
  3677. #setCache(name, postId) {
  3678. try {
  3679. this.#cache[name] = postId;
  3680. GM_setValue('vkCache', this.#cache);
  3681. } catch (error) {
  3682. throwError(error, 'Vk.setCache');
  3683. }
  3684. }
  3685. }
  3686. const social_Vk = Vk;
  3687. const getInfo = async function(link, type) {
  3688. try {
  3689. const logStatus = scripts_echoLog({
  3690. text: i18n('gettingYtbToken')
  3691. });
  3692. const {
  3693. result,
  3694. statusText,
  3695. status,
  3696. data
  3697. } = await tools_httpRequest({
  3698. url: link,
  3699. method: 'GET'
  3700. });
  3701. if (result === 'Success') {
  3702. if (data?.status === 200) {
  3703. if (data.responseText.includes('accounts.google.com/ServiceLogin?service=youtube')) {
  3704. logStatus.error(`Error:${i18n('loginYtb')}`, true);
  3705. return {
  3706. needLogin: true
  3707. };
  3708. }
  3709. const apiKey = data.responseText.match(/"INNERTUBE_API_KEY":"(.*?)"/)?.[1];
  3710. const context = (data.responseText.match(/\(\{"INNERTUBE_CONTEXT":([\w\W]*?)\}\)/) || data.responseText.match(/"INNERTUBE_CONTEXT":([\w\W]*?\}),"INNERTUBE/))?.[1] || '{}';
  3711. const {
  3712. client,
  3713. request
  3714. } = JSON.parse(context);
  3715. if (apiKey && client && request) {
  3716. client.hl = 'en';
  3717. if (type === 'channel') {
  3718. const channelId = data.responseText.match(/"channelId":"(.+?)"/)?.[1];
  3719. if (channelId) {
  3720. logStatus.success();
  3721. return {
  3722. params: {
  3723. apiKey: apiKey,
  3724. client: client,
  3725. request: request,
  3726. channelId: channelId
  3727. }
  3728. };
  3729. }
  3730. logStatus.error('Error: Get "channelId" failed!');
  3731. return {};
  3732. } else if (type === 'likeVideo') {
  3733. const videoId = data.responseText.match(/<link rel="shortlinkUrl" href="https:\/\/youtu\.be\/(.*?)">/)?.[1];
  3734. const likeParams = data.responseText.match(/"likeParams":"(.*?)"/)?.[1];
  3735. if (videoId) {
  3736. logStatus.success();
  3737. return {
  3738. params: {
  3739. apiKey: apiKey,
  3740. client: client,
  3741. request: request,
  3742. videoId: videoId,
  3743. likeParams: likeParams
  3744. }
  3745. };
  3746. }
  3747. logStatus.error('Error: Get "videoId" failed!');
  3748. return {};
  3749. }
  3750. logStatus.error('Error: Unknown type');
  3751. return {};
  3752. }
  3753. logStatus.error('Error: Parameter "apiKey" not found!');
  3754. return {};
  3755. }
  3756. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3757. return {};
  3758. }
  3759. logStatus.error(`${result}:${statusText}(${status})`);
  3760. return {};
  3761. } catch (error) {
  3762. throwError(error, 'Youtube.getInfo');
  3763. return {};
  3764. }
  3765. };
  3766. class Youtube extends social_Social {
  3767. tasks;
  3768. whiteList;
  3769. #auth = GM_getValue('youtubeAuth') || {};
  3770. #initialized = false;
  3771. #verifyChannel = `https://www.youtube.com/channel/${globalOptions.other.youtubeVerifyChannel}`;
  3772. constructor() {
  3773. super();
  3774. const defaultTasksTemplate = {
  3775. channels: [],
  3776. likes: []
  3777. };
  3778. this.tasks = defaultTasksTemplate;
  3779. this.whiteList = {
  3780. ...defaultTasksTemplate,
  3781. ...GM_getValue('whiteList')?.youtube || {}
  3782. };
  3783. }
  3784. async init() {
  3785. try {
  3786. if (this.#initialized) {
  3787. return true;
  3788. }
  3789. if (!this.#auth.PAPISID) {
  3790. if (await this.#updateAuth()) {
  3791. this.#initialized = true;
  3792. return true;
  3793. }
  3794. return false;
  3795. }
  3796. const isVerified = await this.#verifyAuth();
  3797. if (isVerified) {
  3798. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3799. this.#initialized = true;
  3800. return true;
  3801. }
  3802. GM_setValue('youtubeAuth', null);
  3803. if (await this.#updateAuth()) {
  3804. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3805. this.#initialized = true;
  3806. return true;
  3807. }
  3808. scripts_echoLog({}).error(i18n('initFailed', 'Youtube'));
  3809. return false;
  3810. } catch (error) {
  3811. throwError(error, 'Youtube.init');
  3812. return false;
  3813. }
  3814. }
  3815. async #verifyAuth() {
  3816. try {
  3817. return await this.#toggleChannel({
  3818. link: this.#verifyChannel,
  3819. doTask: true,
  3820. verify: true
  3821. });
  3822. } catch (error) {
  3823. throwError(error, 'Youtube.verifyAuth');
  3824. return false;
  3825. }
  3826. }
  3827. async #updateAuth() {
  3828. try {
  3829. const logStatus = scripts_echoLog({
  3830. text: i18n('updatingAuth', 'Youtube')
  3831. });
  3832. return await new Promise(resolve => {
  3833. GM_cookie.list({
  3834. url: 'https://www.youtube.com/@YouTube'
  3835. }, async (cookies, error) => {
  3836. if (!error) {
  3837. const PAPISID = cookies.find(cookie => cookie.name === '__Secure-3PAPISID')?.value;
  3838. if (PAPISID) {
  3839. GM_setValue('youtubeAuth', {
  3840. PAPISID: PAPISID
  3841. });
  3842. this.#auth = {
  3843. PAPISID: PAPISID
  3844. };
  3845. logStatus.success();
  3846. resolve(await this.#verifyAuth());
  3847. } else {
  3848. logStatus.error(i18n('needLogin'));
  3849. resolve(false);
  3850. }
  3851. } else {
  3852. logStatus.error('Error: Update youtube auth failed!');
  3853. resolve(false);
  3854. }
  3855. });
  3856. });
  3857. } catch (error) {
  3858. throwError(error, 'Youtube.updateAuth');
  3859. return false;
  3860. }
  3861. }
  3862. #getInfo(link, type) {
  3863. return getInfo(link, type);
  3864. }
  3865. async #toggleChannel({
  3866. link,
  3867. doTask = true,
  3868. verify = false
  3869. }) {
  3870. try {
  3871. const {
  3872. params,
  3873. needLogin
  3874. } = await this.#getInfo(link, 'channel');
  3875. const {
  3876. apiKey,
  3877. client,
  3878. request,
  3879. channelId
  3880. } = params || {};
  3881. if (needLogin) {
  3882. scripts_echoLog({
  3883. html: i18n('loginYtb')
  3884. });
  3885. return false;
  3886. }
  3887. if (!(apiKey && client && request && channelId)) {
  3888. scripts_echoLog({
  3889. text: '"getYtbToken" failed'
  3890. });
  3891. return false;
  3892. }
  3893. if (!doTask && !verify && this.whiteList.channels.includes(channelId)) {
  3894. scripts_echoLog({
  3895. type: 'whiteList',
  3896. text: 'Youtube.unfollowChannel',
  3897. id: channelId
  3898. });
  3899. return true;
  3900. }
  3901. const logStatus = verify ? scripts_echoLog({
  3902. text: i18n('verifyingAuth', 'Youtube')
  3903. }) : scripts_echoLog({
  3904. type: doTask ? 'followingYtbChannel' : 'unfollowingYtbChannel',
  3905. text: channelId
  3906. });
  3907. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3908. const {
  3909. result,
  3910. statusText,
  3911. status,
  3912. data
  3913. } = await tools_httpRequest({
  3914. url: `https://www.youtube.com/youtubei/v1/subscription/${doTask ? '' : 'un'}subscribe?key=${apiKey}&prettyPrint=false`,
  3915. method: 'POST',
  3916. headers: {
  3917. origin: 'https://www.youtube.com',
  3918. referer: `https://www.youtube.com/channel/${channelId}`,
  3919. 'content-type': 'application/json',
  3920. 'x-goog-authuser': '0',
  3921. 'x-goog-visitor-id': client?.visitorData,
  3922. 'x-origin': 'https://www.youtube.com',
  3923. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  3924. },
  3925. data: JSON.stringify({
  3926. context: {
  3927. client: client,
  3928. request: {
  3929. sessionId: request?.sessionId,
  3930. internalExperimentFlags: [],
  3931. consistencyTokenJars: []
  3932. },
  3933. user: {}
  3934. },
  3935. channelIds: [ channelId ],
  3936. params: doTask ? 'EgIIAhgA' : 'CgIIAhgA'
  3937. })
  3938. });
  3939. if (result === 'Success') {
  3940. if (data?.status === 200) {
  3941. if (doTask && (/"subscribed":true/.test(data.responseText) || data.responseText.includes('The subscription already exists')) || !doTask && /"subscribed":false/.test(data.responseText)) {
  3942. logStatus.success();
  3943. if (doTask && !verify) {
  3944. this.tasks.channels = unique([ ...this.tasks.channels, link ]);
  3945. }
  3946. return true;
  3947. }
  3948. if (verify && data.responseText.includes('You may not subscribe to yourself')) {
  3949. logStatus.success();
  3950. return true;
  3951. }
  3952. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  3953. return false;
  3954. }
  3955. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3956. return false;
  3957. }
  3958. logStatus.error(`${result}:${statusText}(${status})`);
  3959. return false;
  3960. } catch (error) {
  3961. throwError(error, 'Youtube.toggleChannel');
  3962. return false;
  3963. }
  3964. }
  3965. async #toggleLikeVideo({
  3966. link,
  3967. doTask = true
  3968. }) {
  3969. try {
  3970. const {
  3971. params,
  3972. needLogin
  3973. } = await this.#getInfo(link, 'likeVideo');
  3974. const {
  3975. apiKey,
  3976. client,
  3977. request,
  3978. videoId,
  3979. likeParams
  3980. } = params || {};
  3981. if (needLogin) {
  3982. scripts_echoLog({
  3983. html: `${i18n('loginYtb')}`
  3984. });
  3985. return false;
  3986. }
  3987. if (!(apiKey && client && request && videoId && likeParams)) {
  3988. scripts_echoLog({
  3989. text: '"getYtbToken" failed'
  3990. });
  3991. return false;
  3992. }
  3993. if (!doTask && this.whiteList.likes.includes(videoId)) {
  3994. scripts_echoLog({
  3995. type: 'whiteList',
  3996. text: 'Youtube.unlikeVideo',
  3997. id: videoId
  3998. });
  3999. return true;
  4000. }
  4001. const logStatus = scripts_echoLog({
  4002. type: doTask ? 'likingYtbVideo' : 'unlikingYtbVideo',
  4003. text: videoId
  4004. });
  4005. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  4006. const likeVideoData = {
  4007. context: {
  4008. client: client,
  4009. request: {
  4010. sessionId: request.sessionId,
  4011. internalExperimentFlags: [],
  4012. consistencyTokenJars: []
  4013. },
  4014. user: {}
  4015. },
  4016. target: {
  4017. videoId: videoId
  4018. }
  4019. };
  4020. if (doTask) {
  4021. if (likeParams) {
  4022. likeVideoData.params = likeParams;
  4023. } else {
  4024. logStatus.error('Empty likeParams');
  4025. return false;
  4026. }
  4027. }
  4028. const {
  4029. result,
  4030. statusText,
  4031. status,
  4032. data
  4033. } = await tools_httpRequest({
  4034. url: `https://www.youtube.com/youtubei/v1/like/${doTask ? '' : 'remove'}like?key=${apiKey}`,
  4035. method: 'POST',
  4036. headers: {
  4037. origin: 'https://www.youtube.com',
  4038. referer: `https://www.youtube.com/watch?v=${videoId}`,
  4039. 'content-type': 'application/json',
  4040. 'x-goog-authuser': '0',
  4041. 'x-goog-visitor-id': client.visitorData,
  4042. 'x-origin': 'https://www.youtube.com',
  4043. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  4044. },
  4045. data: JSON.stringify(likeVideoData)
  4046. });
  4047. if (result === 'Success') {
  4048. if (data?.status === 200) {
  4049. if (doTask && data.responseText.includes('Added to Liked videos') || !doTask && (data.responseText.includes('Removed from Liked videos') || data.responseText.includes('Dislike removed'))) {
  4050. logStatus.success();
  4051. if (doTask) {
  4052. this.tasks.likes = unique([ ...this.tasks.likes, link ]);
  4053. }
  4054. return true;
  4055. }
  4056. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  4057. return false;
  4058. }
  4059. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4060. return false;
  4061. }
  4062. logStatus.error(`${result}:${statusText}(${status})`);
  4063. return false;
  4064. } catch (error) {
  4065. throwError(error, 'Youtube.toggleLikeVideo');
  4066. return false;
  4067. }
  4068. }
  4069. async toggle({
  4070. doTask = true,
  4071. channelLinks = [],
  4072. videoLinks = []
  4073. }) {
  4074. try {
  4075. if (!this.#initialized) {
  4076. scripts_echoLog({
  4077. text: i18n('needInit')
  4078. });
  4079. return false;
  4080. }
  4081. const prom = [];
  4082. if (doTask && !globalOptions.doTask.youtube.channels || !doTask && !globalOptions.undoTask.youtube.channels) {
  4083. scripts_echoLog({
  4084. type: 'globalOptionsSkip',
  4085. text: 'youtube.channels'
  4086. });
  4087. } else {
  4088. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => {
  4089. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4090. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4091. }
  4092. return link;
  4093. });
  4094. if (realChannels.length > 0) {
  4095. for (const channel of realChannels) {
  4096. prom.push(this.#toggleChannel({
  4097. link: channel,
  4098. doTask: doTask
  4099. }));
  4100. await delay(1e3);
  4101. }
  4102. }
  4103. }
  4104. if (doTask && !globalOptions.doTask.youtube.likes || !doTask && !globalOptions.undoTask.youtube.likes) {
  4105. scripts_echoLog({
  4106. type: 'globalOptionsSkip',
  4107. text: 'youtube.likes'
  4108. });
  4109. } else {
  4110. const realLikes = this.getRealParams('likes', videoLinks, doTask, link => {
  4111. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4112. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4113. }
  4114. return link;
  4115. });
  4116. if (realLikes.length > 0) {
  4117. for (const video of realLikes) {
  4118. prom.push(this.#toggleLikeVideo({
  4119. link: video,
  4120. doTask: doTask
  4121. }));
  4122. await delay(1e3);
  4123. }
  4124. }
  4125. }
  4126. return Promise.all(prom).then(() => true);
  4127. } catch (error) {
  4128. throwError(error, 'Youtube.toggle');
  4129. return false;
  4130. }
  4131. }
  4132. }
  4133. class SteamASF {
  4134. #asfOptions;
  4135. #botName = 'asf';
  4136. #groupInfo;
  4137. async init() {
  4138. try {
  4139. const asfCommandsUrl = new URL('/Api/Command/', globalOptions.ASF.AsfIpcUrl);
  4140. this.#asfOptions = {
  4141. url: asfCommandsUrl.href,
  4142. method: 'POST',
  4143. responseType: 'json',
  4144. headers: {
  4145. accept: 'application/json',
  4146. 'Content-Type': 'application/json',
  4147. Host: asfCommandsUrl.host,
  4148. Origin: asfCommandsUrl.origin,
  4149. Referer: asfCommandsUrl.href,
  4150. Authentication: globalOptions.ASF.AsfIpcPassword
  4151. }
  4152. };
  4153. if (globalOptions.ASF.AsfBotname) {
  4154. this.#botName = globalOptions.ASF.AsfBotname;
  4155. }
  4156. const logStatus = scripts_echoLog({
  4157. text: i18n('initingASF')
  4158. });
  4159. const {
  4160. result,
  4161. statusText,
  4162. status,
  4163. data
  4164. } = await tools_httpRequest({
  4165. ...this.#asfOptions,
  4166. data: '{"Command":"!stats"}'
  4167. });
  4168. if (result === 'Success') {
  4169. if (data?.response?.Success === true && data.response.Message === 'OK' && data.response.Result) {
  4170. logStatus.success();
  4171. return true;
  4172. }
  4173. if (data?.response?.Result || data?.response?.Message) {
  4174. logStatus.error(data?.response?.Result || data.response.Message);
  4175. return false;
  4176. }
  4177. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4178. return false;
  4179. }
  4180. logStatus.error(`${result}:${statusText}(${status})`);
  4181. return false;
  4182. } catch (error) {
  4183. throwError(error, 'SteamASF.init');
  4184. return false;
  4185. }
  4186. }
  4187. async joinGroup(groupName) {
  4188. try {
  4189. const logStatus = scripts_echoLog({
  4190. type: 'joiningSteamGroup',
  4191. text: groupName
  4192. });
  4193. const {
  4194. result,
  4195. statusText,
  4196. status,
  4197. data
  4198. } = await tools_httpRequest({
  4199. ...this.#asfOptions,
  4200. data: JSON.stringify({
  4201. Command: `!JOINGROUP ${this.#botName} ${groupName}`
  4202. })
  4203. });
  4204. if (result === 'Success') {
  4205. if (data?.status === 200 && [ '已加入', '已申请', 'Joined', 'Applied', 'Присоединился', 'costs' ].find(text => data.response?.Result?.includes(text))) {
  4206. logStatus.success();
  4207. return true;
  4208. }
  4209. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4210. return false;
  4211. }
  4212. logStatus.error(`${result}:${statusText}(${status})`);
  4213. return false;
  4214. } catch (error) {
  4215. throwError(error, 'SteamASF.joinGroup');
  4216. return false;
  4217. }
  4218. }
  4219. async leaveGroup(groupName) {
  4220. try {
  4221. if (!this.#groupInfo) {
  4222. if (!await this.#getGroupId()) {
  4223. return false;
  4224. }
  4225. }
  4226. const groupId = await this.#groupInfo[groupName];
  4227. if (!groupId) {
  4228. return false;
  4229. }
  4230. const logStatus = scripts_echoLog({
  4231. type: 'leavingSteamGroup',
  4232. text: groupName
  4233. });
  4234. const {
  4235. result,
  4236. statusText,
  4237. status,
  4238. data
  4239. } = await tools_httpRequest({
  4240. ...this.#asfOptions,
  4241. data: JSON.stringify({
  4242. Command: `!LEAVEGROUP ${this.#botName} ${groupId}`
  4243. })
  4244. });
  4245. if (result === 'Success') {
  4246. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4247. logStatus.success();
  4248. return true;
  4249. }
  4250. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4251. return false;
  4252. }
  4253. logStatus.error(`${result}:${statusText}(${status})`);
  4254. return false;
  4255. } catch (error) {
  4256. throwError(error, 'SteamASF.leaveGroup');
  4257. return false;
  4258. }
  4259. }
  4260. async #getGroupId() {
  4261. try {
  4262. const logStatus = scripts_echoLog({
  4263. type: 'gettingSteamGroupId',
  4264. text: 'All'
  4265. });
  4266. const {
  4267. result,
  4268. statusText,
  4269. status,
  4270. data
  4271. } = await tools_httpRequest({
  4272. ...this.#asfOptions,
  4273. data: JSON.stringify({
  4274. Command: `!GROUPLIST ${this.#botName}`
  4275. })
  4276. });
  4277. if (result === 'Success') {
  4278. if (data?.status === 200 && data.response?.Result?.includes('|')) {
  4279. this.#groupInfo = Object.fromEntries(data.response.Result.split('\n').map(line => {
  4280. const [ , name, id ] = line.trim().split('|');
  4281. if (name && id) {
  4282. return [ name, id ];
  4283. }
  4284. return null;
  4285. }).filter(ele => ele));
  4286. logStatus.success();
  4287. return true;
  4288. }
  4289. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4290. return false;
  4291. }
  4292. logStatus.error(`${result}:${statusText}(${status})`);
  4293. return false;
  4294. } catch (error) {
  4295. throwError(error, 'SteamASF.getGroupID');
  4296. return false;
  4297. }
  4298. }
  4299. async addToWishlist(gameId) {
  4300. try {
  4301. const logStatus = scripts_echoLog({
  4302. type: 'addingToWishlist',
  4303. text: gameId
  4304. });
  4305. const {
  4306. result,
  4307. statusText,
  4308. status,
  4309. data
  4310. } = await tools_httpRequest({
  4311. ...this.#asfOptions,
  4312. data: JSON.stringify({
  4313. Command: `!ADDWISHLIST ${this.#botName} ${gameId}`
  4314. })
  4315. });
  4316. if (result === 'Success') {
  4317. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4318. logStatus.success();
  4319. return true;
  4320. }
  4321. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4322. return false;
  4323. }
  4324. logStatus.error(`${result}:${statusText}(${status})`);
  4325. return false;
  4326. } catch (error) {
  4327. throwError(error, 'SteamASF.addToWishlist');
  4328. return false;
  4329. }
  4330. }
  4331. async removeFromWishlist(gameId) {
  4332. try {
  4333. const logStatus = scripts_echoLog({
  4334. type: 'removingFromWishlist',
  4335. text: gameId
  4336. });
  4337. const {
  4338. result,
  4339. statusText,
  4340. status,
  4341. data
  4342. } = await tools_httpRequest({
  4343. ...this.#asfOptions,
  4344. data: JSON.stringify({
  4345. Command: `!REMOVEWISHLIST ${this.#botName} ${gameId}`
  4346. })
  4347. });
  4348. if (result === 'Success') {
  4349. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4350. logStatus.success();
  4351. return true;
  4352. }
  4353. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4354. return false;
  4355. }
  4356. logStatus.error(`${result}:${statusText}(${status})`);
  4357. return false;
  4358. } catch (error) {
  4359. throwError(error, 'SteamASF.removeFromWishlist');
  4360. return false;
  4361. }
  4362. }
  4363. async toggleFollowGame(gameId, doTask) {
  4364. try {
  4365. const logStatus = scripts_echoLog({
  4366. type: `${doTask ? '' : 'un'}followingGame`,
  4367. text: gameId
  4368. });
  4369. const {
  4370. result,
  4371. statusText,
  4372. status,
  4373. data
  4374. } = await tools_httpRequest({
  4375. ...this.#asfOptions,
  4376. data: JSON.stringify({
  4377. Command: `!${doTask ? '' : 'UN'}FOLLOWGAME ${this.#botName} ${gameId}`
  4378. })
  4379. });
  4380. if (result === 'Success') {
  4381. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4382. logStatus.success();
  4383. return true;
  4384. }
  4385. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4386. return false;
  4387. }
  4388. logStatus.error(`${result}:${statusText}(${status})`);
  4389. return false;
  4390. } catch (error) {
  4391. throwError(error, 'SteamASF.toggleFollowGame');
  4392. return false;
  4393. }
  4394. }
  4395. async toggleCurator(curatorId, doTask = true) {
  4396. try {
  4397. const logStatus = scripts_echoLog({
  4398. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  4399. text: curatorId
  4400. });
  4401. const {
  4402. result,
  4403. statusText,
  4404. status,
  4405. data
  4406. } = await tools_httpRequest({
  4407. ...this.#asfOptions,
  4408. data: JSON.stringify({
  4409. Command: `!${doTask ? '' : 'UN'}FOLLOWCURATOR ${this.#botName} ${curatorId}`
  4410. })
  4411. });
  4412. if (result === 'Success') {
  4413. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4414. logStatus.success();
  4415. return true;
  4416. }
  4417. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4418. return false;
  4419. }
  4420. logStatus.error(`${result}:${statusText}(${status})`);
  4421. return false;
  4422. } catch (error) {
  4423. throwError(error, 'Steam.toggleCurator');
  4424. return false;
  4425. }
  4426. }
  4427. async addLicense(id) {
  4428. try {
  4429. const [ type, ids ] = id.split('-');
  4430. if (type === 'appid') {
  4431. const logStatus = scripts_echoLog({
  4432. type: 'addingFreeLicense',
  4433. text: ids
  4434. });
  4435. const {
  4436. result,
  4437. statusText,
  4438. status,
  4439. data
  4440. } = await tools_httpRequest({
  4441. ...this.#asfOptions,
  4442. data: JSON.stringify({
  4443. Command: `!addlicense ${this.#botName} app/${ids}`
  4444. })
  4445. });
  4446. if (result === 'Success') {
  4447. if (data?.status === 200 && [ 'AlreadyPurchased', 'OK' ].find(text => data.response?.Result?.includes(text))) {
  4448. logStatus.success();
  4449. return true;
  4450. }
  4451. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4452. return false;
  4453. }
  4454. logStatus.error(`${result}:${statusText}(${status})`);
  4455. return false;
  4456. } else if (type === 'subid') {
  4457. const idsArr = ids.split(',');
  4458. const logStatus = scripts_echoLog({
  4459. type: 'addingFreeLicenseSubid',
  4460. text: ids
  4461. });
  4462. const {
  4463. result,
  4464. statusText,
  4465. status,
  4466. data
  4467. } = await tools_httpRequest({
  4468. ...this.#asfOptions,
  4469. data: JSON.stringify({
  4470. Command: `!addlicense ${this.#botName} ${idsArr.map(id => `sub/${id}`).join(',')}`
  4471. })
  4472. });
  4473. if (result === 'Success') {
  4474. if (data?.status === 200 && data.response?.Result) {
  4475. const resultLines = data.response.Result.split('\n');
  4476. idsArr.forEach(subid => {
  4477. const targetLine = resultLines.find(text => text.includes(subid));
  4478. if (targetLine && [ '成功', 'Success', 'Успех' ].find(text => targetLine.includes(text))) {
  4479. scripts_echoLog({}).success(targetLine);
  4480. } else {
  4481. scripts_echoLog({}).error(targetLine);
  4482. }
  4483. });
  4484. return true;
  4485. }
  4486. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4487. return false;
  4488. }
  4489. logStatus.error(`${result}:${statusText}(${status})`);
  4490. return false;
  4491. }
  4492. return false;
  4493. } catch (error) {
  4494. throwError(error, 'SteamASF.addLicense');
  4495. return false;
  4496. }
  4497. }
  4498. async requestPlayTestAccess(id) {
  4499. try {
  4500. const logStatus = scripts_echoLog({
  4501. type: 'requestingPlayTestAccess',
  4502. text: id
  4503. });
  4504. const {
  4505. result,
  4506. statusText,
  4507. status,
  4508. data
  4509. } = await tools_httpRequest({
  4510. ...this.#asfOptions,
  4511. data: JSON.stringify({
  4512. Command: `!REQUESTACCESS ${this.#botName} ${id}`
  4513. })
  4514. });
  4515. if (result === 'Success') {
  4516. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4517. logStatus.success();
  4518. return true;
  4519. }
  4520. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4521. return false;
  4522. }
  4523. logStatus.error(`${result}:${statusText}(${status})`);
  4524. return false;
  4525. } catch (error) {
  4526. throwError(error, 'Steam.requestPlayTestAccess');
  4527. return false;
  4528. }
  4529. }
  4530. }
  4531. const social_SteamASF = SteamASF;
  4532. class Steam extends social_Social {
  4533. tasks;
  4534. whiteList;
  4535. #cache = {
  4536. ...{
  4537. group: {},
  4538. officialGroup: {},
  4539. forum: {},
  4540. workshop: {},
  4541. curator: {}
  4542. },
  4543. ...GM_getValue('steamCache')
  4544. };
  4545. #auth = {};
  4546. #storeInitialized = false;
  4547. #communityInitialized = false;
  4548. #area = 'CN';
  4549. #areaStatus = 'end';
  4550. #ASF;
  4551. constructor() {
  4552. super();
  4553. const defaultTasksTemplate = {
  4554. groups: [],
  4555. officialGroups: [],
  4556. wishlists: [],
  4557. follows: [],
  4558. forums: [],
  4559. workshops: [],
  4560. workshopVotes: [],
  4561. curators: [],
  4562. curatorLikes: [],
  4563. announcements: [],
  4564. licenses: [],
  4565. playtests: []
  4566. };
  4567. this.tasks = defaultTasksTemplate;
  4568. this.whiteList = {
  4569. ...defaultTasksTemplate,
  4570. ...GM_getValue('whiteList')?.steam || {}
  4571. };
  4572. }
  4573. async init(type = 'all') {
  4574. try {
  4575. if (globalOptions.ASF.AsfEnabled && globalOptions.ASF.AsfIpcUrl && globalOptions.ASF.AsfIpcPassword) {
  4576. this.#ASF = new social_SteamASF();
  4577. if (await this.#ASF.init()) {
  4578. this.#storeInitialized = true;
  4579. this.#communityInitialized = true;
  4580. return true;
  4581. }
  4582. return false;
  4583. }
  4584. if (type === 'store') {
  4585. if (this.#storeInitialized) {
  4586. return true;
  4587. }
  4588. let storeInitialized = await this.#updateStoreAuth();
  4589. if (!storeInitialized) {
  4590. storeInitialized = await this.#updateStoreAuthTab();
  4591. }
  4592. this.#storeInitialized = storeInitialized;
  4593. if (!this.#storeInitialized) {
  4594. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4595. return false;
  4596. }
  4597. scripts_echoLog({}).success(i18n('initSuccess', 'SteamStore'));
  4598. return true;
  4599. }
  4600. if (type === 'community') {
  4601. if (this.#communityInitialized) {
  4602. return true;
  4603. }
  4604. let communityInitialized = await this.#updateCommunityAuth();
  4605. if (!communityInitialized) {
  4606. communityInitialized = await this.#updateCommunityAuthTab();
  4607. GM_setValue('steamCommunityAuth', null);
  4608. }
  4609. this.#communityInitialized = communityInitialized;
  4610. if (!this.#communityInitialized) {
  4611. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4612. return false;
  4613. }
  4614. scripts_echoLog({}).success(i18n('initSuccess', 'SteamCommunity'));
  4615. return true;
  4616. }
  4617. if (this.#storeInitialized && this.#communityInitialized) {
  4618. scripts_echoLog({}).success(i18n('initSuccess', 'Steam'));
  4619. return true;
  4620. }
  4621. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4622. return false;
  4623. } catch (error) {
  4624. throwError(error, 'Steam.init');
  4625. return false;
  4626. }
  4627. }
  4628. async #refreshToken(type = 'steamStore') {
  4629. try {
  4630. const host = {
  4631. steamStore: 'store.steampowered.com',
  4632. steamCommunity: 'steamcommunity.com'
  4633. };
  4634. const logStatus = scripts_echoLog({
  4635. text: i18n('refreshingToken', i18n(type))
  4636. });
  4637. const formData = new FormData();
  4638. formData.append('redir', `https://${host[type]}/`);
  4639. const {
  4640. result,
  4641. statusText,
  4642. status,
  4643. data
  4644. } = await tools_httpRequest({
  4645. url: 'https://login.steampowered.com/jwt/ajaxrefresh',
  4646. method: 'POST',
  4647. responseType: 'json',
  4648. headers: {
  4649. Host: 'login.steampowered.com',
  4650. Origin: `https://${host[type]}`,
  4651. Referer: `https://${host[type]}/`
  4652. },
  4653. data: formData
  4654. });
  4655. if (result === 'Success') {
  4656. if (data?.response?.success) {
  4657. if (await this.#setStoreToken(data.response, type)) {
  4658. logStatus.success();
  4659. return true;
  4660. }
  4661. logStatus.error('Error');
  4662. return false;
  4663. }
  4664. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4665. return false;
  4666. }
  4667. logStatus.error(`${result}:${statusText}(${status})`);
  4668. return false;
  4669. } catch (error) {
  4670. throwError(error, 'Steam.refreshToken');
  4671. return false;
  4672. }
  4673. }
  4674. async #setStoreToken(param, type) {
  4675. try {
  4676. const host = {
  4677. steamStore: 'store.steampowered.com',
  4678. steamCommunity: 'steamcommunity.com'
  4679. };
  4680. const logStatus = scripts_echoLog({
  4681. text: i18n('settingToken', i18n(type))
  4682. });
  4683. const formData = new FormData();
  4684. formData.append('steamID', param.steamID);
  4685. formData.append('nonce', param.nonce);
  4686. formData.append('redir', param.redir);
  4687. formData.append('auth', param.auth);
  4688. const {
  4689. result,
  4690. statusText,
  4691. status,
  4692. data
  4693. } = await tools_httpRequest({
  4694. url: `https://${host[type]}/login/settoken`,
  4695. method: 'POST',
  4696. headers: {
  4697. Accept: 'application/json, text/plain, */*',
  4698. Host: host[type],
  4699. Origin: `https://${host[type]}`
  4700. },
  4701. data: formData
  4702. });
  4703. if (result === 'Success') {
  4704. if (data?.status === 200) {
  4705. logStatus.success();
  4706. return true;
  4707. }
  4708. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4709. return false;
  4710. }
  4711. logStatus.error(`${result}:${statusText}(${status})`);
  4712. return false;
  4713. } catch (error) {
  4714. throwError(error, 'Steam.setStoreToken');
  4715. return false;
  4716. }
  4717. }
  4718. async #updateStoreAuth(retry = false) {
  4719. try {
  4720. const logStatus = scripts_echoLog({
  4721. text: i18n('updatingAuth', i18n('steamStore'))
  4722. });
  4723. const {
  4724. result,
  4725. statusText,
  4726. status,
  4727. data
  4728. } = await tools_httpRequest({
  4729. url: 'https://store.steampowered.com/',
  4730. method: 'GET',
  4731. headers: {
  4732. 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',
  4733. 'Sec-Fetch-Dest': 'document',
  4734. 'Sec-Fetch-Mode': 'navigate',
  4735. 'Upgrade-Insecure-Requests': '1'
  4736. },
  4737. fetch: false,
  4738. redirect: 'manual'
  4739. });
  4740. if (data?.status === 200) {
  4741. if (!data.responseText.includes('data-miniprofile=')) {
  4742. if (await this.#refreshToken('steamStore')) {
  4743. logStatus.warning(i18n('retry'));
  4744. if (retry) {
  4745. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4746. return false;
  4747. }
  4748. return this.#updateStoreAuth(true);
  4749. }
  4750. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4751. return false;
  4752. }
  4753. const storeSessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4754. if (storeSessionID) {
  4755. this.#auth.storeSessionID = storeSessionID;
  4756. logStatus.success();
  4757. return true;
  4758. }
  4759. logStatus.error('Error: Get "sessionID" failed');
  4760. return false;
  4761. }
  4762. if ([ 301, 302 ].includes(data?.status)) {
  4763. if (await this.#refreshToken('steamStore')) {
  4764. logStatus.warning(i18n('retry'));
  4765. if (retry) {
  4766. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4767. return false;
  4768. }
  4769. return this.#updateStoreAuth(true);
  4770. }
  4771. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4772. return false;
  4773. }
  4774. logStatus.error(`${result}:${statusText}(${status})`);
  4775. return false;
  4776. } catch (error) {
  4777. throwError(error, 'Steam.updateStoreAuth');
  4778. return false;
  4779. }
  4780. }
  4781. async #updateStoreAuthTab() {
  4782. try {
  4783. const logStatus = scripts_echoLog({
  4784. text: i18n('updatingAuth', i18n('steamStoreTab'))
  4785. });
  4786. return await new Promise(resolve => {
  4787. GM_deleteValue('steamStoreAuth');
  4788. GM_setValue('ATv4_updateStoreAuth', true);
  4789. const newTab = GM_openInTab('https://store.steampowered.com/', {
  4790. active: true,
  4791. setParent: true
  4792. });
  4793. newTab.name = 'ATv4_updateStoreAuth';
  4794. const listenerId = GM_addValueChangeListener('steamStoreAuth', (key, oldValue, newValue) => {
  4795. GM_removeValueChangeListener(listenerId);
  4796. GM_deleteValue('ATv4_updateStoreAuth');
  4797. newTab?.close();
  4798. window.focus();
  4799. if (newValue && JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
  4800. this.#auth.storeSessionID = newValue.storeSessionID;
  4801. logStatus.success();
  4802. resolve(true);
  4803. return;
  4804. }
  4805. logStatus.error('Failed');
  4806. resolve(false);
  4807. });
  4808. newTab.onclose = () => {
  4809. GM_deleteValue('ATv4_updateStoreAuth');
  4810. };
  4811. });
  4812. } catch (error) {
  4813. throwError(error, 'Steam.updateStoreAuthTab');
  4814. return false;
  4815. }
  4816. }
  4817. async #updateCommunityAuthTab() {
  4818. try {
  4819. const logStatus = scripts_echoLog({
  4820. text: i18n('updatingAuth', i18n('steamCommunityTab'))
  4821. });
  4822. return await new Promise(resolve => {
  4823. GM_deleteValue('steamCommunityAuth');
  4824. GM_setValue('ATv4_updateCommunityAuth', true);
  4825. const newTab = GM_openInTab('https://steamcommunity.com/my', {
  4826. active: true,
  4827. setParent: true
  4828. });
  4829. newTab.name = 'ATv4_updateCommunityAuth';
  4830. const listenerId = GM_addValueChangeListener('steamCommunityAuth', (key, oldValue, newValue) => {
  4831. GM_removeValueChangeListener(listenerId);
  4832. GM_deleteValue('ATv4_updateCommunityAuth');
  4833. newTab?.close();
  4834. window.focus();
  4835. if (newValue && JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
  4836. this.#auth.steam64Id = newValue.steam64Id;
  4837. this.#auth.communitySessionID = newValue.communitySessionID;
  4838. logStatus.success();
  4839. resolve(true);
  4840. return;
  4841. }
  4842. logStatus.error('Failed');
  4843. resolve(false);
  4844. });
  4845. newTab.onclose = () => {
  4846. GM_deleteValue('ATv4_updateCommunityAuth');
  4847. };
  4848. });
  4849. } catch (error) {
  4850. throwError(error, 'Steam.updateCommunityAuthTab');
  4851. return false;
  4852. }
  4853. }
  4854. async #updateCommunityAuth() {
  4855. try {
  4856. const logStatus = scripts_echoLog({
  4857. text: i18n('gettingUserLink')
  4858. });
  4859. const {
  4860. result,
  4861. statusText,
  4862. status,
  4863. data
  4864. } = await tools_httpRequest({
  4865. url: 'https://steamcommunity.com/my',
  4866. method: 'GET',
  4867. headers: {
  4868. Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
  4869. Host: 'steamcommunity.com',
  4870. 'Sec-Fetch-Dest': 'document',
  4871. 'Sec-Fetch-Mode': 'navigate'
  4872. },
  4873. fetch: false
  4874. });
  4875. if (data?.status === 200) {
  4876. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4877. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4878. return false;
  4879. }
  4880. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4881. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4882. if (steam64Id && communitySessionID) {
  4883. this.#auth.steam64Id = steam64Id;
  4884. this.#auth.communitySessionID = communitySessionID;
  4885. logStatus.success();
  4886. return true;
  4887. }
  4888. logStatus.error('Error: Get "sessionID" failed');
  4889. return false;
  4890. }
  4891. logStatus.error(`${result}:${statusText}(${status})`);
  4892. return false;
  4893. } catch (error) {
  4894. throwError(error, 'Steam.updateCommunityAuth');
  4895. return false;
  4896. }
  4897. }
  4898. async #getAreaInfo() {
  4899. try {
  4900. const logStatus = scripts_echoLog({
  4901. text: i18n('gettingAreaInfo')
  4902. });
  4903. const {
  4904. result,
  4905. statusText,
  4906. status,
  4907. data
  4908. } = await tools_httpRequest({
  4909. url: 'https://store.steampowered.com/cart/',
  4910. method: 'GET'
  4911. });
  4912. if (result === 'Success') {
  4913. if (data?.status === 200) {
  4914. const cartConfigRaw = data.responseText.match(/data-cart_config="(.*?)"/)?.[1];
  4915. const temp = document.createElement('div');
  4916. temp.innerHTML = cartConfigRaw || '{}';
  4917. const cartConfigStr = temp.textContent || temp.innerText;
  4918. let cartConfig;
  4919. try {
  4920. cartConfig = JSON.parse(cartConfigStr);
  4921. } catch (error) {
  4922. logStatus.error('Error: get country info filed');
  4923. console.error(error);
  4924. return {};
  4925. }
  4926. if (!cartConfig.rgUserCountryOptions) {
  4927. logStatus.warning('Warning: Area cannot be changed');
  4928. return {};
  4929. }
  4930. const userInfoRaw = data.responseText.match(/data-userinfo="(.*?)"/)?.[1];
  4931. const temp1 = document.createElement('div');
  4932. temp1.innerHTML = userInfoRaw || '{}';
  4933. const userInfoStr = temp1.textContent || temp1.innerText;
  4934. let userInfo;
  4935. try {
  4936. userInfo = JSON.parse(userInfoStr);
  4937. } catch (error) {
  4938. logStatus.error('Error: get country info filed');
  4939. console.error(error);
  4940. return {};
  4941. }
  4942. const currentArea = userInfo.country_code;
  4943. const areas = Object.keys(cartConfig.rgUserCountryOptions).filter(area => area !== 'help');
  4944. if (currentArea && areas.length > 0) {
  4945. this.#area = currentArea;
  4946. logStatus.success();
  4947. return {
  4948. currentArea: currentArea,
  4949. areas: areas
  4950. };
  4951. }
  4952. logStatus.error('Error: get country info filed');
  4953. return {};
  4954. }
  4955. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4956. return {};
  4957. }
  4958. logStatus.error(`${result}:${statusText}(${status})`);
  4959. return {};
  4960. } catch (error) {
  4961. throwError(error, 'Steam.getAreaInfo');
  4962. return {};
  4963. }
  4964. }
  4965. async #changeArea(area) {
  4966. try {
  4967. if (this.#areaStatus === 'waiting') {
  4968. await new Promise(resolve => {
  4969. const checker = setInterval(() => {
  4970. if (this.#areaStatus !== 'waiting') {
  4971. clearInterval(checker);
  4972. resolve(true);
  4973. }
  4974. });
  4975. });
  4976. }
  4977. if (this.#area === area || !area && this.#area !== 'CN') {
  4978. return true;
  4979. }
  4980. this.#areaStatus = 'waiting';
  4981. let aimedArea = area;
  4982. if (!aimedArea) {
  4983. const {
  4984. currentArea,
  4985. areas
  4986. } = await this.#getAreaInfo();
  4987. if (!currentArea || !areas) {
  4988. this.#areaStatus = 'error';
  4989. return false;
  4990. }
  4991. if (currentArea !== 'CN') {
  4992. this.#areaStatus = 'skip';
  4993. scripts_echoLog({
  4994. text: 'notNeededChangeArea'
  4995. });
  4996. return 'skip';
  4997. }
  4998. const anotherArea = areas.filter(area => area && area !== 'CN');
  4999. if (!anotherArea || anotherArea.length === 0) {
  5000. this.#areaStatus = 'noAnotherArea';
  5001. scripts_echoLog({
  5002. text: 'noAnotherArea'
  5003. });
  5004. return false;
  5005. }
  5006. [ aimedArea ] = anotherArea;
  5007. }
  5008. const logStatus = scripts_echoLog({
  5009. text: i18n('changingArea', aimedArea)
  5010. });
  5011. const {
  5012. result,
  5013. statusText,
  5014. status,
  5015. data
  5016. } = await tools_httpRequest({
  5017. url: 'https://store.steampowered.com/country/setcountry',
  5018. method: 'POST',
  5019. headers: {
  5020. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5021. },
  5022. data: $.param({
  5023. cc: aimedArea,
  5024. sessionid: this.#auth.storeSessionID
  5025. })
  5026. });
  5027. if (result === 'Success') {
  5028. if (data?.status === 200 && data.responseText === 'true') {
  5029. const {
  5030. currentArea
  5031. } = await this.#getAreaInfo();
  5032. if (currentArea === aimedArea) {
  5033. this.#areaStatus = 'success';
  5034. logStatus.success();
  5035. return currentArea;
  5036. }
  5037. this.#areaStatus = 'error';
  5038. logStatus.error('Error: change country filed');
  5039. return 'CN';
  5040. }
  5041. this.#areaStatus = 'error';
  5042. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5043. return 'CN';
  5044. }
  5045. this.#areaStatus = 'error';
  5046. logStatus.error(`${result}:${statusText}(${status})`);
  5047. return 'CN';
  5048. } catch (error) {
  5049. this.#areaStatus = 'error';
  5050. throwError(error, 'Steam.changeArea');
  5051. return false;
  5052. }
  5053. }
  5054. async #joinGroup(groupName) {
  5055. try {
  5056. if (this.#ASF) {
  5057. if (await this.#ASF.joinGroup(groupName)) {
  5058. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5059. return true;
  5060. }
  5061. return false;
  5062. }
  5063. const logStatus = scripts_echoLog({
  5064. type: 'joiningSteamGroup',
  5065. text: groupName
  5066. });
  5067. const {
  5068. result,
  5069. statusText,
  5070. status,
  5071. data
  5072. } = await tools_httpRequest({
  5073. url: `https://steamcommunity.com/groups/${groupName}`,
  5074. method: 'POST',
  5075. headers: {
  5076. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5077. },
  5078. data: $.param({
  5079. action: 'join',
  5080. sessionID: this.#auth.communitySessionID
  5081. })
  5082. });
  5083. if (result === 'Success') {
  5084. if (data?.status === 200 && !data.responseText.includes('grouppage_join_area')) {
  5085. logStatus.success();
  5086. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5087. return true;
  5088. }
  5089. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5090. return false;
  5091. }
  5092. logStatus.error(`${result}:${statusText}(${status})`);
  5093. return false;
  5094. } catch (error) {
  5095. throwError(error, 'Steam.joinGroup');
  5096. return false;
  5097. }
  5098. }
  5099. async #leaveGroup(groupName) {
  5100. try {
  5101. if (this.whiteList.groups.includes(groupName)) {
  5102. scripts_echoLog({
  5103. type: 'whiteList',
  5104. text: 'Steam.leaveGroup',
  5105. id: groupName
  5106. });
  5107. return true;
  5108. }
  5109. if (this.#ASF) {
  5110. return await this.#ASF.leaveGroup(groupName);
  5111. }
  5112. const groupId = await this.#getGroupId(groupName);
  5113. if (!groupId) {
  5114. return false;
  5115. }
  5116. const logStatus = scripts_echoLog({
  5117. type: 'leavingSteamGroup',
  5118. text: groupName
  5119. });
  5120. const {
  5121. result,
  5122. statusText,
  5123. status,
  5124. data
  5125. } = await tools_httpRequest({
  5126. url: `https://steamcommunity.com/profiles/${this.#auth.steam64Id}/home_process`,
  5127. method: 'POST',
  5128. headers: {
  5129. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5130. },
  5131. data: $.param({
  5132. sessionID: this.#auth.communitySessionID,
  5133. action: 'leaveGroup',
  5134. groupId: groupId
  5135. })
  5136. });
  5137. if (result === 'Success') {
  5138. 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) {
  5139. logStatus.success();
  5140. return true;
  5141. }
  5142. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5143. return false;
  5144. }
  5145. logStatus.error(`${result}:${statusText}(${status})`);
  5146. return false;
  5147. } catch (error) {
  5148. throwError(error, 'Steam.leaveGroup');
  5149. return false;
  5150. }
  5151. }
  5152. async #getGroupId(groupName) {
  5153. try {
  5154. const logStatus = scripts_echoLog({
  5155. type: 'gettingSteamGroupId',
  5156. text: groupName
  5157. });
  5158. const groupId = this.#cache.group[groupName];
  5159. if (groupId) {
  5160. logStatus.success();
  5161. return groupId;
  5162. }
  5163. const {
  5164. result,
  5165. statusText,
  5166. status,
  5167. data
  5168. } = await tools_httpRequest({
  5169. url: `https://steamcommunity.com/groups/${groupName}`,
  5170. method: 'GET',
  5171. headers: {
  5172. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5173. }
  5174. });
  5175. if (result === 'Success') {
  5176. if (data?.status === 200) {
  5177. const groupId = data.responseText.match(/OpenGroupChat\( '([0-9]+)'/)?.[1];
  5178. if (groupId) {
  5179. this.#setCache('group', groupName, groupId);
  5180. logStatus.success();
  5181. return groupId;
  5182. }
  5183. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5184. return false;
  5185. }
  5186. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5187. return false;
  5188. }
  5189. logStatus.error(`${result}:${statusText}(${status})`);
  5190. return false;
  5191. } catch (error) {
  5192. throwError(error, 'Steam.getGroupID');
  5193. return false;
  5194. }
  5195. }
  5196. async #joinOfficialGroup(gameId) {
  5197. try {
  5198. if (this.#ASF) {
  5199. if (await this.#ASF.joinGroup(gameId)) {
  5200. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5201. return true;
  5202. }
  5203. return false;
  5204. }
  5205. const logStatus = scripts_echoLog({
  5206. type: 'joiningSteamOfficialGroup',
  5207. text: gameId
  5208. });
  5209. const {
  5210. result,
  5211. statusText,
  5212. status,
  5213. data
  5214. } = await tools_httpRequest({
  5215. url: `https://steamcommunity.com/games/${gameId}?action=join&sessionID=${this.#auth.communitySessionID}`,
  5216. method: 'GET',
  5217. headers: {
  5218. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5219. }
  5220. });
  5221. if (result === 'Success') {
  5222. if (data?.status === 200 && !data.responseText.includes('id="publicGroupJoin"')) {
  5223. logStatus.success();
  5224. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5225. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5226. if (groupId) {
  5227. this.#setCache('officialGroup', gameId, groupId);
  5228. }
  5229. return true;
  5230. }
  5231. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5232. return false;
  5233. }
  5234. logStatus.error(`${result}:${statusText}(${status})`);
  5235. return false;
  5236. } catch (error) {
  5237. throwError(error, 'Steam.joinOfficialGroup');
  5238. return false;
  5239. }
  5240. }
  5241. async #leaveOfficialGroup(gameId) {
  5242. try {
  5243. if (this.whiteList.officialGroups.includes(gameId)) {
  5244. scripts_echoLog({
  5245. type: 'whiteList',
  5246. text: 'Steam.leaveOfficialGroup',
  5247. id: gameId
  5248. });
  5249. return true;
  5250. }
  5251. if (this.#ASF) {
  5252. return await this.#ASF.leaveGroup(gameId);
  5253. }
  5254. const groupId = await this.#getOfficialGroupId(gameId);
  5255. if (!groupId) {
  5256. return false;
  5257. }
  5258. const logStatus = scripts_echoLog({
  5259. type: 'leavingSteamOfficialGroup',
  5260. text: gameId
  5261. });
  5262. const {
  5263. result,
  5264. statusText,
  5265. status,
  5266. data
  5267. } = await tools_httpRequest({
  5268. url: `https://steamcommunity.com/profiles/${this.#auth.steam64Id}/home_process`,
  5269. method: 'POST',
  5270. headers: {
  5271. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5272. },
  5273. data: $.param({
  5274. sessionID: this.#auth.communitySessionID,
  5275. action: 'leaveGroup',
  5276. groupId: groupId
  5277. })
  5278. });
  5279. if (result === 'Success') {
  5280. if (data?.status === 200) {
  5281. const {
  5282. result: resultR,
  5283. statusText: statusTextR,
  5284. status: statusR,
  5285. data: dataR
  5286. } = await tools_httpRequest({
  5287. url: `https://steamcommunity.com/games/${gameId}`,
  5288. method: 'GET',
  5289. headers: {
  5290. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5291. }
  5292. });
  5293. if (resultR === 'Success') {
  5294. if (dataR?.status === 200 && dataR.responseText.includes('id="publicGroupJoin"')) {
  5295. logStatus.success();
  5296. return true;
  5297. }
  5298. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5299. return false;
  5300. }
  5301. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5302. return false;
  5303. }
  5304. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5305. return false;
  5306. }
  5307. logStatus.error(`${result}:${statusText}(${status})`);
  5308. return false;
  5309. } catch (error) {
  5310. throwError(error, 'Steam.leaveOfficialGroup');
  5311. return false;
  5312. }
  5313. }
  5314. async #getOfficialGroupId(gameId) {
  5315. try {
  5316. const logStatus = scripts_echoLog({
  5317. type: 'gettingSteamOfficialGroupId',
  5318. text: gameId
  5319. });
  5320. const groupId = this.#cache.officialGroup[gameId];
  5321. if (groupId) {
  5322. logStatus.success();
  5323. return groupId;
  5324. }
  5325. const {
  5326. result,
  5327. statusText,
  5328. status,
  5329. data
  5330. } = await tools_httpRequest({
  5331. url: `https://steamcommunity.com/games/${gameId}`,
  5332. method: 'GET',
  5333. headers: {
  5334. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5335. }
  5336. });
  5337. if (result === 'Success') {
  5338. if (data?.status === 200) {
  5339. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5340. if (groupId) {
  5341. this.#setCache('officialGroup', gameId, groupId);
  5342. logStatus.success();
  5343. return groupId;
  5344. }
  5345. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5346. return false;
  5347. }
  5348. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5349. return false;
  5350. }
  5351. logStatus.error(`${result}:${statusText}(${status})`);
  5352. return false;
  5353. } catch (error) {
  5354. throwError(error, 'Steam.getGroupID');
  5355. return false;
  5356. }
  5357. }
  5358. async #addToWishlist(gameId) {
  5359. try {
  5360. if (this.#ASF) {
  5361. if (await this.#ASF.addToWishlist(gameId)) {
  5362. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5363. return true;
  5364. }
  5365. return false;
  5366. }
  5367. const logStatus = scripts_echoLog({
  5368. type: 'addingToWishlist',
  5369. text: gameId
  5370. });
  5371. const {
  5372. result,
  5373. data
  5374. } = await tools_httpRequest({
  5375. url: 'https://store.steampowered.com/api/addtowishlist',
  5376. method: 'POST',
  5377. headers: {
  5378. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5379. },
  5380. data: $.param({
  5381. sessionid: this.#auth.storeSessionID,
  5382. appid: gameId
  5383. }),
  5384. dataType: 'json'
  5385. });
  5386. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5387. logStatus.success();
  5388. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5389. return true;
  5390. }
  5391. const {
  5392. result: resultR,
  5393. statusText: statusTextR,
  5394. status: statusR,
  5395. data: dataR
  5396. } = await tools_httpRequest({
  5397. url: `https://store.steampowered.com/app/${gameId}`,
  5398. method: 'GET'
  5399. });
  5400. if (resultR === 'Success') {
  5401. if (dataR?.status === 200) {
  5402. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5403. logStatus.warning(i18n('changeAreaNotice'));
  5404. if (!await this.#changeArea()) {
  5405. return false;
  5406. }
  5407. return await this.#addToWishlist(gameId);
  5408. }
  5409. if (dataR.responseText.includes('class="queue_actions_ctn"') && dataR.responseText.includes('class="already_in_library"')) {
  5410. logStatus.success();
  5411. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5412. return true;
  5413. } 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"')) {
  5414. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5415. return false;
  5416. }
  5417. logStatus.success();
  5418. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5419. return true;
  5420. }
  5421. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5422. return false;
  5423. }
  5424. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5425. return false;
  5426. } catch (error) {
  5427. throwError(error, 'Steam.addToWishlist');
  5428. return false;
  5429. }
  5430. }
  5431. async #removeFromWishlist(gameId) {
  5432. try {
  5433. if (this.whiteList.wishlists.includes(gameId)) {
  5434. scripts_echoLog({
  5435. type: 'whiteList',
  5436. text: 'Steam.removeFromWishlist',
  5437. id: gameId
  5438. });
  5439. return true;
  5440. }
  5441. if (this.#ASF) {
  5442. return await this.#ASF.removeFromWishlist(gameId);
  5443. }
  5444. const logStatus = scripts_echoLog({
  5445. type: 'removingFromWishlist',
  5446. text: gameId
  5447. });
  5448. const {
  5449. result,
  5450. data
  5451. } = await tools_httpRequest({
  5452. url: 'https://store.steampowered.com/api/removefromwishlist',
  5453. method: 'POST',
  5454. headers: {
  5455. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5456. },
  5457. data: $.param({
  5458. sessionid: this.#auth.storeSessionID,
  5459. appid: gameId
  5460. }),
  5461. dataType: 'json'
  5462. });
  5463. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5464. logStatus.success();
  5465. return true;
  5466. }
  5467. const {
  5468. result: resultR,
  5469. statusText: statusTextR,
  5470. status: statusR,
  5471. data: dataR
  5472. } = await tools_httpRequest({
  5473. url: `https://store.steampowered.com/app/${gameId}`,
  5474. method: 'GET'
  5475. });
  5476. if (resultR === 'Success') {
  5477. if (dataR?.status === 200) {
  5478. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5479. logStatus.warning(i18n('changeAreaNotice'));
  5480. const result = await this.#changeArea();
  5481. if (!result || result === 'CN' || result === 'skip') {
  5482. return false;
  5483. }
  5484. return await this.#removeFromWishlist(gameId);
  5485. }
  5486. if (dataR.responseText.includes('class="queue_actions_ctn"') && (dataR.responseText.includes('ds_owned_flag ds_flag') || dataR.responseText.includes('add_to_wishlist_area'))) {
  5487. logStatus.success();
  5488. return true;
  5489. }
  5490. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5491. return false;
  5492. }
  5493. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5494. return false;
  5495. }
  5496. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5497. return false;
  5498. } catch (error) {
  5499. throwError(error, 'Steam.removeFromWishlist');
  5500. return false;
  5501. }
  5502. }
  5503. async #toggleFollowGame(gameId, doTask) {
  5504. try {
  5505. if (!doTask && this.whiteList.follows.includes(gameId)) {
  5506. scripts_echoLog({
  5507. type: 'whiteList',
  5508. text: 'Steam.unfollowGame',
  5509. id: gameId
  5510. });
  5511. return true;
  5512. }
  5513. if (this.#ASF) {
  5514. if (await this.#ASF.toggleFollowGame(gameId, doTask)) {
  5515. if (doTask) {
  5516. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5517. }
  5518. return true;
  5519. }
  5520. return false;
  5521. }
  5522. const logStatus = scripts_echoLog({
  5523. type: `${doTask ? '' : 'un'}followingGame`,
  5524. text: gameId
  5525. });
  5526. const requestData = {
  5527. sessionid: this.#auth.storeSessionID,
  5528. appid: gameId
  5529. };
  5530. if (!doTask) {
  5531. requestData.unfollow = '1';
  5532. }
  5533. const {
  5534. result,
  5535. data
  5536. } = await tools_httpRequest({
  5537. url: 'https://store.steampowered.com/explore/followgame/',
  5538. method: 'POST',
  5539. headers: {
  5540. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5541. },
  5542. data: $.param(requestData)
  5543. });
  5544. if (result === 'Success' && data?.status === 200 && data.responseText === 'true') {
  5545. logStatus.success();
  5546. return true;
  5547. }
  5548. const followed = await this.#isFollowedGame(gameId);
  5549. if (this.#area === 'CN' && followed === 'areaLocked') {
  5550. logStatus.warning(i18n('changeAreaNotice'));
  5551. if (!await this.#changeArea()) {
  5552. return false;
  5553. }
  5554. return await this.#toggleFollowGame(gameId, doTask);
  5555. }
  5556. if (doTask === followed) {
  5557. logStatus.success();
  5558. if (doTask) {
  5559. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5560. }
  5561. return true;
  5562. }
  5563. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5564. return false;
  5565. } catch (error) {
  5566. throwError(error, 'Steam.toggleFollowGame');
  5567. return false;
  5568. }
  5569. }
  5570. async #isFollowedGame(gameId) {
  5571. try {
  5572. const {
  5573. result,
  5574. data
  5575. } = await tools_httpRequest({
  5576. url: `https://store.steampowered.com/app/${gameId}`,
  5577. method: 'GET'
  5578. });
  5579. if (result === 'Success') {
  5580. if (data?.status === 200) {
  5581. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  5582. return 'areaLocked';
  5583. }
  5584. if ($(data.responseText.replace(/<img.*?>/g, '')).find('.queue_control_button.queue_btn_follow>.btnv6_blue_hoverfade.btn_medium.queue_btn_active').css('display') !== 'none') {
  5585. return true;
  5586. }
  5587. return false;
  5588. }
  5589. return false;
  5590. }
  5591. return false;
  5592. } catch (error) {
  5593. throwError(error, 'Steam.isFollowedGame');
  5594. return false;
  5595. }
  5596. }
  5597. async #toggleForum(gameId, doTask = true) {
  5598. try {
  5599. if (!doTask && this.whiteList.forums.includes(gameId)) {
  5600. scripts_echoLog({
  5601. type: 'whiteList',
  5602. text: 'Steam.unsubscribeForum',
  5603. id: gameId
  5604. });
  5605. return true;
  5606. }
  5607. const forumId = await this.#getForumId(gameId);
  5608. if (!forumId) {
  5609. return false;
  5610. }
  5611. const logStatus = scripts_echoLog({
  5612. type: `${doTask ? '' : 'un'}subscribingForum`,
  5613. text: gameId
  5614. });
  5615. const [ id, feature ] = forumId.split('_');
  5616. const {
  5617. result,
  5618. statusText,
  5619. status,
  5620. data
  5621. } = await tools_httpRequest({
  5622. url: `https://steamcommunity.com/forum/${id}/General/${doTask ? '' : 'un'}subscribe/${feature || '0'}/`,
  5623. method: 'POST',
  5624. responseType: 'json',
  5625. headers: {
  5626. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5627. },
  5628. data: $.param({
  5629. sessionid: this.#auth.communitySessionID
  5630. })
  5631. });
  5632. if (result === 'Success') {
  5633. if (data?.status === 200 && (data.response?.success === 1 || data.response?.success === 29)) {
  5634. if (doTask) {
  5635. this.tasks.forums = unique([ ...this.tasks.forums, gameId ]);
  5636. }
  5637. logStatus.success();
  5638. return true;
  5639. }
  5640. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5641. return true;
  5642. }
  5643. logStatus.error(`${result}:${statusText}(${status})`);
  5644. return true;
  5645. } catch (error) {
  5646. throwError(error, 'Steam.toggleForum');
  5647. return true;
  5648. }
  5649. }
  5650. async #getForumId(gameId) {
  5651. try {
  5652. const logStatus = scripts_echoLog({
  5653. type: 'gettingForumId',
  5654. text: gameId
  5655. });
  5656. const forumId = this.#cache.forum[gameId];
  5657. if (forumId) {
  5658. logStatus.success();
  5659. return forumId;
  5660. }
  5661. const {
  5662. result,
  5663. statusText,
  5664. status,
  5665. data
  5666. } = await tools_httpRequest({
  5667. url: `https://steamcommunity.com/app/${gameId}/discussions/`,
  5668. method: 'GET'
  5669. });
  5670. if (result === 'Success') {
  5671. if (data?.status === 200) {
  5672. const forumId = data.responseText?.match(/General_([\d]+(_[\d]+)?)/)?.[1];
  5673. if (forumId) {
  5674. this.#setCache('forum', gameId, forumId);
  5675. logStatus.success();
  5676. return forumId;
  5677. }
  5678. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5679. return false;
  5680. }
  5681. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5682. return false;
  5683. }
  5684. logStatus.error(`${result}:${statusText}(${status})`);
  5685. return false;
  5686. } catch (error) {
  5687. throwError(error, 'Steam.getForumId');
  5688. return false;
  5689. }
  5690. }
  5691. async #toggleFavoriteWorkshop(id, doTask = true) {
  5692. try {
  5693. if (!doTask && this.whiteList.workshops.includes(id)) {
  5694. scripts_echoLog({
  5695. type: 'whiteList',
  5696. text: 'Steam.unfavoriteWorkshop',
  5697. id: id
  5698. });
  5699. return true;
  5700. }
  5701. const appid = await this.#getWorkshopAppId(id);
  5702. if (!appid) {
  5703. return false;
  5704. }
  5705. const logStatus = scripts_echoLog({
  5706. type: doTask ? 'favoritingWorkshop' : 'unfavoritingWorkshop',
  5707. text: id
  5708. });
  5709. const {
  5710. result,
  5711. statusText,
  5712. status,
  5713. data
  5714. } = await tools_httpRequest({
  5715. url: `https://steamcommunity.com/sharedfiles/${doTask ? '' : 'un'}favorite`,
  5716. method: 'POST',
  5717. headers: {
  5718. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5719. },
  5720. data: $.param({
  5721. id: id,
  5722. appid: appid,
  5723. sessionid: this.#auth.communitySessionID
  5724. })
  5725. });
  5726. if (result === 'Success') {
  5727. if (data?.status === 200 && !data.responseText) {
  5728. if (doTask) {
  5729. this.tasks.workshops = unique([ ...this.tasks.workshops, id ]);
  5730. }
  5731. logStatus.success();
  5732. return true;
  5733. }
  5734. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5735. return false;
  5736. }
  5737. logStatus.error(`${result}:${statusText}(${status})`);
  5738. return false;
  5739. } catch (error) {
  5740. throwError(error, 'Steam.toggleFavoriteWorkshop');
  5741. return false;
  5742. }
  5743. }
  5744. async #getWorkshopAppId(id) {
  5745. try {
  5746. const logStatus = scripts_echoLog({
  5747. type: 'gettingWorkshopAppId',
  5748. text: id
  5749. });
  5750. const appId = this.#cache.workshop[id];
  5751. if (appId) {
  5752. logStatus.success();
  5753. return appId;
  5754. }
  5755. const {
  5756. result,
  5757. statusText,
  5758. status,
  5759. data
  5760. } = await tools_httpRequest({
  5761. url: `https://steamcommunity.com/sharedfiles/filedetails/?id=${id}`,
  5762. method: 'GET'
  5763. });
  5764. if (result === 'Success') {
  5765. if (data?.status === 200) {
  5766. const appId = data.responseText.match(/<input type="hidden" name="appid" value="([\d]+?)" \/>/)?.[1];
  5767. if (appId) {
  5768. this.#setCache('workshop', id, appId);
  5769. logStatus.success();
  5770. return appId;
  5771. }
  5772. logStatus.error('Error: getWorkshopAppId failed');
  5773. return false;
  5774. }
  5775. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5776. return false;
  5777. }
  5778. logStatus.error(`${result}:${statusText}(${status})`);
  5779. return false;
  5780. } catch (error) {
  5781. throwError(error, 'Steam.getWorkshopAppId');
  5782. return false;
  5783. }
  5784. }
  5785. async #voteUpWorkshop(id) {
  5786. try {
  5787. const logStatus = scripts_echoLog({
  5788. type: 'votingUpWorkshop',
  5789. text: id
  5790. });
  5791. const {
  5792. result,
  5793. statusText,
  5794. status,
  5795. data
  5796. } = await tools_httpRequest({
  5797. url: 'https://steamcommunity.com/sharedfiles/voteup',
  5798. method: 'POST',
  5799. responseType: 'json',
  5800. headers: {
  5801. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5802. },
  5803. data: $.param({
  5804. id: id,
  5805. sessionid: this.#auth.communitySessionID
  5806. })
  5807. });
  5808. if (result === 'Success') {
  5809. if (data?.status === 200 && data.response?.success === 1) {
  5810. logStatus.success();
  5811. return true;
  5812. }
  5813. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5814. return true;
  5815. }
  5816. logStatus.error(`${result}:${statusText}(${status})`);
  5817. return true;
  5818. } catch (error) {
  5819. throwError(error, 'Steam.voteupWorkshop');
  5820. return true;
  5821. }
  5822. }
  5823. async #toggleCurator(curatorId, doTask = true) {
  5824. try {
  5825. if (!doTask && this.whiteList.curators.includes(curatorId)) {
  5826. scripts_echoLog({
  5827. type: 'whiteList',
  5828. text: 'Steam.unfollowCurator',
  5829. id: curatorId
  5830. });
  5831. return true;
  5832. }
  5833. if (this.#ASF) {
  5834. return await this.#ASF.toggleCurator(curatorId, doTask);
  5835. }
  5836. const logStatus = scripts_echoLog({
  5837. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  5838. text: curatorId
  5839. });
  5840. const {
  5841. result,
  5842. statusText,
  5843. status,
  5844. data
  5845. } = await tools_httpRequest({
  5846. url: 'https://store.steampowered.com/curators/ajaxfollow',
  5847. method: 'POST',
  5848. headers: {
  5849. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5850. },
  5851. data: $.param({
  5852. clanid: curatorId,
  5853. sessionid: this.#auth.storeSessionID,
  5854. follow: doTask
  5855. }),
  5856. dataType: 'json'
  5857. });
  5858. if (result === 'Success') {
  5859. if (data?.status === 200 && data.response?.success?.success === 1) {
  5860. logStatus.success();
  5861. return true;
  5862. }
  5863. logStatus.error(`Error:${data?.statusText}(${data?.response?.success}` || `${data?.status})`);
  5864. return false;
  5865. }
  5866. logStatus.error(`${result}:${statusText}(${status})`);
  5867. return false;
  5868. } catch (error) {
  5869. throwError(error, 'Steam.toggleCurator');
  5870. return false;
  5871. }
  5872. }
  5873. async getCuratorId(path, name) {
  5874. try {
  5875. const logStatus = scripts_echoLog({
  5876. type: 'gettingCuratorId',
  5877. text: `${path}/${name}`
  5878. });
  5879. const curatorId = this.#cache.curator[`${path}/${name}`];
  5880. if (curatorId) {
  5881. logStatus.success();
  5882. return curatorId;
  5883. }
  5884. const {
  5885. result,
  5886. statusText,
  5887. status,
  5888. data
  5889. } = await tools_httpRequest({
  5890. url: `https://store.steampowered.com/${path}/${name}`,
  5891. method: 'GET',
  5892. headers: {
  5893. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5894. }
  5895. });
  5896. if (result === 'Success') {
  5897. if (data?.status === 200) {
  5898. const curatorId = data.responseText.match(/g_pagingData.*?"clanid":([\d]+)/)?.[1];
  5899. if (curatorId) {
  5900. this.#setCache('curator', `${path}/${name}`, curatorId);
  5901. logStatus.success();
  5902. return curatorId;
  5903. }
  5904. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5905. return false;
  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.getCuratorID');
  5914. return false;
  5915. }
  5916. }
  5917. async #toggleCuratorLike(link, doTask = true) {
  5918. try {
  5919. const [ path, name ] = link.split('/');
  5920. if (!(path && name)) {
  5921. scripts_echoLog({
  5922. text: i18n('errorLink', link)
  5923. });
  5924. return false;
  5925. }
  5926. const curatorId = await this.getCuratorId(path, name);
  5927. if (curatorId) {
  5928. return await this.#toggleCurator(curatorId, doTask);
  5929. }
  5930. return false;
  5931. } catch (error) {
  5932. throwError(error, 'Steam.toggleCuratorLike');
  5933. return false;
  5934. }
  5935. }
  5936. async #getAnnouncementParams(appId, viewId) {
  5937. try {
  5938. const logStatus = scripts_echoLog({
  5939. type: 'gettingAnnouncementParams',
  5940. text: appId,
  5941. id: viewId
  5942. });
  5943. const {
  5944. result,
  5945. statusText,
  5946. status,
  5947. data
  5948. } = await tools_httpRequest({
  5949. 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`,
  5950. method: 'GET',
  5951. responseType: 'json',
  5952. headers: {
  5953. Host: 'store.steampowered.com',
  5954. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  5955. }
  5956. });
  5957. if (result === 'Success') {
  5958. if (data?.status === 200 && data?.response?.success === 1) {
  5959. const {
  5960. clanid,
  5961. gid
  5962. } = data.response.event?.announcement_body || {};
  5963. if (clanid) {
  5964. logStatus.success();
  5965. return {
  5966. clanId: clanid,
  5967. gid: gid
  5968. };
  5969. }
  5970. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5971. return {};
  5972. }
  5973. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5974. return {};
  5975. }
  5976. logStatus.error(`${result}:${statusText}(${status})`);
  5977. return {};
  5978. } catch (error) {
  5979. throwError(error, 'Steam.likeAnnouncement');
  5980. return {};
  5981. }
  5982. }
  5983. async #likeAnnouncement(id) {
  5984. try {
  5985. const [ appId, viewId ] = id.split('/');
  5986. if (!(appId && viewId)) {
  5987. scripts_echoLog({}).error(`${i18n('missParams')}(id)`);
  5988. return false;
  5989. }
  5990. const {
  5991. clanId,
  5992. gid
  5993. } = await this.#getAnnouncementParams(appId, viewId);
  5994. if (!clanId) {
  5995. return false;
  5996. }
  5997. const logStatus = scripts_echoLog({
  5998. type: 'likingAnnouncement',
  5999. text: appId,
  6000. id: viewId
  6001. });
  6002. const {
  6003. result,
  6004. statusText,
  6005. status,
  6006. data
  6007. } = await tools_httpRequest({
  6008. url: `https://store.steampowered.com/updated/ajaxrateupdate/${gid || viewId}`,
  6009. method: 'POST',
  6010. headers: {
  6011. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6012. Host: 'store.steampowered.com',
  6013. Origin: 'https://store.steampowered.com',
  6014. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  6015. },
  6016. data: $.param({
  6017. sessionid: this.#auth.storeSessionID,
  6018. voteup: 1,
  6019. clanid: clanId,
  6020. ajax: 1
  6021. }),
  6022. dataType: 'json'
  6023. });
  6024. if (result === 'Success') {
  6025. if (data?.status === 200 && data.response.success === 1) {
  6026. logStatus.success();
  6027. return true;
  6028. }
  6029. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6030. return false;
  6031. }
  6032. logStatus.error(`${result}:${statusText}(${status})`);
  6033. return false;
  6034. } catch (error) {
  6035. throwError(error, 'Steam.likeAnnouncement');
  6036. return false;
  6037. }
  6038. }
  6039. async #appid2subid(id) {
  6040. try {
  6041. const logStatus = scripts_echoLog({
  6042. type: 'gettingSubid',
  6043. text: id
  6044. });
  6045. const {
  6046. result,
  6047. statusText,
  6048. status,
  6049. data
  6050. } = await tools_httpRequest({
  6051. url: `https://store.steampowered.com/app/${id}`,
  6052. method: 'GET',
  6053. headers: {
  6054. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  6055. }
  6056. });
  6057. if (result === 'Success') {
  6058. if (data?.status === 200) {
  6059. if (data.responseText.includes('ds_owned_flag ds_flag') || data.responseText.includes('class="already_in_library"')) {
  6060. logStatus.success(i18n('owned'));
  6061. return false;
  6062. }
  6063. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6064. logStatus.warning(i18n('changeAreaNotice'));
  6065. const result = await this.#changeArea();
  6066. if (!result || result === 'CN' || result === 'skip') {
  6067. return false;
  6068. }
  6069. return await this.#appid2subid(id);
  6070. }
  6071. let subid = data.responseText.match(/name="subid" value="([\d]+?)"/)?.[1];
  6072. if (subid) {
  6073. logStatus.success();
  6074. return subid;
  6075. }
  6076. subid = data.responseText.match(/AddFreeLicense\(\s*(\d+)/)?.[1];
  6077. if (subid) {
  6078. logStatus.success();
  6079. return subid;
  6080. }
  6081. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6082. return false;
  6083. }
  6084. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6085. return false;
  6086. }
  6087. logStatus.error(`${result}:${statusText}(${status})`);
  6088. return false;
  6089. } catch (error) {
  6090. throwError(error, 'Steam.appid2subid');
  6091. return false;
  6092. }
  6093. }
  6094. async #getLicenses() {
  6095. try {
  6096. const logStatus = scripts_echoLog({
  6097. text: i18n('gettingLicenses')
  6098. });
  6099. const {
  6100. result,
  6101. statusText,
  6102. status,
  6103. data
  6104. } = await tools_httpRequest({
  6105. url: `https://store.steampowered.com/dynamicstore/userdata/?t=${new Date().getTime()}`,
  6106. method: 'GET',
  6107. responseType: 'json'
  6108. });
  6109. if (result === 'Success') {
  6110. if (data?.status === 200) {
  6111. logStatus.success();
  6112. return data.response?.rgOwnedPackages;
  6113. }
  6114. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6115. return false;
  6116. }
  6117. logStatus.error(`${result}:${statusText}(${status})`);
  6118. return false;
  6119. } catch (error) {
  6120. throwError(error, 'Steam.getLicenses');
  6121. return false;
  6122. }
  6123. }
  6124. async #addLicense(id) {
  6125. try {
  6126. if (this.#ASF) {
  6127. return await this.#ASF.addLicense(id);
  6128. }
  6129. const [ type, ids ] = id.split('-');
  6130. if (type === 'appid') {
  6131. const subid = await this.#appid2subid(ids);
  6132. if (!subid) {
  6133. return false;
  6134. }
  6135. const logStatus = scripts_echoLog({
  6136. type: 'addingFreeLicense',
  6137. text: ids
  6138. });
  6139. if (!await this.#addFreeLicense(subid, logStatus)) {
  6140. return false;
  6141. }
  6142. const {
  6143. result,
  6144. statusText,
  6145. status,
  6146. data
  6147. } = await tools_httpRequest({
  6148. url: `https://store.steampowered.com/app/${ids}`,
  6149. method: 'GET'
  6150. });
  6151. if (result === 'Success') {
  6152. if (data?.status === 200) {
  6153. if (data.responseText.includes('ds_owned_flag ds_flag') || data.responseText.includes('class="already_in_library"')) {
  6154. logStatus.success();
  6155. return true;
  6156. }
  6157. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6158. return false;
  6159. }
  6160. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6161. return false;
  6162. }
  6163. logStatus.error(`${result}:${statusText}(${status})`);
  6164. return false;
  6165. } else if (type === 'subid') {
  6166. if (this.#area === 'CN') {
  6167. scripts_echoLog({}).success(i18n('tryChangeAreaNotice'));
  6168. await this.#changeArea();
  6169. }
  6170. const logStatusArr = {};
  6171. const idsArr = ids.split(',');
  6172. for (const subid of idsArr) {
  6173. const logStatus = scripts_echoLog({
  6174. type: 'addingFreeLicenseSubid',
  6175. text: subid
  6176. });
  6177. if (!await this.#addFreeLicense(subid, logStatus)) {
  6178. return false;
  6179. }
  6180. logStatusArr[subid] = logStatus;
  6181. }
  6182. const licenses = await this.#getLicenses();
  6183. if (!licenses) {
  6184. return false;
  6185. }
  6186. for (const subid of idsArr) {
  6187. if (licenses.includes(parseInt(subid, 10))) {
  6188. logStatusArr[subid].success();
  6189. } else {
  6190. logStatusArr[subid].error();
  6191. }
  6192. }
  6193. return true;
  6194. }
  6195. return false;
  6196. } catch (error) {
  6197. throwError(error, 'Steam.addLicense');
  6198. return false;
  6199. }
  6200. }
  6201. async #addFreeLicense(id, logStatusPre) {
  6202. try {
  6203. const logStatus = logStatusPre || scripts_echoLog({
  6204. type: 'addingFreeLicenseSubid',
  6205. text: id
  6206. });
  6207. const {
  6208. result,
  6209. statusText,
  6210. status,
  6211. data
  6212. } = await tools_httpRequest({
  6213. url: `https://store.steampowered.com/freelicense/addfreelicense/${id}`,
  6214. method: 'POST',
  6215. headers: {
  6216. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6217. Host: 'store.steampowered.com',
  6218. Origin: 'https://store.steampowered.com',
  6219. Referer: 'https://store.steampowered.com/account/licenses/'
  6220. },
  6221. data: $.param({
  6222. ajax: true,
  6223. sessionid: this.#auth.storeSessionID
  6224. }),
  6225. dataType: 'json'
  6226. });
  6227. if (result === 'Success') {
  6228. if (data?.status === 200) {
  6229. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6230. logStatus.warning(i18n('changeAreaNotice'));
  6231. const result = await this.#changeArea();
  6232. if (!result || result === 'CN') {
  6233. return false;
  6234. }
  6235. return await this.#addFreeLicense(id);
  6236. }
  6237. logStatus.success();
  6238. return true;
  6239. }
  6240. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6241. return false;
  6242. }
  6243. logStatus.error(`${result}:${statusText}(${status})`);
  6244. return false;
  6245. } catch (error) {
  6246. throwError(error, 'Steam.addFreeLicense');
  6247. return false;
  6248. }
  6249. }
  6250. async #requestPlayTestAccess(id) {
  6251. try {
  6252. if (this.#ASF) {
  6253. return await this.#ASF.requestPlayTestAccess(id);
  6254. }
  6255. const logStatus = scripts_echoLog({
  6256. type: 'requestingPlayTestAccess',
  6257. text: id
  6258. });
  6259. const {
  6260. result,
  6261. statusText,
  6262. status,
  6263. data
  6264. } = await tools_httpRequest({
  6265. url: `https://store.steampowered.com/ajaxrequestplaytestaccess/${id}`,
  6266. method: 'POST',
  6267. headers: {
  6268. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6269. Host: 'store.steampowered.com',
  6270. Origin: 'https://store.steampowered.com',
  6271. Referer: `https://store.steampowered.com/app/${id}`
  6272. },
  6273. data: $.param({
  6274. sessionid: this.#auth.storeSessionID
  6275. }),
  6276. dataType: 'json'
  6277. });
  6278. if (result === 'Success') {
  6279. if (data?.status === 200 && data?.response?.success === 1) {
  6280. logStatus.success();
  6281. return true;
  6282. }
  6283. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6284. return false;
  6285. }
  6286. logStatus.error(`${result}:${statusText}(${status})`);
  6287. return false;
  6288. } catch (error) {
  6289. throwError(error, 'Steam.requestPlayTestAccess');
  6290. return false;
  6291. }
  6292. }
  6293. async toggle({
  6294. doTask = true,
  6295. groupLinks = [],
  6296. officialGroupLinks = [],
  6297. wishlistLinks = [],
  6298. followLinks = [],
  6299. forumLinks = [],
  6300. workshopLinks = [],
  6301. workshopVoteLinks = [],
  6302. curatorLinks = [],
  6303. curatorLikeLinks = [],
  6304. announcementLinks = [],
  6305. licenseLinks = [],
  6306. playtestLinks = []
  6307. }) {
  6308. try {
  6309. if ([ ...groupLinks, ...officialGroupLinks, ...forumLinks, ...workshopLinks, ...workshopVoteLinks ].length > 0 && !this.#communityInitialized) {
  6310. scripts_echoLog({
  6311. text: i18n('needInit')
  6312. });
  6313. return false;
  6314. }
  6315. if ([ ...wishlistLinks, ...followLinks, ...curatorLinks, ...curatorLikeLinks, ...announcementLinks, ...licenseLinks, ...playtestLinks ].length > 0 && !this.#storeInitialized) {
  6316. scripts_echoLog({
  6317. text: i18n('needInit')
  6318. });
  6319. return false;
  6320. }
  6321. const prom = [];
  6322. if (doTask && !globalOptions.doTask.steam.groups || !doTask && !globalOptions.undoTask.steam.groups) {
  6323. scripts_echoLog({
  6324. type: 'globalOptionsSkip',
  6325. text: 'steam.groups'
  6326. });
  6327. } else {
  6328. const realGroups = this.getRealParams('groups', groupLinks, doTask, link => link.match(/groups\/(.+)\/?/)?.[1]);
  6329. if (realGroups.length > 0) {
  6330. for (const group of realGroups) {
  6331. if (doTask) {
  6332. prom.push(this.#joinGroup(group));
  6333. } else {
  6334. prom.push(this.#leaveGroup(group));
  6335. }
  6336. await delay(1e3);
  6337. }
  6338. }
  6339. }
  6340. if (doTask && !globalOptions.doTask.steam.officialGroups || !doTask && !globalOptions.undoTask.steam.officialGroups) {
  6341. scripts_echoLog({
  6342. type: 'globalOptionsSkip',
  6343. text: 'steam.officialGroups'
  6344. });
  6345. } else {
  6346. const realOfficialGroups = this.getRealParams('officialGroups', officialGroupLinks, doTask, link => link.match(/games\/(.+)\/?/)?.[1]);
  6347. if (realOfficialGroups.length > 0) {
  6348. for (const officialGroup of realOfficialGroups) {
  6349. if (doTask) {
  6350. prom.push(this.#joinOfficialGroup(officialGroup));
  6351. } else {
  6352. prom.push(this.#leaveOfficialGroup(officialGroup));
  6353. }
  6354. await delay(1e3);
  6355. }
  6356. }
  6357. }
  6358. if (doTask && !globalOptions.doTask.steam.wishlists || !doTask && !globalOptions.undoTask.steam.wishlists) {
  6359. scripts_echoLog({
  6360. type: 'globalOptionsSkip',
  6361. text: 'steam.wishlists'
  6362. });
  6363. } else {
  6364. const realWishlists = this.getRealParams('wishlists', wishlistLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6365. if (realWishlists.length > 0) {
  6366. for (const game of realWishlists) {
  6367. if (doTask) {
  6368. prom.push(this.#addToWishlist(game));
  6369. } else {
  6370. prom.push(this.#removeFromWishlist(game));
  6371. }
  6372. await delay(1e3);
  6373. }
  6374. }
  6375. }
  6376. if (doTask && !globalOptions.doTask.steam.follows || !doTask && !globalOptions.undoTask.steam.follows) {
  6377. scripts_echoLog({
  6378. type: 'globalOptionsSkip',
  6379. text: 'steam.follows'
  6380. });
  6381. } else {
  6382. const realFollows = this.getRealParams('follows', followLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6383. if (realFollows.length > 0) {
  6384. for (const game of realFollows) {
  6385. prom.push(this.#toggleFollowGame(game, doTask));
  6386. await delay(1e3);
  6387. }
  6388. }
  6389. }
  6390. if (doTask && !globalOptions.doTask.steam.forums || !doTask && !globalOptions.undoTask.steam.forums) {
  6391. scripts_echoLog({
  6392. type: 'globalOptionsSkip',
  6393. text: 'steam.forums'
  6394. });
  6395. } else {
  6396. const realForums = this.getRealParams('forums', forumLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6397. if (realForums.length > 0) {
  6398. for (const forum of realForums) {
  6399. prom.push(this.#toggleForum(forum, doTask));
  6400. await delay(1e3);
  6401. }
  6402. }
  6403. }
  6404. if (doTask && !globalOptions.doTask.steam.workshops || !doTask && !globalOptions.undoTask.steam.workshops) {
  6405. scripts_echoLog({
  6406. type: 'globalOptionsSkip',
  6407. text: 'steam.workshops'
  6408. });
  6409. } else {
  6410. const realWorkshops = this.getRealParams('workshops', workshopLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6411. if (realWorkshops.length > 0) {
  6412. for (const workshop of realWorkshops) {
  6413. prom.push(this.#toggleFavoriteWorkshop(workshop, doTask));
  6414. await delay(1e3);
  6415. }
  6416. }
  6417. }
  6418. if (doTask && !globalOptions.doTask.steam.workshopVotes) {
  6419. scripts_echoLog({
  6420. type: 'globalOptionsSkip',
  6421. text: 'steam.workshopVotes'
  6422. });
  6423. } else {
  6424. const realworkshopVotes = this.getRealParams('workshopVotes', workshopVoteLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6425. if (doTask && realworkshopVotes.length > 0) {
  6426. for (const workshop of realworkshopVotes) {
  6427. prom.push(this.#voteUpWorkshop(workshop));
  6428. await delay(1e3);
  6429. }
  6430. }
  6431. }
  6432. if (doTask && !globalOptions.doTask.steam.curators || !doTask && !globalOptions.undoTask.steam.curators) {
  6433. scripts_echoLog({
  6434. type: 'globalOptionsSkip',
  6435. text: 'steam.curators'
  6436. });
  6437. } else {
  6438. const realCurators = this.getRealParams('curators', curatorLinks, doTask, link => link.match(/curator\/([\d]+)/)?.[1]);
  6439. const realCuratorLikes = this.getRealParams('curatorLikes', curatorLikeLinks, doTask, link => link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3).join('/'));
  6440. if (realCurators.length > 0) {
  6441. for (const curator of realCurators) {
  6442. prom.push(this.#toggleCurator(curator, doTask));
  6443. await delay(1e3);
  6444. }
  6445. }
  6446. if (realCuratorLikes.length > 0) {
  6447. for (const curatorLike of realCuratorLikes) {
  6448. prom.push(this.#toggleCuratorLike(curatorLike, doTask));
  6449. await delay(1e3);
  6450. }
  6451. }
  6452. }
  6453. if (doTask && !globalOptions.doTask.steam.announcements) {
  6454. scripts_echoLog({
  6455. type: 'globalOptionsSkip',
  6456. text: 'steam.announcements'
  6457. });
  6458. } else {
  6459. const realAnnouncements = this.getRealParams('announcements', announcementLinks, doTask, link => {
  6460. if (link.includes('store.steampowered.com')) {
  6461. return link.match(/store\.steampowered\.com\/news\/app\/([\d]+)\/view\/([\d]+)/)?.slice(1, 3).join('/');
  6462. }
  6463. return link.match(/steamcommunity\.com\/games\/([\d]+)\/announcements\/detail\/([\d]+)/)?.slice(1, 3).join('/');
  6464. });
  6465. if (doTask && realAnnouncements.length > 0) {
  6466. for (const id of realAnnouncements) {
  6467. prom.push(this.#likeAnnouncement(id));
  6468. await delay(1e3);
  6469. }
  6470. }
  6471. }
  6472. if (doTask && !globalOptions.doTask.steam.licenses) {
  6473. scripts_echoLog({
  6474. type: 'globalOptionsSkip',
  6475. text: 'steam.licenses'
  6476. });
  6477. } else if (doTask && globalOptions.doTask.steam.licenses && licenseLinks.length > 0) {
  6478. for (const id of licenseLinks) {
  6479. prom.push(this.#addLicense(id));
  6480. await delay(1e3);
  6481. }
  6482. }
  6483. if (doTask && !globalOptions.doTask.steam.playtests) {
  6484. scripts_echoLog({
  6485. type: 'globalOptionsSkip',
  6486. text: 'steam.playtests'
  6487. });
  6488. } else {
  6489. const realPlaytests = this.getRealParams('playtests', playtestLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6490. if (doTask && globalOptions.doTask.steam.playtests && realPlaytests.length > 0) {
  6491. for (const id of realPlaytests) {
  6492. prom.push(this.#requestPlayTestAccess(id));
  6493. await delay(1e3);
  6494. }
  6495. }
  6496. }
  6497. return Promise.all(prom).then(async () => {
  6498. if (this.#area !== 'CN') {
  6499. scripts_echoLog({}).warning(i18n('steamFinishNotice'));
  6500. await this.#changeArea('CN');
  6501. }
  6502. return true;
  6503. });
  6504. } catch (error) {
  6505. throwError(error, 'Steam.toggle');
  6506. return false;
  6507. }
  6508. }
  6509. #setCache(type, name, id) {
  6510. try {
  6511. this.#cache[type][name] = id;
  6512. GM_setValue('steamCache', this.#cache);
  6513. } catch (error) {
  6514. throwError(error, 'Steam.setCache');
  6515. }
  6516. }
  6517. }
  6518. const social_Steam = Steam;
  6519. class Website {
  6520. undoneTasks;
  6521. socialTasks;
  6522. giveawayId;
  6523. socialInitialized = {
  6524. discord: false,
  6525. instagram: false,
  6526. reddit: false,
  6527. twitch: false,
  6528. twitter: false,
  6529. vk: false,
  6530. youtube: false,
  6531. steamStore: false,
  6532. steamCommunity: false
  6533. };
  6534. initialized = false;
  6535. social = {};
  6536. async #bind(name, init) {
  6537. try {
  6538. return {
  6539. name: name,
  6540. result: await init
  6541. };
  6542. } catch (error) {
  6543. throwError(error, 'Website.bind');
  6544. return {
  6545. name: name,
  6546. result: false
  6547. };
  6548. }
  6549. }
  6550. async initSocial(action) {
  6551. try {
  6552. const pro = [];
  6553. const tasks = action === 'do' ? this.undoneTasks : this.socialTasks;
  6554. if (tasks.discord) {
  6555. const hasDiscord = Object.values(tasks.discord).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6556. if (hasDiscord && (!this.socialInitialized.discord || !this.social.discord)) {
  6557. this.social.discord = new social_Discord();
  6558. pro.push(this.#bind('discord', this.social.discord.init(action)));
  6559. }
  6560. }
  6561. if (tasks.instagram) {
  6562. const hasInstagram = Object.values(tasks.instagram).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6563. if (hasInstagram && (!this.socialInitialized.instagram || !this.social.instagram)) {
  6564. this.social.instagram = new social_Instagram();
  6565. pro.push(this.#bind('instagram', this.social.instagram.init()));
  6566. }
  6567. }
  6568. if (tasks.reddit) {
  6569. const hasReddit = Object.values(tasks.reddit).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6570. if (hasReddit && (!this.socialInitialized.reddit || !this.social.reddit)) {
  6571. this.social.reddit = new social_Reddit();
  6572. pro.push(this.#bind('reddit', this.social.reddit.init()));
  6573. }
  6574. }
  6575. if (tasks.twitch) {
  6576. const hasTwitch = Object.values(tasks.twitch).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6577. if (hasTwitch && (!this.socialInitialized.twitch || !this.social.twitch)) {
  6578. this.social.twitch = new social_Twitch();
  6579. pro.push(this.#bind('twitch', this.social.twitch.init()));
  6580. }
  6581. }
  6582. if (tasks.twitter) {
  6583. const hasTwitter = Object.values(tasks.twitter).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6584. if (hasTwitter && (!this.socialInitialized.twitter || !this.social.twitter)) {
  6585. this.social.twitter = new social_Twitter();
  6586. pro.push(this.#bind('twitter', this.social.twitter.init()));
  6587. }
  6588. }
  6589. if (tasks.vk) {
  6590. const hasVk = Object.values(tasks.vk).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6591. if (hasVk && (!this.socialInitialized.vk || !this.social.vk)) {
  6592. this.social.vk = new social_Vk();
  6593. pro.push(this.#bind('vk', this.social.vk.init()));
  6594. }
  6595. }
  6596. if (tasks.youtube) {
  6597. const hasYoutube = Object.values(tasks.youtube).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6598. if (hasYoutube && (!this.socialInitialized.youtube || !this.social.youtube)) {
  6599. this.social.youtube = new Youtube();
  6600. pro.push(this.#bind('youtube', this.social.youtube.init()));
  6601. }
  6602. }
  6603. if (tasks.steam) {
  6604. const steamLength = Object.values(tasks.steam).reduce((total, arr) => [ ...total, ...arr ]).length;
  6605. if (steamLength > 0) {
  6606. if (!this.social.steam) {
  6607. this.social.steam = new social_Steam();
  6608. }
  6609. 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);
  6610. if (steamLength - steamCommunityLength > 0 && !this.socialInitialized.steamStore) {
  6611. pro.push(this.#bind('steamStore', this.social.steam.init('store')));
  6612. }
  6613. if (steamCommunityLength > 0 && !this.socialInitialized.steamCommunity) {
  6614. pro.push(this.#bind('steamCommunity', this.social.steam.init('community')));
  6615. }
  6616. }
  6617. }
  6618. if (tasks.links && tasks.links.length > 0) {
  6619. this.social.visitLink = visitLink;
  6620. }
  6621. return await Promise.all(pro).then(result => {
  6622. let checked = true;
  6623. for (const data of result) {
  6624. if (data.result) {
  6625. this.socialInitialized[data.name] = data.result;
  6626. } else {
  6627. checked = false;
  6628. }
  6629. }
  6630. return checked;
  6631. });
  6632. } catch (error) {
  6633. throwError(error, 'Website.initSocial');
  6634. return false;
  6635. }
  6636. }
  6637. uniqueTasks(allTasks) {
  6638. try {
  6639. const result = {};
  6640. for (const [ social, types ] of Object.entries(allTasks)) {
  6641. result[social] = {};
  6642. for (const [ type, tasks ] of Object.entries(types)) {
  6643. result[social][type] = unique(tasks);
  6644. }
  6645. }
  6646. return result;
  6647. } catch (error) {
  6648. throwError(error, 'Website.uniqueTasks');
  6649. return allTasks;
  6650. }
  6651. }
  6652. async toggleTask(action) {
  6653. try {
  6654. if (!this.initialized && !this.init()) {
  6655. return false;
  6656. }
  6657. if (!await this.classifyTask(action)) {
  6658. return false;
  6659. }
  6660. if (!await this.initSocial(action)) {
  6661. return false;
  6662. }
  6663. const pro = [];
  6664. const doTask = action === 'do';
  6665. const tasks = doTask ? this.undoneTasks : this.socialTasks;
  6666. if (this.socialInitialized.discord !== 'skip' && this.social.discord) {
  6667. pro.push(this.social.discord.toggle({
  6668. doTask: doTask,
  6669. ...tasks.discord
  6670. }));
  6671. }
  6672. if (this.social.instagram) {
  6673. pro.push(this.social.instagram.toggle({
  6674. doTask: doTask,
  6675. ...tasks.instagram
  6676. }));
  6677. }
  6678. if (this.social.reddit) {
  6679. pro.push(this.social.reddit.toggle({
  6680. doTask: doTask,
  6681. ...tasks.reddit
  6682. }));
  6683. }
  6684. if (this.social.twitch) {
  6685. pro.push(this.social.twitch.toggle({
  6686. doTask: doTask,
  6687. ...tasks.twitch
  6688. }));
  6689. }
  6690. if (this.social.twitter) {
  6691. pro.push(this.social.twitter.toggle({
  6692. doTask: doTask,
  6693. ...tasks.twitter
  6694. }));
  6695. }
  6696. if (this.social.vk) {
  6697. pro.push(this.social.vk.toggle({
  6698. doTask: doTask,
  6699. ...tasks.vk
  6700. }));
  6701. }
  6702. if (this.social.youtube) {
  6703. pro.push(this.social.youtube.toggle({
  6704. doTask: doTask,
  6705. ...tasks.youtube
  6706. }));
  6707. }
  6708. if (this.social.steam) {
  6709. pro.push(this.social.steam.toggle({
  6710. doTask: doTask,
  6711. ...tasks.steam
  6712. }));
  6713. }
  6714. if (this.social.visitLink && tasks.links && doTask) {
  6715. for (const link of tasks.links) {
  6716. pro.push(this.social.visitLink(link));
  6717. }
  6718. }
  6719. if (doTask && tasks.extra && this.extraDoTask) {
  6720. const hasExtra = Object.values(tasks.extra).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6721. if (hasExtra) {
  6722. pro.push(this.extraDoTask(tasks.extra));
  6723. }
  6724. }
  6725. await Promise.all(pro);
  6726. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6727. return true;
  6728. } catch (error) {
  6729. throwError(error, 'Website.toggleTask');
  6730. return false;
  6731. }
  6732. }
  6733. async doTask() {
  6734. try {
  6735. return await this.toggleTask('do');
  6736. } catch (error) {
  6737. throwError(error, 'Website.doTask');
  6738. return false;
  6739. }
  6740. }
  6741. async undoTask() {
  6742. try {
  6743. return await this.toggleTask('undo');
  6744. } catch (error) {
  6745. throwError(error, 'Website.undoTask');
  6746. return false;
  6747. }
  6748. }
  6749. }
  6750. const website_Website = Website;
  6751. const defaultTasksTemplate = {
  6752. steam: {
  6753. groupLinks: [],
  6754. wishlistLinks: [],
  6755. curatorLinks: [],
  6756. followLinks: []
  6757. },
  6758. vk: {
  6759. nameLinks: []
  6760. }
  6761. };
  6762. const defaultTasks = JSON.stringify(defaultTasksTemplate);
  6763. class FreeAnyWhere extends website_Website {
  6764. name = 'FreeAnyWhere';
  6765. tasks = [];
  6766. socialTasks = JSON.parse(defaultTasks);
  6767. undoneTasks = JSON.parse(defaultTasks);
  6768. buttons = [ 'doTask', 'undoTask', 'verifyTask', 'getKey' ];
  6769. static test() {
  6770. return window.location.host === 'freeanywhere.net';
  6771. }
  6772. async init() {
  6773. try {
  6774. const logStatus = scripts_echoLog({
  6775. text: i18n('initing')
  6776. });
  6777. if ($('a[href="#/login"]').length > 0) {
  6778. window.open('/#/login', '_self');
  6779. logStatus.warning(i18n('needLogin'));
  6780. return false;
  6781. }
  6782. if (window.location.href.includes('/login')) {
  6783. logStatus.warning(i18n('needLogin'));
  6784. return false;
  6785. }
  6786. if (!/^https?:\/\/freeanywhere\.net\/#\/giveaway\/[\d]+/.test(window.location.href)) {
  6787. const id = window.location.href.match(/https?:\/\/freeanywhere\.net\/.*?#\/giveaway\/([\d]+)/)?.[1];
  6788. if (!id) {
  6789. logStatus.error(i18n('getFailed', 'Id'));
  6790. return false;
  6791. }
  6792. window.location.href = `https://freeanywhere.net/#/giveaway/${id}`;
  6793. }
  6794. if (!this.#getGiveawayId()) {
  6795. return false;
  6796. }
  6797. if (!await this.#checkLeftKey()) {
  6798. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  6799. }
  6800. this.initialized = true;
  6801. logStatus.success();
  6802. return true;
  6803. } catch (error) {
  6804. throwError(error, 'Freeanywhere.init');
  6805. return false;
  6806. }
  6807. }
  6808. async classifyTask(action) {
  6809. try {
  6810. const logStatus = scripts_echoLog({
  6811. text: i18n('getTasksInfo')
  6812. });
  6813. if (action === 'undo') {
  6814. this.socialTasks = GM_getValue(`fawTasks-${this.giveawayId}`)?.tasks || JSON.parse(defaultTasks);
  6815. }
  6816. const {
  6817. result,
  6818. statusText,
  6819. status,
  6820. data
  6821. } = await tools_httpRequest({
  6822. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/?format=json`,
  6823. method: 'GET',
  6824. headers: {
  6825. authorization: `Token ${window.localStorage.getItem('token')}`,
  6826. 'x-csrftoken': external_Cookies_default().get('csrftoken')
  6827. },
  6828. responseType: 'json'
  6829. });
  6830. if (result === 'Success') {
  6831. const tasks = data?.response?.challenges;
  6832. if (tasks) {
  6833. if (action === 'verify') {
  6834. this.tasks = [];
  6835. }
  6836. for (const task of tasks) {
  6837. const type = task.challenge;
  6838. const social = task.challenge_provider;
  6839. const taskInfo = {
  6840. id: task.id,
  6841. title: task.title
  6842. };
  6843. if (action === 'verify' && !task.is_success) {
  6844. this.tasks.push(taskInfo);
  6845. continue;
  6846. }
  6847. switch (social) {
  6848. case 'steam':
  6849. taskInfo.social = 'steam';
  6850. switch (type) {
  6851. case 'WL':
  6852. if (action === 'undo') {
  6853. this.socialTasks.steam.wishlistLinks.push(task.link);
  6854. }
  6855. if (action === 'do' && !task.is_success) {
  6856. this.undoneTasks.steam.wishlistLinks.push(task.link);
  6857. }
  6858. break;
  6859.  
  6860. case 'JTG':
  6861. if (action === 'undo') {
  6862. this.socialTasks.steam.groupLinks.push(task.link);
  6863. }
  6864. if (action === 'do' && !task.is_success) {
  6865. this.undoneTasks.steam.groupLinks.push(task.link);
  6866. }
  6867. break;
  6868.  
  6869. case 'STC':
  6870. if (action === 'undo') {
  6871. this.socialTasks.steam.curatorLinks.push(task.link);
  6872. }
  6873. if (action === 'do' && !task.is_success) {
  6874. this.undoneTasks.steam.curatorLinks.push(task.link);
  6875. }
  6876. break;
  6877.  
  6878. case 'GF':
  6879. if (action === 'undo') {
  6880. this.socialTasks.steam.followLinks.push(task.link);
  6881. }
  6882. if (action === 'do' && !task.is_success) {
  6883. this.undoneTasks.steam.followLinks.push(task.link);
  6884. }
  6885. break;
  6886. }
  6887. break;
  6888.  
  6889. case 'vk-oauth2':
  6890. if (action === 'undo') {
  6891. this.socialTasks.vk.nameLinks.push(task.link);
  6892. }
  6893. if (action === 'do' && !task.is_success) {
  6894. this.undoneTasks.vk.nameLinks.push(task.link);
  6895. }
  6896. break;
  6897.  
  6898. case 'website':
  6899. break;
  6900.  
  6901. default:
  6902. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${social}`);
  6903. break;
  6904. }
  6905. }
  6906. logStatus.success();
  6907. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  6908. this.socialTasks = this.uniqueTasks(this.socialTasks);
  6909. if (window.DEBUG) {
  6910. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  6911. }
  6912. GM_setValue(`fawTasks-${this.giveawayId}`, {
  6913. tasks: this.socialTasks,
  6914. time: new Date().getTime()
  6915. });
  6916. return true;
  6917. }
  6918. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6919. return false;
  6920. }
  6921. logStatus.error(`${result}:${statusText}(${status})`);
  6922. return false;
  6923. } catch (error) {
  6924. throwError(error, 'Freeanywhere.classifyTask');
  6925. return false;
  6926. }
  6927. }
  6928. async verifyTask() {
  6929. try {
  6930. if (!this.initialized && !this.init()) {
  6931. return false;
  6932. }
  6933. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  6934. return false;
  6935. }
  6936. const pro = [];
  6937. for (const task of this.tasks) {
  6938. pro.push(this.#verify(task));
  6939. await delay(1e3);
  6940. }
  6941. await Promise.all(pro);
  6942. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6943. return !!await this.getKey(true);
  6944. } catch (error) {
  6945. throwError(error, 'Freeanywhere.verifyTask');
  6946. return false;
  6947. }
  6948. }
  6949. async getKey(initialized) {
  6950. try {
  6951. if (!initialized && !this.initialized && !this.init()) {
  6952. return false;
  6953. }
  6954. const logStatus = scripts_echoLog({
  6955. text: i18n('gettingKey')
  6956. });
  6957. const {
  6958. result,
  6959. statusText,
  6960. status,
  6961. data
  6962. } = await tools_httpRequest({
  6963. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/reward/?format=json`,
  6964. method: 'GET',
  6965. dataType: 'json',
  6966. headers: {
  6967. authorization: `Token ${window.localStorage.getItem('token')}`
  6968. }
  6969. });
  6970. if (result === 'Success') {
  6971. if (data?.response?.reward) {
  6972. logStatus.success();
  6973. scripts_echoLog({}).success(data.response.reward);
  6974. return data.response.reward;
  6975. }
  6976. if (data?.response?.completed === false) {
  6977. logStatus.error(i18n('tasksNotCompleted'));
  6978. return false;
  6979. }
  6980. if (data?.response?.completed === true) {
  6981. await this.#checkLeftKey();
  6982. }
  6983. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6984. return false;
  6985. }
  6986. logStatus.error(`${result}:${statusText}(${status})`);
  6987. return false;
  6988. } catch (error) {
  6989. throwError(error, 'FreeAnyWhere.getGiveawayId');
  6990. return false;
  6991. }
  6992. }
  6993. #getGiveawayId() {
  6994. try {
  6995. const giveawayId = window.location.href.match(/\/giveaway\/([\d]+)/)?.[1];
  6996. if (giveawayId) {
  6997. this.giveawayId = giveawayId;
  6998. return true;
  6999. }
  7000. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7001. return false;
  7002. } catch (error) {
  7003. throwError(error, 'FreeAnyWhere.getGiveawayId');
  7004. return false;
  7005. }
  7006. }
  7007. async #verify(task) {
  7008. try {
  7009. const logStatus = scripts_echoLog({
  7010. html: `<li>${i18n('verifyingTask')}${task.title.trim()}...<font></font></li>`
  7011. });
  7012. const {
  7013. result,
  7014. statusText,
  7015. status,
  7016. data
  7017. } = await tools_httpRequest({
  7018. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/challenge-status/${task.id}/?format=json`,
  7019. method: 'GET',
  7020. dataType: 'json',
  7021. headers: {
  7022. authorization: `Token ${window.localStorage.getItem('token')}`,
  7023. 'x-csrftoken': external_Cookies_default().get('csrftoken')
  7024. }
  7025. });
  7026. if (result === 'Success') {
  7027. if (data?.response?.status) {
  7028. logStatus.success();
  7029. return true;
  7030. }
  7031. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7032. return false;
  7033. }
  7034. logStatus.error(`${result}:${statusText}(${status})`);
  7035. return false;
  7036. } catch (error) {
  7037. throwError(error, 'Freeanywhere.verify');
  7038. return false;
  7039. }
  7040. }
  7041. async #checkLeftKey() {
  7042. try {
  7043. if (!globalOptions.other.checkLeftKey) {
  7044. return true;
  7045. }
  7046. const {
  7047. data
  7048. } = await tools_httpRequest({
  7049. url: 'https://freeanywhere.net/api/v1/widget/?format=json',
  7050. method: 'GET',
  7051. dataType: 'json',
  7052. headers: {
  7053. authorization: `Token ${window.localStorage.getItem('token')}`
  7054. }
  7055. });
  7056. if (data?.response?.giveaways.find(giveaway => `${giveaway?.id}` === this.giveawayId)) {
  7057. return true;
  7058. }
  7059. await external_Swal_default().fire({
  7060. icon: 'warning',
  7061. title: i18n('notice'),
  7062. text: i18n('noKeysLeft'),
  7063. confirmButtonText: i18n('confirm'),
  7064. cancelButtonText: i18n('cancel'),
  7065. showCancelButton: true
  7066. }).then(({
  7067. value
  7068. }) => {
  7069. if (value) {
  7070. window.close();
  7071. }
  7072. });
  7073. return true;
  7074. } catch (error) {
  7075. throwError(error, 'Giveawaysu.checkLeftKey');
  7076. return false;
  7077. }
  7078. }
  7079. }
  7080. const Freeanywhere = FreeAnyWhere;
  7081. const Giveawaysu_defaultTasks = {
  7082. steam: {
  7083. groupLinks: [],
  7084. wishlistLinks: [],
  7085. curatorLinks: [],
  7086. curatorLikeLinks: [],
  7087. followLinks: [],
  7088. forumLinks: [],
  7089. announcementLinks: [],
  7090. workshopVoteLinks: [],
  7091. playtestLinks: []
  7092. },
  7093. discord: {
  7094. serverLinks: []
  7095. },
  7096. instagram: {
  7097. userLinks: []
  7098. },
  7099. vk: {
  7100. nameLinks: []
  7101. },
  7102. twitch: {
  7103. channelLinks: []
  7104. },
  7105. reddit: {
  7106. redditLinks: []
  7107. },
  7108. youtube: {
  7109. channelLinks: [],
  7110. likeLinks: []
  7111. },
  7112. twitter: {
  7113. userLinks: [],
  7114. retweetLinks: []
  7115. }
  7116. };
  7117. class GiveawaySu extends website_Website {
  7118. name = 'GiveawaySu';
  7119. socialTasks = Giveawaysu_defaultTasks;
  7120. undoneTasks = Giveawaysu_defaultTasks;
  7121. buttons = [ 'doTask', 'undoTask' ];
  7122. static test() {
  7123. return /^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(window.location.href);
  7124. }
  7125. async after() {
  7126. try {
  7127. if (!this.#checkLogin()) {
  7128. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7129. }
  7130. if (!await this.#checkLeftKey()) {
  7131. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7132. }
  7133. scripts_echoLog({}).warning(i18n('gsNotice'));
  7134. } catch (error) {
  7135. throwError(error, 'Giveawaysu.after');
  7136. }
  7137. }
  7138. init() {
  7139. try {
  7140. const logStatus = scripts_echoLog({
  7141. text: i18n('initing')
  7142. });
  7143. if ($('a.steam-login').length > 0) {
  7144. window.open('/steam/redirect', '_self');
  7145. logStatus.warning(i18n('needLogin'));
  7146. return false;
  7147. }
  7148. if (!this.#getGiveawayId()) {
  7149. return false;
  7150. }
  7151. this.initialized = true;
  7152. logStatus.success();
  7153. return true;
  7154. } catch (error) {
  7155. throwError(error, 'Giveawaysu.init');
  7156. return false;
  7157. }
  7158. }
  7159. async classifyTask(action) {
  7160. try {
  7161. const logStatus = scripts_echoLog({
  7162. text: i18n('getTasksInfo')
  7163. });
  7164. if (action === 'undo') {
  7165. this.socialTasks = GM_getValue(`gasTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  7166. return true;
  7167. }
  7168. const pro = [];
  7169. const tasks = $('#actions tr');
  7170. if ($('div.bind-discord').is(':visible')) {
  7171. $('div.bind-discord a')[0].click();
  7172. }
  7173. if ($('div.bind-twitch').is(':visible')) {
  7174. $('div.bind-twitch a')[0].click();
  7175. }
  7176. for (const task of tasks) {
  7177. pro.push(new Promise(resolve => {
  7178. const td = $(task).find('td:not(".hidden")');
  7179. const colorfulTask = td.eq(1).find('a:not([data-trigger="link"])');
  7180. const colorlessTask = td.eq(2).find('a:not([data-trigger="link"])');
  7181. const taskDes = colorfulTask.length > 0 ? colorfulTask : colorlessTask;
  7182. const taskIcon = td.eq(0).find('i').attr('class') || '';
  7183. const taskName = taskDes.text().trim();
  7184. if (taskIcon.includes('ban') || /disable adblock/gi.test(taskName)) {
  7185. return resolve(true);
  7186. }
  7187. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  7188. if (!taskLink) {
  7189. return resolve(false);
  7190. }
  7191. if (taskIcon.includes('steam') && /join/gi.test(taskName)) {
  7192. this.undoneTasks.steam.groupLinks.push(taskLink);
  7193. } else if (/like.*announcement/gi.test(taskName)) {
  7194. this.undoneTasks.steam.announcementLinks.push(taskLink);
  7195. } else if (/(follow|subscribe).*curator/gim.test(taskName) && /^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  7196. this.undoneTasks.steam.curatorLinks.push(taskLink);
  7197. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  7198. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  7199. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  7200. this.undoneTasks.steam.forumLinks.push(taskLink);
  7201. } else if (taskIcon.includes('thumbs-up') && /^https?:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=[\d]+/.test(taskLink)) {
  7202. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7203. } else if (taskIcon.includes('plus') && /request.*playtest/gim.test(taskName)) {
  7204. this.undoneTasks.steam.playtestLinks.push(taskLink);
  7205. } else if (taskIcon.includes('discord') || /join.*discord/gim.test(taskName)) {
  7206. this.undoneTasks.discord.serverLinks.push(taskLink);
  7207. } else if (taskIcon.includes('instagram') || /follow.*instagram/gim.test(taskName)) {
  7208. this.undoneTasks.instagram.userLinks.push(taskLink);
  7209. } else if (taskIcon.includes('twitch') || /follow.*twitch.*channel/gim.test(taskName)) {
  7210. this.undoneTasks.twitch.channelLinks.push(taskLink);
  7211. } else if (taskIcon.includes('reddit') || /subscribe.*subreddit/gim.test(taskName) || /follow.*reddit/gim.test(taskName)) {
  7212. this.undoneTasks.reddit.redditLinks.push(taskLink);
  7213. } else if (/watch.*art/gim.test(taskName)) {
  7214. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7215. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  7216. this.undoneTasks.youtube.channelLinks.push(taskLink);
  7217. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  7218. this.undoneTasks.youtube.likeLinks.push(taskLink);
  7219. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  7220. this.undoneTasks.vk.nameLinks.push(taskLink);
  7221. } else {
  7222. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  7223. if (/wishlist.*game|add.*wishlist/gim.test(taskName)) {
  7224. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  7225. }
  7226. if (/follow.*button/gim.test(taskName)) {
  7227. this.undoneTasks.steam.followLinks.push(taskLink);
  7228. }
  7229. }
  7230. }
  7231. resolve(true);
  7232. }).catch(error => {
  7233. throwError(error, 'Giveawaysu.classifyTask->getRedirectLink');
  7234. return false;
  7235. });
  7236. }));
  7237. }
  7238. await Promise.all(pro);
  7239. logStatus.success();
  7240. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7241. this.socialTasks = this.undoneTasks;
  7242. if (window.DEBUG) {
  7243. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7244. }
  7245. GM_setValue(`gasTasks-${this.giveawayId}`, {
  7246. tasks: this.socialTasks,
  7247. time: new Date().getTime()
  7248. });
  7249. return true;
  7250. } catch (error) {
  7251. throwError(error, 'Giveawaysu.classifyTask');
  7252. return false;
  7253. }
  7254. }
  7255. #checkLogin() {
  7256. try {
  7257. if (!globalOptions.other.checkLogin) {
  7258. return true;
  7259. }
  7260. if ($('a.steam-login').length > 0) {
  7261. window.open('/steam/redirect', '_self');
  7262. }
  7263. return true;
  7264. } catch (error) {
  7265. throwError(error, 'Giveawaysu.checkLogin');
  7266. return false;
  7267. }
  7268. }
  7269. async #checkLeftKey() {
  7270. try {
  7271. if (!globalOptions.other.checkLeftKey) {
  7272. return true;
  7273. }
  7274. if ($('.giveaway-ended').length > 0 && $('.giveaway-key').length === 0) {
  7275. await external_Swal_default().fire({
  7276. icon: 'warning',
  7277. title: i18n('notice'),
  7278. text: i18n('noKeysLeft'),
  7279. confirmButtonText: i18n('confirm'),
  7280. cancelButtonText: i18n('cancel'),
  7281. showCancelButton: true
  7282. }).then(({
  7283. value
  7284. }) => {
  7285. if (value) {
  7286. window.close();
  7287. }
  7288. });
  7289. }
  7290. return true;
  7291. } catch (error) {
  7292. throwError(error, 'Giveawaysu.checkLeftKey');
  7293. return false;
  7294. }
  7295. }
  7296. #getGiveawayId() {
  7297. try {
  7298. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  7299. if (giveawayId) {
  7300. this.giveawayId = giveawayId;
  7301. return true;
  7302. }
  7303. scripts_echoLog({
  7304. text: i18n('getFailed', 'GiveawayId')
  7305. });
  7306. return false;
  7307. } catch (error) {
  7308. throwError(error, 'Giveawaysu.getGiveawayId');
  7309. return false;
  7310. }
  7311. }
  7312. }
  7313. class Indiedb {
  7314. name = 'Indiedb';
  7315. buttons = [ 'doTask' ];
  7316. static test() {
  7317. return window.location.host === 'www.indiedb.com';
  7318. }
  7319. async after() {
  7320. try {
  7321. if (!this.#checkLogin()) {
  7322. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7323. }
  7324. if (!await this.#checkLeftKey()) {
  7325. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7326. }
  7327. } catch (error) {
  7328. throwError(error, 'Indiedb.after');
  7329. }
  7330. }
  7331. async doTask() {
  7332. try {
  7333. if (!await this.#join()) {
  7334. return false;
  7335. }
  7336. return await this.#do();
  7337. } catch (error) {
  7338. throwError(error, 'Indiedb.doTask');
  7339. return false;
  7340. }
  7341. }
  7342. async #join() {
  7343. try {
  7344. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7345. scripts_echoLog({}).error(i18n('needLogin'));
  7346. return false;
  7347. }
  7348. const currentoption = $('a.buttonenter.buttongiveaway');
  7349. if (/join giveaway/gim.test(currentoption.text())) {
  7350. const logStatus = scripts_echoLog({
  7351. text: `${i18n('joiningGiveaway')}...`
  7352. });
  7353. const {
  7354. result,
  7355. statusText,
  7356. status,
  7357. data
  7358. } = await tools_httpRequest({
  7359. url: currentoption.attr('href'),
  7360. method: 'POST',
  7361. data: 'ajax=t',
  7362. dataType: 'json',
  7363. headers: {
  7364. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  7365. accept: 'application/json, text/javascript, */*; q=0.01',
  7366. origin: window.location.origin
  7367. }
  7368. });
  7369. if (result === 'Success') {
  7370. if (data?.status === 200) {
  7371. if (data.response?.success) {
  7372. currentoption.addClass('buttonentered').text('Success - Giveaway joined');
  7373. $('#giveawaysjoined').slideDown();
  7374. $('#giveawaysrecommend').slideDown();
  7375. logStatus.success(`Success${data.response?.text ? `:${data.response?.text}` : ''}`);
  7376. return true;
  7377. }
  7378. logStatus.error(`Error${data.response?.text ? `:${data.response?.text}` : ''}`);
  7379. return false;
  7380. }
  7381. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7382. return false;
  7383. }
  7384. logStatus.error(`${result}:${statusText}(${status})`);
  7385. return false;
  7386. } else if (/success/gim.test($('a.buttonenter.buttongiveaway').text())) {
  7387. return true;
  7388. }
  7389. scripts_echoLog({}).warning(i18n('needJoinGiveaway'));
  7390. return false;
  7391. } catch (error) {
  7392. throwError(error, 'Indiedb.init');
  7393. return false;
  7394. }
  7395. }
  7396. async #do() {
  7397. try {
  7398. const id = $('script').map((index, script) => {
  7399. if (/\$\(document\)/gim.test(script.innerHTML)) {
  7400. return [ script.innerHTML.match(/"\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0], script.innerHTML.match(/"\/newsletter\/ajax\/subscribeprofile\/optin\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0] ];
  7401. }
  7402. return null;
  7403. });
  7404. if (id.length === 2) {
  7405. const pro = [];
  7406. const tasks = $('#giveawaysjoined a[class*=promo]');
  7407. for (const task of tasks) {
  7408. const promo = $(task);
  7409. if (!promo.hasClass('buttonentered')) {
  7410. const status = scripts_echoLog({
  7411. text: `${i18n('doing')}:${promo.parents('p').text()}...`
  7412. });
  7413. if (/facebookpromo|twitterpromo|visitpromo/gim.test(task.className)) {
  7414. let text = '';
  7415. if (promo.hasClass('facebookpromo')) {
  7416. text = 'facebookpromo';
  7417. } else if (promo.hasClass('twitterpromo')) {
  7418. text = 'twitterpromo';
  7419. } else {
  7420. text = 'visitpromo';
  7421. }
  7422. pro.push(new Promise(resolve => {
  7423. $.ajax({
  7424. type: 'POST',
  7425. url: urlPath(`/giveaways/ajax/${text}/${id[0]}`),
  7426. timeout: 6e4,
  7427. dataType: 'json',
  7428. data: {
  7429. ajax: 't'
  7430. },
  7431. error(response, error, exception) {
  7432. if (window.DEBUG) {
  7433. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7434. response: response,
  7435. error: error,
  7436. exception: exception
  7437. });
  7438. }
  7439. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7440. resolve(true);
  7441. },
  7442. success(response) {
  7443. if (response.success) {
  7444. status.success(`Success:${response.text}`);
  7445. promo.addClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7446. resolve(true);
  7447. } else {
  7448. status.error(`Error:${response.text}`);
  7449. resolve(true);
  7450. }
  7451. }
  7452. });
  7453. }));
  7454. } else if (promo.hasClass('emailoptinpromo')) {
  7455. pro.push(new Promise(resolve => {
  7456. $.ajax({
  7457. type: 'POST',
  7458. url: urlPath(`/newsletter/ajax/subscribeprofile/optin/${id[1]}`),
  7459. timeout: 6e4,
  7460. dataType: 'json',
  7461. data: {
  7462. ajax: 't',
  7463. emailsystoggle: 4
  7464. },
  7465. error(response, error, exception) {
  7466. if (window.DEBUG) {
  7467. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7468. response: response,
  7469. error: error,
  7470. exception: exception
  7471. });
  7472. }
  7473. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7474. resolve(true);
  7475. },
  7476. success(response) {
  7477. if (response.success) {
  7478. status.success(`Success:${response.text}`);
  7479. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7480. resolve(true);
  7481. } else {
  7482. status.error(`Error:${response.text}`);
  7483. resolve(true);
  7484. }
  7485. }
  7486. });
  7487. }));
  7488. } else if (promo.hasClass('watchingpromo')) {
  7489. pro.push(new Promise(resolve => {
  7490. const data = getUrlQuery(promo.attr('href'));
  7491. data.ajax = 't';
  7492. $.ajax({
  7493. type: 'POST',
  7494. url: urlPath(promo.attr('href')?.split(/[?#]/)[0]),
  7495. timeout: 6e4,
  7496. dataType: 'json',
  7497. data: data,
  7498. error(response, error, exception) {
  7499. if (window.DEBUG) {
  7500. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7501. response: response,
  7502. error: error,
  7503. exception: exception
  7504. });
  7505. }
  7506. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7507. resolve(true);
  7508. },
  7509. success(response) {
  7510. if (response.success) {
  7511. status.success(`Success:${response.text}`);
  7512. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7513. resolve(true);
  7514. } else {
  7515. status.error(`Error:${response.text}`);
  7516. resolve(true);
  7517. }
  7518. }
  7519. });
  7520. }));
  7521. } else if (!/the-challenge-of-adblock/gim.test(promo.attr('href'))) {
  7522. pro.push(new Promise(resolve => {
  7523. $.ajax({
  7524. type: 'POST',
  7525. url: urlPath(promo.attr('href')),
  7526. timeout: 6e4,
  7527. dataType: 'json',
  7528. data: {
  7529. ajax: 't'
  7530. },
  7531. error(response, error, exception) {
  7532. if (window.DEBUG) {
  7533. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7534. response: response,
  7535. error: error,
  7536. exception: exception
  7537. });
  7538. }
  7539. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7540. resolve(true);
  7541. },
  7542. success(response) {
  7543. if (response.success) {
  7544. status.success(`Success:${response.text}`);
  7545. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7546. resolve(true);
  7547. } else {
  7548. status.error(`Error:${response.text}`);
  7549. resolve(true);
  7550. }
  7551. }
  7552. });
  7553. }));
  7554. } else {
  7555. status.error(`Error:${i18n('unKnownTaskType')}`);
  7556. }
  7557. }
  7558. }
  7559. await Promise.all(pro);
  7560. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7561. return true;
  7562. }
  7563. scripts_echoLog({}).error(i18n('getFailed', 'TaskId'));
  7564. return false;
  7565. } catch (error) {
  7566. throwError(error, 'Indiedb.classifyTask');
  7567. return false;
  7568. }
  7569. }
  7570. #checkLogin() {
  7571. try {
  7572. if (!globalOptions.other.checkLogin) {
  7573. return true;
  7574. }
  7575. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7576. window.open('/members/login', '_self');
  7577. }
  7578. return true;
  7579. } catch (error) {
  7580. throwError(error, 'Indiedb.checkLogin');
  7581. return false;
  7582. }
  7583. }
  7584. async #checkLeftKey() {
  7585. try {
  7586. if (!globalOptions.other.checkLeftKey) {
  7587. return true;
  7588. }
  7589. if ($('a.buttonenter:contains("next time"), a.buttonenter:contains("Giveaway is closed")').length > 0) {
  7590. await external_Swal_default().fire({
  7591. icon: 'warning',
  7592. title: i18n('notice'),
  7593. text: i18n('giveawayEnded'),
  7594. confirmButtonText: i18n('confirm'),
  7595. cancelButtonText: i18n('cancel'),
  7596. showCancelButton: true
  7597. }).then(({
  7598. value
  7599. }) => {
  7600. if (value) {
  7601. window.close();
  7602. }
  7603. });
  7604. }
  7605. return true;
  7606. } catch (error) {
  7607. throwError(error, 'Indiedb.checkLeftKey');
  7608. return false;
  7609. }
  7610. }
  7611. }
  7612. const website_Indiedb = Indiedb;
  7613. const Keyhub_defaultTasksTemplate = {
  7614. steam: {
  7615. groupLinks: [],
  7616. officialGroupLinks: [],
  7617. wishlistLinks: [],
  7618. curatorLinks: []
  7619. },
  7620. discord: {
  7621. serverLinks: []
  7622. },
  7623. extra: {
  7624. videoTasks: []
  7625. },
  7626. links: []
  7627. };
  7628. const Keyhub_defaultTasks = JSON.stringify(Keyhub_defaultTasksTemplate);
  7629. class Keyhub extends website_Website {
  7630. name = 'Keyhub';
  7631. socialTasks = JSON.parse(Keyhub_defaultTasks);
  7632. undoneTasks = JSON.parse(Keyhub_defaultTasks);
  7633. buttons = [ 'doTask', 'undoTask' ];
  7634. static test() {
  7635. return window.location.host === 'key-hub.eu';
  7636. }
  7637. async after() {
  7638. try {
  7639. if (!this.#checkLogin()) {
  7640. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7641. }
  7642. if (!await this.#checkLeftKey()) {
  7643. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7644. }
  7645. $('.NSFW').hide();
  7646. } catch (error) {
  7647. throwError(error, 'Keyhub.after');
  7648. }
  7649. }
  7650. init() {
  7651. try {
  7652. const logStatus = scripts_echoLog({
  7653. text: i18n('initing')
  7654. });
  7655. if ($('a[href*="/connect/steam"]').length > 0) {
  7656. window.open('/connect/steam', '_self');
  7657. logStatus.warning(i18n('needLogin'));
  7658. return false;
  7659. }
  7660. if (!this.#getGiveawayId()) {
  7661. return false;
  7662. }
  7663. $('#VPNoverlay').hide();
  7664. $('#mainArticleSection').show();
  7665. this.initialized = true;
  7666. logStatus.success();
  7667. return true;
  7668. } catch (error) {
  7669. throwError(error, 'Keyhub.init');
  7670. return false;
  7671. }
  7672. }
  7673. async classifyTask(action) {
  7674. try {
  7675. const logStatus = scripts_echoLog({
  7676. text: i18n('getTasksInfo')
  7677. });
  7678. if (action === 'undo') {
  7679. this.socialTasks = GM_getValue(`khTasks-${this.giveawayId}`)?.tasks || JSON.parse(Keyhub_defaultTasks);
  7680. }
  7681. const tasks = $('.task:not(".googleads")').filter((index, element) => action === 'do' ? $(element).find('i.fa-check-circle:visible').length === 0 : true).find('a');
  7682. for (const task of tasks) {
  7683. let link = $(task).attr('href');
  7684. const taskDes = $(task).text().trim();
  7685. if (!link) {
  7686. continue;
  7687. }
  7688. if (/\/away\?data=/.test(link) || /steamcommunity\.com\/gid\//.test(link)) {
  7689. link = await getRedirectLink(link) || link;
  7690. }
  7691. if (/https?:\/\/key-hub\.eu\/connect\/discord/.test(link)) {
  7692. GM_openInTab(link, {
  7693. active: true
  7694. });
  7695. } else if (/steamcommunity\.com\/groups\//.test(link)) {
  7696. if (action === 'undo') {
  7697. this.socialTasks.steam.groupLinks.push(link);
  7698. }
  7699. if (action === 'do') {
  7700. this.undoneTasks.steam.groupLinks.push(link);
  7701. }
  7702. } else if (/steamcommunity\.com\/games\/[\d]+/.test(link)) {
  7703. if (action === 'undo') {
  7704. this.socialTasks.steam.officialGroupLinks.push(link);
  7705. }
  7706. if (action === 'do') {
  7707. this.undoneTasks.steam.officialGroupLinks.push(link);
  7708. }
  7709. } else if (/store\.steampowered\.com\/app\//.test(link) && /wishlist/gim.test(taskDes)) {
  7710. if (action === 'undo') {
  7711. this.socialTasks.steam.wishlistLinks.push(link);
  7712. }
  7713. if (action === 'do') {
  7714. this.undoneTasks.steam.wishlistLinks.push(link);
  7715. }
  7716. } else if (/store\.steampowered\.com\/curator\//.test(link)) {
  7717. if (action === 'undo') {
  7718. this.socialTasks.steam.curatorLinks.push(link);
  7719. }
  7720. if (action === 'do') {
  7721. this.undoneTasks.steam.curatorLinks.push(link);
  7722. }
  7723. } else if (/^https?:\/\/discord\.com\/invite\//.test(link)) {
  7724. if (action === 'undo') {
  7725. this.socialTasks.discord.serverLinks.push(link);
  7726. }
  7727. if (action === 'do') {
  7728. this.undoneTasks.discord.serverLinks.push(link);
  7729. }
  7730. } else if (/^javascript:videoTask.+/.test(link)) {
  7731. if (action === 'do') {
  7732. const taskData = link.match(/javascript:videoTask\('.+?','(.+?)'/)?.[1];
  7733. if (taskData) {
  7734. this.undoneTasks.extra.videoTasks.push(taskData);
  7735. }
  7736. }
  7737. } 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 {
  7738. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  7739. }
  7740. }
  7741. logStatus.success();
  7742. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7743. this.socialTasks = this.uniqueTasks(this.socialTasks);
  7744. if (window.DEBUG) {
  7745. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7746. }
  7747. GM_setValue(`khTasks-${this.giveawayId}`, {
  7748. tasks: this.socialTasks,
  7749. time: new Date().getTime()
  7750. });
  7751. return true;
  7752. } catch (error) {
  7753. throwError(error, 'Keyhub.classifyTask');
  7754. return false;
  7755. }
  7756. }
  7757. async #doScriptTask(data) {
  7758. try {
  7759. const logStatus = scripts_echoLog({
  7760. text: i18n('doingKeyhubTask')
  7761. });
  7762. const {
  7763. result,
  7764. statusText,
  7765. status,
  7766. data: response
  7767. } = await tools_httpRequest({
  7768. url: `/away?data=${data}`,
  7769. method: 'GET',
  7770. headers: {
  7771. origin: 'https://key-hub.eu',
  7772. referer: 'https://key-hub.eu/'
  7773. }
  7774. });
  7775. if (result === 'Success') {
  7776. if (response?.status === 200) {
  7777. logStatus.success();
  7778. return true;
  7779. }
  7780. logStatus.error(`Error:${response?.statusText}(${response?.status})`);
  7781. return false;
  7782. }
  7783. logStatus.error(`${result}:${statusText}(${status})`);
  7784. return false;
  7785. } catch (error) {
  7786. throwError(error, 'Keyhub.doScriptTask');
  7787. return false;
  7788. }
  7789. }
  7790. async extraDoTask({
  7791. videoTasks
  7792. }) {
  7793. try {
  7794. const pro = [];
  7795. for (const data of videoTasks) {
  7796. pro.push(this.#doScriptTask(data));
  7797. }
  7798. return Promise.all(pro).then(() => true);
  7799. } catch (error) {
  7800. throwError(error, 'Keyhub.extraDoTask');
  7801. return false;
  7802. }
  7803. }
  7804. #getGiveawayId() {
  7805. try {
  7806. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  7807. if (giveawayId) {
  7808. this.giveawayId = giveawayId;
  7809. return true;
  7810. }
  7811. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7812. return false;
  7813. } catch (error) {
  7814. throwError(error, 'Keyhub.getGiveawayId');
  7815. return false;
  7816. }
  7817. }
  7818. async #checkLeftKey() {
  7819. try {
  7820. if (!globalOptions.other.checkLeftKey) {
  7821. return true;
  7822. }
  7823. const leftKey = $('#keysleft').text().trim();
  7824. if (leftKey === '0') {
  7825. await external_Swal_default().fire({
  7826. icon: 'warning',
  7827. title: i18n('notice'),
  7828. text: i18n('noKeysLeft'),
  7829. confirmButtonText: i18n('confirm'),
  7830. cancelButtonText: i18n('cancel'),
  7831. showCancelButton: true
  7832. }).then(({
  7833. value
  7834. }) => {
  7835. if (value) {
  7836. window.close();
  7837. }
  7838. });
  7839. }
  7840. return true;
  7841. } catch (error) {
  7842. throwError(error, 'Keyhub.checkLeftKey');
  7843. return false;
  7844. }
  7845. }
  7846. #checkLogin() {
  7847. try {
  7848. if (!globalOptions.other.checkLogin) {
  7849. return true;
  7850. }
  7851. if ($('a[href*="/connect/steam"]').length > 0) {
  7852. window.open('/connect/steam', '_self');
  7853. }
  7854. return true;
  7855. } catch (error) {
  7856. throwError(error, 'Keyhub.checkLogin');
  7857. return false;
  7858. }
  7859. }
  7860. }
  7861. const website_Keyhub = Keyhub;
  7862. const Givekey_defaultTasksTemplate = {
  7863. steam: {
  7864. groupLinks: [],
  7865. wishlistLinks: [],
  7866. curatorLinks: [],
  7867. curatorLikeLinks: []
  7868. },
  7869. twitter: {
  7870. userLinks: []
  7871. },
  7872. vk: {
  7873. nameLinks: []
  7874. },
  7875. discord: {
  7876. serverLinks: []
  7877. }
  7878. };
  7879. const Givekey_defaultTasks = JSON.stringify(Givekey_defaultTasksTemplate);
  7880. class Givekey extends website_Website {
  7881. name = 'Givekey';
  7882. tasks = [];
  7883. socialTasks = JSON.parse(Givekey_defaultTasks);
  7884. undoneTasks = JSON.parse(Givekey_defaultTasks);
  7885. userId;
  7886. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  7887. static test() {
  7888. return window.location.host === 'givekey.ru';
  7889. }
  7890. async after() {
  7891. try {
  7892. await new Promise(resolve => {
  7893. const checker = setInterval(() => {
  7894. if ($('#navbarDropdown').length > 0) {
  7895. clearInterval(checker);
  7896. resolve(true);
  7897. }
  7898. }, 500);
  7899. });
  7900. if (!await this.#checkLeftKey()) {
  7901. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7902. }
  7903. } catch (error) {
  7904. throwError(error, 'Givekey.after');
  7905. }
  7906. }
  7907. init() {
  7908. try {
  7909. const logStatus = scripts_echoLog({
  7910. text: i18n('initing')
  7911. });
  7912. if ($('a[href*="/auth/steam"]').length > 0) {
  7913. window.open('/auth/steam', '_self');
  7914. logStatus.warning(i18n('needLogin'));
  7915. return false;
  7916. }
  7917. if (!this.#getGiveawayId()) {
  7918. return false;
  7919. }
  7920. const userId = $('meta[name="user-id"]').attr('content');
  7921. if (!userId) {
  7922. logStatus.error(i18n('getFailed', i18n('userId')));
  7923. return false;
  7924. }
  7925. this.userId = userId;
  7926. this.initialized = true;
  7927. logStatus.success();
  7928. return true;
  7929. } catch (error) {
  7930. throwError(error, 'Givekey.init');
  7931. return false;
  7932. }
  7933. }
  7934. async classifyTask(action) {
  7935. try {
  7936. const logStatus = scripts_echoLog({
  7937. text: i18n('getTasksInfo')
  7938. });
  7939. if (action === 'undo') {
  7940. this.socialTasks = GM_getValue(`gkTasks-${this.giveawayId}`)?.tasks || JSON.parse(Givekey_defaultTasks);
  7941. }
  7942. const tasks = $('.card-body:has("button") .row');
  7943. for (const task of tasks) {
  7944. const taskEle = $(task);
  7945. const isSuccess = /Complete/i.test(taskEle.find('button').text().trim());
  7946. if (isSuccess && action !== 'undo') {
  7947. continue;
  7948. }
  7949. const checkButton = taskEle.find('#task_check');
  7950. const taskId = checkButton.attr('data-id');
  7951. if (taskId) {
  7952. this.tasks.push(taskId);
  7953. }
  7954. if (action === 'verify') {
  7955. continue;
  7956. }
  7957. let href = taskEle.find('a').attr('href') || null;
  7958. const text = taskEle.find('a').text().trim();
  7959. const icon = taskEle.find('i');
  7960. if (!href || !text) {
  7961. continue;
  7962. }
  7963. if (/^https?:\/\/givekey\.ru\/giveaway\/[\d]+\/execution_task/.test(href)) {
  7964. href = await getRedirectLink(href);
  7965. }
  7966. if (!href) {
  7967. continue;
  7968. }
  7969. if (/^https?:\/\/vk\.com\//.test(href)) {
  7970. this.socialTasks.vk.nameLinks.push(href);
  7971. if (action === 'do' && !isSuccess) {
  7972. this.undoneTasks.vk.nameLinks.push(href);
  7973. }
  7974. } else if (/^https?:\/\/steamcommunity\.com\/groups/.test(href)) {
  7975. this.socialTasks.steam.groupLinks.push(href);
  7976. if (action === 'do' && !isSuccess) {
  7977. this.undoneTasks.steam.groupLinks.push(href);
  7978. }
  7979. } else if (/^https?:\/\/store\.steampowered\.com\/app\//.test(href)) {
  7980. this.socialTasks.steam.wishlistLinks.push(href);
  7981. if (action === 'do' && !isSuccess) {
  7982. this.undoneTasks.steam.wishlistLinks.push(href);
  7983. }
  7984. } else if (/Subscribe/gi.test(text) && icon.hasClass('fa-steam-square')) {
  7985. if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(href)) {
  7986. this.socialTasks.steam.curatorLinks.push(href);
  7987. if (action === 'do' && !isSuccess) {
  7988. this.undoneTasks.steam.curatorLinks.push(href);
  7989. }
  7990. } else {
  7991. this.socialTasks.steam.curatorLikeLinks.push(href);
  7992. if (action === 'do' && !isSuccess) {
  7993. this.undoneTasks.steam.curatorLikeLinks.push(href);
  7994. }
  7995. }
  7996. } else if (/^https?:\/\/twitter\.com\//.test(href) && /Subscribe/gi.test(text)) {
  7997. this.socialTasks.twitter.userLinks.push(href);
  7998. if (action === 'do' && !isSuccess) {
  7999. this.undoneTasks.twitter.userLinks.push(href);
  8000. }
  8001. } else if (icon.hasClass('fa-discord') || /^https?:\/\/discord\.com\/invite\//.test(href)) {
  8002. this.socialTasks.discord.serverLinks.push(href);
  8003. if (action === 'do' && !isSuccess) {
  8004. this.undoneTasks.discord.serverLinks.push(href);
  8005. }
  8006. } else {
  8007. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${text}(${href})`);
  8008. }
  8009. }
  8010. logStatus.success();
  8011. this.tasks = unique(this.tasks);
  8012. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8013. this.socialTasks = this.uniqueTasks(this.socialTasks);
  8014. if (window.DEBUG) {
  8015. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8016. }
  8017. GM_setValue(`gkTasks-${this.giveawayId}`, {
  8018. tasks: this.socialTasks,
  8019. time: new Date().getTime()
  8020. });
  8021. return true;
  8022. } catch (error) {
  8023. throwError(error, 'Givekey.classifyTask');
  8024. return false;
  8025. }
  8026. }
  8027. async verifyTask() {
  8028. try {
  8029. if (!this.initialized && !this.init()) {
  8030. return false;
  8031. }
  8032. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  8033. return false;
  8034. }
  8035. scripts_echoLog({}).warning(i18n('giveKeyNoticeBefore'));
  8036. const taskLength = this.tasks.length;
  8037. for (let i = 0; i < taskLength; i++) {
  8038. await this.#verify(this.tasks[i]);
  8039. if (i < taskLength - 1) {
  8040. await delay(15e3);
  8041. }
  8042. }
  8043. scripts_echoLog({}).success(i18n('allTasksComplete'));
  8044. scripts_echoLog({
  8045. html: `<li><font class="warning">${i18n('giveKeyNoticeAfter')}</font></li>`
  8046. });
  8047. return true;
  8048. } catch (error) {
  8049. throwError(error, 'Givekey.verifyTask');
  8050. return false;
  8051. }
  8052. }
  8053. async #verify(task) {
  8054. try {
  8055. const logStatus = scripts_echoLog({
  8056. html: `<li>${i18n('verifyingTask')}${task}...<font></font></li>`
  8057. });
  8058. return await new Promise(resolve => {
  8059. $.ajax({
  8060. url: 'https://givekey.ru/giveaway/task',
  8061. method: 'POST',
  8062. data: `id=${task}&user_id=${this.userId}`,
  8063. dataType: 'json',
  8064. headers: {
  8065. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  8066. },
  8067. success: data => {
  8068. if (data.btn) {
  8069. $(`button[data-id=${this.userId}]`).html(data.btn);
  8070. }
  8071. if (data.status === 'ok') {
  8072. $(`.task_check_${data.id}`).html(`<button class="btn btn-success mb-2 btn-block" disabled>${data.btn}</button>`);
  8073. logStatus.success();
  8074. resolve(true);
  8075. } else if (data.status === 'end') {
  8076. logStatus.success();
  8077. scripts_echoLog({}).success(data.key);
  8078. resolve(true);
  8079. } else {
  8080. logStatus.error(`Error:${data.msg}`);
  8081. resolve(false);
  8082. }
  8083. },
  8084. error: xhr => {
  8085. logStatus.error(`Error:${xhr.statusText}(${xhr.status})`);
  8086. resolve(false);
  8087. }
  8088. });
  8089. });
  8090. } catch (error) {
  8091. throwError(error, 'Givekey.verify');
  8092. return false;
  8093. }
  8094. }
  8095. #getGiveawayId() {
  8096. try {
  8097. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  8098. if (giveawayId) {
  8099. this.giveawayId = giveawayId;
  8100. return true;
  8101. }
  8102. scripts_echoLog({
  8103. text: i18n('getFailed', 'GiveawayId')
  8104. });
  8105. return false;
  8106. } catch (error) {
  8107. throwError(error, 'Givekey.getGiveawayId');
  8108. return false;
  8109. }
  8110. }
  8111. async #checkLeftKey() {
  8112. try {
  8113. if (!globalOptions.other.checkLeftKey) {
  8114. return true;
  8115. }
  8116. if (!$('#keys_count').text()) {
  8117. await external_Swal_default().fire({
  8118. icon: 'warning',
  8119. title: i18n('notice'),
  8120. text: i18n('noKeysLeft'),
  8121. confirmButtonText: i18n('confirm'),
  8122. cancelButtonText: i18n('cancel'),
  8123. showCancelButton: true
  8124. }).then(({
  8125. value
  8126. }) => {
  8127. if (value) {
  8128. window.close();
  8129. }
  8130. });
  8131. }
  8132. return true;
  8133. } catch (error) {
  8134. throwError(error, 'Givekey.checkLeftKey');
  8135. return false;
  8136. }
  8137. }
  8138. }
  8139. const website_Givekey = Givekey;
  8140. class GiveeClub extends GiveawaySu {
  8141. name = 'GiveeClub';
  8142. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  8143. static test() {
  8144. return /^https?:\/\/givee\.club\/.*?\/event\/[\d]+/.test(window.location.href);
  8145. }
  8146. async after() {
  8147. try {
  8148. if (!this.#checkLogin()) {
  8149. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8150. }
  8151. if (!await this.#checkLeftKey()) {
  8152. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  8153. }
  8154. } catch (error) {
  8155. throwError(error, 'GiveeClub.after');
  8156. }
  8157. }
  8158. init() {
  8159. try {
  8160. const logStatus = scripts_echoLog({
  8161. text: i18n('initing')
  8162. });
  8163. if (!this.#checkLogin()) {
  8164. logStatus.warning(i18n('needLogin'));
  8165. return false;
  8166. }
  8167. if (!this.#getGiveawayId()) {
  8168. return false;
  8169. }
  8170. this.initialized = true;
  8171. logStatus.success();
  8172. return true;
  8173. } catch (error) {
  8174. throwError(error, 'GiveeClub.init');
  8175. return false;
  8176. }
  8177. }
  8178. async classifyTask(action) {
  8179. try {
  8180. const logStatus = scripts_echoLog({
  8181. text: i18n('getTasksInfo')
  8182. });
  8183. if (action === 'undo') {
  8184. this.socialTasks = GM_getValue(`gcTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  8185. return true;
  8186. }
  8187. this.undoneTasks = Giveawaysu_defaultTasks;
  8188. const pro = [];
  8189. const tasks = $('.event-actions tr');
  8190. for (const task of tasks) {
  8191. pro.push(new Promise(resolve => {
  8192. const taskDes = $(task).find('.event-action-label a');
  8193. const taskIcon = $(task).find('.event-action-icon i').attr('class') || '';
  8194. const taskName = taskDes.text().trim();
  8195. const taskType = $(task).find('button[data-type]')?.attr('data-type');
  8196. const taskFinished = $(task).find('.event-action-buttons .btn-success')?.length;
  8197. if (taskIcon.includes('ban') || /AdBlock/i.test(taskName) || taskIcon.includes('envelope') || taskFinished) {
  8198. return resolve(true);
  8199. }
  8200. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  8201. if (!taskLink) {
  8202. return resolve(false);
  8203. }
  8204. if (taskType === 'steam.group.join' && /^https?:\/\/steamcommunity\.com\/groups/.test(taskLink)) {
  8205. this.undoneTasks.steam.groupLinks.push(taskLink);
  8206. } else if (/like.*announcement/gi.test(taskName)) {
  8207. this.undoneTasks.steam.announcementLinks.push(taskLink);
  8208. } else if (taskType === 'steam.game.wishlist' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8209. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  8210. } else if (taskType === 'steam.game.wishlist' && taskDes.attr('data-steam-wishlist-appid')) {
  8211. this.undoneTasks.steam.wishlistLinks.push(`https://store.steampowered.com/app/${taskDes.attr('data-steam-wishlist-appid')}`);
  8212. } else if (taskType === 'steam.game.follow' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8213. this.undoneTasks.steam.followLinks.push(taskLink);
  8214. } else if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  8215. this.undoneTasks.steam.curatorLinks.push(taskLink);
  8216. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  8217. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  8218. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  8219. this.undoneTasks.steam.forumLinks.push(taskLink);
  8220. } else if (taskIcon.includes('discord')) {
  8221. this.undoneTasks.discord.serverLinks.push(taskLink);
  8222. } else if (taskIcon.includes('instagram')) {
  8223. this.undoneTasks.instagram.userLinks.push(taskLink);
  8224. } else if (taskIcon.includes('twitch')) {
  8225. this.undoneTasks.twitch.channelLinks.push(taskLink);
  8226. } else if (taskIcon.includes('reddit')) {
  8227. this.undoneTasks.reddit.redditLinks.push(taskLink);
  8228. } else if (/watch.*art/gim.test(taskName)) {
  8229. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8230. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  8231. this.undoneTasks.youtube.channelLinks.push(taskLink);
  8232. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  8233. this.undoneTasks.youtube.likeLinks.push(taskLink);
  8234. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  8235. this.undoneTasks.vk.nameLinks.push(taskLink);
  8236. } else if (taskIcon.includes('twitter')) {
  8237. if (/https?:\/\/twitter\.com\/[^/]+\/?$/gim.test(taskLink)) {
  8238. this.undoneTasks.twitter.userLinks.push(taskLink);
  8239. } else if (/https?:\/\/twitter\.com\/[^/]+?\/status\/[\d]+/gim.test(taskLink)) {
  8240. this.undoneTasks.twitter.retweetLinks.push(taskLink);
  8241. }
  8242. } else {
  8243. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  8244. if (/follow.*button/gim.test(taskName)) {
  8245. this.undoneTasks.steam.followLinks.push(taskLink);
  8246. }
  8247. }
  8248. }
  8249. resolve(true);
  8250. }).catch(error => {
  8251. throwError(error, 'GiveeClub.classifyTask->getRedirectLink');
  8252. return false;
  8253. });
  8254. }));
  8255. }
  8256. await Promise.all(pro);
  8257. logStatus.success();
  8258. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8259. this.socialTasks = this.undoneTasks;
  8260. if (window.DEBUG) {
  8261. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8262. }
  8263. GM_setValue(`gcTasks-${this.giveawayId}`, {
  8264. tasks: this.socialTasks,
  8265. time: new Date().getTime()
  8266. });
  8267. return true;
  8268. } catch (error) {
  8269. throwError(error, 'GiveeClub.classifyTask');
  8270. return false;
  8271. }
  8272. }
  8273. async verifyTask() {
  8274. try {
  8275. const logStatus = scripts_echoLog({
  8276. text: i18n('giveeClubVerifyNotice')
  8277. });
  8278. const taskButtons = $('.event-actions tr button').has('i.glyphicon-refresh').not('[data-type="user.adblock"]');
  8279. for (const button of taskButtons) {
  8280. button.click();
  8281. if ($(button).attr('data-type') !== 'steam.game.wishlist') {
  8282. await delay(1e3);
  8283. }
  8284. }
  8285. logStatus.warning(i18n('giveeClubVerifyFinished'));
  8286. return true;
  8287. } catch (error) {
  8288. throwError(error, 'Givekey.verifyTask');
  8289. return false;
  8290. }
  8291. }
  8292. #checkLogin() {
  8293. try {
  8294. if (!globalOptions.other.checkLogin) {
  8295. return true;
  8296. }
  8297. if ($('a[href*="/account/auth"]').length > 0) {
  8298. window.open($('a[href*="/account/auth"]').attr('href'), '_self');
  8299. }
  8300. return true;
  8301. } catch (error) {
  8302. throwError(error, 'GiveeClub.checkLogin');
  8303. return false;
  8304. }
  8305. }
  8306. #getGiveawayId() {
  8307. const giveawayId = window.location.href.match(/\/event\/([\d]+)/)?.[1];
  8308. if (giveawayId) {
  8309. this.giveawayId = giveawayId;
  8310. return true;
  8311. }
  8312. scripts_echoLog({
  8313. text: i18n('getFailed', 'GiveawayId')
  8314. });
  8315. return false;
  8316. }
  8317. async #checkLeftKey() {
  8318. try {
  8319. if (!globalOptions.other.checkLeftKey) {
  8320. return true;
  8321. }
  8322. if ($('.event-ended').length > 0 && $('.event-winner').length === 0) {
  8323. await external_Swal_default().fire({
  8324. icon: 'warning',
  8325. title: i18n('notice'),
  8326. text: i18n('giveawayEnded'),
  8327. confirmButtonText: i18n('confirm'),
  8328. cancelButtonText: i18n('cancel'),
  8329. showCancelButton: true
  8330. }).then(({
  8331. value
  8332. }) => {
  8333. if (value) {
  8334. window.close();
  8335. }
  8336. });
  8337. }
  8338. return true;
  8339. } catch (error) {
  8340. throwError(error, 'Giveawaysu.checkLeftKey');
  8341. return false;
  8342. }
  8343. }
  8344. }
  8345. const website_GiveeClub = GiveeClub;
  8346. const defaultOptions = {
  8347. maxPoint: '99999999'
  8348. };
  8349. class OpiumPulses {
  8350. name = 'OpiumPulses';
  8351. options = {
  8352. ...defaultOptions,
  8353. ...GM_getValue('OpiumPulsesOptions')
  8354. };
  8355. maxPoints = 99999999;
  8356. myPoints = 0;
  8357. buttons = [ 'doFreeTask', 'doPointTask' ];
  8358. static test() {
  8359. return window.location.host === 'www.opiumpulses.com';
  8360. }
  8361. async after() {
  8362. try {
  8363. if (!this.#checkLogin()) {
  8364. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8365. }
  8366. this.maxPoints = parseInt(this.options.maxPoint, 10);
  8367. } catch (error) {
  8368. throwError(error, 'OpiumPulses.after');
  8369. }
  8370. }
  8371. async doFreeTask() {
  8372. try {
  8373. this.#toggleTask('FREE');
  8374. } catch (error) {
  8375. throwError(error, 'OpiumPulses.doFreeTask');
  8376. }
  8377. }
  8378. async doPointTask() {
  8379. try {
  8380. this.myPoints = parseInt($('.page-header__nav-func-user-nav-items.points-items').text().match(/[\d]+/gim)?.[0] || '0', 10);
  8381. this.#toggleTask('points');
  8382. } catch (error) {
  8383. throwError(error, 'OpiumPulses.doPointTask');
  8384. }
  8385. }
  8386. async #toggleTask(type) {
  8387. try {
  8388. const items = $(`.giveaways-page-item:contains('${type}'):not(:contains('ENTERED'))`);
  8389. for (const item of items) {
  8390. const needPoints = parseInt($(item).find('.giveaways-page-item-header-points').text().match(/[\d]+/gim)?.[0] || '999999', 10);
  8391. const name = $(item).find('.giveaways-page-item-footer-name').text().trim();
  8392. if (type === 'points' && needPoints > this.myPoints) {
  8393. scripts_echoLog({}).warning(`${i18n('noPoints')}: ${name}`);
  8394. } else if (type === 'points' && !needPoints) {
  8395. scripts_echoLog({}).warning(`${i18n('getNeedPointsFailed')}: ${name}`);
  8396. } else if (!(type === 'points' && needPoints > this.maxPoints)) {
  8397. const logStatus = scripts_echoLog({
  8398. text: `${i18n('joiningLottery')}<a href="${$(item).find('a.giveaways-page-item-img-btn-more').attr('href')}" target="_blank">${name}</a>...`
  8399. });
  8400. const aElement = $(item).find('a.giveaways-page-item-img-btn-enter:contains(\'enter\')');
  8401. if (aElement?.attr('onclick')?.includes('checkUser')) {
  8402. const giveawayId = aElement.attr('onclick')?.match(/[\d]+/)?.[0];
  8403. if (giveawayId) {
  8404. checkUser(giveawayId);
  8405. }
  8406. }
  8407. if (!aElement.attr('href')) {
  8408. logStatus.error('Error: No "href".');
  8409. continue;
  8410. }
  8411. const {
  8412. result,
  8413. statusText,
  8414. status,
  8415. data
  8416. } = await tools_httpRequest({
  8417. url: aElement.attr('href'),
  8418. method: 'GET'
  8419. });
  8420. if (result === 'Success') {
  8421. const {
  8422. result: result0,
  8423. statusText: statusText0,
  8424. status: status0,
  8425. data: data0
  8426. } = await tools_httpRequest({
  8427. url: data?.finalUrl,
  8428. method: 'GET'
  8429. });
  8430. if (data0?.responseText && /You've entered this giveaway/gim.test(data0.responseText)) {
  8431. logStatus.success();
  8432. const points = data0.responseText.match(/Points:[\s]*?([\d]+)/)?.[1];
  8433. if (type === 'points' && points) {
  8434. this.myPoints = parseInt(points, 10);
  8435. }
  8436. } else if (data0?.responseText && /You're not eligible to enter/gim.test(data0.responseText)) {
  8437. logStatus.error('You\'re not eligible to enter');
  8438. } else {
  8439. logStatus.error(`${result0}:${statusText0}(${status0})`);
  8440. }
  8441. } else {
  8442. logStatus.error(`${result}:${statusText}(${status})`);
  8443. }
  8444. }
  8445. }
  8446. scripts_echoLog({
  8447. text: '-----END-----'
  8448. });
  8449. } catch (error) {
  8450. throwError(error, 'OpiumPulses.toggleTask');
  8451. }
  8452. }
  8453. init() {
  8454. return true;
  8455. }
  8456. classifyTask() {
  8457. return true;
  8458. }
  8459. #checkLogin() {
  8460. try {
  8461. if (!globalOptions.other.checkLogin) {
  8462. return true;
  8463. }
  8464. if ($('a[href*="/site/login"]').length > 1) {
  8465. window.open('/site/login', '_self');
  8466. }
  8467. return true;
  8468. } catch (error) {
  8469. throwError(error, 'OpiumPulses.checkLogin');
  8470. return false;
  8471. }
  8472. }
  8473. }
  8474. const website_OpiumPulses = OpiumPulses;
  8475. const external_dayjs_namespaceObject = dayjs;
  8476. var external_dayjs_default = __webpack_require__.n(external_dayjs_namespaceObject);
  8477. const leftKeyChecker = {
  8478. async classify(link) {
  8479. try {
  8480. if (/^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(link)) {
  8481. return await this.giveawaySu(link);
  8482. }
  8483. if (/^https?:\/\/givee\.club\/[\w]+?\/event\/[\d]+/.test(link)) {
  8484. return await this.giveeClub(link);
  8485. }
  8486. if (/^https?:\/\/gleam\.io\/.+?\/.+/.test(link)) {
  8487. return await this.gleam(link);
  8488. }
  8489. if (/^https?:\/\/www\.indiedb\.com\/giveaways\/.+/.test(link)) {
  8490. return await this.indieDb(link);
  8491. }
  8492. if (/^https?:\/\/key-hub\.eu\/giveaway\/[\d]+/.test(link)) {
  8493. return await this.keyhub(link);
  8494. }
  8495. if (/^https?:\/\/opquests\.com\/quests\/[\d]+/.test(link)) {
  8496. return await this.opquests(link);
  8497. }
  8498. if (/^https?:\/\/itch\.io\/s\/[\d]+?\/.*/.test(link)) {
  8499. return await this.itch(link);
  8500. }
  8501. return false;
  8502. } catch (error) {
  8503. throwError(error, 'leftKeyChecker.classify');
  8504. return false;
  8505. }
  8506. },
  8507. async giveawaySu(link) {
  8508. try {
  8509. const {
  8510. result,
  8511. data
  8512. } = await tools_httpRequest({
  8513. url: link,
  8514. method: 'GET'
  8515. });
  8516. if (result === 'Success' && data?.status === 200) {
  8517. if (data.responseText.includes('class="steam-login"')) {
  8518. return false;
  8519. }
  8520. if (data.responseText.includes('class="giveaway-ended"')) {
  8521. return 'Ended';
  8522. }
  8523. return 'Active';
  8524. }
  8525. return false;
  8526. } catch (error) {
  8527. throwError(error, 'leftKeyChecker.giveawaySu');
  8528. return false;
  8529. }
  8530. },
  8531. async giveeClub(link) {
  8532. try {
  8533. const {
  8534. result,
  8535. data
  8536. } = await tools_httpRequest({
  8537. url: link,
  8538. method: 'GET'
  8539. });
  8540. if (result === 'Success' && data?.status === 200) {
  8541. if (data.responseText.includes('class="event-winner"')) {
  8542. return 'Won';
  8543. }
  8544. if (data.responseText.includes('class="event-ended"')) {
  8545. return 'Ended';
  8546. }
  8547. return 'Active';
  8548. }
  8549. return false;
  8550. } catch (error) {
  8551. throwError(error, 'leftKeyChecker.giveeClub');
  8552. return false;
  8553. }
  8554. },
  8555. async gleam(link) {
  8556. try {
  8557. const {
  8558. result,
  8559. data
  8560. } = await tools_httpRequest({
  8561. url: link,
  8562. method: 'GET'
  8563. });
  8564. if (result === 'Success' && data?.status === 200) {
  8565. if (/incentives&quot;:{&quot;[\d]+?&quot;:\[&quot;.+?&quot;\]/.test(data.responseText)) {
  8566. return 'Won';
  8567. }
  8568. const campaignDiv = data.responseText.match(/<div class='popup-blocks-container'[\w\W]+?'>/)?.[0];
  8569. if (!campaignDiv) {
  8570. return false;
  8571. }
  8572. const campaignString = $(campaignDiv).attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  8573. if (!campaignString) {
  8574. return false;
  8575. }
  8576. const {
  8577. campaign
  8578. } = JSON.parse(campaignString);
  8579. if (campaign.banned) {
  8580. return 'Banned';
  8581. }
  8582. if (campaign.finished) {
  8583. return 'Ended';
  8584. }
  8585. if (campaign.paused) {
  8586. return 'Paused';
  8587. }
  8588. if (new Date().getTime() < campaign.starts_at * 1e3) {
  8589. return 'NotStart';
  8590. }
  8591. return 'Active';
  8592. }
  8593. return false;
  8594. } catch (error) {
  8595. throwError(error, 'leftKeyChecker.gleam');
  8596. return false;
  8597. }
  8598. },
  8599. async indieDb(link) {
  8600. try {
  8601. const {
  8602. result,
  8603. data
  8604. } = await tools_httpRequest({
  8605. url: link,
  8606. method: 'GET'
  8607. });
  8608. if (result === 'Success' && data?.status === 200) {
  8609. if (data.responseText.includes('Congrats you WON')) {
  8610. return 'Won';
  8611. }
  8612. if (data.responseText.includes('Giveaway is closed') || data.responseText.includes('next time')) {
  8613. return 'Ended';
  8614. }
  8615. return 'Active';
  8616. }
  8617. return false;
  8618. } catch (error) {
  8619. throwError(error, 'leftKeyChecker.indieDb');
  8620. return false;
  8621. }
  8622. },
  8623. async keyhub(link) {
  8624. try {
  8625. const {
  8626. result,
  8627. data
  8628. } = await tools_httpRequest({
  8629. url: link,
  8630. method: 'GET'
  8631. });
  8632. if (result === 'Success' && data?.status === 200) {
  8633. const keysleft = data.responseText.match(/<span id="keysleft">([\d]+?)<\/span>/)?.[1];
  8634. if (!keysleft) {
  8635. return false;
  8636. }
  8637. if (keysleft === '0') {
  8638. return 'Ended';
  8639. }
  8640. return `Active(${keysleft})`;
  8641. }
  8642. return false;
  8643. } catch (error) {
  8644. throwError(error, 'leftKeyChecker.keyhub');
  8645. return false;
  8646. }
  8647. },
  8648. async opquests(link) {
  8649. try {
  8650. const {
  8651. result,
  8652. data
  8653. } = await tools_httpRequest({
  8654. url: link,
  8655. method: 'GET'
  8656. });
  8657. if (result === 'Success' && data?.status === 200) {
  8658. const keysleft = data.responseText.match(/<div class="">[\s]*?([\d]+?)[\s]*?of/)?.[1];
  8659. if (!keysleft) {
  8660. return false;
  8661. }
  8662. if (keysleft === '0') {
  8663. return 'Ended';
  8664. }
  8665. return `Active(${keysleft})`;
  8666. } else if (data?.status === 404) {
  8667. return 'Ended';
  8668. }
  8669. return false;
  8670. } catch (error) {
  8671. throwError(error, 'leftKeyChecker.opquests');
  8672. return false;
  8673. }
  8674. },
  8675. async itch(link) {
  8676. try {
  8677. const {
  8678. result,
  8679. data
  8680. } = await tools_httpRequest({
  8681. url: link,
  8682. method: 'GET'
  8683. });
  8684. if (result === 'Success' && data?.status === 200) {
  8685. const endDate = data.responseText.match(/{"start_date":"[0-9A-Z-:]+?".*?"end_date":"([0-9A-Z-:]+?)".*?}/)?.[1];
  8686. if (!endDate) {
  8687. return false;
  8688. }
  8689. if (new Date().getTime() > new Date(endDate).getTime()) {
  8690. return 'Ended';
  8691. }
  8692. return `Active(${external_dayjs_default()(endDate).format('YYYY-MM-DD HH:mm:ss')})`;
  8693. }
  8694. return false;
  8695. } catch (error) {
  8696. throwError(error, 'leftKeyChecker.itch');
  8697. return false;
  8698. }
  8699. }
  8700. };
  8701. const website_leftKeyChecker = leftKeyChecker;
  8702. const Keylol_defaultTasksTemplate = {
  8703. steam: {
  8704. groupLinks: [],
  8705. wishlistLinks: [],
  8706. curatorLinks: [],
  8707. curatorLikeLinks: [],
  8708. followLinks: [],
  8709. forumLinks: [],
  8710. announcementLinks: [],
  8711. workshopVoteLinks: [],
  8712. licenseLinks: []
  8713. },
  8714. discord: {
  8715. serverLinks: []
  8716. },
  8717. instagram: {
  8718. userLinks: []
  8719. },
  8720. vk: {
  8721. nameLinks: []
  8722. },
  8723. twitch: {
  8724. channelLinks: []
  8725. },
  8726. reddit: {
  8727. redditLinks: []
  8728. },
  8729. twitter: {
  8730. userLinks: [],
  8731. retweetLinks: []
  8732. },
  8733. youtube: {
  8734. channelLinks: [],
  8735. likeLinks: []
  8736. }
  8737. };
  8738. const Keylol_defaultTasks = JSON.stringify(Keylol_defaultTasksTemplate);
  8739. class Keylol extends website_Website {
  8740. name = 'Keylol';
  8741. socialTasks = JSON.parse(Keylol_defaultTasks);
  8742. undoneTasks = JSON.parse(Keylol_defaultTasks);
  8743. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect' ];
  8744. static test() {
  8745. 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'));
  8746. }
  8747. init() {
  8748. return true;
  8749. }
  8750. after() {
  8751. try {
  8752. const selector = this.name === 'Keylol' ? '#postlist>div[id^="post_"]:first' : 'div.container';
  8753. const mainPost = $(selector);
  8754. const discordLinks = mainPost.find('a[href*="discord.com"]:visible');
  8755. const redditLinks = mainPost.find('a[href*="reddit.com"]:visible');
  8756. const insLinks = mainPost.find('a[href*="instagram.com"]:visible');
  8757. const twitterLinks = mainPost.find('a[href*="twitter.com"]:visible,a[href*="x.com"]:visible');
  8758. const twitchLinks = mainPost.find('a[href*="twitch.tv"]:visible');
  8759. const vkLinks = mainPost.find('a[href*="vk.com"]:visible');
  8760. const steamStoreLinks = mainPost.find('a[href*="store.steampowered.com"]:visible');
  8761. const steamCommunityLinks = mainPost.find('a[href*="steamcommunity.com"]:visible');
  8762. const ytbLinks = mainPost.find('a[href*="youtube.com"]:visible');
  8763. if (discordLinks.length > 0) {
  8764. for (const discordLink of discordLinks) {
  8765. const link = $(discordLink).attr('href');
  8766. if (!(link && /^https?:\/\/discord\.com\/invite\/.+/.test(link))) {
  8767. continue;
  8768. }
  8769. this.#addBtn(discordLink, 'discord', 'serverLinks', link);
  8770. }
  8771. }
  8772. if (redditLinks.length > 0) {
  8773. for (const redditLink of redditLinks) {
  8774. const link = $(redditLink).attr('href');
  8775. if (!(link && /^https?:\/\/www\.reddit\.com\/(r|user)\/.+/.test(link))) {
  8776. continue;
  8777. }
  8778. this.#addBtn(redditLink, 'reddit', 'redditLinks', link);
  8779. }
  8780. }
  8781. if (insLinks.length > 0) {
  8782. for (const insLink of insLinks) {
  8783. const link = $(insLink).attr('href');
  8784. if (!(link && /^https:\/\/www\.instagram\.com\/.+/.test(link))) {
  8785. continue;
  8786. }
  8787. this.#addBtn(insLink, 'instagram', 'userLinks', link);
  8788. }
  8789. }
  8790. if (twitterLinks.length > 0) {
  8791. for (const twitterLink of twitterLinks) {
  8792. const link = $(twitterLink).attr('href');
  8793. if (!(link && /^https:\/\/twitter\.com\/.+/.test(link))) {
  8794. continue;
  8795. }
  8796. if (/https:\/\/twitter\.com\/.*?\/status\/[\d]+/.test(link)) {
  8797. this.#addBtn(twitterLink, 'twitter', 'retweetLinks', link);
  8798. } else {
  8799. this.#addBtn(twitterLink, 'twitter', 'userLinks', link);
  8800. }
  8801. }
  8802. }
  8803. if (twitchLinks.length > 0) {
  8804. for (const twitchLink of twitchLinks) {
  8805. const link = $(twitchLink).attr('href');
  8806. if (!(link && /^https:\/\/(www\.)?twitch\.tv\/.+/.test(link))) {
  8807. continue;
  8808. }
  8809. this.#addBtn(twitchLink, 'twitch', 'channelLinks', link);
  8810. }
  8811. }
  8812. if (vkLinks.length > 0) {
  8813. for (const vkLink of vkLinks) {
  8814. const link = $(vkLink).attr('href');
  8815. if (!(link && /^https:\/\/vk\.com\/.+/.test(link))) {
  8816. continue;
  8817. }
  8818. this.#addBtn(vkLink, 'vk', 'nameLinks', link);
  8819. }
  8820. }
  8821. if (steamStoreLinks.length > 0) {
  8822. for (const steamStoreLink of steamStoreLinks) {
  8823. const link = $(steamStoreLink).attr('href');
  8824. if (!link) {
  8825. continue;
  8826. }
  8827. if (/curator\/[\d]+/.test(link)) {
  8828. this.#addBtn(steamStoreLink, 'steam', 'curatorLinks', link);
  8829. } else if (/(publisher|developer|franchise)\/.+/.test(link)) {
  8830. this.#addBtn(steamStoreLink, 'steam', 'curatorLikeLinks', link);
  8831. } else if (/news(hub)?\/app\/[\d]+\/view\/[\d]+/.test(link)) {
  8832. this.#addBtn(steamStoreLink, 'steam', 'announcementLinks', link);
  8833. } else if (/app\/[\d]+/.test(link)) {
  8834. this.#addBtn(steamStoreLink, 'steam', 'followLinks', link);
  8835. this.#addBtn(steamStoreLink, 'steam', 'wishlistLinks', link);
  8836. }
  8837. }
  8838. }
  8839. if (steamCommunityLinks.length > 0) {
  8840. for (const steamCommunityLink of steamCommunityLinks) {
  8841. const link = $(steamCommunityLink).attr('href');
  8842. if (!link) {
  8843. continue;
  8844. }
  8845. if (/groups\/.+/.test(link)) {
  8846. this.#addBtn(steamCommunityLink, 'steam', 'groupLinks', link);
  8847. } else if (/announcements\/detail\/[\d]+/.test(link)) {
  8848. this.#addBtn(steamCommunityLink, 'steam', 'announcementLinks', link);
  8849. }
  8850. }
  8851. }
  8852. if (ytbLinks.length > 0) {
  8853. for (const ytbLink of ytbLinks) {
  8854. const link = $(ytbLink).attr('href');
  8855. if (!link) {
  8856. continue;
  8857. }
  8858. this.#addBtn(ytbLink, 'youtube', 'channelLinks', link);
  8859. this.#addBtn(ytbLink, 'youtube', 'likeLinks', link);
  8860. }
  8861. }
  8862. 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');
  8863. if (giveawayLinks.length > 0) {
  8864. for (const giveawayLink of giveawayLinks) {
  8865. const link = $(giveawayLink).attr('href');
  8866. if (!link) {
  8867. continue;
  8868. }
  8869. website_leftKeyChecker.classify(link).then(status => {
  8870. if (!status) {
  8871. return;
  8872. }
  8873. if (/^Active/.test(status)) {
  8874. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status active" title="${i18n('Active')}">${status}</font>`);
  8875. return;
  8876. }
  8877. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status not-active" title="${i18n(status)}">${status}</font>`);
  8878. }).catch(error => {
  8879. throwError(error, 'keylol.after -> leftKeyChecker');
  8880. });
  8881. }
  8882. }
  8883. if (this.name === 'Keylol') {
  8884. const asfLinks = mainPost.find('a[href^="#asf"]:visible');
  8885. if (asfLinks.length > 0) {
  8886. for (const asfLink of asfLinks) {
  8887. const link = $(asfLink).attr('href');
  8888. if (!link) {
  8889. continue;
  8890. }
  8891. this.#addBtn($(`a[href="${link}"]`).after('<span style="color: #ccc; margin: 0 -5px 0 5px"> | </span>').next()[0], 'steam', 'licenseLinks', `appid-${link.replace('#asf', '')}`);
  8892. }
  8893. }
  8894. const subLinks = mainPost.find('a[href*="steamdb.info/sub/"]:visible');
  8895. if (subLinks.length > 0) {
  8896. for (const subLink of subLinks) {
  8897. const link = $(subLink).attr('href');
  8898. if (!link) {
  8899. continue;
  8900. }
  8901. const subid = link.match(/^https:\/\/steamdb\.info\/sub\/([\d]+)/)?.[1];
  8902. if (!subid) {
  8903. continue;
  8904. }
  8905. this.#addBtn(subLink, 'steam', 'licenseLinks', `subid-${subid}`);
  8906. }
  8907. }
  8908. const asfLinks2 = mainPost.find('.blockcode:contains("addlicense"):visible');
  8909. if (asfLinks2.length > 0) {
  8910. for (const asfLink of asfLinks2) {
  8911. const appid = [ ...asfLink.innerText.matchAll(/a(pp)?\/([\d]+)/g) ].map(matched => matched?.[2]).filter(id => id) || [];
  8912. if (appid.length > 0) {
  8913. this.#addBtn($(asfLink).children('em')[0], 'steam', 'licenseLinks', `appid-${appid.join(',')}`);
  8914. }
  8915. const subid = asfLink.innerText.match(/[\d]+/g)?.filter(matched => !appid.includes(matched));
  8916. if (!subid || subid.length === 0) {
  8917. continue;
  8918. }
  8919. this.#addBtn($(asfLink).children('em')[0], 'steam', 'licenseLinks', `subid-${subid.join(',')}`);
  8920. }
  8921. }
  8922. }
  8923. } catch (error) {
  8924. throwError(error, 'keylol.after');
  8925. }
  8926. }
  8927. classifyTask(action) {
  8928. try {
  8929. this.socialTasks = JSON.parse(Keylol_defaultTasks);
  8930. this.undoneTasks = JSON.parse(Keylol_defaultTasks);
  8931. const selectedBtns = $('.auto-task-keylol[selected="selected"]:visible');
  8932. for (const btn of selectedBtns) {
  8933. const button = $(btn);
  8934. const social = button.attr('data-social');
  8935. const type = button.attr('data-type');
  8936. const link = button.attr('data-link');
  8937. if (!(social && type && link)) {
  8938. continue;
  8939. }
  8940. if (action === 'do') {
  8941. this.undoneTasks[social][type].push(link);
  8942. }
  8943. if (action === 'undo') {
  8944. this.socialTasks[social][type].push(link);
  8945. }
  8946. }
  8947. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8948. this.socialTasks = this.uniqueTasks(this.socialTasks);
  8949. if (window.DEBUG) {
  8950. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8951. }
  8952. return true;
  8953. } catch (error) {
  8954. throwError(error, 'Keylol.classifyTask');
  8955. return false;
  8956. }
  8957. }
  8958. selectAll() {
  8959. try {
  8960. $('.auto-task-keylol:visible').attr('selected', 'selected');
  8961. } catch (error) {
  8962. throwError(error, 'Keylol.selectAll');
  8963. }
  8964. }
  8965. selectNone() {
  8966. try {
  8967. $('.auto-task-keylol:visible').removeAttr('selected');
  8968. } catch (error) {
  8969. throwError(error, 'Keylol.selectNone');
  8970. }
  8971. }
  8972. invertSelect() {
  8973. try {
  8974. $('.auto-task-keylol:visible').each((index, element) => {
  8975. element.getAttribute('selected') ? element.removeAttribute('selected') : element.setAttribute('selected', 'selected');
  8976. });
  8977. } catch (error) {
  8978. throwError(error, 'Keylol.invertSelect');
  8979. }
  8980. }
  8981. #addBtn(before, social, linkType, link) {
  8982. try {
  8983. $(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>`);
  8984. } catch (error) {
  8985. throwError(error, 'keylol.addBtn');
  8986. }
  8987. }
  8988. }
  8989. const website_Keylol = Keylol;
  8990. const Opquests_defaultTasks = {
  8991. steam: {
  8992. groupLinks: [],
  8993. wishlistLinks: [],
  8994. followLinks: [],
  8995. curatorLikeLinks: []
  8996. }
  8997. };
  8998. class Opquests extends website_Website {
  8999. name = 'Opquests';
  9000. undoneTasks = {
  9001. ...Opquests_defaultTasks
  9002. };
  9003. buttons = [ 'doTask', 'verifyTask', 'getKey' ];
  9004. static test() {
  9005. return window.location.host === 'opquests.com';
  9006. }
  9007. async before() {
  9008. try {
  9009. const opquestsVerifyTasks = GM_getValue('opquestsVerifyTasks') || [];
  9010. if (opquestsVerifyTasks.length > 0) {
  9011. const taskId = opquestsVerifyTasks.pop();
  9012. GM_setValue('opquestsVerifyTasks', opquestsVerifyTasks);
  9013. const [ verifyBtn ] = $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]');
  9014. if (verifyBtn) {
  9015. verifyBtn.click();
  9016. return;
  9017. }
  9018. }
  9019. if (GM_getValue('opquestsVerifyTasks')) {
  9020. GM_deleteValue('opquestsVerifyTasks');
  9021. }
  9022. } catch (error) {
  9023. throwError(error, 'Opquests.before');
  9024. }
  9025. }
  9026. async after() {
  9027. try {
  9028. if (!this.#checkLogin()) {
  9029. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9030. }
  9031. } catch (error) {
  9032. throwError(error, 'Opquests.after');
  9033. }
  9034. }
  9035. init() {
  9036. try {
  9037. const logStatus = scripts_echoLog({
  9038. text: i18n('initing')
  9039. });
  9040. if ($('a[href*="/auth/redirect"]').length > 0) {
  9041. window.open('/auth/redirect', '_self');
  9042. logStatus.warning(i18n('needLogin'));
  9043. return false;
  9044. }
  9045. if (!this.#getGiveawayId()) {
  9046. return false;
  9047. }
  9048. this.initialized = true;
  9049. logStatus.success();
  9050. return true;
  9051. } catch (error) {
  9052. throwError(error, 'Opquests.init');
  9053. return false;
  9054. }
  9055. }
  9056. async classifyTask(action) {
  9057. try {
  9058. if (action === 'undo') {
  9059. scripts_echoLog({
  9060. text: i18n('cannotUndo')
  9061. });
  9062. return false;
  9063. }
  9064. const logStatus = scripts_echoLog({
  9065. text: i18n('getTasksInfo')
  9066. });
  9067. const tasks = $('.w-full:contains("Validate") .items-center');
  9068. for (const task of tasks) {
  9069. const link = $(task).find('a:contains("Open")').attr('href');
  9070. const taskDes = $(task).find('div').eq(1).text().trim();
  9071. if (!link) {
  9072. continue;
  9073. }
  9074. if (/steamcommunity\.com\/groups\//.test(link)) {
  9075. this.undoneTasks.steam.groupLinks.push(link);
  9076. } else if (/store\.steampowered\.com\/app\//.test(link)) {
  9077. if (/wishlist/gim.test(taskDes)) {
  9078. this.undoneTasks.steam.wishlistLinks.push(link);
  9079. } else if (/follow/gim.test(taskDes)) {
  9080. this.undoneTasks.steam.followLinks.push(link);
  9081. }
  9082. } else if (/store\.steampowered\.com\/(publisher|developer|curator)\//.test(link) && /follow/gim.test(taskDes)) {
  9083. this.undoneTasks.steam.curatorLikeLinks.push(link);
  9084. } else {
  9085. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  9086. }
  9087. }
  9088. logStatus.success();
  9089. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9090. if (window.DEBUG) {
  9091. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9092. }
  9093. return true;
  9094. } catch (error) {
  9095. throwError(error, 'Opquests.classifyTask');
  9096. return false;
  9097. }
  9098. }
  9099. async verifyTask() {
  9100. try {
  9101. if (!this.initialized) {
  9102. this.init();
  9103. }
  9104. const tasks = $.makeArray($('div.w-full').find('.items-center').has('button.submit-loader')).map(ele => $(ele).find('input[name="task_id"]').val());
  9105. await this.#confirm();
  9106. const taskId = tasks.pop();
  9107. GM_setValue('opquestsVerifyTasks', tasks);
  9108. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9109. return true;
  9110. } catch (error) {
  9111. throwError(error, 'Opquests.verifyTask');
  9112. return false;
  9113. }
  9114. }
  9115. async #confirm() {
  9116. try {
  9117. const logStatus = scripts_echoLog({
  9118. html: `<li>${i18n('confirmingTask')}...<font></font></li>`
  9119. });
  9120. const {
  9121. result,
  9122. statusText,
  9123. status,
  9124. data
  9125. } = await tools_httpRequest({
  9126. url: `https://opquests.com/quests/${this.giveawayId}?confirm=1`,
  9127. method: 'GET',
  9128. nochche: true,
  9129. headers: {
  9130. origin: 'https://opquests.com',
  9131. referer: `https://opquests.com/warning?id=${this.giveawayId}`
  9132. }
  9133. });
  9134. if (result === 'Success') {
  9135. if (data?.status === 200) {
  9136. logStatus.success();
  9137. return true;
  9138. }
  9139. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9140. return false;
  9141. }
  9142. logStatus.error(`${result}:${statusText}(${status})`);
  9143. return false;
  9144. } catch (error) {
  9145. throwError(error, 'Opquests.confirm');
  9146. return false;
  9147. }
  9148. }
  9149. async getKey(isButton) {
  9150. try {
  9151. const logStatus = scripts_echoLog({
  9152. text: i18n('gettingKey')
  9153. });
  9154. const {
  9155. result,
  9156. statusText,
  9157. status,
  9158. data
  9159. } = await tools_httpRequest({
  9160. url: 'https://opquests.com/keys',
  9161. method: 'GET'
  9162. });
  9163. if (result === 'Success') {
  9164. if (data?.responseText) {
  9165. const key = $(data?.responseText).find(`div.items-center:contains("${$('h1.font-bold').text().trim().replace(' Quest', '')}")`).find('div.font-bold').next().text();
  9166. if (!key) {
  9167. logStatus.error('Error: Key was not found');
  9168. if (isButton) {
  9169. window.open('https://opquests.com/keys', '_self');
  9170. }
  9171. return false;
  9172. }
  9173. logStatus.success();
  9174. scripts_echoLog({}).success(key);
  9175. return true;
  9176. }
  9177. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9178. return false;
  9179. }
  9180. logStatus.error(`${result}:${statusText}(${status})`);
  9181. return false;
  9182. } catch (error) {
  9183. throwError(error, 'Opquests.getGiveawayId');
  9184. return false;
  9185. }
  9186. }
  9187. #getGiveawayId() {
  9188. try {
  9189. const giveawayId = window.location.href.match(/quests\/([\d]+)/)?.[1];
  9190. if (giveawayId) {
  9191. this.giveawayId = giveawayId;
  9192. return true;
  9193. }
  9194. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  9195. return false;
  9196. } catch (error) {
  9197. throwError(error, 'Opquests.getGiveawayId');
  9198. return false;
  9199. }
  9200. }
  9201. #checkLogin() {
  9202. try {
  9203. if (!globalOptions.other.checkLogin) {
  9204. return true;
  9205. }
  9206. if ($('a[href*="/auth/redirect"]').length > 0) {
  9207. window.open('/auth/redirect', '_self');
  9208. }
  9209. return true;
  9210. } catch (error) {
  9211. throwError(error, 'Opquests.checkLogin');
  9212. return false;
  9213. }
  9214. }
  9215. }
  9216. const website_Opquests = Opquests;
  9217. const Gleam_defaultTasksTemplate = {
  9218. steam: {
  9219. groupLinks: [],
  9220. wishlistLinks: [],
  9221. followLinks: [],
  9222. curatorLinks: [],
  9223. curatorLikeLinks: []
  9224. },
  9225. twitter: {
  9226. userLinks: [],
  9227. retweetLinks: []
  9228. },
  9229. twitch: {
  9230. channelLinks: []
  9231. },
  9232. discord: {
  9233. serverLinks: []
  9234. },
  9235. youtube: {
  9236. channelLinks: []
  9237. },
  9238. extra: {
  9239. gleam: []
  9240. }
  9241. };
  9242. const Gleam_defaultTasks = JSON.stringify(Gleam_defaultTasksTemplate);
  9243. class Gleam extends website_Website {
  9244. name = 'Gleam';
  9245. undoneTasks = JSON.parse(Gleam_defaultTasks);
  9246. socialTasks = JSON.parse(Gleam_defaultTasks);
  9247. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  9248. static test() {
  9249. return window.location.host === 'gleam.io';
  9250. }
  9251. before() {
  9252. try {
  9253. unsafeWindow.confirm = () => {};
  9254. unsafeWindow.alert = () => {};
  9255. unsafeWindow.prompt = () => {};
  9256. } catch (error) {
  9257. throwError(error, 'Gleam.before');
  9258. }
  9259. }
  9260. async after() {
  9261. try {
  9262. if (window.location.search.includes('8b07d23f4bfa65f9')) {
  9263. const checkComplete = setInterval(() => {
  9264. if ($('.entry-content .entry-method i.fa-check').length > 0) {
  9265. clearInterval(checkComplete);
  9266. window.close();
  9267. }
  9268. });
  9269. for (const task of $('.entry-content .entry-method')) {
  9270. const taskInfo = $(task).find('.user-links');
  9271. const expandInfo = $(task).find('.expandable');
  9272. const aElements = expandInfo.find('a.btn,a:contains(Continue),button:contains(Continue)');
  9273. if (aElements.length > 0) {
  9274. for (const element of aElements) {
  9275. const $element = $(element);
  9276. const href = $element.attr('href');
  9277. $element.removeAttr('href')[0].click();
  9278. $element.attr('href', href);
  9279. await delay(1e3);
  9280. }
  9281. }
  9282. taskInfo[0].click();
  9283. await delay(1e3);
  9284. }
  9285. scripts_echoLog({}).warning(i18n('gleamTaskNotice'));
  9286. } else if (!await this.#checkLeftKey()) {
  9287. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  9288. }
  9289. } catch (error) {
  9290. throwError(error, 'Gleam.after');
  9291. }
  9292. }
  9293. init() {
  9294. try {
  9295. const logStatus = scripts_echoLog({
  9296. text: i18n('initing')
  9297. });
  9298. if (!this.#getGiveawayId()) {
  9299. return false;
  9300. }
  9301. this.initialized = true;
  9302. logStatus.success();
  9303. return true;
  9304. } catch (error) {
  9305. throwError(error, 'Gleam.init');
  9306. return false;
  9307. }
  9308. }
  9309. async classifyTask(action) {
  9310. try {
  9311. const logStatus = scripts_echoLog({
  9312. text: i18n('getTasksInfo')
  9313. });
  9314. if (action === 'undo') {
  9315. this.socialTasks = GM_getValue(`gleamTasks-${this.giveawayId}`)?.tasks || JSON.parse(Gleam_defaultTasks);
  9316. }
  9317. const tasks = $('.entry-content .entry-method');
  9318. for (const task of tasks) {
  9319. const $task = $(task);
  9320. if (action === 'do' && $task.find('i.fa-question').length === 0) {
  9321. continue;
  9322. }
  9323. const socialIcon = $task.find('.icon-wrapper i');
  9324. const taskInfo = $task.find('.user-links');
  9325. const taskText = taskInfo.text().trim();
  9326. const expandInfo = $task.find('.expandable');
  9327. const aElements = expandInfo.find('a.btn');
  9328. if (aElements.length > 0) {
  9329. for (const element of aElements) {
  9330. const $element = $(element);
  9331. const href = $element.attr('href');
  9332. $element.removeAttr('href')[0].click();
  9333. $element.attr('href', href);
  9334. }
  9335. }
  9336. if (socialIcon.hasClass('fa-twitter') || socialIcon.hasClass('fa-x-twitter')) {
  9337. const link = $task.find('a[href^="https://twitter.com/"],a[href^="https://x.com/"]').attr('href');
  9338. if (!link) {
  9339. continue;
  9340. }
  9341. if (/follow/gi.test(taskText)) {
  9342. if (action === 'undo') {
  9343. this.socialTasks.twitter.userLinks.push(link);
  9344. }
  9345. if (action === 'do') {
  9346. this.undoneTasks.twitter.userLinks.push(link);
  9347. }
  9348. } else if (/retweet/gim.test(taskText)) {
  9349. if (action === 'undo') {
  9350. this.socialTasks.twitter.retweetLinks.push(link);
  9351. }
  9352. if (action === 'do') {
  9353. this.undoneTasks.twitter.retweetLinks.push(link);
  9354. }
  9355. }
  9356. } else if (socialIcon.hasClass('fa-twitch')) {
  9357. if (/follow/gim.test(taskText)) {
  9358. const link = $task.find('a[href^="https://twitch.tv/"]').attr('href');
  9359. if (!link) {
  9360. continue;
  9361. }
  9362. if (action === 'undo') {
  9363. this.socialTasks.twitch.channelLinks.push(link);
  9364. }
  9365. if (action === 'do') {
  9366. this.undoneTasks.twitch.channelLinks.push(link);
  9367. }
  9368. }
  9369. } else if (socialIcon.hasClass('fa-discord')) {
  9370. if (/join/gim.test(taskText)) {
  9371. let link = $task.find('a[href^="https://discord.com/invite/"]').attr('href');
  9372. if (!link) {
  9373. const ggLink = $task.find('a[href^="https://discord.gg/"]').attr('href')?.match(/discord\.gg\/([^/]+)/)?.[1];
  9374. if (!ggLink) {
  9375. continue;
  9376. }
  9377. link = `https://discord.com/invite/${ggLink}`;
  9378. }
  9379. if (action === 'undo') {
  9380. this.socialTasks.discord.serverLinks.push(link);
  9381. }
  9382. if (action === 'do') {
  9383. this.undoneTasks.discord.serverLinks.push(link);
  9384. }
  9385. }
  9386. } else if (socialIcon.hasClass('fa-external-link-square-alt')) {
  9387. continue;
  9388. } else if (socialIcon.hasClass('fa-youtube')) {
  9389. if (/subscribe/gim.test(taskText)) {
  9390. const link = $task.find('a[href^="https://www.youtube.com/channel/"]').attr('href');
  9391. if (!link) {
  9392. continue;
  9393. }
  9394. if (action === 'undo') {
  9395. this.socialTasks.youtube.channelLinks.push(link);
  9396. }
  9397. if (action === 'do') {
  9398. this.undoneTasks.youtube.channelLinks.push(link);
  9399. }
  9400. }
  9401. } else if (socialIcon.attr('class')?.includes('steam')) {
  9402. if (/join.*group/gi.test(taskText)) {
  9403. const link = $task.find('a[href^="https://steamcommunity.com/groups/"]').attr('href');
  9404. if (!link) {
  9405. continue;
  9406. }
  9407. if (action === 'undo') {
  9408. this.socialTasks.steam.groupLinks.push(link);
  9409. }
  9410. if (action === 'do') {
  9411. this.undoneTasks.steam.groupLinks.push(link);
  9412. }
  9413. } else if (/follow.*curator/gi.test(taskText)) {
  9414. const link = $task.find('a[href^="https://store.steampowered.com/curator/"]').attr('href');
  9415. if (!link) {
  9416. continue;
  9417. }
  9418. if (action === 'undo') {
  9419. this.socialTasks.steam.curatorLinks.push(link);
  9420. }
  9421. if (action === 'do') {
  9422. this.undoneTasks.steam.curatorLinks.push(link);
  9423. }
  9424. }
  9425. } else if (socialIcon.hasClass('fa-bullhorn') && /Complete/gi.test(taskText)) {
  9426. if (action !== 'do') {
  9427. continue;
  9428. }
  9429. const gleamLink = await this.#getGleamLink(taskText);
  9430. if (!gleamLink) {
  9431. continue;
  9432. }
  9433. this.undoneTasks.extra.gleam.push(gleamLink);
  9434. } 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-dollar-sign') || socialIcon.hasClass('fa-tiktok') || socialIcon.hasClass('fa-gamepad-alt') || socialIcon.hasClass('fa-shield') && taskText.includes('one of our giveaways') || socialIcon.hasClass('fa-shield') && taskText.includes('Check out') || socialIcon.hasClass('fa-shield') && taskText.includes('vloot.io')) {} else {
  9435. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskText}`);
  9436. }
  9437. }
  9438. logStatus.success();
  9439. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9440. this.socialTasks = this.uniqueTasks(this.socialTasks);
  9441. if (window.DEBUG) {
  9442. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9443. }
  9444. GM_setValue(`gleamTasks-${this.giveawayId}`, {
  9445. tasks: this.socialTasks,
  9446. time: new Date().getTime()
  9447. });
  9448. return true;
  9449. } catch (error) {
  9450. throwError(error, 'Gleam.classifyTask');
  9451. return false;
  9452. }
  9453. }
  9454. async extraDoTask({
  9455. gleam
  9456. }) {
  9457. try {
  9458. const pro = [];
  9459. for (const link of gleam) {
  9460. pro.push(this.#doGleamTask(link));
  9461. }
  9462. return Promise.all(pro).then(() => true);
  9463. } catch (error) {
  9464. throwError(error, 'Gleam.extraDoTask');
  9465. return false;
  9466. }
  9467. }
  9468. async verifyTask() {
  9469. try {
  9470. scripts_echoLog({
  9471. text: `${i18n('verifyingTask')}...`
  9472. });
  9473. const tasks = $('.entry-content .entry-method');
  9474. unsafeWindow._OxA = '_OxA';
  9475. for (const task of tasks) {
  9476. if ($('[campaign-key="campaign.key"]').length > 0) {
  9477. return scripts_echoLog({
  9478. text: i18n('campaign')
  9479. });
  9480. }
  9481. const $task = $(task);
  9482. if ($task.find('i.fa-question').length === 0) {
  9483. continue;
  9484. }
  9485. const taskInfo = $task.find('.user-links');
  9486. taskInfo[0].click();
  9487. const aElements = $task.find('.expandable').find('a.btn');
  9488. if (aElements.length > 0) {
  9489. for (const element of aElements) {
  9490. const $element = $(element);
  9491. const href = $element.attr('href');
  9492. $element.removeAttr('href')[0].click();
  9493. $element.attr('href', href);
  9494. }
  9495. }
  9496. unsafeWindow.$hookTimer?.setSpeed(1e3);
  9497. const visitBtn = $task.find('.expandable').find('span:contains(more seconds),button:contains(more seconds)').filter(':visible');
  9498. if (visitBtn.length > 0) {
  9499. const newTab = GM_openInTab('', {
  9500. active: true
  9501. });
  9502. await delay(1e3);
  9503. newTab?.close();
  9504. window.focus();
  9505. }
  9506. await delay(3e3);
  9507. unsafeWindow.$hookTimer?.setSpeed(1);
  9508. const expandInfo = $task.find('.expandable');
  9509. const [ input ] = expandInfo.find('input');
  9510. if (input) {
  9511. const evt = new Event('input', {
  9512. bubbles: true,
  9513. cancelable: true,
  9514. composed: true
  9515. });
  9516. const valuelimit = [ ...expandInfo.text().matchAll(/"(.+?)"/g) ].at(-1)?.[1];
  9517. input.value = valuelimit || 'vloot';
  9518. input.dispatchEvent(evt);
  9519. await delay(1e3);
  9520. }
  9521. await this.#checkSync();
  9522. const continueBtn = $task.find('.expandable').find('span:contains(Continue),button:contains(Continue)');
  9523. for (const button of continueBtn) {
  9524. button.click();
  9525. await delay(500);
  9526. await this.#checkSync();
  9527. }
  9528. }
  9529. scripts_echoLog({
  9530. text: i18n('verifiedGleamTasks')
  9531. });
  9532. } catch (error) {
  9533. throwError(error, 'Gleam.verifyTask');
  9534. return false;
  9535. }
  9536. }
  9537. async #checkSync() {
  9538. try {
  9539. return await new Promise(resolve => {
  9540. const checker = setInterval(() => {
  9541. if ($('.entry-content .entry-method i.fa-sync').length === 0) {
  9542. clearInterval(checker);
  9543. resolve(true);
  9544. }
  9545. }, 500);
  9546. });
  9547. } catch (error) {
  9548. throwError(error, 'Gleam.checkSync');
  9549. return false;
  9550. }
  9551. }
  9552. async #doGleamTask(link) {
  9553. try {
  9554. const logStatus = scripts_echoLog({
  9555. text: i18n('doingGleamTask')
  9556. });
  9557. return await new Promise(resolve => {
  9558. GM_openInTab(`${link}?8b07d23f4bfa65f9`, {
  9559. active: true,
  9560. insert: true,
  9561. setParent: true
  9562. }).onclose = () => {
  9563. logStatus.success();
  9564. resolve(true);
  9565. };
  9566. });
  9567. } catch (error) {
  9568. throwError(error, 'Gleam.doGleamTask');
  9569. return false;
  9570. }
  9571. }
  9572. #getGiveawayId() {
  9573. try {
  9574. const giveawayId = window.location.pathname;
  9575. if (giveawayId) {
  9576. this.giveawayId = giveawayId;
  9577. return true;
  9578. }
  9579. scripts_echoLog({
  9580. text: i18n('getFailed', 'GiveawayId')
  9581. });
  9582. return false;
  9583. } catch (error) {
  9584. throwError(error, 'Gleam.getGiveawayId');
  9585. return false;
  9586. }
  9587. }
  9588. async #getGleamLink(title) {
  9589. try {
  9590. const logStatus = scripts_echoLog({
  9591. text: i18n('gettingGleamLink')
  9592. });
  9593. const {
  9594. result,
  9595. statusText,
  9596. status,
  9597. data
  9598. } = await tools_httpRequest({
  9599. url: 'https://www.vloot.io/api/v1/giveaways',
  9600. method: 'GET',
  9601. responseType: 'json'
  9602. });
  9603. if (result === 'Success') {
  9604. if (data?.status === 200 && data?.response?.Success === true && data?.response?.Data) {
  9605. const {
  9606. link
  9607. } = data.response.Data.find(giveaway => title.replace(/[\s]/g, '').toLowerCase().includes(giveaway.title.replace(/[\s]/g, '').toLowerCase())) || {};
  9608. if (link) {
  9609. logStatus.success();
  9610. return link;
  9611. }
  9612. logStatus.error(`Error:${i18n('getLinkFailed')}`);
  9613. return false;
  9614. }
  9615. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9616. return false;
  9617. }
  9618. logStatus.error(`${result}:${statusText}(${status})`);
  9619. return false;
  9620. } catch (error) {
  9621. throwError(error, 'Gleam.getGleamLink');
  9622. return false;
  9623. }
  9624. }
  9625. async #checkLeftKey() {
  9626. try {
  9627. if (!globalOptions.other.checkLeftKey) {
  9628. return true;
  9629. }
  9630. const campaignString = $('div.popup-blocks-container').attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  9631. if (!campaignString) {
  9632. return false;
  9633. }
  9634. const {
  9635. campaign,
  9636. incentive
  9637. } = JSON.parse(campaignString);
  9638. const controllerString = $('div.campaign.reward').attr('ng-init')?.match(/initContestant\(([\w\W]+?)\);/)?.[1];
  9639. let ownedKey = false;
  9640. if (controllerString) {
  9641. if (JSON.parse(controllerString).contestant?.claims?.incentives?.[incentive.id]?.length) {
  9642. ownedKey = true;
  9643. }
  9644. }
  9645. if (campaign.banned || campaign.finished && !ownedKey || campaign.paused || new Date().getTime() < campaign.starts_at * 1e3) {
  9646. await external_Swal_default().fire({
  9647. icon: 'warning',
  9648. title: i18n('notice'),
  9649. text: i18n('giveawayNotWork'),
  9650. confirmButtonText: i18n('confirm'),
  9651. cancelButtonText: i18n('cancel'),
  9652. showCancelButton: true
  9653. }).then(({
  9654. value
  9655. }) => {
  9656. if (value) {
  9657. window.close();
  9658. }
  9659. });
  9660. }
  9661. return true;
  9662. } catch (error) {
  9663. throwError(error, 'Gleam.checkLeftKey');
  9664. return false;
  9665. }
  9666. }
  9667. }
  9668. const website_Gleam = Gleam;
  9669. const SweepWidget_defaultOptions = {
  9670. username: '',
  9671. email: ''
  9672. };
  9673. class SweepWidget extends website_Website {
  9674. name = 'SweepWidget';
  9675. options = {
  9676. ...SweepWidget_defaultOptions,
  9677. ...GM_getValue('SweepWidgetOptions')
  9678. };
  9679. buttons = [ 'doTask' ];
  9680. static test() {
  9681. return /^https?:\/\/sweepwidget\.com\/view\/[\d]+/.test(window.location.href);
  9682. }
  9683. async after() {
  9684. try {
  9685. if (!this.#checkLogin()) {
  9686. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9687. }
  9688. } catch (error) {
  9689. throwError(error, 'SweepWidget.after');
  9690. }
  9691. }
  9692. init() {
  9693. try {
  9694. const logStatus = scripts_echoLog({
  9695. text: i18n('initing')
  9696. });
  9697. if (!this.#checkLogin()) {
  9698. logStatus.warning(i18n('needLogin'));
  9699. return false;
  9700. }
  9701. if (!this.#getGiveawayId()) {
  9702. return false;
  9703. }
  9704. this.initialized = true;
  9705. logStatus.success();
  9706. return true;
  9707. } catch (error) {
  9708. throwError(error, 'SweepWidget.init');
  9709. return false;
  9710. }
  9711. }
  9712. classifyTask() {
  9713. return true;
  9714. }
  9715. async doTask() {
  9716. try {
  9717. if ($('#unlock_rewards_main_wrapper').length === 0) {
  9718. if ($('input[name="sw__login_name"]:visible').length > 0) {
  9719. $('input[name="sw__login_name"]').val(this.options.username);
  9720. }
  9721. if ($('input[name="sw__login_email"]:visible').length > 0) {
  9722. $('input[name="sw__login_email"]').val(this.options.email);
  9723. }
  9724. if ($('#sw_login_button:visible').length > 0) {
  9725. $('#sw_login_button')[0].click();
  9726. }
  9727. if (!await this.#checkEnter()) {
  9728. return false;
  9729. }
  9730. }
  9731. const logStatus = scripts_echoLog({
  9732. text: i18n('SweepWidgetNotice')
  9733. });
  9734. const tasks = $('#sw_inner_entry_methods_l2_wrapper>div.sw_entry');
  9735. for (const task of tasks) {
  9736. const $task = $(task);
  9737. if ($task.find('i.fa-check:visible').length > 0) {
  9738. continue;
  9739. }
  9740. const title = $task.find('.sw_text_inner');
  9741. title[0].click();
  9742. const aElement = $task.find('a.sw_link');
  9743. const link = aElement.attr('href');
  9744. aElement.attr('href', '#a').attr('target', '_self');
  9745. aElement[0]?.click();
  9746. await delay(300);
  9747. aElement.attr('href', link).attr('target', '_blank');
  9748. $task.find('input[type="text"]').val('test');
  9749. const verifyBtn = $task.find('input.sw_verify');
  9750. if (verifyBtn.prop('disabled') === true) {
  9751. title[0].click();
  9752. await delay(300);
  9753. title[0].click();
  9754. await delay(300);
  9755. }
  9756. $task.find('input.sw_verify').removeAttr('disabled')[0]?.click();
  9757. await this.#checkFinish($task);
  9758. await delay(parseInt(`${Math.random() * (3e3 - 1e3 + 1) + 1e3}`, 10));
  9759. }
  9760. logStatus.success();
  9761. return true;
  9762. } catch (error) {
  9763. throwError(error, 'SweepWidget.doTask');
  9764. return false;
  9765. }
  9766. }
  9767. #checkLogin() {
  9768. try {
  9769. if ($('#twitter_login_button').length > 0) {
  9770. $('#twitter_login_button')[0].click();
  9771. }
  9772. return true;
  9773. } catch (error) {
  9774. throwError(error, 'SweepWidget.checkLogin');
  9775. return false;
  9776. }
  9777. }
  9778. #getGiveawayId() {
  9779. try {
  9780. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  9781. if (giveawayId) {
  9782. this.giveawayId = giveawayId;
  9783. return true;
  9784. }
  9785. scripts_echoLog({
  9786. text: i18n('getFailed', 'GiveawayId')
  9787. });
  9788. return false;
  9789. } catch (error) {
  9790. throwError(error, 'SweepWidget.getGiveawayId');
  9791. return false;
  9792. }
  9793. }
  9794. async #checkEnter() {
  9795. try {
  9796. return new Promise(resolve => {
  9797. const checker = setInterval(() => {
  9798. if ($('#unlock_rewards_main_wrapper').length > 0) {
  9799. clearInterval(checker);
  9800. resolve(true);
  9801. }
  9802. }, 500);
  9803. });
  9804. } catch (error) {
  9805. throwError(error, 'SweepWidget.checkEnter');
  9806. return false;
  9807. }
  9808. }
  9809. async #checkFinish($task) {
  9810. try {
  9811. return new Promise(resolve => {
  9812. const checker = setInterval(() => {
  9813. if ($task.find('i.fa-check:visible').length > 0 || $task.find('.sw_entry_input:visible').length === 0) {
  9814. clearInterval(checker);
  9815. resolve(true);
  9816. }
  9817. }, 500);
  9818. });
  9819. } catch (error) {
  9820. throwError(error, 'SweepWidget.checkFinish');
  9821. return false;
  9822. }
  9823. }
  9824. }
  9825. const website_SweepWidget = SweepWidget;
  9826. const defaultWhiteList = {
  9827. discord: {
  9828. servers: []
  9829. },
  9830. instagram: {
  9831. users: []
  9832. },
  9833. twitch: {
  9834. channels: []
  9835. },
  9836. twitter: {
  9837. users: [],
  9838. retweets: [],
  9839. likes: []
  9840. },
  9841. vk: {
  9842. names: []
  9843. },
  9844. youtube: {
  9845. channels: [],
  9846. likes: []
  9847. },
  9848. reddit: {
  9849. reddits: []
  9850. },
  9851. steam: {
  9852. groups: [],
  9853. officialGroups: [],
  9854. wishlists: [],
  9855. follows: [],
  9856. forums: [],
  9857. workshops: [],
  9858. curators: [],
  9859. workshopVotes: [],
  9860. curatorLikes: [],
  9861. announcements: [],
  9862. licenses: [],
  9863. playtests: []
  9864. }
  9865. };
  9866. const link2id = async function(type) {
  9867. try {
  9868. const link = $('#socialLink').val();
  9869. let id = '';
  9870. switch (type) {
  9871. case 'discord.servers':
  9872. id = link.match(/invite\/(.+)/)?.[1] || '';
  9873. break;
  9874.  
  9875. case 'instagram.users':
  9876. id = link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1] || '';
  9877. break;
  9878.  
  9879. case 'twitch.channels':
  9880. id = link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2] || '';
  9881. break;
  9882.  
  9883. case 'twitter.users':
  9884. id = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || '';
  9885. break;
  9886.  
  9887. case 'twitter.retweets':
  9888. id = link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1] || '';
  9889. break;
  9890.  
  9891. case 'vk.names':
  9892. id = link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1] || '';
  9893. break;
  9894.  
  9895. case 'youtube.channels':
  9896. id = (await getInfo(link, 'channel'))?.params?.channelId || '';
  9897. break;
  9898.  
  9899. case 'youtube.likes':
  9900. id = (await getInfo(link, 'likeVideo'))?.params?.videoId || '';
  9901. break;
  9902.  
  9903. case 'reddit.reddits':
  9904. id = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1] || link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1] || '';
  9905. break;
  9906.  
  9907. case 'steam.groups':
  9908. id = link.match(/groups\/(.+)\/?/)?.[1] || '';
  9909. break;
  9910.  
  9911. case 'steam.wishlists':
  9912. case 'steam.follows':
  9913. case 'steam.forums':
  9914. id = link.match(/app\/([\d]+)/)?.[1] || '';
  9915. break;
  9916.  
  9917. case 'steam.workshops':
  9918. id = link.match(/\?id=([\d]+)/)?.[1] || '';
  9919. break;
  9920.  
  9921. case 'steam.curators':
  9922. {
  9923. if (link.includes('curator')) {
  9924. id = link.match(/curator\/([\d]+)/)?.[1] || '';
  9925. } else {
  9926. const param = link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3);
  9927. if (!param || param.length !== 2) {
  9928. break;
  9929. }
  9930. const steam = new social_Steam();
  9931. if (await steam.init()) {
  9932. id = await steam.getCuratorId(param[0], param[1]) || '';
  9933. }
  9934. }
  9935. }
  9936. break;
  9937. }
  9938. return id;
  9939. } catch (error) {
  9940. throwError(error, 'link2id');
  9941. return i18n('getFailed', 'id');
  9942. }
  9943. };
  9944. const disabledType = {
  9945. steam: [ 'workshopVotes', 'curatorLikes', 'announcements' ],
  9946. twitter: [ 'likes' ]
  9947. };
  9948. const assignWhiteList = whiteList => {
  9949. try {
  9950. const newWhiteList = {};
  9951. for (const [ key, value ] of Object.entries(defaultWhiteList)) {
  9952. newWhiteList[key] = {
  9953. ...value,
  9954. ...whiteList[key]
  9955. };
  9956. }
  9957. return newWhiteList;
  9958. } catch (error) {
  9959. throwError(error, 'assignWhiteList');
  9960. return defaultWhiteList;
  9961. }
  9962. };
  9963. const whiteListOptions = function(showType) {
  9964. try {
  9965. const whiteList = assignWhiteList(GM_getValue('whiteList') || {});
  9966. let whiteListOptionsForm = `<form id="whiteListForm" class="auto-task-form">
  9967. <table class="auto-task-table"><thead><tr><td>${i18n('website')}</td><td>${i18n('type')}</td><td>${i18n('edit')}</td></tr></thead><tbody>`;
  9968. for (const [ social, types ] of Object.entries(whiteList)) {
  9969. 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('');
  9970. }
  9971. whiteListOptionsForm += '</tbody></table></form>';
  9972. if (showType === 'swal') {
  9973. external_Swal_default().fire({
  9974. title: i18n('whiteListOptions'),
  9975. html: whiteListOptionsForm,
  9976. showConfirmButton: false,
  9977. showCloseButton: true
  9978. });
  9979. } else {
  9980. $('body').append(`<h2>${i18n('whiteList')}</h2>${whiteListOptionsForm}`);
  9981. }
  9982. $('.editWhiteList').on('click', function() {
  9983. const value = $(this).attr('data-value');
  9984. if (!value) {
  9985. return;
  9986. }
  9987. const [ social, type ] = value.split('.');
  9988. if (!whiteList?.[social]?.[type]) {
  9989. scripts_echoLog({}).warning(i18n('whiteListNotFound', value));
  9990. return;
  9991. }
  9992. external_Swal_default().fire({
  9993. title: i18n('changeWhiteListOption', value),
  9994. input: 'textarea',
  9995. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  9996. <button id="link2id" data-type="${value}" class="swal2-confirm swal2-styled">获取id</button>
  9997. <p style="margin-bottom:0 !important;">在下方填写白名单,每行一个</p>`,
  9998. inputValue: whiteList[social][type].join('\n'),
  9999. showConfirmButton: true,
  10000. confirmButtonText: i18n('save'),
  10001. showCancelButton: true,
  10002. cancelButtonText: i18n('close'),
  10003. showDenyButton: true,
  10004. denyButtonText: i18n('return')
  10005. }).then(({
  10006. isDenied,
  10007. isConfirmed,
  10008. value
  10009. }) => {
  10010. if (isDenied) {
  10011. if (showType === 'swal') {
  10012. whiteListOptions(showType);
  10013. }
  10014. return;
  10015. } else if (isConfirmed) {
  10016. whiteList[social][type] = value.split('\n');
  10017. GM_setValue('whiteList', whiteList);
  10018. external_Swal_default().fire({
  10019. title: i18n('changeWhiteListSuccess'),
  10020. icon: 'success'
  10021. });
  10022. }
  10023. });
  10024. $('#link2id').on('click', async function() {
  10025. const type = $(this).attr('data-type');
  10026. $('#socialLink').val(await link2id(type));
  10027. });
  10028. });
  10029. } catch (error) {
  10030. throwError(error, 'whiteListOptions');
  10031. }
  10032. };
  10033. const whiteList = whiteListOptions;
  10034. const setGistData = async (token, gistId, fileName, content) => {
  10035. try {
  10036. const logStatus = scripts_echoLog({
  10037. text: i18n('settingData')
  10038. });
  10039. const contentData = JSON.stringify({
  10040. files: {
  10041. [fileName]: {
  10042. content: JSON.stringify(content)
  10043. }
  10044. }
  10045. });
  10046. const {
  10047. result,
  10048. statusText,
  10049. status,
  10050. data
  10051. } = await tools_httpRequest({
  10052. url: `https://api.github.com/gists/${gistId}`,
  10053. headers: {
  10054. Accept: 'application/vnd.github.v3+json',
  10055. Authorization: `token ${token}`
  10056. },
  10057. data: contentData,
  10058. responseType: 'json',
  10059. method: 'POST',
  10060. timeout: 3e4
  10061. });
  10062. if (result === 'Success') {
  10063. if (data?.status === 200 && data.response.files?.[fileName]?.content === JSON.stringify(content)) {
  10064. logStatus.success();
  10065. return true;
  10066. }
  10067. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10068. return false;
  10069. }
  10070. logStatus.error(`${result}:${statusText}(${status})`);
  10071. return false;
  10072. } catch (error) {
  10073. throwError(error, 'setGistData');
  10074. return false;
  10075. }
  10076. };
  10077. const getGistData = async (token, gistId, fileName, test = false) => {
  10078. try {
  10079. const logStatus = scripts_echoLog({
  10080. text: i18n('gettingData')
  10081. });
  10082. const {
  10083. result,
  10084. statusText,
  10085. status,
  10086. data
  10087. } = await tools_httpRequest({
  10088. url: `https://api.github.com/gists/${gistId}`,
  10089. headers: {
  10090. Accept: 'application/vnd.github.v3+json',
  10091. Authorization: `token ${token}`
  10092. },
  10093. responseType: 'json',
  10094. method: 'GET',
  10095. timeout: 3e4
  10096. });
  10097. if (result === 'Success') {
  10098. if (data?.status === 200) {
  10099. const content = data.response?.files?.[fileName]?.content;
  10100. let formatedContent;
  10101. if (!content) {
  10102. logStatus.error(`Error:${i18n('noRemoteData')}`);
  10103. return false;
  10104. }
  10105. if (test) {
  10106. logStatus.success();
  10107. return true;
  10108. }
  10109. try {
  10110. formatedContent = JSON.parse(content);
  10111. } catch (error) {
  10112. logStatus.error(`Error:${i18n('errorRemoteDataFormat')}`);
  10113. return false;
  10114. }
  10115. logStatus.success();
  10116. return formatedContent;
  10117. }
  10118. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10119. return false;
  10120. }
  10121. logStatus.error(`${result}:${statusText}(${status})`);
  10122. return false;
  10123. } catch (error) {
  10124. throwError(error, 'getGistData');
  10125. return false;
  10126. }
  10127. };
  10128. const syncOptions = () => {
  10129. try {
  10130. const {
  10131. TOKEN,
  10132. GIST_ID,
  10133. FILE_NAME,
  10134. SYNC_HISTORY
  10135. } = GM_getValue('gistOptions') || {
  10136. TOKEN: '',
  10137. GIST_ID: '',
  10138. FILE_NAME: '',
  10139. SYNC_HISTORY: true
  10140. };
  10141. external_Swal_default().fire({
  10142. title: i18n('gistOptions'),
  10143. 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;">
  10144. ${i18n('upload2gist')}</button>` + `<button id="download-data" type="button" class="swal2-confirm swal2-styled" style="display: inline-block;">
  10145. ${i18n('downloadFromGist')}</button></p>`,
  10146. focusConfirm: false,
  10147. showLoaderOnConfirm: true,
  10148. 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>`,
  10149. preConfirm: async () => {
  10150. const token = $('#github-token').val();
  10151. const gistId = $('#gist-id').val();
  10152. const fileName = $('#file-name').val();
  10153. const syncHistory = $('#sync-history').prop('checked');
  10154. GM_setValue('gistOptions', {
  10155. TOKEN: token,
  10156. GIST_ID: gistId,
  10157. FILE_NAME: fileName,
  10158. SYNC_HISTORY: syncHistory
  10159. });
  10160. return await getGistData(token, gistId, fileName, true);
  10161. },
  10162. allowOutsideClick: () => !external_Swal_default().isLoading(),
  10163. confirmButtonText: i18n('saveAndTest'),
  10164. showCancelButton: true,
  10165. cancelButtonText: i18n('close')
  10166. }).then(({
  10167. value
  10168. }) => {
  10169. if (value) {
  10170. external_Swal_default().fire({
  10171. icon: 'success',
  10172. title: i18n('testSuccess')
  10173. }).then(syncOptions);
  10174. } else if (value !== undefined) {
  10175. external_Swal_default().fire({
  10176. icon: 'error',
  10177. title: i18n('testFailed')
  10178. }).then(syncOptions);
  10179. }
  10180. });
  10181. $('#upload-data').on('click', async () => {
  10182. const {
  10183. TOKEN,
  10184. GIST_ID,
  10185. FILE_NAME
  10186. } = GM_getValue('gistOptions') || {};
  10187. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10188. return external_Swal_default().fire({
  10189. icon: 'error',
  10190. title: i18n('saveAndTestNotice')
  10191. }).then(syncOptions);
  10192. }
  10193. external_Swal_default().fire({
  10194. icon: 'info',
  10195. title: i18n('processingData')
  10196. });
  10197. const data = {};
  10198. const names = GM_listValues();
  10199. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10200. for (const name of names) {
  10201. if (name === 'gistOptions' || /^[\w]+?Auth$/.test(name)) {
  10202. continue;
  10203. }
  10204. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10205. continue;
  10206. }
  10207. data[name] = GM_getValue(name);
  10208. }
  10209. external_Swal_default().update({
  10210. icon: 'info',
  10211. title: i18n('updatingData')
  10212. });
  10213. if (await setGistData(TOKEN, GIST_ID, FILE_NAME, data)) {
  10214. external_Swal_default().fire({
  10215. icon: 'success',
  10216. title: i18n('syncDataSuccess')
  10217. });
  10218. } else {
  10219. external_Swal_default().fire({
  10220. icon: 'error',
  10221. title: i18n('syncDataFailed')
  10222. });
  10223. }
  10224. });
  10225. $('#download-data').on('click', async () => {
  10226. const {
  10227. TOKEN,
  10228. GIST_ID,
  10229. FILE_NAME
  10230. } = GM_getValue('gistOptions') || {};
  10231. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10232. return external_Swal_default().fire({
  10233. icon: 'error',
  10234. title: i18n('saveAndTestNotice')
  10235. }).then(syncOptions);
  10236. }
  10237. external_Swal_default().fire({
  10238. icon: 'info',
  10239. title: i18n('downloadingData')
  10240. });
  10241. const data = await getGistData(TOKEN, GIST_ID, FILE_NAME);
  10242. if (!data) {
  10243. return external_Swal_default().fire({
  10244. icon: 'error',
  10245. title: i18n('checkedNoData')
  10246. }).then(syncOptions);
  10247. }
  10248. external_Swal_default().update({
  10249. icon: 'info',
  10250. title: i18n('savingData')
  10251. });
  10252. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10253. for (const [ name, value ] of Object.entries(data)) {
  10254. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10255. continue;
  10256. }
  10257. GM_setValue(name, value);
  10258. }
  10259. external_Swal_default().fire({
  10260. icon: 'success',
  10261. title: i18n('syncDataSuccess')
  10262. });
  10263. });
  10264. } catch (error) {
  10265. throwError(error, 'syncOptions');
  10266. }
  10267. };
  10268. const dataSync = syncOptions;
  10269. class Setting {
  10270. name = 'Setting';
  10271. buttons = [ 'saveGlobalOptions', 'syncData', 'tasksHistory' ];
  10272. syncData = dataSync;
  10273. tasksHistory() {
  10274. GM_openInTab('https://auto-task-v4.hclonely.com/history.html', {
  10275. active: true
  10276. });
  10277. }
  10278. static test() {
  10279. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/setting.html';
  10280. }
  10281. before() {
  10282. try {
  10283. $('body').html('').addClass('auto-task-options');
  10284. } catch (error) {
  10285. throwError(error, 'Setting.before');
  10286. }
  10287. }
  10288. after() {
  10289. try {
  10290. this.#environment();
  10291. changeGlobalOptions('page');
  10292. whiteList('page');
  10293. $('input[name="other.twitterVerifyId"]').after(`<button id="getTwitterUserId" type="button">${i18n('getTwitterUserId')}</button>`);
  10294. $('#getTwitterUserId').on('click', () => {
  10295. this.#getId('twitterUser');
  10296. });
  10297. $('input[name="other.youtubeVerifyChannel"]').after(`<button id="getYoutubeChannelId" type="button">${i18n('getYoutubeChannelId')}</button>`);
  10298. $('#getYoutubeChannelId').on('click', () => {
  10299. this.#getId('youtubeChannel');
  10300. });
  10301. $('input[name^="position"]').on('input', function() {
  10302. const type = $(this).attr('name').replace('position.', '');
  10303. const xLabel = 'rightleft';
  10304. const yLabel = 'topbottpm';
  10305. switch (type) {
  10306. case 'buttonSideX':
  10307. case 'buttonSideY':
  10308. case 'buttonDistance':
  10309. {
  10310. const distance = $('input[name="position.buttonDistance"]').val();
  10311. const sideX = $('input[name="position.buttonSideX"]').val();
  10312. const sideY = $('input[name="position.buttonSideY"]').val();
  10313. if (![ 'right', 'left' ].includes(sideX)) {
  10314. break;
  10315. }
  10316. if (![ 'top', 'bottom' ].includes(sideY)) {
  10317. break;
  10318. }
  10319. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10320. break;
  10321. }
  10322. const distanceArr = distance.split(',');
  10323. $('#auto-task-buttons').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10324. break;
  10325. }
  10326.  
  10327. case 'showButtonSideX':
  10328. case 'showButtonSideY':
  10329. case 'showButtonDistance':
  10330. {
  10331. const distance = $('input[name="position.showButtonDistance"]').val();
  10332. const sideX = $('input[name="position.showButtonSideX"]').val();
  10333. const sideY = $('input[name="position.showButtonSideY"]').val();
  10334. if (![ 'right', 'left' ].includes(sideX)) {
  10335. break;
  10336. }
  10337. if (![ 'top', 'bottom' ].includes(sideY)) {
  10338. break;
  10339. }
  10340. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10341. break;
  10342. }
  10343. const distanceArr = distance.split(',');
  10344. $('div.show-button-div').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10345. break;
  10346. }
  10347.  
  10348. case 'logSideX':
  10349. case 'logSideY':
  10350. case 'logDistance':
  10351. {
  10352. const distance = $('input[name="position.logDistance"]').val();
  10353. const sideX = $('input[name="position.logSideX"]').val();
  10354. const sideY = $('input[name="position.logSideY"]').val();
  10355. if (![ 'right', 'left' ].includes(sideX)) {
  10356. break;
  10357. }
  10358. if (![ 'top', 'bottom' ].includes(sideY)) {
  10359. break;
  10360. }
  10361. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10362. break;
  10363. }
  10364. const distanceArr = distance.split(',');
  10365. $('#auto-task-info').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10366. break;
  10367. }
  10368.  
  10369. default:
  10370. break;
  10371. }
  10372. });
  10373. $('input[name^="hotKey"]').attr('readonly', 'readonly').off('keydown').on('keydown', function(event) {
  10374. let functionKey = '';
  10375. if (event.altKey) {
  10376. functionKey += 'alt + ';
  10377. } else if (event.ctrlKey) {
  10378. functionKey += 'ctrl + ';
  10379. } else if (event.shiftKey) {
  10380. functionKey += 'shift + ';
  10381. }
  10382. $(this).val(functionKey + (event.key.length === 1 ? event.key.toLowerCase() : ''));
  10383. });
  10384. } catch (error) {
  10385. throwError(error, 'Setting.after');
  10386. }
  10387. }
  10388. saveGlobalOptions() {
  10389. try {
  10390. saveData();
  10391. } catch (error) {
  10392. throwError(error, 'Setting.saveGlobalOptions');
  10393. }
  10394. }
  10395. #getId(social) {
  10396. try {
  10397. external_Swal_default().fire({
  10398. title: i18n('getId', i18n(social)),
  10399. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10400. <button id="link2id" data-type="${social}" class="swal2-confirm swal2-styled">获取id</button>`,
  10401. showCancelButton: true,
  10402. cancelButtonText: i18n('close'),
  10403. showConfirmButton: false
  10404. });
  10405. $('#link2id').on('click', async function() {
  10406. const link = $('#socialLink').val();
  10407. if (!link) {
  10408. return;
  10409. }
  10410. const type = $(this).attr('data-type');
  10411. if (type === 'twitterUser') {
  10412. const name = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || link;
  10413. $('#socialLink').val(await new social_Twitter().userName2id(name) || '');
  10414. } else if (type === 'youtubeChannel') {
  10415. const name = /^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www.youtube.com\/.*/.test(link) ? link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1] : link;
  10416. $('#socialLink').val((await getInfo(name, 'channel'))?.params?.channelId || '');
  10417. }
  10418. });
  10419. } catch (error) {
  10420. throwError(error, 'Setting.getId');
  10421. }
  10422. }
  10423. #environment() {
  10424. try {
  10425. const userAgent = (0, javascript_utils_umd_min.ua)();
  10426. const environmentForm = `<form id="environmentForm" class="auto-task-form">
  10427. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('name')}</td><td>${i18n('version')}</td></tr></thead><tbody>
  10428. <tr><td>${i18n('os')}</td><td>${userAgent.os}</td><td>${userAgent.osVersion}</td></tr>
  10429. <tr><td>${i18n('browser')}</td><td>${userAgent.browserZH}</td><td>${userAgent.browserVersion}</td></tr>
  10430. <tr><td>${i18n('scriptManager')}</td><td>${GM_info.scriptHandler}</td><td>${GM_info.version}</td></tr>
  10431. <tr><td>${i18n('script')}</td><td>${GM_info.script.name}</td><td>${GM_info.script.version}</td></tr>
  10432. </tbody></table></form>`;
  10433. $('body').append(`<h2>${i18n('environment')}</h2>${environmentForm}`);
  10434. } catch (error) {
  10435. throwError(error, 'Setting.environment');
  10436. }
  10437. }
  10438. }
  10439. const website_Setting = Setting;
  10440. class History extends website_Keylol {
  10441. name = 'History';
  10442. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect', 'clearHistory' ];
  10443. static test() {
  10444. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/history.html';
  10445. }
  10446. before() {
  10447. try {
  10448. $('body').html('<div class="container"></div>').addClass('auto-task-history');
  10449. const data = GM_listValues() || [];
  10450. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10451. for (const item of tasksHistory) {
  10452. this.#addItem(item);
  10453. }
  10454. } catch (error) {
  10455. throwError(error, 'History.before');
  10456. }
  10457. }
  10458. clearHistory() {
  10459. try {
  10460. const data = GM_listValues() || [];
  10461. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10462. for (const item of tasksHistory) {
  10463. GM_deleteValue(item);
  10464. }
  10465. external_Swal_default().fire({
  10466. title: i18n('clearHistoryFinished'),
  10467. icon: 'success'
  10468. });
  10469. } catch (error) {
  10470. throwError(error, 'History.clearHistory');
  10471. }
  10472. }
  10473. #addItem(item) {
  10474. try {
  10475. const tasksData = GM_getValue(item);
  10476. if (!tasksData?.tasks) {
  10477. return;
  10478. }
  10479. let html = '';
  10480. let title = '';
  10481. let link = '';
  10482. const [ website, id ] = item.split('-');
  10483. switch (website) {
  10484. case 'fawTasks':
  10485. title = `Freeanywhere[${id}]`;
  10486. link = `https://freeanywhere.net/#/giveaway/${id}`;
  10487. break;
  10488.  
  10489. case 'gasTasks':
  10490. title = `Giveawaysu[${id}]`;
  10491. link = `https://giveaway.su/giveaway/view/${id}`;
  10492. break;
  10493.  
  10494. case 'gcTasks':
  10495. title = `GiveeClub[${id}]`;
  10496. link = `https://givee.club/event/${id}`;
  10497. break;
  10498.  
  10499. case 'gkTasks':
  10500. title = `Givekey[${id}]`;
  10501. link = `https://givekey.ru/giveaway/${id}`;
  10502. break;
  10503.  
  10504. case 'gleamTasks':
  10505. title = `Gleam[${id}]`;
  10506. link = `https://gleam.io${id}`;
  10507. break;
  10508.  
  10509. case 'khTasks':
  10510. title = `keyhub[${id}]`;
  10511. link = `https://key-hub.eu/giveaway/${id}`;
  10512. break;
  10513.  
  10514. case 'prysTasks':
  10515. title = `Prys[${id}]`;
  10516. link = `https://prys.revadike.com/giveaway/?id=${id}`;
  10517. break;
  10518.  
  10519. default:
  10520. return;
  10521. }
  10522. for (const [ social, types ] of Object.entries(tasksData.tasks)) {
  10523. for (const [ type, tasks ] of Object.entries(types)) {
  10524. for (const task of tasks) {
  10525. 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>`;
  10526. }
  10527. }
  10528. }
  10529. $('.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>`);
  10530. $('span.delete-task').on('click', function() {
  10531. const itemName = $(this).attr('data-name');
  10532. if (itemName) {
  10533. GM_deleteValue(itemName);
  10534. $(`div.card[data-name="${itemName}"]`).remove();
  10535. external_Swal_default().fire({
  10536. title: i18n('clearTaskFinished'),
  10537. text: itemName,
  10538. icon: 'success'
  10539. });
  10540. } else {
  10541. external_Swal_default().fire({
  10542. title: i18n('clearTaskFailed'),
  10543. icon: 'error'
  10544. });
  10545. }
  10546. });
  10547. } catch (error) {
  10548. throwError(error, 'History.addItem');
  10549. }
  10550. }
  10551. }
  10552. const website_History = History;
  10553. 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 ];
  10554. const websiteOptions = function(website, options) {
  10555. try {
  10556. let websiteOptionsForm = `<form id="websiteOptionsForm" class="auto-task-form">
  10557. <table class="auto-task-table"><thead><tr><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  10558. for (const [ option, value ] of Object.entries(options)) {
  10559. websiteOptionsForm += `<tr><td>${option}</td><td><input class="editOption" type="text" name="${option}" value="${value}"/></td></tr>`;
  10560. }
  10561. websiteOptionsForm += '</tbody></table></form>';
  10562. external_Swal_default().fire({
  10563. title: i18n('websiteOptions'),
  10564. html: websiteOptionsForm,
  10565. showConfirmButton: true,
  10566. confirmButtonText: i18n('save'),
  10567. showCancelButton: true,
  10568. cancelButtonText: i18n('close')
  10569. }).then(({
  10570. isConfirmed
  10571. }) => {
  10572. if (isConfirmed) {
  10573. $('#websiteOptionsForm').serializeArray().map(value => {
  10574. options[value.name] = value.value;
  10575. return value;
  10576. });
  10577. GM_setValue(`${website}Options`, options);
  10578. external_Swal_default().fire({
  10579. title: i18n('changeWebsiteOptionsSuccess'),
  10580. icon: 'success'
  10581. });
  10582. }
  10583. });
  10584. } catch (error) {
  10585. throwError(error, 'websiteOptions');
  10586. }
  10587. };
  10588. const options = websiteOptions;
  10589. const external_keyboardJS_namespaceObject = keyboardJS;
  10590. var external_keyboardJS_default = __webpack_require__.n(external_keyboardJS_namespaceObject);
  10591. const checkUpdate = async (updateLink, auto) => {
  10592. try {
  10593. const checkUrl = `${updateLink}package.json?time=${new Date().getTime()}`;
  10594. const {
  10595. result,
  10596. statusText,
  10597. status,
  10598. data
  10599. } = await tools_httpRequest({
  10600. url: checkUrl,
  10601. responseType: 'json',
  10602. method: 'GET',
  10603. timeout: 3e4
  10604. });
  10605. if (result === 'Success') {
  10606. if (data?.response?.version) {
  10607. return data.response;
  10608. }
  10609. if (!auto) {
  10610. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${data?.statusText}(${data?.status})]`);
  10611. }
  10612. return false;
  10613. }
  10614. if (!auto) {
  10615. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${result}:${statusText}(${status})]`);
  10616. }
  10617. return false;
  10618. } catch (error) {
  10619. throwError(error, 'checkUpdate');
  10620. return false;
  10621. }
  10622. };
  10623. const hasNewVersion = (currentVersion, remoteVersion) => {
  10624. try {
  10625. const [ currentRealVersion ] = currentVersion.split('-');
  10626. const [ remoteRealVersion, isPreview ] = remoteVersion.split('-');
  10627. if (isPreview && !globalOptions.other.receivePreview) {
  10628. return false;
  10629. }
  10630. const [ currentVersion1, currentVersion2, currentVersion3 ] = currentRealVersion.split('.').map(value => parseInt(value, 10));
  10631. const [ remoteVersion1, remoteVersion2, remoteVersion3 ] = remoteRealVersion.split('.').map(value => parseInt(value, 10));
  10632. if (remoteVersion1 > currentVersion1) {
  10633. return true;
  10634. }
  10635. if (remoteVersion1 < currentVersion1) {
  10636. return false;
  10637. }
  10638. if (remoteVersion2 > currentVersion2) {
  10639. return true;
  10640. }
  10641. if (remoteVersion2 < currentVersion2) {
  10642. return false;
  10643. }
  10644. if (remoteVersion3 > currentVersion3) {
  10645. return true;
  10646. }
  10647. return false;
  10648. } catch (error) {
  10649. throwError(error, 'compareVersion');
  10650. return false;
  10651. }
  10652. };
  10653. const updateChecker = async () => {
  10654. try {
  10655. const currentVersion = GM_info.script.version;
  10656. const updateSource = globalOptions.other.autoUpdateSource.toLowerCase();
  10657. const updateLinks = {
  10658. github: 'https://github.com/HCLonely/auto-task-new/raw/main/',
  10659. jsdelivr: 'https://cdn.jsdelivr.net/gh/HCLonely/auto-task-v4@main/',
  10660. standby: 'https://auto-task-v4.hclonely.com/'
  10661. };
  10662. let version;
  10663. let updateLink = '';
  10664. let packageData;
  10665. if ([ 'github', 'jsdelivr', 'standby' ].includes(updateSource)) {
  10666. updateLink = updateLinks[updateSource];
  10667. packageData = await checkUpdate(updateLink, false);
  10668. } else {
  10669. updateLink = updateLinks.github;
  10670. packageData = await checkUpdate(updateLink, true);
  10671. if (!packageData) {
  10672. updateLink = updateLinks.jsdelivr;
  10673. packageData = await checkUpdate(updateLink, true);
  10674. if (!packageData) {
  10675. updateLink = updateLinks.standby;
  10676. packageData = await checkUpdate(updateLink, true);
  10677. }
  10678. }
  10679. }
  10680. if (packageData) {
  10681. version = packageData.version || currentVersion;
  10682. } else {
  10683. version = currentVersion;
  10684. scripts_echoLog({}).error(i18n('checkUpdateFailed'));
  10685. }
  10686. if (packageData && hasNewVersion(currentVersion, version)) {
  10687. scripts_echoLog({
  10688. html: `<li><font>${i18n('newVersionNotice', version, `${updateLink}dist/${GM_info.script.name}.user.js`)}</font></li>`
  10689. });
  10690. scripts_echoLog({
  10691. html: `<li>${i18n('updateText', version)}</li><ol class="update-text">${packageData.change?.map(change => `<li>${change}</li>`).join('')}<li>${i18n('updateHistory')}</li></ol>`
  10692. });
  10693. }
  10694. } catch (error) {
  10695. throwError(error, 'updateChecker');
  10696. }
  10697. };
  10698. const scripts_updateChecker = updateChecker;
  10699. window.STYLE = GM_addStyle(auto_task.A + GM_getResourceText('style'));
  10700. window.DEBUG = !!globalOptions.other?.debug;
  10701. window.TRACE = !!globalOptions.other?.debug && typeof console.trace === 'function';
  10702. const loadScript = async () => {
  10703. if (window.name === 'ATv4_twitchAuth' && window.location.hostname === 'www.twitch.tv') {
  10704. const authToken = external_Cookies_default().get('auth-token');
  10705. const isLogin = !!external_Cookies_default().get('login');
  10706. if (isLogin) {
  10707. GM_setValue('twitchAuth', {
  10708. authToken: authToken,
  10709. clientVersion: __twilightBuildID,
  10710. clientId: commonOptions?.headers?.['Client-ID'],
  10711. deviceId: commonOptions?.headers?.['Device-ID'],
  10712. clientSessionId: window.localStorage.local_storage_app_session_id.replace(/"/g, '')
  10713. });
  10714. window.close();
  10715. external_Swal_default().fire('', i18n('closePageNotice'));
  10716. } else {
  10717. external_Swal_default().fire('', i18n('needLogin'));
  10718. }
  10719. return;
  10720. }
  10721. if (window.name === 'ATv4_redditAuth' && window.location.hostname === 'www.reddit.com') {
  10722. const betaButton = $('#redesign-beta-optin-btn');
  10723. if (betaButton.length > 0) {
  10724. return betaButton[0].click();
  10725. }
  10726. window.close();
  10727. external_Swal_default().fire('', i18n('closePageNotice'));
  10728. return;
  10729. }
  10730. let website;
  10731. for (const Website of Websites) {
  10732. if (Website.test()) {
  10733. website = new Website();
  10734. break;
  10735. }
  10736. }
  10737. if (!website) {
  10738. console.log('%c%s', 'color:#ff0000', 'Auto-Task[Warning]: 脚本停止加载,当前网站不支持!');
  10739. return;
  10740. }
  10741. if (website?.before) {
  10742. await website?.before();
  10743. }
  10744. $('body').append(`
  10745. <div id="auto-task-info"
  10746. style="display:${globalOptions.other.defaultShowLog ? 'block' : 'none'};
  10747. ${globalOptions.position.logSideX}:${globalOptions.position.logDistance.split(',')[0]}px;
  10748. ${globalOptions.position.logSideY}:${globalOptions.position.logDistance.split(',')[1]}px;">
  10749. </div>
  10750. <div id="auto-task-buttons"
  10751. style="display:${globalOptions.other.defaultShowButton ? 'block' : 'none'};
  10752. ${globalOptions.position.buttonSideX}:${globalOptions.position.buttonDistance.split(',')[0]}px;
  10753. ${globalOptions.position.buttonSideY}:${globalOptions.position.buttonDistance.split(',')[1]}px;">
  10754. </div>
  10755. <div class="show-button-div"
  10756. style="display:${globalOptions.other.defaultShowButton ? 'none' : 'block'};
  10757. ${globalOptions.position.showButtonSideX}:${globalOptions.position.showButtonDistance.split(',')[0]}px;
  10758. ${globalOptions.position.showButtonSideY}:${globalOptions.position.showButtonDistance.split(',')[1]}px;">
  10759. <a class="auto-task-website-btn"
  10760. href="javascript:void(0);"
  10761. target="_self"
  10762. title="${i18n('showButton')}"> </a>
  10763. </div>
  10764. `);
  10765. $('div.show-button-div').on('click', () => {
  10766. $('#auto-task-buttons').show();
  10767. $('div.show-button-div').hide();
  10768. });
  10769. const toggleLog = () => {
  10770. const $this = $('#toggle-log');
  10771. const status = $this.attr('data-status');
  10772. if (status === 'show') {
  10773. $('#auto-task-info').hide();
  10774. $this.attr('data-status', 'hide').text(i18n('showLog'));
  10775. } else {
  10776. $('#auto-task-info').show();
  10777. $this.attr('data-status', 'show').text(i18n('hideLog'));
  10778. }
  10779. };
  10780. external_keyboardJS_default().bind(globalOptions.hotKey.doTaskKey, () => {
  10781. if (website.doTask) {
  10782. website.doTask();
  10783. }
  10784. });
  10785. external_keyboardJS_default().bind(globalOptions.hotKey.undoTaskKey, () => {
  10786. if (website.undoTask) {
  10787. website.undoTask();
  10788. }
  10789. });
  10790. external_keyboardJS_default().bind(globalOptions.hotKey.toggleLogKey, toggleLog);
  10791. if (website?.after) {
  10792. await website?.after();
  10793. }
  10794. if (website?.buttons && $('#auto-task-buttons').children().length === 0) {
  10795. $('#auto-task-buttons').addClass(`${website.name}-buttons`);
  10796. for (const button of website.buttons) {
  10797. if (website[button]) {
  10798. const btnElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">${i18n(button)}</a></p>`);
  10799. btnElement.find('a.auto-task-website-btn').on('click', () => {
  10800. website[button]();
  10801. });
  10802. $('#auto-task-buttons').append(btnElement);
  10803. }
  10804. }
  10805. }
  10806. const hideButtonElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">
  10807. ${i18n('hideButton')}</a></p>`);
  10808. hideButtonElement.find('a.auto-task-website-btn').on('click', () => {
  10809. $('#auto-task-buttons').hide();
  10810. $('div.show-button-div').show();
  10811. });
  10812. 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'}">
  10813. ${globalOptions.other.defaultShowLog ? i18n('hideLog') : i18n('showLog')}</a></p>`);
  10814. toggleLogElement.find('a.auto-task-website-btn').on('click', toggleLog);
  10815. $('#auto-task-buttons').append(hideButtonElement).append(toggleLogElement);
  10816. if (website?.options) {
  10817. GM_registerMenuCommand(i18n('changeWebsiteOptions'), () => {
  10818. options(website.name, website.options);
  10819. });
  10820. }
  10821. if (website.name !== 'Setting') {
  10822. GM_registerMenuCommand(i18n('changeGlobalOptions'), () => {
  10823. changeGlobalOptions('swal');
  10824. });
  10825. GM_registerMenuCommand(i18n('settingPage'), () => {
  10826. GM_openInTab('https://auto-task-v4.hclonely.com/setting.html', {
  10827. active: true
  10828. });
  10829. });
  10830. }
  10831. console.log('%c%s', 'color:#1bbe1a', 'Auto-Task[Load]: 脚本加载完成');
  10832. const [ v1, v2 ] = GM_info.version.split('.');
  10833. if (!(parseInt(v1, 10) >= 5 && parseInt(v2, 10) >= 2)) {
  10834. scripts_echoLog({}).error(i18n('versionNotMatched'));
  10835. }
  10836. if (!GM_getValue('notice')) {
  10837. external_Swal_default().fire({
  10838. title: i18n('swalNotice'),
  10839. icon: 'warning'
  10840. }).then(() => {
  10841. GM_openInTab(i18n('noticeLink'), {
  10842. active: true
  10843. });
  10844. GM_setValue('notice', new Date().getTime());
  10845. });
  10846. scripts_echoLog({
  10847. html: `<li><font class="warning">${i18n('echoNotice', i18n('noticeLink'))}</font></li>`
  10848. }).font?.find('a').on('click', () => {
  10849. GM_setValue('notice', new Date().getTime());
  10850. });
  10851. }
  10852. scripts_updateChecker();
  10853. };
  10854. if (window.location.hostname === 'discord.com') {
  10855. const LocalStorage = window.localStorage;
  10856. if (window.name === 'ATv4_discordAuth') {
  10857. window.localStorage.removeItem = () => true;
  10858. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10859. if (discordAuth && discordAuth.length > 0) {
  10860. GM_setValue('discordAuth', {
  10861. auth: discordAuth
  10862. });
  10863. window.close();
  10864. external_Swal_default().fire('', i18n('closePageNotice'));
  10865. } else {
  10866. external_Swal_default().fire({
  10867. text: i18n('getDiscordAuthFailed'),
  10868. icon: 'error'
  10869. });
  10870. }
  10871. } else {
  10872. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10873. if (discordAuth && discordAuth.length > 0) {
  10874. GM_setValue('discordAuth', {
  10875. auth: discordAuth
  10876. });
  10877. }
  10878. }
  10879. } else if (window.location.hostname === 'opquests.com') {
  10880. loadScript();
  10881. } else if ((window.name === 'ATv4_updateStoreAuth' || GM_getValue('ATv4_updateStoreAuth')) && window.location.host === 'store.steampowered.com') {
  10882. $(() => {
  10883. if ($('[data-miniprofile]').length === 0) {
  10884. return;
  10885. }
  10886. const storeSessionID = document.body.innerHTML.match(/g_sessionID = "(.+?)";/)?.[1];
  10887. if (storeSessionID) {
  10888. GM_deleteValue('ATv4_updateStoreAuth');
  10889. GM_setValue('steamStoreAuth', {
  10890. storeSessionID: storeSessionID
  10891. });
  10892. window.close();
  10893. external_Swal_default().fire('', i18n('closePageNotice'));
  10894. } else {
  10895. external_Swal_default().fire({
  10896. title: 'Error: Get "sessionID" failed',
  10897. icon: 'error'
  10898. });
  10899. }
  10900. });
  10901. } else if ((window.name === 'ATv4_updateCommunityAuth' || GM_getValue('ATv4_updateCommunityAuth')) && window.location.host === 'steamcommunity.com') {
  10902. $(() => {
  10903. const steam64Id = document.body.innerHTML.match(/g_steamID = "(.+?)";/)?.[1];
  10904. const communitySessionID = document.body.innerHTML.match(/g_sessionID = "(.+?)";/)?.[1];
  10905. if (steam64Id && communitySessionID) {
  10906. GM_deleteValue('ATv4_updateCommunityAuth');
  10907. GM_setValue('steamCommunityAuth', {
  10908. steam64Id: steam64Id,
  10909. communitySessionID: communitySessionID
  10910. });
  10911. window.close();
  10912. external_Swal_default().fire('', i18n('closePageNotice'));
  10913. } else {
  10914. setTimeout(() => {
  10915. external_Swal_default().fire({
  10916. title: 'Error: Get "sessionID" failed',
  10917. icon: 'error'
  10918. });
  10919. }, 3e3);
  10920. }
  10921. });
  10922. } else {
  10923. if (window.location.hostname === 'key-hub.eu') {
  10924. unsafeWindow.keyhubtracker = 1;
  10925. unsafeWindow.gaData = {};
  10926. }
  10927. $(loadScript);
  10928. }
  10929. }();
  10930. })();