auto-task-v4

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

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

  1. // ==UserScript==
  2. // @name auto-task-v4
  3. // @namespace auto-task-v4
  4. // @version 4.5.0
  5. // @description 自动完成 Freeanywhere,Giveawaysu,GiveeClub,Givekey,Gleam,Indiedb,keyhub,OpiumPulses,Opquests,SweepWidget 等网站的任务。
  6. // @description:en Automatically complete the tasks of FreeAnyWhere, GiveawaySu, GiveeClub, Givekey, Gleam, Indiedb, keyhub, OpiumPulses, Opquests, SweepWidget websites.
  7. // @author HCLonely
  8. // @license MIT
  9. // @run-at document-start
  10. // @homepage https://auto-task-doc.js.org/
  11. // @supportURL https://github.com/HCLonely/auto-task-v4/issues
  12. // @icon https://auto-task-v4.hclonely.com/favicon.ico
  13.  
  14. // @include *://freeanywhere.net/*
  15. // @include *://giveaway.su/giveaway/view/*
  16. // @include *://givee.club/*/event/*
  17. // @include *://givekey.ru/giveaway/*
  18. // @include *://www.indiedb.com/giveaways*
  19. // @include *://key-hub.eu/giveaway/*
  20. // @include *://keylol.com/*
  21. // @include *://www.opiumpulses.com/giveaways
  22. // @include *://prys.revadike.com/giveaway/?id=*
  23. // @include *://opquests.com/quests/*
  24. // @include *://gleam.io/*
  25. // @include *://sweepwidget.com/view/*
  26. // @include *://discord.com/*
  27. // @include *://www.twitch.tv/*
  28. // @include *://www.youtube.com/*
  29. // @include *://*.reddit.com/*
  30. // @include *://twitter.com/settings/account?k*
  31. // @include *://x.com/settings/account*
  32. // @include *://steamcommunity.com/id/*
  33. // @include *://steamcommunity.com/profiles/*
  34. // @include *://store.steampowered.com/*
  35. // @include https://auto-task-v4.hclonely.com/setting.html
  36. // @include https://auto-task-v4.hclonely.com/history.html
  37.  
  38. // @grant GM_setValue
  39. // @grant GM_getValue
  40. // @grant GM_listValues
  41. // @grant GM_deleteValue
  42. // @grant GM_addStyle
  43. // @grant GM_xmlhttpRequest
  44. // @grant GM_registerMenuCommand
  45. // @grant GM_info
  46. // @grant GM_openInTab
  47. // @grant GM_setClipboard
  48. // @grant GM_getResourceText
  49. // @grant GM_cookie
  50. // @grant GM_addValueChangeListener
  51. // @grant GM_removeValueChangeListener
  52. // @grant unsafeWindow
  53. // @grant window.close
  54. // @grant window.localStorage
  55.  
  56. // @connect cdn.jsdelivr.net
  57. // @connect store.steampowered.com
  58. // @connect steamcommunity.com
  59. // @connect login.steampowered.com
  60. // @connect twitter.com
  61. // @connect x.com
  62. // @connect api.twitter.com
  63. // @connect youtube.com
  64. // @connect www.youtube.com
  65. // @connect facebook.com
  66. // @connect instagram.com
  67. // @connect vk.com
  68. // @connect twitch.tv
  69. // @connect www.twitch.tv
  70. // @connect gql.twitch.tv
  71. // @connect github.com
  72. // @connect discordapp.com
  73. // @connect discord.gg
  74. // @connect discord.com
  75. // @connect www.reddit.com
  76. // @connect oauth.reddit.com
  77. // @connect raw.githubusercontent.com
  78. // @connect t.me
  79. // @connect bit.ly
  80. // @connect giveaway.su
  81. // @connect google.com
  82. // @connect www.vloot.io
  83. // @connect givee.club
  84. // @connect gleam.io
  85. // @connect www.indiedb.com
  86. // @connect key-hub.eu
  87. // @connect opquests.com
  88. // @connect itch.io
  89. // @connect auto-task-v4.hclonely.com
  90. // @connect *
  91. // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js
  92. // @require https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js
  93. // @require https://cdn.jsdelivr.net/npm/regenerator-runtime@0.13.5/runtime.min.js
  94. // @require https://cdn.jsdelivr.net/npm/js-sha1@0.6.0/src/sha1.min.js
  95. // @require https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js
  96. // @resource style https://cdn.jsdelivr.net/npm/sweetalert2@11.3.5/dist/sweetalert2.min.css
  97. // @require https://cdn.jsdelivr.net/npm/keyboardjs@2.6.4/dist/keyboard.min.js
  98. // @require https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js
  99.  
  100. // @noframes
  101. // ==/UserScript==
  102.  
  103. console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
  104. (function() {
  105. var __webpack_modules__ = {
  106. 991: function(__unused_webpack_module, exports) {
  107. !function(e, n) {
  108. true ? n(exports) : 0;
  109. }(this, function(e) {
  110. 'use strict';
  111. var t = function() {
  112. return (t = Object.assign || function(e) {
  113. for (var n, o = 1, t = arguments.length; o < t; o++) {
  114. for (var r in n = arguments[o]) {
  115. Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r]);
  116. }
  117. }
  118. return e;
  119. }).apply(this, arguments);
  120. };
  121. function r(e, n, o) {
  122. if (o || 2 === arguments.length) {
  123. for (var t, r = 0, i = n.length; r < i; r++) {
  124. !t && r in n || ((t = t || Array.prototype.slice.call(n, 0, r))[r] = n[r]);
  125. }
  126. }
  127. return e.concat(t || Array.prototype.slice.call(n));
  128. }
  129. function d(e) {
  130. return '[object Object]' === n(e);
  131. }
  132. function l(e, n) {
  133. var o = r(r([], n || [], !0), [ '_' ], !1).join('|');
  134. return e.replace(new RegExp('(('.concat(o, ')[a-z])+'), 'g'), function(e, n) {
  135. return n.replace(new RegExp(o), '').toLocaleUpperCase();
  136. });
  137. }
  138. var n = function(e) {
  139. return Object.prototype.toString.call(e);
  140. };
  141. var o = (i.prototype.init = function() {
  142. try {
  143. this.getSystemName(), this.getBrowserName();
  144. } catch (e) {
  145. console.warn('[UA formatter error] '.concat(e));
  146. }
  147. }, i.prototype.getEngine = function() {
  148. var e = this.agent;
  149. return -1 !== e.indexOf('Trident') ? 'Trident' : -1 !== e.indexOf('Firefox') ? 'Gecko' : -1 !== e.indexOf('Presto') ? 'Presto' : 'WebKit';
  150. }, i.prototype.getSystemName = function() {
  151. var e, n = (this.agent.match(/^[a-z]+\/\d+\.\d+\s?\(([a-z\d\s:;./_-]+)\)/i) || [])[1];
  152. try {
  153. var o = '';
  154. if (/Windows/i.test(n)) {
  155. var t = (n.match(/NT\s(\d+\.\d+)/) || [])[1];
  156. switch (this.info.os = 'Windows', t) {
  157. case '6.3':
  158. o = '8.1';
  159. break;
  160.  
  161. case '6.2':
  162. o = '8';
  163. break;
  164.  
  165. case '6.1':
  166. o = '7';
  167. break;
  168.  
  169. case '5.2':
  170. case '5.1':
  171. o = 'XP';
  172. break;
  173.  
  174. default:
  175. o = t;
  176. }
  177. return this.info.device = 'PC', void (this.info.osVersion = o);
  178. }
  179. if (/^Macintosh/i.test(n)) {
  180. return o = (n.match(/X\s((\d+(_|\.))+\d+)/) || [])[1], this.info.os = 'Macintosh',
  181. this.info.device = 'PC', void (this.info.osVersion = null !== (e = null == o ? void 0 : o.replace(/_/g, '.')) && void 0 !== e ? e : 'Unknown');
  182. }
  183. if (/^iPad/i.test(n)) {
  184. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPad',
  185. this.info.device = 'Tablet', void (this.info.osVersion = o.replace(/_/g, '.'));
  186. }
  187. if (/^iPhone/i.test(n)) {
  188. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPhone',
  189. this.info.device = 'Mobile', void (this.info.osVersion = o.replace(/_/g, '.'));
  190. }
  191. if (-1 !== n.indexOf('Android')) {
  192. var r = (n.match(/Android\s((\d+\.?)+\d?)/) || [])[1];
  193. return this.info.device = 'Mobile', this.info.os = 'Android', void (this.info.osVersion = r);
  194. }
  195. if (/Linux\s[a-z\d_]+/.test(n)) {
  196. return this.info.os = 'Linux', void (this.info.osVersion = 'Unknown');
  197. }
  198. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  199. } catch (e) {
  200. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  201. }
  202. }, i.prototype.getBrowserName = function() {
  203. var e = Object.keys(this.browserNameMap).map(function(e) {
  204. return new RegExp(''.concat(e, '(\\/|\\s)(\\d+\\.)+\\d+'));
  205. }), n = 1 < (n = (this.agent.match(/[a-z\d]+(\/|\s)(\d+\.)+\d+/gi) || []).filter(function(n) {
  206. return -1 !== e.findIndex(function(e) {
  207. return e.test(n);
  208. });
  209. })).length && !/^Safari/.test(n[n.length - 1]) ? n.reverse() : n;
  210. this.info = t(t({}, this.info), this._formatBrowserVersion(n[0]));
  211. }, i.prototype._formatBrowserVersion = function(e) {
  212. var n, o, t, r;
  213. try {
  214. for (var i = null !== (o = null === (n = e.match(/(?<name>[a-z\d]+)(\/|\s)(?<version>(\d+\.)+\d+)/i)) || void 0 === n ? void 0 : n.groups) && void 0 !== o ? o : {}, s = i.name, a = i.version, c = {}, f = 0, u = Object.entries(this.browserNameMap); f < u.length; f++) {
  215. var d = u[f], l = d[0], h = d[1];
  216. if (new RegExp(l).test(s)) {
  217. c = h;
  218. break;
  219. }
  220. }
  221. var p = {
  222. browserVersion: null != a ? a : 'Unknown',
  223. browser: null !== (t = c.en) && void 0 !== t ? t : 'Unknown',
  224. browserZH: null !== (r = (null == c ? void 0 : c.zh) || c.en) && void 0 !== r ? r : 'Unknown'
  225. };
  226. return 'Trident' === s && (p.browserVersion = {
  227. '4.0': 8,
  228. '5.0': 9,
  229. '6.0': 10,
  230. '7.0': 11
  231. }[a]), p;
  232. } catch (e) {
  233. return console.warn('[UA formatter error] '.concat(e)), {
  234. browser: 'Unknown',
  235. browserVersion: 'Unknown'
  236. };
  237. }
  238. }, i);
  239. function i(e) {
  240. this.agent = '', this.info = {
  241. browser: '',
  242. browserZH: '',
  243. browserVersion: '',
  244. os: '',
  245. osVersion: '',
  246. device: 'Unknown',
  247. engine: 'WebKit'
  248. }, this.browserNameMap = {
  249. MicroMessenger: {
  250. en: 'MicroMessenger',
  251. zh: '微信'
  252. },
  253. MetaSr: {
  254. en: 'MetaSr',
  255. zh: '搜狗浏览器'
  256. },
  257. 'QQ(Browser)?': {
  258. en: 'QQBrowser',
  259. zh: 'QQ浏览器'
  260. },
  261. UCBrowser: {
  262. en: 'UCBrowser',
  263. zh: 'UC浏览器'
  264. },
  265. '2345Explorer': {
  266. en: '2345Explorer',
  267. zh: '2345极速浏览器'
  268. },
  269. Mb2345Browser: {
  270. en: 'Mb2345Browser',
  271. zh: '2345手机浏览器'
  272. },
  273. Trident: {
  274. en: 'Internet Explorer'
  275. },
  276. 'Edge?': {
  277. en: 'Edge'
  278. },
  279. OPR: {
  280. en: 'Opera'
  281. },
  282. Vivaldi: {
  283. en: 'Vivaldi'
  284. },
  285. Firefox: {
  286. en: 'Firefox'
  287. },
  288. Chrome: {
  289. en: 'Chrome'
  290. },
  291. Safari: {
  292. en: 'Safari'
  293. }
  294. }, this.agent = e, this.init();
  295. var n = this.info, o = n.browser, e = n.browserVersion, n = n.osVersion;
  296. this.info = t(t({}, this.info), {
  297. engine: this.getEngine(),
  298. browserVersion: 'Safari' === o ? n : e
  299. });
  300. }
  301. function s() {
  302. this.cookies = {}, this.init();
  303. }
  304. var a = new (s.prototype.init = function() {
  305. var o = {};
  306. document.cookie.split(/;\s/).forEach(function(e) {
  307. var n = e.split(/=/), e = n[0], n = n[1];
  308. o[e] = n;
  309. }), this.cookies = o;
  310. }, s.prototype.getItem = function(e) {
  311. return this.cookies[e];
  312. }, s.prototype.getAllItems = function() {
  313. return this.cookies;
  314. }, s.prototype.setItem = function(e, n, o, t, r, i) {
  315. document.cookie = ''.concat(e, '=').concat(n).concat(o ? '; expires='.concat(o) : '').concat(t ? '; path='.concat(t) : '').concat(r ? '; domain='.concat(r) : '').concat(i ? '; secure' : '');
  316. }, s)();
  317. e.countDown = function e(n, o, t, r) {
  318. if (!window) {
  319. throw new Error('window is not defind.');
  320. }
  321. if (0 < n) {
  322. return r && r(), n--, window[o] = window.setTimeout(function() {
  323. e(n, o, t, r);
  324. }, 1e3), function() {
  325. return clearTimeout(window[o]);
  326. };
  327. }
  328. clearTimeout(window[o]), t && t();
  329. }, e.createRandomID = function(e) {
  330. void 0 === e && (e = 12);
  331. for (var n = [], o = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''), t = o.length, r = 0; r < e; r++) {
  332. n.push(o[Math.round(Math.random() * t)]);
  333. }
  334. return n.join('');
  335. }, e.dCookie = a, e.debounce = function(o, t, r) {
  336. var i;
  337. void 0 === t && (t = 0);
  338. var s = r = void 0 === r ? !1 : r;
  339. return function() {
  340. var e = this, n = arguments;
  341. s && (o.apply(this, arguments), s = !1), clearTimeout(i), i = setTimeout(function() {
  342. r ? s = !0 : o.apply(e, n);
  343. }, t);
  344. };
  345. }, e.deepCopy = function e(n) {
  346. if (d(n) || Array.isArray(n)) {
  347. var o, t = Array.isArray(n) ? [] : {};
  348. for (o in n) {
  349. t[o] = e(n[o]);
  350. }
  351. return t;
  352. }
  353. return n;
  354. }, e.formatQueryParams = function(e) {
  355. e = null === (e = /\?(?<params>(.*)=.+)/.exec(decodeURIComponent(e))) || void 0 === e ? void 0 : e.groups;
  356. if (!e) {
  357. return {};
  358. }
  359. for (var n = e.params.split('&'), t = {}, o = 0; o < n.length; o++) {
  360. n[o].replace(/([^?&]*)=([^?&]*)/, function(e, n, o) {
  361. return t[n] = o, e;
  362. });
  363. }
  364. return t;
  365. }, e.formatThousandth = function(e) {
  366. var n = ''.concat(e).split('.'), e = n[0], n = n[1], n = void 0 === n ? '' : n, e = e.replace(/\d{1,3}(?=(\d{3})+$)/g, '$&,');
  367. return ''.concat(e).concat(n ? '.'.concat(n) : '');
  368. }, e.generateTree = function e(n, o, t, r) {
  369. for (var i = [], s = 0; s < n.length; s++) {
  370. var a = n[s];
  371. a[t] === o && (i.push(a), a.children = e(n, a[null != r ? r : 'id'], t, r));
  372. }
  373. return i;
  374. }, e.isEmpty = function(e) {
  375. return Array.isArray(e) ? 0 === e.length : d(e) ? 0 === Object.keys(e).length : [ '[object Set]', '[object Map]' ].includes(n(e)) ? 0 === e.size : [ null, void 0, '' ].includes(e);
  376. }, e.isFunction = function(e) {
  377. return '[object Function]' === n(e);
  378. }, e.isImageUrl = function(e) {
  379. return /\.((png)|(jpe?g)|(gif)|(svg)|(webp))$/gi.test(e);
  380. }, e.isObject = d, e.isRegexp = function(e) {
  381. return '[object RegExp]' === n(e);
  382. }, e.objectKeyToCamelCase = function e(n, o, t) {
  383. if (Array.isArray(n)) {
  384. for (var r = [], i = 0; i < n.length; i++) {
  385. r[i] = e(o && n[i][o] ? n[i][o] : n[i], o, t);
  386. }
  387. } else if (d(n)) {
  388. r = {};
  389. for (var s = o && n[o] ? n[o] : n, a = 0, c = Object.entries(s); a < c.length; a++) {
  390. var f = (u = c[a])[0], u = u[1];
  391. Array.isArray(u) || d(s) ? r[l(f, t)] = e(u, o, t) : r[l(f, t)] = u;
  392. }
  393. } else {
  394. r = n;
  395. }
  396. return r;
  397. }, e.realType = n, e.searchParams = function(e, n) {
  398. return void 0 === e && (e = null === location || void 0 === location ? void 0 : location.search),
  399. new URLSearchParams(e).get(n);
  400. }, e.toLowerCamelCase = l, e.toUnderline = function(e) {
  401. return e.replace(/([A-Z])/g, function(e) {
  402. return '_'.concat(e.toLocaleLowerCase());
  403. });
  404. }, e.ua = function(e) {
  405. return void 0 === e && (e = navigator.userAgent), new o(e).info;
  406. }, Object.defineProperty(e, '__esModule', {
  407. value: !0
  408. });
  409. });
  410. },
  411. 675: function(module, __webpack_exports__, __webpack_require__) {
  412. 'use strict';
  413. __webpack_require__.d(__webpack_exports__, {
  414. A: function() {
  415. return __WEBPACK_DEFAULT_EXPORT__;
  416. }
  417. });
  418. var _node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(601);
  419. var _node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = __webpack_require__.n(_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__);
  420. var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(314);
  421. var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default = __webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__);
  422. var ___CSS_LOADER_EXPORT___ = _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default()(_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default());
  423. ___CSS_LOADER_EXPORT___.push([ module.id, `.colorful-button,#auto-task-buttons a.auto-task-website-btn,.show-button-div a.auto-task-website-btn,body.auto-task-options .auto-task-form table button{position:relative;padding:5px 10px;text-align:center;color:#fff;text-decoration:none;background:linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);border-radius:30px;background-size:400%;text-transform:capitalize}.colorful-button:hover,#auto-task-buttons a.auto-task-website-btn:hover,.show-button-div a.auto-task-website-btn:hover,body.auto-task-options .auto-task-form table button:hover{transform:scale(1.05);box-shadow:0 6px 20px rgba(0,0,0,.3);cursor:pointer}.colorful-button:hover::before,#auto-task-buttons a.auto-task-website-btn:hover::before,.show-button-div a.auto-task-website-btn:hover::before,body.auto-task-options .auto-task-form table button:hover::before{filter:blur(10px);opacity:1}.colorful-button::before,#auto-task-buttons a.auto-task-website-btn::before,.show-button-div a.auto-task-website-btn::before,body.auto-task-options .auto-task-form table button::before{content:"";position:absolute;top:-5px;left:-5px;right:-5px;bottom:-5px;z-index:-1;background:linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);border-radius:40px;background-size:400%;opacity:-1}#auto-task-info{z-index:999999999 !important}#auto-task-info{position:fixed;bottom:10px;right:10px;width:60%;max-width:500px;max-height:60%;overflow-y:auto;color:#000;background-color:#fff;padding-left:5px;border:solid 2px #add8e6;border-radius:10px}#auto-task-info li{text-align:left}#auto-task-info li a.high-light{color:#00aeff;font-weight:bold}#auto-task-info .success{color:green}#auto-task-info .error{color:red}#auto-task-info .warning{color:blue}#auto-task-info .info{color:#ff0}#auto-task-info .update-text{color:green;border:solid 2px #8dcb69;margin:5px 10px 5px 20px;border-radius:10px;padding:5px 20px}.auto-task-keylol{text-decoration:none !important}.auto-task-keylol{display:inline-block;text-transform:capitalize;margin-left:10px;border:solid 1px;border-radius:5px;padding:0 2px}.auto-task-keylol[selected=selected]{background-color:blue !important;color:#fff !important}.auto-task-form table{font-family:verdana,arial,sans-serif;font-size:11px;color:#333;border-width:1px;border-color:#999;border-collapse:collapse;width:100%}.auto-task-form table thead td{border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9;font-weight:bold;background-color:#fff}.auto-task-form table tbody tr{background-color:#d4e3e5}.auto-task-form table tbody tr:hover{background-color:#ff6 !important}.auto-task-form table tbody tr th{background-color:#c3dde0;border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9;text-transform:capitalize}.auto-task-form table tbody tr td{border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9}.swal2-modal{width:70% !important;max-width:1000px !important}body.auto-task-options{padding-top:10px;text-align:center}body.auto-task-options .auto-task-form{width:80%;max-width:1000px;margin:0 auto;padding-bottom:20px}body.auto-task-options .auto-task-form table input.editOption{width:80%}body.auto-task-options .auto-task-form table #getTwitterUserId,body.auto-task-options .auto-task-form table #getYoutubeChannelId{margin-top:5px}body.auto-task-options .auto-task-form table button{z-index:1}body.auto-task-options .auto-task-form table input[type=text]{outline-style:none;border:1px solid #ccc;border-radius:3px;padding:5px 10px;font-size:14px}body.auto-task-options .auto-task-form table input[type=text]:focus{border-color:#66afe9;outline:0;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}body.auto-task-options .auto-task-form table label{position:relative;width:160px;height:80px;cursor:pointer;transform:scale(0.25);margin:-25% 0;top:-30px;display:inline-block}body.auto-task-options .auto-task-form table label input{position:relative;z-index:1;appearance:none}body.auto-task-options .auto-task-form table label input:checked~span{background:#05be05;box-shadow:0 15px 25px rgba(5,190,5,.4)}body.auto-task-options .auto-task-form table label input:checked~span i{left:84px}body.auto-task-options .auto-task-form table label input:checked~span i::before{background:#05be05;box-shadow:35px 0 0 #05be05}body.auto-task-options .auto-task-form table label input:checked~span i::after{bottom:12px;height:15px;border-bottom-left-radius:15px;border-bottom-right-radius:15px;background:#05be05}body.auto-task-options .auto-task-form table label span{position:absolute;top:0;left:0;width:100%;height:100%;background:#fe0000;border-radius:80px;transition:.5s;box-shadow:0 15px 25px rgba(254,0,0,.4)}body.auto-task-options .auto-task-form table label span i{position:absolute;top:4px;left:4px;width:72px;height:72px;background:#fff;border-radius:50%}body.auto-task-options .auto-task-form table label span i::before{content:"";position:absolute;top:22px;left:12px;width:12px;height:12px;border-radius:50%;background:#fe0000;box-shadow:35px 0 0 #fe0000;transition:.5s}body.auto-task-options .auto-task-form table label span i::after{content:"";position:absolute;bottom:15px;left:calc(50% - 15px);width:30px;height:6px;border-radius:6px;background:#fe0000;transition:.5s}body.auto-task-history{font-size:15px;font-weight:400;line-height:1.5}body.auto-task-history .container a{color:#007bff;text-decoration:none;background-color:rgba(0,0,0,0)}body.auto-task-history .container .card{width:80%;max-width:800px;border-radius:10px;background:rgba(118,118,118,.1019607843);border-top:1px solid rgba(255,255,255,.5019607843);-webkit-backdrop-filter:blur(20px);backdrop-filter:blur(20px);box-shadow:0 15px 25px rgba(0,0,0,.1019607843);margin:20px auto;position:relative;display:flex;flex-direction:column;word-wrap:break-word;-webkit-background-clip:border-box;background-clip:border-box;border:1px solid rgba(0,0,0,.125);border-radius:.25rem}body.auto-task-history .container .card .title{text-align:center;font-size:30px;font-weight:bold;margin:5px 0}body.auto-task-history .container .card .title a:hover{text-decoration:none;background:#93e1ff;border-radius:10px;padding:3px}body.auto-task-history .container .card ul{margin-bottom:25px}body.auto-task-history .container .card ul li{margin-bottom:5px;line-height:20px}body.auto-task-history .container .card ul a:hover{text-decoration:underline}body.auto-task-history .container .card .delete-task{right:10px;width:38px;height:35px;position:absolute;font-size:24px;cursor:pointer;border-radius:10px}body.auto-task-history .container .card .delete-task:hover{background:#fff}body.auto-task-history .container .card .time{right:5px;position:absolute;bottom:0;color:#e83e8c;font-family:'SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace';font-size:15px}#auto-task-buttons,.show-button-div{z-index:999999999 !important}#auto-task-buttons,.show-button-div{position:fixed;top:30px;right:15px;width:124px;transform:scale(0.85)}#auto-task-buttons p,.show-button-div p{margin:5px !important}#auto-task-buttons p,.show-button-div p{line-height:30px;height:40px;text-align:center}#auto-task-buttons a.auto-task-website-btn,.show-button-div a.auto-task-website-btn{width:105px;line-height:27px;font-size:20px;display:block}.show-button-div{width:20px}.auto-task-capitalize{text-transform:capitalize !important}.swal2-file:focus,.swal2-input:focus,.swal2-textarea:focus{box-shadow:inset 0px 0px 4px 1px rgba(100,150,200,.5) !important}.swal2-checkbox-custom{align-items:center;justify-content:center;background:#fff;color:inherit;margin:1em auto}.swal2-checkbox-custom input{flex-shrink:0;margin:0 .4em}.giveaway-actions #getKey{display:none !important}.auto-task-giveaway-status{color:#fff;border-radius:10px;padding:0 5px;margin-left:5px}.auto-task-giveaway-status.active{background-color:#5cb85c}.auto-task-giveaway-status.not-active{background-color:#d9534f}`, '' ]);
  424. const __WEBPACK_DEFAULT_EXPORT__ = ___CSS_LOADER_EXPORT___.toString();
  425. },
  426. 314: function(module) {
  427. 'use strict';
  428. module.exports = function(cssWithMappingToString) {
  429. var list = [];
  430. list.toString = function toString() {
  431. return this.map(function(item) {
  432. var content = '';
  433. var needLayer = typeof item[5] !== 'undefined';
  434. if (item[4]) {
  435. content += '@supports ('.concat(item[4], ') {');
  436. }
  437. if (item[2]) {
  438. content += '@media '.concat(item[2], ' {');
  439. }
  440. if (needLayer) {
  441. content += '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {');
  442. }
  443. content += cssWithMappingToString(item);
  444. if (needLayer) {
  445. content += '}';
  446. }
  447. if (item[2]) {
  448. content += '}';
  449. }
  450. if (item[4]) {
  451. content += '}';
  452. }
  453. return content;
  454. }).join('');
  455. };
  456. list.i = function i(modules, media, dedupe, supports, layer) {
  457. if (typeof modules === 'string') {
  458. modules = [ [ null, modules, undefined ] ];
  459. }
  460. var alreadyImportedModules = {};
  461. if (dedupe) {
  462. for (var k = 0; k < this.length; k++) {
  463. var id = this[k][0];
  464. if (id != null) {
  465. alreadyImportedModules[id] = true;
  466. }
  467. }
  468. }
  469. for (var _k = 0; _k < modules.length; _k++) {
  470. var item = [].concat(modules[_k]);
  471. if (dedupe && alreadyImportedModules[item[0]]) {
  472. continue;
  473. }
  474. if (typeof layer !== 'undefined') {
  475. if (typeof item[5] === 'undefined') {
  476. item[5] = layer;
  477. } else {
  478. item[1] = '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {').concat(item[1], '}');
  479. item[5] = layer;
  480. }
  481. }
  482. if (media) {
  483. if (!item[2]) {
  484. item[2] = media;
  485. } else {
  486. item[1] = '@media '.concat(item[2], ' {').concat(item[1], '}');
  487. item[2] = media;
  488. }
  489. }
  490. if (supports) {
  491. if (!item[4]) {
  492. item[4] = ''.concat(supports);
  493. } else {
  494. item[1] = '@supports ('.concat(item[4], ') {').concat(item[1], '}');
  495. item[4] = supports;
  496. }
  497. }
  498. list.push(item);
  499. }
  500. };
  501. return list;
  502. };
  503. },
  504. 601: function(module) {
  505. 'use strict';
  506. module.exports = function(i) {
  507. return i[1];
  508. };
  509. }
  510. };
  511. var __webpack_module_cache__ = {};
  512. function __webpack_require__(moduleId) {
  513. var cachedModule = __webpack_module_cache__[moduleId];
  514. if (cachedModule !== undefined) {
  515. return cachedModule.exports;
  516. }
  517. var module = __webpack_module_cache__[moduleId] = {
  518. id: moduleId,
  519. exports: {}
  520. };
  521. __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  522. return module.exports;
  523. }
  524. !function() {
  525. __webpack_require__.n = function(module) {
  526. var getter = module && module.__esModule ? function() {
  527. return module['default'];
  528. } : function() {
  529. return module;
  530. };
  531. __webpack_require__.d(getter, {
  532. a: getter
  533. });
  534. return getter;
  535. };
  536. }();
  537. !function() {
  538. __webpack_require__.d = function(exports, definition) {
  539. for (var key in definition) {
  540. if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  541. Object.defineProperty(exports, key, {
  542. enumerable: true,
  543. get: definition[key]
  544. });
  545. }
  546. }
  547. };
  548. }();
  549. !function() {
  550. __webpack_require__.o = function(obj, prop) {
  551. return Object.prototype.hasOwnProperty.call(obj, prop);
  552. };
  553. }();
  554. var __webpack_exports__ = {};
  555. !function() {
  556. 'use strict';
  557. const external_Swal_namespaceObject = Swal;
  558. var external_Swal_default = __webpack_require__.n(external_Swal_namespaceObject);
  559. const external_Cookies_namespaceObject = Cookies;
  560. var external_Cookies_default = __webpack_require__.n(external_Cookies_namespaceObject);
  561. var auto_task = __webpack_require__(675);
  562. var javascript_utils_umd_min = __webpack_require__(991);
  563. const httpRequest = async (options, times = 0) => {
  564. if (window.TRACE) {
  565. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  566. }
  567. try {
  568. const result = await new Promise(resolve => {
  569. if (options.dataType) {
  570. options.responseType = options.dataType;
  571. }
  572. const requestObj = {
  573. ...{
  574. timeout: 3e4,
  575. ontimeout(data) {
  576. resolve({
  577. result: 'Error',
  578. statusText: 'Timeout',
  579. status: 601,
  580. data: data,
  581. options: options
  582. });
  583. },
  584. onabort(data) {
  585. resolve({
  586. result: 'Error',
  587. statusText: 'Aborted',
  588. status: 602,
  589. data: data,
  590. options: options
  591. });
  592. },
  593. onerror(data) {
  594. resolve({
  595. result: 'Error',
  596. statusText: 'Error',
  597. status: 603,
  598. data: data,
  599. options: options
  600. });
  601. },
  602. onload(data) {
  603. if (options.responseType === 'json' && data?.response && typeof data.response !== 'object') {
  604. try {
  605. data.response = JSON.parse(data.responseText);
  606. } catch (error) {}
  607. }
  608. resolve({
  609. result: 'Success',
  610. statusText: 'Load',
  611. status: 600,
  612. data: data,
  613. options: options
  614. });
  615. }
  616. },
  617. ...options
  618. };
  619. GM_xmlhttpRequest(requestObj);
  620. });
  621. if (window.DEBUG) {
  622. console.log('%cAuto-Task[httpRequest]:', 'color:blue', JSON.stringify(result));
  623. }
  624. if (result.status !== 600 && times < 2) {
  625. return await httpRequest(options, times + 1);
  626. }
  627. return result;
  628. } catch (error) {
  629. console.log('%cAuto-Task[httpRequest]:', 'color:red', JSON.stringify({
  630. errorMsg: error,
  631. options: options
  632. }));
  633. throwError(error, 'httpRequest');
  634. return {
  635. result: 'JsError',
  636. statusText: 'Error',
  637. status: 604,
  638. error: error,
  639. options: options
  640. };
  641. }
  642. };
  643. const tools_httpRequest = httpRequest;
  644. const echoLog = ({
  645. type,
  646. text,
  647. html,
  648. id
  649. }) => {
  650. const emptyStatus = {
  651. success: () => emptyStatus,
  652. error: () => emptyStatus,
  653. warning: () => emptyStatus,
  654. info: () => emptyStatus,
  655. view: () => emptyStatus
  656. };
  657. try {
  658. let ele;
  659. if (type) {
  660. switch (type) {
  661. case 'joiningSteamGroup':
  662. case 'leavingSteamGroup':
  663. case 'gettingSteamGroupId':
  664. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/groups/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  665. break;
  666.  
  667. case 'joiningSteamOfficialGroup':
  668. case 'leavingSteamOfficialGroup':
  669. case 'gettingSteamOfficialGroupId':
  670. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/games/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  671. break;
  672.  
  673. case 'subscribingForum':
  674. case 'unsubscribingForum':
  675. case 'gettingForumId':
  676. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/app/${text}/discussions/" target="_blank">${text}</a>]...<font></font></li>`);
  677. break;
  678.  
  679. case 'followingCurator':
  680. case 'unfollowingCurator':
  681. case 'gettingCuratorId':
  682. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/${text?.includes('/') ? text : `curator/${text}`}" target="_blank">${text}</a>]...<font></font></li>`);
  683. break;
  684.  
  685. case 'addingToWishlist':
  686. case 'removingFromWishlist':
  687. case 'followingGame':
  688. case 'unfollowingGame':
  689. case 'gettingSubid':
  690. case 'addingFreeLicense':
  691. case 'requestingPlayTestAccess':
  692. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/app/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  693. break;
  694.  
  695. case 'addingFreeLicenseSubid':
  696. ele = $(`<li>${i18n('addingFreeLicense')}[<a href="https://steamdb.info/sub/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  697. break;
  698.  
  699. case 'favoritingWorkshop':
  700. case 'unfavoritingWorkshop':
  701. case 'gettingWorkshopAppId':
  702. case 'votingUpWorkshop':
  703. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/sharedfiles/filedetails/?id=${text}" target="_blank">
  704. ${text}</a>]...<font></font></li>`);
  705. break;
  706.  
  707. case 'gettingAnnouncementParams':
  708. case 'likingAnnouncement':
  709. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/news/app/${text}/view/${id}" target="_blank">
  710. ${id}</a>]...<font></font></li>`);
  711. break;
  712.  
  713. case 'joiningDiscordServer':
  714. case 'gettingDiscordGuild':
  715. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/invite/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  716. break;
  717.  
  718. case 'leavingDiscordServer':
  719. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/channels/@me/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  720. break;
  721.  
  722. case 'updateDiscordAuth':
  723. ele = $(`<li style="color:red;">${i18n('updateDiscordAuth')}</li>`);
  724. break;
  725.  
  726. case 'followingTwitchChannel':
  727. case 'unfollowingTwitchChannel':
  728. case 'gettingTwitchChannelId':
  729. ele = $(`<li>${i18n(type)}[<a href="https://www.twitch.tv/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  730. break;
  731.  
  732. case 'gettingInsUserId':
  733. case 'followingIns':
  734. case 'unfollowingIns':
  735. ele = $(`<li>${i18n(type)}[<a href="https://www.instagram.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  736. break;
  737.  
  738. case 'gettingTwitterUserId':
  739. case 'followingTwitterUser':
  740. case 'unfollowingTwitterUser':
  741. ele = $(`<li>${i18n(type)}[<a href="https://x.com/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  742. break;
  743.  
  744. case 'retweetting':
  745. case 'unretweetting':
  746. ele = $(`<li>${i18n(type)}${text}...<font></font></li>`);
  747. break;
  748.  
  749. case 'joiningReddit':
  750. case 'leavingReddit':
  751. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/r/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  752. break;
  753.  
  754. case 'followingRedditUser':
  755. case 'unfollowingRedditUser':
  756. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/user/${text?.replace('u_', '')}" target="_blank">
  757. ${text?.replace('u_', '')}</a>]...<font></font></li>`);
  758. break;
  759.  
  760. case 'followingYtbChannel':
  761. case 'unfollowingYtbChannel':
  762. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/channel/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  763. break;
  764.  
  765. case 'likingYtbVideo':
  766. case 'unlikingYtbVideo':
  767. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/watch?v=${text}" target="_blank">${text}</a>]...<font></font></li>`);
  768. break;
  769.  
  770. case 'gettingVkId':
  771. case 'joiningVkGroup':
  772. case 'leavingVkGroup':
  773. case 'joiningVkPublic':
  774. case 'leavingVkPublic':
  775. case 'sendingVkWall':
  776. case 'deletingVkWall':
  777. ele = $(`<li>${i18n(type)}[<a href="https://vk.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  778. break;
  779.  
  780. case 'visitingLink':
  781. ele = $(`<li>${i18n('visitingLink')}[<a href="${text}" target="_blank">${text}</a>]...<font></font></li>`);
  782. break;
  783.  
  784. case 'verifyingInsAuth':
  785. case 'text':
  786. ele = $(`<li>${i18n(text)}<font></font></li>`);
  787. break;
  788.  
  789. case 'html':
  790. ele = $(text || html);
  791. break;
  792.  
  793. case 'whiteList':
  794. ele = $(`<li><font class="warning">${i18n('skipTask')}[${text}(${id})](${i18n('whiteList')})</font></li>`);
  795. break;
  796.  
  797. case 'globalOptionsSkip':
  798. ele = $(`<li>${i18n('skipTaskOption')}<font class="warning">${text}</font></li>`);
  799. break;
  800.  
  801. default:
  802. ele = $(`<li>${i18n('unKnown')}:${type}(${text})...<font></font></li>`);
  803. break;
  804. }
  805. } else if (text) {
  806. ele = $(`<li>${i18n(text)}<font></font></li>`);
  807. } else if (html) {
  808. ele = $(html);
  809. } else {
  810. ele = $('<li><font></font></li>');
  811. }
  812. ele.addClass('card-text');
  813. $('#auto-task-info').append(ele);
  814. ele[0]?.scrollIntoView();
  815. const font = ele.find('font');
  816. const status = {
  817. font: font,
  818. success(text = 'Success', html = false) {
  819. this.font?.attr('class', '').addClass('success');
  820. html ? this.font?.html(text) : this.font?.text(text);
  821. return this;
  822. },
  823. error(text = 'Error', html = false) {
  824. this.font?.attr('class', '').addClass('error');
  825. html ? this.font?.html(text) : this.font?.text(text);
  826. return this;
  827. },
  828. warning(text = 'Warning', html = false) {
  829. this.font?.attr('class', '').addClass('warning');
  830. html ? this.font?.html(text) : this.font?.text(text);
  831. return this;
  832. },
  833. info(text = 'Info', html = false) {
  834. this.font?.attr('class', '').addClass('info');
  835. html ? this.font?.html(text) : this.font?.text(text);
  836. return this;
  837. },
  838. view() {
  839. this.font?.[0].scrollIntoView();
  840. return this;
  841. }
  842. };
  843. return status;
  844. } catch (error) {
  845. throwError(error, 'echoLog');
  846. return emptyStatus;
  847. }
  848. };
  849. const scripts_echoLog = echoLog;
  850. const unique = array => {
  851. try {
  852. return [ ...new Set(array) ];
  853. } catch (error) {
  854. throwError(error, 'unique');
  855. return [];
  856. }
  857. };
  858. const delay = (time = 1e3) => new Promise(resolve => {
  859. setTimeout(() => {
  860. resolve(true);
  861. }, time);
  862. });
  863. const getRedirectLink = async link => {
  864. try {
  865. if (!link) {
  866. return null;
  867. }
  868. const redirectLinksCache = GM_getValue('redirectLinks') || {};
  869. if (redirectLinksCache[link]) {
  870. redirectLinksCache[link];
  871. }
  872. return await tools_httpRequest({
  873. url: link,
  874. method: 'GET'
  875. }).then(({
  876. data
  877. }) => {
  878. if (data?.finalUrl) {
  879. redirectLinksCache[link] = data.finalUrl;
  880. GM_setValue('redirectLinks', redirectLinksCache);
  881. return data.finalUrl;
  882. }
  883. return null;
  884. });
  885. } catch (error) {
  886. throwError(error, 'getRedirectLink');
  887. return null;
  888. }
  889. };
  890. const visitLink = async (link, options) => {
  891. try {
  892. const logStatus = scripts_echoLog({
  893. type: 'visitLink',
  894. text: link
  895. });
  896. return await tools_httpRequest({
  897. url: link,
  898. method: 'GET',
  899. ...options
  900. }).then(({
  901. result,
  902. statusText,
  903. status
  904. }) => {
  905. if (result === 'Success') {
  906. logStatus.success();
  907. return true;
  908. }
  909. logStatus.error(`${result}:${statusText}(${status})`);
  910. return false;
  911. });
  912. } catch (error) {
  913. throwError(error, 'visitLink');
  914. return false;
  915. }
  916. };
  917. const getUrlQuery = url => {
  918. try {
  919. const query = {};
  920. if (url) {
  921. if (url.includes('?')) {
  922. url.split('?')[1].replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  923. query[key] = value;
  924. return str;
  925. });
  926. }
  927. } else {
  928. window.location.search.replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  929. query[key] = value;
  930. return str;
  931. });
  932. }
  933. return query;
  934. } catch (error) {
  935. throwError(error, 'getUrlQuery');
  936. return {};
  937. }
  938. };
  939. const getUuid = () => {
  940. const uuidUrl = URL.createObjectURL(new Blob()).toString();
  941. return uuidUrl.slice(uuidUrl.lastIndexOf('/') + 1);
  942. };
  943. const stringToColour = str => {
  944. try {
  945. let hash = 0;
  946. for (let i = 0; i < str.length; i++) {
  947. hash = str.charCodeAt(i) + ((hash << 5) - hash);
  948. }
  949. let colour = '#';
  950. for (let i = 0; i < 3; i++) {
  951. const value = hash >> i * 8 & 255;
  952. colour += `00${value.toString(16)}`.slice(-2);
  953. }
  954. return colour;
  955. } catch (error) {
  956. throwError(error, 'stringToColour');
  957. return '#fff';
  958. }
  959. };
  960. const defaultGlobalOptions = {
  961. doTask: {
  962. discord: {
  963. servers: true
  964. },
  965. instagram: {
  966. users: true
  967. },
  968. twitch: {
  969. channels: true
  970. },
  971. twitter: {
  972. users: true,
  973. retweets: true
  974. },
  975. vk: {
  976. names: true
  977. },
  978. youtube: {
  979. channels: true,
  980. likes: true
  981. },
  982. reddit: {
  983. reddits: true
  984. },
  985. steam: {
  986. groups: true,
  987. officialGroups: true,
  988. wishlists: true,
  989. follows: true,
  990. forums: true,
  991. workshops: true,
  992. curators: true,
  993. workshopVotes: true,
  994. announcements: true,
  995. licenses: true,
  996. playtests: true
  997. }
  998. },
  999. undoTask: {
  1000. discord: {
  1001. servers: true
  1002. },
  1003. instagram: {
  1004. users: true
  1005. },
  1006. twitch: {
  1007. channels: true
  1008. },
  1009. twitter: {
  1010. users: true,
  1011. retweets: true
  1012. },
  1013. vk: {
  1014. names: true
  1015. },
  1016. youtube: {
  1017. channels: true,
  1018. likes: true
  1019. },
  1020. reddit: {
  1021. reddits: true
  1022. },
  1023. steam: {
  1024. groups: true,
  1025. officialGroups: true,
  1026. wishlists: true,
  1027. follows: true,
  1028. forums: true,
  1029. workshops: true,
  1030. curators: true
  1031. }
  1032. },
  1033. ASF: {
  1034. AsfEnabled: false,
  1035. AsfIpcUrl: '',
  1036. AsfIpcPassword: '',
  1037. AsfBotname: 'asf'
  1038. },
  1039. position: {
  1040. buttonSideX: 'right',
  1041. buttonSideY: 'top',
  1042. buttonDistance: '15,30',
  1043. showButtonSideX: 'right',
  1044. showButtonSideY: 'top',
  1045. showButtonDistance: '15,30',
  1046. logSideX: 'right',
  1047. logSideY: 'bottom',
  1048. logDistance: '10,10'
  1049. },
  1050. hotKey: {
  1051. doTaskKey: 'alt + d',
  1052. undoTaskKey: 'alt + u',
  1053. toggleLogKey: 'alt + l'
  1054. },
  1055. other: {
  1056. twitterVerifyId: '783214',
  1057. youtubeVerifyChannel: 'UCrXUsMBcfTVqwAS7DKg9C0Q',
  1058. autoUpdateSource: 'jsdelivr',
  1059. language: 'zh',
  1060. checkLogin: true,
  1061. checkLeftKey: true,
  1062. defaultShowButton: true,
  1063. defaultShowLog: true,
  1064. debug: false,
  1065. receivePreview: true
  1066. }
  1067. };
  1068. const userDefinedGlobalOptions = GM_getValue('globalOptions') || {};
  1069. const assignObject = (obj1, obj2) => {
  1070. try {
  1071. const newObj = {};
  1072. for (const [ key, value ] of Object.entries(obj1)) {
  1073. if (Object.prototype.toString.call(value) === '[object Object]' && Object.prototype.toString.call(obj2[key]) === '[object Object]') {
  1074. newObj[key] = assignObject(value, obj2[key]);
  1075. } else {
  1076. newObj[key] = obj2[key] ?? value;
  1077. }
  1078. }
  1079. return newObj;
  1080. } catch (error) {
  1081. throwError(error, 'assignObject');
  1082. return defaultGlobalOptions;
  1083. }
  1084. };
  1085. const globalOptions = assignObject(defaultGlobalOptions, userDefinedGlobalOptions);
  1086. const saveData = () => {
  1087. try {
  1088. const data = {};
  1089. $('#globalOptionsForm').serializeArray().map(value => {
  1090. data[value.name] = value.value;
  1091. return value;
  1092. });
  1093. $.makeArray($('#globalOptionsForm input')).map(element => {
  1094. const name = $(element).attr('name');
  1095. const keys = name.split('.');
  1096. if (keys.length === 3) {
  1097. globalOptions[keys[0]][keys[1]][keys[2]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1098. } else if (keys.length === 2) {
  1099. globalOptions[keys[0]][keys[1]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1100. }
  1101. return element;
  1102. });
  1103. GM_setValue('globalOptions', globalOptions);
  1104. external_Swal_default().fire({
  1105. title: i18n('changeGlobalOptionsSuccess'),
  1106. icon: 'success'
  1107. });
  1108. } catch (error) {
  1109. throwError(error, 'saveData');
  1110. }
  1111. };
  1112. const changeGlobalOptions = showType => {
  1113. try {
  1114. let globalOptionsForm = `<form id="globalOptionsForm" class="auto-task-form">
  1115. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  1116. for (const [ type, data1 ] of Object.entries(globalOptions)) {
  1117. for (const [ option, data2 ] of Object.entries(data1)) {
  1118. if ([ 'other', 'position', 'hotKey', 'ASF' ].includes(type)) {
  1119. if (typeof data2 === 'boolean') {
  1120. 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>`;
  1121. } else {
  1122. 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>`;
  1123. }
  1124. } else {
  1125. for (const [ socialType, data3 ] of Object.entries(data2)) {
  1126. 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>`;
  1127. }
  1128. }
  1129. }
  1130. }
  1131. globalOptionsForm += '</tbody></table></form>';
  1132. if (showType === 'swal') {
  1133. external_Swal_default().fire({
  1134. title: i18n('globalOptions'),
  1135. html: globalOptionsForm,
  1136. showConfirmButton: true,
  1137. confirmButtonText: i18n('save'),
  1138. showCancelButton: true,
  1139. cancelButtonText: i18n('close')
  1140. }).then(({
  1141. isConfirmed
  1142. }) => {
  1143. if (isConfirmed) {
  1144. saveData();
  1145. }
  1146. });
  1147. } else {
  1148. $('body').append(`<h2>${i18n('globalOptions')}</h2>${globalOptionsForm}`);
  1149. }
  1150. } catch (error) {
  1151. throwError(error, 'changeGlobalOptions');
  1152. }
  1153. };
  1154. const data = {
  1155. website: '网站',
  1156. type: '类型',
  1157. edit: '编辑',
  1158. whiteList: '白名单',
  1159. skipTask: '跳过撤销任务',
  1160. whiteListOptions: '白名单设置',
  1161. changeWhiteListOption: '设置白名单(%0)',
  1162. whiteListNotFound: '找不到此项白名单: %0',
  1163. changeWhiteListSuccess: '白名单修改成功,刷新生效!',
  1164. changeWebsiteOptions: '网站设置',
  1165. changeGlobalOptions: '全局设置',
  1166. ok: '是',
  1167. save: '保存',
  1168. close: '关闭',
  1169. return: '返回',
  1170. option: '选项',
  1171. value: '值',
  1172. websiteOptions: '当前网站设置',
  1173. changeWebsiteOptionsSuccess: '更改当前网站设置成功,刷新生效!',
  1174. changeGlobalOptionsSuccess: '更改全局设置成功,刷新生效!',
  1175. needLogin: '请先登录!',
  1176. getTasksInfo: '正在获取并处理任务信息...',
  1177. gettingKey: '正在获取Key...',
  1178. verifyingTask: '正在验证任务',
  1179. notice: '自动任务脚本提醒',
  1180. noKeysLeft: '此页面已经没有剩余key了,是否关闭?',
  1181. giveawayEnded: '此活动已结束,是否关闭?',
  1182. giveawayNotWork: '此活动因某些原因(已结束/暂停/未开始...)不可用(如果是脚本误判请及时反馈),是否关闭?',
  1183. confirm: '确定',
  1184. cancel: '取消',
  1185. unKnown: '未知',
  1186. unKnownTaskType: '未识别的任务',
  1187. doing: '正在做任务',
  1188. allTasksComplete: '所有任务已完成!',
  1189. getTaskIdFailed: '获取任务Id失败!',
  1190. initSuccess: '%0 初始化成功!',
  1191. initFailed: '%0 初始化失败!',
  1192. errorLink: '链接错误: %0',
  1193. needInit: '请先初始化',
  1194. verifyingAuth: '正在验证%0凭证...',
  1195. updatingAuth: '正在更新%0凭证...',
  1196. refreshingToken: '正在刷新%0凭证...',
  1197. settingToken: '正在设置%0凭证...',
  1198. steamStoreTab: 'Steam商店(弹窗)',
  1199. steamCommunityTab: 'Steam社区(弹窗)',
  1200. initing: '正在初始化...',
  1201. getFailed: '获取%0失败!',
  1202. checkLoginFailed: '检测登录状态失败!',
  1203. checkLeftKeyFailed: '检测剩余Key失败!',
  1204. userId: '用户Id',
  1205. joiningGiveaway: '正在加入赠Key',
  1206. needJoinGiveaway: '需要先加入赠Key',
  1207. cannotUndo: '此网站不支持取消任务',
  1208. verifyAuth: '正在验证 %0 凭证...',
  1209. closePageNotice: '如果此页面没有自动关闭,请自行关闭本页面。',
  1210. errorReport: '检测到脚本报错,是否前往反馈BUG?',
  1211. visitingLink: '正在访问链接: ',
  1212. doTask: '做任务',
  1213. undoTask: '撤销任务',
  1214. verifyTask: '验证任务',
  1215. getKey: '获取Key',
  1216. selectAll: '全选',
  1217. selectNone: '全不选',
  1218. invertSelect: '反选',
  1219. doFreeTask: '加入免费赠品',
  1220. doPointTask: '加入点数赠品',
  1221. skipTaskOption: '设置中已配置跳过任务',
  1222. other: '其他',
  1223. globalOptions: '全局设置',
  1224. checkLogin: '登录检测</br>需要登录的网站自动登录,部分网站支持',
  1225. checkLeftKey: '剩余Key检测</br>赠Key活动结束提示是否关闭,部分网站支持',
  1226. twitterVerifyId: '通过尝试关注该账号验证Twitter凭证</br>默认为Twitter官方帐号 783214</br>不想关注官方账号可以改为自己的帐号',
  1227. youtubeVerifyChannel: '通过尝试订阅该频道验证YouTube凭证</br>默认为YouTube官方频道 UCrXUsMBcfTVqwAS7DKg9C0Q</br>不想关注官方频道可以改为自己的频道',
  1228. autoUpdateSource: '更新源</br>github: 需代理,实时更新</br>jsdelivr: 可不用代理,更新有延迟</br>standby: 备用</br>auto: 依次使用github, jsdelivr, standby源进行尝试更新',
  1229. saveGlobalOptions: '保存设置',
  1230. settingPage: '设置页面',
  1231. name: '名称',
  1232. version: '版本',
  1233. scriptManager: '脚本管理器',
  1234. script: '脚本',
  1235. environment: '环境',
  1236. os: '系统',
  1237. browser: '浏览器',
  1238. getId: '获取 %0 id',
  1239. getTwitterUserId: '获取Twitter用户id(获取id功能仅在设置页面可用)',
  1240. getYoutubeChannelId: '获取Youtube频道id(获取id功能仅在设置页面可用)',
  1241. showButton: '显示按钮',
  1242. hideButton: '隐藏按钮',
  1243. showLog: '显示日志',
  1244. hideLog: '隐藏日志',
  1245. defaultShowButton: '默认显示按钮',
  1246. defaultShowLog: '默认显示日志',
  1247. debug: '输出调试日志,不要开启此选项!',
  1248. receivePreview: '接收预览版更新',
  1249. position: '组件位置',
  1250. buttonSideX: '按钮区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1251. buttonSideY: '按钮区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1252. buttonDistance: '按钮区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1253. showButtonSideX: '显示按钮水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1254. showButtonSideY: '显示按钮垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1255. showButtonDistance: '显示按钮距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1256. logSideX: '日志区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1257. logSideY: '日志区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1258. logDistance: '日志区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1259. hotKey: '快捷键',
  1260. doTaskKey: '做任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1261. undoTaskKey: '撤销任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1262. toggleLogKey: '显示/隐藏日志快捷键</br>(实时预览功能仅在设置页面可用)',
  1263. tasksHistory: '任务历史',
  1264. clearHistory: '清空历史',
  1265. clearHistoryFinished: '已清空任务历史!',
  1266. deleteTask: '删除任务',
  1267. lastChangeTime: '最后一次修改时间',
  1268. clearTaskFinished: '删除以下任务完成!',
  1269. clearTaskFailed: '删除任务失败,没有找到任务名!',
  1270. syncData: '数据同步',
  1271. settingData: '正在上传数据...',
  1272. gettingData: '正在获取数据...',
  1273. help: '帮助',
  1274. fileName: '文件名',
  1275. upload2gist: '同步到Gist',
  1276. downloadFromGist: '从Gist同步',
  1277. saveAndTest: '保存配置并测试',
  1278. testSuccess: '测试成功!',
  1279. testFailed: '测试失败!',
  1280. saveAndTestNotice: '请先保存配置并测试!',
  1281. processingData: '正在处理数据...',
  1282. updatingData: '正在上传数据...',
  1283. syncDataSuccess: '同步数据成功!',
  1284. syncDataFailed: '同步数据失败,请在控制台查看错误信息!',
  1285. downloadingData: '正在下载数据...',
  1286. checkedNoData: '没有检测到远程数据,请确认配置是否正确!',
  1287. savingData: '正在保存数据...',
  1288. syncHistory: '同步任务历史',
  1289. checkUpdateFailed: '检测更新失败',
  1290. newVersionNotice: '检测到新版本V%0, <a class="high-light" href="%1" target="_blank">点此更新</a>',
  1291. language: '语言</br>目前仅支持zh: 中文, en: 英文',
  1292. gistOptions: 'Gist 设置',
  1293. swalNotice: '检测到您第一次安装V4版本脚本,请前往阅读用前必读内容!',
  1294. echoNotice: '检测到您第一次安装V4版本脚本,请<a class="high-light" href="%0" target="_blank">点此前往</a>阅读用前必读内容!',
  1295. noticeLink: 'https://auto-task-doc.js.org/guide/#用前必读',
  1296. toGithub: '前往Github反馈',
  1297. toKeylol: '前往其乐论坛反馈',
  1298. copySuccess: '错误信息已复制到剪切板,是否前往其乐论坛反馈?',
  1299. copyFailed: '请复制下方错误信息后前往Keylol论坛反馈!',
  1300. updateText: '%0 版本更新内容:',
  1301. Active: '进行中',
  1302. Ended: '已结束',
  1303. Banned: '已封禁',
  1304. Paused: '已暂停',
  1305. notStart: '未开始',
  1306. noRemoteData: '检测到远程无数据',
  1307. errorRemoteDataFormat: '远程数据格式错误',
  1308. updateHistory: '历史更新记录<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">点此查看</a>',
  1309. AsfEnabled: '使用ASF做Steam相关任务(需<a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a>插件)',
  1310. AsfIpcUrl: 'ASF IPC 地址',
  1311. AsfIpcPassword: 'ASF IPC 密码',
  1312. versionNotMatched: '脚本管理器版本过低,需TamperMonkey >= 5.2.0或TamperMonkey Beta >= 5.2.6196',
  1313. groups: '组',
  1314. officialGroups: '官方组',
  1315. wishlists: '愿望单',
  1316. follows: '游戏关注',
  1317. forums: '论坛',
  1318. workshops: '创意工坊收藏',
  1319. curators: '鉴赏家',
  1320. workshopVotes: '创意工坊点赞',
  1321. announcements: '社区通知',
  1322. steamCommunity: 'Steam社区',
  1323. steamStore: 'Steam商店',
  1324. licenses: '入库免费游戏',
  1325. playtests: '请求访问权限',
  1326. needLoginSteamStore: '请先<a href="https://store.steampowered.com/login/" target="_blank">登录Steam商店</a>',
  1327. needLoginSteamCommunity: '请先<a href="https://steamcommunity.com/login/home/" target="_blank">登录Steam社区</a>',
  1328. joiningSteamGroup: '正在加入Steam组',
  1329. leavingSteamGroup: '正在退出Steam组',
  1330. gettingSteamGroupId: '正在获取Steam组Id',
  1331. joiningSteamOfficialGroup: '正在加入Steam官方组',
  1332. leavingSteamOfficialGroup: '正在退出Steam官方组',
  1333. gettingSteamOfficialGroupId: '正在获取Steam官方组Id',
  1334. subscribingForum: '正在订阅Steam论坛',
  1335. unsubscribingForum: '正在取消订阅Steam论坛',
  1336. gettingForumId: '正在获取Steam论坛Id',
  1337. followingCurator: '正在关注Steam鉴赏家',
  1338. unfollowingCurator: '正在取关Steam鉴赏家',
  1339. gettingCuratorId: '正在获取Steam鉴赏家Id',
  1340. addingToWishlist: '正在添加游戏到Steam愿望单',
  1341. removingFromWishlist: '正在从Steam愿望单移除游戏',
  1342. followingGame: '正在关注Steam游戏',
  1343. unfollowingGame: '正在取关Steam游戏',
  1344. favoritingWorkshop: '正在收藏Steam创意工坊物品',
  1345. unfavoritingWorkshop: '正在取消收藏Steam创意工坊物品',
  1346. gettingWorkshopAppId: '正在获取Steam创意工坊物品Id',
  1347. votingUpWorkshop: '正在点赞Steam创意工坊物品',
  1348. gettingAnnouncementParams: '正在获取Steam通知信息',
  1349. likingAnnouncement: '正在点赞Steam通知',
  1350. changingArea: '正在更换Steam地区: %0...',
  1351. notNeededChangeArea: '当前地区不需要更换',
  1352. noAnotherArea: '请检测是否开启正确开启代理',
  1353. gettingAreaInfo: '正在获取Steam地区信息...',
  1354. changeAreaNotice: '疑似锁区游戏,尝试换区执行',
  1355. steamFinishNotice: 'Steam任务完成,尝试将购物车地区换回CN',
  1356. gettingSubid: '正在获取游戏subid',
  1357. addingFreeLicense: '正在入库',
  1358. missParams: '缺少参数',
  1359. gettingLicenses: '正在获取Licenses...',
  1360. requestingPlayTestAccess: '正在请求访问权限',
  1361. tryChangeAreaNotice: '此功能无法检测游戏是否限区,因此会尝试换区后再入库,换区失败也不影响后续入库',
  1362. gettingUserLink: '正在获取Steam用户社区链接...',
  1363. retry: '重试',
  1364. owned: '已拥有',
  1365. redirect: '重定向',
  1366. initingASF: '正在初始化ASF...',
  1367. servers: '服务器',
  1368. joiningDiscordServer: '正在加入Discord服务器',
  1369. leavingDiscordServer: '正在退出Discord服务器',
  1370. gettingDiscordGuild: '正在获取Discord服务器Id',
  1371. getDiscordAuthFailed: '获取Discord凭证失败,请检测Discord帐号是否已登录',
  1372. discordImportantNotice: '重要提醒!!!',
  1373. discordImportantNoticeText: '由于Discord网站后台更新,目前使用此脚本加组后可能会导致Discord帐号被强制退出,且需要两步验证才能正常登录,请谨慎使用!!!',
  1374. continue: '继续',
  1375. skipDiscordTask: '跳过Discord任务',
  1376. continueAndDontRemindAgain: '继续且不再提醒',
  1377. users: '用户',
  1378. loginIns: '请先<a href="https://www.instagram.com/accounts/login/" target="_blank">登录Instagram</a>',
  1379. insBanned: '您的Instagram账户已被封禁',
  1380. verifyingInsAuth: '正在验证Instagram凭证...',
  1381. gettingInsUserId: '正在获取Instagram用户Id',
  1382. followingIns: '正在关注Instagram用户',
  1383. unfollowingIns: '正在取关Instagram用户',
  1384. reddits: '社区/用户',
  1385. loginReddit: '请先<a href="https://www.reddit.com/login/" target="_blank">登录Reddit</a>',
  1386. changingRedditVersion: '正在切换Reddit为新版页面...',
  1387. joiningReddit: '正在加入Reddit社区',
  1388. leavingReddit: '正在退出Reddit社区',
  1389. followingRedditUser: '正在关注Reddit用户',
  1390. unfollowingRedditUser: '正在取关Reddit用户',
  1391. channels: '频道',
  1392. followingTwitchChannel: '正在关注Twitch频道',
  1393. unfollowingTwitchChannel: '正在取关Twitch频道',
  1394. gettingTwitchChannelId: '正在获取Twitch频道Id',
  1395. checkingTwitchIntegrity: '正在检查Twitch完整性...',
  1396. twitterUser: '推特用户',
  1397. retweets: '转推',
  1398. gettingTwitterUserId: '正在获取推特用户Id',
  1399. followingTwitterUser: '正在关注推特用户',
  1400. unfollowingTwitterUser: '正在取关推特用户',
  1401. retweetting: '正在转推',
  1402. unretweetting: '正在撤销转推',
  1403. names: '组/社区/动态',
  1404. loginVk: '请先<a href="https://vk.com/login/" target="_blank">登录Vk</a>',
  1405. gettingVkId: '正在获取Vk任务Id',
  1406. joiningVkGroup: '正在加入Vk组',
  1407. leavingVkGroup: '正在退出Vk组',
  1408. joiningVkPublic: '正在加入Vk社区',
  1409. leavingVkPublic: '正在退出Vk社区',
  1410. sendingVkWall: '正在转发Vk动态',
  1411. deletingVkWall: '正在撤销转发Vk动态',
  1412. youtubeChannel: 'YouTube频道',
  1413. likes: '点赞',
  1414. loginYtb: '请先<a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">登录YouTube</a>',
  1415. tryUpdateYtbAuth: '请尝试<a href="https://www.youtube.com/#auth" target="_blank">更新YouTube凭证</a>',
  1416. gettingYtbToken: '正在获取YouTube Token...',
  1417. followingYtbChannel: '正在订阅YouTube频道',
  1418. unfollowingYtbChannel: '正在退订YouTube频道',
  1419. likingYtbVideo: '正在点赞YouTube视频',
  1420. unlikingYtbVideo: '正在取消点赞YouTube视频',
  1421. giveKeyNoticeBefore: '每次验证间隔15s',
  1422. giveKeyNoticeAfter: '如果没有key, 请在<a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>查看',
  1423. noPoints: '点数不够,跳过抽奖',
  1424. getNeedPointsFailed: '获取所需点数失败,跳过抽奖',
  1425. joiningLottery: '正在加入抽奖',
  1426. doingGleamTask: '正在做Gleam任务...',
  1427. gettingGleamLink: '正在获取Gleam任务链接...',
  1428. gleamTaskNotice: '如果此页面长时间未关闭,请完成任一任务后自行关闭!',
  1429. verifiedGleamTasks: '已尝试验证所有任务,验证失败的任务请尝试手动验证或完成!',
  1430. campaign: '检测到人机验证,请完成验证后重新验证任务!',
  1431. gsNotice: '为避免得到"0000-0000-0000"key, 已自动屏蔽"Grab Key"按钮,获取key时请关闭脚本!',
  1432. giveeClubVerifyNotice: '正在验证任务...',
  1433. giveeClubVerifyFinished: '请等待验证完成后自行加入赠Key',
  1434. doingKeyhubTask: '正在做Keyhub任务...',
  1435. SweepWidgetNotice: '正在处理并验证任务,每次验证任务有1~3s间隔防止触发验证过快警告...',
  1436. tasksNotCompleted: '任务未完成',
  1437. confirmingTask: '正在跳过警告页面...'
  1438. };
  1439. const zh_CN = data;
  1440. const en_US_data = {
  1441. website: 'Website',
  1442. type: 'Type',
  1443. edit: 'Edit',
  1444. whiteList: 'Whitelist',
  1445. skipTask: 'Skip undo task',
  1446. whiteListOptions: 'Whitelist options',
  1447. changeWhiteListOption: 'Whitelist option(%0)',
  1448. whiteListNotFound: 'Cannot find this whitelist: %0',
  1449. changeWhiteListSuccess: 'The whitelist is successfully modified, and the page refresh will take effect!',
  1450. changeWebsiteOptions: 'Website options',
  1451. changeGlobalOptions: 'Global options',
  1452. ok: 'OK',
  1453. save: 'Save',
  1454. close: 'Close',
  1455. return: 'Return',
  1456. option: 'Option',
  1457. value: 'Value',
  1458. websiteOptions: 'Current website settings',
  1459. changeWebsiteOptionsSuccess: 'The current website setting is changed successfully, and the page refresh will take effect!',
  1460. changeGlobalOptionsSuccess: 'The global setting is changed successfully, and the refresh will take effect!',
  1461. needLogin: 'Please log in first!',
  1462. getTasksInfo: 'Obtaining and processing task information...',
  1463. gettingKey: 'Getting Key...',
  1464. verifyingTask: 'Verifying task',
  1465. notice: 'Automatic task script notice',
  1466. noKeysLeft: 'There are no more keys left on this page. Do you want to close it?',
  1467. giveawayEnded: 'This event has ended, do you want to close it?',
  1468. 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?',
  1469. confirm: 'Confirm',
  1470. cancel: 'Cancel',
  1471. unKnown: 'Unknown',
  1472. unKnownTaskType: 'Unrecognized task',
  1473. doing: 'Doing a task',
  1474. allTasksComplete: 'All tasks have been completed!',
  1475. getTaskIdFailed: 'Failed to obtain task Id!',
  1476. initSuccess: '%0 was initialized successfully!',
  1477. initFailed: '%0 initialization failed!',
  1478. errorLink: 'Link error: %0',
  1479. needInit: 'Please initialize first',
  1480. verifyingAuth: 'Verifying %0 token...',
  1481. updatingAuth: 'Update %0 token...',
  1482. refreshingToken: 'Refreshing %0 token...',
  1483. settingToken: 'Setting %0 token...',
  1484. steamStoreTab: 'Steam store (new tab)',
  1485. steamCommunityTab: 'Steam community(new tab)',
  1486. initing: 'Initializing...',
  1487. getFailed: 'Failed to get %0!',
  1488. checkLoginFailed: 'Failed to detect login status!',
  1489. checkLeftKeyFailed: 'Failed to detect the remaining keys!',
  1490. userId: 'User Id',
  1491. joiningGiveaway: 'Joining giveaway',
  1492. needJoinGiveaway: 'Need to join the giveaway first',
  1493. cannotUndo: 'This website does not support canceling tasks',
  1494. verifyAuth: 'Verifying %0 token...',
  1495. closePageNotice: 'f this page does not close automatically, please close this page yourself.',
  1496. errorReport: 'A script error is detected, do you want to report the BUG?',
  1497. visitingLink: 'Visiting link: ',
  1498. doTask: 'DoTask',
  1499. undoTask: 'UndoTask',
  1500. verifyTask: 'Verify',
  1501. getKey: 'GetKey',
  1502. selectAll: 'SelectAll',
  1503. selectNone: 'SelectNone',
  1504. invertSelect: 'InvertSelect',
  1505. doFreeTask: 'FreeTask',
  1506. doPointTask: 'PointTask',
  1507. skipTaskOption: 'Skip task has been configured in the settings',
  1508. other: 'Other',
  1509. globalOptions: 'Global Options',
  1510. checkLogin: 'Login detection</br>Need to log in to the website automatically log in, part of this website supports.',
  1511. checkLeftKey: 'Key remaining detection</br>The end of the giveaway event prompts whether to close or not, part of this website supports.',
  1512. 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.',
  1513. 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.',
  1514. 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.',
  1515. saveGlobalOptions: 'SaveSettings',
  1516. settingPage: 'Setting Page',
  1517. name: 'Name',
  1518. version: 'Version',
  1519. scriptManager: 'Script Manager',
  1520. script: 'Script',
  1521. environment: 'Environment',
  1522. os: 'OS',
  1523. browser: 'Browser',
  1524. getId: 'Get %0 id',
  1525. getTwitterUserId: 'Get Twitter user id (Get id function is only available on the settings page).',
  1526. getYoutubeChannelId: 'Get Youtube channel id (Get id function is only available on the settings page).',
  1527. showButton: 'ShowButton',
  1528. hideButton: 'HideButton',
  1529. showLog: 'ShowLog',
  1530. hideLog: 'HideLog',
  1531. defaultShowButton: 'Default display button',
  1532. defaultShowLog: 'Display log by default',
  1533. debug: 'Output debug log, do not enable this option!',
  1534. receivePreview: 'Receive preview updates',
  1535. position: 'Component position',
  1536. buttonSideX: 'Horizontal positioning of the button area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1537. 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',
  1538. 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',
  1539. showButtonSideX: 'ShowButton horizontal positioning (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1540. showButtonSideY: 'ShowButton vertical positioning (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1541. 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',
  1542. logSideX: 'Horizontal positioning of the log area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1543. logSideY: 'Vertical positioning of the log area (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1544. 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',
  1545. hotKey: 'Shortcut key',
  1546. doTaskKey: 'DoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1547. undoTaskKey: 'UndoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1548. toggleLogKey: 'ShowLog/HideLog shortcut keys</br> (real-time preview function is only available on the settings page).',
  1549. tasksHistory: 'TasksHistory',
  1550. clearHistory: 'Clear history',
  1551. clearHistoryFinished: 'The mission history has been cleared!',
  1552. deleteTask: 'Delete task',
  1553. lastChangeTime: 'Last Change Time',
  1554. clearTaskFinished: 'Delete the following tasks completed!',
  1555. clearTaskFailed: 'Failed to delete the task, the task name was not found!',
  1556. syncData: 'DataSync',
  1557. settingData: 'Uploading data...',
  1558. gettingData: 'Getting data...',
  1559. help: 'Help',
  1560. fileName: 'Filename',
  1561. upload2gist: 'Sync to Gist',
  1562. downloadFromGist: 'Sync from Gist',
  1563. saveAndTest: 'Save configuration and test',
  1564. testSuccess: 'Test success!',
  1565. testFailed: 'Test failed!',
  1566. saveAndTestNotice: 'Please save the configuration and test first!',
  1567. processingData: 'Processing data...',
  1568. updatingData: 'Uploading data...',
  1569. syncDataSuccess: 'Synchronized data successfully!',
  1570. syncDataFailed: 'Failed to synchronize data, please check the error message on the console!',
  1571. downloadingData: 'Downloading data...',
  1572. checkedNoData: 'No remote data is detected, please confirm whether the configuration is correct!',
  1573. savingData: 'Saving data...',
  1574. syncHistory: 'Synchronize tasks history',
  1575. checkUpdateFailed: 'Check update failed',
  1576. newVersionNotice: 'Checked a new version V%0, <a class="high-light" href="%1" target="_blank">click to update</a>',
  1577. language: 'Language</br> Currently only supports zh: Chinese, en: English',
  1578. gistOptions: 'Gist Settings',
  1579. 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!',
  1580. 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!',
  1581. noticeLink: 'https://auto-task-doc.js.org/en/guide/#read-me-first',
  1582. toGithub: 'Feedback(Github)',
  1583. toKeylol: 'Feedback(Keylol)',
  1584. copySuccess: 'The error message has been copied to the clipboard. Do you want to go to the Keylol forum to give feedback?',
  1585. copyFailed: 'Please copy the error information below and report back to the Keylol forum!',
  1586. updateText: 'Updates in version %0:',
  1587. Active: 'Active',
  1588. Ended: 'Ended',
  1589. Banned: 'Banned',
  1590. Paused: 'Paused',
  1591. notStart: 'notStart',
  1592. noRemoteData: 'No data remotely',
  1593. errorRemoteDataFormat: 'Remote data has wrong format',
  1594. updateHistory: '<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">Click here</a>' + ' to view the historical update record.',
  1595. AsfEnabled: 'Use ASF to do Steam related tasks (requires <a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a> plugin)',
  1596. AsfIpcUrl: 'ASF IPC URL',
  1597. AsfIpcPassword: 'ASF IPC Password',
  1598. groups: 'Group',
  1599. officialGroups: 'Official Group',
  1600. wishlists: 'Wishlist',
  1601. follows: 'Follow Game',
  1602. forums: 'Forum',
  1603. workshops: 'Favorite Workshop',
  1604. curators: 'Curator',
  1605. workshopVotes: 'Voteup Workshop',
  1606. announcements: 'Announcement',
  1607. steamCommunity: 'Steam Community',
  1608. steamStore: 'Steam Store',
  1609. licenses: 'Add License',
  1610. playtests: 'Playtest Access',
  1611. needLoginSteamStore: 'Please <a href="https://store.steampowered.com/login/" target="_blank">log in to the Steam Store</a>',
  1612. needLoginSteamCommunity: 'Please <a href="https://steamcommunity.com/login/home/" target="_blank">log in to the Steam Community</a>',
  1613. joiningSteamGroup: 'Joining Steam Group',
  1614. leavingSteamGroup: 'Leaving Steam Group',
  1615. gettingSteamGroupId: 'Getting Steam Group Id',
  1616. joiningSteamOfficialGroup: 'Joining Steam Official Group',
  1617. leavingSteamOfficialGroup: 'Leaving Steam Official Group',
  1618. gettingSteamOfficialGroupId: 'Getting Steam Official Group Id',
  1619. subscribingForum: 'Subscribing the Steam Forum',
  1620. unsubscribingForum: 'Unsubscribing the Steam Forum',
  1621. gettingForumId: 'Getting Steam Forum Id',
  1622. followingCurator: 'Following Steam Curator',
  1623. unfollowingCurator: 'Unfollowing Steam Curator',
  1624. gettingCuratorId: 'Getting Steam Curator Id',
  1625. addingToWishlist: 'Adding the game to the Steam wishlist',
  1626. removingFromWishlist: 'Removing the game from the Steam wishlist',
  1627. followingGame: 'Following Steam games',
  1628. unfollowingGame: 'Unfollowing Steam games',
  1629. favoritingWorkshop: 'Favouring Steam Workshop Items',
  1630. unfavoritingWorkshop: 'Unfavoriting Steam Workshop Items',
  1631. gettingWorkshopAppId: 'Getting Steam Workshop Item Id',
  1632. votingUpWorkshop: 'Liking Steam workshop items',
  1633. gettingAnnouncementParams: 'Getting Steam announcement information',
  1634. likingAnnouncement: 'Liking Steam announcement',
  1635. changingArea: 'Changing Steam area: %0...',
  1636. notNeededChangeArea: 'The current area does not need to be changed',
  1637. noAnotherArea: 'Please check whether the proxy is turned on correctly',
  1638. gettingAreaInfo: 'Getting Steam area information...',
  1639. changeAreaNotice: 'Suspected of a locked zone game, try to change the zone to execute',
  1640. steamFinishNotice: 'Steam task completed, try to change the shopping cart area back to CN',
  1641. gettingSubid: 'Getting subid',
  1642. addingFreeLicense: 'Adding free license',
  1643. missParams: 'Missing parameters',
  1644. gettingLicenses: 'Getting licenses...',
  1645. requestingPlayTestAccess: 'Requesting play test access',
  1646. 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.',
  1647. versionNotMatched: 'The script manager version is too low, requiring TamperMonkey >= 5.2.0 or TamperMonkey Beta >= 5.2.6196',
  1648. gettingUserLink: 'Getting steam user community link...',
  1649. retry: 'Retry',
  1650. owned: 'Owned',
  1651. redirect: 'Redirect',
  1652. initingASF: 'Initing ASF...',
  1653. servers: 'Server',
  1654. joiningDiscordServer: 'Joining Discord Server',
  1655. leavingDiscordServer: 'Leaving Discord Server',
  1656. gettingDiscordGuild: 'Getting Discord server Id',
  1657. getDiscordAuthFailed: 'Failed to get Discord token, please check whether the Discord account is logged in',
  1658. discordImportantNotice: 'Important Reminder! ! !',
  1659. 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! ! !',
  1660. continue: 'Continue',
  1661. skipDiscordTask: 'Skip',
  1662. continueAndDontRemindAgain: 'Continue without Reminders',
  1663. users: 'User',
  1664. loginIns: 'Please <a href="https://www.instagram.com/accounts/login/" target="_blank">log in to Instagram</a>',
  1665. insBanned: 'Your Instagram account has been banned',
  1666. verifyingInsAuth: 'Verifying Instagram token...',
  1667. gettingInsUserId: 'Getting Instagram user Id',
  1668. followingIns: 'Following Instagram user',
  1669. unfollowingIns: 'Unfollowing Instagram user',
  1670. reddits: 'Reddit/User',
  1671. loginReddit: 'Please <a href="https://www.reddit.com/login/" target="_blank">log in to Reddit</a>',
  1672. changingRedditVersion: 'Switching Reddit to a new version page...',
  1673. joiningReddit: 'Joining the Reddit',
  1674. leavingReddit: 'Leaving the Reddit',
  1675. followingRedditUser: 'Following Reddit User',
  1676. unfollowingRedditUser: 'Unfollowing Reddit User',
  1677. channels: 'Channel',
  1678. followingTwitchChannel: 'Following Twitch Channel',
  1679. unfollowingTwitchChannel: 'Unfollowing Twitch Channel',
  1680. gettingTwitchChannelId: 'Getting Twitch Channel Id',
  1681. checkingTwitchIntegrity: 'Checking Twitch integrity...',
  1682. twitterUser: 'Twitter User',
  1683. retweets: 'Retweet',
  1684. gettingTwitterUserId: 'Getting Twitter User Id',
  1685. followingTwitterUser: 'Following Twitter User',
  1686. unfollowingTwitterUser: 'Unfollowing Twitter User',
  1687. retweetting: 'Retweetting',
  1688. unretweetting: 'Unretweetting',
  1689. names: 'Group/Public/Wall',
  1690. loginVk: 'Please <a href="https://vk.com/login/" target="_blank">log in to Vk</a>',
  1691. gettingVkId: 'Getting Vk task Id',
  1692. joiningVkGroup: 'Joining Vk Group',
  1693. leavingVkGroup: 'Leaving Vk Group',
  1694. joiningVkPublic: 'Joining Vk Public',
  1695. leavingVkPublic: 'Leaving Vk Public',
  1696. sendingVkWall: 'Sending Vk Wall',
  1697. deletingVkWall: 'Deleting Vk Wall',
  1698. youtubeChannel: 'YouTube Channel',
  1699. likes: 'Like',
  1700. loginYtb: 'Please <a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">log in to YouTube</a>',
  1701. tryUpdateYtbAuth: 'Please try to <a href="https://www.youtube.com/#auth" target="_blank">update YouTube token</a>',
  1702. gettingYtbToken: 'Getting YouTube Token...',
  1703. followingYtbChannel: 'Subscribing to YouTube channel',
  1704. unfollowingYtbChannel: 'Unsubscribing to YouTube channel',
  1705. likingYtbVideo: 'Liking YouTube video',
  1706. unlikingYtbVideo: 'Unliking YouTube video',
  1707. giveKeyNoticeBefore: 'Each verification interval is 15s',
  1708. giveKeyNoticeAfter: 'If there is no key, please check at <a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>',
  1709. noPoints: 'Not enough points, skip the lottery',
  1710. getNeedPointsFailed: 'ailed to obtain the required points, skip the lottery',
  1711. joiningLottery: 'Joining the lottery',
  1712. doingGleamTask: 'Doing Gleam Task...',
  1713. gettingGleamLink: 'Getting Gleam task link...',
  1714. gleamTaskNotice: 'If this page has not been closed for a long time, please close it yourself after completing any task!',
  1715. verifiedGleamTasks: 'Attempted to verify all tasks. If the verification fails, please try to verify manually or complete it!',
  1716. campaign: 'ReCAPTCHA detected, please complete it and re-verify the tasks!',
  1717. 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!',
  1718. giveeClubVerifyNotice: 'Verifying task...',
  1719. giveeClubVerifyFinished: 'Wait for the verification to complete and join it by yourself',
  1720. doingKeyhubTask: 'Doing Keyhub Task...',
  1721. 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...',
  1722. tasksNotCompleted: 'Tasks Not Completed',
  1723. confirmingTask: 'Confirming task...'
  1724. };
  1725. const en_US = en_US_data;
  1726. const languages = {
  1727. zh: zh_CN,
  1728. en: en_US
  1729. };
  1730. const language = [ 'zh', 'en' ].includes(globalOptions.other.language) ? globalOptions.other.language : 'en';
  1731. const I18n = (key, ...argvs) => {
  1732. if (!languages[language]?.[key]) {
  1733. return key;
  1734. }
  1735. return languages[language][key].replace(/%([\d]+)/g, (match, index) => argvs[parseInt(index, 10)]);
  1736. };
  1737. const i18n = I18n;
  1738. function throwError(error, name) {
  1739. if (window.TRACE) {
  1740. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  1741. }
  1742. external_Swal_default().fire({
  1743. title: i18n('errorReport'),
  1744. icon: 'error',
  1745. showCancelButton: true,
  1746. confirmButtonText: i18n('toGithub'),
  1747. showDenyButton: true,
  1748. denyButtonText: i18n('toKeylol'),
  1749. cancelButtonText: i18n('close')
  1750. }).then(({
  1751. isDenied,
  1752. isConfirmed
  1753. }) => {
  1754. if (isConfirmed) {
  1755. GM_openInTab(`https://github.com/HCLonely/auto-task-v4/issues/new?title=${encodeURIComponent(`[BUG] 脚本报错: ${name}`)}&labels=bug&template=bug_report.yml&website=${encodeURIComponent(window.location.href)}&browser=${encodeURIComponent(JSON.stringify((0,
  1756. 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'))}`, {
  1757. active: true
  1758. });
  1759. } else if (isDenied) {
  1760. const text = `错误链接: [url=${window.location.href}]${window.location.href}[/url]
  1761.  
  1762. 环境:
  1763.  
  1764. [code]${JSON.stringify((0, javascript_utils_umd_min.ua)(), null, 4)}[/code]
  1765.  
  1766. 脚本管理器: ${GM_info.scriptHandler} ${GM_info.version}
  1767. 脚本版本: ${GM_info.script.version}
  1768.  
  1769. 报错信息:
  1770. [code]${error.stack}[/code]
  1771.  
  1772. 执行日志:
  1773. [code]${$.makeArray($('#auto-task-info>li')).map(element => element.innerText).join('\n')}[/code]`;
  1774. GM_setClipboard(text);
  1775. external_Swal_default().fire({
  1776. title: i18n('copySuccess'),
  1777. icon: 'success',
  1778. confirmButtonText: i18n('ok')
  1779. }).then(() => {
  1780. GM_openInTab('https://keylol.com/forum.php?mod=post&action=reply&fid=319&tid=777450', {
  1781. active: true
  1782. });
  1783. });
  1784. }
  1785. });
  1786. console.log('%c%s', 'color:white;background:red', `Auto-Task[Error]: ${name}\n${error.stack}`);
  1787. }
  1788. class Social {
  1789. tasks;
  1790. getRealParams(name, links, doTask, link2param) {
  1791. try {
  1792. let realParams = [];
  1793. if (links.length > 0) {
  1794. realParams = [ ...realParams, ...links.map(link => link2param(link)).filter(link => link) ];
  1795. }
  1796. if (!doTask && this.tasks[name].length > 0) {
  1797. realParams = [ ...realParams, ...this.tasks[name] ];
  1798. }
  1799. return unique(realParams);
  1800. } catch (error) {
  1801. throwError(error, 'Social.getRealParams');
  1802. return [];
  1803. }
  1804. }
  1805. }
  1806. const social_Social = Social;
  1807. class Discord extends social_Social {
  1808. tasks;
  1809. whiteList;
  1810. #auth = GM_getValue('discordAuth') || {};
  1811. #cache = GM_getValue('discordCache') || {};
  1812. #initialized = false;
  1813. constructor() {
  1814. super();
  1815. const defaultTasksTemplate = {
  1816. servers: []
  1817. };
  1818. this.tasks = defaultTasksTemplate;
  1819. this.whiteList = {
  1820. ...defaultTasksTemplate,
  1821. ...GM_getValue('whiteList')?.discord || {}
  1822. };
  1823. }
  1824. async init(action) {
  1825. try {
  1826. if (!GM_getValue('dontRemindDiscordAgain')) {
  1827. const result = await external_Swal_default().fire({
  1828. title: i18n('discordImportantNotice'),
  1829. text: i18n('discordImportantNoticeText'),
  1830. showCancelButton: true,
  1831. showDenyButton: true,
  1832. confirmButtonText: i18n('continue'),
  1833. cancelButtonText: i18n('skipDiscordTask'),
  1834. denyButtonText: i18n('continueAndDontRemindAgain')
  1835. }).then(({
  1836. isConfirmed,
  1837. isDenied
  1838. }) => {
  1839. if (isConfirmed) {
  1840. return true;
  1841. }
  1842. if (isDenied) {
  1843. GM_setValue('dontRemindDiscordAgain', true);
  1844. return true;
  1845. }
  1846. return false;
  1847. });
  1848. if (!result) {
  1849. this.#initialized = false;
  1850. return 'skip';
  1851. }
  1852. }
  1853. if (GM_getValue('dontRemindDiscordAgain') || action === 'do' && !globalOptions.doTask.discord.servers || action === 'undo' && !globalOptions.undoTask.discord.servers) {
  1854. this.#initialized = false;
  1855. return 'skip';
  1856. }
  1857. if (this.#initialized) {
  1858. return true;
  1859. }
  1860. if (!this.#auth.auth) {
  1861. if (await this.#updateAuth()) {
  1862. this.#initialized = true;
  1863. return true;
  1864. }
  1865. return false;
  1866. }
  1867. const isVerified = await this.#verifyAuth();
  1868. if (isVerified) {
  1869. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1870. this.#initialized = true;
  1871. return true;
  1872. }
  1873. GM_setValue('discordAuth', {
  1874. auth: null
  1875. });
  1876. if (await this.#updateAuth()) {
  1877. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1878. this.#initialized = true;
  1879. return true;
  1880. }
  1881. scripts_echoLog({}).error(i18n('initFailed', 'Discord'));
  1882. return false;
  1883. } catch (error) {
  1884. throwError(error, 'Discord.init');
  1885. return false;
  1886. }
  1887. }
  1888. async #verifyAuth() {
  1889. try {
  1890. const logStatus = scripts_echoLog({
  1891. text: i18n('verifyingAuth', 'Discord')
  1892. });
  1893. const {
  1894. result,
  1895. statusText,
  1896. status,
  1897. data
  1898. } = await tools_httpRequest({
  1899. url: 'https://discord.com/api/v6/users/@me',
  1900. method: 'HEAD',
  1901. headers: {
  1902. authorization: this.#auth.auth
  1903. }
  1904. });
  1905. if (result === 'Success') {
  1906. if (data?.status === 200) {
  1907. logStatus.success();
  1908. return true;
  1909. }
  1910. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  1911. return false;
  1912. }
  1913. logStatus.error(`${result}:${statusText}(${status})`);
  1914. return false;
  1915. } catch (error) {
  1916. throwError(error, 'Discord.verifyAuth');
  1917. return false;
  1918. }
  1919. }
  1920. async #updateAuth() {
  1921. try {
  1922. const logStatus = scripts_echoLog({
  1923. text: i18n('updatingAuth', 'Discord')
  1924. });
  1925. return await new Promise(resolve => {
  1926. const newTab = GM_openInTab('https://discord.com/channels/@me', {
  1927. active: true,
  1928. insert: true,
  1929. setParent: true
  1930. });
  1931. newTab.name = 'ATv4_discordAuth';
  1932. newTab.onclose = async () => {
  1933. const auth = GM_getValue('discordAuth')?.auth;
  1934. if (auth) {
  1935. this.#auth = {
  1936. auth: auth
  1937. };
  1938. logStatus.success();
  1939. resolve(await this.#verifyAuth());
  1940. } else {
  1941. logStatus.error('Error: Update discord auth failed!');
  1942. resolve(false);
  1943. }
  1944. };
  1945. });
  1946. } catch (error) {
  1947. throwError(error, 'Discord.updateAuth');
  1948. return false;
  1949. }
  1950. }
  1951. async #joinServer(inviteId) {
  1952. try {
  1953. const logStatus = scripts_echoLog({
  1954. type: 'joiningDiscordServer',
  1955. text: inviteId
  1956. });
  1957. const {
  1958. result,
  1959. statusText,
  1960. status,
  1961. data
  1962. } = await tools_httpRequest({
  1963. url: `https://discord.com/api/v9/invites/${inviteId}`,
  1964. method: 'POST',
  1965. dataType: 'json',
  1966. headers: {
  1967. authorization: this.#auth.auth,
  1968. origin: 'https://discord.com',
  1969. referer: `https://discord.com/invite/${inviteId}`
  1970. }
  1971. });
  1972. if (result === 'Success' && data?.status === 200) {
  1973. logStatus.success();
  1974. const guild = String(data.response?.guild?.id);
  1975. if (guild) {
  1976. this.#setCache(inviteId, guild);
  1977. this.tasks.servers = unique([ ...this.tasks.servers, inviteId ]);
  1978. }
  1979. return true;
  1980. }
  1981. logStatus.error(`${result}:${statusText}(${status})`);
  1982. return false;
  1983. } catch (error) {
  1984. throwError(error, 'Discord.joinServer');
  1985. return false;
  1986. }
  1987. }
  1988. async #leaveServer(inviteId) {
  1989. try {
  1990. if (this.whiteList.servers.includes(inviteId)) {
  1991. scripts_echoLog({
  1992. type: 'whiteList',
  1993. text: 'Discord.leaveServer',
  1994. id: inviteId
  1995. });
  1996. return true;
  1997. }
  1998. const guild = await this.#getGuild(inviteId);
  1999. if (!guild) {
  2000. return false;
  2001. }
  2002. const logStatus = scripts_echoLog({
  2003. type: 'leavingDiscordServer',
  2004. text: guild
  2005. });
  2006. const {
  2007. result,
  2008. statusText,
  2009. status,
  2010. data
  2011. } = await tools_httpRequest({
  2012. url: `https://discord.com/api/v9/users/@me/guilds/${guild}`,
  2013. method: 'DELETE',
  2014. headers: {
  2015. authorization: this.#auth.auth
  2016. }
  2017. });
  2018. if (result === 'Success' && data?.status === 204) {
  2019. logStatus.success();
  2020. return true;
  2021. }
  2022. logStatus.error(`${result}:${statusText}(${status})`);
  2023. return false;
  2024. } catch (error) {
  2025. throwError(error, 'Discord.leaveServer');
  2026. return false;
  2027. }
  2028. }
  2029. async #getGuild(inviteId) {
  2030. try {
  2031. const logStatus = scripts_echoLog({
  2032. type: 'gettingDiscordGuild',
  2033. text: inviteId
  2034. });
  2035. const guild = this.#cache[inviteId];
  2036. if (guild) {
  2037. logStatus.success();
  2038. return guild;
  2039. }
  2040. const {
  2041. result,
  2042. statusText,
  2043. status,
  2044. data
  2045. } = await tools_httpRequest({
  2046. url: `https://discord.com/api/v9/invites/${inviteId}`,
  2047. responseType: 'json',
  2048. method: 'GET'
  2049. });
  2050. if (result === 'Success' && data?.status === 200) {
  2051. const guild = data.response?.guild?.id;
  2052. if (guild) {
  2053. logStatus.success();
  2054. this.#setCache(inviteId, guild);
  2055. return guild;
  2056. }
  2057. logStatus.error(`${result}:${statusText}(${status})`);
  2058. return false;
  2059. }
  2060. logStatus.error(`${result}:${statusText}(${status})`);
  2061. return false;
  2062. } catch (error) {
  2063. throwError(error, 'Discord.getGuild');
  2064. return false;
  2065. }
  2066. }
  2067. async toggle({
  2068. doTask = true,
  2069. serverLinks = []
  2070. }) {
  2071. try {
  2072. if (!this.#initialized) {
  2073. scripts_echoLog({
  2074. text: i18n('needInit')
  2075. });
  2076. return false;
  2077. }
  2078. const prom = [];
  2079. if (doTask && !globalOptions.doTask.discord.servers || !doTask && !globalOptions.undoTask.discord.servers) {
  2080. scripts_echoLog({
  2081. type: 'globalOptionsSkip',
  2082. text: 'discord.servers'
  2083. });
  2084. } else {
  2085. const realServers = this.getRealParams('servers', serverLinks, doTask, link => link.match(/invite\/(.+)/)?.[1]);
  2086. if (realServers.length > 0) {
  2087. for (const server of realServers) {
  2088. if (doTask) {
  2089. prom.push(this.#joinServer(server));
  2090. } else {
  2091. prom.push(this.#leaveServer(server));
  2092. }
  2093. await delay(1e3);
  2094. }
  2095. }
  2096. }
  2097. return await Promise.all(prom).then(() => true);
  2098. } catch (error) {
  2099. throwError(error, 'Discord.toggleServers');
  2100. return false;
  2101. }
  2102. }
  2103. #setCache(inviteId, guild) {
  2104. try {
  2105. this.#cache[inviteId] = guild;
  2106. GM_setValue('discordCache', this.#cache);
  2107. } catch (error) {
  2108. throwError(error, 'Discord.setCache');
  2109. }
  2110. }
  2111. }
  2112. const social_Discord = Discord;
  2113. class Instagram extends social_Social {
  2114. tasks;
  2115. whiteList;
  2116. #cache = GM_getValue('instagramCache') || {};
  2117. #auth = {};
  2118. #initialized = false;
  2119. constructor() {
  2120. super();
  2121. const defaultTasksTemplate = {
  2122. users: []
  2123. };
  2124. this.tasks = defaultTasksTemplate;
  2125. this.whiteList = {
  2126. ...defaultTasksTemplate,
  2127. ...GM_getValue('whiteList')?.instagram || {}
  2128. };
  2129. }
  2130. async init() {
  2131. try {
  2132. if (this.#initialized) {
  2133. return true;
  2134. }
  2135. const isVerified = await this.#getUserInfo();
  2136. if (isVerified) {
  2137. scripts_echoLog({}).success(i18n('initSuccess', 'Instagram'));
  2138. this.#initialized = true;
  2139. return true;
  2140. }
  2141. scripts_echoLog({}).error(i18n('initFailed', 'Instagram'));
  2142. return false;
  2143. } catch (error) {
  2144. throwError(error, 'Instagram.init');
  2145. return false;
  2146. }
  2147. }
  2148. async #getUserInfo(name = 'instagram') {
  2149. try {
  2150. const logStatus = scripts_echoLog({
  2151. type: name === 'instagram' ? 'verifyingInsAuth' : 'gettingInsUserId',
  2152. text: name
  2153. });
  2154. const userId = this.#cache[name];
  2155. if (userId && name !== 'instagram') {
  2156. logStatus.success();
  2157. return userId;
  2158. }
  2159. const {
  2160. result,
  2161. statusText,
  2162. status,
  2163. data
  2164. } = await tools_httpRequest({
  2165. url: `https://www.instagram.com/${name}/`,
  2166. method: 'GET'
  2167. });
  2168. if (result === 'Success') {
  2169. if (data?.finalUrl.includes('accounts/login')) {
  2170. logStatus.error(`Error:${i18n('loginIns')}`, true);
  2171. return false;
  2172. } else if (data?.finalUrl.includes('www.instagram.com/challenge')) {
  2173. logStatus.error(`Error:${i18n('insBanned')}`);
  2174. return false;
  2175. }
  2176. if (data?.status === 200) {
  2177. const csrftoken = data.responseText.match(/"csrf_token":"(.+?)"/)?.[1];
  2178. const hash = data.responseText.match(/"rollout_hash":"(.+?)"/)?.[1];
  2179. if (name === 'instagram') {
  2180. if (csrftoken && hash) {
  2181. this.#auth = {
  2182. csrftoken: csrftoken,
  2183. hash: hash
  2184. };
  2185. return true;
  2186. }
  2187. return false;
  2188. }
  2189. const id = data.responseText.match(/"profilePage_([\d]+?)"/)?.[1];
  2190. if (id) {
  2191. this.#setCache(name, id);
  2192. logStatus.success();
  2193. return id;
  2194. }
  2195. logStatus.error('Error: Get ins data error!');
  2196. return false;
  2197. }
  2198. logStatus.error(`${result}:${statusText}(${status})`);
  2199. return false;
  2200. }
  2201. return false;
  2202. } catch (error) {
  2203. throwError(error, 'Instagram.getUserInfo');
  2204. return false;
  2205. }
  2206. }
  2207. async #followUser(name) {
  2208. try {
  2209. const id = await this.#getUserInfo(name);
  2210. if (!id) {
  2211. return false;
  2212. }
  2213. const logStatus = scripts_echoLog({
  2214. type: 'followingIns',
  2215. text: name
  2216. });
  2217. const {
  2218. result,
  2219. statusText,
  2220. status,
  2221. data
  2222. } = await tools_httpRequest({
  2223. url: `https://www.instagram.com/web/friendships/${id}/follow/`,
  2224. method: 'POST',
  2225. dataType: 'json',
  2226. headers: {
  2227. 'x-csrftoken': this.#auth.csrftoken,
  2228. origin: 'https://www.instagram.com',
  2229. referer: `https://www.instagram.com/${name}/`,
  2230. 'content-type': 'application/x-www-form-urlencoded',
  2231. 'sec-fetch-site': 'same-origin',
  2232. 'x-instagram-ajax': this.#auth.hash
  2233. }
  2234. });
  2235. if (result === 'Success') {
  2236. if (data?.status === 200 && data.response?.result === 'following') {
  2237. logStatus.success();
  2238. this.tasks.users = unique([ ...this.tasks.users, name ]);
  2239. return true;
  2240. }
  2241. logStatus.error(`Error:${data?.response?.feedback_message || `${data?.statusText}(${data?.status})`}`);
  2242. return false;
  2243. }
  2244. logStatus.error(`${result}:${statusText}(${status})`);
  2245. return false;
  2246. } catch (error) {
  2247. throwError(error, 'Instagram.followUser');
  2248. return false;
  2249. }
  2250. }
  2251. async #unfollowUser(name) {
  2252. try {
  2253. if (this.whiteList.users.includes(name)) {
  2254. scripts_echoLog({
  2255. type: 'whiteList',
  2256. text: 'Instagram.unfollowUser',
  2257. id: name
  2258. });
  2259. return true;
  2260. }
  2261. const id = await this.#getUserInfo(name);
  2262. if (!id) {
  2263. return false;
  2264. }
  2265. const logStatus = scripts_echoLog({
  2266. type: 'unfollowingIns',
  2267. text: name
  2268. });
  2269. const {
  2270. result,
  2271. statusText,
  2272. status,
  2273. data
  2274. } = await tools_httpRequest({
  2275. url: `https://www.instagram.com/web/friendships/${id}/unfollow/`,
  2276. method: 'POST',
  2277. dataType: 'json',
  2278. headers: {
  2279. 'x-csrftoken': this.#auth.csrftoken,
  2280. origin: 'https://www.instagram.com',
  2281. referer: `https://www.instagram.com/${name}/`,
  2282. 'content-type': 'application/x-www-form-urlencoded',
  2283. 'sec-fetch-site': 'same-origin',
  2284. 'x-instagram-ajax': this.#auth.hash
  2285. }
  2286. });
  2287. if (result === 'Success') {
  2288. if (data?.status === 200 && data.response?.status === 'ok') {
  2289. logStatus.success();
  2290. return true;
  2291. }
  2292. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2293. return false;
  2294. }
  2295. logStatus.error(`${result}:${statusText}(${status})`);
  2296. return false;
  2297. } catch (error) {
  2298. throwError(error, 'Instagram.unfollowUser');
  2299. return false;
  2300. }
  2301. }
  2302. async toggle({
  2303. doTask = true,
  2304. userLinks = []
  2305. }) {
  2306. try {
  2307. if (!this.#initialized) {
  2308. scripts_echoLog({
  2309. text: i18n('needInit')
  2310. });
  2311. return false;
  2312. }
  2313. const prom = [];
  2314. if (doTask && !globalOptions.doTask.instagram.users || !doTask && !globalOptions.undoTask.instagram.users) {
  2315. scripts_echoLog({
  2316. type: 'globalOptionsSkip',
  2317. text: 'instagram.users'
  2318. });
  2319. } else {
  2320. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1]);
  2321. if (realUsers.length > 0) {
  2322. for (const username of realUsers) {
  2323. if (doTask) {
  2324. prom.push(this.#followUser(username));
  2325. } else {
  2326. prom.push(this.#unfollowUser(username));
  2327. }
  2328. await delay(1e3);
  2329. }
  2330. }
  2331. }
  2332. return await Promise.all(prom).then(() => true);
  2333. } catch (error) {
  2334. throwError(error, 'Instagram.toggleUsers');
  2335. return false;
  2336. }
  2337. }
  2338. #setCache(name, id) {
  2339. try {
  2340. this.#cache[name] = id;
  2341. GM_setValue('instagramCache', this.#cache);
  2342. } catch (error) {
  2343. throwError(error, 'Instagram.setCache');
  2344. }
  2345. }
  2346. }
  2347. const social_Instagram = Instagram;
  2348. class Reddit extends social_Social {
  2349. tasks;
  2350. whiteList;
  2351. #auth;
  2352. #initialized = false;
  2353. constructor() {
  2354. super();
  2355. const defaultTasksTemplate = {
  2356. reddits: []
  2357. };
  2358. this.tasks = defaultTasksTemplate;
  2359. this.whiteList = {
  2360. ...defaultTasksTemplate,
  2361. ...GM_getValue('whiteList')?.reddit || {}
  2362. };
  2363. }
  2364. async init() {
  2365. try {
  2366. if (this.#initialized) {
  2367. return true;
  2368. }
  2369. const isVerified = await this.#updateAuth();
  2370. if (isVerified) {
  2371. scripts_echoLog({}).success(i18n('initSuccess', 'Reddit'));
  2372. this.#initialized = true;
  2373. return true;
  2374. }
  2375. scripts_echoLog({}).error(i18n('initFailed', 'Reddit'));
  2376. return false;
  2377. } catch (error) {
  2378. throwError(error, 'Reddit.init');
  2379. return false;
  2380. }
  2381. }
  2382. async #useBeta() {
  2383. try {
  2384. const logStatus = scripts_echoLog({
  2385. text: i18n('changingRedditVersion')
  2386. });
  2387. return await new Promise(resolve => {
  2388. const newTab = GM_openInTab('https://www.reddit.com/', {
  2389. active: true,
  2390. insert: true,
  2391. setParent: true
  2392. });
  2393. newTab.name = 'ATv4_redditAuth';
  2394. newTab.onclose = async () => {
  2395. logStatus.success();
  2396. resolve(await this.#updateAuth(true));
  2397. };
  2398. });
  2399. } catch (error) {
  2400. throwError(error, 'Reddit.useBeta');
  2401. return false;
  2402. }
  2403. }
  2404. async #updateAuth(beta = false) {
  2405. try {
  2406. const logStatus = scripts_echoLog({
  2407. text: i18n('updatingAuth', 'Reddit')
  2408. });
  2409. const {
  2410. result,
  2411. statusText,
  2412. status,
  2413. data
  2414. } = await tools_httpRequest({
  2415. url: 'https://www.reddit.com/',
  2416. method: 'GET',
  2417. nochche: true,
  2418. headers: {
  2419. 'Cache-Control': 'no-cache'
  2420. }
  2421. });
  2422. if (result === 'Success') {
  2423. if (data?.responseText.includes('www.reddit.com/login/')) {
  2424. logStatus.error(`Error:${i18n('loginReddit')}`, true);
  2425. return false;
  2426. }
  2427. if (data?.status === 200) {
  2428. if (data.responseText.includes('redesign-beta-optin-btn') && !beta) {
  2429. return await this.#useBeta();
  2430. }
  2431. const accessToken = data.responseText.match(/"accessToken":"(.*?)","expires":"(.*?)"/)?.[1];
  2432. if (accessToken) {
  2433. this.#auth = {
  2434. token: accessToken
  2435. };
  2436. logStatus.success();
  2437. return true;
  2438. }
  2439. logStatus.error('Error: Parameter "accessToken" not found!');
  2440. return false;
  2441. }
  2442. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2443. return false;
  2444. }
  2445. logStatus.error(`${result}:${statusText}(${status})`);
  2446. return false;
  2447. } catch (error) {
  2448. throwError(error, 'Reddit.updateAuth');
  2449. return false;
  2450. }
  2451. }
  2452. async #toggleTask({
  2453. name,
  2454. doTask = true
  2455. }) {
  2456. try {
  2457. if (!doTask && this.whiteList.reddits.includes(name)) {
  2458. scripts_echoLog({
  2459. type: 'whiteList',
  2460. text: 'Reddit.undoTask',
  2461. id: name
  2462. });
  2463. return true;
  2464. }
  2465. let type = doTask ? 'joiningReddit' : 'leavingReddit';
  2466. if (/^u_/.test(name)) {
  2467. type = doTask ? 'followingRedditUser' : 'unfollowingRedditUser';
  2468. }
  2469. const logStatus = scripts_echoLog({
  2470. type: type,
  2471. text: name
  2472. });
  2473. const {
  2474. result,
  2475. statusText,
  2476. status,
  2477. data
  2478. } = await tools_httpRequest({
  2479. url: 'https://oauth.reddit.com/api/subscribe?redditWebClient=desktop2x&app=desktop2x-client-production&raw_json=1&gilding_detail=1',
  2480. method: 'POST',
  2481. headers: {
  2482. authorization: `Bearer ${this.#auth.token}`,
  2483. 'content-type': 'application/x-www-form-urlencoded'
  2484. },
  2485. data: $.param({
  2486. action: doTask ? 'sub' : 'unsub',
  2487. sr_name: name,
  2488. api_type: 'json'
  2489. })
  2490. });
  2491. if (result === 'Success') {
  2492. if (data?.status === 200) {
  2493. logStatus.success();
  2494. if (doTask) {
  2495. this.tasks.reddits = unique([ ...this.tasks.reddits, name ]);
  2496. }
  2497. return true;
  2498. }
  2499. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2500. return false;
  2501. }
  2502. logStatus.error(`${result}:${statusText}(${status})`);
  2503. return false;
  2504. } catch (error) {
  2505. throwError(error, 'Reddit.toggleTask');
  2506. return false;
  2507. }
  2508. }
  2509. async toggle({
  2510. doTask = true,
  2511. redditLinks = []
  2512. }) {
  2513. try {
  2514. if (!this.#initialized) {
  2515. scripts_echoLog({
  2516. text: i18n('needInit')
  2517. });
  2518. return false;
  2519. }
  2520. const prom = [];
  2521. if (doTask && !globalOptions.doTask.reddit.reddits || !doTask && !globalOptions.undoTask.reddit.reddits) {
  2522. scripts_echoLog({
  2523. type: 'globalOptionsSkip',
  2524. text: 'reddit.reddits'
  2525. });
  2526. } else {
  2527. const realReddits = this.getRealParams('reddits', redditLinks, doTask, link => {
  2528. const name = link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1];
  2529. const userName = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1];
  2530. if (userName) {
  2531. return name || userName;
  2532. }
  2533. return name;
  2534. });
  2535. if (realReddits.length > 0) {
  2536. for (const name of realReddits) {
  2537. prom.push(this.#toggleTask({
  2538. name: name,
  2539. doTask: doTask
  2540. }));
  2541. await delay(1e3);
  2542. }
  2543. }
  2544. }
  2545. return await Promise.all(prom).then(() => true);
  2546. } catch (error) {
  2547. throwError(error, 'Reddit.toggle');
  2548. return false;
  2549. }
  2550. }
  2551. }
  2552. const social_Reddit = Reddit;
  2553. class Twitch extends social_Social {
  2554. tasks;
  2555. whiteList;
  2556. #auth = GM_getValue('twitchAuth') || {};
  2557. #cache = GM_getValue('twitchCache') || {};
  2558. #initialized = false;
  2559. #integrityToken;
  2560. constructor() {
  2561. super();
  2562. const defaultTasksTemplate = {
  2563. channels: []
  2564. };
  2565. this.tasks = defaultTasksTemplate;
  2566. this.whiteList = {
  2567. ...defaultTasksTemplate,
  2568. ...GM_getValue('whiteList')?.twitch || {}
  2569. };
  2570. }
  2571. async init() {
  2572. try {
  2573. if (this.#initialized) {
  2574. return true;
  2575. }
  2576. if (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId) {
  2577. if (await this.#updateAuth()) {
  2578. this.#initialized = true;
  2579. return true;
  2580. }
  2581. return false;
  2582. }
  2583. const isVerified = await this.#verifyAuth(true);
  2584. if (isVerified) {
  2585. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2586. this.#initialized = true;
  2587. return true;
  2588. }
  2589. GM_setValue('twitchAuth', null);
  2590. if (await this.#updateAuth()) {
  2591. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2592. this.#initialized = true;
  2593. return true;
  2594. }
  2595. scripts_echoLog({}).error(i18n('initFailed', 'Twitch'));
  2596. return false;
  2597. } catch (error) {
  2598. throwError(error, 'Twitch.init');
  2599. return false;
  2600. }
  2601. }
  2602. async #verifyAuth(isFirst) {
  2603. try {
  2604. const logStatus = scripts_echoLog({
  2605. text: i18n('verifyingAuth', 'Twitch')
  2606. });
  2607. const {
  2608. result,
  2609. statusText,
  2610. status,
  2611. data
  2612. } = await tools_httpRequest({
  2613. url: 'https://gql.twitch.tv/gql',
  2614. method: 'POST',
  2615. dataType: 'json',
  2616. headers: {
  2617. Authorization: `OAuth ${this.#auth.authToken}`,
  2618. 'Client-Id': this.#auth.clientId
  2619. },
  2620. data: '[{"operationName":"FrontPageNew_User","variables":{"limit":1},"extensions":{"persistedQuery":{"version":1,' + '"sha256Hash":"64bd07a2cbaca80699d62636d966cf6395a5d14a1f0a14282067dcb28b13eb11"}}}]'
  2621. });
  2622. if (result === 'Success') {
  2623. if (data?.status === 200 && data.response?.[0]?.data?.currentUser) {
  2624. await this.#integrity(isFirst);
  2625. logStatus.success();
  2626. return true;
  2627. }
  2628. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2629. return false;
  2630. }
  2631. logStatus.error(`${result}:${statusText}(${status})`);
  2632. return false;
  2633. } catch (error) {
  2634. throwError(error, 'Twitch.verifyAuth');
  2635. return false;
  2636. }
  2637. }
  2638. async #integrity(isFirst = true, ct = '') {
  2639. try {
  2640. const logStatus = scripts_echoLog({
  2641. text: i18n('checkingTwitchIntegrity')
  2642. });
  2643. if (isFirst && (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId)) {
  2644. return await this.#updateAuth(false);
  2645. }
  2646. const {
  2647. result,
  2648. statusText,
  2649. status,
  2650. data
  2651. } = await tools_httpRequest({
  2652. url: 'https://gql.twitch.tv/integrity',
  2653. method: 'POST',
  2654. dataType: 'json',
  2655. anonymous: true,
  2656. headers: {
  2657. Origin: 'https://www.twitch.tv',
  2658. Referer: 'https://www.twitch.tv/',
  2659. Authorization: `OAuth ${this.#auth.authToken}`,
  2660. 'Client-Id': this.#auth.clientId,
  2661. 'Client-Version': this.#auth.clientVersion,
  2662. 'X-Device-Id': this.#auth.deviceId,
  2663. 'Client-Session-Id': this.#auth.clientSessionId,
  2664. 'x-kpsdk-ct': ct
  2665. }
  2666. });
  2667. if (result === 'Success') {
  2668. if (!ct && data?.responseHeaders?.['x-kpsdk-ct']) {
  2669. return await this.#integrity(isFirst, data.responseHeaders['x-kpsdk-ct']);
  2670. }
  2671. if (data?.status === 200 && data.response?.token) {
  2672. this.#integrityToken = data.response.token;
  2673. logStatus.success();
  2674. return true;
  2675. }
  2676. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2677. return false;
  2678. }
  2679. logStatus.error(`${result}:${statusText}(${status})`);
  2680. return false;
  2681. } catch (error) {
  2682. throwError(error, 'Twitch.integrity');
  2683. return false;
  2684. }
  2685. }
  2686. async #updateAuth(isFirst = true) {
  2687. try {
  2688. const logStatus = scripts_echoLog({
  2689. text: i18n('updatingAuth', 'Twitch')
  2690. });
  2691. return await new Promise(resolve => {
  2692. const newTab = GM_openInTab('https://www.twitch.tv/', {
  2693. active: true,
  2694. insert: true,
  2695. setParent: true
  2696. });
  2697. newTab.name = 'ATv4_twitchAuth';
  2698. newTab.onclose = async () => {
  2699. const auth = GM_getValue('twitchAuth');
  2700. if (auth) {
  2701. this.#auth = auth;
  2702. logStatus.success();
  2703. resolve(await this.#verifyAuth(isFirst));
  2704. } else {
  2705. logStatus.error('Error: Update twitch auth failed!');
  2706. resolve(false);
  2707. }
  2708. };
  2709. });
  2710. } catch (error) {
  2711. throwError(error, 'Twitch.updateAuth');
  2712. return false;
  2713. }
  2714. }
  2715. async #toggleChannel({
  2716. name,
  2717. doTask = true
  2718. }) {
  2719. try {
  2720. if (!doTask && this.whiteList.channels.includes(name)) {
  2721. scripts_echoLog({
  2722. type: 'whiteList',
  2723. text: 'Twitch.unfollowChannel',
  2724. id: name
  2725. });
  2726. return true;
  2727. }
  2728. const channelId = await this.#getChannelId(name);
  2729. if (!channelId) {
  2730. return false;
  2731. }
  2732. const logStatus = scripts_echoLog({
  2733. type: `${doTask ? '' : 'un'}followingTwitchChannel`,
  2734. text: name
  2735. });
  2736. const followData = `[{"operationName":"FollowButton_FollowUser","variables":{"input":{"disableNotifications":false,"targetID":"${channelId}` + '"}},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"800e7346bdf7e5278a3c1d3f21b2b56e2639928f86815677a7126b093b2fdd08"}}}]';
  2737. const unfollowData = `[{"operationName":"FollowButton_UnfollowUser","variables":{"input":{"targetID":"${channelId}"}},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"f7dae976ebf41c755ae2d758546bfd176b4eeb856656098bb40e0a672ca0d880"}}}]';
  2738. const {
  2739. result,
  2740. statusText,
  2741. status,
  2742. data
  2743. } = await tools_httpRequest({
  2744. url: 'https://gql.twitch.tv/gql',
  2745. method: 'POST',
  2746. dataType: 'json',
  2747. anonymous: true,
  2748. headers: {
  2749. Origin: 'https://www.twitch.tv',
  2750. Referer: 'https://www.twitch.tv/',
  2751. Authorization: `OAuth ${this.#auth.authToken}`,
  2752. 'Client-Id': this.#auth.clientId,
  2753. 'Client-Version': this.#auth.clientVersion,
  2754. 'X-Device-Id': this.#auth.deviceId,
  2755. 'Client-Session-Id': this.#auth.clientSessionId,
  2756. 'Client-Integrity': this.#integrityToken
  2757. },
  2758. data: doTask ? followData : unfollowData
  2759. });
  2760. if (result === 'Success') {
  2761. if (data?.status === 200 && data.response?.[0] && !data.response[0].errors) {
  2762. logStatus.success();
  2763. if (doTask) {
  2764. this.tasks.channels = unique([ ...this.tasks.channels, name ]);
  2765. }
  2766. return true;
  2767. }
  2768. logStatus.error(`Error:${data?.response?.[0].errors?.[0]?.message || `${data?.statusText}(${data?.status})`}`);
  2769. return false;
  2770. }
  2771. logStatus.error(`${result}:${statusText}(${status})`);
  2772. return false;
  2773. } catch (error) {
  2774. throwError(error, 'Twitch.toggleChannel');
  2775. return false;
  2776. }
  2777. }
  2778. async #getChannelId(name) {
  2779. try {
  2780. const logStatus = scripts_echoLog({
  2781. type: 'gettingTwitchChannelId',
  2782. text: name
  2783. });
  2784. const channelId = this.#cache[name];
  2785. if (channelId) {
  2786. logStatus.success();
  2787. return channelId;
  2788. }
  2789. const {
  2790. result,
  2791. statusText,
  2792. status,
  2793. data
  2794. } = await tools_httpRequest({
  2795. url: 'https://gql.twitch.tv/gql',
  2796. method: 'POST',
  2797. headers: {
  2798. Authorization: `OAuth ${this.#auth.authToken}`,
  2799. 'Client-Id': this.#auth.clientId
  2800. },
  2801. responseType: 'json',
  2802. data: `[{"operationName":"ActiveWatchParty","variables":{"channelLogin":"${name}"},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"4a8156c97b19e3a36e081cf6d6ddb5dbf9f9b02ae60e4d2ff26ed70aebc80a30"}}}]'
  2803. });
  2804. if (result === 'Success') {
  2805. if (data?.status === 200) {
  2806. const channelId = data.response?.[0]?.data?.user?.id;
  2807. if (channelId) {
  2808. this.#setCache(name, String(channelId));
  2809. logStatus.success();
  2810. return channelId;
  2811. }
  2812. logStatus.error(`Error:${data.statusText}(${data.status})`);
  2813. return false;
  2814. }
  2815. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2816. return false;
  2817. }
  2818. logStatus.error(`${result}:${statusText}(${status})`);
  2819. return false;
  2820. } catch (error) {
  2821. throwError(error, 'Twitch.getChannelId');
  2822. return false;
  2823. }
  2824. }
  2825. async toggle({
  2826. doTask = true,
  2827. channelLinks = []
  2828. }) {
  2829. try {
  2830. if (!this.#initialized) {
  2831. scripts_echoLog({
  2832. text: i18n('needInit')
  2833. });
  2834. return false;
  2835. }
  2836. const prom = [];
  2837. if (doTask && !globalOptions.doTask.twitch.channels || !doTask && !globalOptions.undoTask.twitch.channels) {
  2838. scripts_echoLog({
  2839. type: 'globalOptionsSkip',
  2840. text: 'twitch.channels'
  2841. });
  2842. } else {
  2843. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2]);
  2844. if (realChannels.length > 0) {
  2845. for (const channel of realChannels) {
  2846. prom.push(this.#toggleChannel({
  2847. name: channel,
  2848. doTask: doTask
  2849. }));
  2850. await delay(1e3);
  2851. }
  2852. }
  2853. }
  2854. return Promise.all(prom).then(() => true);
  2855. } catch (error) {
  2856. throwError(error, 'Twitch.toggle');
  2857. return false;
  2858. }
  2859. }
  2860. #setCache(name, id) {
  2861. try {
  2862. this.#cache[name] = id;
  2863. GM_setValue('twitchCache', this.#cache);
  2864. } catch (error) {
  2865. throwError(error, 'Twitch.setCache');
  2866. }
  2867. }
  2868. }
  2869. const social_Twitch = Twitch;
  2870. class Twitter extends social_Social {
  2871. tasks;
  2872. whiteList;
  2873. #verifyId = globalOptions.other.twitterVerifyId;
  2874. #auth = GM_getValue('twitterAuth') || {};
  2875. #cache = GM_getValue('twitterCache') || {};
  2876. #initialized = false;
  2877. constructor() {
  2878. super();
  2879. const defaultTasksTemplate = {
  2880. users: [],
  2881. retweets: [],
  2882. likes: []
  2883. };
  2884. this.tasks = defaultTasksTemplate;
  2885. this.whiteList = {
  2886. ...defaultTasksTemplate,
  2887. ...GM_getValue('whiteList')?.twitter || {}
  2888. };
  2889. }
  2890. async init() {
  2891. try {
  2892. if (this.#initialized) {
  2893. return true;
  2894. }
  2895. if (!this.#auth.ct0) {
  2896. if (await this.#updateAuth()) {
  2897. this.#initialized = true;
  2898. return true;
  2899. }
  2900. return false;
  2901. }
  2902. const isVerified = await this.#verifyAuth();
  2903. if (isVerified) {
  2904. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2905. this.#initialized = true;
  2906. return true;
  2907. }
  2908. GM_setValue('twitterAuth', null);
  2909. if (await this.#updateAuth()) {
  2910. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2911. this.#initialized = true;
  2912. return true;
  2913. }
  2914. scripts_echoLog({}).error(i18n('initFailed', 'Twitter'));
  2915. return false;
  2916. } catch (error) {
  2917. throwError(error, 'Twitter.init');
  2918. return false;
  2919. }
  2920. }
  2921. async #verifyAuth() {
  2922. try {
  2923. return await this.#toggleUser({
  2924. name: 'verify',
  2925. doTask: true,
  2926. verify: true
  2927. });
  2928. } catch (error) {
  2929. throwError(error, 'Twitter.verifyAuth');
  2930. return false;
  2931. }
  2932. }
  2933. async #updateAuth() {
  2934. try {
  2935. const logStatus = scripts_echoLog({
  2936. text: i18n('updatingAuth', 'Twitter')
  2937. });
  2938. return await new Promise(resolve => {
  2939. GM_cookie.list({
  2940. url: 'https://x.com/settings/account'
  2941. }, async (cookies, error) => {
  2942. if (!error) {
  2943. const [ ct0, isLogin ] = cookies.map(cookie => [ 'ct0', 'twid' ].includes(cookie.name) ? cookie.value : null).filter(cookie => cookie);
  2944. if (isLogin && ct0) {
  2945. GM_setValue('twitterAuth', {
  2946. ct0: ct0
  2947. });
  2948. this.#auth = {
  2949. ct0: ct0
  2950. };
  2951. logStatus.success();
  2952. resolve(await this.#verifyAuth());
  2953. } else {
  2954. logStatus.error(i18n('needLogin'));
  2955. resolve(false);
  2956. }
  2957. } else {
  2958. logStatus.error('Error: Update twitter auth failed!');
  2959. resolve(false);
  2960. }
  2961. });
  2962. });
  2963. } catch (error) {
  2964. throwError(error, 'Twitter.updateToken');
  2965. return false;
  2966. }
  2967. }
  2968. async #toggleUser({
  2969. name,
  2970. doTask = true,
  2971. verify = false
  2972. }) {
  2973. try {
  2974. if (!doTask && !verify && this.whiteList.users.includes(name)) {
  2975. scripts_echoLog({
  2976. type: 'whiteList',
  2977. text: 'Twitter.unfollowUser',
  2978. id: name
  2979. });
  2980. return true;
  2981. }
  2982. const userId = verify ? this.#verifyId : await this.userName2id(name);
  2983. if (!userId) {
  2984. return false;
  2985. }
  2986. const logStatus = verify ? scripts_echoLog({
  2987. text: i18n('verifyingAuth', 'Twitter')
  2988. }) : scripts_echoLog({
  2989. type: `${doTask ? '' : 'un'}followingTwitterUser`,
  2990. text: name
  2991. });
  2992. const {
  2993. result,
  2994. statusText,
  2995. status,
  2996. data
  2997. } = await tools_httpRequest({
  2998. url: `https://x.com/i/api/1.1/friendships/${doTask ? 'create' : 'destroy'}.json`,
  2999. method: 'POST',
  3000. headers: {
  3001. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3002. 'Content-Type': 'application/x-www-form-urlencoded',
  3003. 'x-csrf-token': this.#auth.ct0
  3004. },
  3005. responseType: 'json',
  3006. data: $.param({
  3007. include_profile_interstitial_type: 1,
  3008. include_blocking: 1,
  3009. include_blocked_by: 1,
  3010. include_followed_by: 1,
  3011. include_want_retweets: 1,
  3012. include_mute_edge: 1,
  3013. include_can_dm: 1,
  3014. include_can_media_tag: 1,
  3015. skip_status: 1,
  3016. id: userId
  3017. })
  3018. });
  3019. if (result === 'Success') {
  3020. if (data?.status === 200) {
  3021. logStatus.success();
  3022. if (doTask && !verify) {
  3023. this.tasks.users = unique([ ...this.tasks.users, name ]);
  3024. }
  3025. return true;
  3026. }
  3027. if (verify && data?.status === 403 && data.response?.errors?.[0]?.code === 158) {
  3028. logStatus.success();
  3029. return true;
  3030. }
  3031. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3032. return false;
  3033. }
  3034. logStatus.error(`${result}:${statusText}(${status})`);
  3035. return false;
  3036. } catch (error) {
  3037. throwError(error, 'Twitter.toggleUser');
  3038. return false;
  3039. }
  3040. }
  3041. async userName2id(name) {
  3042. try {
  3043. const logStatus = scripts_echoLog({
  3044. type: 'gettingTwitterUserId',
  3045. text: name
  3046. });
  3047. const userId = this.#cache[name];
  3048. if (userId) {
  3049. logStatus.success();
  3050. return userId;
  3051. }
  3052. const {
  3053. result,
  3054. statusText,
  3055. status,
  3056. data
  3057. } = await tools_httpRequest({
  3058. 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`,
  3059. method: 'GET',
  3060. headers: {
  3061. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3062. 'content-type': 'application/json',
  3063. referer: `https://x.com/${name}`,
  3064. 'x-csrf-token': this.#auth.ct0
  3065. },
  3066. responseType: 'json'
  3067. });
  3068. if (result === 'Success') {
  3069. if (data?.status === 200) {
  3070. let response = data.response || (typeof data.responseText === 'object' ? data.responseText : null);
  3071. if (!response) {
  3072. try {
  3073. response = JSON.parse(data.responseText);
  3074. } catch (error) {
  3075. response = null;
  3076. }
  3077. }
  3078. const userId = String(response?.data?.user?.result?.rest_id);
  3079. if (userId) {
  3080. this.#setCache(name, userId);
  3081. logStatus.success();
  3082. return userId;
  3083. }
  3084. logStatus.error(`Error:${data.statusText}(${data.status})`);
  3085. return false;
  3086. }
  3087. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3088. return false;
  3089. }
  3090. logStatus.error(`${result}:${statusText}(${status})`);
  3091. return false;
  3092. } catch (error) {
  3093. throwError(error, 'Twitter.getUserId');
  3094. return false;
  3095. }
  3096. }
  3097. async #toggleRetweet({
  3098. retweetId,
  3099. doTask = true
  3100. }) {
  3101. try {
  3102. if (!doTask && this.whiteList.retweets.includes(retweetId)) {
  3103. scripts_echoLog({
  3104. type: 'whiteList',
  3105. text: 'Twitter.unretweet',
  3106. id: retweetId
  3107. });
  3108. return true;
  3109. }
  3110. const logStatus = scripts_echoLog({
  3111. type: `${doTask ? '' : 'un'}retweetting`,
  3112. text: retweetId
  3113. });
  3114. const {
  3115. result,
  3116. statusText,
  3117. status,
  3118. data
  3119. } = await tools_httpRequest({
  3120. url: `https://x.com/i/api/graphql/${doTask ? 'ojPdsZsimiJrUGLR1sjUtA/CreateRetweet' : 'iQtK4dl5hBmXewYZuEOKVw/DeleteRetweet'}`,
  3121. method: 'POST',
  3122. headers: {
  3123. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3124. 'Content-Type': 'application/json',
  3125. 'x-csrf-token': this.#auth.ct0
  3126. },
  3127. data: `{"variables":{"tweet_id":"${retweetId}","dark_request":false},"queryId":"${doTask ? 'ojPdsZsimiJrUGLR1sjUtA' : 'iQtK4dl5hBmXewYZuEOKVw'}"}`,
  3128. responseType: 'json'
  3129. });
  3130. if (result === 'Success') {
  3131. if (data?.status === 200 || data?.status === 403 && data.response?.errors?.[0]?.code === 327) {
  3132. logStatus.success();
  3133. if (doTask) {
  3134. this.tasks.retweets = unique([ ...this.tasks.retweets, retweetId ]);
  3135. }
  3136. return true;
  3137. }
  3138. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3139. return false;
  3140. }
  3141. logStatus.error(`${result}:${statusText}(${status})`);
  3142. return false;
  3143. } catch (error) {
  3144. throwError(error, 'Twitter.toggleRetweet');
  3145. return false;
  3146. }
  3147. }
  3148. async toggle({
  3149. doTask = true,
  3150. userLinks = [],
  3151. retweetLinks = []
  3152. }) {
  3153. try {
  3154. if (!this.#initialized) {
  3155. scripts_echoLog({
  3156. text: i18n('needInit')
  3157. });
  3158. return false;
  3159. }
  3160. const prom = [];
  3161. if (doTask && !globalOptions.doTask.twitter.users || !doTask && !globalOptions.undoTask.twitter.users) {
  3162. scripts_echoLog({
  3163. type: 'globalOptionsSkip',
  3164. text: 'twitter.users'
  3165. });
  3166. } else {
  3167. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/x\.com\/(.+)/)?.[1] || link.match(/https:\/\/twitter\.com\/(.+)/)?.[1]);
  3168. if (realUsers.length > 0) {
  3169. for (const user of realUsers) {
  3170. prom.push(this.#toggleUser({
  3171. name: user,
  3172. doTask: doTask
  3173. }));
  3174. await delay(1e3);
  3175. }
  3176. }
  3177. }
  3178. if (doTask && !globalOptions.doTask.twitter.retweets || !doTask && !globalOptions.undoTask.twitter.retweets) {
  3179. scripts_echoLog({
  3180. type: 'globalOptionsSkip',
  3181. text: 'twitter.retweets'
  3182. });
  3183. } else {
  3184. const realRetweets = this.getRealParams('retweets', retweetLinks, doTask, link => link.match(/https:\/\/x\.com\/.*?\/status\/([\d]+)/)?.[1] || link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1]);
  3185. if (realRetweets.length > 0) {
  3186. for (const retweet of realRetweets) {
  3187. prom.push(this.#toggleRetweet({
  3188. retweetId: retweet,
  3189. doTask: doTask
  3190. }));
  3191. await delay(1e3);
  3192. }
  3193. }
  3194. }
  3195. return Promise.all(prom).then(() => true);
  3196. } catch (error) {
  3197. throwError(error, 'Twitter.toggle');
  3198. return false;
  3199. }
  3200. }
  3201. #setCache(name, id) {
  3202. try {
  3203. this.#cache[name] = id;
  3204. GM_setValue('twitterCache', this.#cache);
  3205. } catch (error) {
  3206. throwError(error, 'Twitter.setCache');
  3207. }
  3208. }
  3209. }
  3210. const social_Twitter = Twitter;
  3211. class Vk extends social_Social {
  3212. tasks;
  3213. whiteList;
  3214. #username = '';
  3215. #cache = GM_getValue('vkCache') || {};
  3216. #initialized = false;
  3217. constructor() {
  3218. super();
  3219. const defaultTasksTemplate = {
  3220. names: []
  3221. };
  3222. this.tasks = defaultTasksTemplate;
  3223. this.whiteList = {
  3224. ...defaultTasksTemplate,
  3225. ...GM_getValue('whiteList')?.vk || {}
  3226. };
  3227. }
  3228. async init() {
  3229. try {
  3230. if (this.#initialized) {
  3231. return true;
  3232. }
  3233. const isVerified = await this.#verifyAuth();
  3234. if (isVerified) {
  3235. scripts_echoLog({}).success(i18n('initSuccess', 'Vk'));
  3236. this.#initialized = true;
  3237. return true;
  3238. }
  3239. scripts_echoLog({}).error(i18n('initFailed', 'Vk'));
  3240. return false;
  3241. } catch (error) {
  3242. throwError(error, 'Vk.init');
  3243. return false;
  3244. }
  3245. }
  3246. async #verifyAuth() {
  3247. try {
  3248. const logStatus = scripts_echoLog({
  3249. text: i18n('verifyAuth', 'Vk')
  3250. });
  3251. const {
  3252. result,
  3253. statusText,
  3254. status,
  3255. data
  3256. } = await tools_httpRequest({
  3257. url: 'https://vk.com/im',
  3258. method: 'GET'
  3259. });
  3260. if (result === 'Success') {
  3261. if (data?.finalUrl.includes('vk.com/login')) {
  3262. logStatus.error(`Error:${i18n('loginVk')}`, true);
  3263. return false;
  3264. }
  3265. if (data?.status === 200) {
  3266. this.#username = data.responseText.match(/TopNavBtn__profileLink" href="\/(.*?)"/)?.[1] || '';
  3267. logStatus.success();
  3268. return true;
  3269. }
  3270. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3271. return false;
  3272. }
  3273. logStatus.error(`${result}:${statusText}(${status})`);
  3274. return false;
  3275. } catch (error) {
  3276. throwError(error, 'Vk.verifyAuth');
  3277. return false;
  3278. }
  3279. }
  3280. async #toggleGroup(name, dataParam, doTask = true) {
  3281. try {
  3282. const logStatus = scripts_echoLog({
  3283. type: doTask ? 'joiningVkGroup' : 'leavingVkGroup',
  3284. text: name
  3285. });
  3286. if (dataParam.groupAct === 'enter' && !doTask || dataParam.groupAct === 'leave' && doTask) {
  3287. logStatus.success();
  3288. return true;
  3289. }
  3290. const reqData = {
  3291. act: doTask ? 'enter' : 'leave',
  3292. al: 1,
  3293. gid: dataParam.groupId,
  3294. hash: dataParam.groupHash
  3295. };
  3296. if (doTask) {
  3297. reqData.context = '_';
  3298. }
  3299. const {
  3300. result,
  3301. statusText,
  3302. status,
  3303. data
  3304. } = await tools_httpRequest({
  3305. url: 'https://vk.com/al_groups.php',
  3306. method: 'POST',
  3307. headers: {
  3308. origin: 'https://vk.com',
  3309. referer: `https://vk.com/${name}`,
  3310. 'content-type': 'application/x-www-form-urlencoded'
  3311. },
  3312. data: $.param(reqData)
  3313. });
  3314. if (result === 'Success') {
  3315. if (data?.status === 200) {
  3316. logStatus.success();
  3317. if (doTask) {
  3318. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3319. }
  3320. return true;
  3321. }
  3322. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3323. return false;
  3324. }
  3325. logStatus.error(`${result}:${statusText}(${status})`);
  3326. return false;
  3327. } catch (error) {
  3328. throwError(error, 'Vk.toggleGroup');
  3329. return false;
  3330. }
  3331. }
  3332. async #togglePublic(name, dataParam, doTask = true) {
  3333. try {
  3334. const logStatus = scripts_echoLog({
  3335. type: doTask ? 'joiningVkPublic' : 'leavingVkPublic',
  3336. text: name
  3337. });
  3338. if (dataParam.publicJoined && doTask || !dataParam.publicJoined && !doTask) {
  3339. logStatus.success();
  3340. return true;
  3341. }
  3342. const {
  3343. result,
  3344. statusText,
  3345. status,
  3346. data
  3347. } = await tools_httpRequest({
  3348. url: 'https://vk.com/al_public.php',
  3349. method: 'POST',
  3350. headers: {
  3351. origin: 'https://vk.com',
  3352. referer: `https://vk.com/${name}`,
  3353. 'content-type': 'application/x-www-form-urlencoded'
  3354. },
  3355. data: $.param({
  3356. act: doTask ? 'a_enter' : 'a_leave',
  3357. al: 1,
  3358. pid: dataParam.publicPid,
  3359. hash: dataParam.publicHash
  3360. })
  3361. });
  3362. if (result === 'Success') {
  3363. if (data?.status === 200) {
  3364. logStatus.success();
  3365. if (doTask) {
  3366. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3367. }
  3368. return true;
  3369. }
  3370. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3371. return false;
  3372. }
  3373. logStatus.error(`${result}:${statusText}(${status})`);
  3374. return false;
  3375. } catch (error) {
  3376. throwError(error, 'Vk.togglePublic');
  3377. return false;
  3378. }
  3379. }
  3380. async #sendWall(name) {
  3381. try {
  3382. const logStatus = scripts_echoLog({
  3383. type: 'sendingVkWall',
  3384. text: name
  3385. });
  3386. const {
  3387. result,
  3388. statusText,
  3389. status,
  3390. data
  3391. } = await tools_httpRequest({
  3392. url: 'https://vk.com/like.php',
  3393. method: 'POST',
  3394. headers: {
  3395. origin: 'https://vk.com',
  3396. referer: `https://vk.com/${name}`,
  3397. 'content-type': 'application/x-www-form-urlencoded'
  3398. },
  3399. data: $.param({
  3400. act: 'publish_box',
  3401. al: 1,
  3402. object: name
  3403. })
  3404. });
  3405. if (result === 'Success') {
  3406. if (data?.status === 200) {
  3407. const hash = data.responseText.match(/shHash:[\s]*'(.*?)'/)?.[1];
  3408. if (hash) {
  3409. const {
  3410. result: resultR,
  3411. statusText: statusTextR,
  3412. status: statusR,
  3413. data: dataR
  3414. } = await tools_httpRequest({
  3415. url: 'https://vk.com/like.php',
  3416. method: 'POST',
  3417. headers: {
  3418. origin: 'https://vk.com',
  3419. referer: `https://vk.com/${name}`,
  3420. 'content-type': 'application/x-www-form-urlencoded'
  3421. },
  3422. data: $.param({
  3423. Message: '',
  3424. act: 'a_do_publish',
  3425. al: 1,
  3426. close_comments: 0,
  3427. friends_only: 0,
  3428. from: 'box',
  3429. hash: hash,
  3430. list: '',
  3431. mark_as_ads: 0,
  3432. mute_notifications: 0,
  3433. object: name,
  3434. ret_data: 1,
  3435. to: 0
  3436. })
  3437. });
  3438. if (resultR === 'Success') {
  3439. if (dataR?.status === 200) {
  3440. const jsonData = JSON.parse(dataR.responseText?.replace('\x3c!--', '') || '{}');
  3441. if (jsonData?.payload?.[1]?.[1]?.share_my === true) {
  3442. logStatus.success();
  3443. const postId = String(jsonData?.payload?.[1]?.[1]?.post_id);
  3444. const ownerId = String(jsonData?.payload?.[1]?.[1]?.owner_id);
  3445. if (postId && ownerId) {
  3446. this.#setCache(name, `${ownerId}_${postId}`);
  3447. }
  3448. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3449. return true;
  3450. }
  3451. }
  3452. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  3453. return false;
  3454. }
  3455. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  3456. return false;
  3457. }
  3458. logStatus.error('Error: Get "hash" failed');
  3459. return false;
  3460. }
  3461. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3462. return false;
  3463. }
  3464. logStatus.error(`${result}:${statusText}(${status})`);
  3465. return false;
  3466. } catch (error) {
  3467. throwError(error, 'Vk.sendWall');
  3468. return false;
  3469. }
  3470. }
  3471. async #deleteWall(name, dataParams) {
  3472. try {
  3473. const logStatus = scripts_echoLog({
  3474. type: 'deletingVkWall',
  3475. text: name
  3476. });
  3477. const {
  3478. result,
  3479. statusText,
  3480. status,
  3481. data
  3482. } = await tools_httpRequest({
  3483. url: 'https://vk.com/al_wall.php?act=delete',
  3484. method: 'POST',
  3485. headers: {
  3486. origin: 'https://vk.com',
  3487. referer: `https://vk.com/${this.#username}?w=wall${this.#cache[name]}%2Fall`,
  3488. 'content-type': 'application/x-www-form-urlencoded'
  3489. },
  3490. data: $.param({
  3491. act: 'delete',
  3492. al: 1,
  3493. confirm: 0,
  3494. from: 'wkview',
  3495. hash: dataParams.wallHash,
  3496. post: this.#cache[name]
  3497. })
  3498. });
  3499. if (result === 'Success') {
  3500. if (data?.status === 200) {
  3501. const jsonData = JSON.parse(data.responseText?.replace('\x3c!--', '') || '{}');
  3502. if (jsonData?.payload?.[1]?.[1]) {
  3503. logStatus.success();
  3504. return true;
  3505. }
  3506. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3507. return false;
  3508. }
  3509. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3510. return false;
  3511. }
  3512. logStatus.error(`${result}:${statusText}(${status})`);
  3513. return false;
  3514. } catch (error) {
  3515. throwError(error, 'Vk.deleteWall');
  3516. return false;
  3517. }
  3518. }
  3519. async #getId(name, doTask) {
  3520. try {
  3521. let url = `https://vk.com/${name}`;
  3522. if (/^wall-/.test(name)) {
  3523. if (doTask) {
  3524. return {
  3525. type: 'sendWall'
  3526. };
  3527. }
  3528. if (!this.#cache[name]) {
  3529. return {
  3530. type: 'unSupport'
  3531. };
  3532. }
  3533. url = `https://vk.com/${this.#username}?w=wall${this.#cache[name]}`;
  3534. }
  3535. const logStatus = scripts_echoLog({
  3536. type: 'gettingVkId',
  3537. text: name
  3538. });
  3539. const {
  3540. result,
  3541. statusText,
  3542. status,
  3543. data
  3544. } = await tools_httpRequest({
  3545. url: url,
  3546. method: 'GET'
  3547. });
  3548. if (result === 'Success') {
  3549. if (data?.status === 200) {
  3550. const [ , groupAct, groupId, , groupHash ] = data.responseText.match(/Groups.(enter|leave)\(.*?,.*?([\d]+?), (&#39;|')(.*?)(&#39;|')/) || [];
  3551. const publicHash = data.responseText.match(/"enterHash":"(.*?)"/)?.[1];
  3552. const publicPid = data.responseText.match(/"public_id":([\d]+?),/)?.[1];
  3553. const publicJoined = !data.responseText.includes('Public.subscribe');
  3554. if (groupAct && groupId && groupHash) {
  3555. logStatus.success();
  3556. return {
  3557. groupAct: groupAct,
  3558. groupId: groupId,
  3559. groupHash: groupHash,
  3560. type: 'group'
  3561. };
  3562. } else if (publicHash && publicPid) {
  3563. logStatus.success();
  3564. return {
  3565. publicHash: publicHash,
  3566. publicPid: publicPid,
  3567. publicJoined: publicJoined,
  3568. type: 'public'
  3569. };
  3570. } else if (data.responseText.includes('wall.deletePost') && !doTask) {
  3571. const wallHash = data.responseText.match(/wall\.deletePost\(this, '.*?', '(.*?)'\)/)?.[1];
  3572. if (wallHash) {
  3573. logStatus.success();
  3574. return {
  3575. type: 'deleteWall',
  3576. wallHash: wallHash
  3577. };
  3578. }
  3579. } else if (name.includes('wall') && doTask) {
  3580. logStatus.success();
  3581. return {
  3582. type: 'sendWall'
  3583. };
  3584. }
  3585. logStatus.error('Error: Parameters not found!');
  3586. return false;
  3587. }
  3588. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3589. return false;
  3590. }
  3591. logStatus.error(`${result}:${statusText}(${status})`);
  3592. return false;
  3593. } catch (error) {
  3594. throwError(error, 'Vk.getId');
  3595. return false;
  3596. }
  3597. }
  3598. async #toggleVk({
  3599. name,
  3600. doTask = true
  3601. }) {
  3602. try {
  3603. if (!doTask && this.whiteList.names.includes(name)) {
  3604. scripts_echoLog({
  3605. type: 'whiteList',
  3606. text: 'Vk.undoTask',
  3607. id: name
  3608. });
  3609. return true;
  3610. }
  3611. const formatName = name.replace(/\/$/, '');
  3612. const data = await this.#getId(formatName, doTask);
  3613. if (!data) {
  3614. return false;
  3615. }
  3616. switch (data.type) {
  3617. case 'group':
  3618. return await this.#toggleGroup(formatName, data, doTask);
  3619.  
  3620. case 'public':
  3621. return await this.#togglePublic(formatName, data, doTask);
  3622.  
  3623. case 'sendWall':
  3624. return doTask ? await this.#sendWall(formatName) : true;
  3625.  
  3626. case 'deleteWall':
  3627. return doTask ? true : await this.#deleteWall(formatName, data);
  3628.  
  3629. default:
  3630. return false;
  3631. }
  3632. } catch (error) {
  3633. throwError(error, 'Vk.toggleVk');
  3634. return false;
  3635. }
  3636. }
  3637. async toggle({
  3638. doTask = true,
  3639. nameLinks = []
  3640. }) {
  3641. try {
  3642. if (!this.#initialized) {
  3643. scripts_echoLog({
  3644. text: i18n('needInit')
  3645. });
  3646. return false;
  3647. }
  3648. const prom = [];
  3649. if (doTask && !globalOptions.doTask.vk.names || !doTask && !globalOptions.undoTask.vk.names) {
  3650. scripts_echoLog({
  3651. type: 'globalOptionsSkip',
  3652. text: 'vk.names'
  3653. });
  3654. } else {
  3655. const realNames = this.getRealParams('names', nameLinks, doTask, link => link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1]);
  3656. if (realNames.length > 0) {
  3657. for (const name of realNames) {
  3658. prom.push(this.#toggleVk({
  3659. name: name,
  3660. doTask: doTask
  3661. }));
  3662. await delay(1e3);
  3663. }
  3664. }
  3665. }
  3666. return Promise.all(prom).then(() => true);
  3667. } catch (error) {
  3668. throwError(error, 'Vk.toggle');
  3669. return false;
  3670. }
  3671. }
  3672. #setCache(name, postId) {
  3673. try {
  3674. this.#cache[name] = postId;
  3675. GM_setValue('vkCache', this.#cache);
  3676. } catch (error) {
  3677. throwError(error, 'Vk.setCache');
  3678. }
  3679. }
  3680. }
  3681. const social_Vk = Vk;
  3682. const getInfo = async function(link, type) {
  3683. try {
  3684. const logStatus = scripts_echoLog({
  3685. text: i18n('gettingYtbToken')
  3686. });
  3687. const {
  3688. result,
  3689. statusText,
  3690. status,
  3691. data
  3692. } = await tools_httpRequest({
  3693. url: link,
  3694. method: 'GET'
  3695. });
  3696. if (result === 'Success') {
  3697. if (data?.status === 200) {
  3698. if (data.responseText.includes('accounts.google.com/ServiceLogin?service=youtube')) {
  3699. logStatus.error(`Error:${i18n('loginYtb')}`, true);
  3700. return {
  3701. needLogin: true
  3702. };
  3703. }
  3704. const apiKey = data.responseText.match(/"INNERTUBE_API_KEY":"(.*?)"/)?.[1];
  3705. const context = (data.responseText.match(/\(\{"INNERTUBE_CONTEXT":([\w\W]*?)\}\)/) || data.responseText.match(/"INNERTUBE_CONTEXT":([\w\W]*?\}),"INNERTUBE/))?.[1] || '{}';
  3706. const {
  3707. client,
  3708. request
  3709. } = JSON.parse(context);
  3710. if (apiKey && client && request) {
  3711. client.hl = 'en';
  3712. if (type === 'channel') {
  3713. const channelId = data.responseText.match(/"channelId":"(.+?)"/)?.[1];
  3714. if (channelId) {
  3715. logStatus.success();
  3716. return {
  3717. params: {
  3718. apiKey: apiKey,
  3719. client: client,
  3720. request: request,
  3721. channelId: channelId
  3722. }
  3723. };
  3724. }
  3725. logStatus.error('Error: Get "channelId" failed!');
  3726. return {};
  3727. } else if (type === 'likeVideo') {
  3728. const videoId = data.responseText.match(/<link rel="shortlinkUrl" href="https:\/\/youtu\.be\/(.*?)">/)?.[1];
  3729. const likeParams = data.responseText.match(/"likeParams":"(.*?)"/)?.[1];
  3730. if (videoId) {
  3731. logStatus.success();
  3732. return {
  3733. params: {
  3734. apiKey: apiKey,
  3735. client: client,
  3736. request: request,
  3737. videoId: videoId,
  3738. likeParams: likeParams
  3739. }
  3740. };
  3741. }
  3742. logStatus.error('Error: Get "videoId" failed!');
  3743. return {};
  3744. }
  3745. logStatus.error('Error: Unknown type');
  3746. return {};
  3747. }
  3748. logStatus.error('Error: Parameter "apiKey" not found!');
  3749. return {};
  3750. }
  3751. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3752. return {};
  3753. }
  3754. logStatus.error(`${result}:${statusText}(${status})`);
  3755. return {};
  3756. } catch (error) {
  3757. throwError(error, 'Youtube.getInfo');
  3758. return {};
  3759. }
  3760. };
  3761. class Youtube extends social_Social {
  3762. tasks;
  3763. whiteList;
  3764. #auth = GM_getValue('youtubeAuth') || {};
  3765. #initialized = false;
  3766. #verifyChannel = `https://www.youtube.com/channel/${globalOptions.other.youtubeVerifyChannel}`;
  3767. constructor() {
  3768. super();
  3769. const defaultTasksTemplate = {
  3770. channels: [],
  3771. likes: []
  3772. };
  3773. this.tasks = defaultTasksTemplate;
  3774. this.whiteList = {
  3775. ...defaultTasksTemplate,
  3776. ...GM_getValue('whiteList')?.youtube || {}
  3777. };
  3778. }
  3779. async init() {
  3780. try {
  3781. if (this.#initialized) {
  3782. return true;
  3783. }
  3784. if (!this.#auth.PAPISID) {
  3785. if (await this.#updateAuth()) {
  3786. this.#initialized = true;
  3787. return true;
  3788. }
  3789. return false;
  3790. }
  3791. const isVerified = await this.#verifyAuth();
  3792. if (isVerified) {
  3793. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3794. this.#initialized = true;
  3795. return true;
  3796. }
  3797. GM_setValue('youtubeAuth', null);
  3798. if (await this.#updateAuth()) {
  3799. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3800. this.#initialized = true;
  3801. return true;
  3802. }
  3803. scripts_echoLog({}).error(i18n('initFailed', 'Youtube'));
  3804. return false;
  3805. } catch (error) {
  3806. throwError(error, 'Youtube.init');
  3807. return false;
  3808. }
  3809. }
  3810. async #verifyAuth() {
  3811. try {
  3812. return await this.#toggleChannel({
  3813. link: this.#verifyChannel,
  3814. doTask: true,
  3815. verify: true
  3816. });
  3817. } catch (error) {
  3818. throwError(error, 'Youtube.verifyAuth');
  3819. return false;
  3820. }
  3821. }
  3822. async #updateAuth() {
  3823. try {
  3824. const logStatus = scripts_echoLog({
  3825. text: i18n('updatingAuth', 'Youtube')
  3826. });
  3827. return await new Promise(resolve => {
  3828. GM_cookie.list({
  3829. url: 'https://www.youtube.com/@YouTube'
  3830. }, async (cookies, error) => {
  3831. if (!error) {
  3832. const PAPISID = cookies.find(cookie => cookie.name === '__Secure-3PAPISID')?.value;
  3833. if (PAPISID) {
  3834. GM_setValue('youtubeAuth', {
  3835. PAPISID: PAPISID
  3836. });
  3837. this.#auth = {
  3838. PAPISID: PAPISID
  3839. };
  3840. logStatus.success();
  3841. resolve(await this.#verifyAuth());
  3842. } else {
  3843. logStatus.error(i18n('needLogin'));
  3844. resolve(false);
  3845. }
  3846. } else {
  3847. logStatus.error('Error: Update youtube auth failed!');
  3848. resolve(false);
  3849. }
  3850. });
  3851. });
  3852. } catch (error) {
  3853. throwError(error, 'Youtube.updateAuth');
  3854. return false;
  3855. }
  3856. }
  3857. #getInfo(link, type) {
  3858. return getInfo(link, type);
  3859. }
  3860. async #toggleChannel({
  3861. link,
  3862. doTask = true,
  3863. verify = false
  3864. }) {
  3865. try {
  3866. const {
  3867. params,
  3868. needLogin
  3869. } = await this.#getInfo(link, 'channel');
  3870. const {
  3871. apiKey,
  3872. client,
  3873. request,
  3874. channelId
  3875. } = params || {};
  3876. if (needLogin) {
  3877. scripts_echoLog({
  3878. html: i18n('loginYtb')
  3879. });
  3880. return false;
  3881. }
  3882. if (!(apiKey && client && request && channelId)) {
  3883. scripts_echoLog({
  3884. text: '"getYtbToken" failed'
  3885. });
  3886. return false;
  3887. }
  3888. if (!doTask && !verify && this.whiteList.channels.includes(channelId)) {
  3889. scripts_echoLog({
  3890. type: 'whiteList',
  3891. text: 'Youtube.unfollowChannel',
  3892. id: channelId
  3893. });
  3894. return true;
  3895. }
  3896. const logStatus = verify ? scripts_echoLog({
  3897. text: i18n('verifyingAuth', 'Youtube')
  3898. }) : scripts_echoLog({
  3899. type: doTask ? 'followingYtbChannel' : 'unfollowingYtbChannel',
  3900. text: channelId
  3901. });
  3902. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3903. const {
  3904. result,
  3905. statusText,
  3906. status,
  3907. data
  3908. } = await tools_httpRequest({
  3909. url: `https://www.youtube.com/youtubei/v1/subscription/${doTask ? '' : 'un'}subscribe?key=${apiKey}&prettyPrint=false`,
  3910. method: 'POST',
  3911. headers: {
  3912. origin: 'https://www.youtube.com',
  3913. referer: `https://www.youtube.com/channel/${channelId}`,
  3914. 'content-type': 'application/json',
  3915. 'x-goog-authuser': '0',
  3916. 'x-goog-visitor-id': client?.visitorData,
  3917. 'x-origin': 'https://www.youtube.com',
  3918. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  3919. },
  3920. data: JSON.stringify({
  3921. context: {
  3922. client: client,
  3923. request: {
  3924. sessionId: request?.sessionId,
  3925. internalExperimentFlags: [],
  3926. consistencyTokenJars: []
  3927. },
  3928. user: {}
  3929. },
  3930. channelIds: [ channelId ],
  3931. params: doTask ? 'EgIIAhgA' : 'CgIIAhgA'
  3932. })
  3933. });
  3934. if (result === 'Success') {
  3935. if (data?.status === 200) {
  3936. if (doTask && (/"subscribed":true/.test(data.responseText) || data.responseText.includes('The subscription already exists')) || !doTask && /"subscribed":false/.test(data.responseText)) {
  3937. logStatus.success();
  3938. if (doTask && !verify) {
  3939. this.tasks.channels = unique([ ...this.tasks.channels, link ]);
  3940. }
  3941. return true;
  3942. }
  3943. if (verify && data.responseText.includes('You may not subscribe to yourself')) {
  3944. logStatus.success();
  3945. return true;
  3946. }
  3947. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  3948. return false;
  3949. }
  3950. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3951. return false;
  3952. }
  3953. logStatus.error(`${result}:${statusText}(${status})`);
  3954. return false;
  3955. } catch (error) {
  3956. throwError(error, 'Youtube.toggleChannel');
  3957. return false;
  3958. }
  3959. }
  3960. async #toggleLikeVideo({
  3961. link,
  3962. doTask = true
  3963. }) {
  3964. try {
  3965. const {
  3966. params,
  3967. needLogin
  3968. } = await this.#getInfo(link, 'likeVideo');
  3969. const {
  3970. apiKey,
  3971. client,
  3972. request,
  3973. videoId,
  3974. likeParams
  3975. } = params || {};
  3976. if (needLogin) {
  3977. scripts_echoLog({
  3978. html: `${i18n('loginYtb')}`
  3979. });
  3980. return false;
  3981. }
  3982. if (!(apiKey && client && request && videoId && likeParams)) {
  3983. scripts_echoLog({
  3984. text: '"getYtbToken" failed'
  3985. });
  3986. return false;
  3987. }
  3988. if (!doTask && this.whiteList.likes.includes(videoId)) {
  3989. scripts_echoLog({
  3990. type: 'whiteList',
  3991. text: 'Youtube.unlikeVideo',
  3992. id: videoId
  3993. });
  3994. return true;
  3995. }
  3996. const logStatus = scripts_echoLog({
  3997. type: doTask ? 'likingYtbVideo' : 'unlikingYtbVideo',
  3998. text: videoId
  3999. });
  4000. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  4001. const likeVideoData = {
  4002. context: {
  4003. client: client,
  4004. request: {
  4005. sessionId: request.sessionId,
  4006. internalExperimentFlags: [],
  4007. consistencyTokenJars: []
  4008. },
  4009. user: {}
  4010. },
  4011. target: {
  4012. videoId: videoId
  4013. }
  4014. };
  4015. if (doTask) {
  4016. if (likeParams) {
  4017. likeVideoData.params = likeParams;
  4018. } else {
  4019. logStatus.error('Empty likeParams');
  4020. return false;
  4021. }
  4022. }
  4023. const {
  4024. result,
  4025. statusText,
  4026. status,
  4027. data
  4028. } = await tools_httpRequest({
  4029. url: `https://www.youtube.com/youtubei/v1/like/${doTask ? '' : 'remove'}like?key=${apiKey}`,
  4030. method: 'POST',
  4031. headers: {
  4032. origin: 'https://www.youtube.com',
  4033. referer: `https://www.youtube.com/watch?v=${videoId}`,
  4034. 'content-type': 'application/json',
  4035. 'x-goog-authuser': '0',
  4036. 'x-goog-visitor-id': client.visitorData,
  4037. 'x-origin': 'https://www.youtube.com',
  4038. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  4039. },
  4040. data: JSON.stringify(likeVideoData)
  4041. });
  4042. if (result === 'Success') {
  4043. if (data?.status === 200) {
  4044. if (doTask && data.responseText.includes('Added to Liked videos') || !doTask && (data.responseText.includes('Removed from Liked videos') || data.responseText.includes('Dislike removed'))) {
  4045. logStatus.success();
  4046. if (doTask) {
  4047. this.tasks.likes = unique([ ...this.tasks.likes, link ]);
  4048. }
  4049. return true;
  4050. }
  4051. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  4052. return false;
  4053. }
  4054. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4055. return false;
  4056. }
  4057. logStatus.error(`${result}:${statusText}(${status})`);
  4058. return false;
  4059. } catch (error) {
  4060. throwError(error, 'Youtube.toggleLikeVideo');
  4061. return false;
  4062. }
  4063. }
  4064. async toggle({
  4065. doTask = true,
  4066. channelLinks = [],
  4067. videoLinks = []
  4068. }) {
  4069. try {
  4070. if (!this.#initialized) {
  4071. scripts_echoLog({
  4072. text: i18n('needInit')
  4073. });
  4074. return false;
  4075. }
  4076. const prom = [];
  4077. if (doTask && !globalOptions.doTask.youtube.channels || !doTask && !globalOptions.undoTask.youtube.channels) {
  4078. scripts_echoLog({
  4079. type: 'globalOptionsSkip',
  4080. text: 'youtube.channels'
  4081. });
  4082. } else {
  4083. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => {
  4084. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4085. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4086. }
  4087. return link;
  4088. });
  4089. if (realChannels.length > 0) {
  4090. for (const channel of realChannels) {
  4091. prom.push(this.#toggleChannel({
  4092. link: channel,
  4093. doTask: doTask
  4094. }));
  4095. await delay(1e3);
  4096. }
  4097. }
  4098. }
  4099. if (doTask && !globalOptions.doTask.youtube.likes || !doTask && !globalOptions.undoTask.youtube.likes) {
  4100. scripts_echoLog({
  4101. type: 'globalOptionsSkip',
  4102. text: 'youtube.likes'
  4103. });
  4104. } else {
  4105. const realLikes = this.getRealParams('likes', videoLinks, doTask, link => {
  4106. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4107. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4108. }
  4109. return link;
  4110. });
  4111. if (realLikes.length > 0) {
  4112. for (const video of realLikes) {
  4113. prom.push(this.#toggleLikeVideo({
  4114. link: video,
  4115. doTask: doTask
  4116. }));
  4117. await delay(1e3);
  4118. }
  4119. }
  4120. }
  4121. return Promise.all(prom).then(() => true);
  4122. } catch (error) {
  4123. throwError(error, 'Youtube.toggle');
  4124. return false;
  4125. }
  4126. }
  4127. }
  4128. class SteamASF {
  4129. #asfOptions;
  4130. #botName = 'asf';
  4131. #groupInfo;
  4132. async init() {
  4133. try {
  4134. const asfCommandsUrl = new URL('/Api/Command/', globalOptions.ASF.AsfIpcUrl);
  4135. this.#asfOptions = {
  4136. url: asfCommandsUrl.href,
  4137. method: 'POST',
  4138. responseType: 'json',
  4139. headers: {
  4140. accept: 'application/json',
  4141. 'Content-Type': 'application/json',
  4142. Host: asfCommandsUrl.host,
  4143. Origin: asfCommandsUrl.origin,
  4144. Referer: asfCommandsUrl.href,
  4145. Authentication: globalOptions.ASF.AsfIpcPassword
  4146. }
  4147. };
  4148. if (globalOptions.ASF.AsfBotname) {
  4149. this.#botName = globalOptions.ASF.AsfBotname;
  4150. }
  4151. const logStatus = scripts_echoLog({
  4152. text: i18n('initingASF')
  4153. });
  4154. const {
  4155. result,
  4156. statusText,
  4157. status,
  4158. data
  4159. } = await tools_httpRequest({
  4160. ...this.#asfOptions,
  4161. data: '{"Command":"!stats"}'
  4162. });
  4163. if (result === 'Success') {
  4164. if (data?.response?.Success === true && data.response.Message === 'OK' && data.response.Result) {
  4165. logStatus.success();
  4166. return true;
  4167. }
  4168. if (data?.response?.Result || data?.response?.Message) {
  4169. logStatus.error(data?.response?.Result || data.response.Message);
  4170. return false;
  4171. }
  4172. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4173. return false;
  4174. }
  4175. logStatus.error(`${result}:${statusText}(${status})`);
  4176. return false;
  4177. } catch (error) {
  4178. throwError(error, 'SteamASF.init');
  4179. return false;
  4180. }
  4181. }
  4182. async joinGroup(groupName) {
  4183. try {
  4184. const logStatus = scripts_echoLog({
  4185. type: 'joiningSteamGroup',
  4186. text: groupName
  4187. });
  4188. const {
  4189. result,
  4190. statusText,
  4191. status,
  4192. data
  4193. } = await tools_httpRequest({
  4194. ...this.#asfOptions,
  4195. data: JSON.stringify({
  4196. Command: `!JOINGROUP ${this.#botName} ${groupName}`
  4197. })
  4198. });
  4199. if (result === 'Success') {
  4200. if (data?.status === 200 && [ '已加入', '已申请', 'Joined', 'Applied', 'Присоединился', 'costs' ].find(text => data.response?.Result?.includes(text))) {
  4201. logStatus.success();
  4202. return true;
  4203. }
  4204. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4205. return false;
  4206. }
  4207. logStatus.error(`${result}:${statusText}(${status})`);
  4208. return false;
  4209. } catch (error) {
  4210. throwError(error, 'SteamASF.joinGroup');
  4211. return false;
  4212. }
  4213. }
  4214. async leaveGroup(groupName) {
  4215. try {
  4216. if (!this.#groupInfo) {
  4217. if (!await this.#getGroupId()) {
  4218. return false;
  4219. }
  4220. }
  4221. const groupId = await this.#groupInfo[groupName];
  4222. if (!groupId) {
  4223. return false;
  4224. }
  4225. const logStatus = scripts_echoLog({
  4226. type: 'leavingSteamGroup',
  4227. text: groupName
  4228. });
  4229. const {
  4230. result,
  4231. statusText,
  4232. status,
  4233. data
  4234. } = await tools_httpRequest({
  4235. ...this.#asfOptions,
  4236. data: JSON.stringify({
  4237. Command: `!LEAVEGROUP ${this.#botName} ${groupId}`
  4238. })
  4239. });
  4240. if (result === 'Success') {
  4241. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4242. logStatus.success();
  4243. return true;
  4244. }
  4245. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4246. return false;
  4247. }
  4248. logStatus.error(`${result}:${statusText}(${status})`);
  4249. return false;
  4250. } catch (error) {
  4251. throwError(error, 'SteamASF.leaveGroup');
  4252. return false;
  4253. }
  4254. }
  4255. async #getGroupId() {
  4256. try {
  4257. const logStatus = scripts_echoLog({
  4258. type: 'gettingSteamGroupId',
  4259. text: 'All'
  4260. });
  4261. const {
  4262. result,
  4263. statusText,
  4264. status,
  4265. data
  4266. } = await tools_httpRequest({
  4267. ...this.#asfOptions,
  4268. data: JSON.stringify({
  4269. Command: `!GROUPLIST ${this.#botName}`
  4270. })
  4271. });
  4272. if (result === 'Success') {
  4273. if (data?.status === 200 && data.response?.Result?.includes('|')) {
  4274. this.#groupInfo = Object.fromEntries(data.response.Result.split('\n').map(line => {
  4275. const [ , name, id ] = line.trim().split('|');
  4276. if (name && id) {
  4277. return [ name, id ];
  4278. }
  4279. return null;
  4280. }).filter(ele => ele));
  4281. logStatus.success();
  4282. return true;
  4283. }
  4284. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4285. return false;
  4286. }
  4287. logStatus.error(`${result}:${statusText}(${status})`);
  4288. return false;
  4289. } catch (error) {
  4290. throwError(error, 'SteamASF.getGroupID');
  4291. return false;
  4292. }
  4293. }
  4294. async addToWishlist(gameId) {
  4295. try {
  4296. const logStatus = scripts_echoLog({
  4297. type: 'addingToWishlist',
  4298. text: gameId
  4299. });
  4300. const {
  4301. result,
  4302. statusText,
  4303. status,
  4304. data
  4305. } = await tools_httpRequest({
  4306. ...this.#asfOptions,
  4307. data: JSON.stringify({
  4308. Command: `!ADDWISHLIST ${this.#botName} ${gameId}`
  4309. })
  4310. });
  4311. if (result === 'Success') {
  4312. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4313. logStatus.success();
  4314. return true;
  4315. }
  4316. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4317. return false;
  4318. }
  4319. logStatus.error(`${result}:${statusText}(${status})`);
  4320. return false;
  4321. } catch (error) {
  4322. throwError(error, 'SteamASF.addToWishlist');
  4323. return false;
  4324. }
  4325. }
  4326. async removeFromWishlist(gameId) {
  4327. try {
  4328. const logStatus = scripts_echoLog({
  4329. type: 'removingFromWishlist',
  4330. text: gameId
  4331. });
  4332. const {
  4333. result,
  4334. statusText,
  4335. status,
  4336. data
  4337. } = await tools_httpRequest({
  4338. ...this.#asfOptions,
  4339. data: JSON.stringify({
  4340. Command: `!REMOVEWISHLIST ${this.#botName} ${gameId}`
  4341. })
  4342. });
  4343. if (result === 'Success') {
  4344. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4345. logStatus.success();
  4346. return true;
  4347. }
  4348. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4349. return false;
  4350. }
  4351. logStatus.error(`${result}:${statusText}(${status})`);
  4352. return false;
  4353. } catch (error) {
  4354. throwError(error, 'SteamASF.removeFromWishlist');
  4355. return false;
  4356. }
  4357. }
  4358. async toggleFollowGame(gameId, doTask) {
  4359. try {
  4360. const logStatus = scripts_echoLog({
  4361. type: `${doTask ? '' : 'un'}followingGame`,
  4362. text: gameId
  4363. });
  4364. const {
  4365. result,
  4366. statusText,
  4367. status,
  4368. data
  4369. } = await tools_httpRequest({
  4370. ...this.#asfOptions,
  4371. data: JSON.stringify({
  4372. Command: `!${doTask ? '' : 'UN'}FOLLOWGAME ${this.#botName} ${gameId}`
  4373. })
  4374. });
  4375. if (result === 'Success') {
  4376. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4377. logStatus.success();
  4378. return true;
  4379. }
  4380. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4381. return false;
  4382. }
  4383. logStatus.error(`${result}:${statusText}(${status})`);
  4384. return false;
  4385. } catch (error) {
  4386. throwError(error, 'SteamASF.toggleFollowGame');
  4387. return false;
  4388. }
  4389. }
  4390. async toggleCurator(curatorId, doTask = true) {
  4391. try {
  4392. const logStatus = scripts_echoLog({
  4393. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  4394. text: curatorId
  4395. });
  4396. const {
  4397. result,
  4398. statusText,
  4399. status,
  4400. data
  4401. } = await tools_httpRequest({
  4402. ...this.#asfOptions,
  4403. data: JSON.stringify({
  4404. Command: `!${doTask ? '' : 'UN'}FOLLOWCURATOR ${this.#botName} ${curatorId}`
  4405. })
  4406. });
  4407. if (result === 'Success') {
  4408. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4409. logStatus.success();
  4410. return true;
  4411. }
  4412. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4413. return false;
  4414. }
  4415. logStatus.error(`${result}:${statusText}(${status})`);
  4416. return false;
  4417. } catch (error) {
  4418. throwError(error, 'Steam.toggleCurator');
  4419. return false;
  4420. }
  4421. }
  4422. async addLicense(id) {
  4423. try {
  4424. const [ type, ids ] = id.split('-');
  4425. if (type === 'appid') {
  4426. const logStatus = scripts_echoLog({
  4427. type: 'addingFreeLicense',
  4428. text: ids
  4429. });
  4430. const {
  4431. result,
  4432. statusText,
  4433. status,
  4434. data
  4435. } = await tools_httpRequest({
  4436. ...this.#asfOptions,
  4437. data: JSON.stringify({
  4438. Command: `!addlicense ${this.#botName} app/${ids}`
  4439. })
  4440. });
  4441. if (result === 'Success') {
  4442. if (data?.status === 200 && [ 'AlreadyPurchased', 'OK' ].find(text => data.response?.Result?.includes(text))) {
  4443. logStatus.success();
  4444. return true;
  4445. }
  4446. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4447. return false;
  4448. }
  4449. logStatus.error(`${result}:${statusText}(${status})`);
  4450. return false;
  4451. } else if (type === 'subid') {
  4452. const idsArr = ids.split(',');
  4453. const logStatus = scripts_echoLog({
  4454. type: 'addingFreeLicenseSubid',
  4455. text: ids
  4456. });
  4457. const {
  4458. result,
  4459. statusText,
  4460. status,
  4461. data
  4462. } = await tools_httpRequest({
  4463. ...this.#asfOptions,
  4464. data: JSON.stringify({
  4465. Command: `!addlicense ${this.#botName} ${idsArr.map(id => `sub/${id}`).join(',')}`
  4466. })
  4467. });
  4468. if (result === 'Success') {
  4469. if (data?.status === 200 && data.response?.Result) {
  4470. const resultLines = data.response.Result.split('\n');
  4471. idsArr.forEach(subid => {
  4472. const targetLine = resultLines.find(text => text.includes(subid));
  4473. if (targetLine && [ '成功', 'Success', 'Успех' ].find(text => targetLine.includes(text))) {
  4474. scripts_echoLog({}).success(targetLine);
  4475. } else {
  4476. scripts_echoLog({}).error(targetLine);
  4477. }
  4478. });
  4479. return true;
  4480. }
  4481. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4482. return false;
  4483. }
  4484. logStatus.error(`${result}:${statusText}(${status})`);
  4485. return false;
  4486. }
  4487. return false;
  4488. } catch (error) {
  4489. throwError(error, 'SteamASF.addLicense');
  4490. return false;
  4491. }
  4492. }
  4493. async requestPlayTestAccess(id) {
  4494. try {
  4495. const logStatus = scripts_echoLog({
  4496. type: 'requestingPlayTestAccess',
  4497. text: id
  4498. });
  4499. const {
  4500. result,
  4501. statusText,
  4502. status,
  4503. data
  4504. } = await tools_httpRequest({
  4505. ...this.#asfOptions,
  4506. data: JSON.stringify({
  4507. Command: `!REQUESTACCESS ${this.#botName} ${id}`
  4508. })
  4509. });
  4510. if (result === 'Success') {
  4511. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4512. logStatus.success();
  4513. return true;
  4514. }
  4515. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4516. return false;
  4517. }
  4518. logStatus.error(`${result}:${statusText}(${status})`);
  4519. return false;
  4520. } catch (error) {
  4521. throwError(error, 'Steam.requestPlayTestAccess');
  4522. return false;
  4523. }
  4524. }
  4525. }
  4526. const social_SteamASF = SteamASF;
  4527. class Steam extends social_Social {
  4528. tasks;
  4529. whiteList;
  4530. #cache = {
  4531. ...{
  4532. group: {},
  4533. officialGroup: {},
  4534. forum: {},
  4535. workshop: {},
  4536. curator: {}
  4537. },
  4538. ...GM_getValue('steamCache')
  4539. };
  4540. #auth = {};
  4541. #storeInitialized = false;
  4542. #communityInitialized = false;
  4543. #area = 'CN';
  4544. #areaStatus = 'end';
  4545. #ASF;
  4546. constructor() {
  4547. super();
  4548. const defaultTasksTemplate = {
  4549. groups: [],
  4550. officialGroups: [],
  4551. wishlists: [],
  4552. follows: [],
  4553. forums: [],
  4554. workshops: [],
  4555. workshopVotes: [],
  4556. curators: [],
  4557. curatorLikes: [],
  4558. announcements: [],
  4559. licenses: [],
  4560. playtests: []
  4561. };
  4562. this.tasks = defaultTasksTemplate;
  4563. this.whiteList = {
  4564. ...defaultTasksTemplate,
  4565. ...GM_getValue('whiteList')?.steam || {}
  4566. };
  4567. }
  4568. async init(type = 'all') {
  4569. try {
  4570. if (globalOptions.ASF.AsfEnabled && globalOptions.ASF.AsfIpcUrl && globalOptions.ASF.AsfIpcPassword) {
  4571. this.#ASF = new social_SteamASF();
  4572. if (await this.#ASF.init()) {
  4573. this.#storeInitialized = true;
  4574. this.#communityInitialized = true;
  4575. return true;
  4576. }
  4577. return false;
  4578. }
  4579. if (type === 'store') {
  4580. if (this.#storeInitialized) {
  4581. return true;
  4582. }
  4583. let storeInitialized = await this.#updateStoreAuth();
  4584. if (!storeInitialized) {
  4585. storeInitialized = await this.#updateStoreAuthTab();
  4586. }
  4587. this.#storeInitialized = storeInitialized;
  4588. if (!this.#storeInitialized) {
  4589. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4590. return false;
  4591. }
  4592. scripts_echoLog({}).success(i18n('initSuccess', 'SteamStore'));
  4593. return true;
  4594. }
  4595. if (type === 'community') {
  4596. if (this.#communityInitialized) {
  4597. return true;
  4598. }
  4599. let communityInitialized = await this.#getUserLink();
  4600. if (!communityInitialized) {
  4601. communityInitialized = await this.#updateCommunityAuthTab();
  4602. GM_setValue('steamCommunityAuth', null);
  4603. }
  4604. this.#communityInitialized = communityInitialized;
  4605. if (!this.#communityInitialized) {
  4606. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4607. return false;
  4608. }
  4609. scripts_echoLog({}).success(i18n('initSuccess', 'SteamCommunity'));
  4610. return true;
  4611. }
  4612. if (this.#storeInitialized && this.#communityInitialized) {
  4613. scripts_echoLog({}).success(i18n('initSuccess', 'Steam'));
  4614. return true;
  4615. }
  4616. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4617. return false;
  4618. } catch (error) {
  4619. throwError(error, 'Steam.init');
  4620. return false;
  4621. }
  4622. }
  4623. async #refreshToken(type = 'steamStore') {
  4624. try {
  4625. const host = {
  4626. steamStore: 'store.steampowered.com',
  4627. steamCommunity: 'steamcommunity.com'
  4628. };
  4629. const logStatus = scripts_echoLog({
  4630. text: i18n('refreshingToken', i18n(type))
  4631. });
  4632. const formData = new FormData();
  4633. formData.append('redir', `https://${host[type]}/`);
  4634. const {
  4635. result,
  4636. statusText,
  4637. status,
  4638. data
  4639. } = await tools_httpRequest({
  4640. url: 'https://login.steampowered.com/jwt/ajaxrefresh',
  4641. method: 'POST',
  4642. responseType: 'json',
  4643. headers: {
  4644. Host: 'login.steampowered.com',
  4645. Origin: `https://${host[type]}`,
  4646. Referer: `https://${host[type]}/`
  4647. },
  4648. data: formData
  4649. });
  4650. if (result === 'Success') {
  4651. if (data?.response?.success) {
  4652. if (await this.#setStoreToken(data.response, type)) {
  4653. logStatus.success();
  4654. return true;
  4655. }
  4656. logStatus.error('Error');
  4657. return false;
  4658. }
  4659. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4660. return false;
  4661. }
  4662. logStatus.error(`${result}:${statusText}(${status})`);
  4663. return false;
  4664. } catch (error) {
  4665. throwError(error, 'Steam.refreshToken');
  4666. return false;
  4667. }
  4668. }
  4669. async #setStoreToken(param, type) {
  4670. try {
  4671. const host = {
  4672. steamStore: 'store.steampowered.com',
  4673. steamCommunity: 'steamcommunity.com'
  4674. };
  4675. const logStatus = scripts_echoLog({
  4676. text: i18n('settingToken', i18n(type))
  4677. });
  4678. const formData = new FormData();
  4679. formData.append('steamID', param.steamID);
  4680. formData.append('nonce', param.nonce);
  4681. formData.append('redir', param.redir);
  4682. formData.append('auth', param.auth);
  4683. const {
  4684. result,
  4685. statusText,
  4686. status,
  4687. data
  4688. } = await tools_httpRequest({
  4689. url: `https://${host[type]}/login/settoken`,
  4690. method: 'POST',
  4691. headers: {
  4692. Accept: 'application/json, text/plain, */*',
  4693. Host: host[type],
  4694. Origin: `https://${host[type]}`
  4695. },
  4696. data: formData
  4697. });
  4698. if (result === 'Success') {
  4699. if (data?.status === 200) {
  4700. logStatus.success();
  4701. return true;
  4702. }
  4703. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4704. return false;
  4705. }
  4706. logStatus.error(`${result}:${statusText}(${status})`);
  4707. return false;
  4708. } catch (error) {
  4709. throwError(error, 'Steam.setStoreToken');
  4710. return false;
  4711. }
  4712. }
  4713. async #updateStoreAuth(retry = false) {
  4714. try {
  4715. const logStatus = scripts_echoLog({
  4716. text: i18n('updatingAuth', i18n('steamStore'))
  4717. });
  4718. const {
  4719. result,
  4720. statusText,
  4721. status,
  4722. data
  4723. } = await tools_httpRequest({
  4724. url: 'https://store.steampowered.com/',
  4725. method: 'GET',
  4726. headers: {
  4727. 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',
  4728. 'Sec-Fetch-Dest': 'document',
  4729. 'Sec-Fetch-Mode': 'navigate',
  4730. 'Upgrade-Insecure-Requests': '1'
  4731. },
  4732. fetch: false,
  4733. redirect: 'manual'
  4734. });
  4735. if (data?.status === 200) {
  4736. if (!data.responseText.includes('data-miniprofile=')) {
  4737. if (await this.#refreshToken('steamStore')) {
  4738. logStatus.warning(i18n('retry'));
  4739. if (retry) {
  4740. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4741. return false;
  4742. }
  4743. return this.#updateStoreAuth(true);
  4744. }
  4745. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4746. return false;
  4747. }
  4748. const storeSessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4749. if (storeSessionID) {
  4750. this.#auth.storeSessionID = storeSessionID;
  4751. logStatus.success();
  4752. return true;
  4753. }
  4754. logStatus.error('Error: Get "sessionID" failed');
  4755. return false;
  4756. }
  4757. if ([ 301, 302 ].includes(data?.status)) {
  4758. if (await this.#refreshToken('steamStore')) {
  4759. logStatus.warning(i18n('retry'));
  4760. if (retry) {
  4761. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4762. return false;
  4763. }
  4764. return this.#updateStoreAuth(true);
  4765. }
  4766. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4767. return false;
  4768. }
  4769. logStatus.error(`${result}:${statusText}(${status})`);
  4770. return false;
  4771. } catch (error) {
  4772. throwError(error, 'Steam.updateStoreAuth');
  4773. return false;
  4774. }
  4775. }
  4776. async #updateStoreAuthTab() {
  4777. try {
  4778. const logStatus = scripts_echoLog({
  4779. text: i18n('updatingAuth', i18n('steamStoreTab'))
  4780. });
  4781. return await new Promise(resolve => {
  4782. GM_deleteValue('steamStoreAuth');
  4783. const newTab = GM_openInTab('https://store.steampowered.com/', {
  4784. active: true,
  4785. setParent: true
  4786. });
  4787. newTab.name = 'ATv4_updateStoreAuth';
  4788. const listenerId = GM_addValueChangeListener('steamStoreAuth', (key, oldValue, newValue) => {
  4789. GM_removeValueChangeListener(listenerId);
  4790. newTab?.close();
  4791. if (newValue && JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
  4792. this.#auth.storeSessionID = newValue.storeSessionID;
  4793. logStatus.success();
  4794. resolve(true);
  4795. return;
  4796. }
  4797. logStatus.error('Failed');
  4798. resolve(false);
  4799. });
  4800. });
  4801. } catch (error) {
  4802. throwError(error, 'Steam.updateStoreAuthTab');
  4803. return false;
  4804. }
  4805. }
  4806. async #updateCommunityAuthTab() {
  4807. try {
  4808. const logStatus = scripts_echoLog({
  4809. text: i18n('updatingAuth', i18n('steamCommunityTab'))
  4810. });
  4811. return await new Promise(resolve => {
  4812. GM_deleteValue('steamCommunityAuth');
  4813. const newTab = GM_openInTab('https://steamcommunity.com/my', {
  4814. active: true,
  4815. setParent: true
  4816. });
  4817. newTab.name = 'ATv4_updateCommunityAuth';
  4818. const listenerId = GM_addValueChangeListener('steamCommunityAuth', (key, oldValue, newValue) => {
  4819. GM_removeValueChangeListener(listenerId);
  4820. newTab?.close();
  4821. if (newValue && JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
  4822. this.#auth.steam64Id = newValue.steam64Id;
  4823. this.#auth.communitySessionID = newValue.communitySessionID;
  4824. logStatus.success();
  4825. resolve(true);
  4826. return;
  4827. }
  4828. logStatus.error('Failed');
  4829. resolve(false);
  4830. });
  4831. });
  4832. } catch (error) {
  4833. throwError(error, 'Steam.updateCommunityAuthTab');
  4834. return false;
  4835. }
  4836. }
  4837. async #getUserLink(retry = false) {
  4838. try {
  4839. const logStatus = scripts_echoLog({
  4840. text: i18n('gettingUserLink')
  4841. });
  4842. const {
  4843. result,
  4844. statusText,
  4845. status,
  4846. data
  4847. } = await tools_httpRequest({
  4848. url: 'https://steamcommunity.com/my',
  4849. method: 'GET',
  4850. headers: {
  4851. 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',
  4852. 'Sec-Fetch-Dest': 'document',
  4853. 'Sec-Fetch-Mode': 'navigate',
  4854. 'Upgrade-Insecure-Requests': '1'
  4855. },
  4856. fetch: false,
  4857. redirect: 'manual'
  4858. });
  4859. if (data?.status === 200) {
  4860. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4861. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4862. return false;
  4863. }
  4864. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4865. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4866. if (steam64Id) {
  4867. this.#auth.steam64Id = steam64Id;
  4868. }
  4869. if (communitySessionID) {
  4870. this.#auth.communitySessionID = communitySessionID;
  4871. logStatus.success();
  4872. return true;
  4873. }
  4874. logStatus.error('Error: Get "sessionID" failed');
  4875. return false;
  4876. }
  4877. if (data?.status === 302) {
  4878. if (await this.#refreshToken('steamCommunity')) {
  4879. if (retry) {
  4880. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4881. return false;
  4882. }
  4883. logStatus.warning(i18n('retry'));
  4884. return this.#getUserLink(true);
  4885. }
  4886. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4887. return false;
  4888. }
  4889. const location = data?.finalUrl || data?.responseHeaders?.split('\n')?.find(header => header.includes('location') ? header.replace('loctation:', '').trim() : null);
  4890. if (data?.status === 301) {
  4891. if (location?.includes('steamcommunity.com/id')) {
  4892. logStatus.success();
  4893. return await this.#updateCommunityAuth(location);
  4894. }
  4895. if (location?.includes('steamcommunity.com/login/home')) {
  4896. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4897. return false;
  4898. }
  4899. if (location?.includes('steamcommunity.com/my')) {
  4900. if (retry) {
  4901. logStatus.error(`Error:${i18n('redirect')}`, true);
  4902. return false;
  4903. }
  4904. logStatus.warning(i18n('retry'));
  4905. return await this.#getUserLink(true);
  4906. }
  4907. logStatus.error(`Error: 301 (${location})`, true);
  4908. return false;
  4909. }
  4910. logStatus.error(`${result}:${statusText}(${status})`);
  4911. return false;
  4912. } catch (error) {
  4913. throwError(error, 'Steam.updateCommunityAuth');
  4914. return false;
  4915. }
  4916. }
  4917. async #updateCommunityAuth(url) {
  4918. try {
  4919. const logStatus = scripts_echoLog({
  4920. text: i18n('updatingAuth', i18n('steamCommunity'))
  4921. });
  4922. const {
  4923. result,
  4924. statusText,
  4925. status,
  4926. data
  4927. } = await tools_httpRequest({
  4928. url: url,
  4929. method: 'GET',
  4930. headers: {
  4931. 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',
  4932. 'Cache-Control': 'max-age=0',
  4933. 'Sec-Fetch-Dest': 'document',
  4934. 'Sec-Fetch-Mode': 'navigate',
  4935. 'Upgrade-Insecure-Requests': '1'
  4936. }
  4937. });
  4938. if (result === 'Success') {
  4939. if (data?.status === 200) {
  4940. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4941. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4942. return false;
  4943. }
  4944. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4945. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4946. if (steam64Id) {
  4947. this.#auth.steam64Id = steam64Id;
  4948. }
  4949. if (communitySessionID) {
  4950. this.#auth.communitySessionID = communitySessionID;
  4951. logStatus.success();
  4952. return true;
  4953. }
  4954. logStatus.error('Error: Get "sessionID" failed');
  4955. return false;
  4956. }
  4957. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4958. return false;
  4959. }
  4960. logStatus.error(`${result}:${statusText}(${status})`);
  4961. return false;
  4962. } catch (error) {
  4963. throwError(error, 'Steam.updateCommunityAuth');
  4964. return false;
  4965. }
  4966. }
  4967. async #getAreaInfo() {
  4968. try {
  4969. const logStatus = scripts_echoLog({
  4970. text: i18n('gettingAreaInfo')
  4971. });
  4972. const {
  4973. result,
  4974. statusText,
  4975. status,
  4976. data
  4977. } = await tools_httpRequest({
  4978. url: 'https://store.steampowered.com/cart/',
  4979. method: 'GET'
  4980. });
  4981. if (result === 'Success') {
  4982. if (data?.status === 200) {
  4983. const cartConfigRaw = data.responseText.match(/data-cart_config="(.*?)"/)?.[1];
  4984. const temp = document.createElement('div');
  4985. temp.innerHTML = cartConfigRaw || '{}';
  4986. const cartConfigStr = temp.textContent || temp.innerText;
  4987. let cartConfig;
  4988. try {
  4989. cartConfig = JSON.parse(cartConfigStr);
  4990. } catch (error) {
  4991. logStatus.error('Error: get country info filed');
  4992. console.error(error);
  4993. return {};
  4994. }
  4995. if (!cartConfig.rgUserCountryOptions) {
  4996. logStatus.warning('Warning: Area cannot be changed');
  4997. return {};
  4998. }
  4999. const userInfoRaw = data.responseText.match(/data-userinfo="(.*?)"/)?.[1];
  5000. const temp1 = document.createElement('div');
  5001. temp1.innerHTML = userInfoRaw || '{}';
  5002. const userInfoStr = temp1.textContent || temp1.innerText;
  5003. let userInfo;
  5004. try {
  5005. userInfo = JSON.parse(userInfoStr);
  5006. } catch (error) {
  5007. logStatus.error('Error: get country info filed');
  5008. console.error(error);
  5009. return {};
  5010. }
  5011. const currentArea = userInfo.country_code;
  5012. const areas = Object.keys(cartConfig.rgUserCountryOptions).filter(area => area !== 'help');
  5013. if (currentArea && areas.length > 0) {
  5014. this.#area = currentArea;
  5015. logStatus.success();
  5016. return {
  5017. currentArea: currentArea,
  5018. areas: areas
  5019. };
  5020. }
  5021. logStatus.error('Error: get country info filed');
  5022. return {};
  5023. }
  5024. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5025. return {};
  5026. }
  5027. logStatus.error(`${result}:${statusText}(${status})`);
  5028. return {};
  5029. } catch (error) {
  5030. throwError(error, 'Steam.getAreaInfo');
  5031. return {};
  5032. }
  5033. }
  5034. async #changeArea(area) {
  5035. try {
  5036. if (this.#areaStatus === 'waiting') {
  5037. await new Promise(resolve => {
  5038. const checker = setInterval(() => {
  5039. if (this.#areaStatus !== 'waiting') {
  5040. clearInterval(checker);
  5041. resolve(true);
  5042. }
  5043. });
  5044. });
  5045. }
  5046. if (this.#area === area || !area && this.#area !== 'CN') {
  5047. return true;
  5048. }
  5049. this.#areaStatus = 'waiting';
  5050. let aimedArea = area;
  5051. if (!aimedArea) {
  5052. const {
  5053. currentArea,
  5054. areas
  5055. } = await this.#getAreaInfo();
  5056. if (!currentArea || !areas) {
  5057. this.#areaStatus = 'error';
  5058. return false;
  5059. }
  5060. if (currentArea !== 'CN') {
  5061. this.#areaStatus = 'skip';
  5062. scripts_echoLog({
  5063. text: 'notNeededChangeArea'
  5064. });
  5065. return 'skip';
  5066. }
  5067. const anotherArea = areas.filter(area => area && area !== 'CN');
  5068. if (!anotherArea || anotherArea.length === 0) {
  5069. this.#areaStatus = 'noAnotherArea';
  5070. scripts_echoLog({
  5071. text: 'noAnotherArea'
  5072. });
  5073. return false;
  5074. }
  5075. [ aimedArea ] = anotherArea;
  5076. }
  5077. const logStatus = scripts_echoLog({
  5078. text: i18n('changingArea', aimedArea)
  5079. });
  5080. const {
  5081. result,
  5082. statusText,
  5083. status,
  5084. data
  5085. } = await tools_httpRequest({
  5086. url: 'https://store.steampowered.com/country/setcountry',
  5087. method: 'POST',
  5088. headers: {
  5089. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5090. },
  5091. data: $.param({
  5092. cc: aimedArea,
  5093. sessionid: this.#auth.storeSessionID
  5094. })
  5095. });
  5096. if (result === 'Success') {
  5097. if (data?.status === 200 && data.responseText === 'true') {
  5098. const {
  5099. currentArea
  5100. } = await this.#getAreaInfo();
  5101. if (currentArea === aimedArea) {
  5102. this.#areaStatus = 'success';
  5103. logStatus.success();
  5104. return currentArea;
  5105. }
  5106. this.#areaStatus = 'error';
  5107. logStatus.error('Error: change country filed');
  5108. return 'CN';
  5109. }
  5110. this.#areaStatus = 'error';
  5111. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5112. return 'CN';
  5113. }
  5114. this.#areaStatus = 'error';
  5115. logStatus.error(`${result}:${statusText}(${status})`);
  5116. return 'CN';
  5117. } catch (error) {
  5118. this.#areaStatus = 'error';
  5119. throwError(error, 'Steam.changeArea');
  5120. return false;
  5121. }
  5122. }
  5123. async #joinGroup(groupName) {
  5124. try {
  5125. if (this.#ASF) {
  5126. if (await this.#ASF.joinGroup(groupName)) {
  5127. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5128. return true;
  5129. }
  5130. return false;
  5131. }
  5132. const logStatus = scripts_echoLog({
  5133. type: 'joiningSteamGroup',
  5134. text: groupName
  5135. });
  5136. const {
  5137. result,
  5138. statusText,
  5139. status,
  5140. data
  5141. } = await tools_httpRequest({
  5142. url: `https://steamcommunity.com/groups/${groupName}`,
  5143. method: 'POST',
  5144. headers: {
  5145. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5146. },
  5147. data: $.param({
  5148. action: 'join',
  5149. sessionID: this.#auth.communitySessionID
  5150. })
  5151. });
  5152. if (result === 'Success') {
  5153. if (data?.status === 200 && !data.responseText.includes('grouppage_join_area')) {
  5154. logStatus.success();
  5155. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5156. return true;
  5157. }
  5158. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5159. return false;
  5160. }
  5161. logStatus.error(`${result}:${statusText}(${status})`);
  5162. return false;
  5163. } catch (error) {
  5164. throwError(error, 'Steam.joinGroup');
  5165. return false;
  5166. }
  5167. }
  5168. async #leaveGroup(groupName) {
  5169. try {
  5170. if (this.whiteList.groups.includes(groupName)) {
  5171. scripts_echoLog({
  5172. type: 'whiteList',
  5173. text: 'Steam.leaveGroup',
  5174. id: groupName
  5175. });
  5176. return true;
  5177. }
  5178. if (this.#ASF) {
  5179. return await this.#ASF.leaveGroup(groupName);
  5180. }
  5181. const groupId = await this.#getGroupId(groupName);
  5182. if (!groupId) {
  5183. return false;
  5184. }
  5185. const logStatus = scripts_echoLog({
  5186. type: 'leavingSteamGroup',
  5187. text: groupName
  5188. });
  5189. const {
  5190. result,
  5191. statusText,
  5192. status,
  5193. data
  5194. } = await tools_httpRequest({
  5195. url: `https://steamcommunity.com/profiles/${this.#auth.steam64Id}/home_process`,
  5196. method: 'POST',
  5197. headers: {
  5198. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5199. },
  5200. data: $.param({
  5201. sessionID: this.#auth.communitySessionID,
  5202. action: 'leaveGroup',
  5203. groupId: groupId
  5204. })
  5205. });
  5206. if (result === 'Success') {
  5207. 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) {
  5208. logStatus.success();
  5209. return true;
  5210. }
  5211. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5212. return false;
  5213. }
  5214. logStatus.error(`${result}:${statusText}(${status})`);
  5215. return false;
  5216. } catch (error) {
  5217. throwError(error, 'Steam.leaveGroup');
  5218. return false;
  5219. }
  5220. }
  5221. async #getGroupId(groupName) {
  5222. try {
  5223. const logStatus = scripts_echoLog({
  5224. type: 'gettingSteamGroupId',
  5225. text: groupName
  5226. });
  5227. const groupId = this.#cache.group[groupName];
  5228. if (groupId) {
  5229. logStatus.success();
  5230. return groupId;
  5231. }
  5232. const {
  5233. result,
  5234. statusText,
  5235. status,
  5236. data
  5237. } = await tools_httpRequest({
  5238. url: `https://steamcommunity.com/groups/${groupName}`,
  5239. method: 'GET',
  5240. headers: {
  5241. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5242. }
  5243. });
  5244. if (result === 'Success') {
  5245. if (data?.status === 200) {
  5246. const groupId = data.responseText.match(/OpenGroupChat\( '([0-9]+)'/)?.[1];
  5247. if (groupId) {
  5248. this.#setCache('group', groupName, groupId);
  5249. logStatus.success();
  5250. return groupId;
  5251. }
  5252. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5253. return false;
  5254. }
  5255. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5256. return false;
  5257. }
  5258. logStatus.error(`${result}:${statusText}(${status})`);
  5259. return false;
  5260. } catch (error) {
  5261. throwError(error, 'Steam.getGroupID');
  5262. return false;
  5263. }
  5264. }
  5265. async #joinOfficialGroup(gameId) {
  5266. try {
  5267. if (this.#ASF) {
  5268. if (await this.#ASF.joinGroup(gameId)) {
  5269. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5270. return true;
  5271. }
  5272. return false;
  5273. }
  5274. const logStatus = scripts_echoLog({
  5275. type: 'joiningSteamOfficialGroup',
  5276. text: gameId
  5277. });
  5278. const {
  5279. result,
  5280. statusText,
  5281. status,
  5282. data
  5283. } = await tools_httpRequest({
  5284. url: `https://steamcommunity.com/games/${gameId}?action=join&sessionID=${this.#auth.communitySessionID}`,
  5285. method: 'GET',
  5286. headers: {
  5287. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5288. }
  5289. });
  5290. if (result === 'Success') {
  5291. if (data?.status === 200 && !data.responseText.includes('id="publicGroupJoin"')) {
  5292. logStatus.success();
  5293. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5294. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5295. if (groupId) {
  5296. this.#setCache('officialGroup', gameId, groupId);
  5297. }
  5298. return true;
  5299. }
  5300. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5301. return false;
  5302. }
  5303. logStatus.error(`${result}:${statusText}(${status})`);
  5304. return false;
  5305. } catch (error) {
  5306. throwError(error, 'Steam.joinOfficialGroup');
  5307. return false;
  5308. }
  5309. }
  5310. async #leaveOfficialGroup(gameId) {
  5311. try {
  5312. if (this.whiteList.officialGroups.includes(gameId)) {
  5313. scripts_echoLog({
  5314. type: 'whiteList',
  5315. text: 'Steam.leaveOfficialGroup',
  5316. id: gameId
  5317. });
  5318. return true;
  5319. }
  5320. if (this.#ASF) {
  5321. return await this.#ASF.leaveGroup(gameId);
  5322. }
  5323. const groupId = await this.#getOfficialGroupId(gameId);
  5324. if (!groupId) {
  5325. return false;
  5326. }
  5327. const logStatus = scripts_echoLog({
  5328. type: 'leavingSteamOfficialGroup',
  5329. text: gameId
  5330. });
  5331. const {
  5332. result,
  5333. statusText,
  5334. status,
  5335. data
  5336. } = await tools_httpRequest({
  5337. url: `https://steamcommunity.com/profiles/${this.#auth.steam64Id}/home_process`,
  5338. method: 'POST',
  5339. headers: {
  5340. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5341. },
  5342. data: $.param({
  5343. sessionID: this.#auth.communitySessionID,
  5344. action: 'leaveGroup',
  5345. groupId: groupId
  5346. })
  5347. });
  5348. if (result === 'Success') {
  5349. if (data?.status === 200) {
  5350. const {
  5351. result: resultR,
  5352. statusText: statusTextR,
  5353. status: statusR,
  5354. data: dataR
  5355. } = await tools_httpRequest({
  5356. url: `https://steamcommunity.com/games/${gameId}`,
  5357. method: 'GET',
  5358. headers: {
  5359. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5360. }
  5361. });
  5362. if (resultR === 'Success') {
  5363. if (dataR?.status === 200 && dataR.responseText.includes('id="publicGroupJoin"')) {
  5364. logStatus.success();
  5365. return true;
  5366. }
  5367. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5368. return false;
  5369. }
  5370. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5371. return false;
  5372. }
  5373. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5374. return false;
  5375. }
  5376. logStatus.error(`${result}:${statusText}(${status})`);
  5377. return false;
  5378. } catch (error) {
  5379. throwError(error, 'Steam.leaveOfficialGroup');
  5380. return false;
  5381. }
  5382. }
  5383. async #getOfficialGroupId(gameId) {
  5384. try {
  5385. const logStatus = scripts_echoLog({
  5386. type: 'gettingSteamOfficialGroupId',
  5387. text: gameId
  5388. });
  5389. const groupId = this.#cache.officialGroup[gameId];
  5390. if (groupId) {
  5391. logStatus.success();
  5392. return groupId;
  5393. }
  5394. const {
  5395. result,
  5396. statusText,
  5397. status,
  5398. data
  5399. } = await tools_httpRequest({
  5400. url: `https://steamcommunity.com/games/${gameId}`,
  5401. method: 'GET',
  5402. headers: {
  5403. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5404. }
  5405. });
  5406. if (result === 'Success') {
  5407. if (data?.status === 200) {
  5408. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5409. if (groupId) {
  5410. this.#setCache('officialGroup', gameId, groupId);
  5411. logStatus.success();
  5412. return groupId;
  5413. }
  5414. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5415. return false;
  5416. }
  5417. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5418. return false;
  5419. }
  5420. logStatus.error(`${result}:${statusText}(${status})`);
  5421. return false;
  5422. } catch (error) {
  5423. throwError(error, 'Steam.getGroupID');
  5424. return false;
  5425. }
  5426. }
  5427. async #addToWishlist(gameId) {
  5428. try {
  5429. if (this.#ASF) {
  5430. if (await this.#ASF.addToWishlist(gameId)) {
  5431. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5432. return true;
  5433. }
  5434. return false;
  5435. }
  5436. const logStatus = scripts_echoLog({
  5437. type: 'addingToWishlist',
  5438. text: gameId
  5439. });
  5440. const {
  5441. result,
  5442. data
  5443. } = await tools_httpRequest({
  5444. url: 'https://store.steampowered.com/api/addtowishlist',
  5445. method: 'POST',
  5446. headers: {
  5447. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5448. },
  5449. data: $.param({
  5450. sessionid: this.#auth.storeSessionID,
  5451. appid: gameId
  5452. }),
  5453. dataType: 'json'
  5454. });
  5455. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5456. logStatus.success();
  5457. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5458. return true;
  5459. }
  5460. const {
  5461. result: resultR,
  5462. statusText: statusTextR,
  5463. status: statusR,
  5464. data: dataR
  5465. } = await tools_httpRequest({
  5466. url: `https://store.steampowered.com/app/${gameId}`,
  5467. method: 'GET'
  5468. });
  5469. if (resultR === 'Success') {
  5470. if (dataR?.status === 200) {
  5471. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5472. logStatus.warning(i18n('changeAreaNotice'));
  5473. if (!await this.#changeArea()) {
  5474. return false;
  5475. }
  5476. return await this.#addToWishlist(gameId);
  5477. }
  5478. if (dataR.responseText.includes('class="queue_actions_ctn"') && dataR.responseText.includes('class="already_in_library"')) {
  5479. logStatus.success();
  5480. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5481. return true;
  5482. } 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"')) {
  5483. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5484. return false;
  5485. }
  5486. logStatus.success();
  5487. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5488. return true;
  5489. }
  5490. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5491. return false;
  5492. }
  5493. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5494. return false;
  5495. } catch (error) {
  5496. throwError(error, 'Steam.addToWishlist');
  5497. return false;
  5498. }
  5499. }
  5500. async #removeFromWishlist(gameId) {
  5501. try {
  5502. if (this.whiteList.wishlists.includes(gameId)) {
  5503. scripts_echoLog({
  5504. type: 'whiteList',
  5505. text: 'Steam.removeFromWishlist',
  5506. id: gameId
  5507. });
  5508. return true;
  5509. }
  5510. if (this.#ASF) {
  5511. return await this.#ASF.removeFromWishlist(gameId);
  5512. }
  5513. const logStatus = scripts_echoLog({
  5514. type: 'removingFromWishlist',
  5515. text: gameId
  5516. });
  5517. const {
  5518. result,
  5519. data
  5520. } = await tools_httpRequest({
  5521. url: 'https://store.steampowered.com/api/removefromwishlist',
  5522. method: 'POST',
  5523. headers: {
  5524. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5525. },
  5526. data: $.param({
  5527. sessionid: this.#auth.storeSessionID,
  5528. appid: gameId
  5529. }),
  5530. dataType: 'json'
  5531. });
  5532. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5533. logStatus.success();
  5534. return true;
  5535. }
  5536. const {
  5537. result: resultR,
  5538. statusText: statusTextR,
  5539. status: statusR,
  5540. data: dataR
  5541. } = await tools_httpRequest({
  5542. url: `https://store.steampowered.com/app/${gameId}`,
  5543. method: 'GET'
  5544. });
  5545. if (resultR === 'Success') {
  5546. if (dataR?.status === 200) {
  5547. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5548. logStatus.warning(i18n('changeAreaNotice'));
  5549. const result = await this.#changeArea();
  5550. if (!result || result === 'CN' || result === 'skip') {
  5551. return false;
  5552. }
  5553. return await this.#removeFromWishlist(gameId);
  5554. }
  5555. if (dataR.responseText.includes('class="queue_actions_ctn"') && (dataR.responseText.includes('ds_owned_flag ds_flag') || dataR.responseText.includes('add_to_wishlist_area'))) {
  5556. logStatus.success();
  5557. return true;
  5558. }
  5559. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5560. return false;
  5561. }
  5562. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5563. return false;
  5564. }
  5565. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5566. return false;
  5567. } catch (error) {
  5568. throwError(error, 'Steam.removeFromWishlist');
  5569. return false;
  5570. }
  5571. }
  5572. async #toggleFollowGame(gameId, doTask) {
  5573. try {
  5574. if (!doTask && this.whiteList.follows.includes(gameId)) {
  5575. scripts_echoLog({
  5576. type: 'whiteList',
  5577. text: 'Steam.unfollowGame',
  5578. id: gameId
  5579. });
  5580. return true;
  5581. }
  5582. if (this.#ASF) {
  5583. if (await this.#ASF.toggleFollowGame(gameId, doTask)) {
  5584. if (doTask) {
  5585. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5586. }
  5587. return true;
  5588. }
  5589. return false;
  5590. }
  5591. const logStatus = scripts_echoLog({
  5592. type: `${doTask ? '' : 'un'}followingGame`,
  5593. text: gameId
  5594. });
  5595. const requestData = {
  5596. sessionid: this.#auth.storeSessionID,
  5597. appid: gameId
  5598. };
  5599. if (!doTask) {
  5600. requestData.unfollow = '1';
  5601. }
  5602. const {
  5603. result,
  5604. data
  5605. } = await tools_httpRequest({
  5606. url: 'https://store.steampowered.com/explore/followgame/',
  5607. method: 'POST',
  5608. headers: {
  5609. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5610. },
  5611. data: $.param(requestData)
  5612. });
  5613. if (result === 'Success' && data?.status === 200 && data.responseText === 'true') {
  5614. logStatus.success();
  5615. return true;
  5616. }
  5617. const followed = await this.#isFollowedGame(gameId);
  5618. if (this.#area === 'CN' && followed === 'areaLocked') {
  5619. logStatus.warning(i18n('changeAreaNotice'));
  5620. if (!await this.#changeArea()) {
  5621. return false;
  5622. }
  5623. return await this.#removeFromWishlist(gameId);
  5624. }
  5625. if (doTask === followed) {
  5626. logStatus.success();
  5627. if (doTask) {
  5628. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5629. }
  5630. return true;
  5631. }
  5632. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5633. return false;
  5634. } catch (error) {
  5635. throwError(error, 'Steam.toggleFollowGame');
  5636. return false;
  5637. }
  5638. }
  5639. async #isFollowedGame(gameId) {
  5640. try {
  5641. const {
  5642. result,
  5643. data
  5644. } = await tools_httpRequest({
  5645. url: `https://store.steampowered.com/app/${gameId}`,
  5646. method: 'GET'
  5647. });
  5648. if (result === 'Success') {
  5649. if (data?.status === 200) {
  5650. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  5651. return 'areaLocked';
  5652. }
  5653. if ($(data.responseText.replace(/<img.*?>/g, '')).find('.queue_control_button.queue_btn_follow>.btnv6_blue_hoverfade.btn_medium.queue_btn_active').css('display') !== 'none') {
  5654. return true;
  5655. }
  5656. return false;
  5657. }
  5658. return false;
  5659. }
  5660. return false;
  5661. } catch (error) {
  5662. throwError(error, 'Steam.isFollowedGame');
  5663. return false;
  5664. }
  5665. }
  5666. async #toggleForum(gameId, doTask = true) {
  5667. try {
  5668. if (!doTask && this.whiteList.forums.includes(gameId)) {
  5669. scripts_echoLog({
  5670. type: 'whiteList',
  5671. text: 'Steam.unsubscribeForum',
  5672. id: gameId
  5673. });
  5674. return true;
  5675. }
  5676. const forumId = await this.#getForumId(gameId);
  5677. if (!forumId) {
  5678. return false;
  5679. }
  5680. const logStatus = scripts_echoLog({
  5681. type: `${doTask ? '' : 'un'}subscribingForum`,
  5682. text: gameId
  5683. });
  5684. const [ id, feature ] = forumId.split('_');
  5685. const {
  5686. result,
  5687. statusText,
  5688. status,
  5689. data
  5690. } = await tools_httpRequest({
  5691. url: `https://steamcommunity.com/forum/${id}/General/${doTask ? '' : 'un'}subscribe/${feature || '0'}/`,
  5692. method: 'POST',
  5693. responseType: 'json',
  5694. headers: {
  5695. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5696. },
  5697. data: $.param({
  5698. sessionid: this.#auth.communitySessionID
  5699. })
  5700. });
  5701. if (result === 'Success') {
  5702. if (data?.status === 200 && (data.response?.success === 1 || data.response?.success === 29)) {
  5703. if (doTask) {
  5704. this.tasks.forums = unique([ ...this.tasks.forums, gameId ]);
  5705. }
  5706. logStatus.success();
  5707. return true;
  5708. }
  5709. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5710. return true;
  5711. }
  5712. logStatus.error(`${result}:${statusText}(${status})`);
  5713. return true;
  5714. } catch (error) {
  5715. throwError(error, 'Steam.toggleForum');
  5716. return true;
  5717. }
  5718. }
  5719. async #getForumId(gameId) {
  5720. try {
  5721. const logStatus = scripts_echoLog({
  5722. type: 'gettingForumId',
  5723. text: gameId
  5724. });
  5725. const forumId = this.#cache.forum[gameId];
  5726. if (forumId) {
  5727. logStatus.success();
  5728. return forumId;
  5729. }
  5730. const {
  5731. result,
  5732. statusText,
  5733. status,
  5734. data
  5735. } = await tools_httpRequest({
  5736. url: `https://steamcommunity.com/app/${gameId}/discussions/`,
  5737. method: 'GET'
  5738. });
  5739. if (result === 'Success') {
  5740. if (data?.status === 200) {
  5741. const forumId = data.responseText?.match(/General_([\d]+(_[\d]+)?)/)?.[1];
  5742. if (forumId) {
  5743. this.#setCache('forum', gameId, forumId);
  5744. logStatus.success();
  5745. return forumId;
  5746. }
  5747. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5748. return false;
  5749. }
  5750. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5751. return false;
  5752. }
  5753. logStatus.error(`${result}:${statusText}(${status})`);
  5754. return false;
  5755. } catch (error) {
  5756. throwError(error, 'Steam.getForumId');
  5757. return false;
  5758. }
  5759. }
  5760. async #toggleFavoriteWorkshop(id, doTask = true) {
  5761. try {
  5762. if (!doTask && this.whiteList.workshops.includes(id)) {
  5763. scripts_echoLog({
  5764. type: 'whiteList',
  5765. text: 'Steam.unfavoriteWorkshop',
  5766. id: id
  5767. });
  5768. return true;
  5769. }
  5770. const appid = await this.#getWorkshopAppId(id);
  5771. if (!appid) {
  5772. return false;
  5773. }
  5774. const logStatus = scripts_echoLog({
  5775. type: doTask ? 'favoritingWorkshop' : 'unfavoritingWorkshop',
  5776. text: id
  5777. });
  5778. const {
  5779. result,
  5780. statusText,
  5781. status,
  5782. data
  5783. } = await tools_httpRequest({
  5784. url: `https://steamcommunity.com/sharedfiles/${doTask ? '' : 'un'}favorite`,
  5785. method: 'POST',
  5786. headers: {
  5787. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5788. },
  5789. data: $.param({
  5790. id: id,
  5791. appid: appid,
  5792. sessionid: this.#auth.communitySessionID
  5793. })
  5794. });
  5795. if (result === 'Success') {
  5796. if (data?.status === 200 && !data.responseText) {
  5797. if (doTask) {
  5798. this.tasks.workshops = unique([ ...this.tasks.workshops, id ]);
  5799. }
  5800. logStatus.success();
  5801. return true;
  5802. }
  5803. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5804. return false;
  5805. }
  5806. logStatus.error(`${result}:${statusText}(${status})`);
  5807. return false;
  5808. } catch (error) {
  5809. throwError(error, 'Steam.toggleFavoriteWorkshop');
  5810. return false;
  5811. }
  5812. }
  5813. async #getWorkshopAppId(id) {
  5814. try {
  5815. const logStatus = scripts_echoLog({
  5816. type: 'gettingWorkshopAppId',
  5817. text: id
  5818. });
  5819. const appId = this.#cache.workshop[id];
  5820. if (appId) {
  5821. logStatus.success();
  5822. return appId;
  5823. }
  5824. const {
  5825. result,
  5826. statusText,
  5827. status,
  5828. data
  5829. } = await tools_httpRequest({
  5830. url: `https://steamcommunity.com/sharedfiles/filedetails/?id=${id}`,
  5831. method: 'GET'
  5832. });
  5833. if (result === 'Success') {
  5834. if (data?.status === 200) {
  5835. const appId = data.responseText.match(/<input type="hidden" name="appid" value="([\d]+?)" \/>/)?.[1];
  5836. if (appId) {
  5837. this.#setCache('workshop', id, appId);
  5838. logStatus.success();
  5839. return appId;
  5840. }
  5841. logStatus.error('Error: getWorkshopAppId failed');
  5842. return false;
  5843. }
  5844. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5845. return false;
  5846. }
  5847. logStatus.error(`${result}:${statusText}(${status})`);
  5848. return false;
  5849. } catch (error) {
  5850. throwError(error, 'Steam.getWorkshopAppId');
  5851. return false;
  5852. }
  5853. }
  5854. async #voteUpWorkshop(id) {
  5855. try {
  5856. const logStatus = scripts_echoLog({
  5857. type: 'votingUpWorkshop',
  5858. text: id
  5859. });
  5860. const {
  5861. result,
  5862. statusText,
  5863. status,
  5864. data
  5865. } = await tools_httpRequest({
  5866. url: 'https://steamcommunity.com/sharedfiles/voteup',
  5867. method: 'POST',
  5868. responseType: 'json',
  5869. headers: {
  5870. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5871. },
  5872. data: $.param({
  5873. id: id,
  5874. sessionid: this.#auth.communitySessionID
  5875. })
  5876. });
  5877. if (result === 'Success') {
  5878. if (data?.status === 200 && data.response?.success === 1) {
  5879. logStatus.success();
  5880. return true;
  5881. }
  5882. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5883. return true;
  5884. }
  5885. logStatus.error(`${result}:${statusText}(${status})`);
  5886. return true;
  5887. } catch (error) {
  5888. throwError(error, 'Steam.voteupWorkshop');
  5889. return true;
  5890. }
  5891. }
  5892. async #toggleCurator(curatorId, doTask = true) {
  5893. try {
  5894. if (!doTask && this.whiteList.curators.includes(curatorId)) {
  5895. scripts_echoLog({
  5896. type: 'whiteList',
  5897. text: 'Steam.unfollowCurator',
  5898. id: curatorId
  5899. });
  5900. return true;
  5901. }
  5902. if (this.#ASF) {
  5903. return await this.#ASF.toggleCurator(curatorId, doTask);
  5904. }
  5905. const logStatus = scripts_echoLog({
  5906. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  5907. text: curatorId
  5908. });
  5909. const {
  5910. result,
  5911. statusText,
  5912. status,
  5913. data
  5914. } = await tools_httpRequest({
  5915. url: 'https://store.steampowered.com/curators/ajaxfollow',
  5916. method: 'POST',
  5917. headers: {
  5918. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5919. },
  5920. data: $.param({
  5921. clanid: curatorId,
  5922. sessionid: this.#auth.storeSessionID,
  5923. follow: doTask
  5924. }),
  5925. dataType: 'json'
  5926. });
  5927. if (result === 'Success') {
  5928. if (data?.status === 200 && data.response?.success?.success === 1) {
  5929. logStatus.success();
  5930. return true;
  5931. }
  5932. logStatus.error(`Error:${data?.statusText}(${data?.response?.success}` || `${data?.status})`);
  5933. return false;
  5934. }
  5935. logStatus.error(`${result}:${statusText}(${status})`);
  5936. return false;
  5937. } catch (error) {
  5938. throwError(error, 'Steam.toggleCurator');
  5939. return false;
  5940. }
  5941. }
  5942. async getCuratorId(path, name) {
  5943. try {
  5944. const logStatus = scripts_echoLog({
  5945. type: 'gettingCuratorId',
  5946. text: `${path}/${name}`
  5947. });
  5948. const curatorId = this.#cache.curator[`${path}/${name}`];
  5949. if (curatorId) {
  5950. logStatus.success();
  5951. return curatorId;
  5952. }
  5953. const {
  5954. result,
  5955. statusText,
  5956. status,
  5957. data
  5958. } = await tools_httpRequest({
  5959. url: `https://store.steampowered.com/${path}/${name}`,
  5960. method: 'GET',
  5961. headers: {
  5962. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5963. }
  5964. });
  5965. if (result === 'Success') {
  5966. if (data?.status === 200) {
  5967. const curatorId = data.responseText.match(/g_pagingData.*?"clanid":([\d]+)/)?.[1];
  5968. if (curatorId) {
  5969. this.#setCache('curator', `${path}/${name}`, curatorId);
  5970. logStatus.success();
  5971. return curatorId;
  5972. }
  5973. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5974. return false;
  5975. }
  5976. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5977. return false;
  5978. }
  5979. logStatus.error(`${result}:${statusText}(${status})`);
  5980. return false;
  5981. } catch (error) {
  5982. throwError(error, 'Steam.getCuratorID');
  5983. return false;
  5984. }
  5985. }
  5986. async #toggleCuratorLike(link, doTask = true) {
  5987. try {
  5988. const [ path, name ] = link.split('/');
  5989. if (!(path && name)) {
  5990. scripts_echoLog({
  5991. text: i18n('errorLink', link)
  5992. });
  5993. return false;
  5994. }
  5995. const curatorId = await this.getCuratorId(path, name);
  5996. if (curatorId) {
  5997. return await this.#toggleCurator(curatorId, doTask);
  5998. }
  5999. return false;
  6000. } catch (error) {
  6001. throwError(error, 'Steam.toggleCuratorLike');
  6002. return false;
  6003. }
  6004. }
  6005. async #getAnnouncementParams(appId, viewId) {
  6006. try {
  6007. const logStatus = scripts_echoLog({
  6008. type: 'gettingAnnouncementParams',
  6009. text: appId,
  6010. id: viewId
  6011. });
  6012. const {
  6013. result,
  6014. statusText,
  6015. status,
  6016. data
  6017. } = await tools_httpRequest({
  6018. 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`,
  6019. method: 'GET',
  6020. responseType: 'json',
  6021. headers: {
  6022. Host: 'store.steampowered.com',
  6023. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  6024. }
  6025. });
  6026. if (result === 'Success') {
  6027. if (data?.status === 200 && data?.response?.success === 1) {
  6028. const {
  6029. clanid,
  6030. gid
  6031. } = data.response.event?.announcement_body || {};
  6032. if (clanid) {
  6033. logStatus.success();
  6034. return {
  6035. clanId: clanid,
  6036. gid: gid
  6037. };
  6038. }
  6039. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6040. return {};
  6041. }
  6042. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6043. return {};
  6044. }
  6045. logStatus.error(`${result}:${statusText}(${status})`);
  6046. return {};
  6047. } catch (error) {
  6048. throwError(error, 'Steam.likeAnnouncement');
  6049. return {};
  6050. }
  6051. }
  6052. async #likeAnnouncement(id) {
  6053. try {
  6054. const [ appId, viewId ] = id.split('/');
  6055. if (!(appId && viewId)) {
  6056. scripts_echoLog({}).error(`${i18n('missParams')}(id)`);
  6057. return false;
  6058. }
  6059. const {
  6060. clanId,
  6061. gid
  6062. } = await this.#getAnnouncementParams(appId, viewId);
  6063. if (!clanId) {
  6064. return false;
  6065. }
  6066. const logStatus = scripts_echoLog({
  6067. type: 'likingAnnouncement',
  6068. text: appId,
  6069. id: viewId
  6070. });
  6071. const {
  6072. result,
  6073. statusText,
  6074. status,
  6075. data
  6076. } = await tools_httpRequest({
  6077. url: `https://store.steampowered.com/updated/ajaxrateupdate/${gid || viewId}`,
  6078. method: 'POST',
  6079. headers: {
  6080. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6081. Host: 'store.steampowered.com',
  6082. Origin: 'https://store.steampowered.com',
  6083. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  6084. },
  6085. data: $.param({
  6086. sessionid: this.#auth.storeSessionID,
  6087. voteup: 1,
  6088. clanid: clanId,
  6089. ajax: 1
  6090. }),
  6091. dataType: 'json'
  6092. });
  6093. if (result === 'Success') {
  6094. if (data?.status === 200 && data.response.success === 1) {
  6095. logStatus.success();
  6096. return true;
  6097. }
  6098. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6099. return false;
  6100. }
  6101. logStatus.error(`${result}:${statusText}(${status})`);
  6102. return false;
  6103. } catch (error) {
  6104. throwError(error, 'Steam.likeAnnouncement');
  6105. return false;
  6106. }
  6107. }
  6108. async #appid2subid(id) {
  6109. try {
  6110. const logStatus = scripts_echoLog({
  6111. type: 'gettingSubid',
  6112. text: id
  6113. });
  6114. const {
  6115. result,
  6116. statusText,
  6117. status,
  6118. data
  6119. } = await tools_httpRequest({
  6120. url: `https://store.steampowered.com/app/${id}`,
  6121. method: 'GET',
  6122. headers: {
  6123. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  6124. }
  6125. });
  6126. if (result === 'Success') {
  6127. if (data?.status === 200) {
  6128. if (data.responseText.includes('ds_owned_flag ds_flag') || data.responseText.includes('class="already_in_library"')) {
  6129. logStatus.success(i18n('owned'));
  6130. return false;
  6131. }
  6132. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6133. logStatus.warning(i18n('changeAreaNotice'));
  6134. const result = await this.#changeArea();
  6135. if (!result || result === 'CN' || result === 'skip') {
  6136. return false;
  6137. }
  6138. return await this.#appid2subid(id);
  6139. }
  6140. let subid = data.responseText.match(/name="subid" value="([\d]+?)"/)?.[1];
  6141. if (subid) {
  6142. logStatus.success();
  6143. return subid;
  6144. }
  6145. subid = data.responseText.match(/AddFreeLicense\(\s*(\d+)/)?.[1];
  6146. if (subid) {
  6147. logStatus.success();
  6148. return subid;
  6149. }
  6150. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6151. return false;
  6152. }
  6153. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6154. return false;
  6155. }
  6156. logStatus.error(`${result}:${statusText}(${status})`);
  6157. return false;
  6158. } catch (error) {
  6159. throwError(error, 'Steam.appid2subid');
  6160. return false;
  6161. }
  6162. }
  6163. async #getLicenses() {
  6164. try {
  6165. const logStatus = scripts_echoLog({
  6166. text: i18n('gettingLicenses')
  6167. });
  6168. const {
  6169. result,
  6170. statusText,
  6171. status,
  6172. data
  6173. } = await tools_httpRequest({
  6174. url: `https://store.steampowered.com/dynamicstore/userdata/?t=${new Date().getTime()}`,
  6175. method: 'GET',
  6176. responseType: 'json'
  6177. });
  6178. if (result === 'Success') {
  6179. if (data?.status === 200) {
  6180. logStatus.success();
  6181. return data.response?.rgOwnedPackages;
  6182. }
  6183. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6184. return false;
  6185. }
  6186. logStatus.error(`${result}:${statusText}(${status})`);
  6187. return false;
  6188. } catch (error) {
  6189. throwError(error, 'Steam.getLicenses');
  6190. return false;
  6191. }
  6192. }
  6193. async #addLicense(id) {
  6194. try {
  6195. if (this.#ASF) {
  6196. return await this.#ASF.addLicense(id);
  6197. }
  6198. const [ type, ids ] = id.split('-');
  6199. if (type === 'appid') {
  6200. const subid = await this.#appid2subid(ids);
  6201. if (!subid) {
  6202. return false;
  6203. }
  6204. const logStatus = scripts_echoLog({
  6205. type: 'addingFreeLicense',
  6206. text: ids
  6207. });
  6208. if (!await this.#addFreeLicense(subid, logStatus)) {
  6209. return false;
  6210. }
  6211. const {
  6212. result,
  6213. statusText,
  6214. status,
  6215. data
  6216. } = await tools_httpRequest({
  6217. url: `https://store.steampowered.com/app/${ids}`,
  6218. method: 'GET'
  6219. });
  6220. if (result === 'Success') {
  6221. if (data?.status === 200) {
  6222. if (data.responseText.includes('ds_owned_flag ds_flag') || data.responseText.includes('class="already_in_library"')) {
  6223. logStatus.success();
  6224. return true;
  6225. }
  6226. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6227. return false;
  6228. }
  6229. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6230. return false;
  6231. }
  6232. logStatus.error(`${result}:${statusText}(${status})`);
  6233. return false;
  6234. } else if (type === 'subid') {
  6235. if (this.#area === 'CN') {
  6236. scripts_echoLog({}).success(i18n('tryChangeAreaNotice'));
  6237. await this.#changeArea();
  6238. }
  6239. const logStatusArr = {};
  6240. const idsArr = ids.split(',');
  6241. for (const subid of idsArr) {
  6242. const logStatus = scripts_echoLog({
  6243. type: 'addingFreeLicenseSubid',
  6244. text: subid
  6245. });
  6246. if (!await this.#addFreeLicense(subid, logStatus)) {
  6247. return false;
  6248. }
  6249. logStatusArr[subid] = logStatus;
  6250. }
  6251. const licenses = await this.#getLicenses();
  6252. if (!licenses) {
  6253. return false;
  6254. }
  6255. for (const subid of idsArr) {
  6256. if (licenses.includes(parseInt(subid, 10))) {
  6257. logStatusArr[subid].success();
  6258. } else {
  6259. logStatusArr[subid].error();
  6260. }
  6261. }
  6262. return true;
  6263. }
  6264. return false;
  6265. } catch (error) {
  6266. throwError(error, 'Steam.addLicense');
  6267. return false;
  6268. }
  6269. }
  6270. async #addFreeLicense(id, logStatusPre) {
  6271. try {
  6272. const logStatus = logStatusPre || scripts_echoLog({
  6273. type: 'addingFreeLicenseSubid',
  6274. text: id
  6275. });
  6276. const {
  6277. result,
  6278. statusText,
  6279. status,
  6280. data
  6281. } = await tools_httpRequest({
  6282. url: `https://store.steampowered.com/freelicense/addfreelicense/${id}`,
  6283. method: 'POST',
  6284. headers: {
  6285. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6286. Host: 'store.steampowered.com',
  6287. Origin: 'https://store.steampowered.com',
  6288. Referer: 'https://store.steampowered.com/account/licenses/'
  6289. },
  6290. data: $.param({
  6291. ajax: true,
  6292. sessionid: this.#auth.storeSessionID
  6293. }),
  6294. dataType: 'json'
  6295. });
  6296. if (result === 'Success') {
  6297. if (data?.status === 200) {
  6298. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6299. logStatus.warning(i18n('changeAreaNotice'));
  6300. const result = await this.#changeArea();
  6301. if (!result || result === 'CN') {
  6302. return false;
  6303. }
  6304. return await this.#addFreeLicense(id);
  6305. }
  6306. logStatus.success();
  6307. return true;
  6308. }
  6309. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6310. return false;
  6311. }
  6312. logStatus.error(`${result}:${statusText}(${status})`);
  6313. return false;
  6314. } catch (error) {
  6315. throwError(error, 'Steam.addFreeLicense');
  6316. return false;
  6317. }
  6318. }
  6319. async #requestPlayTestAccess(id) {
  6320. try {
  6321. if (this.#ASF) {
  6322. return await this.#ASF.requestPlayTestAccess(id);
  6323. }
  6324. const logStatus = scripts_echoLog({
  6325. type: 'requestingPlayTestAccess',
  6326. text: id
  6327. });
  6328. const {
  6329. result,
  6330. statusText,
  6331. status,
  6332. data
  6333. } = await tools_httpRequest({
  6334. url: `https://store.steampowered.com/ajaxrequestplaytestaccess/${id}`,
  6335. method: 'POST',
  6336. headers: {
  6337. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6338. Host: 'store.steampowered.com',
  6339. Origin: 'https://store.steampowered.com',
  6340. Referer: `https://store.steampowered.com/app/${id}`
  6341. },
  6342. data: $.param({
  6343. sessionid: this.#auth.storeSessionID
  6344. }),
  6345. dataType: 'json'
  6346. });
  6347. if (result === 'Success') {
  6348. if (data?.status === 200 && data?.response?.success === 1) {
  6349. logStatus.success();
  6350. return true;
  6351. }
  6352. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6353. return false;
  6354. }
  6355. logStatus.error(`${result}:${statusText}(${status})`);
  6356. return false;
  6357. } catch (error) {
  6358. throwError(error, 'Steam.requestPlayTestAccess');
  6359. return false;
  6360. }
  6361. }
  6362. async toggle({
  6363. doTask = true,
  6364. groupLinks = [],
  6365. officialGroupLinks = [],
  6366. wishlistLinks = [],
  6367. followLinks = [],
  6368. forumLinks = [],
  6369. workshopLinks = [],
  6370. workshopVoteLinks = [],
  6371. curatorLinks = [],
  6372. curatorLikeLinks = [],
  6373. announcementLinks = [],
  6374. licenseLinks = [],
  6375. playtestLinks = []
  6376. }) {
  6377. try {
  6378. if ([ ...groupLinks, ...officialGroupLinks, ...forumLinks, ...workshopLinks, ...workshopVoteLinks ].length > 0 && !this.#communityInitialized) {
  6379. scripts_echoLog({
  6380. text: i18n('needInit')
  6381. });
  6382. return false;
  6383. }
  6384. if ([ ...wishlistLinks, ...followLinks, ...curatorLinks, ...curatorLikeLinks, ...announcementLinks, ...licenseLinks, ...playtestLinks ].length > 0 && !this.#storeInitialized) {
  6385. scripts_echoLog({
  6386. text: i18n('needInit')
  6387. });
  6388. return false;
  6389. }
  6390. const prom = [];
  6391. if (doTask && !globalOptions.doTask.steam.groups || !doTask && !globalOptions.undoTask.steam.groups) {
  6392. scripts_echoLog({
  6393. type: 'globalOptionsSkip',
  6394. text: 'steam.groups'
  6395. });
  6396. } else {
  6397. const realGroups = this.getRealParams('groups', groupLinks, doTask, link => link.match(/groups\/(.+)\/?/)?.[1]);
  6398. if (realGroups.length > 0) {
  6399. for (const group of realGroups) {
  6400. if (doTask) {
  6401. prom.push(this.#joinGroup(group));
  6402. } else {
  6403. prom.push(this.#leaveGroup(group));
  6404. }
  6405. await delay(1e3);
  6406. }
  6407. }
  6408. }
  6409. if (doTask && !globalOptions.doTask.steam.officialGroups || !doTask && !globalOptions.undoTask.steam.officialGroups) {
  6410. scripts_echoLog({
  6411. type: 'globalOptionsSkip',
  6412. text: 'steam.officialGroups'
  6413. });
  6414. } else {
  6415. const realOfficialGroups = this.getRealParams('officialGroups', officialGroupLinks, doTask, link => link.match(/games\/(.+)\/?/)?.[1]);
  6416. if (realOfficialGroups.length > 0) {
  6417. for (const officialGroup of realOfficialGroups) {
  6418. if (doTask) {
  6419. prom.push(this.#joinOfficialGroup(officialGroup));
  6420. } else {
  6421. prom.push(this.#leaveOfficialGroup(officialGroup));
  6422. }
  6423. await delay(1e3);
  6424. }
  6425. }
  6426. }
  6427. if (doTask && !globalOptions.doTask.steam.wishlists || !doTask && !globalOptions.undoTask.steam.wishlists) {
  6428. scripts_echoLog({
  6429. type: 'globalOptionsSkip',
  6430. text: 'steam.wishlists'
  6431. });
  6432. } else {
  6433. const realWishlists = this.getRealParams('wishlists', wishlistLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6434. if (realWishlists.length > 0) {
  6435. for (const game of realWishlists) {
  6436. if (doTask) {
  6437. prom.push(this.#addToWishlist(game));
  6438. } else {
  6439. prom.push(this.#removeFromWishlist(game));
  6440. }
  6441. await delay(1e3);
  6442. }
  6443. }
  6444. }
  6445. if (doTask && !globalOptions.doTask.steam.follows || !doTask && !globalOptions.undoTask.steam.follows) {
  6446. scripts_echoLog({
  6447. type: 'globalOptionsSkip',
  6448. text: 'steam.follows'
  6449. });
  6450. } else {
  6451. const realFollows = this.getRealParams('follows', followLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6452. if (realFollows.length > 0) {
  6453. for (const game of realFollows) {
  6454. prom.push(this.#toggleFollowGame(game, doTask));
  6455. await delay(1e3);
  6456. }
  6457. }
  6458. }
  6459. if (doTask && !globalOptions.doTask.steam.forums || !doTask && !globalOptions.undoTask.steam.forums) {
  6460. scripts_echoLog({
  6461. type: 'globalOptionsSkip',
  6462. text: 'steam.forums'
  6463. });
  6464. } else {
  6465. const realForums = this.getRealParams('forums', forumLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6466. if (realForums.length > 0) {
  6467. for (const forum of realForums) {
  6468. prom.push(this.#toggleForum(forum, doTask));
  6469. await delay(1e3);
  6470. }
  6471. }
  6472. }
  6473. if (doTask && !globalOptions.doTask.steam.workshops || !doTask && !globalOptions.undoTask.steam.workshops) {
  6474. scripts_echoLog({
  6475. type: 'globalOptionsSkip',
  6476. text: 'steam.workshops'
  6477. });
  6478. } else {
  6479. const realWorkshops = this.getRealParams('workshops', workshopLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6480. if (realWorkshops.length > 0) {
  6481. for (const workshop of realWorkshops) {
  6482. prom.push(this.#toggleFavoriteWorkshop(workshop, doTask));
  6483. await delay(1e3);
  6484. }
  6485. }
  6486. }
  6487. if (doTask && !globalOptions.doTask.steam.workshopVotes) {
  6488. scripts_echoLog({
  6489. type: 'globalOptionsSkip',
  6490. text: 'steam.workshopVotes'
  6491. });
  6492. } else {
  6493. const realworkshopVotes = this.getRealParams('workshopVotes', workshopVoteLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6494. if (doTask && realworkshopVotes.length > 0) {
  6495. for (const workshop of realworkshopVotes) {
  6496. prom.push(this.#voteUpWorkshop(workshop));
  6497. await delay(1e3);
  6498. }
  6499. }
  6500. }
  6501. if (doTask && !globalOptions.doTask.steam.curators || !doTask && !globalOptions.undoTask.steam.curators) {
  6502. scripts_echoLog({
  6503. type: 'globalOptionsSkip',
  6504. text: 'steam.curators'
  6505. });
  6506. } else {
  6507. const realCurators = this.getRealParams('curators', curatorLinks, doTask, link => link.match(/curator\/([\d]+)/)?.[1]);
  6508. const realCuratorLikes = this.getRealParams('curatorLikes', curatorLikeLinks, doTask, link => link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3).join('/'));
  6509. if (realCurators.length > 0) {
  6510. for (const curator of realCurators) {
  6511. prom.push(this.#toggleCurator(curator, doTask));
  6512. await delay(1e3);
  6513. }
  6514. }
  6515. if (realCuratorLikes.length > 0) {
  6516. for (const curatorLike of realCuratorLikes) {
  6517. prom.push(this.#toggleCuratorLike(curatorLike, doTask));
  6518. await delay(1e3);
  6519. }
  6520. }
  6521. }
  6522. if (doTask && !globalOptions.doTask.steam.announcements) {
  6523. scripts_echoLog({
  6524. type: 'globalOptionsSkip',
  6525. text: 'steam.announcements'
  6526. });
  6527. } else {
  6528. const realAnnouncements = this.getRealParams('announcements', announcementLinks, doTask, link => {
  6529. if (link.includes('store.steampowered.com')) {
  6530. return link.match(/store\.steampowered\.com\/news\/app\/([\d]+)\/view\/([\d]+)/)?.slice(1, 3).join('/');
  6531. }
  6532. return link.match(/steamcommunity\.com\/games\/([\d]+)\/announcements\/detail\/([\d]+)/)?.slice(1, 3).join('/');
  6533. });
  6534. if (doTask && realAnnouncements.length > 0) {
  6535. for (const id of realAnnouncements) {
  6536. prom.push(this.#likeAnnouncement(id));
  6537. await delay(1e3);
  6538. }
  6539. }
  6540. }
  6541. if (doTask && !globalOptions.doTask.steam.licenses) {
  6542. scripts_echoLog({
  6543. type: 'globalOptionsSkip',
  6544. text: 'steam.licenses'
  6545. });
  6546. } else if (doTask && globalOptions.doTask.steam.licenses && licenseLinks.length > 0) {
  6547. for (const id of licenseLinks) {
  6548. prom.push(this.#addLicense(id));
  6549. await delay(1e3);
  6550. }
  6551. }
  6552. if (doTask && !globalOptions.doTask.steam.playtests) {
  6553. scripts_echoLog({
  6554. type: 'globalOptionsSkip',
  6555. text: 'steam.playtests'
  6556. });
  6557. } else {
  6558. const realPlaytests = this.getRealParams('playtests', playtestLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6559. if (doTask && globalOptions.doTask.steam.playtests && realPlaytests.length > 0) {
  6560. for (const id of realPlaytests) {
  6561. prom.push(this.#requestPlayTestAccess(id));
  6562. await delay(1e3);
  6563. }
  6564. }
  6565. }
  6566. return Promise.all(prom).then(async () => {
  6567. if (this.#area !== 'CN') {
  6568. scripts_echoLog({}).warning(i18n('steamFinishNotice'));
  6569. await this.#changeArea('CN');
  6570. }
  6571. return true;
  6572. });
  6573. } catch (error) {
  6574. throwError(error, 'Steam.toggle');
  6575. return false;
  6576. }
  6577. }
  6578. #setCache(type, name, id) {
  6579. try {
  6580. this.#cache[type][name] = id;
  6581. GM_setValue('steamCache', this.#cache);
  6582. } catch (error) {
  6583. throwError(error, 'Steam.setCache');
  6584. }
  6585. }
  6586. }
  6587. const social_Steam = Steam;
  6588. class Website {
  6589. undoneTasks;
  6590. socialTasks;
  6591. giveawayId;
  6592. socialInitialized = {
  6593. discord: false,
  6594. instagram: false,
  6595. reddit: false,
  6596. twitch: false,
  6597. twitter: false,
  6598. vk: false,
  6599. youtube: false,
  6600. steamStore: false,
  6601. steamCommunity: false
  6602. };
  6603. initialized = false;
  6604. social = {};
  6605. async #bind(name, init) {
  6606. try {
  6607. return {
  6608. name: name,
  6609. result: await init
  6610. };
  6611. } catch (error) {
  6612. throwError(error, 'Website.bind');
  6613. return {
  6614. name: name,
  6615. result: false
  6616. };
  6617. }
  6618. }
  6619. async initSocial(action) {
  6620. try {
  6621. const pro = [];
  6622. const tasks = action === 'do' ? this.undoneTasks : this.socialTasks;
  6623. if (tasks.discord) {
  6624. const hasDiscord = Object.values(tasks.discord).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6625. if (hasDiscord && (!this.socialInitialized.discord || !this.social.discord)) {
  6626. this.social.discord = new social_Discord();
  6627. pro.push(this.#bind('discord', this.social.discord.init(action)));
  6628. }
  6629. }
  6630. if (tasks.instagram) {
  6631. const hasInstagram = Object.values(tasks.instagram).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6632. if (hasInstagram && (!this.socialInitialized.instagram || !this.social.instagram)) {
  6633. this.social.instagram = new social_Instagram();
  6634. pro.push(this.#bind('instagram', this.social.instagram.init()));
  6635. }
  6636. }
  6637. if (tasks.reddit) {
  6638. const hasReddit = Object.values(tasks.reddit).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6639. if (hasReddit && (!this.socialInitialized.reddit || !this.social.reddit)) {
  6640. this.social.reddit = new social_Reddit();
  6641. pro.push(this.#bind('reddit', this.social.reddit.init()));
  6642. }
  6643. }
  6644. if (tasks.twitch) {
  6645. const hasTwitch = Object.values(tasks.twitch).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6646. if (hasTwitch && (!this.socialInitialized.twitch || !this.social.twitch)) {
  6647. this.social.twitch = new social_Twitch();
  6648. pro.push(this.#bind('twitch', this.social.twitch.init()));
  6649. }
  6650. }
  6651. if (tasks.twitter) {
  6652. const hasTwitter = Object.values(tasks.twitter).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6653. if (hasTwitter && (!this.socialInitialized.twitter || !this.social.twitter)) {
  6654. this.social.twitter = new social_Twitter();
  6655. pro.push(this.#bind('twitter', this.social.twitter.init()));
  6656. }
  6657. }
  6658. if (tasks.vk) {
  6659. const hasVk = Object.values(tasks.vk).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6660. if (hasVk && (!this.socialInitialized.vk || !this.social.vk)) {
  6661. this.social.vk = new social_Vk();
  6662. pro.push(this.#bind('vk', this.social.vk.init()));
  6663. }
  6664. }
  6665. if (tasks.youtube) {
  6666. const hasYoutube = Object.values(tasks.youtube).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6667. if (hasYoutube && (!this.socialInitialized.youtube || !this.social.youtube)) {
  6668. this.social.youtube = new Youtube();
  6669. pro.push(this.#bind('youtube', this.social.youtube.init()));
  6670. }
  6671. }
  6672. if (tasks.steam) {
  6673. const steamLength = Object.values(tasks.steam).reduce((total, arr) => [ ...total, ...arr ]).length;
  6674. if (steamLength > 0) {
  6675. if (!this.social.steam) {
  6676. this.social.steam = new social_Steam();
  6677. }
  6678. 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);
  6679. if (steamLength - steamCommunityLength > 0 && !this.socialInitialized.steamStore) {
  6680. pro.push(this.#bind('steamStore', this.social.steam.init('store')));
  6681. }
  6682. if (steamCommunityLength > 0 && !this.socialInitialized.steamCommunity) {
  6683. pro.push(this.#bind('steamCommunity', this.social.steam.init('community')));
  6684. }
  6685. }
  6686. }
  6687. if (tasks.links && tasks.links.length > 0) {
  6688. this.social.visitLink = visitLink;
  6689. }
  6690. return await Promise.all(pro).then(result => {
  6691. let checked = true;
  6692. for (const data of result) {
  6693. if (data.result) {
  6694. this.socialInitialized[data.name] = data.result;
  6695. } else {
  6696. checked = false;
  6697. }
  6698. }
  6699. return checked;
  6700. });
  6701. } catch (error) {
  6702. throwError(error, 'Website.initSocial');
  6703. return false;
  6704. }
  6705. }
  6706. uniqueTasks(allTasks) {
  6707. try {
  6708. const result = {};
  6709. for (const [ social, types ] of Object.entries(allTasks)) {
  6710. result[social] = {};
  6711. for (const [ type, tasks ] of Object.entries(types)) {
  6712. result[social][type] = unique(tasks);
  6713. }
  6714. }
  6715. return result;
  6716. } catch (error) {
  6717. throwError(error, 'Website.uniqueTasks');
  6718. return allTasks;
  6719. }
  6720. }
  6721. async toggleTask(action) {
  6722. try {
  6723. if (!this.initialized && !this.init()) {
  6724. return false;
  6725. }
  6726. if (!await this.classifyTask(action)) {
  6727. return false;
  6728. }
  6729. if (!await this.initSocial(action)) {
  6730. return false;
  6731. }
  6732. const pro = [];
  6733. const doTask = action === 'do';
  6734. const tasks = doTask ? this.undoneTasks : this.socialTasks;
  6735. if (this.socialInitialized.discord !== 'skip' && this.social.discord) {
  6736. pro.push(this.social.discord.toggle({
  6737. doTask: doTask,
  6738. ...tasks.discord
  6739. }));
  6740. }
  6741. if (this.social.instagram) {
  6742. pro.push(this.social.instagram.toggle({
  6743. doTask: doTask,
  6744. ...tasks.instagram
  6745. }));
  6746. }
  6747. if (this.social.reddit) {
  6748. pro.push(this.social.reddit.toggle({
  6749. doTask: doTask,
  6750. ...tasks.reddit
  6751. }));
  6752. }
  6753. if (this.social.twitch) {
  6754. pro.push(this.social.twitch.toggle({
  6755. doTask: doTask,
  6756. ...tasks.twitch
  6757. }));
  6758. }
  6759. if (this.social.twitter) {
  6760. pro.push(this.social.twitter.toggle({
  6761. doTask: doTask,
  6762. ...tasks.twitter
  6763. }));
  6764. }
  6765. if (this.social.vk) {
  6766. pro.push(this.social.vk.toggle({
  6767. doTask: doTask,
  6768. ...tasks.vk
  6769. }));
  6770. }
  6771. if (this.social.youtube) {
  6772. pro.push(this.social.youtube.toggle({
  6773. doTask: doTask,
  6774. ...tasks.youtube
  6775. }));
  6776. }
  6777. if (this.social.steam) {
  6778. pro.push(this.social.steam.toggle({
  6779. doTask: doTask,
  6780. ...tasks.steam
  6781. }));
  6782. }
  6783. if (this.social.visitLink && tasks.links && doTask) {
  6784. for (const link of tasks.links) {
  6785. pro.push(this.social.visitLink(link));
  6786. }
  6787. }
  6788. if (doTask && tasks.extra && this.extraDoTask) {
  6789. const hasExtra = Object.values(tasks.extra).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6790. if (hasExtra) {
  6791. pro.push(this.extraDoTask(tasks.extra));
  6792. }
  6793. }
  6794. await Promise.all(pro);
  6795. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6796. return true;
  6797. } catch (error) {
  6798. throwError(error, 'Website.toggleTask');
  6799. return false;
  6800. }
  6801. }
  6802. async doTask() {
  6803. try {
  6804. return await this.toggleTask('do');
  6805. } catch (error) {
  6806. throwError(error, 'Website.doTask');
  6807. return false;
  6808. }
  6809. }
  6810. async undoTask() {
  6811. try {
  6812. return await this.toggleTask('undo');
  6813. } catch (error) {
  6814. throwError(error, 'Website.undoTask');
  6815. return false;
  6816. }
  6817. }
  6818. }
  6819. const website_Website = Website;
  6820. const defaultTasksTemplate = {
  6821. steam: {
  6822. groupLinks: [],
  6823. wishlistLinks: [],
  6824. curatorLinks: [],
  6825. followLinks: []
  6826. },
  6827. vk: {
  6828. nameLinks: []
  6829. }
  6830. };
  6831. const defaultTasks = JSON.stringify(defaultTasksTemplate);
  6832. class FreeAnyWhere extends website_Website {
  6833. name = 'FreeAnyWhere';
  6834. tasks = [];
  6835. socialTasks = JSON.parse(defaultTasks);
  6836. undoneTasks = JSON.parse(defaultTasks);
  6837. buttons = [ 'doTask', 'undoTask', 'verifyTask', 'getKey' ];
  6838. static test() {
  6839. return window.location.host === 'freeanywhere.net';
  6840. }
  6841. async init() {
  6842. try {
  6843. const logStatus = scripts_echoLog({
  6844. text: i18n('initing')
  6845. });
  6846. if ($('a[href="#/login"]').length > 0) {
  6847. window.open('/#/login', '_self');
  6848. logStatus.warning(i18n('needLogin'));
  6849. return false;
  6850. }
  6851. if (window.location.href.includes('/login')) {
  6852. logStatus.warning(i18n('needLogin'));
  6853. return false;
  6854. }
  6855. if (!/^https?:\/\/freeanywhere\.net\/#\/giveaway\/[\d]+/.test(window.location.href)) {
  6856. const id = window.location.href.match(/https?:\/\/freeanywhere\.net\/.*?#\/giveaway\/([\d]+)/)?.[1];
  6857. if (!id) {
  6858. logStatus.error(i18n('getFailed', 'Id'));
  6859. return false;
  6860. }
  6861. window.location.href = `https://freeanywhere.net/#/giveaway/${id}`;
  6862. }
  6863. if (!this.#getGiveawayId()) {
  6864. return false;
  6865. }
  6866. if (!await this.#checkLeftKey()) {
  6867. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  6868. }
  6869. this.initialized = true;
  6870. logStatus.success();
  6871. return true;
  6872. } catch (error) {
  6873. throwError(error, 'Freeanywhere.init');
  6874. return false;
  6875. }
  6876. }
  6877. async classifyTask(action) {
  6878. try {
  6879. const logStatus = scripts_echoLog({
  6880. text: i18n('getTasksInfo')
  6881. });
  6882. if (action === 'undo') {
  6883. this.socialTasks = GM_getValue(`fawTasks-${this.giveawayId}`)?.tasks || JSON.parse(defaultTasks);
  6884. }
  6885. const {
  6886. result,
  6887. statusText,
  6888. status,
  6889. data
  6890. } = await tools_httpRequest({
  6891. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/?format=json`,
  6892. method: 'GET',
  6893. headers: {
  6894. authorization: `Token ${window.localStorage.getItem('token')}`,
  6895. 'x-csrftoken': external_Cookies_default().get('csrftoken')
  6896. },
  6897. responseType: 'json'
  6898. });
  6899. if (result === 'Success') {
  6900. const tasks = data?.response?.challenges;
  6901. if (tasks) {
  6902. if (action === 'verify') {
  6903. this.tasks = [];
  6904. }
  6905. for (const task of tasks) {
  6906. const type = task.challenge;
  6907. const social = task.challenge_provider;
  6908. const taskInfo = {
  6909. id: task.id,
  6910. title: task.title
  6911. };
  6912. if (action === 'verify' && !task.is_success) {
  6913. this.tasks.push(taskInfo);
  6914. continue;
  6915. }
  6916. switch (social) {
  6917. case 'steam':
  6918. taskInfo.social = 'steam';
  6919. switch (type) {
  6920. case 'WL':
  6921. if (action === 'undo') {
  6922. this.socialTasks.steam.wishlistLinks.push(task.link);
  6923. }
  6924. if (action === 'do' && !task.is_success) {
  6925. this.undoneTasks.steam.wishlistLinks.push(task.link);
  6926. }
  6927. break;
  6928.  
  6929. case 'JTG':
  6930. if (action === 'undo') {
  6931. this.socialTasks.steam.groupLinks.push(task.link);
  6932. }
  6933. if (action === 'do' && !task.is_success) {
  6934. this.undoneTasks.steam.groupLinks.push(task.link);
  6935. }
  6936. break;
  6937.  
  6938. case 'STC':
  6939. if (action === 'undo') {
  6940. this.socialTasks.steam.curatorLinks.push(task.link);
  6941. }
  6942. if (action === 'do' && !task.is_success) {
  6943. this.undoneTasks.steam.curatorLinks.push(task.link);
  6944. }
  6945. break;
  6946.  
  6947. case 'GF':
  6948. if (action === 'undo') {
  6949. this.socialTasks.steam.followLinks.push(task.link);
  6950. }
  6951. if (action === 'do' && !task.is_success) {
  6952. this.undoneTasks.steam.followLinks.push(task.link);
  6953. }
  6954. break;
  6955. }
  6956. break;
  6957.  
  6958. case 'vk-oauth2':
  6959. if (action === 'undo') {
  6960. this.socialTasks.vk.nameLinks.push(task.link);
  6961. }
  6962. if (action === 'do' && !task.is_success) {
  6963. this.undoneTasks.vk.nameLinks.push(task.link);
  6964. }
  6965. break;
  6966.  
  6967. case 'website':
  6968. break;
  6969.  
  6970. default:
  6971. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${social}`);
  6972. break;
  6973. }
  6974. }
  6975. logStatus.success();
  6976. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  6977. this.socialTasks = this.uniqueTasks(this.socialTasks);
  6978. if (window.DEBUG) {
  6979. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  6980. }
  6981. GM_setValue(`fawTasks-${this.giveawayId}`, {
  6982. tasks: this.socialTasks,
  6983. time: new Date().getTime()
  6984. });
  6985. return true;
  6986. }
  6987. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6988. return false;
  6989. }
  6990. logStatus.error(`${result}:${statusText}(${status})`);
  6991. return false;
  6992. } catch (error) {
  6993. throwError(error, 'Freeanywhere.classifyTask');
  6994. return false;
  6995. }
  6996. }
  6997. async verifyTask() {
  6998. try {
  6999. if (!this.initialized && !this.init()) {
  7000. return false;
  7001. }
  7002. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  7003. return false;
  7004. }
  7005. const pro = [];
  7006. for (const task of this.tasks) {
  7007. pro.push(this.#verify(task));
  7008. await delay(1e3);
  7009. }
  7010. await Promise.all(pro);
  7011. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7012. return !!await this.getKey(true);
  7013. } catch (error) {
  7014. throwError(error, 'Freeanywhere.verifyTask');
  7015. return false;
  7016. }
  7017. }
  7018. async getKey(initialized) {
  7019. try {
  7020. if (!initialized && !this.initialized && !this.init()) {
  7021. return false;
  7022. }
  7023. const logStatus = scripts_echoLog({
  7024. text: i18n('gettingKey')
  7025. });
  7026. const {
  7027. result,
  7028. statusText,
  7029. status,
  7030. data
  7031. } = await tools_httpRequest({
  7032. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/reward/?format=json`,
  7033. method: 'GET',
  7034. dataType: 'json',
  7035. headers: {
  7036. authorization: `Token ${window.localStorage.getItem('token')}`
  7037. }
  7038. });
  7039. if (result === 'Success') {
  7040. if (data?.response?.reward) {
  7041. logStatus.success();
  7042. scripts_echoLog({}).success(data.response.reward);
  7043. return data.response.reward;
  7044. }
  7045. if (data?.response?.completed === false) {
  7046. logStatus.error(i18n('tasksNotCompleted'));
  7047. return false;
  7048. }
  7049. if (data?.response?.completed === true) {
  7050. await this.#checkLeftKey();
  7051. }
  7052. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7053. return false;
  7054. }
  7055. logStatus.error(`${result}:${statusText}(${status})`);
  7056. return false;
  7057. } catch (error) {
  7058. throwError(error, 'FreeAnyWhere.getGiveawayId');
  7059. return false;
  7060. }
  7061. }
  7062. #getGiveawayId() {
  7063. try {
  7064. const giveawayId = window.location.href.match(/\/giveaway\/([\d]+)/)?.[1];
  7065. if (giveawayId) {
  7066. this.giveawayId = giveawayId;
  7067. return true;
  7068. }
  7069. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7070. return false;
  7071. } catch (error) {
  7072. throwError(error, 'FreeAnyWhere.getGiveawayId');
  7073. return false;
  7074. }
  7075. }
  7076. async #verify(task) {
  7077. try {
  7078. const logStatus = scripts_echoLog({
  7079. html: `<li>${i18n('verifyingTask')}${task.title.trim()}...<font></font></li>`
  7080. });
  7081. const {
  7082. result,
  7083. statusText,
  7084. status,
  7085. data
  7086. } = await tools_httpRequest({
  7087. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/challenge-status/${task.id}/?format=json`,
  7088. method: 'GET',
  7089. dataType: 'json',
  7090. headers: {
  7091. authorization: `Token ${window.localStorage.getItem('token')}`,
  7092. 'x-csrftoken': external_Cookies_default().get('csrftoken')
  7093. }
  7094. });
  7095. if (result === 'Success') {
  7096. if (data?.response?.status) {
  7097. logStatus.success();
  7098. return true;
  7099. }
  7100. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7101. return false;
  7102. }
  7103. logStatus.error(`${result}:${statusText}(${status})`);
  7104. return false;
  7105. } catch (error) {
  7106. throwError(error, 'Freeanywhere.verify');
  7107. return false;
  7108. }
  7109. }
  7110. async #checkLeftKey() {
  7111. try {
  7112. if (!globalOptions.other.checkLeftKey) {
  7113. return true;
  7114. }
  7115. const {
  7116. data
  7117. } = await tools_httpRequest({
  7118. url: 'https://freeanywhere.net/api/v1/widget/?format=json',
  7119. method: 'GET',
  7120. dataType: 'json',
  7121. headers: {
  7122. authorization: `Token ${window.localStorage.getItem('token')}`
  7123. }
  7124. });
  7125. if (data?.response?.giveaways.find(giveaway => `${giveaway?.id}` === this.giveawayId)) {
  7126. return true;
  7127. }
  7128. await external_Swal_default().fire({
  7129. icon: 'warning',
  7130. title: i18n('notice'),
  7131. text: i18n('noKeysLeft'),
  7132. confirmButtonText: i18n('confirm'),
  7133. cancelButtonText: i18n('cancel'),
  7134. showCancelButton: true
  7135. }).then(({
  7136. value
  7137. }) => {
  7138. if (value) {
  7139. window.close();
  7140. }
  7141. });
  7142. return true;
  7143. } catch (error) {
  7144. throwError(error, 'Giveawaysu.checkLeftKey');
  7145. return false;
  7146. }
  7147. }
  7148. }
  7149. const Freeanywhere = FreeAnyWhere;
  7150. const Giveawaysu_defaultTasks = {
  7151. steam: {
  7152. groupLinks: [],
  7153. wishlistLinks: [],
  7154. curatorLinks: [],
  7155. curatorLikeLinks: [],
  7156. followLinks: [],
  7157. forumLinks: [],
  7158. announcementLinks: [],
  7159. workshopVoteLinks: [],
  7160. playtestLinks: []
  7161. },
  7162. discord: {
  7163. serverLinks: []
  7164. },
  7165. instagram: {
  7166. userLinks: []
  7167. },
  7168. vk: {
  7169. nameLinks: []
  7170. },
  7171. twitch: {
  7172. channelLinks: []
  7173. },
  7174. reddit: {
  7175. redditLinks: []
  7176. },
  7177. youtube: {
  7178. channelLinks: [],
  7179. likeLinks: []
  7180. },
  7181. twitter: {
  7182. userLinks: [],
  7183. retweetLinks: []
  7184. }
  7185. };
  7186. class GiveawaySu extends website_Website {
  7187. name = 'GiveawaySu';
  7188. socialTasks = Giveawaysu_defaultTasks;
  7189. undoneTasks = Giveawaysu_defaultTasks;
  7190. buttons = [ 'doTask', 'undoTask' ];
  7191. static test() {
  7192. return /^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(window.location.href);
  7193. }
  7194. async after() {
  7195. try {
  7196. if (!this.#checkLogin()) {
  7197. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7198. }
  7199. if (!await this.#checkLeftKey()) {
  7200. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7201. }
  7202. scripts_echoLog({}).warning(i18n('gsNotice'));
  7203. } catch (error) {
  7204. throwError(error, 'Giveawaysu.after');
  7205. }
  7206. }
  7207. init() {
  7208. try {
  7209. const logStatus = scripts_echoLog({
  7210. text: i18n('initing')
  7211. });
  7212. if ($('a.steam-login').length > 0) {
  7213. window.open('/steam/redirect', '_self');
  7214. logStatus.warning(i18n('needLogin'));
  7215. return false;
  7216. }
  7217. if (!this.#getGiveawayId()) {
  7218. return false;
  7219. }
  7220. this.initialized = true;
  7221. logStatus.success();
  7222. return true;
  7223. } catch (error) {
  7224. throwError(error, 'Giveawaysu.init');
  7225. return false;
  7226. }
  7227. }
  7228. async classifyTask(action) {
  7229. try {
  7230. const logStatus = scripts_echoLog({
  7231. text: i18n('getTasksInfo')
  7232. });
  7233. if (action === 'undo') {
  7234. this.socialTasks = GM_getValue(`gasTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  7235. return true;
  7236. }
  7237. const pro = [];
  7238. const tasks = $('#actions tr');
  7239. if ($('div.bind-discord').is(':visible')) {
  7240. $('div.bind-discord a')[0].click();
  7241. }
  7242. if ($('div.bind-twitch').is(':visible')) {
  7243. $('div.bind-twitch a')[0].click();
  7244. }
  7245. for (const task of tasks) {
  7246. pro.push(new Promise(resolve => {
  7247. const td = $(task).find('td:not(".hidden")');
  7248. const colorfulTask = td.eq(1).find('a:not([data-trigger="link"])');
  7249. const colorlessTask = td.eq(2).find('a:not([data-trigger="link"])');
  7250. const taskDes = colorfulTask.length > 0 ? colorfulTask : colorlessTask;
  7251. const taskIcon = td.eq(0).find('i').attr('class') || '';
  7252. const taskName = taskDes.text().trim();
  7253. if (taskIcon.includes('ban') || /disable adblock/gi.test(taskName)) {
  7254. return resolve(true);
  7255. }
  7256. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  7257. if (!taskLink) {
  7258. return resolve(false);
  7259. }
  7260. if (taskIcon.includes('steam') && /join/gi.test(taskName)) {
  7261. this.undoneTasks.steam.groupLinks.push(taskLink);
  7262. } else if (/like.*announcement/gi.test(taskName)) {
  7263. this.undoneTasks.steam.announcementLinks.push(taskLink);
  7264. } else if (/(follow|subscribe).*curator/gim.test(taskName) && /^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  7265. this.undoneTasks.steam.curatorLinks.push(taskLink);
  7266. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  7267. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  7268. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  7269. this.undoneTasks.steam.forumLinks.push(taskLink);
  7270. } else if (taskIcon.includes('thumbs-up') && /^https?:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=[\d]+/.test(taskLink)) {
  7271. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7272. } else if (taskIcon.includes('plus') && /request.*playtest/gim.test(taskName)) {
  7273. this.undoneTasks.steam.playtestLinks.push(taskLink);
  7274. } else if (taskIcon.includes('discord') || /join.*discord/gim.test(taskName)) {
  7275. this.undoneTasks.discord.serverLinks.push(taskLink);
  7276. } else if (taskIcon.includes('instagram') || /follow.*instagram/gim.test(taskName)) {
  7277. this.undoneTasks.instagram.userLinks.push(taskLink);
  7278. } else if (taskIcon.includes('twitch') || /follow.*twitch.*channel/gim.test(taskName)) {
  7279. this.undoneTasks.twitch.channelLinks.push(taskLink);
  7280. } else if (taskIcon.includes('reddit') || /subscribe.*subreddit/gim.test(taskName) || /follow.*reddit/gim.test(taskName)) {
  7281. this.undoneTasks.reddit.redditLinks.push(taskLink);
  7282. } else if (/watch.*art/gim.test(taskName)) {
  7283. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7284. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  7285. this.undoneTasks.youtube.channelLinks.push(taskLink);
  7286. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  7287. this.undoneTasks.youtube.likeLinks.push(taskLink);
  7288. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  7289. this.undoneTasks.vk.nameLinks.push(taskLink);
  7290. } else {
  7291. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  7292. if (/wishlist.*game|add.*wishlist/gim.test(taskName)) {
  7293. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  7294. }
  7295. if (/follow.*button/gim.test(taskName)) {
  7296. this.undoneTasks.steam.followLinks.push(taskLink);
  7297. }
  7298. }
  7299. }
  7300. resolve(true);
  7301. }).catch(error => {
  7302. throwError(error, 'Giveawaysu.classifyTask->getRedirectLink');
  7303. return false;
  7304. });
  7305. }));
  7306. }
  7307. await Promise.all(pro);
  7308. logStatus.success();
  7309. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7310. this.socialTasks = this.undoneTasks;
  7311. if (window.DEBUG) {
  7312. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7313. }
  7314. GM_setValue(`gasTasks-${this.giveawayId}`, {
  7315. tasks: this.socialTasks,
  7316. time: new Date().getTime()
  7317. });
  7318. return true;
  7319. } catch (error) {
  7320. throwError(error, 'Giveawaysu.classifyTask');
  7321. return false;
  7322. }
  7323. }
  7324. #checkLogin() {
  7325. try {
  7326. if (!globalOptions.other.checkLogin) {
  7327. return true;
  7328. }
  7329. if ($('a.steam-login').length > 0) {
  7330. window.open('/steam/redirect', '_self');
  7331. }
  7332. return true;
  7333. } catch (error) {
  7334. throwError(error, 'Giveawaysu.checkLogin');
  7335. return false;
  7336. }
  7337. }
  7338. async #checkLeftKey() {
  7339. try {
  7340. if (!globalOptions.other.checkLeftKey) {
  7341. return true;
  7342. }
  7343. if ($('.giveaway-ended').length > 0 && $('.giveaway-key').length === 0) {
  7344. await external_Swal_default().fire({
  7345. icon: 'warning',
  7346. title: i18n('notice'),
  7347. text: i18n('noKeysLeft'),
  7348. confirmButtonText: i18n('confirm'),
  7349. cancelButtonText: i18n('cancel'),
  7350. showCancelButton: true
  7351. }).then(({
  7352. value
  7353. }) => {
  7354. if (value) {
  7355. window.close();
  7356. }
  7357. });
  7358. }
  7359. return true;
  7360. } catch (error) {
  7361. throwError(error, 'Giveawaysu.checkLeftKey');
  7362. return false;
  7363. }
  7364. }
  7365. #getGiveawayId() {
  7366. try {
  7367. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  7368. if (giveawayId) {
  7369. this.giveawayId = giveawayId;
  7370. return true;
  7371. }
  7372. scripts_echoLog({
  7373. text: i18n('getFailed', 'GiveawayId')
  7374. });
  7375. return false;
  7376. } catch (error) {
  7377. throwError(error, 'Giveawaysu.getGiveawayId');
  7378. return false;
  7379. }
  7380. }
  7381. }
  7382. class Indiedb {
  7383. name = 'Indiedb';
  7384. buttons = [ 'doTask' ];
  7385. static test() {
  7386. return window.location.host === 'www.indiedb.com';
  7387. }
  7388. async after() {
  7389. try {
  7390. if (!this.#checkLogin()) {
  7391. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7392. }
  7393. if (!await this.#checkLeftKey()) {
  7394. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7395. }
  7396. } catch (error) {
  7397. throwError(error, 'Indiedb.after');
  7398. }
  7399. }
  7400. async doTask() {
  7401. try {
  7402. if (!await this.#join()) {
  7403. return false;
  7404. }
  7405. return await this.#do();
  7406. } catch (error) {
  7407. throwError(error, 'Indiedb.doTask');
  7408. return false;
  7409. }
  7410. }
  7411. async #join() {
  7412. try {
  7413. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7414. scripts_echoLog({}).error(i18n('needLogin'));
  7415. return false;
  7416. }
  7417. const currentoption = $('a.buttonenter.buttongiveaway');
  7418. if (/join giveaway/gim.test(currentoption.text())) {
  7419. const logStatus = scripts_echoLog({
  7420. text: `${i18n('joiningGiveaway')}...`
  7421. });
  7422. const {
  7423. result,
  7424. statusText,
  7425. status,
  7426. data
  7427. } = await tools_httpRequest({
  7428. url: currentoption.attr('href'),
  7429. method: 'POST',
  7430. data: 'ajax=t',
  7431. dataType: 'json',
  7432. headers: {
  7433. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  7434. accept: 'application/json, text/javascript, */*; q=0.01',
  7435. origin: window.location.origin
  7436. }
  7437. });
  7438. if (result === 'Success') {
  7439. if (data?.status === 200) {
  7440. if (data.response?.success) {
  7441. currentoption.addClass('buttonentered').text('Success - Giveaway joined');
  7442. $('#giveawaysjoined').slideDown();
  7443. $('#giveawaysrecommend').slideDown();
  7444. logStatus.success(`Success${data.response?.text ? `:${data.response?.text}` : ''}`);
  7445. return true;
  7446. }
  7447. logStatus.error(`Error${data.response?.text ? `:${data.response?.text}` : ''}`);
  7448. return false;
  7449. }
  7450. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7451. return false;
  7452. }
  7453. logStatus.error(`${result}:${statusText}(${status})`);
  7454. return false;
  7455. } else if (/success/gim.test($('a.buttonenter.buttongiveaway').text())) {
  7456. return true;
  7457. }
  7458. scripts_echoLog({}).warning(i18n('needJoinGiveaway'));
  7459. return false;
  7460. } catch (error) {
  7461. throwError(error, 'Indiedb.init');
  7462. return false;
  7463. }
  7464. }
  7465. async #do() {
  7466. try {
  7467. const id = $('script').map((index, script) => {
  7468. if (/\$\(document\)/gim.test(script.innerHTML)) {
  7469. return [ script.innerHTML.match(/"\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0], script.innerHTML.match(/"\/newsletter\/ajax\/subscribeprofile\/optin\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0] ];
  7470. }
  7471. return null;
  7472. });
  7473. if (id.length === 2) {
  7474. const pro = [];
  7475. const tasks = $('#giveawaysjoined a[class*=promo]');
  7476. for (const task of tasks) {
  7477. const promo = $(task);
  7478. if (!promo.hasClass('buttonentered')) {
  7479. const status = scripts_echoLog({
  7480. text: `${i18n('doing')}:${promo.parents('p').text()}...`
  7481. });
  7482. if (/facebookpromo|twitterpromo|visitpromo/gim.test(task.className)) {
  7483. let text = '';
  7484. if (promo.hasClass('facebookpromo')) {
  7485. text = 'facebookpromo';
  7486. } else if (promo.hasClass('twitterpromo')) {
  7487. text = 'twitterpromo';
  7488. } else {
  7489. text = 'visitpromo';
  7490. }
  7491. pro.push(new Promise(resolve => {
  7492. $.ajax({
  7493. type: 'POST',
  7494. url: urlPath(`/giveaways/ajax/${text}/${id[0]}`),
  7495. timeout: 6e4,
  7496. dataType: 'json',
  7497. data: {
  7498. ajax: 't'
  7499. },
  7500. error(response, error, exception) {
  7501. if (window.DEBUG) {
  7502. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7503. response: response,
  7504. error: error,
  7505. exception: exception
  7506. });
  7507. }
  7508. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7509. resolve(true);
  7510. },
  7511. success(response) {
  7512. if (response.success) {
  7513. status.success(`Success:${response.text}`);
  7514. promo.addClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7515. resolve(true);
  7516. } else {
  7517. status.error(`Error:${response.text}`);
  7518. resolve(true);
  7519. }
  7520. }
  7521. });
  7522. }));
  7523. } else if (promo.hasClass('emailoptinpromo')) {
  7524. pro.push(new Promise(resolve => {
  7525. $.ajax({
  7526. type: 'POST',
  7527. url: urlPath(`/newsletter/ajax/subscribeprofile/optin/${id[1]}`),
  7528. timeout: 6e4,
  7529. dataType: 'json',
  7530. data: {
  7531. ajax: 't',
  7532. emailsystoggle: 4
  7533. },
  7534. error(response, error, exception) {
  7535. if (window.DEBUG) {
  7536. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7537. response: response,
  7538. error: error,
  7539. exception: exception
  7540. });
  7541. }
  7542. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7543. resolve(true);
  7544. },
  7545. success(response) {
  7546. if (response.success) {
  7547. status.success(`Success:${response.text}`);
  7548. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7549. resolve(true);
  7550. } else {
  7551. status.error(`Error:${response.text}`);
  7552. resolve(true);
  7553. }
  7554. }
  7555. });
  7556. }));
  7557. } else if (promo.hasClass('watchingpromo')) {
  7558. pro.push(new Promise(resolve => {
  7559. const data = getUrlQuery(promo.attr('href'));
  7560. data.ajax = 't';
  7561. $.ajax({
  7562. type: 'POST',
  7563. url: urlPath(promo.attr('href')?.split(/[?#]/)[0]),
  7564. timeout: 6e4,
  7565. dataType: 'json',
  7566. data: data,
  7567. error(response, error, exception) {
  7568. if (window.DEBUG) {
  7569. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7570. response: response,
  7571. error: error,
  7572. exception: exception
  7573. });
  7574. }
  7575. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7576. resolve(true);
  7577. },
  7578. success(response) {
  7579. if (response.success) {
  7580. status.success(`Success:${response.text}`);
  7581. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7582. resolve(true);
  7583. } else {
  7584. status.error(`Error:${response.text}`);
  7585. resolve(true);
  7586. }
  7587. }
  7588. });
  7589. }));
  7590. } else if (!/the-challenge-of-adblock/gim.test(promo.attr('href'))) {
  7591. pro.push(new Promise(resolve => {
  7592. $.ajax({
  7593. type: 'POST',
  7594. url: urlPath(promo.attr('href')),
  7595. timeout: 6e4,
  7596. dataType: 'json',
  7597. data: {
  7598. ajax: 't'
  7599. },
  7600. error(response, error, exception) {
  7601. if (window.DEBUG) {
  7602. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7603. response: response,
  7604. error: error,
  7605. exception: exception
  7606. });
  7607. }
  7608. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7609. resolve(true);
  7610. },
  7611. success(response) {
  7612. if (response.success) {
  7613. status.success(`Success:${response.text}`);
  7614. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7615. resolve(true);
  7616. } else {
  7617. status.error(`Error:${response.text}`);
  7618. resolve(true);
  7619. }
  7620. }
  7621. });
  7622. }));
  7623. } else {
  7624. status.error(`Error:${i18n('unKnownTaskType')}`);
  7625. }
  7626. }
  7627. }
  7628. await Promise.all(pro);
  7629. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7630. return true;
  7631. }
  7632. scripts_echoLog({}).error(i18n('getFailed', 'TaskId'));
  7633. return false;
  7634. } catch (error) {
  7635. throwError(error, 'Indiedb.classifyTask');
  7636. return false;
  7637. }
  7638. }
  7639. #checkLogin() {
  7640. try {
  7641. if (!globalOptions.other.checkLogin) {
  7642. return true;
  7643. }
  7644. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7645. window.open('/members/login', '_self');
  7646. }
  7647. return true;
  7648. } catch (error) {
  7649. throwError(error, 'Indiedb.checkLogin');
  7650. return false;
  7651. }
  7652. }
  7653. async #checkLeftKey() {
  7654. try {
  7655. if (!globalOptions.other.checkLeftKey) {
  7656. return true;
  7657. }
  7658. if ($('a.buttonenter:contains("next time"), a.buttonenter:contains("Giveaway is closed")').length > 0) {
  7659. await external_Swal_default().fire({
  7660. icon: 'warning',
  7661. title: i18n('notice'),
  7662. text: i18n('giveawayEnded'),
  7663. confirmButtonText: i18n('confirm'),
  7664. cancelButtonText: i18n('cancel'),
  7665. showCancelButton: true
  7666. }).then(({
  7667. value
  7668. }) => {
  7669. if (value) {
  7670. window.close();
  7671. }
  7672. });
  7673. }
  7674. return true;
  7675. } catch (error) {
  7676. throwError(error, 'Indiedb.checkLeftKey');
  7677. return false;
  7678. }
  7679. }
  7680. }
  7681. const website_Indiedb = Indiedb;
  7682. const Keyhub_defaultTasksTemplate = {
  7683. steam: {
  7684. groupLinks: [],
  7685. officialGroupLinks: [],
  7686. wishlistLinks: [],
  7687. curatorLinks: []
  7688. },
  7689. discord: {
  7690. serverLinks: []
  7691. },
  7692. extra: {
  7693. videoTasks: []
  7694. },
  7695. links: []
  7696. };
  7697. const Keyhub_defaultTasks = JSON.stringify(Keyhub_defaultTasksTemplate);
  7698. class Keyhub extends website_Website {
  7699. name = 'Keyhub';
  7700. socialTasks = JSON.parse(Keyhub_defaultTasks);
  7701. undoneTasks = JSON.parse(Keyhub_defaultTasks);
  7702. buttons = [ 'doTask', 'undoTask' ];
  7703. static test() {
  7704. return window.location.host === 'key-hub.eu';
  7705. }
  7706. async after() {
  7707. try {
  7708. if (!this.#checkLogin()) {
  7709. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7710. }
  7711. if (!await this.#checkLeftKey()) {
  7712. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7713. }
  7714. $('.NSFW').hide();
  7715. } catch (error) {
  7716. throwError(error, 'Keyhub.after');
  7717. }
  7718. }
  7719. init() {
  7720. try {
  7721. const logStatus = scripts_echoLog({
  7722. text: i18n('initing')
  7723. });
  7724. if ($('a[href*="/connect/steam"]').length > 0) {
  7725. window.open('/connect/steam', '_self');
  7726. logStatus.warning(i18n('needLogin'));
  7727. return false;
  7728. }
  7729. if (!this.#getGiveawayId()) {
  7730. return false;
  7731. }
  7732. $('#VPNoverlay').hide();
  7733. $('#mainArticleSection').show();
  7734. this.initialized = true;
  7735. logStatus.success();
  7736. return true;
  7737. } catch (error) {
  7738. throwError(error, 'Keyhub.init');
  7739. return false;
  7740. }
  7741. }
  7742. async classifyTask(action) {
  7743. try {
  7744. const logStatus = scripts_echoLog({
  7745. text: i18n('getTasksInfo')
  7746. });
  7747. if (action === 'undo') {
  7748. this.socialTasks = GM_getValue(`khTasks-${this.giveawayId}`)?.tasks || JSON.parse(Keyhub_defaultTasks);
  7749. }
  7750. const tasks = $('.task:not(".googleads")').filter((index, element) => action === 'do' ? $(element).find('i.fa-check-circle:visible').length === 0 : true).find('a');
  7751. for (const task of tasks) {
  7752. let link = $(task).attr('href');
  7753. const taskDes = $(task).text().trim();
  7754. if (!link) {
  7755. continue;
  7756. }
  7757. if (/\/away\?data=/.test(link) || /steamcommunity\.com\/gid\//.test(link)) {
  7758. link = await getRedirectLink(link) || link;
  7759. }
  7760. if (/https?:\/\/key-hub\.eu\/connect\/discord/.test(link)) {
  7761. GM_openInTab(link, {
  7762. active: true
  7763. });
  7764. } else if (/steamcommunity\.com\/groups\//.test(link)) {
  7765. if (action === 'undo') {
  7766. this.socialTasks.steam.groupLinks.push(link);
  7767. }
  7768. if (action === 'do') {
  7769. this.undoneTasks.steam.groupLinks.push(link);
  7770. }
  7771. } else if (/steamcommunity\.com\/games\/[\d]+/.test(link)) {
  7772. if (action === 'undo') {
  7773. this.socialTasks.steam.officialGroupLinks.push(link);
  7774. }
  7775. if (action === 'do') {
  7776. this.undoneTasks.steam.officialGroupLinks.push(link);
  7777. }
  7778. } else if (/store\.steampowered\.com\/app\//.test(link) && /wishlist/gim.test(taskDes)) {
  7779. if (action === 'undo') {
  7780. this.socialTasks.steam.wishlistLinks.push(link);
  7781. }
  7782. if (action === 'do') {
  7783. this.undoneTasks.steam.wishlistLinks.push(link);
  7784. }
  7785. } else if (/store\.steampowered\.com\/curator\//.test(link)) {
  7786. if (action === 'undo') {
  7787. this.socialTasks.steam.curatorLinks.push(link);
  7788. }
  7789. if (action === 'do') {
  7790. this.undoneTasks.steam.curatorLinks.push(link);
  7791. }
  7792. } else if (/^https?:\/\/discord\.com\/invite\//.test(link)) {
  7793. if (action === 'undo') {
  7794. this.socialTasks.discord.serverLinks.push(link);
  7795. }
  7796. if (action === 'do') {
  7797. this.undoneTasks.discord.serverLinks.push(link);
  7798. }
  7799. } else if (/^javascript:videoTask.+/.test(link)) {
  7800. if (action === 'do') {
  7801. const taskData = link.match(/javascript:videoTask\('.+?','(.+?)'/)?.[1];
  7802. if (taskData) {
  7803. this.undoneTasks.extra.videoTasks.push(taskData);
  7804. }
  7805. }
  7806. } 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 {
  7807. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  7808. }
  7809. }
  7810. logStatus.success();
  7811. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7812. this.socialTasks = this.uniqueTasks(this.socialTasks);
  7813. if (window.DEBUG) {
  7814. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7815. }
  7816. GM_setValue(`khTasks-${this.giveawayId}`, {
  7817. tasks: this.socialTasks,
  7818. time: new Date().getTime()
  7819. });
  7820. return true;
  7821. } catch (error) {
  7822. throwError(error, 'Keyhub.classifyTask');
  7823. return false;
  7824. }
  7825. }
  7826. async #doScriptTask(data) {
  7827. try {
  7828. const logStatus = scripts_echoLog({
  7829. text: i18n('doingKeyhubTask')
  7830. });
  7831. const {
  7832. result,
  7833. statusText,
  7834. status,
  7835. data: response
  7836. } = await tools_httpRequest({
  7837. url: `/away?data=${data}`,
  7838. method: 'GET',
  7839. headers: {
  7840. origin: 'https://key-hub.eu',
  7841. referer: 'https://key-hub.eu/'
  7842. }
  7843. });
  7844. if (result === 'Success') {
  7845. if (response?.status === 200) {
  7846. logStatus.success();
  7847. return true;
  7848. }
  7849. logStatus.error(`Error:${response?.statusText}(${response?.status})`);
  7850. return false;
  7851. }
  7852. logStatus.error(`${result}:${statusText}(${status})`);
  7853. return false;
  7854. } catch (error) {
  7855. throwError(error, 'Keyhub.doScriptTask');
  7856. return false;
  7857. }
  7858. }
  7859. async extraDoTask({
  7860. videoTasks
  7861. }) {
  7862. try {
  7863. const pro = [];
  7864. for (const data of videoTasks) {
  7865. pro.push(this.#doScriptTask(data));
  7866. }
  7867. return Promise.all(pro).then(() => true);
  7868. } catch (error) {
  7869. throwError(error, 'Keyhub.extraDoTask');
  7870. return false;
  7871. }
  7872. }
  7873. #getGiveawayId() {
  7874. try {
  7875. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  7876. if (giveawayId) {
  7877. this.giveawayId = giveawayId;
  7878. return true;
  7879. }
  7880. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7881. return false;
  7882. } catch (error) {
  7883. throwError(error, 'Keyhub.getGiveawayId');
  7884. return false;
  7885. }
  7886. }
  7887. async #checkLeftKey() {
  7888. try {
  7889. if (!globalOptions.other.checkLeftKey) {
  7890. return true;
  7891. }
  7892. const leftKey = $('#keysleft').text().trim();
  7893. if (leftKey === '0') {
  7894. await external_Swal_default().fire({
  7895. icon: 'warning',
  7896. title: i18n('notice'),
  7897. text: i18n('noKeysLeft'),
  7898. confirmButtonText: i18n('confirm'),
  7899. cancelButtonText: i18n('cancel'),
  7900. showCancelButton: true
  7901. }).then(({
  7902. value
  7903. }) => {
  7904. if (value) {
  7905. window.close();
  7906. }
  7907. });
  7908. }
  7909. return true;
  7910. } catch (error) {
  7911. throwError(error, 'Keyhub.checkLeftKey');
  7912. return false;
  7913. }
  7914. }
  7915. #checkLogin() {
  7916. try {
  7917. if (!globalOptions.other.checkLogin) {
  7918. return true;
  7919. }
  7920. if ($('a[href*="/connect/steam"]').length > 0) {
  7921. window.open('/connect/steam', '_self');
  7922. }
  7923. return true;
  7924. } catch (error) {
  7925. throwError(error, 'Keyhub.checkLogin');
  7926. return false;
  7927. }
  7928. }
  7929. }
  7930. const website_Keyhub = Keyhub;
  7931. const Givekey_defaultTasksTemplate = {
  7932. steam: {
  7933. groupLinks: [],
  7934. wishlistLinks: [],
  7935. curatorLinks: [],
  7936. curatorLikeLinks: []
  7937. },
  7938. twitter: {
  7939. userLinks: []
  7940. },
  7941. vk: {
  7942. nameLinks: []
  7943. },
  7944. discord: {
  7945. serverLinks: []
  7946. }
  7947. };
  7948. const Givekey_defaultTasks = JSON.stringify(Givekey_defaultTasksTemplate);
  7949. class Givekey extends website_Website {
  7950. name = 'Givekey';
  7951. tasks = [];
  7952. socialTasks = JSON.parse(Givekey_defaultTasks);
  7953. undoneTasks = JSON.parse(Givekey_defaultTasks);
  7954. userId;
  7955. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  7956. static test() {
  7957. return window.location.host === 'givekey.ru';
  7958. }
  7959. async after() {
  7960. try {
  7961. await new Promise(resolve => {
  7962. const checker = setInterval(() => {
  7963. if ($('#navbarDropdown').length > 0) {
  7964. clearInterval(checker);
  7965. resolve(true);
  7966. }
  7967. }, 500);
  7968. });
  7969. if (!await this.#checkLeftKey()) {
  7970. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7971. }
  7972. } catch (error) {
  7973. throwError(error, 'Givekey.after');
  7974. }
  7975. }
  7976. init() {
  7977. try {
  7978. const logStatus = scripts_echoLog({
  7979. text: i18n('initing')
  7980. });
  7981. if ($('a[href*="/auth/steam"]').length > 0) {
  7982. window.open('/auth/steam', '_self');
  7983. logStatus.warning(i18n('needLogin'));
  7984. return false;
  7985. }
  7986. if (!this.#getGiveawayId()) {
  7987. return false;
  7988. }
  7989. const userId = $('meta[name="user-id"]').attr('content');
  7990. if (!userId) {
  7991. logStatus.error(i18n('getFailed', i18n('userId')));
  7992. return false;
  7993. }
  7994. this.userId = userId;
  7995. this.initialized = true;
  7996. logStatus.success();
  7997. return true;
  7998. } catch (error) {
  7999. throwError(error, 'Givekey.init');
  8000. return false;
  8001. }
  8002. }
  8003. async classifyTask(action) {
  8004. try {
  8005. const logStatus = scripts_echoLog({
  8006. text: i18n('getTasksInfo')
  8007. });
  8008. if (action === 'undo') {
  8009. this.socialTasks = GM_getValue(`gkTasks-${this.giveawayId}`)?.tasks || JSON.parse(Givekey_defaultTasks);
  8010. }
  8011. const tasks = $('.card-body:has("button") .row');
  8012. for (const task of tasks) {
  8013. const taskEle = $(task);
  8014. const isSuccess = /Complete/i.test(taskEle.find('button').text().trim());
  8015. if (isSuccess && action !== 'undo') {
  8016. continue;
  8017. }
  8018. const checkButton = taskEle.find('#task_check');
  8019. const taskId = checkButton.attr('data-id');
  8020. if (taskId) {
  8021. this.tasks.push(taskId);
  8022. }
  8023. if (action === 'verify') {
  8024. continue;
  8025. }
  8026. let href = taskEle.find('a').attr('href') || null;
  8027. const text = taskEle.find('a').text().trim();
  8028. const icon = taskEle.find('i');
  8029. if (!href || !text) {
  8030. continue;
  8031. }
  8032. if (/^https?:\/\/givekey\.ru\/giveaway\/[\d]+\/execution_task/.test(href)) {
  8033. href = await getRedirectLink(href);
  8034. }
  8035. if (!href) {
  8036. continue;
  8037. }
  8038. if (/^https?:\/\/vk\.com\//.test(href)) {
  8039. this.socialTasks.vk.nameLinks.push(href);
  8040. if (action === 'do' && !isSuccess) {
  8041. this.undoneTasks.vk.nameLinks.push(href);
  8042. }
  8043. } else if (/^https?:\/\/steamcommunity\.com\/groups/.test(href)) {
  8044. this.socialTasks.steam.groupLinks.push(href);
  8045. if (action === 'do' && !isSuccess) {
  8046. this.undoneTasks.steam.groupLinks.push(href);
  8047. }
  8048. } else if (/^https?:\/\/store\.steampowered\.com\/app\//.test(href)) {
  8049. this.socialTasks.steam.wishlistLinks.push(href);
  8050. if (action === 'do' && !isSuccess) {
  8051. this.undoneTasks.steam.wishlistLinks.push(href);
  8052. }
  8053. } else if (/Subscribe/gi.test(text) && icon.hasClass('fa-steam-square')) {
  8054. if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(href)) {
  8055. this.socialTasks.steam.curatorLinks.push(href);
  8056. if (action === 'do' && !isSuccess) {
  8057. this.undoneTasks.steam.curatorLinks.push(href);
  8058. }
  8059. } else {
  8060. this.socialTasks.steam.curatorLikeLinks.push(href);
  8061. if (action === 'do' && !isSuccess) {
  8062. this.undoneTasks.steam.curatorLikeLinks.push(href);
  8063. }
  8064. }
  8065. } else if (/^https?:\/\/twitter\.com\//.test(href) && /Subscribe/gi.test(text)) {
  8066. this.socialTasks.twitter.userLinks.push(href);
  8067. if (action === 'do' && !isSuccess) {
  8068. this.undoneTasks.twitter.userLinks.push(href);
  8069. }
  8070. } else if (icon.hasClass('fa-discord') || /^https?:\/\/discord\.com\/invite\//.test(href)) {
  8071. this.socialTasks.discord.serverLinks.push(href);
  8072. if (action === 'do' && !isSuccess) {
  8073. this.undoneTasks.discord.serverLinks.push(href);
  8074. }
  8075. } else {
  8076. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${text}(${href})`);
  8077. }
  8078. }
  8079. logStatus.success();
  8080. this.tasks = unique(this.tasks);
  8081. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8082. this.socialTasks = this.uniqueTasks(this.socialTasks);
  8083. if (window.DEBUG) {
  8084. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8085. }
  8086. GM_setValue(`gkTasks-${this.giveawayId}`, {
  8087. tasks: this.socialTasks,
  8088. time: new Date().getTime()
  8089. });
  8090. return true;
  8091. } catch (error) {
  8092. throwError(error, 'Givekey.classifyTask');
  8093. return false;
  8094. }
  8095. }
  8096. async verifyTask() {
  8097. try {
  8098. if (!this.initialized && !this.init()) {
  8099. return false;
  8100. }
  8101. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  8102. return false;
  8103. }
  8104. scripts_echoLog({}).warning(i18n('giveKeyNoticeBefore'));
  8105. const taskLength = this.tasks.length;
  8106. for (let i = 0; i < taskLength; i++) {
  8107. await this.#verify(this.tasks[i]);
  8108. if (i < taskLength - 1) {
  8109. await delay(15e3);
  8110. }
  8111. }
  8112. scripts_echoLog({}).success(i18n('allTasksComplete'));
  8113. scripts_echoLog({
  8114. html: `<li><font class="warning">${i18n('giveKeyNoticeAfter')}</font></li>`
  8115. });
  8116. return true;
  8117. } catch (error) {
  8118. throwError(error, 'Givekey.verifyTask');
  8119. return false;
  8120. }
  8121. }
  8122. async #verify(task) {
  8123. try {
  8124. const logStatus = scripts_echoLog({
  8125. html: `<li>${i18n('verifyingTask')}${task}...<font></font></li>`
  8126. });
  8127. return await new Promise(resolve => {
  8128. $.ajax({
  8129. url: 'https://givekey.ru/giveaway/task',
  8130. method: 'POST',
  8131. data: `id=${task}&user_id=${this.userId}`,
  8132. dataType: 'json',
  8133. headers: {
  8134. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  8135. },
  8136. success: data => {
  8137. if (data.btn) {
  8138. $(`button[data-id=${this.userId}]`).html(data.btn);
  8139. }
  8140. if (data.status === 'ok') {
  8141. $(`.task_check_${data.id}`).html(`<button class="btn btn-success mb-2 btn-block" disabled>${data.btn}</button>`);
  8142. logStatus.success();
  8143. resolve(true);
  8144. } else if (data.status === 'end') {
  8145. logStatus.success();
  8146. scripts_echoLog({}).success(data.key);
  8147. resolve(true);
  8148. } else {
  8149. logStatus.error(`Error:${data.msg}`);
  8150. resolve(false);
  8151. }
  8152. },
  8153. error: xhr => {
  8154. logStatus.error(`Error:${xhr.statusText}(${xhr.status})`);
  8155. resolve(false);
  8156. }
  8157. });
  8158. });
  8159. } catch (error) {
  8160. throwError(error, 'Givekey.verify');
  8161. return false;
  8162. }
  8163. }
  8164. #getGiveawayId() {
  8165. try {
  8166. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  8167. if (giveawayId) {
  8168. this.giveawayId = giveawayId;
  8169. return true;
  8170. }
  8171. scripts_echoLog({
  8172. text: i18n('getFailed', 'GiveawayId')
  8173. });
  8174. return false;
  8175. } catch (error) {
  8176. throwError(error, 'Givekey.getGiveawayId');
  8177. return false;
  8178. }
  8179. }
  8180. async #checkLeftKey() {
  8181. try {
  8182. if (!globalOptions.other.checkLeftKey) {
  8183. return true;
  8184. }
  8185. if (!$('#keys_count').text()) {
  8186. await external_Swal_default().fire({
  8187. icon: 'warning',
  8188. title: i18n('notice'),
  8189. text: i18n('noKeysLeft'),
  8190. confirmButtonText: i18n('confirm'),
  8191. cancelButtonText: i18n('cancel'),
  8192. showCancelButton: true
  8193. }).then(({
  8194. value
  8195. }) => {
  8196. if (value) {
  8197. window.close();
  8198. }
  8199. });
  8200. }
  8201. return true;
  8202. } catch (error) {
  8203. throwError(error, 'Givekey.checkLeftKey');
  8204. return false;
  8205. }
  8206. }
  8207. }
  8208. const website_Givekey = Givekey;
  8209. class GiveeClub extends GiveawaySu {
  8210. name = 'GiveeClub';
  8211. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  8212. static test() {
  8213. return /^https?:\/\/givee\.club\/.*?\/event\/[\d]+/.test(window.location.href);
  8214. }
  8215. async after() {
  8216. try {
  8217. if (!this.#checkLogin()) {
  8218. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8219. }
  8220. if (!await this.#checkLeftKey()) {
  8221. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  8222. }
  8223. } catch (error) {
  8224. throwError(error, 'GiveeClub.after');
  8225. }
  8226. }
  8227. init() {
  8228. try {
  8229. const logStatus = scripts_echoLog({
  8230. text: i18n('initing')
  8231. });
  8232. if (!this.#checkLogin()) {
  8233. logStatus.warning(i18n('needLogin'));
  8234. return false;
  8235. }
  8236. if (!this.#getGiveawayId()) {
  8237. return false;
  8238. }
  8239. this.initialized = true;
  8240. logStatus.success();
  8241. return true;
  8242. } catch (error) {
  8243. throwError(error, 'GiveeClub.init');
  8244. return false;
  8245. }
  8246. }
  8247. async classifyTask(action) {
  8248. try {
  8249. const logStatus = scripts_echoLog({
  8250. text: i18n('getTasksInfo')
  8251. });
  8252. if (action === 'undo') {
  8253. this.socialTasks = GM_getValue(`gcTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  8254. return true;
  8255. }
  8256. const pro = [];
  8257. const tasks = $('.event-actions tr');
  8258. for (const task of tasks) {
  8259. pro.push(new Promise(resolve => {
  8260. const taskDes = $(task).find('.event-action-label a');
  8261. const taskIcon = $(task).find('.event-action-icon i').attr('class') || '';
  8262. const taskName = taskDes.text().trim();
  8263. const taskType = $(task).find('button[data-type]')?.attr('data-type');
  8264. const taskFinished = $(task).find('.event-action-buttons .btn-success')?.length;
  8265. if (taskIcon.includes('ban') || /AdBlock/i.test(taskName) || taskIcon.includes('envelope') || taskFinished) {
  8266. return resolve(true);
  8267. }
  8268. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  8269. if (!taskLink) {
  8270. return resolve(false);
  8271. }
  8272. if (taskType === 'steam.group.join' && /^https?:\/\/steamcommunity\.com\/groups/.test(taskLink)) {
  8273. this.undoneTasks.steam.groupLinks.push(taskLink);
  8274. } else if (/like.*announcement/gi.test(taskName)) {
  8275. this.undoneTasks.steam.announcementLinks.push(taskLink);
  8276. } else if (taskType === 'steam.game.wishlist' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8277. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  8278. } else if (taskType === 'steam.game.wishlist' && taskDes.attr('data-steam-wishlist-appid')) {
  8279. this.undoneTasks.steam.wishlistLinks.push(`https://store.steampowered.com/app/${taskDes.attr('data-steam-wishlist-appid')}`);
  8280. } else if (taskType === 'steam.game.follow' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8281. this.undoneTasks.steam.followLinks.push(taskLink);
  8282. } else if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  8283. this.undoneTasks.steam.curatorLinks.push(taskLink);
  8284. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  8285. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  8286. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  8287. this.undoneTasks.steam.forumLinks.push(taskLink);
  8288. } else if (taskIcon.includes('discord')) {
  8289. this.undoneTasks.discord.serverLinks.push(taskLink);
  8290. } else if (taskIcon.includes('instagram')) {
  8291. this.undoneTasks.instagram.userLinks.push(taskLink);
  8292. } else if (taskIcon.includes('twitch')) {
  8293. this.undoneTasks.twitch.channelLinks.push(taskLink);
  8294. } else if (taskIcon.includes('reddit')) {
  8295. this.undoneTasks.reddit.redditLinks.push(taskLink);
  8296. } else if (/watch.*art/gim.test(taskName)) {
  8297. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8298. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  8299. this.undoneTasks.youtube.channelLinks.push(taskLink);
  8300. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  8301. this.undoneTasks.youtube.likeLinks.push(taskLink);
  8302. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  8303. this.undoneTasks.vk.nameLinks.push(taskLink);
  8304. } else if (taskIcon.includes('twitter')) {
  8305. if (/https?:\/\/twitter\.com\/[^/]+\/?$/gim.test(taskLink)) {
  8306. this.undoneTasks.twitter.userLinks.push(taskLink);
  8307. } else if (/https?:\/\/twitter\.com\/[^/]+?\/status\/[\d]+/gim.test(taskLink)) {
  8308. this.undoneTasks.twitter.retweetLinks.push(taskLink);
  8309. }
  8310. } else {
  8311. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  8312. if (/follow.*button/gim.test(taskName)) {
  8313. this.undoneTasks.steam.followLinks.push(taskLink);
  8314. }
  8315. }
  8316. }
  8317. resolve(true);
  8318. }).catch(error => {
  8319. throwError(error, 'GiveeClub.classifyTask->getRedirectLink');
  8320. return false;
  8321. });
  8322. }));
  8323. }
  8324. await Promise.all(pro);
  8325. logStatus.success();
  8326. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8327. this.socialTasks = this.undoneTasks;
  8328. if (window.DEBUG) {
  8329. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8330. }
  8331. GM_setValue(`gcTasks-${this.giveawayId}`, {
  8332. tasks: this.socialTasks,
  8333. time: new Date().getTime()
  8334. });
  8335. return true;
  8336. } catch (error) {
  8337. throwError(error, 'GiveeClub.classifyTask');
  8338. return false;
  8339. }
  8340. }
  8341. async verifyTask() {
  8342. try {
  8343. const logStatus = scripts_echoLog({
  8344. text: i18n('giveeClubVerifyNotice')
  8345. });
  8346. const taskButtons = $('.event-actions tr button').has('i.glyphicon-refresh').not('[data-type="user.adblock"]');
  8347. for (const button of taskButtons) {
  8348. button.click();
  8349. if ($(button).attr('data-type') !== 'steam.game.wishlist') {
  8350. await delay(1e3);
  8351. }
  8352. }
  8353. logStatus.warning(i18n('giveeClubVerifyFinished'));
  8354. return true;
  8355. } catch (error) {
  8356. throwError(error, 'Givekey.verifyTask');
  8357. return false;
  8358. }
  8359. }
  8360. #checkLogin() {
  8361. try {
  8362. if (!globalOptions.other.checkLogin) {
  8363. return true;
  8364. }
  8365. if ($('a[href*="/account/auth"]').length > 0) {
  8366. window.open($('a[href*="/account/auth"]').attr('href'), '_self');
  8367. }
  8368. return true;
  8369. } catch (error) {
  8370. throwError(error, 'GiveeClub.checkLogin');
  8371. return false;
  8372. }
  8373. }
  8374. #getGiveawayId() {
  8375. const giveawayId = window.location.href.match(/\/event\/([\d]+)/)?.[1];
  8376. if (giveawayId) {
  8377. this.giveawayId = giveawayId;
  8378. return true;
  8379. }
  8380. scripts_echoLog({
  8381. text: i18n('getFailed', 'GiveawayId')
  8382. });
  8383. return false;
  8384. }
  8385. async #checkLeftKey() {
  8386. try {
  8387. if (!globalOptions.other.checkLeftKey) {
  8388. return true;
  8389. }
  8390. if ($('.event-ended').length > 0 && $('.event-winner').length === 0) {
  8391. await external_Swal_default().fire({
  8392. icon: 'warning',
  8393. title: i18n('notice'),
  8394. text: i18n('giveawayEnded'),
  8395. confirmButtonText: i18n('confirm'),
  8396. cancelButtonText: i18n('cancel'),
  8397. showCancelButton: true
  8398. }).then(({
  8399. value
  8400. }) => {
  8401. if (value) {
  8402. window.close();
  8403. }
  8404. });
  8405. }
  8406. return true;
  8407. } catch (error) {
  8408. throwError(error, 'Giveawaysu.checkLeftKey');
  8409. return false;
  8410. }
  8411. }
  8412. }
  8413. const website_GiveeClub = GiveeClub;
  8414. const defaultOptions = {
  8415. maxPoint: '99999999'
  8416. };
  8417. class OpiumPulses {
  8418. name = 'OpiumPulses';
  8419. options = {
  8420. ...defaultOptions,
  8421. ...GM_getValue('OpiumPulsesOptions')
  8422. };
  8423. maxPoints = 99999999;
  8424. myPoints = 0;
  8425. buttons = [ 'doFreeTask', 'doPointTask' ];
  8426. static test() {
  8427. return window.location.host === 'www.opiumpulses.com';
  8428. }
  8429. async after() {
  8430. try {
  8431. if (!this.#checkLogin()) {
  8432. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8433. }
  8434. this.maxPoints = parseInt(this.options.maxPoint, 10);
  8435. } catch (error) {
  8436. throwError(error, 'OpiumPulses.after');
  8437. }
  8438. }
  8439. async doFreeTask() {
  8440. try {
  8441. this.#toggleTask('FREE');
  8442. } catch (error) {
  8443. throwError(error, 'OpiumPulses.doFreeTask');
  8444. }
  8445. }
  8446. async doPointTask() {
  8447. try {
  8448. this.myPoints = parseInt($('.page-header__nav-func-user-nav-items.points-items').text().match(/[\d]+/gim)?.[0] || '0', 10);
  8449. this.#toggleTask('points');
  8450. } catch (error) {
  8451. throwError(error, 'OpiumPulses.doPointTask');
  8452. }
  8453. }
  8454. async #toggleTask(type) {
  8455. try {
  8456. const items = $(`.giveaways-page-item:contains('${type}'):not(:contains('ENTERED'))`);
  8457. for (const item of items) {
  8458. const needPoints = parseInt($(item).find('.giveaways-page-item-header-points').text().match(/[\d]+/gim)?.[0] || '999999', 10);
  8459. const name = $(item).find('.giveaways-page-item-footer-name').text().trim();
  8460. if (type === 'points' && needPoints > this.myPoints) {
  8461. scripts_echoLog({}).warning(`${i18n('noPoints')}: ${name}`);
  8462. } else if (type === 'points' && !needPoints) {
  8463. scripts_echoLog({}).warning(`${i18n('getNeedPointsFailed')}: ${name}`);
  8464. } else if (!(type === 'points' && needPoints > this.maxPoints)) {
  8465. const logStatus = scripts_echoLog({
  8466. text: `${i18n('joiningLottery')}<a href="${$(item).find('a.giveaways-page-item-img-btn-more').attr('href')}" target="_blank">${name}</a>...`
  8467. });
  8468. const aElement = $(item).find('a.giveaways-page-item-img-btn-enter:contains(\'enter\')');
  8469. if (aElement?.attr('onclick')?.includes('checkUser')) {
  8470. const giveawayId = aElement.attr('onclick')?.match(/[\d]+/)?.[0];
  8471. if (giveawayId) {
  8472. checkUser(giveawayId);
  8473. }
  8474. }
  8475. if (!aElement.attr('href')) {
  8476. logStatus.error('Error: No "href".');
  8477. continue;
  8478. }
  8479. const {
  8480. result,
  8481. statusText,
  8482. status,
  8483. data
  8484. } = await tools_httpRequest({
  8485. url: aElement.attr('href'),
  8486. method: 'GET'
  8487. });
  8488. if (result === 'Success') {
  8489. const {
  8490. result: result0,
  8491. statusText: statusText0,
  8492. status: status0,
  8493. data: data0
  8494. } = await tools_httpRequest({
  8495. url: data?.finalUrl,
  8496. method: 'GET'
  8497. });
  8498. if (data0?.responseText && /You've entered this giveaway/gim.test(data0.responseText)) {
  8499. logStatus.success();
  8500. const points = data0.responseText.match(/Points:[\s]*?([\d]+)/)?.[1];
  8501. if (type === 'points' && points) {
  8502. this.myPoints = parseInt(points, 10);
  8503. }
  8504. } else if (data0?.responseText && /You're not eligible to enter/gim.test(data0.responseText)) {
  8505. logStatus.error('You\'re not eligible to enter');
  8506. } else {
  8507. logStatus.error(`${result0}:${statusText0}(${status0})`);
  8508. }
  8509. } else {
  8510. logStatus.error(`${result}:${statusText}(${status})`);
  8511. }
  8512. }
  8513. }
  8514. scripts_echoLog({
  8515. text: '-----END-----'
  8516. });
  8517. } catch (error) {
  8518. throwError(error, 'OpiumPulses.toggleTask');
  8519. }
  8520. }
  8521. init() {
  8522. return true;
  8523. }
  8524. classifyTask() {
  8525. return true;
  8526. }
  8527. #checkLogin() {
  8528. try {
  8529. if (!globalOptions.other.checkLogin) {
  8530. return true;
  8531. }
  8532. if ($('a[href*="/site/login"]').length > 1) {
  8533. window.open('/site/login', '_self');
  8534. }
  8535. return true;
  8536. } catch (error) {
  8537. throwError(error, 'OpiumPulses.checkLogin');
  8538. return false;
  8539. }
  8540. }
  8541. }
  8542. const website_OpiumPulses = OpiumPulses;
  8543. const external_dayjs_namespaceObject = dayjs;
  8544. var external_dayjs_default = __webpack_require__.n(external_dayjs_namespaceObject);
  8545. const leftKeyChecker = {
  8546. async classify(link) {
  8547. try {
  8548. if (/^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(link)) {
  8549. return await this.giveawaySu(link);
  8550. }
  8551. if (/^https?:\/\/givee\.club\/[\w]+?\/event\/[\d]+/.test(link)) {
  8552. return await this.giveeClub(link);
  8553. }
  8554. if (/^https?:\/\/gleam\.io\/.+?\/.+/.test(link)) {
  8555. return await this.gleam(link);
  8556. }
  8557. if (/^https?:\/\/www\.indiedb\.com\/giveaways\/.+/.test(link)) {
  8558. return await this.indieDb(link);
  8559. }
  8560. if (/^https?:\/\/key-hub\.eu\/giveaway\/[\d]+/.test(link)) {
  8561. return await this.keyhub(link);
  8562. }
  8563. if (/^https?:\/\/opquests\.com\/quests\/[\d]+/.test(link)) {
  8564. return await this.opquests(link);
  8565. }
  8566. if (/^https?:\/\/itch\.io\/s\/[\d]+?\/.*/.test(link)) {
  8567. return await this.itch(link);
  8568. }
  8569. return false;
  8570. } catch (error) {
  8571. throwError(error, 'leftKeyChecker.classify');
  8572. return false;
  8573. }
  8574. },
  8575. async giveawaySu(link) {
  8576. try {
  8577. const {
  8578. result,
  8579. data
  8580. } = await tools_httpRequest({
  8581. url: link,
  8582. method: 'GET'
  8583. });
  8584. if (result === 'Success' && data?.status === 200) {
  8585. if (data.responseText.includes('class="steam-login"')) {
  8586. return false;
  8587. }
  8588. if (data.responseText.includes('class="giveaway-ended"')) {
  8589. return 'Ended';
  8590. }
  8591. return 'Active';
  8592. }
  8593. return false;
  8594. } catch (error) {
  8595. throwError(error, 'leftKeyChecker.giveawaySu');
  8596. return false;
  8597. }
  8598. },
  8599. async giveeClub(link) {
  8600. try {
  8601. const {
  8602. result,
  8603. data
  8604. } = await tools_httpRequest({
  8605. url: link,
  8606. method: 'GET'
  8607. });
  8608. if (result === 'Success' && data?.status === 200) {
  8609. if (data.responseText.includes('class="event-winner"')) {
  8610. return 'Won';
  8611. }
  8612. if (data.responseText.includes('class="event-ended"')) {
  8613. return 'Ended';
  8614. }
  8615. return 'Active';
  8616. }
  8617. return false;
  8618. } catch (error) {
  8619. throwError(error, 'leftKeyChecker.giveeClub');
  8620. return false;
  8621. }
  8622. },
  8623. async gleam(link) {
  8624. try {
  8625. const {
  8626. result,
  8627. data
  8628. } = await tools_httpRequest({
  8629. url: link,
  8630. method: 'GET'
  8631. });
  8632. if (result === 'Success' && data?.status === 200) {
  8633. if (/incentives&quot;:{&quot;[\d]+?&quot;:\[&quot;.+?&quot;\]/.test(data.responseText)) {
  8634. return 'Won';
  8635. }
  8636. const campaignDiv = data.responseText.match(/<div class='popup-blocks-container'[\w\W]+?'>/)?.[0];
  8637. if (!campaignDiv) {
  8638. return false;
  8639. }
  8640. const campaignString = $(campaignDiv).attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  8641. if (!campaignString) {
  8642. return false;
  8643. }
  8644. const {
  8645. campaign
  8646. } = JSON.parse(campaignString);
  8647. if (campaign.banned) {
  8648. return 'Banned';
  8649. }
  8650. if (campaign.finished) {
  8651. return 'Ended';
  8652. }
  8653. if (campaign.paused) {
  8654. return 'Paused';
  8655. }
  8656. if (new Date().getTime() < campaign.starts_at * 1e3) {
  8657. return 'NotStart';
  8658. }
  8659. return 'Active';
  8660. }
  8661. return false;
  8662. } catch (error) {
  8663. throwError(error, 'leftKeyChecker.gleam');
  8664. return false;
  8665. }
  8666. },
  8667. async indieDb(link) {
  8668. try {
  8669. const {
  8670. result,
  8671. data
  8672. } = await tools_httpRequest({
  8673. url: link,
  8674. method: 'GET'
  8675. });
  8676. if (result === 'Success' && data?.status === 200) {
  8677. if (data.responseText.includes('Congrats you WON')) {
  8678. return 'Won';
  8679. }
  8680. if (data.responseText.includes('Giveaway is closed') || data.responseText.includes('next time')) {
  8681. return 'Ended';
  8682. }
  8683. return 'Active';
  8684. }
  8685. return false;
  8686. } catch (error) {
  8687. throwError(error, 'leftKeyChecker.indieDb');
  8688. return false;
  8689. }
  8690. },
  8691. async keyhub(link) {
  8692. try {
  8693. const {
  8694. result,
  8695. data
  8696. } = await tools_httpRequest({
  8697. url: link,
  8698. method: 'GET'
  8699. });
  8700. if (result === 'Success' && data?.status === 200) {
  8701. const keysleft = data.responseText.match(/<span id="keysleft">([\d]+?)<\/span>/)?.[1];
  8702. if (!keysleft) {
  8703. return false;
  8704. }
  8705. if (keysleft === '0') {
  8706. return 'Ended';
  8707. }
  8708. return `Active(${keysleft})`;
  8709. }
  8710. return false;
  8711. } catch (error) {
  8712. throwError(error, 'leftKeyChecker.keyhub');
  8713. return false;
  8714. }
  8715. },
  8716. async opquests(link) {
  8717. try {
  8718. const {
  8719. result,
  8720. data
  8721. } = await tools_httpRequest({
  8722. url: link,
  8723. method: 'GET'
  8724. });
  8725. if (result === 'Success' && data?.status === 200) {
  8726. const keysleft = data.responseText.match(/<div class="">[\s]*?([\d]+?)[\s]*?of/)?.[1];
  8727. if (!keysleft) {
  8728. return false;
  8729. }
  8730. if (keysleft === '0') {
  8731. return 'Ended';
  8732. }
  8733. return `Active(${keysleft})`;
  8734. } else if (data?.status === 404) {
  8735. return 'Ended';
  8736. }
  8737. return false;
  8738. } catch (error) {
  8739. throwError(error, 'leftKeyChecker.opquests');
  8740. return false;
  8741. }
  8742. },
  8743. async itch(link) {
  8744. try {
  8745. const {
  8746. result,
  8747. data
  8748. } = await tools_httpRequest({
  8749. url: link,
  8750. method: 'GET'
  8751. });
  8752. if (result === 'Success' && data?.status === 200) {
  8753. const endDate = data.responseText.match(/{"start_date":"[0-9A-Z-:]+?".*?"end_date":"([0-9A-Z-:]+?)".*?}/)?.[1];
  8754. if (!endDate) {
  8755. return false;
  8756. }
  8757. if (new Date().getTime() > new Date(endDate).getTime()) {
  8758. return 'Ended';
  8759. }
  8760. return `Active(${external_dayjs_default()(endDate).format('YYYY-MM-DD HH:mm:ss')})`;
  8761. }
  8762. return false;
  8763. } catch (error) {
  8764. throwError(error, 'leftKeyChecker.itch');
  8765. return false;
  8766. }
  8767. }
  8768. };
  8769. const website_leftKeyChecker = leftKeyChecker;
  8770. const Keylol_defaultTasksTemplate = {
  8771. steam: {
  8772. groupLinks: [],
  8773. wishlistLinks: [],
  8774. curatorLinks: [],
  8775. curatorLikeLinks: [],
  8776. followLinks: [],
  8777. forumLinks: [],
  8778. announcementLinks: [],
  8779. workshopVoteLinks: [],
  8780. licenseLinks: []
  8781. },
  8782. discord: {
  8783. serverLinks: []
  8784. },
  8785. instagram: {
  8786. userLinks: []
  8787. },
  8788. vk: {
  8789. nameLinks: []
  8790. },
  8791. twitch: {
  8792. channelLinks: []
  8793. },
  8794. reddit: {
  8795. redditLinks: []
  8796. },
  8797. twitter: {
  8798. userLinks: [],
  8799. retweetLinks: []
  8800. },
  8801. youtube: {
  8802. channelLinks: [],
  8803. likeLinks: []
  8804. }
  8805. };
  8806. const Keylol_defaultTasks = JSON.stringify(Keylol_defaultTasksTemplate);
  8807. class Keylol extends website_Website {
  8808. name = 'Keylol';
  8809. socialTasks = JSON.parse(Keylol_defaultTasks);
  8810. undoneTasks = JSON.parse(Keylol_defaultTasks);
  8811. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect' ];
  8812. static test() {
  8813. 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'));
  8814. }
  8815. init() {
  8816. return true;
  8817. }
  8818. after() {
  8819. try {
  8820. const selector = this.name === 'Keylol' ? '#postlist>div[id^="post_"]:first' : 'div.container';
  8821. const mainPost = $(selector);
  8822. const discordLinks = mainPost.find('a[href*="discord.com"]:visible');
  8823. const redditLinks = mainPost.find('a[href*="reddit.com"]:visible');
  8824. const insLinks = mainPost.find('a[href*="instagram.com"]:visible');
  8825. const twitterLinks = mainPost.find('a[href*="twitter.com"]:visible,a[href*="x.com"]:visible');
  8826. const twitchLinks = mainPost.find('a[href*="twitch.tv"]:visible');
  8827. const vkLinks = mainPost.find('a[href*="vk.com"]:visible');
  8828. const steamStoreLinks = mainPost.find('a[href*="store.steampowered.com"]:visible');
  8829. const steamCommunityLinks = mainPost.find('a[href*="steamcommunity.com"]:visible');
  8830. const ytbLinks = mainPost.find('a[href*="youtube.com"]:visible');
  8831. if (discordLinks.length > 0) {
  8832. for (const discordLink of discordLinks) {
  8833. const link = $(discordLink).attr('href');
  8834. if (!(link && /^https?:\/\/discord\.com\/invite\/.+/.test(link))) {
  8835. continue;
  8836. }
  8837. this.#addBtn(discordLink, 'discord', 'serverLinks', link);
  8838. }
  8839. }
  8840. if (redditLinks.length > 0) {
  8841. for (const redditLink of redditLinks) {
  8842. const link = $(redditLink).attr('href');
  8843. if (!(link && /^https?:\/\/www\.reddit\.com\/(r|user)\/.+/.test(link))) {
  8844. continue;
  8845. }
  8846. this.#addBtn(redditLink, 'reddit', 'redditLinks', link);
  8847. }
  8848. }
  8849. if (insLinks.length > 0) {
  8850. for (const insLink of insLinks) {
  8851. const link = $(insLink).attr('href');
  8852. if (!(link && /^https:\/\/www\.instagram\.com\/.+/.test(link))) {
  8853. continue;
  8854. }
  8855. this.#addBtn(insLink, 'instagram', 'userLinks', link);
  8856. }
  8857. }
  8858. if (twitterLinks.length > 0) {
  8859. for (const twitterLink of twitterLinks) {
  8860. const link = $(twitterLink).attr('href');
  8861. if (!(link && /^https:\/\/twitter\.com\/.+/.test(link))) {
  8862. continue;
  8863. }
  8864. if (/https:\/\/twitter\.com\/.*?\/status\/[\d]+/.test(link)) {
  8865. this.#addBtn(twitterLink, 'twitter', 'retweetLinks', link);
  8866. } else {
  8867. this.#addBtn(twitterLink, 'twitter', 'userLinks', link);
  8868. }
  8869. }
  8870. }
  8871. if (twitchLinks.length > 0) {
  8872. for (const twitchLink of twitchLinks) {
  8873. const link = $(twitchLink).attr('href');
  8874. if (!(link && /^https:\/\/(www\.)?twitch\.tv\/.+/.test(link))) {
  8875. continue;
  8876. }
  8877. this.#addBtn(twitchLink, 'twitch', 'channelLinks', link);
  8878. }
  8879. }
  8880. if (vkLinks.length > 0) {
  8881. for (const vkLink of vkLinks) {
  8882. const link = $(vkLink).attr('href');
  8883. if (!(link && /^https:\/\/vk\.com\/.+/.test(link))) {
  8884. continue;
  8885. }
  8886. this.#addBtn(vkLink, 'vk', 'nameLinks', link);
  8887. }
  8888. }
  8889. if (steamStoreLinks.length > 0) {
  8890. for (const steamStoreLink of steamStoreLinks) {
  8891. const link = $(steamStoreLink).attr('href');
  8892. if (!link) {
  8893. continue;
  8894. }
  8895. if (/curator\/[\d]+/.test(link)) {
  8896. this.#addBtn(steamStoreLink, 'steam', 'curatorLinks', link);
  8897. } else if (/(publisher|developer|franchise)\/.+/.test(link)) {
  8898. this.#addBtn(steamStoreLink, 'steam', 'curatorLikeLinks', link);
  8899. } else if (/news(hub)?\/app\/[\d]+\/view\/[\d]+/.test(link)) {
  8900. this.#addBtn(steamStoreLink, 'steam', 'announcementLinks', link);
  8901. } else if (/app\/[\d]+/.test(link)) {
  8902. this.#addBtn(steamStoreLink, 'steam', 'followLinks', link);
  8903. this.#addBtn(steamStoreLink, 'steam', 'wishlistLinks', link);
  8904. }
  8905. }
  8906. }
  8907. if (steamCommunityLinks.length > 0) {
  8908. for (const steamCommunityLink of steamCommunityLinks) {
  8909. const link = $(steamCommunityLink).attr('href');
  8910. if (!link) {
  8911. continue;
  8912. }
  8913. if (/groups\/.+/.test(link)) {
  8914. this.#addBtn(steamCommunityLink, 'steam', 'groupLinks', link);
  8915. } else if (/announcements\/detail\/[\d]+/.test(link)) {
  8916. this.#addBtn(steamCommunityLink, 'steam', 'announcementLinks', link);
  8917. }
  8918. }
  8919. }
  8920. if (ytbLinks.length > 0) {
  8921. for (const ytbLink of ytbLinks) {
  8922. const link = $(ytbLink).attr('href');
  8923. if (!link) {
  8924. continue;
  8925. }
  8926. this.#addBtn(ytbLink, 'youtube', 'channelLinks', link);
  8927. this.#addBtn(ytbLink, 'youtube', 'likeLinks', link);
  8928. }
  8929. }
  8930. 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');
  8931. if (giveawayLinks.length > 0) {
  8932. for (const giveawayLink of giveawayLinks) {
  8933. const link = $(giveawayLink).attr('href');
  8934. if (!link) {
  8935. continue;
  8936. }
  8937. website_leftKeyChecker.classify(link).then(status => {
  8938. if (!status) {
  8939. return;
  8940. }
  8941. if (/^Active/.test(status)) {
  8942. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status active" title="${i18n('Active')}">${status}</font>`);
  8943. return;
  8944. }
  8945. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status not-active" title="${i18n(status)}">${status}</font>`);
  8946. }).catch(error => {
  8947. throwError(error, 'keylol.after -> leftKeyChecker');
  8948. });
  8949. }
  8950. }
  8951. if (this.name === 'Keylol') {
  8952. const asfLinks = mainPost.find('a[href^="#asf"]:visible');
  8953. if (asfLinks.length > 0) {
  8954. for (const asfLink of asfLinks) {
  8955. const link = $(asfLink).attr('href');
  8956. if (!link) {
  8957. continue;
  8958. }
  8959. this.#addBtn($(`a[href="${link}"]`).after('<span style="color: #ccc; margin: 0 -5px 0 5px"> | </span>').next()[0], 'steam', 'licenseLinks', `appid-${link.replace('#asf', '')}`);
  8960. }
  8961. }
  8962. const subLinks = mainPost.find('a[href*="steamdb.info/sub/"]:visible');
  8963. if (subLinks.length > 0) {
  8964. for (const subLink of subLinks) {
  8965. const link = $(subLink).attr('href');
  8966. if (!link) {
  8967. continue;
  8968. }
  8969. const subid = link.match(/^https:\/\/steamdb\.info\/sub\/([\d]+)/)?.[1];
  8970. if (!subid) {
  8971. continue;
  8972. }
  8973. this.#addBtn(subLink, 'steam', 'licenseLinks', `subid-${subid}`);
  8974. }
  8975. }
  8976. const asfLinks2 = mainPost.find('.blockcode:contains("addlicense"):visible');
  8977. if (asfLinks2.length > 0) {
  8978. for (const asfLink of asfLinks2) {
  8979. const appid = [ ...asfLink.innerText.matchAll(/a(pp)?\/([\d]+)/g) ].map(matched => matched?.[2]).filter(id => id) || [];
  8980. if (appid.length > 0) {
  8981. this.#addBtn($(asfLink).children('em')[0], 'steam', 'licenseLinks', `appid-${appid.join(',')}`);
  8982. }
  8983. const subid = asfLink.innerText.match(/[\d]+/g)?.filter(matched => !appid.includes(matched));
  8984. if (!subid || subid.length === 0) {
  8985. continue;
  8986. }
  8987. this.#addBtn($(asfLink).children('em')[0], 'steam', 'licenseLinks', `subid-${subid.join(',')}`);
  8988. }
  8989. }
  8990. }
  8991. } catch (error) {
  8992. throwError(error, 'keylol.after');
  8993. }
  8994. }
  8995. classifyTask(action) {
  8996. try {
  8997. this.socialTasks = JSON.parse(Keylol_defaultTasks);
  8998. this.undoneTasks = JSON.parse(Keylol_defaultTasks);
  8999. const selectedBtns = $('.auto-task-keylol[selected="selected"]:visible');
  9000. for (const btn of selectedBtns) {
  9001. const button = $(btn);
  9002. const social = button.attr('data-social');
  9003. const type = button.attr('data-type');
  9004. const link = button.attr('data-link');
  9005. if (!(social && type && link)) {
  9006. continue;
  9007. }
  9008. if (action === 'do') {
  9009. this.undoneTasks[social][type].push(link);
  9010. }
  9011. if (action === 'undo') {
  9012. this.socialTasks[social][type].push(link);
  9013. }
  9014. }
  9015. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9016. this.socialTasks = this.uniqueTasks(this.socialTasks);
  9017. if (window.DEBUG) {
  9018. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9019. }
  9020. return true;
  9021. } catch (error) {
  9022. throwError(error, 'Keylol.classifyTask');
  9023. return false;
  9024. }
  9025. }
  9026. selectAll() {
  9027. try {
  9028. $('.auto-task-keylol:visible').attr('selected', 'selected');
  9029. } catch (error) {
  9030. throwError(error, 'Keylol.selectAll');
  9031. }
  9032. }
  9033. selectNone() {
  9034. try {
  9035. $('.auto-task-keylol:visible').removeAttr('selected');
  9036. } catch (error) {
  9037. throwError(error, 'Keylol.selectNone');
  9038. }
  9039. }
  9040. invertSelect() {
  9041. try {
  9042. $('.auto-task-keylol:visible').each((index, element) => {
  9043. element.getAttribute('selected') ? element.removeAttribute('selected') : element.setAttribute('selected', 'selected');
  9044. });
  9045. } catch (error) {
  9046. throwError(error, 'Keylol.invertSelect');
  9047. }
  9048. }
  9049. #addBtn(before, social, linkType, link) {
  9050. try {
  9051. $(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>`);
  9052. } catch (error) {
  9053. throwError(error, 'keylol.addBtn');
  9054. }
  9055. }
  9056. }
  9057. const website_Keylol = Keylol;
  9058. const Opquests_defaultTasks = {
  9059. steam: {
  9060. groupLinks: [],
  9061. wishlistLinks: [],
  9062. followLinks: [],
  9063. curatorLikeLinks: []
  9064. }
  9065. };
  9066. class Opquests extends website_Website {
  9067. name = 'Opquests';
  9068. undoneTasks = {
  9069. ...Opquests_defaultTasks
  9070. };
  9071. buttons = [ 'doTask', 'verifyTask', 'getKey' ];
  9072. static test() {
  9073. return window.location.host === 'opquests.com';
  9074. }
  9075. async before() {
  9076. try {
  9077. const opquestsVerifyTasks = GM_getValue('opquestsVerifyTasks') || [];
  9078. if (opquestsVerifyTasks.length > 0) {
  9079. const taskId = opquestsVerifyTasks.pop();
  9080. GM_setValue('opquestsVerifyTasks', opquestsVerifyTasks);
  9081. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9082. } else {
  9083. if (GM_getValue('opquestsVerifyTasks')) {
  9084. GM_deleteValue('opquestsVerifyTasks');
  9085. }
  9086. }
  9087. } catch (error) {
  9088. throwError(error, 'Opquests.before');
  9089. }
  9090. }
  9091. async after() {
  9092. try {
  9093. if (!this.#checkLogin()) {
  9094. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9095. }
  9096. } catch (error) {
  9097. throwError(error, 'Opquests.after');
  9098. }
  9099. }
  9100. init() {
  9101. try {
  9102. const logStatus = scripts_echoLog({
  9103. text: i18n('initing')
  9104. });
  9105. if ($('a[href*="/auth/redirect"]').length > 0) {
  9106. window.open('/auth/redirect', '_self');
  9107. logStatus.warning(i18n('needLogin'));
  9108. return false;
  9109. }
  9110. if (!this.#getGiveawayId()) {
  9111. return false;
  9112. }
  9113. this.initialized = true;
  9114. logStatus.success();
  9115. return true;
  9116. } catch (error) {
  9117. throwError(error, 'Opquests.init');
  9118. return false;
  9119. }
  9120. }
  9121. async classifyTask(action) {
  9122. try {
  9123. if (action === 'undo') {
  9124. scripts_echoLog({
  9125. text: i18n('cannotUndo')
  9126. });
  9127. return false;
  9128. }
  9129. const logStatus = scripts_echoLog({
  9130. text: i18n('getTasksInfo')
  9131. });
  9132. const tasks = $('.w-full:contains("Validate") .items-center');
  9133. for (const task of tasks) {
  9134. const link = $(task).find('a:contains("Open")').attr('href');
  9135. const taskDes = $(task).find('div').eq(1).text().trim();
  9136. if (!link) {
  9137. continue;
  9138. }
  9139. if (/steamcommunity\.com\/groups\//.test(link)) {
  9140. this.undoneTasks.steam.groupLinks.push(link);
  9141. } else if (/store\.steampowered\.com\/app\//.test(link)) {
  9142. if (/wishlist/gim.test(taskDes)) {
  9143. this.undoneTasks.steam.wishlistLinks.push(link);
  9144. } else if (/follow/gim.test(taskDes)) {
  9145. this.undoneTasks.steam.followLinks.push(link);
  9146. }
  9147. } else if (/store\.steampowered\.com\/(publisher|developer|curator)\//.test(link) && /follow/gim.test(taskDes)) {
  9148. this.undoneTasks.steam.curatorLikeLinks.push(link);
  9149. } else {
  9150. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  9151. }
  9152. }
  9153. logStatus.success();
  9154. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9155. if (window.DEBUG) {
  9156. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9157. }
  9158. return true;
  9159. } catch (error) {
  9160. throwError(error, 'Opquests.classifyTask');
  9161. return false;
  9162. }
  9163. }
  9164. async verifyTask() {
  9165. try {
  9166. if (!this.initialized) {
  9167. this.init();
  9168. }
  9169. const tasks = $.makeArray($('div.w-full').find('.items-center').has('button.submit-loader')).map(ele => $(ele).find('input[name="task_id"]').val());
  9170. await this.#confirm();
  9171. const taskId = tasks.pop();
  9172. GM_setValue('opquestsVerifyTasks', tasks);
  9173. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9174. return true;
  9175. } catch (error) {
  9176. throwError(error, 'Opquests.verifyTask');
  9177. return false;
  9178. }
  9179. }
  9180. async #confirm() {
  9181. try {
  9182. const logStatus = scripts_echoLog({
  9183. html: `<li>${i18n('confirmingTask')}...<font></font></li>`
  9184. });
  9185. const {
  9186. result,
  9187. statusText,
  9188. status,
  9189. data
  9190. } = await tools_httpRequest({
  9191. url: `https://opquests.com/quests/${this.giveawayId}?confirm=1`,
  9192. method: 'GET',
  9193. nochche: true,
  9194. headers: {
  9195. origin: 'https://opquests.com',
  9196. referer: `https://opquests.com/warning?id=${this.giveawayId}`
  9197. }
  9198. });
  9199. if (result === 'Success') {
  9200. if (data?.status === 200) {
  9201. logStatus.success();
  9202. return true;
  9203. }
  9204. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9205. return false;
  9206. }
  9207. logStatus.error(`${result}:${statusText}(${status})`);
  9208. return false;
  9209. } catch (error) {
  9210. throwError(error, 'Opquests.confirm');
  9211. return false;
  9212. }
  9213. }
  9214. async getKey(isButton) {
  9215. try {
  9216. const logStatus = scripts_echoLog({
  9217. text: i18n('gettingKey')
  9218. });
  9219. const {
  9220. result,
  9221. statusText,
  9222. status,
  9223. data
  9224. } = await tools_httpRequest({
  9225. url: 'https://opquests.com/keys',
  9226. method: 'GET'
  9227. });
  9228. if (result === 'Success') {
  9229. if (data?.responseText) {
  9230. const key = $(data?.responseText).find(`div.items-center:contains("${$('h1.font-bold').text().trim().replace(' Quest', '')}")`).find('div.font-bold').next().text();
  9231. if (!key) {
  9232. logStatus.error('Error: Key was not found');
  9233. if (isButton) {
  9234. window.open('https://opquests.com/keys', '_self');
  9235. }
  9236. return false;
  9237. }
  9238. logStatus.success();
  9239. scripts_echoLog({}).success(key);
  9240. return true;
  9241. }
  9242. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9243. return false;
  9244. }
  9245. logStatus.error(`${result}:${statusText}(${status})`);
  9246. return false;
  9247. } catch (error) {
  9248. throwError(error, 'Opquests.getGiveawayId');
  9249. return false;
  9250. }
  9251. }
  9252. #getGiveawayId() {
  9253. try {
  9254. const giveawayId = window.location.href.match(/quests\/([\d]+)/)?.[1];
  9255. if (giveawayId) {
  9256. this.giveawayId = giveawayId;
  9257. return true;
  9258. }
  9259. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  9260. return false;
  9261. } catch (error) {
  9262. throwError(error, 'Opquests.getGiveawayId');
  9263. return false;
  9264. }
  9265. }
  9266. #checkLogin() {
  9267. try {
  9268. if (!globalOptions.other.checkLogin) {
  9269. return true;
  9270. }
  9271. if ($('a[href*="/auth/redirect"]').length > 0) {
  9272. window.open('/auth/redirect', '_self');
  9273. }
  9274. return true;
  9275. } catch (error) {
  9276. throwError(error, 'Opquests.checkLogin');
  9277. return false;
  9278. }
  9279. }
  9280. }
  9281. const website_Opquests = Opquests;
  9282. const Gleam_defaultTasksTemplate = {
  9283. steam: {
  9284. groupLinks: [],
  9285. wishlistLinks: [],
  9286. followLinks: [],
  9287. curatorLinks: [],
  9288. curatorLikeLinks: []
  9289. },
  9290. twitter: {
  9291. userLinks: [],
  9292. retweetLinks: []
  9293. },
  9294. twitch: {
  9295. channelLinks: []
  9296. },
  9297. discord: {
  9298. serverLinks: []
  9299. },
  9300. youtube: {
  9301. channelLinks: []
  9302. },
  9303. extra: {
  9304. gleam: []
  9305. }
  9306. };
  9307. const Gleam_defaultTasks = JSON.stringify(Gleam_defaultTasksTemplate);
  9308. class Gleam extends website_Website {
  9309. name = 'Gleam';
  9310. undoneTasks = JSON.parse(Gleam_defaultTasks);
  9311. socialTasks = JSON.parse(Gleam_defaultTasks);
  9312. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  9313. static test() {
  9314. return window.location.host === 'gleam.io';
  9315. }
  9316. before() {
  9317. try {
  9318. unsafeWindow.confirm = () => {};
  9319. unsafeWindow.alert = () => {};
  9320. unsafeWindow.prompt = () => {};
  9321. } catch (error) {
  9322. throwError(error, 'Gleam.before');
  9323. }
  9324. }
  9325. async after() {
  9326. try {
  9327. if (window.location.search.includes('8b07d23f4bfa65f9')) {
  9328. const checkComplete = setInterval(() => {
  9329. if ($('.entry-content .entry-method i.fa-check').length > 0) {
  9330. clearInterval(checkComplete);
  9331. window.close();
  9332. }
  9333. });
  9334. for (const task of $('.entry-content .entry-method')) {
  9335. const taskInfo = $(task).find('.user-links');
  9336. const expandInfo = $(task).find('.expandable');
  9337. const aElements = expandInfo.find('a.btn,a:contains(Continue),button:contains(Continue)');
  9338. if (aElements.length > 0) {
  9339. for (const element of aElements) {
  9340. const $element = $(element);
  9341. const href = $element.attr('href');
  9342. $element.removeAttr('href')[0].click();
  9343. $element.attr('href', href);
  9344. await delay(1e3);
  9345. }
  9346. }
  9347. taskInfo[0].click();
  9348. await delay(1e3);
  9349. }
  9350. scripts_echoLog({}).warning(i18n('gleamTaskNotice'));
  9351. } else if (!await this.#checkLeftKey()) {
  9352. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  9353. }
  9354. } catch (error) {
  9355. throwError(error, 'Gleam.after');
  9356. }
  9357. }
  9358. init() {
  9359. try {
  9360. const logStatus = scripts_echoLog({
  9361. text: i18n('initing')
  9362. });
  9363. if (!this.#getGiveawayId()) {
  9364. return false;
  9365. }
  9366. this.initialized = true;
  9367. logStatus.success();
  9368. return true;
  9369. } catch (error) {
  9370. throwError(error, 'Gleam.init');
  9371. return false;
  9372. }
  9373. }
  9374. async classifyTask(action) {
  9375. try {
  9376. const logStatus = scripts_echoLog({
  9377. text: i18n('getTasksInfo')
  9378. });
  9379. if (action === 'undo') {
  9380. this.socialTasks = GM_getValue(`gleamTasks-${this.giveawayId}`)?.tasks || JSON.parse(Gleam_defaultTasks);
  9381. }
  9382. const tasks = $('.entry-content .entry-method');
  9383. for (const task of tasks) {
  9384. const $task = $(task);
  9385. if (action === 'do' && $task.find('i.fa-question').length === 0) {
  9386. continue;
  9387. }
  9388. const socialIcon = $task.find('.icon-wrapper i');
  9389. const taskInfo = $task.find('.user-links');
  9390. const taskText = taskInfo.text().trim();
  9391. const expandInfo = $task.find('.expandable');
  9392. const aElements = expandInfo.find('a.btn');
  9393. if (aElements.length > 0) {
  9394. for (const element of aElements) {
  9395. const $element = $(element);
  9396. const href = $element.attr('href');
  9397. $element.removeAttr('href')[0].click();
  9398. $element.attr('href', href);
  9399. }
  9400. }
  9401. if (socialIcon.hasClass('fa-twitter') || socialIcon.hasClass('fa-x-twitter')) {
  9402. const link = $task.find('a[href^="https://twitter.com/"],a[href^="https://x.com/"]').attr('href');
  9403. if (!link) {
  9404. continue;
  9405. }
  9406. if (/follow/gi.test(taskText)) {
  9407. if (action === 'undo') {
  9408. this.socialTasks.twitter.userLinks.push(link);
  9409. }
  9410. if (action === 'do') {
  9411. this.undoneTasks.twitter.userLinks.push(link);
  9412. }
  9413. } else if (/retweet/gim.test(taskText)) {
  9414. if (action === 'undo') {
  9415. this.socialTasks.twitter.retweetLinks.push(link);
  9416. }
  9417. if (action === 'do') {
  9418. this.undoneTasks.twitter.retweetLinks.push(link);
  9419. }
  9420. }
  9421. } else if (socialIcon.hasClass('fa-twitch')) {
  9422. if (/follow/gim.test(taskText)) {
  9423. const link = $task.find('a[href^="https://twitch.tv/"]').attr('href');
  9424. if (!link) {
  9425. continue;
  9426. }
  9427. if (action === 'undo') {
  9428. this.socialTasks.twitch.channelLinks.push(link);
  9429. }
  9430. if (action === 'do') {
  9431. this.undoneTasks.twitch.channelLinks.push(link);
  9432. }
  9433. }
  9434. } else if (socialIcon.hasClass('fa-discord')) {
  9435. if (/join/gim.test(taskText)) {
  9436. let link = $task.find('a[href^="https://discord.com/invite/"]').attr('href');
  9437. if (!link) {
  9438. const ggLink = $task.find('a[href^="https://discord.gg/"]').attr('href')?.match(/discord\.gg\/([^/]+)/)?.[1];
  9439. if (!ggLink) {
  9440. continue;
  9441. }
  9442. link = `https://discord.com/invite/${ggLink}`;
  9443. }
  9444. if (action === 'undo') {
  9445. this.socialTasks.discord.serverLinks.push(link);
  9446. }
  9447. if (action === 'do') {
  9448. this.undoneTasks.discord.serverLinks.push(link);
  9449. }
  9450. }
  9451. } else if (socialIcon.hasClass('fa-external-link-square-alt')) {
  9452. continue;
  9453. } else if (socialIcon.hasClass('fa-youtube')) {
  9454. if (/subscribe/gim.test(taskText)) {
  9455. const link = $task.find('a[href^="https://www.youtube.com/channel/"]').attr('href');
  9456. if (!link) {
  9457. continue;
  9458. }
  9459. if (action === 'undo') {
  9460. this.socialTasks.youtube.channelLinks.push(link);
  9461. }
  9462. if (action === 'do') {
  9463. this.undoneTasks.youtube.channelLinks.push(link);
  9464. }
  9465. }
  9466. } else if (socialIcon.attr('class')?.includes('steam')) {
  9467. if (/join.*group/gi.test(taskText)) {
  9468. const link = $task.find('a[href^="https://steamcommunity.com/groups/"]').attr('href');
  9469. if (!link) {
  9470. continue;
  9471. }
  9472. if (action === 'undo') {
  9473. this.socialTasks.steam.groupLinks.push(link);
  9474. }
  9475. if (action === 'do') {
  9476. this.undoneTasks.steam.groupLinks.push(link);
  9477. }
  9478. } else if (/follow.*curator/gi.test(taskText)) {
  9479. const link = $task.find('a[href^="https://store.steampowered.com/curator/"]').attr('href');
  9480. if (!link) {
  9481. continue;
  9482. }
  9483. if (action === 'undo') {
  9484. this.socialTasks.steam.curatorLinks.push(link);
  9485. }
  9486. if (action === 'do') {
  9487. this.undoneTasks.steam.curatorLinks.push(link);
  9488. }
  9489. }
  9490. } else if (socialIcon.hasClass('fa-bullhorn') && /Complete/gi.test(taskText)) {
  9491. if (action !== 'do') {
  9492. continue;
  9493. }
  9494. const gleamLink = await this.#getGleamLink(taskText);
  9495. if (!gleamLink) {
  9496. continue;
  9497. }
  9498. this.undoneTasks.extra.gleam.push(gleamLink);
  9499. } 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 {
  9500. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskText}`);
  9501. }
  9502. }
  9503. logStatus.success();
  9504. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9505. this.socialTasks = this.uniqueTasks(this.socialTasks);
  9506. if (window.DEBUG) {
  9507. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9508. }
  9509. GM_setValue(`gleamTasks-${this.giveawayId}`, {
  9510. tasks: this.socialTasks,
  9511. time: new Date().getTime()
  9512. });
  9513. return true;
  9514. } catch (error) {
  9515. throwError(error, 'Gleam.classifyTask');
  9516. return false;
  9517. }
  9518. }
  9519. async extraDoTask({
  9520. gleam
  9521. }) {
  9522. try {
  9523. const pro = [];
  9524. for (const link of gleam) {
  9525. pro.push(this.#doGleamTask(link));
  9526. }
  9527. return Promise.all(pro).then(() => true);
  9528. } catch (error) {
  9529. throwError(error, 'Gleam.extraDoTask');
  9530. return false;
  9531. }
  9532. }
  9533. async verifyTask() {
  9534. try {
  9535. scripts_echoLog({
  9536. text: `${i18n('verifyingTask')}...`
  9537. });
  9538. const tasks = $('.entry-content .entry-method');
  9539. unsafeWindow._OxA = '_OxA';
  9540. for (const task of tasks) {
  9541. if ($('[campaign-key="campaign.key"]').length > 0) {
  9542. return scripts_echoLog({
  9543. text: i18n('campaign')
  9544. });
  9545. }
  9546. const $task = $(task);
  9547. if ($task.find('i.fa-question').length === 0) {
  9548. continue;
  9549. }
  9550. const taskInfo = $task.find('.user-links');
  9551. taskInfo[0].click();
  9552. const aElements = $task.find('.expandable').find('a.btn');
  9553. if (aElements.length > 0) {
  9554. for (const element of aElements) {
  9555. const $element = $(element);
  9556. const href = $element.attr('href');
  9557. $element.removeAttr('href')[0].click();
  9558. $element.attr('href', href);
  9559. }
  9560. }
  9561. unsafeWindow.$hookTimer?.setSpeed(1e3);
  9562. const visitBtn = $task.find('.expandable').find('span:contains(more seconds),button:contains(more seconds)').filter(':visible');
  9563. if (visitBtn.length > 0) {
  9564. const newTab = GM_openInTab('', {
  9565. active: true
  9566. });
  9567. await delay(1e3);
  9568. newTab?.close();
  9569. }
  9570. await delay(3e3);
  9571. unsafeWindow.$hookTimer?.setSpeed(1);
  9572. const expandInfo = $task.find('.expandable');
  9573. const [ input ] = expandInfo.find('input');
  9574. if (input) {
  9575. const evt = new Event('input', {
  9576. bubbles: true,
  9577. cancelable: true,
  9578. composed: true
  9579. });
  9580. const valuelimit = [ ...expandInfo.text().matchAll(/"(.+?)"/g) ].at(-1)?.[1];
  9581. input.value = valuelimit || 'vloot';
  9582. input.dispatchEvent(evt);
  9583. await delay(1e3);
  9584. }
  9585. await this.#checkSync();
  9586. const continueBtn = $task.find('.expandable').find('span:contains(Continue),button:contains(Continue)');
  9587. for (const button of continueBtn) {
  9588. button.click();
  9589. await delay(500);
  9590. await this.#checkSync();
  9591. }
  9592. }
  9593. scripts_echoLog({
  9594. text: i18n('verifiedGleamTasks')
  9595. });
  9596. } catch (error) {
  9597. throwError(error, 'Gleam.verifyTask');
  9598. return false;
  9599. }
  9600. }
  9601. async #checkSync() {
  9602. try {
  9603. return await new Promise(resolve => {
  9604. const checker = setInterval(() => {
  9605. if ($('.entry-content .entry-method i.fa-sync').length === 0) {
  9606. clearInterval(checker);
  9607. resolve(true);
  9608. }
  9609. }, 500);
  9610. });
  9611. } catch (error) {
  9612. throwError(error, 'Gleam.checkSync');
  9613. return false;
  9614. }
  9615. }
  9616. async #doGleamTask(link) {
  9617. try {
  9618. const logStatus = scripts_echoLog({
  9619. text: i18n('doingGleamTask')
  9620. });
  9621. return await new Promise(resolve => {
  9622. GM_openInTab(`${link}?8b07d23f4bfa65f9`, {
  9623. active: true,
  9624. insert: true,
  9625. setParent: true
  9626. }).onclose = () => {
  9627. logStatus.success();
  9628. resolve(true);
  9629. };
  9630. });
  9631. } catch (error) {
  9632. throwError(error, 'Gleam.doGleamTask');
  9633. return false;
  9634. }
  9635. }
  9636. #getGiveawayId() {
  9637. try {
  9638. const giveawayId = window.location.pathname;
  9639. if (giveawayId) {
  9640. this.giveawayId = giveawayId;
  9641. return true;
  9642. }
  9643. scripts_echoLog({
  9644. text: i18n('getFailed', 'GiveawayId')
  9645. });
  9646. return false;
  9647. } catch (error) {
  9648. throwError(error, 'Gleam.getGiveawayId');
  9649. return false;
  9650. }
  9651. }
  9652. async #getGleamLink(title) {
  9653. try {
  9654. const logStatus = scripts_echoLog({
  9655. text: i18n('gettingGleamLink')
  9656. });
  9657. const {
  9658. result,
  9659. statusText,
  9660. status,
  9661. data
  9662. } = await tools_httpRequest({
  9663. url: 'https://www.vloot.io/api/v1/giveaways',
  9664. method: 'GET',
  9665. responseType: 'json'
  9666. });
  9667. if (result === 'Success') {
  9668. if (data?.status === 200 && data?.response?.Success === true && data?.response?.Data) {
  9669. const {
  9670. link
  9671. } = data.response.Data.find(giveaway => title.replace(/[\s]/g, '').toLowerCase().includes(giveaway.title.replace(/[\s]/g, '').toLowerCase())) || {};
  9672. if (link) {
  9673. logStatus.success();
  9674. return link;
  9675. }
  9676. logStatus.error(`Error:${i18n('getLinkFailed')}`);
  9677. return false;
  9678. }
  9679. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9680. return false;
  9681. }
  9682. logStatus.error(`${result}:${statusText}(${status})`);
  9683. return false;
  9684. } catch (error) {
  9685. throwError(error, 'Gleam.getGleamLink');
  9686. return false;
  9687. }
  9688. }
  9689. async #checkLeftKey() {
  9690. try {
  9691. if (!globalOptions.other.checkLeftKey) {
  9692. return true;
  9693. }
  9694. const campaignString = $('div.popup-blocks-container').attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  9695. if (!campaignString) {
  9696. return false;
  9697. }
  9698. const {
  9699. campaign,
  9700. incentive
  9701. } = JSON.parse(campaignString);
  9702. const controllerString = $('div.campaign.reward').attr('ng-init')?.match(/initContestant\(([\w\W]+?)\);/)?.[1];
  9703. let ownedKey = false;
  9704. if (controllerString) {
  9705. if (JSON.parse(controllerString).contestant?.claims?.incentives?.[incentive.id]?.length) {
  9706. ownedKey = true;
  9707. }
  9708. }
  9709. if (campaign.banned || campaign.finished && !ownedKey || campaign.paused || new Date().getTime() < campaign.starts_at * 1e3) {
  9710. await external_Swal_default().fire({
  9711. icon: 'warning',
  9712. title: i18n('notice'),
  9713. text: i18n('giveawayNotWork'),
  9714. confirmButtonText: i18n('confirm'),
  9715. cancelButtonText: i18n('cancel'),
  9716. showCancelButton: true
  9717. }).then(({
  9718. value
  9719. }) => {
  9720. if (value) {
  9721. window.close();
  9722. }
  9723. });
  9724. }
  9725. return true;
  9726. } catch (error) {
  9727. throwError(error, 'Gleam.checkLeftKey');
  9728. return false;
  9729. }
  9730. }
  9731. }
  9732. const website_Gleam = Gleam;
  9733. const SweepWidget_defaultOptions = {
  9734. username: '',
  9735. email: ''
  9736. };
  9737. class SweepWidget extends website_Website {
  9738. name = 'SweepWidget';
  9739. options = {
  9740. ...SweepWidget_defaultOptions,
  9741. ...GM_getValue('SweepWidgetOptions')
  9742. };
  9743. buttons = [ 'doTask' ];
  9744. static test() {
  9745. return /^https?:\/\/sweepwidget\.com\/view\/[\d]+/.test(window.location.href);
  9746. }
  9747. async after() {
  9748. try {
  9749. if (!this.#checkLogin()) {
  9750. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9751. }
  9752. } catch (error) {
  9753. throwError(error, 'SweepWidget.after');
  9754. }
  9755. }
  9756. init() {
  9757. try {
  9758. const logStatus = scripts_echoLog({
  9759. text: i18n('initing')
  9760. });
  9761. if (!this.#checkLogin()) {
  9762. logStatus.warning(i18n('needLogin'));
  9763. return false;
  9764. }
  9765. if (!this.#getGiveawayId()) {
  9766. return false;
  9767. }
  9768. this.initialized = true;
  9769. logStatus.success();
  9770. return true;
  9771. } catch (error) {
  9772. throwError(error, 'SweepWidget.init');
  9773. return false;
  9774. }
  9775. }
  9776. classifyTask() {
  9777. return true;
  9778. }
  9779. async doTask() {
  9780. try {
  9781. if ($('#unlock_rewards_main_wrapper').length === 0) {
  9782. if ($('input[name="sw__login_name"]:visible').length > 0) {
  9783. $('input[name="sw__login_name"]').val(this.options.username);
  9784. }
  9785. if ($('input[name="sw__login_email"]:visible').length > 0) {
  9786. $('input[name="sw__login_email"]').val(this.options.email);
  9787. }
  9788. if ($('#sw_login_button:visible').length > 0) {
  9789. $('#sw_login_button')[0].click();
  9790. }
  9791. if (!await this.#checkEnter()) {
  9792. return false;
  9793. }
  9794. }
  9795. const logStatus = scripts_echoLog({
  9796. text: i18n('SweepWidgetNotice')
  9797. });
  9798. const tasks = $('#sw_inner_entry_methods_l2_wrapper>div.sw_entry');
  9799. for (const task of tasks) {
  9800. const $task = $(task);
  9801. if ($task.find('i.fa-check:visible').length > 0) {
  9802. continue;
  9803. }
  9804. const title = $task.find('.sw_text_inner');
  9805. title[0].click();
  9806. const aElement = $task.find('a.sw_link');
  9807. const link = aElement.attr('href');
  9808. aElement.attr('href', '#a').attr('target', '_self');
  9809. aElement[0]?.click();
  9810. await delay(300);
  9811. aElement.attr('href', link).attr('target', '_blank');
  9812. $task.find('input[type="text"]').val('test');
  9813. const verifyBtn = $task.find('input.sw_verify');
  9814. if (verifyBtn.prop('disabled') === true) {
  9815. title[0].click();
  9816. await delay(300);
  9817. title[0].click();
  9818. await delay(300);
  9819. }
  9820. $task.find('input.sw_verify').removeAttr('disabled')[0]?.click();
  9821. await this.#checkFinish($task);
  9822. await delay(parseInt(`${Math.random() * (3e3 - 1e3 + 1) + 1e3}`, 10));
  9823. }
  9824. logStatus.success();
  9825. return true;
  9826. } catch (error) {
  9827. throwError(error, 'SweepWidget.doTask');
  9828. return false;
  9829. }
  9830. }
  9831. #checkLogin() {
  9832. try {
  9833. if ($('#twitter_login_button').length > 0) {
  9834. $('#twitter_login_button')[0].click();
  9835. }
  9836. return true;
  9837. } catch (error) {
  9838. throwError(error, 'SweepWidget.checkLogin');
  9839. return false;
  9840. }
  9841. }
  9842. #getGiveawayId() {
  9843. try {
  9844. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  9845. if (giveawayId) {
  9846. this.giveawayId = giveawayId;
  9847. return true;
  9848. }
  9849. scripts_echoLog({
  9850. text: i18n('getFailed', 'GiveawayId')
  9851. });
  9852. return false;
  9853. } catch (error) {
  9854. throwError(error, 'SweepWidget.getGiveawayId');
  9855. return false;
  9856. }
  9857. }
  9858. async #checkEnter() {
  9859. try {
  9860. return new Promise(resolve => {
  9861. const checker = setInterval(() => {
  9862. if ($('#unlock_rewards_main_wrapper').length > 0) {
  9863. clearInterval(checker);
  9864. resolve(true);
  9865. }
  9866. }, 500);
  9867. });
  9868. } catch (error) {
  9869. throwError(error, 'SweepWidget.checkEnter');
  9870. return false;
  9871. }
  9872. }
  9873. async #checkFinish($task) {
  9874. try {
  9875. return new Promise(resolve => {
  9876. const checker = setInterval(() => {
  9877. if ($task.find('i.fa-check:visible').length > 0 || $task.find('.sw_entry_input:visible').length === 0) {
  9878. clearInterval(checker);
  9879. resolve(true);
  9880. }
  9881. }, 500);
  9882. });
  9883. } catch (error) {
  9884. throwError(error, 'SweepWidget.checkFinish');
  9885. return false;
  9886. }
  9887. }
  9888. }
  9889. const website_SweepWidget = SweepWidget;
  9890. const defaultWhiteList = {
  9891. discord: {
  9892. servers: []
  9893. },
  9894. instagram: {
  9895. users: []
  9896. },
  9897. twitch: {
  9898. channels: []
  9899. },
  9900. twitter: {
  9901. users: [],
  9902. retweets: [],
  9903. likes: []
  9904. },
  9905. vk: {
  9906. names: []
  9907. },
  9908. youtube: {
  9909. channels: [],
  9910. likes: []
  9911. },
  9912. reddit: {
  9913. reddits: []
  9914. },
  9915. steam: {
  9916. groups: [],
  9917. officialGroups: [],
  9918. wishlists: [],
  9919. follows: [],
  9920. forums: [],
  9921. workshops: [],
  9922. curators: [],
  9923. workshopVotes: [],
  9924. curatorLikes: [],
  9925. announcements: [],
  9926. licenses: [],
  9927. playtests: []
  9928. }
  9929. };
  9930. const link2id = async function(type) {
  9931. try {
  9932. const link = $('#socialLink').val();
  9933. let id = '';
  9934. switch (type) {
  9935. case 'discord.servers':
  9936. id = link.match(/invite\/(.+)/)?.[1] || '';
  9937. break;
  9938.  
  9939. case 'instagram.users':
  9940. id = link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1] || '';
  9941. break;
  9942.  
  9943. case 'twitch.channels':
  9944. id = link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2] || '';
  9945. break;
  9946.  
  9947. case 'twitter.users':
  9948. id = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || '';
  9949. break;
  9950.  
  9951. case 'twitter.retweets':
  9952. id = link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1] || '';
  9953. break;
  9954.  
  9955. case 'vk.names':
  9956. id = link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1] || '';
  9957. break;
  9958.  
  9959. case 'youtube.channels':
  9960. id = (await getInfo(link, 'channel'))?.params?.channelId || '';
  9961. break;
  9962.  
  9963. case 'youtube.likes':
  9964. id = (await getInfo(link, 'likeVideo'))?.params?.videoId || '';
  9965. break;
  9966.  
  9967. case 'reddit.reddits':
  9968. id = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1] || link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1] || '';
  9969. break;
  9970.  
  9971. case 'steam.groups':
  9972. id = link.match(/groups\/(.+)\/?/)?.[1] || '';
  9973. break;
  9974.  
  9975. case 'steam.wishlists':
  9976. case 'steam.follows':
  9977. case 'steam.forums':
  9978. id = link.match(/app\/([\d]+)/)?.[1] || '';
  9979. break;
  9980.  
  9981. case 'steam.workshops':
  9982. id = link.match(/\?id=([\d]+)/)?.[1] || '';
  9983. break;
  9984.  
  9985. case 'steam.curators':
  9986. {
  9987. if (link.includes('curator')) {
  9988. id = link.match(/curator\/([\d]+)/)?.[1] || '';
  9989. } else {
  9990. const param = link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3);
  9991. if (!param || param.length !== 2) {
  9992. break;
  9993. }
  9994. const steam = new social_Steam();
  9995. if (await steam.init()) {
  9996. id = await steam.getCuratorId(param[0], param[1]) || '';
  9997. }
  9998. }
  9999. }
  10000. break;
  10001. }
  10002. return id;
  10003. } catch (error) {
  10004. throwError(error, 'link2id');
  10005. return i18n('getFailed', 'id');
  10006. }
  10007. };
  10008. const disabledType = {
  10009. steam: [ 'workshopVotes', 'curatorLikes', 'announcements' ],
  10010. twitter: [ 'likes' ]
  10011. };
  10012. const assignWhiteList = whiteList => {
  10013. try {
  10014. const newWhiteList = {};
  10015. for (const [ key, value ] of Object.entries(defaultWhiteList)) {
  10016. newWhiteList[key] = {
  10017. ...value,
  10018. ...whiteList[key]
  10019. };
  10020. }
  10021. return newWhiteList;
  10022. } catch (error) {
  10023. throwError(error, 'assignWhiteList');
  10024. return defaultWhiteList;
  10025. }
  10026. };
  10027. const whiteListOptions = function(showType) {
  10028. try {
  10029. const whiteList = assignWhiteList(GM_getValue('whiteList') || {});
  10030. let whiteListOptionsForm = `<form id="whiteListForm" class="auto-task-form">
  10031. <table class="auto-task-table"><thead><tr><td>${i18n('website')}</td><td>${i18n('type')}</td><td>${i18n('edit')}</td></tr></thead><tbody>`;
  10032. for (const [ social, types ] of Object.entries(whiteList)) {
  10033. 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('');
  10034. }
  10035. whiteListOptionsForm += '</tbody></table></form>';
  10036. if (showType === 'swal') {
  10037. external_Swal_default().fire({
  10038. title: i18n('whiteListOptions'),
  10039. html: whiteListOptionsForm,
  10040. showConfirmButton: false,
  10041. showCloseButton: true
  10042. });
  10043. } else {
  10044. $('body').append(`<h2>${i18n('whiteList')}</h2>${whiteListOptionsForm}`);
  10045. }
  10046. $('.editWhiteList').on('click', function() {
  10047. const value = $(this).attr('data-value');
  10048. if (!value) {
  10049. return;
  10050. }
  10051. const [ social, type ] = value.split('.');
  10052. if (!whiteList?.[social]?.[type]) {
  10053. scripts_echoLog({}).warning(i18n('whiteListNotFound', value));
  10054. return;
  10055. }
  10056. external_Swal_default().fire({
  10057. title: i18n('changeWhiteListOption', value),
  10058. input: 'textarea',
  10059. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10060. <button id="link2id" data-type="${value}" class="swal2-confirm swal2-styled">获取id</button>
  10061. <p style="margin-bottom:0 !important;">在下方填写白名单,每行一个</p>`,
  10062. inputValue: whiteList[social][type].join('\n'),
  10063. showConfirmButton: true,
  10064. confirmButtonText: i18n('save'),
  10065. showCancelButton: true,
  10066. cancelButtonText: i18n('close'),
  10067. showDenyButton: true,
  10068. denyButtonText: i18n('return')
  10069. }).then(({
  10070. isDenied,
  10071. isConfirmed,
  10072. value
  10073. }) => {
  10074. if (isDenied) {
  10075. if (showType === 'swal') {
  10076. whiteListOptions(showType);
  10077. }
  10078. return;
  10079. } else if (isConfirmed) {
  10080. whiteList[social][type] = value.split('\n');
  10081. GM_setValue('whiteList', whiteList);
  10082. external_Swal_default().fire({
  10083. title: i18n('changeWhiteListSuccess'),
  10084. icon: 'success'
  10085. });
  10086. }
  10087. });
  10088. $('#link2id').on('click', async function() {
  10089. const type = $(this).attr('data-type');
  10090. $('#socialLink').val(await link2id(type));
  10091. });
  10092. });
  10093. } catch (error) {
  10094. throwError(error, 'whiteListOptions');
  10095. }
  10096. };
  10097. const whiteList = whiteListOptions;
  10098. const setGistData = async (token, gistId, fileName, content) => {
  10099. try {
  10100. const logStatus = scripts_echoLog({
  10101. text: i18n('settingData')
  10102. });
  10103. const contentData = JSON.stringify({
  10104. files: {
  10105. [fileName]: {
  10106. content: JSON.stringify(content)
  10107. }
  10108. }
  10109. });
  10110. const {
  10111. result,
  10112. statusText,
  10113. status,
  10114. data
  10115. } = await tools_httpRequest({
  10116. url: `https://api.github.com/gists/${gistId}`,
  10117. headers: {
  10118. Accept: 'application/vnd.github.v3+json',
  10119. Authorization: `token ${token}`
  10120. },
  10121. data: contentData,
  10122. responseType: 'json',
  10123. method: 'POST',
  10124. timeout: 3e4
  10125. });
  10126. if (result === 'Success') {
  10127. if (data?.status === 200 && data.response.files?.[fileName]?.content === JSON.stringify(content)) {
  10128. logStatus.success();
  10129. return true;
  10130. }
  10131. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10132. return false;
  10133. }
  10134. logStatus.error(`${result}:${statusText}(${status})`);
  10135. return false;
  10136. } catch (error) {
  10137. throwError(error, 'setGistData');
  10138. return false;
  10139. }
  10140. };
  10141. const getGistData = async (token, gistId, fileName, test = false) => {
  10142. try {
  10143. const logStatus = scripts_echoLog({
  10144. text: i18n('gettingData')
  10145. });
  10146. const {
  10147. result,
  10148. statusText,
  10149. status,
  10150. data
  10151. } = await tools_httpRequest({
  10152. url: `https://api.github.com/gists/${gistId}`,
  10153. headers: {
  10154. Accept: 'application/vnd.github.v3+json',
  10155. Authorization: `token ${token}`
  10156. },
  10157. responseType: 'json',
  10158. method: 'GET',
  10159. timeout: 3e4
  10160. });
  10161. if (result === 'Success') {
  10162. if (data?.status === 200) {
  10163. const content = data.response?.files?.[fileName]?.content;
  10164. let formatedContent;
  10165. if (!content) {
  10166. logStatus.error(`Error:${i18n('noRemoteData')}`);
  10167. return false;
  10168. }
  10169. if (test) {
  10170. logStatus.success();
  10171. return true;
  10172. }
  10173. try {
  10174. formatedContent = JSON.parse(content);
  10175. } catch (error) {
  10176. logStatus.error(`Error:${i18n('errorRemoteDataFormat')}`);
  10177. return false;
  10178. }
  10179. logStatus.success();
  10180. return formatedContent;
  10181. }
  10182. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10183. return false;
  10184. }
  10185. logStatus.error(`${result}:${statusText}(${status})`);
  10186. return false;
  10187. } catch (error) {
  10188. throwError(error, 'getGistData');
  10189. return false;
  10190. }
  10191. };
  10192. const syncOptions = () => {
  10193. try {
  10194. const {
  10195. TOKEN,
  10196. GIST_ID,
  10197. FILE_NAME,
  10198. SYNC_HISTORY
  10199. } = GM_getValue('gistOptions') || {
  10200. TOKEN: '',
  10201. GIST_ID: '',
  10202. FILE_NAME: '',
  10203. SYNC_HISTORY: true
  10204. };
  10205. external_Swal_default().fire({
  10206. title: i18n('gistOptions'),
  10207. 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;">
  10208. ${i18n('upload2gist')}</button>` + `<button id="download-data" type="button" class="swal2-confirm swal2-styled" style="display: inline-block;">
  10209. ${i18n('downloadFromGist')}</button></p>`,
  10210. focusConfirm: false,
  10211. showLoaderOnConfirm: true,
  10212. 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>`,
  10213. preConfirm: async () => {
  10214. const token = $('#github-token').val();
  10215. const gistId = $('#gist-id').val();
  10216. const fileName = $('#file-name').val();
  10217. const syncHistory = $('#sync-history').prop('checked');
  10218. GM_setValue('gistOptions', {
  10219. TOKEN: token,
  10220. GIST_ID: gistId,
  10221. FILE_NAME: fileName,
  10222. SYNC_HISTORY: syncHistory
  10223. });
  10224. return await getGistData(token, gistId, fileName, true);
  10225. },
  10226. allowOutsideClick: () => !external_Swal_default().isLoading(),
  10227. confirmButtonText: i18n('saveAndTest'),
  10228. showCancelButton: true,
  10229. cancelButtonText: i18n('close')
  10230. }).then(({
  10231. value
  10232. }) => {
  10233. if (value) {
  10234. external_Swal_default().fire({
  10235. icon: 'success',
  10236. title: i18n('testSuccess')
  10237. }).then(syncOptions);
  10238. } else if (value !== undefined) {
  10239. external_Swal_default().fire({
  10240. icon: 'error',
  10241. title: i18n('testFailed')
  10242. }).then(syncOptions);
  10243. }
  10244. });
  10245. $('#upload-data').on('click', async () => {
  10246. const {
  10247. TOKEN,
  10248. GIST_ID,
  10249. FILE_NAME
  10250. } = GM_getValue('gistOptions') || {};
  10251. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10252. return external_Swal_default().fire({
  10253. icon: 'error',
  10254. title: i18n('saveAndTestNotice')
  10255. }).then(syncOptions);
  10256. }
  10257. external_Swal_default().fire({
  10258. icon: 'info',
  10259. title: i18n('processingData')
  10260. });
  10261. const data = {};
  10262. const names = GM_listValues();
  10263. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10264. for (const name of names) {
  10265. if (name === 'gistOptions' || /^[\w]+?Auth$/.test(name)) {
  10266. continue;
  10267. }
  10268. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10269. continue;
  10270. }
  10271. data[name] = GM_getValue(name);
  10272. }
  10273. external_Swal_default().update({
  10274. icon: 'info',
  10275. title: i18n('updatingData')
  10276. });
  10277. if (await setGistData(TOKEN, GIST_ID, FILE_NAME, data)) {
  10278. external_Swal_default().fire({
  10279. icon: 'success',
  10280. title: i18n('syncDataSuccess')
  10281. });
  10282. } else {
  10283. external_Swal_default().fire({
  10284. icon: 'error',
  10285. title: i18n('syncDataFailed')
  10286. });
  10287. }
  10288. });
  10289. $('#download-data').on('click', async () => {
  10290. const {
  10291. TOKEN,
  10292. GIST_ID,
  10293. FILE_NAME
  10294. } = GM_getValue('gistOptions') || {};
  10295. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10296. return external_Swal_default().fire({
  10297. icon: 'error',
  10298. title: i18n('saveAndTestNotice')
  10299. }).then(syncOptions);
  10300. }
  10301. external_Swal_default().fire({
  10302. icon: 'info',
  10303. title: i18n('downloadingData')
  10304. });
  10305. const data = await getGistData(TOKEN, GIST_ID, FILE_NAME);
  10306. if (!data) {
  10307. return external_Swal_default().fire({
  10308. icon: 'error',
  10309. title: i18n('checkedNoData')
  10310. }).then(syncOptions);
  10311. }
  10312. external_Swal_default().update({
  10313. icon: 'info',
  10314. title: i18n('savingData')
  10315. });
  10316. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10317. for (const [ name, value ] of Object.entries(data)) {
  10318. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10319. continue;
  10320. }
  10321. GM_setValue(name, value);
  10322. }
  10323. external_Swal_default().fire({
  10324. icon: 'success',
  10325. title: i18n('syncDataSuccess')
  10326. });
  10327. });
  10328. } catch (error) {
  10329. throwError(error, 'syncOptions');
  10330. }
  10331. };
  10332. const dataSync = syncOptions;
  10333. class Setting {
  10334. name = 'Setting';
  10335. buttons = [ 'saveGlobalOptions', 'syncData', 'tasksHistory' ];
  10336. syncData = dataSync;
  10337. tasksHistory() {
  10338. GM_openInTab('https://auto-task-v4.hclonely.com/history.html', {
  10339. active: true
  10340. });
  10341. }
  10342. static test() {
  10343. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/setting.html';
  10344. }
  10345. before() {
  10346. try {
  10347. $('body').html('').addClass('auto-task-options');
  10348. } catch (error) {
  10349. throwError(error, 'Setting.before');
  10350. }
  10351. }
  10352. after() {
  10353. try {
  10354. this.#environment();
  10355. changeGlobalOptions('page');
  10356. whiteList('page');
  10357. $('input[name="other.twitterVerifyId"]').after(`<button id="getTwitterUserId" type="button">${i18n('getTwitterUserId')}</button>`);
  10358. $('#getTwitterUserId').on('click', () => {
  10359. this.#getId('twitterUser');
  10360. });
  10361. $('input[name="other.youtubeVerifyChannel"]').after(`<button id="getYoutubeChannelId" type="button">${i18n('getYoutubeChannelId')}</button>`);
  10362. $('#getYoutubeChannelId').on('click', () => {
  10363. this.#getId('youtubeChannel');
  10364. });
  10365. $('input[name^="position"]').on('input', function() {
  10366. const type = $(this).attr('name').replace('position.', '');
  10367. const xLabel = 'rightleft';
  10368. const yLabel = 'topbottpm';
  10369. switch (type) {
  10370. case 'buttonSideX':
  10371. case 'buttonSideY':
  10372. case 'buttonDistance':
  10373. {
  10374. const distance = $('input[name="position.buttonDistance"]').val();
  10375. const sideX = $('input[name="position.buttonSideX"]').val();
  10376. const sideY = $('input[name="position.buttonSideY"]').val();
  10377. if (![ 'right', 'left' ].includes(sideX)) {
  10378. break;
  10379. }
  10380. if (![ 'top', 'bottom' ].includes(sideY)) {
  10381. break;
  10382. }
  10383. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10384. break;
  10385. }
  10386. const distanceArr = distance.split(',');
  10387. $('#auto-task-buttons').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10388. break;
  10389. }
  10390.  
  10391. case 'showButtonSideX':
  10392. case 'showButtonSideY':
  10393. case 'showButtonDistance':
  10394. {
  10395. const distance = $('input[name="position.showButtonDistance"]').val();
  10396. const sideX = $('input[name="position.showButtonSideX"]').val();
  10397. const sideY = $('input[name="position.showButtonSideY"]').val();
  10398. if (![ 'right', 'left' ].includes(sideX)) {
  10399. break;
  10400. }
  10401. if (![ 'top', 'bottom' ].includes(sideY)) {
  10402. break;
  10403. }
  10404. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10405. break;
  10406. }
  10407. const distanceArr = distance.split(',');
  10408. $('div.show-button-div').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10409. break;
  10410. }
  10411.  
  10412. case 'logSideX':
  10413. case 'logSideY':
  10414. case 'logDistance':
  10415. {
  10416. const distance = $('input[name="position.logDistance"]').val();
  10417. const sideX = $('input[name="position.logSideX"]').val();
  10418. const sideY = $('input[name="position.logSideY"]').val();
  10419. if (![ 'right', 'left' ].includes(sideX)) {
  10420. break;
  10421. }
  10422. if (![ 'top', 'bottom' ].includes(sideY)) {
  10423. break;
  10424. }
  10425. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10426. break;
  10427. }
  10428. const distanceArr = distance.split(',');
  10429. $('#auto-task-info').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10430. break;
  10431. }
  10432.  
  10433. default:
  10434. break;
  10435. }
  10436. });
  10437. $('input[name^="hotKey"]').attr('readonly', 'readonly').off('keydown').on('keydown', function(event) {
  10438. let functionKey = '';
  10439. if (event.altKey) {
  10440. functionKey += 'alt + ';
  10441. } else if (event.ctrlKey) {
  10442. functionKey += 'ctrl + ';
  10443. } else if (event.shiftKey) {
  10444. functionKey += 'shift + ';
  10445. }
  10446. $(this).val(functionKey + (event.key.length === 1 ? event.key.toLowerCase() : ''));
  10447. });
  10448. } catch (error) {
  10449. throwError(error, 'Setting.after');
  10450. }
  10451. }
  10452. saveGlobalOptions() {
  10453. try {
  10454. saveData();
  10455. } catch (error) {
  10456. throwError(error, 'Setting.saveGlobalOptions');
  10457. }
  10458. }
  10459. #getId(social) {
  10460. try {
  10461. external_Swal_default().fire({
  10462. title: i18n('getId', i18n(social)),
  10463. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10464. <button id="link2id" data-type="${social}" class="swal2-confirm swal2-styled">获取id</button>`,
  10465. showCancelButton: true,
  10466. cancelButtonText: i18n('close'),
  10467. showConfirmButton: false
  10468. });
  10469. $('#link2id').on('click', async function() {
  10470. const link = $('#socialLink').val();
  10471. if (!link) {
  10472. return;
  10473. }
  10474. const type = $(this).attr('data-type');
  10475. if (type === 'twitterUser') {
  10476. const name = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || link;
  10477. $('#socialLink').val(await new social_Twitter().userName2id(name) || '');
  10478. } else if (type === 'youtubeChannel') {
  10479. const name = /^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www.youtube.com\/.*/.test(link) ? link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1] : link;
  10480. $('#socialLink').val((await getInfo(name, 'channel'))?.params?.channelId || '');
  10481. }
  10482. });
  10483. } catch (error) {
  10484. throwError(error, 'Setting.getId');
  10485. }
  10486. }
  10487. #environment() {
  10488. try {
  10489. const userAgent = (0, javascript_utils_umd_min.ua)();
  10490. const environmentForm = `<form id="environmentForm" class="auto-task-form">
  10491. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('name')}</td><td>${i18n('version')}</td></tr></thead><tbody>
  10492. <tr><td>${i18n('os')}</td><td>${userAgent.os}</td><td>${userAgent.osVersion}</td></tr>
  10493. <tr><td>${i18n('browser')}</td><td>${userAgent.browserZH}</td><td>${userAgent.browserVersion}</td></tr>
  10494. <tr><td>${i18n('scriptManager')}</td><td>${GM_info.scriptHandler}</td><td>${GM_info.version}</td></tr>
  10495. <tr><td>${i18n('script')}</td><td>${GM_info.script.name}</td><td>${GM_info.script.version}</td></tr>
  10496. </tbody></table></form>`;
  10497. $('body').append(`<h2>${i18n('environment')}</h2>${environmentForm}`);
  10498. } catch (error) {
  10499. throwError(error, 'Setting.environment');
  10500. }
  10501. }
  10502. }
  10503. const website_Setting = Setting;
  10504. class History extends website_Keylol {
  10505. name = 'History';
  10506. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect', 'clearHistory' ];
  10507. static test() {
  10508. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/history.html';
  10509. }
  10510. before() {
  10511. try {
  10512. $('body').html('<div class="container"></div>').addClass('auto-task-history');
  10513. const data = GM_listValues() || [];
  10514. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10515. for (const item of tasksHistory) {
  10516. this.#addItem(item);
  10517. }
  10518. } catch (error) {
  10519. throwError(error, 'History.before');
  10520. }
  10521. }
  10522. clearHistory() {
  10523. try {
  10524. const data = GM_listValues() || [];
  10525. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10526. for (const item of tasksHistory) {
  10527. GM_deleteValue(item);
  10528. }
  10529. external_Swal_default().fire({
  10530. title: i18n('clearHistoryFinished'),
  10531. icon: 'success'
  10532. });
  10533. } catch (error) {
  10534. throwError(error, 'History.clearHistory');
  10535. }
  10536. }
  10537. #addItem(item) {
  10538. try {
  10539. const tasksData = GM_getValue(item);
  10540. if (!tasksData?.tasks) {
  10541. return;
  10542. }
  10543. let html = '';
  10544. let title = '';
  10545. let link = '';
  10546. const [ website, id ] = item.split('-');
  10547. switch (website) {
  10548. case 'fawTasks':
  10549. title = `Freeanywhere[${id}]`;
  10550. link = `https://freeanywhere.net/#/giveaway/${id}`;
  10551. break;
  10552.  
  10553. case 'gasTasks':
  10554. title = `Giveawaysu[${id}]`;
  10555. link = `https://giveaway.su/giveaway/view/${id}`;
  10556. break;
  10557.  
  10558. case 'gcTasks':
  10559. title = `GiveeClub[${id}]`;
  10560. link = `https://givee.club/event/${id}`;
  10561. break;
  10562.  
  10563. case 'gkTasks':
  10564. title = `Givekey[${id}]`;
  10565. link = `https://givekey.ru/giveaway/${id}`;
  10566. break;
  10567.  
  10568. case 'gleamTasks':
  10569. title = `Gleam[${id}]`;
  10570. link = `https://gleam.io${id}`;
  10571. break;
  10572.  
  10573. case 'khTasks':
  10574. title = `keyhub[${id}]`;
  10575. link = `https://key-hub.eu/giveaway/${id}`;
  10576. break;
  10577.  
  10578. case 'prysTasks':
  10579. title = `Prys[${id}]`;
  10580. link = `https://prys.revadike.com/giveaway/?id=${id}`;
  10581. break;
  10582.  
  10583. default:
  10584. return;
  10585. }
  10586. for (const [ social, types ] of Object.entries(tasksData.tasks)) {
  10587. for (const [ type, tasks ] of Object.entries(types)) {
  10588. for (const task of tasks) {
  10589. 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>`;
  10590. }
  10591. }
  10592. }
  10593. $('.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>`);
  10594. $('span.delete-task').on('click', function() {
  10595. const itemName = $(this).attr('data-name');
  10596. if (itemName) {
  10597. GM_deleteValue(itemName);
  10598. $(`div.card[data-name="${itemName}"]`).remove();
  10599. external_Swal_default().fire({
  10600. title: i18n('clearTaskFinished'),
  10601. text: itemName,
  10602. icon: 'success'
  10603. });
  10604. } else {
  10605. external_Swal_default().fire({
  10606. title: i18n('clearTaskFailed'),
  10607. icon: 'error'
  10608. });
  10609. }
  10610. });
  10611. } catch (error) {
  10612. throwError(error, 'History.addItem');
  10613. }
  10614. }
  10615. }
  10616. const website_History = History;
  10617. 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 ];
  10618. const websiteOptions = function(website, options) {
  10619. try {
  10620. let websiteOptionsForm = `<form id="websiteOptionsForm" class="auto-task-form">
  10621. <table class="auto-task-table"><thead><tr><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  10622. for (const [ option, value ] of Object.entries(options)) {
  10623. websiteOptionsForm += `<tr><td>${option}</td><td><input class="editOption" type="text" name="${option}" value="${value}"/></td></tr>`;
  10624. }
  10625. websiteOptionsForm += '</tbody></table></form>';
  10626. external_Swal_default().fire({
  10627. title: i18n('websiteOptions'),
  10628. html: websiteOptionsForm,
  10629. showConfirmButton: true,
  10630. confirmButtonText: i18n('save'),
  10631. showCancelButton: true,
  10632. cancelButtonText: i18n('close')
  10633. }).then(({
  10634. isConfirmed
  10635. }) => {
  10636. if (isConfirmed) {
  10637. $('#websiteOptionsForm').serializeArray().map(value => {
  10638. options[value.name] = value.value;
  10639. return value;
  10640. });
  10641. GM_setValue(`${website}Options`, options);
  10642. external_Swal_default().fire({
  10643. title: i18n('changeWebsiteOptionsSuccess'),
  10644. icon: 'success'
  10645. });
  10646. }
  10647. });
  10648. } catch (error) {
  10649. throwError(error, 'websiteOptions');
  10650. }
  10651. };
  10652. const options = websiteOptions;
  10653. const external_keyboardJS_namespaceObject = keyboardJS;
  10654. var external_keyboardJS_default = __webpack_require__.n(external_keyboardJS_namespaceObject);
  10655. const checkUpdate = async (updateLink, auto) => {
  10656. try {
  10657. const checkUrl = `${updateLink}package.json?time=${new Date().getTime()}`;
  10658. const {
  10659. result,
  10660. statusText,
  10661. status,
  10662. data
  10663. } = await tools_httpRequest({
  10664. url: checkUrl,
  10665. responseType: 'json',
  10666. method: 'GET',
  10667. timeout: 3e4
  10668. });
  10669. if (result === 'Success') {
  10670. if (data?.response?.version) {
  10671. return data.response;
  10672. }
  10673. if (!auto) {
  10674. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${data?.statusText}(${data?.status})]`);
  10675. }
  10676. return false;
  10677. }
  10678. if (!auto) {
  10679. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${result}:${statusText}(${status})]`);
  10680. }
  10681. return false;
  10682. } catch (error) {
  10683. throwError(error, 'checkUpdate');
  10684. return false;
  10685. }
  10686. };
  10687. const hasNewVersion = (currentVersion, remoteVersion) => {
  10688. try {
  10689. const [ currentRealVersion ] = currentVersion.split('-');
  10690. const [ remoteRealVersion, isPreview ] = remoteVersion.split('-');
  10691. if (isPreview && !globalOptions.other.receivePreview) {
  10692. return false;
  10693. }
  10694. const [ currentVersion1, currentVersion2, currentVersion3 ] = currentRealVersion.split('.').map(value => parseInt(value, 10));
  10695. const [ remoteVersion1, remoteVersion2, remoteVersion3 ] = remoteRealVersion.split('.').map(value => parseInt(value, 10));
  10696. if (remoteVersion1 > currentVersion1) {
  10697. return true;
  10698. }
  10699. if (remoteVersion1 < currentVersion1) {
  10700. return false;
  10701. }
  10702. if (remoteVersion2 > currentVersion2) {
  10703. return true;
  10704. }
  10705. if (remoteVersion2 < currentVersion2) {
  10706. return false;
  10707. }
  10708. if (remoteVersion3 > currentVersion3) {
  10709. return true;
  10710. }
  10711. return false;
  10712. } catch (error) {
  10713. throwError(error, 'compareVersion');
  10714. return false;
  10715. }
  10716. };
  10717. const updateChecker = async () => {
  10718. try {
  10719. const currentVersion = GM_info.script.version;
  10720. const updateSource = globalOptions.other.autoUpdateSource.toLowerCase();
  10721. const updateLinks = {
  10722. github: 'https://github.com/HCLonely/auto-task-new/raw/main/',
  10723. jsdelivr: 'https://cdn.jsdelivr.net/gh/HCLonely/auto-task-v4@main/',
  10724. standby: 'https://auto-task-v4.hclonely.com/'
  10725. };
  10726. let version;
  10727. let updateLink = '';
  10728. let packageData;
  10729. if ([ 'github', 'jsdelivr', 'standby' ].includes(updateSource)) {
  10730. updateLink = updateLinks[updateSource];
  10731. packageData = await checkUpdate(updateLink, false);
  10732. } else {
  10733. updateLink = updateLinks.github;
  10734. packageData = await checkUpdate(updateLink, true);
  10735. if (!packageData) {
  10736. updateLink = updateLinks.jsdelivr;
  10737. packageData = await checkUpdate(updateLink, true);
  10738. if (!packageData) {
  10739. updateLink = updateLinks.standby;
  10740. packageData = await checkUpdate(updateLink, true);
  10741. }
  10742. }
  10743. }
  10744. if (packageData) {
  10745. version = packageData.version || currentVersion;
  10746. } else {
  10747. version = currentVersion;
  10748. scripts_echoLog({}).error(i18n('checkUpdateFailed'));
  10749. }
  10750. if (packageData && hasNewVersion(currentVersion, version)) {
  10751. scripts_echoLog({
  10752. html: `<li><font>${i18n('newVersionNotice', version, `${updateLink}dist/${GM_info.script.name}.user.js`)}</font></li>`
  10753. });
  10754. scripts_echoLog({
  10755. html: `<li>${i18n('updateText', version)}</li><ol class="update-text">${packageData.change?.map(change => `<li>${change}</li>`).join('')}<li>${i18n('updateHistory')}</li></ol>`
  10756. });
  10757. }
  10758. } catch (error) {
  10759. throwError(error, 'updateChecker');
  10760. }
  10761. };
  10762. const scripts_updateChecker = updateChecker;
  10763. window.STYLE = GM_addStyle(auto_task.A + GM_getResourceText('style'));
  10764. window.DEBUG = !!globalOptions.other?.debug;
  10765. window.TRACE = !!globalOptions.other?.debug && typeof console.trace === 'function';
  10766. const loadScript = async () => {
  10767. if (window.name === 'ATv4_twitchAuth' && window.location.hostname === 'www.twitch.tv') {
  10768. const authToken = external_Cookies_default().get('auth-token');
  10769. const isLogin = !!external_Cookies_default().get('login');
  10770. if (isLogin) {
  10771. GM_setValue('twitchAuth', {
  10772. authToken: authToken,
  10773. clientVersion: __twilightBuildID,
  10774. clientId: commonOptions?.headers?.['Client-ID'],
  10775. deviceId: commonOptions?.headers?.['Device-ID'],
  10776. clientSessionId: window.localStorage.local_storage_app_session_id.replace(/"/g, '')
  10777. });
  10778. window.close();
  10779. external_Swal_default().fire('', i18n('closePageNotice'));
  10780. } else {
  10781. external_Swal_default().fire('', i18n('needLogin'));
  10782. }
  10783. return;
  10784. }
  10785. if (window.name === 'ATv4_redditAuth' && window.location.hostname === 'www.reddit.com') {
  10786. const betaButton = $('#redesign-beta-optin-btn');
  10787. if (betaButton.length > 0) {
  10788. return betaButton[0].click();
  10789. }
  10790. window.close();
  10791. external_Swal_default().fire('', i18n('closePageNotice'));
  10792. return;
  10793. }
  10794. let website;
  10795. for (const Website of Websites) {
  10796. if (Website.test()) {
  10797. website = new Website();
  10798. break;
  10799. }
  10800. }
  10801. if (!website) {
  10802. console.log('%c%s', 'color:#ff0000', 'Auto-Task[Warning]: 脚本停止加载,当前网站不支持!');
  10803. return;
  10804. }
  10805. if (website?.before) {
  10806. await website?.before();
  10807. }
  10808. $('body').append(`
  10809. <div id="auto-task-info"
  10810. style="display:${globalOptions.other.defaultShowLog ? 'block' : 'none'};
  10811. ${globalOptions.position.logSideX}:${globalOptions.position.logDistance.split(',')[0]}px;
  10812. ${globalOptions.position.logSideY}:${globalOptions.position.logDistance.split(',')[1]}px;">
  10813. </div>
  10814. <div id="auto-task-buttons"
  10815. style="display:${globalOptions.other.defaultShowButton ? 'block' : 'none'};
  10816. ${globalOptions.position.buttonSideX}:${globalOptions.position.buttonDistance.split(',')[0]}px;
  10817. ${globalOptions.position.buttonSideY}:${globalOptions.position.buttonDistance.split(',')[1]}px;">
  10818. </div>
  10819. <div class="show-button-div"
  10820. style="display:${globalOptions.other.defaultShowButton ? 'none' : 'block'};
  10821. ${globalOptions.position.showButtonSideX}:${globalOptions.position.showButtonDistance.split(',')[0]}px;
  10822. ${globalOptions.position.showButtonSideY}:${globalOptions.position.showButtonDistance.split(',')[1]}px;">
  10823. <a class="auto-task-website-btn"
  10824. href="javascript:void(0);"
  10825. target="_self"
  10826. title="${i18n('showButton')}"> </a>
  10827. </div>
  10828. `);
  10829. $('div.show-button-div').on('click', () => {
  10830. $('#auto-task-buttons').show();
  10831. $('div.show-button-div').hide();
  10832. });
  10833. const toggleLog = () => {
  10834. const $this = $('#toggle-log');
  10835. const status = $this.attr('data-status');
  10836. if (status === 'show') {
  10837. $('#auto-task-info').hide();
  10838. $this.attr('data-status', 'hide').text(i18n('showLog'));
  10839. } else {
  10840. $('#auto-task-info').show();
  10841. $this.attr('data-status', 'show').text(i18n('hideLog'));
  10842. }
  10843. };
  10844. external_keyboardJS_default().bind(globalOptions.hotKey.doTaskKey, () => {
  10845. if (website.doTask) {
  10846. website.doTask();
  10847. }
  10848. });
  10849. external_keyboardJS_default().bind(globalOptions.hotKey.undoTaskKey, () => {
  10850. if (website.undoTask) {
  10851. website.undoTask();
  10852. }
  10853. });
  10854. external_keyboardJS_default().bind(globalOptions.hotKey.toggleLogKey, toggleLog);
  10855. if (website?.after) {
  10856. await website?.after();
  10857. }
  10858. if (website?.buttons && $('#auto-task-buttons').children().length === 0) {
  10859. $('#auto-task-buttons').addClass(`${website.name}-buttons`);
  10860. for (const button of website.buttons) {
  10861. if (website[button]) {
  10862. const btnElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">${i18n(button)}</a></p>`);
  10863. btnElement.find('a.auto-task-website-btn').on('click', () => {
  10864. website[button]();
  10865. });
  10866. $('#auto-task-buttons').append(btnElement);
  10867. }
  10868. }
  10869. }
  10870. const hideButtonElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">
  10871. ${i18n('hideButton')}</a></p>`);
  10872. hideButtonElement.find('a.auto-task-website-btn').on('click', () => {
  10873. $('#auto-task-buttons').hide();
  10874. $('div.show-button-div').show();
  10875. });
  10876. 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'}">
  10877. ${globalOptions.other.defaultShowLog ? i18n('hideLog') : i18n('showLog')}</a></p>`);
  10878. toggleLogElement.find('a.auto-task-website-btn').on('click', toggleLog);
  10879. $('#auto-task-buttons').append(hideButtonElement).append(toggleLogElement);
  10880. if (website?.options) {
  10881. GM_registerMenuCommand(i18n('changeWebsiteOptions'), () => {
  10882. options(website.name, website.options);
  10883. });
  10884. }
  10885. if (website.name !== 'Setting') {
  10886. GM_registerMenuCommand(i18n('changeGlobalOptions'), () => {
  10887. changeGlobalOptions('swal');
  10888. });
  10889. GM_registerMenuCommand(i18n('settingPage'), () => {
  10890. GM_openInTab('https://auto-task-v4.hclonely.com/setting.html', {
  10891. active: true
  10892. });
  10893. });
  10894. }
  10895. console.log('%c%s', 'color:#1bbe1a', 'Auto-Task[Load]: 脚本加载完成');
  10896. const [ v1, v2 ] = GM_info.version.split('.');
  10897. if (!(parseInt(v1, 10) >= 5 && parseInt(v2, 10) >= 2)) {
  10898. scripts_echoLog({}).error(i18n('versionNotMatched'));
  10899. }
  10900. if (!GM_getValue('notice')) {
  10901. external_Swal_default().fire({
  10902. title: i18n('swalNotice'),
  10903. icon: 'warning'
  10904. }).then(() => {
  10905. GM_openInTab(i18n('noticeLink'), {
  10906. active: true
  10907. });
  10908. GM_setValue('notice', new Date().getTime());
  10909. });
  10910. scripts_echoLog({
  10911. html: `<li><font class="warning">${i18n('echoNotice', i18n('noticeLink'))}</font></li>`
  10912. }).font?.find('a').on('click', () => {
  10913. GM_setValue('notice', new Date().getTime());
  10914. });
  10915. }
  10916. scripts_updateChecker();
  10917. };
  10918. if (window.location.hostname === 'discord.com') {
  10919. const LocalStorage = window.localStorage;
  10920. if (window.name === 'ATv4_discordAuth') {
  10921. window.localStorage.removeItem = () => true;
  10922. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10923. if (discordAuth && discordAuth.length > 0) {
  10924. GM_setValue('discordAuth', {
  10925. auth: discordAuth
  10926. });
  10927. window.close();
  10928. external_Swal_default().fire('', i18n('closePageNotice'));
  10929. } else {
  10930. external_Swal_default().fire({
  10931. text: i18n('getDiscordAuthFailed'),
  10932. icon: 'error'
  10933. });
  10934. }
  10935. } else {
  10936. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10937. if (discordAuth && discordAuth.length > 0) {
  10938. GM_setValue('discordAuth', {
  10939. auth: discordAuth
  10940. });
  10941. }
  10942. }
  10943. } else if (window.location.hostname === 'opquests.com') {
  10944. loadScript();
  10945. } else if (window.name === 'ATv4_updateStoreAuth' && window.location.host === 'store.steampowered.com') {
  10946. $(() => {
  10947. if ($('[data-miniprofile]').length === 0) {
  10948. return;
  10949. }
  10950. const storeSessionID = document.body.innerHTML.match(/g_sessionID = "(.+?)";/)?.[1];
  10951. if (storeSessionID) {
  10952. GM_setValue('steamStoreAuth', {
  10953. storeSessionID: storeSessionID
  10954. });
  10955. window.close();
  10956. external_Swal_default().fire('', i18n('closePageNotice'));
  10957. } else {
  10958. external_Swal_default().fire({
  10959. title: 'Error: Get "sessionID" failed',
  10960. icon: 'error'
  10961. });
  10962. }
  10963. });
  10964. } else if (window.name === 'ATv4_updateCommunityAuth' && window.location.host === 'steamcommunity.com') {
  10965. $(() => {
  10966. const steam64Id = document.body.innerHTML.match(/g_steamID = "(.+?)";/)?.[1];
  10967. const communitySessionID = document.body.innerHTML.match(/g_sessionID = "(.+?)";/)?.[1];
  10968. const data = {};
  10969. if (steam64Id) {
  10970. data.steam64Id = steam64Id;
  10971. }
  10972. if (communitySessionID) {
  10973. data.communitySessionID = communitySessionID;
  10974. GM_setValue('steamCommunityAuth', data);
  10975. window.close();
  10976. } else {
  10977. external_Swal_default().fire({
  10978. title: 'Error: Get "sessionID" failed',
  10979. icon: 'error'
  10980. });
  10981. }
  10982. });
  10983. } else {
  10984. if (window.location.hostname === 'key-hub.eu') {
  10985. unsafeWindow.keyhubtracker = 1;
  10986. unsafeWindow.gaData = {};
  10987. }
  10988. $(loadScript);
  10989. }
  10990. }();
  10991. })();