auto-task-v4

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

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

  1. // ==UserScript==
  2. // @name auto-task-v4
  3. // @namespace auto-task-v4
  4. // @version 4.4.11
  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/id/*
  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.  
  55. // @connect cdn.jsdelivr.net
  56. // @connect store.steampowered.com
  57. // @connect steamcommunity.com
  58. // @connect login.steampowered.com
  59. // @connect twitter.com
  60. // @connect x.com
  61. // @connect api.twitter.com
  62. // @connect youtube.com
  63. // @connect www.youtube.com
  64. // @connect facebook.com
  65. // @connect instagram.com
  66. // @connect vk.com
  67. // @connect twitch.tv
  68. // @connect www.twitch.tv
  69. // @connect gql.twitch.tv
  70. // @connect github.com
  71. // @connect discordapp.com
  72. // @connect discord.gg
  73. // @connect discord.com
  74. // @connect www.reddit.com
  75. // @connect oauth.reddit.com
  76. // @connect raw.githubusercontent.com
  77. // @connect t.me
  78. // @connect bit.ly
  79. // @connect giveaway.su
  80. // @connect google.com
  81. // @connect www.vloot.io
  82. // @connect givee.club
  83. // @connect gleam.io
  84. // @connect www.indiedb.com
  85. // @connect key-hub.eu
  86. // @connect opquests.com
  87. // @connect itch.io
  88. // @connect auto-task-v4.hclonely.com
  89. // @connect *
  90. // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js
  91. // @require https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js
  92. // @require https://cdn.jsdelivr.net/npm/regenerator-runtime@0.13.5/runtime.min.js
  93. // @require https://cdn.jsdelivr.net/npm/js-sha1@0.6.0/src/sha1.min.js
  94. // @require https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js
  95. // @resource style https://cdn.jsdelivr.net/npm/sweetalert2@11.3.5/dist/sweetalert2.min.css
  96. // @require https://cdn.jsdelivr.net/npm/keyboardjs@2.6.4/dist/keyboard.min.js
  97. // @require https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js
  98.  
  99. // @noframes
  100. // ==/UserScript==
  101.  
  102. console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
  103.  
  104. (function() {
  105. var __webpack_modules__ = {
  106. 108: 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', this.info.device = 'Tablet',
  185. 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', this.info.device = 'Mobile',
  189. 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. 568: function(module, __webpack_exports__, __webpack_require__) {
  412. 'use strict';
  413. __webpack_require__.d(__webpack_exports__, {
  414. Z: function() {
  415. return __WEBPACK_DEFAULT_EXPORT__;
  416. }
  417. });
  418. var _node_modules_pnpm_css_loader_6_5_1_webpack_5_76_0_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(494);
  419. var _node_modules_pnpm_css_loader_6_5_1_webpack_5_76_0_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = __webpack_require__.n(_node_modules_pnpm_css_loader_6_5_1_webpack_5_76_0_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__);
  420. var _node_modules_pnpm_css_loader_6_5_1_webpack_5_76_0_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(999);
  421. var _node_modules_pnpm_css_loader_6_5_1_webpack_5_76_0_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default = __webpack_require__.n(_node_modules_pnpm_css_loader_6_5_1_webpack_5_76_0_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__);
  422. var ___CSS_LOADER_EXPORT___ = _node_modules_pnpm_css_loader_6_5_1_webpack_5_76_0_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default()(_node_modules_pnpm_css_loader_6_5_1_webpack_5_76_0_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{position:fixed;bottom:10px;right:10px;width:60%;max-width:500px;max-height:60%;overflow-y:auto;color:#000;background-color:#fff;padding-left:5px;z-index:999999999 !important;border:solid 2px #add8e6;border-radius:10px}#auto-task-info li{text-align:left}#auto-task-info li a.high-light{color:#00aeff;font-weight:bold}#auto-task-info .success{color:green}#auto-task-info .error{color:red}#auto-task-info .warning{color:blue}#auto-task-info .info{color:#ff0}#auto-task-info .update-text{color:green;border:solid 2px #8dcb69;margin:5px 10px 5px 20px;border-radius:10px;padding:5px 20px}.auto-task-keylol{display:inline-block;text-transform:capitalize;margin-left:10px;text-decoration:none !important;border:solid 1px;border-radius:5px;padding:0 2px}.auto-task-keylol[selected=selected]{background-color:blue !important;color:#fff !important}.auto-task-form table{font-family:verdana,arial,sans-serif;font-size:11px;color:#333;border-width:1px;border-color:#999;border-collapse:collapse;width:100%}.auto-task-form table thead td{border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9;font-weight:bold;background-color:#fff}.auto-task-form table tbody tr{background-color:#d4e3e5}.auto-task-form table tbody tr:hover{background-color:#ff6 !important}.auto-task-form table tbody tr th{background-color:#c3dde0;border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9;text-transform:capitalize}.auto-task-form table tbody tr td{border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9}.swal2-modal{width:70% !important;max-width:1000px !important}body.auto-task-options{padding-top:10px;text-align:center}body.auto-task-options .auto-task-form{width:80%;max-width:1000px;margin:0 auto;padding-bottom:20px}body.auto-task-options .auto-task-form table input.editOption{width:80%}body.auto-task-options .auto-task-form table #getTwitterUserId,body.auto-task-options .auto-task-form table #getYoutubeChannelId{margin-top:5px}body.auto-task-options .auto-task-form table button{z-index:1}body.auto-task-options .auto-task-form table input[type=text]{outline-style:none;border:1px solid #ccc;border-radius:3px;padding:5px 10px;font-size:14px}body.auto-task-options .auto-task-form table input[type=text]:focus{border-color:#66afe9;outline:0;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}body.auto-task-options .auto-task-form table label{position:relative;width:160px;height:80px;cursor:pointer;transform:scale(0.25);margin:-25% 0;top:-30px;display:inline-block}body.auto-task-options .auto-task-form table label input{position:relative;z-index:1;appearance:none}body.auto-task-options .auto-task-form table label input:checked~span{background:#05be05;box-shadow:0 15px 25px #05be0566}body.auto-task-options .auto-task-form table label input:checked~span i{left:84px}body.auto-task-options .auto-task-form table label input:checked~span i::before{background:#05be05;box-shadow:35px 0 0 #05be05}body.auto-task-options .auto-task-form table label input:checked~span i::after{bottom:12px;height:15px;border-bottom-left-radius:15px;border-bottom-right-radius:15px;background:#05be05}body.auto-task-options .auto-task-form table label span{position:absolute;top:0;left:0;width:100%;height:100%;background:#fe0000;border-radius:80px;transition:.5s;box-shadow:0 15px 25px #fe000066}body.auto-task-options .auto-task-form table label span i{position:absolute;top:4px;left:4px;width:72px;height:72px;background:#fff;border-radius:50%}body.auto-task-options .auto-task-form table label span i::before{content:"";position:absolute;top:22px;left:12px;width:12px;height:12px;border-radius:50%;background:#fe0000;box-shadow:35px 0 0 #fe0000;transition:.5s}body.auto-task-options .auto-task-form table label span i::after{content:"";position:absolute;bottom:15px;left:calc(50% - 15px);width:30px;height:6px;border-radius:6px;background:#fe0000;transition:.5s}body.auto-task-history{font-size:15px;font-weight:400;line-height:1.5}body.auto-task-history .container a{color:#007bff;text-decoration:none;background-color:transparent}body.auto-task-history .container .card{width:80%;max-width:800px;border-radius:10px;background:#7676761a;border-top:1px solid #ffffff80;-webkit-backdrop-filter:blur(20px);backdrop-filter:blur(20px);box-shadow:0 15px 25px #0000001a;margin:20px auto;position:relative;display:flex;flex-direction:column;word-wrap:break-word;-webkit-background-clip:border-box;background-clip:border-box;border:1px solid rgba(0,0,0,.125);border-radius:.25rem}body.auto-task-history .container .card .title{text-align:center;font-size:30px;font-weight:bold;margin:5px 0}body.auto-task-history .container .card .title a:hover{text-decoration:none;background:#93e1ff;border-radius:10px;padding:3px}body.auto-task-history .container .card ul{margin-bottom:25px}body.auto-task-history .container .card ul li{margin-bottom:5px;line-height:20px}body.auto-task-history .container .card ul a:hover{text-decoration:underline}body.auto-task-history .container .card .delete-task{right:10px;width:38px;height:35px;position:absolute;font-size:24px;cursor:pointer;border-radius:10px}body.auto-task-history .container .card .delete-task:hover{background:#fff}body.auto-task-history .container .card .time{right:5px;position:absolute;bottom:0;color:#e83e8c;font-family:\'SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace\';font-size:15px}#auto-task-buttons,.show-button-div{position:fixed;top:30px;right:15px;width:124px;z-index:999999999 !important;transform:scale(0.85)}#auto-task-buttons p,.show-button-div p{line-height:30px;height:40px;text-align:center;margin:5px !important}#auto-task-buttons a.auto-task-website-btn,.show-button-div a.auto-task-website-btn{width: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. 999: 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. 494: 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 auto_task = __webpack_require__(568);
  561. var javascript_utils_umd_min = __webpack_require__(108);
  562. const httpRequest = async (options, times = 0) => {
  563. if (window.TRACE) {
  564. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  565. }
  566. try {
  567. const result = await new Promise(resolve => {
  568. if (options.dataType) {
  569. options.responseType = options.dataType;
  570. }
  571. const requestObj = {
  572. ...{
  573. timeout: 3e4,
  574. ontimeout(data) {
  575. resolve({
  576. result: 'Error',
  577. statusText: 'Timeout',
  578. status: 601,
  579. data: data,
  580. options: options
  581. });
  582. },
  583. onabort(data) {
  584. resolve({
  585. result: 'Error',
  586. statusText: 'Aborted',
  587. status: 602,
  588. data: data,
  589. options: options
  590. });
  591. },
  592. onerror(data) {
  593. resolve({
  594. result: 'Error',
  595. statusText: 'Error',
  596. status: 603,
  597. data: data,
  598. options: options
  599. });
  600. },
  601. onload(data) {
  602. if (options.responseType === 'json' && data?.response && typeof data.response !== 'object') {
  603. try {
  604. data.response = JSON.parse(data.responseText);
  605. } catch (error) {}
  606. }
  607. resolve({
  608. result: 'Success',
  609. statusText: 'Load',
  610. status: 600,
  611. data: data,
  612. options: options
  613. });
  614. }
  615. },
  616. ...options
  617. };
  618. GM_xmlhttpRequest(requestObj);
  619. });
  620. if (window.DEBUG) {
  621. console.log('%cAuto-Task[httpRequest]:', 'color:blue', JSON.stringify(result));
  622. }
  623. if (result.status !== 600 && times < 2) {
  624. return await httpRequest(options, times + 1);
  625. }
  626. return result;
  627. } catch (error) {
  628. console.log('%cAuto-Task[httpRequest]:', 'color:red', JSON.stringify({
  629. errorMsg: error,
  630. options: options
  631. }));
  632. throwError(error, 'httpRequest');
  633. return {
  634. result: 'JsError',
  635. statusText: 'Error',
  636. status: 604,
  637. error: error,
  638. options: options
  639. };
  640. }
  641. };
  642. const tools_httpRequest = httpRequest;
  643. const echoLog = ({
  644. type,
  645. text,
  646. html,
  647. id
  648. }) => {
  649. const emptyStatus = {
  650. success: () => emptyStatus,
  651. error: () => emptyStatus,
  652. warning: () => emptyStatus,
  653. info: () => emptyStatus,
  654. view: () => emptyStatus
  655. };
  656. try {
  657. let ele;
  658. if (type) {
  659. switch (type) {
  660. case 'joiningSteamGroup':
  661. case 'leavingSteamGroup':
  662. case 'gettingSteamGroupId':
  663. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/groups/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  664. break;
  665.  
  666. case 'joiningSteamOfficialGroup':
  667. case 'leavingSteamOfficialGroup':
  668. case 'gettingSteamOfficialGroupId':
  669. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/games/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  670. break;
  671.  
  672. case 'subscribingForum':
  673. case 'unsubscribingForum':
  674. case 'gettingForumId':
  675. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/app/${text}/discussions/" target="_blank">${text}</a>]...<font></font></li>`);
  676. break;
  677.  
  678. case 'followingCurator':
  679. case 'unfollowingCurator':
  680. case 'gettingCuratorId':
  681. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/${text?.includes('/') ? text : `curator/${text}`}" target="_blank">${text}</a>]...<font></font></li>`);
  682. break;
  683.  
  684. case 'addingToWishlist':
  685. case 'removingFromWishlist':
  686. case 'followingGame':
  687. case 'unfollowingGame':
  688. case 'gettingSubid':
  689. case 'addingFreeLicense':
  690. case 'requestingPlayTestAccess':
  691. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/app/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  692. break;
  693.  
  694. case 'addingFreeLicenseSubid':
  695. ele = $(`<li>${i18n('addingFreeLicense')}[<a href="https://steamdb.info/sub/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  696. break;
  697.  
  698. case 'favoritingWorkshop':
  699. case 'unfavoritingWorkshop':
  700. case 'gettingWorkshopAppId':
  701. case 'votingUpWorkshop':
  702. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/sharedfiles/filedetails/?id=${text}" target="_blank">
  703. ${text}</a>]...<font></font></li>`);
  704. break;
  705.  
  706. case 'gettingAnnouncementParams':
  707. case 'likingAnnouncement':
  708. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/news/app/${text}/view/${id}" target="_blank">
  709. ${id}</a>]...<font></font></li>`);
  710. break;
  711.  
  712. case 'joiningDiscordServer':
  713. case 'gettingDiscordGuild':
  714. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/invite/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  715. break;
  716.  
  717. case 'leavingDiscordServer':
  718. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/channels/@me/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  719. break;
  720.  
  721. case 'updateDiscordAuth':
  722. ele = $(`<li style="color:red;">${i18n('updateDiscordAuth')}</li>`);
  723. break;
  724.  
  725. case 'followingTwitchChannel':
  726. case 'unfollowingTwitchChannel':
  727. case 'gettingTwitchChannelId':
  728. ele = $(`<li>${i18n(type)}[<a href="https://www.twitch.tv/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  729. break;
  730.  
  731. case 'gettingInsUserId':
  732. case 'followingIns':
  733. case 'unfollowingIns':
  734. ele = $(`<li>${i18n(type)}[<a href="https://www.instagram.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  735. break;
  736.  
  737. case 'gettingTwitterUserId':
  738. case 'followingTwitterUser':
  739. case 'unfollowingTwitterUser':
  740. ele = $(`<li>${i18n(type)}[<a href="https://x.com/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  741. break;
  742.  
  743. case 'retweetting':
  744. case 'unretweetting':
  745. ele = $(`<li>${i18n(type)}${text}...<font></font></li>`);
  746. break;
  747.  
  748. case 'joiningReddit':
  749. case 'leavingReddit':
  750. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/r/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  751. break;
  752.  
  753. case 'followingRedditUser':
  754. case 'unfollowingRedditUser':
  755. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/user/${text?.replace('u_', '')}" target="_blank">
  756. ${text?.replace('u_', '')}</a>]...<font></font></li>`);
  757. break;
  758.  
  759. case 'followingYtbChannel':
  760. case 'unfollowingYtbChannel':
  761. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/channel/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  762. break;
  763.  
  764. case 'likingYtbVideo':
  765. case 'unlikingYtbVideo':
  766. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/watch?v=${text}" target="_blank">${text}</a>]...<font></font></li>`);
  767. break;
  768.  
  769. case 'gettingVkId':
  770. case 'joiningVkGroup':
  771. case 'leavingVkGroup':
  772. case 'joiningVkPublic':
  773. case 'leavingVkPublic':
  774. case 'sendingVkWall':
  775. case 'deletingVkWall':
  776. ele = $(`<li>${i18n(type)}[<a href="https://vk.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  777. break;
  778.  
  779. case 'visitingLink':
  780. ele = $(`<li>${i18n('visitingLink')}[<a href="${text}" target="_blank">${text}</a>]...<font></font></li>`);
  781. break;
  782.  
  783. case 'verifyingInsAuth':
  784. case 'text':
  785. ele = $(`<li>${i18n(text)}<font></font></li>`);
  786. break;
  787.  
  788. case 'html':
  789. ele = $(text || html);
  790. break;
  791.  
  792. case 'whiteList':
  793. ele = $(`<li><font class="warning">${i18n('skipTask')}[${text}(${id})](${i18n('whiteList')})</font></li>`);
  794. break;
  795.  
  796. case 'globalOptionsSkip':
  797. ele = $(`<li>${i18n('skipTaskOption')}<font class="warning">${text}</font></li>`);
  798. break;
  799.  
  800. default:
  801. ele = $(`<li>${i18n('unKnown')}:${type}(${text})...<font></font></li>`);
  802. break;
  803. }
  804. } else if (text) {
  805. ele = $(`<li>${i18n(text)}<font></font></li>`);
  806. } else if (html) {
  807. ele = $(html);
  808. } else {
  809. ele = $('<li><font></font></li>');
  810. }
  811. ele.addClass('card-text');
  812. $('#auto-task-info').append(ele);
  813. ele[0]?.scrollIntoView();
  814. const font = ele.find('font');
  815. const status = {
  816. font: font,
  817. success(text = 'Success', html = false) {
  818. this.font?.attr('class', '').addClass('success');
  819. html ? this.font?.html(text) : this.font?.text(text);
  820. return this;
  821. },
  822. error(text = 'Error', html = false) {
  823. this.font?.attr('class', '').addClass('error');
  824. html ? this.font?.html(text) : this.font?.text(text);
  825. return this;
  826. },
  827. warning(text = 'Warning', html = false) {
  828. this.font?.attr('class', '').addClass('warning');
  829. html ? this.font?.html(text) : this.font?.text(text);
  830. return this;
  831. },
  832. info(text = 'Info', html = false) {
  833. this.font?.attr('class', '').addClass('info');
  834. html ? this.font?.html(text) : this.font?.text(text);
  835. return this;
  836. },
  837. view() {
  838. this.font?.[0].scrollIntoView();
  839. return this;
  840. }
  841. };
  842. return status;
  843. } catch (error) {
  844. throwError(error, 'echoLog');
  845. return emptyStatus;
  846. }
  847. };
  848. const scripts_echoLog = echoLog;
  849. const unique = array => {
  850. try {
  851. return [ ...new Set(array) ];
  852. } catch (error) {
  853. throwError(error, 'unique');
  854. return [];
  855. }
  856. };
  857. const delay = (time = 1e3) => new Promise(resolve => {
  858. setTimeout(() => {
  859. resolve(true);
  860. }, time);
  861. });
  862. const getRedirectLink = async link => {
  863. try {
  864. if (!link) {
  865. return null;
  866. }
  867. const redirectLinksCache = GM_getValue('redirectLinks') || {};
  868. if (redirectLinksCache[link]) {
  869. redirectLinksCache[link];
  870. }
  871. return await tools_httpRequest({
  872. url: link,
  873. method: 'GET'
  874. }).then(({
  875. data
  876. }) => {
  877. if (data?.finalUrl) {
  878. redirectLinksCache[link] = data.finalUrl;
  879. GM_setValue('redirectLinks', redirectLinksCache);
  880. return data.finalUrl;
  881. }
  882. return null;
  883. });
  884. } catch (error) {
  885. throwError(error, 'getRedirectLink');
  886. return null;
  887. }
  888. };
  889. const visitLink = async (link, options) => {
  890. try {
  891. const logStatus = scripts_echoLog({
  892. type: 'visitLink',
  893. text: link
  894. });
  895. return await tools_httpRequest({
  896. url: link,
  897. method: 'GET',
  898. ...options
  899. }).then(({
  900. result,
  901. statusText,
  902. status
  903. }) => {
  904. if (result === 'Success') {
  905. logStatus.success();
  906. return true;
  907. }
  908. logStatus.error(`${result}:${statusText}(${status})`);
  909. return false;
  910. });
  911. } catch (error) {
  912. throwError(error, 'visitLink');
  913. return false;
  914. }
  915. };
  916. const getUrlQuery = url => {
  917. try {
  918. const query = {};
  919. if (url) {
  920. if (url.includes('?')) {
  921. url.split('?')[1].replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  922. query[key] = value;
  923. return str;
  924. });
  925. }
  926. } else {
  927. window.location.search.replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  928. query[key] = value;
  929. return str;
  930. });
  931. }
  932. return query;
  933. } catch (error) {
  934. throwError(error, 'getUrlQuery');
  935. return {};
  936. }
  937. };
  938. const getUuid = () => {
  939. const uuidUrl = URL.createObjectURL(new Blob()).toString();
  940. return uuidUrl.slice(uuidUrl.lastIndexOf('/') + 1);
  941. };
  942. const stringToColour = str => {
  943. try {
  944. let hash = 0;
  945. for (let i = 0; i < str.length; i++) {
  946. hash = str.charCodeAt(i) + ((hash << 5) - hash);
  947. }
  948. let colour = '#';
  949. for (let i = 0; i < 3; i++) {
  950. const value = hash >> i * 8 & 255;
  951. colour += `00${value.toString(16)}`.slice(-2);
  952. }
  953. return colour;
  954. } catch (error) {
  955. throwError(error, 'stringToColour');
  956. return '#fff';
  957. }
  958. };
  959. const defaultGlobalOptions = {
  960. doTask: {
  961. discord: {
  962. servers: true
  963. },
  964. instagram: {
  965. users: true
  966. },
  967. twitch: {
  968. channels: true
  969. },
  970. twitter: {
  971. users: true,
  972. retweets: true
  973. },
  974. vk: {
  975. names: true
  976. },
  977. youtube: {
  978. channels: true,
  979. likes: true
  980. },
  981. reddit: {
  982. reddits: true
  983. },
  984. steam: {
  985. groups: true,
  986. officialGroups: true,
  987. wishlists: true,
  988. follows: true,
  989. forums: true,
  990. workshops: true,
  991. curators: true,
  992. workshopVotes: true,
  993. announcements: true,
  994. licenses: true,
  995. playtests: true
  996. }
  997. },
  998. undoTask: {
  999. discord: {
  1000. servers: true
  1001. },
  1002. instagram: {
  1003. users: true
  1004. },
  1005. twitch: {
  1006. channels: true
  1007. },
  1008. twitter: {
  1009. users: true,
  1010. retweets: true
  1011. },
  1012. vk: {
  1013. names: true
  1014. },
  1015. youtube: {
  1016. channels: true,
  1017. likes: true
  1018. },
  1019. reddit: {
  1020. reddits: true
  1021. },
  1022. steam: {
  1023. groups: true,
  1024. officialGroups: true,
  1025. wishlists: true,
  1026. follows: true,
  1027. forums: true,
  1028. workshops: true,
  1029. curators: true
  1030. }
  1031. },
  1032. ASF: {
  1033. AsfEnabled: false,
  1034. AsfIpcUrl: '',
  1035. AsfIpcPassword: '',
  1036. AsfBotname: 'asf'
  1037. },
  1038. position: {
  1039. buttonSideX: 'right',
  1040. buttonSideY: 'top',
  1041. buttonDistance: '15,30',
  1042. showButtonSideX: 'right',
  1043. showButtonSideY: 'top',
  1044. showButtonDistance: '15,30',
  1045. logSideX: 'right',
  1046. logSideY: 'bottom',
  1047. logDistance: '10,10'
  1048. },
  1049. hotKey: {
  1050. doTaskKey: 'alt + d',
  1051. undoTaskKey: 'alt + u',
  1052. toggleLogKey: 'alt + l'
  1053. },
  1054. other: {
  1055. twitterVerifyId: '783214',
  1056. youtubeVerifyChannel: 'UCrXUsMBcfTVqwAS7DKg9C0Q',
  1057. autoUpdateSource: 'jsdelivr',
  1058. language: 'zh',
  1059. checkLogin: true,
  1060. checkLeftKey: true,
  1061. defaultShowButton: true,
  1062. defaultShowLog: true,
  1063. debug: false,
  1064. receivePreview: true
  1065. }
  1066. };
  1067. const userDefinedGlobalOptions = GM_getValue('globalOptions') || {};
  1068. const assignObject = (obj1, obj2) => {
  1069. try {
  1070. const newObj = {};
  1071. for (const [ key, value ] of Object.entries(obj1)) {
  1072. if (Object.prototype.toString.call(value) === '[object Object]' && Object.prototype.toString.call(obj2[key]) === '[object Object]') {
  1073. newObj[key] = assignObject(value, obj2[key]);
  1074. } else {
  1075. newObj[key] = obj2[key] ?? value;
  1076. }
  1077. }
  1078. return newObj;
  1079. } catch (error) {
  1080. throwError(error, 'assignObject');
  1081. return defaultGlobalOptions;
  1082. }
  1083. };
  1084. const globalOptions = assignObject(defaultGlobalOptions, userDefinedGlobalOptions);
  1085. const saveData = () => {
  1086. try {
  1087. const data = {};
  1088. $('#globalOptionsForm').serializeArray().map(value => {
  1089. data[value.name] = value.value;
  1090. return value;
  1091. });
  1092. $.makeArray($('#globalOptionsForm input')).map(element => {
  1093. const name = $(element).attr('name');
  1094. const keys = name.split('.');
  1095. if (keys.length === 3) {
  1096. globalOptions[keys[0]][keys[1]][keys[2]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1097. } else if (keys.length === 2) {
  1098. globalOptions[keys[0]][keys[1]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1099. }
  1100. return element;
  1101. });
  1102. GM_setValue('globalOptions', globalOptions);
  1103. external_Swal_default().fire({
  1104. title: i18n('changeGlobalOptionsSuccess'),
  1105. icon: 'success'
  1106. });
  1107. } catch (error) {
  1108. throwError(error, 'saveData');
  1109. }
  1110. };
  1111. const changeGlobalOptions = showType => {
  1112. try {
  1113. let globalOptionsForm = `<form id="globalOptionsForm" class="auto-task-form">
  1114. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  1115. for (const [ type, data1 ] of Object.entries(globalOptions)) {
  1116. for (const [ option, data2 ] of Object.entries(data1)) {
  1117. if ([ 'other', 'position', 'hotKey', 'ASF' ].includes(type)) {
  1118. if (typeof data2 === 'boolean') {
  1119. 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>`;
  1120. } else {
  1121. 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>`;
  1122. }
  1123. } else {
  1124. for (const [ socialType, data3 ] of Object.entries(data2)) {
  1125. 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>`;
  1126. }
  1127. }
  1128. }
  1129. }
  1130. globalOptionsForm += '</tbody></table></form>';
  1131. if (showType === 'swal') {
  1132. external_Swal_default().fire({
  1133. title: i18n('globalOptions'),
  1134. html: globalOptionsForm,
  1135. showConfirmButton: true,
  1136. confirmButtonText: i18n('save'),
  1137. showCancelButton: true,
  1138. cancelButtonText: i18n('close')
  1139. }).then(({
  1140. isConfirmed
  1141. }) => {
  1142. if (isConfirmed) {
  1143. saveData();
  1144. }
  1145. });
  1146. } else {
  1147. $('body').append(`<h2>${i18n('globalOptions')}</h2>${globalOptionsForm}`);
  1148. }
  1149. } catch (error) {
  1150. throwError(error, 'changeGlobalOptions');
  1151. }
  1152. };
  1153. const data = {
  1154. website: '网站',
  1155. type: '类型',
  1156. edit: '编辑',
  1157. whiteList: '白名单',
  1158. skipTask: '跳过撤销任务',
  1159. whiteListOptions: '白名单设置',
  1160. changeWhiteListOption: '设置白名单(%0)',
  1161. whiteListNotFound: '找不到此项白名单: %0',
  1162. changeWhiteListSuccess: '白名单修改成功,刷新生效!',
  1163. changeWebsiteOptions: '网站设置',
  1164. changeGlobalOptions: '全局设置',
  1165. ok: '是',
  1166. save: '保存',
  1167. close: '关闭',
  1168. return: '返回',
  1169. option: '选项',
  1170. value: '值',
  1171. websiteOptions: '当前网站设置',
  1172. changeWebsiteOptionsSuccess: '更改当前网站设置成功,刷新生效!',
  1173. changeGlobalOptionsSuccess: '更改全局设置成功,刷新生效!',
  1174. needLogin: '请先登录!',
  1175. getTasksInfo: '正在获取并处理任务信息...',
  1176. gettingKey: '正在获取Key...',
  1177. verifyingTask: '正在验证任务',
  1178. notice: '自动任务脚本提醒',
  1179. noKeysLeft: '此页面已经没有剩余key了,是否关闭?',
  1180. giveawayEnded: '此活动已结束,是否关闭?',
  1181. giveawayNotWork: '此活动因某些原因(已结束/暂停/未开始...)不可用(如果是脚本误判请及时反馈),是否关闭?',
  1182. confirm: '确定',
  1183. cancel: '取消',
  1184. unKnown: '未知',
  1185. unKnownTaskType: '未识别的任务',
  1186. doing: '正在做任务',
  1187. allTasksComplete: '所有任务已完成!',
  1188. getTaskIdFailed: '获取任务Id失败!',
  1189. initSuccess: '%0 初始化成功!',
  1190. initFailed: '%0 初始化失败!',
  1191. errorLink: '链接错误: %0',
  1192. needInit: '请先初始化',
  1193. verifyingAuth: '正在验证%0凭证...',
  1194. updatingAuth: '正在更新%0凭证...',
  1195. refreshingToken: '正在刷新%0凭证...',
  1196. settingToken: '正在设置%0凭证...',
  1197. initing: '正在初始化...',
  1198. getFailed: '获取%0失败!',
  1199. checkLoginFailed: '检测登录状态失败!',
  1200. checkLeftKeyFailed: '检测剩余Key失败!',
  1201. userId: '用户Id',
  1202. joiningGiveaway: '正在加入赠Key',
  1203. needJoinGiveaway: '需要先加入赠Key',
  1204. cannotUndo: '此网站不支持取消任务',
  1205. verifyAuth: '正在验证 %0 凭证...',
  1206. closePageNotice: '如果此页面没有自动关闭,请自行关闭本页面。',
  1207. errorReport: '检测到脚本报错,是否前往反馈BUG?',
  1208. visitingLink: '正在访问链接: ',
  1209. doTask: '做任务',
  1210. undoTask: '撤销任务',
  1211. verifyTask: '验证任务',
  1212. getKey: '获取Key',
  1213. selectAll: '全选',
  1214. selectNone: '全不选',
  1215. invertSelect: '反选',
  1216. doFreeTask: '加入免费赠品',
  1217. doPointTask: '加入点数赠品',
  1218. skipTaskOption: '设置中已配置跳过任务',
  1219. other: '其他',
  1220. globalOptions: '全局设置',
  1221. checkLogin: '登录检测</br>需要登录的网站自动登录,部分本网站支持',
  1222. checkLeftKey: '剩余Key检测</br>赠Key活动结束提示是否关闭,部分本网站支持',
  1223. twitterVerifyId: '通过尝试关注该账号验证Twitter凭证</br>默认为Twitter官方帐号 783214</br>不想关注官方账号可以改为自己的帐号',
  1224. youtubeVerifyChannel: '通过尝试订阅该频道验证YouTube凭证</br>默认为YouTube官方频道 UCrXUsMBcfTVqwAS7DKg9C0Q</br>不想关注官方频道可以改为自己的频道',
  1225. autoUpdateSource: '更新源</br>github: 需代理,实时更新</br>jsdelivr: 可不用代理,更新有延迟</br>standby: 备用</br>auto: 依次使用github, jsdelivr, standby源进行尝试更新',
  1226. saveGlobalOptions: '保存全局设置',
  1227. settingPage: '设置页面',
  1228. name: '名称',
  1229. version: '版本',
  1230. scriptManager: '脚本管理器',
  1231. script: '脚本',
  1232. environment: '环境',
  1233. os: '系统',
  1234. browser: '浏览器',
  1235. getId: '获取 %0 id',
  1236. getTwitterUserId: '获取Twitter用户id(获取id功能仅在设置页面可用)',
  1237. getYoutubeChannelId: '获取Youtube频道id(获取id功能仅在设置页面可用)',
  1238. showButton: '显示按钮',
  1239. hideButton: '隐藏按钮',
  1240. showLog: '显示日志',
  1241. hideLog: '隐藏日志',
  1242. defaultShowButton: '默认显示按钮',
  1243. defaultShowLog: '默认显示日志',
  1244. debug: '输出调试日志,不要开启此选项!',
  1245. receivePreview: '接收预览版更新',
  1246. position: '组件位置',
  1247. buttonSideX: '按钮区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1248. buttonSideY: '按钮区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1249. buttonDistance: '按钮区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1250. showButtonSideX: '显示按钮水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1251. showButtonSideY: '显示按钮垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1252. showButtonDistance: '显示按钮距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1253. logSideX: '日志区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1254. logSideY: '日志区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1255. logDistance: '日志区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1256. hotKey: '快捷键',
  1257. doTaskKey: '做任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1258. undoTaskKey: '撤销任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1259. toggleLogKey: '显示/隐藏日志快捷键</br>(实时预览功能仅在设置页面可用)',
  1260. tasksHistory: '任务历史',
  1261. clearHistory: '清空历史',
  1262. clearHistoryFinished: '已清空任务历史!',
  1263. deleteTask: '删除任务',
  1264. lastChangeTime: '最后一次修改时间',
  1265. clearTaskFinished: '删除以下任务完成!',
  1266. clearTaskFailed: '删除任务失败,没有找到任务名!',
  1267. syncData: '数据同步',
  1268. settingData: '正在上传数据...',
  1269. gettingData: '正在获取数据...',
  1270. help: '帮助',
  1271. fileName: '文件名',
  1272. upload2gist: '同步到Gist',
  1273. downloadFromGist: '从Gist同步',
  1274. saveAndTest: '保存配置并测试',
  1275. testSuccess: '测试成功!',
  1276. testFailed: '测试失败!',
  1277. saveAndTestNotice: '请先保存配置并测试!',
  1278. processingData: '正在处理数据...',
  1279. updatingData: '正在上传数据...',
  1280. syncDataSuccess: '同步数据成功!',
  1281. syncDataFailed: '同步数据失败,请在控制台查看错误信息!',
  1282. downloadingData: '正在下载数据...',
  1283. checkedNoData: '没有检测到远程数据,请确认配置是否正确!',
  1284. savingData: '正在保存数据...',
  1285. syncHistory: '同步任务历史',
  1286. checkUpdateFailed: '检测更新失败',
  1287. newVersionNotice: '检测到新版本V%0, <a class="high-light" href="%1" target="_blank">点此更新</a>',
  1288. language: '语言</br>目前仅支持zh: 中文, en: 英文',
  1289. gistOptions: 'Gist 设置',
  1290. swalNotice: '检测到您第一次安装V4版本脚本,请前往阅读用前必读内容!',
  1291. echoNotice: '检测到您第一次安装V4版本脚本,请<a class="high-light" href="%0" target="_blank">点此前往</a>阅读用前必读内容!',
  1292. noticeLink: 'https://auto-task-doc.js.org/guide/#用前必读',
  1293. toGithub: '前往Github反馈',
  1294. toKeylol: '前往其乐论坛反馈',
  1295. copySuccess: '错误信息已复制到剪切板,是否前往其乐论坛反馈?',
  1296. copyFailed: '请复制下方错误信息后前往Keylol论坛反馈!',
  1297. updateText: '%0 版本更新内容:',
  1298. Active: '进行中',
  1299. Ended: '已结束',
  1300. Banned: '已封禁',
  1301. Paused: '已暂停',
  1302. notStart: '未开始',
  1303. noRemoteData: '检测到远程无数据',
  1304. errorRemoteDataFormat: '远程数据格式错误',
  1305. updateHistory: '历史更新记录<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">点此查看</a>',
  1306. AsfEnabled: '使用ASF做Steam相关任务(需<a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a>插件)',
  1307. AsfIpcUrl: 'ASF IPC 地址',
  1308. AsfIpcPassword: 'ASF IPC 密码',
  1309. versionNotMatched: '脚本管理器版本过低,需TamperMonkey >= 5.2.0或TamperMonkey Beta >= 5.2.6196',
  1310. groups: '组',
  1311. officialGroups: '官方组',
  1312. wishlists: '愿望单',
  1313. follows: '游戏关注',
  1314. forums: '论坛',
  1315. workshops: '创意工坊收藏',
  1316. curators: '鉴赏家',
  1317. workshopVotes: '创意工坊点赞',
  1318. announcements: '社区通知',
  1319. steamCommunity: 'Steam社区',
  1320. steamStore: 'Steam商店',
  1321. licenses: '入库免费游戏',
  1322. playtests: '请求访问权限',
  1323. needLoginSteamStore: '请先<a href="https://store.steampowered.com/login/" target="_blank">登录Steam商店</a>',
  1324. needLoginSteamCommunity: '请先<a href="https://steamcommunity.com/login/home/" target="_blank">登录Steam社区</a>',
  1325. joiningSteamGroup: '正在加入Steam组',
  1326. leavingSteamGroup: '正在退出Steam组',
  1327. gettingSteamGroupId: '正在获取Steam组Id',
  1328. joiningSteamOfficialGroup: '正在加入Steam官方组',
  1329. leavingSteamOfficialGroup: '正在退出Steam官方组',
  1330. gettingSteamOfficialGroupId: '正在获取Steam官方组Id',
  1331. subscribingForum: '正在订阅Steam论坛',
  1332. unsubscribingForum: '正在取消订阅Steam论坛',
  1333. gettingForumId: '正在获取Steam论坛Id',
  1334. followingCurator: '正在关注Steam鉴赏家',
  1335. unfollowingCurator: '正在取关Steam鉴赏家',
  1336. gettingCuratorId: '正在获取Steam鉴赏家Id',
  1337. addingToWishlist: '正在添加游戏到Steam愿望单',
  1338. removingFromWishlist: '正在从Steam愿望单移除游戏',
  1339. followingGame: '正在关注Steam游戏',
  1340. unfollowingGame: '正在取关Steam游戏',
  1341. favoritingWorkshop: '正在收藏Steam创意工坊物品',
  1342. unfavoritingWorkshop: '正在取消收藏Steam创意工坊物品',
  1343. gettingWorkshopAppId: '正在获取Steam创意工坊物品Id',
  1344. votingUpWorkshop: '正在点赞Steam创意工坊物品',
  1345. gettingAnnouncementParams: '正在获取Steam通知信息',
  1346. likingAnnouncement: '正在点赞Steam通知',
  1347. changingArea: '正在更换Steam地区: %0...',
  1348. notNeededChangeArea: '当前地区不需要更换',
  1349. noAnotherArea: '请检测是否开启正确开启代理',
  1350. gettingAreaInfo: '正在获取Steam地区信息...',
  1351. changeAreaNotice: '疑似锁区游戏,尝试换区执行',
  1352. steamFinishNotice: 'Steam任务完成,尝试将购物车地区换回CN',
  1353. gettingSubid: '正在获取游戏subid',
  1354. addingFreeLicense: '正在入库',
  1355. missParams: '缺少参数',
  1356. gettingLicenses: '正在获取Licenses...',
  1357. requestingPlayTestAccess: '正在请求访问权限',
  1358. tryChangeAreaNotice: '此功能无法检测游戏是否限区,因此会尝试换区后再入库,换区失败也不影响后续入库',
  1359. gettingUserLink: '正在获取Steam用户社区链接...',
  1360. retry: '重试',
  1361. initingASF: '正在初始化ASF...',
  1362. servers: '服务器',
  1363. joiningDiscordServer: '正在加入Discord服务器',
  1364. leavingDiscordServer: '正在退出Discord服务器',
  1365. gettingDiscordGuild: '正在获取Discord服务器Id',
  1366. getDiscordAuthFailed: '获取Discord凭证失败,请检测Discord帐号是否已登录',
  1367. discordImportantNotice: '重要提醒!!!',
  1368. discordImportantNoticeText: '由于Discord网站后台更新,目前使用此脚本加组后可能会导致Discord帐号被强制退出,且需要两步验证才能正常登录,请谨慎使用!!!',
  1369. continue: '继续',
  1370. skipDiscordTask: '跳过Discord任务',
  1371. continueAndDontRemindAgain: '继续且不再提醒',
  1372. users: '用户',
  1373. loginIns: '请先<a href="https://www.instagram.com/accounts/login/" target="_blank">登录Instagram</a>',
  1374. insBanned: '您的Instagram账户已被封禁',
  1375. verifyingInsAuth: '正在验证Instagram凭证...',
  1376. gettingInsUserId: '正在获取Instagram用户Id',
  1377. followingIns: '正在关注Instagram用户',
  1378. unfollowingIns: '正在取关Instagram用户',
  1379. reddits: '社区/用户',
  1380. loginReddit: '请先<a href="https://www.reddit.com/login/" target="_blank">登录Reddit</a>',
  1381. changingRedditVersion: '正在切换Reddit为新版页面...',
  1382. joiningReddit: '正在加入Reddit社区',
  1383. leavingReddit: '正在退出Reddit社区',
  1384. followingRedditUser: '正在关注Reddit用户',
  1385. unfollowingRedditUser: '正在取关Reddit用户',
  1386. channels: '频道',
  1387. followingTwitchChannel: '正在关注Twitch频道',
  1388. unfollowingTwitchChannel: '正在取关Twitch频道',
  1389. gettingTwitchChannelId: '正在获取Twitch频道Id',
  1390. checkingTwitchIntegrity: '正在检查Twitch完整性...',
  1391. twitterUser: '推特用户',
  1392. retweets: '转推',
  1393. gettingTwitterUserId: '正在获取推特用户Id',
  1394. followingTwitterUser: '正在关注推特用户',
  1395. unfollowingTwitterUser: '正在取关推特用户',
  1396. retweetting: '正在转推',
  1397. unretweetting: '正在撤销转推',
  1398. names: '组/社区/动态',
  1399. loginVk: '请先<a href="https://vk.com/login/" target="_blank">登录Vk</a>',
  1400. gettingVkId: '正在获取Vk任务Id',
  1401. joiningVkGroup: '正在加入Vk组',
  1402. leavingVkGroup: '正在退出Vk组',
  1403. joiningVkPublic: '正在加入Vk社区',
  1404. leavingVkPublic: '正在退出Vk社区',
  1405. sendingVkWall: '正在转发Vk动态',
  1406. deletingVkWall: '正在撤销转发Vk动态',
  1407. youtubeChannel: 'YouTube频道',
  1408. likes: '点赞',
  1409. loginYtb: '请先<a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">登录YouTube</a>',
  1410. tryUpdateYtbAuth: '请尝试<a href="https://www.youtube.com/#auth" target="_blank">更新YouTube凭证</a>',
  1411. gettingYtbToken: '正在获取YouTube Token...',
  1412. followingYtbChannel: '正在订阅YouTube频道',
  1413. unfollowingYtbChannel: '正在退订YouTube频道',
  1414. likingYtbVideo: '正在点赞YouTube视频',
  1415. unlikingYtbVideo: '正在取消点赞YouTube视频',
  1416. giveKeyNoticeBefore: '每次验证间隔15s',
  1417. giveKeyNoticeAfter: '如果没有key, 请在<a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>查看',
  1418. noPoints: '点数不够,跳过抽奖',
  1419. getNeedPointsFailed: '获取所需点数失败,跳过抽奖',
  1420. joiningLottery: '正在加入抽奖',
  1421. doingGleamTask: '正在做Gleam任务...',
  1422. gettingGleamLink: '正在获取Gleam任务链接...',
  1423. gleamTaskNotice: '如果此页面长时间未关闭,请完成任一任务后自行关闭!',
  1424. verifiedGleamTasks: '已尝试验证所有任务,验证失败的任务请尝试手动验证或完成!',
  1425. campaign: '检测到人机验证,请完成验证后重新验证任务!',
  1426. gsNotice: '为避免得到"0000-0000-0000"key, 已自动屏蔽"Grab Key"按钮,获取key时请关闭脚本!',
  1427. giveeClubVerifyNotice: '正在验证任务...',
  1428. giveeClubVerifyFinished: '请等待验证完成后自行加入赠Key',
  1429. doingKeyhubTask: '正在做Keyhub任务...',
  1430. SweepWidgetNotice: '正在处理并验证任务,每次验证任务有1~3s间隔防止触发验证过快警告...',
  1431. tasksNotCompleted: '任务未完成',
  1432. confirmingTask: '正在跳过警告页面...'
  1433. };
  1434. const zh_CN = data;
  1435. const en_US_data = {
  1436. website: 'Website',
  1437. type: 'Type',
  1438. edit: 'Edit',
  1439. whiteList: 'Whitelist',
  1440. skipTask: 'Skip undo task',
  1441. whiteListOptions: 'Whitelist options',
  1442. changeWhiteListOption: 'Whitelist option(%0)',
  1443. whiteListNotFound: 'Cannot find this whitelist: %0',
  1444. changeWhiteListSuccess: 'The whitelist is successfully modified, and the page refresh will take effect!',
  1445. changeWebsiteOptions: 'Website options',
  1446. changeGlobalOptions: 'Global options',
  1447. ok: 'OK',
  1448. save: 'Save',
  1449. close: 'Close',
  1450. return: 'Return',
  1451. option: 'Option',
  1452. value: 'Value',
  1453. websiteOptions: 'Current website settings',
  1454. changeWebsiteOptionsSuccess: 'The current website setting is changed successfully, and the page refresh will take effect!',
  1455. changeGlobalOptionsSuccess: 'The global setting is changed successfully, and the refresh will take effect!',
  1456. needLogin: 'Please log in first!',
  1457. getTasksInfo: 'Obtaining and processing task information...',
  1458. gettingKey: 'Getting Key...',
  1459. verifyingTask: 'Verifying task',
  1460. notice: 'Automatic task script notice',
  1461. noKeysLeft: 'There are no more keys left on this page. Do you want to close it?',
  1462. giveawayEnded: 'This event has ended, do you want to close it?',
  1463. 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?',
  1464. confirm: 'Confirm',
  1465. cancel: 'Cancel',
  1466. unKnown: 'Unknown',
  1467. unKnownTaskType: 'Unrecognized task',
  1468. doing: 'Doing a task',
  1469. allTasksComplete: 'All tasks have been completed!',
  1470. getTaskIdFailed: 'Failed to obtain task Id!',
  1471. initSuccess: '%0 was initialized successfully!',
  1472. initFailed: '%0 initialization failed!',
  1473. errorLink: 'Link error: %0',
  1474. needInit: 'Please initialize first',
  1475. verifyingAuth: 'Verifying %0 token...',
  1476. updatingAuth: 'Update %0 token...',
  1477. initing: 'Initializing...',
  1478. getFailed: 'Failed to get %0!',
  1479. checkLoginFailed: 'Failed to detect login status!',
  1480. checkLeftKeyFailed: 'Failed to detect the remaining keys!',
  1481. userId: 'User Id',
  1482. joiningGiveaway: 'Joining giveaway',
  1483. needJoinGiveaway: 'Need to join the giveaway first',
  1484. cannotUndo: 'This website does not support canceling tasks',
  1485. verifyAuth: 'Verifying %0 token...',
  1486. closePageNotice: 'f this page does not close automatically, please close this page yourself.',
  1487. errorReport: 'A script error is detected, do you want to report the BUG?',
  1488. visitingLink: 'Visiting link: ',
  1489. doTask: 'DoTask',
  1490. undoTask: 'UndoTask',
  1491. verifyTask: 'Verify',
  1492. getKey: 'GetKey',
  1493. selectAll: 'SelectAll',
  1494. selectNone: 'SelectNone',
  1495. invertSelect: 'InvertSelect',
  1496. doFreeTask: 'FreeTask',
  1497. doPointTask: 'PointTask',
  1498. skipTaskOption: 'Skip task has been configured in the settings',
  1499. other: 'Other',
  1500. globalOptions: 'Global Options',
  1501. checkLogin: 'Login detection</br>Need to log in to the website automatically log in, part of this website supports.',
  1502. checkLeftKey: 'Key remaining detection</br>The end of the giveaway event prompts whether to close or not, part of this website supports.',
  1503. 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.',
  1504. 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.',
  1505. 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.',
  1506. saveGlobalOptions: 'SaveSettings',
  1507. settingPage: 'Setting Page',
  1508. name: 'Name',
  1509. version: 'Version',
  1510. scriptManager: 'Script Manager',
  1511. script: 'Script',
  1512. environment: 'Environment',
  1513. os: 'OS',
  1514. browser: 'Browser',
  1515. getId: 'Get %0 id',
  1516. getTwitterUserId: 'Get Twitter user id (Get id function is only available on the settings page).',
  1517. getYoutubeChannelId: 'Get Youtube channel id (Get id function is only available on the settings page).',
  1518. showButton: 'ShowButton',
  1519. hideButton: 'HideButton',
  1520. showLog: 'ShowLog',
  1521. hideLog: 'HideLog',
  1522. defaultShowButton: 'Default display button',
  1523. defaultShowLog: 'Display log by default',
  1524. debug: 'Output debug log, do not enable this option!',
  1525. receivePreview: 'Receive preview updates',
  1526. position: 'Component position',
  1527. buttonSideX: 'Horizontal positioning of the button area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1528. 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',
  1529. 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',
  1530. showButtonSideX: 'ShowButton horizontal positioning (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1531. showButtonSideY: 'ShowButton vertical positioning (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1532. 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',
  1533. logSideX: 'Horizontal positioning of the log area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1534. logSideY: 'Vertical positioning of the log area (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1535. 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',
  1536. hotKey: 'Shortcut key',
  1537. doTaskKey: 'DoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1538. undoTaskKey: 'UndoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1539. toggleLogKey: 'ShowLog/HideLog shortcut keys</br> (real-time preview function is only available on the settings page).',
  1540. tasksHistory: 'TasksHistory',
  1541. clearHistory: 'Clear history',
  1542. clearHistoryFinished: 'The mission history has been cleared!',
  1543. deleteTask: 'Delete task',
  1544. lastChangeTime: 'Last Change Time',
  1545. clearTaskFinished: 'Delete the following tasks completed!',
  1546. clearTaskFailed: 'Failed to delete the task, the task name was not found!',
  1547. syncData: 'DataSync',
  1548. settingData: 'Uploading data...',
  1549. gettingData: 'Getting data...',
  1550. help: 'Help',
  1551. fileName: 'Filename',
  1552. upload2gist: 'Sync to Gist',
  1553. downloadFromGist: 'Sync from Gist',
  1554. saveAndTest: 'Save configuration and test',
  1555. testSuccess: 'Test success!',
  1556. testFailed: 'Test failed!',
  1557. saveAndTestNotice: 'Please save the configuration and test first!',
  1558. processingData: 'Processing data...',
  1559. updatingData: 'Uploading data...',
  1560. syncDataSuccess: 'Synchronized data successfully!',
  1561. syncDataFailed: 'Failed to synchronize data, please check the error message on the console!',
  1562. downloadingData: 'Downloading data...',
  1563. checkedNoData: 'No remote data is detected, please confirm whether the configuration is correct!',
  1564. savingData: 'Saving data...',
  1565. syncHistory: 'Synchronize tasks history',
  1566. checkUpdateFailed: 'Check update failed',
  1567. newVersionNotice: 'Checked a new version V%0, <a class="high-light" href="%1" target="_blank">click to update</a>',
  1568. language: 'Language</br> Currently only supports zh: Chinese, en: English',
  1569. gistOptions: 'Gist Settings',
  1570. 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!',
  1571. 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!',
  1572. noticeLink: 'https://auto-task-doc.js.org/en/guide/#read-me-first',
  1573. toGithub: 'Feedback(Github)',
  1574. toKeylol: 'Feedback(Keylol)',
  1575. copySuccess: 'The error message has been copied to the clipboard. Do you want to go to the Keylol forum to give feedback?',
  1576. copyFailed: 'Please copy the error information below and report back to the Keylol forum!',
  1577. updateText: 'Updates in version %0:',
  1578. Active: 'Active',
  1579. Ended: 'Ended',
  1580. Banned: 'Banned',
  1581. Paused: 'Paused',
  1582. notStart: 'notStart',
  1583. noRemoteData: 'No data remotely',
  1584. errorRemoteDataFormat: 'Remote data has wrong format',
  1585. updateHistory: '<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">Click here</a>' + ' to view the historical update record.',
  1586. AsfEnabled: 'Use ASF to do Steam related tasks (requires <a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a> plugin)',
  1587. AsfIpcUrl: 'ASF IPC URL',
  1588. AsfIpcPassword: 'ASF IPC Password',
  1589. groups: 'Group',
  1590. officialGroups: 'Official Group',
  1591. wishlists: 'Wishlist',
  1592. follows: 'Follow Game',
  1593. forums: 'Forum',
  1594. workshops: 'Favorite Workshop',
  1595. curators: 'Curator',
  1596. workshopVotes: 'Voteup Workshop',
  1597. announcements: 'Announcement',
  1598. steamCommunity: 'Steam Community',
  1599. steamStore: 'Steam Store',
  1600. licenses: 'Add License',
  1601. playtests: 'Playtest Access',
  1602. needLoginSteamStore: 'Please <a href="https://store.steampowered.com/login/" target="_blank">log in to the Steam Store</a>',
  1603. needLoginSteamCommunity: 'Please <a href="https://steamcommunity.com/login/home/" target="_blank">log in to the Steam Community</a>',
  1604. joiningSteamGroup: 'Joining Steam Group',
  1605. leavingSteamGroup: 'Leaving Steam Group',
  1606. gettingSteamGroupId: 'Getting Steam Group Id',
  1607. joiningSteamOfficialGroup: 'Joining Steam Official Group',
  1608. leavingSteamOfficialGroup: 'Leaving Steam Official Group',
  1609. gettingSteamOfficialGroupId: 'Getting Steam Official Group Id',
  1610. subscribingForum: 'Subscribing the Steam Forum',
  1611. unsubscribingForum: 'Unsubscribing the Steam Forum',
  1612. gettingForumId: 'Getting Steam Forum Id',
  1613. followingCurator: 'Following Steam Curator',
  1614. unfollowingCurator: 'Unfollowing Steam Curator',
  1615. gettingCuratorId: 'Getting Steam Curator Id',
  1616. addingToWishlist: 'Adding the game to the Steam wishlist',
  1617. removingFromWishlist: 'Removing the game from the Steam wishlist',
  1618. followingGame: 'Following Steam games',
  1619. unfollowingGame: 'Unfollowing Steam games',
  1620. favoritingWorkshop: 'Favouring Steam Workshop Items',
  1621. unfavoritingWorkshop: 'Unfavoriting Steam Workshop Items',
  1622. gettingWorkshopAppId: 'Getting Steam Workshop Item Id',
  1623. votingUpWorkshop: 'Liking Steam workshop items',
  1624. gettingAnnouncementParams: 'Getting Steam announcement information',
  1625. likingAnnouncement: 'Liking Steam announcement',
  1626. changingArea: 'Changing Steam area: %0...',
  1627. notNeededChangeArea: 'The current area does not need to be changed',
  1628. noAnotherArea: 'Please check whether the proxy is turned on correctly',
  1629. gettingAreaInfo: 'Getting Steam area information...',
  1630. changeAreaNotice: 'Suspected of a locked zone game, try to change the zone to execute',
  1631. steamFinishNotice: 'Steam task completed, try to change the shopping cart area back to CN',
  1632. gettingSubid: 'Getting subid',
  1633. addingFreeLicense: 'Adding free license',
  1634. missParams: 'Missing parameters',
  1635. gettingLicenses: 'Getting licenses...',
  1636. requestingPlayTestAccess: 'Requesting play test access',
  1637. 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.',
  1638. versionNotMatched: 'The script manager version is too low, requiring TamperMonkey >= 5.2.0 or TamperMonkey Beta >= 5.2.6196',
  1639. gettingUserLink: 'Getting steam user community link...',
  1640. retry: 'Retry',
  1641. initingASF: 'Initing ASF...',
  1642. servers: 'Server',
  1643. joiningDiscordServer: 'Joining Discord Server',
  1644. leavingDiscordServer: 'Leaving Discord Server',
  1645. gettingDiscordGuild: 'Getting Discord server Id',
  1646. getDiscordAuthFailed: 'Failed to get Discord token, please check whether the Discord account is logged in',
  1647. discordImportantNotice: 'Important Reminder! ! !',
  1648. 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! ! !',
  1649. continue: 'Continue',
  1650. skipDiscordTask: 'Skip',
  1651. continueAndDontRemindAgain: 'Continue without Reminders',
  1652. users: 'User',
  1653. loginIns: 'Please <a href="https://www.instagram.com/accounts/login/" target="_blank">log in to Instagram</a>',
  1654. insBanned: 'Your Instagram account has been banned',
  1655. verifyingInsAuth: 'Verifying Instagram token...',
  1656. gettingInsUserId: 'Getting Instagram user Id',
  1657. followingIns: 'Following Instagram user',
  1658. unfollowingIns: 'Unfollowing Instagram user',
  1659. reddits: 'Reddit/User',
  1660. loginReddit: 'Please <a href="https://www.reddit.com/login/" target="_blank">log in to Reddit</a>',
  1661. changingRedditVersion: 'Switching Reddit to a new version page...',
  1662. joiningReddit: 'Joining the Reddit',
  1663. leavingReddit: 'Leaving the Reddit',
  1664. followingRedditUser: 'Following Reddit User',
  1665. unfollowingRedditUser: 'Unfollowing Reddit User',
  1666. channels: 'Channel',
  1667. followingTwitchChannel: 'Following Twitch Channel',
  1668. unfollowingTwitchChannel: 'Unfollowing Twitch Channel',
  1669. gettingTwitchChannelId: 'Getting Twitch Channel Id',
  1670. checkingTwitchIntegrity: 'Checking Twitch integrity...',
  1671. twitterUser: 'Twitter User',
  1672. retweets: 'Retweet',
  1673. gettingTwitterUserId: 'Getting Twitter User Id',
  1674. followingTwitterUser: 'Following Twitter User',
  1675. unfollowingTwitterUser: 'Unfollowing Twitter User',
  1676. retweetting: 'Retweetting',
  1677. unretweetting: 'Unretweetting',
  1678. names: 'Group/Public/Wall',
  1679. loginVk: 'Please <a href="https://vk.com/login/" target="_blank">log in to Vk</a>',
  1680. gettingVkId: 'Getting Vk task Id',
  1681. joiningVkGroup: 'Joining Vk Group',
  1682. leavingVkGroup: 'Leaving Vk Group',
  1683. joiningVkPublic: 'Joining Vk Public',
  1684. leavingVkPublic: 'Leaving Vk Public',
  1685. sendingVkWall: 'Sending Vk Wall',
  1686. deletingVkWall: 'Deleting Vk Wall',
  1687. youtubeChannel: 'YouTube Channel',
  1688. likes: 'Like',
  1689. loginYtb: 'Please <a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">log in to YouTube</a>',
  1690. tryUpdateYtbAuth: 'Please try to <a href="https://www.youtube.com/#auth" target="_blank">update YouTube token</a>',
  1691. gettingYtbToken: 'Getting YouTube Token...',
  1692. followingYtbChannel: 'Subscribing to YouTube channel',
  1693. unfollowingYtbChannel: 'Unsubscribing to YouTube channel',
  1694. likingYtbVideo: 'Liking YouTube video',
  1695. unlikingYtbVideo: 'Unliking YouTube video',
  1696. giveKeyNoticeBefore: 'Each verification interval is 15s',
  1697. giveKeyNoticeAfter: 'If there is no key, please check at <a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>',
  1698. noPoints: 'Not enough points, skip the lottery',
  1699. getNeedPointsFailed: 'ailed to obtain the required points, skip the lottery',
  1700. joiningLottery: 'Joining the lottery',
  1701. doingGleamTask: 'Doing Gleam Task...',
  1702. gettingGleamLink: 'Getting Gleam task link...',
  1703. gleamTaskNotice: 'If this page has not been closed for a long time, please close it yourself after completing any task!',
  1704. verifiedGleamTasks: 'Attempted to verify all tasks. If the verification fails, please try to verify manually or complete it!',
  1705. campaign: 'ReCAPTCHA detected, please complete it and re-verify the tasks!',
  1706. 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!',
  1707. giveeClubVerifyNotice: 'Verifying task...',
  1708. giveeClubVerifyFinished: 'Wait for the verification to complete and join it by yourself',
  1709. doingKeyhubTask: 'Doing Keyhub Task...',
  1710. 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...',
  1711. tasksNotCompleted: 'Tasks Not Completed',
  1712. confirmingTask: 'Confirming task...'
  1713. };
  1714. const en_US = en_US_data;
  1715. const languages = {
  1716. zh: zh_CN,
  1717. en: en_US
  1718. };
  1719. const language = [ 'zh', 'en' ].includes(globalOptions.other.language) ? globalOptions.other.language : 'en';
  1720. const I18n = (key, ...argvs) => {
  1721. if (!languages[language]?.[key]) {
  1722. return key;
  1723. }
  1724. return languages[language][key].replace(/%([\d]+)/g, (match, index) => argvs[parseInt(index, 10)]);
  1725. };
  1726. const i18n = I18n;
  1727. function throwError(error, name) {
  1728. if (window.TRACE) {
  1729. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  1730. }
  1731. external_Swal_default().fire({
  1732. title: i18n('errorReport'),
  1733. icon: 'error',
  1734. showCancelButton: true,
  1735. confirmButtonText: i18n('toGithub'),
  1736. showDenyButton: true,
  1737. denyButtonText: i18n('toKeylol'),
  1738. cancelButtonText: i18n('close')
  1739. }).then(({
  1740. isDenied,
  1741. isConfirmed
  1742. }) => {
  1743. if (isConfirmed) {
  1744. window.open(`https://github.com/HCLonely/auto-task-v4/issues/new?title=${encodeURIComponent(`[BUG] 脚本报错: ${name}`)}&labels=bug&template=bug_report.yml&website=${encodeURIComponent(window.location.href)}&browser=${encodeURIComponent(JSON.stringify((0,
  1745. javascript_utils_umd_min.ua)(), null, 4))}&manager=${encodeURIComponent(`${GM_info.scriptHandler} ${GM_info.version}`)}&user-script=${encodeURIComponent(GM_info.script.version)}&logs=${encodeURIComponent(error.stack || 'null')}&run-logs=${encodeURIComponent($.makeArray($('#auto-task-info>li')).map(element => element.innerText).join('\n'))}`, '_blank');
  1746. } else if (isDenied) {
  1747. const text = `错误链接: [url=${window.location.href}]${window.location.href}[/url]
  1748.  
  1749. 环境:
  1750.  
  1751. [code]${JSON.stringify((0, javascript_utils_umd_min.ua)(), null, 4)}[/code]
  1752.  
  1753. 脚本管理器: ${GM_info.scriptHandler} ${GM_info.version}
  1754. 脚本版本: ${GM_info.script.version}
  1755.  
  1756. 报错信息:
  1757. [code]${error.stack}[/code]
  1758.  
  1759. 执行日志:
  1760. [code]${$.makeArray($('#auto-task-info>li')).map(element => element.innerText).join('\n')}[/code]`;
  1761. GM_setClipboard(text);
  1762. external_Swal_default().fire({
  1763. title: i18n('copySuccess'),
  1764. icon: 'success',
  1765. confirmButtonText: i18n('ok')
  1766. }).then(() => {
  1767. window.open('https://keylol.com/forum.php?mod=post&action=reply&fid=319&tid=777450', '_blank');
  1768. });
  1769. }
  1770. });
  1771. console.log('%c%s', 'color:white;background:red', `Auto-Task[Error]: ${name}\n${error.stack}`);
  1772. }
  1773. class Social {
  1774. tasks;
  1775. getRealParams(name, links, doTask, link2param) {
  1776. try {
  1777. let realParams = [];
  1778. if (links.length > 0) {
  1779. realParams = [ ...realParams, ...links.map(link => link2param(link)).filter(link => link) ];
  1780. }
  1781. if (!doTask && this.tasks[name].length > 0) {
  1782. realParams = [ ...realParams, ...this.tasks[name] ];
  1783. }
  1784. return unique(realParams);
  1785. } catch (error) {
  1786. throwError(error, 'Social.getRealParams');
  1787. return [];
  1788. }
  1789. }
  1790. }
  1791. const social_Social = Social;
  1792. class Discord extends social_Social {
  1793. tasks;
  1794. whiteList;
  1795. #auth = GM_getValue('discordAuth') || {};
  1796. #cache = GM_getValue('discordCache') || {};
  1797. #initialized = false;
  1798. constructor() {
  1799. super();
  1800. const defaultTasksTemplate = {
  1801. servers: []
  1802. };
  1803. this.tasks = defaultTasksTemplate;
  1804. this.whiteList = {
  1805. ...defaultTasksTemplate,
  1806. ...GM_getValue('whiteList')?.discord || {}
  1807. };
  1808. }
  1809. async init(action) {
  1810. try {
  1811. if (!GM_getValue('dontRemindDiscordAgain')) {
  1812. const result = await external_Swal_default().fire({
  1813. title: i18n('discordImportantNotice'),
  1814. text: i18n('discordImportantNoticeText'),
  1815. showCancelButton: true,
  1816. showDenyButton: true,
  1817. confirmButtonText: i18n('continue'),
  1818. cancelButtonText: i18n('skipDiscordTask'),
  1819. denyButtonText: i18n('continueAndDontRemindAgain')
  1820. }).then(({
  1821. isConfirmed,
  1822. isDenied
  1823. }) => {
  1824. if (isConfirmed) {
  1825. return true;
  1826. }
  1827. if (isDenied) {
  1828. GM_setValue('dontRemindDiscordAgain', true);
  1829. return true;
  1830. }
  1831. return false;
  1832. });
  1833. if (!result) {
  1834. this.#initialized = false;
  1835. return 'skip';
  1836. }
  1837. }
  1838. if (GM_getValue('dontRemindDiscordAgain') || action === 'do' && !globalOptions.doTask.discord.servers || action === 'undo' && !globalOptions.undoTask.discord.servers) {
  1839. this.#initialized = false;
  1840. return 'skip';
  1841. }
  1842. if (this.#initialized) {
  1843. return true;
  1844. }
  1845. if (!this.#auth.auth) {
  1846. if (await this.#updateAuth()) {
  1847. this.#initialized = true;
  1848. return true;
  1849. }
  1850. return false;
  1851. }
  1852. const isVerified = await this.#verifyAuth();
  1853. if (isVerified) {
  1854. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1855. this.#initialized = true;
  1856. return true;
  1857. }
  1858. GM_setValue('discordAuth', {
  1859. auth: null
  1860. });
  1861. if (await this.#updateAuth()) {
  1862. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1863. this.#initialized = true;
  1864. return true;
  1865. }
  1866. scripts_echoLog({}).error(i18n('initFailed', 'Discord'));
  1867. return false;
  1868. } catch (error) {
  1869. throwError(error, 'Discord.init');
  1870. return false;
  1871. }
  1872. }
  1873. async #verifyAuth() {
  1874. try {
  1875. const logStatus = scripts_echoLog({
  1876. text: i18n('verifyingAuth', 'Discord')
  1877. });
  1878. const {
  1879. result,
  1880. statusText,
  1881. status,
  1882. data
  1883. } = await tools_httpRequest({
  1884. url: 'https://discord.com/api/v6/users/@me',
  1885. method: 'HEAD',
  1886. headers: {
  1887. authorization: this.#auth.auth
  1888. }
  1889. });
  1890. if (result === 'Success') {
  1891. if (data?.status === 200) {
  1892. logStatus.success();
  1893. return true;
  1894. }
  1895. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  1896. return false;
  1897. }
  1898. logStatus.error(`${result}:${statusText}(${status})`);
  1899. return false;
  1900. } catch (error) {
  1901. throwError(error, 'Discord.verifyAuth');
  1902. return false;
  1903. }
  1904. }
  1905. async #updateAuth() {
  1906. try {
  1907. const logStatus = scripts_echoLog({
  1908. text: i18n('updatingAuth', 'Discord')
  1909. });
  1910. return await new Promise(resolve => {
  1911. const newTab = GM_openInTab('https://discord.com/channels/@me#auth', {
  1912. active: true,
  1913. insert: true,
  1914. setParent: true
  1915. });
  1916. newTab.onclose = async () => {
  1917. const auth = GM_getValue('discordAuth')?.auth;
  1918. if (auth) {
  1919. this.#auth = {
  1920. auth: auth
  1921. };
  1922. logStatus.success();
  1923. resolve(await this.#verifyAuth());
  1924. } else {
  1925. logStatus.error('Error: Update discord auth failed!');
  1926. resolve(false);
  1927. }
  1928. };
  1929. });
  1930. } catch (error) {
  1931. throwError(error, 'Discord.updateAuth');
  1932. return false;
  1933. }
  1934. }
  1935. async #joinServer(inviteId) {
  1936. try {
  1937. const logStatus = scripts_echoLog({
  1938. type: 'joiningDiscordServer',
  1939. text: inviteId
  1940. });
  1941. const {
  1942. result,
  1943. statusText,
  1944. status,
  1945. data
  1946. } = await tools_httpRequest({
  1947. url: `https://discord.com/api/v9/invites/${inviteId}`,
  1948. method: 'POST',
  1949. dataType: 'json',
  1950. headers: {
  1951. authorization: this.#auth.auth,
  1952. origin: 'https://discord.com',
  1953. referer: `https://discord.com/invite/${inviteId}`
  1954. }
  1955. });
  1956. if (result === 'Success' && data?.status === 200) {
  1957. logStatus.success();
  1958. const guild = String(data.response?.guild?.id);
  1959. if (guild) {
  1960. this.#setCache(inviteId, guild);
  1961. this.tasks.servers = unique([ ...this.tasks.servers, inviteId ]);
  1962. }
  1963. return true;
  1964. }
  1965. logStatus.error(`${result}:${statusText}(${status})`);
  1966. return false;
  1967. } catch (error) {
  1968. throwError(error, 'Discord.joinServer');
  1969. return false;
  1970. }
  1971. }
  1972. async #leaveServer(inviteId) {
  1973. try {
  1974. if (this.whiteList.servers.includes(inviteId)) {
  1975. scripts_echoLog({
  1976. type: 'whiteList',
  1977. text: 'Discord.leaveServer',
  1978. id: inviteId
  1979. });
  1980. return true;
  1981. }
  1982. const guild = await this.#getGuild(inviteId);
  1983. if (!guild) {
  1984. return false;
  1985. }
  1986. const logStatus = scripts_echoLog({
  1987. type: 'leavingDiscordServer',
  1988. text: guild
  1989. });
  1990. const {
  1991. result,
  1992. statusText,
  1993. status,
  1994. data
  1995. } = await tools_httpRequest({
  1996. url: `https://discord.com/api/v9/users/@me/guilds/${guild}`,
  1997. method: 'DELETE',
  1998. headers: {
  1999. authorization: this.#auth.auth
  2000. }
  2001. });
  2002. if (result === 'Success' && data?.status === 204) {
  2003. logStatus.success();
  2004. return true;
  2005. }
  2006. logStatus.error(`${result}:${statusText}(${status})`);
  2007. return false;
  2008. } catch (error) {
  2009. throwError(error, 'Discord.leaveServer');
  2010. return false;
  2011. }
  2012. }
  2013. async #getGuild(inviteId) {
  2014. try {
  2015. const logStatus = scripts_echoLog({
  2016. type: 'gettingDiscordGuild',
  2017. text: inviteId
  2018. });
  2019. const guild = this.#cache[inviteId];
  2020. if (guild) {
  2021. logStatus.success();
  2022. return guild;
  2023. }
  2024. const {
  2025. result,
  2026. statusText,
  2027. status,
  2028. data
  2029. } = await tools_httpRequest({
  2030. url: `https://discord.com/api/v9/invites/${inviteId}`,
  2031. responseType: 'json',
  2032. method: 'GET'
  2033. });
  2034. if (result === 'Success' && data?.status === 200) {
  2035. const guild = data.response?.guild?.id;
  2036. if (guild) {
  2037. logStatus.success();
  2038. this.#setCache(inviteId, guild);
  2039. return guild;
  2040. }
  2041. logStatus.error(`${result}:${statusText}(${status})`);
  2042. return false;
  2043. }
  2044. logStatus.error(`${result}:${statusText}(${status})`);
  2045. return false;
  2046. } catch (error) {
  2047. throwError(error, 'Discord.getGuild');
  2048. return false;
  2049. }
  2050. }
  2051. async toggle({
  2052. doTask = true,
  2053. serverLinks = []
  2054. }) {
  2055. try {
  2056. if (!this.#initialized) {
  2057. scripts_echoLog({
  2058. text: i18n('needInit')
  2059. });
  2060. return false;
  2061. }
  2062. const prom = [];
  2063. if (doTask && !globalOptions.doTask.discord.servers || !doTask && !globalOptions.undoTask.discord.servers) {
  2064. scripts_echoLog({
  2065. type: 'globalOptionsSkip',
  2066. text: 'discord.servers'
  2067. });
  2068. } else {
  2069. const realServers = this.getRealParams('servers', serverLinks, doTask, link => link.match(/invite\/(.+)/)?.[1]);
  2070. if (realServers.length > 0) {
  2071. for (const server of realServers) {
  2072. if (doTask) {
  2073. prom.push(this.#joinServer(server));
  2074. } else {
  2075. prom.push(this.#leaveServer(server));
  2076. }
  2077. await delay(1e3);
  2078. }
  2079. }
  2080. }
  2081. return await Promise.all(prom).then(() => true);
  2082. } catch (error) {
  2083. throwError(error, 'Discord.toggleServers');
  2084. return false;
  2085. }
  2086. }
  2087. #setCache(inviteId, guild) {
  2088. try {
  2089. this.#cache[inviteId] = guild;
  2090. GM_setValue('discordCache', this.#cache);
  2091. } catch (error) {
  2092. throwError(error, 'Discord.setCache');
  2093. }
  2094. }
  2095. }
  2096. const social_Discord = Discord;
  2097. class Instagram extends social_Social {
  2098. tasks;
  2099. whiteList;
  2100. #cache = GM_getValue('instagramCache') || {};
  2101. #auth = {};
  2102. #initialized = false;
  2103. constructor() {
  2104. super();
  2105. const defaultTasksTemplate = {
  2106. users: []
  2107. };
  2108. this.tasks = defaultTasksTemplate;
  2109. this.whiteList = {
  2110. ...defaultTasksTemplate,
  2111. ...GM_getValue('whiteList')?.instagram || {}
  2112. };
  2113. }
  2114. async init() {
  2115. try {
  2116. if (this.#initialized) {
  2117. return true;
  2118. }
  2119. const isVerified = await this.#getUserInfo();
  2120. if (isVerified) {
  2121. scripts_echoLog({}).success(i18n('initSuccess', 'Instagram'));
  2122. this.#initialized = true;
  2123. return true;
  2124. }
  2125. scripts_echoLog({}).error(i18n('initFailed', 'Instagram'));
  2126. return false;
  2127. } catch (error) {
  2128. throwError(error, 'Instagram.init');
  2129. return false;
  2130. }
  2131. }
  2132. async #getUserInfo(name = 'instagram') {
  2133. try {
  2134. const logStatus = scripts_echoLog({
  2135. type: name === 'instagram' ? 'verifyingInsAuth' : 'gettingInsUserId',
  2136. text: name
  2137. });
  2138. const userId = this.#cache[name];
  2139. if (userId && name !== 'instagram') {
  2140. logStatus.success();
  2141. return userId;
  2142. }
  2143. const {
  2144. result,
  2145. statusText,
  2146. status,
  2147. data
  2148. } = await tools_httpRequest({
  2149. url: `https://www.instagram.com/${name}/`,
  2150. method: 'GET'
  2151. });
  2152. if (result === 'Success') {
  2153. if (data?.finalUrl.includes('accounts/login')) {
  2154. logStatus.error(`Error:${i18n('loginIns')}`, true);
  2155. return false;
  2156. } else if (data?.finalUrl.includes('www.instagram.com/challenge')) {
  2157. logStatus.error(`Error:${i18n('insBanned')}`);
  2158. return false;
  2159. }
  2160. if (data?.status === 200) {
  2161. const csrftoken = data.responseText.match(/"csrf_token":"(.+?)"/)?.[1];
  2162. const hash = data.responseText.match(/"rollout_hash":"(.+?)"/)?.[1];
  2163. if (name === 'instagram') {
  2164. if (csrftoken && hash) {
  2165. this.#auth = {
  2166. csrftoken: csrftoken,
  2167. hash: hash
  2168. };
  2169. return true;
  2170. }
  2171. return false;
  2172. }
  2173. const id = data.responseText.match(/"profilePage_([\d]+?)"/)?.[1];
  2174. if (id) {
  2175. this.#setCache(name, id);
  2176. logStatus.success();
  2177. return id;
  2178. }
  2179. logStatus.error('Error: Get ins data error!');
  2180. return false;
  2181. }
  2182. logStatus.error(`${result}:${statusText}(${status})`);
  2183. return false;
  2184. }
  2185. return false;
  2186. } catch (error) {
  2187. throwError(error, 'Instagram.getUserInfo');
  2188. return false;
  2189. }
  2190. }
  2191. async #followUser(name) {
  2192. try {
  2193. const id = await this.#getUserInfo(name);
  2194. if (!id) {
  2195. return false;
  2196. }
  2197. const logStatus = scripts_echoLog({
  2198. type: 'followingIns',
  2199. text: name
  2200. });
  2201. const {
  2202. result,
  2203. statusText,
  2204. status,
  2205. data
  2206. } = await tools_httpRequest({
  2207. url: `https://www.instagram.com/web/friendships/${id}/follow/`,
  2208. method: 'POST',
  2209. dataType: 'json',
  2210. headers: {
  2211. 'x-csrftoken': this.#auth.csrftoken,
  2212. origin: 'https://www.instagram.com',
  2213. referer: `https://www.instagram.com/${name}/`,
  2214. 'content-type': 'application/x-www-form-urlencoded',
  2215. 'sec-fetch-site': 'same-origin',
  2216. 'x-instagram-ajax': this.#auth.hash
  2217. }
  2218. });
  2219. if (result === 'Success') {
  2220. if (data?.status === 200 && data.response?.result === 'following') {
  2221. logStatus.success();
  2222. this.tasks.users = unique([ ...this.tasks.users, name ]);
  2223. return true;
  2224. }
  2225. logStatus.error(`Error:${data?.response?.feedback_message || `${data?.statusText}(${data?.status})`}`);
  2226. return false;
  2227. }
  2228. logStatus.error(`${result}:${statusText}(${status})`);
  2229. return false;
  2230. } catch (error) {
  2231. throwError(error, 'Instagram.followUser');
  2232. return false;
  2233. }
  2234. }
  2235. async #unfollowUser(name) {
  2236. try {
  2237. if (this.whiteList.users.includes(name)) {
  2238. scripts_echoLog({
  2239. type: 'whiteList',
  2240. text: 'Instagram.unfollowUser',
  2241. id: name
  2242. });
  2243. return true;
  2244. }
  2245. const id = await this.#getUserInfo(name);
  2246. if (!id) {
  2247. return false;
  2248. }
  2249. const logStatus = scripts_echoLog({
  2250. type: 'unfollowingIns',
  2251. text: name
  2252. });
  2253. const {
  2254. result,
  2255. statusText,
  2256. status,
  2257. data
  2258. } = await tools_httpRequest({
  2259. url: `https://www.instagram.com/web/friendships/${id}/unfollow/`,
  2260. method: 'POST',
  2261. dataType: 'json',
  2262. headers: {
  2263. 'x-csrftoken': this.#auth.csrftoken,
  2264. origin: 'https://www.instagram.com',
  2265. referer: `https://www.instagram.com/${name}/`,
  2266. 'content-type': 'application/x-www-form-urlencoded',
  2267. 'sec-fetch-site': 'same-origin',
  2268. 'x-instagram-ajax': this.#auth.hash
  2269. }
  2270. });
  2271. if (result === 'Success') {
  2272. if (data?.status === 200 && data.response?.status === 'ok') {
  2273. logStatus.success();
  2274. return true;
  2275. }
  2276. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2277. return false;
  2278. }
  2279. logStatus.error(`${result}:${statusText}(${status})`);
  2280. return false;
  2281. } catch (error) {
  2282. throwError(error, 'Instagram.unfollowUser');
  2283. return false;
  2284. }
  2285. }
  2286. async toggle({
  2287. doTask = true,
  2288. userLinks = []
  2289. }) {
  2290. try {
  2291. if (!this.#initialized) {
  2292. scripts_echoLog({
  2293. text: i18n('needInit')
  2294. });
  2295. return false;
  2296. }
  2297. const prom = [];
  2298. if (doTask && !globalOptions.doTask.instagram.users || !doTask && !globalOptions.undoTask.instagram.users) {
  2299. scripts_echoLog({
  2300. type: 'globalOptionsSkip',
  2301. text: 'instagram.users'
  2302. });
  2303. } else {
  2304. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1]);
  2305. if (realUsers.length > 0) {
  2306. for (const username of realUsers) {
  2307. if (doTask) {
  2308. prom.push(this.#followUser(username));
  2309. } else {
  2310. prom.push(this.#unfollowUser(username));
  2311. }
  2312. await delay(1e3);
  2313. }
  2314. }
  2315. }
  2316. return await Promise.all(prom).then(() => true);
  2317. } catch (error) {
  2318. throwError(error, 'Instagram.toggleUsers');
  2319. return false;
  2320. }
  2321. }
  2322. #setCache(name, id) {
  2323. try {
  2324. this.#cache[name] = id;
  2325. GM_setValue('instagramCache', this.#cache);
  2326. } catch (error) {
  2327. throwError(error, 'Instagram.setCache');
  2328. }
  2329. }
  2330. }
  2331. const social_Instagram = Instagram;
  2332. class Reddit extends social_Social {
  2333. tasks;
  2334. whiteList;
  2335. #auth;
  2336. #initialized = false;
  2337. constructor() {
  2338. super();
  2339. const defaultTasksTemplate = {
  2340. reddits: []
  2341. };
  2342. this.tasks = defaultTasksTemplate;
  2343. this.whiteList = {
  2344. ...defaultTasksTemplate,
  2345. ...GM_getValue('whiteList')?.reddit || {}
  2346. };
  2347. }
  2348. async init() {
  2349. try {
  2350. if (this.#initialized) {
  2351. return true;
  2352. }
  2353. const isVerified = await this.#updateAuth();
  2354. if (isVerified) {
  2355. scripts_echoLog({}).success(i18n('initSuccess', 'Reddit'));
  2356. this.#initialized = true;
  2357. return true;
  2358. }
  2359. scripts_echoLog({}).error(i18n('initFailed', 'Reddit'));
  2360. return false;
  2361. } catch (error) {
  2362. throwError(error, 'Reddit.init');
  2363. return false;
  2364. }
  2365. }
  2366. async #useBeta() {
  2367. try {
  2368. const logStatus = scripts_echoLog({
  2369. text: i18n('changingRedditVersion')
  2370. });
  2371. GM_setValue('redditAuth', null);
  2372. return await new Promise(resolve => {
  2373. const newTab = GM_openInTab('https://www.reddit.com/#auth', {
  2374. active: true,
  2375. insert: true,
  2376. setParent: true
  2377. });
  2378. newTab.onclose = async () => {
  2379. logStatus.success();
  2380. resolve(await this.#updateAuth(true));
  2381. };
  2382. });
  2383. } catch (error) {
  2384. throwError(error, 'Reddit.useBeta');
  2385. return false;
  2386. }
  2387. }
  2388. async #updateAuth(beta = false) {
  2389. try {
  2390. const logStatus = scripts_echoLog({
  2391. text: i18n('updatingAuth', 'Reddit')
  2392. });
  2393. const {
  2394. result,
  2395. statusText,
  2396. status,
  2397. data
  2398. } = await tools_httpRequest({
  2399. url: 'https://www.reddit.com/',
  2400. method: 'GET',
  2401. nochche: true,
  2402. headers: {
  2403. 'Cache-Control': 'no-cache'
  2404. }
  2405. });
  2406. if (result === 'Success') {
  2407. if (data?.responseText.includes('www.reddit.com/login/')) {
  2408. logStatus.error(`Error:${i18n('loginReddit')}`, true);
  2409. return false;
  2410. }
  2411. if (data?.status === 200) {
  2412. if (data.responseText.includes('redesign-beta-optin-btn') && !beta) {
  2413. return await this.#useBeta();
  2414. }
  2415. const accessToken = data.responseText.match(/"accessToken":"(.*?)","expires":"(.*?)"/)?.[1];
  2416. if (accessToken) {
  2417. this.#auth = {
  2418. token: accessToken
  2419. };
  2420. logStatus.success();
  2421. return true;
  2422. }
  2423. logStatus.error('Error: Parameter "accessToken" not found!');
  2424. return false;
  2425. }
  2426. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2427. return false;
  2428. }
  2429. logStatus.error(`${result}:${statusText}(${status})`);
  2430. return false;
  2431. } catch (error) {
  2432. throwError(error, 'Reddit.updateAuth');
  2433. return false;
  2434. }
  2435. }
  2436. async toggleTask({
  2437. name,
  2438. doTask = true
  2439. }) {
  2440. try {
  2441. if (!doTask && this.whiteList.reddits.includes(name)) {
  2442. scripts_echoLog({
  2443. type: 'whiteList',
  2444. text: 'Reddit.undoTask',
  2445. id: name
  2446. });
  2447. return true;
  2448. }
  2449. let type = doTask ? 'joiningReddit' : 'leavingReddit';
  2450. if (/^u_/.test(name)) {
  2451. type = doTask ? 'followingRedditUser' : 'unfollowingRedditUser';
  2452. }
  2453. const logStatus = scripts_echoLog({
  2454. type: type,
  2455. text: name
  2456. });
  2457. const {
  2458. result,
  2459. statusText,
  2460. status,
  2461. data
  2462. } = await tools_httpRequest({
  2463. url: 'https://oauth.reddit.com/api/subscribe?redditWebClient=desktop2x&app=desktop2x-client-production&raw_json=1&gilding_detail=1',
  2464. method: 'POST',
  2465. headers: {
  2466. authorization: `Bearer ${this.#auth.token}`,
  2467. 'content-type': 'application/x-www-form-urlencoded'
  2468. },
  2469. data: $.param({
  2470. action: doTask ? 'sub' : 'unsub',
  2471. sr_name: name,
  2472. api_type: 'json'
  2473. })
  2474. });
  2475. if (result === 'Success') {
  2476. if (data?.status === 200) {
  2477. logStatus.success();
  2478. if (doTask) {
  2479. this.tasks.reddits = unique([ ...this.tasks.reddits, name ]);
  2480. }
  2481. return true;
  2482. }
  2483. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2484. return false;
  2485. }
  2486. logStatus.error(`${result}:${statusText}(${status})`);
  2487. return false;
  2488. } catch (error) {
  2489. throwError(error, 'Reddit.toggleTask');
  2490. return false;
  2491. }
  2492. }
  2493. async toggle({
  2494. doTask = true,
  2495. redditLinks = []
  2496. }) {
  2497. try {
  2498. if (!this.#initialized) {
  2499. scripts_echoLog({
  2500. text: i18n('needInit')
  2501. });
  2502. return false;
  2503. }
  2504. const prom = [];
  2505. if (doTask && !globalOptions.doTask.reddit.reddits || !doTask && !globalOptions.undoTask.reddit.reddits) {
  2506. scripts_echoLog({
  2507. type: 'globalOptionsSkip',
  2508. text: 'reddit.reddits'
  2509. });
  2510. } else {
  2511. const realReddits = this.getRealParams('reddits', redditLinks, doTask, link => {
  2512. const name = link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1];
  2513. const userName = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1];
  2514. if (userName) {
  2515. return name || userName;
  2516. }
  2517. return name;
  2518. });
  2519. if (realReddits.length > 0) {
  2520. for (const name of realReddits) {
  2521. prom.push(this.toggleTask({
  2522. name: name,
  2523. doTask: doTask
  2524. }));
  2525. await delay(1e3);
  2526. }
  2527. }
  2528. }
  2529. return await Promise.all(prom).then(() => true);
  2530. } catch (error) {
  2531. throwError(error, 'Reddit.toggle');
  2532. return false;
  2533. }
  2534. }
  2535. }
  2536. const social_Reddit = Reddit;
  2537. class Twitch extends social_Social {
  2538. tasks;
  2539. whiteList;
  2540. #auth = GM_getValue('twitchAuth') || {};
  2541. #cache = GM_getValue('twitchCache') || {};
  2542. #initialized = false;
  2543. #integrityToken;
  2544. constructor() {
  2545. super();
  2546. const defaultTasksTemplate = {
  2547. channels: []
  2548. };
  2549. this.tasks = defaultTasksTemplate;
  2550. this.whiteList = {
  2551. ...defaultTasksTemplate,
  2552. ...GM_getValue('whiteList')?.twitch || {}
  2553. };
  2554. }
  2555. async init() {
  2556. try {
  2557. if (this.#initialized) {
  2558. return true;
  2559. }
  2560. if (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId) {
  2561. if (await this.#updateAuth()) {
  2562. this.#initialized = true;
  2563. return true;
  2564. }
  2565. return false;
  2566. }
  2567. const isVerified = await this.#verifyAuth(true);
  2568. if (isVerified) {
  2569. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2570. this.#initialized = true;
  2571. return true;
  2572. }
  2573. GM_setValue('twitchAuth', null);
  2574. if (await this.#updateAuth()) {
  2575. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2576. this.#initialized = true;
  2577. return true;
  2578. }
  2579. scripts_echoLog({}).error(i18n('initFailed', 'Twitch'));
  2580. return false;
  2581. } catch (error) {
  2582. throwError(error, 'Twitch.init');
  2583. return false;
  2584. }
  2585. }
  2586. async #verifyAuth(isFirst) {
  2587. try {
  2588. const logStatus = scripts_echoLog({
  2589. text: i18n('verifyingAuth', 'Twitch')
  2590. });
  2591. const {
  2592. result,
  2593. statusText,
  2594. status,
  2595. data
  2596. } = await tools_httpRequest({
  2597. url: 'https://gql.twitch.tv/gql',
  2598. method: 'POST',
  2599. dataType: 'json',
  2600. headers: {
  2601. Authorization: `OAuth ${this.#auth.authToken}`,
  2602. 'Client-Id': this.#auth.clientId
  2603. },
  2604. data: '[{"operationName":"FrontPageNew_User","variables":{"limit":1},"extensions":{"persistedQuery":{"version":1,' + '"sha256Hash":"64bd07a2cbaca80699d62636d966cf6395a5d14a1f0a14282067dcb28b13eb11"}}}]'
  2605. });
  2606. if (result === 'Success') {
  2607. if (data?.status === 200 && data.response?.[0]?.data?.currentUser) {
  2608. await this.#integrity(isFirst);
  2609. logStatus.success();
  2610. return true;
  2611. }
  2612. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2613. return false;
  2614. }
  2615. logStatus.error(`${result}:${statusText}(${status})`);
  2616. return false;
  2617. } catch (error) {
  2618. throwError(error, 'Twitch.verifyAuth');
  2619. return false;
  2620. }
  2621. }
  2622. async #integrity(isFirst = true, ct = '') {
  2623. try {
  2624. const logStatus = scripts_echoLog({
  2625. text: i18n('checkingTwitchIntegrity')
  2626. });
  2627. if (isFirst && (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId)) {
  2628. return await this.#updateAuth(false);
  2629. }
  2630. const {
  2631. result,
  2632. statusText,
  2633. status,
  2634. data
  2635. } = await tools_httpRequest({
  2636. url: 'https://gql.twitch.tv/integrity',
  2637. method: 'POST',
  2638. dataType: 'json',
  2639. anonymous: true,
  2640. headers: {
  2641. Origin: 'https://www.twitch.tv',
  2642. Referer: 'https://www.twitch.tv/',
  2643. Authorization: `OAuth ${this.#auth.authToken}`,
  2644. 'Client-Id': this.#auth.clientId,
  2645. 'Client-Version': this.#auth.clientVersion,
  2646. 'X-Device-Id': this.#auth.deviceId,
  2647. 'Client-Session-Id': this.#auth.clientSessionId,
  2648. 'x-kpsdk-ct': ct
  2649. }
  2650. });
  2651. if (result === 'Success') {
  2652. if (!ct && data?.responseHeaders?.['x-kpsdk-ct']) {
  2653. return await this.#integrity(isFirst, data.responseHeaders['x-kpsdk-ct']);
  2654. }
  2655. if (data?.status === 200 && data.response?.token) {
  2656. this.#integrityToken = data.response.token;
  2657. logStatus.success();
  2658. return true;
  2659. }
  2660. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2661. return false;
  2662. }
  2663. logStatus.error(`${result}:${statusText}(${status})`);
  2664. return false;
  2665. } catch (error) {
  2666. throwError(error, 'Twitch.integrity');
  2667. return false;
  2668. }
  2669. }
  2670. async #updateAuth(isFirst = true) {
  2671. try {
  2672. const logStatus = scripts_echoLog({
  2673. text: i18n('updatingAuth', 'Twitch')
  2674. });
  2675. return await new Promise(resolve => {
  2676. const newTab = GM_openInTab('https://www.twitch.tv/#auth', {
  2677. active: true,
  2678. insert: true,
  2679. setParent: true
  2680. });
  2681. newTab.onclose = async () => {
  2682. const auth = GM_getValue('twitchAuth');
  2683. if (auth) {
  2684. this.#auth = auth;
  2685. logStatus.success();
  2686. resolve(await this.#verifyAuth(isFirst));
  2687. } else {
  2688. logStatus.error('Error: Update twitch auth failed!');
  2689. resolve(false);
  2690. }
  2691. };
  2692. });
  2693. } catch (error) {
  2694. throwError(error, 'Twitch.updateAuth');
  2695. return false;
  2696. }
  2697. }
  2698. async #toggleChannel({
  2699. name,
  2700. doTask = true
  2701. }) {
  2702. try {
  2703. if (!doTask && this.whiteList.channels.includes(name)) {
  2704. scripts_echoLog({
  2705. type: 'whiteList',
  2706. text: 'Twitch.unfollowChannel',
  2707. id: name
  2708. });
  2709. return true;
  2710. }
  2711. const channelId = await this.#getChannelId(name);
  2712. if (!channelId) {
  2713. return false;
  2714. }
  2715. const logStatus = scripts_echoLog({
  2716. type: `${doTask ? '' : 'un'}followingTwitchChannel`,
  2717. text: name
  2718. });
  2719. const followData = `[{"operationName":"FollowButton_FollowUser","variables":{"input":{"disableNotifications":false,"targetID":"${channelId}` + '"}},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"800e7346bdf7e5278a3c1d3f21b2b56e2639928f86815677a7126b093b2fdd08"}}}]';
  2720. const unfollowData = `[{"operationName":"FollowButton_UnfollowUser","variables":{"input":{"targetID":"${channelId}"}},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"f7dae976ebf41c755ae2d758546bfd176b4eeb856656098bb40e0a672ca0d880"}}}]';
  2721. const {
  2722. result,
  2723. statusText,
  2724. status,
  2725. data
  2726. } = await tools_httpRequest({
  2727. url: 'https://gql.twitch.tv/gql',
  2728. method: 'POST',
  2729. dataType: 'json',
  2730. anonymous: true,
  2731. headers: {
  2732. Origin: 'https://www.twitch.tv',
  2733. Referer: 'https://www.twitch.tv/',
  2734. Authorization: `OAuth ${this.#auth.authToken}`,
  2735. 'Client-Id': this.#auth.clientId,
  2736. 'Client-Version': this.#auth.clientVersion,
  2737. 'X-Device-Id': this.#auth.deviceId,
  2738. 'Client-Session-Id': this.#auth.clientSessionId,
  2739. 'Client-Integrity': this.#integrityToken
  2740. },
  2741. data: doTask ? followData : unfollowData
  2742. });
  2743. if (result === 'Success') {
  2744. if (data?.status === 200 && data.response?.[0] && !data.response[0].errors) {
  2745. logStatus.success();
  2746. if (doTask) {
  2747. this.tasks.channels = unique([ ...this.tasks.channels, name ]);
  2748. }
  2749. return true;
  2750. }
  2751. logStatus.error(`Error:${data?.response?.[0].errors?.[0]?.message || `${data?.statusText}(${data?.status})`}`);
  2752. return false;
  2753. }
  2754. logStatus.error(`${result}:${statusText}(${status})`);
  2755. return false;
  2756. } catch (error) {
  2757. throwError(error, 'Twitch.toggleChannel');
  2758. return false;
  2759. }
  2760. }
  2761. async #getChannelId(name) {
  2762. try {
  2763. const logStatus = scripts_echoLog({
  2764. type: 'gettingTwitchChannelId',
  2765. text: name
  2766. });
  2767. const channelId = this.#cache[name];
  2768. if (channelId) {
  2769. logStatus.success();
  2770. return channelId;
  2771. }
  2772. const {
  2773. result,
  2774. statusText,
  2775. status,
  2776. data
  2777. } = await tools_httpRequest({
  2778. url: 'https://gql.twitch.tv/gql',
  2779. method: 'POST',
  2780. headers: {
  2781. Authorization: `OAuth ${this.#auth.authToken}`,
  2782. 'Client-Id': this.#auth.clientId
  2783. },
  2784. responseType: 'json',
  2785. data: `[{"operationName":"ActiveWatchParty","variables":{"channelLogin":"${name}"},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"4a8156c97b19e3a36e081cf6d6ddb5dbf9f9b02ae60e4d2ff26ed70aebc80a30"}}}]'
  2786. });
  2787. if (result === 'Success') {
  2788. if (data?.status === 200) {
  2789. const channelId = data.response?.[0]?.data?.user?.id;
  2790. if (channelId) {
  2791. this.#setCache(name, String(channelId));
  2792. logStatus.success();
  2793. return channelId;
  2794. }
  2795. logStatus.error(`Error:${data.statusText}(${data.status})`);
  2796. return false;
  2797. }
  2798. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2799. return false;
  2800. }
  2801. logStatus.error(`${result}:${statusText}(${status})`);
  2802. return false;
  2803. } catch (error) {
  2804. throwError(error, 'Twitch.getChannelId');
  2805. return false;
  2806. }
  2807. }
  2808. async toggle({
  2809. doTask = true,
  2810. channelLinks = []
  2811. }) {
  2812. try {
  2813. if (!this.#initialized) {
  2814. scripts_echoLog({
  2815. text: i18n('needInit')
  2816. });
  2817. return false;
  2818. }
  2819. const prom = [];
  2820. if (doTask && !globalOptions.doTask.twitch.channels || !doTask && !globalOptions.undoTask.twitch.channels) {
  2821. scripts_echoLog({
  2822. type: 'globalOptionsSkip',
  2823. text: 'twitch.channels'
  2824. });
  2825. } else {
  2826. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2]);
  2827. if (realChannels.length > 0) {
  2828. for (const channel of realChannels) {
  2829. prom.push(this.#toggleChannel({
  2830. name: channel,
  2831. doTask: doTask
  2832. }));
  2833. await delay(1e3);
  2834. }
  2835. }
  2836. }
  2837. return Promise.all(prom).then(() => true);
  2838. } catch (error) {
  2839. throwError(error, 'Twitch.toggle');
  2840. return false;
  2841. }
  2842. }
  2843. #setCache(name, id) {
  2844. try {
  2845. this.#cache[name] = id;
  2846. GM_setValue('twitchCache', this.#cache);
  2847. } catch (error) {
  2848. throwError(error, 'Twitch.setCache');
  2849. }
  2850. }
  2851. }
  2852. const social_Twitch = Twitch;
  2853. class Twitter extends social_Social {
  2854. tasks;
  2855. whiteList;
  2856. #verifyId = globalOptions.other.twitterVerifyId;
  2857. #auth = GM_getValue('twitterAuth') || {};
  2858. #cache = GM_getValue('twitterCache') || {};
  2859. #initialized = false;
  2860. constructor() {
  2861. super();
  2862. const defaultTasksTemplate = {
  2863. users: [],
  2864. retweets: [],
  2865. likes: []
  2866. };
  2867. this.tasks = defaultTasksTemplate;
  2868. this.whiteList = {
  2869. ...defaultTasksTemplate,
  2870. ...GM_getValue('whiteList')?.twitter || {}
  2871. };
  2872. }
  2873. async init() {
  2874. try {
  2875. if (this.#initialized) {
  2876. return true;
  2877. }
  2878. if (!this.#auth.ct0) {
  2879. if (await this.#updateAuth()) {
  2880. this.#initialized = true;
  2881. return true;
  2882. }
  2883. return false;
  2884. }
  2885. const isVerified = await this.#verifyAuth();
  2886. if (isVerified) {
  2887. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2888. this.#initialized = true;
  2889. return true;
  2890. }
  2891. GM_setValue('twitterAuth', null);
  2892. if (await this.#updateAuth()) {
  2893. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2894. this.#initialized = true;
  2895. return true;
  2896. }
  2897. scripts_echoLog({}).error(i18n('initFailed', 'Twitter'));
  2898. return false;
  2899. } catch (error) {
  2900. throwError(error, 'Twitter.init');
  2901. return false;
  2902. }
  2903. }
  2904. async #verifyAuth() {
  2905. try {
  2906. return await this.#toggleUser({
  2907. name: 'verify',
  2908. doTask: true,
  2909. verify: true
  2910. });
  2911. } catch (error) {
  2912. throwError(error, 'Twitter.verifyAuth');
  2913. return false;
  2914. }
  2915. }
  2916. async #updateAuth() {
  2917. try {
  2918. const logStatus = scripts_echoLog({
  2919. text: i18n('updatingAuth', 'Twitter')
  2920. });
  2921. return await new Promise(resolve => {
  2922. GM_cookie.list({
  2923. url: 'https://x.com/settings/account'
  2924. }, async (cookies, error) => {
  2925. if (!error) {
  2926. const [ ct0, isLogin ] = cookies.map(cookie => [ 'ct0', 'twid' ].includes(cookie.name) ? cookie.value : null).filter(cookie => cookie);
  2927. if (isLogin && ct0) {
  2928. GM_setValue('twitterAuth', {
  2929. ct0: ct0
  2930. });
  2931. this.#auth = {
  2932. ct0: ct0
  2933. };
  2934. logStatus.success();
  2935. resolve(await this.#verifyAuth());
  2936. } else {
  2937. logStatus.error(i18n('needLogin'));
  2938. resolve(false);
  2939. }
  2940. } else {
  2941. logStatus.error('Error: Update twitter auth failed!');
  2942. resolve(false);
  2943. }
  2944. });
  2945. });
  2946. } catch (error) {
  2947. throwError(error, 'Twitter.updateToken');
  2948. return false;
  2949. }
  2950. }
  2951. async #toggleUser({
  2952. name,
  2953. doTask = true,
  2954. verify = false
  2955. }) {
  2956. try {
  2957. if (!doTask && !verify && this.whiteList.users.includes(name)) {
  2958. scripts_echoLog({
  2959. type: 'whiteList',
  2960. text: 'Twitter.unfollowUser',
  2961. id: name
  2962. });
  2963. return true;
  2964. }
  2965. const userId = verify ? this.#verifyId : await this.userName2id(name);
  2966. if (!userId) {
  2967. return false;
  2968. }
  2969. const logStatus = verify ? scripts_echoLog({
  2970. text: i18n('verifyingAuth', 'Twitter')
  2971. }) : scripts_echoLog({
  2972. type: `${doTask ? '' : 'un'}followingTwitterUser`,
  2973. text: name
  2974. });
  2975. const {
  2976. result,
  2977. statusText,
  2978. status,
  2979. data
  2980. } = await tools_httpRequest({
  2981. url: `https://x.com/i/api/1.1/friendships/${doTask ? 'create' : 'destroy'}.json`,
  2982. method: 'POST',
  2983. headers: {
  2984. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  2985. 'Content-Type': 'application/x-www-form-urlencoded',
  2986. 'x-csrf-token': this.#auth.ct0
  2987. },
  2988. responseType: 'json',
  2989. data: $.param({
  2990. include_profile_interstitial_type: 1,
  2991. include_blocking: 1,
  2992. include_blocked_by: 1,
  2993. include_followed_by: 1,
  2994. include_want_retweets: 1,
  2995. include_mute_edge: 1,
  2996. include_can_dm: 1,
  2997. include_can_media_tag: 1,
  2998. skip_status: 1,
  2999. id: userId
  3000. })
  3001. });
  3002. if (result === 'Success') {
  3003. if (data?.status === 200) {
  3004. logStatus.success();
  3005. if (doTask && !verify) {
  3006. this.tasks.users = unique([ ...this.tasks.users, name ]);
  3007. }
  3008. return true;
  3009. }
  3010. if (verify && data?.status === 403 && data.response?.errors?.[0]?.code === 158) {
  3011. logStatus.success();
  3012. return true;
  3013. }
  3014. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3015. return false;
  3016. }
  3017. logStatus.error(`${result}:${statusText}(${status})`);
  3018. return false;
  3019. } catch (error) {
  3020. throwError(error, 'Twitter.toggleUser');
  3021. return false;
  3022. }
  3023. }
  3024. async userName2id(name) {
  3025. try {
  3026. const logStatus = scripts_echoLog({
  3027. type: 'gettingTwitterUserId',
  3028. text: name
  3029. });
  3030. const userId = this.#cache[name];
  3031. if (userId) {
  3032. logStatus.success();
  3033. return userId;
  3034. }
  3035. const {
  3036. result,
  3037. statusText,
  3038. status,
  3039. data
  3040. } = await tools_httpRequest({
  3041. 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`,
  3042. method: 'GET',
  3043. headers: {
  3044. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3045. 'content-type': 'application/json',
  3046. referer: `https://x.com/${name}`,
  3047. 'x-csrf-token': this.#auth.ct0
  3048. },
  3049. responseType: 'json'
  3050. });
  3051. if (result === 'Success') {
  3052. if (data?.status === 200) {
  3053. let response = data.response || (typeof data.responseText === 'object' ? data.responseText : null);
  3054. if (!response) {
  3055. try {
  3056. response = JSON.parse(data.responseText);
  3057. } catch (error) {
  3058. response = null;
  3059. }
  3060. }
  3061. const userId = String(response?.data?.user?.result?.rest_id);
  3062. if (userId) {
  3063. this.#setCache(name, userId);
  3064. logStatus.success();
  3065. return userId;
  3066. }
  3067. logStatus.error(`Error:${data.statusText}(${data.status})`);
  3068. return false;
  3069. }
  3070. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3071. return false;
  3072. }
  3073. logStatus.error(`${result}:${statusText}(${status})`);
  3074. return false;
  3075. } catch (error) {
  3076. throwError(error, 'Twitter.getUserId');
  3077. return false;
  3078. }
  3079. }
  3080. async #toggleRetweet({
  3081. retweetId,
  3082. doTask = true
  3083. }) {
  3084. try {
  3085. if (!doTask && this.whiteList.retweets.includes(retweetId)) {
  3086. scripts_echoLog({
  3087. type: 'whiteList',
  3088. text: 'Twitter.unretweet',
  3089. id: retweetId
  3090. });
  3091. return true;
  3092. }
  3093. const logStatus = scripts_echoLog({
  3094. type: `${doTask ? '' : 'un'}retweetting`,
  3095. text: retweetId
  3096. });
  3097. const {
  3098. result,
  3099. statusText,
  3100. status,
  3101. data
  3102. } = await tools_httpRequest({
  3103. url: `https://x.com/i/api/graphql/${doTask ? 'ojPdsZsimiJrUGLR1sjUtA/CreateRetweet' : 'iQtK4dl5hBmXewYZuEOKVw/DeleteRetweet'}`,
  3104. method: 'POST',
  3105. headers: {
  3106. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3107. 'Content-Type': 'application/json',
  3108. 'x-csrf-token': this.#auth.ct0
  3109. },
  3110. data: `{"variables":{"tweet_id":"${retweetId}","dark_request":false},"queryId":"${doTask ? 'ojPdsZsimiJrUGLR1sjUtA' : 'iQtK4dl5hBmXewYZuEOKVw'}"}`,
  3111. responseType: 'json'
  3112. });
  3113. if (result === 'Success') {
  3114. if (data?.status === 200 || data?.status === 403 && data.response?.errors?.[0]?.code === 327) {
  3115. logStatus.success();
  3116. if (doTask) {
  3117. this.tasks.retweets = unique([ ...this.tasks.retweets, retweetId ]);
  3118. }
  3119. return true;
  3120. }
  3121. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3122. return false;
  3123. }
  3124. logStatus.error(`${result}:${statusText}(${status})`);
  3125. return false;
  3126. } catch (error) {
  3127. throwError(error, 'Twitter.toggleRetweet');
  3128. return false;
  3129. }
  3130. }
  3131. async toggle({
  3132. doTask = true,
  3133. userLinks = [],
  3134. retweetLinks = []
  3135. }) {
  3136. try {
  3137. if (!this.#initialized) {
  3138. scripts_echoLog({
  3139. text: i18n('needInit')
  3140. });
  3141. return false;
  3142. }
  3143. const prom = [];
  3144. if (doTask && !globalOptions.doTask.twitter.users || !doTask && !globalOptions.undoTask.twitter.users) {
  3145. scripts_echoLog({
  3146. type: 'globalOptionsSkip',
  3147. text: 'twitter.users'
  3148. });
  3149. } else {
  3150. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/x\.com\/(.+)/)?.[1] || link.match(/https:\/\/twitter\.com\/(.+)/)?.[1]);
  3151. if (realUsers.length > 0) {
  3152. for (const user of realUsers) {
  3153. prom.push(this.#toggleUser({
  3154. name: user,
  3155. doTask: doTask
  3156. }));
  3157. await delay(1e3);
  3158. }
  3159. }
  3160. }
  3161. if (doTask && !globalOptions.doTask.twitter.retweets || !doTask && !globalOptions.undoTask.twitter.retweets) {
  3162. scripts_echoLog({
  3163. type: 'globalOptionsSkip',
  3164. text: 'twitter.retweets'
  3165. });
  3166. } else {
  3167. const realRetweets = this.getRealParams('retweets', retweetLinks, doTask, link => link.match(/https:\/\/x\.com\/.*?\/status\/([\d]+)/)?.[1] || link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1]);
  3168. if (realRetweets.length > 0) {
  3169. for (const retweet of realRetweets) {
  3170. prom.push(this.#toggleRetweet({
  3171. retweetId: retweet,
  3172. doTask: doTask
  3173. }));
  3174. await delay(1e3);
  3175. }
  3176. }
  3177. }
  3178. return Promise.all(prom).then(() => true);
  3179. } catch (error) {
  3180. throwError(error, 'Twitter.toggle');
  3181. return false;
  3182. }
  3183. }
  3184. #setCache(name, id) {
  3185. try {
  3186. this.#cache[name] = id;
  3187. GM_setValue('twitterCache', this.#cache);
  3188. } catch (error) {
  3189. throwError(error, 'Twitter.setCache');
  3190. }
  3191. }
  3192. }
  3193. const social_Twitter = Twitter;
  3194. class Vk extends social_Social {
  3195. tasks;
  3196. whiteList;
  3197. #username = '';
  3198. #cache = GM_getValue('vkCache') || {};
  3199. #initialized = false;
  3200. constructor() {
  3201. super();
  3202. const defaultTasksTemplate = {
  3203. names: []
  3204. };
  3205. this.tasks = defaultTasksTemplate;
  3206. this.whiteList = {
  3207. ...defaultTasksTemplate,
  3208. ...GM_getValue('whiteList')?.vk || {}
  3209. };
  3210. }
  3211. async init() {
  3212. try {
  3213. if (this.#initialized) {
  3214. return true;
  3215. }
  3216. const isVerified = await this.#verifyAuth();
  3217. if (isVerified) {
  3218. scripts_echoLog({}).success(i18n('initSuccess', 'Vk'));
  3219. this.#initialized = true;
  3220. return true;
  3221. }
  3222. scripts_echoLog({}).error(i18n('initFailed', 'Vk'));
  3223. return false;
  3224. } catch (error) {
  3225. throwError(error, 'Vk.init');
  3226. return false;
  3227. }
  3228. }
  3229. async #verifyAuth() {
  3230. try {
  3231. const logStatus = scripts_echoLog({
  3232. text: i18n('verifyAuth', 'Vk')
  3233. });
  3234. const {
  3235. result,
  3236. statusText,
  3237. status,
  3238. data
  3239. } = await tools_httpRequest({
  3240. url: 'https://vk.com/im',
  3241. method: 'GET'
  3242. });
  3243. if (result === 'Success') {
  3244. if (data?.finalUrl.includes('vk.com/login')) {
  3245. logStatus.error(`Error:${i18n('loginVk')}`, true);
  3246. return false;
  3247. }
  3248. if (data?.status === 200) {
  3249. this.#username = data.responseText.match(/TopNavBtn__profileLink" href="\/(.*?)"/)?.[1] || '';
  3250. logStatus.success();
  3251. return true;
  3252. }
  3253. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3254. return false;
  3255. }
  3256. logStatus.error(`${result}:${statusText}(${status})`);
  3257. return false;
  3258. } catch (error) {
  3259. throwError(error, 'Vk.verifyAuth');
  3260. return false;
  3261. }
  3262. }
  3263. async #toggleGroup(name, dataParam, doTask = true) {
  3264. try {
  3265. const logStatus = scripts_echoLog({
  3266. type: doTask ? 'joiningVkGroup' : 'leavingVkGroup',
  3267. text: name
  3268. });
  3269. if (dataParam.groupAct === 'enter' && !doTask || dataParam.groupAct === 'leave' && doTask) {
  3270. logStatus.success();
  3271. return true;
  3272. }
  3273. const reqData = {
  3274. act: doTask ? 'enter' : 'leave',
  3275. al: 1,
  3276. gid: dataParam.groupId,
  3277. hash: dataParam.groupHash
  3278. };
  3279. if (doTask) {
  3280. reqData.context = '_';
  3281. }
  3282. const {
  3283. result,
  3284. statusText,
  3285. status,
  3286. data
  3287. } = await tools_httpRequest({
  3288. url: 'https://vk.com/al_groups.php',
  3289. method: 'POST',
  3290. headers: {
  3291. origin: 'https://vk.com',
  3292. referer: `https://vk.com/${name}`,
  3293. 'content-type': 'application/x-www-form-urlencoded'
  3294. },
  3295. data: $.param(reqData)
  3296. });
  3297. if (result === 'Success') {
  3298. if (data?.status === 200) {
  3299. logStatus.success();
  3300. if (doTask) {
  3301. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3302. }
  3303. return true;
  3304. }
  3305. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3306. return false;
  3307. }
  3308. logStatus.error(`${result}:${statusText}(${status})`);
  3309. return false;
  3310. } catch (error) {
  3311. throwError(error, 'Vk.toggleGroup');
  3312. return false;
  3313. }
  3314. }
  3315. async #togglePublic(name, dataParam, doTask = true) {
  3316. try {
  3317. const logStatus = scripts_echoLog({
  3318. type: doTask ? 'joiningVkPublic' : 'leavingVkPublic',
  3319. text: name
  3320. });
  3321. if (dataParam.publicJoined && doTask || !dataParam.publicJoined && !doTask) {
  3322. logStatus.success();
  3323. return true;
  3324. }
  3325. const {
  3326. result,
  3327. statusText,
  3328. status,
  3329. data
  3330. } = await tools_httpRequest({
  3331. url: 'https://vk.com/al_public.php',
  3332. method: 'POST',
  3333. headers: {
  3334. origin: 'https://vk.com',
  3335. referer: `https://vk.com/${name}`,
  3336. 'content-type': 'application/x-www-form-urlencoded'
  3337. },
  3338. data: $.param({
  3339. act: doTask ? 'a_enter' : 'a_leave',
  3340. al: 1,
  3341. pid: dataParam.publicPid,
  3342. hash: dataParam.publicHash
  3343. })
  3344. });
  3345. if (result === 'Success') {
  3346. if (data?.status === 200) {
  3347. logStatus.success();
  3348. if (doTask) {
  3349. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3350. }
  3351. return true;
  3352. }
  3353. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3354. return false;
  3355. }
  3356. logStatus.error(`${result}:${statusText}(${status})`);
  3357. return false;
  3358. } catch (error) {
  3359. throwError(error, 'Vk.togglePublic');
  3360. return false;
  3361. }
  3362. }
  3363. async #sendWall(name) {
  3364. try {
  3365. const logStatus = scripts_echoLog({
  3366. type: 'sendingVkWall',
  3367. text: name
  3368. });
  3369. const {
  3370. result,
  3371. statusText,
  3372. status,
  3373. data
  3374. } = await tools_httpRequest({
  3375. url: 'https://vk.com/like.php',
  3376. method: 'POST',
  3377. headers: {
  3378. origin: 'https://vk.com',
  3379. referer: `https://vk.com/${name}`,
  3380. 'content-type': 'application/x-www-form-urlencoded'
  3381. },
  3382. data: $.param({
  3383. act: 'publish_box',
  3384. al: 1,
  3385. object: name
  3386. })
  3387. });
  3388. if (result === 'Success') {
  3389. if (data?.status === 200) {
  3390. const hash = data.responseText.match(/shHash:[\s]*'(.*?)'/)?.[1];
  3391. if (hash) {
  3392. const {
  3393. result: resultR,
  3394. statusText: statusTextR,
  3395. status: statusR,
  3396. data: dataR
  3397. } = await tools_httpRequest({
  3398. url: 'https://vk.com/like.php',
  3399. method: 'POST',
  3400. headers: {
  3401. origin: 'https://vk.com',
  3402. referer: `https://vk.com/${name}`,
  3403. 'content-type': 'application/x-www-form-urlencoded'
  3404. },
  3405. data: $.param({
  3406. Message: '',
  3407. act: 'a_do_publish',
  3408. al: 1,
  3409. close_comments: 0,
  3410. friends_only: 0,
  3411. from: 'box',
  3412. hash: hash,
  3413. list: '',
  3414. mark_as_ads: 0,
  3415. mute_notifications: 0,
  3416. object: name,
  3417. ret_data: 1,
  3418. to: 0
  3419. })
  3420. });
  3421. if (resultR === 'Success') {
  3422. if (dataR?.status === 200) {
  3423. const jsonData = JSON.parse(dataR.responseText?.replace('\x3c!--', '') || '{}');
  3424. if (jsonData?.payload?.[1]?.[1]?.share_my === true) {
  3425. logStatus.success();
  3426. const postId = String(jsonData?.payload?.[1]?.[1]?.post_id);
  3427. const ownerId = String(jsonData?.payload?.[1]?.[1]?.owner_id);
  3428. if (postId && ownerId) {
  3429. this.#setCache(name, `${ownerId}_${postId}`);
  3430. }
  3431. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3432. return true;
  3433. }
  3434. }
  3435. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  3436. return false;
  3437. }
  3438. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  3439. return false;
  3440. }
  3441. logStatus.error('Error: Get "hash" failed');
  3442. return false;
  3443. }
  3444. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3445. return false;
  3446. }
  3447. logStatus.error(`${result}:${statusText}(${status})`);
  3448. return false;
  3449. } catch (error) {
  3450. throwError(error, 'Vk.sendWall');
  3451. return false;
  3452. }
  3453. }
  3454. async #deleteWall(name, dataParams) {
  3455. try {
  3456. const logStatus = scripts_echoLog({
  3457. type: 'deletingVkWall',
  3458. text: name
  3459. });
  3460. const {
  3461. result,
  3462. statusText,
  3463. status,
  3464. data
  3465. } = await tools_httpRequest({
  3466. url: 'https://vk.com/al_wall.php?act=delete',
  3467. method: 'POST',
  3468. headers: {
  3469. origin: 'https://vk.com',
  3470. referer: `https://vk.com/${this.#username}?w=wall${this.#cache[name]}%2Fall`,
  3471. 'content-type': 'application/x-www-form-urlencoded'
  3472. },
  3473. data: $.param({
  3474. act: 'delete',
  3475. al: 1,
  3476. confirm: 0,
  3477. from: 'wkview',
  3478. hash: dataParams.wallHash,
  3479. post: this.#cache[name]
  3480. })
  3481. });
  3482. if (result === 'Success') {
  3483. if (data?.status === 200) {
  3484. const jsonData = JSON.parse(data.responseText?.replace('\x3c!--', '') || '{}');
  3485. if (jsonData?.payload?.[1]?.[1]) {
  3486. logStatus.success();
  3487. return true;
  3488. }
  3489. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3490. return false;
  3491. }
  3492. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3493. return false;
  3494. }
  3495. logStatus.error(`${result}:${statusText}(${status})`);
  3496. return false;
  3497. } catch (error) {
  3498. throwError(error, 'Vk.deleteWall');
  3499. return false;
  3500. }
  3501. }
  3502. async #getId(name, doTask) {
  3503. try {
  3504. let url = `https://vk.com/${name}`;
  3505. if (/^wall-/.test(name)) {
  3506. if (doTask) {
  3507. return {
  3508. type: 'sendWall'
  3509. };
  3510. }
  3511. if (!this.#cache[name]) {
  3512. return {
  3513. type: 'unSupport'
  3514. };
  3515. }
  3516. url = `https://vk.com/${this.#username}?w=wall${this.#cache[name]}`;
  3517. }
  3518. const logStatus = scripts_echoLog({
  3519. type: 'gettingVkId',
  3520. text: name
  3521. });
  3522. const {
  3523. result,
  3524. statusText,
  3525. status,
  3526. data
  3527. } = await tools_httpRequest({
  3528. url: url,
  3529. method: 'GET'
  3530. });
  3531. if (result === 'Success') {
  3532. if (data?.status === 200) {
  3533. const [ , groupAct, groupId, , groupHash ] = data.responseText.match(/Groups.(enter|leave)\(.*?,.*?([\d]+?), (&#39;|')(.*?)(&#39;|')/) || [];
  3534. const publicHash = data.responseText.match(/"enterHash":"(.*?)"/)?.[1];
  3535. const publicPid = data.responseText.match(/"public_id":([\d]+?),/)?.[1];
  3536. const publicJoined = !data.responseText.includes('Public.subscribe');
  3537. if (groupAct && groupId && groupHash) {
  3538. logStatus.success();
  3539. return {
  3540. groupAct: groupAct,
  3541. groupId: groupId,
  3542. groupHash: groupHash,
  3543. type: 'group'
  3544. };
  3545. } else if (publicHash && publicPid) {
  3546. logStatus.success();
  3547. return {
  3548. publicHash: publicHash,
  3549. publicPid: publicPid,
  3550. publicJoined: publicJoined,
  3551. type: 'public'
  3552. };
  3553. } else if (data.responseText.includes('wall.deletePost') && !doTask) {
  3554. const wallHash = data.responseText.match(/wall\.deletePost\(this, '.*?', '(.*?)'\)/)?.[1];
  3555. if (wallHash) {
  3556. logStatus.success();
  3557. return {
  3558. type: 'deleteWall',
  3559. wallHash: wallHash
  3560. };
  3561. }
  3562. } else if (name.includes('wall') && doTask) {
  3563. logStatus.success();
  3564. return {
  3565. type: 'sendWall'
  3566. };
  3567. }
  3568. logStatus.error('Error: Parameters not found!');
  3569. return false;
  3570. }
  3571. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3572. return false;
  3573. }
  3574. logStatus.error(`${result}:${statusText}(${status})`);
  3575. return false;
  3576. } catch (error) {
  3577. throwError(error, 'Vk.getId');
  3578. return false;
  3579. }
  3580. }
  3581. async #toggleVk({
  3582. name,
  3583. doTask = true
  3584. }) {
  3585. try {
  3586. if (!doTask && this.whiteList.names.includes(name)) {
  3587. scripts_echoLog({
  3588. type: 'whiteList',
  3589. text: 'Vk.undoTask',
  3590. id: name
  3591. });
  3592. return true;
  3593. }
  3594. const formatName = name.replace(/\/$/, '');
  3595. const data = await this.#getId(formatName, doTask);
  3596. if (!data) {
  3597. return false;
  3598. }
  3599. switch (data.type) {
  3600. case 'group':
  3601. return await this.#toggleGroup(formatName, data, doTask);
  3602.  
  3603. case 'public':
  3604. return await this.#togglePublic(formatName, data, doTask);
  3605.  
  3606. case 'sendWall':
  3607. return doTask ? await this.#sendWall(formatName) : true;
  3608.  
  3609. case 'deleteWall':
  3610. return doTask ? true : await this.#deleteWall(formatName, data);
  3611.  
  3612. default:
  3613. return false;
  3614. }
  3615. } catch (error) {
  3616. throwError(error, 'Vk.toggleVk');
  3617. return false;
  3618. }
  3619. }
  3620. async toggle({
  3621. doTask = true,
  3622. nameLinks = []
  3623. }) {
  3624. try {
  3625. if (!this.#initialized) {
  3626. scripts_echoLog({
  3627. text: i18n('needInit')
  3628. });
  3629. return false;
  3630. }
  3631. const prom = [];
  3632. if (doTask && !globalOptions.doTask.vk.names || !doTask && !globalOptions.undoTask.vk.names) {
  3633. scripts_echoLog({
  3634. type: 'globalOptionsSkip',
  3635. text: 'vk.names'
  3636. });
  3637. } else {
  3638. const realNames = this.getRealParams('names', nameLinks, doTask, link => link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1]);
  3639. if (realNames.length > 0) {
  3640. for (const name of realNames) {
  3641. prom.push(this.#toggleVk({
  3642. name: name,
  3643. doTask: doTask
  3644. }));
  3645. await delay(1e3);
  3646. }
  3647. }
  3648. }
  3649. return Promise.all(prom).then(() => true);
  3650. } catch (error) {
  3651. throwError(error, 'Vk.toggle');
  3652. return false;
  3653. }
  3654. }
  3655. #setCache(name, postId) {
  3656. try {
  3657. this.#cache[name] = postId;
  3658. GM_setValue('vkCache', this.#cache);
  3659. } catch (error) {
  3660. throwError(error, 'Vk.setCache');
  3661. }
  3662. }
  3663. }
  3664. const social_Vk = Vk;
  3665. const getInfo = async function(link, type) {
  3666. try {
  3667. const logStatus = scripts_echoLog({
  3668. text: i18n('gettingYtbToken')
  3669. });
  3670. const {
  3671. result,
  3672. statusText,
  3673. status,
  3674. data
  3675. } = await tools_httpRequest({
  3676. url: link,
  3677. method: 'GET'
  3678. });
  3679. if (result === 'Success') {
  3680. if (data?.status === 200) {
  3681. if (data.responseText.includes('accounts.google.com/ServiceLogin?service=youtube')) {
  3682. logStatus.error(`Error:${i18n('loginYtb')}`, true);
  3683. return {
  3684. needLogin: true
  3685. };
  3686. }
  3687. const apiKey = data.responseText.match(/"INNERTUBE_API_KEY":"(.*?)"/)?.[1];
  3688. const context = (data.responseText.match(/\(\{"INNERTUBE_CONTEXT":([\w\W]*?)\}\)/) || data.responseText.match(/"INNERTUBE_CONTEXT":([\w\W]*?\}),"INNERTUBE/))?.[1] || '{}';
  3689. const {
  3690. client,
  3691. request
  3692. } = JSON.parse(context);
  3693. if (apiKey && client && request) {
  3694. client.hl = 'en';
  3695. if (type === 'channel') {
  3696. const channelId = data.responseText.match(/"channelId":"(.+?)"/)?.[1];
  3697. if (channelId) {
  3698. logStatus.success();
  3699. return {
  3700. params: {
  3701. apiKey: apiKey,
  3702. client: client,
  3703. request: request,
  3704. channelId: channelId
  3705. }
  3706. };
  3707. }
  3708. logStatus.error('Error: Get "channelId" failed!');
  3709. return {};
  3710. } else if (type === 'likeVideo') {
  3711. const videoId = data.responseText.match(/<link rel="shortlinkUrl" href="https:\/\/youtu\.be\/(.*?)">/)?.[1];
  3712. const likeParams = data.responseText.match(/"likeParams":"(.*?)"/)?.[1];
  3713. if (videoId) {
  3714. logStatus.success();
  3715. return {
  3716. params: {
  3717. apiKey: apiKey,
  3718. client: client,
  3719. request: request,
  3720. videoId: videoId,
  3721. likeParams: likeParams
  3722. }
  3723. };
  3724. }
  3725. logStatus.error('Error: Get "videoId" failed!');
  3726. return {};
  3727. }
  3728. logStatus.error('Error: Unknown type');
  3729. return {};
  3730. }
  3731. logStatus.error('Error: Parameter "apiKey" not found!');
  3732. return {};
  3733. }
  3734. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3735. return {};
  3736. }
  3737. logStatus.error(`${result}:${statusText}(${status})`);
  3738. return {};
  3739. } catch (error) {
  3740. throwError(error, 'Youtube.getInfo');
  3741. return {};
  3742. }
  3743. };
  3744. class Youtube extends social_Social {
  3745. tasks;
  3746. whiteList;
  3747. #auth = GM_getValue('youtubeAuth') || {};
  3748. #initialized = false;
  3749. #verifyChannel = `https://www.youtube.com/channel/${globalOptions.other.youtubeVerifyChannel}`;
  3750. constructor() {
  3751. super();
  3752. const defaultTasksTemplate = {
  3753. channels: [],
  3754. likes: []
  3755. };
  3756. this.tasks = defaultTasksTemplate;
  3757. this.whiteList = {
  3758. ...defaultTasksTemplate,
  3759. ...GM_getValue('whiteList')?.youtube || {}
  3760. };
  3761. }
  3762. async init() {
  3763. try {
  3764. if (this.#initialized) {
  3765. return true;
  3766. }
  3767. if (!this.#auth.PAPISID) {
  3768. if (await this.#updateAuth()) {
  3769. this.#initialized = true;
  3770. return true;
  3771. }
  3772. return false;
  3773. }
  3774. const isVerified = await this.#verifyAuth();
  3775. if (isVerified) {
  3776. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3777. this.#initialized = true;
  3778. return true;
  3779. }
  3780. GM_setValue('youtubeAuth', null);
  3781. if (await this.#updateAuth()) {
  3782. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3783. this.#initialized = true;
  3784. return true;
  3785. }
  3786. scripts_echoLog({}).error(i18n('initFailed', 'Youtube'));
  3787. return false;
  3788. } catch (error) {
  3789. throwError(error, 'Youtube.init');
  3790. return false;
  3791. }
  3792. }
  3793. async #verifyAuth() {
  3794. try {
  3795. return await this.#toggleChannel({
  3796. link: this.#verifyChannel,
  3797. doTask: true,
  3798. verify: true
  3799. });
  3800. } catch (error) {
  3801. throwError(error, 'Youtube.verifyAuth');
  3802. return false;
  3803. }
  3804. }
  3805. async #updateAuth() {
  3806. try {
  3807. const logStatus = scripts_echoLog({
  3808. text: i18n('updatingAuth', 'Youtube')
  3809. });
  3810. return await new Promise(resolve => {
  3811. GM_cookie.list({
  3812. url: 'https://www.youtube.com/@YouTube'
  3813. }, async (cookies, error) => {
  3814. if (!error) {
  3815. const PAPISID = cookies.find(cookie => cookie.name === '__Secure-3PAPISID')?.value;
  3816. if (PAPISID) {
  3817. GM_setValue('youtubeAuth', {
  3818. PAPISID: PAPISID
  3819. });
  3820. this.#auth = {
  3821. PAPISID: PAPISID
  3822. };
  3823. logStatus.success();
  3824. resolve(await this.#verifyAuth());
  3825. } else {
  3826. logStatus.error(i18n('needLogin'));
  3827. resolve(false);
  3828. }
  3829. } else {
  3830. logStatus.error('Error: Update youtube auth failed!');
  3831. resolve(false);
  3832. }
  3833. });
  3834. });
  3835. } catch (error) {
  3836. throwError(error, 'Youtube.updateAuth');
  3837. return false;
  3838. }
  3839. }
  3840. #getInfo(link, type) {
  3841. return getInfo(link, type);
  3842. }
  3843. async #toggleChannel({
  3844. link,
  3845. doTask = true,
  3846. verify = false
  3847. }) {
  3848. try {
  3849. const {
  3850. params,
  3851. needLogin
  3852. } = await this.#getInfo(link, 'channel');
  3853. const {
  3854. apiKey,
  3855. client,
  3856. request,
  3857. channelId
  3858. } = params || {};
  3859. if (needLogin) {
  3860. scripts_echoLog({
  3861. html: i18n('loginYtb')
  3862. });
  3863. return false;
  3864. }
  3865. if (!(apiKey && client && request && channelId)) {
  3866. scripts_echoLog({
  3867. text: '"getYtbToken" failed'
  3868. });
  3869. return false;
  3870. }
  3871. if (!doTask && !verify && this.whiteList.channels.includes(channelId)) {
  3872. scripts_echoLog({
  3873. type: 'whiteList',
  3874. text: 'Youtube.unfollowChannel',
  3875. id: channelId
  3876. });
  3877. return true;
  3878. }
  3879. const logStatus = verify ? scripts_echoLog({
  3880. text: i18n('verifyingAuth', 'Youtube')
  3881. }) : scripts_echoLog({
  3882. type: doTask ? 'followingYtbChannel' : 'unfollowingYtbChannel',
  3883. text: channelId
  3884. });
  3885. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3886. const {
  3887. result,
  3888. statusText,
  3889. status,
  3890. data
  3891. } = await tools_httpRequest({
  3892. url: `https://www.youtube.com/youtubei/v1/subscription/${doTask ? '' : 'un'}subscribe?key=${apiKey}&prettyPrint=false`,
  3893. method: 'POST',
  3894. headers: {
  3895. origin: 'https://www.youtube.com',
  3896. referer: `https://www.youtube.com/channel/${channelId}`,
  3897. 'content-type': 'application/json',
  3898. 'x-goog-authuser': '0',
  3899. 'x-goog-visitor-id': client?.visitorData,
  3900. 'x-origin': 'https://www.youtube.com',
  3901. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  3902. },
  3903. data: JSON.stringify({
  3904. context: {
  3905. client: client,
  3906. request: {
  3907. sessionId: request?.sessionId,
  3908. internalExperimentFlags: [],
  3909. consistencyTokenJars: []
  3910. },
  3911. user: {}
  3912. },
  3913. channelIds: [ channelId ],
  3914. params: doTask ? 'EgIIAhgA' : 'CgIIAhgA'
  3915. })
  3916. });
  3917. if (result === 'Success') {
  3918. if (data?.status === 200) {
  3919. if (doTask && (/"subscribed":true/.test(data.responseText) || data.responseText.includes('The subscription already exists')) || !doTask && /"subscribed":false/.test(data.responseText)) {
  3920. logStatus.success();
  3921. if (doTask && !verify) {
  3922. this.tasks.channels = unique([ ...this.tasks.channels, link ]);
  3923. }
  3924. return true;
  3925. }
  3926. if (verify && data.responseText.includes('You may not subscribe to yourself')) {
  3927. logStatus.success();
  3928. return true;
  3929. }
  3930. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  3931. return false;
  3932. }
  3933. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3934. return false;
  3935. }
  3936. logStatus.error(`${result}:${statusText}(${status})`);
  3937. return false;
  3938. } catch (error) {
  3939. throwError(error, 'Youtube.toggleChannel');
  3940. return false;
  3941. }
  3942. }
  3943. async #toggleLikeVideo({
  3944. link,
  3945. doTask = true
  3946. }) {
  3947. try {
  3948. const {
  3949. params,
  3950. needLogin
  3951. } = await this.#getInfo(link, 'likeVideo');
  3952. const {
  3953. apiKey,
  3954. client,
  3955. request,
  3956. videoId,
  3957. likeParams
  3958. } = params || {};
  3959. if (needLogin) {
  3960. scripts_echoLog({
  3961. html: `${i18n('loginYtb')}`
  3962. });
  3963. return false;
  3964. }
  3965. if (!(apiKey && client && request && videoId && likeParams)) {
  3966. scripts_echoLog({
  3967. text: '"getYtbToken" failed'
  3968. });
  3969. return false;
  3970. }
  3971. if (!doTask && this.whiteList.likes.includes(videoId)) {
  3972. scripts_echoLog({
  3973. type: 'whiteList',
  3974. text: 'Youtube.unlikeVideo',
  3975. id: videoId
  3976. });
  3977. return true;
  3978. }
  3979. const logStatus = scripts_echoLog({
  3980. type: doTask ? 'likingYtbVideo' : 'unlikingYtbVideo',
  3981. text: videoId
  3982. });
  3983. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3984. const likeVideoData = {
  3985. context: {
  3986. client: client,
  3987. request: {
  3988. sessionId: request.sessionId,
  3989. internalExperimentFlags: [],
  3990. consistencyTokenJars: []
  3991. },
  3992. user: {}
  3993. },
  3994. target: {
  3995. videoId: videoId
  3996. }
  3997. };
  3998. if (doTask) {
  3999. if (likeParams) {
  4000. likeVideoData.params = likeParams;
  4001. } else {
  4002. logStatus.error('Empty likeParams');
  4003. return false;
  4004. }
  4005. }
  4006. const {
  4007. result,
  4008. statusText,
  4009. status,
  4010. data
  4011. } = await tools_httpRequest({
  4012. url: `https://www.youtube.com/youtubei/v1/like/${doTask ? '' : 'remove'}like?key=${apiKey}`,
  4013. method: 'POST',
  4014. headers: {
  4015. origin: 'https://www.youtube.com',
  4016. referer: `https://www.youtube.com/watch?v=${videoId}`,
  4017. 'content-type': 'application/json',
  4018. 'x-goog-authuser': '0',
  4019. 'x-goog-visitor-id': client.visitorData,
  4020. 'x-origin': 'https://www.youtube.com',
  4021. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  4022. },
  4023. data: JSON.stringify(likeVideoData)
  4024. });
  4025. if (result === 'Success') {
  4026. if (data?.status === 200) {
  4027. if (doTask && data.responseText.includes('Added to Liked videos') || !doTask && (data.responseText.includes('Removed from Liked videos') || data.responseText.includes('Dislike removed'))) {
  4028. logStatus.success();
  4029. if (doTask) {
  4030. this.tasks.likes = unique([ ...this.tasks.likes, link ]);
  4031. }
  4032. return true;
  4033. }
  4034. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  4035. return false;
  4036. }
  4037. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4038. return false;
  4039. }
  4040. logStatus.error(`${result}:${statusText}(${status})`);
  4041. return false;
  4042. } catch (error) {
  4043. throwError(error, 'Youtube.toggleLikeVideo');
  4044. return false;
  4045. }
  4046. }
  4047. async toggle({
  4048. doTask = true,
  4049. channelLinks = [],
  4050. videoLinks = []
  4051. }) {
  4052. try {
  4053. if (!this.#initialized) {
  4054. scripts_echoLog({
  4055. text: i18n('needInit')
  4056. });
  4057. return false;
  4058. }
  4059. const prom = [];
  4060. if (doTask && !globalOptions.doTask.youtube.channels || !doTask && !globalOptions.undoTask.youtube.channels) {
  4061. scripts_echoLog({
  4062. type: 'globalOptionsSkip',
  4063. text: 'youtube.channels'
  4064. });
  4065. } else {
  4066. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => {
  4067. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4068. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4069. }
  4070. return link;
  4071. });
  4072. if (realChannels.length > 0) {
  4073. for (const channel of realChannels) {
  4074. prom.push(this.#toggleChannel({
  4075. link: channel,
  4076. doTask: doTask
  4077. }));
  4078. await delay(1e3);
  4079. }
  4080. }
  4081. }
  4082. if (doTask && !globalOptions.doTask.youtube.likes || !doTask && !globalOptions.undoTask.youtube.likes) {
  4083. scripts_echoLog({
  4084. type: 'globalOptionsSkip',
  4085. text: 'youtube.likes'
  4086. });
  4087. } else {
  4088. const realLikes = this.getRealParams('likes', videoLinks, 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 (realLikes.length > 0) {
  4095. for (const video of realLikes) {
  4096. prom.push(this.#toggleLikeVideo({
  4097. link: video,
  4098. doTask: doTask
  4099. }));
  4100. await delay(1e3);
  4101. }
  4102. }
  4103. }
  4104. return Promise.all(prom).then(() => true);
  4105. } catch (error) {
  4106. throwError(error, 'Youtube.toggle');
  4107. return false;
  4108. }
  4109. }
  4110. }
  4111. class SteamASF {
  4112. #asfOptions;
  4113. #botName = 'asf';
  4114. #groupInfo;
  4115. async init() {
  4116. try {
  4117. const asfCommandsUrl = new URL('/Api/Command/', globalOptions.ASF.AsfIpcUrl);
  4118. this.#asfOptions = {
  4119. url: asfCommandsUrl.href,
  4120. method: 'POST',
  4121. responseType: 'json',
  4122. headers: {
  4123. accept: 'application/json',
  4124. 'Content-Type': 'application/json',
  4125. Host: asfCommandsUrl.host,
  4126. Origin: asfCommandsUrl.origin,
  4127. Referer: asfCommandsUrl.href,
  4128. Authentication: globalOptions.ASF.AsfIpcPassword
  4129. }
  4130. };
  4131. if (globalOptions.ASF.AsfBotname) {
  4132. this.#botName = globalOptions.ASF.AsfBotname;
  4133. }
  4134. const logStatus = scripts_echoLog({
  4135. text: i18n('initingASF')
  4136. });
  4137. const {
  4138. result,
  4139. statusText,
  4140. status,
  4141. data
  4142. } = await tools_httpRequest({
  4143. ...this.#asfOptions,
  4144. data: '{"Command":"!stats"}'
  4145. });
  4146. if (result === 'Success') {
  4147. if (data?.response?.Success === true && data.response.Message === 'OK' && data.response.Result) {
  4148. logStatus.success();
  4149. return true;
  4150. }
  4151. if (data?.response?.Result || data?.response?.Message) {
  4152. logStatus.error(data?.response?.Result || data.response.Message);
  4153. return false;
  4154. }
  4155. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4156. return false;
  4157. }
  4158. logStatus.error(`${result}:${statusText}(${status})`);
  4159. return false;
  4160. } catch (error) {
  4161. throwError(error, 'SteamASF.init');
  4162. return false;
  4163. }
  4164. }
  4165. async joinGroup(groupName) {
  4166. try {
  4167. const logStatus = scripts_echoLog({
  4168. type: 'joiningSteamGroup',
  4169. text: groupName
  4170. });
  4171. const {
  4172. result,
  4173. statusText,
  4174. status,
  4175. data
  4176. } = await tools_httpRequest({
  4177. ...this.#asfOptions,
  4178. data: JSON.stringify({
  4179. Command: `!JOINGROUP ${this.#botName} ${groupName}`
  4180. })
  4181. });
  4182. if (result === 'Success') {
  4183. if (data?.status === 200 && [ '已加入', '已申请', 'Joined', 'Applied', 'Присоединился', 'costs' ].find(text => data.response?.Result?.includes(text))) {
  4184. logStatus.success();
  4185. return true;
  4186. }
  4187. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4188. return false;
  4189. }
  4190. logStatus.error(`${result}:${statusText}(${status})`);
  4191. return false;
  4192. } catch (error) {
  4193. throwError(error, 'SteamASF.joinGroup');
  4194. return false;
  4195. }
  4196. }
  4197. async leaveGroup(groupName) {
  4198. try {
  4199. if (!this.#groupInfo) {
  4200. if (!await this.#getGroupId()) {
  4201. return false;
  4202. }
  4203. }
  4204. const groupId = await this.#groupInfo[groupName];
  4205. if (!groupId) {
  4206. return false;
  4207. }
  4208. const logStatus = scripts_echoLog({
  4209. type: 'leavingSteamGroup',
  4210. text: groupName
  4211. });
  4212. const {
  4213. result,
  4214. statusText,
  4215. status,
  4216. data
  4217. } = await tools_httpRequest({
  4218. ...this.#asfOptions,
  4219. data: JSON.stringify({
  4220. Command: `!LEAVEGROUP ${this.#botName} ${groupId}`
  4221. })
  4222. });
  4223. if (result === 'Success') {
  4224. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4225. logStatus.success();
  4226. return true;
  4227. }
  4228. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4229. return false;
  4230. }
  4231. logStatus.error(`${result}:${statusText}(${status})`);
  4232. return false;
  4233. } catch (error) {
  4234. throwError(error, 'SteamASF.leaveGroup');
  4235. return false;
  4236. }
  4237. }
  4238. async #getGroupId() {
  4239. try {
  4240. const logStatus = scripts_echoLog({
  4241. type: 'gettingSteamGroupId',
  4242. text: 'All'
  4243. });
  4244. const {
  4245. result,
  4246. statusText,
  4247. status,
  4248. data
  4249. } = await tools_httpRequest({
  4250. ...this.#asfOptions,
  4251. data: JSON.stringify({
  4252. Command: `!GROUPLIST ${this.#botName}`
  4253. })
  4254. });
  4255. if (result === 'Success') {
  4256. if (data?.status === 200 && data.response?.Result?.includes('|')) {
  4257. this.#groupInfo = Object.fromEntries(data.response.Result.split('\n').map(line => {
  4258. const [ , name, id ] = line.trim().split('|');
  4259. if (name && id) {
  4260. return [ name, id ];
  4261. }
  4262. return null;
  4263. }).filter(ele => ele));
  4264. logStatus.success();
  4265. return true;
  4266. }
  4267. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4268. return false;
  4269. }
  4270. logStatus.error(`${result}:${statusText}(${status})`);
  4271. return false;
  4272. } catch (error) {
  4273. throwError(error, 'SteamASF.getGroupID');
  4274. return false;
  4275. }
  4276. }
  4277. async addToWishlist(gameId) {
  4278. try {
  4279. const logStatus = scripts_echoLog({
  4280. type: 'addingToWishlist',
  4281. text: gameId
  4282. });
  4283. const {
  4284. result,
  4285. statusText,
  4286. status,
  4287. data
  4288. } = await tools_httpRequest({
  4289. ...this.#asfOptions,
  4290. data: JSON.stringify({
  4291. Command: `!ADDWISHLIST ${this.#botName} ${gameId}`
  4292. })
  4293. });
  4294. if (result === 'Success') {
  4295. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4296. logStatus.success();
  4297. return true;
  4298. }
  4299. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4300. return false;
  4301. }
  4302. logStatus.error(`${result}:${statusText}(${status})`);
  4303. return false;
  4304. } catch (error) {
  4305. throwError(error, 'SteamASF.addToWishlist');
  4306. return false;
  4307. }
  4308. }
  4309. async removeFromWishlist(gameId) {
  4310. try {
  4311. const logStatus = scripts_echoLog({
  4312. type: 'removingFromWishlist',
  4313. text: gameId
  4314. });
  4315. const {
  4316. result,
  4317. statusText,
  4318. status,
  4319. data
  4320. } = await tools_httpRequest({
  4321. ...this.#asfOptions,
  4322. data: JSON.stringify({
  4323. Command: `!REMOVEWISHLIST ${this.#botName} ${gameId}`
  4324. })
  4325. });
  4326. if (result === 'Success') {
  4327. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4328. logStatus.success();
  4329. return true;
  4330. }
  4331. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4332. return false;
  4333. }
  4334. logStatus.error(`${result}:${statusText}(${status})`);
  4335. return false;
  4336. } catch (error) {
  4337. throwError(error, 'SteamASF.removeFromWishlist');
  4338. return false;
  4339. }
  4340. }
  4341. async toggleFollowGame(gameId, doTask) {
  4342. try {
  4343. const logStatus = scripts_echoLog({
  4344. type: `${doTask ? '' : 'un'}followingGame`,
  4345. text: gameId
  4346. });
  4347. const {
  4348. result,
  4349. statusText,
  4350. status,
  4351. data
  4352. } = await tools_httpRequest({
  4353. ...this.#asfOptions,
  4354. data: JSON.stringify({
  4355. Command: `!${doTask ? '' : 'UN'}FOLLOWGAME ${this.#botName} ${gameId}`
  4356. })
  4357. });
  4358. if (result === 'Success') {
  4359. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4360. logStatus.success();
  4361. return true;
  4362. }
  4363. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4364. return false;
  4365. }
  4366. logStatus.error(`${result}:${statusText}(${status})`);
  4367. return false;
  4368. } catch (error) {
  4369. throwError(error, 'SteamASF.toggleFollowGame');
  4370. return false;
  4371. }
  4372. }
  4373. async toggleCurator(curatorId, doTask = true) {
  4374. try {
  4375. const logStatus = scripts_echoLog({
  4376. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  4377. text: curatorId
  4378. });
  4379. const {
  4380. result,
  4381. statusText,
  4382. status,
  4383. data
  4384. } = await tools_httpRequest({
  4385. ...this.#asfOptions,
  4386. data: JSON.stringify({
  4387. Command: `!${doTask ? '' : 'UN'}FOLLOWCURATOR ${this.#botName} ${curatorId}`
  4388. })
  4389. });
  4390. if (result === 'Success') {
  4391. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4392. logStatus.success();
  4393. return true;
  4394. }
  4395. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4396. return false;
  4397. }
  4398. logStatus.error(`${result}:${statusText}(${status})`);
  4399. return false;
  4400. } catch (error) {
  4401. throwError(error, 'Steam.toggleCurator');
  4402. return false;
  4403. }
  4404. }
  4405. async addLicense(id) {
  4406. try {
  4407. const [ type, ids ] = id.split('-');
  4408. if (type === 'appid') {
  4409. const logStatus = scripts_echoLog({
  4410. type: 'addingFreeLicense',
  4411. text: ids
  4412. });
  4413. const {
  4414. result,
  4415. statusText,
  4416. status,
  4417. data
  4418. } = await tools_httpRequest({
  4419. ...this.#asfOptions,
  4420. data: JSON.stringify({
  4421. Command: `!addlicense ${this.#botName} app/${ids}`
  4422. })
  4423. });
  4424. if (result === 'Success') {
  4425. if (data?.status === 200 && [ 'AlreadyPurchased', 'OK' ].find(text => data.response?.Result?.includes(text))) {
  4426. logStatus.success();
  4427. return true;
  4428. }
  4429. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4430. return false;
  4431. }
  4432. logStatus.error(`${result}:${statusText}(${status})`);
  4433. return false;
  4434. } else if (type === 'subid') {
  4435. const idsArr = ids.split(',');
  4436. const logStatus = scripts_echoLog({
  4437. type: 'addingFreeLicenseSubid',
  4438. text: ids
  4439. });
  4440. const {
  4441. result,
  4442. statusText,
  4443. status,
  4444. data
  4445. } = await tools_httpRequest({
  4446. ...this.#asfOptions,
  4447. data: JSON.stringify({
  4448. Command: `!addlicense ${this.#botName} ${idsArr.map(id => `sub/${id}`).join(',')}`
  4449. })
  4450. });
  4451. if (result === 'Success') {
  4452. if (data?.status === 200 && data.response?.Result) {
  4453. const resultLines = data.response.Result.split('\n');
  4454. idsArr.forEach(subid => {
  4455. const targetLine = resultLines.find(text => text.includes(subid));
  4456. if (targetLine && [ '成功', 'Success', 'Успех' ].find(text => targetLine.includes(text))) {
  4457. scripts_echoLog({}).success(targetLine);
  4458. } else {
  4459. scripts_echoLog({}).error(targetLine);
  4460. }
  4461. });
  4462. return true;
  4463. }
  4464. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4465. return false;
  4466. }
  4467. logStatus.error(`${result}:${statusText}(${status})`);
  4468. return false;
  4469. }
  4470. return false;
  4471. } catch (error) {
  4472. throwError(error, 'SteamASF.addLicense');
  4473. return false;
  4474. }
  4475. }
  4476. async requestPlayTestAccess(id) {
  4477. try {
  4478. const logStatus = scripts_echoLog({
  4479. type: 'requestingPlayTestAccess',
  4480. text: id
  4481. });
  4482. const {
  4483. result,
  4484. statusText,
  4485. status,
  4486. data
  4487. } = await tools_httpRequest({
  4488. ...this.#asfOptions,
  4489. data: JSON.stringify({
  4490. Command: `!REQUESTACCESS ${this.#botName} ${id}`
  4491. })
  4492. });
  4493. if (result === 'Success') {
  4494. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4495. logStatus.success();
  4496. return true;
  4497. }
  4498. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4499. return false;
  4500. }
  4501. logStatus.error(`${result}:${statusText}(${status})`);
  4502. return false;
  4503. } catch (error) {
  4504. throwError(error, 'Steam.requestPlayTestAccess');
  4505. return false;
  4506. }
  4507. }
  4508. }
  4509. const social_SteamASF = SteamASF;
  4510. class Steam extends social_Social {
  4511. tasks;
  4512. whiteList;
  4513. #cache = {
  4514. ...{
  4515. group: {},
  4516. officialGroup: {},
  4517. forum: {},
  4518. workshop: {},
  4519. curator: {}
  4520. },
  4521. ...GM_getValue('steamCache')
  4522. };
  4523. #auth = {};
  4524. #storeInitialized = false;
  4525. #communityInitialized = false;
  4526. #area = 'CN';
  4527. #areaStatus = 'end';
  4528. #ASF;
  4529. constructor() {
  4530. super();
  4531. const defaultTasksTemplate = {
  4532. groups: [],
  4533. officialGroups: [],
  4534. wishlists: [],
  4535. follows: [],
  4536. forums: [],
  4537. workshops: [],
  4538. workshopVotes: [],
  4539. curators: [],
  4540. curatorLikes: [],
  4541. announcements: [],
  4542. licenses: [],
  4543. playtests: []
  4544. };
  4545. this.tasks = defaultTasksTemplate;
  4546. this.whiteList = {
  4547. ...defaultTasksTemplate,
  4548. ...GM_getValue('whiteList')?.steam || {}
  4549. };
  4550. }
  4551. async init(type = 'all') {
  4552. try {
  4553. if (globalOptions.ASF.AsfEnabled && globalOptions.ASF.AsfIpcUrl && globalOptions.ASF.AsfIpcPassword) {
  4554. this.#ASF = new social_SteamASF();
  4555. if (await this.#ASF.init()) {
  4556. this.#storeInitialized = true;
  4557. this.#communityInitialized = true;
  4558. return true;
  4559. }
  4560. return false;
  4561. }
  4562. if (type === 'store') {
  4563. if (this.#storeInitialized) {
  4564. return true;
  4565. }
  4566. let storeInitialized = await this.#updateStoreAuth();
  4567. if (!storeInitialized) {
  4568. storeInitialized = await this.#updateStoreAuthTab();
  4569. }
  4570. this.#storeInitialized = storeInitialized;
  4571. if (!this.#storeInitialized) {
  4572. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4573. return false;
  4574. }
  4575. scripts_echoLog({}).success(i18n('initSuccess', 'SteamStore'));
  4576. return true;
  4577. }
  4578. if (type === 'community') {
  4579. if (this.#communityInitialized) {
  4580. return true;
  4581. }
  4582. let communityInitialized = await this.#getUserLink();
  4583. if (!communityInitialized) {
  4584. communityInitialized = await this.#updateCommunityAuthTab();
  4585. GM_setValue('steamCommunityAuth', null);
  4586. }
  4587. this.#communityInitialized = communityInitialized;
  4588. if (!this.#communityInitialized) {
  4589. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4590. return false;
  4591. }
  4592. scripts_echoLog({}).success(i18n('initSuccess', 'SteamCommunity'));
  4593. return true;
  4594. }
  4595. if (this.#storeInitialized && this.#communityInitialized) {
  4596. scripts_echoLog({}).success(i18n('initSuccess', 'Steam'));
  4597. return true;
  4598. }
  4599. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4600. return false;
  4601. } catch (error) {
  4602. throwError(error, 'Steam.init');
  4603. return false;
  4604. }
  4605. }
  4606. async #refreshToken(type = 'steamStore') {
  4607. try {
  4608. const host = {
  4609. steamStore: 'store.steampowered.com',
  4610. steamCommunity: 'steamcommunity.com'
  4611. };
  4612. const logStatus = scripts_echoLog({
  4613. text: i18n('refreshingToken', i18n(type))
  4614. });
  4615. const formData = new FormData();
  4616. formData.append('redir', `https://${host[type]}/`);
  4617. const {
  4618. result,
  4619. statusText,
  4620. status,
  4621. data
  4622. } = await tools_httpRequest({
  4623. url: 'https://login.steampowered.com/jwt/ajaxrefresh',
  4624. method: 'POST',
  4625. responseType: 'json',
  4626. headers: {
  4627. Host: 'login.steampowered.com',
  4628. Origin: `https://${host[type]}`,
  4629. Referer: `https://${host[type]}/`
  4630. },
  4631. data: formData
  4632. });
  4633. if (result === 'Success') {
  4634. if (data?.response?.success) {
  4635. if (await this.#setStoreToken(data.response, type)) {
  4636. logStatus.success();
  4637. return true;
  4638. }
  4639. logStatus.error('Error');
  4640. return false;
  4641. }
  4642. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4643. return false;
  4644. }
  4645. logStatus.error(`${result}:${statusText}(${status})`);
  4646. return false;
  4647. } catch (error) {
  4648. throwError(error, 'Steam.refreshToken');
  4649. return false;
  4650. }
  4651. }
  4652. async #setStoreToken(param, type) {
  4653. try {
  4654. const host = {
  4655. steamStore: 'store.steampowered.com',
  4656. steamCommunity: 'steamcommunity.com'
  4657. };
  4658. const logStatus = scripts_echoLog({
  4659. text: i18n('settingToken', i18n(type))
  4660. });
  4661. const formData = new FormData();
  4662. formData.append('steamID', param.steamID);
  4663. formData.append('nonce', param.nonce);
  4664. formData.append('redir', param.redir);
  4665. formData.append('auth', param.auth);
  4666. const {
  4667. result,
  4668. statusText,
  4669. status,
  4670. data
  4671. } = await tools_httpRequest({
  4672. url: `https://${host[type]}/login/settoken`,
  4673. method: 'POST',
  4674. headers: {
  4675. Accept: 'application/json, text/plain, */*',
  4676. Host: host[type],
  4677. Origin: `https://${host[type]}`
  4678. },
  4679. data: formData
  4680. });
  4681. if (result === 'Success') {
  4682. if (data?.status === 200) {
  4683. logStatus.success();
  4684. return true;
  4685. }
  4686. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4687. return false;
  4688. }
  4689. logStatus.error(`${result}:${statusText}(${status})`);
  4690. return false;
  4691. } catch (error) {
  4692. throwError(error, 'Steam.setStoreToken');
  4693. return false;
  4694. }
  4695. }
  4696. async #updateStoreAuth(retry = false) {
  4697. try {
  4698. const logStatus = scripts_echoLog({
  4699. text: i18n('updatingAuth', i18n('steamStore'))
  4700. });
  4701. const {
  4702. result,
  4703. statusText,
  4704. status,
  4705. data
  4706. } = await tools_httpRequest({
  4707. url: 'https://store.steampowered.com/',
  4708. method: 'GET',
  4709. headers: {
  4710. 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',
  4711. 'Cache-Control': 'max-age=0',
  4712. 'Sec-Fetch-Dest': 'document',
  4713. 'Sec-Fetch-Mode': 'navigate',
  4714. 'Upgrade-Insecure-Requests': '1'
  4715. },
  4716. fetch: false,
  4717. redirect: 'manual'
  4718. });
  4719. if (data?.status === 200) {
  4720. if (!data.responseText.includes('data-miniprofile=')) {
  4721. if (await this.#refreshToken('steamStore')) {
  4722. logStatus.warning(i18n('retry'));
  4723. if (retry) {
  4724. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4725. return false;
  4726. }
  4727. return this.#updateStoreAuth(true);
  4728. }
  4729. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4730. return false;
  4731. }
  4732. const storeSessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4733. if (storeSessionID) {
  4734. this.#auth.storeSessionID = storeSessionID;
  4735. logStatus.success();
  4736. return true;
  4737. }
  4738. logStatus.error('Error: Get "sessionID" failed');
  4739. return false;
  4740. }
  4741. if ([ 301, 302 ].includes(data?.status)) {
  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. logStatus.error(`${result}:${statusText}(${status})`);
  4754. return false;
  4755. } catch (error) {
  4756. throwError(error, 'Steam.updateStoreAuth');
  4757. return false;
  4758. }
  4759. }
  4760. async #updateStoreAuthTab() {
  4761. try {
  4762. const logStatus = scripts_echoLog({
  4763. text: i18n('updatingAuth', i18n('steamStore'))
  4764. });
  4765. return await new Promise(resolve => {
  4766. const newTab = window.open('https://store.steampowered.com/', 'mozillaWindow', 'pop=1;');
  4767. GM_setValue('steamStoreAuth', 'update');
  4768. const listenerId = GM_addValueChangeListener('steamStoreAuth', (key, oldValue, newValue, remote) => {
  4769. GM_removeValueChangeListener(listenerId);
  4770. newTab?.close();
  4771. if (newValue && JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
  4772. this.#auth.storeSessionID = newValue.storeSessionID;
  4773. logStatus.success();
  4774. resolve(true);
  4775. return;
  4776. }
  4777. logStatus.error('Failed');
  4778. resolve(false);
  4779. });
  4780. });
  4781. } catch (error) {
  4782. throwError(error, 'Steam.updateStoreAuthTab');
  4783. return false;
  4784. }
  4785. }
  4786. async #updateCommunityAuthTab() {
  4787. try {
  4788. const logStatus = scripts_echoLog({
  4789. text: i18n('updatingAuth', i18n('steamCommunity'))
  4790. });
  4791. return await new Promise(resolve => {
  4792. const newTab = window.open('https://steamcommunity.com/my', 'mozillaWindow', 'pop=1;');
  4793. GM_setValue('steamCommunityAuth', 'update');
  4794. const listenerId = GM_addValueChangeListener('steamCommunityAuth', (key, oldValue, newValue, remote) => {
  4795. GM_removeValueChangeListener(listenerId);
  4796. newTab?.close();
  4797. if (newValue && JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
  4798. this.#auth.steam64Id = newValue.steam64Id;
  4799. this.#auth.userName = newValue.userName;
  4800. this.#auth.communitySessionID = newValue.communitySessionID;
  4801. logStatus.success();
  4802. resolve(true);
  4803. return;
  4804. }
  4805. logStatus.error('Failed');
  4806. resolve(false);
  4807. });
  4808. });
  4809. } catch (error) {
  4810. throwError(error, 'Steam.updateCommunityAuthTab');
  4811. return false;
  4812. }
  4813. }
  4814. async #getUserLink(retry = false) {
  4815. try {
  4816. const logStatus = scripts_echoLog({
  4817. text: i18n('gettingUserLink')
  4818. });
  4819. const {
  4820. result,
  4821. statusText,
  4822. status,
  4823. data
  4824. } = await tools_httpRequest({
  4825. url: 'https://steamcommunity.com/my',
  4826. method: 'GET',
  4827. headers: {
  4828. 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',
  4829. 'Cache-Control': 'max-age=0',
  4830. 'Sec-Fetch-Dest': 'document',
  4831. 'Sec-Fetch-Mode': 'navigate',
  4832. 'Upgrade-Insecure-Requests': '1'
  4833. },
  4834. fetch: false,
  4835. redirect: 'manual'
  4836. });
  4837. if (data?.status === 200) {
  4838. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4839. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4840. return false;
  4841. }
  4842. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4843. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4844. const userName = data.responseText.match(/steamcommunity.com\/id\/(.+?)\/friends\//)?.[1];
  4845. if (steam64Id) {
  4846. this.#auth.steam64Id = steam64Id;
  4847. }
  4848. if (userName) {
  4849. this.#auth.userName = userName;
  4850. }
  4851. if (communitySessionID) {
  4852. this.#auth.communitySessionID = communitySessionID;
  4853. logStatus.success();
  4854. return true;
  4855. }
  4856. logStatus.error('Error: Get "sessionID" failed');
  4857. return false;
  4858. }
  4859. if (data?.status === 302) {
  4860. if (await this.#refreshToken('steamCommunity')) {
  4861. if (retry) {
  4862. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4863. return false;
  4864. }
  4865. logStatus.warning(i18n('retry'));
  4866. return this.#getUserLink(true);
  4867. }
  4868. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4869. return false;
  4870. }
  4871. const location = data?.responseHeaders?.split('\n')?.find(header => header.includes('location') ? header.replace('loctation:', '').trim() : null);
  4872. if (data?.status === 301 && location?.includes('steamcommunity.com/id')) {
  4873. logStatus.success();
  4874. return await this.#updateCommunityAuth(data.finalUrl);
  4875. }
  4876. if (data?.status === 301 && location?.includes('https://steamcommunity.com/login/home')) {
  4877. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4878. return false;
  4879. }
  4880. logStatus.error(`${result}:${statusText}(${status})`);
  4881. return false;
  4882. } catch (error) {
  4883. throwError(error, 'Steam.updateCommunityAuth');
  4884. return false;
  4885. }
  4886. }
  4887. async #updateCommunityAuth(url) {
  4888. try {
  4889. const logStatus = scripts_echoLog({
  4890. text: i18n('updatingAuth', i18n('steamCommunity'))
  4891. });
  4892. const {
  4893. result,
  4894. statusText,
  4895. status,
  4896. data
  4897. } = await tools_httpRequest({
  4898. url: url,
  4899. method: 'GET',
  4900. headers: {
  4901. 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',
  4902. 'Cache-Control': 'max-age=0',
  4903. 'Sec-Fetch-Dest': 'document',
  4904. 'Sec-Fetch-Mode': 'navigate',
  4905. 'Upgrade-Insecure-Requests': '1'
  4906. }
  4907. });
  4908. if (result === 'Success') {
  4909. if (data?.status === 200) {
  4910. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4911. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4912. return false;
  4913. }
  4914. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4915. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4916. const userName = data.responseText.match(/steamcommunity.com\/id\/(.+?)\/friends\//)?.[1];
  4917. if (steam64Id) {
  4918. this.#auth.steam64Id = steam64Id;
  4919. }
  4920. if (userName) {
  4921. this.#auth.userName = userName;
  4922. }
  4923. if (communitySessionID) {
  4924. this.#auth.communitySessionID = communitySessionID;
  4925. logStatus.success();
  4926. return true;
  4927. }
  4928. logStatus.error('Error: Get "sessionID" failed');
  4929. return false;
  4930. }
  4931. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4932. return false;
  4933. }
  4934. logStatus.error(`${result}:${statusText}(${status})`);
  4935. return false;
  4936. } catch (error) {
  4937. throwError(error, 'Steam.updateCommunityAuth');
  4938. return false;
  4939. }
  4940. }
  4941. async #getAreaInfo() {
  4942. try {
  4943. const logStatus = scripts_echoLog({
  4944. text: i18n('gettingAreaInfo')
  4945. });
  4946. const {
  4947. result,
  4948. statusText,
  4949. status,
  4950. data
  4951. } = await tools_httpRequest({
  4952. url: 'https://store.steampowered.com/cart/',
  4953. method: 'GET'
  4954. });
  4955. if (result === 'Success') {
  4956. if (data?.status === 200) {
  4957. const cartConfigRaw = data.responseText.match(/data-cart_config="(.*?)"/)?.[1];
  4958. const temp = document.createElement('div');
  4959. temp.innerHTML = cartConfigRaw || '{}';
  4960. const cartConfigStr = temp.textContent || temp.innerText;
  4961. let cartConfig;
  4962. try {
  4963. cartConfig = JSON.parse(cartConfigStr);
  4964. } catch (error) {
  4965. logStatus.error('Error: get country info filed');
  4966. console.error(error);
  4967. return {};
  4968. }
  4969. if (!cartConfig.rgUserCountryOptions) {
  4970. logStatus.warning('Warning: Area cannot be changed');
  4971. return {};
  4972. }
  4973. const userInfoRaw = data.responseText.match(/data-userinfo="(.*?)"/)?.[1];
  4974. const temp1 = document.createElement('div');
  4975. temp1.innerHTML = userInfoRaw || '{}';
  4976. const userInfoStr = temp1.textContent || temp1.innerText;
  4977. let userInfo;
  4978. try {
  4979. userInfo = JSON.parse(userInfoStr);
  4980. } catch (error) {
  4981. logStatus.error('Error: get country info filed');
  4982. console.error(error);
  4983. return {};
  4984. }
  4985. const currentArea = userInfo.country_code;
  4986. const areas = Object.keys(cartConfig.rgUserCountryOptions).filter(area => area !== 'help');
  4987. if (currentArea && areas.length > 0) {
  4988. this.#area = currentArea;
  4989. logStatus.success();
  4990. return {
  4991. currentArea: currentArea,
  4992. areas: areas
  4993. };
  4994. }
  4995. logStatus.error('Error: get country info filed');
  4996. return {};
  4997. }
  4998. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4999. return {};
  5000. }
  5001. logStatus.error(`${result}:${statusText}(${status})`);
  5002. return {};
  5003. } catch (error) {
  5004. throwError(error, 'Steam.getAreaInfo');
  5005. return {};
  5006. }
  5007. }
  5008. async #changeArea(area) {
  5009. try {
  5010. if (this.#areaStatus === 'waiting') {
  5011. await new Promise(resolve => {
  5012. const checker = setInterval(() => {
  5013. if (this.#areaStatus !== 'waiting') {
  5014. clearInterval(checker);
  5015. resolve(true);
  5016. }
  5017. });
  5018. });
  5019. }
  5020. if (this.#area === area || !area && this.#area !== 'CN') {
  5021. return true;
  5022. }
  5023. this.#areaStatus = 'waiting';
  5024. let aimedArea = area;
  5025. if (!aimedArea) {
  5026. const {
  5027. currentArea,
  5028. areas
  5029. } = await this.#getAreaInfo();
  5030. if (!currentArea || !areas) {
  5031. this.#areaStatus = 'error';
  5032. return false;
  5033. }
  5034. if (currentArea !== 'CN') {
  5035. this.#areaStatus = 'skip';
  5036. scripts_echoLog({
  5037. text: 'notNeededChangeArea'
  5038. });
  5039. return 'skip';
  5040. }
  5041. const anotherArea = areas.filter(area => area && area !== 'CN');
  5042. if (!anotherArea || anotherArea.length === 0) {
  5043. this.#areaStatus = 'noAnotherArea';
  5044. scripts_echoLog({
  5045. text: 'noAnotherArea'
  5046. });
  5047. return false;
  5048. }
  5049. [ aimedArea ] = anotherArea;
  5050. }
  5051. const logStatus = scripts_echoLog({
  5052. text: i18n('changingArea', aimedArea)
  5053. });
  5054. const {
  5055. result,
  5056. statusText,
  5057. status,
  5058. data
  5059. } = await tools_httpRequest({
  5060. url: 'https://store.steampowered.com/country/setcountry',
  5061. method: 'POST',
  5062. headers: {
  5063. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5064. },
  5065. data: $.param({
  5066. cc: aimedArea,
  5067. sessionid: this.#auth.storeSessionID
  5068. })
  5069. });
  5070. if (result === 'Success') {
  5071. if (data?.status === 200 && data.responseText === 'true') {
  5072. const {
  5073. currentArea
  5074. } = await this.#getAreaInfo();
  5075. if (currentArea === aimedArea) {
  5076. this.#areaStatus = 'success';
  5077. logStatus.success();
  5078. return currentArea;
  5079. }
  5080. this.#areaStatus = 'error';
  5081. logStatus.error('Error: change country filed');
  5082. return 'CN';
  5083. }
  5084. this.#areaStatus = 'error';
  5085. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5086. return 'CN';
  5087. }
  5088. this.#areaStatus = 'error';
  5089. logStatus.error(`${result}:${statusText}(${status})`);
  5090. return 'CN';
  5091. } catch (error) {
  5092. this.#areaStatus = 'error';
  5093. throwError(error, 'Steam.changeArea');
  5094. return false;
  5095. }
  5096. }
  5097. async #joinGroup(groupName) {
  5098. try {
  5099. if (this.#ASF) {
  5100. if (await this.#ASF.joinGroup(groupName)) {
  5101. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5102. return true;
  5103. }
  5104. return false;
  5105. }
  5106. const logStatus = scripts_echoLog({
  5107. type: 'joiningSteamGroup',
  5108. text: groupName
  5109. });
  5110. const {
  5111. result,
  5112. statusText,
  5113. status,
  5114. data
  5115. } = await tools_httpRequest({
  5116. url: `https://steamcommunity.com/groups/${groupName}`,
  5117. method: 'POST',
  5118. headers: {
  5119. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5120. },
  5121. data: $.param({
  5122. action: 'join',
  5123. sessionID: this.#auth.communitySessionID
  5124. })
  5125. });
  5126. if (result === 'Success') {
  5127. if (data?.status === 200 && !data.responseText.includes('grouppage_join_area')) {
  5128. logStatus.success();
  5129. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5130. return true;
  5131. }
  5132. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5133. return false;
  5134. }
  5135. logStatus.error(`${result}:${statusText}(${status})`);
  5136. return false;
  5137. } catch (error) {
  5138. throwError(error, 'Steam.joinGroup');
  5139. return false;
  5140. }
  5141. }
  5142. async #leaveGroup(groupName) {
  5143. try {
  5144. if (this.whiteList.groups.includes(groupName)) {
  5145. scripts_echoLog({
  5146. type: 'whiteList',
  5147. text: 'Steam.leaveGroup',
  5148. id: groupName
  5149. });
  5150. return true;
  5151. }
  5152. if (this.#ASF) {
  5153. return await this.#ASF.leaveGroup(groupName);
  5154. }
  5155. const groupId = await this.#getGroupId(groupName);
  5156. if (!groupId) {
  5157. return false;
  5158. }
  5159. const logStatus = scripts_echoLog({
  5160. type: 'leavingSteamGroup',
  5161. text: groupName
  5162. });
  5163. const {
  5164. result,
  5165. statusText,
  5166. status,
  5167. data
  5168. } = await tools_httpRequest({
  5169. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5170. method: 'POST',
  5171. headers: {
  5172. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5173. },
  5174. data: $.param({
  5175. sessionID: this.#auth.communitySessionID,
  5176. action: 'leaveGroup',
  5177. groupId: groupId
  5178. })
  5179. });
  5180. if (result === 'Success') {
  5181. 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) {
  5182. logStatus.success();
  5183. return true;
  5184. }
  5185. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5186. return false;
  5187. }
  5188. logStatus.error(`${result}:${statusText}(${status})`);
  5189. return false;
  5190. } catch (error) {
  5191. throwError(error, 'Steam.leaveGroup');
  5192. return false;
  5193. }
  5194. }
  5195. async #getGroupId(groupName) {
  5196. try {
  5197. const logStatus = scripts_echoLog({
  5198. type: 'gettingSteamGroupId',
  5199. text: groupName
  5200. });
  5201. const groupId = this.#cache.group[groupName];
  5202. if (groupId) {
  5203. logStatus.success();
  5204. return groupId;
  5205. }
  5206. const {
  5207. result,
  5208. statusText,
  5209. status,
  5210. data
  5211. } = await tools_httpRequest({
  5212. url: `https://steamcommunity.com/groups/${groupName}`,
  5213. method: 'GET',
  5214. headers: {
  5215. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5216. }
  5217. });
  5218. if (result === 'Success') {
  5219. if (data?.status === 200) {
  5220. const groupId = data.responseText.match(/OpenGroupChat\( '([0-9]+)'/)?.[1];
  5221. if (groupId) {
  5222. this.#setCache('group', groupName, groupId);
  5223. logStatus.success();
  5224. return groupId;
  5225. }
  5226. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5227. return false;
  5228. }
  5229. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5230. return false;
  5231. }
  5232. logStatus.error(`${result}:${statusText}(${status})`);
  5233. return false;
  5234. } catch (error) {
  5235. throwError(error, 'Steam.getGroupID');
  5236. return false;
  5237. }
  5238. }
  5239. async #joinOfficialGroup(gameId) {
  5240. try {
  5241. if (this.#ASF) {
  5242. if (await this.#ASF.joinGroup(gameId)) {
  5243. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5244. return true;
  5245. }
  5246. return false;
  5247. }
  5248. const logStatus = scripts_echoLog({
  5249. type: 'joiningSteamOfficialGroup',
  5250. text: gameId
  5251. });
  5252. const {
  5253. result,
  5254. statusText,
  5255. status,
  5256. data
  5257. } = await tools_httpRequest({
  5258. url: `https://steamcommunity.com/games/${gameId}?action=join&sessionID=${this.#auth.communitySessionID}`,
  5259. method: 'GET',
  5260. headers: {
  5261. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5262. }
  5263. });
  5264. if (result === 'Success') {
  5265. if (data?.status === 200 && !data.responseText.includes('id="publicGroupJoin"')) {
  5266. logStatus.success();
  5267. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5268. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5269. if (groupId) {
  5270. this.#setCache('officialGroup', gameId, groupId);
  5271. }
  5272. return true;
  5273. }
  5274. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5275. return false;
  5276. }
  5277. logStatus.error(`${result}:${statusText}(${status})`);
  5278. return false;
  5279. } catch (error) {
  5280. throwError(error, 'Steam.joinOfficialGroup');
  5281. return false;
  5282. }
  5283. }
  5284. async #leaveOfficialGroup(gameId) {
  5285. try {
  5286. if (this.whiteList.officialGroups.includes(gameId)) {
  5287. scripts_echoLog({
  5288. type: 'whiteList',
  5289. text: 'Steam.leaveOfficialGroup',
  5290. id: gameId
  5291. });
  5292. return true;
  5293. }
  5294. if (this.#ASF) {
  5295. return await this.#ASF.leaveGroup(gameId);
  5296. }
  5297. const groupId = await this.#getOfficialGroupId(gameId);
  5298. if (!groupId) {
  5299. return false;
  5300. }
  5301. const logStatus = scripts_echoLog({
  5302. type: 'leavingSteamOfficialGroup',
  5303. text: gameId
  5304. });
  5305. const {
  5306. result,
  5307. statusText,
  5308. status,
  5309. data
  5310. } = await tools_httpRequest({
  5311. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5312. method: 'POST',
  5313. headers: {
  5314. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5315. },
  5316. data: $.param({
  5317. sessionID: this.#auth.communitySessionID,
  5318. action: 'leaveGroup',
  5319. groupId: groupId
  5320. })
  5321. });
  5322. if (result === 'Success') {
  5323. if (data?.status === 200) {
  5324. const {
  5325. result: resultR,
  5326. statusText: statusTextR,
  5327. status: statusR,
  5328. data: dataR
  5329. } = await tools_httpRequest({
  5330. url: `https://steamcommunity.com/games/${gameId}`,
  5331. method: 'GET',
  5332. headers: {
  5333. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5334. }
  5335. });
  5336. if (resultR === 'Success') {
  5337. if (dataR?.status === 200 && dataR.responseText.includes('id="publicGroupJoin"')) {
  5338. logStatus.success();
  5339. return true;
  5340. }
  5341. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5342. return false;
  5343. }
  5344. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5345. return false;
  5346. }
  5347. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5348. return false;
  5349. }
  5350. logStatus.error(`${result}:${statusText}(${status})`);
  5351. return false;
  5352. } catch (error) {
  5353. throwError(error, 'Steam.leaveOfficialGroup');
  5354. return false;
  5355. }
  5356. }
  5357. async #getOfficialGroupId(gameId) {
  5358. try {
  5359. const logStatus = scripts_echoLog({
  5360. type: 'gettingSteamOfficialGroupId',
  5361. text: gameId
  5362. });
  5363. const groupId = this.#cache.officialGroup[gameId];
  5364. if (groupId) {
  5365. logStatus.success();
  5366. return groupId;
  5367. }
  5368. const {
  5369. result,
  5370. statusText,
  5371. status,
  5372. data
  5373. } = await tools_httpRequest({
  5374. url: `https://steamcommunity.com/games/${gameId}`,
  5375. method: 'GET',
  5376. headers: {
  5377. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5378. }
  5379. });
  5380. if (result === 'Success') {
  5381. if (data?.status === 200) {
  5382. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5383. if (groupId) {
  5384. this.#setCache('officialGroup', gameId, groupId);
  5385. logStatus.success();
  5386. return groupId;
  5387. }
  5388. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5389. return false;
  5390. }
  5391. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5392. return false;
  5393. }
  5394. logStatus.error(`${result}:${statusText}(${status})`);
  5395. return false;
  5396. } catch (error) {
  5397. throwError(error, 'Steam.getGroupID');
  5398. return false;
  5399. }
  5400. }
  5401. async #addToWishlist(gameId) {
  5402. try {
  5403. if (this.#ASF) {
  5404. if (await this.#ASF.addToWishlist(gameId)) {
  5405. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5406. return true;
  5407. }
  5408. return false;
  5409. }
  5410. const logStatus = scripts_echoLog({
  5411. type: 'addingToWishlist',
  5412. text: gameId
  5413. });
  5414. const {
  5415. result,
  5416. data
  5417. } = await tools_httpRequest({
  5418. url: 'https://store.steampowered.com/api/addtowishlist',
  5419. method: 'POST',
  5420. headers: {
  5421. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5422. },
  5423. data: $.param({
  5424. sessionid: this.#auth.storeSessionID,
  5425. appid: gameId
  5426. }),
  5427. dataType: 'json'
  5428. });
  5429. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5430. logStatus.success();
  5431. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5432. return true;
  5433. }
  5434. const {
  5435. result: resultR,
  5436. statusText: statusTextR,
  5437. status: statusR,
  5438. data: dataR
  5439. } = await tools_httpRequest({
  5440. url: `https://store.steampowered.com/app/${gameId}`,
  5441. method: 'GET'
  5442. });
  5443. if (resultR === 'Success') {
  5444. if (dataR?.status === 200) {
  5445. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5446. logStatus.warning(i18n('changeAreaNotice'));
  5447. if (!await this.#changeArea()) {
  5448. return false;
  5449. }
  5450. return await this.#addToWishlist(gameId);
  5451. }
  5452. if (dataR.responseText.includes('class="queue_actions_ctn"') && dataR.responseText.includes('class="already_in_library"')) {
  5453. logStatus.success();
  5454. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5455. return true;
  5456. } 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"')) {
  5457. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5458. return false;
  5459. }
  5460. logStatus.success();
  5461. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5462. return true;
  5463. }
  5464. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5465. return false;
  5466. }
  5467. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5468. return false;
  5469. } catch (error) {
  5470. throwError(error, 'Steam.addToWishlist');
  5471. return false;
  5472. }
  5473. }
  5474. async #removeFromWishlist(gameId) {
  5475. try {
  5476. if (this.whiteList.wishlists.includes(gameId)) {
  5477. scripts_echoLog({
  5478. type: 'whiteList',
  5479. text: 'Steam.removeFromWishlist',
  5480. id: gameId
  5481. });
  5482. return true;
  5483. }
  5484. if (this.#ASF) {
  5485. return await this.#ASF.removeFromWishlist(gameId);
  5486. }
  5487. const logStatus = scripts_echoLog({
  5488. type: 'removingFromWishlist',
  5489. text: gameId
  5490. });
  5491. const {
  5492. result,
  5493. data
  5494. } = await tools_httpRequest({
  5495. url: 'https://store.steampowered.com/api/removefromwishlist',
  5496. method: 'POST',
  5497. headers: {
  5498. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5499. },
  5500. data: $.param({
  5501. sessionid: this.#auth.storeSessionID,
  5502. appid: gameId
  5503. }),
  5504. dataType: 'json'
  5505. });
  5506. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5507. logStatus.success();
  5508. return true;
  5509. }
  5510. const {
  5511. result: resultR,
  5512. statusText: statusTextR,
  5513. status: statusR,
  5514. data: dataR
  5515. } = await tools_httpRequest({
  5516. url: `https://store.steampowered.com/app/${gameId}`,
  5517. method: 'GET'
  5518. });
  5519. if (resultR === 'Success') {
  5520. if (dataR?.status === 200) {
  5521. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5522. logStatus.warning(i18n('changeAreaNotice'));
  5523. const result = await this.#changeArea();
  5524. if (!result || result === 'CN' || result === 'skip') {
  5525. return false;
  5526. }
  5527. return await this.#removeFromWishlist(gameId);
  5528. }
  5529. if (dataR.responseText.includes('class="queue_actions_ctn"') && (dataR.responseText.includes('ds_owned_flag ds_flag') || dataR.responseText.includes('add_to_wishlist_area'))) {
  5530. logStatus.success();
  5531. return true;
  5532. }
  5533. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5534. return false;
  5535. }
  5536. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5537. return false;
  5538. }
  5539. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5540. return false;
  5541. } catch (error) {
  5542. throwError(error, 'Steam.removeFromWishlist');
  5543. return false;
  5544. }
  5545. }
  5546. async #toggleFollowGame(gameId, doTask) {
  5547. try {
  5548. if (!doTask && this.whiteList.follows.includes(gameId)) {
  5549. scripts_echoLog({
  5550. type: 'whiteList',
  5551. text: 'Steam.unfollowGame',
  5552. id: gameId
  5553. });
  5554. return true;
  5555. }
  5556. if (this.#ASF) {
  5557. if (await this.#ASF.toggleFollowGame(gameId, doTask)) {
  5558. if (doTask) {
  5559. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5560. }
  5561. return true;
  5562. }
  5563. return false;
  5564. }
  5565. const logStatus = scripts_echoLog({
  5566. type: `${doTask ? '' : 'un'}followingGame`,
  5567. text: gameId
  5568. });
  5569. const requestData = {
  5570. sessionid: this.#auth.storeSessionID,
  5571. appid: gameId
  5572. };
  5573. if (!doTask) {
  5574. requestData.unfollow = '1';
  5575. }
  5576. const {
  5577. result,
  5578. data
  5579. } = await tools_httpRequest({
  5580. url: 'https://store.steampowered.com/explore/followgame/',
  5581. method: 'POST',
  5582. headers: {
  5583. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5584. },
  5585. data: $.param(requestData)
  5586. });
  5587. if (result === 'Success' && data?.status === 200 && data.responseText === 'true') {
  5588. logStatus.success();
  5589. return true;
  5590. }
  5591. const followed = await this.#isFollowedGame(gameId);
  5592. if (this.#area === 'CN' && followed === 'areaLocked') {
  5593. logStatus.warning(i18n('changeAreaNotice'));
  5594. if (!await this.#changeArea()) {
  5595. return false;
  5596. }
  5597. return await this.#removeFromWishlist(gameId);
  5598. }
  5599. if (doTask === followed) {
  5600. logStatus.success();
  5601. if (doTask) {
  5602. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5603. }
  5604. return true;
  5605. }
  5606. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5607. return false;
  5608. } catch (error) {
  5609. throwError(error, 'Steam.toggleFollowGame');
  5610. return false;
  5611. }
  5612. }
  5613. async #isFollowedGame(gameId) {
  5614. try {
  5615. const {
  5616. result,
  5617. data
  5618. } = await tools_httpRequest({
  5619. url: `https://store.steampowered.com/app/${gameId}`,
  5620. method: 'GET'
  5621. });
  5622. if (result === 'Success') {
  5623. if (data?.status === 200) {
  5624. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  5625. return 'areaLocked';
  5626. }
  5627. if ($(data.responseText.replace(/<img.*?>/g, '')).find('.queue_control_button.queue_btn_follow>.btnv6_blue_hoverfade.btn_medium.queue_btn_active').css('display') !== 'none') {
  5628. return true;
  5629. }
  5630. return false;
  5631. }
  5632. return false;
  5633. }
  5634. return false;
  5635. } catch (error) {
  5636. throwError(error, 'Steam.isFollowedGame');
  5637. return false;
  5638. }
  5639. }
  5640. async #toggleForum(gameId, doTask = true) {
  5641. try {
  5642. if (!doTask && this.whiteList.forums.includes(gameId)) {
  5643. scripts_echoLog({
  5644. type: 'whiteList',
  5645. text: 'Steam.unsubscribeForum',
  5646. id: gameId
  5647. });
  5648. return true;
  5649. }
  5650. const forumId = await this.#getForumId(gameId);
  5651. if (!forumId) {
  5652. return false;
  5653. }
  5654. const logStatus = scripts_echoLog({
  5655. type: `${doTask ? '' : 'un'}subscribingForum`,
  5656. text: gameId
  5657. });
  5658. const [ id, feature ] = forumId.split('_');
  5659. const {
  5660. result,
  5661. statusText,
  5662. status,
  5663. data
  5664. } = await tools_httpRequest({
  5665. url: `https://steamcommunity.com/forum/${id}/General/${doTask ? '' : 'un'}subscribe/${feature || '0'}/`,
  5666. method: 'POST',
  5667. responseType: 'json',
  5668. headers: {
  5669. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5670. },
  5671. data: $.param({
  5672. sessionid: this.#auth.communitySessionID
  5673. })
  5674. });
  5675. if (result === 'Success') {
  5676. if (data?.status === 200 && (data.response?.success === 1 || data.response?.success === 29)) {
  5677. if (doTask) {
  5678. this.tasks.forums = unique([ ...this.tasks.forums, gameId ]);
  5679. }
  5680. logStatus.success();
  5681. return true;
  5682. }
  5683. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5684. return true;
  5685. }
  5686. logStatus.error(`${result}:${statusText}(${status})`);
  5687. return true;
  5688. } catch (error) {
  5689. throwError(error, 'Steam.toggleForum');
  5690. return true;
  5691. }
  5692. }
  5693. async #getForumId(gameId) {
  5694. try {
  5695. const logStatus = scripts_echoLog({
  5696. type: 'gettingForumId',
  5697. text: gameId
  5698. });
  5699. const forumId = this.#cache.forum[gameId];
  5700. if (forumId) {
  5701. logStatus.success();
  5702. return forumId;
  5703. }
  5704. const {
  5705. result,
  5706. statusText,
  5707. status,
  5708. data
  5709. } = await tools_httpRequest({
  5710. url: `https://steamcommunity.com/app/${gameId}/discussions/`,
  5711. method: 'GET'
  5712. });
  5713. if (result === 'Success') {
  5714. if (data?.status === 200) {
  5715. const forumId = data.responseText?.match(/General_([\d]+(_[\d]+)?)/)?.[1];
  5716. if (forumId) {
  5717. this.#setCache('forum', gameId, forumId);
  5718. logStatus.success();
  5719. return forumId;
  5720. }
  5721. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5722. return false;
  5723. }
  5724. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5725. return false;
  5726. }
  5727. logStatus.error(`${result}:${statusText}(${status})`);
  5728. return false;
  5729. } catch (error) {
  5730. throwError(error, 'Steam.getForumId');
  5731. return false;
  5732. }
  5733. }
  5734. async #toggleFavoriteWorkshop(id, doTask = true) {
  5735. try {
  5736. if (!doTask && this.whiteList.workshops.includes(id)) {
  5737. scripts_echoLog({
  5738. type: 'whiteList',
  5739. text: 'Steam.unfavoriteWorkshop',
  5740. id: id
  5741. });
  5742. return true;
  5743. }
  5744. const appid = await this.#getWorkshopAppId(id);
  5745. if (!appid) {
  5746. return false;
  5747. }
  5748. const logStatus = scripts_echoLog({
  5749. type: doTask ? 'favoritingWorkshop' : 'unfavoritingWorkshop',
  5750. text: id
  5751. });
  5752. const {
  5753. result,
  5754. statusText,
  5755. status,
  5756. data
  5757. } = await tools_httpRequest({
  5758. url: `https://steamcommunity.com/sharedfiles/${doTask ? '' : 'un'}favorite`,
  5759. method: 'POST',
  5760. headers: {
  5761. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5762. },
  5763. data: $.param({
  5764. id: id,
  5765. appid: appid,
  5766. sessionid: this.#auth.communitySessionID
  5767. })
  5768. });
  5769. if (result === 'Success') {
  5770. if (data?.status === 200 && !data.responseText) {
  5771. if (doTask) {
  5772. this.tasks.workshops = unique([ ...this.tasks.workshops, id ]);
  5773. }
  5774. logStatus.success();
  5775. return true;
  5776. }
  5777. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5778. return false;
  5779. }
  5780. logStatus.error(`${result}:${statusText}(${status})`);
  5781. return false;
  5782. } catch (error) {
  5783. throwError(error, 'Steam.toggleFavoriteWorkshop');
  5784. return false;
  5785. }
  5786. }
  5787. async #getWorkshopAppId(id) {
  5788. try {
  5789. const logStatus = scripts_echoLog({
  5790. type: 'gettingWorkshopAppId',
  5791. text: id
  5792. });
  5793. const appId = this.#cache.workshop[id];
  5794. if (appId) {
  5795. logStatus.success();
  5796. return appId;
  5797. }
  5798. const {
  5799. result,
  5800. statusText,
  5801. status,
  5802. data
  5803. } = await tools_httpRequest({
  5804. url: `https://steamcommunity.com/sharedfiles/filedetails/?id=${id}`,
  5805. method: 'GET'
  5806. });
  5807. if (result === 'Success') {
  5808. if (data?.status === 200) {
  5809. const appId = data.responseText.match(/<input type="hidden" name="appid" value="([\d]+?)" \/>/)?.[1];
  5810. if (appId) {
  5811. this.#setCache('workshop', id, appId);
  5812. logStatus.success();
  5813. return appId;
  5814. }
  5815. logStatus.error('Error: getWorkshopAppId failed');
  5816. return false;
  5817. }
  5818. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5819. return false;
  5820. }
  5821. logStatus.error(`${result}:${statusText}(${status})`);
  5822. return false;
  5823. } catch (error) {
  5824. throwError(error, 'Steam.getWorkshopAppId');
  5825. return false;
  5826. }
  5827. }
  5828. async #voteUpWorkshop(id) {
  5829. try {
  5830. const logStatus = scripts_echoLog({
  5831. type: 'votingUpWorkshop',
  5832. text: id
  5833. });
  5834. const {
  5835. result,
  5836. statusText,
  5837. status,
  5838. data
  5839. } = await tools_httpRequest({
  5840. url: 'https://steamcommunity.com/sharedfiles/voteup',
  5841. method: 'POST',
  5842. responseType: 'json',
  5843. headers: {
  5844. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5845. },
  5846. data: $.param({
  5847. id: id,
  5848. sessionid: this.#auth.communitySessionID
  5849. })
  5850. });
  5851. if (result === 'Success') {
  5852. if (data?.status === 200 && data.response?.success === 1) {
  5853. logStatus.success();
  5854. return true;
  5855. }
  5856. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5857. return true;
  5858. }
  5859. logStatus.error(`${result}:${statusText}(${status})`);
  5860. return true;
  5861. } catch (error) {
  5862. throwError(error, 'Steam.voteupWorkshop');
  5863. return true;
  5864. }
  5865. }
  5866. async #toggleCurator(curatorId, doTask = true) {
  5867. try {
  5868. if (!doTask && this.whiteList.curators.includes(curatorId)) {
  5869. scripts_echoLog({
  5870. type: 'whiteList',
  5871. text: 'Steam.unfollowCurator',
  5872. id: curatorId
  5873. });
  5874. return true;
  5875. }
  5876. if (this.#ASF) {
  5877. return await this.#ASF.toggleCurator(curatorId, doTask);
  5878. }
  5879. const logStatus = scripts_echoLog({
  5880. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  5881. text: curatorId
  5882. });
  5883. const {
  5884. result,
  5885. statusText,
  5886. status,
  5887. data
  5888. } = await tools_httpRequest({
  5889. url: 'https://store.steampowered.com/curators/ajaxfollow',
  5890. method: 'POST',
  5891. headers: {
  5892. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5893. },
  5894. data: $.param({
  5895. clanid: curatorId,
  5896. sessionid: this.#auth.storeSessionID,
  5897. follow: doTask
  5898. }),
  5899. dataType: 'json'
  5900. });
  5901. if (result === 'Success') {
  5902. if (data?.status === 200 && data.response?.success?.success === 1) {
  5903. logStatus.success();
  5904. return true;
  5905. }
  5906. logStatus.error(`Error:${data?.statusText}(${data?.response?.success}` || `${data?.status})`);
  5907. return false;
  5908. }
  5909. logStatus.error(`${result}:${statusText}(${status})`);
  5910. return false;
  5911. } catch (error) {
  5912. throwError(error, 'Steam.toggleCurator');
  5913. return false;
  5914. }
  5915. }
  5916. async getCuratorId(path, name) {
  5917. try {
  5918. const logStatus = scripts_echoLog({
  5919. type: 'gettingCuratorId',
  5920. text: `${path}/${name}`
  5921. });
  5922. const curatorId = this.#cache.curator[`${path}/${name}`];
  5923. if (curatorId) {
  5924. logStatus.success();
  5925. return curatorId;
  5926. }
  5927. const {
  5928. result,
  5929. statusText,
  5930. status,
  5931. data
  5932. } = await tools_httpRequest({
  5933. url: `https://store.steampowered.com/${path}/${name}`,
  5934. method: 'GET',
  5935. headers: {
  5936. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5937. }
  5938. });
  5939. if (result === 'Success') {
  5940. if (data?.status === 200) {
  5941. const curatorId = data.responseText.match(/g_pagingData.*?"clanid":([\d]+)/)?.[1];
  5942. if (curatorId) {
  5943. this.#setCache('curator', `${path}/${name}`, curatorId);
  5944. logStatus.success();
  5945. return curatorId;
  5946. }
  5947. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5948. return false;
  5949. }
  5950. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5951. return false;
  5952. }
  5953. logStatus.error(`${result}:${statusText}(${status})`);
  5954. return false;
  5955. } catch (error) {
  5956. throwError(error, 'Steam.getCuratorID');
  5957. return false;
  5958. }
  5959. }
  5960. async #toggleCuratorLike(link, doTask = true) {
  5961. try {
  5962. const [ path, name ] = link.split('/');
  5963. if (!(path && name)) {
  5964. scripts_echoLog({
  5965. text: i18n('errorLink', link)
  5966. });
  5967. return false;
  5968. }
  5969. const curatorId = await this.getCuratorId(path, name);
  5970. if (curatorId) {
  5971. return await this.#toggleCurator(curatorId, doTask);
  5972. }
  5973. return false;
  5974. } catch (error) {
  5975. throwError(error, 'Steam.toggleCuratorLike');
  5976. return false;
  5977. }
  5978. }
  5979. async #getAnnouncementParams(appId, viewId) {
  5980. try {
  5981. const logStatus = scripts_echoLog({
  5982. type: 'gettingAnnouncementParams',
  5983. text: appId,
  5984. id: viewId
  5985. });
  5986. const {
  5987. result,
  5988. statusText,
  5989. status,
  5990. data
  5991. } = await tools_httpRequest({
  5992. 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`,
  5993. method: 'GET',
  5994. responseType: 'json',
  5995. headers: {
  5996. Host: 'store.steampowered.com',
  5997. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  5998. }
  5999. });
  6000. if (result === 'Success') {
  6001. if (data?.status === 200 && data?.response?.success === 1) {
  6002. const {
  6003. clanid,
  6004. gid
  6005. } = data.response.event?.announcement_body || {};
  6006. if (clanid) {
  6007. logStatus.success();
  6008. return {
  6009. clanId: clanid,
  6010. gid: gid
  6011. };
  6012. }
  6013. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6014. return {};
  6015. }
  6016. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6017. return {};
  6018. }
  6019. logStatus.error(`${result}:${statusText}(${status})`);
  6020. return {};
  6021. } catch (error) {
  6022. throwError(error, 'Steam.likeAnnouncement');
  6023. return {};
  6024. }
  6025. }
  6026. async #likeAnnouncement(id) {
  6027. try {
  6028. const [ appId, viewId ] = id.split('/');
  6029. if (!(appId && viewId)) {
  6030. scripts_echoLog({}).error(`${i18n('missParams')}(id)`);
  6031. return false;
  6032. }
  6033. const {
  6034. clanId,
  6035. gid
  6036. } = await this.#getAnnouncementParams(appId, viewId);
  6037. if (!clanId) {
  6038. return false;
  6039. }
  6040. const logStatus = scripts_echoLog({
  6041. type: 'likingAnnouncement',
  6042. text: appId,
  6043. id: viewId
  6044. });
  6045. const {
  6046. result,
  6047. statusText,
  6048. status,
  6049. data
  6050. } = await tools_httpRequest({
  6051. url: `https://store.steampowered.com/updated/ajaxrateupdate/${gid || viewId}`,
  6052. method: 'POST',
  6053. headers: {
  6054. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6055. Host: 'store.steampowered.com',
  6056. Origin: 'https://store.steampowered.com',
  6057. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  6058. },
  6059. data: $.param({
  6060. sessionid: this.#auth.storeSessionID,
  6061. voteup: 1,
  6062. clanid: clanId,
  6063. ajax: 1
  6064. }),
  6065. dataType: 'json'
  6066. });
  6067. if (result === 'Success') {
  6068. if (data?.status === 200 && data.response.success === 1) {
  6069. logStatus.success();
  6070. return true;
  6071. }
  6072. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6073. return false;
  6074. }
  6075. logStatus.error(`${result}:${statusText}(${status})`);
  6076. return false;
  6077. } catch (error) {
  6078. throwError(error, 'Steam.likeAnnouncement');
  6079. return false;
  6080. }
  6081. }
  6082. async #appid2subid(id) {
  6083. try {
  6084. const logStatus = scripts_echoLog({
  6085. type: 'gettingSubid',
  6086. text: id
  6087. });
  6088. const {
  6089. result,
  6090. statusText,
  6091. status,
  6092. data
  6093. } = await tools_httpRequest({
  6094. url: `https://store.steampowered.com/app/${id}`,
  6095. method: 'GET',
  6096. headers: {
  6097. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  6098. }
  6099. });
  6100. if (result === 'Success') {
  6101. if (data?.status === 200) {
  6102. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6103. logStatus.warning(i18n('changeAreaNotice'));
  6104. const result = await this.#changeArea();
  6105. if (!result || result === 'CN' || result === 'skip') {
  6106. return false;
  6107. }
  6108. return await this.#appid2subid(id);
  6109. }
  6110. const subid = data.responseText.match(/name="subid" value="([\d]+?)"/)?.[1];
  6111. if (subid) {
  6112. logStatus.success();
  6113. return subid;
  6114. }
  6115. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6116. return false;
  6117. }
  6118. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6119. return false;
  6120. }
  6121. logStatus.error(`${result}:${statusText}(${status})`);
  6122. return false;
  6123. } catch (error) {
  6124. throwError(error, 'Steam.appid2subid');
  6125. return false;
  6126. }
  6127. }
  6128. async #getLicenses() {
  6129. try {
  6130. const logStatus = scripts_echoLog({
  6131. text: i18n('gettingLicenses')
  6132. });
  6133. const {
  6134. result,
  6135. statusText,
  6136. status,
  6137. data
  6138. } = await tools_httpRequest({
  6139. url: `https://store.steampowered.com/dynamicstore/userdata/?t=${new Date().getTime()}`,
  6140. method: 'GET',
  6141. responseType: 'json'
  6142. });
  6143. if (result === 'Success') {
  6144. if (data?.status === 200) {
  6145. logStatus.success();
  6146. return data.response?.rgOwnedPackages;
  6147. }
  6148. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6149. return false;
  6150. }
  6151. logStatus.error(`${result}:${statusText}(${status})`);
  6152. return false;
  6153. } catch (error) {
  6154. throwError(error, 'Steam.getLicenses');
  6155. return false;
  6156. }
  6157. }
  6158. async #addLicense(id) {
  6159. try {
  6160. if (this.#ASF) {
  6161. return await this.#ASF.addLicense(id);
  6162. }
  6163. const [ type, ids ] = id.split('-');
  6164. if (type === 'appid') {
  6165. const subid = await this.#appid2subid(ids);
  6166. if (!subid) {
  6167. return false;
  6168. }
  6169. const logStatus = scripts_echoLog({
  6170. type: 'addingFreeLicense',
  6171. text: ids
  6172. });
  6173. if (!await this.#addFreeLicense(subid, logStatus)) {
  6174. return false;
  6175. }
  6176. const {
  6177. result,
  6178. statusText,
  6179. status,
  6180. data
  6181. } = await tools_httpRequest({
  6182. url: `https://store.steampowered.com/app/${ids}`,
  6183. method: 'GET'
  6184. });
  6185. if (result === 'Success') {
  6186. if (data?.status === 200) {
  6187. if (data.responseText.includes('ds_owned_flag ds_flag') || data.responseText.includes('class="already_in_library"')) {
  6188. logStatus.success();
  6189. return true;
  6190. }
  6191. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6192. return false;
  6193. }
  6194. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6195. return false;
  6196. }
  6197. logStatus.error(`${result}:${statusText}(${status})`);
  6198. return false;
  6199. } else if (type === 'subid') {
  6200. if (this.#area === 'CN') {
  6201. scripts_echoLog({}).success(i18n('tryChangeAreaNotice'));
  6202. await this.#changeArea();
  6203. }
  6204. const logStatusArr = {};
  6205. const idsArr = ids.split(',');
  6206. for (const subid of idsArr) {
  6207. const logStatus = scripts_echoLog({
  6208. type: 'addingFreeLicenseSubid',
  6209. text: subid
  6210. });
  6211. if (!await this.#addFreeLicense(subid, logStatus)) {
  6212. return false;
  6213. }
  6214. logStatusArr[subid] = logStatus;
  6215. }
  6216. const licenses = await this.#getLicenses();
  6217. if (!licenses) {
  6218. return false;
  6219. }
  6220. for (const subid of idsArr) {
  6221. if (licenses.includes(parseInt(subid, 10))) {
  6222. logStatusArr[subid].success();
  6223. } else {
  6224. logStatusArr[subid].error();
  6225. }
  6226. }
  6227. return true;
  6228. }
  6229. return false;
  6230. } catch (error) {
  6231. throwError(error, 'Steam.addLicense');
  6232. return false;
  6233. }
  6234. }
  6235. async #addFreeLicense(id, logStatusPre) {
  6236. try {
  6237. const logStatus = logStatusPre || scripts_echoLog({
  6238. type: 'addingFreeLicenseSubid',
  6239. text: id
  6240. });
  6241. const {
  6242. result,
  6243. statusText,
  6244. status,
  6245. data
  6246. } = await tools_httpRequest({
  6247. url: 'https://store.steampowered.com/checkout/addfreelicense',
  6248. method: 'POST',
  6249. headers: {
  6250. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6251. Host: 'store.steampowered.com',
  6252. Origin: 'https://store.steampowered.com',
  6253. Referer: 'https://store.steampowered.com/account/licenses/'
  6254. },
  6255. data: $.param({
  6256. action: 'add_to_cart',
  6257. sessionid: this.#auth.storeSessionID,
  6258. subid: id
  6259. }),
  6260. dataType: 'json'
  6261. });
  6262. if (result === 'Success') {
  6263. if (data?.status === 200) {
  6264. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6265. logStatus.warning(i18n('changeAreaNotice'));
  6266. const result = await this.#changeArea();
  6267. if (!result || result === 'CN') {
  6268. return false;
  6269. }
  6270. return await this.#addFreeLicense(id);
  6271. }
  6272. logStatus.success();
  6273. return true;
  6274. }
  6275. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6276. return false;
  6277. }
  6278. logStatus.error(`${result}:${statusText}(${status})`);
  6279. return false;
  6280. } catch (error) {
  6281. throwError(error, 'Steam.addFreeLicense');
  6282. return false;
  6283. }
  6284. }
  6285. async #requestPlayTestAccess(id) {
  6286. try {
  6287. if (this.#ASF) {
  6288. return await this.#ASF.requestPlayTestAccess(id);
  6289. }
  6290. const logStatus = scripts_echoLog({
  6291. type: 'requestingPlayTestAccess',
  6292. text: id
  6293. });
  6294. const {
  6295. result,
  6296. statusText,
  6297. status,
  6298. data
  6299. } = await tools_httpRequest({
  6300. url: `https://store.steampowered.com/ajaxrequestplaytestaccess/${id}`,
  6301. method: 'POST',
  6302. headers: {
  6303. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6304. Host: 'store.steampowered.com',
  6305. Origin: 'https://store.steampowered.com',
  6306. Referer: `https://store.steampowered.com/app/${id}`
  6307. },
  6308. data: $.param({
  6309. sessionid: this.#auth.storeSessionID
  6310. }),
  6311. dataType: 'json'
  6312. });
  6313. if (result === 'Success') {
  6314. if (data?.status === 200 && data?.response?.success === 1) {
  6315. logStatus.success();
  6316. return true;
  6317. }
  6318. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6319. return false;
  6320. }
  6321. logStatus.error(`${result}:${statusText}(${status})`);
  6322. return false;
  6323. } catch (error) {
  6324. throwError(error, 'Steam.requestPlayTestAccess');
  6325. return false;
  6326. }
  6327. }
  6328. async toggle({
  6329. doTask = true,
  6330. groupLinks = [],
  6331. officialGroupLinks = [],
  6332. wishlistLinks = [],
  6333. followLinks = [],
  6334. forumLinks = [],
  6335. workshopLinks = [],
  6336. workshopVoteLinks = [],
  6337. curatorLinks = [],
  6338. curatorLikeLinks = [],
  6339. announcementLinks = [],
  6340. licenseLinks = [],
  6341. playtestLinks = []
  6342. }) {
  6343. try {
  6344. if ([ ...groupLinks, ...officialGroupLinks, ...forumLinks, ...workshopLinks, ...workshopVoteLinks ].length > 0 && !this.#communityInitialized) {
  6345. scripts_echoLog({
  6346. text: i18n('needInit')
  6347. });
  6348. return false;
  6349. }
  6350. if ([ ...wishlistLinks, ...followLinks, ...curatorLinks, ...curatorLikeLinks, ...announcementLinks, ...licenseLinks, ...playtestLinks ].length > 0 && !this.#storeInitialized) {
  6351. scripts_echoLog({
  6352. text: i18n('needInit')
  6353. });
  6354. return false;
  6355. }
  6356. const prom = [];
  6357. if (doTask && !globalOptions.doTask.steam.groups || !doTask && !globalOptions.undoTask.steam.groups) {
  6358. scripts_echoLog({
  6359. type: 'globalOptionsSkip',
  6360. text: 'steam.groups'
  6361. });
  6362. } else {
  6363. const realGroups = this.getRealParams('groups', groupLinks, doTask, link => link.match(/groups\/(.+)\/?/)?.[1]);
  6364. if (realGroups.length > 0) {
  6365. for (const group of realGroups) {
  6366. if (doTask) {
  6367. prom.push(this.#joinGroup(group));
  6368. } else {
  6369. prom.push(this.#leaveGroup(group));
  6370. }
  6371. await delay(1e3);
  6372. }
  6373. }
  6374. }
  6375. if (doTask && !globalOptions.doTask.steam.officialGroups || !doTask && !globalOptions.undoTask.steam.officialGroups) {
  6376. scripts_echoLog({
  6377. type: 'globalOptionsSkip',
  6378. text: 'steam.officialGroups'
  6379. });
  6380. } else {
  6381. const realOfficialGroups = this.getRealParams('officialGroups', officialGroupLinks, doTask, link => link.match(/games\/(.+)\/?/)?.[1]);
  6382. if (realOfficialGroups.length > 0) {
  6383. for (const officialGroup of realOfficialGroups) {
  6384. if (doTask) {
  6385. prom.push(this.#joinOfficialGroup(officialGroup));
  6386. } else {
  6387. prom.push(this.#leaveOfficialGroup(officialGroup));
  6388. }
  6389. await delay(1e3);
  6390. }
  6391. }
  6392. }
  6393. if (doTask && !globalOptions.doTask.steam.wishlists || !doTask && !globalOptions.undoTask.steam.wishlists) {
  6394. scripts_echoLog({
  6395. type: 'globalOptionsSkip',
  6396. text: 'steam.wishlists'
  6397. });
  6398. } else {
  6399. const realWishlists = this.getRealParams('wishlists', wishlistLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6400. if (realWishlists.length > 0) {
  6401. for (const game of realWishlists) {
  6402. if (doTask) {
  6403. prom.push(this.#addToWishlist(game));
  6404. } else {
  6405. prom.push(this.#removeFromWishlist(game));
  6406. }
  6407. await delay(1e3);
  6408. }
  6409. }
  6410. }
  6411. if (doTask && !globalOptions.doTask.steam.follows || !doTask && !globalOptions.undoTask.steam.follows) {
  6412. scripts_echoLog({
  6413. type: 'globalOptionsSkip',
  6414. text: 'steam.follows'
  6415. });
  6416. } else {
  6417. const realFollows = this.getRealParams('follows', followLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6418. if (realFollows.length > 0) {
  6419. for (const game of realFollows) {
  6420. prom.push(this.#toggleFollowGame(game, doTask));
  6421. await delay(1e3);
  6422. }
  6423. }
  6424. }
  6425. if (doTask && !globalOptions.doTask.steam.forums || !doTask && !globalOptions.undoTask.steam.forums) {
  6426. scripts_echoLog({
  6427. type: 'globalOptionsSkip',
  6428. text: 'steam.forums'
  6429. });
  6430. } else {
  6431. const realForums = this.getRealParams('forums', forumLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6432. if (realForums.length > 0) {
  6433. for (const forum of realForums) {
  6434. prom.push(this.#toggleForum(forum, doTask));
  6435. await delay(1e3);
  6436. }
  6437. }
  6438. }
  6439. if (doTask && !globalOptions.doTask.steam.workshops || !doTask && !globalOptions.undoTask.steam.workshops) {
  6440. scripts_echoLog({
  6441. type: 'globalOptionsSkip',
  6442. text: 'steam.workshops'
  6443. });
  6444. } else {
  6445. const realWorkshops = this.getRealParams('workshops', workshopLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6446. if (realWorkshops.length > 0) {
  6447. for (const workshop of realWorkshops) {
  6448. prom.push(this.#toggleFavoriteWorkshop(workshop, doTask));
  6449. await delay(1e3);
  6450. }
  6451. }
  6452. }
  6453. if (doTask && !globalOptions.doTask.steam.workshopVotes) {
  6454. scripts_echoLog({
  6455. type: 'globalOptionsSkip',
  6456. text: 'steam.workshopVotes'
  6457. });
  6458. } else {
  6459. const realworkshopVotes = this.getRealParams('workshopVotes', workshopVoteLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6460. if (doTask && realworkshopVotes.length > 0) {
  6461. for (const workshop of realworkshopVotes) {
  6462. prom.push(this.#voteUpWorkshop(workshop));
  6463. await delay(1e3);
  6464. }
  6465. }
  6466. }
  6467. if (doTask && !globalOptions.doTask.steam.curators || !doTask && !globalOptions.undoTask.steam.curators) {
  6468. scripts_echoLog({
  6469. type: 'globalOptionsSkip',
  6470. text: 'steam.curators'
  6471. });
  6472. } else {
  6473. const realCurators = this.getRealParams('curators', curatorLinks, doTask, link => link.match(/curator\/([\d]+)/)?.[1]);
  6474. const realCuratorLikes = this.getRealParams('curatorLikes', curatorLikeLinks, doTask, link => link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3).join('/'));
  6475. if (realCurators.length > 0) {
  6476. for (const curator of realCurators) {
  6477. prom.push(this.#toggleCurator(curator, doTask));
  6478. await delay(1e3);
  6479. }
  6480. }
  6481. if (realCuratorLikes.length > 0) {
  6482. for (const curatorLike of realCuratorLikes) {
  6483. prom.push(this.#toggleCuratorLike(curatorLike, doTask));
  6484. await delay(1e3);
  6485. }
  6486. }
  6487. }
  6488. if (doTask && !globalOptions.doTask.steam.announcements) {
  6489. scripts_echoLog({
  6490. type: 'globalOptionsSkip',
  6491. text: 'steam.announcements'
  6492. });
  6493. } else {
  6494. const realAnnouncements = this.getRealParams('announcements', announcementLinks, doTask, link => {
  6495. if (link.includes('store.steampowered.com')) {
  6496. return link.match(/store\.steampowered\.com\/news\/app\/([\d]+)\/view\/([\d]+)/)?.slice(1, 3).join('/');
  6497. }
  6498. return link.match(/steamcommunity\.com\/games\/([\d]+)\/announcements\/detail\/([\d]+)/)?.slice(1, 3).join('/');
  6499. });
  6500. if (doTask && realAnnouncements.length > 0) {
  6501. for (const id of realAnnouncements) {
  6502. prom.push(this.#likeAnnouncement(id));
  6503. await delay(1e3);
  6504. }
  6505. }
  6506. }
  6507. if (doTask && !globalOptions.doTask.steam.licenses) {
  6508. scripts_echoLog({
  6509. type: 'globalOptionsSkip',
  6510. text: 'steam.licenses'
  6511. });
  6512. } else if (doTask && globalOptions.doTask.steam.licenses && licenseLinks.length > 0) {
  6513. for (const id of licenseLinks) {
  6514. prom.push(this.#addLicense(id));
  6515. await delay(1e3);
  6516. }
  6517. }
  6518. if (doTask && !globalOptions.doTask.steam.playtests) {
  6519. scripts_echoLog({
  6520. type: 'globalOptionsSkip',
  6521. text: 'steam.playtests'
  6522. });
  6523. } else {
  6524. const realPlaytests = this.getRealParams('playtests', playtestLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6525. if (doTask && globalOptions.doTask.steam.playtests && realPlaytests.length > 0) {
  6526. for (const id of realPlaytests) {
  6527. prom.push(this.#requestPlayTestAccess(id));
  6528. await delay(1e3);
  6529. }
  6530. }
  6531. }
  6532. return Promise.all(prom).then(async () => {
  6533. if (this.#area !== 'CN') {
  6534. scripts_echoLog({}).warning(i18n('steamFinishNotice'));
  6535. await this.#changeArea('CN');
  6536. }
  6537. return true;
  6538. });
  6539. } catch (error) {
  6540. throwError(error, 'Steam.toggle');
  6541. return false;
  6542. }
  6543. }
  6544. #setCache(type, name, id) {
  6545. try {
  6546. this.#cache[type][name] = id;
  6547. GM_setValue('steamCache', this.#cache);
  6548. } catch (error) {
  6549. throwError(error, 'Steam.setCache');
  6550. }
  6551. }
  6552. }
  6553. const social_Steam = Steam;
  6554. class Website {
  6555. undoneTasks;
  6556. socialTasks;
  6557. giveawayId;
  6558. socialInitialized = {
  6559. discord: false,
  6560. instagram: false,
  6561. reddit: false,
  6562. twitch: false,
  6563. twitter: false,
  6564. vk: false,
  6565. youtube: false,
  6566. steamStore: false,
  6567. steamCommunity: false
  6568. };
  6569. initialized = false;
  6570. social = {};
  6571. async #bind(name, init) {
  6572. try {
  6573. return {
  6574. name: name,
  6575. result: await init
  6576. };
  6577. } catch (error) {
  6578. throwError(error, 'Website.bind');
  6579. return {
  6580. name: name,
  6581. result: false
  6582. };
  6583. }
  6584. }
  6585. async initSocial(action) {
  6586. try {
  6587. const pro = [];
  6588. const tasks = action === 'do' ? this.undoneTasks : this.socialTasks;
  6589. if (tasks.discord) {
  6590. const hasDiscord = Object.values(tasks.discord).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6591. if (hasDiscord && (!this.socialInitialized.discord || !this.social.discord)) {
  6592. this.social.discord = new social_Discord();
  6593. pro.push(this.#bind('discord', this.social.discord.init(action)));
  6594. }
  6595. }
  6596. if (tasks.instagram) {
  6597. const hasInstagram = Object.values(tasks.instagram).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6598. if (hasInstagram && (!this.socialInitialized.instagram || !this.social.instagram)) {
  6599. this.social.instagram = new social_Instagram();
  6600. pro.push(this.#bind('instagram', this.social.instagram.init()));
  6601. }
  6602. }
  6603. if (tasks.reddit) {
  6604. const hasReddit = Object.values(tasks.reddit).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6605. if (hasReddit && (!this.socialInitialized.reddit || !this.social.reddit)) {
  6606. this.social.reddit = new social_Reddit();
  6607. pro.push(this.#bind('reddit', this.social.reddit.init()));
  6608. }
  6609. }
  6610. if (tasks.twitch) {
  6611. const hasTwitch = Object.values(tasks.twitch).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6612. if (hasTwitch && (!this.socialInitialized.twitch || !this.social.twitch)) {
  6613. this.social.twitch = new social_Twitch();
  6614. pro.push(this.#bind('twitch', this.social.twitch.init()));
  6615. }
  6616. }
  6617. if (tasks.twitter) {
  6618. const hasTwitter = Object.values(tasks.twitter).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6619. if (hasTwitter && (!this.socialInitialized.twitter || !this.social.twitter)) {
  6620. this.social.twitter = new social_Twitter();
  6621. pro.push(this.#bind('twitter', this.social.twitter.init()));
  6622. }
  6623. }
  6624. if (tasks.vk) {
  6625. const hasVk = Object.values(tasks.vk).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6626. if (hasVk && (!this.socialInitialized.vk || !this.social.vk)) {
  6627. this.social.vk = new social_Vk();
  6628. pro.push(this.#bind('vk', this.social.vk.init()));
  6629. }
  6630. }
  6631. if (tasks.youtube) {
  6632. const hasYoutube = Object.values(tasks.youtube).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6633. if (hasYoutube && (!this.socialInitialized.youtube || !this.social.youtube)) {
  6634. this.social.youtube = new Youtube();
  6635. pro.push(this.#bind('youtube', this.social.youtube.init()));
  6636. }
  6637. }
  6638. if (tasks.steam) {
  6639. const steamLength = Object.values(tasks.steam).reduce((total, arr) => [ ...total, ...arr ]).length;
  6640. if (steamLength > 0) {
  6641. if (!this.social.steam) {
  6642. this.social.steam = new social_Steam();
  6643. }
  6644. 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);
  6645. if (steamLength - steamCommunityLength > 0 && !this.socialInitialized.steamStore) {
  6646. pro.push(this.#bind('steamStore', this.social.steam.init('store')));
  6647. }
  6648. if (steamCommunityLength > 0 && !this.socialInitialized.steamCommunity) {
  6649. pro.push(this.#bind('steamCommunity', this.social.steam.init('community')));
  6650. }
  6651. }
  6652. }
  6653. if (tasks.links && tasks.links.length > 0) {
  6654. this.social.visitLink = visitLink;
  6655. }
  6656. return await Promise.all(pro).then(result => {
  6657. let checked = true;
  6658. for (const data of result) {
  6659. if (data.result) {
  6660. this.socialInitialized[data.name] = data.result;
  6661. } else {
  6662. checked = false;
  6663. }
  6664. }
  6665. return checked;
  6666. });
  6667. } catch (error) {
  6668. throwError(error, 'Website.initSocial');
  6669. return false;
  6670. }
  6671. }
  6672. uniqueTasks(allTasks) {
  6673. const result = {};
  6674. for (const [ social, types ] of Object.entries(allTasks)) {
  6675. result[social] = {};
  6676. for (const [ type, tasks ] of Object.entries(types)) {
  6677. result[social][type] = unique(tasks);
  6678. }
  6679. }
  6680. return result;
  6681. }
  6682. async toggleTask(action) {
  6683. try {
  6684. if (!this.initialized && !this.init()) {
  6685. return false;
  6686. }
  6687. if (!await this.classifyTask(action)) {
  6688. return false;
  6689. }
  6690. if (!await this.initSocial(action)) {
  6691. return false;
  6692. }
  6693. const pro = [];
  6694. const doTask = action === 'do';
  6695. const tasks = doTask ? this.undoneTasks : this.socialTasks;
  6696. if (this.socialInitialized.discord !== 'skip' && this.social.discord) {
  6697. pro.push(this.social.discord.toggle({
  6698. doTask: doTask,
  6699. ...tasks.discord
  6700. }));
  6701. }
  6702. if (this.social.instagram) {
  6703. pro.push(this.social.instagram.toggle({
  6704. doTask: doTask,
  6705. ...tasks.instagram
  6706. }));
  6707. }
  6708. if (this.social.reddit) {
  6709. pro.push(this.social.reddit.toggle({
  6710. doTask: doTask,
  6711. ...tasks.reddit
  6712. }));
  6713. }
  6714. if (this.social.twitch) {
  6715. pro.push(this.social.twitch.toggle({
  6716. doTask: doTask,
  6717. ...tasks.twitch
  6718. }));
  6719. }
  6720. if (this.social.twitter) {
  6721. pro.push(this.social.twitter.toggle({
  6722. doTask: doTask,
  6723. ...tasks.twitter
  6724. }));
  6725. }
  6726. if (this.social.vk) {
  6727. pro.push(this.social.vk.toggle({
  6728. doTask: doTask,
  6729. ...tasks.vk
  6730. }));
  6731. }
  6732. if (this.social.youtube) {
  6733. pro.push(this.social.youtube.toggle({
  6734. doTask: doTask,
  6735. ...tasks.youtube
  6736. }));
  6737. }
  6738. if (this.social.steam) {
  6739. pro.push(this.social.steam.toggle({
  6740. doTask: doTask,
  6741. ...tasks.steam
  6742. }));
  6743. }
  6744. if (this.social.visitLink && tasks.links && doTask) {
  6745. for (const link of tasks.links) {
  6746. pro.push(this.social.visitLink(link));
  6747. }
  6748. }
  6749. if (doTask && tasks.extra && this.extraDoTask) {
  6750. const hasExtra = Object.values(tasks.extra).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6751. if (hasExtra) {
  6752. pro.push(this.extraDoTask(tasks.extra));
  6753. }
  6754. }
  6755. await Promise.all(pro);
  6756. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6757. return true;
  6758. } catch (error) {
  6759. throwError(error, 'Website.toggleTask');
  6760. return false;
  6761. }
  6762. }
  6763. async doTask() {
  6764. try {
  6765. return await this.toggleTask('do');
  6766. } catch (error) {
  6767. throwError(error, 'Website.doTask');
  6768. return false;
  6769. }
  6770. }
  6771. async undoTask() {
  6772. try {
  6773. return await this.toggleTask('undo');
  6774. } catch (error) {
  6775. throwError(error, 'Website.undoTask');
  6776. return false;
  6777. }
  6778. }
  6779. }
  6780. const website_Website = Website;
  6781. const defaultTasksTemplate = {
  6782. steam: {
  6783. groupLinks: [],
  6784. wishlistLinks: [],
  6785. curatorLinks: [],
  6786. followLinks: []
  6787. },
  6788. vk: {
  6789. nameLinks: []
  6790. }
  6791. };
  6792. const defaultTasks = JSON.stringify(defaultTasksTemplate);
  6793. class FreeAnyWhere extends website_Website {
  6794. name = 'FreeAnyWhere';
  6795. tasks = [];
  6796. socialTasks = JSON.parse(defaultTasks);
  6797. undoneTasks = JSON.parse(defaultTasks);
  6798. buttons = [ 'doTask', 'undoTask', 'verifyTask', 'getKey' ];
  6799. static test() {
  6800. return window.location.host === 'freeanywhere.net';
  6801. }
  6802. async init() {
  6803. try {
  6804. const logStatus = scripts_echoLog({
  6805. text: i18n('initing')
  6806. });
  6807. if ($('a[href="#/login"]').length > 0) {
  6808. window.open('/#/login', '_self');
  6809. logStatus.warning(i18n('needLogin'));
  6810. return false;
  6811. }
  6812. if (window.location.href.includes('/login')) {
  6813. logStatus.warning(i18n('needLogin'));
  6814. return false;
  6815. }
  6816. if (!/^https?:\/\/freeanywhere\.net\/#\/giveaway\/[\d]+/.test(window.location.href)) {
  6817. const id = window.location.href.match(/https?:\/\/freeanywhere\.net\/.*?#\/giveaway\/([\d]+)/)?.[1];
  6818. if (!id) {
  6819. logStatus.error(i18n('getFailed', 'Id'));
  6820. return false;
  6821. }
  6822. window.location.href = `https://freeanywhere.net/#/giveaway/${id}`;
  6823. }
  6824. if (!this.#getGiveawayId()) {
  6825. return false;
  6826. }
  6827. if (!await this.#checkLeftKey()) {
  6828. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  6829. }
  6830. this.initialized = true;
  6831. logStatus.success();
  6832. return true;
  6833. } catch (error) {
  6834. throwError(error, 'Freeanywhere.init');
  6835. return false;
  6836. }
  6837. }
  6838. async classifyTask(action) {
  6839. try {
  6840. const logStatus = scripts_echoLog({
  6841. text: i18n('getTasksInfo')
  6842. });
  6843. if (action === 'undo') {
  6844. this.socialTasks = GM_getValue(`fawTasks-${this.giveawayId}`)?.tasks || JSON.parse(defaultTasks);
  6845. }
  6846. const {
  6847. result,
  6848. statusText,
  6849. status,
  6850. data
  6851. } = await tools_httpRequest({
  6852. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/?format=json`,
  6853. method: 'GET',
  6854. headers: {
  6855. authorization: `Token ${window.localStorage.getItem('token')}`,
  6856. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  6857. },
  6858. responseType: 'json'
  6859. });
  6860. if (result === 'Success') {
  6861. const tasks = data?.response?.challenges;
  6862. if (tasks) {
  6863. if (action === 'verify') {
  6864. this.tasks = [];
  6865. }
  6866. for (const task of tasks) {
  6867. const type = task.challenge;
  6868. const social = task.challenge_provider;
  6869. const taskInfo = {
  6870. id: task.id,
  6871. title: task.title
  6872. };
  6873. if (action === 'verify' && !task.is_success) {
  6874. this.tasks.push(taskInfo);
  6875. continue;
  6876. }
  6877. switch (social) {
  6878. case 'steam':
  6879. taskInfo.social = 'steam';
  6880. switch (type) {
  6881. case 'WL':
  6882. if (action === 'undo') {
  6883. this.socialTasks.steam.wishlistLinks.push(task.link);
  6884. }
  6885. if (action === 'do' && !task.is_success) {
  6886. this.undoneTasks.steam.wishlistLinks.push(task.link);
  6887. }
  6888. break;
  6889.  
  6890. case 'JTG':
  6891. if (action === 'undo') {
  6892. this.socialTasks.steam.groupLinks.push(task.link);
  6893. }
  6894. if (action === 'do' && !task.is_success) {
  6895. this.undoneTasks.steam.groupLinks.push(task.link);
  6896. }
  6897. break;
  6898.  
  6899. case 'STC':
  6900. if (action === 'undo') {
  6901. this.socialTasks.steam.curatorLinks.push(task.link);
  6902. }
  6903. if (action === 'do' && !task.is_success) {
  6904. this.undoneTasks.steam.curatorLinks.push(task.link);
  6905. }
  6906. break;
  6907.  
  6908. case 'GF':
  6909. if (action === 'undo') {
  6910. this.socialTasks.steam.followLinks.push(task.link);
  6911. }
  6912. if (action === 'do' && !task.is_success) {
  6913. this.undoneTasks.steam.followLinks.push(task.link);
  6914. }
  6915. break;
  6916. }
  6917. break;
  6918.  
  6919. case 'vk-oauth2':
  6920. if (action === 'undo') {
  6921. this.socialTasks.vk.nameLinks.push(task.link);
  6922. }
  6923. if (action === 'do' && !task.is_success) {
  6924. this.undoneTasks.vk.nameLinks.push(task.link);
  6925. }
  6926. break;
  6927.  
  6928. case 'website':
  6929. break;
  6930.  
  6931. default:
  6932. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${social}`);
  6933. break;
  6934. }
  6935. }
  6936. logStatus.success();
  6937. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  6938. this.socialTasks = this.uniqueTasks(this.socialTasks);
  6939. if (window.DEBUG) {
  6940. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  6941. }
  6942. GM_setValue(`fawTasks-${this.giveawayId}`, {
  6943. tasks: this.socialTasks,
  6944. time: new Date().getTime()
  6945. });
  6946. return true;
  6947. }
  6948. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6949. return false;
  6950. }
  6951. logStatus.error(`${result}:${statusText}(${status})`);
  6952. return false;
  6953. } catch (error) {
  6954. throwError(error, 'Freeanywhere.classifyTask');
  6955. return false;
  6956. }
  6957. }
  6958. async verifyTask() {
  6959. try {
  6960. if (!this.initialized && !this.init()) {
  6961. return false;
  6962. }
  6963. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  6964. return false;
  6965. }
  6966. const pro = [];
  6967. for (const task of this.tasks) {
  6968. pro.push(this.#verify(task));
  6969. await delay(1e3);
  6970. }
  6971. await Promise.all(pro);
  6972. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6973. return !!await this.getKey(true);
  6974. } catch (error) {
  6975. throwError(error, 'Freeanywhere.verifyTask');
  6976. return false;
  6977. }
  6978. }
  6979. async getKey(initialized) {
  6980. try {
  6981. if (!initialized && !this.initialized && !this.init()) {
  6982. return false;
  6983. }
  6984. const logStatus = scripts_echoLog({
  6985. text: i18n('gettingKey')
  6986. });
  6987. const {
  6988. result,
  6989. statusText,
  6990. status,
  6991. data
  6992. } = await tools_httpRequest({
  6993. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/reward/?format=json`,
  6994. method: 'GET',
  6995. dataType: 'json',
  6996. headers: {
  6997. authorization: `Token ${window.localStorage.getItem('token')}`
  6998. }
  6999. });
  7000. if (result === 'Success') {
  7001. if (data?.response?.reward) {
  7002. logStatus.success();
  7003. scripts_echoLog({}).success(data.response.reward);
  7004. return data.response.reward;
  7005. }
  7006. if (data?.response?.completed === false) {
  7007. logStatus.error(i18n('tasksNotCompleted'));
  7008. return false;
  7009. }
  7010. if (data?.response?.completed === true) {
  7011. await this.#checkLeftKey();
  7012. }
  7013. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7014. return false;
  7015. }
  7016. logStatus.error(`${result}:${statusText}(${status})`);
  7017. return false;
  7018. } catch (error) {
  7019. throwError(error, 'FreeAnyWhere.getGiveawayId');
  7020. return false;
  7021. }
  7022. }
  7023. #getGiveawayId() {
  7024. try {
  7025. const giveawayId = window.location.href.match(/\/giveaway\/([\d]+)/)?.[1];
  7026. if (giveawayId) {
  7027. this.giveawayId = giveawayId;
  7028. return true;
  7029. }
  7030. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7031. return false;
  7032. } catch (error) {
  7033. throwError(error, 'FreeAnyWhere.getGiveawayId');
  7034. }
  7035. }
  7036. async #verify(task) {
  7037. try {
  7038. const logStatus = scripts_echoLog({
  7039. html: `<li>${i18n('verifyingTask')}${task.title.trim()}...<font></font></li>`
  7040. });
  7041. const {
  7042. result,
  7043. statusText,
  7044. status,
  7045. data
  7046. } = await tools_httpRequest({
  7047. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/challenge-status/${task.id}/?format=json`,
  7048. method: 'GET',
  7049. dataType: 'json',
  7050. headers: {
  7051. authorization: `Token ${window.localStorage.getItem('token')}`,
  7052. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  7053. }
  7054. });
  7055. if (result === 'Success') {
  7056. if (data?.response?.status) {
  7057. logStatus.success();
  7058. return true;
  7059. }
  7060. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7061. return false;
  7062. }
  7063. logStatus.error(`${result}:${statusText}(${status})`);
  7064. return false;
  7065. } catch (error) {
  7066. throwError(error, 'Freeanywhere.verify');
  7067. return false;
  7068. }
  7069. }
  7070. async #checkLeftKey() {
  7071. try {
  7072. if (!globalOptions.other.checkLeftKey) {
  7073. return true;
  7074. }
  7075. const {
  7076. data
  7077. } = await tools_httpRequest({
  7078. url: 'https://freeanywhere.net/api/v1/widget/?format=json',
  7079. method: 'GET',
  7080. dataType: 'json',
  7081. headers: {
  7082. authorization: `Token ${window.localStorage.getItem('token')}`
  7083. }
  7084. });
  7085. if (data?.response?.giveaways.find(giveaway => `${giveaway?.id}` === this.giveawayId)) {
  7086. return true;
  7087. }
  7088. await external_Swal_default().fire({
  7089. icon: 'warning',
  7090. title: i18n('notice'),
  7091. text: i18n('noKeysLeft'),
  7092. confirmButtonText: i18n('confirm'),
  7093. cancelButtonText: i18n('cancel'),
  7094. showCancelButton: true
  7095. }).then(({
  7096. value
  7097. }) => {
  7098. if (value) {
  7099. window.close();
  7100. }
  7101. });
  7102. return true;
  7103. } catch (error) {
  7104. throwError(error, 'Giveawaysu.checkLeftKey');
  7105. return false;
  7106. }
  7107. }
  7108. }
  7109. const Freeanywhere = FreeAnyWhere;
  7110. const Giveawaysu_defaultTasks = {
  7111. steam: {
  7112. groupLinks: [],
  7113. wishlistLinks: [],
  7114. curatorLinks: [],
  7115. curatorLikeLinks: [],
  7116. followLinks: [],
  7117. forumLinks: [],
  7118. announcementLinks: [],
  7119. workshopVoteLinks: [],
  7120. playtestLinks: []
  7121. },
  7122. discord: {
  7123. serverLinks: []
  7124. },
  7125. instagram: {
  7126. userLinks: []
  7127. },
  7128. vk: {
  7129. nameLinks: []
  7130. },
  7131. twitch: {
  7132. channelLinks: []
  7133. },
  7134. reddit: {
  7135. redditLinks: []
  7136. },
  7137. youtube: {
  7138. channelLinks: [],
  7139. likeLinks: []
  7140. },
  7141. twitter: {
  7142. userLinks: [],
  7143. retweetLinks: []
  7144. }
  7145. };
  7146. class GiveawaySu extends website_Website {
  7147. name = 'GiveawaySu';
  7148. socialTasks = Giveawaysu_defaultTasks;
  7149. undoneTasks = Giveawaysu_defaultTasks;
  7150. buttons = [ 'doTask', 'undoTask' ];
  7151. static test() {
  7152. return /^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(window.location.href);
  7153. }
  7154. async after() {
  7155. try {
  7156. if (!this.#checkLogin()) {
  7157. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7158. }
  7159. if (!await this.#checkLeftKey()) {
  7160. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7161. }
  7162. scripts_echoLog({}).warning(i18n('gsNotice'));
  7163. } catch (error) {
  7164. throwError(error, 'Giveawaysu.after');
  7165. }
  7166. }
  7167. init() {
  7168. try {
  7169. const logStatus = scripts_echoLog({
  7170. text: i18n('initing')
  7171. });
  7172. if ($('a.steam-login').length > 0) {
  7173. window.open('/steam/redirect', '_self');
  7174. logStatus.warning(i18n('needLogin'));
  7175. return false;
  7176. }
  7177. if (!this.#getGiveawayId()) {
  7178. return false;
  7179. }
  7180. this.initialized = true;
  7181. logStatus.success();
  7182. return true;
  7183. } catch (error) {
  7184. throwError(error, 'Giveawaysu.init');
  7185. return false;
  7186. }
  7187. }
  7188. async classifyTask(action) {
  7189. try {
  7190. const logStatus = scripts_echoLog({
  7191. text: i18n('getTasksInfo')
  7192. });
  7193. if (action === 'undo') {
  7194. this.socialTasks = GM_getValue(`gasTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  7195. return true;
  7196. }
  7197. const pro = [];
  7198. const tasks = $('#actions tr');
  7199. if ($('div.bind-discord').is(':visible')) {
  7200. $('div.bind-discord a')[0].click();
  7201. }
  7202. if ($('div.bind-twitch').is(':visible')) {
  7203. $('div.bind-twitch a')[0].click();
  7204. }
  7205. for (const task of tasks) {
  7206. pro.push(new Promise(resolve => {
  7207. const td = $(task).find('td:not(".hidden")');
  7208. const colorfulTask = td.eq(1).find('a:not([data-trigger="link"])');
  7209. const colorlessTask = td.eq(2).find('a:not([data-trigger="link"])');
  7210. const taskDes = colorfulTask.length > 0 ? colorfulTask : colorlessTask;
  7211. const taskIcon = td.eq(0).find('i').attr('class') || '';
  7212. const taskName = taskDes.text().trim();
  7213. if (taskIcon.includes('ban') || /disable adblock/gi.test(taskName)) {
  7214. return resolve(true);
  7215. }
  7216. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  7217. if (!taskLink) {
  7218. return resolve(false);
  7219. }
  7220. if (taskIcon.includes('steam') && /join/gi.test(taskName)) {
  7221. this.undoneTasks.steam.groupLinks.push(taskLink);
  7222. } else if (/like.*announcement/gi.test(taskName)) {
  7223. this.undoneTasks.steam.announcementLinks.push(taskLink);
  7224. } else if (/(follow|subscribe).*curator/gim.test(taskName) && /^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  7225. this.undoneTasks.steam.curatorLinks.push(taskLink);
  7226. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  7227. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  7228. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  7229. this.undoneTasks.steam.forumLinks.push(taskLink);
  7230. } else if (taskIcon.includes('thumbs-up') && /^https?:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=[\d]+/.test(taskLink)) {
  7231. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7232. } else if (taskIcon.includes('plus') && /request.*playtest/gim.test(taskName)) {
  7233. this.undoneTasks.steam.playtestLinks.push(taskLink);
  7234. } else if (taskIcon.includes('discord') || /join.*discord/gim.test(taskName)) {
  7235. this.undoneTasks.discord.serverLinks.push(taskLink);
  7236. } else if (taskIcon.includes('instagram') || /follow.*instagram/gim.test(taskName)) {
  7237. this.undoneTasks.instagram.userLinks.push(taskLink);
  7238. } else if (taskIcon.includes('twitch') || /follow.*twitch.*channel/gim.test(taskName)) {
  7239. this.undoneTasks.twitch.channelLinks.push(taskLink);
  7240. } else if (taskIcon.includes('reddit') || /subscribe.*subreddit/gim.test(taskName) || /follow.*reddit/gim.test(taskName)) {
  7241. this.undoneTasks.reddit.redditLinks.push(taskLink);
  7242. } else if (/watch.*art/gim.test(taskName)) {
  7243. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7244. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  7245. this.undoneTasks.youtube.channelLinks.push(taskLink);
  7246. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  7247. this.undoneTasks.youtube.likeLinks.push(taskLink);
  7248. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  7249. this.undoneTasks.vk.nameLinks.push(taskLink);
  7250. } else {
  7251. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  7252. if (/wishlist.*game|add.*wishlist/gim.test(taskName)) {
  7253. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  7254. }
  7255. if (/follow.*button/gim.test(taskName)) {
  7256. this.undoneTasks.steam.followLinks.push(taskLink);
  7257. }
  7258. }
  7259. }
  7260. resolve(true);
  7261. }).catch(error => {
  7262. throwError(error, 'Giveawaysu.classifyTask->getRedirectLink');
  7263. return false;
  7264. });
  7265. }));
  7266. }
  7267. await Promise.all(pro);
  7268. logStatus.success();
  7269. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7270. this.socialTasks = this.undoneTasks;
  7271. if (window.DEBUG) {
  7272. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7273. }
  7274. GM_setValue(`gasTasks-${this.giveawayId}`, {
  7275. tasks: this.socialTasks,
  7276. time: new Date().getTime()
  7277. });
  7278. return true;
  7279. } catch (error) {
  7280. throwError(error, 'Giveawaysu.classifyTask');
  7281. return false;
  7282. }
  7283. }
  7284. #checkLogin() {
  7285. try {
  7286. if (!globalOptions.other.checkLogin) {
  7287. return true;
  7288. }
  7289. if ($('a.steam-login').length > 0) {
  7290. window.open('/steam/redirect', '_self');
  7291. }
  7292. return true;
  7293. } catch (error) {
  7294. throwError(error, 'Giveawaysu.checkLogin');
  7295. return false;
  7296. }
  7297. }
  7298. async #checkLeftKey() {
  7299. try {
  7300. if (!globalOptions.other.checkLeftKey) {
  7301. return true;
  7302. }
  7303. if ($('.giveaway-ended').length > 0 && $('.giveaway-key').length === 0) {
  7304. await external_Swal_default().fire({
  7305. icon: 'warning',
  7306. title: i18n('notice'),
  7307. text: i18n('noKeysLeft'),
  7308. confirmButtonText: i18n('confirm'),
  7309. cancelButtonText: i18n('cancel'),
  7310. showCancelButton: true
  7311. }).then(({
  7312. value
  7313. }) => {
  7314. if (value) {
  7315. window.close();
  7316. }
  7317. });
  7318. }
  7319. return true;
  7320. } catch (error) {
  7321. throwError(error, 'Giveawaysu.checkLeftKey');
  7322. return false;
  7323. }
  7324. }
  7325. #getGiveawayId() {
  7326. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  7327. if (giveawayId) {
  7328. this.giveawayId = giveawayId;
  7329. return true;
  7330. }
  7331. scripts_echoLog({
  7332. text: i18n('getFailed', 'GiveawayId')
  7333. });
  7334. return false;
  7335. }
  7336. }
  7337. class Indiedb {
  7338. name = 'Indiedb';
  7339. buttons = [ 'doTask' ];
  7340. static test() {
  7341. return window.location.host === 'www.indiedb.com';
  7342. }
  7343. async after() {
  7344. try {
  7345. if (!this.#checkLogin()) {
  7346. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7347. }
  7348. if (!await this.#checkLeftKey()) {
  7349. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7350. }
  7351. } catch (error) {
  7352. throwError(error, 'Indiedb.after');
  7353. }
  7354. }
  7355. async doTask() {
  7356. try {
  7357. if (!await this.#join()) {
  7358. return false;
  7359. }
  7360. return await this.#do();
  7361. } catch (error) {
  7362. throwError(error, 'Indiedb.doTask');
  7363. return false;
  7364. }
  7365. }
  7366. async #join() {
  7367. try {
  7368. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7369. scripts_echoLog({}).error(i18n('needLogin'));
  7370. return false;
  7371. }
  7372. const currentoption = $('a.buttonenter.buttongiveaway');
  7373. if (/join giveaway/gim.test(currentoption.text())) {
  7374. const logStatus = scripts_echoLog({
  7375. text: `${i18n('joiningGiveaway')}...`
  7376. });
  7377. const {
  7378. result,
  7379. statusText,
  7380. status,
  7381. data
  7382. } = await tools_httpRequest({
  7383. url: currentoption.attr('href'),
  7384. method: 'POST',
  7385. data: 'ajax=t',
  7386. dataType: 'json',
  7387. headers: {
  7388. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  7389. accept: 'application/json, text/javascript, */*; q=0.01',
  7390. origin: window.location.origin
  7391. }
  7392. });
  7393. if (result === 'Success') {
  7394. if (data?.status === 200) {
  7395. if (data.response?.success) {
  7396. currentoption.addClass('buttonentered').text('Success - Giveaway joined');
  7397. $('#giveawaysjoined').slideDown();
  7398. $('#giveawaysrecommend').slideDown();
  7399. logStatus.success(`Success${data.response?.text ? `:${data.response?.text}` : ''}`);
  7400. return true;
  7401. }
  7402. logStatus.error(`Error${data.response?.text ? `:${data.response?.text}` : ''}`);
  7403. return false;
  7404. }
  7405. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7406. return false;
  7407. }
  7408. logStatus.error(`${result}:${statusText}(${status})`);
  7409. return false;
  7410. } else if (/success/gim.test($('a.buttonenter.buttongiveaway').text())) {
  7411. return true;
  7412. }
  7413. scripts_echoLog({}).warning(i18n('needJoinGiveaway'));
  7414. return false;
  7415. } catch (error) {
  7416. throwError(error, 'Indiedb.init');
  7417. return false;
  7418. }
  7419. }
  7420. async #do() {
  7421. try {
  7422. const id = $('script').map((index, script) => {
  7423. if (/\$\(document\)/gim.test(script.innerHTML)) {
  7424. return [ script.innerHTML.match(/"\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0], script.innerHTML.match(/"\/newsletter\/ajax\/subscribeprofile\/optin\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0] ];
  7425. }
  7426. return null;
  7427. });
  7428. if (id.length === 2) {
  7429. const pro = [];
  7430. const tasks = $('#giveawaysjoined a[class*=promo]');
  7431. for (const task of tasks) {
  7432. const promo = $(task);
  7433. if (!promo.hasClass('buttonentered')) {
  7434. const status = scripts_echoLog({
  7435. text: `${i18n('doing')}:${promo.parents('p').text()}...`
  7436. });
  7437. if (/facebookpromo|twitterpromo|visitpromo/gim.test(task.className)) {
  7438. let text = '';
  7439. if (promo.hasClass('facebookpromo')) {
  7440. text = 'facebookpromo';
  7441. } else if (promo.hasClass('twitterpromo')) {
  7442. text = 'twitterpromo';
  7443. } else {
  7444. text = 'visitpromo';
  7445. }
  7446. pro.push(new Promise(resolve => {
  7447. $.ajax({
  7448. type: 'POST',
  7449. url: urlPath(`/giveaways/ajax/${text}/${id[0]}`),
  7450. timeout: 6e4,
  7451. dataType: 'json',
  7452. data: {
  7453. ajax: 't'
  7454. },
  7455. error(response, error, exception) {
  7456. if (window.DEBUG) {
  7457. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7458. response: response,
  7459. error: error,
  7460. exception: exception
  7461. });
  7462. }
  7463. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7464. resolve(true);
  7465. },
  7466. success(response) {
  7467. if (response.success) {
  7468. status.success(`Success:${response.text}`);
  7469. promo.addClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7470. resolve(true);
  7471. } else {
  7472. status.error(`Error:${response.text}`);
  7473. resolve(true);
  7474. }
  7475. }
  7476. });
  7477. }));
  7478. } else if (promo.hasClass('emailoptinpromo')) {
  7479. pro.push(new Promise(resolve => {
  7480. $.ajax({
  7481. type: 'POST',
  7482. url: urlPath(`/newsletter/ajax/subscribeprofile/optin/${id[1]}`),
  7483. timeout: 6e4,
  7484. dataType: 'json',
  7485. data: {
  7486. ajax: 't',
  7487. emailsystoggle: 4
  7488. },
  7489. error(response, error, exception) {
  7490. if (window.DEBUG) {
  7491. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7492. response: response,
  7493. error: error,
  7494. exception: exception
  7495. });
  7496. }
  7497. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7498. resolve(true);
  7499. },
  7500. success(response) {
  7501. if (response.success) {
  7502. status.success(`Success:${response.text}`);
  7503. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7504. resolve(true);
  7505. } else {
  7506. status.error(`Error:${response.text}`);
  7507. resolve(true);
  7508. }
  7509. }
  7510. });
  7511. }));
  7512. } else if (promo.hasClass('watchingpromo')) {
  7513. pro.push(new Promise(resolve => {
  7514. const data = getUrlQuery(promo.attr('href'));
  7515. data.ajax = 't';
  7516. $.ajax({
  7517. type: 'POST',
  7518. url: urlPath(promo.attr('href')?.split(/[?#]/)[0]),
  7519. timeout: 6e4,
  7520. dataType: 'json',
  7521. data: data,
  7522. error(response, error, exception) {
  7523. if (window.DEBUG) {
  7524. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7525. response: response,
  7526. error: error,
  7527. exception: exception
  7528. });
  7529. }
  7530. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7531. resolve(true);
  7532. },
  7533. success(response) {
  7534. if (response.success) {
  7535. status.success(`Success:${response.text}`);
  7536. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7537. resolve(true);
  7538. } else {
  7539. status.error(`Error:${response.text}`);
  7540. resolve(true);
  7541. }
  7542. }
  7543. });
  7544. }));
  7545. } else if (!/the-challenge-of-adblock/gim.test(promo.attr('href'))) {
  7546. pro.push(new Promise(resolve => {
  7547. $.ajax({
  7548. type: 'POST',
  7549. url: urlPath(promo.attr('href')),
  7550. timeout: 6e4,
  7551. dataType: 'json',
  7552. data: {
  7553. ajax: 't'
  7554. },
  7555. error(response, error, exception) {
  7556. if (window.DEBUG) {
  7557. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7558. response: response,
  7559. error: error,
  7560. exception: exception
  7561. });
  7562. }
  7563. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7564. resolve(true);
  7565. },
  7566. success(response) {
  7567. if (response.success) {
  7568. status.success(`Success:${response.text}`);
  7569. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7570. resolve(true);
  7571. } else {
  7572. status.error(`Error:${response.text}`);
  7573. resolve(true);
  7574. }
  7575. }
  7576. });
  7577. }));
  7578. } else {
  7579. status.error(`Error:${i18n('unKnownTaskType')}`);
  7580. }
  7581. }
  7582. }
  7583. await Promise.all(pro);
  7584. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7585. return true;
  7586. }
  7587. scripts_echoLog({}).error(i18n('getFailed', 'TaskId'));
  7588. return false;
  7589. } catch (error) {
  7590. throwError(error, 'Indiedb.classifyTask');
  7591. return false;
  7592. }
  7593. }
  7594. #checkLogin() {
  7595. try {
  7596. if (!globalOptions.other.checkLogin) {
  7597. return true;
  7598. }
  7599. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7600. window.open('/members/login', '_self');
  7601. }
  7602. return true;
  7603. } catch (error) {
  7604. throwError(error, 'Indiedb.checkLogin');
  7605. return false;
  7606. }
  7607. }
  7608. async #checkLeftKey() {
  7609. try {
  7610. if (!globalOptions.other.checkLeftKey) {
  7611. return true;
  7612. }
  7613. if ($('a.buttonenter:contains("next time"),a.buttonenter:contains("Giveaway is closed")').length > 0) {
  7614. await external_Swal_default().fire({
  7615. icon: 'warning',
  7616. title: i18n('notice'),
  7617. text: i18n('giveawayEnded'),
  7618. confirmButtonText: i18n('confirm'),
  7619. cancelButtonText: i18n('cancel'),
  7620. showCancelButton: true
  7621. }).then(({
  7622. value
  7623. }) => {
  7624. if (value) {
  7625. window.close();
  7626. }
  7627. });
  7628. }
  7629. return true;
  7630. } catch (error) {
  7631. throwError(error, 'Indiedb.checkLeftKey');
  7632. return false;
  7633. }
  7634. }
  7635. }
  7636. const website_Indiedb = Indiedb;
  7637. const Keyhub_defaultTasksTemplate = {
  7638. steam: {
  7639. groupLinks: [],
  7640. officialGroupLinks: [],
  7641. wishlistLinks: [],
  7642. curatorLinks: []
  7643. },
  7644. discord: {
  7645. serverLinks: []
  7646. },
  7647. extra: {
  7648. videoTasks: []
  7649. },
  7650. links: []
  7651. };
  7652. const Keyhub_defaultTasks = JSON.stringify(Keyhub_defaultTasksTemplate);
  7653. class Keyhub extends website_Website {
  7654. name = 'Keyhub';
  7655. socialTasks = JSON.parse(Keyhub_defaultTasks);
  7656. undoneTasks = JSON.parse(Keyhub_defaultTasks);
  7657. buttons = [ 'doTask', 'undoTask' ];
  7658. static test() {
  7659. return window.location.host === 'key-hub.eu';
  7660. }
  7661. async after() {
  7662. try {
  7663. if (!this.#checkLogin()) {
  7664. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7665. }
  7666. if (!await this.#checkLeftKey()) {
  7667. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7668. }
  7669. $('.NSFW').hide();
  7670. } catch (error) {
  7671. throwError(error, 'Keyhub.after');
  7672. }
  7673. }
  7674. init() {
  7675. try {
  7676. const logStatus = scripts_echoLog({
  7677. text: i18n('initing')
  7678. });
  7679. if ($('a[href*="/connect/steam"]').length > 0) {
  7680. window.open('/connect/steam', '_self');
  7681. logStatus.warning(i18n('needLogin'));
  7682. return false;
  7683. }
  7684. if (!this.#getGiveawayId()) {
  7685. return false;
  7686. }
  7687. $('#VPNoverlay').hide();
  7688. $('#mainArticleSection').show();
  7689. this.initialized = true;
  7690. logStatus.success();
  7691. return true;
  7692. } catch (error) {
  7693. throwError(error, 'Keyhub.init');
  7694. return false;
  7695. }
  7696. }
  7697. async classifyTask(action) {
  7698. try {
  7699. const logStatus = scripts_echoLog({
  7700. text: i18n('getTasksInfo')
  7701. });
  7702. if (action === 'undo') {
  7703. this.socialTasks = GM_getValue(`khTasks-${this.giveawayId}`)?.tasks || JSON.parse(Keyhub_defaultTasks);
  7704. }
  7705. const tasks = $('.task:not(".googleads")').filter((index, element) => action === 'do' ? $(element).find('i.fa-check-circle:visible').length === 0 : true).find('a');
  7706. for (const task of tasks) {
  7707. let link = $(task).attr('href');
  7708. const taskDes = $(task).text().trim();
  7709. if (!link) {
  7710. continue;
  7711. }
  7712. if (/\/away\?data=/.test(link) || /steamcommunity\.com\/gid\//.test(link)) {
  7713. link = await getRedirectLink(link) || link;
  7714. }
  7715. if (/https?:\/\/key-hub\.eu\/connect\/discord/.test(link)) {
  7716. window.open(link, '_blank');
  7717. } else if (/steamcommunity\.com\/groups\//.test(link)) {
  7718. if (action === 'undo') {
  7719. this.socialTasks.steam.groupLinks.push(link);
  7720. }
  7721. if (action === 'do') {
  7722. this.undoneTasks.steam.groupLinks.push(link);
  7723. }
  7724. } else if (/steamcommunity\.com\/games\/[\d]+/.test(link)) {
  7725. if (action === 'undo') {
  7726. this.socialTasks.steam.officialGroupLinks.push(link);
  7727. }
  7728. if (action === 'do') {
  7729. this.undoneTasks.steam.officialGroupLinks.push(link);
  7730. }
  7731. } else if (/store\.steampowered\.com\/app\//.test(link) && /wishlist/gim.test(taskDes)) {
  7732. if (action === 'undo') {
  7733. this.socialTasks.steam.wishlistLinks.push(link);
  7734. }
  7735. if (action === 'do') {
  7736. this.undoneTasks.steam.wishlistLinks.push(link);
  7737. }
  7738. } else if (/store\.steampowered\.com\/curator\//.test(link)) {
  7739. if (action === 'undo') {
  7740. this.socialTasks.steam.curatorLinks.push(link);
  7741. }
  7742. if (action === 'do') {
  7743. this.undoneTasks.steam.curatorLinks.push(link);
  7744. }
  7745. } else if (/^https?:\/\/discord\.com\/invite\//.test(link)) {
  7746. if (action === 'undo') {
  7747. this.socialTasks.discord.serverLinks.push(link);
  7748. }
  7749. if (action === 'do') {
  7750. this.undoneTasks.discord.serverLinks.push(link);
  7751. }
  7752. } else if (/^javascript:videoTask.+/.test(link)) {
  7753. if (action === 'do') {
  7754. const taskData = link.match(/javascript:videoTask\('.+?','(.+?)'/)?.[1];
  7755. if (taskData) {
  7756. this.undoneTasks.extra.videoTasks.push(taskData);
  7757. }
  7758. }
  7759. } 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 {
  7760. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  7761. }
  7762. }
  7763. logStatus.success();
  7764. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7765. this.socialTasks = this.uniqueTasks(this.socialTasks);
  7766. if (window.DEBUG) {
  7767. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7768. }
  7769. GM_setValue(`khTasks-${this.giveawayId}`, {
  7770. tasks: this.socialTasks,
  7771. time: new Date().getTime()
  7772. });
  7773. return true;
  7774. } catch (error) {
  7775. throwError(error, 'Keyhub.classifyTask');
  7776. return false;
  7777. }
  7778. }
  7779. async #doScriptTask(data) {
  7780. try {
  7781. const logStatus = scripts_echoLog({
  7782. text: i18n('doingKeyhubTask')
  7783. });
  7784. const {
  7785. result,
  7786. statusText,
  7787. status,
  7788. data: response
  7789. } = await tools_httpRequest({
  7790. url: `/away?data=${data}`,
  7791. method: 'GET',
  7792. headers: {
  7793. origin: 'https://key-hub.eu',
  7794. referer: 'https://key-hub.eu/'
  7795. }
  7796. });
  7797. if (result === 'Success') {
  7798. if (response?.status === 200) {
  7799. logStatus.success();
  7800. return true;
  7801. }
  7802. logStatus.error(`Error:${response?.statusText}(${response?.status})`);
  7803. return false;
  7804. }
  7805. logStatus.error(`${result}:${statusText}(${status})`);
  7806. return false;
  7807. } catch (error) {
  7808. throwError(error, 'Keyhub.doScriptTask');
  7809. return false;
  7810. }
  7811. }
  7812. async extraDoTask({
  7813. videoTasks
  7814. }) {
  7815. try {
  7816. const pro = [];
  7817. for (const data of videoTasks) {
  7818. pro.push(this.#doScriptTask(data));
  7819. }
  7820. return Promise.all(pro).then(() => true);
  7821. } catch (error) {
  7822. throwError(error, 'Keyhub.extraDoTask');
  7823. return false;
  7824. }
  7825. }
  7826. #getGiveawayId() {
  7827. try {
  7828. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  7829. if (giveawayId) {
  7830. this.giveawayId = giveawayId;
  7831. return true;
  7832. }
  7833. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7834. return false;
  7835. } catch (error) {
  7836. throwError(error, 'Keyhub.getGiveawayId');
  7837. return false;
  7838. }
  7839. }
  7840. async #checkLeftKey() {
  7841. try {
  7842. if (!globalOptions.other.checkLeftKey) {
  7843. return true;
  7844. }
  7845. const leftKey = $('#keysleft').text().trim();
  7846. if (leftKey === '0') {
  7847. await external_Swal_default().fire({
  7848. icon: 'warning',
  7849. title: i18n('notice'),
  7850. text: i18n('noKeysLeft'),
  7851. confirmButtonText: i18n('confirm'),
  7852. cancelButtonText: i18n('cancel'),
  7853. showCancelButton: true
  7854. }).then(({
  7855. value
  7856. }) => {
  7857. if (value) {
  7858. window.close();
  7859. }
  7860. });
  7861. }
  7862. return true;
  7863. } catch (error) {
  7864. throwError(error, 'Keyhub.checkLeftKey');
  7865. return false;
  7866. }
  7867. }
  7868. #checkLogin() {
  7869. try {
  7870. if (!globalOptions.other.checkLogin) {
  7871. return true;
  7872. }
  7873. if ($('a[href*="/connect/steam"]').length > 0) {
  7874. window.open('/connect/steam', '_self');
  7875. }
  7876. return true;
  7877. } catch (error) {
  7878. throwError(error, 'Keyhub.checkLogin');
  7879. return false;
  7880. }
  7881. }
  7882. }
  7883. const website_Keyhub = Keyhub;
  7884. const Givekey_defaultTasksTemplate = {
  7885. steam: {
  7886. groupLinks: [],
  7887. wishlistLinks: [],
  7888. curatorLinks: [],
  7889. curatorLikeLinks: []
  7890. },
  7891. twitter: {
  7892. userLinks: []
  7893. },
  7894. vk: {
  7895. nameLinks: []
  7896. },
  7897. discord: {
  7898. serverLinks: []
  7899. }
  7900. };
  7901. const Givekey_defaultTasks = JSON.stringify(Givekey_defaultTasksTemplate);
  7902. class Givekey extends website_Website {
  7903. name = 'Givekey';
  7904. tasks = [];
  7905. socialTasks = JSON.parse(Givekey_defaultTasks);
  7906. undoneTasks = JSON.parse(Givekey_defaultTasks);
  7907. userId;
  7908. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  7909. static test() {
  7910. return window.location.host === 'givekey.ru';
  7911. }
  7912. async after() {
  7913. try {
  7914. await new Promise(resolve => {
  7915. const checker = setInterval(() => {
  7916. if ($('#navbarDropdown').length > 0) {
  7917. clearInterval(checker);
  7918. resolve(true);
  7919. }
  7920. });
  7921. });
  7922. if (!await this.#checkLeftKey()) {
  7923. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7924. }
  7925. } catch (error) {
  7926. throwError(error, 'Givekey.after');
  7927. return false;
  7928. }
  7929. }
  7930. init() {
  7931. try {
  7932. const logStatus = scripts_echoLog({
  7933. text: i18n('initing')
  7934. });
  7935. if ($('a[href*="/auth/steam"]').length > 0) {
  7936. window.open('/auth/steam', '_self');
  7937. logStatus.warning(i18n('needLogin'));
  7938. return false;
  7939. }
  7940. if (!this.#getGiveawayId()) {
  7941. return false;
  7942. }
  7943. const userId = $('meta[name="user-id"]').attr('content');
  7944. if (!userId) {
  7945. logStatus.error(i18n('getFailed', i18n('userId')));
  7946. return false;
  7947. }
  7948. this.userId = userId;
  7949. this.initialized = true;
  7950. logStatus.success();
  7951. return true;
  7952. } catch (error) {
  7953. throwError(error, 'Givekey.init');
  7954. return false;
  7955. }
  7956. }
  7957. async classifyTask(action) {
  7958. try {
  7959. const logStatus = scripts_echoLog({
  7960. text: i18n('getTasksInfo')
  7961. });
  7962. if (action === 'undo') {
  7963. this.socialTasks = GM_getValue(`gkTasks-${this.giveawayId}`)?.tasks || JSON.parse(Givekey_defaultTasks);
  7964. }
  7965. const tasks = $('.card-body:has("button") .row');
  7966. for (const task of tasks) {
  7967. const taskEle = $(task);
  7968. const isSuccess = /Complete/i.test(taskEle.find('button').text().trim());
  7969. if (isSuccess && action !== 'undo') {
  7970. continue;
  7971. }
  7972. const checkButton = taskEle.find('#task_check');
  7973. const taskId = checkButton.attr('data-id');
  7974. if (taskId) {
  7975. this.tasks.push(taskId);
  7976. }
  7977. if (action === 'verify') {
  7978. continue;
  7979. }
  7980. let href = taskEle.find('a').attr('href') || null;
  7981. const text = taskEle.find('a').text().trim();
  7982. const icon = taskEle.find('i');
  7983. if (!href || !text) {
  7984. continue;
  7985. }
  7986. if (/^https?:\/\/givekey\.ru\/giveaway\/[\d]+\/execution_task/.test(href)) {
  7987. href = await getRedirectLink(href);
  7988. }
  7989. if (!href) {
  7990. continue;
  7991. }
  7992. if (/^https?:\/\/vk\.com\//.test(href)) {
  7993. this.socialTasks.vk.nameLinks.push(href);
  7994. if (action === 'do' && !isSuccess) {
  7995. this.undoneTasks.vk.nameLinks.push(href);
  7996. }
  7997. } else if (/^https?:\/\/steamcommunity\.com\/groups/.test(href)) {
  7998. this.socialTasks.steam.groupLinks.push(href);
  7999. if (action === 'do' && !isSuccess) {
  8000. this.undoneTasks.steam.groupLinks.push(href);
  8001. }
  8002. } else if (/^https?:\/\/store\.steampowered\.com\/app\//.test(href)) {
  8003. this.socialTasks.steam.wishlistLinks.push(href);
  8004. if (action === 'do' && !isSuccess) {
  8005. this.undoneTasks.steam.wishlistLinks.push(href);
  8006. }
  8007. } else if (/Subscribe/gi.test(text) && icon.hasClass('fa-steam-square')) {
  8008. if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(href)) {
  8009. this.socialTasks.steam.curatorLinks.push(href);
  8010. if (action === 'do' && !isSuccess) {
  8011. this.undoneTasks.steam.curatorLinks.push(href);
  8012. }
  8013. } else {
  8014. this.socialTasks.steam.curatorLikeLinks.push(href);
  8015. if (action === 'do' && !isSuccess) {
  8016. this.undoneTasks.steam.curatorLikeLinks.push(href);
  8017. }
  8018. }
  8019. } else if (/^https?:\/\/twitter\.com\//.test(href) && /Subscribe/gi.test(text)) {
  8020. this.socialTasks.twitter.userLinks.push(href);
  8021. if (action === 'do' && !isSuccess) {
  8022. this.undoneTasks.twitter.userLinks.push(href);
  8023. }
  8024. } else if (icon.hasClass('fa-discord') || /^https?:\/\/discord\.com\/invite\//.test(href)) {
  8025. this.socialTasks.discord.serverLinks.push(href);
  8026. if (action === 'do' && !isSuccess) {
  8027. this.undoneTasks.discord.serverLinks.push(href);
  8028. }
  8029. } else {
  8030. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${text}(${href})`);
  8031. }
  8032. }
  8033. logStatus.success();
  8034. this.tasks = unique(this.tasks);
  8035. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8036. this.socialTasks = this.uniqueTasks(this.socialTasks);
  8037. if (window.DEBUG) {
  8038. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8039. }
  8040. GM_setValue(`gkTasks-${this.giveawayId}`, {
  8041. tasks: this.socialTasks,
  8042. time: new Date().getTime()
  8043. });
  8044. return true;
  8045. } catch (error) {
  8046. throwError(error, 'Givekey.classifyTask');
  8047. return false;
  8048. }
  8049. }
  8050. async verifyTask() {
  8051. try {
  8052. if (!this.initialized && !this.init()) {
  8053. return false;
  8054. }
  8055. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  8056. return false;
  8057. }
  8058. scripts_echoLog({}).warning(i18n('giveKeyNoticeBefore'));
  8059. const taskLength = this.tasks.length;
  8060. for (let i = 0; i < taskLength; i++) {
  8061. await this.#verify(this.tasks[i]);
  8062. if (i < taskLength - 1) {
  8063. await delay(15e3);
  8064. }
  8065. }
  8066. scripts_echoLog({}).success(i18n('allTasksComplete'));
  8067. scripts_echoLog({
  8068. html: `<li><font class="warning">${i18n('giveKeyNoticeAfter')}</font></li>`
  8069. });
  8070. return true;
  8071. } catch (error) {
  8072. throwError(error, 'Givekey.verifyTask');
  8073. return false;
  8074. }
  8075. }
  8076. async #verify(task) {
  8077. try {
  8078. const logStatus = scripts_echoLog({
  8079. html: `<li>${i18n('verifyingTask')}${task}...<font></font></li>`
  8080. });
  8081. return await new Promise(resolve => {
  8082. $.ajax({
  8083. url: 'https://givekey.ru/giveaway/task',
  8084. method: 'POST',
  8085. data: `id=${task}&user_id=${this.userId}`,
  8086. dataType: 'json',
  8087. headers: {
  8088. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  8089. },
  8090. success: data => {
  8091. if (data.btn) {
  8092. $(`button[data-id=${this.userId}]`).html(data.btn);
  8093. }
  8094. if (data.status === 'ok') {
  8095. $(`.task_check_${data.id}`).html(`<button class="btn btn-success mb-2 btn-block" disabled>${data.btn}</button>`);
  8096. logStatus.success();
  8097. resolve(true);
  8098. } else if (data.status === 'end') {
  8099. logStatus.success();
  8100. scripts_echoLog({}).success(data.key);
  8101. resolve(true);
  8102. } else {
  8103. logStatus.error(`Error:${data.msg}`);
  8104. resolve(false);
  8105. }
  8106. },
  8107. error: xhr => {
  8108. logStatus.error(`Error:${xhr.statusText}(${xhr.status})`);
  8109. resolve(false);
  8110. }
  8111. });
  8112. });
  8113. } catch (error) {
  8114. throwError(error, 'Givekey.verify');
  8115. return false;
  8116. }
  8117. }
  8118. #getGiveawayId() {
  8119. try {
  8120. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  8121. if (giveawayId) {
  8122. this.giveawayId = giveawayId;
  8123. return true;
  8124. }
  8125. scripts_echoLog({
  8126. text: i18n('getFailed', 'GiveawayId')
  8127. });
  8128. return false;
  8129. } catch (error) {
  8130. throwError(error, 'Givekey.getGiveawayId');
  8131. return false;
  8132. }
  8133. }
  8134. async #checkLeftKey() {
  8135. try {
  8136. if (!globalOptions.other.checkLeftKey) {
  8137. return true;
  8138. }
  8139. if (!$('#keys_count').text()) {
  8140. await external_Swal_default().fire({
  8141. icon: 'warning',
  8142. title: i18n('notice'),
  8143. text: i18n('noKeysLeft'),
  8144. confirmButtonText: i18n('confirm'),
  8145. cancelButtonText: i18n('cancel'),
  8146. showCancelButton: true
  8147. }).then(({
  8148. value
  8149. }) => {
  8150. if (value) {
  8151. window.close();
  8152. }
  8153. });
  8154. }
  8155. return true;
  8156. } catch (error) {
  8157. throwError(error, 'Givekey.checkLeftKey');
  8158. return false;
  8159. }
  8160. }
  8161. }
  8162. const website_Givekey = Givekey;
  8163. class GiveeClub extends GiveawaySu {
  8164. name = 'GiveeClub';
  8165. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  8166. static test() {
  8167. return /^https?:\/\/givee\.club\/.*?\/event\/[\d]+/.test(window.location.href);
  8168. }
  8169. async after() {
  8170. try {
  8171. if (!this.#checkLogin()) {
  8172. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8173. }
  8174. if (!await this.#checkLeftKey()) {
  8175. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  8176. }
  8177. } catch (error) {
  8178. throwError(error, 'GiveeClub.after');
  8179. }
  8180. }
  8181. init() {
  8182. try {
  8183. const logStatus = scripts_echoLog({
  8184. text: i18n('initing')
  8185. });
  8186. if (!this.#checkLogin()) {
  8187. logStatus.warning(i18n('needLogin'));
  8188. return false;
  8189. }
  8190. if (!this.#getGiveawayId()) {
  8191. return false;
  8192. }
  8193. this.initialized = true;
  8194. logStatus.success();
  8195. return true;
  8196. } catch (error) {
  8197. throwError(error, 'GiveeClub.init');
  8198. return false;
  8199. }
  8200. }
  8201. async classifyTask(action) {
  8202. try {
  8203. const logStatus = scripts_echoLog({
  8204. text: i18n('getTasksInfo')
  8205. });
  8206. if (action === 'undo') {
  8207. this.socialTasks = GM_getValue(`gcTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  8208. return true;
  8209. }
  8210. const pro = [];
  8211. const tasks = $('.event-actions tr');
  8212. for (const task of tasks) {
  8213. pro.push(new Promise(resolve => {
  8214. const taskDes = $(task).find('.event-action-label a');
  8215. const taskIcon = $(task).find('.event-action-icon i').attr('class') || '';
  8216. const taskName = taskDes.text().trim();
  8217. const taskType = $(task).find('button[data-type]')?.attr('data-type');
  8218. const taskFinished = $(task).find('.event-action-buttons .btn-success')?.length;
  8219. if (taskIcon.includes('ban') || /AdBlock/i.test(taskName) || taskIcon.includes('envelope') || taskFinished) {
  8220. return resolve(true);
  8221. }
  8222. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  8223. if (!taskLink) {
  8224. return resolve(false);
  8225. }
  8226. if (taskType === 'steam.group.join' && /^https?:\/\/steamcommunity\.com\/groups/.test(taskLink)) {
  8227. this.undoneTasks.steam.groupLinks.push(taskLink);
  8228. } else if (/like.*announcement/gi.test(taskName)) {
  8229. this.undoneTasks.steam.announcementLinks.push(taskLink);
  8230. } else if (taskType === 'steam.game.wishlist' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8231. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  8232. } else if (taskType === 'steam.game.wishlist' && taskDes.attr('data-steam-wishlist-appid')) {
  8233. this.undoneTasks.steam.wishlistLinks.push(`https://store.steampowered.com/app/${taskDes.attr('data-steam-wishlist-appid')}`);
  8234. } else if (taskType === 'steam.game.follow' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8235. this.undoneTasks.steam.followLinks.push(taskLink);
  8236. } else if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  8237. this.undoneTasks.steam.curatorLinks.push(taskLink);
  8238. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  8239. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  8240. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  8241. this.undoneTasks.steam.forumLinks.push(taskLink);
  8242. } else if (taskIcon.includes('discord')) {
  8243. this.undoneTasks.discord.serverLinks.push(taskLink);
  8244. } else if (taskIcon.includes('instagram')) {
  8245. this.undoneTasks.instagram.userLinks.push(taskLink);
  8246. } else if (taskIcon.includes('twitch')) {
  8247. this.undoneTasks.twitch.channelLinks.push(taskLink);
  8248. } else if (taskIcon.includes('reddit')) {
  8249. this.undoneTasks.reddit.redditLinks.push(taskLink);
  8250. } else if (/watch.*art/gim.test(taskName)) {
  8251. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8252. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  8253. this.undoneTasks.youtube.channelLinks.push(taskLink);
  8254. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  8255. this.undoneTasks.youtube.likeLinks.push(taskLink);
  8256. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  8257. this.undoneTasks.vk.nameLinks.push(taskLink);
  8258. } else if (taskIcon.includes('twitter')) {
  8259. if (/https?:\/\/twitter\.com\/[^/]+\/?$/gim.test(taskLink)) {
  8260. this.undoneTasks.twitter.userLinks.push(taskLink);
  8261. } else if (/https?:\/\/twitter\.com\/[^/]+?\/status\/[\d]+/gim.test(taskLink)) {
  8262. this.undoneTasks.twitter.retweetLinks.push(taskLink);
  8263. }
  8264. } else {
  8265. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  8266. if (/follow.*button/gim.test(taskName)) {
  8267. this.undoneTasks.steam.followLinks.push(taskLink);
  8268. }
  8269. }
  8270. }
  8271. resolve(true);
  8272. }).catch(error => {
  8273. throwError(error, 'GiveeClub.classifyTask->getRedirectLink');
  8274. return false;
  8275. });
  8276. }));
  8277. }
  8278. await Promise.all(pro);
  8279. logStatus.success();
  8280. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8281. this.socialTasks = this.undoneTasks;
  8282. if (window.DEBUG) {
  8283. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8284. }
  8285. GM_setValue(`gcTasks-${this.giveawayId}`, {
  8286. tasks: this.socialTasks,
  8287. time: new Date().getTime()
  8288. });
  8289. return true;
  8290. } catch (error) {
  8291. throwError(error, 'GiveeClub.classifyTask');
  8292. return false;
  8293. }
  8294. }
  8295. async verifyTask() {
  8296. try {
  8297. const logStatus = scripts_echoLog({
  8298. text: i18n('giveeClubVerifyNotice')
  8299. });
  8300. const taskButtons = $('.event-actions tr button').has('i.glyphicon-refresh').not('[data-type="user.adblock"]');
  8301. for (const button of taskButtons) {
  8302. button.click();
  8303. if ($(button).attr('data-type') !== 'steam.game.wishlist') {
  8304. await delay(1e3);
  8305. }
  8306. }
  8307. logStatus.warning(i18n('giveeClubVerifyFinished'));
  8308. return true;
  8309. } catch (error) {
  8310. throwError(error, 'Givekey.verifyTask');
  8311. return false;
  8312. }
  8313. }
  8314. #checkLogin() {
  8315. try {
  8316. if (!globalOptions.other.checkLogin) {
  8317. return true;
  8318. }
  8319. if ($('a[href*="/account/auth"]').length > 0) {
  8320. window.open($('a[href*="/account/auth"]').attr('href'), '_self');
  8321. }
  8322. return true;
  8323. } catch (error) {
  8324. throwError(error, 'GiveeClub.checkLogin');
  8325. return false;
  8326. }
  8327. }
  8328. #getGiveawayId() {
  8329. const giveawayId = window.location.href.match(/\/event\/([\d]+)/)?.[1];
  8330. if (giveawayId) {
  8331. this.giveawayId = giveawayId;
  8332. return true;
  8333. }
  8334. scripts_echoLog({
  8335. text: i18n('getFailed', 'GiveawayId')
  8336. });
  8337. return false;
  8338. }
  8339. async #checkLeftKey() {
  8340. try {
  8341. if (!globalOptions.other.checkLeftKey) {
  8342. return true;
  8343. }
  8344. if ($('.event-ended').length > 0 && $('.event-winner').length === 0) {
  8345. await external_Swal_default().fire({
  8346. icon: 'warning',
  8347. title: i18n('notice'),
  8348. text: i18n('giveawayEnded'),
  8349. confirmButtonText: i18n('confirm'),
  8350. cancelButtonText: i18n('cancel'),
  8351. showCancelButton: true
  8352. }).then(({
  8353. value
  8354. }) => {
  8355. if (value) {
  8356. window.close();
  8357. }
  8358. });
  8359. }
  8360. return true;
  8361. } catch (error) {
  8362. throwError(error, 'Giveawaysu.checkLeftKey');
  8363. return false;
  8364. }
  8365. }
  8366. }
  8367. const website_GiveeClub = GiveeClub;
  8368. const defaultOptions = {
  8369. maxPoint: '99999999'
  8370. };
  8371. class OpiumPulses {
  8372. name = 'OpiumPulses';
  8373. options = {
  8374. ...defaultOptions,
  8375. ...GM_getValue('OpiumPulsesOptions')
  8376. };
  8377. maxPoints = 99999999;
  8378. myPoints = 0;
  8379. buttons = [ 'doFreeTask', 'doPointTask' ];
  8380. static test() {
  8381. return window.location.host === 'www.opiumpulses.com';
  8382. }
  8383. async after() {
  8384. try {
  8385. if (!this.#checkLogin()) {
  8386. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8387. }
  8388. this.maxPoints = parseInt(this.options.maxPoint, 10);
  8389. } catch (error) {
  8390. throwError(error, 'OpiumPulses.after');
  8391. }
  8392. }
  8393. async doFreeTask() {
  8394. try {
  8395. this.#toggleTask('FREE');
  8396. } catch (error) {
  8397. throwError(error, 'OpiumPulses.doFreeTask');
  8398. }
  8399. }
  8400. async doPointTask() {
  8401. try {
  8402. this.myPoints = parseInt($('.page-header__nav-func-user-nav-items.points-items').text().match(/[\d]+/gim)?.[0] || '0', 10);
  8403. this.#toggleTask('points');
  8404. } catch (error) {
  8405. throwError(error, 'OpiumPulses.doPointTask');
  8406. }
  8407. }
  8408. async #toggleTask(type) {
  8409. try {
  8410. const items = $(`.giveaways-page-item:contains('${type}'):not(:contains('ENTERED'))`);
  8411. for (const item of items) {
  8412. const needPoints = parseInt($(item).find('.giveaways-page-item-header-points').text().match(/[\d]+/gim)?.[0] || '999999', 10);
  8413. const name = $(item).find('.giveaways-page-item-footer-name').text().trim();
  8414. if (type === 'points' && needPoints > this.myPoints) {
  8415. scripts_echoLog({}).warning(`${i18n('noPoints')}: ${name}`);
  8416. } else if (type === 'points' && !needPoints) {
  8417. scripts_echoLog({}).warning(`${i18n('getNeedPointsFailed')}: ${name}`);
  8418. } else if (!(type === 'points' && needPoints > this.maxPoints)) {
  8419. const logStatus = scripts_echoLog({
  8420. text: `${i18n('joiningLottery')}<a href="${$(item).find('a.giveaways-page-item-img-btn-more').attr('href')}" target="_blank">${name}</a>...`
  8421. });
  8422. const aElement = $(item).find('a.giveaways-page-item-img-btn-enter:contains(\'enter\')');
  8423. if (aElement?.attr('onclick')?.includes('checkUser')) {
  8424. const giveawayId = aElement.attr('onclick')?.match(/[\d]+/)?.[0];
  8425. if (giveawayId) {
  8426. checkUser(giveawayId);
  8427. }
  8428. }
  8429. if (!aElement.attr('href')) {
  8430. logStatus.error('Error: No "href".');
  8431. continue;
  8432. }
  8433. const {
  8434. result,
  8435. statusText,
  8436. status,
  8437. data
  8438. } = await tools_httpRequest({
  8439. url: aElement.attr('href'),
  8440. method: 'GET'
  8441. });
  8442. if (result === 'Success') {
  8443. const {
  8444. result: result0,
  8445. statusText: statusText0,
  8446. status: status0,
  8447. data: data0
  8448. } = await tools_httpRequest({
  8449. url: data?.finalUrl,
  8450. method: 'GET'
  8451. });
  8452. if (data0?.responseText && /You've entered this giveaway/gim.test(data0.responseText)) {
  8453. logStatus.success();
  8454. const points = data0.responseText.match(/Points:[\s]*?([\d]+)/)?.[1];
  8455. if (type === 'points' && points) {
  8456. this.myPoints = parseInt(points, 10);
  8457. }
  8458. } else if (data0?.responseText && /You're not eligible to enter/gim.test(data0.responseText)) {
  8459. logStatus.error('You\'re not eligible to enter');
  8460. } else {
  8461. logStatus.error(`${result0}:${statusText0}(${status0})`);
  8462. }
  8463. } else {
  8464. logStatus.error(`${result}:${statusText}(${status})`);
  8465. }
  8466. }
  8467. }
  8468. scripts_echoLog({
  8469. text: '-----END-----'
  8470. });
  8471. } catch (error) {
  8472. throwError(error, 'OpiumPulses.toggleTask');
  8473. }
  8474. }
  8475. init() {
  8476. return true;
  8477. }
  8478. classifyTask() {
  8479. return true;
  8480. }
  8481. #checkLogin() {
  8482. try {
  8483. if (!globalOptions.other.checkLogin) {
  8484. return true;
  8485. }
  8486. if ($('a[href*="/site/login"]').length > 1) {
  8487. window.open('/site/login', '_self');
  8488. }
  8489. return true;
  8490. } catch (error) {
  8491. throwError(error, 'OpiumPulses.checkLogin');
  8492. return false;
  8493. }
  8494. }
  8495. }
  8496. const website_OpiumPulses = OpiumPulses;
  8497. const external_dayjs_namespaceObject = dayjs;
  8498. var external_dayjs_default = __webpack_require__.n(external_dayjs_namespaceObject);
  8499. const leftKeyChecker = {
  8500. async classify(link) {
  8501. try {
  8502. if (/^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(link)) {
  8503. return await this.giveawaySu(link);
  8504. }
  8505. if (/^https?:\/\/givee\.club\/[\w]+?\/event\/[\d]+/.test(link)) {
  8506. return await this.giveeClub(link);
  8507. }
  8508. if (/^https?:\/\/gleam\.io\/.+?\/.+/.test(link)) {
  8509. return await this.gleam(link);
  8510. }
  8511. if (/^https?:\/\/www\.indiedb\.com\/giveaways\/.+/.test(link)) {
  8512. return await this.indieDb(link);
  8513. }
  8514. if (/^https?:\/\/key-hub\.eu\/giveaway\/[\d]+/.test(link)) {
  8515. return await this.keyhub(link);
  8516. }
  8517. if (/^https?:\/\/opquests\.com\/quests\/[\d]+/.test(link)) {
  8518. return await this.opquests(link);
  8519. }
  8520. if (/^https?:\/\/itch\.io\/s\/[\d]+?\/.*/.test(link)) {
  8521. return await this.itch(link);
  8522. }
  8523. return false;
  8524. } catch (error) {
  8525. throwError(error, 'leftKeyChecker.classify');
  8526. return false;
  8527. }
  8528. },
  8529. async giveawaySu(link) {
  8530. try {
  8531. const {
  8532. result,
  8533. data
  8534. } = await tools_httpRequest({
  8535. url: link,
  8536. method: 'GET'
  8537. });
  8538. if (result === 'Success' && data?.status === 200) {
  8539. if (data.responseText.includes('class="steam-login"')) {
  8540. return false;
  8541. }
  8542. if (data.responseText.includes('class="giveaway-ended"')) {
  8543. return 'Ended';
  8544. }
  8545. return 'Active';
  8546. }
  8547. return false;
  8548. } catch (error) {
  8549. throwError(error, 'leftKeyChecker.giveawaySu');
  8550. return false;
  8551. }
  8552. },
  8553. async giveeClub(link) {
  8554. try {
  8555. const {
  8556. result,
  8557. data
  8558. } = await tools_httpRequest({
  8559. url: link,
  8560. method: 'GET'
  8561. });
  8562. if (result === 'Success' && data?.status === 200) {
  8563. if (data.responseText.includes('class="event-winner"')) {
  8564. return 'Won';
  8565. }
  8566. if (data.responseText.includes('class="event-ended"')) {
  8567. return 'Ended';
  8568. }
  8569. return 'Active';
  8570. }
  8571. return false;
  8572. } catch (error) {
  8573. throwError(error, 'leftKeyChecker.giveeClub');
  8574. return false;
  8575. }
  8576. },
  8577. async gleam(link) {
  8578. try {
  8579. const {
  8580. result,
  8581. data
  8582. } = await tools_httpRequest({
  8583. url: link,
  8584. method: 'GET'
  8585. });
  8586. if (result === 'Success' && data?.status === 200) {
  8587. if (/incentives&quot;:{&quot;[\d]+?&quot;:\[&quot;.+?&quot;\]/.test(data.responseText)) {
  8588. return 'Won';
  8589. }
  8590. const campaignDiv = data.responseText.match(/<div class='popup-blocks-container'[\w\W]+?'>/)?.[0];
  8591. if (!campaignDiv) {
  8592. return false;
  8593. }
  8594. const campaignString = $(campaignDiv).attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  8595. if (!campaignString) {
  8596. return false;
  8597. }
  8598. const {
  8599. campaign
  8600. } = JSON.parse(campaignString);
  8601. if (campaign.banned) {
  8602. return 'Banned';
  8603. }
  8604. if (campaign.finished) {
  8605. return 'Ended';
  8606. }
  8607. if (campaign.paused) {
  8608. return 'Paused';
  8609. }
  8610. if (new Date().getTime() < campaign.starts_at * 1e3) {
  8611. return 'NotStart';
  8612. }
  8613. return 'Active';
  8614. }
  8615. return false;
  8616. } catch (error) {
  8617. throwError(error, 'leftKeyChecker.gleam');
  8618. return false;
  8619. }
  8620. },
  8621. async indieDb(link) {
  8622. try {
  8623. const {
  8624. result,
  8625. data
  8626. } = await tools_httpRequest({
  8627. url: link,
  8628. method: 'GET'
  8629. });
  8630. if (result === 'Success' && data?.status === 200) {
  8631. if (data.responseText.includes('Congrats you WON')) {
  8632. return 'Won';
  8633. }
  8634. if (data.responseText.includes('Giveaway is closed') || data.responseText.includes('next time')) {
  8635. return 'Ended';
  8636. }
  8637. return 'Active';
  8638. }
  8639. return false;
  8640. } catch (error) {
  8641. throwError(error, 'leftKeyChecker.indieDb');
  8642. return false;
  8643. }
  8644. },
  8645. async keyhub(link) {
  8646. try {
  8647. const {
  8648. result,
  8649. data
  8650. } = await tools_httpRequest({
  8651. url: link,
  8652. method: 'GET'
  8653. });
  8654. if (result === 'Success' && data?.status === 200) {
  8655. const keysleft = data.responseText.match(/<span id="keysleft">([\d]+?)<\/span>/)?.[1];
  8656. if (!keysleft) {
  8657. return false;
  8658. }
  8659. if (keysleft === '0') {
  8660. return 'Ended';
  8661. }
  8662. return `Active(${keysleft})`;
  8663. }
  8664. return false;
  8665. } catch (error) {
  8666. throwError(error, 'leftKeyChecker.keyhub');
  8667. return false;
  8668. }
  8669. },
  8670. async opquests(link) {
  8671. try {
  8672. const {
  8673. result,
  8674. data
  8675. } = await tools_httpRequest({
  8676. url: link,
  8677. method: 'GET'
  8678. });
  8679. if (result === 'Success' && data?.status === 200) {
  8680. const keysleft = data.responseText.match(/<div class="">[\s]*?([\d]+?)[\s]*?of/)?.[1];
  8681. if (!keysleft) {
  8682. return false;
  8683. }
  8684. if (keysleft === '0') {
  8685. return 'Ended';
  8686. }
  8687. return `Active(${keysleft})`;
  8688. } else if (data?.status === 404) {
  8689. return 'Ended';
  8690. }
  8691. return false;
  8692. } catch (error) {
  8693. throwError(error, 'leftKeyChecker.opquests');
  8694. return false;
  8695. }
  8696. },
  8697. async itch(link) {
  8698. try {
  8699. const {
  8700. result,
  8701. data
  8702. } = await tools_httpRequest({
  8703. url: link,
  8704. method: 'GET'
  8705. });
  8706. if (result === 'Success' && data?.status === 200) {
  8707. const endDate = data.responseText.match(/{"start_date":"[0-9A-Z-:]+?".*?"end_date":"([0-9A-Z-:]+?)".*?}/)?.[1];
  8708. if (!endDate) {
  8709. return false;
  8710. }
  8711. if (new Date().getTime() > new Date(endDate).getTime()) {
  8712. return 'Ended';
  8713. }
  8714. return `Active(${external_dayjs_default()(endDate).format('YYYY-MM-DD HH:mm:ss')})`;
  8715. }
  8716. return false;
  8717. } catch (error) {
  8718. throwError(error, 'leftKeyChecker.opquests');
  8719. return false;
  8720. }
  8721. }
  8722. };
  8723. const website_leftKeyChecker = leftKeyChecker;
  8724. const Keylol_defaultTasksTemplate = {
  8725. steam: {
  8726. groupLinks: [],
  8727. wishlistLinks: [],
  8728. curatorLinks: [],
  8729. curatorLikeLinks: [],
  8730. followLinks: [],
  8731. forumLinks: [],
  8732. announcementLinks: [],
  8733. workshopVoteLinks: [],
  8734. licenseLinks: []
  8735. },
  8736. discord: {
  8737. serverLinks: []
  8738. },
  8739. instagram: {
  8740. userLinks: []
  8741. },
  8742. vk: {
  8743. nameLinks: []
  8744. },
  8745. twitch: {
  8746. channelLinks: []
  8747. },
  8748. reddit: {
  8749. redditLinks: []
  8750. },
  8751. twitter: {
  8752. userLinks: [],
  8753. retweetLinks: []
  8754. },
  8755. youtube: {
  8756. channelLinks: [],
  8757. likeLinks: []
  8758. }
  8759. };
  8760. const Keylol_defaultTasks = JSON.stringify(Keylol_defaultTasksTemplate);
  8761. class Keylol extends website_Website {
  8762. name = 'Keylol';
  8763. socialTasks = JSON.parse(Keylol_defaultTasks);
  8764. undoneTasks = JSON.parse(Keylol_defaultTasks);
  8765. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect' ];
  8766. static test() {
  8767. 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'));
  8768. }
  8769. init() {
  8770. return true;
  8771. }
  8772. after() {
  8773. try {
  8774. const selector = this.name === 'Keylol' ? '#postlist>div[id^="post_"]:first' : 'div.container';
  8775. const mainPost = $(selector);
  8776. const discordLinks = mainPost.find('a[href*="discord.com"]:visible');
  8777. const redditLinks = mainPost.find('a[href*="reddit.com"]:visible');
  8778. const insLinks = mainPost.find('a[href*="instagram.com"]:visible');
  8779. const twitterLinks = mainPost.find('a[href*="twitter.com"]:visible,a[href*="x.com"]:visible');
  8780. const twitchLinks = mainPost.find('a[href*="twitch.tv"]:visible');
  8781. const vkLinks = mainPost.find('a[href*="vk.com"]:visible');
  8782. const steamStoreLinks = mainPost.find('a[href*="store.steampowered.com"]:visible');
  8783. const steamCommunityLinks = mainPost.find('a[href*="steamcommunity.com"]:visible');
  8784. const ytbLinks = mainPost.find('a[href*="youtube.com"]:visible');
  8785. if (discordLinks.length > 0) {
  8786. for (const discordLink of discordLinks) {
  8787. const link = $(discordLink).attr('href');
  8788. if (!(link && /^https?:\/\/discord\.com\/invite\/.+/.test(link))) {
  8789. continue;
  8790. }
  8791. this.#addBtn(discordLink, 'discord', 'serverLinks', link);
  8792. }
  8793. }
  8794. if (redditLinks.length > 0) {
  8795. for (const redditLink of redditLinks) {
  8796. const link = $(redditLink).attr('href');
  8797. if (!(link && /^https?:\/\/www\.reddit\.com\/(r|user)\/.+/.test(link))) {
  8798. continue;
  8799. }
  8800. this.#addBtn(redditLink, 'reddit', 'redditLinks', link);
  8801. }
  8802. }
  8803. if (insLinks.length > 0) {
  8804. for (const insLink of insLinks) {
  8805. const link = $(insLink).attr('href');
  8806. if (!(link && /^https:\/\/www\.instagram\.com\/.+/.test(link))) {
  8807. continue;
  8808. }
  8809. this.#addBtn(insLink, 'instagram', 'userLinks', link);
  8810. }
  8811. }
  8812. if (twitterLinks.length > 0) {
  8813. for (const twitterLink of twitterLinks) {
  8814. const link = $(twitterLink).attr('href');
  8815. if (!(link && /^https:\/\/twitter\.com\/.+/.test(link))) {
  8816. continue;
  8817. }
  8818. if (/https:\/\/twitter\.com\/.*?\/status\/[\d]+/.test(link)) {
  8819. this.#addBtn(twitterLink, 'twitter', 'retweetLinks', link);
  8820. } else {
  8821. this.#addBtn(twitterLink, 'twitter', 'userLinks', link);
  8822. }
  8823. }
  8824. }
  8825. if (twitchLinks.length > 0) {
  8826. for (const twitchLink of twitchLinks) {
  8827. const link = $(twitchLink).attr('href');
  8828. if (!(link && /^https:\/\/(www\.)?twitch\.tv\/.+/.test(link))) {
  8829. continue;
  8830. }
  8831. this.#addBtn(twitchLink, 'twitch', 'channelLinks', link);
  8832. }
  8833. }
  8834. if (vkLinks.length > 0) {
  8835. for (const vkLink of vkLinks) {
  8836. const link = $(vkLink).attr('href');
  8837. if (!(link && /^https:\/\/vk\.com\/.+/.test(link))) {
  8838. continue;
  8839. }
  8840. this.#addBtn(vkLink, 'vk', 'nameLinks', link);
  8841. }
  8842. }
  8843. if (steamStoreLinks.length > 0) {
  8844. for (const steamStoreLink of steamStoreLinks) {
  8845. const link = $(steamStoreLink).attr('href');
  8846. if (!link) {
  8847. continue;
  8848. }
  8849. if (/curator\/[\d]+/.test(link)) {
  8850. this.#addBtn(steamStoreLink, 'steam', 'curatorLinks', link);
  8851. } else if (/(publisher|developer|franchise)\/.+/.test(link)) {
  8852. this.#addBtn(steamStoreLink, 'steam', 'curatorLikeLinks', link);
  8853. } else if (/news(hub)?\/app\/[\d]+\/view\/[\d]+/.test(link)) {
  8854. this.#addBtn(steamStoreLink, 'steam', 'announcementLinks', link);
  8855. } else if (/app\/[\d]+/.test(link)) {
  8856. this.#addBtn(steamStoreLink, 'steam', 'followLinks', link);
  8857. this.#addBtn(steamStoreLink, 'steam', 'wishlistLinks', link);
  8858. }
  8859. }
  8860. }
  8861. if (steamCommunityLinks.length > 0) {
  8862. for (const steamCommunityLink of steamCommunityLinks) {
  8863. const link = $(steamCommunityLink).attr('href');
  8864. if (!link) {
  8865. continue;
  8866. }
  8867. if (/groups\/.+/.test(link)) {
  8868. this.#addBtn(steamCommunityLink, 'steam', 'groupLinks', link);
  8869. } else if (/announcements\/detail\/[\d]+/.test(link)) {
  8870. this.#addBtn(steamCommunityLink, 'steam', 'announcementLinks', link);
  8871. }
  8872. }
  8873. }
  8874. if (ytbLinks.length > 0) {
  8875. for (const ytbLink of ytbLinks) {
  8876. const link = $(ytbLink).attr('href');
  8877. if (!link) {
  8878. continue;
  8879. }
  8880. this.#addBtn(ytbLink, 'youtube', 'channelLinks', link);
  8881. this.#addBtn(ytbLink, 'youtube', 'likeLinks', link);
  8882. }
  8883. }
  8884. 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');
  8885. if (giveawayLinks.length > 0) {
  8886. for (const giveawayLink of giveawayLinks) {
  8887. const link = $(giveawayLink).attr('href');
  8888. if (!link) {
  8889. continue;
  8890. }
  8891. website_leftKeyChecker.classify(link).then(status => {
  8892. if (!status) {
  8893. return;
  8894. }
  8895. if (/^Active/.test(status)) {
  8896. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status active" title="${i18n('Active')}">${status}</font>`);
  8897. return;
  8898. }
  8899. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status not-active" title="${i18n(status)}">${status}</font>`);
  8900. }).catch(error => {
  8901. throwError(error, 'keylol.after -> leftKeyChecker');
  8902. });
  8903. }
  8904. }
  8905. if (this.name === 'Keylol') {
  8906. const asfLinks = mainPost.find('a[href^="#asf"]:visible');
  8907. if (asfLinks.length > 0) {
  8908. for (const asfLink of asfLinks) {
  8909. const link = $(asfLink).attr('href');
  8910. if (!link) {
  8911. continue;
  8912. }
  8913. this.#addBtn($(`a[href="${link}"]`).after('<span style="color: #ccc; margin: 0 -5px 0 5px"> | </span>').next()[0], 'steam', 'licenseLinks', `appid-${link.replace('#asf', '')}`);
  8914. }
  8915. }
  8916. const subLinks = mainPost.find('a[href*="steamdb.info/sub/"]:visible');
  8917. if (subLinks.length > 0) {
  8918. for (const subLink of subLinks) {
  8919. const link = $(subLink).attr('href');
  8920. if (!link) {
  8921. continue;
  8922. }
  8923. const subid = link.match(/^https:\/\/steamdb\.info\/sub\/([\d]+)/)?.[1];
  8924. if (!subid) {
  8925. continue;
  8926. }
  8927. this.#addBtn(subLink, 'steam', 'licenseLinks', `subid-${subid}`);
  8928. }
  8929. }
  8930. const asfLinks2 = mainPost.find('.blockcode:contains("addlicense"):visible');
  8931. if (asfLinks2.length > 0) {
  8932. for (const asfLink of asfLinks2) {
  8933. const subid = asfLink.innerText.match(/[\d]+/g);
  8934. if (!subid || subid.length === 0) {
  8935. continue;
  8936. }
  8937. this.#addBtn($(asfLink).children('em')[0], 'steam', 'licenseLinks', `subid-${subid.join(',')}`);
  8938. }
  8939. }
  8940. }
  8941. } catch (error) {
  8942. throwError(error, 'keylol.after');
  8943. }
  8944. }
  8945. classifyTask(action) {
  8946. try {
  8947. this.socialTasks = JSON.parse(Keylol_defaultTasks);
  8948. this.undoneTasks = JSON.parse(Keylol_defaultTasks);
  8949. const selectedBtns = $('.auto-task-keylol[selected="selected"]:visible');
  8950. for (const btn of selectedBtns) {
  8951. const button = $(btn);
  8952. const social = button.attr('data-social');
  8953. const type = button.attr('data-type');
  8954. const link = button.attr('data-link');
  8955. if (!(social && type && link)) {
  8956. continue;
  8957. }
  8958. if (action === 'do') {
  8959. this.undoneTasks[social][type].push(link);
  8960. }
  8961. if (action === 'undo') {
  8962. this.socialTasks[social][type].push(link);
  8963. }
  8964. }
  8965. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8966. this.socialTasks = this.uniqueTasks(this.socialTasks);
  8967. if (window.DEBUG) {
  8968. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8969. }
  8970. return true;
  8971. } catch (error) {
  8972. throwError(error, 'Keylol.classifyTask');
  8973. return false;
  8974. }
  8975. }
  8976. selectAll() {
  8977. try {
  8978. $('.auto-task-keylol:visible').attr('selected', 'selected');
  8979. } catch (error) {
  8980. throwError(error, 'Keylol.selectAll');
  8981. }
  8982. }
  8983. selectNone() {
  8984. try {
  8985. $('.auto-task-keylol:visible').removeAttr('selected');
  8986. } catch (error) {
  8987. throwError(error, 'Keylol.selectNone');
  8988. }
  8989. }
  8990. invertSelect() {
  8991. try {
  8992. $('.auto-task-keylol:visible').each((index, element) => {
  8993. element.getAttribute('selected') ? element.removeAttribute('selected') : element.setAttribute('selected', 'selected');
  8994. });
  8995. } catch (error) {
  8996. throwError(error, 'Keylol.invertSelect');
  8997. }
  8998. }
  8999. #addBtn(before, social, linkType, link) {
  9000. try {
  9001. $(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>`);
  9002. } catch (error) {
  9003. throwError(error, 'keylol.addBtn');
  9004. }
  9005. }
  9006. }
  9007. const website_Keylol = Keylol;
  9008. const Opquests_defaultTasks = {
  9009. steam: {
  9010. groupLinks: [],
  9011. wishlistLinks: [],
  9012. followLinks: [],
  9013. curatorLikeLinks: []
  9014. }
  9015. };
  9016. class Opquests extends website_Website {
  9017. name = 'Opquests';
  9018. undoneTasks = {
  9019. ...Opquests_defaultTasks
  9020. };
  9021. buttons = [ 'doTask', 'verifyTask', 'getKey' ];
  9022. static test() {
  9023. return window.location.host === 'opquests.com';
  9024. }
  9025. async before() {
  9026. const opquestsVerifyTasks = GM_getValue('opquestsVerifyTasks') || [];
  9027. if (opquestsVerifyTasks.length > 0) {
  9028. const taskId = opquestsVerifyTasks.pop();
  9029. GM_setValue('opquestsVerifyTasks', opquestsVerifyTasks);
  9030. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9031. } else {
  9032. if (GM_getValue('opquestsVerifyTasks')) {
  9033. GM_deleteValue('opquestsVerifyTasks');
  9034. }
  9035. }
  9036. }
  9037. async after() {
  9038. try {
  9039. if (!this.#checkLogin()) {
  9040. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9041. }
  9042. } catch (error) {
  9043. throwError(error, 'Opquests.after');
  9044. }
  9045. }
  9046. init() {
  9047. try {
  9048. const logStatus = scripts_echoLog({
  9049. text: i18n('initing')
  9050. });
  9051. if ($('a[href*="/auth/redirect"]').length > 0) {
  9052. window.open('/auth/redirect', '_self');
  9053. logStatus.warning(i18n('needLogin'));
  9054. return false;
  9055. }
  9056. if (!this.#getGiveawayId()) {
  9057. return false;
  9058. }
  9059. this.initialized = true;
  9060. logStatus.success();
  9061. return true;
  9062. } catch (error) {
  9063. throwError(error, 'Opquests.init');
  9064. return false;
  9065. }
  9066. }
  9067. async classifyTask(action) {
  9068. try {
  9069. if (action === 'undo') {
  9070. scripts_echoLog({
  9071. text: i18n('cannotUndo')
  9072. });
  9073. return false;
  9074. }
  9075. const logStatus = scripts_echoLog({
  9076. text: i18n('getTasksInfo')
  9077. });
  9078. const tasks = $('.w-full:contains("Validate") .items-center');
  9079. for (const task of tasks) {
  9080. const link = $(task).find('a:contains("Open")').attr('href');
  9081. const taskDes = $(task).find('div').eq(1).text().trim();
  9082. if (!link) {
  9083. continue;
  9084. }
  9085. if (/steamcommunity\.com\/groups\//.test(link)) {
  9086. this.undoneTasks.steam.groupLinks.push(link);
  9087. } else if (/store\.steampowered\.com\/app\//.test(link)) {
  9088. if (/wishlist/gim.test(taskDes)) {
  9089. this.undoneTasks.steam.wishlistLinks.push(link);
  9090. } else if (/follow/gim.test(taskDes)) {
  9091. this.undoneTasks.steam.followLinks.push(link);
  9092. }
  9093. } else if (/store\.steampowered\.com\/(publisher|developer|curator)\//.test(link) && /follow/gim.test(taskDes)) {
  9094. this.undoneTasks.steam.curatorLikeLinks.push(link);
  9095. } else {
  9096. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  9097. }
  9098. }
  9099. logStatus.success();
  9100. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9101. if (window.DEBUG) {
  9102. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9103. }
  9104. return true;
  9105. } catch (error) {
  9106. throwError(error, 'Opquests.classifyTask');
  9107. return false;
  9108. }
  9109. }
  9110. async verifyTask() {
  9111. try {
  9112. if (!this.initialized) {
  9113. this.init();
  9114. }
  9115. const tasks = $.makeArray($('div.w-full').find('.items-center').has('button.submit-loader')).map(ele => $(ele).find('input[name="task_id"]').val());
  9116. await this.#confirm();
  9117. const taskId = tasks.pop();
  9118. GM_setValue('opquestsVerifyTasks', tasks);
  9119. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9120. return true;
  9121. } catch (error) {
  9122. throwError(error, 'Opquests.verifyTask');
  9123. return false;
  9124. }
  9125. }
  9126. async #confirm() {
  9127. try {
  9128. const logStatus = scripts_echoLog({
  9129. html: `<li>${i18n('confirmingTask')}...<font></font></li>`
  9130. });
  9131. const {
  9132. result,
  9133. statusText,
  9134. status,
  9135. data
  9136. } = await tools_httpRequest({
  9137. url: `https://opquests.com/quests/${this.giveawayId}?confirm=1`,
  9138. method: 'GET',
  9139. nochche: true,
  9140. headers: {
  9141. origin: 'https://opquests.com',
  9142. referer: `https://opquests.com/warning?id=${this.giveawayId}`
  9143. }
  9144. });
  9145. if (result === 'Success') {
  9146. if (data?.status === 200) {
  9147. logStatus.success();
  9148. return true;
  9149. }
  9150. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9151. return false;
  9152. }
  9153. logStatus.error(`${result}:${statusText}(${status})`);
  9154. return false;
  9155. } catch (error) {
  9156. throwError(error, 'Opquests.confirm');
  9157. return false;
  9158. }
  9159. }
  9160. async getKey(isButton) {
  9161. try {
  9162. const logStatus = scripts_echoLog({
  9163. text: i18n('gettingKey')
  9164. });
  9165. const {
  9166. result,
  9167. statusText,
  9168. status,
  9169. data
  9170. } = await tools_httpRequest({
  9171. url: 'https://opquests.com/keys',
  9172. method: 'GET'
  9173. });
  9174. if (result === 'Success') {
  9175. if (data?.responseText) {
  9176. const key = $(data?.responseText).find(`div.items-center:contains("${$('h1.font-bold').text().trim().replace(' Quest', '')}")`).find('div.font-bold').next().text();
  9177. if (!key) {
  9178. logStatus.error('Error: Key was not found');
  9179. if (isButton) {
  9180. window.open('https://opquests.com/keys', '_self');
  9181. }
  9182. return false;
  9183. }
  9184. logStatus.success();
  9185. scripts_echoLog({}).success(key);
  9186. return true;
  9187. }
  9188. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9189. return false;
  9190. }
  9191. logStatus.error(`${result}:${statusText}(${status})`);
  9192. return false;
  9193. } catch (error) {
  9194. throwError(error, 'Opquests.getGiveawayId');
  9195. return false;
  9196. }
  9197. }
  9198. #getGiveawayId() {
  9199. try {
  9200. const giveawayId = window.location.href.match(/quests\/([\d]+)/)?.[1];
  9201. if (giveawayId) {
  9202. this.giveawayId = giveawayId;
  9203. return true;
  9204. }
  9205. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  9206. return false;
  9207. } catch (error) {
  9208. throwError(error, 'Opquests.getGiveawayId');
  9209. return false;
  9210. }
  9211. }
  9212. #checkLogin() {
  9213. try {
  9214. if (!globalOptions.other.checkLogin) {
  9215. return true;
  9216. }
  9217. if ($('a[href*="/auth/redirect"]').length > 0) {
  9218. window.open('/auth/redirect', '_self');
  9219. }
  9220. return true;
  9221. } catch (error) {
  9222. throwError(error, 'Opquests.checkLogin');
  9223. return false;
  9224. }
  9225. }
  9226. }
  9227. const website_Opquests = Opquests;
  9228. const Gleam_defaultTasksTemplate = {
  9229. steam: {
  9230. groupLinks: [],
  9231. wishlistLinks: [],
  9232. followLinks: [],
  9233. curatorLinks: [],
  9234. curatorLikeLinks: []
  9235. },
  9236. twitter: {
  9237. userLinks: [],
  9238. retweetLinks: []
  9239. },
  9240. twitch: {
  9241. channelLinks: []
  9242. },
  9243. discord: {
  9244. serverLinks: []
  9245. },
  9246. youtube: {
  9247. channelLinks: []
  9248. },
  9249. extra: {
  9250. gleam: []
  9251. }
  9252. };
  9253. const Gleam_defaultTasks = JSON.stringify(Gleam_defaultTasksTemplate);
  9254. class Gleam extends website_Website {
  9255. name = 'Gleam';
  9256. undoneTasks = JSON.parse(Gleam_defaultTasks);
  9257. socialTasks = JSON.parse(Gleam_defaultTasks);
  9258. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  9259. static test() {
  9260. return window.location.host === 'gleam.io';
  9261. }
  9262. before() {
  9263. unsafeWindow.confirm = () => {};
  9264. unsafeWindow.alert = () => {};
  9265. unsafeWindow.prompt = () => {};
  9266. }
  9267. async after() {
  9268. try {
  9269. if (window.location.search.includes('8b07d23f4bfa65f9')) {
  9270. const checkComplete = setInterval(() => {
  9271. if ($('.entry-content .entry-method i.fa-check').length > 0) {
  9272. clearInterval(checkComplete);
  9273. window.close();
  9274. }
  9275. });
  9276. for (const task of $('.entry-content .entry-method')) {
  9277. const taskInfo = $(task).find('.user-links');
  9278. const expandInfo = $(task).find('.expandable');
  9279. const aElements = expandInfo.find('a.btn,a:contains(Continue),button:contains(Continue)');
  9280. if (aElements.length > 0) {
  9281. for (const element of aElements) {
  9282. const $element = $(element);
  9283. const href = $element.attr('href');
  9284. $element.removeAttr('href')[0].click();
  9285. $element.attr('href', href);
  9286. await delay(1e3);
  9287. }
  9288. }
  9289. taskInfo[0].click();
  9290. await delay(1e3);
  9291. }
  9292. scripts_echoLog({}).warning(i18n('gleamTaskNotice'));
  9293. } else if (!await this.#checkLeftKey()) {
  9294. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  9295. }
  9296. } catch (error) {
  9297. throwError(error, 'Gleam.after');
  9298. return false;
  9299. }
  9300. }
  9301. init() {
  9302. try {
  9303. const logStatus = scripts_echoLog({
  9304. text: i18n('initing')
  9305. });
  9306. if (!this.#getGiveawayId()) {
  9307. return false;
  9308. }
  9309. this.initialized = true;
  9310. logStatus.success();
  9311. return true;
  9312. } catch (error) {
  9313. throwError(error, 'Gleam.init');
  9314. return false;
  9315. }
  9316. }
  9317. async classifyTask(action) {
  9318. try {
  9319. const logStatus = scripts_echoLog({
  9320. text: i18n('getTasksInfo')
  9321. });
  9322. if (action === 'undo') {
  9323. this.socialTasks = GM_getValue(`gleamTasks-${this.giveawayId}`)?.tasks || JSON.parse(Gleam_defaultTasks);
  9324. }
  9325. const tasks = $('.entry-content .entry-method');
  9326. for (const task of tasks) {
  9327. const $task = $(task);
  9328. if (action === 'do' && $task.find('i.fa-question').length === 0) {
  9329. continue;
  9330. }
  9331. const socialIcon = $task.find('.icon-wrapper i');
  9332. const taskInfo = $task.find('.user-links');
  9333. const taskText = taskInfo.text().trim();
  9334. const expandInfo = $task.find('.expandable');
  9335. const aElements = expandInfo.find('a.btn');
  9336. if (aElements.length > 0) {
  9337. for (const element of aElements) {
  9338. const $element = $(element);
  9339. const href = $element.attr('href');
  9340. $element.removeAttr('href')[0].click();
  9341. $element.attr('href', href);
  9342. }
  9343. }
  9344. if (socialIcon.hasClass('fa-twitter') || socialIcon.hasClass('fa-x-twitter')) {
  9345. const link = $task.find('a[href^="https://twitter.com/"],a[href^="https://x.com/"]').attr('href');
  9346. if (!link) {
  9347. continue;
  9348. }
  9349. if (/follow/gi.test(taskText)) {
  9350. if (action === 'undo') {
  9351. this.socialTasks.twitter.userLinks.push(link);
  9352. }
  9353. if (action === 'do') {
  9354. this.undoneTasks.twitter.userLinks.push(link);
  9355. }
  9356. } else if (/retweet/gim.test(taskText)) {
  9357. if (action === 'undo') {
  9358. this.socialTasks.twitter.retweetLinks.push(link);
  9359. }
  9360. if (action === 'do') {
  9361. this.undoneTasks.twitter.retweetLinks.push(link);
  9362. }
  9363. }
  9364. } else if (socialIcon.hasClass('fa-twitch')) {
  9365. if (/follow/gim.test(taskText)) {
  9366. const link = $task.find('a[href^="https://twitch.tv/"]').attr('href');
  9367. if (!link) {
  9368. continue;
  9369. }
  9370. if (action === 'undo') {
  9371. this.socialTasks.twitch.channelLinks.push(link);
  9372. }
  9373. if (action === 'do') {
  9374. this.undoneTasks.twitch.channelLinks.push(link);
  9375. }
  9376. }
  9377. } else if (socialIcon.hasClass('fa-discord')) {
  9378. if (/join/gim.test(taskText)) {
  9379. let link = $task.find('a[href^="https://discord.com/invite/"]').attr('href');
  9380. if (!link) {
  9381. const ggLink = $task.find('a[href^="https://discord.gg/"]').attr('href')?.match(/discord\.gg\/([^/]+)/)?.[1];
  9382. if (!ggLink) {
  9383. continue;
  9384. }
  9385. link = `https://discord.com/invite/${ggLink}`;
  9386. }
  9387. if (action === 'undo') {
  9388. this.socialTasks.discord.serverLinks.push(link);
  9389. }
  9390. if (action === 'do') {
  9391. this.undoneTasks.discord.serverLinks.push(link);
  9392. }
  9393. }
  9394. } else if (socialIcon.hasClass('fa-external-link-square-alt')) {
  9395. continue;
  9396. } else if (socialIcon.hasClass('fa-youtube')) {
  9397. if (/subscribe/gim.test(taskText)) {
  9398. const link = $task.find('a[href^="https://www.youtube.com/channel/"]').attr('href');
  9399. if (!link) {
  9400. continue;
  9401. }
  9402. if (action === 'undo') {
  9403. this.socialTasks.youtube.channelLinks.push(link);
  9404. }
  9405. if (action === 'do') {
  9406. this.undoneTasks.youtube.channelLinks.push(link);
  9407. }
  9408. }
  9409. } else if (socialIcon.attr('class')?.includes('steam')) {
  9410. if (/join.*group/gi.test(taskText)) {
  9411. const link = $task.find('a[href^="https://steamcommunity.com/groups/"]').attr('href');
  9412. if (!link) {
  9413. continue;
  9414. }
  9415. if (action === 'undo') {
  9416. this.socialTasks.steam.groupLinks.push(link);
  9417. }
  9418. if (action === 'do') {
  9419. this.undoneTasks.steam.groupLinks.push(link);
  9420. }
  9421. } else if (/follow.*curator/gi.test(taskText)) {
  9422. const link = $task.find('a[href^="https://store.steampowered.com/curator/"]').attr('href');
  9423. if (!link) {
  9424. continue;
  9425. }
  9426. if (action === 'undo') {
  9427. this.socialTasks.steam.curatorLinks.push(link);
  9428. }
  9429. if (action === 'do') {
  9430. this.undoneTasks.steam.curatorLinks.push(link);
  9431. }
  9432. }
  9433. } else if (socialIcon.hasClass('fa-bullhorn') && /Complete/gi.test(taskText)) {
  9434. if (action !== 'do') {
  9435. continue;
  9436. }
  9437. const gleamLink = await this.#getGleamLink(taskText);
  9438. if (!gleamLink) {
  9439. continue;
  9440. }
  9441. this.undoneTasks.extra.gleam.push(gleamLink);
  9442. } 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 {
  9443. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskText}`);
  9444. }
  9445. }
  9446. logStatus.success();
  9447. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9448. this.socialTasks = this.uniqueTasks(this.socialTasks);
  9449. if (window.DEBUG) {
  9450. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9451. }
  9452. GM_setValue(`gleamTasks-${this.giveawayId}`, {
  9453. tasks: this.socialTasks,
  9454. time: new Date().getTime()
  9455. });
  9456. return true;
  9457. } catch (error) {
  9458. throwError(error, 'Gleam.classifyTask');
  9459. return false;
  9460. }
  9461. }
  9462. async extraDoTask({
  9463. gleam
  9464. }) {
  9465. try {
  9466. const pro = [];
  9467. for (const link of gleam) {
  9468. pro.push(this.#doGleamTask(link));
  9469. }
  9470. return Promise.all(pro).then(() => true);
  9471. } catch (error) {
  9472. throwError(error, 'Gleam.extraDoTask');
  9473. return false;
  9474. }
  9475. }
  9476. async verifyTask() {
  9477. try {
  9478. scripts_echoLog({
  9479. text: `${i18n('verifyingTask')}...`
  9480. });
  9481. const tasks = $('.entry-content .entry-method');
  9482. unsafeWindow._OxA = '_OxA';
  9483. for (const task of tasks) {
  9484. if ($('[campaign-key="campaign.key"]').length > 0) {
  9485. return scripts_echoLog({
  9486. text: i18n('campaign')
  9487. });
  9488. }
  9489. const $task = $(task);
  9490. if ($task.find('i.fa-question').length === 0) {
  9491. continue;
  9492. }
  9493. const taskInfo = $task.find('.user-links');
  9494. taskInfo[0].click();
  9495. unsafeWindow.$hookTimer?.setSpeed(1e3);
  9496. await delay(3e3);
  9497. unsafeWindow.$hookTimer?.setSpeed(1);
  9498. const expandInfo = $task.find('.expandable');
  9499. const input = expandInfo.find('input')[0];
  9500. if (input) {
  9501. const evt = new Event('input', {
  9502. bubbles: true,
  9503. cancelable: true,
  9504. composed: true
  9505. });
  9506. const valuelimit = [ ...expandInfo.text().matchAll(/"(.+?)"/g) ].at(-1)?.[1];
  9507. input.value = valuelimit || 'vloot';
  9508. input.dispatchEvent(evt);
  9509. await delay(1e3);
  9510. }
  9511. await this.#checkSync();
  9512. const continueBtn = $task.find('.expandable').find('span:contains(Continue),button:contains(Continue)');
  9513. for (const button of continueBtn) {
  9514. button.click();
  9515. await delay(500);
  9516. await this.#checkSync();
  9517. }
  9518. }
  9519. scripts_echoLog({
  9520. text: i18n('verifiedGleamTasks')
  9521. });
  9522. } catch (error) {
  9523. throwError(error, 'Gleam.verifyTask');
  9524. return false;
  9525. }
  9526. }
  9527. async #checkSync() {
  9528. try {
  9529. return await new Promise(resolve => {
  9530. const checker = setInterval(() => {
  9531. if ($('.entry-content .entry-method i.fa-sync').length === 0) {
  9532. clearInterval(checker);
  9533. resolve(true);
  9534. }
  9535. }, 500);
  9536. });
  9537. } catch (error) {
  9538. throwError(error, 'Gleam.checkSync');
  9539. return false;
  9540. }
  9541. }
  9542. async #doGleamTask(link) {
  9543. try {
  9544. const logStatus = scripts_echoLog({
  9545. text: i18n('doingGleamTask')
  9546. });
  9547. return await new Promise(resolve => {
  9548. GM_openInTab(`${link}?8b07d23f4bfa65f9`, {
  9549. active: true,
  9550. insert: true,
  9551. setParent: true
  9552. }).onclose = () => {
  9553. logStatus.success();
  9554. resolve(true);
  9555. };
  9556. });
  9557. } catch (error) {
  9558. throwError(error, 'Gleam.doGleamTask');
  9559. return false;
  9560. }
  9561. }
  9562. #getGiveawayId() {
  9563. try {
  9564. const giveawayId = window.location.pathname;
  9565. if (giveawayId) {
  9566. this.giveawayId = giveawayId;
  9567. return true;
  9568. }
  9569. scripts_echoLog({
  9570. text: i18n('getFailed', 'GiveawayId')
  9571. });
  9572. return false;
  9573. } catch (error) {
  9574. throwError(error, 'Gleam.getGiveawayId');
  9575. return false;
  9576. }
  9577. }
  9578. async #getGleamLink(title) {
  9579. try {
  9580. const logStatus = scripts_echoLog({
  9581. text: i18n('gettingGleamLink')
  9582. });
  9583. const {
  9584. result,
  9585. statusText,
  9586. status,
  9587. data
  9588. } = await tools_httpRequest({
  9589. url: 'https://www.vloot.io/api/v1/giveaways',
  9590. method: 'GET',
  9591. responseType: 'json'
  9592. });
  9593. if (result === 'Success') {
  9594. if (data?.status === 200 && data?.response?.Success === true && data?.response?.Data) {
  9595. const {
  9596. link
  9597. } = data.response.Data.find(giveaway => title.replace(/[\s]/g, '').toLowerCase().includes(giveaway.title.replace(/[\s]/g, '').toLowerCase())) || {};
  9598. if (link) {
  9599. logStatus.success();
  9600. return link;
  9601. }
  9602. logStatus.error(`Error:${i18n('getLinkFailed')}`);
  9603. return false;
  9604. }
  9605. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9606. return false;
  9607. }
  9608. logStatus.error(`${result}:${statusText}(${status})`);
  9609. return false;
  9610. } catch (error) {
  9611. throwError(error, 'Gleam.getGleamLink');
  9612. return false;
  9613. }
  9614. }
  9615. async #checkLeftKey() {
  9616. try {
  9617. if (!globalOptions.other.checkLeftKey) {
  9618. return true;
  9619. }
  9620. const campaignString = $('div.popup-blocks-container').attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  9621. if (!campaignString) {
  9622. return false;
  9623. }
  9624. const {
  9625. campaign,
  9626. incentive
  9627. } = JSON.parse(campaignString);
  9628. const controllerString = $('div.campaign.reward').attr('ng-init')?.match(/initContestant\(([\w\W]+?)\);/)?.[1];
  9629. let ownedKey = false;
  9630. if (controllerString) {
  9631. if (JSON.parse(controllerString).contestant?.claims?.incentives?.[incentive.id]?.length) {
  9632. ownedKey = true;
  9633. }
  9634. }
  9635. if (campaign.banned || campaign.finished && !ownedKey || campaign.paused || new Date().getTime() < campaign.starts_at * 1e3) {
  9636. await external_Swal_default().fire({
  9637. icon: 'warning',
  9638. title: i18n('notice'),
  9639. text: i18n('giveawayNotWork'),
  9640. confirmButtonText: i18n('confirm'),
  9641. cancelButtonText: i18n('cancel'),
  9642. showCancelButton: true
  9643. }).then(({
  9644. value
  9645. }) => {
  9646. if (value) {
  9647. window.close();
  9648. }
  9649. });
  9650. }
  9651. return true;
  9652. } catch (error) {
  9653. throwError(error, 'Gleam.checkLeftKey');
  9654. return false;
  9655. }
  9656. }
  9657. }
  9658. const website_Gleam = Gleam;
  9659. const SweepWidget_defaultOptions = {
  9660. username: '',
  9661. email: ''
  9662. };
  9663. class SweepWidget extends website_Website {
  9664. name = 'SweepWidget';
  9665. options = {
  9666. ...SweepWidget_defaultOptions,
  9667. ...GM_getValue('SweepWidgetOptions')
  9668. };
  9669. buttons = [ 'doTask' ];
  9670. static test() {
  9671. return /^https?:\/\/sweepwidget\.com\/view\/[\d]+/.test(window.location.href);
  9672. }
  9673. async after() {
  9674. try {
  9675. if (!this.#checkLogin()) {
  9676. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9677. }
  9678. } catch (error) {
  9679. throwError(error, 'SweepWidget.after');
  9680. }
  9681. }
  9682. init() {
  9683. try {
  9684. const logStatus = scripts_echoLog({
  9685. text: i18n('initing')
  9686. });
  9687. if (!this.#checkLogin()) {
  9688. logStatus.warning(i18n('needLogin'));
  9689. return false;
  9690. }
  9691. if (!this.#getGiveawayId()) {
  9692. return false;
  9693. }
  9694. this.initialized = true;
  9695. logStatus.success();
  9696. return true;
  9697. } catch (error) {
  9698. throwError(error, 'SweepWidget.init');
  9699. return false;
  9700. }
  9701. }
  9702. classifyTask() {
  9703. return true;
  9704. }
  9705. async doTask() {
  9706. try {
  9707. if ($('#unlock_rewards_main_wrapper').length === 0) {
  9708. if ($('input[name="sw__login_name"]:visible').length > 0) {
  9709. $('input[name="sw__login_name"]').val(this.options.username);
  9710. }
  9711. if ($('input[name="sw__login_email"]:visible').length > 0) {
  9712. $('input[name="sw__login_email"]').val(this.options.email);
  9713. }
  9714. if ($('#sw_login_button:visible').length > 0) {
  9715. $('#sw_login_button')[0].click();
  9716. }
  9717. if (!await this.#checkEnter()) {
  9718. return false;
  9719. }
  9720. }
  9721. const logStatus = scripts_echoLog({
  9722. text: i18n('SweepWidgetNotice')
  9723. });
  9724. const tasks = $('#sw_inner_entry_methods_l2_wrapper>div.sw_entry');
  9725. for (const task of tasks) {
  9726. const $task = $(task);
  9727. if ($task.find('i.fa-check:visible').length > 0) {
  9728. continue;
  9729. }
  9730. const title = $task.find('.sw_text_inner');
  9731. title[0].click();
  9732. const aElement = $task.find('a.sw_link');
  9733. const link = aElement.attr('href');
  9734. aElement.attr('href', '#a').attr('target', '_self');
  9735. aElement[0]?.click();
  9736. await delay(300);
  9737. aElement.attr('href', link).attr('target', '_blank');
  9738. $task.find('input[type="text"]').val('test');
  9739. const verifyBtn = $task.find('input.sw_verify');
  9740. if (verifyBtn.prop('disabled') === true) {
  9741. title[0].click();
  9742. await delay(300);
  9743. title[0].click();
  9744. await delay(300);
  9745. }
  9746. $task.find('input.sw_verify').removeAttr('disabled')[0]?.click();
  9747. await this.#checkFinish($task);
  9748. await delay(parseInt(`${Math.random() * (3e3 - 1e3 + 1) + 1e3}`, 10));
  9749. }
  9750. logStatus.success();
  9751. return true;
  9752. } catch (error) {
  9753. throwError(error, 'SweepWidget.doTask');
  9754. return false;
  9755. }
  9756. }
  9757. #checkLogin() {
  9758. try {
  9759. if ($('#twitter_login_button').length > 0) {
  9760. $('#twitter_login_button')[0].click();
  9761. }
  9762. return true;
  9763. } catch (error) {
  9764. throwError(error, 'SweepWidget.checkLogin');
  9765. return false;
  9766. }
  9767. }
  9768. #getGiveawayId() {
  9769. try {
  9770. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  9771. if (giveawayId) {
  9772. this.giveawayId = giveawayId;
  9773. return true;
  9774. }
  9775. scripts_echoLog({
  9776. text: i18n('getFailed', 'GiveawayId')
  9777. });
  9778. return false;
  9779. } catch (error) {
  9780. throwError(error, 'SweepWidget.getGiveawayId');
  9781. return false;
  9782. }
  9783. }
  9784. async #checkEnter() {
  9785. try {
  9786. return new Promise(resolve => {
  9787. const checker = setInterval(() => {
  9788. if ($('#unlock_rewards_main_wrapper').length > 0) {
  9789. clearInterval(checker);
  9790. resolve(true);
  9791. }
  9792. });
  9793. });
  9794. } catch (error) {
  9795. throwError(error, 'SweepWidget.checkEnter');
  9796. return false;
  9797. }
  9798. }
  9799. async #checkFinish($task) {
  9800. try {
  9801. return new Promise(resolve => {
  9802. const checker = setInterval(() => {
  9803. if ($task.find('i.fa-check:visible').length > 0 || $task.find('.sw_entry_input:visible').length === 0) {
  9804. clearInterval(checker);
  9805. resolve(true);
  9806. }
  9807. });
  9808. });
  9809. } catch (error) {
  9810. throwError(error, 'SweepWidget.checkFinish');
  9811. return false;
  9812. }
  9813. }
  9814. }
  9815. const website_SweepWidget = SweepWidget;
  9816. const defaultWhiteList = {
  9817. discord: {
  9818. servers: []
  9819. },
  9820. instagram: {
  9821. users: []
  9822. },
  9823. twitch: {
  9824. channels: []
  9825. },
  9826. twitter: {
  9827. users: [],
  9828. retweets: [],
  9829. likes: []
  9830. },
  9831. vk: {
  9832. names: []
  9833. },
  9834. youtube: {
  9835. channels: [],
  9836. likes: []
  9837. },
  9838. reddit: {
  9839. reddits: []
  9840. },
  9841. steam: {
  9842. groups: [],
  9843. officialGroups: [],
  9844. wishlists: [],
  9845. follows: [],
  9846. forums: [],
  9847. workshops: [],
  9848. curators: [],
  9849. workshopVotes: [],
  9850. curatorLikes: [],
  9851. announcements: [],
  9852. licenses: [],
  9853. playtests: []
  9854. }
  9855. };
  9856. const link2id = async function(type) {
  9857. try {
  9858. const link = $('#socialLink').val();
  9859. let id = '';
  9860. switch (type) {
  9861. case 'discord.servers':
  9862. id = link.match(/invite\/(.+)/)?.[1] || '';
  9863. break;
  9864.  
  9865. case 'instagram.users':
  9866. id = link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1] || '';
  9867. break;
  9868.  
  9869. case 'twitch.channels':
  9870. id = link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2] || '';
  9871. break;
  9872.  
  9873. case 'twitter.users':
  9874. id = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || '';
  9875. break;
  9876.  
  9877. case 'twitter.retweets':
  9878. id = link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1] || '';
  9879. break;
  9880.  
  9881. case 'vk.names':
  9882. id = link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1] || '';
  9883. break;
  9884.  
  9885. case 'youtube.channels':
  9886. id = (await getInfo(link, 'channel'))?.params?.channelId || '';
  9887. break;
  9888.  
  9889. case 'youtube.likes':
  9890. id = (await getInfo(link, 'likeVideo'))?.params?.videoId || '';
  9891. break;
  9892.  
  9893. case 'reddit.reddits':
  9894. id = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1] || link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1] || '';
  9895. break;
  9896.  
  9897. case 'steam.groups':
  9898. id = link.match(/groups\/(.+)\/?/)?.[1] || '';
  9899. break;
  9900.  
  9901. case 'steam.wishlists':
  9902. case 'steam.follows':
  9903. case 'steam.forums':
  9904. id = link.match(/app\/([\d]+)/)?.[1] || '';
  9905. break;
  9906.  
  9907. case 'steam.workshops':
  9908. id = link.match(/\?id=([\d]+)/)?.[1] || '';
  9909. break;
  9910.  
  9911. case 'steam.curators':
  9912. {
  9913. if (link.includes('curator')) {
  9914. id = link.match(/curator\/([\d]+)/)?.[1] || '';
  9915. } else {
  9916. const param = link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3);
  9917. if (!param || param.length !== 2) {
  9918. break;
  9919. }
  9920. const steam = new social_Steam();
  9921. if (await steam.init()) {
  9922. id = await steam.getCuratorId(param[0], param[1]) || '';
  9923. }
  9924. }
  9925. }
  9926. break;
  9927. }
  9928. return id;
  9929. } catch (error) {
  9930. throwError(error, 'link2id');
  9931. return i18n('getFailed', 'id');
  9932. }
  9933. };
  9934. const disabledType = {
  9935. steam: [ 'workshopVotes', 'curatorLikes', 'announcements' ],
  9936. twitter: [ 'likes' ]
  9937. };
  9938. const assignWhiteList = whiteList => {
  9939. try {
  9940. const newWhiteList = {};
  9941. for (const [ key, value ] of Object.entries(defaultWhiteList)) {
  9942. newWhiteList[key] = {
  9943. ...value,
  9944. ...whiteList[key]
  9945. };
  9946. }
  9947. return newWhiteList;
  9948. } catch (error) {
  9949. throwError(error, 'assignWhiteList');
  9950. return defaultWhiteList;
  9951. }
  9952. };
  9953. const whiteListOptions = function(showType) {
  9954. try {
  9955. const whiteList = assignWhiteList(GM_getValue('whiteList') || {});
  9956. let whiteListOptionsForm = `<form id="whiteListForm" class="auto-task-form">
  9957. <table class="auto-task-table"><thead><tr><td>${i18n('website')}</td><td>${i18n('type')}</td><td>${i18n('edit')}</td></tr></thead><tbody>`;
  9958. for (const [ social, types ] of Object.entries(whiteList)) {
  9959. 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('');
  9960. }
  9961. whiteListOptionsForm += '</tbody></table></form>';
  9962. if (showType === 'swal') {
  9963. external_Swal_default().fire({
  9964. title: i18n('whiteListOptions'),
  9965. html: whiteListOptionsForm,
  9966. showConfirmButton: false,
  9967. showCloseButton: true
  9968. });
  9969. } else {
  9970. $('body').append(`<h2>${i18n('whiteList')}</h2>${whiteListOptionsForm}`);
  9971. }
  9972. $('.editWhiteList').on('click', function() {
  9973. const value = $(this).attr('data-value');
  9974. if (!value) {
  9975. return;
  9976. }
  9977. const [ social, type ] = value.split('.');
  9978. if (!whiteList?.[social]?.[type]) {
  9979. scripts_echoLog({}).warning(i18n('whiteListNotFound', value));
  9980. return;
  9981. }
  9982. external_Swal_default().fire({
  9983. title: i18n('changeWhiteListOption', value),
  9984. input: 'textarea',
  9985. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  9986. <button id="link2id" data-type="${value}" class="swal2-confirm swal2-styled">获取id</button>
  9987. <p style="margin-bottom:0 !important;">在下方填写白名单,每行一个</p>`,
  9988. inputValue: whiteList[social][type].join('\n'),
  9989. showConfirmButton: true,
  9990. confirmButtonText: i18n('save'),
  9991. showCancelButton: true,
  9992. cancelButtonText: i18n('close'),
  9993. showDenyButton: true,
  9994. denyButtonText: i18n('return')
  9995. }).then(({
  9996. isDenied,
  9997. isConfirmed,
  9998. value
  9999. }) => {
  10000. if (isDenied) {
  10001. if (showType === 'swal') {
  10002. whiteListOptions(showType);
  10003. }
  10004. return;
  10005. } else if (isConfirmed) {
  10006. whiteList[social][type] = value.split('\n');
  10007. GM_setValue('whiteList', whiteList);
  10008. external_Swal_default().fire({
  10009. title: i18n('changeWhiteListSuccess'),
  10010. icon: 'success'
  10011. });
  10012. }
  10013. });
  10014. $('#link2id').on('click', async function() {
  10015. const type = $(this).attr('data-type');
  10016. $('#socialLink').val(await link2id(type));
  10017. });
  10018. });
  10019. } catch (error) {
  10020. throwError(error, 'whiteListOptions');
  10021. }
  10022. };
  10023. const whiteList = whiteListOptions;
  10024. const setGistData = async (token, gistId, fileName, content) => {
  10025. try {
  10026. const logStatus = scripts_echoLog({
  10027. text: i18n('settingData')
  10028. });
  10029. const contentData = JSON.stringify({
  10030. files: {
  10031. [fileName]: {
  10032. content: JSON.stringify(content)
  10033. }
  10034. }
  10035. });
  10036. const {
  10037. result,
  10038. statusText,
  10039. status,
  10040. data
  10041. } = await tools_httpRequest({
  10042. url: `https://api.github.com/gists/${gistId}`,
  10043. headers: {
  10044. Accept: 'application/vnd.github.v3+json',
  10045. Authorization: `token ${token}`
  10046. },
  10047. data: contentData,
  10048. responseType: 'json',
  10049. method: 'POST',
  10050. timeout: 3e4
  10051. });
  10052. if (result === 'Success') {
  10053. if (data?.status === 200 && data.response.files?.[fileName]?.content === JSON.stringify(content)) {
  10054. logStatus.success();
  10055. return true;
  10056. }
  10057. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10058. return false;
  10059. }
  10060. logStatus.error(`${result}:${statusText}(${status})`);
  10061. return false;
  10062. } catch (error) {
  10063. throwError(error, 'setGistData');
  10064. return false;
  10065. }
  10066. };
  10067. const getGistData = async (token, gistId, fileName, test = false) => {
  10068. try {
  10069. const logStatus = scripts_echoLog({
  10070. text: i18n('gettingData')
  10071. });
  10072. const {
  10073. result,
  10074. statusText,
  10075. status,
  10076. data
  10077. } = await tools_httpRequest({
  10078. url: `https://api.github.com/gists/${gistId}`,
  10079. headers: {
  10080. Accept: 'application/vnd.github.v3+json',
  10081. Authorization: `token ${token}`
  10082. },
  10083. responseType: 'json',
  10084. method: 'GET',
  10085. timeout: 3e4
  10086. });
  10087. if (result === 'Success') {
  10088. if (data?.status === 200) {
  10089. const content = data.response?.files?.[fileName]?.content;
  10090. let formatedContent;
  10091. if (!content) {
  10092. logStatus.error(`Error:${i18n('noRemoteData')}`);
  10093. return false;
  10094. }
  10095. if (test) {
  10096. logStatus.success();
  10097. return true;
  10098. }
  10099. try {
  10100. formatedContent = JSON.parse(content);
  10101. } catch (error) {
  10102. logStatus.error(`Error:${i18n('errorRemoteDataFormat')}`);
  10103. return false;
  10104. }
  10105. logStatus.success();
  10106. return formatedContent;
  10107. }
  10108. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10109. return false;
  10110. }
  10111. logStatus.error(`${result}:${statusText}(${status})`);
  10112. return false;
  10113. } catch (error) {
  10114. throwError(error, 'getGistData');
  10115. return false;
  10116. }
  10117. };
  10118. const syncOptions = () => {
  10119. try {
  10120. const {
  10121. TOKEN,
  10122. GIST_ID,
  10123. FILE_NAME,
  10124. SYNC_HISTORY
  10125. } = GM_getValue('gistOptions') || {
  10126. TOKEN: '',
  10127. GIST_ID: '',
  10128. FILE_NAME: '',
  10129. SYNC_HISTORY: true
  10130. };
  10131. external_Swal_default().fire({
  10132. title: i18n('gistOptions'),
  10133. 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;">
  10134. ${i18n('upload2gist')}</button>` + `<button id="download-data" type="button" class="swal2-confirm swal2-styled" style="display: inline-block;">
  10135. ${i18n('downloadFromGist')}</button></p>`,
  10136. focusConfirm: false,
  10137. showLoaderOnConfirm: true,
  10138. 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>`,
  10139. preConfirm: async () => {
  10140. const token = $('#github-token').val();
  10141. const gistId = $('#gist-id').val();
  10142. const fileName = $('#file-name').val();
  10143. const syncHistory = $('#sync-history').prop('checked');
  10144. GM_setValue('gistOptions', {
  10145. TOKEN: token,
  10146. GIST_ID: gistId,
  10147. FILE_NAME: fileName,
  10148. SYNC_HISTORY: syncHistory
  10149. });
  10150. return await getGistData(token, gistId, fileName, true);
  10151. },
  10152. allowOutsideClick: () => !external_Swal_default().isLoading(),
  10153. confirmButtonText: i18n('saveAndTest'),
  10154. showCancelButton: true,
  10155. cancelButtonText: i18n('close')
  10156. }).then(({
  10157. value
  10158. }) => {
  10159. if (value) {
  10160. external_Swal_default().fire({
  10161. icon: 'success',
  10162. title: i18n('testSuccess')
  10163. }).then(syncOptions);
  10164. } else if (value !== undefined) {
  10165. external_Swal_default().fire({
  10166. icon: 'error',
  10167. title: i18n('testFailed')
  10168. }).then(syncOptions);
  10169. }
  10170. });
  10171. $('#upload-data').on('click', async () => {
  10172. const {
  10173. TOKEN,
  10174. GIST_ID,
  10175. FILE_NAME
  10176. } = GM_getValue('gistOptions') || {};
  10177. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10178. return external_Swal_default().fire({
  10179. icon: 'error',
  10180. title: i18n('saveAndTestNotice')
  10181. }).then(syncOptions);
  10182. }
  10183. external_Swal_default().fire({
  10184. icon: 'info',
  10185. title: i18n('processingData')
  10186. });
  10187. const data = {};
  10188. const names = GM_listValues();
  10189. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10190. for (const name of names) {
  10191. if (name === 'gistOptions' || /^[\w]+?Auth$/.test(name)) {
  10192. continue;
  10193. }
  10194. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10195. continue;
  10196. }
  10197. data[name] = GM_getValue(name);
  10198. }
  10199. external_Swal_default().update({
  10200. icon: 'info',
  10201. title: i18n('updatingData')
  10202. });
  10203. if (await setGistData(TOKEN, GIST_ID, FILE_NAME, data)) {
  10204. external_Swal_default().fire({
  10205. icon: 'success',
  10206. title: i18n('syncDataSuccess')
  10207. });
  10208. } else {
  10209. external_Swal_default().fire({
  10210. icon: 'error',
  10211. title: i18n('syncDataFailed')
  10212. });
  10213. }
  10214. });
  10215. $('#download-data').on('click', async () => {
  10216. const {
  10217. TOKEN,
  10218. GIST_ID,
  10219. FILE_NAME
  10220. } = GM_getValue('gistOptions') || {};
  10221. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10222. return external_Swal_default().fire({
  10223. icon: 'error',
  10224. title: i18n('saveAndTestNotice')
  10225. }).then(syncOptions);
  10226. }
  10227. external_Swal_default().fire({
  10228. icon: 'info',
  10229. title: i18n('downloadingData')
  10230. });
  10231. const data = await getGistData(TOKEN, GIST_ID, FILE_NAME);
  10232. if (!data) {
  10233. return external_Swal_default().fire({
  10234. icon: 'error',
  10235. title: i18n('checkedNoData')
  10236. }).then(syncOptions);
  10237. }
  10238. external_Swal_default().update({
  10239. icon: 'info',
  10240. title: i18n('savingData')
  10241. });
  10242. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10243. for (const [ name, value ] of Object.entries(data)) {
  10244. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10245. continue;
  10246. }
  10247. GM_setValue(name, value);
  10248. }
  10249. external_Swal_default().fire({
  10250. icon: 'success',
  10251. title: i18n('syncDataSuccess')
  10252. });
  10253. });
  10254. } catch (error) {
  10255. throwError(error, 'syncOptions');
  10256. }
  10257. };
  10258. const dataSync = syncOptions;
  10259. class Setting {
  10260. name = 'Setting';
  10261. buttons = [ 'saveGlobalOptions', 'syncData', 'tasksHistory' ];
  10262. syncData = dataSync;
  10263. tasksHistory() {
  10264. window.open('https://auto-task-v4.hclonely.com/history.html', '_blank');
  10265. }
  10266. static test() {
  10267. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/setting.html';
  10268. }
  10269. before() {
  10270. $('body').html('').addClass('auto-task-options');
  10271. }
  10272. after() {
  10273. try {
  10274. this.#environment();
  10275. changeGlobalOptions('page');
  10276. whiteList('page');
  10277. $('input[name="other.twitterVerifyId"]').after(`<button id="getTwitterUserId" type="button">${i18n('getTwitterUserId')}</button>`);
  10278. $('#getTwitterUserId').on('click', () => {
  10279. this.#getId('twitterUser');
  10280. });
  10281. $('input[name="other.youtubeVerifyChannel"]').after(`<button id="getYoutubeChannelId" type="button">${i18n('getYoutubeChannelId')}</button>`);
  10282. $('#getYoutubeChannelId').on('click', () => {
  10283. this.#getId('youtubeChannel');
  10284. });
  10285. $('input[name^="position"]').on('input', function() {
  10286. const type = $(this).attr('name').replace('position.', '');
  10287. const xLabel = 'rightleft';
  10288. const yLabel = 'topbottpm';
  10289. switch (type) {
  10290. case 'buttonSideX':
  10291. case 'buttonSideY':
  10292. case 'buttonDistance':
  10293. {
  10294. const distance = $('input[name="position.buttonDistance"]').val();
  10295. const sideX = $('input[name="position.buttonSideX"]').val();
  10296. const sideY = $('input[name="position.buttonSideY"]').val();
  10297. if (![ 'right', 'left' ].includes(sideX)) {
  10298. break;
  10299. }
  10300. if (![ 'top', 'bottom' ].includes(sideY)) {
  10301. break;
  10302. }
  10303. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10304. break;
  10305. }
  10306. const distanceArr = distance.split(',');
  10307. $('#auto-task-buttons').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10308. break;
  10309. }
  10310.  
  10311. case 'showButtonSideX':
  10312. case 'showButtonSideY':
  10313. case 'showButtonDistance':
  10314. {
  10315. const distance = $('input[name="position.showButtonDistance"]').val();
  10316. const sideX = $('input[name="position.showButtonSideX"]').val();
  10317. const sideY = $('input[name="position.showButtonSideY"]').val();
  10318. if (![ 'right', 'left' ].includes(sideX)) {
  10319. break;
  10320. }
  10321. if (![ 'top', 'bottom' ].includes(sideY)) {
  10322. break;
  10323. }
  10324. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10325. break;
  10326. }
  10327. const distanceArr = distance.split(',');
  10328. $('div.show-button-div').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10329. break;
  10330. }
  10331.  
  10332. case 'logSideX':
  10333. case 'logSideY':
  10334. case 'logDistance':
  10335. {
  10336. const distance = $('input[name="position.logDistance"]').val();
  10337. const sideX = $('input[name="position.logSideX"]').val();
  10338. const sideY = $('input[name="position.logSideY"]').val();
  10339. if (![ 'right', 'left' ].includes(sideX)) {
  10340. break;
  10341. }
  10342. if (![ 'top', 'bottom' ].includes(sideY)) {
  10343. break;
  10344. }
  10345. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10346. break;
  10347. }
  10348. const distanceArr = distance.split(',');
  10349. $('#auto-task-info').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10350. break;
  10351. }
  10352.  
  10353. default:
  10354. break;
  10355. }
  10356. });
  10357. $('input[name^="hotKey"]').attr('readonly', 'readonly').off('keydown').on('keydown', function(event) {
  10358. let functionKey = '';
  10359. if (event.altKey) {
  10360. functionKey += 'alt + ';
  10361. } else if (event.ctrlKey) {
  10362. functionKey += 'ctrl + ';
  10363. } else if (event.shiftKey) {
  10364. functionKey += 'shift + ';
  10365. }
  10366. $(this).val(functionKey + (event.key.length === 1 ? event.key.toLowerCase() : ''));
  10367. });
  10368. } catch (error) {
  10369. throwError(error, 'Setting.after');
  10370. }
  10371. }
  10372. saveGlobalOptions() {
  10373. saveData();
  10374. }
  10375. #getId(social) {
  10376. try {
  10377. external_Swal_default().fire({
  10378. title: i18n('getId', i18n(social)),
  10379. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10380. <button id="link2id" data-type="${social}" class="swal2-confirm swal2-styled">获取id</button>`,
  10381. showCancelButton: true,
  10382. cancelButtonText: i18n('close'),
  10383. showConfirmButton: false
  10384. });
  10385. $('#link2id').on('click', async function() {
  10386. const link = $('#socialLink').val();
  10387. if (!link) {
  10388. return;
  10389. }
  10390. const type = $(this).attr('data-type');
  10391. if (type === 'twitterUser') {
  10392. const name = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || link;
  10393. $('#socialLink').val(await new social_Twitter().userName2id(name) || '');
  10394. } else if (type === 'youtubeChannel') {
  10395. const name = /^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www.youtube.com\/.*/.test(link) ? link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1] : link;
  10396. $('#socialLink').val((await getInfo(name, 'channel'))?.params?.channelId || '');
  10397. }
  10398. });
  10399. } catch (error) {
  10400. throwError(error, 'Setting.getId');
  10401. }
  10402. }
  10403. #environment() {
  10404. try {
  10405. const userAgent = (0, javascript_utils_umd_min.ua)();
  10406. const environmentForm = `<form id="environmentForm" class="auto-task-form">
  10407. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('name')}</td><td>${i18n('version')}</td></tr></thead><tbody>
  10408. <tr><td>${i18n('os')}</td><td>${userAgent.os}</td><td>${userAgent.osVersion}</td></tr>
  10409. <tr><td>${i18n('browser')}</td><td>${userAgent.browserZH}</td><td>${userAgent.browserVersion}</td></tr>
  10410. <tr><td>${i18n('scriptManager')}</td><td>${GM_info.scriptHandler}</td><td>${GM_info.version}</td></tr>
  10411. <tr><td>${i18n('script')}</td><td>${GM_info.script.name}</td><td>${GM_info.script.version}</td></tr>
  10412. </tbody></table></form>`;
  10413. $('body').append(`<h2>${i18n('environment')}</h2>${environmentForm}`);
  10414. } catch (error) {
  10415. throwError(error, 'Setting.environment');
  10416. }
  10417. }
  10418. }
  10419. const website_Setting = Setting;
  10420. class History extends website_Keylol {
  10421. name = 'History';
  10422. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect', 'clearHistory' ];
  10423. static test() {
  10424. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/history.html';
  10425. }
  10426. before() {
  10427. try {
  10428. $('body').html('<div class="container"></div>').addClass('auto-task-history');
  10429. const data = GM_listValues() || [];
  10430. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10431. for (const item of tasksHistory) {
  10432. this.#addItem(item);
  10433. }
  10434. } catch (error) {
  10435. throwError(error, 'History.before');
  10436. }
  10437. }
  10438. clearHistory() {
  10439. try {
  10440. const data = GM_listValues() || [];
  10441. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10442. for (const item of tasksHistory) {
  10443. GM_deleteValue(item);
  10444. }
  10445. external_Swal_default().fire({
  10446. title: i18n('clearHistoryFinished'),
  10447. icon: 'success'
  10448. });
  10449. } catch (error) {
  10450. throwError(error, 'History.after');
  10451. }
  10452. }
  10453. #addItem(item) {
  10454. try {
  10455. const tasksData = GM_getValue(item);
  10456. if (!tasksData?.tasks) {
  10457. return;
  10458. }
  10459. let html = '';
  10460. let title = '';
  10461. let link = '';
  10462. const [ website, id ] = item.split('-');
  10463. switch (website) {
  10464. case 'fawTasks':
  10465. title = `Freeanywhere[${id}]`;
  10466. link = `https://freeanywhere.net/#/giveaway/${id}`;
  10467. break;
  10468.  
  10469. case 'gasTasks':
  10470. title = `Giveawaysu[${id}]`;
  10471. link = `https://giveaway.su/giveaway/view/${id}`;
  10472. break;
  10473.  
  10474. case 'gcTasks':
  10475. title = `GiveeClub[${id}]`;
  10476. link = `https://givee.club/event/${id}`;
  10477. break;
  10478.  
  10479. case 'gkTasks':
  10480. title = `Givekey[${id}]`;
  10481. link = `https://givekey.ru/giveaway/${id}`;
  10482. break;
  10483.  
  10484. case 'gleamTasks':
  10485. title = `Gleam[${id}]`;
  10486. link = `https://gleam.io${id}`;
  10487. break;
  10488.  
  10489. case 'khTasks':
  10490. title = `keyhub[${id}]`;
  10491. link = `https://key-hub.eu/giveaway/${id}`;
  10492. break;
  10493.  
  10494. case 'prysTasks':
  10495. title = `Prys[${id}]`;
  10496. link = `https://prys.revadike.com/giveaway/?id=${id}`;
  10497. break;
  10498.  
  10499. default:
  10500. return;
  10501. }
  10502. for (const [ social, types ] of Object.entries(tasksData.tasks)) {
  10503. for (const [ type, tasks ] of Object.entries(types)) {
  10504. for (const task of tasks) {
  10505. 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>`;
  10506. }
  10507. }
  10508. }
  10509. $('.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>`);
  10510. $('span.delete-task').on('click', function() {
  10511. const itemName = $(this).attr('data-name');
  10512. if (itemName) {
  10513. GM_deleteValue(itemName);
  10514. $(`div.card[data-name="${itemName}"]`).remove();
  10515. external_Swal_default().fire({
  10516. title: i18n('clearTaskFinished'),
  10517. text: itemName,
  10518. icon: 'success'
  10519. });
  10520. } else {
  10521. external_Swal_default().fire({
  10522. title: i18n('clearTaskFailed'),
  10523. icon: 'error'
  10524. });
  10525. }
  10526. });
  10527. } catch (error) {
  10528. throwError(error, 'History.addItem');
  10529. }
  10530. }
  10531. }
  10532. const website_History = History;
  10533. 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 ];
  10534. const websiteOptions = function(website, options) {
  10535. try {
  10536. let websiteOptionsForm = `<form id="websiteOptionsForm" class="auto-task-form">
  10537. <table class="auto-task-table"><thead><tr><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  10538. for (const [ option, value ] of Object.entries(options)) {
  10539. websiteOptionsForm += `<tr><td>${option}</td><td><input class="editOption" type="text" name="${option}" value="${value}"/></td></tr>`;
  10540. }
  10541. websiteOptionsForm += '</tbody></table></form>';
  10542. external_Swal_default().fire({
  10543. title: i18n('websiteOptions'),
  10544. html: websiteOptionsForm,
  10545. showConfirmButton: true,
  10546. confirmButtonText: i18n('save'),
  10547. showCancelButton: true,
  10548. cancelButtonText: i18n('close')
  10549. }).then(({
  10550. isConfirmed
  10551. }) => {
  10552. if (isConfirmed) {
  10553. $('#websiteOptionsForm').serializeArray().map(value => {
  10554. options[value.name] = value.value;
  10555. return value;
  10556. });
  10557. GM_setValue(`${website}Options`, options);
  10558. external_Swal_default().fire({
  10559. title: i18n('changeWebsiteOptionsSuccess'),
  10560. icon: 'success'
  10561. });
  10562. }
  10563. });
  10564. } catch (error) {
  10565. throwError(error, 'websiteOptions');
  10566. }
  10567. };
  10568. const options = websiteOptions;
  10569. const external_keyboardJS_namespaceObject = keyboardJS;
  10570. var external_keyboardJS_default = __webpack_require__.n(external_keyboardJS_namespaceObject);
  10571. const checkUpdate = async (updateLink, auto) => {
  10572. try {
  10573. const checkUrl = `${updateLink}package.json?time=${new Date().getTime()}`;
  10574. const {
  10575. result,
  10576. statusText,
  10577. status,
  10578. data
  10579. } = await tools_httpRequest({
  10580. url: checkUrl,
  10581. responseType: 'json',
  10582. method: 'GET',
  10583. timeout: 3e4
  10584. });
  10585. if (result === 'Success') {
  10586. if (data?.response?.version) {
  10587. return data.response;
  10588. }
  10589. if (!auto) {
  10590. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${data?.statusText}(${data?.status})]`);
  10591. }
  10592. return false;
  10593. }
  10594. if (!auto) {
  10595. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${result}:${statusText}(${status})]`);
  10596. }
  10597. return false;
  10598. } catch (error) {
  10599. throwError(error, 'checkUpdate');
  10600. return false;
  10601. }
  10602. };
  10603. const hasNewVersion = (currentVersion, remoteVersion) => {
  10604. try {
  10605. const [ currentRealVersion ] = currentVersion.split('-');
  10606. const [ remoteRealVersion, isPreview ] = remoteVersion.split('-');
  10607. if (isPreview && !globalOptions.other.receivePreview) {
  10608. return false;
  10609. }
  10610. const [ currentVersion1, currentVersion2, currentVersion3 ] = currentRealVersion.split('.').map(value => parseInt(value, 10));
  10611. const [ remoteVersion1, remoteVersion2, remoteVersion3 ] = remoteRealVersion.split('.').map(value => parseInt(value, 10));
  10612. if (remoteVersion1 > currentVersion1) {
  10613. return true;
  10614. }
  10615. if (remoteVersion1 < currentVersion1) {
  10616. return false;
  10617. }
  10618. if (remoteVersion2 > currentVersion2) {
  10619. return true;
  10620. }
  10621. if (remoteVersion2 < currentVersion2) {
  10622. return false;
  10623. }
  10624. if (remoteVersion3 > currentVersion3) {
  10625. return true;
  10626. }
  10627. return false;
  10628. } catch (error) {
  10629. throwError(error, 'compareVersion');
  10630. return false;
  10631. }
  10632. };
  10633. const updateChecker = async () => {
  10634. try {
  10635. const currentVersion = GM_info.script.version;
  10636. const updateSource = globalOptions.other.autoUpdateSource.toLowerCase();
  10637. const updateLinks = {
  10638. github: 'https://github.com/HCLonely/auto-task-new/raw/main/',
  10639. jsdelivr: 'https://cdn.jsdelivr.net/gh/HCLonely/auto-task-v4@main/',
  10640. standby: 'https://auto-task-v4.hclonely.com/'
  10641. };
  10642. let version;
  10643. let updateLink = '';
  10644. let packageData;
  10645. if ([ 'github', 'jsdelivr', 'standby' ].includes(updateSource)) {
  10646. updateLink = updateLinks[updateSource];
  10647. packageData = await checkUpdate(updateLink, false);
  10648. } else {
  10649. updateLink = updateLinks.github;
  10650. packageData = await checkUpdate(updateLink, true);
  10651. if (!packageData) {
  10652. updateLink = updateLinks.jsdelivr;
  10653. packageData = await checkUpdate(updateLink, true);
  10654. if (!packageData) {
  10655. updateLink = updateLinks.standby;
  10656. packageData = await checkUpdate(updateLink, true);
  10657. }
  10658. }
  10659. }
  10660. if (packageData) {
  10661. version = packageData.version || currentVersion;
  10662. } else {
  10663. version = currentVersion;
  10664. scripts_echoLog({}).error(i18n('checkUpdateFailed'));
  10665. }
  10666. if (packageData && hasNewVersion(currentVersion, version)) {
  10667. scripts_echoLog({
  10668. html: `<li><font>${i18n('newVersionNotice', version, `${updateLink}dist/${GM_info.script.name}.user.js`)}</font></li>`
  10669. });
  10670. scripts_echoLog({
  10671. html: `<li>${i18n('updateText', version)}</li><ol class="update-text">${packageData.change?.map(change => `<li>${change}</li>`).join('')}<li>${i18n('updateHistory')}</li></ol>`
  10672. });
  10673. }
  10674. } catch (error) {
  10675. throwError(error, 'updateChecker');
  10676. }
  10677. };
  10678. const scripts_updateChecker = updateChecker;
  10679. window.STYLE = GM_addStyle(auto_task.Z + GM_getResourceText('style'));
  10680. window.DEBUG = !!globalOptions.other?.debug;
  10681. window.TRACE = !!globalOptions.other?.debug && typeof console.trace === 'function';
  10682. const loadScript = async () => {
  10683. if (window.location.hostname === 'www.twitch.tv' && window.location.hash === '#auth') {
  10684. const authToken = external_Cookies_namespaceObject.get('auth-token');
  10685. const isLogin = !!external_Cookies_namespaceObject.get('login');
  10686. if (isLogin) {
  10687. GM_setValue('twitchAuth', {
  10688. authToken: authToken,
  10689. clientVersion: __twilightBuildID,
  10690. clientId: commonOptions?.headers?.['Client-ID'],
  10691. deviceId: commonOptions?.headers?.['Device-ID'],
  10692. clientSessionId: window.localStorage.local_storage_app_session_id.replace(/"/g, '')
  10693. });
  10694. window.close();
  10695. external_Swal_default().fire('', i18n('closePageNotice'));
  10696. } else {
  10697. external_Swal_default().fire('', i18n('needLogin'));
  10698. }
  10699. return;
  10700. }
  10701. if (window.location.hostname === 'www.reddit.com' && (window.location.hash === '#auth' || GM_getValue('redditAuth') === '#auth')) {
  10702. const betaButton = $('#redesign-beta-optin-btn');
  10703. if (betaButton.length > 0) {
  10704. GM_setValue('redditAuth', '#auth');
  10705. return betaButton[0].click();
  10706. }
  10707. GM_setValue('redditAuth', null);
  10708. window.close();
  10709. external_Swal_default().fire('', i18n('closePageNotice'));
  10710. return;
  10711. }
  10712. let website;
  10713. for (const Website of Websites) {
  10714. if (Website.test()) {
  10715. website = new Website();
  10716. break;
  10717. }
  10718. }
  10719. if (!website) {
  10720. console.log('%c%s', 'color:#ff0000', 'Auto-Task[Warning]: 脚本停止加载,当前网站不支持!');
  10721. return;
  10722. }
  10723. if (website?.before) {
  10724. await website?.before();
  10725. }
  10726. $('body').append(`<div id="auto-task-info" style="display:${globalOptions.other.defaultShowLog ? 'block' : 'none'};${globalOptions.position.logSideX}:${globalOptions.position.logDistance.split(',')[0]}px;${globalOptions.position.logSideY}:${globalOptions.position.logDistance.split(',')[1]}px;"></div><div id="auto-task-buttons" style="display:${globalOptions.other.defaultShowButton ? 'block' : 'none'};${globalOptions.position.buttonSideX}:${globalOptions.position.buttonDistance.split(',')[0]}px;${globalOptions.position.buttonSideY}:${globalOptions.position.buttonDistance.split(',')[1]}px;"></div><div class="show-button-div" style="display:${globalOptions.other.defaultShowButton ? 'none' : 'block'};${globalOptions.position.showButtonSideX}:${globalOptions.position.showButtonDistance.split(',')[0]}px;${globalOptions.position.showButtonSideY}:${globalOptions.position.showButtonDistance.split(',')[1]}px;"><a class="auto-task-website-btn" href="javascript:void(0);" target="_self" title="${i18n('showButton')}"> </a></div>`);
  10727. $('div.show-button-div').on('click', () => {
  10728. $('#auto-task-buttons').show();
  10729. $('div.show-button-div').hide();
  10730. });
  10731. const toggleLog = () => {
  10732. const $this = $('#toggle-log');
  10733. const status = $this.attr('data-status');
  10734. if (status === 'show') {
  10735. $('#auto-task-info').hide();
  10736. $this.attr('data-status', 'hide').text(i18n('showLog'));
  10737. } else {
  10738. $('#auto-task-info').show();
  10739. $this.attr('data-status', 'show').text(i18n('hideLog'));
  10740. }
  10741. };
  10742. external_keyboardJS_default().bind(globalOptions.hotKey.doTaskKey, () => {
  10743. if (website.doTask) {
  10744. website.doTask();
  10745. }
  10746. });
  10747. external_keyboardJS_default().bind(globalOptions.hotKey.undoTaskKey, () => {
  10748. if (website.undoTask) {
  10749. website.doTask();
  10750. }
  10751. });
  10752. external_keyboardJS_default().bind(globalOptions.hotKey.toggleLogKey, toggleLog);
  10753. if (website?.after) {
  10754. await website?.after();
  10755. }
  10756. if (website?.buttons && $('#auto-task-buttons').children().length === 0) {
  10757. $('#auto-task-buttons').addClass(`${website.name}-buttons`);
  10758. for (const button of website.buttons) {
  10759. if (website[button]) {
  10760. const btnElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">${i18n(button)}</a></p>`);
  10761. btnElement.find('a.auto-task-website-btn').on('click', () => {
  10762. website[button]();
  10763. });
  10764. $('#auto-task-buttons').append(btnElement);
  10765. }
  10766. }
  10767. }
  10768. const hideButtonElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">
  10769. ${i18n('hideButton')}</a></p>`);
  10770. hideButtonElement.find('a.auto-task-website-btn').on('click', () => {
  10771. $('#auto-task-buttons').hide();
  10772. $('div.show-button-div').show();
  10773. });
  10774. 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'}">
  10775. ${globalOptions.other.defaultShowLog ? i18n('hideLog') : i18n('showLog')}</a></p>`);
  10776. toggleLogElement.find('a.auto-task-website-btn').on('click', toggleLog);
  10777. $('#auto-task-buttons').append(hideButtonElement).append(toggleLogElement);
  10778. if (website?.options) {
  10779. GM_registerMenuCommand(i18n('changeWebsiteOptions'), () => {
  10780. options(website.name, website.options);
  10781. });
  10782. }
  10783. if (website.name !== 'Setting') {
  10784. GM_registerMenuCommand(i18n('changeGlobalOptions'), () => {
  10785. changeGlobalOptions('swal');
  10786. });
  10787. GM_registerMenuCommand(i18n('settingPage'), () => {
  10788. window.open('https://auto-task-v4.hclonely.com/setting.html', '_blank');
  10789. });
  10790. }
  10791. console.log('%c%s', 'color:#1bbe1a', 'Auto-Task[Load]: 脚本加载完成');
  10792. const [ v1, v2 ] = GM_info.version.split('.');
  10793. if (!(parseInt(v1, 10) >= 5 && parseInt(v2, 10) >= 2)) {
  10794. scripts_echoLog({}).error(i18n('versionNotMatched'));
  10795. }
  10796. if (!GM_getValue('notice')) {
  10797. external_Swal_default().fire({
  10798. title: i18n('swalNotice'),
  10799. icon: 'warning'
  10800. }).then(() => {
  10801. window.open(i18n('noticeLink'), '_blank');
  10802. GM_setValue('notice', new Date().getTime());
  10803. });
  10804. scripts_echoLog({
  10805. html: `<li><font class="warning">${i18n('echoNotice', i18n('noticeLink'))}</font></li>`
  10806. }).font?.find('a').on('click', () => {
  10807. GM_setValue('notice', new Date().getTime());
  10808. });
  10809. }
  10810. scripts_updateChecker();
  10811. };
  10812. if (window.location.hostname === 'discord.com') {
  10813. const LocalStorage = window.localStorage;
  10814. if (window.location.hash === '#auth') {
  10815. window.localStorage.removeItem = () => true;
  10816. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10817. if (discordAuth && discordAuth.length > 0) {
  10818. GM_setValue('discordAuth', {
  10819. auth: discordAuth
  10820. });
  10821. window.close();
  10822. external_Swal_default().fire('', i18n('closePageNotice'));
  10823. } else {
  10824. external_Swal_default().fire({
  10825. text: i18n('getDiscordAuthFailed'),
  10826. icon: 'error'
  10827. });
  10828. }
  10829. } else {
  10830. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10831. if (discordAuth && discordAuth.length > 0) {
  10832. GM_setValue('discordAuth', {
  10833. auth: discordAuth
  10834. });
  10835. }
  10836. }
  10837. } else if (window.location.hostname === 'opquests.com') {
  10838. loadScript();
  10839. } else if (window.opener && window.location.host === 'store.steampowered.com' && window.location.pathname === '/') {
  10840. $(() => {
  10841. if ($('[data-miniprofile]').length === 0) {
  10842. return;
  10843. }
  10844. window.onbeforeunload = function(event) {
  10845. GM_setValue('steamStoreAuth', null);
  10846. return null;
  10847. };
  10848. const storeSessionID = document.body.innerHTML.match(/g_sessionID = "(.+?)";/)?.[1];
  10849. if (storeSessionID) {
  10850. GM_setValue('steamStoreAuth', {
  10851. storeSessionID: storeSessionID
  10852. });
  10853. return true;
  10854. }
  10855. });
  10856. } else if (window.opener && window.location.host === 'steamcommunity.com') {
  10857. $(() => {
  10858. window.onbeforeunload = function(event) {
  10859. GM_setValue('steamCommunityAuth', null);
  10860. return null;
  10861. };
  10862. if (GM_getValue('steamCommunityAuth') !== 'update') {
  10863. return null;
  10864. }
  10865. const steam64Id = document.body.innerHTML.match(/g_steamID = "(.+?)";/)?.[1];
  10866. const communitySessionID = document.body.innerHTML.match(/g_sessionID = "(.+?)";/)?.[1];
  10867. const userName = document.body.innerHTML.match(/steamcommunity.com\/id\/(.+?)\//)?.[1];
  10868. const data = {};
  10869. if (steam64Id) {
  10870. data.steam64Id = steam64Id;
  10871. }
  10872. if (userName) {
  10873. data.userName = userName;
  10874. }
  10875. if (communitySessionID) {
  10876. data.communitySessionID = communitySessionID;
  10877. GM_setValue('steamCommunityAuth', data);
  10878. window.close();
  10879. }
  10880. });
  10881. } else {
  10882. if (window.location.hostname === 'key-hub.eu') {
  10883. unsafeWindow.keyhubtracker = 1;
  10884. unsafeWindow.gaData = {};
  10885. }
  10886. $(loadScript);
  10887. }
  10888. }();
  10889. })();