Greasy Fork 还支持 简体中文。

auto-task-v4

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

目前為 2024-06-15 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name auto-task-v4
  3. // @namespace auto-task-v4
  4. // @version 4.4.4
  5. // @description 自动完成 Freeanywhere,Giveawaysu,GiveeClub,Givekey,Gleam,Indiedb,keyhub,OpiumPulses,Opquests,SweepWidget 等网站的任务。
  6. // @description:en Automatically complete the tasks of FreeAnyWhere, GiveawaySu, GiveeClub, Givekey, Gleam, Indiedb, keyhub, OpiumPulses, Opquests, SweepWidget websites.
  7. // @author HCLonely
  8. // @license MIT
  9. // @run-at document-start
  10. // @homepage https://auto-task-doc.js.org/
  11. // @supportURL https://github.com/HCLonely/auto-task-v4/issues
  12. // @icon https://auto-task-v4.hclonely.com/favicon.ico
  13.  
  14. // @include *://freeanywhere.net/*
  15. // @include *://giveaway.su/giveaway/view/*
  16. // @include *://givee.club/*/event/*
  17. // @include *://givekey.ru/giveaway/*
  18. // @include *://www.indiedb.com/giveaways*
  19. // @include *://key-hub.eu/giveaway/*
  20. // @include *://keylol.com/*
  21. // @include *://www.opiumpulses.com/giveaways
  22. // @include *://prys.revadike.com/giveaway/?id=*
  23. // @include *://opquests.com/quests/*
  24. // @include *://gleam.io/*
  25. // @include *://sweepwidget.com/view/*
  26. // @include *://discord.com/*
  27. // @include *://www.twitch.tv/*
  28. // @include *://www.youtube.com/*
  29. // @include *://*.reddit.com/*
  30. // @include *://twitter.com/settings/account?k*
  31. // @include *://x.com/settings/account*
  32. // @include https://auto-task-v4.hclonely.com/setting.html
  33. // @include https://auto-task-v4.hclonely.com/history.html
  34.  
  35. // @grant GM_setValue
  36. // @grant GM_getValue
  37. // @grant GM_listValues
  38. // @grant GM_deleteValue
  39. // @grant GM_addStyle
  40. // @grant GM_xmlhttpRequest
  41. // @grant GM_registerMenuCommand
  42. // @grant GM_info
  43. // @grant GM_openInTab
  44. // @grant GM_setClipboard
  45. // @grant GM_getResourceText
  46. // @grant GM_cookie
  47. // @grant unsafeWindow
  48. // @grant window.close
  49. // @grant window.localStorage
  50.  
  51. // @connect cdn.jsdelivr.net
  52. // @connect store.steampowered.com
  53. // @connect steamcommunity.com
  54. // @connect login.steampowered.com
  55. // @connect twitter.com
  56. // @connect x.com
  57. // @connect api.twitter.com
  58. // @connect youtube.com
  59. // @connect www.youtube.com
  60. // @connect facebook.com
  61. // @connect instagram.com
  62. // @connect vk.com
  63. // @connect twitch.tv
  64. // @connect www.twitch.tv
  65. // @connect gql.twitch.tv
  66. // @connect github.com
  67. // @connect discordapp.com
  68. // @connect discord.gg
  69. // @connect discord.com
  70. // @connect www.reddit.com
  71. // @connect oauth.reddit.com
  72. // @connect raw.githubusercontent.com
  73. // @connect t.me
  74. // @connect bit.ly
  75. // @connect giveaway.su
  76. // @connect google.com
  77. // @connect www.vloot.io
  78. // @connect givee.club
  79. // @connect gleam.io
  80. // @connect www.indiedb.com
  81. // @connect key-hub.eu
  82. // @connect opquests.com
  83. // @connect itch.io
  84. // @connect auto-task-v4.hclonely.com
  85. // @connect *
  86. // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js
  87. // @require https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js
  88. // @require https://cdn.jsdelivr.net/npm/regenerator-runtime@0.13.5/runtime.min.js
  89. // @require https://cdn.jsdelivr.net/npm/js-sha1@0.6.0/src/sha1.min.js
  90. // @require https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js
  91. // @resource style https://cdn.jsdelivr.net/npm/sweetalert2@11.3.5/dist/sweetalert2.min.css
  92. // @require https://cdn.jsdelivr.net/npm/keyboardjs@2.6.4/dist/keyboard.min.js
  93. // @require https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js
  94.  
  95. // @noframes
  96. // ==/UserScript==
  97.  
  98. console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
  99.  
  100. (function() {
  101. var __webpack_modules__ = {
  102. 108: function(__unused_webpack_module, exports) {
  103. !function(e, n) {
  104. true ? n(exports) : 0;
  105. }(this, function(e) {
  106. 'use strict';
  107. var t = function() {
  108. return (t = Object.assign || function(e) {
  109. for (var n, o = 1, t = arguments.length; o < t; o++) {
  110. for (var r in n = arguments[o]) {
  111. Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r]);
  112. }
  113. }
  114. return e;
  115. }).apply(this, arguments);
  116. };
  117. function r(e, n, o) {
  118. if (o || 2 === arguments.length) {
  119. for (var t, r = 0, i = n.length; r < i; r++) {
  120. !t && r in n || ((t = t || Array.prototype.slice.call(n, 0, r))[r] = n[r]);
  121. }
  122. }
  123. return e.concat(t || Array.prototype.slice.call(n));
  124. }
  125. function d(e) {
  126. return '[object Object]' === n(e);
  127. }
  128. function l(e, n) {
  129. var o = r(r([], n || [], !0), [ '_' ], !1).join('|');
  130. return e.replace(new RegExp('(('.concat(o, ')[a-z])+'), 'g'), function(e, n) {
  131. return n.replace(new RegExp(o), '').toLocaleUpperCase();
  132. });
  133. }
  134. var n = function(e) {
  135. return Object.prototype.toString.call(e);
  136. };
  137. var o = (i.prototype.init = function() {
  138. try {
  139. this.getSystemName(), this.getBrowserName();
  140. } catch (e) {
  141. console.warn('[UA formatter error] '.concat(e));
  142. }
  143. }, i.prototype.getEngine = function() {
  144. var e = this.agent;
  145. return -1 !== e.indexOf('Trident') ? 'Trident' : -1 !== e.indexOf('Firefox') ? 'Gecko' : -1 !== e.indexOf('Presto') ? 'Presto' : 'WebKit';
  146. }, i.prototype.getSystemName = function() {
  147. var e, n = (this.agent.match(/^[a-z]+\/\d+\.\d+\s?\(([a-z\d\s:;./_-]+)\)/i) || [])[1];
  148. try {
  149. var o = '';
  150. if (/Windows/i.test(n)) {
  151. var t = (n.match(/NT\s(\d+\.\d+)/) || [])[1];
  152. switch (this.info.os = 'Windows', t) {
  153. case '6.3':
  154. o = '8.1';
  155. break;
  156.  
  157. case '6.2':
  158. o = '8';
  159. break;
  160.  
  161. case '6.1':
  162. o = '7';
  163. break;
  164.  
  165. case '5.2':
  166. case '5.1':
  167. o = 'XP';
  168. break;
  169.  
  170. default:
  171. o = t;
  172. }
  173. return this.info.device = 'PC', void (this.info.osVersion = o);
  174. }
  175. if (/^Macintosh/i.test(n)) {
  176. return o = (n.match(/X\s((\d+(_|\.))+\d+)/) || [])[1], this.info.os = 'Macintosh',
  177. this.info.device = 'PC', void (this.info.osVersion = null !== (e = null == o ? void 0 : o.replace(/_/g, '.')) && void 0 !== e ? e : 'Unknown');
  178. }
  179. if (/^iPad/i.test(n)) {
  180. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPad', this.info.device = 'Tablet',
  181. void (this.info.osVersion = o.replace(/_/g, '.'));
  182. }
  183. if (/^iPhone/i.test(n)) {
  184. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPhone', this.info.device = 'Mobile',
  185. void (this.info.osVersion = o.replace(/_/g, '.'));
  186. }
  187. if (-1 !== n.indexOf('Android')) {
  188. var r = (n.match(/Android\s((\d+\.?)+\d?)/) || [])[1];
  189. return this.info.device = 'Mobile', this.info.os = 'Android', void (this.info.osVersion = r);
  190. }
  191. if (/Linux\s[a-z\d_]+/.test(n)) {
  192. return this.info.os = 'Linux', void (this.info.osVersion = 'Unknown');
  193. }
  194. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  195. } catch (e) {
  196. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  197. }
  198. }, i.prototype.getBrowserName = function() {
  199. var e = Object.keys(this.browserNameMap).map(function(e) {
  200. return new RegExp(''.concat(e, '(\\/|\\s)(\\d+\\.)+\\d+'));
  201. }), n = 1 < (n = (this.agent.match(/[a-z\d]+(\/|\s)(\d+\.)+\d+/gi) || []).filter(function(n) {
  202. return -1 !== e.findIndex(function(e) {
  203. return e.test(n);
  204. });
  205. })).length && !/^Safari/.test(n[n.length - 1]) ? n.reverse() : n;
  206. this.info = t(t({}, this.info), this._formatBrowserVersion(n[0]));
  207. }, i.prototype._formatBrowserVersion = function(e) {
  208. var n, o, t, r;
  209. try {
  210. for (var i = null !== (o = null === (n = e.match(/(?<name>[a-z\d]+)(\/|\s)(?<version>(\d+\.)+\d+)/i)) || void 0 === n ? void 0 : n.groups) && void 0 !== o ? o : {}, s = i.name, a = i.version, c = {}, f = 0, u = Object.entries(this.browserNameMap); f < u.length; f++) {
  211. var d = u[f], l = d[0], h = d[1];
  212. if (new RegExp(l).test(s)) {
  213. c = h;
  214. break;
  215. }
  216. }
  217. var p = {
  218. browserVersion: null != a ? a : 'Unknown',
  219. browser: null !== (t = c.en) && void 0 !== t ? t : 'Unknown',
  220. browserZH: null !== (r = (null == c ? void 0 : c.zh) || c.en) && void 0 !== r ? r : 'Unknown'
  221. };
  222. return 'Trident' === s && (p.browserVersion = {
  223. '4.0': 8,
  224. '5.0': 9,
  225. '6.0': 10,
  226. '7.0': 11
  227. }[a]), p;
  228. } catch (e) {
  229. return console.warn('[UA formatter error] '.concat(e)), {
  230. browser: 'Unknown',
  231. browserVersion: 'Unknown'
  232. };
  233. }
  234. }, i);
  235. function i(e) {
  236. this.agent = '', this.info = {
  237. browser: '',
  238. browserZH: '',
  239. browserVersion: '',
  240. os: '',
  241. osVersion: '',
  242. device: 'Unknown',
  243. engine: 'WebKit'
  244. }, this.browserNameMap = {
  245. MicroMessenger: {
  246. en: 'MicroMessenger',
  247. zh: '微信'
  248. },
  249. MetaSr: {
  250. en: 'MetaSr',
  251. zh: '搜狗浏览器'
  252. },
  253. 'QQ(Browser)?': {
  254. en: 'QQBrowser',
  255. zh: 'QQ浏览器'
  256. },
  257. UCBrowser: {
  258. en: 'UCBrowser',
  259. zh: 'UC浏览器'
  260. },
  261. '2345Explorer': {
  262. en: '2345Explorer',
  263. zh: '2345极速浏览器'
  264. },
  265. Mb2345Browser: {
  266. en: 'Mb2345Browser',
  267. zh: '2345手机浏览器'
  268. },
  269. Trident: {
  270. en: 'Internet Explorer'
  271. },
  272. 'Edge?': {
  273. en: 'Edge'
  274. },
  275. OPR: {
  276. en: 'Opera'
  277. },
  278. Vivaldi: {
  279. en: 'Vivaldi'
  280. },
  281. Firefox: {
  282. en: 'Firefox'
  283. },
  284. Chrome: {
  285. en: 'Chrome'
  286. },
  287. Safari: {
  288. en: 'Safari'
  289. }
  290. }, this.agent = e, this.init();
  291. var n = this.info, o = n.browser, e = n.browserVersion, n = n.osVersion;
  292. this.info = t(t({}, this.info), {
  293. engine: this.getEngine(),
  294. browserVersion: 'Safari' === o ? n : e
  295. });
  296. }
  297. function s() {
  298. this.cookies = {}, this.init();
  299. }
  300. var a = new (s.prototype.init = function() {
  301. var o = {};
  302. document.cookie.split(/;\s/).forEach(function(e) {
  303. var n = e.split(/=/), e = n[0], n = n[1];
  304. o[e] = n;
  305. }), this.cookies = o;
  306. }, s.prototype.getItem = function(e) {
  307. return this.cookies[e];
  308. }, s.prototype.getAllItems = function() {
  309. return this.cookies;
  310. }, s.prototype.setItem = function(e, n, o, t, r, i) {
  311. document.cookie = ''.concat(e, '=').concat(n).concat(o ? '; expires='.concat(o) : '').concat(t ? '; path='.concat(t) : '').concat(r ? '; domain='.concat(r) : '').concat(i ? '; secure' : '');
  312. }, s)();
  313. e.countDown = function e(n, o, t, r) {
  314. if (!window) {
  315. throw new Error('window is not defind.');
  316. }
  317. if (0 < n) {
  318. return r && r(), n--, window[o] = window.setTimeout(function() {
  319. e(n, o, t, r);
  320. }, 1e3), function() {
  321. return clearTimeout(window[o]);
  322. };
  323. }
  324. clearTimeout(window[o]), t && t();
  325. }, e.createRandomID = function(e) {
  326. void 0 === e && (e = 12);
  327. for (var n = [], o = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''), t = o.length, r = 0; r < e; r++) {
  328. n.push(o[Math.round(Math.random() * t)]);
  329. }
  330. return n.join('');
  331. }, e.dCookie = a, e.debounce = function(o, t, r) {
  332. var i;
  333. void 0 === t && (t = 0);
  334. var s = r = void 0 === r ? !1 : r;
  335. return function() {
  336. var e = this, n = arguments;
  337. s && (o.apply(this, arguments), s = !1), clearTimeout(i), i = setTimeout(function() {
  338. r ? s = !0 : o.apply(e, n);
  339. }, t);
  340. };
  341. }, e.deepCopy = function e(n) {
  342. if (d(n) || Array.isArray(n)) {
  343. var o, t = Array.isArray(n) ? [] : {};
  344. for (o in n) {
  345. t[o] = e(n[o]);
  346. }
  347. return t;
  348. }
  349. return n;
  350. }, e.formatQueryParams = function(e) {
  351. e = null === (e = /\?(?<params>(.*)=.+)/.exec(decodeURIComponent(e))) || void 0 === e ? void 0 : e.groups;
  352. if (!e) {
  353. return {};
  354. }
  355. for (var n = e.params.split('&'), t = {}, o = 0; o < n.length; o++) {
  356. n[o].replace(/([^?&]*)=([^?&]*)/, function(e, n, o) {
  357. return t[n] = o, e;
  358. });
  359. }
  360. return t;
  361. }, e.formatThousandth = function(e) {
  362. var n = ''.concat(e).split('.'), e = n[0], n = n[1], n = void 0 === n ? '' : n, e = e.replace(/\d{1,3}(?=(\d{3})+$)/g, '$&,');
  363. return ''.concat(e).concat(n ? '.'.concat(n) : '');
  364. }, e.generateTree = function e(n, o, t, r) {
  365. for (var i = [], s = 0; s < n.length; s++) {
  366. var a = n[s];
  367. a[t] === o && (i.push(a), a.children = e(n, a[null != r ? r : 'id'], t, r));
  368. }
  369. return i;
  370. }, e.isEmpty = function(e) {
  371. return Array.isArray(e) ? 0 === e.length : d(e) ? 0 === Object.keys(e).length : [ '[object Set]', '[object Map]' ].includes(n(e)) ? 0 === e.size : [ null, void 0, '' ].includes(e);
  372. }, e.isFunction = function(e) {
  373. return '[object Function]' === n(e);
  374. }, e.isImageUrl = function(e) {
  375. return /\.((png)|(jpe?g)|(gif)|(svg)|(webp))$/gi.test(e);
  376. }, e.isObject = d, e.isRegexp = function(e) {
  377. return '[object RegExp]' === n(e);
  378. }, e.objectKeyToCamelCase = function e(n, o, t) {
  379. if (Array.isArray(n)) {
  380. for (var r = [], i = 0; i < n.length; i++) {
  381. r[i] = e(o && n[i][o] ? n[i][o] : n[i], o, t);
  382. }
  383. } else if (d(n)) {
  384. r = {};
  385. for (var s = o && n[o] ? n[o] : n, a = 0, c = Object.entries(s); a < c.length; a++) {
  386. var f = (u = c[a])[0], u = u[1];
  387. Array.isArray(u) || d(s) ? r[l(f, t)] = e(u, o, t) : r[l(f, t)] = u;
  388. }
  389. } else {
  390. r = n;
  391. }
  392. return r;
  393. }, e.realType = n, e.searchParams = function(e, n) {
  394. return void 0 === e && (e = null === location || void 0 === location ? void 0 : location.search),
  395. new URLSearchParams(e).get(n);
  396. }, e.toLowerCamelCase = l, e.toUnderline = function(e) {
  397. return e.replace(/([A-Z])/g, function(e) {
  398. return '_'.concat(e.toLocaleLowerCase());
  399. });
  400. }, e.ua = function(e) {
  401. return void 0 === e && (e = navigator.userAgent), new o(e).info;
  402. }, Object.defineProperty(e, '__esModule', {
  403. value: !0
  404. });
  405. });
  406. },
  407. 221: function(module, __webpack_exports__, __webpack_require__) {
  408. 'use strict';
  409. __webpack_require__.d(__webpack_exports__, {
  410. Z: function() {
  411. return __WEBPACK_DEFAULT_EXPORT__;
  412. }
  413. });
  414. var _node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(398);
  415. var _node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = __webpack_require__.n(_node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__);
  416. var _node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
  417. var _node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default = __webpack_require__.n(_node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__);
  418. var ___CSS_LOADER_EXPORT___ = _node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default()(_node_modules_pnpm_css_loader_6_5_1_webpack_5_60_0_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default());
  419. ___CSS_LOADER_EXPORT___.push([ module.id, '.colorful-button,#auto-task-buttons a.auto-task-website-btn,.show-button-div a.auto-task-website-btn,body.auto-task-options .auto-task-form table button{position:relative;padding:5px 10px;text-align:center;color:#fff;text-decoration:none;background:linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);border-radius:30px;background-size:400%;text-transform:capitalize}.colorful-button:hover,#auto-task-buttons a.auto-task-website-btn:hover,.show-button-div a.auto-task-website-btn:hover,body.auto-task-options .auto-task-form table button:hover{animation:animate 8s linear infinite;cursor:pointer}.colorful-button:hover::before,#auto-task-buttons a.auto-task-website-btn:hover::before,.show-button-div a.auto-task-website-btn:hover::before,body.auto-task-options .auto-task-form table button:hover::before{filter:blur(10px);opacity:1}.colorful-button::before,#auto-task-buttons a.auto-task-website-btn::before,.show-button-div a.auto-task-website-btn::before,body.auto-task-options .auto-task-form table button::before{content:"";position:absolute;top:-5px;left:-5px;right:-5px;bottom:-5px;z-index:-1;background:linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);border-radius:40px;background-size:400%;opacity:-1;transition:.5s}@keyframes animate{0%{background-position:0%}100%{background-position:100%}}#auto-task-info{position:fixed;bottom:10px;right:10px;width:60%;max-width:500px;max-height:60%;overflow-y:auto;color:#000;background-color:#fff;padding-left:5px;z-index:999999999 !important;border:solid 2px #add8e6;border-radius:10px}#auto-task-info li{text-align:left}#auto-task-info li a.high-light{color:#00aeff;font-weight:bold}#auto-task-info .success{color:green}#auto-task-info .error{color:red}#auto-task-info .warning{color:blue}#auto-task-info .info{color:#ff0}#auto-task-info .update-text{color:green;border:solid 2px #8dcb69;margin:5px 10px 5px 20px;border-radius:10px;padding:5px 20px}.auto-task-keylol{display:inline-block;text-transform:capitalize;margin-left:10px;text-decoration:none !important;border:solid 1px;border-radius:5px;padding:0 2px}.auto-task-keylol[selected=selected]{background-color:blue !important;color:#fff !important}.auto-task-form table{font-family:verdana,arial,sans-serif;font-size:11px;color:#333;border-width:1px;border-color:#999;border-collapse:collapse;width:100%}.auto-task-form table thead td{border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9;font-weight:bold;background-color:#fff}.auto-task-form table tbody tr{background-color:#d4e3e5}.auto-task-form table tbody tr:hover{background-color:#ff6 !important}.auto-task-form table tbody tr th{background-color:#c3dde0;border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9;text-transform:capitalize}.auto-task-form table tbody tr td{border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9}.swal2-modal{width:70% !important;max-width:1000px !important}body.auto-task-options{padding-top:10px;text-align:center}body.auto-task-options .auto-task-form{width:80%;max-width:1000px;margin:0 auto;padding-bottom:20px}body.auto-task-options .auto-task-form table input.editOption{width:80%}body.auto-task-options .auto-task-form table #getTwitterUserId,body.auto-task-options .auto-task-form table #getYoutubeChannelId{margin-top:5px}body.auto-task-options .auto-task-form table button{z-index:1}body.auto-task-options .auto-task-form table input[type=text]{outline-style:none;border:1px solid #ccc;border-radius:3px;padding:5px 10px;font-size:14px}body.auto-task-options .auto-task-form table input[type=text]:focus{border-color:#66afe9;outline:0;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}body.auto-task-options .auto-task-form table label{position:relative;width:160px;height:80px;cursor:pointer;transform:scale(0.25);margin:-25% 0;top:-30px;display:inline-block}body.auto-task-options .auto-task-form table label input{position:relative;z-index:1;appearance:none}body.auto-task-options .auto-task-form table label input:checked~span{background:#05be05;box-shadow:0 15px 25px #05be0566}body.auto-task-options .auto-task-form table label input:checked~span i{left:84px}body.auto-task-options .auto-task-form table label input:checked~span i::before{background:#05be05;box-shadow:35px 0 0 #05be05}body.auto-task-options .auto-task-form table label input:checked~span i::after{bottom:12px;height:15px;border-bottom-left-radius:15px;border-bottom-right-radius:15px;background:#05be05}body.auto-task-options .auto-task-form table label span{position:absolute;top:0;left:0;width:100%;height:100%;background:#fe0000;border-radius:80px;transition:.5s;box-shadow:0 15px 25px #fe000066}body.auto-task-options .auto-task-form table label span i{position:absolute;top:4px;left:4px;width:72px;height:72px;background:#fff;border-radius:50%}body.auto-task-options .auto-task-form table label span i::before{content:"";position:absolute;top:22px;left:12px;width:12px;height:12px;border-radius:50%;background:#fe0000;box-shadow:35px 0 0 #fe0000;transition:.5s}body.auto-task-options .auto-task-form table label span i::after{content:"";position:absolute;bottom:15px;left:calc(50% - 15px);width:30px;height:6px;border-radius:6px;background:#fe0000;transition:.5s}body.auto-task-history{font-size:15px;font-weight:400;line-height:1.5}body.auto-task-history .container a{color:#007bff;text-decoration:none;background-color:transparent}body.auto-task-history .container .card{width:80%;max-width:800px;border-radius:10px;background:#7676761a;border-top:1px solid #ffffff80;-webkit-backdrop-filter:blur(20px);backdrop-filter:blur(20px);box-shadow:0 15px 25px #0000001a;margin:20px auto;position:relative;display:flex;flex-direction:column;word-wrap:break-word;-webkit-background-clip:border-box;background-clip:border-box;border:1px solid rgba(0,0,0,.125);border-radius:.25rem}body.auto-task-history .container .card .title{text-align:center;font-size:30px;font-weight:bold;margin:5px 0}body.auto-task-history .container .card .title a:hover{text-decoration:none;background:#93e1ff;border-radius:10px;padding:3px}body.auto-task-history .container .card ul{margin-bottom:25px}body.auto-task-history .container .card ul li{margin-bottom:5px;line-height:20px}body.auto-task-history .container .card ul a:hover{text-decoration:underline}body.auto-task-history .container .card .delete-task{right:10px;width:38px;height:35px;position:absolute;font-size:24px;cursor:pointer;border-radius:10px}body.auto-task-history .container .card .delete-task:hover{background:#fff}body.auto-task-history .container .card .time{right:5px;position:absolute;bottom:0;color:#e83e8c;font-family:\'SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace\';font-size:15px}#auto-task-buttons,.show-button-div{position:fixed;top:30px;right:15px;width:170px;z-index:999999999 !important;transform:scale(0.9)}#auto-task-buttons p,.show-button-div p{line-height:30px;height:40px;text-align:center;margin:5px !important}#auto-task-buttons a.auto-task-website-btn,.show-button-div a.auto-task-website-btn{width:150px;height:40px;line-height:30px;font-size:20px}.show-button-div{width:20px}.auto-task-capitalize{text-transform:capitalize !important}.swal2-file:focus,.swal2-input:focus,.swal2-textarea:focus{box-shadow:inset 0px 0px 4px 1px rgba(100,150,200,.5) !important}.swal2-checkbox-custom{align-items:center;justify-content:center;background:#fff;color:inherit;margin:1em auto}.swal2-checkbox-custom input{flex-shrink:0;margin:0 .4em}.giveaway-actions #getKey{display:none !important}.auto-task-giveaway-status{color:#fff;border-radius:10px;padding:0 5px;margin-left:5px}.auto-task-giveaway-status.active{background-color:#5cb85c}.auto-task-giveaway-status.not-active{background-color:#d9534f}', '' ]);
  420. const __WEBPACK_DEFAULT_EXPORT__ = ___CSS_LOADER_EXPORT___.toString();
  421. },
  422. 1: function(module) {
  423. 'use strict';
  424. module.exports = function(cssWithMappingToString) {
  425. var list = [];
  426. list.toString = function toString() {
  427. return this.map(function(item) {
  428. var content = '';
  429. var needLayer = typeof item[5] !== 'undefined';
  430. if (item[4]) {
  431. content += '@supports ('.concat(item[4], ') {');
  432. }
  433. if (item[2]) {
  434. content += '@media '.concat(item[2], ' {');
  435. }
  436. if (needLayer) {
  437. content += '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {');
  438. }
  439. content += cssWithMappingToString(item);
  440. if (needLayer) {
  441. content += '}';
  442. }
  443. if (item[2]) {
  444. content += '}';
  445. }
  446. if (item[4]) {
  447. content += '}';
  448. }
  449. return content;
  450. }).join('');
  451. };
  452. list.i = function i(modules, media, dedupe, supports, layer) {
  453. if (typeof modules === 'string') {
  454. modules = [ [ null, modules, undefined ] ];
  455. }
  456. var alreadyImportedModules = {};
  457. if (dedupe) {
  458. for (var k = 0; k < this.length; k++) {
  459. var id = this[k][0];
  460. if (id != null) {
  461. alreadyImportedModules[id] = true;
  462. }
  463. }
  464. }
  465. for (var _k = 0; _k < modules.length; _k++) {
  466. var item = [].concat(modules[_k]);
  467. if (dedupe && alreadyImportedModules[item[0]]) {
  468. continue;
  469. }
  470. if (typeof layer !== 'undefined') {
  471. if (typeof item[5] === 'undefined') {
  472. item[5] = layer;
  473. } else {
  474. item[1] = '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {').concat(item[1], '}');
  475. item[5] = layer;
  476. }
  477. }
  478. if (media) {
  479. if (!item[2]) {
  480. item[2] = media;
  481. } else {
  482. item[1] = '@media '.concat(item[2], ' {').concat(item[1], '}');
  483. item[2] = media;
  484. }
  485. }
  486. if (supports) {
  487. if (!item[4]) {
  488. item[4] = ''.concat(supports);
  489. } else {
  490. item[1] = '@supports ('.concat(item[4], ') {').concat(item[1], '}');
  491. item[4] = supports;
  492. }
  493. }
  494. list.push(item);
  495. }
  496. };
  497. return list;
  498. };
  499. },
  500. 398: function(module) {
  501. 'use strict';
  502. module.exports = function(i) {
  503. return i[1];
  504. };
  505. }
  506. };
  507. var __webpack_module_cache__ = {};
  508. function __webpack_require__(moduleId) {
  509. var cachedModule = __webpack_module_cache__[moduleId];
  510. if (cachedModule !== undefined) {
  511. return cachedModule.exports;
  512. }
  513. var module = __webpack_module_cache__[moduleId] = {
  514. id: moduleId,
  515. exports: {}
  516. };
  517. __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  518. return module.exports;
  519. }
  520. !function() {
  521. __webpack_require__.n = function(module) {
  522. var getter = module && module.__esModule ? function() {
  523. return module['default'];
  524. } : function() {
  525. return module;
  526. };
  527. __webpack_require__.d(getter, {
  528. a: getter
  529. });
  530. return getter;
  531. };
  532. }();
  533. !function() {
  534. __webpack_require__.d = function(exports, definition) {
  535. for (var key in definition) {
  536. if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  537. Object.defineProperty(exports, key, {
  538. enumerable: true,
  539. get: definition[key]
  540. });
  541. }
  542. }
  543. };
  544. }();
  545. !function() {
  546. __webpack_require__.o = function(obj, prop) {
  547. return Object.prototype.hasOwnProperty.call(obj, prop);
  548. };
  549. }();
  550. var __webpack_exports__ = {};
  551. !function() {
  552. 'use strict';
  553. const external_Swal_namespaceObject = Swal;
  554. var external_Swal_default = __webpack_require__.n(external_Swal_namespaceObject);
  555. const external_Cookies_namespaceObject = Cookies;
  556. var auto_task = __webpack_require__(221);
  557. var javascript_utils_umd_min = __webpack_require__(108);
  558. const httpRequest = async (options, times = 0) => {
  559. if (window.TRACE) {
  560. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  561. }
  562. try {
  563. const result = await new Promise(resolve => {
  564. if (options.dataType) {
  565. options.responseType = options.dataType;
  566. }
  567. const requestObj = {
  568. ...{
  569. timeout: 3e4,
  570. ontimeout(data) {
  571. resolve({
  572. result: 'Error',
  573. statusText: 'Timeout',
  574. status: 601,
  575. data: data,
  576. options: options
  577. });
  578. },
  579. onabort(data) {
  580. resolve({
  581. result: 'Error',
  582. statusText: 'Aborted',
  583. status: 602,
  584. data: data,
  585. options: options
  586. });
  587. },
  588. onerror(data) {
  589. resolve({
  590. result: 'Error',
  591. statusText: 'Error',
  592. status: 603,
  593. data: data,
  594. options: options
  595. });
  596. },
  597. onload(data) {
  598. if (options.responseType === 'json' && data?.response && typeof data.response !== 'object') {
  599. try {
  600. data.response = JSON.parse(data.responseText);
  601. } catch (error) {}
  602. }
  603. resolve({
  604. result: 'Success',
  605. statusText: 'Load',
  606. status: 600,
  607. data: data,
  608. options: options
  609. });
  610. }
  611. },
  612. ...options
  613. };
  614. GM_xmlhttpRequest(requestObj);
  615. });
  616. if (window.DEBUG) {
  617. console.log('%cAuto-Task[httpRequest]:', 'color:blue', JSON.stringify(result));
  618. }
  619. if (result.status !== 600 && times < 2) {
  620. return await httpRequest(options, times + 1);
  621. }
  622. return result;
  623. } catch (error) {
  624. console.log('%cAuto-Task[httpRequest]:', 'color:red', JSON.stringify({
  625. errorMsg: error,
  626. options: options
  627. }));
  628. throwError(error, 'httpRequest');
  629. return {
  630. result: 'JsError',
  631. statusText: 'Error',
  632. status: 604,
  633. error: error,
  634. options: options
  635. };
  636. }
  637. };
  638. const tools_httpRequest = httpRequest;
  639. const echoLog = ({
  640. type,
  641. text,
  642. html,
  643. id
  644. }) => {
  645. const emptyStatus = {
  646. success: () => emptyStatus,
  647. error: () => emptyStatus,
  648. warning: () => emptyStatus,
  649. info: () => emptyStatus,
  650. view: () => emptyStatus
  651. };
  652. try {
  653. let ele;
  654. if (type) {
  655. switch (type) {
  656. case 'joiningSteamGroup':
  657. case 'leavingSteamGroup':
  658. case 'gettingSteamGroupId':
  659. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/groups/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  660. break;
  661.  
  662. case 'joiningSteamOfficialGroup':
  663. case 'leavingSteamOfficialGroup':
  664. case 'gettingSteamOfficialGroupId':
  665. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/games/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  666. break;
  667.  
  668. case 'subscribingForum':
  669. case 'unsubscribingForum':
  670. case 'gettingForumId':
  671. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/app/${text}/discussions/" target="_blank">${text}</a>]...<font></font></li>`);
  672. break;
  673.  
  674. case 'followingCurator':
  675. case 'unfollowingCurator':
  676. case 'gettingCuratorId':
  677. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/${text?.includes('/') ? text : `curator/${text}`}" target="_blank">${text}</a>]...<font></font></li>`);
  678. break;
  679.  
  680. case 'addingToWishlist':
  681. case 'removingFromWishlist':
  682. case 'followingGame':
  683. case 'unfollowingGame':
  684. case 'gettingSubid':
  685. case 'addingFreeLicense':
  686. case 'requestingPlayTestAccess':
  687. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/app/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  688. break;
  689.  
  690. case 'addingFreeLicenseSubid':
  691. ele = $(`<li>${i18n('addingFreeLicense')}[<a href="https://steamdb.info/sub/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  692. break;
  693.  
  694. case 'favoritingWorkshop':
  695. case 'unfavoritingWorkshop':
  696. case 'gettingWorkshopAppId':
  697. case 'votingUpWorkshop':
  698. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/sharedfiles/filedetails/?id=${text}" target="_blank">
  699. ${text}</a>]...<font></font></li>`);
  700. break;
  701.  
  702. case 'gettingAnnouncementParams':
  703. case 'likingAnnouncement':
  704. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/news/app/${text}/view/${id}" target="_blank">
  705. ${id}</a>]...<font></font></li>`);
  706. break;
  707.  
  708. case 'joiningDiscordServer':
  709. case 'gettingDiscordGuild':
  710. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/invite/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  711. break;
  712.  
  713. case 'leavingDiscordServer':
  714. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/channels/@me/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  715. break;
  716.  
  717. case 'updateDiscordAuth':
  718. ele = $(`<li style="color:red;">${i18n('updateDiscordAuth')}</li>`);
  719. break;
  720.  
  721. case 'followingTwitchChannel':
  722. case 'unfollowingTwitchChannel':
  723. case 'gettingTwitchChannelId':
  724. ele = $(`<li>${i18n(type)}[<a href="https://www.twitch.tv/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  725. break;
  726.  
  727. case 'gettingInsUserId':
  728. case 'followingIns':
  729. case 'unfollowingIns':
  730. ele = $(`<li>${i18n(type)}[<a href="https://www.instagram.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  731. break;
  732.  
  733. case 'gettingTwitterUserId':
  734. case 'followingTwitterUser':
  735. case 'unfollowingTwitterUser':
  736. ele = $(`<li>${i18n(type)}[<a href="https://x.com/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  737. break;
  738.  
  739. case 'retweetting':
  740. case 'unretweetting':
  741. ele = $(`<li>${i18n(type)}${text}...<font></font></li>`);
  742. break;
  743.  
  744. case 'joiningReddit':
  745. case 'leavingReddit':
  746. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/r/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  747. break;
  748.  
  749. case 'followingRedditUser':
  750. case 'unfollowingRedditUser':
  751. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/user/${text?.replace('u_', '')}" target="_blank">
  752. ${text?.replace('u_', '')}</a>]...<font></font></li>`);
  753. break;
  754.  
  755. case 'followingYtbChannel':
  756. case 'unfollowingYtbChannel':
  757. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/channel/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  758. break;
  759.  
  760. case 'likingYtbVideo':
  761. case 'unlikingYtbVideo':
  762. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/watch?v=${text}" target="_blank">${text}</a>]...<font></font></li>`);
  763. break;
  764.  
  765. case 'gettingVkId':
  766. case 'joiningVkGroup':
  767. case 'leavingVkGroup':
  768. case 'joiningVkPublic':
  769. case 'leavingVkPublic':
  770. case 'sendingVkWall':
  771. case 'deletingVkWall':
  772. ele = $(`<li>${i18n(type)}[<a href="https://vk.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  773. break;
  774.  
  775. case 'visitingLink':
  776. ele = $(`<li>${i18n('visitingLink')}[<a href="${text}" target="_blank">${text}</a>]...<font></font></li>`);
  777. break;
  778.  
  779. case 'verifyingInsAuth':
  780. case 'text':
  781. ele = $(`<li>${i18n(text)}<font></font></li>`);
  782. break;
  783.  
  784. case 'html':
  785. ele = $(text || html);
  786. break;
  787.  
  788. case 'whiteList':
  789. ele = $(`<li><font class="warning">${i18n('skipTask')}[${text}(${id})](${i18n('whiteList')})</font></li>`);
  790. break;
  791.  
  792. case 'globalOptionsSkip':
  793. ele = $(`<li>${i18n('skipTaskOption')}<font class="warning">${text}</font></li>`);
  794. break;
  795.  
  796. default:
  797. ele = $(`<li>${i18n('unKnown')}:${type}(${text})...<font></font></li>`);
  798. break;
  799. }
  800. } else if (text) {
  801. ele = $(`<li>${i18n(text)}<font></font></li>`);
  802. } else if (html) {
  803. ele = $(html);
  804. } else {
  805. ele = $('<li><font></font></li>');
  806. }
  807. ele.addClass('card-text');
  808. $('#auto-task-info').append(ele);
  809. ele[0]?.scrollIntoView();
  810. const font = ele.find('font');
  811. const status = {
  812. font: font,
  813. success(text = 'Success', html = false) {
  814. this.font?.attr('class', '').addClass('success');
  815. html ? this.font?.html(text) : this.font?.text(text);
  816. return this;
  817. },
  818. error(text = 'Error', html = false) {
  819. this.font?.attr('class', '').addClass('error');
  820. html ? this.font?.html(text) : this.font?.text(text);
  821. return this;
  822. },
  823. warning(text = 'Warning', html = false) {
  824. this.font?.attr('class', '').addClass('warning');
  825. html ? this.font?.html(text) : this.font?.text(text);
  826. return this;
  827. },
  828. info(text = 'Info', html = false) {
  829. this.font?.attr('class', '').addClass('info');
  830. html ? this.font?.html(text) : this.font?.text(text);
  831. return this;
  832. },
  833. view() {
  834. this.font?.[0].scrollIntoView();
  835. return this;
  836. }
  837. };
  838. return status;
  839. } catch (error) {
  840. throwError(error, 'echoLog');
  841. return emptyStatus;
  842. }
  843. };
  844. const scripts_echoLog = echoLog;
  845. const unique = array => {
  846. try {
  847. return [ ...new Set(array) ];
  848. } catch (error) {
  849. throwError(error, 'unique');
  850. return [];
  851. }
  852. };
  853. const delay = (time = 1e3) => new Promise(resolve => {
  854. setTimeout(() => {
  855. resolve(true);
  856. }, time);
  857. });
  858. const getRedirectLink = async link => {
  859. try {
  860. if (!link) {
  861. return null;
  862. }
  863. const redirectLinksCache = GM_getValue('redirectLinks') || {};
  864. if (redirectLinksCache[link]) {
  865. redirectLinksCache[link];
  866. }
  867. return await tools_httpRequest({
  868. url: link,
  869. method: 'GET'
  870. }).then(({
  871. data
  872. }) => {
  873. if (data?.finalUrl) {
  874. redirectLinksCache[link] = data.finalUrl;
  875. GM_setValue('redirectLinks', redirectLinksCache);
  876. return data.finalUrl;
  877. }
  878. return null;
  879. });
  880. } catch (error) {
  881. throwError(error, 'getRedirectLink');
  882. return null;
  883. }
  884. };
  885. const visitLink = async (link, options) => {
  886. try {
  887. const logStatus = scripts_echoLog({
  888. type: 'visitLink',
  889. text: link
  890. });
  891. return await tools_httpRequest({
  892. url: link,
  893. method: 'GET',
  894. ...options
  895. }).then(({
  896. result,
  897. statusText,
  898. status
  899. }) => {
  900. if (result === 'Success') {
  901. logStatus.success();
  902. return true;
  903. }
  904. logStatus.error(`${result}:${statusText}(${status})`);
  905. return false;
  906. });
  907. } catch (error) {
  908. throwError(error, 'visitLink');
  909. return false;
  910. }
  911. };
  912. const getUrlQuery = url => {
  913. try {
  914. const query = {};
  915. if (url) {
  916. if (url.includes('?')) {
  917. url.split('?')[1].replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  918. query[key] = value;
  919. return str;
  920. });
  921. }
  922. } else {
  923. window.location.search.replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  924. query[key] = value;
  925. return str;
  926. });
  927. }
  928. return query;
  929. } catch (error) {
  930. throwError(error, 'getUrlQuery');
  931. return {};
  932. }
  933. };
  934. const getUuid = () => {
  935. const uuidUrl = URL.createObjectURL(new Blob()).toString();
  936. return uuidUrl.slice(uuidUrl.lastIndexOf('/') + 1);
  937. };
  938. const stringToColour = str => {
  939. try {
  940. let hash = 0;
  941. for (let i = 0; i < str.length; i++) {
  942. hash = str.charCodeAt(i) + ((hash << 5) - hash);
  943. }
  944. let colour = '#';
  945. for (let i = 0; i < 3; i++) {
  946. const value = hash >> i * 8 & 255;
  947. colour += `00${value.toString(16)}`.slice(-2);
  948. }
  949. return colour;
  950. } catch (error) {
  951. throwError(error, 'stringToColour');
  952. return '#fff';
  953. }
  954. };
  955. const defaultGlobalOptions = {
  956. doTask: {
  957. discord: {
  958. servers: true
  959. },
  960. instagram: {
  961. users: true
  962. },
  963. twitch: {
  964. channels: true
  965. },
  966. twitter: {
  967. users: true,
  968. retweets: true
  969. },
  970. vk: {
  971. names: true
  972. },
  973. youtube: {
  974. channels: true,
  975. likes: true
  976. },
  977. reddit: {
  978. reddits: true
  979. },
  980. steam: {
  981. groups: true,
  982. officialGroups: true,
  983. wishlists: true,
  984. follows: true,
  985. forums: true,
  986. workshops: true,
  987. curators: true,
  988. workshopVotes: true,
  989. announcements: true,
  990. licenses: true,
  991. playtests: true
  992. }
  993. },
  994. undoTask: {
  995. discord: {
  996. servers: true
  997. },
  998. instagram: {
  999. users: true
  1000. },
  1001. twitch: {
  1002. channels: true
  1003. },
  1004. twitter: {
  1005. users: true,
  1006. retweets: true
  1007. },
  1008. vk: {
  1009. names: true
  1010. },
  1011. youtube: {
  1012. channels: true,
  1013. likes: true
  1014. },
  1015. reddit: {
  1016. reddits: true
  1017. },
  1018. steam: {
  1019. groups: true,
  1020. officialGroups: true,
  1021. wishlists: true,
  1022. follows: true,
  1023. forums: true,
  1024. workshops: true,
  1025. curators: true
  1026. }
  1027. },
  1028. ASF: {
  1029. AsfEnabled: false,
  1030. AsfIpcUrl: '',
  1031. AsfIpcPassword: '',
  1032. AsfBotname: 'asf'
  1033. },
  1034. position: {
  1035. buttonSideX: 'right',
  1036. buttonSideY: 'top',
  1037. buttonDistance: '15,30',
  1038. showButtonSideX: 'right',
  1039. showButtonSideY: 'top',
  1040. showButtonDistance: '15,30',
  1041. logSideX: 'right',
  1042. logSideY: 'bottom',
  1043. logDistance: '10,10'
  1044. },
  1045. hotKey: {
  1046. doTaskKey: 'alt + d',
  1047. undoTaskKey: 'alt + u',
  1048. toggleLogKey: 'alt + l'
  1049. },
  1050. other: {
  1051. twitterVerifyId: '783214',
  1052. youtubeVerifyChannel: 'UCrXUsMBcfTVqwAS7DKg9C0Q',
  1053. autoUpdateSource: 'jsdelivr',
  1054. language: 'zh',
  1055. checkLogin: true,
  1056. checkLeftKey: true,
  1057. defaultShowButton: true,
  1058. defaultShowLog: true,
  1059. debug: false,
  1060. receivePreview: true
  1061. }
  1062. };
  1063. const userDefinedGlobalOptions = GM_getValue('globalOptions') || {};
  1064. const assignObject = (obj1, obj2) => {
  1065. try {
  1066. const newObj = {};
  1067. for (const [ key, value ] of Object.entries(obj1)) {
  1068. if (Object.prototype.toString.call(value) === '[object Object]' && Object.prototype.toString.call(obj2[key]) === '[object Object]') {
  1069. newObj[key] = assignObject(value, obj2[key]);
  1070. } else {
  1071. newObj[key] = obj2[key] ?? value;
  1072. }
  1073. }
  1074. return newObj;
  1075. } catch (error) {
  1076. throwError(error, 'assignObject');
  1077. return defaultGlobalOptions;
  1078. }
  1079. };
  1080. const globalOptions = assignObject(defaultGlobalOptions, userDefinedGlobalOptions);
  1081. const saveData = () => {
  1082. try {
  1083. const data = {};
  1084. $('#globalOptionsForm').serializeArray().map(value => {
  1085. data[value.name] = value.value;
  1086. return value;
  1087. });
  1088. $.makeArray($('#globalOptionsForm input')).map(element => {
  1089. const name = $(element).attr('name');
  1090. const keys = name.split('.');
  1091. if (keys.length === 3) {
  1092. globalOptions[keys[0]][keys[1]][keys[2]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1093. } else if (keys.length === 2) {
  1094. globalOptions[keys[0]][keys[1]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1095. }
  1096. return element;
  1097. });
  1098. GM_setValue('globalOptions', globalOptions);
  1099. external_Swal_default().fire({
  1100. title: i18n('changeGlobalOptionsSuccess'),
  1101. icon: 'success'
  1102. });
  1103. } catch (error) {
  1104. throwError(error, 'saveData');
  1105. }
  1106. };
  1107. const changeGlobalOptions = showType => {
  1108. try {
  1109. let globalOptionsForm = `<form id="globalOptionsForm" class="auto-task-form">
  1110. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  1111. for (const [ type, data1 ] of Object.entries(globalOptions)) {
  1112. for (const [ option, data2 ] of Object.entries(data1)) {
  1113. if ([ 'other', 'position', 'hotKey', 'ASF' ].includes(type)) {
  1114. if (typeof data2 === 'boolean') {
  1115. globalOptionsForm += `<tr style="background-color: ${stringToColour(type)}44">${Object.keys(data1).indexOf(option) === 0 ? `<th rowspan="${Object.keys(data1).length}">${i18n(type)}</th>` : ''}<td>${i18n(option)}</td><td><label><input type="checkbox" name="${type}.${option}"${data2 ? ' checked="checked"' : ''}/><span><i></i></span></label></td></tr>`;
  1116. } else {
  1117. globalOptionsForm += `<tr style="background-color: ${stringToColour(type)}44">${Object.keys(data1).indexOf(option) === 0 ? `<th rowspan="${Object.keys(data1).length}" style="background-color: ${stringToColour(type)}66">${i18n(type)}</th>` : ''}<td>${i18n(option)}</td><td><input class="editOption" type="text" name="${type}.${option}" value="${data2}"/></td></tr>`;
  1118. }
  1119. } else {
  1120. for (const [ socialType, data3 ] of Object.entries(data2)) {
  1121. globalOptionsForm += `<tr style="background-color: ${stringToColour(option)}66">${Object.keys(data1).indexOf(option) === 0 ? `<th rowspan="${Object.keys(data1).map(key => Object.keys(data1[key]).length).reduce((acr, cur) => acr + cur)}" style="background-color: ${stringToColour(type)}66">${i18n(type)}</th>` : ''}<td>${option}.${i18n(socialType)}</td><td><label><input type="checkbox" name="${type}.${option}.${socialType}"${data3 ? ' checked="checked"' : ''}/><span><i></i></span></label></td></tr>`;
  1122. }
  1123. }
  1124. }
  1125. }
  1126. globalOptionsForm += '</tbody></table></form>';
  1127. if (showType === 'swal') {
  1128. external_Swal_default().fire({
  1129. title: i18n('globalOptions'),
  1130. html: globalOptionsForm,
  1131. showConfirmButton: true,
  1132. confirmButtonText: i18n('save'),
  1133. showCancelButton: true,
  1134. cancelButtonText: i18n('close')
  1135. }).then(({
  1136. isConfirmed
  1137. }) => {
  1138. if (isConfirmed) {
  1139. saveData();
  1140. }
  1141. });
  1142. } else {
  1143. $('body').append(`<h2>${i18n('globalOptions')}</h2>${globalOptionsForm}`);
  1144. }
  1145. } catch (error) {
  1146. throwError(error, 'changeGlobalOptions');
  1147. }
  1148. };
  1149. const data = {
  1150. website: '网站',
  1151. type: '类型',
  1152. edit: '编辑',
  1153. whiteList: '白名单',
  1154. skipTask: '跳过撤销任务',
  1155. whiteListOptions: '白名单设置',
  1156. changeWhiteListOption: '设置白名单(%0)',
  1157. whiteListNotFound: '找不到此项白名单: %0',
  1158. changeWhiteListSuccess: '白名单修改成功,刷新生效!',
  1159. changeWebsiteOptions: '网站设置',
  1160. changeGlobalOptions: '全局设置',
  1161. ok: '是',
  1162. save: '保存',
  1163. close: '关闭',
  1164. return: '返回',
  1165. option: '选项',
  1166. value: '值',
  1167. websiteOptions: '当前网站设置',
  1168. changeWebsiteOptionsSuccess: '更改当前网站设置成功,刷新生效!',
  1169. changeGlobalOptionsSuccess: '更改全局设置成功,刷新生效!',
  1170. needLogin: '请先登录!',
  1171. getTasksInfo: '正在获取并处理任务信息...',
  1172. gettingKey: '正在获取Key...',
  1173. verifyingTask: '正在验证任务',
  1174. notice: '自动任务脚本提醒',
  1175. noKeysLeft: '此页面已经没有剩余key了,是否关闭?',
  1176. giveawayEnded: '此活动已结束,是否关闭?',
  1177. giveawayNotWork: '此活动因某些原因(已结束/暂停/未开始...)不可用(如果是脚本误判请及时反馈),是否关闭?',
  1178. confirm: '确定',
  1179. cancel: '取消',
  1180. unKnown: '未知',
  1181. unKnownTaskType: '未识别的任务',
  1182. doing: '正在做任务',
  1183. allTasksComplete: '所有任务已完成!',
  1184. getTaskIdFailed: '获取任务Id失败!',
  1185. initSuccess: '%0 初始化成功!',
  1186. initFailed: '%0 初始化失败!',
  1187. errorLink: '链接错误: %0',
  1188. needInit: '请先初始化',
  1189. verifyingAuth: '正在验证%0凭证...',
  1190. updatingAuth: '正在更新%0凭证...',
  1191. refreshingToken: '正在刷新%0凭证...',
  1192. settingToken: '正在设置%0凭证...',
  1193. initing: '正在初始化...',
  1194. getFailed: '获取%0失败!',
  1195. checkLoginFailed: '检测登录状态失败!',
  1196. checkLeftKeyFailed: '检测剩余Key失败!',
  1197. userId: '用户Id',
  1198. joiningGiveaway: '正在加入赠Key',
  1199. needJoinGiveaway: '需要先加入赠Key',
  1200. cannotUndo: '此网站不支持取消任务',
  1201. verifyAuth: '正在验证 %0 凭证...',
  1202. closePageNotice: '如果此页面没有自动关闭,请自行关闭本页面。',
  1203. errorReport: '检测到脚本报错,是否前往反馈BUG?',
  1204. visitingLink: '正在访问链接: ',
  1205. doTask: '做任务',
  1206. undoTask: '撤销任务',
  1207. verifyTask: '验证任务',
  1208. getKey: '获取Key',
  1209. selectAll: '全选',
  1210. selectNone: '全不选',
  1211. invertSelect: '反选',
  1212. doFreeTask: '加入免费赠品',
  1213. doPointTask: '加入点数赠品',
  1214. skipTaskOption: '设置中已配置跳过任务',
  1215. other: '其他',
  1216. globalOptions: '全局设置',
  1217. checkLogin: '登录检测</br>需要登录的网站自动登录,部分本网站支持',
  1218. checkLeftKey: '剩余Key检测</br>赠Key活动结束提示是否关闭,部分本网站支持',
  1219. twitterVerifyId: '通过尝试关注该账号验证Twitter凭证</br>默认为Twitter官方帐号 783214</br>不想关注官方账号可以改为自己的帐号',
  1220. youtubeVerifyChannel: '通过尝试订阅该频道验证YouTube凭证</br>默认为YouTube官方频道 UCrXUsMBcfTVqwAS7DKg9C0Q</br>不想关注官方频道可以改为自己的频道',
  1221. autoUpdateSource: '更新源</br>github: 需代理,实时更新</br>jsdelivr: 可不用代理,更新有延迟</br>standby: 备用</br>auto: 依次使用github, jsdelivr, standby源进行尝试更新',
  1222. saveGlobalOptions: '保存全局设置',
  1223. settingPage: '设置页面',
  1224. name: '名称',
  1225. version: '版本',
  1226. scriptManager: '脚本管理器',
  1227. script: '脚本',
  1228. environment: '环境',
  1229. os: '系统',
  1230. browser: '浏览器',
  1231. getId: '获取 %0 id',
  1232. getTwitterUserId: '获取Twitter用户id(获取id功能仅在设置页面可用)',
  1233. getYoutubeChannelId: '获取Youtube频道id(获取id功能仅在设置页面可用)',
  1234. showButton: '显示按钮',
  1235. hideButton: '隐藏按钮',
  1236. showLog: '显示日志',
  1237. hideLog: '隐藏日志',
  1238. defaultShowButton: '默认显示按钮',
  1239. defaultShowLog: '默认显示日志',
  1240. debug: '输出调试日志,不要开启此选项!',
  1241. receivePreview: '接收预览版更新',
  1242. position: '组件位置',
  1243. buttonSideX: '按钮区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1244. buttonSideY: '按钮区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1245. buttonDistance: '按钮区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1246. showButtonSideX: '显示按钮水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1247. showButtonSideY: '显示按钮垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1248. showButtonDistance: '显示按钮距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1249. logSideX: '日志区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1250. logSideY: '日志区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1251. logDistance: '日志区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1252. hotKey: '快捷键',
  1253. doTaskKey: '做任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1254. undoTaskKey: '撤销任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1255. toggleLogKey: '显示/隐藏日志快捷键</br>(实时预览功能仅在设置页面可用)',
  1256. tasksHistory: '任务历史',
  1257. clearHistory: '清空历史',
  1258. clearHistoryFinished: '已清空任务历史!',
  1259. deleteTask: '删除任务',
  1260. lastChangeTime: '最后一次修改时间',
  1261. clearTaskFinished: '删除以下任务完成!',
  1262. clearTaskFailed: '删除任务失败,没有找到任务名!',
  1263. syncData: '数据同步',
  1264. settingData: '正在上传数据...',
  1265. gettingData: '正在获取数据...',
  1266. help: '帮助',
  1267. fileName: '文件名',
  1268. upload2gist: '同步到Gist',
  1269. downloadFromGist: '从Gist同步',
  1270. saveAndTest: '保存配置并测试',
  1271. testSuccess: '测试成功!',
  1272. testFailed: '测试失败!',
  1273. saveAndTestNotice: '请先保存配置并测试!',
  1274. processingData: '正在处理数据...',
  1275. updatingData: '正在上传数据...',
  1276. syncDataSuccess: '同步数据成功!',
  1277. syncDataFailed: '同步数据失败,请在控制台查看错误信息!',
  1278. downloadingData: '正在下载数据...',
  1279. checkedNoData: '没有检测到远程数据,请确认配置是否正确!',
  1280. savingData: '正在保存数据...',
  1281. syncHistory: '同步任务历史',
  1282. checkUpdateFailed: '检测更新失败',
  1283. newVersionNotice: '检测到新版本V%0, <a class="high-light" href="%1" target="_blank">点此更新</a>',
  1284. language: '语言</br>目前仅支持zh: 中文, en: 英文',
  1285. gistOptions: 'Gist 设置',
  1286. swalNotice: '检测到您第一次安装V4版本脚本,请前往阅读用前必读内容!',
  1287. echoNotice: '检测到您第一次安装V4版本脚本,请<a class="high-light" href="%0" target="_blank">点此前往</a>阅读用前必读内容!',
  1288. noticeLink: 'https://auto-task-doc.js.org/guide/#用前必读',
  1289. toGithub: '前往Github反馈',
  1290. toKeylol: '前往其乐论坛反馈',
  1291. copySuccess: '错误信息已复制到剪切板,是否前往其乐论坛反馈?',
  1292. copyFailed: '请复制下方错误信息后前往Keylol论坛反馈!',
  1293. updateText: '%0 版本更新内容:',
  1294. Active: '进行中',
  1295. Ended: '已结束',
  1296. Banned: '已封禁',
  1297. Paused: '已暂停',
  1298. notStart: '未开始',
  1299. noRemoteData: '检测到远程无数据',
  1300. errorRemoteDataFormat: '远程数据格式错误',
  1301. updateHistory: '历史更新记录<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">点此查看</a>',
  1302. AsfEnabled: '使用ASF做Steam相关任务(需<a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a>插件)',
  1303. AsfIpcUrl: 'ASF IPC 地址',
  1304. AsfIpcPassword: 'ASF IPC 密码',
  1305. versionNotMatched: '脚本管理器版本过低,需TamperMonkey >= 5.2.0或TamperMonkey Beta >= 5.2.6196',
  1306. groups: '组',
  1307. officialGroups: '官方组',
  1308. wishlists: '愿望单',
  1309. follows: '游戏关注',
  1310. forums: '论坛',
  1311. workshops: '创意工坊收藏',
  1312. curators: '鉴赏家',
  1313. workshopVotes: '创意工坊点赞',
  1314. announcements: '社区通知',
  1315. steamCommunity: 'Steam社区',
  1316. steamStore: 'Steam商店',
  1317. licenses: '入库免费游戏',
  1318. playtests: '请求访问权限',
  1319. needLoginSteamStore: '请先<a href="https://store.steampowered.com/login/" target="_blank">登录Steam商店</a>',
  1320. needLoginSteamCommunity: '请先<a href="https://steamcommunity.com/login/home/" target="_blank">登录Steam社区</a>',
  1321. joiningSteamGroup: '正在加入Steam组',
  1322. leavingSteamGroup: '正在退出Steam组',
  1323. gettingSteamGroupId: '正在获取Steam组Id',
  1324. joiningSteamOfficialGroup: '正在加入Steam官方组',
  1325. leavingSteamOfficialGroup: '正在退出Steam官方组',
  1326. gettingSteamOfficialGroupId: '正在获取Steam官方组Id',
  1327. subscribingForum: '正在订阅Steam论坛',
  1328. unsubscribingForum: '正在取消订阅Steam论坛',
  1329. gettingForumId: '正在获取Steam论坛Id',
  1330. followingCurator: '正在关注Steam鉴赏家',
  1331. unfollowingCurator: '正在取关Steam鉴赏家',
  1332. gettingCuratorId: '正在获取Steam鉴赏家Id',
  1333. addingToWishlist: '正在添加游戏到Steam愿望单',
  1334. removingFromWishlist: '正在从Steam愿望单移除游戏',
  1335. followingGame: '正在关注Steam游戏',
  1336. unfollowingGame: '正在取关Steam游戏',
  1337. favoritingWorkshop: '正在收藏Steam创意工坊物品',
  1338. unfavoritingWorkshop: '正在取消收藏Steam创意工坊物品',
  1339. gettingWorkshopAppId: '正在获取Steam创意工坊物品Id',
  1340. votingUpWorkshop: '正在点赞Steam创意工坊物品',
  1341. gettingAnnouncementParams: '正在获取Steam通知信息',
  1342. likingAnnouncement: '正在点赞Steam通知',
  1343. changingArea: '正在更换Steam地区: %0...',
  1344. notNeededChangeArea: '当前地区不需要更换',
  1345. noAnotherArea: '请检测是否开启正确开启代理',
  1346. gettingAreaInfo: '正在获取Steam地区信息...',
  1347. changeAreaNotice: '疑似锁区游戏,尝试换区执行',
  1348. steamFinishNotice: 'Steam任务完成,尝试将购物车地区换回CN',
  1349. gettingSubid: '正在获取游戏subid',
  1350. addingFreeLicense: '正在入库',
  1351. missParams: '缺少参数',
  1352. gettingLicenses: '正在获取Licenses...',
  1353. requestingPlayTestAccess: '正在请求访问权限',
  1354. tryChangeAreaNotice: '此功能无法检测游戏是否限区,因此会尝试换区后再入库,换区失败也不影响后续入库',
  1355. gettingUserLink: '正在获取Steam用户社区链接...',
  1356. retry: '重试',
  1357. initingASF: '正在初始化ASF...',
  1358. servers: '服务器',
  1359. joiningDiscordServer: '正在加入Discord服务器',
  1360. leavingDiscordServer: '正在退出Discord服务器',
  1361. gettingDiscordGuild: '正在获取Discord服务器Id',
  1362. getDiscordAuthFailed: '获取Discord凭证失败,请检测Discord帐号是否已登录',
  1363. discordImportantNotice: '重要提醒!!!',
  1364. discordImportantNoticeText: '由于Discord网站后台更新,目前使用此脚本加组后可能会导致Discord帐号被强制退出,且需要两步验证才能正常登录,请谨慎使用!!!',
  1365. continue: '继续',
  1366. skipDiscordTask: '跳过Discord任务',
  1367. continueAndDontRemindAgain: '继续且不再提醒',
  1368. users: '用户',
  1369. loginIns: '请先<a href="https://www.instagram.com/accounts/login/" target="_blank">登录Instagram</a>',
  1370. insBanned: '您的Instagram账户已被封禁',
  1371. verifyingInsAuth: '正在验证Instagram凭证...',
  1372. gettingInsUserId: '正在获取Instagram用户Id',
  1373. followingIns: '正在关注Instagram用户',
  1374. unfollowingIns: '正在取关Instagram用户',
  1375. reddits: '社区/用户',
  1376. loginReddit: '请先<a href="https://www.reddit.com/login/" target="_blank">登录Reddit</a>',
  1377. changingRedditVersion: '正在切换Reddit为新版页面...',
  1378. joiningReddit: '正在加入Reddit社区',
  1379. leavingReddit: '正在退出Reddit社区',
  1380. followingRedditUser: '正在关注Reddit用户',
  1381. unfollowingRedditUser: '正在取关Reddit用户',
  1382. channels: '频道',
  1383. followingTwitchChannel: '正在关注Twitch频道',
  1384. unfollowingTwitchChannel: '正在取关Twitch频道',
  1385. gettingTwitchChannelId: '正在获取Twitch频道Id',
  1386. checkingTwitchIntegrity: '正在检查Twitch完整性...',
  1387. twitterUser: '推特用户',
  1388. retweets: '转推',
  1389. gettingTwitterUserId: '正在获取推特用户Id',
  1390. followingTwitterUser: '正在关注推特用户',
  1391. unfollowingTwitterUser: '正在取关推特用户',
  1392. retweetting: '正在转推',
  1393. unretweetting: '正在撤销转推',
  1394. names: '组/社区/动态',
  1395. loginVk: '请先<a href="https://vk.com/login/" target="_blank">登录Vk</a>',
  1396. gettingVkId: '正在获取Vk任务Id',
  1397. joiningVkGroup: '正在加入Vk组',
  1398. leavingVkGroup: '正在退出Vk组',
  1399. joiningVkPublic: '正在加入Vk社区',
  1400. leavingVkPublic: '正在退出Vk社区',
  1401. sendingVkWall: '正在转发Vk动态',
  1402. deletingVkWall: '正在撤销转发Vk动态',
  1403. youtubeChannel: 'YouTube频道',
  1404. likes: '点赞',
  1405. loginYtb: '请先<a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">登录YouTube</a>',
  1406. tryUpdateYtbAuth: '请尝试<a href="https://www.youtube.com/#auth" target="_blank">更新YouTube凭证</a>',
  1407. gettingYtbToken: '正在获取YouTube Token...',
  1408. followingYtbChannel: '正在订阅YouTube频道',
  1409. unfollowingYtbChannel: '正在退订YouTube频道',
  1410. likingYtbVideo: '正在点赞YouTube视频',
  1411. unlikingYtbVideo: '正在取消点赞YouTube视频',
  1412. giveKeyNoticeBefore: '每次验证间隔15s',
  1413. giveKeyNoticeAfter: '如果没有key, 请在<a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>查看',
  1414. noPoints: '点数不够,跳过抽奖',
  1415. getNeedPointsFailed: '获取所需点数失败,跳过抽奖',
  1416. joiningLottery: '正在加入抽奖',
  1417. doingGleamTask: '正在做Gleam任务...',
  1418. gettingGleamLink: '正在获取Gleam任务链接...',
  1419. gleamTaskNotice: '如果此页面长时间未关闭,请完成任一任务后自行关闭!',
  1420. verifiedGleamTasks: '已尝试验证所有任务,验证失败的任务请尝试手动验证或完成!',
  1421. campaign: '检测到人机验证,请完成验证后重新验证任务!',
  1422. gsNotice: '为避免得到"0000-0000-0000"key, 已自动屏蔽"Grab Key"按钮,获取key时请关闭脚本!',
  1423. giveeClubVerifyNotice: '正在验证任务...',
  1424. giveeClubVerifyFinished: '请等待验证完成后自行加入赠Key',
  1425. doingKeyhubTask: '正在做Keyhub任务...',
  1426. SweepWidgetNotice: '正在处理并验证任务,每次验证任务有1~3s间隔防止触发验证过快警告...',
  1427. confirmingTask: '正在跳过警告页面...'
  1428. };
  1429. const zh_CN = data;
  1430. const en_US_data = {
  1431. website: 'Website',
  1432. type: 'Type',
  1433. edit: 'Edit',
  1434. whiteList: 'Whitelist',
  1435. skipTask: 'Skip undo task',
  1436. whiteListOptions: 'Whitelist options',
  1437. changeWhiteListOption: 'Whitelist option(%0)',
  1438. whiteListNotFound: 'Cannot find this whitelist: %0',
  1439. changeWhiteListSuccess: 'The whitelist is successfully modified, and the page refresh will take effect!',
  1440. changeWebsiteOptions: 'Website options',
  1441. changeGlobalOptions: 'Global options',
  1442. ok: 'OK',
  1443. save: 'Save',
  1444. close: 'Close',
  1445. return: 'Return',
  1446. option: 'Option',
  1447. value: 'Value',
  1448. websiteOptions: 'Current website settings',
  1449. changeWebsiteOptionsSuccess: 'The current website setting is changed successfully, and the page refresh will take effect!',
  1450. changeGlobalOptionsSuccess: 'The global setting is changed successfully, and the refresh will take effect!',
  1451. needLogin: 'Please log in first!',
  1452. getTasksInfo: 'Obtaining and processing task information...',
  1453. gettingKey: 'Getting Key...',
  1454. verifyingTask: 'Verifying task',
  1455. notice: 'Automatic task script notice',
  1456. noKeysLeft: 'There are no more keys left on this page. Do you want to close it?',
  1457. giveawayEnded: 'This event has ended, do you want to close it?',
  1458. 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?',
  1459. confirm: 'Confirm',
  1460. cancel: 'Cancel',
  1461. unKnown: 'Unknown',
  1462. unKnownTaskType: 'Unrecognized task',
  1463. doing: 'Doing a task',
  1464. allTasksComplete: 'All tasks have been completed!',
  1465. getTaskIdFailed: 'Failed to obtain task Id!',
  1466. initSuccess: '%0 was initialized successfully!',
  1467. initFailed: '%0 initialization failed!',
  1468. errorLink: 'Link error: %0',
  1469. needInit: 'Please initialize first',
  1470. verifyingAuth: 'Verifying %0 token...',
  1471. updatingAuth: 'Update %0 token...',
  1472. initing: 'Initializing...',
  1473. getFailed: 'Failed to get %0!',
  1474. checkLoginFailed: 'Failed to detect login status!',
  1475. checkLeftKeyFailed: 'Failed to detect the remaining keys!',
  1476. userId: 'User Id',
  1477. joiningGiveaway: 'Joining giveaway',
  1478. needJoinGiveaway: 'Need to join the giveaway first',
  1479. cannotUndo: 'This website does not support canceling tasks',
  1480. verifyAuth: 'Verifying %0 token...',
  1481. closePageNotice: 'f this page does not close automatically, please close this page yourself.',
  1482. errorReport: 'A script error is detected, do you want to report the BUG?',
  1483. visitingLink: 'Visiting link: ',
  1484. doTask: 'DoTask',
  1485. undoTask: 'UndoTask',
  1486. verifyTask: 'Verify',
  1487. getKey: 'GetKey',
  1488. selectAll: 'SelectAll',
  1489. selectNone: 'SelectNone',
  1490. invertSelect: 'InvertSelect',
  1491. doFreeTask: 'FreeTask',
  1492. doPointTask: 'PointTask',
  1493. skipTaskOption: 'Skip task has been configured in the settings',
  1494. other: 'Other',
  1495. globalOptions: 'Global Options',
  1496. checkLogin: 'Login detection</br>Need to log in to the website automatically log in, part of this website supports.',
  1497. checkLeftKey: 'Key remaining detection</br>The end of the giveaway event prompts whether to close or not, part of this website supports.',
  1498. 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.',
  1499. 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.',
  1500. 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.',
  1501. saveGlobalOptions: 'SaveSettings',
  1502. settingPage: 'Setting Page',
  1503. name: 'Name',
  1504. version: 'Version',
  1505. scriptManager: 'Script Manager',
  1506. script: 'Script',
  1507. environment: 'Environment',
  1508. os: 'OS',
  1509. browser: 'Browser',
  1510. getId: 'Get %0 id',
  1511. getTwitterUserId: 'Get Twitter user id (Get id function is only available on the settings page).',
  1512. getYoutubeChannelId: 'Get Youtube channel id (Get id function is only available on the settings page).',
  1513. showButton: 'ShowButton',
  1514. hideButton: 'HideButton',
  1515. showLog: 'ShowLog',
  1516. hideLog: 'HideLog',
  1517. defaultShowButton: 'Default display button',
  1518. defaultShowLog: 'Display log by default',
  1519. debug: 'Output debug log, do not enable this option!',
  1520. receivePreview: 'Receive preview updates',
  1521. position: 'Component position',
  1522. buttonSideX: 'Horizontal positioning of the button area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1523. 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',
  1524. 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',
  1525. showButtonSideX: 'ShowButton horizontal positioning (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1526. showButtonSideY: 'ShowButton vertical positioning (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1527. 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',
  1528. logSideX: 'Horizontal positioning of the log area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1529. logSideY: 'Vertical positioning of the log area (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1530. 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',
  1531. hotKey: 'Shortcut key',
  1532. doTaskKey: 'DoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1533. undoTaskKey: 'UndoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1534. toggleLogKey: 'ShowLog/HideLog shortcut keys</br> (real-time preview function is only available on the settings page).',
  1535. tasksHistory: 'TasksHistory',
  1536. clearHistory: 'Clear history',
  1537. clearHistoryFinished: 'The mission history has been cleared!',
  1538. deleteTask: 'Delete task',
  1539. lastChangeTime: 'Last Change Time',
  1540. clearTaskFinished: 'Delete the following tasks completed!',
  1541. clearTaskFailed: 'Failed to delete the task, the task name was not found!',
  1542. syncData: 'DataSync',
  1543. settingData: 'Uploading data...',
  1544. gettingData: 'Getting data...',
  1545. help: 'Help',
  1546. fileName: 'Filename',
  1547. upload2gist: 'Sync to Gist',
  1548. downloadFromGist: 'Sync from Gist',
  1549. saveAndTest: 'Save configuration and test',
  1550. testSuccess: 'Test success!',
  1551. testFailed: 'Test failed!',
  1552. saveAndTestNotice: 'Please save the configuration and test first!',
  1553. processingData: 'Processing data...',
  1554. updatingData: 'Uploading data...',
  1555. syncDataSuccess: 'Synchronized data successfully!',
  1556. syncDataFailed: 'Failed to synchronize data, please check the error message on the console!',
  1557. downloadingData: 'Downloading data...',
  1558. checkedNoData: 'No remote data is detected, please confirm whether the configuration is correct!',
  1559. savingData: 'Saving data...',
  1560. syncHistory: 'Synchronize tasks history',
  1561. checkUpdateFailed: 'Check update failed',
  1562. newVersionNotice: 'Checked a new version V%0, <a class="high-light" href="%1" target="_blank">click to update</a>',
  1563. language: 'Language</br> Currently only supports zh: Chinese, en: English',
  1564. gistOptions: 'Gist Settings',
  1565. 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!',
  1566. 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!',
  1567. noticeLink: 'https://auto-task-doc.js.org/en/guide/#read-me-first',
  1568. toGithub: 'Feedback(Github)',
  1569. toKeylol: 'Feedback(Keylol)',
  1570. copySuccess: 'The error message has been copied to the clipboard. Do you want to go to the Keylol forum to give feedback?',
  1571. copyFailed: 'Please copy the error information below and report back to the Keylol forum!',
  1572. updateText: 'Updates in version %0:',
  1573. Active: 'Active',
  1574. Ended: 'Ended',
  1575. Banned: 'Banned',
  1576. Paused: 'Paused',
  1577. notStart: 'notStart',
  1578. noRemoteData: 'No data remotely',
  1579. errorRemoteDataFormat: 'Remote data has wrong format',
  1580. updateHistory: '<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">Click here</a>' + ' to view the historical update record.',
  1581. AsfEnabled: 'Use ASF to do Steam related tasks (requires <a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a> plugin)',
  1582. AsfIpcUrl: 'ASF IPC URL',
  1583. AsfIpcPassword: 'ASF IPC Password',
  1584. groups: 'Group',
  1585. officialGroups: 'Official Group',
  1586. wishlists: 'Wishlist',
  1587. follows: 'Follow Game',
  1588. forums: 'Forum',
  1589. workshops: 'Favorite Workshop',
  1590. curators: 'Curator',
  1591. workshopVotes: 'Voteup Workshop',
  1592. announcements: 'Announcement',
  1593. steamCommunity: 'Steam Community',
  1594. steamStore: 'Steam Store',
  1595. licenses: 'Add License',
  1596. playtests: 'Playtest Access',
  1597. needLoginSteamStore: 'Please <a href="https://store.steampowered.com/login/" target="_blank">log in to the Steam Store</a>',
  1598. needLoginSteamCommunity: 'Please <a href="https://steamcommunity.com/login/home/" target="_blank">log in to the Steam Community</a>',
  1599. joiningSteamGroup: 'Joining Steam Group',
  1600. leavingSteamGroup: 'Leaving Steam Group',
  1601. gettingSteamGroupId: 'Getting Steam Group Id',
  1602. joiningSteamOfficialGroup: 'Joining Steam Official Group',
  1603. leavingSteamOfficialGroup: 'Leaving Steam Official Group',
  1604. gettingSteamOfficialGroupId: 'Getting Steam Official Group Id',
  1605. subscribingForum: 'Subscribing the Steam Forum',
  1606. unsubscribingForum: 'Unsubscribing the Steam Forum',
  1607. gettingForumId: 'Getting Steam Forum Id',
  1608. followingCurator: 'Following Steam Curator',
  1609. unfollowingCurator: 'Unfollowing Steam Curator',
  1610. gettingCuratorId: 'Getting Steam Curator Id',
  1611. addingToWishlist: 'Adding the game to the Steam wishlist',
  1612. removingFromWishlist: 'Removing the game from the Steam wishlist',
  1613. followingGame: 'Following Steam games',
  1614. unfollowingGame: 'Unfollowing Steam games',
  1615. favoritingWorkshop: 'Favouring Steam Workshop Items',
  1616. unfavoritingWorkshop: 'Unfavoriting Steam Workshop Items',
  1617. gettingWorkshopAppId: 'Getting Steam Workshop Item Id',
  1618. votingUpWorkshop: 'Liking Steam workshop items',
  1619. gettingAnnouncementParams: 'Getting Steam announcement information',
  1620. likingAnnouncement: 'Liking Steam announcement',
  1621. changingArea: 'Changing Steam area: %0...',
  1622. notNeededChangeArea: 'The current area does not need to be changed',
  1623. noAnotherArea: 'Please check whether the proxy is turned on correctly',
  1624. gettingAreaInfo: 'Getting Steam area information...',
  1625. changeAreaNotice: 'Suspected of a locked zone game, try to change the zone to execute',
  1626. steamFinishNotice: 'Steam task completed, try to change the shopping cart area back to CN',
  1627. gettingSubid: 'Getting subid',
  1628. addingFreeLicense: 'Adding free license',
  1629. missParams: 'Missing parameters',
  1630. gettingLicenses: 'Getting licenses...',
  1631. requestingPlayTestAccess: 'Requesting play test access',
  1632. 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.',
  1633. versionNotMatched: 'The script manager version is too low, requiring TamperMonkey >= 5.2.0 or TamperMonkey Beta >= 5.2.6196',
  1634. gettingUserLink: 'Getting steam user community link...',
  1635. retry: 'Retry',
  1636. initingASF: 'Initing ASF...',
  1637. servers: 'Server',
  1638. joiningDiscordServer: 'Joining Discord Server',
  1639. leavingDiscordServer: 'Leaving Discord Server',
  1640. gettingDiscordGuild: 'Getting Discord server Id',
  1641. getDiscordAuthFailed: 'Failed to get Discord token, please check whether the Discord account is logged in',
  1642. discordImportantNotice: 'Important Reminder! ! !',
  1643. 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! ! !',
  1644. continue: 'Continue',
  1645. skipDiscordTask: 'Skip',
  1646. continueAndDontRemindAgain: 'Continue without Reminders',
  1647. users: 'User',
  1648. loginIns: 'Please <a href="https://www.instagram.com/accounts/login/" target="_blank">log in to Instagram</a>',
  1649. insBanned: 'Your Instagram account has been banned',
  1650. verifyingInsAuth: 'Verifying Instagram token...',
  1651. gettingInsUserId: 'Getting Instagram user Id',
  1652. followingIns: 'Following Instagram user',
  1653. unfollowingIns: 'Unfollowing Instagram user',
  1654. reddits: 'Reddit/User',
  1655. loginReddit: 'Please <a href="https://www.reddit.com/login/" target="_blank">log in to Reddit</a>',
  1656. changingRedditVersion: 'Switching Reddit to a new version page...',
  1657. joiningReddit: 'Joining the Reddit',
  1658. leavingReddit: 'Leaving the Reddit',
  1659. followingRedditUser: 'Following Reddit User',
  1660. unfollowingRedditUser: 'Unfollowing Reddit User',
  1661. channels: 'Channel',
  1662. followingTwitchChannel: 'Following Twitch Channel',
  1663. unfollowingTwitchChannel: 'Unfollowing Twitch Channel',
  1664. gettingTwitchChannelId: 'Getting Twitch Channel Id',
  1665. checkingTwitchIntegrity: 'Checking Twitch integrity...',
  1666. twitterUser: 'Twitter User',
  1667. retweets: 'Retweet',
  1668. gettingTwitterUserId: 'Getting Twitter User Id',
  1669. followingTwitterUser: 'Following Twitter User',
  1670. unfollowingTwitterUser: 'Unfollowing Twitter User',
  1671. retweetting: 'Retweetting',
  1672. unretweetting: 'Unretweetting',
  1673. names: 'Group/Public/Wall',
  1674. loginVk: 'Please <a href="https://vk.com/login/" target="_blank">log in to Vk</a>',
  1675. gettingVkId: 'Getting Vk task Id',
  1676. joiningVkGroup: 'Joining Vk Group',
  1677. leavingVkGroup: 'Leaving Vk Group',
  1678. joiningVkPublic: 'Joining Vk Public',
  1679. leavingVkPublic: 'Leaving Vk Public',
  1680. sendingVkWall: 'Sending Vk Wall',
  1681. deletingVkWall: 'Deleting Vk Wall',
  1682. youtubeChannel: 'YouTube Channel',
  1683. likes: 'Like',
  1684. loginYtb: 'Please <a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">log in to YouTube</a>',
  1685. tryUpdateYtbAuth: 'Please try to <a href="https://www.youtube.com/#auth" target="_blank">update YouTube token</a>',
  1686. gettingYtbToken: 'Getting YouTube Token...',
  1687. followingYtbChannel: 'Subscribing to YouTube channel',
  1688. unfollowingYtbChannel: 'Unsubscribing to YouTube channel',
  1689. likingYtbVideo: 'Liking YouTube video',
  1690. unlikingYtbVideo: 'Unliking YouTube video',
  1691. giveKeyNoticeBefore: 'Each verification interval is 15s',
  1692. giveKeyNoticeAfter: 'If there is no key, please check at <a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>',
  1693. noPoints: 'Not enough points, skip the lottery',
  1694. getNeedPointsFailed: 'ailed to obtain the required points, skip the lottery',
  1695. joiningLottery: 'Joining the lottery',
  1696. doingGleamTask: 'Doing Gleam Task...',
  1697. gettingGleamLink: 'Getting Gleam task link...',
  1698. gleamTaskNotice: 'If this page has not been closed for a long time, please close it yourself after completing any task!',
  1699. verifiedGleamTasks: 'Attempted to verify all tasks. If the verification fails, please try to verify manually or complete it!',
  1700. campaign: 'ReCAPTCHA detected, please complete it and re-verify the tasks!',
  1701. 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!',
  1702. giveeClubVerifyNotice: 'Verifying task...',
  1703. giveeClubVerifyFinished: 'Wait for the verification to complete and join it by yourself',
  1704. doingKeyhubTask: 'Doing Keyhub Task...',
  1705. 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...',
  1706. confirmingTask: 'Confirming task...'
  1707. };
  1708. const en_US = en_US_data;
  1709. const languages = {
  1710. zh: zh_CN,
  1711. en: en_US
  1712. };
  1713. const language = [ 'zh', 'en' ].includes(globalOptions.other.language) ? globalOptions.other.language : 'en';
  1714. const I18n = (key, ...argvs) => {
  1715. if (!languages[language]?.[key]) {
  1716. return key;
  1717. }
  1718. return languages[language][key].replace(/%([\d]+)/g, (match, index) => argvs[parseInt(index, 10)]);
  1719. };
  1720. const i18n = I18n;
  1721. function throwError(error, name) {
  1722. if (window.TRACE) {
  1723. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  1724. }
  1725. external_Swal_default().fire({
  1726. title: i18n('errorReport'),
  1727. icon: 'error',
  1728. showCancelButton: true,
  1729. confirmButtonText: i18n('toGithub'),
  1730. showDenyButton: true,
  1731. denyButtonText: i18n('toKeylol'),
  1732. cancelButtonText: i18n('close')
  1733. }).then(({
  1734. isDenied,
  1735. isConfirmed
  1736. }) => {
  1737. if (isConfirmed) {
  1738. window.open(`https://github.com/HCLonely/auto-task-v4/issues/new?title=${encodeURIComponent(`[BUG] 脚本报错: ${name}`)}&labels=bug&template=bug_report.yml&website=${encodeURIComponent(window.location.href)}&browser=${encodeURIComponent(JSON.stringify((0,
  1739. javascript_utils_umd_min.ua)(), null, 4))}&manager=${encodeURIComponent(`${GM_info.scriptHandler} ${GM_info.version}`)}&user-script=${encodeURIComponent(GM_info.script.version)}&logs=${encodeURIComponent(error.stack || 'null')}&run-logs=${encodeURIComponent($.makeArray($('#auto-task-info>li')).map(element => element.innerText).join('\n'))}`, '_blank');
  1740. } else if (isDenied) {
  1741. const text = `错误链接: [url=${window.location.href}]${window.location.href}[/url]
  1742.  
  1743. 环境:
  1744.  
  1745. [code]${JSON.stringify((0, javascript_utils_umd_min.ua)(), null, 4)}[/code]
  1746.  
  1747. 脚本管理器: ${GM_info.scriptHandler} ${GM_info.version}
  1748. 脚本版本: ${GM_info.script.version}
  1749.  
  1750. 报错信息:
  1751. [code]${error.stack}[/code]
  1752.  
  1753. 执行日志:
  1754. [code]${$.makeArray($('#auto-task-info>li')).map(element => element.innerText).join('\n')}[/code]`;
  1755. GM_setClipboard(text);
  1756. external_Swal_default().fire({
  1757. title: i18n('copySuccess'),
  1758. icon: 'success',
  1759. confirmButtonText: i18n('ok')
  1760. }).then(() => {
  1761. window.open('https://keylol.com/forum.php?mod=post&action=reply&fid=319&tid=777450', '_blank');
  1762. });
  1763. }
  1764. });
  1765. console.log('%c%s', 'color:white;background:red', `Auto-Task[Error]: ${name}\n${error.stack}`);
  1766. }
  1767. class Social {
  1768. tasks;
  1769. getRealParams(name, links, doTask, link2param) {
  1770. try {
  1771. let realParams = [];
  1772. if (links.length > 0) {
  1773. realParams = [ ...realParams, ...links.map(link => link2param(link)).filter(link => link) ];
  1774. }
  1775. if (!doTask && this.tasks[name].length > 0) {
  1776. realParams = [ ...realParams, ...this.tasks[name] ];
  1777. }
  1778. return unique(realParams);
  1779. } catch (error) {
  1780. throwError(error, 'Social.getRealParams');
  1781. return [];
  1782. }
  1783. }
  1784. }
  1785. const social_Social = Social;
  1786. class Discord extends social_Social {
  1787. tasks;
  1788. whiteList;
  1789. #auth = GM_getValue('discordAuth') || {};
  1790. #cache = GM_getValue('discordCache') || {};
  1791. #initialized = false;
  1792. constructor() {
  1793. super();
  1794. const defaultTasksTemplate = {
  1795. servers: []
  1796. };
  1797. this.tasks = defaultTasksTemplate;
  1798. this.whiteList = {
  1799. ...defaultTasksTemplate,
  1800. ...GM_getValue('whiteList')?.discord || {}
  1801. };
  1802. }
  1803. async init(action) {
  1804. try {
  1805. if (!GM_getValue('dontRemindDiscordAgain')) {
  1806. const result = await external_Swal_default().fire({
  1807. title: i18n('discordImportantNotice'),
  1808. text: i18n('discordImportantNoticeText'),
  1809. showCancelButton: true,
  1810. showDenyButton: true,
  1811. confirmButtonText: i18n('continue'),
  1812. cancelButtonText: i18n('skipDiscordTask'),
  1813. denyButtonText: i18n('continueAndDontRemindAgain')
  1814. }).then(({
  1815. isConfirmed,
  1816. isDenied
  1817. }) => {
  1818. if (isConfirmed) {
  1819. return true;
  1820. }
  1821. if (isDenied) {
  1822. GM_setValue('dontRemindDiscordAgain', true);
  1823. return true;
  1824. }
  1825. return false;
  1826. });
  1827. if (!result) {
  1828. this.#initialized = false;
  1829. return 'skip';
  1830. }
  1831. }
  1832. if (GM_getValue('dontRemindDiscordAgain') || action === 'do' && !globalOptions.doTask.discord.servers || action === 'undo' && !globalOptions.undoTask.discord.servers) {
  1833. this.#initialized = false;
  1834. return 'skip';
  1835. }
  1836. if (this.#initialized) {
  1837. return true;
  1838. }
  1839. if (!this.#auth.auth) {
  1840. if (await this.#updateAuth()) {
  1841. this.#initialized = true;
  1842. return true;
  1843. }
  1844. return false;
  1845. }
  1846. const isVerified = await this.#verifyAuth();
  1847. if (isVerified) {
  1848. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1849. this.#initialized = true;
  1850. return true;
  1851. }
  1852. GM_setValue('discordAuth', {
  1853. auth: null
  1854. });
  1855. if (await this.#updateAuth()) {
  1856. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1857. this.#initialized = true;
  1858. return true;
  1859. }
  1860. scripts_echoLog({}).error(i18n('initFailed', 'Discord'));
  1861. return false;
  1862. } catch (error) {
  1863. throwError(error, 'Discord.init');
  1864. return false;
  1865. }
  1866. }
  1867. async #verifyAuth() {
  1868. try {
  1869. const logStatus = scripts_echoLog({
  1870. text: i18n('verifyingAuth', 'Discord')
  1871. });
  1872. const {
  1873. result,
  1874. statusText,
  1875. status,
  1876. data
  1877. } = await tools_httpRequest({
  1878. url: 'https://discord.com/api/v6/users/@me',
  1879. method: 'HEAD',
  1880. headers: {
  1881. authorization: this.#auth.auth
  1882. }
  1883. });
  1884. if (result === 'Success') {
  1885. if (data?.status === 200) {
  1886. logStatus.success();
  1887. return true;
  1888. }
  1889. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  1890. return false;
  1891. }
  1892. logStatus.error(`${result}:${statusText}(${status})`);
  1893. return false;
  1894. } catch (error) {
  1895. throwError(error, 'Discord.verifyAuth');
  1896. return false;
  1897. }
  1898. }
  1899. async #updateAuth() {
  1900. try {
  1901. const logStatus = scripts_echoLog({
  1902. text: i18n('updatingAuth', 'Discord')
  1903. });
  1904. return await new Promise(resolve => {
  1905. const newTab = GM_openInTab('https://discord.com/channels/@me#auth', {
  1906. active: true,
  1907. insert: true,
  1908. setParent: true
  1909. });
  1910. newTab.onclose = async () => {
  1911. const auth = GM_getValue('discordAuth')?.auth;
  1912. if (auth) {
  1913. this.#auth = {
  1914. auth: auth
  1915. };
  1916. logStatus.success();
  1917. resolve(await this.#verifyAuth());
  1918. } else {
  1919. logStatus.error('Error: Update discord auth failed!');
  1920. resolve(false);
  1921. }
  1922. };
  1923. });
  1924. } catch (error) {
  1925. throwError(error, 'Discord.updateAuth');
  1926. return false;
  1927. }
  1928. }
  1929. async #joinServer(inviteId) {
  1930. try {
  1931. const logStatus = scripts_echoLog({
  1932. type: 'joiningDiscordServer',
  1933. text: inviteId
  1934. });
  1935. const {
  1936. result,
  1937. statusText,
  1938. status,
  1939. data
  1940. } = await tools_httpRequest({
  1941. url: `https://discord.com/api/v9/invites/${inviteId}`,
  1942. method: 'POST',
  1943. dataType: 'json',
  1944. headers: {
  1945. authorization: this.#auth.auth,
  1946. origin: 'https://discord.com',
  1947. referer: `https://discord.com/invite/${inviteId}`
  1948. }
  1949. });
  1950. if (result === 'Success' && data?.status === 200) {
  1951. logStatus.success();
  1952. const guild = String(data.response?.guild?.id);
  1953. if (guild) {
  1954. this.#setCache(inviteId, guild);
  1955. this.tasks.servers = unique([ ...this.tasks.servers, inviteId ]);
  1956. }
  1957. return true;
  1958. }
  1959. logStatus.error(`${result}:${statusText}(${status})`);
  1960. return false;
  1961. } catch (error) {
  1962. throwError(error, 'Discord.joinServer');
  1963. return false;
  1964. }
  1965. }
  1966. async #leaveServer(inviteId) {
  1967. try {
  1968. if (this.whiteList.servers.includes(inviteId)) {
  1969. scripts_echoLog({
  1970. type: 'whiteList',
  1971. text: 'Discord.leaveServer',
  1972. id: inviteId
  1973. });
  1974. return true;
  1975. }
  1976. const guild = await this.#getGuild(inviteId);
  1977. if (!guild) {
  1978. return false;
  1979. }
  1980. const logStatus = scripts_echoLog({
  1981. type: 'leavingDiscordServer',
  1982. text: guild
  1983. });
  1984. const {
  1985. result,
  1986. statusText,
  1987. status,
  1988. data
  1989. } = await tools_httpRequest({
  1990. url: `https://discord.com/api/v9/users/@me/guilds/${guild}`,
  1991. method: 'DELETE',
  1992. headers: {
  1993. authorization: this.#auth.auth
  1994. }
  1995. });
  1996. if (result === 'Success' && data?.status === 204) {
  1997. logStatus.success();
  1998. return true;
  1999. }
  2000. logStatus.error(`${result}:${statusText}(${status})`);
  2001. return false;
  2002. } catch (error) {
  2003. throwError(error, 'Discord.leaveServer');
  2004. return false;
  2005. }
  2006. }
  2007. async #getGuild(inviteId) {
  2008. try {
  2009. const logStatus = scripts_echoLog({
  2010. type: 'gettingDiscordGuild',
  2011. text: inviteId
  2012. });
  2013. const guild = this.#cache[inviteId];
  2014. if (guild) {
  2015. logStatus.success();
  2016. return guild;
  2017. }
  2018. const {
  2019. result,
  2020. statusText,
  2021. status,
  2022. data
  2023. } = await tools_httpRequest({
  2024. url: `https://discord.com/api/v9/invites/${inviteId}`,
  2025. responseType: 'json',
  2026. method: 'GET'
  2027. });
  2028. if (result === 'Success' && data?.status === 200) {
  2029. const guild = data.response?.guild?.id;
  2030. if (guild) {
  2031. logStatus.success();
  2032. this.#setCache(inviteId, guild);
  2033. return guild;
  2034. }
  2035. logStatus.error(`${result}:${statusText}(${status})`);
  2036. return false;
  2037. }
  2038. logStatus.error(`${result}:${statusText}(${status})`);
  2039. return false;
  2040. } catch (error) {
  2041. throwError(error, 'Discord.getGuild');
  2042. return false;
  2043. }
  2044. }
  2045. async toggle({
  2046. doTask = true,
  2047. serverLinks = []
  2048. }) {
  2049. try {
  2050. if (!this.#initialized) {
  2051. scripts_echoLog({
  2052. text: i18n('needInit')
  2053. });
  2054. return false;
  2055. }
  2056. const prom = [];
  2057. if (doTask && !globalOptions.doTask.discord.servers || !doTask && !globalOptions.undoTask.discord.servers) {
  2058. scripts_echoLog({
  2059. type: 'globalOptionsSkip',
  2060. text: 'discord.servers'
  2061. });
  2062. } else {
  2063. const realServers = this.getRealParams('servers', serverLinks, doTask, link => link.match(/invite\/(.+)/)?.[1]);
  2064. if (realServers.length > 0) {
  2065. for (const server of realServers) {
  2066. if (doTask) {
  2067. prom.push(this.#joinServer(server));
  2068. } else {
  2069. prom.push(this.#leaveServer(server));
  2070. }
  2071. await delay(1e3);
  2072. }
  2073. }
  2074. }
  2075. return await Promise.all(prom).then(() => true);
  2076. } catch (error) {
  2077. throwError(error, 'Discord.toggleServers');
  2078. return false;
  2079. }
  2080. }
  2081. #setCache(inviteId, guild) {
  2082. try {
  2083. this.#cache[inviteId] = guild;
  2084. GM_setValue('discordCache', this.#cache);
  2085. } catch (error) {
  2086. throwError(error, 'Discord.setCache');
  2087. }
  2088. }
  2089. }
  2090. const social_Discord = Discord;
  2091. class Instagram extends social_Social {
  2092. tasks;
  2093. whiteList;
  2094. #cache = GM_getValue('instagramCache') || {};
  2095. #auth = {};
  2096. #initialized = false;
  2097. constructor() {
  2098. super();
  2099. const defaultTasksTemplate = {
  2100. users: []
  2101. };
  2102. this.tasks = defaultTasksTemplate;
  2103. this.whiteList = {
  2104. ...defaultTasksTemplate,
  2105. ...GM_getValue('whiteList')?.instagram || {}
  2106. };
  2107. }
  2108. async init() {
  2109. try {
  2110. if (this.#initialized) {
  2111. return true;
  2112. }
  2113. const isVerified = await this.#getUserInfo();
  2114. if (isVerified) {
  2115. scripts_echoLog({}).success(i18n('initSuccess', 'Instagram'));
  2116. this.#initialized = true;
  2117. return true;
  2118. }
  2119. scripts_echoLog({}).error(i18n('initFailed', 'Instagram'));
  2120. return false;
  2121. } catch (error) {
  2122. throwError(error, 'Instagram.init');
  2123. return false;
  2124. }
  2125. }
  2126. async #getUserInfo(name = 'instagram') {
  2127. try {
  2128. const logStatus = scripts_echoLog({
  2129. type: name === 'instagram' ? 'verifyingInsAuth' : 'gettingInsUserId',
  2130. text: name
  2131. });
  2132. const userId = this.#cache[name];
  2133. if (userId && name !== 'instagram') {
  2134. logStatus.success();
  2135. return userId;
  2136. }
  2137. const {
  2138. result,
  2139. statusText,
  2140. status,
  2141. data
  2142. } = await tools_httpRequest({
  2143. url: `https://www.instagram.com/${name}/`,
  2144. method: 'GET'
  2145. });
  2146. if (result === 'Success') {
  2147. if (data?.finalUrl.includes('accounts/login')) {
  2148. logStatus.error(`Error:${i18n('loginIns')}`, true);
  2149. return false;
  2150. } else if (data?.finalUrl.includes('www.instagram.com/challenge')) {
  2151. logStatus.error(`Error:${i18n('insBanned')}`);
  2152. return false;
  2153. }
  2154. if (data?.status === 200) {
  2155. const csrftoken = data.responseText.match(/"csrf_token":"(.+?)"/)?.[1];
  2156. const hash = data.responseText.match(/"rollout_hash":"(.+?)"/)?.[1];
  2157. if (name === 'instagram') {
  2158. if (csrftoken && hash) {
  2159. this.#auth = {
  2160. csrftoken: csrftoken,
  2161. hash: hash
  2162. };
  2163. return true;
  2164. }
  2165. return false;
  2166. }
  2167. const id = data.responseText.match(/"profilePage_([\d]+?)"/)?.[1];
  2168. if (id) {
  2169. this.#setCache(name, id);
  2170. logStatus.success();
  2171. return id;
  2172. }
  2173. logStatus.error('Error: Get ins data error!');
  2174. return false;
  2175. }
  2176. logStatus.error(`${result}:${statusText}(${status})`);
  2177. return false;
  2178. }
  2179. return false;
  2180. } catch (error) {
  2181. throwError(error, 'Instagram.getUserInfo');
  2182. return false;
  2183. }
  2184. }
  2185. async #followUser(name) {
  2186. try {
  2187. const id = await this.#getUserInfo(name);
  2188. if (!id) {
  2189. return false;
  2190. }
  2191. const logStatus = scripts_echoLog({
  2192. type: 'followingIns',
  2193. text: name
  2194. });
  2195. const {
  2196. result,
  2197. statusText,
  2198. status,
  2199. data
  2200. } = await tools_httpRequest({
  2201. url: `https://www.instagram.com/web/friendships/${id}/follow/`,
  2202. method: 'POST',
  2203. dataType: 'json',
  2204. headers: {
  2205. 'x-csrftoken': this.#auth.csrftoken,
  2206. origin: 'https://www.instagram.com',
  2207. referer: `https://www.instagram.com/${name}/`,
  2208. 'content-type': 'application/x-www-form-urlencoded',
  2209. 'sec-fetch-site': 'same-origin',
  2210. 'x-instagram-ajax': this.#auth.hash
  2211. }
  2212. });
  2213. if (result === 'Success') {
  2214. if (data?.status === 200 && data.response?.result === 'following') {
  2215. logStatus.success();
  2216. this.tasks.users = unique([ ...this.tasks.users, name ]);
  2217. return true;
  2218. }
  2219. logStatus.error(`Error:${data?.response?.feedback_message || `${data?.statusText}(${data?.status})`}`);
  2220. return false;
  2221. }
  2222. logStatus.error(`${result}:${statusText}(${status})`);
  2223. return false;
  2224. } catch (error) {
  2225. throwError(error, 'Instagram.followUser');
  2226. return false;
  2227. }
  2228. }
  2229. async #unfollowUser(name) {
  2230. try {
  2231. if (this.whiteList.users.includes(name)) {
  2232. scripts_echoLog({
  2233. type: 'whiteList',
  2234. text: 'Instagram.unfollowUser',
  2235. id: name
  2236. });
  2237. return true;
  2238. }
  2239. const id = await this.#getUserInfo(name);
  2240. if (!id) {
  2241. return false;
  2242. }
  2243. const logStatus = scripts_echoLog({
  2244. type: 'unfollowingIns',
  2245. text: name
  2246. });
  2247. const {
  2248. result,
  2249. statusText,
  2250. status,
  2251. data
  2252. } = await tools_httpRequest({
  2253. url: `https://www.instagram.com/web/friendships/${id}/unfollow/`,
  2254. method: 'POST',
  2255. dataType: 'json',
  2256. headers: {
  2257. 'x-csrftoken': this.#auth.csrftoken,
  2258. origin: 'https://www.instagram.com',
  2259. referer: `https://www.instagram.com/${name}/`,
  2260. 'content-type': 'application/x-www-form-urlencoded',
  2261. 'sec-fetch-site': 'same-origin',
  2262. 'x-instagram-ajax': this.#auth.hash
  2263. }
  2264. });
  2265. if (result === 'Success') {
  2266. if (data?.status === 200 && data.response?.status === 'ok') {
  2267. logStatus.success();
  2268. return true;
  2269. }
  2270. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2271. return false;
  2272. }
  2273. logStatus.error(`${result}:${statusText}(${status})`);
  2274. return false;
  2275. } catch (error) {
  2276. throwError(error, 'Instagram.unfollowUser');
  2277. return false;
  2278. }
  2279. }
  2280. async toggle({
  2281. doTask = true,
  2282. userLinks = []
  2283. }) {
  2284. try {
  2285. if (!this.#initialized) {
  2286. scripts_echoLog({
  2287. text: i18n('needInit')
  2288. });
  2289. return false;
  2290. }
  2291. const prom = [];
  2292. if (doTask && !globalOptions.doTask.instagram.users || !doTask && !globalOptions.undoTask.instagram.users) {
  2293. scripts_echoLog({
  2294. type: 'globalOptionsSkip',
  2295. text: 'instagram.users'
  2296. });
  2297. } else {
  2298. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1]);
  2299. if (realUsers.length > 0) {
  2300. for (const username of realUsers) {
  2301. if (doTask) {
  2302. prom.push(this.#followUser(username));
  2303. } else {
  2304. prom.push(this.#unfollowUser(username));
  2305. }
  2306. await delay(1e3);
  2307. }
  2308. }
  2309. }
  2310. return await Promise.all(prom).then(() => true);
  2311. } catch (error) {
  2312. throwError(error, 'Instagram.toggleUsers');
  2313. return false;
  2314. }
  2315. }
  2316. #setCache(name, id) {
  2317. try {
  2318. this.#cache[name] = id;
  2319. GM_setValue('instagramCache', this.#cache);
  2320. } catch (error) {
  2321. throwError(error, 'Instagram.setCache');
  2322. }
  2323. }
  2324. }
  2325. const social_Instagram = Instagram;
  2326. class Reddit extends social_Social {
  2327. tasks;
  2328. whiteList;
  2329. #auth;
  2330. #initialized = false;
  2331. constructor() {
  2332. super();
  2333. const defaultTasksTemplate = {
  2334. reddits: []
  2335. };
  2336. this.tasks = defaultTasksTemplate;
  2337. this.whiteList = {
  2338. ...defaultTasksTemplate,
  2339. ...GM_getValue('whiteList')?.reddit || {}
  2340. };
  2341. }
  2342. async init() {
  2343. try {
  2344. if (this.#initialized) {
  2345. return true;
  2346. }
  2347. const isVerified = await this.#updateAuth();
  2348. if (isVerified) {
  2349. scripts_echoLog({}).success(i18n('initSuccess', 'Reddit'));
  2350. this.#initialized = true;
  2351. return true;
  2352. }
  2353. scripts_echoLog({}).error(i18n('initFailed', 'Reddit'));
  2354. return false;
  2355. } catch (error) {
  2356. throwError(error, 'Reddit.init');
  2357. return false;
  2358. }
  2359. }
  2360. async #useBeta() {
  2361. try {
  2362. const logStatus = scripts_echoLog({
  2363. text: i18n('changingRedditVersion')
  2364. });
  2365. GM_setValue('redditAuth', null);
  2366. return await new Promise(resolve => {
  2367. const newTab = GM_openInTab('https://www.reddit.com/#auth', {
  2368. active: true,
  2369. insert: true,
  2370. setParent: true
  2371. });
  2372. newTab.onclose = async () => {
  2373. logStatus.success();
  2374. resolve(await this.#updateAuth(true));
  2375. };
  2376. });
  2377. } catch (error) {
  2378. throwError(error, 'Reddit.useBeta');
  2379. return false;
  2380. }
  2381. }
  2382. async #updateAuth(beta = false) {
  2383. try {
  2384. const logStatus = scripts_echoLog({
  2385. text: i18n('updatingAuth', 'Reddit')
  2386. });
  2387. const {
  2388. result,
  2389. statusText,
  2390. status,
  2391. data
  2392. } = await tools_httpRequest({
  2393. url: 'https://www.reddit.com/',
  2394. method: 'GET',
  2395. nochche: true,
  2396. headers: {
  2397. 'Cache-Control': 'no-cache'
  2398. }
  2399. });
  2400. if (result === 'Success') {
  2401. if (data?.responseText.includes('www.reddit.com/login/')) {
  2402. logStatus.error(`Error:${i18n('loginReddit')}`, true);
  2403. return false;
  2404. }
  2405. if (data?.status === 200) {
  2406. if (data.responseText.includes('redesign-beta-optin-btn') && !beta) {
  2407. return await this.#useBeta();
  2408. }
  2409. const accessToken = data.responseText.match(/"accessToken":"(.*?)","expires":"(.*?)"/)?.[1];
  2410. if (accessToken) {
  2411. this.#auth = {
  2412. token: accessToken
  2413. };
  2414. logStatus.success();
  2415. return true;
  2416. }
  2417. logStatus.error('Error: Parameter "accessToken" not found!');
  2418. return false;
  2419. }
  2420. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2421. return false;
  2422. }
  2423. logStatus.error(`${result}:${statusText}(${status})`);
  2424. return false;
  2425. } catch (error) {
  2426. throwError(error, 'Reddit.updateAuth');
  2427. return false;
  2428. }
  2429. }
  2430. async toggleTask({
  2431. name,
  2432. doTask = true
  2433. }) {
  2434. try {
  2435. if (!doTask && this.whiteList.reddits.includes(name)) {
  2436. scripts_echoLog({
  2437. type: 'whiteList',
  2438. text: 'Reddit.undoTask',
  2439. id: name
  2440. });
  2441. return true;
  2442. }
  2443. let type = doTask ? 'joiningReddit' : 'leavingReddit';
  2444. if (/^u_/.test(name)) {
  2445. type = doTask ? 'followingRedditUser' : 'unfollowingRedditUser';
  2446. }
  2447. const logStatus = scripts_echoLog({
  2448. type: type,
  2449. text: name
  2450. });
  2451. const {
  2452. result,
  2453. statusText,
  2454. status,
  2455. data
  2456. } = await tools_httpRequest({
  2457. url: 'https://oauth.reddit.com/api/subscribe?redditWebClient=desktop2x&app=desktop2x-client-production&raw_json=1&gilding_detail=1',
  2458. method: 'POST',
  2459. headers: {
  2460. authorization: `Bearer ${this.#auth.token}`,
  2461. 'content-type': 'application/x-www-form-urlencoded'
  2462. },
  2463. data: $.param({
  2464. action: doTask ? 'sub' : 'unsub',
  2465. sr_name: name,
  2466. api_type: 'json'
  2467. })
  2468. });
  2469. if (result === 'Success') {
  2470. if (data?.status === 200) {
  2471. logStatus.success();
  2472. if (doTask) {
  2473. this.tasks.reddits = unique([ ...this.tasks.reddits, name ]);
  2474. }
  2475. return true;
  2476. }
  2477. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2478. return false;
  2479. }
  2480. logStatus.error(`${result}:${statusText}(${status})`);
  2481. return false;
  2482. } catch (error) {
  2483. throwError(error, 'Reddit.toggleTask');
  2484. return false;
  2485. }
  2486. }
  2487. async toggle({
  2488. doTask = true,
  2489. redditLinks = []
  2490. }) {
  2491. try {
  2492. if (!this.#initialized) {
  2493. scripts_echoLog({
  2494. text: i18n('needInit')
  2495. });
  2496. return false;
  2497. }
  2498. const prom = [];
  2499. if (doTask && !globalOptions.doTask.reddit.reddits || !doTask && !globalOptions.undoTask.reddit.reddits) {
  2500. scripts_echoLog({
  2501. type: 'globalOptionsSkip',
  2502. text: 'reddit.reddits'
  2503. });
  2504. } else {
  2505. const realReddits = this.getRealParams('reddits', redditLinks, doTask, link => {
  2506. const name = link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1];
  2507. const userName = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1];
  2508. if (userName) {
  2509. return name || userName;
  2510. }
  2511. return name;
  2512. });
  2513. if (realReddits.length > 0) {
  2514. for (const name of realReddits) {
  2515. prom.push(this.toggleTask({
  2516. name: name,
  2517. doTask: doTask
  2518. }));
  2519. await delay(1e3);
  2520. }
  2521. }
  2522. }
  2523. return await Promise.all(prom).then(() => true);
  2524. } catch (error) {
  2525. throwError(error, 'Reddit.toggle');
  2526. return false;
  2527. }
  2528. }
  2529. }
  2530. const social_Reddit = Reddit;
  2531. class Twitch extends social_Social {
  2532. tasks;
  2533. whiteList;
  2534. #auth = GM_getValue('twitchAuth') || {};
  2535. #cache = GM_getValue('twitchCache') || {};
  2536. #initialized = false;
  2537. #integrityToken;
  2538. constructor() {
  2539. super();
  2540. const defaultTasksTemplate = {
  2541. channels: []
  2542. };
  2543. this.tasks = defaultTasksTemplate;
  2544. this.whiteList = {
  2545. ...defaultTasksTemplate,
  2546. ...GM_getValue('whiteList')?.twitch || {}
  2547. };
  2548. }
  2549. async init() {
  2550. try {
  2551. if (this.#initialized) {
  2552. return true;
  2553. }
  2554. if (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId) {
  2555. if (await this.#updateAuth()) {
  2556. this.#initialized = true;
  2557. return true;
  2558. }
  2559. return false;
  2560. }
  2561. const isVerified = await this.#verifyAuth(true);
  2562. if (isVerified) {
  2563. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2564. this.#initialized = true;
  2565. return true;
  2566. }
  2567. GM_setValue('twitchAuth', null);
  2568. if (await this.#updateAuth()) {
  2569. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2570. this.#initialized = true;
  2571. return true;
  2572. }
  2573. scripts_echoLog({}).error(i18n('initFailed', 'Twitch'));
  2574. return false;
  2575. } catch (error) {
  2576. throwError(error, 'Twitch.init');
  2577. return false;
  2578. }
  2579. }
  2580. async #verifyAuth(isFirst) {
  2581. try {
  2582. const logStatus = scripts_echoLog({
  2583. text: i18n('verifyingAuth', 'Twitch')
  2584. });
  2585. const {
  2586. result,
  2587. statusText,
  2588. status,
  2589. data
  2590. } = await tools_httpRequest({
  2591. url: 'https://gql.twitch.tv/gql',
  2592. method: 'POST',
  2593. dataType: 'json',
  2594. headers: {
  2595. Authorization: `OAuth ${this.#auth.authToken}`,
  2596. 'Client-Id': this.#auth.clientId
  2597. },
  2598. data: '[{"operationName":"FrontPageNew_User","variables":{"limit":1},"extensions":{"persistedQuery":{"version":1,' + '"sha256Hash":"64bd07a2cbaca80699d62636d966cf6395a5d14a1f0a14282067dcb28b13eb11"}}}]'
  2599. });
  2600. if (result === 'Success') {
  2601. if (data?.status === 200 && data.response?.[0]?.data?.currentUser) {
  2602. await this.#integrity(isFirst);
  2603. logStatus.success();
  2604. return true;
  2605. }
  2606. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2607. return false;
  2608. }
  2609. logStatus.error(`${result}:${statusText}(${status})`);
  2610. return false;
  2611. } catch (error) {
  2612. throwError(error, 'Twitch.verifyAuth');
  2613. return false;
  2614. }
  2615. }
  2616. async #integrity(isFirst = true, ct = '') {
  2617. try {
  2618. const logStatus = scripts_echoLog({
  2619. text: i18n('checkingTwitchIntegrity')
  2620. });
  2621. if (isFirst && (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId)) {
  2622. return await this.#updateAuth(false);
  2623. }
  2624. const {
  2625. result,
  2626. statusText,
  2627. status,
  2628. data
  2629. } = await tools_httpRequest({
  2630. url: 'https://gql.twitch.tv/integrity',
  2631. method: 'POST',
  2632. dataType: 'json',
  2633. anonymous: true,
  2634. headers: {
  2635. Origin: 'https://www.twitch.tv',
  2636. Referer: 'https://www.twitch.tv/',
  2637. Authorization: `OAuth ${this.#auth.authToken}`,
  2638. 'Client-Id': this.#auth.clientId,
  2639. 'Client-Version': this.#auth.clientVersion,
  2640. 'X-Device-Id': this.#auth.deviceId,
  2641. 'Client-Session-Id': this.#auth.clientSessionId,
  2642. 'x-kpsdk-ct': ct
  2643. }
  2644. });
  2645. if (result === 'Success') {
  2646. if (!ct && data?.responseHeaders?.['x-kpsdk-ct']) {
  2647. return await this.#integrity(isFirst, data.responseHeaders['x-kpsdk-ct']);
  2648. }
  2649. if (data?.status === 200 && data.response?.token) {
  2650. this.#integrityToken = data.response.token;
  2651. logStatus.success();
  2652. return true;
  2653. }
  2654. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2655. return false;
  2656. }
  2657. logStatus.error(`${result}:${statusText}(${status})`);
  2658. return false;
  2659. } catch (error) {
  2660. throwError(error, 'Twitch.integrity');
  2661. return false;
  2662. }
  2663. }
  2664. async #updateAuth(isFirst = true) {
  2665. try {
  2666. const logStatus = scripts_echoLog({
  2667. text: i18n('updatingAuth', 'Twitch')
  2668. });
  2669. return await new Promise(resolve => {
  2670. const newTab = GM_openInTab('https://www.twitch.tv/#auth', {
  2671. active: true,
  2672. insert: true,
  2673. setParent: true
  2674. });
  2675. newTab.onclose = async () => {
  2676. const auth = GM_getValue('twitchAuth');
  2677. if (auth) {
  2678. this.#auth = auth;
  2679. logStatus.success();
  2680. resolve(await this.#verifyAuth(isFirst));
  2681. } else {
  2682. logStatus.error('Error: Update twitch auth failed!');
  2683. resolve(false);
  2684. }
  2685. };
  2686. });
  2687. } catch (error) {
  2688. throwError(error, 'Twitch.updateAuth');
  2689. return false;
  2690. }
  2691. }
  2692. async #toggleChannel({
  2693. name,
  2694. doTask = true
  2695. }) {
  2696. try {
  2697. if (!doTask && this.whiteList.channels.includes(name)) {
  2698. scripts_echoLog({
  2699. type: 'whiteList',
  2700. text: 'Twitch.unfollowChannel',
  2701. id: name
  2702. });
  2703. return true;
  2704. }
  2705. const channelId = await this.#getChannelId(name);
  2706. if (!channelId) {
  2707. return false;
  2708. }
  2709. const logStatus = scripts_echoLog({
  2710. type: `${doTask ? '' : 'un'}followingTwitchChannel`,
  2711. text: name
  2712. });
  2713. const followData = `[{"operationName":"FollowButton_FollowUser","variables":{"input":{"disableNotifications":false,"targetID":"${channelId}` + '"}},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"800e7346bdf7e5278a3c1d3f21b2b56e2639928f86815677a7126b093b2fdd08"}}}]';
  2714. const unfollowData = `[{"operationName":"FollowButton_UnfollowUser","variables":{"input":{"targetID":"${channelId}"}},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"f7dae976ebf41c755ae2d758546bfd176b4eeb856656098bb40e0a672ca0d880"}}}]';
  2715. const {
  2716. result,
  2717. statusText,
  2718. status,
  2719. data
  2720. } = await tools_httpRequest({
  2721. url: 'https://gql.twitch.tv/gql',
  2722. method: 'POST',
  2723. dataType: 'json',
  2724. anonymous: true,
  2725. headers: {
  2726. Origin: 'https://www.twitch.tv',
  2727. Referer: 'https://www.twitch.tv/',
  2728. Authorization: `OAuth ${this.#auth.authToken}`,
  2729. 'Client-Id': this.#auth.clientId,
  2730. 'Client-Version': this.#auth.clientVersion,
  2731. 'X-Device-Id': this.#auth.deviceId,
  2732. 'Client-Session-Id': this.#auth.clientSessionId,
  2733. 'Client-Integrity': this.#integrityToken
  2734. },
  2735. data: doTask ? followData : unfollowData
  2736. });
  2737. if (result === 'Success') {
  2738. if (data?.status === 200 && data.response?.[0] && !data.response[0].errors) {
  2739. logStatus.success();
  2740. if (doTask) {
  2741. this.tasks.channels = unique([ ...this.tasks.channels, name ]);
  2742. }
  2743. return true;
  2744. }
  2745. logStatus.error(`Error:${data?.response?.[0].errors?.[0]?.message || `${data?.statusText}(${data?.status})`}`);
  2746. return false;
  2747. }
  2748. logStatus.error(`${result}:${statusText}(${status})`);
  2749. return false;
  2750. } catch (error) {
  2751. throwError(error, 'Twitch.toggleChannel');
  2752. return false;
  2753. }
  2754. }
  2755. async #getChannelId(name) {
  2756. try {
  2757. const logStatus = scripts_echoLog({
  2758. type: 'gettingTwitchChannelId',
  2759. text: name
  2760. });
  2761. const channelId = this.#cache[name];
  2762. if (channelId) {
  2763. logStatus.success();
  2764. return channelId;
  2765. }
  2766. const {
  2767. result,
  2768. statusText,
  2769. status,
  2770. data
  2771. } = await tools_httpRequest({
  2772. url: 'https://gql.twitch.tv/gql',
  2773. method: 'POST',
  2774. headers: {
  2775. Authorization: `OAuth ${this.#auth.authToken}`,
  2776. 'Client-Id': this.#auth.clientId
  2777. },
  2778. responseType: 'json',
  2779. data: `[{"operationName":"ActiveWatchParty","variables":{"channelLogin":"${name}"},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"4a8156c97b19e3a36e081cf6d6ddb5dbf9f9b02ae60e4d2ff26ed70aebc80a30"}}}]'
  2780. });
  2781. if (result === 'Success') {
  2782. if (data?.status === 200) {
  2783. const channelId = data.response?.[0]?.data?.user?.id;
  2784. if (channelId) {
  2785. this.#setCache(name, String(channelId));
  2786. logStatus.success();
  2787. return channelId;
  2788. }
  2789. logStatus.error(`Error:${data.statusText}(${data.status})`);
  2790. return false;
  2791. }
  2792. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2793. return false;
  2794. }
  2795. logStatus.error(`${result}:${statusText}(${status})`);
  2796. return false;
  2797. } catch (error) {
  2798. throwError(error, 'Twitch.getChannelId');
  2799. return false;
  2800. }
  2801. }
  2802. async toggle({
  2803. doTask = true,
  2804. channelLinks = []
  2805. }) {
  2806. try {
  2807. if (!this.#initialized) {
  2808. scripts_echoLog({
  2809. text: i18n('needInit')
  2810. });
  2811. return false;
  2812. }
  2813. const prom = [];
  2814. if (doTask && !globalOptions.doTask.twitch.channels || !doTask && !globalOptions.undoTask.twitch.channels) {
  2815. scripts_echoLog({
  2816. type: 'globalOptionsSkip',
  2817. text: 'twitch.channels'
  2818. });
  2819. } else {
  2820. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2]);
  2821. if (realChannels.length > 0) {
  2822. for (const channel of realChannels) {
  2823. prom.push(this.#toggleChannel({
  2824. name: channel,
  2825. doTask: doTask
  2826. }));
  2827. await delay(1e3);
  2828. }
  2829. }
  2830. }
  2831. return Promise.all(prom).then(() => true);
  2832. } catch (error) {
  2833. throwError(error, 'Twitch.toggle');
  2834. return false;
  2835. }
  2836. }
  2837. #setCache(name, id) {
  2838. try {
  2839. this.#cache[name] = id;
  2840. GM_setValue('twitchCache', this.#cache);
  2841. } catch (error) {
  2842. throwError(error, 'Twitch.setCache');
  2843. }
  2844. }
  2845. }
  2846. const social_Twitch = Twitch;
  2847. class Twitter extends social_Social {
  2848. tasks;
  2849. whiteList;
  2850. #verifyId = globalOptions.other.twitterVerifyId;
  2851. #auth = GM_getValue('twitterAuth') || {};
  2852. #cache = GM_getValue('twitterCache') || {};
  2853. #initialized = false;
  2854. constructor() {
  2855. super();
  2856. const defaultTasksTemplate = {
  2857. users: [],
  2858. retweets: [],
  2859. likes: []
  2860. };
  2861. this.tasks = defaultTasksTemplate;
  2862. this.whiteList = {
  2863. ...defaultTasksTemplate,
  2864. ...GM_getValue('whiteList')?.twitter || {}
  2865. };
  2866. }
  2867. async init() {
  2868. try {
  2869. if (this.#initialized) {
  2870. return true;
  2871. }
  2872. if (!this.#auth.ct0) {
  2873. if (await this.#updateAuth()) {
  2874. this.#initialized = true;
  2875. return true;
  2876. }
  2877. return false;
  2878. }
  2879. const isVerified = await this.#verifyAuth();
  2880. if (isVerified) {
  2881. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2882. this.#initialized = true;
  2883. return true;
  2884. }
  2885. GM_setValue('twitterAuth', null);
  2886. if (await this.#updateAuth()) {
  2887. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2888. this.#initialized = true;
  2889. return true;
  2890. }
  2891. scripts_echoLog({}).error(i18n('initFailed', 'Twitter'));
  2892. return false;
  2893. } catch (error) {
  2894. throwError(error, 'Twitter.init');
  2895. return false;
  2896. }
  2897. }
  2898. async #verifyAuth() {
  2899. try {
  2900. return await this.#toggleUser({
  2901. name: 'verify',
  2902. doTask: true,
  2903. verify: true
  2904. });
  2905. } catch (error) {
  2906. throwError(error, 'Twitter.verifyAuth');
  2907. return false;
  2908. }
  2909. }
  2910. async #updateAuth() {
  2911. try {
  2912. const logStatus = scripts_echoLog({
  2913. text: i18n('updatingAuth', 'Twitter')
  2914. });
  2915. return await new Promise(resolve => {
  2916. GM_cookie.list({
  2917. url: 'https://x.com/settings/account'
  2918. }, async (cookies, error) => {
  2919. if (!error) {
  2920. const [ ct0, isLogin ] = cookies.map(cookie => [ 'ct0', 'twid' ].includes(cookie.name) ? cookie.value : null).filter(cookie => cookie);
  2921. if (isLogin && ct0) {
  2922. GM_setValue('twitterAuth', {
  2923. ct0: ct0
  2924. });
  2925. this.#auth = {
  2926. ct0: ct0
  2927. };
  2928. logStatus.success();
  2929. resolve(await this.#verifyAuth());
  2930. } else {
  2931. logStatus.error(i18n('needLogin'));
  2932. resolve(false);
  2933. }
  2934. } else {
  2935. logStatus.error('Error: Update twitter auth failed!');
  2936. resolve(false);
  2937. }
  2938. });
  2939. });
  2940. } catch (error) {
  2941. throwError(error, 'Twitter.updateToken');
  2942. return false;
  2943. }
  2944. }
  2945. async #toggleUser({
  2946. name,
  2947. doTask = true,
  2948. verify = false
  2949. }) {
  2950. try {
  2951. if (!doTask && !verify && this.whiteList.users.includes(name)) {
  2952. scripts_echoLog({
  2953. type: 'whiteList',
  2954. text: 'Twitter.unfollowUser',
  2955. id: name
  2956. });
  2957. return true;
  2958. }
  2959. const userId = verify ? this.#verifyId : await this.userName2id(name);
  2960. if (!userId) {
  2961. return false;
  2962. }
  2963. const logStatus = verify ? scripts_echoLog({
  2964. text: i18n('verifyingAuth', 'Twitter')
  2965. }) : scripts_echoLog({
  2966. type: `${doTask ? '' : 'un'}followingTwitterUser`,
  2967. text: name
  2968. });
  2969. const {
  2970. result,
  2971. statusText,
  2972. status,
  2973. data
  2974. } = await tools_httpRequest({
  2975. url: `https://x.com/i/api/1.1/friendships/${doTask ? 'create' : 'destroy'}.json`,
  2976. method: 'POST',
  2977. headers: {
  2978. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  2979. 'Content-Type': 'application/x-www-form-urlencoded',
  2980. 'x-csrf-token': this.#auth.ct0
  2981. },
  2982. responseType: 'json',
  2983. data: $.param({
  2984. include_profile_interstitial_type: 1,
  2985. include_blocking: 1,
  2986. include_blocked_by: 1,
  2987. include_followed_by: 1,
  2988. include_want_retweets: 1,
  2989. include_mute_edge: 1,
  2990. include_can_dm: 1,
  2991. include_can_media_tag: 1,
  2992. skip_status: 1,
  2993. id: userId
  2994. })
  2995. });
  2996. if (result === 'Success') {
  2997. if (data?.status === 200) {
  2998. logStatus.success();
  2999. if (doTask && !verify) {
  3000. this.tasks.users = unique([ ...this.tasks.users, name ]);
  3001. }
  3002. return true;
  3003. }
  3004. if (verify && data?.status === 403 && data.response?.errors?.[0]?.code === 158) {
  3005. logStatus.success();
  3006. return true;
  3007. }
  3008. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3009. return false;
  3010. }
  3011. logStatus.error(`${result}:${statusText}(${status})`);
  3012. return false;
  3013. } catch (error) {
  3014. throwError(error, 'Twitter.toggleUser');
  3015. return false;
  3016. }
  3017. }
  3018. async userName2id(name) {
  3019. try {
  3020. const logStatus = scripts_echoLog({
  3021. type: 'gettingTwitterUserId',
  3022. text: name
  3023. });
  3024. const userId = this.#cache[name];
  3025. if (userId) {
  3026. logStatus.success();
  3027. return userId;
  3028. }
  3029. const {
  3030. result,
  3031. statusText,
  3032. status,
  3033. data
  3034. } = await tools_httpRequest({
  3035. 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`,
  3036. method: 'GET',
  3037. headers: {
  3038. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3039. 'content-type': 'application/json',
  3040. referer: `https://x.com/${name}`,
  3041. 'x-csrf-token': this.#auth.ct0
  3042. },
  3043. responseType: 'json'
  3044. });
  3045. if (result === 'Success') {
  3046. if (data?.status === 200) {
  3047. let response = data.response || (typeof data.responseText === 'object' ? data.responseText : null);
  3048. if (!response) {
  3049. try {
  3050. response = JSON.parse(data.responseText);
  3051. } catch (error) {
  3052. response = null;
  3053. }
  3054. }
  3055. const userId = String(response?.data?.user?.result?.rest_id);
  3056. if (userId) {
  3057. this.#setCache(name, userId);
  3058. logStatus.success();
  3059. return userId;
  3060. }
  3061. logStatus.error(`Error:${data.statusText}(${data.status})`);
  3062. return false;
  3063. }
  3064. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3065. return false;
  3066. }
  3067. logStatus.error(`${result}:${statusText}(${status})`);
  3068. return false;
  3069. } catch (error) {
  3070. throwError(error, 'Twitter.getUserId');
  3071. return false;
  3072. }
  3073. }
  3074. async #toggleRetweet({
  3075. retweetId,
  3076. doTask = true
  3077. }) {
  3078. try {
  3079. if (!doTask && this.whiteList.retweets.includes(retweetId)) {
  3080. scripts_echoLog({
  3081. type: 'whiteList',
  3082. text: 'Twitter.unretweet',
  3083. id: retweetId
  3084. });
  3085. return true;
  3086. }
  3087. const logStatus = scripts_echoLog({
  3088. type: `${doTask ? '' : 'un'}retweetting`,
  3089. text: retweetId
  3090. });
  3091. const {
  3092. result,
  3093. statusText,
  3094. status,
  3095. data
  3096. } = await tools_httpRequest({
  3097. url: `https://x.com/i/api/graphql/${doTask ? 'ojPdsZsimiJrUGLR1sjUtA/CreateRetweet' : 'iQtK4dl5hBmXewYZuEOKVw/DeleteRetweet'}`,
  3098. method: 'POST',
  3099. headers: {
  3100. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3101. 'Content-Type': 'application/json',
  3102. 'x-csrf-token': this.#auth.ct0
  3103. },
  3104. data: `{"variables":{"tweet_id":"${retweetId}","dark_request":false},"queryId":"${doTask ? 'ojPdsZsimiJrUGLR1sjUtA' : 'iQtK4dl5hBmXewYZuEOKVw'}"}`,
  3105. responseType: 'json'
  3106. });
  3107. if (result === 'Success') {
  3108. if (data?.status === 200 || data?.status === 403 && data.response?.errors?.[0]?.code === 327) {
  3109. logStatus.success();
  3110. if (doTask) {
  3111. this.tasks.retweets = unique([ ...this.tasks.retweets, retweetId ]);
  3112. }
  3113. return true;
  3114. }
  3115. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3116. return false;
  3117. }
  3118. logStatus.error(`${result}:${statusText}(${status})`);
  3119. return false;
  3120. } catch (error) {
  3121. throwError(error, 'Twitter.toggleRetweet');
  3122. return false;
  3123. }
  3124. }
  3125. async toggle({
  3126. doTask = true,
  3127. userLinks = [],
  3128. retweetLinks = []
  3129. }) {
  3130. try {
  3131. if (!this.#initialized) {
  3132. scripts_echoLog({
  3133. text: i18n('needInit')
  3134. });
  3135. return false;
  3136. }
  3137. const prom = [];
  3138. if (doTask && !globalOptions.doTask.twitter.users || !doTask && !globalOptions.undoTask.twitter.users) {
  3139. scripts_echoLog({
  3140. type: 'globalOptionsSkip',
  3141. text: 'twitter.users'
  3142. });
  3143. } else {
  3144. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/x\.com\/(.+)/)?.[1]);
  3145. if (realUsers.length > 0) {
  3146. for (const user of realUsers) {
  3147. prom.push(this.#toggleUser({
  3148. name: user,
  3149. doTask: doTask
  3150. }));
  3151. await delay(1e3);
  3152. }
  3153. }
  3154. }
  3155. if (doTask && !globalOptions.doTask.twitter.retweets || !doTask && !globalOptions.undoTask.twitter.retweets) {
  3156. scripts_echoLog({
  3157. type: 'globalOptionsSkip',
  3158. text: 'twitter.retweets'
  3159. });
  3160. } else {
  3161. const realRetweets = this.getRealParams('retweets', retweetLinks, doTask, link => link.match(/https:\/\/x\.com\/.*?\/status\/([\d]+)/)?.[1]);
  3162. if (realRetweets.length > 0) {
  3163. for (const retweet of realRetweets) {
  3164. prom.push(this.#toggleRetweet({
  3165. retweetId: retweet,
  3166. doTask: doTask
  3167. }));
  3168. await delay(1e3);
  3169. }
  3170. }
  3171. }
  3172. return Promise.all(prom).then(() => true);
  3173. } catch (error) {
  3174. throwError(error, 'Twitter.toggle');
  3175. return false;
  3176. }
  3177. }
  3178. #setCache(name, id) {
  3179. try {
  3180. this.#cache[name] = id;
  3181. GM_setValue('twitterCache', this.#cache);
  3182. } catch (error) {
  3183. throwError(error, 'Twitter.setCache');
  3184. }
  3185. }
  3186. }
  3187. const social_Twitter = Twitter;
  3188. class Vk extends social_Social {
  3189. tasks;
  3190. whiteList;
  3191. #username = '';
  3192. #cache = GM_getValue('vkCache') || {};
  3193. #initialized = false;
  3194. constructor() {
  3195. super();
  3196. const defaultTasksTemplate = {
  3197. names: []
  3198. };
  3199. this.tasks = defaultTasksTemplate;
  3200. this.whiteList = {
  3201. ...defaultTasksTemplate,
  3202. ...GM_getValue('whiteList')?.vk || {}
  3203. };
  3204. }
  3205. async init() {
  3206. try {
  3207. if (this.#initialized) {
  3208. return true;
  3209. }
  3210. const isVerified = await this.#verifyAuth();
  3211. if (isVerified) {
  3212. scripts_echoLog({}).success(i18n('initSuccess', 'Vk'));
  3213. this.#initialized = true;
  3214. return true;
  3215. }
  3216. scripts_echoLog({}).error(i18n('initFailed', 'Vk'));
  3217. return false;
  3218. } catch (error) {
  3219. throwError(error, 'Vk.init');
  3220. return false;
  3221. }
  3222. }
  3223. async #verifyAuth() {
  3224. try {
  3225. const logStatus = scripts_echoLog({
  3226. text: i18n('verifyAuth', 'Vk')
  3227. });
  3228. const {
  3229. result,
  3230. statusText,
  3231. status,
  3232. data
  3233. } = await tools_httpRequest({
  3234. url: 'https://vk.com/im',
  3235. method: 'GET'
  3236. });
  3237. if (result === 'Success') {
  3238. if (data?.finalUrl.includes('vk.com/login')) {
  3239. logStatus.error(`Error:${i18n('loginVk')}`, true);
  3240. return false;
  3241. }
  3242. if (data?.status === 200) {
  3243. this.#username = data.responseText.match(/TopNavBtn__profileLink" href="\/(.*?)"/)?.[1] || '';
  3244. logStatus.success();
  3245. return true;
  3246. }
  3247. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3248. return false;
  3249. }
  3250. logStatus.error(`${result}:${statusText}(${status})`);
  3251. return false;
  3252. } catch (error) {
  3253. throwError(error, 'Vk.verifyAuth');
  3254. return false;
  3255. }
  3256. }
  3257. async #toggleGroup(name, dataParam, doTask = true) {
  3258. try {
  3259. const logStatus = scripts_echoLog({
  3260. type: doTask ? 'joiningVkGroup' : 'leavingVkGroup',
  3261. text: name
  3262. });
  3263. if (dataParam.groupAct === 'enter' && !doTask || dataParam.groupAct === 'leave' && doTask) {
  3264. logStatus.success();
  3265. return true;
  3266. }
  3267. const reqData = {
  3268. act: doTask ? 'enter' : 'leave',
  3269. al: 1,
  3270. gid: dataParam.groupId,
  3271. hash: dataParam.groupHash
  3272. };
  3273. if (doTask) {
  3274. reqData.context = '_';
  3275. }
  3276. const {
  3277. result,
  3278. statusText,
  3279. status,
  3280. data
  3281. } = await tools_httpRequest({
  3282. url: 'https://vk.com/al_groups.php',
  3283. method: 'POST',
  3284. headers: {
  3285. origin: 'https://vk.com',
  3286. referer: `https://vk.com/${name}`,
  3287. 'content-type': 'application/x-www-form-urlencoded'
  3288. },
  3289. data: $.param(reqData)
  3290. });
  3291. if (result === 'Success') {
  3292. if (data?.status === 200) {
  3293. logStatus.success();
  3294. if (doTask) {
  3295. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3296. }
  3297. return true;
  3298. }
  3299. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3300. return false;
  3301. }
  3302. logStatus.error(`${result}:${statusText}(${status})`);
  3303. return false;
  3304. } catch (error) {
  3305. throwError(error, 'Vk.toggleGroup');
  3306. return false;
  3307. }
  3308. }
  3309. async #togglePublic(name, dataParam, doTask = true) {
  3310. try {
  3311. const logStatus = scripts_echoLog({
  3312. type: doTask ? 'joiningVkPublic' : 'leavingVkPublic',
  3313. text: name
  3314. });
  3315. if (dataParam.publicJoined && doTask || !dataParam.publicJoined && !doTask) {
  3316. logStatus.success();
  3317. return true;
  3318. }
  3319. const {
  3320. result,
  3321. statusText,
  3322. status,
  3323. data
  3324. } = await tools_httpRequest({
  3325. url: 'https://vk.com/al_public.php',
  3326. method: 'POST',
  3327. headers: {
  3328. origin: 'https://vk.com',
  3329. referer: `https://vk.com/${name}`,
  3330. 'content-type': 'application/x-www-form-urlencoded'
  3331. },
  3332. data: $.param({
  3333. act: doTask ? 'a_enter' : 'a_leave',
  3334. al: 1,
  3335. pid: dataParam.publicPid,
  3336. hash: dataParam.publicHash
  3337. })
  3338. });
  3339. if (result === 'Success') {
  3340. if (data?.status === 200) {
  3341. logStatus.success();
  3342. if (doTask) {
  3343. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3344. }
  3345. return true;
  3346. }
  3347. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3348. return false;
  3349. }
  3350. logStatus.error(`${result}:${statusText}(${status})`);
  3351. return false;
  3352. } catch (error) {
  3353. throwError(error, 'Vk.togglePublic');
  3354. return false;
  3355. }
  3356. }
  3357. async #sendWall(name) {
  3358. try {
  3359. const logStatus = scripts_echoLog({
  3360. type: 'sendingVkWall',
  3361. text: name
  3362. });
  3363. const {
  3364. result,
  3365. statusText,
  3366. status,
  3367. data
  3368. } = await tools_httpRequest({
  3369. url: 'https://vk.com/like.php',
  3370. method: 'POST',
  3371. headers: {
  3372. origin: 'https://vk.com',
  3373. referer: `https://vk.com/${name}`,
  3374. 'content-type': 'application/x-www-form-urlencoded'
  3375. },
  3376. data: $.param({
  3377. act: 'publish_box',
  3378. al: 1,
  3379. object: name
  3380. })
  3381. });
  3382. if (result === 'Success') {
  3383. if (data?.status === 200) {
  3384. const hash = data.responseText.match(/shHash:[\s]*'(.*?)'/)?.[1];
  3385. if (hash) {
  3386. const {
  3387. result: resultR,
  3388. statusText: statusTextR,
  3389. status: statusR,
  3390. data: dataR
  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. Message: '',
  3401. act: 'a_do_publish',
  3402. al: 1,
  3403. close_comments: 0,
  3404. friends_only: 0,
  3405. from: 'box',
  3406. hash: hash,
  3407. list: '',
  3408. mark_as_ads: 0,
  3409. mute_notifications: 0,
  3410. object: name,
  3411. ret_data: 1,
  3412. to: 0
  3413. })
  3414. });
  3415. if (resultR === 'Success') {
  3416. if (dataR?.status === 200) {
  3417. const jsonData = JSON.parse(dataR.responseText?.replace('\x3c!--', '') || '{}');
  3418. if (jsonData?.payload?.[1]?.[1]?.share_my === true) {
  3419. logStatus.success();
  3420. const postId = String(jsonData?.payload?.[1]?.[1]?.post_id);
  3421. const ownerId = String(jsonData?.payload?.[1]?.[1]?.owner_id);
  3422. if (postId && ownerId) {
  3423. this.#setCache(name, `${ownerId}_${postId}`);
  3424. }
  3425. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3426. return true;
  3427. }
  3428. }
  3429. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  3430. return false;
  3431. }
  3432. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  3433. return false;
  3434. }
  3435. logStatus.error('Error: Get "hash" failed');
  3436. return false;
  3437. }
  3438. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3439. return false;
  3440. }
  3441. logStatus.error(`${result}:${statusText}(${status})`);
  3442. return false;
  3443. } catch (error) {
  3444. throwError(error, 'Vk.sendWall');
  3445. return false;
  3446. }
  3447. }
  3448. async #deleteWall(name, dataParams) {
  3449. try {
  3450. const logStatus = scripts_echoLog({
  3451. type: 'deletingVkWall',
  3452. text: name
  3453. });
  3454. const {
  3455. result,
  3456. statusText,
  3457. status,
  3458. data
  3459. } = await tools_httpRequest({
  3460. url: 'https://vk.com/al_wall.php?act=delete',
  3461. method: 'POST',
  3462. headers: {
  3463. origin: 'https://vk.com',
  3464. referer: `https://vk.com/${this.#username}?w=wall${this.#cache[name]}%2Fall`,
  3465. 'content-type': 'application/x-www-form-urlencoded'
  3466. },
  3467. data: $.param({
  3468. act: 'delete',
  3469. al: 1,
  3470. confirm: 0,
  3471. from: 'wkview',
  3472. hash: dataParams.wallHash,
  3473. post: this.#cache[name]
  3474. })
  3475. });
  3476. if (result === 'Success') {
  3477. if (data?.status === 200) {
  3478. const jsonData = JSON.parse(data.responseText?.replace('\x3c!--', '') || '{}');
  3479. if (jsonData?.payload?.[1]?.[1]) {
  3480. logStatus.success();
  3481. return true;
  3482. }
  3483. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3484. return false;
  3485. }
  3486. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3487. return false;
  3488. }
  3489. logStatus.error(`${result}:${statusText}(${status})`);
  3490. return false;
  3491. } catch (error) {
  3492. throwError(error, 'Vk.deleteWall');
  3493. return false;
  3494. }
  3495. }
  3496. async #getId(name, doTask) {
  3497. try {
  3498. let url = `https://vk.com/${name}`;
  3499. if (/^wall-/.test(name)) {
  3500. if (doTask) {
  3501. return {
  3502. type: 'sendWall'
  3503. };
  3504. }
  3505. if (!this.#cache[name]) {
  3506. return {
  3507. type: 'unSupport'
  3508. };
  3509. }
  3510. url = `https://vk.com/${this.#username}?w=wall${this.#cache[name]}`;
  3511. }
  3512. const logStatus = scripts_echoLog({
  3513. type: 'gettingVkId',
  3514. text: name
  3515. });
  3516. const {
  3517. result,
  3518. statusText,
  3519. status,
  3520. data
  3521. } = await tools_httpRequest({
  3522. url: url,
  3523. method: 'GET'
  3524. });
  3525. if (result === 'Success') {
  3526. if (data?.status === 200) {
  3527. const [ , groupAct, groupId, , groupHash ] = data.responseText.match(/Groups.(enter|leave)\(.*?,.*?([\d]+?), (&#39;|')(.*?)(&#39;|')/) || [];
  3528. const publicHash = data.responseText.match(/"enterHash":"(.*?)"/)?.[1];
  3529. const publicPid = data.responseText.match(/"public_id":([\d]+?),/)?.[1];
  3530. const publicJoined = !data.responseText.includes('Public.subscribe');
  3531. if (groupAct && groupId && groupHash) {
  3532. logStatus.success();
  3533. return {
  3534. groupAct: groupAct,
  3535. groupId: groupId,
  3536. groupHash: groupHash,
  3537. type: 'group'
  3538. };
  3539. } else if (publicHash && publicPid) {
  3540. logStatus.success();
  3541. return {
  3542. publicHash: publicHash,
  3543. publicPid: publicPid,
  3544. publicJoined: publicJoined,
  3545. type: 'public'
  3546. };
  3547. } else if (data.responseText.includes('wall.deletePost') && !doTask) {
  3548. const wallHash = data.responseText.match(/wall\.deletePost\(this, '.*?', '(.*?)'\)/)?.[1];
  3549. if (wallHash) {
  3550. logStatus.success();
  3551. return {
  3552. type: 'deleteWall',
  3553. wallHash: wallHash
  3554. };
  3555. }
  3556. } else if (name.includes('wall') && doTask) {
  3557. logStatus.success();
  3558. return {
  3559. type: 'sendWall'
  3560. };
  3561. }
  3562. logStatus.error('Error: Parameters not found!');
  3563. return false;
  3564. }
  3565. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3566. return false;
  3567. }
  3568. logStatus.error(`${result}:${statusText}(${status})`);
  3569. return false;
  3570. } catch (error) {
  3571. throwError(error, 'Vk.getId');
  3572. return false;
  3573. }
  3574. }
  3575. async #toggleVk({
  3576. name,
  3577. doTask = true
  3578. }) {
  3579. try {
  3580. if (!doTask && this.whiteList.names.includes(name)) {
  3581. scripts_echoLog({
  3582. type: 'whiteList',
  3583. text: 'Vk.undoTask',
  3584. id: name
  3585. });
  3586. return true;
  3587. }
  3588. const formatName = name.replace(/\/$/, '');
  3589. const data = await this.#getId(formatName, doTask);
  3590. if (!data) {
  3591. return false;
  3592. }
  3593. switch (data.type) {
  3594. case 'group':
  3595. return await this.#toggleGroup(formatName, data, doTask);
  3596.  
  3597. case 'public':
  3598. return await this.#togglePublic(formatName, data, doTask);
  3599.  
  3600. case 'sendWall':
  3601. return doTask ? await this.#sendWall(formatName) : true;
  3602.  
  3603. case 'deleteWall':
  3604. return doTask ? true : await this.#deleteWall(formatName, data);
  3605.  
  3606. default:
  3607. return false;
  3608. }
  3609. } catch (error) {
  3610. throwError(error, 'Vk.toggleVk');
  3611. return false;
  3612. }
  3613. }
  3614. async toggle({
  3615. doTask = true,
  3616. nameLinks = []
  3617. }) {
  3618. try {
  3619. if (!this.#initialized) {
  3620. scripts_echoLog({
  3621. text: i18n('needInit')
  3622. });
  3623. return false;
  3624. }
  3625. const prom = [];
  3626. if (doTask && !globalOptions.doTask.vk.names || !doTask && !globalOptions.undoTask.vk.names) {
  3627. scripts_echoLog({
  3628. type: 'globalOptionsSkip',
  3629. text: 'vk.names'
  3630. });
  3631. } else {
  3632. const realNames = this.getRealParams('names', nameLinks, doTask, link => link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1]);
  3633. if (realNames.length > 0) {
  3634. for (const name of realNames) {
  3635. prom.push(this.#toggleVk({
  3636. name: name,
  3637. doTask: doTask
  3638. }));
  3639. await delay(1e3);
  3640. }
  3641. }
  3642. }
  3643. return Promise.all(prom).then(() => true);
  3644. } catch (error) {
  3645. throwError(error, 'Vk.toggle');
  3646. return false;
  3647. }
  3648. }
  3649. #setCache(name, postId) {
  3650. try {
  3651. this.#cache[name] = postId;
  3652. GM_setValue('vkCache', this.#cache);
  3653. } catch (error) {
  3654. throwError(error, 'Vk.setCache');
  3655. }
  3656. }
  3657. }
  3658. const social_Vk = Vk;
  3659. const getInfo = async function(link, type) {
  3660. try {
  3661. const logStatus = scripts_echoLog({
  3662. text: i18n('gettingYtbToken')
  3663. });
  3664. const {
  3665. result,
  3666. statusText,
  3667. status,
  3668. data
  3669. } = await tools_httpRequest({
  3670. url: link,
  3671. method: 'GET'
  3672. });
  3673. if (result === 'Success') {
  3674. if (data?.status === 200) {
  3675. if (data.responseText.includes('accounts.google.com/ServiceLogin?service=youtube')) {
  3676. logStatus.error(`Error:${i18n('loginYtb')}`, true);
  3677. return {
  3678. needLogin: true
  3679. };
  3680. }
  3681. const apiKey = data.responseText.match(/"INNERTUBE_API_KEY":"(.*?)"/)?.[1];
  3682. const context = (data.responseText.match(/\(\{"INNERTUBE_CONTEXT":([\w\W]*?)\}\)/) || data.responseText.match(/"INNERTUBE_CONTEXT":([\w\W]*?\}),"INNERTUBE/))?.[1] || '{}';
  3683. const {
  3684. client,
  3685. request
  3686. } = JSON.parse(context);
  3687. if (apiKey && client && request) {
  3688. client.hl = 'en';
  3689. if (type === 'channel') {
  3690. const channelId = data.responseText.match(/"channelId":"(.+?)"/)?.[1];
  3691. if (channelId) {
  3692. logStatus.success();
  3693. return {
  3694. params: {
  3695. apiKey: apiKey,
  3696. client: client,
  3697. request: request,
  3698. channelId: channelId
  3699. }
  3700. };
  3701. }
  3702. logStatus.error('Error: Get "channelId" failed!');
  3703. return {};
  3704. } else if (type === 'likeVideo') {
  3705. const videoId = data.responseText.match(/<link rel="shortlinkUrl" href="https:\/\/youtu\.be\/(.*?)">/)?.[1];
  3706. const likeParams = data.responseText.match(/"likeParams":"(.*?)"/)?.[1];
  3707. if (videoId) {
  3708. logStatus.success();
  3709. return {
  3710. params: {
  3711. apiKey: apiKey,
  3712. client: client,
  3713. request: request,
  3714. videoId: videoId,
  3715. likeParams: likeParams
  3716. }
  3717. };
  3718. }
  3719. logStatus.error('Error: Get "videoId" failed!');
  3720. return {};
  3721. }
  3722. logStatus.error('Error: Unknown type');
  3723. return {};
  3724. }
  3725. logStatus.error('Error: Parameter "apiKey" not found!');
  3726. return {};
  3727. }
  3728. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3729. return {};
  3730. }
  3731. logStatus.error(`${result}:${statusText}(${status})`);
  3732. return {};
  3733. } catch (error) {
  3734. throwError(error, 'Youtube.getInfo');
  3735. return {};
  3736. }
  3737. };
  3738. class Youtube extends social_Social {
  3739. tasks;
  3740. whiteList;
  3741. #auth = GM_getValue('youtubeAuth') || {};
  3742. #initialized = false;
  3743. #verifyChannel = `https://www.youtube.com/channel/${globalOptions.other.youtubeVerifyChannel}`;
  3744. constructor() {
  3745. super();
  3746. const defaultTasksTemplate = {
  3747. channels: [],
  3748. likes: []
  3749. };
  3750. this.tasks = defaultTasksTemplate;
  3751. this.whiteList = {
  3752. ...defaultTasksTemplate,
  3753. ...GM_getValue('whiteList')?.youtube || {}
  3754. };
  3755. }
  3756. async init() {
  3757. try {
  3758. if (this.#initialized) {
  3759. return true;
  3760. }
  3761. if (!this.#auth.PAPISID) {
  3762. if (await this.#updateAuth()) {
  3763. this.#initialized = true;
  3764. return true;
  3765. }
  3766. return false;
  3767. }
  3768. const isVerified = await this.#verifyAuth();
  3769. if (isVerified) {
  3770. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3771. this.#initialized = true;
  3772. return true;
  3773. }
  3774. GM_setValue('youtubeAuth', null);
  3775. if (await this.#updateAuth()) {
  3776. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3777. this.#initialized = true;
  3778. return true;
  3779. }
  3780. scripts_echoLog({}).error(i18n('initFailed', 'Youtube'));
  3781. return false;
  3782. } catch (error) {
  3783. throwError(error, 'Youtube.init');
  3784. return false;
  3785. }
  3786. }
  3787. async #verifyAuth() {
  3788. try {
  3789. return await this.#toggleChannel({
  3790. link: this.#verifyChannel,
  3791. doTask: true,
  3792. verify: true
  3793. });
  3794. } catch (error) {
  3795. throwError(error, 'Youtube.verifyAuth');
  3796. return false;
  3797. }
  3798. }
  3799. async #updateAuth() {
  3800. try {
  3801. const logStatus = scripts_echoLog({
  3802. text: i18n('updatingAuth', 'Youtube')
  3803. });
  3804. return await new Promise(resolve => {
  3805. GM_cookie.list({
  3806. url: 'https://www.youtube.com/@YouTube'
  3807. }, async (cookies, error) => {
  3808. if (!error) {
  3809. const PAPISID = cookies.find(cookie => cookie.name === '__Secure-3PAPISID')?.value;
  3810. if (PAPISID) {
  3811. GM_setValue('youtubeAuth', {
  3812. PAPISID: PAPISID
  3813. });
  3814. this.#auth = {
  3815. PAPISID: PAPISID
  3816. };
  3817. logStatus.success();
  3818. resolve(await this.#verifyAuth());
  3819. } else {
  3820. logStatus.error(i18n('needLogin'));
  3821. resolve(false);
  3822. }
  3823. } else {
  3824. logStatus.error('Error: Update youtube auth failed!');
  3825. resolve(false);
  3826. }
  3827. });
  3828. });
  3829. } catch (error) {
  3830. throwError(error, 'Youtube.updateAuth');
  3831. return false;
  3832. }
  3833. }
  3834. #getInfo(link, type) {
  3835. return getInfo(link, type);
  3836. }
  3837. async #toggleChannel({
  3838. link,
  3839. doTask = true,
  3840. verify = false
  3841. }) {
  3842. try {
  3843. const {
  3844. params,
  3845. needLogin
  3846. } = await this.#getInfo(link, 'channel');
  3847. const {
  3848. apiKey,
  3849. client,
  3850. request,
  3851. channelId
  3852. } = params || {};
  3853. if (needLogin) {
  3854. scripts_echoLog({
  3855. html: i18n('loginYtb')
  3856. });
  3857. return false;
  3858. }
  3859. if (!(apiKey && client && request && channelId)) {
  3860. scripts_echoLog({
  3861. text: '"getYtbToken" failed'
  3862. });
  3863. return false;
  3864. }
  3865. if (!doTask && !verify && this.whiteList.channels.includes(channelId)) {
  3866. scripts_echoLog({
  3867. type: 'whiteList',
  3868. text: 'Youtube.unfollowChannel',
  3869. id: channelId
  3870. });
  3871. return true;
  3872. }
  3873. const logStatus = verify ? scripts_echoLog({
  3874. text: i18n('verifyingAuth', 'Youtube')
  3875. }) : scripts_echoLog({
  3876. type: doTask ? 'followingYtbChannel' : 'unfollowingYtbChannel',
  3877. text: channelId
  3878. });
  3879. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3880. const {
  3881. result,
  3882. statusText,
  3883. status,
  3884. data
  3885. } = await tools_httpRequest({
  3886. url: `https://www.youtube.com/youtubei/v1/subscription/${doTask ? '' : 'un'}subscribe?key=${apiKey}&prettyPrint=false`,
  3887. method: 'POST',
  3888. headers: {
  3889. origin: 'https://www.youtube.com',
  3890. referer: `https://www.youtube.com/channel/${channelId}`,
  3891. 'content-type': 'application/json',
  3892. 'x-goog-authuser': '0',
  3893. 'x-goog-visitor-id': client?.visitorData,
  3894. 'x-origin': 'https://www.youtube.com',
  3895. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  3896. },
  3897. data: JSON.stringify({
  3898. context: {
  3899. client: client,
  3900. request: {
  3901. sessionId: request?.sessionId,
  3902. internalExperimentFlags: [],
  3903. consistencyTokenJars: []
  3904. },
  3905. user: {}
  3906. },
  3907. channelIds: [ channelId ],
  3908. params: doTask ? 'EgIIAhgA' : 'CgIIAhgA'
  3909. })
  3910. });
  3911. if (result === 'Success') {
  3912. if (data?.status === 200) {
  3913. if (doTask && (/"subscribed":true/.test(data.responseText) || data.responseText.includes('The subscription already exists')) || !doTask && /"subscribed":false/.test(data.responseText)) {
  3914. logStatus.success();
  3915. if (doTask && !verify) {
  3916. this.tasks.channels = unique([ ...this.tasks.channels, link ]);
  3917. }
  3918. return true;
  3919. }
  3920. if (verify && data.responseText.includes('You may not subscribe to yourself')) {
  3921. logStatus.success();
  3922. return true;
  3923. }
  3924. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  3925. return false;
  3926. }
  3927. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3928. return false;
  3929. }
  3930. logStatus.error(`${result}:${statusText}(${status})`);
  3931. return false;
  3932. } catch (error) {
  3933. throwError(error, 'Youtube.toggleChannel');
  3934. return false;
  3935. }
  3936. }
  3937. async #toggleLikeVideo({
  3938. link,
  3939. doTask = true
  3940. }) {
  3941. try {
  3942. const {
  3943. params,
  3944. needLogin
  3945. } = await this.#getInfo(link, 'likeVideo');
  3946. const {
  3947. apiKey,
  3948. client,
  3949. request,
  3950. videoId,
  3951. likeParams
  3952. } = params || {};
  3953. if (needLogin) {
  3954. scripts_echoLog({
  3955. html: `${i18n('loginYtb')}`
  3956. });
  3957. return false;
  3958. }
  3959. if (!(apiKey && client && request && videoId && likeParams)) {
  3960. scripts_echoLog({
  3961. text: '"getYtbToken" failed'
  3962. });
  3963. return false;
  3964. }
  3965. if (!doTask && this.whiteList.likes.includes(videoId)) {
  3966. scripts_echoLog({
  3967. type: 'whiteList',
  3968. text: 'Youtube.unlikeVideo',
  3969. id: videoId
  3970. });
  3971. return true;
  3972. }
  3973. const logStatus = scripts_echoLog({
  3974. type: doTask ? 'likingYtbVideo' : 'unlikingYtbVideo',
  3975. text: videoId
  3976. });
  3977. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3978. const likeVideoData = {
  3979. context: {
  3980. client: client,
  3981. request: {
  3982. sessionId: request.sessionId,
  3983. internalExperimentFlags: [],
  3984. consistencyTokenJars: []
  3985. },
  3986. user: {}
  3987. },
  3988. target: {
  3989. videoId: videoId
  3990. }
  3991. };
  3992. if (doTask) {
  3993. if (likeParams) {
  3994. likeVideoData.params = likeParams;
  3995. } else {
  3996. logStatus.error('Empty likeParams');
  3997. return false;
  3998. }
  3999. }
  4000. const {
  4001. result,
  4002. statusText,
  4003. status,
  4004. data
  4005. } = await tools_httpRequest({
  4006. url: `https://www.youtube.com/youtubei/v1/like/${doTask ? '' : 'remove'}like?key=${apiKey}`,
  4007. method: 'POST',
  4008. headers: {
  4009. origin: 'https://www.youtube.com',
  4010. referer: `https://www.youtube.com/watch?v=${videoId}`,
  4011. 'content-type': 'application/json',
  4012. 'x-goog-authuser': '0',
  4013. 'x-goog-visitor-id': client.visitorData,
  4014. 'x-origin': 'https://www.youtube.com',
  4015. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  4016. },
  4017. data: JSON.stringify(likeVideoData)
  4018. });
  4019. if (result === 'Success') {
  4020. if (data?.status === 200) {
  4021. if (doTask && data.responseText.includes('Added to Liked videos') || !doTask && (data.responseText.includes('Removed from Liked videos') || data.responseText.includes('Dislike removed'))) {
  4022. logStatus.success();
  4023. if (doTask) {
  4024. this.tasks.likes = unique([ ...this.tasks.likes, link ]);
  4025. }
  4026. return true;
  4027. }
  4028. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  4029. return false;
  4030. }
  4031. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4032. return false;
  4033. }
  4034. logStatus.error(`${result}:${statusText}(${status})`);
  4035. return false;
  4036. } catch (error) {
  4037. throwError(error, 'Youtube.toggleLikeVideo');
  4038. return false;
  4039. }
  4040. }
  4041. async toggle({
  4042. doTask = true,
  4043. channelLinks = [],
  4044. videoLinks = []
  4045. }) {
  4046. try {
  4047. if (!this.#initialized) {
  4048. scripts_echoLog({
  4049. text: i18n('needInit')
  4050. });
  4051. return false;
  4052. }
  4053. const prom = [];
  4054. if (doTask && !globalOptions.doTask.youtube.channels || !doTask && !globalOptions.undoTask.youtube.channels) {
  4055. scripts_echoLog({
  4056. type: 'globalOptionsSkip',
  4057. text: 'youtube.channels'
  4058. });
  4059. } else {
  4060. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => {
  4061. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4062. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4063. }
  4064. return link;
  4065. });
  4066. if (realChannels.length > 0) {
  4067. for (const channel of realChannels) {
  4068. prom.push(this.#toggleChannel({
  4069. link: channel,
  4070. doTask: doTask
  4071. }));
  4072. await delay(1e3);
  4073. }
  4074. }
  4075. }
  4076. if (doTask && !globalOptions.doTask.youtube.likes || !doTask && !globalOptions.undoTask.youtube.likes) {
  4077. scripts_echoLog({
  4078. type: 'globalOptionsSkip',
  4079. text: 'youtube.likes'
  4080. });
  4081. } else {
  4082. const realLikes = this.getRealParams('likes', videoLinks, doTask, link => {
  4083. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4084. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4085. }
  4086. return link;
  4087. });
  4088. if (realLikes.length > 0) {
  4089. for (const video of realLikes) {
  4090. prom.push(this.#toggleLikeVideo({
  4091. link: video,
  4092. doTask: doTask
  4093. }));
  4094. await delay(1e3);
  4095. }
  4096. }
  4097. }
  4098. return Promise.all(prom).then(() => true);
  4099. } catch (error) {
  4100. throwError(error, 'Youtube.toggle');
  4101. return false;
  4102. }
  4103. }
  4104. }
  4105. class SteamASF {
  4106. #asfOptions;
  4107. #botName = 'asf';
  4108. #groupInfo;
  4109. async init() {
  4110. try {
  4111. const asfCommandsUrl = new URL('/Api/Command/', globalOptions.ASF.AsfIpcUrl);
  4112. this.#asfOptions = {
  4113. url: asfCommandsUrl.href,
  4114. method: 'POST',
  4115. responseType: 'json',
  4116. headers: {
  4117. accept: 'application/json',
  4118. 'Content-Type': 'application/json',
  4119. Host: asfCommandsUrl.host,
  4120. Origin: asfCommandsUrl.origin,
  4121. Referer: asfCommandsUrl.href,
  4122. Authentication: globalOptions.ASF.AsfIpcPassword
  4123. }
  4124. };
  4125. if (globalOptions.ASF.AsfBotname) {
  4126. this.#botName = globalOptions.ASF.AsfBotname;
  4127. }
  4128. const logStatus = scripts_echoLog({
  4129. text: i18n('initingASF')
  4130. });
  4131. const {
  4132. result,
  4133. statusText,
  4134. status,
  4135. data
  4136. } = await tools_httpRequest({
  4137. ...this.#asfOptions,
  4138. data: '{"Command":"!stats"}'
  4139. });
  4140. if (result === 'Success') {
  4141. if (data?.response?.Success === true && data.response.Message === 'OK' && data.response.Result) {
  4142. logStatus.success();
  4143. return true;
  4144. }
  4145. if (data?.response?.Result || data?.response?.Message) {
  4146. logStatus.error(data?.response?.Result || data.response.Message);
  4147. return false;
  4148. }
  4149. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4150. return false;
  4151. }
  4152. logStatus.error(`${result}:${statusText}(${status})`);
  4153. return false;
  4154. } catch (error) {
  4155. throwError(error, 'SteamASF.init');
  4156. return false;
  4157. }
  4158. }
  4159. async joinGroup(groupName) {
  4160. try {
  4161. const logStatus = scripts_echoLog({
  4162. type: 'joiningSteamGroup',
  4163. text: groupName
  4164. });
  4165. const {
  4166. result,
  4167. statusText,
  4168. status,
  4169. data
  4170. } = await tools_httpRequest({
  4171. ...this.#asfOptions,
  4172. data: JSON.stringify({
  4173. Command: `!JOINGROUP ${this.#botName} ${groupName}`
  4174. })
  4175. });
  4176. if (result === 'Success') {
  4177. if (data?.status === 200 && [ '已加入', '已申请', 'Joined', 'Applied', 'Присоединился', 'costs' ].find(text => data.response?.Result?.includes(text))) {
  4178. logStatus.success();
  4179. return true;
  4180. }
  4181. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4182. return false;
  4183. }
  4184. logStatus.error(`${result}:${statusText}(${status})`);
  4185. return false;
  4186. } catch (error) {
  4187. throwError(error, 'SteamASF.joinGroup');
  4188. return false;
  4189. }
  4190. }
  4191. async leaveGroup(groupName) {
  4192. try {
  4193. if (!this.#groupInfo) {
  4194. if (!await this.#getGroupId()) {
  4195. return false;
  4196. }
  4197. }
  4198. const groupId = await this.#groupInfo[groupName];
  4199. if (!groupId) {
  4200. return false;
  4201. }
  4202. const logStatus = scripts_echoLog({
  4203. type: 'leavingSteamGroup',
  4204. text: groupName
  4205. });
  4206. const {
  4207. result,
  4208. statusText,
  4209. status,
  4210. data
  4211. } = await tools_httpRequest({
  4212. ...this.#asfOptions,
  4213. data: JSON.stringify({
  4214. Command: `!LEAVEGROUP ${this.#botName} ${groupId}`
  4215. })
  4216. });
  4217. if (result === 'Success') {
  4218. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4219. logStatus.success();
  4220. return true;
  4221. }
  4222. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4223. return false;
  4224. }
  4225. logStatus.error(`${result}:${statusText}(${status})`);
  4226. return false;
  4227. } catch (error) {
  4228. throwError(error, 'SteamASF.leaveGroup');
  4229. return false;
  4230. }
  4231. }
  4232. async #getGroupId() {
  4233. try {
  4234. const logStatus = scripts_echoLog({
  4235. type: 'gettingSteamGroupId',
  4236. text: 'All'
  4237. });
  4238. const {
  4239. result,
  4240. statusText,
  4241. status,
  4242. data
  4243. } = await tools_httpRequest({
  4244. ...this.#asfOptions,
  4245. data: JSON.stringify({
  4246. Command: `!GROUPLIST ${this.#botName}`
  4247. })
  4248. });
  4249. if (result === 'Success') {
  4250. if (data?.status === 200 && data.response?.Result?.includes('|')) {
  4251. this.#groupInfo = Object.fromEntries(data.response.Result.split('\n').map(line => {
  4252. const [ , name, id ] = line.trim().split('|');
  4253. if (name && id) {
  4254. return [ name, id ];
  4255. }
  4256. return null;
  4257. }).filter(ele => ele));
  4258. logStatus.success();
  4259. return true;
  4260. }
  4261. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4262. return false;
  4263. }
  4264. logStatus.error(`${result}:${statusText}(${status})`);
  4265. return false;
  4266. } catch (error) {
  4267. throwError(error, 'SteamASF.getGroupID');
  4268. return false;
  4269. }
  4270. }
  4271. async addToWishlist(gameId) {
  4272. try {
  4273. const logStatus = scripts_echoLog({
  4274. type: 'addingToWishlist',
  4275. text: gameId
  4276. });
  4277. const {
  4278. result,
  4279. statusText,
  4280. status,
  4281. data
  4282. } = await tools_httpRequest({
  4283. ...this.#asfOptions,
  4284. data: JSON.stringify({
  4285. Command: `!ADDWISHLIST ${this.#botName} ${gameId}`
  4286. })
  4287. });
  4288. if (result === 'Success') {
  4289. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4290. logStatus.success();
  4291. return true;
  4292. }
  4293. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4294. return false;
  4295. }
  4296. logStatus.error(`${result}:${statusText}(${status})`);
  4297. return false;
  4298. } catch (error) {
  4299. throwError(error, 'SteamASF.addToWishlist');
  4300. return false;
  4301. }
  4302. }
  4303. async removeFromWishlist(gameId) {
  4304. try {
  4305. const logStatus = scripts_echoLog({
  4306. type: 'removingFromWishlist',
  4307. text: gameId
  4308. });
  4309. const {
  4310. result,
  4311. statusText,
  4312. status,
  4313. data
  4314. } = await tools_httpRequest({
  4315. ...this.#asfOptions,
  4316. data: JSON.stringify({
  4317. Command: `!REMOVEWISHLIST ${this.#botName} ${gameId}`
  4318. })
  4319. });
  4320. if (result === 'Success') {
  4321. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4322. logStatus.success();
  4323. return true;
  4324. }
  4325. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4326. return false;
  4327. }
  4328. logStatus.error(`${result}:${statusText}(${status})`);
  4329. return false;
  4330. } catch (error) {
  4331. throwError(error, 'SteamASF.removeFromWishlist');
  4332. return false;
  4333. }
  4334. }
  4335. async toggleFollowGame(gameId, doTask) {
  4336. try {
  4337. const logStatus = scripts_echoLog({
  4338. type: `${doTask ? '' : 'un'}followingGame`,
  4339. text: gameId
  4340. });
  4341. const {
  4342. result,
  4343. statusText,
  4344. status,
  4345. data
  4346. } = await tools_httpRequest({
  4347. ...this.#asfOptions,
  4348. data: JSON.stringify({
  4349. Command: `!${doTask ? '' : 'UN'}FOLLOWGAME ${this.#botName} ${gameId}`
  4350. })
  4351. });
  4352. if (result === 'Success') {
  4353. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4354. logStatus.success();
  4355. return true;
  4356. }
  4357. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4358. return false;
  4359. }
  4360. logStatus.error(`${result}:${statusText}(${status})`);
  4361. return false;
  4362. } catch (error) {
  4363. throwError(error, 'SteamASF.toggleFollowGame');
  4364. return false;
  4365. }
  4366. }
  4367. async toggleCurator(curatorId, doTask = true) {
  4368. try {
  4369. const logStatus = scripts_echoLog({
  4370. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  4371. text: curatorId
  4372. });
  4373. const {
  4374. result,
  4375. statusText,
  4376. status,
  4377. data
  4378. } = await tools_httpRequest({
  4379. ...this.#asfOptions,
  4380. data: JSON.stringify({
  4381. Command: `!${doTask ? '' : 'UN'}FOLLOWCURATOR ${this.#botName} ${curatorId}`
  4382. })
  4383. });
  4384. if (result === 'Success') {
  4385. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4386. logStatus.success();
  4387. return true;
  4388. }
  4389. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4390. return false;
  4391. }
  4392. logStatus.error(`${result}:${statusText}(${status})`);
  4393. return false;
  4394. } catch (error) {
  4395. throwError(error, 'Steam.toggleCurator');
  4396. return false;
  4397. }
  4398. }
  4399. async addLicense(id) {
  4400. try {
  4401. const [ type, ids ] = id.split('-');
  4402. if (type === 'appid') {
  4403. const logStatus = scripts_echoLog({
  4404. type: 'addingFreeLicense',
  4405. text: ids
  4406. });
  4407. const {
  4408. result,
  4409. statusText,
  4410. status,
  4411. data
  4412. } = await tools_httpRequest({
  4413. ...this.#asfOptions,
  4414. data: JSON.stringify({
  4415. Command: `!addlicense ${this.#botName} app/${ids}`
  4416. })
  4417. });
  4418. if (result === 'Success') {
  4419. if (data?.status === 200 && [ 'AlreadyPurchased', 'OK' ].find(text => data.response?.Result?.includes(text))) {
  4420. logStatus.success();
  4421. return true;
  4422. }
  4423. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4424. return false;
  4425. }
  4426. logStatus.error(`${result}:${statusText}(${status})`);
  4427. return false;
  4428. } else if (type === 'subid') {
  4429. const idsArr = ids.split(',');
  4430. const logStatus = scripts_echoLog({
  4431. type: 'addingFreeLicenseSubid',
  4432. text: ids
  4433. });
  4434. const {
  4435. result,
  4436. statusText,
  4437. status,
  4438. data
  4439. } = await tools_httpRequest({
  4440. ...this.#asfOptions,
  4441. data: JSON.stringify({
  4442. Command: `!addlicense ${this.#botName} ${idsArr.map(id => `sub/${id}`).join(',')}`
  4443. })
  4444. });
  4445. if (result === 'Success') {
  4446. if (data?.status === 200 && data.response?.Result) {
  4447. const resultLines = data.response.Result.split('\n');
  4448. idsArr.forEach(subid => {
  4449. const targetLine = resultLines.find(text => text.includes(subid));
  4450. if (targetLine && [ '成功', 'Success', 'Успех' ].find(text => targetLine.includes(text))) {
  4451. scripts_echoLog({}).success(targetLine);
  4452. } else {
  4453. scripts_echoLog({}).error(targetLine);
  4454. }
  4455. });
  4456. return true;
  4457. }
  4458. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4459. return false;
  4460. }
  4461. logStatus.error(`${result}:${statusText}(${status})`);
  4462. return false;
  4463. }
  4464. return false;
  4465. } catch (error) {
  4466. throwError(error, 'SteamASF.addLicense');
  4467. return false;
  4468. }
  4469. }
  4470. async requestPlayTestAccess(id) {
  4471. try {
  4472. const logStatus = scripts_echoLog({
  4473. type: 'requestingPlayTestAccess',
  4474. text: id
  4475. });
  4476. const {
  4477. result,
  4478. statusText,
  4479. status,
  4480. data
  4481. } = await tools_httpRequest({
  4482. ...this.#asfOptions,
  4483. data: JSON.stringify({
  4484. Command: `!REQUESTACCESS ${this.#botName} ${id}`
  4485. })
  4486. });
  4487. if (result === 'Success') {
  4488. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4489. logStatus.success();
  4490. return true;
  4491. }
  4492. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4493. return false;
  4494. }
  4495. logStatus.error(`${result}:${statusText}(${status})`);
  4496. return false;
  4497. } catch (error) {
  4498. throwError(error, 'Steam.requestPlayTestAccess');
  4499. return false;
  4500. }
  4501. }
  4502. }
  4503. const social_SteamASF = SteamASF;
  4504. class Steam extends social_Social {
  4505. tasks;
  4506. whiteList;
  4507. #cache = {
  4508. ...{
  4509. group: {},
  4510. officialGroup: {},
  4511. forum: {},
  4512. workshop: {},
  4513. curator: {}
  4514. },
  4515. ...GM_getValue('steamCache')
  4516. };
  4517. #auth = {};
  4518. #storeInitialized = false;
  4519. #communityInitialized = false;
  4520. #area = 'CN';
  4521. #areaStatus = 'end';
  4522. #ASF;
  4523. constructor() {
  4524. super();
  4525. const defaultTasksTemplate = {
  4526. groups: [],
  4527. officialGroups: [],
  4528. wishlists: [],
  4529. follows: [],
  4530. forums: [],
  4531. workshops: [],
  4532. workshopVotes: [],
  4533. curators: [],
  4534. curatorLikes: [],
  4535. announcements: [],
  4536. licenses: [],
  4537. playtests: []
  4538. };
  4539. this.tasks = defaultTasksTemplate;
  4540. this.whiteList = {
  4541. ...defaultTasksTemplate,
  4542. ...GM_getValue('whiteList')?.steam || {}
  4543. };
  4544. }
  4545. async init(type = 'all') {
  4546. try {
  4547. if (globalOptions.ASF.AsfEnabled && globalOptions.ASF.AsfIpcUrl && globalOptions.ASF.AsfIpcPassword) {
  4548. this.#ASF = new social_SteamASF();
  4549. if (await this.#ASF.init()) {
  4550. this.#storeInitialized = true;
  4551. this.#communityInitialized = true;
  4552. return true;
  4553. }
  4554. return false;
  4555. }
  4556. if (type === 'store') {
  4557. if (this.#storeInitialized) {
  4558. return true;
  4559. }
  4560. this.#storeInitialized = await this.#updateStoreAuth();
  4561. if (!this.#storeInitialized) {
  4562. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4563. return false;
  4564. }
  4565. scripts_echoLog({}).success(i18n('initSuccess', 'SteamStore'));
  4566. return true;
  4567. }
  4568. if (type === 'community') {
  4569. if (this.#communityInitialized) {
  4570. return true;
  4571. }
  4572. this.#communityInitialized = await this.#getUserLink();
  4573. if (!this.#communityInitialized) {
  4574. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4575. return false;
  4576. }
  4577. scripts_echoLog({}).success(i18n('initSuccess', 'SteamCommunity'));
  4578. return true;
  4579. }
  4580. this.#storeInitialized = await this.#updateStoreAuth();
  4581. this.#communityInitialized = await this.#getUserLink();
  4582. if (this.#storeInitialized && this.#communityInitialized) {
  4583. scripts_echoLog({}).success(i18n('initSuccess', 'Steam'));
  4584. return true;
  4585. }
  4586. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4587. return false;
  4588. } catch (error) {
  4589. throwError(error, 'Steam.init');
  4590. return false;
  4591. }
  4592. }
  4593. async #refreshToken(type = 'steamStore') {
  4594. try {
  4595. const host = {
  4596. steamStore: 'store.steampowered.com',
  4597. steamCommunity: 'steamcommunity.com'
  4598. };
  4599. const logStatus = scripts_echoLog({
  4600. text: i18n('refreshingToken', i18n(type))
  4601. });
  4602. const formData = new FormData();
  4603. formData.append('redir', `https://${host[type]}/`);
  4604. const {
  4605. result,
  4606. statusText,
  4607. status,
  4608. data
  4609. } = await tools_httpRequest({
  4610. url: 'https://login.steampowered.com/jwt/ajaxrefresh',
  4611. method: 'POST',
  4612. responseType: 'json',
  4613. headers: {
  4614. Host: 'login.steampowered.com',
  4615. Origin: `https://${host[type]}`,
  4616. Referer: `https://${host[type]}/`
  4617. },
  4618. data: formData
  4619. });
  4620. if (result === 'Success') {
  4621. if (data?.response?.success) {
  4622. if (await this.#setStoreToken(data.response, type)) {
  4623. logStatus.success();
  4624. return true;
  4625. }
  4626. logStatus.error('Error');
  4627. return false;
  4628. }
  4629. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4630. return false;
  4631. }
  4632. logStatus.error(`${result}:${statusText}(${status})`);
  4633. return false;
  4634. } catch (error) {
  4635. throwError(error, 'Steam.refreshToken');
  4636. return false;
  4637. }
  4638. }
  4639. async #setStoreToken(param, type) {
  4640. try {
  4641. const host = {
  4642. steamStore: 'store.steampowered.com',
  4643. steamCommunity: 'steamcommunity.com'
  4644. };
  4645. const logStatus = scripts_echoLog({
  4646. text: i18n('settingToken', i18n(type))
  4647. });
  4648. const formData = new FormData();
  4649. formData.append('steamID', param.steamID);
  4650. formData.append('nonce', param.nonce);
  4651. formData.append('redir', param.redir);
  4652. formData.append('auth', param.auth);
  4653. const {
  4654. result,
  4655. statusText,
  4656. status,
  4657. data
  4658. } = await tools_httpRequest({
  4659. url: `https://${host[type]}/login/settoken`,
  4660. method: 'POST',
  4661. headers: {
  4662. Accept: 'application/json, text/plain, */*',
  4663. Host: host[type],
  4664. Origin: `https://${host[type]}`
  4665. },
  4666. data: formData
  4667. });
  4668. if (result === 'Success') {
  4669. if (data?.status === 200) {
  4670. logStatus.success();
  4671. return true;
  4672. }
  4673. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4674. return false;
  4675. }
  4676. logStatus.error(`${result}:${statusText}(${status})`);
  4677. return false;
  4678. } catch (error) {
  4679. throwError(error, 'Steam.setStoreToken');
  4680. return false;
  4681. }
  4682. }
  4683. async #updateStoreAuth(retry = false) {
  4684. try {
  4685. const logStatus = scripts_echoLog({
  4686. text: i18n('updatingAuth', i18n('steamStore'))
  4687. });
  4688. const {
  4689. result,
  4690. statusText,
  4691. status,
  4692. data
  4693. } = await tools_httpRequest({
  4694. url: 'https://store.steampowered.com/',
  4695. method: 'GET',
  4696. headers: {
  4697. 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',
  4698. 'Cache-Control': 'max-age=0',
  4699. 'Sec-Fetch-Dest': 'document',
  4700. 'Sec-Fetch-Mode': 'navigate',
  4701. 'Upgrade-Insecure-Requests': '1'
  4702. },
  4703. fetch: false,
  4704. redirect: 'manual'
  4705. });
  4706. if (result === 'Success') {
  4707. if (data?.status === 200) {
  4708. if (!data.responseText.includes('data-miniprofile=')) {
  4709. if (await this.#refreshToken('steamStore')) {
  4710. logStatus.warning(i18n('retry'));
  4711. if (retry) {
  4712. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4713. return false;
  4714. }
  4715. return this.#updateStoreAuth(true);
  4716. }
  4717. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4718. return false;
  4719. }
  4720. const storeSessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4721. if (storeSessionID) {
  4722. this.#auth.storeSessionID = storeSessionID;
  4723. logStatus.success();
  4724. return true;
  4725. }
  4726. logStatus.error('Error: Get "sessionID" failed');
  4727. return false;
  4728. }
  4729. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4730. return false;
  4731. }
  4732. if ([ 301, 302 ].includes(data?.status)) {
  4733. if (await this.#refreshToken('steamStore')) {
  4734. logStatus.warning(i18n('retry'));
  4735. if (retry) {
  4736. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4737. return false;
  4738. }
  4739. return this.#updateStoreAuth(true);
  4740. }
  4741. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4742. return false;
  4743. }
  4744. logStatus.error(`${result}:${statusText}(${status})`);
  4745. return false;
  4746. } catch (error) {
  4747. throwError(error, 'Steam.updateStoreAuth');
  4748. return false;
  4749. }
  4750. }
  4751. async #getUserLink(retry = false) {
  4752. try {
  4753. const logStatus = scripts_echoLog({
  4754. text: i18n('gettingUserLink')
  4755. });
  4756. const {
  4757. result,
  4758. statusText,
  4759. status,
  4760. data
  4761. } = await tools_httpRequest({
  4762. url: 'https://steamcommunity.com/my',
  4763. method: 'GET',
  4764. headers: {
  4765. 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',
  4766. 'Cache-Control': 'max-age=0',
  4767. 'Sec-Fetch-Dest': 'document',
  4768. 'Sec-Fetch-Mode': 'navigate',
  4769. 'Upgrade-Insecure-Requests': '1'
  4770. },
  4771. fetch: false,
  4772. redirect: 'manual'
  4773. });
  4774. if (data?.status === 302) {
  4775. if (await this.#refreshToken('steamCommunity')) {
  4776. if (retry) {
  4777. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4778. return false;
  4779. }
  4780. logStatus.warning(i18n('retry'));
  4781. return this.#getUserLink(true);
  4782. }
  4783. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4784. return false;
  4785. }
  4786. const location = data?.responseHeaders?.split('\n')?.find(header => header.includes('location') ? header.replace('loctation:', '').trim() : null);
  4787. if (data?.status === 301 && location?.includes('steamcommunity.com/id')) {
  4788. logStatus.success();
  4789. return await this.#updateCommunityAuth(data.finalUrl);
  4790. }
  4791. logStatus.error(`${result}:${statusText}(${status})`);
  4792. return false;
  4793. } catch (error) {
  4794. throwError(error, 'Steam.updateCommunityAuth');
  4795. return false;
  4796. }
  4797. }
  4798. async #updateCommunityAuth(url) {
  4799. try {
  4800. const logStatus = scripts_echoLog({
  4801. text: i18n('updatingAuth', i18n('steamCommunity'))
  4802. });
  4803. const {
  4804. result,
  4805. statusText,
  4806. status,
  4807. data
  4808. } = await tools_httpRequest({
  4809. url: url,
  4810. method: 'GET',
  4811. headers: {
  4812. 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',
  4813. 'Cache-Control': 'max-age=0',
  4814. 'Sec-Fetch-Dest': 'document',
  4815. 'Sec-Fetch-Mode': 'navigate',
  4816. 'Upgrade-Insecure-Requests': '1'
  4817. }
  4818. });
  4819. if (result === 'Success') {
  4820. if (data?.status === 200) {
  4821. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4822. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4823. return false;
  4824. }
  4825. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4826. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4827. const userName = data.responseText.match(/steamcommunity.com\/id\/(.+?)\/friends\//)?.[1];
  4828. if (steam64Id) {
  4829. this.#auth.steam64Id = steam64Id;
  4830. }
  4831. if (userName) {
  4832. this.#auth.userName = userName;
  4833. }
  4834. if (communitySessionID) {
  4835. this.#auth.communitySessionID = communitySessionID;
  4836. logStatus.success();
  4837. return true;
  4838. }
  4839. logStatus.error('Error: Get "sessionID" failed');
  4840. return false;
  4841. }
  4842. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4843. return false;
  4844. }
  4845. logStatus.error(`${result}:${statusText}(${status})`);
  4846. return false;
  4847. } catch (error) {
  4848. throwError(error, 'Steam.updateCommunityAuth');
  4849. return false;
  4850. }
  4851. }
  4852. async #getAreaInfo() {
  4853. try {
  4854. const logStatus = scripts_echoLog({
  4855. text: i18n('gettingAreaInfo')
  4856. });
  4857. const {
  4858. result,
  4859. statusText,
  4860. status,
  4861. data
  4862. } = await tools_httpRequest({
  4863. url: 'https://store.steampowered.com/cart/',
  4864. method: 'GET'
  4865. });
  4866. if (result === 'Success') {
  4867. if (data?.status === 200) {
  4868. const cartConfigRaw = data.responseText.match(/data-cart_config="(.*?)"/)?.[1];
  4869. const temp = document.createElement('div');
  4870. temp.innerHTML = cartConfigRaw || '{}';
  4871. const cartConfigStr = temp.textContent || temp.innerText;
  4872. let cartConfig;
  4873. try {
  4874. cartConfig = JSON.parse(cartConfigStr);
  4875. } catch (error) {
  4876. logStatus.error('Error: get country info filed');
  4877. console.error(error);
  4878. return {};
  4879. }
  4880. if (!cartConfig.rgUserCountryOptions) {
  4881. logStatus.warning('Warning: Area cannot be changed');
  4882. return {};
  4883. }
  4884. const userInfoRaw = data.responseText.match(/data-userinfo="(.*?)"/)?.[1];
  4885. const temp1 = document.createElement('div');
  4886. temp1.innerHTML = userInfoRaw || '{}';
  4887. const userInfoStr = temp1.textContent || temp1.innerText;
  4888. let userInfo;
  4889. try {
  4890. userInfo = JSON.parse(userInfoStr);
  4891. } catch (error) {
  4892. logStatus.error('Error: get country info filed');
  4893. console.error(error);
  4894. return {};
  4895. }
  4896. const currentArea = userInfo.country_code;
  4897. const areas = Object.keys(cartConfig.rgUserCountryOptions).filter(area => area !== 'help');
  4898. if (currentArea && areas.length > 0) {
  4899. this.#area = currentArea;
  4900. logStatus.success();
  4901. return {
  4902. currentArea: currentArea,
  4903. areas: areas
  4904. };
  4905. }
  4906. logStatus.error('Error: get country info filed');
  4907. return {};
  4908. }
  4909. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4910. return {};
  4911. }
  4912. logStatus.error(`${result}:${statusText}(${status})`);
  4913. return {};
  4914. } catch (error) {
  4915. throwError(error, 'Steam.getAreaInfo');
  4916. return {};
  4917. }
  4918. }
  4919. async #changeArea(area) {
  4920. try {
  4921. if (this.#areaStatus === 'waiting') {
  4922. await new Promise(resolve => {
  4923. const checker = setInterval(() => {
  4924. if (this.#areaStatus !== 'waiting') {
  4925. clearInterval(checker);
  4926. resolve(true);
  4927. }
  4928. });
  4929. });
  4930. }
  4931. if (this.#area === area || !area && this.#area !== 'CN') {
  4932. return true;
  4933. }
  4934. this.#areaStatus = 'waiting';
  4935. let aimedArea = area;
  4936. if (!aimedArea) {
  4937. const {
  4938. currentArea,
  4939. areas
  4940. } = await this.#getAreaInfo();
  4941. if (!currentArea || !areas) {
  4942. this.#areaStatus = 'error';
  4943. return false;
  4944. }
  4945. if (currentArea !== 'CN') {
  4946. this.#areaStatus = 'skip';
  4947. scripts_echoLog({
  4948. text: 'notNeededChangeArea'
  4949. });
  4950. return 'skip';
  4951. }
  4952. const anotherArea = areas.filter(area => area && area !== 'CN');
  4953. if (!anotherArea || anotherArea.length === 0) {
  4954. this.#areaStatus = 'noAnotherArea';
  4955. scripts_echoLog({
  4956. text: 'noAnotherArea'
  4957. });
  4958. return false;
  4959. }
  4960. [ aimedArea ] = anotherArea;
  4961. }
  4962. const logStatus = scripts_echoLog({
  4963. text: i18n('changingArea', aimedArea)
  4964. });
  4965. const {
  4966. result,
  4967. statusText,
  4968. status,
  4969. data
  4970. } = await tools_httpRequest({
  4971. url: 'https://store.steampowered.com/country/setcountry',
  4972. method: 'POST',
  4973. headers: {
  4974. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  4975. },
  4976. data: $.param({
  4977. cc: aimedArea,
  4978. sessionid: this.#auth.storeSessionID
  4979. })
  4980. });
  4981. if (result === 'Success') {
  4982. if (data?.status === 200 && data.responseText === 'true') {
  4983. const {
  4984. currentArea
  4985. } = await this.#getAreaInfo();
  4986. if (currentArea === aimedArea) {
  4987. this.#areaStatus = 'success';
  4988. logStatus.success();
  4989. return currentArea;
  4990. }
  4991. this.#areaStatus = 'error';
  4992. logStatus.error('Error: change country filed');
  4993. return 'CN';
  4994. }
  4995. this.#areaStatus = 'error';
  4996. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4997. return 'CN';
  4998. }
  4999. this.#areaStatus = 'error';
  5000. logStatus.error(`${result}:${statusText}(${status})`);
  5001. return 'CN';
  5002. } catch (error) {
  5003. this.#areaStatus = 'error';
  5004. throwError(error, 'Steam.changeArea');
  5005. return false;
  5006. }
  5007. }
  5008. async #joinGroup(groupName) {
  5009. try {
  5010. if (this.#ASF) {
  5011. if (await this.#ASF.joinGroup(groupName)) {
  5012. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5013. return true;
  5014. }
  5015. return false;
  5016. }
  5017. const logStatus = scripts_echoLog({
  5018. type: 'joiningSteamGroup',
  5019. text: groupName
  5020. });
  5021. const {
  5022. result,
  5023. statusText,
  5024. status,
  5025. data
  5026. } = await tools_httpRequest({
  5027. url: `https://steamcommunity.com/groups/${groupName}`,
  5028. method: 'POST',
  5029. headers: {
  5030. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5031. },
  5032. data: $.param({
  5033. action: 'join',
  5034. sessionID: this.#auth.communitySessionID
  5035. })
  5036. });
  5037. if (result === 'Success') {
  5038. if (data?.status === 200 && !data.responseText.includes('grouppage_join_area')) {
  5039. logStatus.success();
  5040. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5041. return true;
  5042. }
  5043. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5044. return false;
  5045. }
  5046. logStatus.error(`${result}:${statusText}(${status})`);
  5047. return false;
  5048. } catch (error) {
  5049. throwError(error, 'Steam.joinGroup');
  5050. return false;
  5051. }
  5052. }
  5053. async #leaveGroup(groupName) {
  5054. try {
  5055. if (this.whiteList.groups.includes(groupName)) {
  5056. scripts_echoLog({
  5057. type: 'whiteList',
  5058. text: 'Steam.leaveGroup',
  5059. id: groupName
  5060. });
  5061. return true;
  5062. }
  5063. if (this.#ASF) {
  5064. return await this.#ASF.leaveGroup(groupName);
  5065. }
  5066. const groupId = await this.#getGroupId(groupName);
  5067. if (!groupId) {
  5068. return false;
  5069. }
  5070. const logStatus = scripts_echoLog({
  5071. type: 'leavingSteamGroup',
  5072. text: groupName
  5073. });
  5074. const {
  5075. result,
  5076. statusText,
  5077. status,
  5078. data
  5079. } = await tools_httpRequest({
  5080. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5081. method: 'POST',
  5082. headers: {
  5083. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5084. },
  5085. data: $.param({
  5086. sessionID: this.#auth.communitySessionID,
  5087. action: 'leaveGroup',
  5088. groupId: groupId
  5089. })
  5090. });
  5091. if (result === 'Success') {
  5092. 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) {
  5093. logStatus.success();
  5094. return true;
  5095. }
  5096. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5097. return false;
  5098. }
  5099. logStatus.error(`${result}:${statusText}(${status})`);
  5100. return false;
  5101. } catch (error) {
  5102. throwError(error, 'Steam.leaveGroup');
  5103. return false;
  5104. }
  5105. }
  5106. async #getGroupId(groupName) {
  5107. try {
  5108. const logStatus = scripts_echoLog({
  5109. type: 'gettingSteamGroupId',
  5110. text: groupName
  5111. });
  5112. const groupId = this.#cache.group[groupName];
  5113. if (groupId) {
  5114. logStatus.success();
  5115. return groupId;
  5116. }
  5117. const {
  5118. result,
  5119. statusText,
  5120. status,
  5121. data
  5122. } = await tools_httpRequest({
  5123. url: `https://steamcommunity.com/groups/${groupName}`,
  5124. method: 'GET',
  5125. headers: {
  5126. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5127. }
  5128. });
  5129. if (result === 'Success') {
  5130. if (data?.status === 200) {
  5131. const groupId = data.responseText.match(/OpenGroupChat\( '([0-9]+)'/)?.[1];
  5132. if (groupId) {
  5133. this.#setCache('group', groupName, groupId);
  5134. logStatus.success();
  5135. return groupId;
  5136. }
  5137. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5138. return false;
  5139. }
  5140. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5141. return false;
  5142. }
  5143. logStatus.error(`${result}:${statusText}(${status})`);
  5144. return false;
  5145. } catch (error) {
  5146. throwError(error, 'Steam.getGroupID');
  5147. return false;
  5148. }
  5149. }
  5150. async #joinOfficialGroup(gameId) {
  5151. try {
  5152. if (this.#ASF) {
  5153. if (await this.#ASF.joinGroup(gameId)) {
  5154. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5155. return true;
  5156. }
  5157. return false;
  5158. }
  5159. const logStatus = scripts_echoLog({
  5160. type: 'joiningSteamOfficialGroup',
  5161. text: gameId
  5162. });
  5163. const {
  5164. result,
  5165. statusText,
  5166. status,
  5167. data
  5168. } = await tools_httpRequest({
  5169. url: `https://steamcommunity.com/games/${gameId}?action=join&sessionID=${this.#auth.communitySessionID}`,
  5170. method: 'GET',
  5171. headers: {
  5172. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5173. }
  5174. });
  5175. if (result === 'Success') {
  5176. if (data?.status === 200 && !data.responseText.includes('id="publicGroupJoin"')) {
  5177. logStatus.success();
  5178. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5179. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5180. if (groupId) {
  5181. this.#setCache('officialGroup', gameId, groupId);
  5182. }
  5183. return true;
  5184. }
  5185. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5186. return false;
  5187. }
  5188. logStatus.error(`${result}:${statusText}(${status})`);
  5189. return false;
  5190. } catch (error) {
  5191. throwError(error, 'Steam.joinOfficialGroup');
  5192. return false;
  5193. }
  5194. }
  5195. async #leaveOfficialGroup(gameId) {
  5196. try {
  5197. if (this.whiteList.officialGroups.includes(gameId)) {
  5198. scripts_echoLog({
  5199. type: 'whiteList',
  5200. text: 'Steam.leaveOfficialGroup',
  5201. id: gameId
  5202. });
  5203. return true;
  5204. }
  5205. if (this.#ASF) {
  5206. return await this.#ASF.leaveGroup(gameId);
  5207. }
  5208. const groupId = await this.#getOfficialGroupId(gameId);
  5209. if (!groupId) {
  5210. return false;
  5211. }
  5212. const logStatus = scripts_echoLog({
  5213. type: 'leavingSteamOfficialGroup',
  5214. text: gameId
  5215. });
  5216. const {
  5217. result,
  5218. statusText,
  5219. status,
  5220. data
  5221. } = await tools_httpRequest({
  5222. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5223. method: 'POST',
  5224. headers: {
  5225. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5226. },
  5227. data: $.param({
  5228. sessionID: this.#auth.communitySessionID,
  5229. action: 'leaveGroup',
  5230. groupId: groupId
  5231. })
  5232. });
  5233. if (result === 'Success') {
  5234. if (data?.status === 200) {
  5235. const {
  5236. result: resultR,
  5237. statusText: statusTextR,
  5238. status: statusR,
  5239. data: dataR
  5240. } = await tools_httpRequest({
  5241. url: `https://steamcommunity.com/games/${gameId}`,
  5242. method: 'GET',
  5243. headers: {
  5244. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5245. }
  5246. });
  5247. if (resultR === 'Success') {
  5248. if (dataR?.status === 200 && dataR.responseText.includes('id="publicGroupJoin"')) {
  5249. logStatus.success();
  5250. return true;
  5251. }
  5252. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5253. return false;
  5254. }
  5255. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5256. return false;
  5257. }
  5258. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5259. return false;
  5260. }
  5261. logStatus.error(`${result}:${statusText}(${status})`);
  5262. return false;
  5263. } catch (error) {
  5264. throwError(error, 'Steam.leaveOfficialGroup');
  5265. return false;
  5266. }
  5267. }
  5268. async #getOfficialGroupId(gameId) {
  5269. try {
  5270. const logStatus = scripts_echoLog({
  5271. type: 'gettingSteamOfficialGroupId',
  5272. text: gameId
  5273. });
  5274. const groupId = this.#cache.officialGroup[gameId];
  5275. if (groupId) {
  5276. logStatus.success();
  5277. return groupId;
  5278. }
  5279. const {
  5280. result,
  5281. statusText,
  5282. status,
  5283. data
  5284. } = await tools_httpRequest({
  5285. url: `https://steamcommunity.com/games/${gameId}`,
  5286. method: 'GET',
  5287. headers: {
  5288. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5289. }
  5290. });
  5291. if (result === 'Success') {
  5292. if (data?.status === 200) {
  5293. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5294. if (groupId) {
  5295. this.#setCache('officialGroup', gameId, groupId);
  5296. logStatus.success();
  5297. return groupId;
  5298. }
  5299. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5300. return false;
  5301. }
  5302. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5303. return false;
  5304. }
  5305. logStatus.error(`${result}:${statusText}(${status})`);
  5306. return false;
  5307. } catch (error) {
  5308. throwError(error, 'Steam.getGroupID');
  5309. return false;
  5310. }
  5311. }
  5312. async #addToWishlist(gameId) {
  5313. try {
  5314. if (this.#ASF) {
  5315. if (await this.#ASF.addToWishlist(gameId)) {
  5316. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5317. return true;
  5318. }
  5319. return false;
  5320. }
  5321. const logStatus = scripts_echoLog({
  5322. type: 'addingToWishlist',
  5323. text: gameId
  5324. });
  5325. const {
  5326. result,
  5327. data
  5328. } = await tools_httpRequest({
  5329. url: 'https://store.steampowered.com/api/addtowishlist',
  5330. method: 'POST',
  5331. headers: {
  5332. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5333. },
  5334. data: $.param({
  5335. sessionid: this.#auth.storeSessionID,
  5336. appid: gameId
  5337. }),
  5338. dataType: 'json'
  5339. });
  5340. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5341. logStatus.success();
  5342. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5343. return true;
  5344. }
  5345. const {
  5346. result: resultR,
  5347. statusText: statusTextR,
  5348. status: statusR,
  5349. data: dataR
  5350. } = await tools_httpRequest({
  5351. url: `https://store.steampowered.com/app/${gameId}`,
  5352. method: 'GET'
  5353. });
  5354. if (resultR === 'Success') {
  5355. if (dataR?.status === 200) {
  5356. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5357. logStatus.warning(i18n('changeAreaNotice'));
  5358. if (!await this.#changeArea()) {
  5359. return false;
  5360. }
  5361. return await this.#addToWishlist(gameId);
  5362. }
  5363. if (dataR.responseText.includes('class="queue_actions_ctn"') && dataR.responseText.includes('class="already_in_library"')) {
  5364. logStatus.success();
  5365. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5366. return true;
  5367. } 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"')) {
  5368. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5369. return false;
  5370. }
  5371. logStatus.success();
  5372. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5373. return true;
  5374. }
  5375. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5376. return false;
  5377. }
  5378. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5379. return false;
  5380. } catch (error) {
  5381. throwError(error, 'Steam.addToWishlist');
  5382. return false;
  5383. }
  5384. }
  5385. async #removeFromWishlist(gameId) {
  5386. try {
  5387. if (this.whiteList.wishlists.includes(gameId)) {
  5388. scripts_echoLog({
  5389. type: 'whiteList',
  5390. text: 'Steam.removeFromWishlist',
  5391. id: gameId
  5392. });
  5393. return true;
  5394. }
  5395. if (this.#ASF) {
  5396. return await this.#ASF.removeFromWishlist(gameId);
  5397. }
  5398. const logStatus = scripts_echoLog({
  5399. type: 'removingFromWishlist',
  5400. text: gameId
  5401. });
  5402. const {
  5403. result,
  5404. data
  5405. } = await tools_httpRequest({
  5406. url: 'https://store.steampowered.com/api/removefromwishlist',
  5407. method: 'POST',
  5408. headers: {
  5409. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5410. },
  5411. data: $.param({
  5412. sessionid: this.#auth.storeSessionID,
  5413. appid: gameId
  5414. }),
  5415. dataType: 'json'
  5416. });
  5417. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5418. logStatus.success();
  5419. return true;
  5420. }
  5421. const {
  5422. result: resultR,
  5423. statusText: statusTextR,
  5424. status: statusR,
  5425. data: dataR
  5426. } = await tools_httpRequest({
  5427. url: `https://store.steampowered.com/app/${gameId}`,
  5428. method: 'GET'
  5429. });
  5430. if (resultR === 'Success') {
  5431. if (dataR?.status === 200) {
  5432. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5433. logStatus.warning(i18n('changeAreaNotice'));
  5434. const result = await this.#changeArea();
  5435. if (!result || result === 'CN' || result === 'skip') {
  5436. return false;
  5437. }
  5438. return await this.#removeFromWishlist(gameId);
  5439. }
  5440. if (dataR.responseText.includes('class="queue_actions_ctn"') && (dataR.responseText.includes('ds_owned_flag ds_flag') || dataR.responseText.includes('add_to_wishlist_area'))) {
  5441. logStatus.success();
  5442. return true;
  5443. }
  5444. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5445. return false;
  5446. }
  5447. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5448. return false;
  5449. }
  5450. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5451. return false;
  5452. } catch (error) {
  5453. throwError(error, 'Steam.removeFromWishlist');
  5454. return false;
  5455. }
  5456. }
  5457. async #toggleFollowGame(gameId, doTask) {
  5458. try {
  5459. if (!doTask && this.whiteList.follows.includes(gameId)) {
  5460. scripts_echoLog({
  5461. type: 'whiteList',
  5462. text: 'Steam.unfollowGame',
  5463. id: gameId
  5464. });
  5465. return true;
  5466. }
  5467. if (this.#ASF) {
  5468. if (await this.#ASF.toggleFollowGame(gameId, doTask)) {
  5469. if (doTask) {
  5470. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5471. }
  5472. return true;
  5473. }
  5474. return false;
  5475. }
  5476. const logStatus = scripts_echoLog({
  5477. type: `${doTask ? '' : 'un'}followingGame`,
  5478. text: gameId
  5479. });
  5480. const requestData = {
  5481. sessionid: this.#auth.storeSessionID,
  5482. appid: gameId
  5483. };
  5484. if (!doTask) {
  5485. requestData.unfollow = '1';
  5486. }
  5487. const {
  5488. result,
  5489. data
  5490. } = await tools_httpRequest({
  5491. url: 'https://store.steampowered.com/explore/followgame/',
  5492. method: 'POST',
  5493. headers: {
  5494. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5495. },
  5496. data: $.param(requestData)
  5497. });
  5498. if (result === 'Success' && data?.status === 200 && data.responseText === 'true') {
  5499. logStatus.success();
  5500. return true;
  5501. }
  5502. const followed = await this.#isFollowedGame(gameId);
  5503. if (this.#area === 'CN' && followed === 'areaLocked') {
  5504. logStatus.warning(i18n('changeAreaNotice'));
  5505. if (!await this.#changeArea()) {
  5506. return false;
  5507. }
  5508. return await this.#removeFromWishlist(gameId);
  5509. }
  5510. if (doTask === followed) {
  5511. logStatus.success();
  5512. if (doTask) {
  5513. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5514. }
  5515. return true;
  5516. }
  5517. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5518. return false;
  5519. } catch (error) {
  5520. throwError(error, 'Steam.toggleFollowGame');
  5521. return false;
  5522. }
  5523. }
  5524. async #isFollowedGame(gameId) {
  5525. try {
  5526. const {
  5527. result,
  5528. data
  5529. } = await tools_httpRequest({
  5530. url: `https://store.steampowered.com/app/${gameId}`,
  5531. method: 'GET'
  5532. });
  5533. if (result === 'Success') {
  5534. if (data?.status === 200) {
  5535. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  5536. return 'areaLocked';
  5537. }
  5538. if ($(data.responseText.replace(/<img.*?>/g, '')).find('.queue_control_button.queue_btn_follow>.btnv6_blue_hoverfade.btn_medium.queue_btn_active').css('display') !== 'none') {
  5539. return true;
  5540. }
  5541. return false;
  5542. }
  5543. return false;
  5544. }
  5545. return false;
  5546. } catch (error) {
  5547. throwError(error, 'Steam.isFollowedGame');
  5548. return false;
  5549. }
  5550. }
  5551. async #toggleForum(gameId, doTask = true) {
  5552. try {
  5553. if (!doTask && this.whiteList.forums.includes(gameId)) {
  5554. scripts_echoLog({
  5555. type: 'whiteList',
  5556. text: 'Steam.unsubscribeForum',
  5557. id: gameId
  5558. });
  5559. return true;
  5560. }
  5561. const forumId = await this.#getForumId(gameId);
  5562. if (!forumId) {
  5563. return false;
  5564. }
  5565. const logStatus = scripts_echoLog({
  5566. type: `${doTask ? '' : 'un'}subscribingForum`,
  5567. text: gameId
  5568. });
  5569. const [ id, feature ] = forumId.split('_');
  5570. const {
  5571. result,
  5572. statusText,
  5573. status,
  5574. data
  5575. } = await tools_httpRequest({
  5576. url: `https://steamcommunity.com/forum/${id}/General/${doTask ? '' : 'un'}subscribe/${feature || '0'}/`,
  5577. method: 'POST',
  5578. responseType: 'json',
  5579. headers: {
  5580. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5581. },
  5582. data: $.param({
  5583. sessionid: this.#auth.communitySessionID
  5584. })
  5585. });
  5586. if (result === 'Success') {
  5587. if (data?.status === 200 && (data.response?.success === 1 || data.response?.success === 29)) {
  5588. if (doTask) {
  5589. this.tasks.forums = unique([ ...this.tasks.forums, gameId ]);
  5590. }
  5591. logStatus.success();
  5592. return true;
  5593. }
  5594. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5595. return true;
  5596. }
  5597. logStatus.error(`${result}:${statusText}(${status})`);
  5598. return true;
  5599. } catch (error) {
  5600. throwError(error, 'Steam.toggleForum');
  5601. return true;
  5602. }
  5603. }
  5604. async #getForumId(gameId) {
  5605. try {
  5606. const logStatus = scripts_echoLog({
  5607. type: 'gettingForumId',
  5608. text: gameId
  5609. });
  5610. const forumId = this.#cache.forum[gameId];
  5611. if (forumId) {
  5612. logStatus.success();
  5613. return forumId;
  5614. }
  5615. const {
  5616. result,
  5617. statusText,
  5618. status,
  5619. data
  5620. } = await tools_httpRequest({
  5621. url: `https://steamcommunity.com/app/${gameId}/discussions/`,
  5622. method: 'GET'
  5623. });
  5624. if (result === 'Success') {
  5625. if (data?.status === 200) {
  5626. const forumId = data.responseText?.match(/General_([\d]+(_[\d]+)?)/)?.[1];
  5627. if (forumId) {
  5628. this.#setCache('forum', gameId, forumId);
  5629. logStatus.success();
  5630. return forumId;
  5631. }
  5632. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5633. return false;
  5634. }
  5635. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5636. return false;
  5637. }
  5638. logStatus.error(`${result}:${statusText}(${status})`);
  5639. return false;
  5640. } catch (error) {
  5641. throwError(error, 'Steam.getForumId');
  5642. return false;
  5643. }
  5644. }
  5645. async #toggleFavoriteWorkshop(id, doTask = true) {
  5646. try {
  5647. if (!doTask && this.whiteList.workshops.includes(id)) {
  5648. scripts_echoLog({
  5649. type: 'whiteList',
  5650. text: 'Steam.unfavoriteWorkshop',
  5651. id: id
  5652. });
  5653. return true;
  5654. }
  5655. const appid = await this.#getWorkshopAppId(id);
  5656. if (!appid) {
  5657. return false;
  5658. }
  5659. const logStatus = scripts_echoLog({
  5660. type: doTask ? 'favoritingWorkshop' : 'unfavoritingWorkshop',
  5661. text: id
  5662. });
  5663. const {
  5664. result,
  5665. statusText,
  5666. status,
  5667. data
  5668. } = await tools_httpRequest({
  5669. url: `https://steamcommunity.com/sharedfiles/${doTask ? '' : 'un'}favorite`,
  5670. method: 'POST',
  5671. headers: {
  5672. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5673. },
  5674. data: $.param({
  5675. id: id,
  5676. appid: appid,
  5677. sessionid: this.#auth.communitySessionID
  5678. })
  5679. });
  5680. if (result === 'Success') {
  5681. if (data?.status === 200 && !data.responseText) {
  5682. if (doTask) {
  5683. this.tasks.workshops = unique([ ...this.tasks.workshops, id ]);
  5684. }
  5685. logStatus.success();
  5686. return true;
  5687. }
  5688. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5689. return false;
  5690. }
  5691. logStatus.error(`${result}:${statusText}(${status})`);
  5692. return false;
  5693. } catch (error) {
  5694. throwError(error, 'Steam.toggleFavoriteWorkshop');
  5695. return false;
  5696. }
  5697. }
  5698. async #getWorkshopAppId(id) {
  5699. try {
  5700. const logStatus = scripts_echoLog({
  5701. type: 'gettingWorkshopAppId',
  5702. text: id
  5703. });
  5704. const appId = this.#cache.workshop[id];
  5705. if (appId) {
  5706. logStatus.success();
  5707. return appId;
  5708. }
  5709. const {
  5710. result,
  5711. statusText,
  5712. status,
  5713. data
  5714. } = await tools_httpRequest({
  5715. url: `https://steamcommunity.com/sharedfiles/filedetails/?id=${id}`,
  5716. method: 'GET'
  5717. });
  5718. if (result === 'Success') {
  5719. if (data?.status === 200) {
  5720. const appId = data.responseText.match(/<input type="hidden" name="appid" value="([\d]+?)" \/>/)?.[1];
  5721. if (appId) {
  5722. this.#setCache('workshop', id, appId);
  5723. logStatus.success();
  5724. return appId;
  5725. }
  5726. logStatus.error('Error: getWorkshopAppId failed');
  5727. return false;
  5728. }
  5729. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5730. return false;
  5731. }
  5732. logStatus.error(`${result}:${statusText}(${status})`);
  5733. return false;
  5734. } catch (error) {
  5735. throwError(error, 'Steam.getWorkshopAppId');
  5736. return false;
  5737. }
  5738. }
  5739. async #voteUpWorkshop(id) {
  5740. try {
  5741. const logStatus = scripts_echoLog({
  5742. type: 'votingUpWorkshop',
  5743. text: id
  5744. });
  5745. const {
  5746. result,
  5747. statusText,
  5748. status,
  5749. data
  5750. } = await tools_httpRequest({
  5751. url: 'https://steamcommunity.com/sharedfiles/voteup',
  5752. method: 'POST',
  5753. responseType: 'json',
  5754. headers: {
  5755. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5756. },
  5757. data: $.param({
  5758. id: id,
  5759. sessionid: this.#auth.communitySessionID
  5760. })
  5761. });
  5762. if (result === 'Success') {
  5763. if (data?.status === 200 && data.response?.success === 1) {
  5764. logStatus.success();
  5765. return true;
  5766. }
  5767. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5768. return true;
  5769. }
  5770. logStatus.error(`${result}:${statusText}(${status})`);
  5771. return true;
  5772. } catch (error) {
  5773. throwError(error, 'Steam.voteupWorkshop');
  5774. return true;
  5775. }
  5776. }
  5777. async #toggleCurator(curatorId, doTask = true) {
  5778. try {
  5779. if (!doTask && this.whiteList.curators.includes(curatorId)) {
  5780. scripts_echoLog({
  5781. type: 'whiteList',
  5782. text: 'Steam.unfollowCurator',
  5783. id: curatorId
  5784. });
  5785. return true;
  5786. }
  5787. if (this.#ASF) {
  5788. return await this.#ASF.toggleCurator(curatorId, doTask);
  5789. }
  5790. const logStatus = scripts_echoLog({
  5791. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  5792. text: curatorId
  5793. });
  5794. const {
  5795. result,
  5796. statusText,
  5797. status,
  5798. data
  5799. } = await tools_httpRequest({
  5800. url: 'https://store.steampowered.com/curators/ajaxfollow',
  5801. method: 'POST',
  5802. headers: {
  5803. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5804. },
  5805. data: $.param({
  5806. clanid: curatorId,
  5807. sessionid: this.#auth.storeSessionID,
  5808. follow: doTask
  5809. }),
  5810. dataType: 'json'
  5811. });
  5812. if (result === 'Success') {
  5813. if (data?.status === 200 && data.response?.success?.success === 1) {
  5814. logStatus.success();
  5815. return true;
  5816. }
  5817. logStatus.error(`Error:${data?.statusText}(${data?.response?.success}` || `${data?.status})`);
  5818. return false;
  5819. }
  5820. logStatus.error(`${result}:${statusText}(${status})`);
  5821. return false;
  5822. } catch (error) {
  5823. throwError(error, 'Steam.toggleCurator');
  5824. return false;
  5825. }
  5826. }
  5827. async getCuratorId(path, name) {
  5828. try {
  5829. const logStatus = scripts_echoLog({
  5830. type: 'gettingCuratorId',
  5831. text: `${path}/${name}`
  5832. });
  5833. const curatorId = this.#cache.curator[`${path}/${name}`];
  5834. if (curatorId) {
  5835. logStatus.success();
  5836. return curatorId;
  5837. }
  5838. const {
  5839. result,
  5840. statusText,
  5841. status,
  5842. data
  5843. } = await tools_httpRequest({
  5844. url: `https://store.steampowered.com/${path}/${name}`,
  5845. method: 'GET',
  5846. headers: {
  5847. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5848. }
  5849. });
  5850. if (result === 'Success') {
  5851. if (data?.status === 200) {
  5852. const curatorId = data.responseText.match(/g_pagingData.*?"clanid":([\d]+)/)?.[1];
  5853. if (curatorId) {
  5854. this.#setCache('curator', `${path}/${name}`, curatorId);
  5855. logStatus.success();
  5856. return curatorId;
  5857. }
  5858. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5859. return false;
  5860. }
  5861. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5862. return false;
  5863. }
  5864. logStatus.error(`${result}:${statusText}(${status})`);
  5865. return false;
  5866. } catch (error) {
  5867. throwError(error, 'Steam.getCuratorID');
  5868. return false;
  5869. }
  5870. }
  5871. async #toggleCuratorLike(link, doTask = true) {
  5872. try {
  5873. const [ path, name ] = link.split('/');
  5874. if (!(path && name)) {
  5875. scripts_echoLog({
  5876. text: i18n('errorLink', link)
  5877. });
  5878. return false;
  5879. }
  5880. const curatorId = await this.getCuratorId(path, name);
  5881. if (curatorId) {
  5882. return await this.#toggleCurator(curatorId, doTask);
  5883. }
  5884. return false;
  5885. } catch (error) {
  5886. throwError(error, 'Steam.toggleCuratorLike');
  5887. return false;
  5888. }
  5889. }
  5890. async #getAnnouncementParams(appId, viewId) {
  5891. try {
  5892. const logStatus = scripts_echoLog({
  5893. type: 'gettingAnnouncementParams',
  5894. text: appId,
  5895. id: viewId
  5896. });
  5897. const {
  5898. result,
  5899. statusText,
  5900. status,
  5901. data
  5902. } = await tools_httpRequest({
  5903. 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`,
  5904. method: 'GET',
  5905. responseType: 'json',
  5906. headers: {
  5907. Host: 'store.steampowered.com',
  5908. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  5909. }
  5910. });
  5911. if (result === 'Success') {
  5912. if (data?.status === 200 && data?.response?.success === 1) {
  5913. const {
  5914. clanid,
  5915. gid
  5916. } = data.response.event?.announcement_body || {};
  5917. if (clanid) {
  5918. logStatus.success();
  5919. return {
  5920. clanId: clanid,
  5921. gid: gid
  5922. };
  5923. }
  5924. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5925. return {};
  5926. }
  5927. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5928. return {};
  5929. }
  5930. logStatus.error(`${result}:${statusText}(${status})`);
  5931. return {};
  5932. } catch (error) {
  5933. throwError(error, 'Steam.likeAnnouncement');
  5934. return {};
  5935. }
  5936. }
  5937. async #likeAnnouncement(id) {
  5938. try {
  5939. const [ appId, viewId ] = id.split('/');
  5940. if (!(appId && viewId)) {
  5941. scripts_echoLog({}).error(`${i18n('missParams')}(id)`);
  5942. return false;
  5943. }
  5944. const {
  5945. clanId,
  5946. gid
  5947. } = await this.#getAnnouncementParams(appId, viewId);
  5948. if (!clanId) {
  5949. return false;
  5950. }
  5951. const logStatus = scripts_echoLog({
  5952. type: 'likingAnnouncement',
  5953. text: appId,
  5954. id: viewId
  5955. });
  5956. const {
  5957. result,
  5958. statusText,
  5959. status,
  5960. data
  5961. } = await tools_httpRequest({
  5962. url: `https://store.steampowered.com/updated/ajaxrateupdate/${gid || viewId}`,
  5963. method: 'POST',
  5964. headers: {
  5965. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  5966. Host: 'store.steampowered.com',
  5967. Origin: 'https://store.steampowered.com',
  5968. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  5969. },
  5970. data: $.param({
  5971. sessionid: this.#auth.storeSessionID,
  5972. voteup: 1,
  5973. clanid: clanId,
  5974. ajax: 1
  5975. }),
  5976. dataType: 'json'
  5977. });
  5978. if (result === 'Success') {
  5979. if (data?.status === 200 && data.response.success === 1) {
  5980. logStatus.success();
  5981. return true;
  5982. }
  5983. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5984. return false;
  5985. }
  5986. logStatus.error(`${result}:${statusText}(${status})`);
  5987. return false;
  5988. } catch (error) {
  5989. throwError(error, 'Steam.likeAnnouncement');
  5990. return false;
  5991. }
  5992. }
  5993. async #appid2subid(id) {
  5994. try {
  5995. const logStatus = scripts_echoLog({
  5996. type: 'gettingSubid',
  5997. text: id
  5998. });
  5999. const {
  6000. result,
  6001. statusText,
  6002. status,
  6003. data
  6004. } = await tools_httpRequest({
  6005. url: `https://store.steampowered.com/app/${id}`,
  6006. method: 'GET',
  6007. headers: {
  6008. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  6009. }
  6010. });
  6011. if (result === 'Success') {
  6012. if (data?.status === 200) {
  6013. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6014. logStatus.warning(i18n('changeAreaNotice'));
  6015. const result = await this.#changeArea();
  6016. if (!result || result === 'CN' || result === 'skip') {
  6017. return false;
  6018. }
  6019. return await this.#appid2subid(id);
  6020. }
  6021. const subid = data.responseText.match(/name="subid" value="([\d]+?)"/)?.[1];
  6022. if (subid) {
  6023. logStatus.success();
  6024. return subid;
  6025. }
  6026. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6027. return false;
  6028. }
  6029. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6030. return false;
  6031. }
  6032. logStatus.error(`${result}:${statusText}(${status})`);
  6033. return false;
  6034. } catch (error) {
  6035. throwError(error, 'Steam.appid2subid');
  6036. return false;
  6037. }
  6038. }
  6039. async #getLicenses() {
  6040. try {
  6041. const logStatus = scripts_echoLog({
  6042. text: i18n('gettingLicenses')
  6043. });
  6044. const {
  6045. result,
  6046. statusText,
  6047. status,
  6048. data
  6049. } = await tools_httpRequest({
  6050. url: `https://store.steampowered.com/dynamicstore/userdata/?t=${new Date().getTime()}`,
  6051. method: 'GET',
  6052. responseType: 'json'
  6053. });
  6054. if (result === 'Success') {
  6055. if (data?.status === 200) {
  6056. logStatus.success();
  6057. return data.response?.rgOwnedPackages;
  6058. }
  6059. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6060. return false;
  6061. }
  6062. logStatus.error(`${result}:${statusText}(${status})`);
  6063. return false;
  6064. } catch (error) {
  6065. throwError(error, 'Steam.getLicenses');
  6066. return false;
  6067. }
  6068. }
  6069. async #addLicense(id) {
  6070. try {
  6071. if (this.#ASF) {
  6072. return await this.#ASF.addLicense(id);
  6073. }
  6074. const [ type, ids ] = id.split('-');
  6075. if (type === 'appid') {
  6076. const subid = await this.#appid2subid(ids);
  6077. if (!subid) {
  6078. return false;
  6079. }
  6080. const logStatus = scripts_echoLog({
  6081. type: 'addingFreeLicense',
  6082. text: ids
  6083. });
  6084. if (!await this.#addFreeLicense(subid, logStatus)) {
  6085. return false;
  6086. }
  6087. const {
  6088. result,
  6089. statusText,
  6090. status,
  6091. data
  6092. } = await tools_httpRequest({
  6093. url: `https://store.steampowered.com/app/${ids}`,
  6094. method: 'GET'
  6095. });
  6096. if (result === 'Success') {
  6097. if (data?.status === 200) {
  6098. if (data.responseText.includes('ds_owned_flag ds_flag') || data.responseText.includes('class="already_in_library"')) {
  6099. logStatus.success();
  6100. return true;
  6101. }
  6102. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6103. return false;
  6104. }
  6105. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6106. return false;
  6107. }
  6108. logStatus.error(`${result}:${statusText}(${status})`);
  6109. return false;
  6110. } else if (type === 'subid') {
  6111. if (this.#area === 'CN') {
  6112. scripts_echoLog({}).success(i18n('tryChangeAreaNotice'));
  6113. await this.#changeArea();
  6114. }
  6115. const logStatusArr = {};
  6116. const idsArr = ids.split(',');
  6117. for (const subid of idsArr) {
  6118. const logStatus = scripts_echoLog({
  6119. type: 'addingFreeLicenseSubid',
  6120. text: subid
  6121. });
  6122. if (!await this.#addFreeLicense(subid, logStatus)) {
  6123. return false;
  6124. }
  6125. logStatusArr[subid] = logStatus;
  6126. }
  6127. const licenses = await this.#getLicenses();
  6128. if (!licenses) {
  6129. return false;
  6130. }
  6131. for (const subid of idsArr) {
  6132. if (licenses.includes(parseInt(subid, 10))) {
  6133. logStatusArr[subid].success();
  6134. } else {
  6135. logStatusArr[subid].error();
  6136. }
  6137. }
  6138. return true;
  6139. }
  6140. return false;
  6141. } catch (error) {
  6142. throwError(error, 'Steam.addLicense');
  6143. return false;
  6144. }
  6145. }
  6146. async #addFreeLicense(id, logStatusPre) {
  6147. try {
  6148. const logStatus = logStatusPre || scripts_echoLog({
  6149. type: 'addingFreeLicenseSubid',
  6150. text: id
  6151. });
  6152. const {
  6153. result,
  6154. statusText,
  6155. status,
  6156. data
  6157. } = await tools_httpRequest({
  6158. url: 'https://store.steampowered.com/checkout/addfreelicense',
  6159. method: 'POST',
  6160. headers: {
  6161. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6162. Host: 'store.steampowered.com',
  6163. Origin: 'https://store.steampowered.com',
  6164. Referer: 'https://store.steampowered.com/account/licenses/'
  6165. },
  6166. data: $.param({
  6167. action: 'add_to_cart',
  6168. sessionid: this.#auth.storeSessionID,
  6169. subid: id
  6170. }),
  6171. dataType: 'json'
  6172. });
  6173. if (result === 'Success') {
  6174. if (data?.status === 200) {
  6175. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6176. logStatus.warning(i18n('changeAreaNotice'));
  6177. const result = await this.#changeArea();
  6178. if (!result || result === 'CN') {
  6179. return false;
  6180. }
  6181. return await this.#addFreeLicense(id);
  6182. }
  6183. logStatus.success();
  6184. return true;
  6185. }
  6186. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6187. return false;
  6188. }
  6189. logStatus.error(`${result}:${statusText}(${status})`);
  6190. return false;
  6191. } catch (error) {
  6192. throwError(error, 'Steam.addFreeLicense');
  6193. return false;
  6194. }
  6195. }
  6196. async #requestPlayTestAccess(id) {
  6197. try {
  6198. if (this.#ASF) {
  6199. return await this.#ASF.requestPlayTestAccess(id);
  6200. }
  6201. const logStatus = scripts_echoLog({
  6202. type: 'requestingPlayTestAccess',
  6203. text: id
  6204. });
  6205. const {
  6206. result,
  6207. statusText,
  6208. status,
  6209. data
  6210. } = await tools_httpRequest({
  6211. url: `https://store.steampowered.com/ajaxrequestplaytestaccess/${id}`,
  6212. method: 'POST',
  6213. headers: {
  6214. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6215. Host: 'store.steampowered.com',
  6216. Origin: 'https://store.steampowered.com',
  6217. Referer: `https://store.steampowered.com/app/${id}`
  6218. },
  6219. data: $.param({
  6220. sessionid: this.#auth.storeSessionID
  6221. }),
  6222. dataType: 'json'
  6223. });
  6224. if (result === 'Success') {
  6225. if (data?.status === 200 && data?.response?.success === 1) {
  6226. logStatus.success();
  6227. return true;
  6228. }
  6229. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6230. return false;
  6231. }
  6232. logStatus.error(`${result}:${statusText}(${status})`);
  6233. return false;
  6234. } catch (error) {
  6235. throwError(error, 'Steam.requestPlayTestAccess');
  6236. return false;
  6237. }
  6238. }
  6239. async toggle({
  6240. doTask = true,
  6241. groupLinks = [],
  6242. officialGroupLinks = [],
  6243. wishlistLinks = [],
  6244. followLinks = [],
  6245. forumLinks = [],
  6246. workshopLinks = [],
  6247. workshopVoteLinks = [],
  6248. curatorLinks = [],
  6249. curatorLikeLinks = [],
  6250. announcementLinks = [],
  6251. licenseLinks = [],
  6252. playtestLinks = []
  6253. }) {
  6254. try {
  6255. if ([ ...groupLinks, ...officialGroupLinks, ...forumLinks, ...workshopLinks, ...workshopVoteLinks ].length > 0 && !this.#communityInitialized) {
  6256. scripts_echoLog({
  6257. text: i18n('needInit')
  6258. });
  6259. return false;
  6260. }
  6261. if ([ ...wishlistLinks, ...followLinks, ...curatorLinks, ...curatorLikeLinks, ...announcementLinks, ...licenseLinks, ...playtestLinks ].length > 0 && !this.#storeInitialized) {
  6262. scripts_echoLog({
  6263. text: i18n('needInit')
  6264. });
  6265. return false;
  6266. }
  6267. const prom = [];
  6268. if (doTask && !globalOptions.doTask.steam.groups || !doTask && !globalOptions.undoTask.steam.groups) {
  6269. scripts_echoLog({
  6270. type: 'globalOptionsSkip',
  6271. text: 'steam.groups'
  6272. });
  6273. } else {
  6274. const realGroups = this.getRealParams('groups', groupLinks, doTask, link => link.match(/groups\/(.+)\/?/)?.[1]);
  6275. if (realGroups.length > 0) {
  6276. for (const group of realGroups) {
  6277. if (doTask) {
  6278. prom.push(this.#joinGroup(group));
  6279. } else {
  6280. prom.push(this.#leaveGroup(group));
  6281. }
  6282. await delay(1e3);
  6283. }
  6284. }
  6285. }
  6286. if (doTask && !globalOptions.doTask.steam.officialGroups || !doTask && !globalOptions.undoTask.steam.officialGroups) {
  6287. scripts_echoLog({
  6288. type: 'globalOptionsSkip',
  6289. text: 'steam.officialGroups'
  6290. });
  6291. } else {
  6292. const realOfficialGroups = this.getRealParams('officialGroups', officialGroupLinks, doTask, link => link.match(/games\/(.+)\/?/)?.[1]);
  6293. if (realOfficialGroups.length > 0) {
  6294. for (const officialGroup of realOfficialGroups) {
  6295. if (doTask) {
  6296. prom.push(this.#joinOfficialGroup(officialGroup));
  6297. } else {
  6298. prom.push(this.#leaveOfficialGroup(officialGroup));
  6299. }
  6300. await delay(1e3);
  6301. }
  6302. }
  6303. }
  6304. if (doTask && !globalOptions.doTask.steam.wishlists || !doTask && !globalOptions.undoTask.steam.wishlists) {
  6305. scripts_echoLog({
  6306. type: 'globalOptionsSkip',
  6307. text: 'steam.wishlists'
  6308. });
  6309. } else {
  6310. const realWishlists = this.getRealParams('wishlists', wishlistLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6311. if (realWishlists.length > 0) {
  6312. for (const game of realWishlists) {
  6313. if (doTask) {
  6314. prom.push(this.#addToWishlist(game));
  6315. } else {
  6316. prom.push(this.#removeFromWishlist(game));
  6317. }
  6318. await delay(1e3);
  6319. }
  6320. }
  6321. }
  6322. if (doTask && !globalOptions.doTask.steam.follows || !doTask && !globalOptions.undoTask.steam.follows) {
  6323. scripts_echoLog({
  6324. type: 'globalOptionsSkip',
  6325. text: 'steam.follows'
  6326. });
  6327. } else {
  6328. const realFollows = this.getRealParams('follows', followLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6329. if (realFollows.length > 0) {
  6330. for (const game of realFollows) {
  6331. prom.push(this.#toggleFollowGame(game, doTask));
  6332. await delay(1e3);
  6333. }
  6334. }
  6335. }
  6336. if (doTask && !globalOptions.doTask.steam.forums || !doTask && !globalOptions.undoTask.steam.forums) {
  6337. scripts_echoLog({
  6338. type: 'globalOptionsSkip',
  6339. text: 'steam.forums'
  6340. });
  6341. } else {
  6342. const realForums = this.getRealParams('forums', forumLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6343. if (realForums.length > 0) {
  6344. for (const forum of realForums) {
  6345. prom.push(this.#toggleForum(forum, doTask));
  6346. await delay(1e3);
  6347. }
  6348. }
  6349. }
  6350. if (doTask && !globalOptions.doTask.steam.workshops || !doTask && !globalOptions.undoTask.steam.workshops) {
  6351. scripts_echoLog({
  6352. type: 'globalOptionsSkip',
  6353. text: 'steam.workshops'
  6354. });
  6355. } else {
  6356. const realWorkshops = this.getRealParams('workshops', workshopLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6357. if (realWorkshops.length > 0) {
  6358. for (const workshop of realWorkshops) {
  6359. prom.push(this.#toggleFavoriteWorkshop(workshop, doTask));
  6360. await delay(1e3);
  6361. }
  6362. }
  6363. }
  6364. if (doTask && !globalOptions.doTask.steam.workshopVotes) {
  6365. scripts_echoLog({
  6366. type: 'globalOptionsSkip',
  6367. text: 'steam.workshopVotes'
  6368. });
  6369. } else {
  6370. const realworkshopVotes = this.getRealParams('workshopVotes', workshopVoteLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6371. if (doTask && realworkshopVotes.length > 0) {
  6372. for (const workshop of realworkshopVotes) {
  6373. prom.push(this.#voteUpWorkshop(workshop));
  6374. await delay(1e3);
  6375. }
  6376. }
  6377. }
  6378. if (doTask && !globalOptions.doTask.steam.curators || !doTask && !globalOptions.undoTask.steam.curators) {
  6379. scripts_echoLog({
  6380. type: 'globalOptionsSkip',
  6381. text: 'steam.curators'
  6382. });
  6383. } else {
  6384. const realCurators = this.getRealParams('curators', curatorLinks, doTask, link => link.match(/curator\/([\d]+)/)?.[1]);
  6385. const realCuratorLikes = this.getRealParams('curatorLikes', curatorLikeLinks, doTask, link => link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3).join('/'));
  6386. if (realCurators.length > 0) {
  6387. for (const curator of realCurators) {
  6388. prom.push(this.#toggleCurator(curator, doTask));
  6389. await delay(1e3);
  6390. }
  6391. }
  6392. if (realCuratorLikes.length > 0) {
  6393. for (const curatorLike of realCuratorLikes) {
  6394. prom.push(this.#toggleCuratorLike(curatorLike, doTask));
  6395. await delay(1e3);
  6396. }
  6397. }
  6398. }
  6399. if (doTask && !globalOptions.doTask.steam.announcements) {
  6400. scripts_echoLog({
  6401. type: 'globalOptionsSkip',
  6402. text: 'steam.announcements'
  6403. });
  6404. } else {
  6405. const realAnnouncements = this.getRealParams('announcements', announcementLinks, doTask, link => {
  6406. if (link.includes('store.steampowered.com')) {
  6407. return link.match(/store\.steampowered\.com\/news\/app\/([\d]+)\/view\/([\d]+)/)?.slice(1, 3).join('/');
  6408. }
  6409. return link.match(/steamcommunity\.com\/games\/([\d]+)\/announcements\/detail\/([\d]+)/)?.slice(1, 3).join('/');
  6410. });
  6411. if (doTask && realAnnouncements.length > 0) {
  6412. for (const id of realAnnouncements) {
  6413. prom.push(this.#likeAnnouncement(id));
  6414. await delay(1e3);
  6415. }
  6416. }
  6417. }
  6418. if (doTask && !globalOptions.doTask.steam.licenses) {
  6419. scripts_echoLog({
  6420. type: 'globalOptionsSkip',
  6421. text: 'steam.licenses'
  6422. });
  6423. } else if (doTask && globalOptions.doTask.steam.licenses && licenseLinks.length > 0) {
  6424. for (const id of licenseLinks) {
  6425. prom.push(this.#addLicense(id));
  6426. await delay(1e3);
  6427. }
  6428. }
  6429. if (doTask && !globalOptions.doTask.steam.playtests) {
  6430. scripts_echoLog({
  6431. type: 'globalOptionsSkip',
  6432. text: 'steam.playtests'
  6433. });
  6434. } else {
  6435. const realPlaytests = this.getRealParams('playtests', playtestLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6436. if (doTask && globalOptions.doTask.steam.playtests && realPlaytests.length > 0) {
  6437. for (const id of realPlaytests) {
  6438. prom.push(this.#requestPlayTestAccess(id));
  6439. await delay(1e3);
  6440. }
  6441. }
  6442. }
  6443. return Promise.all(prom).then(async () => {
  6444. if (this.#area !== 'CN') {
  6445. scripts_echoLog({}).warning(i18n('steamFinishNotice'));
  6446. await this.#changeArea('CN');
  6447. }
  6448. return true;
  6449. });
  6450. } catch (error) {
  6451. throwError(error, 'Steam.toggle');
  6452. return false;
  6453. }
  6454. }
  6455. #setCache(type, name, id) {
  6456. try {
  6457. this.#cache[type][name] = id;
  6458. GM_setValue('steamCache', this.#cache);
  6459. } catch (error) {
  6460. throwError(error, 'Steam.setCache');
  6461. }
  6462. }
  6463. }
  6464. const social_Steam = Steam;
  6465. class Website {
  6466. undoneTasks;
  6467. socialTasks;
  6468. giveawayId;
  6469. socialInitialized = {
  6470. discord: false,
  6471. instagram: false,
  6472. reddit: false,
  6473. twitch: false,
  6474. twitter: false,
  6475. vk: false,
  6476. youtube: false,
  6477. steamStore: false,
  6478. steamCommunity: false
  6479. };
  6480. initialized = false;
  6481. social = {};
  6482. async #bind(name, init) {
  6483. try {
  6484. return {
  6485. name: name,
  6486. result: await init
  6487. };
  6488. } catch (error) {
  6489. throwError(error, 'Website.bind');
  6490. return {
  6491. name: name,
  6492. result: false
  6493. };
  6494. }
  6495. }
  6496. async initSocial(action) {
  6497. try {
  6498. const pro = [];
  6499. const tasks = action === 'do' ? this.undoneTasks : this.socialTasks;
  6500. if (tasks.discord) {
  6501. const hasDiscord = Object.values(tasks.discord).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6502. if (hasDiscord && (!this.socialInitialized.discord || !this.social.discord)) {
  6503. this.social.discord = new social_Discord();
  6504. pro.push(this.#bind('discord', this.social.discord.init(action)));
  6505. }
  6506. }
  6507. if (tasks.instagram) {
  6508. const hasInstagram = Object.values(tasks.instagram).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6509. if (hasInstagram && (!this.socialInitialized.instagram || !this.social.instagram)) {
  6510. this.social.instagram = new social_Instagram();
  6511. pro.push(this.#bind('instagram', this.social.instagram.init()));
  6512. }
  6513. }
  6514. if (tasks.reddit) {
  6515. const hasReddit = Object.values(tasks.reddit).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6516. if (hasReddit && (!this.socialInitialized.reddit || !this.social.reddit)) {
  6517. this.social.reddit = new social_Reddit();
  6518. pro.push(this.#bind('reddit', this.social.reddit.init()));
  6519. }
  6520. }
  6521. if (tasks.twitch) {
  6522. const hasTwitch = Object.values(tasks.twitch).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6523. if (hasTwitch && (!this.socialInitialized.twitch || !this.social.twitch)) {
  6524. this.social.twitch = new social_Twitch();
  6525. pro.push(this.#bind('twitch', this.social.twitch.init()));
  6526. }
  6527. }
  6528. if (tasks.twitter) {
  6529. const hasTwitter = Object.values(tasks.twitter).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6530. if (hasTwitter && (!this.socialInitialized.twitter || !this.social.twitter)) {
  6531. this.social.twitter = new social_Twitter();
  6532. pro.push(this.#bind('twitter', this.social.twitter.init()));
  6533. }
  6534. }
  6535. if (tasks.vk) {
  6536. const hasVk = Object.values(tasks.vk).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6537. if (hasVk && (!this.socialInitialized.vk || !this.social.vk)) {
  6538. this.social.vk = new social_Vk();
  6539. pro.push(this.#bind('vk', this.social.vk.init()));
  6540. }
  6541. }
  6542. if (tasks.youtube) {
  6543. const hasYoutube = Object.values(tasks.youtube).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6544. if (hasYoutube && (!this.socialInitialized.youtube || !this.social.youtube)) {
  6545. this.social.youtube = new Youtube();
  6546. pro.push(this.#bind('youtube', this.social.youtube.init()));
  6547. }
  6548. }
  6549. if (tasks.steam) {
  6550. const steamLength = Object.values(tasks.steam).reduce((total, arr) => [ ...total, ...arr ]).length;
  6551. if (steamLength > 0) {
  6552. if (!this.social.steam) {
  6553. this.social.steam = new social_Steam();
  6554. }
  6555. 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);
  6556. if (steamLength - steamCommunityLength > 0 && !this.socialInitialized.steamStore) {
  6557. pro.push(this.#bind('steamStore', this.social.steam.init('store')));
  6558. }
  6559. if (steamCommunityLength > 0 && !this.socialInitialized.steamCommunity) {
  6560. pro.push(this.#bind('steamCommunity', this.social.steam.init('community')));
  6561. }
  6562. }
  6563. }
  6564. if (tasks.links && tasks.links.length > 0) {
  6565. this.social.visitLink = visitLink;
  6566. }
  6567. return await Promise.all(pro).then(result => {
  6568. let checked = true;
  6569. for (const data of result) {
  6570. if (data.result) {
  6571. this.socialInitialized[data.name] = data.result;
  6572. } else {
  6573. checked = false;
  6574. }
  6575. }
  6576. return checked;
  6577. });
  6578. } catch (error) {
  6579. throwError(error, 'Website.initSocial');
  6580. return false;
  6581. }
  6582. }
  6583. uniqueTasks(allTasks) {
  6584. const result = {};
  6585. for (const [ social, types ] of Object.entries(allTasks)) {
  6586. result[social] = {};
  6587. for (const [ type, tasks ] of Object.entries(types)) {
  6588. result[social][type] = unique(tasks);
  6589. }
  6590. }
  6591. return result;
  6592. }
  6593. async toggleTask(action) {
  6594. try {
  6595. if (!this.initialized && !this.init()) {
  6596. return false;
  6597. }
  6598. if (!await this.classifyTask(action)) {
  6599. return false;
  6600. }
  6601. if (!await this.initSocial(action)) {
  6602. return false;
  6603. }
  6604. const pro = [];
  6605. const doTask = action === 'do';
  6606. const tasks = doTask ? this.undoneTasks : this.socialTasks;
  6607. if (this.socialInitialized.discord !== 'skip' && this.social.discord) {
  6608. pro.push(this.social.discord.toggle({
  6609. doTask: doTask,
  6610. ...tasks.discord
  6611. }));
  6612. }
  6613. if (this.social.instagram) {
  6614. pro.push(this.social.instagram.toggle({
  6615. doTask: doTask,
  6616. ...tasks.instagram
  6617. }));
  6618. }
  6619. if (this.social.reddit) {
  6620. pro.push(this.social.reddit.toggle({
  6621. doTask: doTask,
  6622. ...tasks.reddit
  6623. }));
  6624. }
  6625. if (this.social.twitch) {
  6626. pro.push(this.social.twitch.toggle({
  6627. doTask: doTask,
  6628. ...tasks.twitch
  6629. }));
  6630. }
  6631. if (this.social.twitter) {
  6632. pro.push(this.social.twitter.toggle({
  6633. doTask: doTask,
  6634. ...tasks.twitter
  6635. }));
  6636. }
  6637. if (this.social.vk) {
  6638. pro.push(this.social.vk.toggle({
  6639. doTask: doTask,
  6640. ...tasks.vk
  6641. }));
  6642. }
  6643. if (this.social.youtube) {
  6644. pro.push(this.social.youtube.toggle({
  6645. doTask: doTask,
  6646. ...tasks.youtube
  6647. }));
  6648. }
  6649. if (this.social.steam) {
  6650. pro.push(this.social.steam.toggle({
  6651. doTask: doTask,
  6652. ...tasks.steam
  6653. }));
  6654. }
  6655. if (this.social.visitLink && tasks.links && doTask) {
  6656. for (const link of tasks.links) {
  6657. pro.push(this.social.visitLink(link));
  6658. }
  6659. }
  6660. if (doTask && tasks.extra && this.extraDoTask) {
  6661. const hasExtra = Object.values(tasks.extra).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6662. if (hasExtra) {
  6663. pro.push(this.extraDoTask(tasks.extra));
  6664. }
  6665. }
  6666. await Promise.all(pro);
  6667. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6668. return true;
  6669. } catch (error) {
  6670. throwError(error, 'Website.toggleTask');
  6671. return false;
  6672. }
  6673. }
  6674. async doTask() {
  6675. try {
  6676. return await this.toggleTask('do');
  6677. } catch (error) {
  6678. throwError(error, 'Website.doTask');
  6679. return false;
  6680. }
  6681. }
  6682. async undoTask() {
  6683. try {
  6684. return await this.toggleTask('undo');
  6685. } catch (error) {
  6686. throwError(error, 'Website.undoTask');
  6687. return false;
  6688. }
  6689. }
  6690. }
  6691. const website_Website = Website;
  6692. const defaultTasksTemplate = {
  6693. steam: {
  6694. groupLinks: [],
  6695. wishlistLinks: [],
  6696. curatorLinks: [],
  6697. followLinks: []
  6698. },
  6699. vk: {
  6700. nameLinks: []
  6701. }
  6702. };
  6703. const defaultTasks = JSON.stringify(defaultTasksTemplate);
  6704. class FreeAnyWhere extends website_Website {
  6705. name = 'FreeAnyWhere';
  6706. tasks = [];
  6707. socialTasks = JSON.parse(defaultTasks);
  6708. undoneTasks = JSON.parse(defaultTasks);
  6709. buttons = [ 'doTask', 'undoTask', 'verifyTask', 'getKey' ];
  6710. static test() {
  6711. return window.location.host === 'freeanywhere.net';
  6712. }
  6713. async init() {
  6714. try {
  6715. const logStatus = scripts_echoLog({
  6716. text: i18n('initing')
  6717. });
  6718. if ($('a[href="#/login"]').length > 0) {
  6719. window.open('/#/login', '_self');
  6720. logStatus.warning(i18n('needLogin'));
  6721. return false;
  6722. }
  6723. if (window.location.href.includes('/login')) {
  6724. logStatus.warning(i18n('needLogin'));
  6725. return false;
  6726. }
  6727. if (!/^https?:\/\/freeanywhere\.net\/#\/giveaway\/[\d]+/.test(window.location.href)) {
  6728. const id = window.location.href.match(/https?:\/\/freeanywhere\.net\/.*?#\/giveaway\/([\d]+)/)?.[1];
  6729. if (!id) {
  6730. logStatus.error(i18n('getFailed', 'Id'));
  6731. return false;
  6732. }
  6733. window.location.href = `https://freeanywhere.net/#/giveaway/${id}`;
  6734. }
  6735. if (!this.#getGiveawayId()) {
  6736. return false;
  6737. }
  6738. if (!await this.#checkLeftKey()) {
  6739. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  6740. }
  6741. this.initialized = true;
  6742. logStatus.success();
  6743. return true;
  6744. } catch (error) {
  6745. throwError(error, 'Freeanywhere.init');
  6746. return false;
  6747. }
  6748. }
  6749. async classifyTask(action) {
  6750. try {
  6751. const logStatus = scripts_echoLog({
  6752. text: i18n('getTasksInfo')
  6753. });
  6754. if (action === 'undo') {
  6755. this.socialTasks = GM_getValue(`fawTasks-${this.giveawayId}`)?.tasks || JSON.parse(defaultTasks);
  6756. }
  6757. const {
  6758. result,
  6759. statusText,
  6760. status,
  6761. data
  6762. } = await tools_httpRequest({
  6763. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/?format=json`,
  6764. method: 'GET',
  6765. headers: {
  6766. authorization: `Token ${window.localStorage.getItem('token')}`,
  6767. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  6768. },
  6769. responseType: 'json'
  6770. });
  6771. if (result === 'Success') {
  6772. const tasks = data?.response?.challenges;
  6773. if (tasks) {
  6774. if (action === 'verify') {
  6775. this.tasks = [];
  6776. }
  6777. for (const task of tasks) {
  6778. const type = task.challenge;
  6779. const social = task.challenge_provider;
  6780. const taskInfo = {
  6781. id: task.id,
  6782. title: task.title
  6783. };
  6784. if (action === 'verify' && !task.is_success) {
  6785. this.tasks.push(taskInfo);
  6786. continue;
  6787. }
  6788. switch (social) {
  6789. case 'steam':
  6790. taskInfo.social = 'steam';
  6791. switch (type) {
  6792. case 'WL':
  6793. if (action === 'undo') {
  6794. this.socialTasks.steam.wishlistLinks.push(task.link);
  6795. }
  6796. if (action === 'do' && !task.is_success) {
  6797. this.undoneTasks.steam.wishlistLinks.push(task.link);
  6798. }
  6799. break;
  6800.  
  6801. case 'JTG':
  6802. if (action === 'undo') {
  6803. this.socialTasks.steam.groupLinks.push(task.link);
  6804. }
  6805. if (action === 'do' && !task.is_success) {
  6806. this.undoneTasks.steam.groupLinks.push(task.link);
  6807. }
  6808. break;
  6809.  
  6810. case 'STC':
  6811. if (action === 'undo') {
  6812. this.socialTasks.steam.curatorLinks.push(task.link);
  6813. }
  6814. if (action === 'do' && !task.is_success) {
  6815. this.undoneTasks.steam.curatorLinks.push(task.link);
  6816. }
  6817. break;
  6818.  
  6819. case 'GF':
  6820. if (action === 'undo') {
  6821. this.socialTasks.steam.followLinks.push(task.link);
  6822. }
  6823. if (action === 'do' && !task.is_success) {
  6824. this.undoneTasks.steam.followLinks.push(task.link);
  6825. }
  6826. break;
  6827. }
  6828. break;
  6829.  
  6830. case 'vk-oauth2':
  6831. if (action === 'undo') {
  6832. this.socialTasks.vk.nameLinks.push(task.link);
  6833. }
  6834. if (action === 'do' && !task.is_success) {
  6835. this.undoneTasks.vk.nameLinks.push(task.link);
  6836. }
  6837. break;
  6838.  
  6839. case 'website':
  6840. break;
  6841.  
  6842. default:
  6843. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${social}`);
  6844. break;
  6845. }
  6846. }
  6847. logStatus.success();
  6848. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  6849. this.socialTasks = this.uniqueTasks(this.socialTasks);
  6850. if (window.DEBUG) {
  6851. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  6852. }
  6853. GM_setValue(`fawTasks-${this.giveawayId}`, {
  6854. tasks: this.socialTasks,
  6855. time: new Date().getTime()
  6856. });
  6857. return true;
  6858. }
  6859. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6860. return false;
  6861. }
  6862. logStatus.error(`${result}:${statusText}(${status})`);
  6863. return false;
  6864. } catch (error) {
  6865. throwError(error, 'Freeanywhere.classifyTask');
  6866. return false;
  6867. }
  6868. }
  6869. async verifyTask() {
  6870. try {
  6871. if (!this.initialized && !this.init()) {
  6872. return false;
  6873. }
  6874. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  6875. return false;
  6876. }
  6877. const pro = [];
  6878. for (const task of this.tasks) {
  6879. pro.push(this.#verify(task));
  6880. await delay(1e3);
  6881. }
  6882. await Promise.all(pro);
  6883. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6884. return !!await this.getKey(true);
  6885. } catch (error) {
  6886. throwError(error, 'Freeanywhere.verifyTask');
  6887. return false;
  6888. }
  6889. }
  6890. async getKey(initialized) {
  6891. try {
  6892. if (!initialized && !this.initialized && !this.init()) {
  6893. return false;
  6894. }
  6895. const logStatus = scripts_echoLog({
  6896. text: i18n('gettingKey')
  6897. });
  6898. const {
  6899. result,
  6900. statusText,
  6901. status,
  6902. data
  6903. } = await tools_httpRequest({
  6904. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/reward/?format=json`,
  6905. method: 'GET',
  6906. dataType: 'json',
  6907. headers: {
  6908. authorization: `Token ${window.localStorage.getItem('token')}`
  6909. }
  6910. });
  6911. if (result === 'Success') {
  6912. if (data?.response?.reward) {
  6913. logStatus.success();
  6914. scripts_echoLog({}).success(data.response.reward);
  6915. return data.response.reward;
  6916. }
  6917. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6918. return false;
  6919. }
  6920. logStatus.error(`${result}:${statusText}(${status})`);
  6921. return false;
  6922. } catch (error) {
  6923. throwError(error, 'FreeAnyWhere.getGiveawayId');
  6924. return false;
  6925. }
  6926. }
  6927. #getGiveawayId() {
  6928. try {
  6929. const giveawayId = window.location.href.match(/\/giveaway\/([\d]+)/)?.[1];
  6930. if (giveawayId) {
  6931. this.giveawayId = giveawayId;
  6932. return true;
  6933. }
  6934. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  6935. return false;
  6936. } catch (error) {
  6937. throwError(error, 'FreeAnyWhere.getGiveawayId');
  6938. }
  6939. }
  6940. async #verify(task) {
  6941. try {
  6942. const logStatus = scripts_echoLog({
  6943. html: `<li>${i18n('verifyingTask')}${task.title.trim()}...<font></font></li>`
  6944. });
  6945. const {
  6946. result,
  6947. statusText,
  6948. status,
  6949. data
  6950. } = await tools_httpRequest({
  6951. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/challenge-status/${task.id}/?format=json`,
  6952. method: 'GET',
  6953. dataType: 'json',
  6954. headers: {
  6955. authorization: `Token ${window.localStorage.getItem('token')}`,
  6956. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  6957. }
  6958. });
  6959. if (result === 'Success') {
  6960. if (data?.response?.status) {
  6961. logStatus.success();
  6962. return true;
  6963. }
  6964. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6965. return false;
  6966. }
  6967. logStatus.error(`${result}:${statusText}(${status})`);
  6968. return false;
  6969. } catch (error) {
  6970. throwError(error, 'Freeanywhere.verify');
  6971. return false;
  6972. }
  6973. }
  6974. async #checkLeftKey() {
  6975. try {
  6976. if (!globalOptions.other.checkLeftKey) {
  6977. return true;
  6978. }
  6979. const {
  6980. data
  6981. } = await tools_httpRequest({
  6982. url: 'https://freeanywhere.net/api/v1/widget/?format=json',
  6983. method: 'GET',
  6984. dataType: 'json',
  6985. headers: {
  6986. authorization: `Token ${window.localStorage.getItem('token')}`
  6987. }
  6988. });
  6989. if (data?.response?.giveaways.find(giveaway => `${giveaway?.id}` === this.giveawayId)) {
  6990. return true;
  6991. }
  6992. await external_Swal_default().fire({
  6993. icon: 'warning',
  6994. title: i18n('notice'),
  6995. text: i18n('noKeysLeft'),
  6996. confirmButtonText: i18n('confirm'),
  6997. cancelButtonText: i18n('cancel'),
  6998. showCancelButton: true
  6999. }).then(({
  7000. value
  7001. }) => {
  7002. if (value) {
  7003. window.close();
  7004. }
  7005. });
  7006. return true;
  7007. } catch (error) {
  7008. throwError(error, 'Giveawaysu.checkLeftKey');
  7009. return false;
  7010. }
  7011. }
  7012. }
  7013. const Freeanywhere = FreeAnyWhere;
  7014. const Giveawaysu_defaultTasks = {
  7015. steam: {
  7016. groupLinks: [],
  7017. wishlistLinks: [],
  7018. curatorLinks: [],
  7019. curatorLikeLinks: [],
  7020. followLinks: [],
  7021. forumLinks: [],
  7022. announcementLinks: [],
  7023. workshopVoteLinks: [],
  7024. playtestLinks: []
  7025. },
  7026. discord: {
  7027. serverLinks: []
  7028. },
  7029. instagram: {
  7030. userLinks: []
  7031. },
  7032. vk: {
  7033. nameLinks: []
  7034. },
  7035. twitch: {
  7036. channelLinks: []
  7037. },
  7038. reddit: {
  7039. redditLinks: []
  7040. },
  7041. youtube: {
  7042. channelLinks: [],
  7043. likeLinks: []
  7044. },
  7045. twitter: {
  7046. userLinks: [],
  7047. retweetLinks: []
  7048. }
  7049. };
  7050. class GiveawaySu extends website_Website {
  7051. name = 'GiveawaySu';
  7052. socialTasks = Giveawaysu_defaultTasks;
  7053. undoneTasks = Giveawaysu_defaultTasks;
  7054. buttons = [ 'doTask', 'undoTask' ];
  7055. static test() {
  7056. return /^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(window.location.href);
  7057. }
  7058. async after() {
  7059. try {
  7060. if (!this.#checkLogin()) {
  7061. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7062. }
  7063. if (!await this.#checkLeftKey()) {
  7064. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7065. }
  7066. scripts_echoLog({}).warning(i18n('gsNotice'));
  7067. } catch (error) {
  7068. throwError(error, 'Giveawaysu.after');
  7069. }
  7070. }
  7071. init() {
  7072. try {
  7073. const logStatus = scripts_echoLog({
  7074. text: i18n('initing')
  7075. });
  7076. if ($('a.steam-login').length > 0) {
  7077. window.open('/steam/redirect', '_self');
  7078. logStatus.warning(i18n('needLogin'));
  7079. return false;
  7080. }
  7081. if (!this.#getGiveawayId()) {
  7082. return false;
  7083. }
  7084. this.initialized = true;
  7085. logStatus.success();
  7086. return true;
  7087. } catch (error) {
  7088. throwError(error, 'Giveawaysu.init');
  7089. return false;
  7090. }
  7091. }
  7092. async classifyTask(action) {
  7093. try {
  7094. const logStatus = scripts_echoLog({
  7095. text: i18n('getTasksInfo')
  7096. });
  7097. if (action === 'undo') {
  7098. this.socialTasks = GM_getValue(`gasTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  7099. return true;
  7100. }
  7101. const pro = [];
  7102. const tasks = $('#actions tr');
  7103. if ($('div.bind-discord').is(':visible')) {
  7104. $('div.bind-discord a')[0].click();
  7105. }
  7106. if ($('div.bind-twitch').is(':visible')) {
  7107. $('div.bind-twitch a')[0].click();
  7108. }
  7109. for (const task of tasks) {
  7110. pro.push(new Promise(resolve => {
  7111. const td = $(task).find('td:not(".hidden")');
  7112. const colorfulTask = td.eq(1).find('a:not([data-trigger="link"])');
  7113. const colorlessTask = td.eq(2).find('a:not([data-trigger="link"])');
  7114. const taskDes = colorfulTask.length > 0 ? colorfulTask : colorlessTask;
  7115. const taskIcon = td.eq(0).find('i').attr('class') || '';
  7116. const taskName = taskDes.text().trim();
  7117. if (taskIcon.includes('ban') || /disable adblock/gi.test(taskName)) {
  7118. return resolve(true);
  7119. }
  7120. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  7121. if (!taskLink) {
  7122. return resolve(false);
  7123. }
  7124. if (taskIcon.includes('steam') && /join/gi.test(taskName)) {
  7125. this.undoneTasks.steam.groupLinks.push(taskLink);
  7126. } else if (/like.*announcement/gi.test(taskName)) {
  7127. this.undoneTasks.steam.announcementLinks.push(taskLink);
  7128. } else if (/(follow|subscribe).*curator/gim.test(taskName) && /^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  7129. this.undoneTasks.steam.curatorLinks.push(taskLink);
  7130. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  7131. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  7132. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  7133. this.undoneTasks.steam.forumLinks.push(taskLink);
  7134. } else if (taskIcon.includes('thumbs-up') && /^https?:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=[\d]+/.test(taskLink)) {
  7135. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7136. } else if (taskIcon.includes('plus') && /request.*playtest/gim.test(taskName)) {
  7137. this.undoneTasks.steam.playtestLinks.push(taskLink);
  7138. } else if (taskIcon.includes('discord') || /join.*discord/gim.test(taskName)) {
  7139. this.undoneTasks.discord.serverLinks.push(taskLink);
  7140. } else if (taskIcon.includes('instagram') || /follow.*instagram/gim.test(taskName)) {
  7141. this.undoneTasks.instagram.userLinks.push(taskLink);
  7142. } else if (taskIcon.includes('twitch') || /follow.*twitch.*channel/gim.test(taskName)) {
  7143. this.undoneTasks.twitch.channelLinks.push(taskLink);
  7144. } else if (taskIcon.includes('reddit') || /subscribe.*subreddit/gim.test(taskName) || /follow.*reddit/gim.test(taskName)) {
  7145. this.undoneTasks.reddit.redditLinks.push(taskLink);
  7146. } else if (/watch.*art/gim.test(taskName)) {
  7147. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7148. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  7149. this.undoneTasks.youtube.channelLinks.push(taskLink);
  7150. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  7151. this.undoneTasks.youtube.likeLinks.push(taskLink);
  7152. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  7153. this.undoneTasks.vk.nameLinks.push(taskLink);
  7154. } else {
  7155. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  7156. if (/wishlist.*game|add.*wishlist/gim.test(taskName)) {
  7157. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  7158. }
  7159. if (/follow.*button/gim.test(taskName)) {
  7160. this.undoneTasks.steam.followLinks.push(taskLink);
  7161. }
  7162. }
  7163. }
  7164. resolve(true);
  7165. }).catch(error => {
  7166. throwError(error, 'Giveawaysu.classifyTask->getRedirectLink');
  7167. return false;
  7168. });
  7169. }));
  7170. }
  7171. await Promise.all(pro);
  7172. logStatus.success();
  7173. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7174. this.socialTasks = this.undoneTasks;
  7175. if (window.DEBUG) {
  7176. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7177. }
  7178. GM_setValue(`gasTasks-${this.giveawayId}`, {
  7179. tasks: this.socialTasks,
  7180. time: new Date().getTime()
  7181. });
  7182. return true;
  7183. } catch (error) {
  7184. throwError(error, 'Giveawaysu.classifyTask');
  7185. return false;
  7186. }
  7187. }
  7188. #checkLogin() {
  7189. try {
  7190. if (!globalOptions.other.checkLogin) {
  7191. return true;
  7192. }
  7193. if ($('a.steam-login').length > 0) {
  7194. window.open('/steam/redirect', '_self');
  7195. }
  7196. return true;
  7197. } catch (error) {
  7198. throwError(error, 'Giveawaysu.checkLogin');
  7199. return false;
  7200. }
  7201. }
  7202. async #checkLeftKey() {
  7203. try {
  7204. if (!globalOptions.other.checkLeftKey) {
  7205. return true;
  7206. }
  7207. if ($('.giveaway-ended').length > 0 && $('.giveaway-key').length === 0) {
  7208. await external_Swal_default().fire({
  7209. icon: 'warning',
  7210. title: i18n('notice'),
  7211. text: i18n('noKeysLeft'),
  7212. confirmButtonText: i18n('confirm'),
  7213. cancelButtonText: i18n('cancel'),
  7214. showCancelButton: true
  7215. }).then(({
  7216. value
  7217. }) => {
  7218. if (value) {
  7219. window.close();
  7220. }
  7221. });
  7222. }
  7223. return true;
  7224. } catch (error) {
  7225. throwError(error, 'Giveawaysu.checkLeftKey');
  7226. return false;
  7227. }
  7228. }
  7229. #getGiveawayId() {
  7230. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  7231. if (giveawayId) {
  7232. this.giveawayId = giveawayId;
  7233. return true;
  7234. }
  7235. scripts_echoLog({
  7236. text: i18n('getFailed', 'GiveawayId')
  7237. });
  7238. return false;
  7239. }
  7240. }
  7241. class Indiedb {
  7242. name = 'Indiedb';
  7243. buttons = [ 'doTask' ];
  7244. static test() {
  7245. return window.location.host === 'www.indiedb.com';
  7246. }
  7247. async after() {
  7248. try {
  7249. if (!this.#checkLogin()) {
  7250. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7251. }
  7252. if (!await this.#checkLeftKey()) {
  7253. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7254. }
  7255. } catch (error) {
  7256. throwError(error, 'Indiedb.after');
  7257. }
  7258. }
  7259. async doTask() {
  7260. try {
  7261. if (!await this.#join()) {
  7262. return false;
  7263. }
  7264. return await this.#do();
  7265. } catch (error) {
  7266. throwError(error, 'Indiedb.doTask');
  7267. return false;
  7268. }
  7269. }
  7270. async #join() {
  7271. try {
  7272. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7273. scripts_echoLog({}).error(i18n('needLogin'));
  7274. return false;
  7275. }
  7276. const currentoption = $('a.buttonenter.buttongiveaway');
  7277. if (/join giveaway/gim.test(currentoption.text())) {
  7278. const logStatus = scripts_echoLog({
  7279. text: `${i18n('joiningGiveaway')}...`
  7280. });
  7281. const {
  7282. result,
  7283. statusText,
  7284. status,
  7285. data
  7286. } = await tools_httpRequest({
  7287. url: currentoption.attr('href'),
  7288. method: 'POST',
  7289. data: 'ajax=t',
  7290. dataType: 'json',
  7291. headers: {
  7292. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  7293. accept: 'application/json, text/javascript, */*; q=0.01',
  7294. origin: window.location.origin
  7295. }
  7296. });
  7297. if (result === 'Success') {
  7298. if (data?.status === 200) {
  7299. if (data.response?.success) {
  7300. currentoption.addClass('buttonentered').text('Success - Giveaway joined');
  7301. $('#giveawaysjoined').slideDown();
  7302. $('#giveawaysrecommend').slideDown();
  7303. logStatus.success(`Success${data.response?.text ? `:${data.response?.text}` : ''}`);
  7304. return true;
  7305. }
  7306. logStatus.error(`Error${data.response?.text ? `:${data.response?.text}` : ''}`);
  7307. return false;
  7308. }
  7309. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7310. return false;
  7311. }
  7312. logStatus.error(`${result}:${statusText}(${status})`);
  7313. return false;
  7314. } else if (/success/gim.test($('a.buttonenter.buttongiveaway').text())) {
  7315. return true;
  7316. }
  7317. scripts_echoLog({}).warning(i18n('needJoinGiveaway'));
  7318. return false;
  7319. } catch (error) {
  7320. throwError(error, 'Indiedb.init');
  7321. return false;
  7322. }
  7323. }
  7324. async #do() {
  7325. try {
  7326. const id = $('script').map((index, script) => {
  7327. if (/\$\(document\)/gim.test(script.innerHTML)) {
  7328. return [ script.innerHTML.match(/"\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0], script.innerHTML.match(/"\/newsletter\/ajax\/subscribeprofile\/optin\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0] ];
  7329. }
  7330. return null;
  7331. });
  7332. if (id.length === 2) {
  7333. const pro = [];
  7334. const tasks = $('#giveawaysjoined a[class*=promo]');
  7335. for (const task of tasks) {
  7336. const promo = $(task);
  7337. if (!promo.hasClass('buttonentered')) {
  7338. const status = scripts_echoLog({
  7339. text: `${i18n('doing')}:${promo.parents('p').text()}...`
  7340. });
  7341. if (/facebookpromo|twitterpromo|visitpromo/gim.test(task.className)) {
  7342. let text = '';
  7343. if (promo.hasClass('facebookpromo')) {
  7344. text = 'facebookpromo';
  7345. } else if (promo.hasClass('twitterpromo')) {
  7346. text = 'twitterpromo';
  7347. } else {
  7348. text = 'visitpromo';
  7349. }
  7350. pro.push(new Promise(resolve => {
  7351. $.ajax({
  7352. type: 'POST',
  7353. url: urlPath(`/giveaways/ajax/${text}/${id[0]}`),
  7354. timeout: 6e4,
  7355. dataType: 'json',
  7356. data: {
  7357. ajax: 't'
  7358. },
  7359. error(response, error, exception) {
  7360. if (window.DEBUG) {
  7361. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7362. response: response,
  7363. error: error,
  7364. exception: exception
  7365. });
  7366. }
  7367. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7368. resolve(true);
  7369. },
  7370. success(response) {
  7371. if (response.success) {
  7372. status.success(`Success:${response.text}`);
  7373. promo.addClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7374. resolve(true);
  7375. } else {
  7376. status.error(`Error:${response.text}`);
  7377. resolve(true);
  7378. }
  7379. }
  7380. });
  7381. }));
  7382. } else if (promo.hasClass('emailoptinpromo')) {
  7383. pro.push(new Promise(resolve => {
  7384. $.ajax({
  7385. type: 'POST',
  7386. url: urlPath(`/newsletter/ajax/subscribeprofile/optin/${id[1]}`),
  7387. timeout: 6e4,
  7388. dataType: 'json',
  7389. data: {
  7390. ajax: 't',
  7391. emailsystoggle: 4
  7392. },
  7393. error(response, error, exception) {
  7394. if (window.DEBUG) {
  7395. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7396. response: response,
  7397. error: error,
  7398. exception: exception
  7399. });
  7400. }
  7401. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7402. resolve(true);
  7403. },
  7404. success(response) {
  7405. if (response.success) {
  7406. status.success(`Success:${response.text}`);
  7407. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7408. resolve(true);
  7409. } else {
  7410. status.error(`Error:${response.text}`);
  7411. resolve(true);
  7412. }
  7413. }
  7414. });
  7415. }));
  7416. } else if (promo.hasClass('watchingpromo')) {
  7417. pro.push(new Promise(resolve => {
  7418. const data = getUrlQuery(promo.attr('href'));
  7419. data.ajax = 't';
  7420. $.ajax({
  7421. type: 'POST',
  7422. url: urlPath(promo.attr('href')?.split(/[?#]/)[0]),
  7423. timeout: 6e4,
  7424. dataType: 'json',
  7425. data: data,
  7426. error(response, error, exception) {
  7427. if (window.DEBUG) {
  7428. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7429. response: response,
  7430. error: error,
  7431. exception: exception
  7432. });
  7433. }
  7434. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7435. resolve(true);
  7436. },
  7437. success(response) {
  7438. if (response.success) {
  7439. status.success(`Success:${response.text}`);
  7440. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7441. resolve(true);
  7442. } else {
  7443. status.error(`Error:${response.text}`);
  7444. resolve(true);
  7445. }
  7446. }
  7447. });
  7448. }));
  7449. } else if (!/the-challenge-of-adblock/gim.test(promo.attr('href'))) {
  7450. pro.push(new Promise(resolve => {
  7451. $.ajax({
  7452. type: 'POST',
  7453. url: urlPath(promo.attr('href')),
  7454. timeout: 6e4,
  7455. dataType: 'json',
  7456. data: {
  7457. ajax: 't'
  7458. },
  7459. error(response, error, exception) {
  7460. if (window.DEBUG) {
  7461. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7462. response: response,
  7463. error: error,
  7464. exception: exception
  7465. });
  7466. }
  7467. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7468. resolve(true);
  7469. },
  7470. success(response) {
  7471. if (response.success) {
  7472. status.success(`Success:${response.text}`);
  7473. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7474. resolve(true);
  7475. } else {
  7476. status.error(`Error:${response.text}`);
  7477. resolve(true);
  7478. }
  7479. }
  7480. });
  7481. }));
  7482. } else {
  7483. status.error(`Error:${i18n('unKnownTaskType')}`);
  7484. }
  7485. }
  7486. }
  7487. await Promise.all(pro);
  7488. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7489. return true;
  7490. }
  7491. scripts_echoLog({}).error(i18n('getFailed', 'TaskId'));
  7492. return false;
  7493. } catch (error) {
  7494. throwError(error, 'Indiedb.classifyTask');
  7495. return false;
  7496. }
  7497. }
  7498. #checkLogin() {
  7499. try {
  7500. if (!globalOptions.other.checkLogin) {
  7501. return true;
  7502. }
  7503. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7504. window.open('/members/login', '_self');
  7505. }
  7506. return true;
  7507. } catch (error) {
  7508. throwError(error, 'Indiedb.checkLogin');
  7509. return false;
  7510. }
  7511. }
  7512. async #checkLeftKey() {
  7513. try {
  7514. if (!globalOptions.other.checkLeftKey) {
  7515. return true;
  7516. }
  7517. if ($('a.buttonenter:contains("next time"),a.buttonenter:contains("Giveaway is closed")').length > 0) {
  7518. await external_Swal_default().fire({
  7519. icon: 'warning',
  7520. title: i18n('notice'),
  7521. text: i18n('giveawayEnded'),
  7522. confirmButtonText: i18n('confirm'),
  7523. cancelButtonText: i18n('cancel'),
  7524. showCancelButton: true
  7525. }).then(({
  7526. value
  7527. }) => {
  7528. if (value) {
  7529. window.close();
  7530. }
  7531. });
  7532. }
  7533. return true;
  7534. } catch (error) {
  7535. throwError(error, 'Indiedb.checkLeftKey');
  7536. return false;
  7537. }
  7538. }
  7539. }
  7540. const website_Indiedb = Indiedb;
  7541. const Keyhub_defaultTasksTemplate = {
  7542. steam: {
  7543. groupLinks: [],
  7544. officialGroupLinks: [],
  7545. wishlistLinks: [],
  7546. curatorLinks: []
  7547. },
  7548. discord: {
  7549. serverLinks: []
  7550. },
  7551. extra: {
  7552. videoTasks: []
  7553. },
  7554. links: []
  7555. };
  7556. const Keyhub_defaultTasks = JSON.stringify(Keyhub_defaultTasksTemplate);
  7557. class Keyhub extends website_Website {
  7558. name = 'Keyhub';
  7559. socialTasks = JSON.parse(Keyhub_defaultTasks);
  7560. undoneTasks = JSON.parse(Keyhub_defaultTasks);
  7561. buttons = [ 'doTask', 'undoTask' ];
  7562. static test() {
  7563. return window.location.host === 'key-hub.eu';
  7564. }
  7565. async after() {
  7566. try {
  7567. if (!this.#checkLogin()) {
  7568. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7569. }
  7570. if (!await this.#checkLeftKey()) {
  7571. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7572. }
  7573. $('.NSFW').hide();
  7574. } catch (error) {
  7575. throwError(error, 'Keyhub.after');
  7576. }
  7577. }
  7578. init() {
  7579. try {
  7580. const logStatus = scripts_echoLog({
  7581. text: i18n('initing')
  7582. });
  7583. if ($('a[href*="/connect/steam"]').length > 0) {
  7584. window.open('/connect/steam', '_self');
  7585. logStatus.warning(i18n('needLogin'));
  7586. return false;
  7587. }
  7588. if (!this.#getGiveawayId()) {
  7589. return false;
  7590. }
  7591. $('#VPNoverlay').hide();
  7592. $('#mainArticleSection').show();
  7593. this.initialized = true;
  7594. logStatus.success();
  7595. return true;
  7596. } catch (error) {
  7597. throwError(error, 'Keyhub.init');
  7598. return false;
  7599. }
  7600. }
  7601. async classifyTask(action) {
  7602. try {
  7603. const logStatus = scripts_echoLog({
  7604. text: i18n('getTasksInfo')
  7605. });
  7606. if (action === 'undo') {
  7607. this.socialTasks = GM_getValue(`khTasks-${this.giveawayId}`)?.tasks || JSON.parse(Keyhub_defaultTasks);
  7608. }
  7609. const tasks = $('.task:not(".googleads")').filter((index, element) => action === 'do' ? $(element).find('i.fa-check-circle:visible').length === 0 : true).find('a');
  7610. for (const task of tasks) {
  7611. let link = $(task).attr('href');
  7612. const taskDes = $(task).text().trim();
  7613. if (!link) {
  7614. continue;
  7615. }
  7616. if (/\/away\?data=/.test(link) || /steamcommunity\.com\/gid\//.test(link)) {
  7617. link = await getRedirectLink(link) || link;
  7618. }
  7619. if (/https?:\/\/key-hub\.eu\/connect\/discord/.test(link)) {
  7620. window.open(link, '_blank');
  7621. } else if (/steamcommunity\.com\/groups\//.test(link)) {
  7622. if (action === 'undo') {
  7623. this.socialTasks.steam.groupLinks.push(link);
  7624. }
  7625. if (action === 'do') {
  7626. this.undoneTasks.steam.groupLinks.push(link);
  7627. }
  7628. } else if (/steamcommunity\.com\/games\/[\d]+/.test(link)) {
  7629. if (action === 'undo') {
  7630. this.socialTasks.steam.officialGroupLinks.push(link);
  7631. }
  7632. if (action === 'do') {
  7633. this.undoneTasks.steam.officialGroupLinks.push(link);
  7634. }
  7635. } else if (/store\.steampowered\.com\/app\//.test(link) && /wishlist/gim.test(taskDes)) {
  7636. if (action === 'undo') {
  7637. this.socialTasks.steam.wishlistLinks.push(link);
  7638. }
  7639. if (action === 'do') {
  7640. this.undoneTasks.steam.wishlistLinks.push(link);
  7641. }
  7642. } else if (/store\.steampowered\.com\/curator\//.test(link)) {
  7643. if (action === 'undo') {
  7644. this.socialTasks.steam.curatorLinks.push(link);
  7645. }
  7646. if (action === 'do') {
  7647. this.undoneTasks.steam.curatorLinks.push(link);
  7648. }
  7649. } else if (/^https?:\/\/discord\.com\/invite\//.test(link)) {
  7650. if (action === 'undo') {
  7651. this.socialTasks.discord.serverLinks.push(link);
  7652. }
  7653. if (action === 'do') {
  7654. this.undoneTasks.discord.serverLinks.push(link);
  7655. }
  7656. } else if (/^javascript:videoTask.+/.test(link)) {
  7657. if (action === 'do') {
  7658. const taskData = link.match(/javascript:videoTask\('.+?','(.+?)'/)?.[1];
  7659. if (taskData) {
  7660. this.undoneTasks.extra.videoTasks.push(taskData);
  7661. }
  7662. }
  7663. } 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 {
  7664. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  7665. }
  7666. }
  7667. logStatus.success();
  7668. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7669. this.socialTasks = this.uniqueTasks(this.socialTasks);
  7670. if (window.DEBUG) {
  7671. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7672. }
  7673. GM_setValue(`khTasks-${this.giveawayId}`, {
  7674. tasks: this.socialTasks,
  7675. time: new Date().getTime()
  7676. });
  7677. return true;
  7678. } catch (error) {
  7679. throwError(error, 'Keyhub.classifyTask');
  7680. return false;
  7681. }
  7682. }
  7683. async #doScriptTask(data) {
  7684. try {
  7685. const logStatus = scripts_echoLog({
  7686. text: i18n('doingKeyhubTask')
  7687. });
  7688. const {
  7689. result,
  7690. statusText,
  7691. status,
  7692. data: response
  7693. } = await tools_httpRequest({
  7694. url: `/away?data=${data}`,
  7695. method: 'GET',
  7696. headers: {
  7697. origin: 'https://key-hub.eu',
  7698. referer: 'https://key-hub.eu/'
  7699. }
  7700. });
  7701. if (result === 'Success') {
  7702. if (response?.status === 200) {
  7703. logStatus.success();
  7704. return true;
  7705. }
  7706. logStatus.error(`Error:${response?.statusText}(${response?.status})`);
  7707. return false;
  7708. }
  7709. logStatus.error(`${result}:${statusText}(${status})`);
  7710. return false;
  7711. } catch (error) {
  7712. throwError(error, 'Keyhub.doScriptTask');
  7713. return false;
  7714. }
  7715. }
  7716. async extraDoTask({
  7717. videoTasks
  7718. }) {
  7719. try {
  7720. const pro = [];
  7721. for (const data of videoTasks) {
  7722. pro.push(this.#doScriptTask(data));
  7723. }
  7724. return Promise.all(pro).then(() => true);
  7725. } catch (error) {
  7726. throwError(error, 'Keyhub.extraDoTask');
  7727. return false;
  7728. }
  7729. }
  7730. #getGiveawayId() {
  7731. try {
  7732. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  7733. if (giveawayId) {
  7734. this.giveawayId = giveawayId;
  7735. return true;
  7736. }
  7737. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7738. return false;
  7739. } catch (error) {
  7740. throwError(error, 'Keyhub.getGiveawayId');
  7741. return false;
  7742. }
  7743. }
  7744. async #checkLeftKey() {
  7745. try {
  7746. if (!globalOptions.other.checkLeftKey) {
  7747. return true;
  7748. }
  7749. const leftKey = $('#keysleft').text().trim();
  7750. if (leftKey === '0') {
  7751. await external_Swal_default().fire({
  7752. icon: 'warning',
  7753. title: i18n('notice'),
  7754. text: i18n('noKeysLeft'),
  7755. confirmButtonText: i18n('confirm'),
  7756. cancelButtonText: i18n('cancel'),
  7757. showCancelButton: true
  7758. }).then(({
  7759. value
  7760. }) => {
  7761. if (value) {
  7762. window.close();
  7763. }
  7764. });
  7765. }
  7766. return true;
  7767. } catch (error) {
  7768. throwError(error, 'Keyhub.checkLeftKey');
  7769. return false;
  7770. }
  7771. }
  7772. #checkLogin() {
  7773. try {
  7774. if (!globalOptions.other.checkLogin) {
  7775. return true;
  7776. }
  7777. if ($('a[href*="/connect/steam"]').length > 0) {
  7778. window.open('/connect/steam', '_self');
  7779. }
  7780. return true;
  7781. } catch (error) {
  7782. throwError(error, 'Keyhub.checkLogin');
  7783. return false;
  7784. }
  7785. }
  7786. }
  7787. const website_Keyhub = Keyhub;
  7788. const Givekey_defaultTasksTemplate = {
  7789. steam: {
  7790. groupLinks: [],
  7791. wishlistLinks: [],
  7792. curatorLinks: [],
  7793. curatorLikeLinks: []
  7794. },
  7795. twitter: {
  7796. userLinks: []
  7797. },
  7798. vk: {
  7799. nameLinks: []
  7800. },
  7801. discord: {
  7802. serverLinks: []
  7803. }
  7804. };
  7805. const Givekey_defaultTasks = JSON.stringify(Givekey_defaultTasksTemplate);
  7806. class Givekey extends website_Website {
  7807. name = 'Givekey';
  7808. tasks = [];
  7809. socialTasks = JSON.parse(Givekey_defaultTasks);
  7810. undoneTasks = JSON.parse(Givekey_defaultTasks);
  7811. userId;
  7812. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  7813. static test() {
  7814. return window.location.host === 'givekey.ru';
  7815. }
  7816. async after() {
  7817. try {
  7818. await new Promise(resolve => {
  7819. const checker = setInterval(() => {
  7820. if ($('#navbarDropdown').length > 0) {
  7821. clearInterval(checker);
  7822. resolve(true);
  7823. }
  7824. });
  7825. });
  7826. if (!await this.#checkLeftKey()) {
  7827. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7828. }
  7829. } catch (error) {
  7830. throwError(error, 'Givekey.after');
  7831. return false;
  7832. }
  7833. }
  7834. init() {
  7835. try {
  7836. const logStatus = scripts_echoLog({
  7837. text: i18n('initing')
  7838. });
  7839. if ($('a[href*="/auth/steam"]').length > 0) {
  7840. window.open('/auth/steam', '_self');
  7841. logStatus.warning(i18n('needLogin'));
  7842. return false;
  7843. }
  7844. if (!this.#getGiveawayId()) {
  7845. return false;
  7846. }
  7847. const userId = $('meta[name="user-id"]').attr('content');
  7848. if (!userId) {
  7849. logStatus.error(i18n('getFailed', i18n('userId')));
  7850. return false;
  7851. }
  7852. this.userId = userId;
  7853. this.initialized = true;
  7854. logStatus.success();
  7855. return true;
  7856. } catch (error) {
  7857. throwError(error, 'Givekey.init');
  7858. return false;
  7859. }
  7860. }
  7861. async classifyTask(action) {
  7862. try {
  7863. const logStatus = scripts_echoLog({
  7864. text: i18n('getTasksInfo')
  7865. });
  7866. if (action === 'undo') {
  7867. this.socialTasks = GM_getValue(`gkTasks-${this.giveawayId}`)?.tasks || JSON.parse(Givekey_defaultTasks);
  7868. }
  7869. const tasks = $('.card-body:has("button") .row');
  7870. for (const task of tasks) {
  7871. const taskEle = $(task);
  7872. const isSuccess = /Complete/i.test(taskEle.find('button').text().trim());
  7873. if (isSuccess && action !== 'undo') {
  7874. continue;
  7875. }
  7876. const checkButton = taskEle.find('#task_check');
  7877. const taskId = checkButton.attr('data-id');
  7878. if (taskId) {
  7879. this.tasks.push(taskId);
  7880. }
  7881. if (action === 'verify') {
  7882. continue;
  7883. }
  7884. let href = taskEle.find('a').attr('href') || null;
  7885. const text = taskEle.find('a').text().trim();
  7886. const icon = taskEle.find('i');
  7887. if (!href || !text) {
  7888. continue;
  7889. }
  7890. if (/^https?:\/\/givekey\.ru\/giveaway\/[\d]+\/execution_task/.test(href)) {
  7891. href = await getRedirectLink(href);
  7892. }
  7893. if (!href) {
  7894. continue;
  7895. }
  7896. if (/^https?:\/\/vk\.com\//.test(href)) {
  7897. this.socialTasks.vk.nameLinks.push(href);
  7898. if (action === 'do' && !isSuccess) {
  7899. this.undoneTasks.vk.nameLinks.push(href);
  7900. }
  7901. } else if (/^https?:\/\/steamcommunity\.com\/groups/.test(href)) {
  7902. this.socialTasks.steam.groupLinks.push(href);
  7903. if (action === 'do' && !isSuccess) {
  7904. this.undoneTasks.steam.groupLinks.push(href);
  7905. }
  7906. } else if (/^https?:\/\/store\.steampowered\.com\/app\//.test(href)) {
  7907. this.socialTasks.steam.wishlistLinks.push(href);
  7908. if (action === 'do' && !isSuccess) {
  7909. this.undoneTasks.steam.wishlistLinks.push(href);
  7910. }
  7911. } else if (/Subscribe/gi.test(text) && icon.hasClass('fa-steam-square')) {
  7912. if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(href)) {
  7913. this.socialTasks.steam.curatorLinks.push(href);
  7914. if (action === 'do' && !isSuccess) {
  7915. this.undoneTasks.steam.curatorLinks.push(href);
  7916. }
  7917. } else {
  7918. this.socialTasks.steam.curatorLikeLinks.push(href);
  7919. if (action === 'do' && !isSuccess) {
  7920. this.undoneTasks.steam.curatorLikeLinks.push(href);
  7921. }
  7922. }
  7923. } else if (/^https?:\/\/twitter\.com\//.test(href) && /Subscribe/gi.test(text)) {
  7924. this.socialTasks.twitter.userLinks.push(href);
  7925. if (action === 'do' && !isSuccess) {
  7926. this.undoneTasks.twitter.userLinks.push(href);
  7927. }
  7928. } else if (icon.hasClass('fa-discord') || /^https?:\/\/discord\.com\/invite\//.test(href)) {
  7929. this.socialTasks.discord.serverLinks.push(href);
  7930. if (action === 'do' && !isSuccess) {
  7931. this.undoneTasks.discord.serverLinks.push(href);
  7932. }
  7933. } else {
  7934. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${text}(${href})`);
  7935. }
  7936. }
  7937. logStatus.success();
  7938. this.tasks = unique(this.tasks);
  7939. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7940. this.socialTasks = this.uniqueTasks(this.socialTasks);
  7941. if (window.DEBUG) {
  7942. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7943. }
  7944. GM_setValue(`gkTasks-${this.giveawayId}`, {
  7945. tasks: this.socialTasks,
  7946. time: new Date().getTime()
  7947. });
  7948. return true;
  7949. } catch (error) {
  7950. throwError(error, 'Givekey.classifyTask');
  7951. return false;
  7952. }
  7953. }
  7954. async verifyTask() {
  7955. try {
  7956. if (!this.initialized && !this.init()) {
  7957. return false;
  7958. }
  7959. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  7960. return false;
  7961. }
  7962. scripts_echoLog({}).warning(i18n('giveKeyNoticeBefore'));
  7963. const taskLength = this.tasks.length;
  7964. for (let i = 0; i < taskLength; i++) {
  7965. await this.#verify(this.tasks[i]);
  7966. if (i < taskLength - 1) {
  7967. await delay(15e3);
  7968. }
  7969. }
  7970. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7971. scripts_echoLog({
  7972. html: `<li><font class="warning">${i18n('giveKeyNoticeAfter')}</font></li>`
  7973. });
  7974. return true;
  7975. } catch (error) {
  7976. throwError(error, 'Givekey.verifyTask');
  7977. return false;
  7978. }
  7979. }
  7980. async #verify(task) {
  7981. try {
  7982. const logStatus = scripts_echoLog({
  7983. html: `<li>${i18n('verifyingTask')}${task}...<font></font></li>`
  7984. });
  7985. return await new Promise(resolve => {
  7986. $.ajax({
  7987. url: 'https://givekey.ru/giveaway/task',
  7988. method: 'POST',
  7989. data: `id=${task}&user_id=${this.userId}`,
  7990. dataType: 'json',
  7991. headers: {
  7992. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  7993. },
  7994. success: data => {
  7995. if (data.btn) {
  7996. $(`button[data-id=${this.userId}]`).html(data.btn);
  7997. }
  7998. if (data.status === 'ok') {
  7999. $(`.task_check_${data.id}`).html(`<button class="btn btn-success mb-2 btn-block" disabled>${data.btn}</button>`);
  8000. logStatus.success();
  8001. resolve(true);
  8002. } else if (data.status === 'end') {
  8003. logStatus.success();
  8004. scripts_echoLog({}).success(data.key);
  8005. resolve(true);
  8006. } else {
  8007. logStatus.error(`Error:${data.msg}`);
  8008. resolve(false);
  8009. }
  8010. },
  8011. error: xhr => {
  8012. logStatus.error(`Error:${xhr.statusText}(${xhr.status})`);
  8013. resolve(false);
  8014. }
  8015. });
  8016. });
  8017. } catch (error) {
  8018. throwError(error, 'Givekey.verify');
  8019. return false;
  8020. }
  8021. }
  8022. #getGiveawayId() {
  8023. try {
  8024. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  8025. if (giveawayId) {
  8026. this.giveawayId = giveawayId;
  8027. return true;
  8028. }
  8029. scripts_echoLog({
  8030. text: i18n('getFailed', 'GiveawayId')
  8031. });
  8032. return false;
  8033. } catch (error) {
  8034. throwError(error, 'Givekey.getGiveawayId');
  8035. return false;
  8036. }
  8037. }
  8038. async #checkLeftKey() {
  8039. try {
  8040. if (!globalOptions.other.checkLeftKey) {
  8041. return true;
  8042. }
  8043. if (!$('#keys_count').text()) {
  8044. await external_Swal_default().fire({
  8045. icon: 'warning',
  8046. title: i18n('notice'),
  8047. text: i18n('noKeysLeft'),
  8048. confirmButtonText: i18n('confirm'),
  8049. cancelButtonText: i18n('cancel'),
  8050. showCancelButton: true
  8051. }).then(({
  8052. value
  8053. }) => {
  8054. if (value) {
  8055. window.close();
  8056. }
  8057. });
  8058. }
  8059. return true;
  8060. } catch (error) {
  8061. throwError(error, 'Givekey.checkLeftKey');
  8062. return false;
  8063. }
  8064. }
  8065. }
  8066. const website_Givekey = Givekey;
  8067. const GiveawaySu_defaultTasks = {
  8068. steam: {
  8069. groupLinks: [],
  8070. wishlistLinks: [],
  8071. curatorLinks: [],
  8072. curatorLikeLinks: [],
  8073. followLinks: [],
  8074. forumLinks: [],
  8075. announcementLinks: [],
  8076. workshopVoteLinks: [],
  8077. playtestLinks: []
  8078. },
  8079. discord: {
  8080. serverLinks: []
  8081. },
  8082. instagram: {
  8083. userLinks: []
  8084. },
  8085. vk: {
  8086. nameLinks: []
  8087. },
  8088. twitch: {
  8089. channelLinks: []
  8090. },
  8091. reddit: {
  8092. redditLinks: []
  8093. },
  8094. youtube: {
  8095. channelLinks: [],
  8096. likeLinks: []
  8097. },
  8098. twitter: {
  8099. userLinks: [],
  8100. retweetLinks: []
  8101. }
  8102. };
  8103. class GiveawaySu_GiveawaySu extends website_Website {
  8104. name = 'GiveawaySu';
  8105. socialTasks = GiveawaySu_defaultTasks;
  8106. undoneTasks = GiveawaySu_defaultTasks;
  8107. buttons = [ 'doTask', 'undoTask' ];
  8108. static test() {
  8109. return /^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(window.location.href);
  8110. }
  8111. async after() {
  8112. try {
  8113. if (!this.#checkLogin()) {
  8114. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8115. }
  8116. if (!await this.#checkLeftKey()) {
  8117. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  8118. }
  8119. scripts_echoLog({}).warning(i18n('gsNotice'));
  8120. } catch (error) {
  8121. throwError(error, 'Giveawaysu.after');
  8122. }
  8123. }
  8124. init() {
  8125. try {
  8126. const logStatus = scripts_echoLog({
  8127. text: i18n('initing')
  8128. });
  8129. if ($('a.steam-login').length > 0) {
  8130. window.open('/steam/redirect', '_self');
  8131. logStatus.warning(i18n('needLogin'));
  8132. return false;
  8133. }
  8134. if (!this.#getGiveawayId()) {
  8135. return false;
  8136. }
  8137. this.initialized = true;
  8138. logStatus.success();
  8139. return true;
  8140. } catch (error) {
  8141. throwError(error, 'Giveawaysu.init');
  8142. return false;
  8143. }
  8144. }
  8145. async classifyTask(action) {
  8146. try {
  8147. const logStatus = scripts_echoLog({
  8148. text: i18n('getTasksInfo')
  8149. });
  8150. if (action === 'undo') {
  8151. this.socialTasks = GM_getValue(`gasTasks-${this.giveawayId}`)?.tasks || GiveawaySu_defaultTasks;
  8152. return true;
  8153. }
  8154. const pro = [];
  8155. const tasks = $('#actions tr');
  8156. if ($('div.bind-discord').is(':visible')) {
  8157. $('div.bind-discord a')[0].click();
  8158. }
  8159. if ($('div.bind-twitch').is(':visible')) {
  8160. $('div.bind-twitch a')[0].click();
  8161. }
  8162. for (const task of tasks) {
  8163. pro.push(new Promise(resolve => {
  8164. const td = $(task).find('td:not(".hidden")');
  8165. const colorfulTask = td.eq(1).find('a:not([data-trigger="link"])');
  8166. const colorlessTask = td.eq(2).find('a:not([data-trigger="link"])');
  8167. const taskDes = colorfulTask.length > 0 ? colorfulTask : colorlessTask;
  8168. const taskIcon = td.eq(0).find('i').attr('class') || '';
  8169. const taskName = taskDes.text().trim();
  8170. if (taskIcon.includes('ban') || /disable adblock/gi.test(taskName)) {
  8171. return resolve(true);
  8172. }
  8173. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  8174. if (!taskLink) {
  8175. return resolve(false);
  8176. }
  8177. if (taskIcon.includes('steam') && /join/gi.test(taskName)) {
  8178. this.undoneTasks.steam.groupLinks.push(taskLink);
  8179. } else if (/like.*announcement/gi.test(taskName)) {
  8180. this.undoneTasks.steam.announcementLinks.push(taskLink);
  8181. } else if (/(follow|subscribe).*curator/gim.test(taskName) && /^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  8182. this.undoneTasks.steam.curatorLinks.push(taskLink);
  8183. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  8184. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  8185. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  8186. this.undoneTasks.steam.forumLinks.push(taskLink);
  8187. } else if (taskIcon.includes('thumbs-up') && /^https?:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=[\d]+/.test(taskLink)) {
  8188. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8189. } else if (taskIcon.includes('plus') && /request.*playtest/gim.test(taskName)) {
  8190. this.undoneTasks.steam.playtestLinks.push(taskLink);
  8191. } else if (taskIcon.includes('discord') || /join.*discord/gim.test(taskName)) {
  8192. this.undoneTasks.discord.serverLinks.push(taskLink);
  8193. } else if (taskIcon.includes('instagram') || /follow.*instagram/gim.test(taskName)) {
  8194. this.undoneTasks.instagram.userLinks.push(taskLink);
  8195. } else if (taskIcon.includes('twitch') || /follow.*twitch.*channel/gim.test(taskName)) {
  8196. this.undoneTasks.twitch.channelLinks.push(taskLink);
  8197. } else if (taskIcon.includes('reddit') || /subscribe.*subreddit/gim.test(taskName) || /follow.*reddit/gim.test(taskName)) {
  8198. this.undoneTasks.reddit.redditLinks.push(taskLink);
  8199. } else if (/watch.*art/gim.test(taskName)) {
  8200. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8201. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  8202. this.undoneTasks.youtube.channelLinks.push(taskLink);
  8203. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  8204. this.undoneTasks.youtube.likeLinks.push(taskLink);
  8205. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  8206. this.undoneTasks.vk.nameLinks.push(taskLink);
  8207. } else {
  8208. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  8209. if (/wishlist.*game|add.*wishlist/gim.test(taskName)) {
  8210. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  8211. }
  8212. if (/follow.*button/gim.test(taskName)) {
  8213. this.undoneTasks.steam.followLinks.push(taskLink);
  8214. }
  8215. }
  8216. }
  8217. resolve(true);
  8218. }).catch(error => {
  8219. throwError(error, 'Giveawaysu.classifyTask->getRedirectLink');
  8220. return false;
  8221. });
  8222. }));
  8223. }
  8224. await Promise.all(pro);
  8225. logStatus.success();
  8226. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8227. this.socialTasks = this.undoneTasks;
  8228. if (window.DEBUG) {
  8229. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8230. }
  8231. GM_setValue(`gasTasks-${this.giveawayId}`, {
  8232. tasks: this.socialTasks,
  8233. time: new Date().getTime()
  8234. });
  8235. return true;
  8236. } catch (error) {
  8237. throwError(error, 'Giveawaysu.classifyTask');
  8238. return false;
  8239. }
  8240. }
  8241. #checkLogin() {
  8242. try {
  8243. if (!globalOptions.other.checkLogin) {
  8244. return true;
  8245. }
  8246. if ($('a.steam-login').length > 0) {
  8247. window.open('/steam/redirect', '_self');
  8248. }
  8249. return true;
  8250. } catch (error) {
  8251. throwError(error, 'Giveawaysu.checkLogin');
  8252. return false;
  8253. }
  8254. }
  8255. async #checkLeftKey() {
  8256. try {
  8257. if (!globalOptions.other.checkLeftKey) {
  8258. return true;
  8259. }
  8260. if ($('.giveaway-ended').length > 0 && $('.giveaway-key').length === 0) {
  8261. await external_Swal_default().fire({
  8262. icon: 'warning',
  8263. title: i18n('notice'),
  8264. text: i18n('noKeysLeft'),
  8265. confirmButtonText: i18n('confirm'),
  8266. cancelButtonText: i18n('cancel'),
  8267. showCancelButton: true
  8268. }).then(({
  8269. value
  8270. }) => {
  8271. if (value) {
  8272. window.close();
  8273. }
  8274. });
  8275. }
  8276. return true;
  8277. } catch (error) {
  8278. throwError(error, 'Giveawaysu.checkLeftKey');
  8279. return false;
  8280. }
  8281. }
  8282. #getGiveawayId() {
  8283. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  8284. if (giveawayId) {
  8285. this.giveawayId = giveawayId;
  8286. return true;
  8287. }
  8288. scripts_echoLog({
  8289. text: i18n('getFailed', 'GiveawayId')
  8290. });
  8291. return false;
  8292. }
  8293. }
  8294. class GiveeClub extends GiveawaySu_GiveawaySu {
  8295. name = 'GiveeClub';
  8296. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  8297. static test() {
  8298. return /^https?:\/\/givee\.club\/.*?\/event\/[\d]+/.test(window.location.href);
  8299. }
  8300. async after() {
  8301. try {
  8302. if (!this.#checkLogin()) {
  8303. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8304. }
  8305. if (!await this.#checkLeftKey()) {
  8306. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  8307. }
  8308. } catch (error) {
  8309. throwError(error, 'GiveeClub.after');
  8310. }
  8311. }
  8312. init() {
  8313. try {
  8314. const logStatus = scripts_echoLog({
  8315. text: i18n('initing')
  8316. });
  8317. if (!this.#checkLogin()) {
  8318. logStatus.warning(i18n('needLogin'));
  8319. return false;
  8320. }
  8321. if (!this.#getGiveawayId()) {
  8322. return false;
  8323. }
  8324. this.initialized = true;
  8325. logStatus.success();
  8326. return true;
  8327. } catch (error) {
  8328. throwError(error, 'GiveeClub.init');
  8329. return false;
  8330. }
  8331. }
  8332. async classifyTask(action) {
  8333. try {
  8334. const logStatus = scripts_echoLog({
  8335. text: i18n('getTasksInfo')
  8336. });
  8337. if (action === 'undo') {
  8338. this.socialTasks = GM_getValue(`gcTasks-${this.giveawayId}`)?.tasks || GiveawaySu_defaultTasks;
  8339. return true;
  8340. }
  8341. const pro = [];
  8342. const tasks = $('.event-actions tr');
  8343. for (const task of tasks) {
  8344. pro.push(new Promise(resolve => {
  8345. const taskDes = $(task).find('.event-action-label a');
  8346. const taskIcon = $(task).find('.event-action-icon i').attr('class') || '';
  8347. const taskName = taskDes.text().trim();
  8348. const taskType = $(task).find('button[data-type]')?.attr('data-type');
  8349. const taskFinished = $(task).find('.event-action-buttons .btn-success')?.length;
  8350. if (taskIcon.includes('ban') || /AdBlock/i.test(taskName) || taskIcon.includes('envelope') || taskFinished) {
  8351. return resolve(true);
  8352. }
  8353. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  8354. if (!taskLink) {
  8355. return resolve(false);
  8356. }
  8357. if (taskType === 'steam.group.join' && /^https?:\/\/steamcommunity\.com\/groups/.test(taskLink)) {
  8358. this.undoneTasks.steam.groupLinks.push(taskLink);
  8359. } else if (/like.*announcement/gi.test(taskName)) {
  8360. this.undoneTasks.steam.announcementLinks.push(taskLink);
  8361. } else if (taskType === 'steam.game.wishlist' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8362. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  8363. } else if (taskType === 'steam.game.wishlist' && taskDes.attr('data-steam-wishlist-appid')) {
  8364. this.undoneTasks.steam.wishlistLinks.push(`https://store.steampowered.com/app/${taskDes.attr('data-steam-wishlist-appid')}`);
  8365. } else if (taskType === 'steam.game.follow' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8366. this.undoneTasks.steam.followLinks.push(taskLink);
  8367. } else if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  8368. this.undoneTasks.steam.curatorLinks.push(taskLink);
  8369. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  8370. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  8371. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  8372. this.undoneTasks.steam.forumLinks.push(taskLink);
  8373. } else if (taskIcon.includes('discord')) {
  8374. this.undoneTasks.discord.serverLinks.push(taskLink);
  8375. } else if (taskIcon.includes('instagram')) {
  8376. this.undoneTasks.instagram.userLinks.push(taskLink);
  8377. } else if (taskIcon.includes('twitch')) {
  8378. this.undoneTasks.twitch.channelLinks.push(taskLink);
  8379. } else if (taskIcon.includes('reddit')) {
  8380. this.undoneTasks.reddit.redditLinks.push(taskLink);
  8381. } else if (/watch.*art/gim.test(taskName)) {
  8382. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8383. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  8384. this.undoneTasks.youtube.channelLinks.push(taskLink);
  8385. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  8386. this.undoneTasks.youtube.likeLinks.push(taskLink);
  8387. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  8388. this.undoneTasks.vk.nameLinks.push(taskLink);
  8389. } else if (taskIcon.includes('twitter')) {
  8390. if (/https?:\/\/twitter\.com\/[^/]+\/?$/gim.test(taskLink)) {
  8391. this.undoneTasks.twitter.userLinks.push(taskLink);
  8392. } else if (/https?:\/\/twitter\.com\/[^/]+?\/status\/[\d]+/gim.test(taskLink)) {
  8393. this.undoneTasks.twitter.retweetLinks.push(taskLink);
  8394. }
  8395. } else {
  8396. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  8397. if (/follow.*button/gim.test(taskName)) {
  8398. this.undoneTasks.steam.followLinks.push(taskLink);
  8399. }
  8400. }
  8401. }
  8402. resolve(true);
  8403. }).catch(error => {
  8404. throwError(error, 'GiveeClub.classifyTask->getRedirectLink');
  8405. return false;
  8406. });
  8407. }));
  8408. }
  8409. await Promise.all(pro);
  8410. logStatus.success();
  8411. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8412. this.socialTasks = this.undoneTasks;
  8413. if (window.DEBUG) {
  8414. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8415. }
  8416. GM_setValue(`gcTasks-${this.giveawayId}`, {
  8417. tasks: this.socialTasks,
  8418. time: new Date().getTime()
  8419. });
  8420. return true;
  8421. } catch (error) {
  8422. throwError(error, 'GiveeClub.classifyTask');
  8423. return false;
  8424. }
  8425. }
  8426. async verifyTask() {
  8427. try {
  8428. const logStatus = scripts_echoLog({
  8429. text: i18n('giveeClubVerifyNotice')
  8430. });
  8431. const taskButtons = $('.event-actions tr button').has('i.glyphicon-refresh').not('[data-type="user.adblock"]');
  8432. for (const button of taskButtons) {
  8433. button.click();
  8434. if ($(button).attr('data-type') !== 'steam.game.wishlist') {
  8435. await delay(1e3);
  8436. }
  8437. }
  8438. logStatus.warning(i18n('giveeClubVerifyFinished'));
  8439. return true;
  8440. } catch (error) {
  8441. throwError(error, 'Givekey.verifyTask');
  8442. return false;
  8443. }
  8444. }
  8445. #checkLogin() {
  8446. try {
  8447. if (!globalOptions.other.checkLogin) {
  8448. return true;
  8449. }
  8450. if ($('a[href*="/account/auth"]').length > 0) {
  8451. window.open($('a[href*="/account/auth"]').attr('href'), '_self');
  8452. }
  8453. return true;
  8454. } catch (error) {
  8455. throwError(error, 'GiveeClub.checkLogin');
  8456. return false;
  8457. }
  8458. }
  8459. #getGiveawayId() {
  8460. const giveawayId = window.location.href.match(/\/event\/([\d]+)/)?.[1];
  8461. if (giveawayId) {
  8462. this.giveawayId = giveawayId;
  8463. return true;
  8464. }
  8465. scripts_echoLog({
  8466. text: i18n('getFailed', 'GiveawayId')
  8467. });
  8468. return false;
  8469. }
  8470. async #checkLeftKey() {
  8471. try {
  8472. if (!globalOptions.other.checkLeftKey) {
  8473. return true;
  8474. }
  8475. if ($('.event-ended').length > 0 && $('.event-winner').length === 0) {
  8476. await external_Swal_default().fire({
  8477. icon: 'warning',
  8478. title: i18n('notice'),
  8479. text: i18n('giveawayEnded'),
  8480. confirmButtonText: i18n('confirm'),
  8481. cancelButtonText: i18n('cancel'),
  8482. showCancelButton: true
  8483. }).then(({
  8484. value
  8485. }) => {
  8486. if (value) {
  8487. window.close();
  8488. }
  8489. });
  8490. }
  8491. return true;
  8492. } catch (error) {
  8493. throwError(error, 'Giveawaysu.checkLeftKey');
  8494. return false;
  8495. }
  8496. }
  8497. }
  8498. const website_GiveeClub = GiveeClub;
  8499. const defaultOptions = {
  8500. maxPoint: '99999999'
  8501. };
  8502. class OpiumPulses {
  8503. name = 'OpiumPulses';
  8504. options = {
  8505. ...defaultOptions,
  8506. ...GM_getValue('OpiumPulsesOptions')
  8507. };
  8508. maxPoints = 99999999;
  8509. myPoints = 0;
  8510. buttons = [ 'doFreeTask', 'doPointTask' ];
  8511. static test() {
  8512. return window.location.host === 'www.opiumpulses.com';
  8513. }
  8514. async after() {
  8515. try {
  8516. if (!this.#checkLogin()) {
  8517. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8518. }
  8519. this.maxPoints = parseInt(this.options.maxPoint, 10);
  8520. } catch (error) {
  8521. throwError(error, 'OpiumPulses.after');
  8522. }
  8523. }
  8524. async doFreeTask() {
  8525. try {
  8526. this.#toggleTask('FREE');
  8527. } catch (error) {
  8528. throwError(error, 'OpiumPulses.doFreeTask');
  8529. }
  8530. }
  8531. async doPointTask() {
  8532. try {
  8533. this.myPoints = parseInt($('.page-header__nav-func-user-nav-items.points-items').text().match(/[\d]+/gim)?.[0] || '0', 10);
  8534. this.#toggleTask('points');
  8535. } catch (error) {
  8536. throwError(error, 'OpiumPulses.doPointTask');
  8537. }
  8538. }
  8539. async #toggleTask(type) {
  8540. try {
  8541. const items = $(`.giveaways-page-item:contains('${type}'):not(:contains('ENTERED'))`);
  8542. for (const item of items) {
  8543. const needPoints = parseInt($(item).find('.giveaways-page-item-header-points').text().match(/[\d]+/gim)?.[0] || '999999', 10);
  8544. const name = $(item).find('.giveaways-page-item-footer-name').text().trim();
  8545. if (type === 'points' && needPoints > this.myPoints) {
  8546. scripts_echoLog({}).warning(`${i18n('noPoints')}: ${name}`);
  8547. } else if (type === 'points' && !needPoints) {
  8548. scripts_echoLog({}).warning(`${i18n('getNeedPointsFailed')}: ${name}`);
  8549. } else if (!(type === 'points' && needPoints > this.maxPoints)) {
  8550. const logStatus = scripts_echoLog({
  8551. text: `${i18n('joiningLottery')}<a href="${$(item).find('a.giveaways-page-item-img-btn-more').attr('href')}" target="_blank">${name}</a>...`
  8552. });
  8553. const aElement = $(item).find('a.giveaways-page-item-img-btn-enter:contains(\'enter\')');
  8554. if (aElement?.attr('onclick')?.includes('checkUser')) {
  8555. const giveawayId = aElement.attr('onclick')?.match(/[\d]+/)?.[0];
  8556. if (giveawayId) {
  8557. checkUser(giveawayId);
  8558. }
  8559. }
  8560. if (!aElement.attr('href')) {
  8561. logStatus.error('Error: No "href".');
  8562. continue;
  8563. }
  8564. const {
  8565. result,
  8566. statusText,
  8567. status,
  8568. data
  8569. } = await tools_httpRequest({
  8570. url: aElement.attr('href'),
  8571. method: 'GET'
  8572. });
  8573. if (result === 'Success') {
  8574. const {
  8575. result: result0,
  8576. statusText: statusText0,
  8577. status: status0,
  8578. data: data0
  8579. } = await tools_httpRequest({
  8580. url: data?.finalUrl,
  8581. method: 'GET'
  8582. });
  8583. if (data0?.responseText && /You've entered this giveaway/gim.test(data0.responseText)) {
  8584. logStatus.success();
  8585. const points = data0.responseText.match(/Points:[\s]*?([\d]+)/)?.[1];
  8586. if (type === 'points' && points) {
  8587. this.myPoints = parseInt(points, 10);
  8588. }
  8589. } else if (data0?.responseText && /You're not eligible to enter/gim.test(data0.responseText)) {
  8590. logStatus.error('You\'re not eligible to enter');
  8591. } else {
  8592. logStatus.error(`${result0}:${statusText0}(${status0})`);
  8593. }
  8594. } else {
  8595. logStatus.error(`${result}:${statusText}(${status})`);
  8596. }
  8597. }
  8598. }
  8599. scripts_echoLog({
  8600. text: '-----END-----'
  8601. });
  8602. } catch (error) {
  8603. throwError(error, 'OpiumPulses.toggleTask');
  8604. }
  8605. }
  8606. init() {
  8607. return true;
  8608. }
  8609. classifyTask() {
  8610. return true;
  8611. }
  8612. #checkLogin() {
  8613. try {
  8614. if (!globalOptions.other.checkLogin) {
  8615. return true;
  8616. }
  8617. if ($('a[href*="/site/login"]').length > 1) {
  8618. window.open('/site/login', '_self');
  8619. }
  8620. return true;
  8621. } catch (error) {
  8622. throwError(error, 'OpiumPulses.checkLogin');
  8623. return false;
  8624. }
  8625. }
  8626. }
  8627. const website_OpiumPulses = OpiumPulses;
  8628. const external_dayjs_namespaceObject = dayjs;
  8629. var external_dayjs_default = __webpack_require__.n(external_dayjs_namespaceObject);
  8630. const leftKeyChecker = {
  8631. async classify(link) {
  8632. try {
  8633. if (/^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(link)) {
  8634. return await this.giveawaySu(link);
  8635. }
  8636. if (/^https?:\/\/givee\.club\/[\w]+?\/event\/[\d]+/.test(link)) {
  8637. return await this.giveeClub(link);
  8638. }
  8639. if (/^https?:\/\/gleam\.io\/.+?\/.+/.test(link)) {
  8640. return await this.gleam(link);
  8641. }
  8642. if (/^https?:\/\/www\.indiedb\.com\/giveaways\/.+/.test(link)) {
  8643. return await this.indieDb(link);
  8644. }
  8645. if (/^https?:\/\/key-hub\.eu\/giveaway\/[\d]+/.test(link)) {
  8646. return await this.keyhub(link);
  8647. }
  8648. if (/^https?:\/\/opquests\.com\/quests\/[\d]+/.test(link)) {
  8649. return await this.opquests(link);
  8650. }
  8651. if (/^https?:\/\/itch\.io\/s\/[\d]+?\/.*/.test(link)) {
  8652. return await this.itch(link);
  8653. }
  8654. return false;
  8655. } catch (error) {
  8656. throwError(error, 'leftKeyChecker.classify');
  8657. return false;
  8658. }
  8659. },
  8660. async giveawaySu(link) {
  8661. try {
  8662. const {
  8663. result,
  8664. data
  8665. } = await tools_httpRequest({
  8666. url: link,
  8667. method: 'GET'
  8668. });
  8669. if (result === 'Success' && data?.status === 200) {
  8670. if (data.responseText.includes('class="steam-login"')) {
  8671. return false;
  8672. }
  8673. if (data.responseText.includes('class="giveaway-ended"')) {
  8674. return 'Ended';
  8675. }
  8676. return 'Active';
  8677. }
  8678. return false;
  8679. } catch (error) {
  8680. throwError(error, 'leftKeyChecker.giveawaySu');
  8681. return false;
  8682. }
  8683. },
  8684. async giveeClub(link) {
  8685. try {
  8686. const {
  8687. result,
  8688. data
  8689. } = await tools_httpRequest({
  8690. url: link,
  8691. method: 'GET'
  8692. });
  8693. if (result === 'Success' && data?.status === 200) {
  8694. if (data.responseText.includes('class="event-winner"')) {
  8695. return 'Won';
  8696. }
  8697. if (data.responseText.includes('class="event-ended"')) {
  8698. return 'Ended';
  8699. }
  8700. return 'Active';
  8701. }
  8702. return false;
  8703. } catch (error) {
  8704. throwError(error, 'leftKeyChecker.giveeClub');
  8705. return false;
  8706. }
  8707. },
  8708. async gleam(link) {
  8709. try {
  8710. const {
  8711. result,
  8712. data
  8713. } = await tools_httpRequest({
  8714. url: link,
  8715. method: 'GET'
  8716. });
  8717. if (result === 'Success' && data?.status === 200) {
  8718. if (/incentives&quot;:{&quot;[\d]+?&quot;:\[&quot;.+?&quot;\]/.test(data.responseText)) {
  8719. return 'Won';
  8720. }
  8721. const campaignDiv = data.responseText.match(/<div class='popup-blocks-container'[\w\W]+?'>/)?.[0];
  8722. if (!campaignDiv) {
  8723. return false;
  8724. }
  8725. const campaignString = $(campaignDiv).attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  8726. if (!campaignString) {
  8727. return false;
  8728. }
  8729. const {
  8730. campaign
  8731. } = JSON.parse(campaignString);
  8732. if (campaign.banned) {
  8733. return 'Banned';
  8734. }
  8735. if (campaign.finished) {
  8736. return 'Ended';
  8737. }
  8738. if (campaign.paused) {
  8739. return 'Paused';
  8740. }
  8741. if (new Date().getTime() < campaign.starts_at * 1e3) {
  8742. return 'NotStart';
  8743. }
  8744. return 'Active';
  8745. }
  8746. return false;
  8747. } catch (error) {
  8748. throwError(error, 'leftKeyChecker.gleam');
  8749. return false;
  8750. }
  8751. },
  8752. async indieDb(link) {
  8753. try {
  8754. const {
  8755. result,
  8756. data
  8757. } = await tools_httpRequest({
  8758. url: link,
  8759. method: 'GET'
  8760. });
  8761. if (result === 'Success' && data?.status === 200) {
  8762. if (data.responseText.includes('Congrats you WON')) {
  8763. return 'Won';
  8764. }
  8765. if (data.responseText.includes('Giveaway is closed') || data.responseText.includes('next time')) {
  8766. return 'Ended';
  8767. }
  8768. return 'Active';
  8769. }
  8770. return false;
  8771. } catch (error) {
  8772. throwError(error, 'leftKeyChecker.indieDb');
  8773. return false;
  8774. }
  8775. },
  8776. async keyhub(link) {
  8777. try {
  8778. const {
  8779. result,
  8780. data
  8781. } = await tools_httpRequest({
  8782. url: link,
  8783. method: 'GET'
  8784. });
  8785. if (result === 'Success' && data?.status === 200) {
  8786. const keysleft = data.responseText.match(/<span id="keysleft">([\d]+?)<\/span>/)?.[1];
  8787. if (!keysleft) {
  8788. return false;
  8789. }
  8790. if (keysleft === '0') {
  8791. return 'Ended';
  8792. }
  8793. return `Active(${keysleft})`;
  8794. }
  8795. return false;
  8796. } catch (error) {
  8797. throwError(error, 'leftKeyChecker.keyhub');
  8798. return false;
  8799. }
  8800. },
  8801. async opquests(link) {
  8802. try {
  8803. const {
  8804. result,
  8805. data
  8806. } = await tools_httpRequest({
  8807. url: link,
  8808. method: 'GET'
  8809. });
  8810. if (result === 'Success' && data?.status === 200) {
  8811. const keysleft = data.responseText.match(/<div class="">[\s]*?([\d]+?)[\s]*?of/)?.[1];
  8812. if (!keysleft) {
  8813. return false;
  8814. }
  8815. if (keysleft === '0') {
  8816. return 'Ended';
  8817. }
  8818. return `Active(${keysleft})`;
  8819. } else if (data?.status === 404) {
  8820. return 'Ended';
  8821. }
  8822. return false;
  8823. } catch (error) {
  8824. throwError(error, 'leftKeyChecker.opquests');
  8825. return false;
  8826. }
  8827. },
  8828. async itch(link) {
  8829. try {
  8830. const {
  8831. result,
  8832. data
  8833. } = await tools_httpRequest({
  8834. url: link,
  8835. method: 'GET'
  8836. });
  8837. if (result === 'Success' && data?.status === 200) {
  8838. const endDate = data.responseText.match(/{"start_date":"[0-9A-Z-:]+?".*?"end_date":"([0-9A-Z-:]+?)".*?}/)?.[1];
  8839. if (!endDate) {
  8840. return false;
  8841. }
  8842. if (new Date().getTime() > new Date(endDate).getTime()) {
  8843. return 'Ended';
  8844. }
  8845. return `Active(${external_dayjs_default()(endDate).format('YYYY-MM-DD HH:mm:ss')})`;
  8846. }
  8847. return false;
  8848. } catch (error) {
  8849. throwError(error, 'leftKeyChecker.opquests');
  8850. return false;
  8851. }
  8852. }
  8853. };
  8854. const website_leftKeyChecker = leftKeyChecker;
  8855. const Keylol_defaultTasksTemplate = {
  8856. steam: {
  8857. groupLinks: [],
  8858. wishlistLinks: [],
  8859. curatorLinks: [],
  8860. curatorLikeLinks: [],
  8861. followLinks: [],
  8862. forumLinks: [],
  8863. announcementLinks: [],
  8864. workshopVoteLinks: [],
  8865. licenseLinks: []
  8866. },
  8867. discord: {
  8868. serverLinks: []
  8869. },
  8870. instagram: {
  8871. userLinks: []
  8872. },
  8873. vk: {
  8874. nameLinks: []
  8875. },
  8876. twitch: {
  8877. channelLinks: []
  8878. },
  8879. reddit: {
  8880. redditLinks: []
  8881. },
  8882. twitter: {
  8883. userLinks: [],
  8884. retweetLinks: []
  8885. },
  8886. youtube: {
  8887. channelLinks: [],
  8888. likeLinks: []
  8889. }
  8890. };
  8891. const Keylol_defaultTasks = JSON.stringify(Keylol_defaultTasksTemplate);
  8892. class Keylol extends website_Website {
  8893. name = 'Keylol';
  8894. socialTasks = JSON.parse(Keylol_defaultTasks);
  8895. undoneTasks = JSON.parse(Keylol_defaultTasks);
  8896. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect' ];
  8897. static test() {
  8898. 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'));
  8899. }
  8900. init() {
  8901. return true;
  8902. }
  8903. after() {
  8904. try {
  8905. const selector = this.name === 'Keylol' ? '#postlist>div[id^="post_"]:first' : 'div.container';
  8906. const mainPost = $(selector);
  8907. const discordLinks = mainPost.find('a[href*="discord.com"]:visible');
  8908. const redditLinks = mainPost.find('a[href*="reddit.com"]:visible');
  8909. const insLinks = mainPost.find('a[href*="instagram.com"]:visible');
  8910. const twitterLinks = mainPost.find('a[href*="twitter.com"]:visible,a[href*="x.com"]:visible');
  8911. const twitchLinks = mainPost.find('a[href*="twitch.tv"]:visible');
  8912. const vkLinks = mainPost.find('a[href*="vk.com"]:visible');
  8913. const steamStoreLinks = mainPost.find('a[href*="store.steampowered.com"]:visible');
  8914. const steamCommunityLinks = mainPost.find('a[href*="steamcommunity.com"]:visible');
  8915. const ytbLinks = mainPost.find('a[href*="youtube.com"]:visible');
  8916. if (discordLinks.length > 0) {
  8917. for (const discordLink of discordLinks) {
  8918. const link = $(discordLink).attr('href');
  8919. if (!(link && /^https?:\/\/discord\.com\/invite\/.+/.test(link))) {
  8920. continue;
  8921. }
  8922. this.#addBtn(discordLink, 'discord', 'serverLinks', link);
  8923. }
  8924. }
  8925. if (redditLinks.length > 0) {
  8926. for (const redditLink of redditLinks) {
  8927. const link = $(redditLink).attr('href');
  8928. if (!(link && /^https?:\/\/www\.reddit\.com\/(r|user)\/.+/.test(link))) {
  8929. continue;
  8930. }
  8931. this.#addBtn(redditLink, 'reddit', 'redditLinks', link);
  8932. }
  8933. }
  8934. if (insLinks.length > 0) {
  8935. for (const insLink of insLinks) {
  8936. const link = $(insLink).attr('href');
  8937. if (!(link && /^https:\/\/www\.instagram\.com\/.+/.test(link))) {
  8938. continue;
  8939. }
  8940. this.#addBtn(insLink, 'instagram', 'userLinks', link);
  8941. }
  8942. }
  8943. if (twitterLinks.length > 0) {
  8944. for (const twitterLink of twitterLinks) {
  8945. const link = $(twitterLink).attr('href');
  8946. if (!(link && /^https:\/\/twitter\.com\/.+/.test(link))) {
  8947. continue;
  8948. }
  8949. if (/https:\/\/twitter\.com\/.*?\/status\/[\d]+/.test(link)) {
  8950. this.#addBtn(twitterLink, 'twitter', 'retweetLinks', link);
  8951. } else {
  8952. this.#addBtn(twitterLink, 'twitter', 'userLinks', link);
  8953. }
  8954. }
  8955. }
  8956. if (twitchLinks.length > 0) {
  8957. for (const twitchLink of twitchLinks) {
  8958. const link = $(twitchLink).attr('href');
  8959. if (!(link && /^https:\/\/(www\.)?twitch\.tv\/.+/.test(link))) {
  8960. continue;
  8961. }
  8962. this.#addBtn(twitchLink, 'twitch', 'channelLinks', link);
  8963. }
  8964. }
  8965. if (vkLinks.length > 0) {
  8966. for (const vkLink of vkLinks) {
  8967. const link = $(vkLink).attr('href');
  8968. if (!(link && /^https:\/\/vk\.com\/.+/.test(link))) {
  8969. continue;
  8970. }
  8971. this.#addBtn(vkLink, 'vk', 'nameLinks', link);
  8972. }
  8973. }
  8974. if (steamStoreLinks.length > 0) {
  8975. for (const steamStoreLink of steamStoreLinks) {
  8976. const link = $(steamStoreLink).attr('href');
  8977. if (!link) {
  8978. continue;
  8979. }
  8980. if (/curator\/[\d]+/.test(link)) {
  8981. this.#addBtn(steamStoreLink, 'steam', 'curatorLinks', link);
  8982. } else if (/(publisher|developer|franchise)\/.+/.test(link)) {
  8983. this.#addBtn(steamStoreLink, 'steam', 'curatorLikeLinks', link);
  8984. } else if (/news(hub)?\/app\/[\d]+\/view\/[\d]+/.test(link)) {
  8985. this.#addBtn(steamStoreLink, 'steam', 'announcementLinks', link);
  8986. } else if (/app\/[\d]+/.test(link)) {
  8987. this.#addBtn(steamStoreLink, 'steam', 'followLinks', link);
  8988. this.#addBtn(steamStoreLink, 'steam', 'wishlistLinks', link);
  8989. }
  8990. }
  8991. }
  8992. if (steamCommunityLinks.length > 0) {
  8993. for (const steamCommunityLink of steamCommunityLinks) {
  8994. const link = $(steamCommunityLink).attr('href');
  8995. if (!link) {
  8996. continue;
  8997. }
  8998. if (/groups\/.+/.test(link)) {
  8999. this.#addBtn(steamCommunityLink, 'steam', 'groupLinks', link);
  9000. } else if (/announcements\/detail\/[\d]+/.test(link)) {
  9001. this.#addBtn(steamCommunityLink, 'steam', 'announcementLinks', link);
  9002. }
  9003. }
  9004. }
  9005. if (ytbLinks.length > 0) {
  9006. for (const ytbLink of ytbLinks) {
  9007. const link = $(ytbLink).attr('href');
  9008. if (!link) {
  9009. continue;
  9010. }
  9011. this.#addBtn(ytbLink, 'youtube', 'channelLinks', link);
  9012. this.#addBtn(ytbLink, 'youtube', 'likeLinks', link);
  9013. }
  9014. }
  9015. 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');
  9016. if (giveawayLinks.length > 0) {
  9017. for (const giveawayLink of giveawayLinks) {
  9018. const link = $(giveawayLink).attr('href');
  9019. if (!link) {
  9020. continue;
  9021. }
  9022. website_leftKeyChecker.classify(link).then(status => {
  9023. if (!status) {
  9024. return;
  9025. }
  9026. if (/^Active/.test(status)) {
  9027. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status active" title="${i18n('Active')}">${status}</font>`);
  9028. return;
  9029. }
  9030. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status not-active" title="${i18n(status)}">${status}</font>`);
  9031. }).catch(error => {
  9032. throwError(error, 'keylol.after -> leftKeyChecker');
  9033. });
  9034. }
  9035. }
  9036. if (this.name === 'Keylol') {
  9037. const asfLinks = mainPost.find('a[href^="#asf"]:visible');
  9038. if (asfLinks.length > 0) {
  9039. for (const asfLink of asfLinks) {
  9040. const link = $(asfLink).attr('href');
  9041. if (!link) {
  9042. continue;
  9043. }
  9044. this.#addBtn($(`a[href="${link}"]`).after('<span style="color: #ccc; margin: 0 -5px 0 5px"> | </span>').next()[0], 'steam', 'licenseLinks', `appid-${link.replace('#asf', '')}`);
  9045. }
  9046. }
  9047. const subLinks = mainPost.find('a[href*="steamdb.info/sub/"]:visible');
  9048. if (subLinks.length > 0) {
  9049. for (const subLink of subLinks) {
  9050. const link = $(subLink).attr('href');
  9051. if (!link) {
  9052. continue;
  9053. }
  9054. const subid = link.match(/^https:\/\/steamdb\.info\/sub\/([\d]+)/)?.[1];
  9055. if (!subid) {
  9056. continue;
  9057. }
  9058. this.#addBtn(subLink, 'steam', 'licenseLinks', `subid-${subid}`);
  9059. }
  9060. }
  9061. const asfLinks2 = mainPost.find('.blockcode:contains("addlicense"):visible');
  9062. if (asfLinks2.length > 0) {
  9063. for (const asfLink of asfLinks2) {
  9064. const subid = asfLink.innerText.match(/[\d]+/g);
  9065. if (!subid || subid.length === 0) {
  9066. continue;
  9067. }
  9068. this.#addBtn($(asfLink).children('em')[0], 'steam', 'licenseLinks', `subid-${subid.join(',')}`);
  9069. }
  9070. }
  9071. }
  9072. } catch (error) {
  9073. throwError(error, 'keylol.after');
  9074. }
  9075. }
  9076. classifyTask(action) {
  9077. try {
  9078. this.socialTasks = JSON.parse(Keylol_defaultTasks);
  9079. this.undoneTasks = JSON.parse(Keylol_defaultTasks);
  9080. const selectedBtns = $('.auto-task-keylol[selected="selected"]:visible');
  9081. for (const btn of selectedBtns) {
  9082. const button = $(btn);
  9083. const social = button.attr('data-social');
  9084. const type = button.attr('data-type');
  9085. const link = button.attr('data-link');
  9086. if (!(social && type && link)) {
  9087. continue;
  9088. }
  9089. if (action === 'do') {
  9090. this.undoneTasks[social][type].push(link);
  9091. }
  9092. if (action === 'undo') {
  9093. this.socialTasks[social][type].push(link);
  9094. }
  9095. }
  9096. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9097. this.socialTasks = this.uniqueTasks(this.socialTasks);
  9098. if (window.DEBUG) {
  9099. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9100. }
  9101. return true;
  9102. } catch (error) {
  9103. throwError(error, 'Keylol.classifyTask');
  9104. return false;
  9105. }
  9106. }
  9107. selectAll() {
  9108. try {
  9109. $('.auto-task-keylol:visible').attr('selected', 'selected');
  9110. } catch (error) {
  9111. throwError(error, 'Keylol.selectAll');
  9112. }
  9113. }
  9114. selectNone() {
  9115. try {
  9116. $('.auto-task-keylol:visible').removeAttr('selected');
  9117. } catch (error) {
  9118. throwError(error, 'Keylol.selectNone');
  9119. }
  9120. }
  9121. invertSelect() {
  9122. try {
  9123. $('.auto-task-keylol:visible').each((index, element) => {
  9124. element.getAttribute('selected') ? element.removeAttribute('selected') : element.setAttribute('selected', 'selected');
  9125. });
  9126. } catch (error) {
  9127. throwError(error, 'Keylol.invertSelect');
  9128. }
  9129. }
  9130. #addBtn(before, social, linkType, link) {
  9131. try {
  9132. $(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>`);
  9133. } catch (error) {
  9134. throwError(error, 'keylol.addBtn');
  9135. }
  9136. }
  9137. }
  9138. const website_Keylol = Keylol;
  9139. const Opquests_defaultTasks = {
  9140. steam: {
  9141. groupLinks: [],
  9142. wishlistLinks: [],
  9143. followLinks: [],
  9144. curatorLikeLinks: []
  9145. }
  9146. };
  9147. class Opquests extends website_Website {
  9148. name = 'Opquests';
  9149. undoneTasks = {
  9150. ...Opquests_defaultTasks
  9151. };
  9152. buttons = [ 'doTask', 'verifyTask', 'getKey' ];
  9153. static test() {
  9154. return window.location.host === 'opquests.com';
  9155. }
  9156. async before() {
  9157. const opquestsVerifyTasks = GM_getValue('opquestsVerifyTasks') || [];
  9158. if (opquestsVerifyTasks.length > 0) {
  9159. const taskId = opquestsVerifyTasks.pop();
  9160. GM_setValue('opquestsVerifyTasks', opquestsVerifyTasks);
  9161. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9162. } else {
  9163. if (GM_getValue('opquestsVerifyTasks')) {
  9164. GM_deleteValue('opquestsVerifyTasks');
  9165. }
  9166. }
  9167. }
  9168. async after() {
  9169. try {
  9170. if (!this.#checkLogin()) {
  9171. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9172. }
  9173. } catch (error) {
  9174. throwError(error, 'Opquests.after');
  9175. }
  9176. }
  9177. init() {
  9178. try {
  9179. const logStatus = scripts_echoLog({
  9180. text: i18n('initing')
  9181. });
  9182. if ($('a[href*="/auth/redirect"]').length > 0) {
  9183. window.open('/auth/redirect', '_self');
  9184. logStatus.warning(i18n('needLogin'));
  9185. return false;
  9186. }
  9187. if (!this.#getGiveawayId()) {
  9188. return false;
  9189. }
  9190. this.initialized = true;
  9191. logStatus.success();
  9192. return true;
  9193. } catch (error) {
  9194. throwError(error, 'Opquests.init');
  9195. return false;
  9196. }
  9197. }
  9198. async classifyTask(action) {
  9199. try {
  9200. if (action === 'undo') {
  9201. scripts_echoLog({
  9202. text: i18n('cannotUndo')
  9203. });
  9204. return false;
  9205. }
  9206. const logStatus = scripts_echoLog({
  9207. text: i18n('getTasksInfo')
  9208. });
  9209. const tasks = $('.w-full:contains("Validate") .items-center');
  9210. for (const task of tasks) {
  9211. const link = $(task).find('a:contains("Open")').attr('href');
  9212. const taskDes = $(task).find('div').eq(1).text().trim();
  9213. if (!link) {
  9214. continue;
  9215. }
  9216. if (/steamcommunity\.com\/groups\//.test(link)) {
  9217. this.undoneTasks.steam.groupLinks.push(link);
  9218. } else if (/store\.steampowered\.com\/app\//.test(link)) {
  9219. if (/wishlist/gim.test(taskDes)) {
  9220. this.undoneTasks.steam.wishlistLinks.push(link);
  9221. } else if (/follow/gim.test(taskDes)) {
  9222. this.undoneTasks.steam.followLinks.push(link);
  9223. }
  9224. } else if (/store\.steampowered\.com\/(publisher|developer|curator)\//.test(link) && /follow/gim.test(taskDes)) {
  9225. this.undoneTasks.steam.curatorLikeLinks.push(link);
  9226. } else {
  9227. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  9228. }
  9229. }
  9230. logStatus.success();
  9231. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9232. if (window.DEBUG) {
  9233. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9234. }
  9235. return true;
  9236. } catch (error) {
  9237. throwError(error, 'Opquests.classifyTask');
  9238. return false;
  9239. }
  9240. }
  9241. async verifyTask() {
  9242. try {
  9243. if (!this.initialized) {
  9244. this.init();
  9245. }
  9246. const tasks = $.makeArray($('div.w-full').find('.items-center').has('button.submit-loader')).map(ele => $(ele).find('input[name="task_id"]').val());
  9247. await this.#confirm();
  9248. const taskId = tasks.pop();
  9249. GM_setValue('opquestsVerifyTasks', tasks);
  9250. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9251. return true;
  9252. } catch (error) {
  9253. throwError(error, 'Opquests.verifyTask');
  9254. return false;
  9255. }
  9256. }
  9257. async #confirm() {
  9258. try {
  9259. const logStatus = scripts_echoLog({
  9260. html: `<li>${i18n('confirmingTask')}...<font></font></li>`
  9261. });
  9262. const {
  9263. result,
  9264. statusText,
  9265. status,
  9266. data
  9267. } = await tools_httpRequest({
  9268. url: `https://opquests.com/quests/${this.giveawayId}?confirm=1`,
  9269. method: 'GET',
  9270. nochche: true,
  9271. headers: {
  9272. origin: 'https://opquests.com',
  9273. referer: `https://opquests.com/warning?id=${this.giveawayId}`
  9274. }
  9275. });
  9276. if (result === 'Success') {
  9277. if (data?.status === 200) {
  9278. logStatus.success();
  9279. return true;
  9280. }
  9281. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9282. return false;
  9283. }
  9284. logStatus.error(`${result}:${statusText}(${status})`);
  9285. return false;
  9286. } catch (error) {
  9287. throwError(error, 'Opquests.confirm');
  9288. return false;
  9289. }
  9290. }
  9291. async getKey(isButton) {
  9292. try {
  9293. const logStatus = scripts_echoLog({
  9294. text: i18n('gettingKey')
  9295. });
  9296. const {
  9297. result,
  9298. statusText,
  9299. status,
  9300. data
  9301. } = await tools_httpRequest({
  9302. url: 'https://opquests.com/keys',
  9303. method: 'GET'
  9304. });
  9305. if (result === 'Success') {
  9306. if (data?.responseText) {
  9307. const key = $(data?.responseText).find(`div.items-center:contains("${$('h1.font-bold').text().trim().replace(' Quest', '')}")`).find('div.font-bold').next().text();
  9308. if (!key) {
  9309. logStatus.error('Error: Key was not found');
  9310. if (isButton) {
  9311. window.open('https://opquests.com/keys', '_self');
  9312. }
  9313. return false;
  9314. }
  9315. logStatus.success();
  9316. scripts_echoLog({}).success(key);
  9317. return true;
  9318. }
  9319. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9320. return false;
  9321. }
  9322. logStatus.error(`${result}:${statusText}(${status})`);
  9323. return false;
  9324. } catch (error) {
  9325. throwError(error, 'Opquests.getGiveawayId');
  9326. return false;
  9327. }
  9328. }
  9329. #getGiveawayId() {
  9330. try {
  9331. const giveawayId = window.location.href.match(/quests\/([\d]+)/)?.[1];
  9332. if (giveawayId) {
  9333. this.giveawayId = giveawayId;
  9334. return true;
  9335. }
  9336. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  9337. return false;
  9338. } catch (error) {
  9339. throwError(error, 'Opquests.getGiveawayId');
  9340. return false;
  9341. }
  9342. }
  9343. #checkLogin() {
  9344. try {
  9345. if (!globalOptions.other.checkLogin) {
  9346. return true;
  9347. }
  9348. if ($('a[href*="/auth/redirect"]').length > 0) {
  9349. window.open('/auth/redirect', '_self');
  9350. }
  9351. return true;
  9352. } catch (error) {
  9353. throwError(error, 'Opquests.checkLogin');
  9354. return false;
  9355. }
  9356. }
  9357. }
  9358. const website_Opquests = Opquests;
  9359. const Gleam_defaultTasksTemplate = {
  9360. steam: {
  9361. groupLinks: [],
  9362. wishlistLinks: [],
  9363. followLinks: [],
  9364. curatorLinks: [],
  9365. curatorLikeLinks: []
  9366. },
  9367. twitter: {
  9368. userLinks: [],
  9369. retweetLinks: []
  9370. },
  9371. twitch: {
  9372. channelLinks: []
  9373. },
  9374. discord: {
  9375. serverLinks: []
  9376. },
  9377. youtube: {
  9378. channelLinks: []
  9379. },
  9380. extra: {
  9381. gleam: []
  9382. }
  9383. };
  9384. const Gleam_defaultTasks = JSON.stringify(Gleam_defaultTasksTemplate);
  9385. const Gleam_defaultOptions = {
  9386. vlootUsername: '',
  9387. gameroundUsername: ''
  9388. };
  9389. class Gleam extends website_Website {
  9390. name = 'Gleam';
  9391. undoneTasks = JSON.parse(Gleam_defaultTasks);
  9392. socialTasks = JSON.parse(Gleam_defaultTasks);
  9393. options = {
  9394. ...Gleam_defaultOptions,
  9395. ...GM_getValue('GleamOptions')
  9396. };
  9397. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  9398. static test() {
  9399. return window.location.host === 'gleam.io';
  9400. }
  9401. async after() {
  9402. try {
  9403. if (window.location.search.includes('8b07d23f4bfa65f9')) {
  9404. const checkComplete = setInterval(() => {
  9405. if ($('.entry-content .entry-method i.fa-check').length > 0) {
  9406. clearInterval(checkComplete);
  9407. window.close();
  9408. }
  9409. });
  9410. for (const task of $('.entry-content .entry-method')) {
  9411. const taskInfo = $(task).find('.user-links');
  9412. const expandInfo = $(task).find('.expandable');
  9413. const aElements = expandInfo.find('a.btn,a:contains(Continue),button:contains(Continue)');
  9414. if (aElements.length > 0) {
  9415. for (const element of aElements) {
  9416. const $element = $(element);
  9417. const href = $element.attr('href');
  9418. $element.removeAttr('href')[0].click();
  9419. $element.attr('href', href);
  9420. await delay(1e3);
  9421. }
  9422. }
  9423. taskInfo[0].click();
  9424. await delay(1e3);
  9425. }
  9426. scripts_echoLog({}).warning(i18n('gleamTaskNotice'));
  9427. } else if (!await this.#checkLeftKey()) {
  9428. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  9429. }
  9430. } catch (error) {
  9431. throwError(error, 'Gleam.after');
  9432. return false;
  9433. }
  9434. }
  9435. init() {
  9436. try {
  9437. const logStatus = scripts_echoLog({
  9438. text: i18n('initing')
  9439. });
  9440. if (!this.#getGiveawayId()) {
  9441. return false;
  9442. }
  9443. this.initialized = true;
  9444. logStatus.success();
  9445. return true;
  9446. } catch (error) {
  9447. throwError(error, 'Gleam.init');
  9448. return false;
  9449. }
  9450. }
  9451. async classifyTask(action) {
  9452. try {
  9453. const logStatus = scripts_echoLog({
  9454. text: i18n('getTasksInfo')
  9455. });
  9456. if (action === 'undo') {
  9457. this.socialTasks = GM_getValue(`gleamTasks-${this.giveawayId}`)?.tasks || JSON.parse(Gleam_defaultTasks);
  9458. }
  9459. const tasks = $('.entry-content .entry-method');
  9460. for (const task of tasks) {
  9461. const $task = $(task);
  9462. if (action === 'do' && $task.find('i.fa-question').length === 0) {
  9463. continue;
  9464. }
  9465. const socialIcon = $task.find('.icon-wrapper i');
  9466. const taskInfo = $task.find('.user-links');
  9467. const taskText = taskInfo.text().trim();
  9468. const expandInfo = $task.find('.expandable');
  9469. const aElements = expandInfo.find('a.btn');
  9470. if (aElements.length > 0) {
  9471. for (const element of aElements) {
  9472. const $element = $(element);
  9473. const href = $element.attr('href');
  9474. $element.removeAttr('href')[0].click();
  9475. $element.attr('href', href);
  9476. }
  9477. }
  9478. if (socialIcon.hasClass('fa-twitter')) {
  9479. const link = $task.find('a[href^="https://twitter.com/"],a[href^="https://x.com/"]').attr('href');
  9480. if (!link) {
  9481. continue;
  9482. }
  9483. if (/follow/gi.test(taskText)) {
  9484. if (action === 'undo') {
  9485. this.socialTasks.twitter.userLinks.push(link);
  9486. }
  9487. if (action === 'do') {
  9488. this.undoneTasks.twitter.userLinks.push(link);
  9489. }
  9490. } else if (/retweet/gim.test(taskText)) {
  9491. if (action === 'undo') {
  9492. this.socialTasks.twitter.retweetLinks.push(link);
  9493. }
  9494. if (action === 'do') {
  9495. this.undoneTasks.twitter.retweetLinks.push(link);
  9496. }
  9497. }
  9498. } else if (socialIcon.hasClass('fa-twitch')) {
  9499. if (/follow/gim.test(taskText)) {
  9500. const link = $task.find('a[href^="https://twitch.tv/"]').attr('href');
  9501. if (!link) {
  9502. continue;
  9503. }
  9504. if (action === 'undo') {
  9505. this.socialTasks.twitch.channelLinks.push(link);
  9506. }
  9507. if (action === 'do') {
  9508. this.undoneTasks.twitch.channelLinks.push(link);
  9509. }
  9510. }
  9511. } else if (socialIcon.hasClass('fa-discord')) {
  9512. if (/join/gim.test(taskText)) {
  9513. let link = $task.find('a[href^="https://discord.com/invite/"]').attr('href');
  9514. if (!link) {
  9515. const ggLink = $task.find('a[href^="https://discord.gg/"]').attr('href')?.match(/discord\.gg\/([^/]+)/)?.[1];
  9516. if (!ggLink) {
  9517. continue;
  9518. }
  9519. link = `https://discord.com/invite/${ggLink}`;
  9520. }
  9521. if (action === 'undo') {
  9522. this.socialTasks.discord.serverLinks.push(link);
  9523. }
  9524. if (action === 'do') {
  9525. this.undoneTasks.discord.serverLinks.push(link);
  9526. }
  9527. }
  9528. } else if (socialIcon.hasClass('fa-external-link-square-alt')) {
  9529. continue;
  9530. } else if (socialIcon.hasClass('fa-youtube')) {
  9531. if (/subscribe/gim.test(taskText)) {
  9532. const link = $task.find('a[href^="https://www.youtube.com/channel/"]').attr('href');
  9533. if (!link) {
  9534. continue;
  9535. }
  9536. if (action === 'undo') {
  9537. this.socialTasks.youtube.channelLinks.push(link);
  9538. }
  9539. if (action === 'do') {
  9540. this.undoneTasks.youtube.channelLinks.push(link);
  9541. }
  9542. }
  9543. } else if (socialIcon.attr('class')?.includes('steam')) {
  9544. if (/join.*group/gi.test(taskText)) {
  9545. const link = $task.find('a[href^="https://steamcommunity.com/groups/"]').attr('href');
  9546. if (!link) {
  9547. continue;
  9548. }
  9549. if (action === 'undo') {
  9550. this.socialTasks.steam.groupLinks.push(link);
  9551. }
  9552. if (action === 'do') {
  9553. this.undoneTasks.steam.groupLinks.push(link);
  9554. }
  9555. } else if (/follow.*curator/gi.test(taskText)) {
  9556. const link = $task.find('a[href^="https://store.steampowered.com/curator/"]').attr('href');
  9557. if (!link) {
  9558. continue;
  9559. }
  9560. if (action === 'undo') {
  9561. this.socialTasks.steam.curatorLinks.push(link);
  9562. }
  9563. if (action === 'do') {
  9564. this.undoneTasks.steam.curatorLinks.push(link);
  9565. }
  9566. }
  9567. } else if (socialIcon.hasClass('fa-shield') && taskText.includes('vloot.io') || socialIcon.hasClass('fa-tiktok')) {
  9568. const continueBtn = expandInfo.find('span:contains(Continue),button:contains(Continue)');
  9569. for (const button of continueBtn) {
  9570. button.click();
  9571. await delay(500);
  9572. expandInfo.find('input').val(this.options.vlootUsername);
  9573. }
  9574. } else if (socialIcon.hasClass('fa-gamepad-alt') && taskText.includes('Gameround')) {
  9575. const continueBtn = expandInfo.find('span:contains(Continue),button:contains(Continue)');
  9576. for (const button of continueBtn) {
  9577. button.click();
  9578. await delay(500);
  9579. expandInfo.find('input').val(this.options.gameroundUsername);
  9580. }
  9581. } else if (socialIcon.hasClass('fa-bullhorn') && /Complete/gi.test(taskText)) {
  9582. if (action !== 'do') {
  9583. continue;
  9584. }
  9585. const gleamLink = await this.#getGleamLink(taskText);
  9586. if (!gleamLink) {
  9587. continue;
  9588. }
  9589. this.undoneTasks.extra.gleam.push(gleamLink);
  9590. } else if (socialIcon.hasClass('fa-question') || socialIcon.hasClass('fa-reddit') || socialIcon.hasClass('fa-instagram') || socialIcon.hasClass('fa-facebook-f') || socialIcon.hasClass('fa-telegram-plane') || socialIcon.hasClass('fa-telegram') || socialIcon.hasClass('fa-vk') || socialIcon.hasClass('fa-envelope') || socialIcon.hasClass('fa-gift') || socialIcon.hasClass('fa-square-up-right') || socialIcon.hasClass('fa-gamepad-modern') || socialIcon.hasClass('fa-shield') && taskText.includes('one of our giveaways') || socialIcon.hasClass('fa-shield') && taskText.includes('Check out')) {} else {
  9591. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskText}`);
  9592. }
  9593. }
  9594. logStatus.success();
  9595. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9596. this.socialTasks = this.uniqueTasks(this.socialTasks);
  9597. if (window.DEBUG) {
  9598. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9599. }
  9600. GM_setValue(`gleamTasks-${this.giveawayId}`, {
  9601. tasks: this.socialTasks,
  9602. time: new Date().getTime()
  9603. });
  9604. return true;
  9605. } catch (error) {
  9606. throwError(error, 'Gleam.classifyTask');
  9607. return false;
  9608. }
  9609. }
  9610. async extraDoTask({
  9611. gleam
  9612. }) {
  9613. try {
  9614. const pro = [];
  9615. for (const link of gleam) {
  9616. pro.push(this.#doGleamTask(link));
  9617. }
  9618. return Promise.all(pro).then(() => true);
  9619. } catch (error) {
  9620. throwError(error, 'Gleam.extraDoTask');
  9621. return false;
  9622. }
  9623. }
  9624. async verifyTask() {
  9625. try {
  9626. scripts_echoLog({
  9627. text: `${i18n('verifyingTask')}...`
  9628. });
  9629. const tasks = $('.entry-content .entry-method');
  9630. unsafeWindow._OxA = '_OxA';
  9631. for (const task of tasks) {
  9632. if ($('[campaign-key="campaign.key"]').length > 0) {
  9633. return scripts_echoLog({
  9634. text: i18n('campaign')
  9635. });
  9636. }
  9637. const $task = $(task);
  9638. if ($task.find('i.fa-question').length === 0) {
  9639. continue;
  9640. }
  9641. const taskInfo = $task.find('.user-links');
  9642. taskInfo[0].click();
  9643. unsafeWindow.$hookTimer?.setSpeed(1e3);
  9644. await delay(3e3);
  9645. unsafeWindow.$hookTimer?.setSpeed(1);
  9646. await this.#checkSync();
  9647. const continueBtn = $task.find('.expandable').find('span:contains(Continue),button:contains(Continue)');
  9648. for (const button of continueBtn) {
  9649. button.click();
  9650. await delay(500);
  9651. await this.#checkSync();
  9652. }
  9653. }
  9654. scripts_echoLog({
  9655. text: i18n('verifiedGleamTasks')
  9656. });
  9657. } catch (error) {
  9658. throwError(error, 'Gleam.verifyTask');
  9659. return false;
  9660. }
  9661. }
  9662. async #checkSync() {
  9663. try {
  9664. return await new Promise(resolve => {
  9665. const checker = setInterval(() => {
  9666. if ($('.entry-content .entry-method i.fa-sync').length === 0) {
  9667. clearInterval(checker);
  9668. resolve(true);
  9669. }
  9670. }, 500);
  9671. });
  9672. } catch (error) {
  9673. throwError(error, 'Gleam.checkSync');
  9674. return false;
  9675. }
  9676. }
  9677. async #doGleamTask(link) {
  9678. try {
  9679. const logStatus = scripts_echoLog({
  9680. text: i18n('doingGleamTask')
  9681. });
  9682. return await new Promise(resolve => {
  9683. GM_openInTab(`${link}?8b07d23f4bfa65f9`, {
  9684. active: true,
  9685. insert: true,
  9686. setParent: true
  9687. }).onclose = () => {
  9688. logStatus.success();
  9689. resolve(true);
  9690. };
  9691. });
  9692. } catch (error) {
  9693. throwError(error, 'Gleam.doGleamTask');
  9694. return false;
  9695. }
  9696. }
  9697. #getGiveawayId() {
  9698. try {
  9699. const giveawayId = window.location.pathname;
  9700. if (giveawayId) {
  9701. this.giveawayId = giveawayId;
  9702. return true;
  9703. }
  9704. scripts_echoLog({
  9705. text: i18n('getFailed', 'GiveawayId')
  9706. });
  9707. return false;
  9708. } catch (error) {
  9709. throwError(error, 'Gleam.getGiveawayId');
  9710. return false;
  9711. }
  9712. }
  9713. async #getGleamLink(title) {
  9714. try {
  9715. const logStatus = scripts_echoLog({
  9716. text: i18n('gettingGleamLink')
  9717. });
  9718. const {
  9719. result,
  9720. statusText,
  9721. status,
  9722. data
  9723. } = await tools_httpRequest({
  9724. url: 'https://www.vloot.io/api/v1/giveaways',
  9725. method: 'GET',
  9726. responseType: 'json'
  9727. });
  9728. if (result === 'Success') {
  9729. if (data?.status === 200 && data?.response?.Success === true && data?.response?.Data) {
  9730. const {
  9731. link
  9732. } = data.response.Data.find(giveaway => title.replace(/[\s]/g, '').toLowerCase().includes(giveaway.title.replace(/[\s]/g, '').toLowerCase())) || {};
  9733. if (link) {
  9734. logStatus.success();
  9735. return link;
  9736. }
  9737. logStatus.error(`Error:${i18n('getLinkFailed')}`);
  9738. return false;
  9739. }
  9740. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9741. return false;
  9742. }
  9743. logStatus.error(`${result}:${statusText}(${status})`);
  9744. return false;
  9745. } catch (error) {
  9746. throwError(error, 'Gleam.getGleamLink');
  9747. return false;
  9748. }
  9749. }
  9750. async #checkLeftKey() {
  9751. try {
  9752. if (!globalOptions.other.checkLeftKey) {
  9753. return true;
  9754. }
  9755. const campaignString = $('div.popup-blocks-container').attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  9756. if (!campaignString) {
  9757. return false;
  9758. }
  9759. const {
  9760. campaign,
  9761. incentive
  9762. } = JSON.parse(campaignString);
  9763. const controllerString = $('div.campaign.reward').attr('ng-init')?.match(/initContestant\(([\w\W]+?)\);/)?.[1];
  9764. let ownedKey = false;
  9765. if (controllerString) {
  9766. if (JSON.parse(controllerString).contestant?.claims?.incentives?.[incentive.id]?.length) {
  9767. ownedKey = true;
  9768. }
  9769. }
  9770. if (campaign.banned || campaign.finished && !ownedKey || campaign.paused || new Date().getTime() < campaign.starts_at * 1e3) {
  9771. await external_Swal_default().fire({
  9772. icon: 'warning',
  9773. title: i18n('notice'),
  9774. text: i18n('giveawayNotWork'),
  9775. confirmButtonText: i18n('confirm'),
  9776. cancelButtonText: i18n('cancel'),
  9777. showCancelButton: true
  9778. }).then(({
  9779. value
  9780. }) => {
  9781. if (value) {
  9782. window.close();
  9783. }
  9784. });
  9785. }
  9786. return true;
  9787. } catch (error) {
  9788. throwError(error, 'Gleam.checkLeftKey');
  9789. return false;
  9790. }
  9791. }
  9792. }
  9793. const website_Gleam = Gleam;
  9794. const SweepWidget_defaultOptions = {
  9795. username: '',
  9796. email: ''
  9797. };
  9798. class SweepWidget extends website_Website {
  9799. name = 'SweepWidget';
  9800. options = {
  9801. ...SweepWidget_defaultOptions,
  9802. ...GM_getValue('SweepWidgetOptions')
  9803. };
  9804. buttons = [ 'doTask' ];
  9805. static test() {
  9806. return /^https?:\/\/sweepwidget\.com\/view\/[\d]+/.test(window.location.href);
  9807. }
  9808. async after() {
  9809. try {
  9810. if (!this.#checkLogin()) {
  9811. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9812. }
  9813. } catch (error) {
  9814. throwError(error, 'SweepWidget.after');
  9815. }
  9816. }
  9817. init() {
  9818. try {
  9819. const logStatus = scripts_echoLog({
  9820. text: i18n('initing')
  9821. });
  9822. if (!this.#checkLogin()) {
  9823. logStatus.warning(i18n('needLogin'));
  9824. return false;
  9825. }
  9826. if (!this.#getGiveawayId()) {
  9827. return false;
  9828. }
  9829. this.initialized = true;
  9830. logStatus.success();
  9831. return true;
  9832. } catch (error) {
  9833. throwError(error, 'SweepWidget.init');
  9834. return false;
  9835. }
  9836. }
  9837. classifyTask() {
  9838. return true;
  9839. }
  9840. async doTask() {
  9841. try {
  9842. if ($('#unlock_rewards_main_wrapper').length === 0) {
  9843. if ($('input[name="sw__login_name"]:visible').length > 0) {
  9844. $('input[name="sw__login_name"]').val(this.options.username);
  9845. }
  9846. if ($('input[name="sw__login_email"]:visible').length > 0) {
  9847. $('input[name="sw__login_email"]').val(this.options.email);
  9848. }
  9849. if ($('#sw_login_button:visible').length > 0) {
  9850. $('#sw_login_button')[0].click();
  9851. }
  9852. if (!await this.#checkEnter()) {
  9853. return false;
  9854. }
  9855. }
  9856. const logStatus = scripts_echoLog({
  9857. text: i18n('SweepWidgetNotice')
  9858. });
  9859. const tasks = $('#sw_inner_entry_methods_l2_wrapper>div.sw_entry');
  9860. for (const task of tasks) {
  9861. const $task = $(task);
  9862. if ($task.find('i.fa-check:visible').length > 0) {
  9863. continue;
  9864. }
  9865. const title = $task.find('.sw_text_inner');
  9866. title[0].click();
  9867. const aElement = $task.find('a.sw_link');
  9868. const link = aElement.attr('href');
  9869. aElement.attr('href', '#a').attr('target', '_self');
  9870. aElement[0]?.click();
  9871. await delay(300);
  9872. aElement.attr('href', link).attr('target', '_blank');
  9873. $task.find('input[type="text"]').val('test');
  9874. const verifyBtn = $task.find('input.sw_verify');
  9875. if (verifyBtn.prop('disabled') === true) {
  9876. title[0].click();
  9877. await delay(300);
  9878. title[0].click();
  9879. await delay(300);
  9880. }
  9881. $task.find('input.sw_verify').removeAttr('disabled')[0]?.click();
  9882. await this.#checkFinish($task);
  9883. await delay(parseInt(`${Math.random() * (3e3 - 1e3 + 1) + 1e3}`, 10));
  9884. }
  9885. logStatus.success();
  9886. return true;
  9887. } catch (error) {
  9888. throwError(error, 'SweepWidget.doTask');
  9889. return false;
  9890. }
  9891. }
  9892. #checkLogin() {
  9893. try {
  9894. if ($('#twitter_login_button').length > 0) {
  9895. $('#twitter_login_button')[0].click();
  9896. }
  9897. return true;
  9898. } catch (error) {
  9899. throwError(error, 'SweepWidget.checkLogin');
  9900. return false;
  9901. }
  9902. }
  9903. #getGiveawayId() {
  9904. try {
  9905. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  9906. if (giveawayId) {
  9907. this.giveawayId = giveawayId;
  9908. return true;
  9909. }
  9910. scripts_echoLog({
  9911. text: i18n('getFailed', 'GiveawayId')
  9912. });
  9913. return false;
  9914. } catch (error) {
  9915. throwError(error, 'SweepWidget.getGiveawayId');
  9916. return false;
  9917. }
  9918. }
  9919. async #checkEnter() {
  9920. try {
  9921. return new Promise(resolve => {
  9922. const checker = setInterval(() => {
  9923. if ($('#unlock_rewards_main_wrapper').length > 0) {
  9924. clearInterval(checker);
  9925. resolve(true);
  9926. }
  9927. });
  9928. });
  9929. } catch (error) {
  9930. throwError(error, 'SweepWidget.checkEnter');
  9931. return false;
  9932. }
  9933. }
  9934. async #checkFinish($task) {
  9935. try {
  9936. return new Promise(resolve => {
  9937. const checker = setInterval(() => {
  9938. if ($task.find('i.fa-check:visible').length > 0 || $task.find('.sw_entry_input:visible').length === 0) {
  9939. clearInterval(checker);
  9940. resolve(true);
  9941. }
  9942. });
  9943. });
  9944. } catch (error) {
  9945. throwError(error, 'SweepWidget.checkFinish');
  9946. return false;
  9947. }
  9948. }
  9949. }
  9950. const website_SweepWidget = SweepWidget;
  9951. const defaultWhiteList = {
  9952. discord: {
  9953. servers: []
  9954. },
  9955. instagram: {
  9956. users: []
  9957. },
  9958. twitch: {
  9959. channels: []
  9960. },
  9961. twitter: {
  9962. users: [],
  9963. retweets: [],
  9964. likes: []
  9965. },
  9966. vk: {
  9967. names: []
  9968. },
  9969. youtube: {
  9970. channels: [],
  9971. likes: []
  9972. },
  9973. reddit: {
  9974. reddits: []
  9975. },
  9976. steam: {
  9977. groups: [],
  9978. officialGroups: [],
  9979. wishlists: [],
  9980. follows: [],
  9981. forums: [],
  9982. workshops: [],
  9983. curators: [],
  9984. workshopVotes: [],
  9985. curatorLikes: [],
  9986. announcements: [],
  9987. licenses: [],
  9988. playtests: []
  9989. }
  9990. };
  9991. const link2id = async function(type) {
  9992. try {
  9993. const link = $('#socialLink').val();
  9994. let id = '';
  9995. switch (type) {
  9996. case 'discord.servers':
  9997. id = link.match(/invite\/(.+)/)?.[1] || '';
  9998. break;
  9999.  
  10000. case 'instagram.users':
  10001. id = link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1] || '';
  10002. break;
  10003.  
  10004. case 'twitch.channels':
  10005. id = link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2] || '';
  10006. break;
  10007.  
  10008. case 'twitter.users':
  10009. id = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || '';
  10010. break;
  10011.  
  10012. case 'twitter.retweets':
  10013. id = link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1] || '';
  10014. break;
  10015.  
  10016. case 'vk.names':
  10017. id = link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1] || '';
  10018. break;
  10019.  
  10020. case 'youtube.channels':
  10021. id = (await getInfo(link, 'channel'))?.params?.channelId || '';
  10022. break;
  10023.  
  10024. case 'youtube.likes':
  10025. id = (await getInfo(link, 'likeVideo'))?.params?.videoId || '';
  10026. break;
  10027.  
  10028. case 'reddit.reddits':
  10029. id = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1] || link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1] || '';
  10030. break;
  10031.  
  10032. case 'steam.groups':
  10033. id = link.match(/groups\/(.+)\/?/)?.[1] || '';
  10034. break;
  10035.  
  10036. case 'steam.wishlists':
  10037. case 'steam.follows':
  10038. case 'steam.forums':
  10039. id = link.match(/app\/([\d]+)/)?.[1] || '';
  10040. break;
  10041.  
  10042. case 'steam.workshops':
  10043. id = link.match(/\?id=([\d]+)/)?.[1] || '';
  10044. break;
  10045.  
  10046. case 'steam.curators':
  10047. {
  10048. if (link.includes('curator')) {
  10049. id = link.match(/curator\/([\d]+)/)?.[1] || '';
  10050. } else {
  10051. const param = link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3);
  10052. if (!param || param.length !== 2) {
  10053. break;
  10054. }
  10055. const steam = new social_Steam();
  10056. if (await steam.init()) {
  10057. id = await steam.getCuratorId(param[0], param[1]) || '';
  10058. }
  10059. }
  10060. }
  10061. break;
  10062. }
  10063. return id;
  10064. } catch (error) {
  10065. throwError(error, 'link2id');
  10066. return i18n('getFailed', 'id');
  10067. }
  10068. };
  10069. const disabledType = {
  10070. steam: [ 'workshopVotes', 'curatorLikes', 'announcements' ],
  10071. twitter: [ 'likes' ]
  10072. };
  10073. const assignWhiteList = whiteList => {
  10074. try {
  10075. const newWhiteList = {};
  10076. for (const [ key, value ] of Object.entries(defaultWhiteList)) {
  10077. newWhiteList[key] = {
  10078. ...value,
  10079. ...whiteList[key]
  10080. };
  10081. }
  10082. return newWhiteList;
  10083. } catch (error) {
  10084. throwError(error, 'assignWhiteList');
  10085. return defaultWhiteList;
  10086. }
  10087. };
  10088. const whiteListOptions = function(showType) {
  10089. try {
  10090. const whiteList = assignWhiteList(GM_getValue('whiteList') || {});
  10091. let whiteListOptionsForm = `<form id="whiteListForm" class="auto-task-form">
  10092. <table class="auto-task-table"><thead><tr><td>${i18n('website')}</td><td>${i18n('type')}</td><td>${i18n('edit')}</td></tr></thead><tbody>`;
  10093. for (const [ social, types ] of Object.entries(whiteList)) {
  10094. 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('');
  10095. }
  10096. whiteListOptionsForm += '</tbody></table></form>';
  10097. if (showType === 'swal') {
  10098. external_Swal_default().fire({
  10099. title: i18n('whiteListOptions'),
  10100. html: whiteListOptionsForm,
  10101. showConfirmButton: false,
  10102. showCloseButton: true
  10103. });
  10104. } else {
  10105. $('body').append(`<h2>${i18n('whiteList')}</h2>${whiteListOptionsForm}`);
  10106. }
  10107. $('.editWhiteList').on('click', function() {
  10108. const value = $(this).attr('data-value');
  10109. if (!value) {
  10110. return;
  10111. }
  10112. const [ social, type ] = value.split('.');
  10113. if (!whiteList?.[social]?.[type]) {
  10114. scripts_echoLog({}).warning(i18n('whiteListNotFound', value));
  10115. return;
  10116. }
  10117. external_Swal_default().fire({
  10118. title: i18n('changeWhiteListOption', value),
  10119. input: 'textarea',
  10120. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10121. <button id="link2id" data-type="${value}" class="swal2-confirm swal2-styled">获取id</button>
  10122. <p style="margin-bottom:0 !important;">在下方填写白名单,每行一个</p>`,
  10123. inputValue: whiteList[social][type].join('\n'),
  10124. showConfirmButton: true,
  10125. confirmButtonText: i18n('save'),
  10126. showCancelButton: true,
  10127. cancelButtonText: i18n('close'),
  10128. showDenyButton: true,
  10129. denyButtonText: i18n('return')
  10130. }).then(({
  10131. isDenied,
  10132. isConfirmed,
  10133. value
  10134. }) => {
  10135. if (isDenied) {
  10136. if (showType === 'swal') {
  10137. whiteListOptions(showType);
  10138. }
  10139. return;
  10140. } else if (isConfirmed) {
  10141. whiteList[social][type] = value.split('\n');
  10142. GM_setValue('whiteList', whiteList);
  10143. external_Swal_default().fire({
  10144. title: i18n('changeWhiteListSuccess'),
  10145. icon: 'success'
  10146. });
  10147. }
  10148. });
  10149. $('#link2id').on('click', async function() {
  10150. const type = $(this).attr('data-type');
  10151. $('#socialLink').val(await link2id(type));
  10152. });
  10153. });
  10154. } catch (error) {
  10155. throwError(error, 'whiteListOptions');
  10156. }
  10157. };
  10158. const whiteList = whiteListOptions;
  10159. const setGistData = async (token, gistId, fileName, content) => {
  10160. try {
  10161. const logStatus = scripts_echoLog({
  10162. text: i18n('settingData')
  10163. });
  10164. const contentData = JSON.stringify({
  10165. files: {
  10166. [fileName]: {
  10167. content: JSON.stringify(content)
  10168. }
  10169. }
  10170. });
  10171. const {
  10172. result,
  10173. statusText,
  10174. status,
  10175. data
  10176. } = await tools_httpRequest({
  10177. url: `https://api.github.com/gists/${gistId}`,
  10178. headers: {
  10179. Accept: 'application/vnd.github.v3+json',
  10180. Authorization: `token ${token}`
  10181. },
  10182. data: contentData,
  10183. responseType: 'json',
  10184. method: 'POST',
  10185. timeout: 3e4
  10186. });
  10187. if (result === 'Success') {
  10188. if (data?.status === 200 && data.response.files?.[fileName]?.content === JSON.stringify(content)) {
  10189. logStatus.success();
  10190. return true;
  10191. }
  10192. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10193. return false;
  10194. }
  10195. logStatus.error(`${result}:${statusText}(${status})`);
  10196. return false;
  10197. } catch (error) {
  10198. throwError(error, 'setGistData');
  10199. return false;
  10200. }
  10201. };
  10202. const getGistData = async (token, gistId, fileName, test = false) => {
  10203. try {
  10204. const logStatus = scripts_echoLog({
  10205. text: i18n('gettingData')
  10206. });
  10207. const {
  10208. result,
  10209. statusText,
  10210. status,
  10211. data
  10212. } = await tools_httpRequest({
  10213. url: `https://api.github.com/gists/${gistId}`,
  10214. headers: {
  10215. Accept: 'application/vnd.github.v3+json',
  10216. Authorization: `token ${token}`
  10217. },
  10218. responseType: 'json',
  10219. method: 'GET',
  10220. timeout: 3e4
  10221. });
  10222. if (result === 'Success') {
  10223. if (data?.status === 200) {
  10224. const content = data.response?.files?.[fileName]?.content;
  10225. let formatedContent;
  10226. if (!content) {
  10227. logStatus.error(`Error:${i18n('noRemoteData')}`);
  10228. return false;
  10229. }
  10230. if (test) {
  10231. logStatus.success();
  10232. return true;
  10233. }
  10234. try {
  10235. formatedContent = JSON.parse(content);
  10236. } catch (error) {
  10237. logStatus.error(`Error:${i18n('errorRemoteDataFormat')}`);
  10238. return false;
  10239. }
  10240. logStatus.success();
  10241. return formatedContent;
  10242. }
  10243. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10244. return false;
  10245. }
  10246. logStatus.error(`${result}:${statusText}(${status})`);
  10247. return false;
  10248. } catch (error) {
  10249. throwError(error, 'getGistData');
  10250. return false;
  10251. }
  10252. };
  10253. const syncOptions = () => {
  10254. try {
  10255. const {
  10256. TOKEN,
  10257. GIST_ID,
  10258. FILE_NAME,
  10259. SYNC_HISTORY
  10260. } = GM_getValue('gistOptions') || {
  10261. TOKEN: '',
  10262. GIST_ID: '',
  10263. FILE_NAME: '',
  10264. SYNC_HISTORY: true
  10265. };
  10266. external_Swal_default().fire({
  10267. title: i18n('gistOptions'),
  10268. 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;">
  10269. ${i18n('upload2gist')}</button>` + `<button id="download-data" type="button" class="swal2-confirm swal2-styled" style="display: inline-block;">
  10270. ${i18n('downloadFromGist')}</button></p>`,
  10271. focusConfirm: false,
  10272. showLoaderOnConfirm: true,
  10273. 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>`,
  10274. preConfirm: async () => {
  10275. const token = $('#github-token').val();
  10276. const gistId = $('#gist-id').val();
  10277. const fileName = $('#file-name').val();
  10278. const syncHistory = $('#sync-history').prop('checked');
  10279. GM_setValue('gistOptions', {
  10280. TOKEN: token,
  10281. GIST_ID: gistId,
  10282. FILE_NAME: fileName,
  10283. SYNC_HISTORY: syncHistory
  10284. });
  10285. return await getGistData(token, gistId, fileName, true);
  10286. },
  10287. allowOutsideClick: () => !external_Swal_default().isLoading(),
  10288. confirmButtonText: i18n('saveAndTest'),
  10289. showCancelButton: true,
  10290. cancelButtonText: i18n('close')
  10291. }).then(({
  10292. value
  10293. }) => {
  10294. if (value) {
  10295. external_Swal_default().fire({
  10296. icon: 'success',
  10297. title: i18n('testSuccess')
  10298. }).then(syncOptions);
  10299. } else if (value !== undefined) {
  10300. external_Swal_default().fire({
  10301. icon: 'error',
  10302. title: i18n('testFailed')
  10303. }).then(syncOptions);
  10304. }
  10305. });
  10306. $('#upload-data').on('click', async () => {
  10307. const {
  10308. TOKEN,
  10309. GIST_ID,
  10310. FILE_NAME
  10311. } = GM_getValue('gistOptions') || {};
  10312. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10313. return external_Swal_default().fire({
  10314. icon: 'error',
  10315. title: i18n('saveAndTestNotice')
  10316. }).then(syncOptions);
  10317. }
  10318. external_Swal_default().fire({
  10319. icon: 'info',
  10320. title: i18n('processingData')
  10321. });
  10322. const data = {};
  10323. const names = GM_listValues();
  10324. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10325. for (const name of names) {
  10326. if (name === 'gistOptions' || /^[\w]+?Auth$/.test(name)) {
  10327. continue;
  10328. }
  10329. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10330. continue;
  10331. }
  10332. data[name] = GM_getValue(name);
  10333. }
  10334. external_Swal_default().update({
  10335. icon: 'info',
  10336. title: i18n('updatingData')
  10337. });
  10338. if (await setGistData(TOKEN, GIST_ID, FILE_NAME, data)) {
  10339. external_Swal_default().fire({
  10340. icon: 'success',
  10341. title: i18n('syncDataSuccess')
  10342. });
  10343. } else {
  10344. external_Swal_default().fire({
  10345. icon: 'error',
  10346. title: i18n('syncDataFailed')
  10347. });
  10348. }
  10349. });
  10350. $('#download-data').on('click', async () => {
  10351. const {
  10352. TOKEN,
  10353. GIST_ID,
  10354. FILE_NAME
  10355. } = GM_getValue('gistOptions') || {};
  10356. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10357. return external_Swal_default().fire({
  10358. icon: 'error',
  10359. title: i18n('saveAndTestNotice')
  10360. }).then(syncOptions);
  10361. }
  10362. external_Swal_default().fire({
  10363. icon: 'info',
  10364. title: i18n('downloadingData')
  10365. });
  10366. const data = await getGistData(TOKEN, GIST_ID, FILE_NAME);
  10367. if (!data) {
  10368. return external_Swal_default().fire({
  10369. icon: 'error',
  10370. title: i18n('checkedNoData')
  10371. }).then(syncOptions);
  10372. }
  10373. external_Swal_default().update({
  10374. icon: 'info',
  10375. title: i18n('savingData')
  10376. });
  10377. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10378. for (const [ name, value ] of Object.entries(data)) {
  10379. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10380. continue;
  10381. }
  10382. GM_setValue(name, value);
  10383. }
  10384. external_Swal_default().fire({
  10385. icon: 'success',
  10386. title: i18n('syncDataSuccess')
  10387. });
  10388. });
  10389. } catch (error) {
  10390. throwError(error, 'syncOptions');
  10391. }
  10392. };
  10393. const dataSync = syncOptions;
  10394. class Setting {
  10395. name = 'Setting';
  10396. buttons = [ 'saveGlobalOptions', 'syncData', 'tasksHistory' ];
  10397. syncData = dataSync;
  10398. tasksHistory() {
  10399. window.open('https://auto-task-v4.hclonely.com/history.html', '_blank');
  10400. }
  10401. static test() {
  10402. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/setting.html';
  10403. }
  10404. before() {
  10405. $('body').html('').addClass('auto-task-options');
  10406. }
  10407. after() {
  10408. try {
  10409. this.#environment();
  10410. changeGlobalOptions('page');
  10411. whiteList('page');
  10412. $('input[name="other.twitterVerifyId"]').after(`<button id="getTwitterUserId" type="button">${i18n('getTwitterUserId')}</button>`);
  10413. $('#getTwitterUserId').on('click', () => {
  10414. this.#getId('twitterUser');
  10415. });
  10416. $('input[name="other.youtubeVerifyChannel"]').after(`<button id="getYoutubeChannelId" type="button">${i18n('getYoutubeChannelId')}</button>`);
  10417. $('#getYoutubeChannelId').on('click', () => {
  10418. this.#getId('youtubeChannel');
  10419. });
  10420. $('input[name^="position"]').on('input', function() {
  10421. const type = $(this).attr('name').replace('position.', '');
  10422. const xLabel = 'rightleft';
  10423. const yLabel = 'topbottpm';
  10424. switch (type) {
  10425. case 'buttonSideX':
  10426. case 'buttonSideY':
  10427. case 'buttonDistance':
  10428. {
  10429. const distance = $('input[name="position.buttonDistance"]').val();
  10430. const sideX = $('input[name="position.buttonSideX"]').val();
  10431. const sideY = $('input[name="position.buttonSideY"]').val();
  10432. if (![ 'right', 'left' ].includes(sideX)) {
  10433. break;
  10434. }
  10435. if (![ 'top', 'bottom' ].includes(sideY)) {
  10436. break;
  10437. }
  10438. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10439. break;
  10440. }
  10441. const distanceArr = distance.split(',');
  10442. $('#auto-task-buttons').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10443. break;
  10444. }
  10445.  
  10446. case 'showButtonSideX':
  10447. case 'showButtonSideY':
  10448. case 'showButtonDistance':
  10449. {
  10450. const distance = $('input[name="position.showButtonDistance"]').val();
  10451. const sideX = $('input[name="position.showButtonSideX"]').val();
  10452. const sideY = $('input[name="position.showButtonSideY"]').val();
  10453. if (![ 'right', 'left' ].includes(sideX)) {
  10454. break;
  10455. }
  10456. if (![ 'top', 'bottom' ].includes(sideY)) {
  10457. break;
  10458. }
  10459. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10460. break;
  10461. }
  10462. const distanceArr = distance.split(',');
  10463. $('div.show-button-div').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10464. break;
  10465. }
  10466.  
  10467. case 'logSideX':
  10468. case 'logSideY':
  10469. case 'logDistance':
  10470. {
  10471. const distance = $('input[name="position.logDistance"]').val();
  10472. const sideX = $('input[name="position.logSideX"]').val();
  10473. const sideY = $('input[name="position.logSideY"]').val();
  10474. if (![ 'right', 'left' ].includes(sideX)) {
  10475. break;
  10476. }
  10477. if (![ 'top', 'bottom' ].includes(sideY)) {
  10478. break;
  10479. }
  10480. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10481. break;
  10482. }
  10483. const distanceArr = distance.split(',');
  10484. $('#auto-task-info').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10485. break;
  10486. }
  10487.  
  10488. default:
  10489. break;
  10490. }
  10491. });
  10492. $('input[name^="hotKey"]').attr('readonly', 'readonly').off('keydown').on('keydown', function(event) {
  10493. let functionKey = '';
  10494. if (event.altKey) {
  10495. functionKey += 'alt + ';
  10496. } else if (event.ctrlKey) {
  10497. functionKey += 'ctrl + ';
  10498. } else if (event.shiftKey) {
  10499. functionKey += 'shift + ';
  10500. }
  10501. $(this).val(functionKey + (event.key.length === 1 ? event.key.toLowerCase() : ''));
  10502. });
  10503. } catch (error) {
  10504. throwError(error, 'Setting.after');
  10505. }
  10506. }
  10507. saveGlobalOptions() {
  10508. saveData();
  10509. }
  10510. #getId(social) {
  10511. try {
  10512. external_Swal_default().fire({
  10513. title: i18n('getId', i18n(social)),
  10514. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10515. <button id="link2id" data-type="${social}" class="swal2-confirm swal2-styled">获取id</button>`,
  10516. showCancelButton: true,
  10517. cancelButtonText: i18n('close'),
  10518. showConfirmButton: false
  10519. });
  10520. $('#link2id').on('click', async function() {
  10521. const link = $('#socialLink').val();
  10522. if (!link) {
  10523. return;
  10524. }
  10525. const type = $(this).attr('data-type');
  10526. if (type === 'twitterUser') {
  10527. const name = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || link;
  10528. $('#socialLink').val(await new social_Twitter().userName2id(name) || '');
  10529. } else if (type === 'youtubeChannel') {
  10530. const name = /^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www.youtube.com\/.*/.test(link) ? link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1] : link;
  10531. $('#socialLink').val((await getInfo(name, 'channel'))?.params?.channelId || '');
  10532. }
  10533. });
  10534. } catch (error) {
  10535. throwError(error, 'Setting.getId');
  10536. }
  10537. }
  10538. #environment() {
  10539. try {
  10540. const userAgent = (0, javascript_utils_umd_min.ua)();
  10541. const environmentForm = `<form id="environmentForm" class="auto-task-form">
  10542. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('name')}</td><td>${i18n('version')}</td></tr></thead><tbody>
  10543. <tr><td>${i18n('os')}</td><td>${userAgent.os}</td><td>${userAgent.osVersion}</td></tr>
  10544. <tr><td>${i18n('browser')}</td><td>${userAgent.browserZH}</td><td>${userAgent.browserVersion}</td></tr>
  10545. <tr><td>${i18n('scriptManager')}</td><td>${GM_info.scriptHandler}</td><td>${GM_info.version}</td></tr>
  10546. <tr><td>${i18n('script')}</td><td>${GM_info.script.name}</td><td>${GM_info.script.version}</td></tr>
  10547. </tbody></table></form>`;
  10548. $('body').append(`<h2>${i18n('environment')}</h2>${environmentForm}`);
  10549. } catch (error) {
  10550. throwError(error, 'Setting.environment');
  10551. }
  10552. }
  10553. }
  10554. const website_Setting = Setting;
  10555. class History extends website_Keylol {
  10556. name = 'History';
  10557. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect', 'clearHistory' ];
  10558. static test() {
  10559. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/history.html';
  10560. }
  10561. before() {
  10562. try {
  10563. $('body').html('<div class="container"></div>').addClass('auto-task-history');
  10564. const data = GM_listValues() || [];
  10565. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10566. for (const item of tasksHistory) {
  10567. this.#addItem(item);
  10568. }
  10569. } catch (error) {
  10570. throwError(error, 'History.before');
  10571. }
  10572. }
  10573. clearHistory() {
  10574. try {
  10575. const data = GM_listValues() || [];
  10576. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10577. for (const item of tasksHistory) {
  10578. GM_deleteValue(item);
  10579. }
  10580. external_Swal_default().fire({
  10581. title: i18n('clearHistoryFinished'),
  10582. icon: 'success'
  10583. });
  10584. } catch (error) {
  10585. throwError(error, 'History.after');
  10586. }
  10587. }
  10588. #addItem(item) {
  10589. try {
  10590. const tasksData = GM_getValue(item);
  10591. if (!tasksData?.tasks) {
  10592. return;
  10593. }
  10594. let html = '';
  10595. let title = '';
  10596. let link = '';
  10597. const [ website, id ] = item.split('-');
  10598. switch (website) {
  10599. case 'fawTasks':
  10600. title = `Freeanywhere[${id}]`;
  10601. link = `https://freeanywhere.net/#/giveaway/${id}`;
  10602. break;
  10603.  
  10604. case 'gasTasks':
  10605. title = `Giveawaysu[${id}]`;
  10606. link = `https://giveaway.su/giveaway/view/${id}`;
  10607. break;
  10608.  
  10609. case 'gcTasks':
  10610. title = `GiveeClub[${id}]`;
  10611. link = `https://givee.club/event/${id}`;
  10612. break;
  10613.  
  10614. case 'gkTasks':
  10615. title = `Givekey[${id}]`;
  10616. link = `https://givekey.ru/giveaway/${id}`;
  10617. break;
  10618.  
  10619. case 'gleamTasks':
  10620. title = `Gleam[${id}]`;
  10621. link = `https://gleam.io${id}`;
  10622. break;
  10623.  
  10624. case 'khTasks':
  10625. title = `keyhub[${id}]`;
  10626. link = `https://key-hub.eu/giveaway/${id}`;
  10627. break;
  10628.  
  10629. case 'prysTasks':
  10630. title = `Prys[${id}]`;
  10631. link = `https://prys.revadike.com/giveaway/?id=${id}`;
  10632. break;
  10633.  
  10634. default:
  10635. return;
  10636. }
  10637. for (const [ social, types ] of Object.entries(tasksData.tasks)) {
  10638. for (const [ type, tasks ] of Object.entries(types)) {
  10639. for (const task of tasks) {
  10640. 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>`;
  10641. }
  10642. }
  10643. }
  10644. $('.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>`);
  10645. $('span.delete-task').on('click', function() {
  10646. const itemName = $(this).attr('data-name');
  10647. if (itemName) {
  10648. GM_deleteValue(itemName);
  10649. $(`div.card[data-name="${itemName}"]`).remove();
  10650. external_Swal_default().fire({
  10651. title: i18n('clearTaskFinished'),
  10652. text: itemName,
  10653. icon: 'success'
  10654. });
  10655. } else {
  10656. external_Swal_default().fire({
  10657. title: i18n('clearTaskFailed'),
  10658. icon: 'error'
  10659. });
  10660. }
  10661. });
  10662. } catch (error) {
  10663. throwError(error, 'History.addItem');
  10664. }
  10665. }
  10666. }
  10667. const website_History = History;
  10668. 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 ];
  10669. const websiteOptions = function(website, options) {
  10670. try {
  10671. let websiteOptionsForm = `<form id="websiteOptionsForm" class="auto-task-form">
  10672. <table class="auto-task-table"><thead><tr><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  10673. for (const [ option, value ] of Object.entries(options)) {
  10674. websiteOptionsForm += `<tr><td>${option}</td><td><input class="editOption" type="text" name="${option}" value="${value}"/></td></tr>`;
  10675. }
  10676. websiteOptionsForm += '</tbody></table></form>';
  10677. external_Swal_default().fire({
  10678. title: i18n('websiteOptions'),
  10679. html: websiteOptionsForm,
  10680. showConfirmButton: true,
  10681. confirmButtonText: i18n('save'),
  10682. showCancelButton: true,
  10683. cancelButtonText: i18n('close')
  10684. }).then(({
  10685. isConfirmed
  10686. }) => {
  10687. if (isConfirmed) {
  10688. $('#websiteOptionsForm').serializeArray().map(value => {
  10689. options[value.name] = value.value;
  10690. return value;
  10691. });
  10692. GM_setValue(`${website}Options`, options);
  10693. external_Swal_default().fire({
  10694. title: i18n('changeWebsiteOptionsSuccess'),
  10695. icon: 'success'
  10696. });
  10697. }
  10698. });
  10699. } catch (error) {
  10700. throwError(error, 'websiteOptions');
  10701. }
  10702. };
  10703. const options = websiteOptions;
  10704. const external_keyboardJS_namespaceObject = keyboardJS;
  10705. var external_keyboardJS_default = __webpack_require__.n(external_keyboardJS_namespaceObject);
  10706. const checkUpdate = async (updateLink, auto) => {
  10707. try {
  10708. const checkUrl = `${updateLink}package.json?time=${new Date().getTime()}`;
  10709. const {
  10710. result,
  10711. statusText,
  10712. status,
  10713. data
  10714. } = await tools_httpRequest({
  10715. url: checkUrl,
  10716. responseType: 'json',
  10717. method: 'GET',
  10718. timeout: 3e4
  10719. });
  10720. if (result === 'Success') {
  10721. if (data?.response?.version) {
  10722. return data.response;
  10723. }
  10724. if (!auto) {
  10725. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${data?.statusText}(${data?.status})]`);
  10726. }
  10727. return false;
  10728. }
  10729. if (!auto) {
  10730. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${result}:${statusText}(${status})]`);
  10731. }
  10732. return false;
  10733. } catch (error) {
  10734. throwError(error, 'checkUpdate');
  10735. return false;
  10736. }
  10737. };
  10738. const hasNewVersion = (currentVersion, remoteVersion) => {
  10739. try {
  10740. const [ currentRealVersion ] = currentVersion.split('-');
  10741. const [ remoteRealVersion, isPreview ] = remoteVersion.split('-');
  10742. if (isPreview && !globalOptions.other.receivePreview) {
  10743. return false;
  10744. }
  10745. const [ currentVersion1, currentVersion2, currentVersion3 ] = currentRealVersion.split('.').map(value => parseInt(value, 10));
  10746. const [ remoteVersion1, remoteVersion2, remoteVersion3 ] = remoteRealVersion.split('.').map(value => parseInt(value, 10));
  10747. if (remoteVersion1 > currentVersion1) {
  10748. return true;
  10749. }
  10750. if (remoteVersion1 < currentVersion1) {
  10751. return false;
  10752. }
  10753. if (remoteVersion2 > currentVersion2) {
  10754. return true;
  10755. }
  10756. if (remoteVersion2 < currentVersion2) {
  10757. return false;
  10758. }
  10759. if (remoteVersion3 > currentVersion3) {
  10760. return true;
  10761. }
  10762. return false;
  10763. } catch (error) {
  10764. throwError(error, 'compareVersion');
  10765. return false;
  10766. }
  10767. };
  10768. const updateChecker = async () => {
  10769. try {
  10770. const currentVersion = GM_info.script.version;
  10771. const updateSource = globalOptions.other.autoUpdateSource.toLowerCase();
  10772. const updateLinks = {
  10773. github: 'https://github.com/HCLonely/auto-task-new/raw/main/',
  10774. jsdelivr: 'https://cdn.jsdelivr.net/gh/HCLonely/auto-task-v4@main/',
  10775. standby: 'https://auto-task-v4.hclonely.com/'
  10776. };
  10777. let version;
  10778. let updateLink = '';
  10779. let packageData;
  10780. if ([ 'github', 'jsdelivr', 'standby' ].includes(updateSource)) {
  10781. updateLink = updateLinks[updateSource];
  10782. packageData = await checkUpdate(updateLink, false);
  10783. } else {
  10784. updateLink = updateLinks.github;
  10785. packageData = await checkUpdate(updateLink, true);
  10786. if (!packageData) {
  10787. updateLink = updateLinks.jsdelivr;
  10788. packageData = await checkUpdate(updateLink, true);
  10789. if (!packageData) {
  10790. updateLink = updateLinks.standby;
  10791. packageData = await checkUpdate(updateLink, true);
  10792. }
  10793. }
  10794. }
  10795. if (packageData) {
  10796. version = packageData.version || currentVersion;
  10797. } else {
  10798. version = currentVersion;
  10799. scripts_echoLog({}).error(i18n('checkUpdateFailed'));
  10800. }
  10801. if (packageData && hasNewVersion(currentVersion, version)) {
  10802. scripts_echoLog({
  10803. html: `<li><font>${i18n('newVersionNotice', version, `${updateLink}dist/${GM_info.script.name}.user.js`)}</font></li>`
  10804. });
  10805. scripts_echoLog({
  10806. html: `<li>${i18n('updateText', version)}</li><ol class="update-text">${packageData.change?.map(change => `<li>${change}</li>`).join('')}<li>${i18n('updateHistory')}</li></ol>`
  10807. });
  10808. }
  10809. } catch (error) {
  10810. throwError(error, 'updateChecker');
  10811. }
  10812. };
  10813. const scripts_updateChecker = updateChecker;
  10814. window.STYLE = GM_addStyle(auto_task.Z + GM_getResourceText('style'));
  10815. window.DEBUG = !!globalOptions.other.debug;
  10816. window.TRACE = !!globalOptions.other.debug && typeof console.trace === 'function';
  10817. const loadScript = async () => {
  10818. if (window.location.hostname === 'www.twitch.tv' && window.location.hash === '#auth') {
  10819. const authToken = external_Cookies_namespaceObject.get('auth-token');
  10820. const isLogin = !!external_Cookies_namespaceObject.get('login');
  10821. if (isLogin) {
  10822. GM_setValue('twitchAuth', {
  10823. authToken: authToken,
  10824. clientVersion: __twilightBuildID,
  10825. clientId: commonOptions?.headers?.['Client-ID'],
  10826. deviceId: commonOptions?.headers?.['Device-ID'],
  10827. clientSessionId: window.localStorage.local_storage_app_session_id.replace(/"/g, '')
  10828. });
  10829. window.close();
  10830. external_Swal_default().fire('', i18n('closePageNotice'));
  10831. } else {
  10832. external_Swal_default().fire('', i18n('needLogin'));
  10833. }
  10834. return;
  10835. }
  10836. if (window.location.hostname === 'www.reddit.com' && (window.location.hash === '#auth' || GM_getValue('redditAuth') === '#auth')) {
  10837. const betaButton = $('#redesign-beta-optin-btn');
  10838. if (betaButton.length > 0) {
  10839. GM_setValue('redditAuth', '#auth');
  10840. return betaButton[0].click();
  10841. }
  10842. GM_setValue('redditAuth', null);
  10843. window.close();
  10844. external_Swal_default().fire('', i18n('closePageNotice'));
  10845. return;
  10846. }
  10847. let website;
  10848. for (const Website of Websites) {
  10849. if (Website.test()) {
  10850. website = new Website();
  10851. break;
  10852. }
  10853. }
  10854. if (!website) {
  10855. console.log('%c%s', 'color:#ff0000', 'Auto-Task[Warning]: 脚本停止加载,当前网站不支持!');
  10856. return;
  10857. }
  10858. if (website?.before) {
  10859. await website?.before();
  10860. }
  10861. $('body').append(`<div id="auto-task-info" style="display:${globalOptions.other.defaultShowLog ? 'block' : 'none'};${globalOptions.position.logSideX}:${globalOptions.position.logDistance.split(',')[0]}px;${globalOptions.position.logSideY}:${globalOptions.position.logDistance.split(',')[1]}px;"></div><div id="auto-task-buttons" style="display:${globalOptions.other.defaultShowButton ? 'block' : 'none'};${globalOptions.position.buttonSideX}:${globalOptions.position.buttonDistance.split(',')[0]}px;${globalOptions.position.buttonSideY}:${globalOptions.position.buttonDistance.split(',')[1]}px;"></div><div class="show-button-div" style="display:${globalOptions.other.defaultShowButton ? 'none' : 'block'};${globalOptions.position.showButtonSideX}:${globalOptions.position.showButtonDistance.split(',')[0]}px;${globalOptions.position.showButtonSideY}:${globalOptions.position.showButtonDistance.split(',')[1]}px;"><a class="auto-task-website-btn" href="javascript:void(0);" target="_self" title="${i18n('showButton')}"></a></div>`);
  10862. $('div.show-button-div').on('click', () => {
  10863. $('#auto-task-buttons').show();
  10864. $('div.show-button-div').hide();
  10865. });
  10866. const toggleLog = () => {
  10867. const $this = $('#toggle-log');
  10868. const status = $this.attr('data-status');
  10869. if (status === 'show') {
  10870. $('#auto-task-info').hide();
  10871. $this.attr('data-status', 'hide').text(i18n('showLog'));
  10872. } else {
  10873. $('#auto-task-info').show();
  10874. $this.attr('data-status', 'show').text(i18n('hideLog'));
  10875. }
  10876. };
  10877. external_keyboardJS_default().bind(globalOptions.hotKey.doTaskKey, () => {
  10878. if (website.doTask) {
  10879. website.doTask();
  10880. }
  10881. });
  10882. external_keyboardJS_default().bind(globalOptions.hotKey.undoTaskKey, () => {
  10883. if (website.undoTask) {
  10884. website.doTask();
  10885. }
  10886. });
  10887. external_keyboardJS_default().bind(globalOptions.hotKey.toggleLogKey, toggleLog);
  10888. if (website?.after) {
  10889. await website?.after();
  10890. }
  10891. if (website?.buttons && $('#auto-task-buttons').children().length === 0) {
  10892. $('#auto-task-buttons').addClass(`${website.name}-buttons`);
  10893. for (const button of website.buttons) {
  10894. if (website[button]) {
  10895. const btnElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">${i18n(button)}</a></p>`);
  10896. btnElement.find('a.auto-task-website-btn').on('click', () => {
  10897. website[button]();
  10898. });
  10899. $('#auto-task-buttons').append(btnElement);
  10900. }
  10901. }
  10902. }
  10903. const hideButtonElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">
  10904. ${i18n('hideButton')}</a></p>`);
  10905. hideButtonElement.find('a.auto-task-website-btn').on('click', () => {
  10906. $('#auto-task-buttons').hide();
  10907. $('div.show-button-div').show();
  10908. });
  10909. 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'}">
  10910. ${globalOptions.other.defaultShowLog ? i18n('hideLog') : i18n('showLog')}</a></p>`);
  10911. toggleLogElement.find('a.auto-task-website-btn').on('click', toggleLog);
  10912. $('#auto-task-buttons').append(hideButtonElement).append(toggleLogElement);
  10913. if (website?.options) {
  10914. GM_registerMenuCommand(i18n('changeWebsiteOptions'), () => {
  10915. options(website.name, website.options);
  10916. });
  10917. }
  10918. if (website.name !== 'Setting') {
  10919. GM_registerMenuCommand(i18n('changeGlobalOptions'), () => {
  10920. changeGlobalOptions('swal');
  10921. });
  10922. GM_registerMenuCommand(i18n('settingPage'), () => {
  10923. window.open('https://auto-task-v4.hclonely.com/setting.html', '_blank');
  10924. });
  10925. }
  10926. console.log('%c%s', 'color:#1bbe1a', 'Auto-Task[Load]: 脚本加载完成');
  10927. const [ v1, v2 ] = GM_info.version.split('.');
  10928. if (!(parseInt(v1, 10) >= 5 && parseInt(v2, 10) >= 2)) {
  10929. scripts_echoLog({}).error(i18n('versionNotMatched'));
  10930. }
  10931. if (!GM_getValue('notice')) {
  10932. external_Swal_default().fire({
  10933. title: i18n('swalNotice'),
  10934. icon: 'warning'
  10935. }).then(() => {
  10936. window.open(i18n('noticeLink'), '_blank');
  10937. GM_setValue('notice', new Date().getTime());
  10938. });
  10939. scripts_echoLog({
  10940. html: `<li><font class="warning">${i18n('echoNotice', i18n('noticeLink'))}</font></li>`
  10941. }).font?.find('a').on('click', () => {
  10942. GM_setValue('notice', new Date().getTime());
  10943. });
  10944. }
  10945. scripts_updateChecker();
  10946. };
  10947. if (window.location.hostname === 'discord.com') {
  10948. const LocalStorage = window.localStorage;
  10949. if (window.location.hash === '#auth') {
  10950. window.localStorage.removeItem = () => true;
  10951. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10952. if (discordAuth && discordAuth.length > 0) {
  10953. GM_setValue('discordAuth', {
  10954. auth: discordAuth
  10955. });
  10956. window.close();
  10957. external_Swal_default().fire('', i18n('closePageNotice'));
  10958. } else {
  10959. external_Swal_default().fire({
  10960. text: i18n('getDiscordAuthFailed'),
  10961. icon: 'error'
  10962. });
  10963. }
  10964. } else {
  10965. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10966. if (discordAuth && discordAuth.length > 0) {
  10967. GM_setValue('discordAuth', {
  10968. auth: discordAuth
  10969. });
  10970. }
  10971. }
  10972. } else if (window.location.hostname === 'opquests.com') {
  10973. loadScript();
  10974. } else {
  10975. if (window.location.hostname === 'key-hub.eu') {
  10976. unsafeWindow.keyhubtracker = 1;
  10977. unsafeWindow.gaData = {};
  10978. }
  10979. $(loadScript);
  10980. }
  10981. }();
  10982. })();