Greasy Fork 还支持 简体中文。

auto-task-v4

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

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

  1. // ==UserScript==
  2. // @name auto-task-v4
  3. // @namespace auto-task-v4
  4. // @version 4.3.1
  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 https://auto-task-v4.hclonely.com/setting.html
  32. // @include https://auto-task-v4.hclonely.com/history.html
  33.  
  34. // @grant GM_setValue
  35. // @grant GM_getValue
  36. // @grant GM_listValues
  37. // @grant GM_deleteValue
  38. // @grant GM_addStyle
  39. // @grant GM_xmlhttpRequest
  40. // @grant GM_registerMenuCommand
  41. // @grant GM_info
  42. // @grant GM_openInTab
  43. // @grant GM_setClipboard
  44. // @grant GM_getResourceText
  45. // @grant unsafeWindow
  46. // @grant window.close
  47. // @grant window.localStorage
  48.  
  49. // @connect cdn.jsdelivr.net
  50. // @connect store.steampowered.com
  51. // @connect steamcommunity.com
  52. // @connect login.steampowered.com
  53. // @connect twitter.com
  54. // @connect api.twitter.com
  55. // @connect youtube.com
  56. // @connect www.youtube.com
  57. // @connect facebook.com
  58. // @connect instagram.com
  59. // @connect vk.com
  60. // @connect twitch.tv
  61. // @connect www.twitch.tv
  62. // @connect gql.twitch.tv
  63. // @connect github.com
  64. // @connect discordapp.com
  65. // @connect discord.gg
  66. // @connect discord.com
  67. // @connect www.reddit.com
  68. // @connect oauth.reddit.com
  69. // @connect raw.githubusercontent.com
  70. // @connect t.me
  71. // @connect bit.ly
  72. // @connect giveaway.su
  73. // @connect google.com
  74. // @connect www.vloot.io
  75. // @connect givee.club
  76. // @connect gleam.io
  77. // @connect www.indiedb.com
  78. // @connect key-hub.eu
  79. // @connect opquests.com
  80. // @connect itch.io
  81. // @connect auto-task-v4.hclonely.com
  82. // @connect *
  83. // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js
  84. // @require https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js
  85. // @require https://cdn.jsdelivr.net/npm/regenerator-runtime@0.13.5/runtime.min.js
  86. // @require https://cdn.jsdelivr.net/npm/js-sha1@0.6.0/src/sha1.min.js
  87. // @require https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js
  88. // @resource style https://cdn.jsdelivr.net/npm/sweetalert2@11.3.5/dist/sweetalert2.min.css
  89. // @require https://cdn.jsdelivr.net/npm/keyboardjs@2.6.4/dist/keyboard.min.js
  90. // @require https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js
  91.  
  92. // @noframes
  93. // ==/UserScript==
  94.  
  95. console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
  96.  
  97. (function() {
  98. var __webpack_modules__ = {
  99. 108: function(__unused_webpack_module, exports) {
  100. !function(e, n) {
  101. true ? n(exports) : 0;
  102. }(this, function(e) {
  103. 'use strict';
  104. var t = function() {
  105. return (t = Object.assign || function(e) {
  106. for (var n, o = 1, t = arguments.length; o < t; o++) {
  107. for (var r in n = arguments[o]) {
  108. Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r]);
  109. }
  110. }
  111. return e;
  112. }).apply(this, arguments);
  113. };
  114. function r(e, n, o) {
  115. if (o || 2 === arguments.length) {
  116. for (var t, r = 0, i = n.length; r < i; r++) {
  117. !t && r in n || ((t = t || Array.prototype.slice.call(n, 0, r))[r] = n[r]);
  118. }
  119. }
  120. return e.concat(t || Array.prototype.slice.call(n));
  121. }
  122. function d(e) {
  123. return '[object Object]' === n(e);
  124. }
  125. function l(e, n) {
  126. var o = r(r([], n || [], !0), [ '_' ], !1).join('|');
  127. return e.replace(new RegExp('(('.concat(o, ')[a-z])+'), 'g'), function(e, n) {
  128. return n.replace(new RegExp(o), '').toLocaleUpperCase();
  129. });
  130. }
  131. var n = function(e) {
  132. return Object.prototype.toString.call(e);
  133. };
  134. var o = (i.prototype.init = function() {
  135. try {
  136. this.getSystemName(), this.getBrowserName();
  137. } catch (e) {
  138. console.warn('[UA formatter error] '.concat(e));
  139. }
  140. }, i.prototype.getEngine = function() {
  141. var e = this.agent;
  142. return -1 !== e.indexOf('Trident') ? 'Trident' : -1 !== e.indexOf('Firefox') ? 'Gecko' : -1 !== e.indexOf('Presto') ? 'Presto' : 'WebKit';
  143. }, i.prototype.getSystemName = function() {
  144. var e, n = (this.agent.match(/^[a-z]+\/\d+\.\d+\s?\(([a-z\d\s:;./_-]+)\)/i) || [])[1];
  145. try {
  146. var o = '';
  147. if (/Windows/i.test(n)) {
  148. var t = (n.match(/NT\s(\d+\.\d+)/) || [])[1];
  149. switch (this.info.os = 'Windows', t) {
  150. case '6.3':
  151. o = '8.1';
  152. break;
  153.  
  154. case '6.2':
  155. o = '8';
  156. break;
  157.  
  158. case '6.1':
  159. o = '7';
  160. break;
  161.  
  162. case '5.2':
  163. case '5.1':
  164. o = 'XP';
  165. break;
  166.  
  167. default:
  168. o = t;
  169. }
  170. return this.info.device = 'PC', void (this.info.osVersion = o);
  171. }
  172. if (/^Macintosh/i.test(n)) {
  173. return o = (n.match(/X\s((\d+(_|\.))+\d+)/) || [])[1], this.info.os = 'Macintosh',
  174. this.info.device = 'PC', void (this.info.osVersion = null !== (e = null == o ? void 0 : o.replace(/_/g, '.')) && void 0 !== e ? e : 'Unknown');
  175. }
  176. if (/^iPad/i.test(n)) {
  177. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPad', this.info.device = 'Tablet',
  178. void (this.info.osVersion = o.replace(/_/g, '.'));
  179. }
  180. if (/^iPhone/i.test(n)) {
  181. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPhone', this.info.device = 'Mobile',
  182. void (this.info.osVersion = o.replace(/_/g, '.'));
  183. }
  184. if (-1 !== n.indexOf('Android')) {
  185. var r = (n.match(/Android\s((\d+\.?)+\d?)/) || [])[1];
  186. return this.info.device = 'Mobile', this.info.os = 'Android', void (this.info.osVersion = r);
  187. }
  188. if (/Linux\s[a-z\d_]+/.test(n)) {
  189. return this.info.os = 'Linux', void (this.info.osVersion = 'Unknown');
  190. }
  191. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  192. } catch (e) {
  193. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  194. }
  195. }, i.prototype.getBrowserName = function() {
  196. var e = Object.keys(this.browserNameMap).map(function(e) {
  197. return new RegExp(''.concat(e, '(\\/|\\s)(\\d+\\.)+\\d+'));
  198. }), n = 1 < (n = (this.agent.match(/[a-z\d]+(\/|\s)(\d+\.)+\d+/gi) || []).filter(function(n) {
  199. return -1 !== e.findIndex(function(e) {
  200. return e.test(n);
  201. });
  202. })).length && !/^Safari/.test(n[n.length - 1]) ? n.reverse() : n;
  203. this.info = t(t({}, this.info), this._formatBrowserVersion(n[0]));
  204. }, i.prototype._formatBrowserVersion = function(e) {
  205. var n, o, t, r;
  206. try {
  207. 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++) {
  208. var d = u[f], l = d[0], h = d[1];
  209. if (new RegExp(l).test(s)) {
  210. c = h;
  211. break;
  212. }
  213. }
  214. var p = {
  215. browserVersion: null != a ? a : 'Unknown',
  216. browser: null !== (t = c.en) && void 0 !== t ? t : 'Unknown',
  217. browserZH: null !== (r = (null == c ? void 0 : c.zh) || c.en) && void 0 !== r ? r : 'Unknown'
  218. };
  219. return 'Trident' === s && (p.browserVersion = {
  220. '4.0': 8,
  221. '5.0': 9,
  222. '6.0': 10,
  223. '7.0': 11
  224. }[a]), p;
  225. } catch (e) {
  226. return console.warn('[UA formatter error] '.concat(e)), {
  227. browser: 'Unknown',
  228. browserVersion: 'Unknown'
  229. };
  230. }
  231. }, i);
  232. function i(e) {
  233. this.agent = '', this.info = {
  234. browser: '',
  235. browserZH: '',
  236. browserVersion: '',
  237. os: '',
  238. osVersion: '',
  239. device: 'Unknown',
  240. engine: 'WebKit'
  241. }, this.browserNameMap = {
  242. MicroMessenger: {
  243. en: 'MicroMessenger',
  244. zh: '微信'
  245. },
  246. MetaSr: {
  247. en: 'MetaSr',
  248. zh: '搜狗浏览器'
  249. },
  250. 'QQ(Browser)?': {
  251. en: 'QQBrowser',
  252. zh: 'QQ浏览器'
  253. },
  254. UCBrowser: {
  255. en: 'UCBrowser',
  256. zh: 'UC浏览器'
  257. },
  258. '2345Explorer': {
  259. en: '2345Explorer',
  260. zh: '2345极速浏览器'
  261. },
  262. Mb2345Browser: {
  263. en: 'Mb2345Browser',
  264. zh: '2345手机浏览器'
  265. },
  266. Trident: {
  267. en: 'Internet Explorer'
  268. },
  269. 'Edge?': {
  270. en: 'Edge'
  271. },
  272. OPR: {
  273. en: 'Opera'
  274. },
  275. Vivaldi: {
  276. en: 'Vivaldi'
  277. },
  278. Firefox: {
  279. en: 'Firefox'
  280. },
  281. Chrome: {
  282. en: 'Chrome'
  283. },
  284. Safari: {
  285. en: 'Safari'
  286. }
  287. }, this.agent = e, this.init();
  288. var n = this.info, o = n.browser, e = n.browserVersion, n = n.osVersion;
  289. this.info = t(t({}, this.info), {
  290. engine: this.getEngine(),
  291. browserVersion: 'Safari' === o ? n : e
  292. });
  293. }
  294. function s() {
  295. this.cookies = {}, this.init();
  296. }
  297. var a = new (s.prototype.init = function() {
  298. var o = {};
  299. document.cookie.split(/;\s/).forEach(function(e) {
  300. var n = e.split(/=/), e = n[0], n = n[1];
  301. o[e] = n;
  302. }), this.cookies = o;
  303. }, s.prototype.getItem = function(e) {
  304. return this.cookies[e];
  305. }, s.prototype.getAllItems = function() {
  306. return this.cookies;
  307. }, s.prototype.setItem = function(e, n, o, t, r, i) {
  308. document.cookie = ''.concat(e, '=').concat(n).concat(o ? '; expires='.concat(o) : '').concat(t ? '; path='.concat(t) : '').concat(r ? '; domain='.concat(r) : '').concat(i ? '; secure' : '');
  309. }, s)();
  310. e.countDown = function e(n, o, t, r) {
  311. if (!window) {
  312. throw new Error('window is not defind.');
  313. }
  314. if (0 < n) {
  315. return r && r(), n--, window[o] = window.setTimeout(function() {
  316. e(n, o, t, r);
  317. }, 1e3), function() {
  318. return clearTimeout(window[o]);
  319. };
  320. }
  321. clearTimeout(window[o]), t && t();
  322. }, e.createRandomID = function(e) {
  323. void 0 === e && (e = 12);
  324. for (var n = [], o = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''), t = o.length, r = 0; r < e; r++) {
  325. n.push(o[Math.round(Math.random() * t)]);
  326. }
  327. return n.join('');
  328. }, e.dCookie = a, e.debounce = function(o, t, r) {
  329. var i;
  330. void 0 === t && (t = 0);
  331. var s = r = void 0 === r ? !1 : r;
  332. return function() {
  333. var e = this, n = arguments;
  334. s && (o.apply(this, arguments), s = !1), clearTimeout(i), i = setTimeout(function() {
  335. r ? s = !0 : o.apply(e, n);
  336. }, t);
  337. };
  338. }, e.deepCopy = function e(n) {
  339. if (d(n) || Array.isArray(n)) {
  340. var o, t = Array.isArray(n) ? [] : {};
  341. for (o in n) {
  342. t[o] = e(n[o]);
  343. }
  344. return t;
  345. }
  346. return n;
  347. }, e.formatQueryParams = function(e) {
  348. e = null === (e = /\?(?<params>(.*)=.+)/.exec(decodeURIComponent(e))) || void 0 === e ? void 0 : e.groups;
  349. if (!e) {
  350. return {};
  351. }
  352. for (var n = e.params.split('&'), t = {}, o = 0; o < n.length; o++) {
  353. n[o].replace(/([^?&]*)=([^?&]*)/, function(e, n, o) {
  354. return t[n] = o, e;
  355. });
  356. }
  357. return t;
  358. }, e.formatThousandth = function(e) {
  359. 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, '$&,');
  360. return ''.concat(e).concat(n ? '.'.concat(n) : '');
  361. }, e.generateTree = function e(n, o, t, r) {
  362. for (var i = [], s = 0; s < n.length; s++) {
  363. var a = n[s];
  364. a[t] === o && (i.push(a), a.children = e(n, a[null != r ? r : 'id'], t, r));
  365. }
  366. return i;
  367. }, e.isEmpty = function(e) {
  368. 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);
  369. }, e.isFunction = function(e) {
  370. return '[object Function]' === n(e);
  371. }, e.isImageUrl = function(e) {
  372. return /\.((png)|(jpe?g)|(gif)|(svg)|(webp))$/gi.test(e);
  373. }, e.isObject = d, e.isRegexp = function(e) {
  374. return '[object RegExp]' === n(e);
  375. }, e.objectKeyToCamelCase = function e(n, o, t) {
  376. if (Array.isArray(n)) {
  377. for (var r = [], i = 0; i < n.length; i++) {
  378. r[i] = e(o && n[i][o] ? n[i][o] : n[i], o, t);
  379. }
  380. } else if (d(n)) {
  381. r = {};
  382. for (var s = o && n[o] ? n[o] : n, a = 0, c = Object.entries(s); a < c.length; a++) {
  383. var f = (u = c[a])[0], u = u[1];
  384. Array.isArray(u) || d(s) ? r[l(f, t)] = e(u, o, t) : r[l(f, t)] = u;
  385. }
  386. } else {
  387. r = n;
  388. }
  389. return r;
  390. }, e.realType = n, e.searchParams = function(e, n) {
  391. return void 0 === e && (e = null === location || void 0 === location ? void 0 : location.search),
  392. new URLSearchParams(e).get(n);
  393. }, e.toLowerCamelCase = l, e.toUnderline = function(e) {
  394. return e.replace(/([A-Z])/g, function(e) {
  395. return '_'.concat(e.toLocaleLowerCase());
  396. });
  397. }, e.ua = function(e) {
  398. return void 0 === e && (e = navigator.userAgent), new o(e).info;
  399. }, Object.defineProperty(e, '__esModule', {
  400. value: !0
  401. });
  402. });
  403. },
  404. 221: function(module, __webpack_exports__, __webpack_require__) {
  405. 'use strict';
  406. __webpack_require__.d(__webpack_exports__, {
  407. Z: function() {
  408. return __WEBPACK_DEFAULT_EXPORT__;
  409. }
  410. });
  411. 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);
  412. 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__);
  413. 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);
  414. 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__);
  415. 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());
  416. ___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}', '' ]);
  417. const __WEBPACK_DEFAULT_EXPORT__ = ___CSS_LOADER_EXPORT___.toString();
  418. },
  419. 1: function(module) {
  420. 'use strict';
  421. module.exports = function(cssWithMappingToString) {
  422. var list = [];
  423. list.toString = function toString() {
  424. return this.map(function(item) {
  425. var content = '';
  426. var needLayer = typeof item[5] !== 'undefined';
  427. if (item[4]) {
  428. content += '@supports ('.concat(item[4], ') {');
  429. }
  430. if (item[2]) {
  431. content += '@media '.concat(item[2], ' {');
  432. }
  433. if (needLayer) {
  434. content += '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {');
  435. }
  436. content += cssWithMappingToString(item);
  437. if (needLayer) {
  438. content += '}';
  439. }
  440. if (item[2]) {
  441. content += '}';
  442. }
  443. if (item[4]) {
  444. content += '}';
  445. }
  446. return content;
  447. }).join('');
  448. };
  449. list.i = function i(modules, media, dedupe, supports, layer) {
  450. if (typeof modules === 'string') {
  451. modules = [ [ null, modules, undefined ] ];
  452. }
  453. var alreadyImportedModules = {};
  454. if (dedupe) {
  455. for (var k = 0; k < this.length; k++) {
  456. var id = this[k][0];
  457. if (id != null) {
  458. alreadyImportedModules[id] = true;
  459. }
  460. }
  461. }
  462. for (var _k = 0; _k < modules.length; _k++) {
  463. var item = [].concat(modules[_k]);
  464. if (dedupe && alreadyImportedModules[item[0]]) {
  465. continue;
  466. }
  467. if (typeof layer !== 'undefined') {
  468. if (typeof item[5] === 'undefined') {
  469. item[5] = layer;
  470. } else {
  471. item[1] = '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {').concat(item[1], '}');
  472. item[5] = layer;
  473. }
  474. }
  475. if (media) {
  476. if (!item[2]) {
  477. item[2] = media;
  478. } else {
  479. item[1] = '@media '.concat(item[2], ' {').concat(item[1], '}');
  480. item[2] = media;
  481. }
  482. }
  483. if (supports) {
  484. if (!item[4]) {
  485. item[4] = ''.concat(supports);
  486. } else {
  487. item[1] = '@supports ('.concat(item[4], ') {').concat(item[1], '}');
  488. item[4] = supports;
  489. }
  490. }
  491. list.push(item);
  492. }
  493. };
  494. return list;
  495. };
  496. },
  497. 398: function(module) {
  498. 'use strict';
  499. module.exports = function(i) {
  500. return i[1];
  501. };
  502. }
  503. };
  504. var __webpack_module_cache__ = {};
  505. function __webpack_require__(moduleId) {
  506. var cachedModule = __webpack_module_cache__[moduleId];
  507. if (cachedModule !== undefined) {
  508. return cachedModule.exports;
  509. }
  510. var module = __webpack_module_cache__[moduleId] = {
  511. id: moduleId,
  512. exports: {}
  513. };
  514. __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  515. return module.exports;
  516. }
  517. !function() {
  518. __webpack_require__.n = function(module) {
  519. var getter = module && module.__esModule ? function() {
  520. return module['default'];
  521. } : function() {
  522. return module;
  523. };
  524. __webpack_require__.d(getter, {
  525. a: getter
  526. });
  527. return getter;
  528. };
  529. }();
  530. !function() {
  531. __webpack_require__.d = function(exports, definition) {
  532. for (var key in definition) {
  533. if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  534. Object.defineProperty(exports, key, {
  535. enumerable: true,
  536. get: definition[key]
  537. });
  538. }
  539. }
  540. };
  541. }();
  542. !function() {
  543. __webpack_require__.o = function(obj, prop) {
  544. return Object.prototype.hasOwnProperty.call(obj, prop);
  545. };
  546. }();
  547. var __webpack_exports__ = {};
  548. !function() {
  549. 'use strict';
  550. const external_Swal_namespaceObject = Swal;
  551. var external_Swal_default = __webpack_require__.n(external_Swal_namespaceObject);
  552. const external_Cookies_namespaceObject = Cookies;
  553. var auto_task = __webpack_require__(221);
  554. var javascript_utils_umd_min = __webpack_require__(108);
  555. const httpRequest = async (options, times = 0) => {
  556. if (window.TRACE) {
  557. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  558. }
  559. try {
  560. const result = await new Promise(resolve => {
  561. if (options.dataType) {
  562. options.responseType = options.dataType;
  563. }
  564. const requestObj = {
  565. ...{
  566. timeout: 3e4,
  567. ontimeout(data) {
  568. resolve({
  569. result: 'Error',
  570. statusText: 'Timeout',
  571. status: 601,
  572. data: data,
  573. options: options
  574. });
  575. },
  576. onabort(data) {
  577. resolve({
  578. result: 'Error',
  579. statusText: 'Aborted',
  580. status: 602,
  581. data: data,
  582. options: options
  583. });
  584. },
  585. onerror(data) {
  586. resolve({
  587. result: 'Error',
  588. statusText: 'Error',
  589. status: 603,
  590. data: data,
  591. options: options
  592. });
  593. },
  594. onload(data) {
  595. resolve({
  596. result: 'Success',
  597. statusText: 'Load',
  598. status: 600,
  599. data: data,
  600. options: options
  601. });
  602. }
  603. },
  604. ...options
  605. };
  606. GM_xmlhttpRequest(requestObj);
  607. });
  608. if (window.DEBUG) {
  609. console.log('%cAuto-Task[httpRequest]:', 'color:blue', JSON.stringify(result));
  610. }
  611. if (result.status !== 600 && times < 2) {
  612. return await httpRequest(options, times + 1);
  613. }
  614. return result;
  615. } catch (error) {
  616. console.log('%cAuto-Task[httpRequest]:', 'color:red', JSON.stringify({
  617. errorMsg: error,
  618. options: options
  619. }));
  620. throwError(error, 'httpRequest');
  621. return {
  622. result: 'JsError',
  623. statusText: 'Error',
  624. status: 604,
  625. error: error,
  626. options: options
  627. };
  628. }
  629. };
  630. const tools_httpRequest = httpRequest;
  631. const echoLog = ({
  632. type,
  633. text,
  634. html,
  635. id
  636. }) => {
  637. const emptyStatus = {
  638. success: () => emptyStatus,
  639. error: () => emptyStatus,
  640. warning: () => emptyStatus,
  641. info: () => emptyStatus,
  642. view: () => emptyStatus
  643. };
  644. try {
  645. let ele;
  646. if (type) {
  647. switch (type) {
  648. case 'joiningSteamGroup':
  649. case 'leavingSteamGroup':
  650. case 'gettingSteamGroupId':
  651. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/groups/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  652. break;
  653.  
  654. case 'joiningSteamOfficialGroup':
  655. case 'leavingSteamOfficialGroup':
  656. case 'gettingSteamOfficialGroupId':
  657. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/games/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  658. break;
  659.  
  660. case 'subscribingForum':
  661. case 'unsubscribingForum':
  662. case 'gettingForumId':
  663. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/app/${text}/discussions/" target="_blank">${text}</a>]...<font></font></li>`);
  664. break;
  665.  
  666. case 'followingCurator':
  667. case 'unfollowingCurator':
  668. case 'gettingCuratorId':
  669. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/${text?.includes('/') ? text : `curator/${text}`}" target="_blank">${text}</a>]...<font></font></li>`);
  670. break;
  671.  
  672. case 'addingToWishlist':
  673. case 'removingFromWishlist':
  674. case 'followingGame':
  675. case 'unfollowingGame':
  676. case 'gettingSubid':
  677. case 'addingFreeLicense':
  678. case 'requestingPlayTestAccess':
  679. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/app/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  680. break;
  681.  
  682. case 'addingFreeLicenseSubid':
  683. ele = $(`<li>${i18n('addingFreeLicense')}[<a href="https://steamdb.info/sub/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  684. break;
  685.  
  686. case 'favoritingWorkshop':
  687. case 'unfavoritingWorkshop':
  688. case 'gettingWorkshopAppId':
  689. case 'votingUpWorkshop':
  690. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/sharedfiles/filedetails/?id=${text}" target="_blank">
  691. ${text}</a>]...<font></font></li>`);
  692. break;
  693.  
  694. case 'gettingAnnouncementParams':
  695. case 'likingAnnouncement':
  696. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/news/app/${text}/view/${id}" target="_blank">
  697. ${id}</a>]...<font></font></li>`);
  698. break;
  699.  
  700. case 'joiningDiscordServer':
  701. case 'gettingDiscordGuild':
  702. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/invite/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  703. break;
  704.  
  705. case 'leavingDiscordServer':
  706. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/channels/@me/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  707. break;
  708.  
  709. case 'updateDiscordAuth':
  710. ele = $(`<li style="color:red;">${i18n('updateDiscordAuth')}</li>`);
  711. break;
  712.  
  713. case 'followingTwitchChannel':
  714. case 'unfollowingTwitchChannel':
  715. case 'gettingTwitchChannelId':
  716. ele = $(`<li>${i18n(type)}[<a href="https://www.twitch.tv/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  717. break;
  718.  
  719. case 'gettingInsUserId':
  720. case 'followingIns':
  721. case 'unfollowingIns':
  722. ele = $(`<li>${i18n(type)}[<a href="https://www.instagram.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  723. break;
  724.  
  725. case 'gettingTwitterUserId':
  726. case 'followingTwitterUser':
  727. case 'unfollowingTwitterUser':
  728. ele = $(`<li>${i18n(type)}[<a href="https://twitter.com/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  729. break;
  730.  
  731. case 'retweetting':
  732. case 'unretweetting':
  733. ele = $(`<li>${i18n(type)}${text}...<font></font></li>`);
  734. break;
  735.  
  736. case 'joiningReddit':
  737. case 'leavingReddit':
  738. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/r/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  739. break;
  740.  
  741. case 'followingRedditUser':
  742. case 'unfollowingRedditUser':
  743. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/user/${text?.replace('u_', '')}" target="_blank">
  744. ${text?.replace('u_', '')}</a>]...<font></font></li>`);
  745. break;
  746.  
  747. case 'followingYtbChannel':
  748. case 'unfollowingYtbChannel':
  749. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/channel/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  750. break;
  751.  
  752. case 'likingYtbVideo':
  753. case 'unlikingYtbVideo':
  754. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/watch?v=${text}" target="_blank">${text}</a>]...<font></font></li>`);
  755. break;
  756.  
  757. case 'gettingVkId':
  758. case 'joiningVkGroup':
  759. case 'leavingVkGroup':
  760. case 'joiningVkPublic':
  761. case 'leavingVkPublic':
  762. case 'sendingVkWall':
  763. case 'deletingVkWall':
  764. ele = $(`<li>${i18n(type)}[<a href="https://vk.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  765. break;
  766.  
  767. case 'visitingLink':
  768. ele = $(`<li>${i18n('visitingLink')}[<a href="${text}" target="_blank">${text}</a>]...<font></font></li>`);
  769. break;
  770.  
  771. case 'verifyingInsAuth':
  772. case 'text':
  773. ele = $(`<li>${i18n(text)}<font></font></li>`);
  774. break;
  775.  
  776. case 'html':
  777. ele = $(text || html);
  778. break;
  779.  
  780. case 'whiteList':
  781. ele = $(`<li><font class="warning">${i18n('skipTask')}[${text}(${id})](${i18n('whiteList')})</font></li>`);
  782. break;
  783.  
  784. case 'globalOptionsSkip':
  785. ele = $(`<li>${i18n('skipTaskOption')}<font class="warning">${text}</font></li>`);
  786. break;
  787.  
  788. default:
  789. ele = $(`<li>${i18n('unKnown')}:${type}(${text})...<font></font></li>`);
  790. break;
  791. }
  792. } else if (text) {
  793. ele = $(`<li>${i18n(text)}<font></font></li>`);
  794. } else if (html) {
  795. ele = $(html);
  796. } else {
  797. ele = $('<li><font></font></li>');
  798. }
  799. ele.addClass('card-text');
  800. $('#auto-task-info').append(ele);
  801. ele[0]?.scrollIntoView();
  802. const font = ele.find('font');
  803. const status = {
  804. font: font,
  805. success(text = 'Success', html = false) {
  806. this.font?.attr('class', '').addClass('success');
  807. html ? this.font?.html(text) : this.font?.text(text);
  808. return this;
  809. },
  810. error(text = 'Error', html = false) {
  811. this.font?.attr('class', '').addClass('error');
  812. html ? this.font?.html(text) : this.font?.text(text);
  813. return this;
  814. },
  815. warning(text = 'Warning', html = false) {
  816. this.font?.attr('class', '').addClass('warning');
  817. html ? this.font?.html(text) : this.font?.text(text);
  818. return this;
  819. },
  820. info(text = 'Info', html = false) {
  821. this.font?.attr('class', '').addClass('info');
  822. html ? this.font?.html(text) : this.font?.text(text);
  823. return this;
  824. },
  825. view() {
  826. this.font?.[0].scrollIntoView();
  827. return this;
  828. }
  829. };
  830. return status;
  831. } catch (error) {
  832. throwError(error, 'echoLog');
  833. return emptyStatus;
  834. }
  835. };
  836. const scripts_echoLog = echoLog;
  837. const unique = array => {
  838. try {
  839. return [ ...new Set(array) ];
  840. } catch (error) {
  841. throwError(error, 'unique');
  842. return [];
  843. }
  844. };
  845. const delay = (time = 1e3) => new Promise(resolve => {
  846. setTimeout(() => {
  847. resolve(true);
  848. }, time);
  849. });
  850. const getRedirectLink = async link => {
  851. try {
  852. if (!link) {
  853. return null;
  854. }
  855. const redirectLinksCache = GM_getValue('redirectLinks') || {};
  856. if (redirectLinksCache[link]) {
  857. redirectLinksCache[link];
  858. }
  859. return await tools_httpRequest({
  860. url: link,
  861. method: 'GET'
  862. }).then(({
  863. data
  864. }) => {
  865. if (data?.finalUrl) {
  866. redirectLinksCache[link] = data.finalUrl;
  867. GM_setValue('redirectLinks', redirectLinksCache);
  868. return data.finalUrl;
  869. }
  870. return null;
  871. });
  872. } catch (error) {
  873. throwError(error, 'getRedirectLink');
  874. return null;
  875. }
  876. };
  877. const visitLink = async (link, options) => {
  878. try {
  879. const logStatus = scripts_echoLog({
  880. type: 'visitLink',
  881. text: link
  882. });
  883. return await tools_httpRequest({
  884. url: link,
  885. method: 'GET',
  886. ...options
  887. }).then(({
  888. result,
  889. statusText,
  890. status
  891. }) => {
  892. if (result === 'Success') {
  893. logStatus.success();
  894. return true;
  895. }
  896. logStatus.error(`${result}:${statusText}(${status})`);
  897. return false;
  898. });
  899. } catch (error) {
  900. throwError(error, 'visitLink');
  901. return false;
  902. }
  903. };
  904. const getUrlQuery = url => {
  905. try {
  906. const query = {};
  907. if (url) {
  908. if (url.includes('?')) {
  909. url.split('?')[1].replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  910. query[key] = value;
  911. return str;
  912. });
  913. }
  914. } else {
  915. window.location.search.replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  916. query[key] = value;
  917. return str;
  918. });
  919. }
  920. return query;
  921. } catch (error) {
  922. throwError(error, 'getUrlQuery');
  923. return {};
  924. }
  925. };
  926. const getUuid = () => {
  927. const uuidUrl = URL.createObjectURL(new Blob()).toString();
  928. return uuidUrl.slice(uuidUrl.lastIndexOf('/') + 1);
  929. };
  930. const stringToColour = str => {
  931. try {
  932. let hash = 0;
  933. for (let i = 0; i < str.length; i++) {
  934. hash = str.charCodeAt(i) + ((hash << 5) - hash);
  935. }
  936. let colour = '#';
  937. for (let i = 0; i < 3; i++) {
  938. const value = hash >> i * 8 & 255;
  939. colour += `00${value.toString(16)}`.slice(-2);
  940. }
  941. return colour;
  942. } catch (error) {
  943. throwError(error, 'stringToColour');
  944. return '#fff';
  945. }
  946. };
  947. const defaultGlobalOptions = {
  948. doTask: {
  949. discord: {
  950. servers: true
  951. },
  952. instagram: {
  953. users: true
  954. },
  955. twitch: {
  956. channels: true
  957. },
  958. twitter: {
  959. users: true,
  960. retweets: true
  961. },
  962. vk: {
  963. names: true
  964. },
  965. youtube: {
  966. channels: true,
  967. likes: true
  968. },
  969. reddit: {
  970. reddits: true
  971. },
  972. steam: {
  973. groups: true,
  974. officialGroups: true,
  975. wishlists: true,
  976. follows: true,
  977. forums: true,
  978. workshops: true,
  979. curators: true,
  980. workshopVotes: true,
  981. announcements: true,
  982. licenses: true,
  983. playtests: true
  984. }
  985. },
  986. undoTask: {
  987. discord: {
  988. servers: true
  989. },
  990. instagram: {
  991. users: true
  992. },
  993. twitch: {
  994. channels: true
  995. },
  996. twitter: {
  997. users: true,
  998. retweets: true
  999. },
  1000. vk: {
  1001. names: true
  1002. },
  1003. youtube: {
  1004. channels: true,
  1005. likes: true
  1006. },
  1007. reddit: {
  1008. reddits: true
  1009. },
  1010. steam: {
  1011. groups: true,
  1012. officialGroups: true,
  1013. wishlists: true,
  1014. follows: true,
  1015. forums: true,
  1016. workshops: true,
  1017. curators: true
  1018. }
  1019. },
  1020. ASF: {
  1021. AsfEnabled: false,
  1022. AsfIpcUrl: '',
  1023. AsfIpcPassword: '',
  1024. AsfBotname: 'asf'
  1025. },
  1026. position: {
  1027. buttonSideX: 'right',
  1028. buttonSideY: 'top',
  1029. buttonDistance: '15,30',
  1030. showButtonSideX: 'right',
  1031. showButtonSideY: 'top',
  1032. showButtonDistance: '15,30',
  1033. logSideX: 'right',
  1034. logSideY: 'bottom',
  1035. logDistance: '10,10'
  1036. },
  1037. hotKey: {
  1038. doTaskKey: 'alt + d',
  1039. undoTaskKey: 'alt + u',
  1040. toggleLogKey: 'alt + l'
  1041. },
  1042. other: {
  1043. twitterVerifyId: '783214',
  1044. youtubeVerifyChannel: 'UCrXUsMBcfTVqwAS7DKg9C0Q',
  1045. autoUpdateSource: 'jsdelivr',
  1046. language: 'zh',
  1047. checkLogin: true,
  1048. checkLeftKey: true,
  1049. defaultShowButton: true,
  1050. defaultShowLog: true,
  1051. debug: false,
  1052. receivePreview: true
  1053. }
  1054. };
  1055. const userDefinedGlobalOptions = GM_getValue('globalOptions') || {};
  1056. const assignObject = (obj1, obj2) => {
  1057. try {
  1058. const newObj = {};
  1059. for (const [ key, value ] of Object.entries(obj1)) {
  1060. if (Object.prototype.toString.call(value) === '[object Object]' && Object.prototype.toString.call(obj2[key]) === '[object Object]') {
  1061. newObj[key] = assignObject(value, obj2[key]);
  1062. } else {
  1063. newObj[key] = obj2[key] ?? value;
  1064. }
  1065. }
  1066. return newObj;
  1067. } catch (error) {
  1068. throwError(error, 'assignObject');
  1069. return defaultGlobalOptions;
  1070. }
  1071. };
  1072. const globalOptions = assignObject(defaultGlobalOptions, userDefinedGlobalOptions);
  1073. const saveData = () => {
  1074. try {
  1075. const data = {};
  1076. $('#globalOptionsForm').serializeArray().map(value => {
  1077. data[value.name] = value.value;
  1078. return value;
  1079. });
  1080. $.makeArray($('#globalOptionsForm input')).map(element => {
  1081. const name = $(element).attr('name');
  1082. const keys = name.split('.');
  1083. if (keys.length === 3) {
  1084. globalOptions[keys[0]][keys[1]][keys[2]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1085. } else if (keys.length === 2) {
  1086. globalOptions[keys[0]][keys[1]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1087. }
  1088. return element;
  1089. });
  1090. GM_setValue('globalOptions', globalOptions);
  1091. external_Swal_default().fire({
  1092. title: i18n('changeGlobalOptionsSuccess'),
  1093. icon: 'success'
  1094. });
  1095. } catch (error) {
  1096. throwError(error, 'saveData');
  1097. }
  1098. };
  1099. const changeGlobalOptions = showType => {
  1100. try {
  1101. let globalOptionsForm = `<form id="globalOptionsForm" class="auto-task-form">
  1102. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  1103. for (const [ type, data1 ] of Object.entries(globalOptions)) {
  1104. for (const [ option, data2 ] of Object.entries(data1)) {
  1105. if ([ 'other', 'position', 'hotKey', 'ASF' ].includes(type)) {
  1106. if (typeof data2 === 'boolean') {
  1107. 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>`;
  1108. } else {
  1109. 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>`;
  1110. }
  1111. } else {
  1112. for (const [ socialType, data3 ] of Object.entries(data2)) {
  1113. 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>`;
  1114. }
  1115. }
  1116. }
  1117. }
  1118. globalOptionsForm += '</tbody></table></form>';
  1119. if (showType === 'swal') {
  1120. external_Swal_default().fire({
  1121. title: i18n('globalOptions'),
  1122. html: globalOptionsForm,
  1123. showConfirmButton: true,
  1124. confirmButtonText: i18n('save'),
  1125. showCancelButton: true,
  1126. cancelButtonText: i18n('close')
  1127. }).then(({
  1128. isConfirmed
  1129. }) => {
  1130. if (isConfirmed) {
  1131. saveData();
  1132. }
  1133. });
  1134. } else {
  1135. $('body').append(`<h2>${i18n('globalOptions')}</h2>${globalOptionsForm}`);
  1136. }
  1137. } catch (error) {
  1138. throwError(error, 'changeGlobalOptions');
  1139. }
  1140. };
  1141. const data = {
  1142. website: '网站',
  1143. type: '类型',
  1144. edit: '编辑',
  1145. whiteList: '白名单',
  1146. skipTask: '跳过撤销任务',
  1147. whiteListOptions: '白名单设置',
  1148. changeWhiteListOption: '设置白名单(%0)',
  1149. whiteListNotFound: '找不到此项白名单: %0',
  1150. changeWhiteListSuccess: '白名单修改成功,刷新生效!',
  1151. changeWebsiteOptions: '网站设置',
  1152. changeGlobalOptions: '全局设置',
  1153. ok: '是',
  1154. save: '保存',
  1155. close: '关闭',
  1156. return: '返回',
  1157. option: '选项',
  1158. value: '值',
  1159. websiteOptions: '当前网站设置',
  1160. changeWebsiteOptionsSuccess: '更改当前网站设置成功,刷新生效!',
  1161. changeGlobalOptionsSuccess: '更改全局设置成功,刷新生效!',
  1162. needLogin: '请先登录!',
  1163. getTasksInfo: '正在获取并处理任务信息...',
  1164. gettingKey: '正在获取Key...',
  1165. verifyingTask: '正在验证任务',
  1166. notice: '自动任务脚本提醒',
  1167. noKeysLeft: '此页面已经没有剩余key了,是否关闭?',
  1168. giveawayEnded: '此活动已结束,是否关闭?',
  1169. giveawayNotWork: '此活动因某些原因(已结束/暂停/未开始...)不可用(如果是脚本误判请及时反馈),是否关闭?',
  1170. confirm: '确定',
  1171. cancel: '取消',
  1172. unKnown: '未知',
  1173. unKnownTaskType: '未识别的任务',
  1174. doing: '正在做任务',
  1175. allTasksComplete: '所有任务已完成!',
  1176. getTaskIdFailed: '获取任务Id失败!',
  1177. initSuccess: '%0 初始化成功!',
  1178. initFailed: '%0 初始化失败!',
  1179. errorLink: '链接错误: %0',
  1180. needInit: '请先初始化',
  1181. verifyingAuth: '正在验证%0凭证...',
  1182. updatingAuth: '正在更新%0凭证...',
  1183. refreshingToken: '正在刷新%0凭证...',
  1184. settingToken: '正在设置%0凭证...',
  1185. initing: '正在初始化...',
  1186. getFailed: '获取%0失败!',
  1187. checkLoginFailed: '检测登录状态失败!',
  1188. checkLeftKeyFailed: '检测剩余Key失败!',
  1189. userId: '用户Id',
  1190. joiningGiveaway: '正在加入赠Key',
  1191. needJoinGiveaway: '需要先加入赠Key',
  1192. cannotUndo: '此网站不支持取消任务',
  1193. verifyAuth: '正在验证 %0 凭证...',
  1194. closePageNotice: '如果此页面没有自动关闭,请自行关闭本页面。',
  1195. errorReport: '检测到脚本报错,是否前往反馈BUG?',
  1196. visitingLink: '正在访问链接: ',
  1197. doTask: '做任务',
  1198. undoTask: '撤销任务',
  1199. verifyTask: '验证任务',
  1200. getKey: '获取Key',
  1201. selectAll: '全选',
  1202. selectNone: '全不选',
  1203. invertSelect: '反选',
  1204. doFreeTask: '加入免费赠品',
  1205. doPointTask: '加入点数赠品',
  1206. skipTaskOption: '设置中已配置跳过任务',
  1207. other: '其他',
  1208. globalOptions: '全局设置',
  1209. checkLogin: '登录检测</br>需要登录的网站自动登录,部分本网站支持',
  1210. checkLeftKey: '剩余Key检测</br>赠Key活动结束提示是否关闭,部分本网站支持',
  1211. twitterVerifyId: '通过尝试关注该账号验证Twitter凭证</br>默认为Twitter官方帐号 783214</br>不想关注官方账号可以改为自己的帐号',
  1212. youtubeVerifyChannel: '通过尝试订阅该频道验证YouTube凭证</br>默认为YouTube官方频道 UCrXUsMBcfTVqwAS7DKg9C0Q</br>不想关注官方频道可以改为自己的频道',
  1213. autoUpdateSource: '更新源</br>github: 需代理,实时更新</br>jsdelivr: 可不用代理,更新有延迟</br>standby: 备用</br>auto: 依次使用github, jsdelivr, standby源进行尝试更新',
  1214. saveGlobalOptions: '保存全局设置',
  1215. settingPage: '设置页面',
  1216. name: '名称',
  1217. version: '版本',
  1218. scriptManager: '脚本管理器',
  1219. script: '脚本',
  1220. environment: '环境',
  1221. os: '系统',
  1222. browser: '浏览器',
  1223. getId: '获取 %0 id',
  1224. getTwitterUserId: '获取Twitter用户id(获取id功能仅在设置页面可用)',
  1225. getYoutubeChannelId: '获取Youtube频道id(获取id功能仅在设置页面可用)',
  1226. showButton: '显示按钮',
  1227. hideButton: '隐藏按钮',
  1228. showLog: '显示日志',
  1229. hideLog: '隐藏日志',
  1230. defaultShowButton: '默认显示按钮',
  1231. defaultShowLog: '默认显示日志',
  1232. debug: '输出调试日志,不要开启此选项!',
  1233. receivePreview: '接收预览版更新',
  1234. position: '组件位置',
  1235. buttonSideX: '按钮区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1236. buttonSideY: '按钮区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1237. buttonDistance: '按钮区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1238. showButtonSideX: '显示按钮水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1239. showButtonSideY: '显示按钮垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1240. showButtonDistance: '显示按钮距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1241. logSideX: '日志区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1242. logSideY: '日志区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1243. logDistance: '日志区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1244. hotKey: '快捷键',
  1245. doTaskKey: '做任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1246. undoTaskKey: '撤销任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1247. toggleLogKey: '显示/隐藏日志快捷键</br>(实时预览功能仅在设置页面可用)',
  1248. tasksHistory: '任务历史',
  1249. clearHistory: '清空历史',
  1250. clearHistoryFinished: '已清空任务历史!',
  1251. deleteTask: '删除任务',
  1252. lastChangeTime: '最后一次修改时间',
  1253. clearTaskFinished: '删除以下任务完成!',
  1254. clearTaskFailed: '删除任务失败,没有找到任务名!',
  1255. syncData: '数据同步',
  1256. settingData: '正在上传数据...',
  1257. gettingData: '正在获取数据...',
  1258. help: '帮助',
  1259. fileName: '文件名',
  1260. upload2gist: '同步到Gist',
  1261. downloadFromGist: '从Gist同步',
  1262. saveAndTest: '保存配置并测试',
  1263. testSuccess: '测试成功!',
  1264. testFailed: '测试失败!',
  1265. saveAndTestNotice: '请先保存配置并测试!',
  1266. processingData: '正在处理数据...',
  1267. updatingData: '正在上传数据...',
  1268. syncDataSuccess: '同步数据成功!',
  1269. syncDataFailed: '同步数据失败,请在控制台查看错误信息!',
  1270. downloadingData: '正在下载数据...',
  1271. checkedNoData: '没有检测到远程数据,请确认配置是否正确!',
  1272. savingData: '正在保存数据...',
  1273. syncHistory: '同步任务历史',
  1274. checkUpdateFailed: '检测更新失败',
  1275. newVersionNotice: '检测到新版本V%0, <a class="high-light" href="%1" target="_blank">点此更新</a>',
  1276. language: '语言</br>目前仅支持zh: 中文, en: 英文',
  1277. gistOptions: 'Gist 设置',
  1278. swalNotice: '检测到您第一次安装V4版本脚本,请前往阅读用前必读内容!',
  1279. echoNotice: '检测到您第一次安装V4版本脚本,请<a class="high-light" href="%0" target="_blank">点此前往</a>阅读用前必读内容!',
  1280. noticeLink: 'https://auto-task-doc.js.org/guide/#用前必读',
  1281. toGithub: '前往Github反馈',
  1282. toKeylol: '前往其乐论坛反馈',
  1283. copySuccess: '错误信息已复制到剪切板,是否前往其乐论坛反馈?',
  1284. copyFailed: '请复制下方错误信息后前往Keylol论坛反馈!',
  1285. updateText: '%0 版本更新内容:',
  1286. Active: '进行中',
  1287. Ended: '已结束',
  1288. Banned: '已封禁',
  1289. Paused: '已暂停',
  1290. notStart: '未开始',
  1291. noRemoteData: '检测到远程无数据',
  1292. errorRemoteDataFormat: '远程数据格式错误',
  1293. updateHistory: '历史更新记录<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">点此查看</a>',
  1294. AsfEnabled: '使用ASF做Steam相关任务(需<a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a>插件)',
  1295. AsfIpcUrl: 'ASF IPC 地址',
  1296. AsfIpcPassword: 'ASF IPC 密码',
  1297. groups: '组',
  1298. officialGroups: '官方组',
  1299. wishlists: '愿望单',
  1300. follows: '游戏关注',
  1301. forums: '论坛',
  1302. workshops: '创意工坊收藏',
  1303. curators: '鉴赏家',
  1304. workshopVotes: '创意工坊点赞',
  1305. announcements: '社区通知',
  1306. steamCommunity: 'Steam社区',
  1307. steamStore: 'Steam商店',
  1308. licenses: '入库免费游戏',
  1309. playtests: '请求访问权限',
  1310. needLoginSteamStore: '请先<a href="https://store.steampowered.com/login/" target="_blank">登录Steam商店</a>',
  1311. needLoginSteamCommunity: '请先<a href="https://steamcommunity.com/login/home/" target="_blank">登录Steam社区</a>',
  1312. joiningSteamGroup: '正在加入Steam组',
  1313. leavingSteamGroup: '正在退出Steam组',
  1314. gettingSteamGroupId: '正在获取Steam组Id',
  1315. joiningSteamOfficialGroup: '正在加入Steam官方组',
  1316. leavingSteamOfficialGroup: '正在退出Steam官方组',
  1317. gettingSteamOfficialGroupId: '正在获取Steam官方组Id',
  1318. subscribingForum: '正在订阅Steam论坛',
  1319. unsubscribingForum: '正在取消订阅Steam论坛',
  1320. gettingForumId: '正在获取Steam论坛Id',
  1321. followingCurator: '正在关注Steam鉴赏家',
  1322. unfollowingCurator: '正在取关Steam鉴赏家',
  1323. gettingCuratorId: '正在获取Steam鉴赏家Id',
  1324. addingToWishlist: '正在添加游戏到Steam愿望单',
  1325. removingFromWishlist: '正在从Steam愿望单移除游戏',
  1326. followingGame: '正在关注Steam游戏',
  1327. unfollowingGame: '正在取关Steam游戏',
  1328. favoritingWorkshop: '正在收藏Steam创意工坊物品',
  1329. unfavoritingWorkshop: '正在取消收藏Steam创意工坊物品',
  1330. gettingWorkshopAppId: '正在获取Steam创意工坊物品Id',
  1331. votingUpWorkshop: '正在点赞Steam创意工坊物品',
  1332. gettingAnnouncementParams: '正在获取Steam通知信息',
  1333. likingAnnouncement: '正在点赞Steam通知',
  1334. changingArea: '正在更换Steam地区: %0...',
  1335. notNeededChangeArea: '当前地区不需要更换',
  1336. noAnotherArea: '请检测是否开启正确开启代理',
  1337. gettingAreaInfo: '正在获取Steam地区信息...',
  1338. changeAreaNotice: '疑似锁区游戏,尝试换区执行',
  1339. steamFinishNotice: 'Steam任务完成,尝试将购物车地区换回CN',
  1340. gettingSubid: '正在获取游戏subid',
  1341. addingFreeLicense: '正在入库',
  1342. missParams: '缺少参数',
  1343. gettingLicenses: '正在获取Licenses...',
  1344. requestingPlayTestAccess: '正在请求访问权限',
  1345. tryChangeAreaNotice: '此功能无法检测游戏是否限区,因此会尝试换区后再入库,换区失败也不影响后续入库',
  1346. initingASF: '正在初始化ASF...',
  1347. servers: '服务器',
  1348. joiningDiscordServer: '正在加入Discord服务器',
  1349. leavingDiscordServer: '正在退出Discord服务器',
  1350. gettingDiscordGuild: '正在获取Discord服务器Id',
  1351. getDiscordAuthFailed: '获取Discord凭证失败,请检测Discord帐号是否已登录',
  1352. discordImportantNotice: '重要提醒!!!',
  1353. discordImportantNoticeText: '由于Discord网站后台更新,目前使用此脚本加组后可能会导致Discord帐号被强制退出,且需要两步验证才能正常登录,请谨慎使用!!!',
  1354. continue: '继续',
  1355. skipDiscordTask: '跳过Discord任务',
  1356. continueAndDontRemindAgain: '继续且不再提醒',
  1357. users: '用户',
  1358. loginIns: '请先<a href="https://www.instagram.com/accounts/login/" target="_blank">登录Instagram</a>',
  1359. insBanned: '您的Instagram账户已被封禁',
  1360. verifyingInsAuth: '正在验证Instagram凭证...',
  1361. gettingInsUserId: '正在获取Instagram用户Id',
  1362. followingIns: '正在关注Instagram用户',
  1363. unfollowingIns: '正在取关Instagram用户',
  1364. reddits: '社区/用户',
  1365. loginReddit: '请先<a href="https://www.reddit.com/login/" target="_blank">登录Reddit</a>',
  1366. changingRedditVersion: '正在切换Reddit为新版页面...',
  1367. joiningReddit: '正在加入Reddit社区',
  1368. leavingReddit: '正在退出Reddit社区',
  1369. followingRedditUser: '正在关注Reddit用户',
  1370. unfollowingRedditUser: '正在取关Reddit用户',
  1371. channels: '频道',
  1372. followingTwitchChannel: '正在关注Twitch频道',
  1373. unfollowingTwitchChannel: '正在取关Twitch频道',
  1374. gettingTwitchChannelId: '正在获取Twitch频道Id',
  1375. checkingTwitchIntegrity: '正在检查Twitch完整性...',
  1376. twitterUser: '推特用户',
  1377. retweets: '转推',
  1378. gettingTwitterUserId: '正在获取推特用户Id',
  1379. followingTwitterUser: '正在关注推特用户',
  1380. unfollowingTwitterUser: '正在取关推特用户',
  1381. retweetting: '正在转推',
  1382. unretweetting: '正在撤销转推',
  1383. names: '组/社区/动态',
  1384. loginVk: '请先<a href="https://vk.com/login/" target="_blank">登录Vk</a>',
  1385. gettingVkId: '正在获取Vk任务Id',
  1386. joiningVkGroup: '正在加入Vk组',
  1387. leavingVkGroup: '正在退出Vk组',
  1388. joiningVkPublic: '正在加入Vk社区',
  1389. leavingVkPublic: '正在退出Vk社区',
  1390. sendingVkWall: '正在转发Vk动态',
  1391. deletingVkWall: '正在撤销转发Vk动态',
  1392. youtubeChannel: 'YouTube频道',
  1393. likes: '点赞',
  1394. loginYtb: '请先<a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">登录YouTube</a>',
  1395. tryUpdateYtbAuth: '请尝试<a href="https://www.youtube.com/#auth" target="_blank">更新YouTube凭证</a>',
  1396. gettingYtbToken: '正在获取YouTube Token...',
  1397. followingYtbChannel: '正在订阅YouTube频道',
  1398. unfollowingYtbChannel: '正在退订YouTube频道',
  1399. likingYtbVideo: '正在点赞YouTube视频',
  1400. unlikingYtbVideo: '正在取消点赞YouTube视频',
  1401. giveKeyNoticeBefore: '每次验证间隔15s',
  1402. giveKeyNoticeAfter: '如果没有key, 请在<a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>查看',
  1403. noPoints: '点数不够,跳过抽奖',
  1404. getNeedPointsFailed: '获取所需点数失败,跳过抽奖',
  1405. joiningLottery: '正在加入抽奖',
  1406. doingGleamTask: '正在做Gleam任务...',
  1407. gettingGleamLink: '正在获取Gleam任务链接...',
  1408. gleamTaskNotice: '如果此页面长时间未关闭,请完成任一任务后自行关闭!',
  1409. verifiedGleamTasks: '已尝试验证所有任务,验证失败的任务请尝试手动验证或完成!',
  1410. campaign: '检测到人机验证,请完成验证后重新验证任务!',
  1411. gsNotice: '为避免得到"0000-0000-0000"key, 已自动屏蔽"Grab Key"按钮,获取key时请关闭脚本!',
  1412. giveeClubVerifyNotice: '正在验证任务...',
  1413. giveeClubVerifyFinished: '请等待验证完成后自行加入赠Key',
  1414. doingKeyhubTask: '正在做Keyhub任务...',
  1415. SweepWidgetNotice: '正在处理并验证任务,每次验证任务有1~3s间隔防止触发验证过快警告...',
  1416. confirmingTask: '正在跳过警告页面...'
  1417. };
  1418. const zh_CN = data;
  1419. const en_US_data = {
  1420. website: 'Website',
  1421. type: 'Type',
  1422. edit: 'Edit',
  1423. whiteList: 'Whitelist',
  1424. skipTask: 'Skip undo task',
  1425. whiteListOptions: 'Whitelist options',
  1426. changeWhiteListOption: 'Whitelist option(%0)',
  1427. whiteListNotFound: 'Cannot find this whitelist: %0',
  1428. changeWhiteListSuccess: 'The whitelist is successfully modified, and the page refresh will take effect!',
  1429. changeWebsiteOptions: 'Website options',
  1430. changeGlobalOptions: 'Global options',
  1431. ok: 'OK',
  1432. save: 'Save',
  1433. close: 'Close',
  1434. return: 'Return',
  1435. option: 'Option',
  1436. value: 'Value',
  1437. websiteOptions: 'Current website settings',
  1438. changeWebsiteOptionsSuccess: 'The current website setting is changed successfully, and the page refresh will take effect!',
  1439. changeGlobalOptionsSuccess: 'The global setting is changed successfully, and the refresh will take effect!',
  1440. needLogin: 'Please log in first!',
  1441. getTasksInfo: 'Obtaining and processing task information...',
  1442. gettingKey: 'Getting Key...',
  1443. verifyingTask: 'Verifying task',
  1444. notice: 'Automatic task script notice',
  1445. noKeysLeft: 'There are no more keys left on this page. Do you want to close it?',
  1446. giveawayEnded: 'This event has ended, do you want to close it?',
  1447. 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?',
  1448. confirm: 'Confirm',
  1449. cancel: 'Cancel',
  1450. unKnown: 'Unknown',
  1451. unKnownTaskType: 'Unrecognized task',
  1452. doing: 'Doing a task',
  1453. allTasksComplete: 'All tasks have been completed!',
  1454. getTaskIdFailed: 'Failed to obtain task Id!',
  1455. initSuccess: '%0 was initialized successfully!',
  1456. initFailed: '%0 initialization failed!',
  1457. errorLink: 'Link error: %0',
  1458. needInit: 'Please initialize first',
  1459. verifyingAuth: 'Verifying %0 token...',
  1460. updatingAuth: 'Update %0 token...',
  1461. initing: 'Initializing...',
  1462. getFailed: 'Failed to get %0!',
  1463. checkLoginFailed: 'Failed to detect login status!',
  1464. checkLeftKeyFailed: 'Failed to detect the remaining keys!',
  1465. userId: 'User Id',
  1466. joiningGiveaway: 'Joining giveaway',
  1467. needJoinGiveaway: 'Need to join the giveaway first',
  1468. cannotUndo: 'This website does not support canceling tasks',
  1469. verifyAuth: 'Verifying %0 token...',
  1470. closePageNotice: 'f this page does not close automatically, please close this page yourself.',
  1471. errorReport: 'A script error is detected, do you want to report the BUG?',
  1472. visitingLink: 'Visiting link: ',
  1473. doTask: 'DoTask',
  1474. undoTask: 'UndoTask',
  1475. verifyTask: 'Verify',
  1476. getKey: 'GetKey',
  1477. selectAll: 'SelectAll',
  1478. selectNone: 'SelectNone',
  1479. invertSelect: 'InvertSelect',
  1480. doFreeTask: 'FreeTask',
  1481. doPointTask: 'PointTask',
  1482. skipTaskOption: 'Skip task has been configured in the settings',
  1483. other: 'Other',
  1484. globalOptions: 'Global Options',
  1485. checkLogin: 'Login detection</br>Need to log in to the website automatically log in, part of this website supports.',
  1486. checkLeftKey: 'Key remaining detection</br>The end of the giveaway event prompts whether to close or not, part of this website supports.',
  1487. 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.',
  1488. 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.',
  1489. 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.',
  1490. saveGlobalOptions: 'SaveSettings',
  1491. settingPage: 'Setting Page',
  1492. name: 'Name',
  1493. version: 'Version',
  1494. scriptManager: 'Script Manager',
  1495. script: 'Script',
  1496. environment: 'Environment',
  1497. os: 'OS',
  1498. browser: 'Browser',
  1499. getId: 'Get %0 id',
  1500. getTwitterUserId: 'Get Twitter user id (Get id function is only available on the settings page).',
  1501. getYoutubeChannelId: 'Get Youtube channel id (Get id function is only available on the settings page).',
  1502. showButton: 'ShowButton',
  1503. hideButton: 'HideButton',
  1504. showLog: 'ShowLog',
  1505. hideLog: 'HideLog',
  1506. defaultShowButton: 'Default display button',
  1507. defaultShowLog: 'Display log by default',
  1508. debug: 'Output debug log, do not enable this option!',
  1509. receivePreview: 'Receive preview updates',
  1510. position: 'Component position',
  1511. buttonSideX: 'Horizontal positioning of the button area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1512. 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',
  1513. 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',
  1514. showButtonSideX: 'ShowButton horizontal positioning (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1515. showButtonSideY: 'ShowButton vertical positioning (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1516. 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',
  1517. logSideX: 'Horizontal positioning of the log area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1518. logSideY: 'Vertical positioning of the log area (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1519. 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',
  1520. hotKey: 'Shortcut key',
  1521. doTaskKey: 'DoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1522. undoTaskKey: 'UndoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1523. toggleLogKey: 'ShowLog/HideLog shortcut keys</br> (real-time preview function is only available on the settings page).',
  1524. tasksHistory: 'TasksHistory',
  1525. clearHistory: 'Clear history',
  1526. clearHistoryFinished: 'The mission history has been cleared!',
  1527. deleteTask: 'Delete task',
  1528. lastChangeTime: 'Last Change Time',
  1529. clearTaskFinished: 'Delete the following tasks completed!',
  1530. clearTaskFailed: 'Failed to delete the task, the task name was not found!',
  1531. syncData: 'DataSync',
  1532. settingData: 'Uploading data...',
  1533. gettingData: 'Getting data...',
  1534. help: 'Help',
  1535. fileName: 'Filename',
  1536. upload2gist: 'Sync to Gist',
  1537. downloadFromGist: 'Sync from Gist',
  1538. saveAndTest: 'Save configuration and test',
  1539. testSuccess: 'Test success!',
  1540. testFailed: 'Test failed!',
  1541. saveAndTestNotice: 'Please save the configuration and test first!',
  1542. processingData: 'Processing data...',
  1543. updatingData: 'Uploading data...',
  1544. syncDataSuccess: 'Synchronized data successfully!',
  1545. syncDataFailed: 'Failed to synchronize data, please check the error message on the console!',
  1546. downloadingData: 'Downloading data...',
  1547. checkedNoData: 'No remote data is detected, please confirm whether the configuration is correct!',
  1548. savingData: 'Saving data...',
  1549. syncHistory: 'Synchronize tasks history',
  1550. checkUpdateFailed: 'Check update failed',
  1551. newVersionNotice: 'Checked a new version V%0, <a class="high-light" href="%1" target="_blank">click to update</a>',
  1552. language: 'Language</br> Currently only supports zh: Chinese, en: English',
  1553. gistOptions: 'Gist Settings',
  1554. 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!',
  1555. 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!',
  1556. noticeLink: 'https://auto-task-doc.js.org/en/guide/#read-me-first',
  1557. toGithub: 'Feedback(Github)',
  1558. toKeylol: 'Feedback(Keylol)',
  1559. copySuccess: 'The error message has been copied to the clipboard. Do you want to go to the Keylol forum to give feedback?',
  1560. copyFailed: 'Please copy the error information below and report back to the Keylol forum!',
  1561. updateText: 'Updates in version %0:',
  1562. Active: 'Active',
  1563. Ended: 'Ended',
  1564. Banned: 'Banned',
  1565. Paused: 'Paused',
  1566. notStart: 'notStart',
  1567. noRemoteData: 'No data remotely',
  1568. errorRemoteDataFormat: 'Remote data has wrong format',
  1569. updateHistory: '<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">Click here</a>' + ' to view the historical update record.',
  1570. AsfEnabled: 'Use ASF to do Steam related tasks (requires <a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a> plugin)',
  1571. AsfIpcUrl: 'ASF IPC URL',
  1572. AsfIpcPassword: 'ASF IPC Password',
  1573. groups: 'Group',
  1574. officialGroups: 'Official Group',
  1575. wishlists: 'Wishlist',
  1576. follows: 'Follow Game',
  1577. forums: 'Forum',
  1578. workshops: 'Favorite Workshop',
  1579. curators: 'Curator',
  1580. workshopVotes: 'Voteup Workshop',
  1581. announcements: 'Announcement',
  1582. steamCommunity: 'Steam Community',
  1583. steamStore: 'Steam Store',
  1584. licenses: 'Add License',
  1585. playtests: 'Playtest Access',
  1586. needLoginSteamStore: 'Please <a href="https://store.steampowered.com/login/" target="_blank">log in to the Steam Store</a>',
  1587. needLoginSteamCommunity: 'Please <a href="https://steamcommunity.com/login/home/" target="_blank">log in to the Steam Community</a>',
  1588. joiningSteamGroup: 'Joining Steam Group',
  1589. leavingSteamGroup: 'Leaving Steam Group',
  1590. gettingSteamGroupId: 'Getting Steam Group Id',
  1591. joiningSteamOfficialGroup: 'Joining Steam Official Group',
  1592. leavingSteamOfficialGroup: 'Leaving Steam Official Group',
  1593. gettingSteamOfficialGroupId: 'Getting Steam Official Group Id',
  1594. subscribingForum: 'Subscribing the Steam Forum',
  1595. unsubscribingForum: 'Unsubscribing the Steam Forum',
  1596. gettingForumId: 'Getting Steam Forum Id',
  1597. followingCurator: 'Following Steam Curator',
  1598. unfollowingCurator: 'Unfollowing Steam Curator',
  1599. gettingCuratorId: 'Getting Steam Curator Id',
  1600. addingToWishlist: 'Adding the game to the Steam wishlist',
  1601. removingFromWishlist: 'Removing the game from the Steam wishlist',
  1602. followingGame: 'Following Steam games',
  1603. unfollowingGame: 'Unfollowing Steam games',
  1604. favoritingWorkshop: 'Favouring Steam Workshop Items',
  1605. unfavoritingWorkshop: 'Unfavoriting Steam Workshop Items',
  1606. gettingWorkshopAppId: 'Getting Steam Workshop Item Id',
  1607. votingUpWorkshop: 'Liking Steam workshop items',
  1608. gettingAnnouncementParams: 'Getting Steam announcement information',
  1609. likingAnnouncement: 'Liking Steam announcement',
  1610. changingArea: 'Changing Steam area: %0...',
  1611. notNeededChangeArea: 'The current area does not need to be changed',
  1612. noAnotherArea: 'Please check whether the proxy is turned on correctly',
  1613. gettingAreaInfo: 'Getting Steam area information...',
  1614. changeAreaNotice: 'Suspected of a locked zone game, try to change the zone to execute',
  1615. steamFinishNotice: 'Steam task completed, try to change the shopping cart area back to CN',
  1616. gettingSubid: 'Getting subid',
  1617. addingFreeLicense: 'Adding free license',
  1618. missParams: 'Missing parameters',
  1619. gettingLicenses: 'Getting licenses...',
  1620. requestingPlayTestAccess: 'Requesting play test access',
  1621. 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.',
  1622. initingASF: 'Initing ASF...',
  1623. servers: 'Server',
  1624. joiningDiscordServer: 'Joining Discord Server',
  1625. leavingDiscordServer: 'Leaving Discord Server',
  1626. gettingDiscordGuild: 'Getting Discord server Id',
  1627. getDiscordAuthFailed: 'Failed to get Discord token, please check whether the Discord account is logged in',
  1628. discordImportantNotice: 'Important Reminder! ! !',
  1629. 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! ! !',
  1630. continue: 'Continue',
  1631. skipDiscordTask: 'Skip',
  1632. continueAndDontRemindAgain: 'Continue without Reminders',
  1633. users: 'User',
  1634. loginIns: 'Please <a href="https://www.instagram.com/accounts/login/" target="_blank">log in to Instagram</a>',
  1635. insBanned: 'Your Instagram account has been banned',
  1636. verifyingInsAuth: 'Verifying Instagram token...',
  1637. gettingInsUserId: 'Getting Instagram user Id',
  1638. followingIns: 'Following Instagram user',
  1639. unfollowingIns: 'Unfollowing Instagram user',
  1640. reddits: 'Reddit/User',
  1641. loginReddit: 'Please <a href="https://www.reddit.com/login/" target="_blank">log in to Reddit</a>',
  1642. changingRedditVersion: 'Switching Reddit to a new version page...',
  1643. joiningReddit: 'Joining the Reddit',
  1644. leavingReddit: 'Leaving the Reddit',
  1645. followingRedditUser: 'Following Reddit User',
  1646. unfollowingRedditUser: 'Unfollowing Reddit User',
  1647. channels: 'Channel',
  1648. followingTwitchChannel: 'Following Twitch Channel',
  1649. unfollowingTwitchChannel: 'Unfollowing Twitch Channel',
  1650. gettingTwitchChannelId: 'Getting Twitch Channel Id',
  1651. checkingTwitchIntegrity: 'Checking Twitch integrity...',
  1652. twitterUser: 'Twitter User',
  1653. retweets: 'Retweet',
  1654. gettingTwitterUserId: 'Getting Twitter User Id',
  1655. followingTwitterUser: 'Following Twitter User',
  1656. unfollowingTwitterUser: 'Unfollowing Twitter User',
  1657. retweetting: 'Retweetting',
  1658. unretweetting: 'Unretweetting',
  1659. names: 'Group/Public/Wall',
  1660. loginVk: 'Please <a href="https://vk.com/login/" target="_blank">log in to Vk</a>',
  1661. gettingVkId: 'Getting Vk task Id',
  1662. joiningVkGroup: 'Joining Vk Group',
  1663. leavingVkGroup: 'Leaving Vk Group',
  1664. joiningVkPublic: 'Joining Vk Public',
  1665. leavingVkPublic: 'Leaving Vk Public',
  1666. sendingVkWall: 'Sending Vk Wall',
  1667. deletingVkWall: 'Deleting Vk Wall',
  1668. youtubeChannel: 'YouTube Channel',
  1669. likes: 'Like',
  1670. loginYtb: 'Please <a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">log in to YouTube</a>',
  1671. tryUpdateYtbAuth: 'Please try to <a href="https://www.youtube.com/#auth" target="_blank">update YouTube token</a>',
  1672. gettingYtbToken: 'Getting YouTube Token...',
  1673. followingYtbChannel: 'Subscribing to YouTube channel',
  1674. unfollowingYtbChannel: 'Unsubscribing to YouTube channel',
  1675. likingYtbVideo: 'Liking YouTube video',
  1676. unlikingYtbVideo: 'Unliking YouTube video',
  1677. giveKeyNoticeBefore: 'Each verification interval is 15s',
  1678. giveKeyNoticeAfter: 'If there is no key, please check at <a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>',
  1679. noPoints: 'Not enough points, skip the lottery',
  1680. getNeedPointsFailed: 'ailed to obtain the required points, skip the lottery',
  1681. joiningLottery: 'Joining the lottery',
  1682. doingGleamTask: 'Doing Gleam Task...',
  1683. gettingGleamLink: 'Getting Gleam task link...',
  1684. gleamTaskNotice: 'If this page has not been closed for a long time, please close it yourself after completing any task!',
  1685. verifiedGleamTasks: 'Attempted to verify all tasks. If the verification fails, please try to verify manually or complete it!',
  1686. campaign: 'ReCAPTCHA detected, please complete it and re-verify the tasks!',
  1687. 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!',
  1688. giveeClubVerifyNotice: 'Verifying task...',
  1689. giveeClubVerifyFinished: 'Wait for the verification to complete and join it by yourself',
  1690. doingKeyhubTask: 'Doing Keyhub Task...',
  1691. 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...',
  1692. confirmingTask: 'Confirming task...'
  1693. };
  1694. const en_US = en_US_data;
  1695. const languages = {
  1696. zh: zh_CN,
  1697. en: en_US
  1698. };
  1699. const language = [ 'zh', 'en' ].includes(globalOptions.other.language) ? globalOptions.other.language : 'en';
  1700. const I18n = (key, ...argvs) => {
  1701. if (!languages[language]?.[key]) {
  1702. return key;
  1703. }
  1704. return languages[language][key].replace(/%([\d]+)/g, (match, index) => argvs[parseInt(index, 10)]);
  1705. };
  1706. const i18n = I18n;
  1707. function throwError(error, name) {
  1708. if (window.TRACE) {
  1709. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  1710. }
  1711. external_Swal_default().fire({
  1712. title: i18n('errorReport'),
  1713. icon: 'error',
  1714. showCancelButton: true,
  1715. confirmButtonText: i18n('toGithub'),
  1716. showDenyButton: true,
  1717. denyButtonText: i18n('toKeylol'),
  1718. cancelButtonText: i18n('close')
  1719. }).then(({
  1720. isDenied,
  1721. isConfirmed
  1722. }) => {
  1723. if (isConfirmed) {
  1724. 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,
  1725. 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');
  1726. } else if (isDenied) {
  1727. const text = `错误链接: [url=${window.location.href}]${window.location.href}[/url]
  1728.  
  1729. 环境:
  1730.  
  1731. [code]${JSON.stringify((0, javascript_utils_umd_min.ua)(), null, 4)}[/code]
  1732.  
  1733. 脚本管理器: ${GM_info.scriptHandler} ${GM_info.version}
  1734. 脚本版本: ${GM_info.script.version}
  1735.  
  1736. 报错信息:
  1737. [code]${error.stack}[/code]
  1738.  
  1739. 执行日志:
  1740. [code]${$.makeArray($('#auto-task-info>li')).map(element => element.innerText).join('\n')}[/code]`;
  1741. GM_setClipboard(text);
  1742. external_Swal_default().fire({
  1743. title: i18n('copySuccess'),
  1744. icon: 'success',
  1745. confirmButtonText: i18n('ok')
  1746. }).then(() => {
  1747. window.open('https://keylol.com/forum.php?mod=post&action=reply&fid=319&tid=777450', '_blank');
  1748. });
  1749. }
  1750. });
  1751. console.log('%c%s', 'color:white;background:red', `Auto-Task[Error]: ${name}\n${error.stack}`);
  1752. }
  1753. class Social {
  1754. tasks;
  1755. getRealParams(name, links, doTask, link2param) {
  1756. try {
  1757. let realParams = [];
  1758. if (links.length > 0) {
  1759. realParams = [ ...realParams, ...links.map(link => link2param(link)).filter(link => link) ];
  1760. }
  1761. if (!doTask && this.tasks[name].length > 0) {
  1762. realParams = [ ...realParams, ...this.tasks[name] ];
  1763. }
  1764. return unique(realParams);
  1765. } catch (error) {
  1766. throwError(error, 'Social.getRealParams');
  1767. return [];
  1768. }
  1769. }
  1770. }
  1771. const social_Social = Social;
  1772. class Discord extends social_Social {
  1773. tasks;
  1774. whiteList;
  1775. #auth = GM_getValue('discordAuth') || {};
  1776. #cache = GM_getValue('discordCache') || {};
  1777. #initialized = false;
  1778. constructor() {
  1779. super();
  1780. const defaultTasksTemplate = {
  1781. servers: []
  1782. };
  1783. this.tasks = defaultTasksTemplate;
  1784. this.whiteList = {
  1785. ...defaultTasksTemplate,
  1786. ...GM_getValue('whiteList')?.discord || {}
  1787. };
  1788. }
  1789. async init() {
  1790. try {
  1791. if (!GM_getValue('dontRemindDiscordAgain')) {
  1792. const result = await external_Swal_default().fire({
  1793. title: i18n('discordImportantNotice'),
  1794. text: i18n('discordImportantNoticeText'),
  1795. showCancelButton: true,
  1796. showDenyButton: true,
  1797. confirmButtonText: i18n('continue'),
  1798. cancelButtonText: i18n('skipDiscordTask'),
  1799. denyButtonText: i18n('continueAndDontRemindAgain')
  1800. }).then(({
  1801. isConfirmed,
  1802. isDenied
  1803. }) => {
  1804. if (isConfirmed) {
  1805. return true;
  1806. }
  1807. if (isDenied) {
  1808. GM_setValue('dontRemindDiscordAgain', true);
  1809. return true;
  1810. }
  1811. return false;
  1812. });
  1813. if (!result) {
  1814. this.#initialized = false;
  1815. return 'skip';
  1816. }
  1817. }
  1818. if (!globalOptions.doTask.discord.servers && !globalOptions.undoTask.discord.servers) {
  1819. this.#initialized = false;
  1820. return 'skip';
  1821. }
  1822. if (this.#initialized) {
  1823. return true;
  1824. }
  1825. if (!this.#auth.auth) {
  1826. if (await this.#updateAuth()) {
  1827. this.#initialized = true;
  1828. return true;
  1829. }
  1830. return false;
  1831. }
  1832. const isVerified = await this.#verifyAuth();
  1833. if (isVerified) {
  1834. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1835. this.#initialized = true;
  1836. return true;
  1837. }
  1838. GM_setValue('discordAuth', {
  1839. auth: null
  1840. });
  1841. if (await this.#updateAuth()) {
  1842. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1843. this.#initialized = true;
  1844. return true;
  1845. }
  1846. scripts_echoLog({}).error(i18n('initFailed', 'Discord'));
  1847. return false;
  1848. } catch (error) {
  1849. throwError(error, 'Discord.init');
  1850. return false;
  1851. }
  1852. }
  1853. async #verifyAuth() {
  1854. try {
  1855. const logStatus = scripts_echoLog({
  1856. text: i18n('verifyingAuth', 'Discord')
  1857. });
  1858. const {
  1859. result,
  1860. statusText,
  1861. status,
  1862. data
  1863. } = await tools_httpRequest({
  1864. url: 'https://discord.com/api/v6/users/@me',
  1865. method: 'HEAD',
  1866. headers: {
  1867. authorization: this.#auth.auth
  1868. }
  1869. });
  1870. if (result === 'Success') {
  1871. if (data?.status === 200) {
  1872. logStatus.success();
  1873. return true;
  1874. }
  1875. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  1876. return false;
  1877. }
  1878. logStatus.error(`${result}:${statusText}(${status})`);
  1879. return false;
  1880. } catch (error) {
  1881. throwError(error, 'Discord.verifyAuth');
  1882. return false;
  1883. }
  1884. }
  1885. async #updateAuth() {
  1886. try {
  1887. const logStatus = scripts_echoLog({
  1888. text: i18n('updatingAuth', 'Discord')
  1889. });
  1890. return await new Promise(resolve => {
  1891. const newTab = GM_openInTab('https://discord.com/channels/@me#auth', {
  1892. active: true,
  1893. insert: true,
  1894. setParent: true
  1895. });
  1896. newTab.onclose = async () => {
  1897. const auth = GM_getValue('discordAuth')?.auth;
  1898. if (auth) {
  1899. this.#auth = {
  1900. auth: auth
  1901. };
  1902. logStatus.success();
  1903. resolve(await this.#verifyAuth());
  1904. } else {
  1905. logStatus.error('Error: Update discord auth failed!');
  1906. resolve(false);
  1907. }
  1908. };
  1909. });
  1910. } catch (error) {
  1911. throwError(error, 'Discord.updateAuth');
  1912. return false;
  1913. }
  1914. }
  1915. async #joinServer(inviteId) {
  1916. try {
  1917. const logStatus = scripts_echoLog({
  1918. type: 'joiningDiscordServer',
  1919. text: inviteId
  1920. });
  1921. const {
  1922. result,
  1923. statusText,
  1924. status,
  1925. data
  1926. } = await tools_httpRequest({
  1927. url: `https://discord.com/api/v9/invites/${inviteId}`,
  1928. method: 'POST',
  1929. dataType: 'json',
  1930. headers: {
  1931. authorization: this.#auth.auth,
  1932. origin: 'https://discord.com',
  1933. referer: `https://discord.com/invite/${inviteId}`
  1934. }
  1935. });
  1936. if (result === 'Success' && data?.status === 200) {
  1937. logStatus.success();
  1938. const guild = String(data.response?.guild?.id);
  1939. if (guild) {
  1940. this.#setCache(inviteId, guild);
  1941. this.tasks.servers = unique([ ...this.tasks.servers, inviteId ]);
  1942. }
  1943. return true;
  1944. }
  1945. logStatus.error(`${result}:${statusText}(${status})`);
  1946. return false;
  1947. } catch (error) {
  1948. throwError(error, 'Discord.joinServer');
  1949. return false;
  1950. }
  1951. }
  1952. async #leaveServer(inviteId) {
  1953. try {
  1954. if (this.whiteList.servers.includes(inviteId)) {
  1955. scripts_echoLog({
  1956. type: 'whiteList',
  1957. text: 'Discord.leaveServer',
  1958. id: inviteId
  1959. });
  1960. return true;
  1961. }
  1962. const guild = await this.#getGuild(inviteId);
  1963. if (!guild) {
  1964. return false;
  1965. }
  1966. const logStatus = scripts_echoLog({
  1967. type: 'leavingDiscordServer',
  1968. text: guild
  1969. });
  1970. const {
  1971. result,
  1972. statusText,
  1973. status,
  1974. data
  1975. } = await tools_httpRequest({
  1976. url: `https://discord.com/api/v9/users/@me/guilds/${guild}`,
  1977. method: 'DELETE',
  1978. headers: {
  1979. authorization: this.#auth.auth
  1980. }
  1981. });
  1982. if (result === 'Success' && data?.status === 204) {
  1983. logStatus.success();
  1984. return true;
  1985. }
  1986. logStatus.error(`${result}:${statusText}(${status})`);
  1987. return false;
  1988. } catch (error) {
  1989. throwError(error, 'Discord.leaveServer');
  1990. return false;
  1991. }
  1992. }
  1993. async #getGuild(inviteId) {
  1994. try {
  1995. const logStatus = scripts_echoLog({
  1996. type: 'gettingDiscordGuild',
  1997. text: inviteId
  1998. });
  1999. const guild = this.#cache[inviteId];
  2000. if (guild) {
  2001. logStatus.success();
  2002. return guild;
  2003. }
  2004. const {
  2005. result,
  2006. statusText,
  2007. status,
  2008. data
  2009. } = await tools_httpRequest({
  2010. url: `https://discord.com/api/v9/invites/${inviteId}`,
  2011. responseType: 'json',
  2012. method: 'GET'
  2013. });
  2014. if (result === 'Success' && data?.status === 200) {
  2015. const guild = data.response?.guild?.id;
  2016. if (guild) {
  2017. logStatus.success();
  2018. this.#setCache(inviteId, guild);
  2019. return guild;
  2020. }
  2021. logStatus.error(`${result}:${statusText}(${status})`);
  2022. return false;
  2023. }
  2024. logStatus.error(`${result}:${statusText}(${status})`);
  2025. return false;
  2026. } catch (error) {
  2027. throwError(error, 'Discord.getGuild');
  2028. return false;
  2029. }
  2030. }
  2031. async toggle({
  2032. doTask = true,
  2033. serverLinks = []
  2034. }) {
  2035. try {
  2036. if (!this.#initialized) {
  2037. scripts_echoLog({
  2038. text: i18n('needInit')
  2039. });
  2040. return false;
  2041. }
  2042. const prom = [];
  2043. if (doTask && !globalOptions.doTask.discord.servers || !doTask && !globalOptions.undoTask.discord.servers) {
  2044. scripts_echoLog({
  2045. type: 'globalOptionsSkip',
  2046. text: 'discord.servers'
  2047. });
  2048. } else {
  2049. const realServers = this.getRealParams('servers', serverLinks, doTask, link => link.match(/invite\/(.+)/)?.[1]);
  2050. if (realServers.length > 0) {
  2051. for (const server of realServers) {
  2052. if (doTask) {
  2053. prom.push(this.#joinServer(server));
  2054. } else {
  2055. prom.push(this.#leaveServer(server));
  2056. }
  2057. await delay(1e3);
  2058. }
  2059. }
  2060. }
  2061. return await Promise.all(prom).then(() => true);
  2062. } catch (error) {
  2063. throwError(error, 'Discord.toggleServers');
  2064. return false;
  2065. }
  2066. }
  2067. #setCache(inviteId, guild) {
  2068. try {
  2069. this.#cache[inviteId] = guild;
  2070. GM_setValue('discordCache', this.#cache);
  2071. } catch (error) {
  2072. throwError(error, 'Discord.setCache');
  2073. }
  2074. }
  2075. }
  2076. const social_Discord = Discord;
  2077. class Instagram extends social_Social {
  2078. tasks;
  2079. whiteList;
  2080. #cache = GM_getValue('instagramCache') || {};
  2081. #auth = {};
  2082. #initialized = false;
  2083. constructor() {
  2084. super();
  2085. const defaultTasksTemplate = {
  2086. users: []
  2087. };
  2088. this.tasks = defaultTasksTemplate;
  2089. this.whiteList = {
  2090. ...defaultTasksTemplate,
  2091. ...GM_getValue('whiteList')?.instagram || {}
  2092. };
  2093. }
  2094. async init() {
  2095. try {
  2096. if (this.#initialized) {
  2097. return true;
  2098. }
  2099. const isVerified = await this.#getUserInfo();
  2100. if (isVerified) {
  2101. scripts_echoLog({}).success(i18n('initSuccess', 'Instagram'));
  2102. this.#initialized = true;
  2103. return true;
  2104. }
  2105. scripts_echoLog({}).error(i18n('initFailed', 'Instagram'));
  2106. return false;
  2107. } catch (error) {
  2108. throwError(error, 'Instagram.init');
  2109. return false;
  2110. }
  2111. }
  2112. async #getUserInfo(name = 'instagram') {
  2113. try {
  2114. const logStatus = scripts_echoLog({
  2115. type: name === 'instagram' ? 'verifyingInsAuth' : 'gettingInsUserId',
  2116. text: name
  2117. });
  2118. const userId = this.#cache[name];
  2119. if (userId && name !== 'instagram') {
  2120. logStatus.success();
  2121. return userId;
  2122. }
  2123. const {
  2124. result,
  2125. statusText,
  2126. status,
  2127. data
  2128. } = await tools_httpRequest({
  2129. url: `https://www.instagram.com/${name}/`,
  2130. method: 'GET'
  2131. });
  2132. if (result === 'Success') {
  2133. if (data?.finalUrl.includes('accounts/login')) {
  2134. logStatus.error(`Error:${i18n('loginIns')}`, true);
  2135. return false;
  2136. } else if (data?.finalUrl.includes('www.instagram.com/challenge')) {
  2137. logStatus.error(`Error:${i18n('insBanned')}`);
  2138. return false;
  2139. }
  2140. if (data?.status === 200) {
  2141. const csrftoken = data.responseText.match(/"csrf_token":"(.+?)"/)?.[1];
  2142. const hash = data.responseText.match(/"rollout_hash":"(.+?)"/)?.[1];
  2143. if (name === 'instagram') {
  2144. if (csrftoken && hash) {
  2145. this.#auth = {
  2146. csrftoken: csrftoken,
  2147. hash: hash
  2148. };
  2149. return true;
  2150. }
  2151. return false;
  2152. }
  2153. const id = data.responseText.match(/"profilePage_([\d]+?)"/)?.[1];
  2154. if (id) {
  2155. this.#setCache(name, id);
  2156. logStatus.success();
  2157. return id;
  2158. }
  2159. logStatus.error('Error: Get ins data error!');
  2160. return false;
  2161. }
  2162. logStatus.error(`${result}:${statusText}(${status})`);
  2163. return false;
  2164. }
  2165. return false;
  2166. } catch (error) {
  2167. throwError(error, 'Instagram.getUserInfo');
  2168. return false;
  2169. }
  2170. }
  2171. async #followUser(name) {
  2172. try {
  2173. const id = await this.#getUserInfo(name);
  2174. if (!id) {
  2175. return false;
  2176. }
  2177. const logStatus = scripts_echoLog({
  2178. type: 'followingIns',
  2179. text: name
  2180. });
  2181. const {
  2182. result,
  2183. statusText,
  2184. status,
  2185. data
  2186. } = await tools_httpRequest({
  2187. url: `https://www.instagram.com/web/friendships/${id}/follow/`,
  2188. method: 'POST',
  2189. dataType: 'json',
  2190. headers: {
  2191. 'x-csrftoken': this.#auth.csrftoken,
  2192. origin: 'https://www.instagram.com',
  2193. referer: `https://www.instagram.com/${name}/`,
  2194. 'content-type': 'application/x-www-form-urlencoded',
  2195. 'sec-fetch-site': 'same-origin',
  2196. 'x-instagram-ajax': this.#auth.hash
  2197. }
  2198. });
  2199. if (result === 'Success') {
  2200. if (data?.status === 200 && data.response?.result === 'following') {
  2201. logStatus.success();
  2202. this.tasks.users = unique([ ...this.tasks.users, name ]);
  2203. return true;
  2204. }
  2205. logStatus.error(`Error:${data?.response?.feedback_message || `${data?.statusText}(${data?.status})`}`);
  2206. return false;
  2207. }
  2208. logStatus.error(`${result}:${statusText}(${status})`);
  2209. return false;
  2210. } catch (error) {
  2211. throwError(error, 'Instagram.followUser');
  2212. return false;
  2213. }
  2214. }
  2215. async #unfollowUser(name) {
  2216. try {
  2217. if (this.whiteList.users.includes(name)) {
  2218. scripts_echoLog({
  2219. type: 'whiteList',
  2220. text: 'Instagram.unfollowUser',
  2221. id: name
  2222. });
  2223. return true;
  2224. }
  2225. const id = await this.#getUserInfo(name);
  2226. if (!id) {
  2227. return false;
  2228. }
  2229. const logStatus = scripts_echoLog({
  2230. type: 'unfollowingIns',
  2231. text: name
  2232. });
  2233. const {
  2234. result,
  2235. statusText,
  2236. status,
  2237. data
  2238. } = await tools_httpRequest({
  2239. url: `https://www.instagram.com/web/friendships/${id}/unfollow/`,
  2240. method: 'POST',
  2241. dataType: 'json',
  2242. headers: {
  2243. 'x-csrftoken': this.#auth.csrftoken,
  2244. origin: 'https://www.instagram.com',
  2245. referer: `https://www.instagram.com/${name}/`,
  2246. 'content-type': 'application/x-www-form-urlencoded',
  2247. 'sec-fetch-site': 'same-origin',
  2248. 'x-instagram-ajax': this.#auth.hash
  2249. }
  2250. });
  2251. if (result === 'Success') {
  2252. if (data?.status === 200 && data.response?.status === 'ok') {
  2253. logStatus.success();
  2254. return true;
  2255. }
  2256. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2257. return false;
  2258. }
  2259. logStatus.error(`${result}:${statusText}(${status})`);
  2260. return false;
  2261. } catch (error) {
  2262. throwError(error, 'Instagram.unfollowUser');
  2263. return false;
  2264. }
  2265. }
  2266. async toggle({
  2267. doTask = true,
  2268. userLinks = []
  2269. }) {
  2270. try {
  2271. if (!this.#initialized) {
  2272. scripts_echoLog({
  2273. text: i18n('needInit')
  2274. });
  2275. return false;
  2276. }
  2277. const prom = [];
  2278. if (doTask && !globalOptions.doTask.instagram.users || !doTask && !globalOptions.undoTask.instagram.users) {
  2279. scripts_echoLog({
  2280. type: 'globalOptionsSkip',
  2281. text: 'instagram.users'
  2282. });
  2283. } else {
  2284. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1]);
  2285. if (realUsers.length > 0) {
  2286. for (const username of realUsers) {
  2287. if (doTask) {
  2288. prom.push(this.#followUser(username));
  2289. } else {
  2290. prom.push(this.#unfollowUser(username));
  2291. }
  2292. await delay(1e3);
  2293. }
  2294. }
  2295. }
  2296. return await Promise.all(prom).then(() => true);
  2297. } catch (error) {
  2298. throwError(error, 'Instagram.toggleUsers');
  2299. return false;
  2300. }
  2301. }
  2302. #setCache(name, id) {
  2303. try {
  2304. this.#cache[name] = id;
  2305. GM_setValue('instagramCache', this.#cache);
  2306. } catch (error) {
  2307. throwError(error, 'Instagram.setCache');
  2308. }
  2309. }
  2310. }
  2311. const social_Instagram = Instagram;
  2312. class Reddit extends social_Social {
  2313. tasks;
  2314. whiteList;
  2315. #auth;
  2316. #initialized = false;
  2317. constructor() {
  2318. super();
  2319. const defaultTasksTemplate = {
  2320. reddits: []
  2321. };
  2322. this.tasks = defaultTasksTemplate;
  2323. this.whiteList = {
  2324. ...defaultTasksTemplate,
  2325. ...GM_getValue('whiteList')?.reddit || {}
  2326. };
  2327. }
  2328. async init() {
  2329. try {
  2330. if (this.#initialized) {
  2331. return true;
  2332. }
  2333. const isVerified = await this.#updateAuth();
  2334. if (isVerified) {
  2335. scripts_echoLog({}).success(i18n('initSuccess', 'Reddit'));
  2336. this.#initialized = true;
  2337. return true;
  2338. }
  2339. scripts_echoLog({}).error(i18n('initFailed', 'Reddit'));
  2340. return false;
  2341. } catch (error) {
  2342. throwError(error, 'Reddit.init');
  2343. return false;
  2344. }
  2345. }
  2346. async #useBeta() {
  2347. try {
  2348. const logStatus = scripts_echoLog({
  2349. text: i18n('changingRedditVersion')
  2350. });
  2351. GM_setValue('redditAuth', null);
  2352. return await new Promise(resolve => {
  2353. const newTab = GM_openInTab('https://www.reddit.com/#auth', {
  2354. active: true,
  2355. insert: true,
  2356. setParent: true
  2357. });
  2358. newTab.onclose = async () => {
  2359. logStatus.success();
  2360. resolve(await this.#updateAuth(true));
  2361. };
  2362. });
  2363. } catch (error) {
  2364. throwError(error, 'Reddit.useBeta');
  2365. return false;
  2366. }
  2367. }
  2368. async #updateAuth(beta = false) {
  2369. try {
  2370. const logStatus = scripts_echoLog({
  2371. text: i18n('updatingAuth', 'Reddit')
  2372. });
  2373. const {
  2374. result,
  2375. statusText,
  2376. status,
  2377. data
  2378. } = await tools_httpRequest({
  2379. url: 'https://www.reddit.com/',
  2380. method: 'GET',
  2381. nochche: true,
  2382. headers: {
  2383. 'Cache-Control': 'no-cache'
  2384. }
  2385. });
  2386. if (result === 'Success') {
  2387. if (data?.responseText.includes('www.reddit.com/login/')) {
  2388. logStatus.error(`Error:${i18n('loginReddit')}`, true);
  2389. return false;
  2390. }
  2391. if (data?.status === 200) {
  2392. if (data.responseText.includes('redesign-beta-optin-btn') && !beta) {
  2393. return await this.#useBeta();
  2394. }
  2395. const accessToken = data.responseText.match(/"accessToken":"(.*?)","expires":"(.*?)"/)?.[1];
  2396. if (accessToken) {
  2397. this.#auth = {
  2398. token: accessToken
  2399. };
  2400. logStatus.success();
  2401. return true;
  2402. }
  2403. logStatus.error('Error: Parameter "accessToken" not found!');
  2404. return false;
  2405. }
  2406. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2407. return false;
  2408. }
  2409. logStatus.error(`${result}:${statusText}(${status})`);
  2410. return false;
  2411. } catch (error) {
  2412. throwError(error, 'Reddit.updateAuth');
  2413. return false;
  2414. }
  2415. }
  2416. async toggleTask({
  2417. name,
  2418. doTask = true
  2419. }) {
  2420. try {
  2421. if (!doTask && this.whiteList.reddits.includes(name)) {
  2422. scripts_echoLog({
  2423. type: 'whiteList',
  2424. text: 'Reddit.undoTask',
  2425. id: name
  2426. });
  2427. return true;
  2428. }
  2429. let type = doTask ? 'joiningReddit' : 'leavingReddit';
  2430. if (/^u_/.test(name)) {
  2431. type = doTask ? 'followingRedditUser' : 'unfollowingRedditUser';
  2432. }
  2433. const logStatus = scripts_echoLog({
  2434. type: type,
  2435. text: name
  2436. });
  2437. const {
  2438. result,
  2439. statusText,
  2440. status,
  2441. data
  2442. } = await tools_httpRequest({
  2443. url: 'https://oauth.reddit.com/api/subscribe?redditWebClient=desktop2x&app=desktop2x-client-production&raw_json=1&gilding_detail=1',
  2444. method: 'POST',
  2445. headers: {
  2446. authorization: `Bearer ${this.#auth.token}`,
  2447. 'content-type': 'application/x-www-form-urlencoded'
  2448. },
  2449. data: $.param({
  2450. action: doTask ? 'sub' : 'unsub',
  2451. sr_name: name,
  2452. api_type: 'json'
  2453. })
  2454. });
  2455. if (result === 'Success') {
  2456. if (data?.status === 200) {
  2457. logStatus.success();
  2458. if (doTask) {
  2459. this.tasks.reddits = unique([ ...this.tasks.reddits, name ]);
  2460. }
  2461. return true;
  2462. }
  2463. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2464. return false;
  2465. }
  2466. logStatus.error(`${result}:${statusText}(${status})`);
  2467. return false;
  2468. } catch (error) {
  2469. throwError(error, 'Reddit.toggleTask');
  2470. return false;
  2471. }
  2472. }
  2473. async toggle({
  2474. doTask = true,
  2475. redditLinks = []
  2476. }) {
  2477. try {
  2478. if (!this.#initialized) {
  2479. scripts_echoLog({
  2480. text: i18n('needInit')
  2481. });
  2482. return false;
  2483. }
  2484. const prom = [];
  2485. if (doTask && !globalOptions.doTask.reddit.reddits || !doTask && !globalOptions.undoTask.reddit.reddits) {
  2486. scripts_echoLog({
  2487. type: 'globalOptionsSkip',
  2488. text: 'reddit.reddits'
  2489. });
  2490. } else {
  2491. const realReddits = this.getRealParams('reddits', redditLinks, doTask, link => {
  2492. const name = link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1];
  2493. const userName = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1];
  2494. if (userName) {
  2495. return name || userName;
  2496. }
  2497. return name;
  2498. });
  2499. if (realReddits.length > 0) {
  2500. for (const name of realReddits) {
  2501. prom.push(this.toggleTask({
  2502. name: name,
  2503. doTask: doTask
  2504. }));
  2505. await delay(1e3);
  2506. }
  2507. }
  2508. }
  2509. return await Promise.all(prom).then(() => true);
  2510. } catch (error) {
  2511. throwError(error, 'Reddit.toggle');
  2512. return false;
  2513. }
  2514. }
  2515. }
  2516. const social_Reddit = Reddit;
  2517. class Twitch extends social_Social {
  2518. tasks;
  2519. whiteList;
  2520. #auth = GM_getValue('twitchAuth') || {};
  2521. #cache = GM_getValue('twitchCache') || {};
  2522. #initialized = false;
  2523. #integrityToken;
  2524. constructor() {
  2525. super();
  2526. const defaultTasksTemplate = {
  2527. channels: []
  2528. };
  2529. this.tasks = defaultTasksTemplate;
  2530. this.whiteList = {
  2531. ...defaultTasksTemplate,
  2532. ...GM_getValue('whiteList')?.twitch || {}
  2533. };
  2534. }
  2535. async init() {
  2536. try {
  2537. if (this.#initialized) {
  2538. return true;
  2539. }
  2540. if (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId) {
  2541. if (await this.#updateAuth()) {
  2542. this.#initialized = true;
  2543. return true;
  2544. }
  2545. return false;
  2546. }
  2547. const isVerified = await this.#verifyAuth(true);
  2548. if (isVerified) {
  2549. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2550. this.#initialized = true;
  2551. return true;
  2552. }
  2553. GM_setValue('twitchAuth', null);
  2554. if (await this.#updateAuth()) {
  2555. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2556. this.#initialized = true;
  2557. return true;
  2558. }
  2559. scripts_echoLog({}).error(i18n('initFailed', 'Twitch'));
  2560. return false;
  2561. } catch (error) {
  2562. throwError(error, 'Twitch.init');
  2563. return false;
  2564. }
  2565. }
  2566. async #verifyAuth(isFirst) {
  2567. try {
  2568. const logStatus = scripts_echoLog({
  2569. text: i18n('verifyingAuth', 'Twitch')
  2570. });
  2571. const {
  2572. result,
  2573. statusText,
  2574. status,
  2575. data
  2576. } = await tools_httpRequest({
  2577. url: 'https://gql.twitch.tv/gql',
  2578. method: 'POST',
  2579. dataType: 'json',
  2580. headers: {
  2581. Authorization: `OAuth ${this.#auth.authToken}`,
  2582. 'Client-Id': this.#auth.clientId
  2583. },
  2584. data: '[{"operationName":"FrontPageNew_User","variables":{"limit":1},"extensions":{"persistedQuery":{"version":1,' + '"sha256Hash":"64bd07a2cbaca80699d62636d966cf6395a5d14a1f0a14282067dcb28b13eb11"}}}]'
  2585. });
  2586. if (result === 'Success') {
  2587. if (data?.status === 200 && data.response?.[0]?.data?.currentUser) {
  2588. await this.#integrity(isFirst);
  2589. logStatus.success();
  2590. return true;
  2591. }
  2592. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2593. return false;
  2594. }
  2595. logStatus.error(`${result}:${statusText}(${status})`);
  2596. return false;
  2597. } catch (error) {
  2598. throwError(error, 'Twitch.verifyAuth');
  2599. return false;
  2600. }
  2601. }
  2602. async #integrity(isFirst = true, ct = '') {
  2603. try {
  2604. const logStatus = scripts_echoLog({
  2605. text: i18n('checkingTwitchIntegrity')
  2606. });
  2607. if (isFirst && (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId)) {
  2608. return await this.#updateAuth(false);
  2609. }
  2610. const {
  2611. result,
  2612. statusText,
  2613. status,
  2614. data
  2615. } = await tools_httpRequest({
  2616. url: 'https://gql.twitch.tv/integrity',
  2617. method: 'POST',
  2618. dataType: 'json',
  2619. anonymous: true,
  2620. headers: {
  2621. Origin: 'https://www.twitch.tv',
  2622. Referer: 'https://www.twitch.tv/',
  2623. Authorization: `OAuth ${this.#auth.authToken}`,
  2624. 'Client-Id': this.#auth.clientId,
  2625. 'Client-Version': this.#auth.clientVersion,
  2626. 'X-Device-Id': this.#auth.deviceId,
  2627. 'Client-Session-Id': this.#auth.clientSessionId,
  2628. 'x-kpsdk-ct': ct
  2629. }
  2630. });
  2631. if (result === 'Success') {
  2632. if (!ct && data?.responseHeaders?.['x-kpsdk-ct']) {
  2633. return await this.#integrity(isFirst, data.responseHeaders['x-kpsdk-ct']);
  2634. }
  2635. if (data?.status === 200 && data.response?.token) {
  2636. this.#integrityToken = data.response.token;
  2637. logStatus.success();
  2638. return true;
  2639. }
  2640. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2641. return false;
  2642. }
  2643. logStatus.error(`${result}:${statusText}(${status})`);
  2644. return false;
  2645. } catch (error) {
  2646. throwError(error, 'Twitch.integrity');
  2647. return false;
  2648. }
  2649. }
  2650. async #updateAuth(isFirst = true) {
  2651. try {
  2652. const logStatus = scripts_echoLog({
  2653. text: i18n('updatingAuth', 'Twitch')
  2654. });
  2655. return await new Promise(resolve => {
  2656. const newTab = GM_openInTab('https://www.twitch.tv/#auth', {
  2657. active: true,
  2658. insert: true,
  2659. setParent: true
  2660. });
  2661. newTab.onclose = async () => {
  2662. const auth = GM_getValue('twitchAuth');
  2663. if (auth) {
  2664. this.#auth = auth;
  2665. logStatus.success();
  2666. resolve(await this.#verifyAuth(isFirst));
  2667. } else {
  2668. logStatus.error('Error: Update twitch auth failed!');
  2669. resolve(false);
  2670. }
  2671. };
  2672. });
  2673. } catch (error) {
  2674. throwError(error, 'Twitch.updateAuth');
  2675. return false;
  2676. }
  2677. }
  2678. async #toggleChannel({
  2679. name,
  2680. doTask = true
  2681. }) {
  2682. try {
  2683. if (!doTask && this.whiteList.channels.includes(name)) {
  2684. scripts_echoLog({
  2685. type: 'whiteList',
  2686. text: 'Twitch.unfollowChannel',
  2687. id: name
  2688. });
  2689. return true;
  2690. }
  2691. const channelId = await this.#getChannelId(name);
  2692. if (!channelId) {
  2693. return false;
  2694. }
  2695. const logStatus = scripts_echoLog({
  2696. type: `${doTask ? '' : 'un'}followingTwitchChannel`,
  2697. text: name
  2698. });
  2699. const followData = `[{"operationName":"FollowButton_FollowUser","variables":{"input":{"disableNotifications":false,"targetID":"${channelId}` + '"}},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"800e7346bdf7e5278a3c1d3f21b2b56e2639928f86815677a7126b093b2fdd08"}}}]';
  2700. const unfollowData = `[{"operationName":"FollowButton_UnfollowUser","variables":{"input":{"targetID":"${channelId}"}},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"f7dae976ebf41c755ae2d758546bfd176b4eeb856656098bb40e0a672ca0d880"}}}]';
  2701. const {
  2702. result,
  2703. statusText,
  2704. status,
  2705. data
  2706. } = await tools_httpRequest({
  2707. url: 'https://gql.twitch.tv/gql',
  2708. method: 'POST',
  2709. dataType: 'json',
  2710. anonymous: true,
  2711. headers: {
  2712. Origin: 'https://www.twitch.tv',
  2713. Referer: 'https://www.twitch.tv/',
  2714. Authorization: `OAuth ${this.#auth.authToken}`,
  2715. 'Client-Id': this.#auth.clientId,
  2716. 'Client-Version': this.#auth.clientVersion,
  2717. 'X-Device-Id': this.#auth.deviceId,
  2718. 'Client-Session-Id': this.#auth.clientSessionId,
  2719. 'Client-Integrity': this.#integrityToken
  2720. },
  2721. data: doTask ? followData : unfollowData
  2722. });
  2723. if (result === 'Success') {
  2724. if (data?.status === 200 && data.response?.[0] && !data.response[0].errors) {
  2725. logStatus.success();
  2726. if (doTask) {
  2727. this.tasks.channels = unique([ ...this.tasks.channels, name ]);
  2728. }
  2729. return true;
  2730. }
  2731. logStatus.error(`Error:${data?.response?.[0].errors?.[0]?.message || `${data?.statusText}(${data?.status})`}`);
  2732. return false;
  2733. }
  2734. logStatus.error(`${result}:${statusText}(${status})`);
  2735. return false;
  2736. } catch (error) {
  2737. throwError(error, 'Twitch.toggleChannel');
  2738. return false;
  2739. }
  2740. }
  2741. async #getChannelId(name) {
  2742. try {
  2743. const logStatus = scripts_echoLog({
  2744. type: 'gettingTwitchChannelId',
  2745. text: name
  2746. });
  2747. const channelId = this.#cache[name];
  2748. if (channelId) {
  2749. logStatus.success();
  2750. return channelId;
  2751. }
  2752. const {
  2753. result,
  2754. statusText,
  2755. status,
  2756. data
  2757. } = await tools_httpRequest({
  2758. url: 'https://gql.twitch.tv/gql',
  2759. method: 'POST',
  2760. headers: {
  2761. Authorization: `OAuth ${this.#auth.authToken}`,
  2762. 'Client-Id': this.#auth.clientId
  2763. },
  2764. responseType: 'json',
  2765. data: `[{"operationName":"ActiveWatchParty","variables":{"channelLogin":"${name}"},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"4a8156c97b19e3a36e081cf6d6ddb5dbf9f9b02ae60e4d2ff26ed70aebc80a30"}}}]'
  2766. });
  2767. if (result === 'Success') {
  2768. if (data?.status === 200) {
  2769. const channelId = data.response?.[0]?.data?.user?.id;
  2770. if (channelId) {
  2771. this.#setCache(name, String(channelId));
  2772. logStatus.success();
  2773. return channelId;
  2774. }
  2775. logStatus.error(`Error:${data.statusText}(${data.status})`);
  2776. return false;
  2777. }
  2778. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2779. return false;
  2780. }
  2781. logStatus.error(`${result}:${statusText}(${status})`);
  2782. return false;
  2783. } catch (error) {
  2784. throwError(error, 'Twitch.getChannelId');
  2785. return false;
  2786. }
  2787. }
  2788. async toggle({
  2789. doTask = true,
  2790. channelLinks = []
  2791. }) {
  2792. try {
  2793. if (!this.#initialized) {
  2794. scripts_echoLog({
  2795. text: i18n('needInit')
  2796. });
  2797. return false;
  2798. }
  2799. const prom = [];
  2800. if (doTask && !globalOptions.doTask.twitch.channels || !doTask && !globalOptions.undoTask.twitch.channels) {
  2801. scripts_echoLog({
  2802. type: 'globalOptionsSkip',
  2803. text: 'twitch.channels'
  2804. });
  2805. } else {
  2806. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2]);
  2807. if (realChannels.length > 0) {
  2808. for (const channel of realChannels) {
  2809. prom.push(this.#toggleChannel({
  2810. name: channel,
  2811. doTask: doTask
  2812. }));
  2813. await delay(1e3);
  2814. }
  2815. }
  2816. }
  2817. return Promise.all(prom).then(() => true);
  2818. } catch (error) {
  2819. throwError(error, 'Twitch.toggle');
  2820. return false;
  2821. }
  2822. }
  2823. #setCache(name, id) {
  2824. try {
  2825. this.#cache[name] = id;
  2826. GM_setValue('twitchCache', this.#cache);
  2827. } catch (error) {
  2828. throwError(error, 'Twitch.setCache');
  2829. }
  2830. }
  2831. }
  2832. const social_Twitch = Twitch;
  2833. class Twitter extends social_Social {
  2834. tasks;
  2835. whiteList;
  2836. #verifyId = globalOptions.other.twitterVerifyId;
  2837. #auth = GM_getValue('twitterAuth') || {};
  2838. #cache = GM_getValue('twitterCache') || {};
  2839. #initialized = false;
  2840. constructor() {
  2841. super();
  2842. const defaultTasksTemplate = {
  2843. users: [],
  2844. retweets: [],
  2845. likes: []
  2846. };
  2847. this.tasks = defaultTasksTemplate;
  2848. this.whiteList = {
  2849. ...defaultTasksTemplate,
  2850. ...GM_getValue('whiteList')?.twitter || {}
  2851. };
  2852. }
  2853. async init() {
  2854. try {
  2855. if (this.#initialized) {
  2856. return true;
  2857. }
  2858. if (!this.#auth.ct0) {
  2859. if (await this.#updateAuth()) {
  2860. this.#initialized = true;
  2861. return true;
  2862. }
  2863. return false;
  2864. }
  2865. const isVerified = await this.#verifyAuth();
  2866. if (isVerified) {
  2867. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2868. this.#initialized = true;
  2869. return true;
  2870. }
  2871. GM_setValue('twitterAuth', null);
  2872. if (await this.#updateAuth()) {
  2873. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2874. this.#initialized = true;
  2875. return true;
  2876. }
  2877. scripts_echoLog({}).error(i18n('initFailed', 'Twitter'));
  2878. return false;
  2879. } catch (error) {
  2880. throwError(error, 'Twitter.init');
  2881. return false;
  2882. }
  2883. }
  2884. async #verifyAuth() {
  2885. try {
  2886. return await this.#toggleUser({
  2887. name: 'verify',
  2888. doTask: true,
  2889. verify: true
  2890. });
  2891. } catch (error) {
  2892. throwError(error, 'Twitter.verifyAuth');
  2893. return false;
  2894. }
  2895. }
  2896. async #updateAuth() {
  2897. try {
  2898. const logStatus = scripts_echoLog({
  2899. text: i18n('updatingAuth', 'Twitter')
  2900. });
  2901. return await new Promise(resolve => {
  2902. const newTab = GM_openInTab('https://twitter.com/settings/account?k#auth', {
  2903. active: true,
  2904. insert: true,
  2905. setParent: true
  2906. });
  2907. newTab.onclose = async () => {
  2908. const auth = GM_getValue('twitterAuth');
  2909. if (auth) {
  2910. this.#auth = auth;
  2911. logStatus.success();
  2912. resolve(await this.#verifyAuth());
  2913. } else {
  2914. logStatus.error('Error: Update twitter auth failed!');
  2915. resolve(false);
  2916. }
  2917. };
  2918. });
  2919. } catch (error) {
  2920. throwError(error, 'Twitter.updateToken');
  2921. return false;
  2922. }
  2923. }
  2924. async #toggleUser({
  2925. name,
  2926. doTask = true,
  2927. verify = false
  2928. }) {
  2929. try {
  2930. if (!doTask && !verify && this.whiteList.users.includes(name)) {
  2931. scripts_echoLog({
  2932. type: 'whiteList',
  2933. text: 'Twitter.unfollowUser',
  2934. id: name
  2935. });
  2936. return true;
  2937. }
  2938. const userId = verify ? this.#verifyId : await this.userName2id(name);
  2939. if (!userId) {
  2940. return false;
  2941. }
  2942. const logStatus = verify ? scripts_echoLog({
  2943. text: i18n('verifyingAuth', 'Twitter')
  2944. }) : scripts_echoLog({
  2945. type: `${doTask ? '' : 'un'}followingTwitterUser`,
  2946. text: name
  2947. });
  2948. const {
  2949. result,
  2950. statusText,
  2951. status,
  2952. data
  2953. } = await tools_httpRequest({
  2954. url: `https://api.twitter.com/1.1/friendships/${doTask ? 'create' : 'destroy'}.json`,
  2955. method: 'POST',
  2956. headers: {
  2957. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  2958. 'Content-Type': 'application/x-www-form-urlencoded',
  2959. 'x-csrf-token': this.#auth.ct0
  2960. },
  2961. responseType: 'json',
  2962. data: $.param({
  2963. include_profile_interstitial_type: 1,
  2964. include_blocking: 1,
  2965. include_blocked_by: 1,
  2966. include_followed_by: 1,
  2967. include_want_retweets: 1,
  2968. include_mute_edge: 1,
  2969. include_can_dm: 1,
  2970. include_can_media_tag: 1,
  2971. skip_status: 1,
  2972. id: userId
  2973. })
  2974. });
  2975. if (result === 'Success') {
  2976. if (data?.status === 200) {
  2977. logStatus.success();
  2978. if (doTask && !verify) {
  2979. this.tasks.users = unique([ ...this.tasks.users, name ]);
  2980. }
  2981. return true;
  2982. }
  2983. if (verify && data?.status === 403 && data.response?.errors?.[0]?.code === 158) {
  2984. logStatus.success();
  2985. return true;
  2986. }
  2987. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2988. return false;
  2989. }
  2990. logStatus.error(`${result}:${statusText}(${status})`);
  2991. return false;
  2992. } catch (error) {
  2993. throwError(error, 'Twitter.toggleUser');
  2994. return false;
  2995. }
  2996. }
  2997. async userName2id(name) {
  2998. try {
  2999. const logStatus = scripts_echoLog({
  3000. type: 'gettingTwitterUserId',
  3001. text: name
  3002. });
  3003. const userId = this.#cache[name];
  3004. if (userId) {
  3005. logStatus.success();
  3006. return userId;
  3007. }
  3008. const {
  3009. result,
  3010. statusText,
  3011. status,
  3012. data
  3013. } = await tools_httpRequest({
  3014. url: 'https://api.twitter.com/graphql/mCbpQvZAw6zu_4PvuAUVVQ/UserByScreenName' + `?variables=%7B%22screen_name%22%3A%22${name}%22%2C%22withSafetyModeUserFields%22%3Atrue%2C%22withSuperFollowsUserFields%22%3Atrue%7D`,
  3015. method: 'GET',
  3016. headers: {
  3017. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3018. 'content-type': 'application/json',
  3019. referer: `https://twitter.com/${name}`,
  3020. 'x-csrf-token': this.#auth.ct0
  3021. },
  3022. responseType: 'json'
  3023. });
  3024. if (result === 'Success') {
  3025. if (data?.status === 200) {
  3026. let response = data.response || (typeof data.responseText === 'object' ? data.responseText : null);
  3027. if (!response) {
  3028. try {
  3029. response = JSON.parse(data.responseText);
  3030. } catch (error) {
  3031. response = null;
  3032. }
  3033. }
  3034. const userId = String(response?.data?.user?.result?.rest_id);
  3035. if (userId) {
  3036. this.#setCache(name, userId);
  3037. logStatus.success();
  3038. return userId;
  3039. }
  3040. logStatus.error(`Error:${data.statusText}(${data.status})`);
  3041. return false;
  3042. }
  3043. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3044. return false;
  3045. }
  3046. logStatus.error(`${result}:${statusText}(${status})`);
  3047. return false;
  3048. } catch (error) {
  3049. throwError(error, 'Twitter.getUserId');
  3050. return false;
  3051. }
  3052. }
  3053. async #toggleRetweet({
  3054. retweetId,
  3055. doTask = true
  3056. }) {
  3057. try {
  3058. if (!doTask && this.whiteList.retweets.includes(retweetId)) {
  3059. scripts_echoLog({
  3060. type: 'whiteList',
  3061. text: 'Twitter.unretweet',
  3062. id: retweetId
  3063. });
  3064. return true;
  3065. }
  3066. const logStatus = scripts_echoLog({
  3067. type: `${doTask ? '' : 'un'}retweetting`,
  3068. text: retweetId
  3069. });
  3070. const {
  3071. result,
  3072. statusText,
  3073. status,
  3074. data
  3075. } = await tools_httpRequest({
  3076. url: `https://api.twitter.com/1.1/statuses/${doTask ? '' : 'un'}retweet.json`,
  3077. method: 'POST',
  3078. headers: {
  3079. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3080. 'Content-Type': 'application/x-www-form-urlencoded',
  3081. 'x-csrf-token': this.#auth.ct0
  3082. },
  3083. data: $.param({
  3084. tweet_mode: 'extended',
  3085. id: retweetId
  3086. }),
  3087. responseType: 'json'
  3088. });
  3089. if (result === 'Success') {
  3090. if (data?.status === 200 || data?.status === 403 && data.response?.errors?.[0]?.code === 327) {
  3091. logStatus.success();
  3092. if (doTask) {
  3093. this.tasks.retweets = unique([ ...this.tasks.retweets, retweetId ]);
  3094. }
  3095. return true;
  3096. }
  3097. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3098. return false;
  3099. }
  3100. logStatus.error(`${result}:${statusText}(${status})`);
  3101. return false;
  3102. } catch (error) {
  3103. throwError(error, 'Twitter.toggleRetweet');
  3104. return false;
  3105. }
  3106. }
  3107. async toggle({
  3108. doTask = true,
  3109. userLinks = [],
  3110. retweetLinks = []
  3111. }) {
  3112. try {
  3113. if (!this.#initialized) {
  3114. scripts_echoLog({
  3115. text: i18n('needInit')
  3116. });
  3117. return false;
  3118. }
  3119. const prom = [];
  3120. if (doTask && !globalOptions.doTask.twitter.users || !doTask && !globalOptions.undoTask.twitter.users) {
  3121. scripts_echoLog({
  3122. type: 'globalOptionsSkip',
  3123. text: 'twitter.users'
  3124. });
  3125. } else {
  3126. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/twitter\.com\/(.+)/)?.[1]);
  3127. if (realUsers.length > 0) {
  3128. for (const user of realUsers) {
  3129. prom.push(this.#toggleUser({
  3130. name: user,
  3131. doTask: doTask
  3132. }));
  3133. await delay(1e3);
  3134. }
  3135. }
  3136. }
  3137. if (doTask && !globalOptions.doTask.twitter.retweets || !doTask && !globalOptions.undoTask.twitter.retweets) {
  3138. scripts_echoLog({
  3139. type: 'globalOptionsSkip',
  3140. text: 'twitter.retweets'
  3141. });
  3142. } else {
  3143. const realRetweets = this.getRealParams('retweets', retweetLinks, doTask, link => link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1]);
  3144. if (realRetweets.length > 0) {
  3145. for (const retweet of realRetweets) {
  3146. prom.push(this.#toggleRetweet({
  3147. retweetId: retweet,
  3148. doTask: doTask
  3149. }));
  3150. await delay(1e3);
  3151. }
  3152. }
  3153. }
  3154. return Promise.all(prom).then(() => true);
  3155. } catch (error) {
  3156. throwError(error, 'Twitter.toggle');
  3157. return false;
  3158. }
  3159. }
  3160. #setCache(name, id) {
  3161. try {
  3162. this.#cache[name] = id;
  3163. GM_setValue('twitterCache', this.#cache);
  3164. } catch (error) {
  3165. throwError(error, 'Twitter.setCache');
  3166. }
  3167. }
  3168. }
  3169. const social_Twitter = Twitter;
  3170. class Vk extends social_Social {
  3171. tasks;
  3172. whiteList;
  3173. #username = '';
  3174. #cache = GM_getValue('vkCache') || {};
  3175. #initialized = false;
  3176. constructor() {
  3177. super();
  3178. const defaultTasksTemplate = {
  3179. names: []
  3180. };
  3181. this.tasks = defaultTasksTemplate;
  3182. this.whiteList = {
  3183. ...defaultTasksTemplate,
  3184. ...GM_getValue('whiteList')?.vk || {}
  3185. };
  3186. }
  3187. async init() {
  3188. try {
  3189. if (this.#initialized) {
  3190. return true;
  3191. }
  3192. const isVerified = await this.#verifyAuth();
  3193. if (isVerified) {
  3194. scripts_echoLog({}).success(i18n('initSuccess', 'Vk'));
  3195. this.#initialized = true;
  3196. return true;
  3197. }
  3198. scripts_echoLog({}).error(i18n('initFailed', 'Vk'));
  3199. return false;
  3200. } catch (error) {
  3201. throwError(error, 'Vk.init');
  3202. return false;
  3203. }
  3204. }
  3205. async #verifyAuth() {
  3206. try {
  3207. const logStatus = scripts_echoLog({
  3208. text: i18n('verifyAuth', 'Vk')
  3209. });
  3210. const {
  3211. result,
  3212. statusText,
  3213. status,
  3214. data
  3215. } = await tools_httpRequest({
  3216. url: 'https://vk.com/im',
  3217. method: 'GET'
  3218. });
  3219. if (result === 'Success') {
  3220. if (data?.finalUrl.includes('vk.com/login')) {
  3221. logStatus.error(`Error:${i18n('loginVk')}`, true);
  3222. return false;
  3223. }
  3224. if (data?.status === 200) {
  3225. this.#username = data.responseText.match(/TopNavBtn__profileLink" href="\/(.*?)"/)?.[1] || '';
  3226. logStatus.success();
  3227. return true;
  3228. }
  3229. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3230. return false;
  3231. }
  3232. logStatus.error(`${result}:${statusText}(${status})`);
  3233. return false;
  3234. } catch (error) {
  3235. throwError(error, 'Vk.verifyAuth');
  3236. return false;
  3237. }
  3238. }
  3239. async #toggleGroup(name, dataParam, doTask = true) {
  3240. try {
  3241. const logStatus = scripts_echoLog({
  3242. type: doTask ? 'joiningVkGroup' : 'leavingVkGroup',
  3243. text: name
  3244. });
  3245. if (dataParam.groupAct === 'enter' && !doTask || dataParam.groupAct === 'leave' && doTask) {
  3246. logStatus.success();
  3247. return true;
  3248. }
  3249. const reqData = {
  3250. act: doTask ? 'enter' : 'leave',
  3251. al: 1,
  3252. gid: dataParam.groupId,
  3253. hash: dataParam.groupHash
  3254. };
  3255. if (doTask) {
  3256. reqData.context = '_';
  3257. }
  3258. const {
  3259. result,
  3260. statusText,
  3261. status,
  3262. data
  3263. } = await tools_httpRequest({
  3264. url: 'https://vk.com/al_groups.php',
  3265. method: 'POST',
  3266. headers: {
  3267. origin: 'https://vk.com',
  3268. referer: `https://vk.com/${name}`,
  3269. 'content-type': 'application/x-www-form-urlencoded'
  3270. },
  3271. data: $.param(reqData)
  3272. });
  3273. if (result === 'Success') {
  3274. if (data?.status === 200) {
  3275. logStatus.success();
  3276. if (doTask) {
  3277. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3278. }
  3279. return true;
  3280. }
  3281. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3282. return false;
  3283. }
  3284. logStatus.error(`${result}:${statusText}(${status})`);
  3285. return false;
  3286. } catch (error) {
  3287. throwError(error, 'Vk.toggleGroup');
  3288. return false;
  3289. }
  3290. }
  3291. async #togglePublic(name, dataParam, doTask = true) {
  3292. try {
  3293. const logStatus = scripts_echoLog({
  3294. type: doTask ? 'joiningVkPublic' : 'leavingVkPublic',
  3295. text: name
  3296. });
  3297. if (dataParam.publicJoined && doTask || !dataParam.publicJoined && !doTask) {
  3298. logStatus.success();
  3299. return true;
  3300. }
  3301. const {
  3302. result,
  3303. statusText,
  3304. status,
  3305. data
  3306. } = await tools_httpRequest({
  3307. url: 'https://vk.com/al_public.php',
  3308. method: 'POST',
  3309. headers: {
  3310. origin: 'https://vk.com',
  3311. referer: `https://vk.com/${name}`,
  3312. 'content-type': 'application/x-www-form-urlencoded'
  3313. },
  3314. data: $.param({
  3315. act: doTask ? 'a_enter' : 'a_leave',
  3316. al: 1,
  3317. pid: dataParam.publicPid,
  3318. hash: dataParam.publicHash
  3319. })
  3320. });
  3321. if (result === 'Success') {
  3322. if (data?.status === 200) {
  3323. logStatus.success();
  3324. if (doTask) {
  3325. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3326. }
  3327. return true;
  3328. }
  3329. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3330. return false;
  3331. }
  3332. logStatus.error(`${result}:${statusText}(${status})`);
  3333. return false;
  3334. } catch (error) {
  3335. throwError(error, 'Vk.togglePublic');
  3336. return false;
  3337. }
  3338. }
  3339. async #sendWall(name) {
  3340. try {
  3341. const logStatus = scripts_echoLog({
  3342. type: 'sendingVkWall',
  3343. text: name
  3344. });
  3345. const {
  3346. result,
  3347. statusText,
  3348. status,
  3349. data
  3350. } = await tools_httpRequest({
  3351. url: 'https://vk.com/like.php',
  3352. method: 'POST',
  3353. headers: {
  3354. origin: 'https://vk.com',
  3355. referer: `https://vk.com/${name}`,
  3356. 'content-type': 'application/x-www-form-urlencoded'
  3357. },
  3358. data: $.param({
  3359. act: 'publish_box',
  3360. al: 1,
  3361. object: name
  3362. })
  3363. });
  3364. if (result === 'Success') {
  3365. if (data?.status === 200) {
  3366. const hash = data.responseText.match(/shHash:[\s]*'(.*?)'/)?.[1];
  3367. if (hash) {
  3368. const {
  3369. result: resultR,
  3370. statusText: statusTextR,
  3371. status: statusR,
  3372. data: dataR
  3373. } = await tools_httpRequest({
  3374. url: 'https://vk.com/like.php',
  3375. method: 'POST',
  3376. headers: {
  3377. origin: 'https://vk.com',
  3378. referer: `https://vk.com/${name}`,
  3379. 'content-type': 'application/x-www-form-urlencoded'
  3380. },
  3381. data: $.param({
  3382. Message: '',
  3383. act: 'a_do_publish',
  3384. al: 1,
  3385. close_comments: 0,
  3386. friends_only: 0,
  3387. from: 'box',
  3388. hash: hash,
  3389. list: '',
  3390. mark_as_ads: 0,
  3391. mute_notifications: 0,
  3392. object: name,
  3393. ret_data: 1,
  3394. to: 0
  3395. })
  3396. });
  3397. if (resultR === 'Success') {
  3398. if (dataR?.status === 200) {
  3399. const jsonData = JSON.parse(dataR.responseText?.replace('\x3c!--', '') || '{}');
  3400. if (jsonData?.payload?.[1]?.[1]?.share_my === true) {
  3401. logStatus.success();
  3402. const postId = String(jsonData?.payload?.[1]?.[1]?.post_id);
  3403. const ownerId = String(jsonData?.payload?.[1]?.[1]?.owner_id);
  3404. if (postId && ownerId) {
  3405. this.#setCache(name, `${ownerId}_${postId}`);
  3406. }
  3407. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3408. return true;
  3409. }
  3410. }
  3411. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  3412. return false;
  3413. }
  3414. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  3415. return false;
  3416. }
  3417. logStatus.error('Error: Get "hash" failed');
  3418. return false;
  3419. }
  3420. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3421. return false;
  3422. }
  3423. logStatus.error(`${result}:${statusText}(${status})`);
  3424. return false;
  3425. } catch (error) {
  3426. throwError(error, 'Vk.sendWall');
  3427. return false;
  3428. }
  3429. }
  3430. async #deleteWall(name, dataParams) {
  3431. try {
  3432. const logStatus = scripts_echoLog({
  3433. type: 'deletingVkWall',
  3434. text: name
  3435. });
  3436. const {
  3437. result,
  3438. statusText,
  3439. status,
  3440. data
  3441. } = await tools_httpRequest({
  3442. url: 'https://vk.com/al_wall.php?act=delete',
  3443. method: 'POST',
  3444. headers: {
  3445. origin: 'https://vk.com',
  3446. referer: `https://vk.com/${this.#username}?w=wall${this.#cache[name]}%2Fall`,
  3447. 'content-type': 'application/x-www-form-urlencoded'
  3448. },
  3449. data: $.param({
  3450. act: 'delete',
  3451. al: 1,
  3452. confirm: 0,
  3453. from: 'wkview',
  3454. hash: dataParams.wallHash,
  3455. post: this.#cache[name]
  3456. })
  3457. });
  3458. if (result === 'Success') {
  3459. if (data?.status === 200) {
  3460. const jsonData = JSON.parse(data.responseText?.replace('\x3c!--', '') || '{}');
  3461. if (jsonData?.payload?.[1]?.[1]) {
  3462. logStatus.success();
  3463. return true;
  3464. }
  3465. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3466. return false;
  3467. }
  3468. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3469. return false;
  3470. }
  3471. logStatus.error(`${result}:${statusText}(${status})`);
  3472. return false;
  3473. } catch (error) {
  3474. throwError(error, 'Vk.deleteWall');
  3475. return false;
  3476. }
  3477. }
  3478. async #getId(name, doTask) {
  3479. try {
  3480. let url = `https://vk.com/${name}`;
  3481. if (/^wall-/.test(name)) {
  3482. if (doTask) {
  3483. return {
  3484. type: 'sendWall'
  3485. };
  3486. }
  3487. if (!this.#cache[name]) {
  3488. return {
  3489. type: 'unSupport'
  3490. };
  3491. }
  3492. url = `https://vk.com/${this.#username}?w=wall${this.#cache[name]}`;
  3493. }
  3494. const logStatus = scripts_echoLog({
  3495. type: 'gettingVkId',
  3496. text: name
  3497. });
  3498. const {
  3499. result,
  3500. statusText,
  3501. status,
  3502. data
  3503. } = await tools_httpRequest({
  3504. url: url,
  3505. method: 'GET'
  3506. });
  3507. if (result === 'Success') {
  3508. if (data?.status === 200) {
  3509. const [ , groupAct, groupId, , groupHash ] = data.responseText.match(/Groups.(enter|leave)\(.*?,.*?([\d]+?), (&#39;|')(.*?)(&#39;|')/) || [];
  3510. const publicHash = data.responseText.match(/"enterHash":"(.*?)"/)?.[1];
  3511. const publicPid = data.responseText.match(/"public_id":([\d]+?),/)?.[1];
  3512. const publicJoined = !data.responseText.includes('Public.subscribe');
  3513. if (groupAct && groupId && groupHash) {
  3514. logStatus.success();
  3515. return {
  3516. groupAct: groupAct,
  3517. groupId: groupId,
  3518. groupHash: groupHash,
  3519. type: 'group'
  3520. };
  3521. } else if (publicHash && publicPid) {
  3522. logStatus.success();
  3523. return {
  3524. publicHash: publicHash,
  3525. publicPid: publicPid,
  3526. publicJoined: publicJoined,
  3527. type: 'public'
  3528. };
  3529. } else if (data.responseText.includes('wall.deletePost') && !doTask) {
  3530. const wallHash = data.responseText.match(/wall\.deletePost\(this, '.*?', '(.*?)'\)/)?.[1];
  3531. if (wallHash) {
  3532. logStatus.success();
  3533. return {
  3534. type: 'deleteWall',
  3535. wallHash: wallHash
  3536. };
  3537. }
  3538. } else if (name.includes('wall') && doTask) {
  3539. logStatus.success();
  3540. return {
  3541. type: 'sendWall'
  3542. };
  3543. }
  3544. logStatus.error('Error: Parameters not found!');
  3545. return false;
  3546. }
  3547. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3548. return false;
  3549. }
  3550. logStatus.error(`${result}:${statusText}(${status})`);
  3551. return false;
  3552. } catch (error) {
  3553. throwError(error, 'Vk.getId');
  3554. return false;
  3555. }
  3556. }
  3557. async #toggleVk({
  3558. name,
  3559. doTask = true
  3560. }) {
  3561. try {
  3562. if (!doTask && this.whiteList.names.includes(name)) {
  3563. scripts_echoLog({
  3564. type: 'whiteList',
  3565. text: 'Vk.undoTask',
  3566. id: name
  3567. });
  3568. return true;
  3569. }
  3570. const formatName = name.replace(/\/$/, '');
  3571. const data = await this.#getId(formatName, doTask);
  3572. if (!data) {
  3573. return false;
  3574. }
  3575. switch (data.type) {
  3576. case 'group':
  3577. return await this.#toggleGroup(formatName, data, doTask);
  3578.  
  3579. case 'public':
  3580. return await this.#togglePublic(formatName, data, doTask);
  3581.  
  3582. case 'sendWall':
  3583. return doTask ? await this.#sendWall(formatName) : true;
  3584.  
  3585. case 'deleteWall':
  3586. return doTask ? true : await this.#deleteWall(formatName, data);
  3587.  
  3588. default:
  3589. return false;
  3590. }
  3591. } catch (error) {
  3592. throwError(error, 'Vk.toggleVk');
  3593. return false;
  3594. }
  3595. }
  3596. async toggle({
  3597. doTask = true,
  3598. nameLinks = []
  3599. }) {
  3600. try {
  3601. if (!this.#initialized) {
  3602. scripts_echoLog({
  3603. text: i18n('needInit')
  3604. });
  3605. return false;
  3606. }
  3607. const prom = [];
  3608. if (doTask && !globalOptions.doTask.vk.names || !doTask && !globalOptions.undoTask.vk.names) {
  3609. scripts_echoLog({
  3610. type: 'globalOptionsSkip',
  3611. text: 'vk.names'
  3612. });
  3613. } else {
  3614. const realNames = this.getRealParams('names', nameLinks, doTask, link => link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1]);
  3615. if (realNames.length > 0) {
  3616. for (const name of realNames) {
  3617. prom.push(this.#toggleVk({
  3618. name: name,
  3619. doTask: doTask
  3620. }));
  3621. await delay(1e3);
  3622. }
  3623. }
  3624. }
  3625. return Promise.all(prom).then(() => true);
  3626. } catch (error) {
  3627. throwError(error, 'Vk.toggle');
  3628. return false;
  3629. }
  3630. }
  3631. #setCache(name, postId) {
  3632. try {
  3633. this.#cache[name] = postId;
  3634. GM_setValue('vkCache', this.#cache);
  3635. } catch (error) {
  3636. throwError(error, 'Vk.setCache');
  3637. }
  3638. }
  3639. }
  3640. const social_Vk = Vk;
  3641. const getInfo = async function(link, type) {
  3642. try {
  3643. const logStatus = scripts_echoLog({
  3644. text: i18n('gettingYtbToken')
  3645. });
  3646. const {
  3647. result,
  3648. statusText,
  3649. status,
  3650. data
  3651. } = await tools_httpRequest({
  3652. url: link,
  3653. method: 'GET'
  3654. });
  3655. if (result === 'Success') {
  3656. if (data?.status === 200) {
  3657. if (data.responseText.includes('accounts.google.com/ServiceLogin?service=youtube')) {
  3658. logStatus.error(`Error:${i18n('loginYtb')}`, true);
  3659. return {
  3660. needLogin: true
  3661. };
  3662. }
  3663. const apiKey = data.responseText.match(/"INNERTUBE_API_KEY":"(.*?)"/)?.[1];
  3664. const context = (data.responseText.match(/\(\{"INNERTUBE_CONTEXT":([\w\W]*?)\}\)/) || data.responseText.match(/"INNERTUBE_CONTEXT":([\w\W]*?\}),"INNERTUBE/))?.[1] || '{}';
  3665. const {
  3666. client,
  3667. request
  3668. } = JSON.parse(context);
  3669. if (apiKey && client && request) {
  3670. client.hl = 'en';
  3671. if (type === 'channel') {
  3672. const channelId = data.responseText.match(/"channelId":"(.+?)"/)?.[1];
  3673. if (channelId) {
  3674. logStatus.success();
  3675. return {
  3676. params: {
  3677. apiKey: apiKey,
  3678. client: client,
  3679. request: request,
  3680. channelId: channelId
  3681. }
  3682. };
  3683. }
  3684. logStatus.error('Error: Get "channelId" failed!');
  3685. return {};
  3686. } else if (type === 'likeVideo') {
  3687. const videoId = data.responseText.match(/<link rel="shortlinkUrl" href="https:\/\/youtu\.be\/(.*?)">/)?.[1];
  3688. const likeParams = data.responseText.match(/"likeParams":"(.*?)"/)?.[1];
  3689. if (videoId) {
  3690. logStatus.success();
  3691. return {
  3692. params: {
  3693. apiKey: apiKey,
  3694. client: client,
  3695. request: request,
  3696. videoId: videoId,
  3697. likeParams: likeParams
  3698. }
  3699. };
  3700. }
  3701. logStatus.error('Error: Get "videoId" failed!');
  3702. return {};
  3703. }
  3704. logStatus.error('Error: Unknown type');
  3705. return {};
  3706. }
  3707. logStatus.error('Error: Parameter "apiKey" not found!');
  3708. return {};
  3709. }
  3710. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3711. return {};
  3712. }
  3713. logStatus.error(`${result}:${statusText}(${status})`);
  3714. return {};
  3715. } catch (error) {
  3716. throwError(error, 'Youtube.getInfo');
  3717. return {};
  3718. }
  3719. };
  3720. class Youtube extends social_Social {
  3721. tasks;
  3722. whiteList;
  3723. #auth = GM_getValue('youtubeAuth') || {};
  3724. #initialized = false;
  3725. #verifyChannel = `https://www.youtube.com/channel/${globalOptions.other.youtubeVerifyChannel}`;
  3726. constructor() {
  3727. super();
  3728. const defaultTasksTemplate = {
  3729. channels: [],
  3730. likes: []
  3731. };
  3732. this.tasks = defaultTasksTemplate;
  3733. this.whiteList = {
  3734. ...defaultTasksTemplate,
  3735. ...GM_getValue('whiteList')?.youtube || {}
  3736. };
  3737. }
  3738. async init() {
  3739. try {
  3740. if (this.#initialized) {
  3741. return true;
  3742. }
  3743. if (!this.#auth.PAPISID) {
  3744. if (await this.#updateAuth()) {
  3745. this.#initialized = true;
  3746. return true;
  3747. }
  3748. return false;
  3749. }
  3750. const isVerified = await this.#verifyAuth();
  3751. if (isVerified) {
  3752. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3753. this.#initialized = true;
  3754. return true;
  3755. }
  3756. GM_setValue('youtubeAuth', null);
  3757. if (await this.#updateAuth()) {
  3758. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3759. this.#initialized = true;
  3760. return true;
  3761. }
  3762. scripts_echoLog({}).error(i18n('initFailed', 'Youtube'));
  3763. return false;
  3764. } catch (error) {
  3765. throwError(error, 'Youtube.init');
  3766. return false;
  3767. }
  3768. }
  3769. async #verifyAuth() {
  3770. try {
  3771. return await this.#toggleChannel({
  3772. link: this.#verifyChannel,
  3773. doTask: true,
  3774. verify: true
  3775. });
  3776. } catch (error) {
  3777. throwError(error, 'Youtube.verifyAuth');
  3778. return false;
  3779. }
  3780. }
  3781. async #updateAuth() {
  3782. try {
  3783. const logStatus = scripts_echoLog({
  3784. text: i18n('updatingAuth', 'Youtube')
  3785. });
  3786. return await new Promise(resolve => {
  3787. const newTab = GM_openInTab('https://www.youtube.com/#auth', {
  3788. active: true,
  3789. insert: true,
  3790. setParent: true
  3791. });
  3792. newTab.onclose = async () => {
  3793. const auth = GM_getValue('youtubeAuth');
  3794. if (auth) {
  3795. this.#auth = auth;
  3796. logStatus.success();
  3797. this.#verifyAuth().then(result => {
  3798. resolve(result);
  3799. });
  3800. } else {
  3801. logStatus.error('Error: Update youtube auth failed!');
  3802. resolve(false);
  3803. }
  3804. };
  3805. });
  3806. } catch (error) {
  3807. throwError(error, 'Discord.updateAuth');
  3808. return false;
  3809. }
  3810. }
  3811. #getInfo(link, type) {
  3812. return getInfo(link, type);
  3813. }
  3814. async #toggleChannel({
  3815. link,
  3816. doTask = true,
  3817. verify = false
  3818. }) {
  3819. try {
  3820. const {
  3821. params,
  3822. needLogin
  3823. } = await this.#getInfo(link, 'channel');
  3824. const {
  3825. apiKey,
  3826. client,
  3827. request,
  3828. channelId
  3829. } = params || {};
  3830. if (needLogin) {
  3831. scripts_echoLog({
  3832. html: i18n('loginYtb')
  3833. });
  3834. return false;
  3835. }
  3836. if (!(apiKey && client && request && channelId)) {
  3837. scripts_echoLog({
  3838. text: '"getYtbToken" failed'
  3839. });
  3840. return false;
  3841. }
  3842. if (!doTask && !verify && this.whiteList.channels.includes(channelId)) {
  3843. scripts_echoLog({
  3844. type: 'whiteList',
  3845. text: 'Youtube.unfollowChannel',
  3846. id: channelId
  3847. });
  3848. return true;
  3849. }
  3850. const logStatus = verify ? scripts_echoLog({
  3851. text: i18n('verifyingAuth', 'Youtube')
  3852. }) : scripts_echoLog({
  3853. type: doTask ? 'followingYtbChannel' : 'unfollowingYtbChannel',
  3854. text: channelId
  3855. });
  3856. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3857. const {
  3858. result,
  3859. statusText,
  3860. status,
  3861. data
  3862. } = await tools_httpRequest({
  3863. url: `https://www.youtube.com/youtubei/v1/subscription/${doTask ? '' : 'un'}subscribe?key=${apiKey}&prettyPrint=false`,
  3864. method: 'POST',
  3865. headers: {
  3866. origin: 'https://www.youtube.com',
  3867. referer: `https://www.youtube.com/channel/${channelId}`,
  3868. 'content-type': 'application/json',
  3869. 'x-goog-authuser': '0',
  3870. 'x-goog-visitor-id': client?.visitorData,
  3871. 'x-origin': 'https://www.youtube.com',
  3872. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  3873. },
  3874. data: JSON.stringify({
  3875. context: {
  3876. client: client,
  3877. request: {
  3878. sessionId: request?.sessionId,
  3879. internalExperimentFlags: [],
  3880. consistencyTokenJars: []
  3881. },
  3882. user: {}
  3883. },
  3884. channelIds: [ channelId ],
  3885. params: doTask ? 'EgIIAhgA' : 'CgIIAhgA'
  3886. })
  3887. });
  3888. if (result === 'Success') {
  3889. if (data?.status === 200) {
  3890. if (doTask && (/"subscribed":true/.test(data.responseText) || data.responseText.includes('The subscription already exists')) || !doTask && /"subscribed":false/.test(data.responseText)) {
  3891. logStatus.success();
  3892. if (doTask && !verify) {
  3893. this.tasks.channels = unique([ ...this.tasks.channels, link ]);
  3894. }
  3895. return true;
  3896. }
  3897. if (verify && data.responseText.includes('You may not subscribe to yourself')) {
  3898. logStatus.success();
  3899. return true;
  3900. }
  3901. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  3902. return false;
  3903. }
  3904. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3905. return false;
  3906. }
  3907. logStatus.error(`${result}:${statusText}(${status})`);
  3908. return false;
  3909. } catch (error) {
  3910. throwError(error, 'Youtube.toggleChannel');
  3911. return false;
  3912. }
  3913. }
  3914. async #toggleLikeVideo({
  3915. link,
  3916. doTask = true
  3917. }) {
  3918. try {
  3919. const {
  3920. params,
  3921. needLogin
  3922. } = await this.#getInfo(link, 'likeVideo');
  3923. const {
  3924. apiKey,
  3925. client,
  3926. request,
  3927. videoId,
  3928. likeParams
  3929. } = params || {};
  3930. if (needLogin) {
  3931. scripts_echoLog({
  3932. html: `${i18n('loginYtb')}`
  3933. });
  3934. return false;
  3935. }
  3936. if (!(apiKey && client && request && videoId && likeParams)) {
  3937. scripts_echoLog({
  3938. text: '"getYtbToken" failed'
  3939. });
  3940. return false;
  3941. }
  3942. if (!doTask && this.whiteList.likes.includes(videoId)) {
  3943. scripts_echoLog({
  3944. type: 'whiteList',
  3945. text: 'Youtube.unlikeVideo',
  3946. id: videoId
  3947. });
  3948. return true;
  3949. }
  3950. const logStatus = scripts_echoLog({
  3951. type: doTask ? 'likingYtbVideo' : 'unlikingYtbVideo',
  3952. text: videoId
  3953. });
  3954. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3955. const likeVideoData = {
  3956. context: {
  3957. client: client,
  3958. request: {
  3959. sessionId: request.sessionId,
  3960. internalExperimentFlags: [],
  3961. consistencyTokenJars: []
  3962. },
  3963. user: {}
  3964. },
  3965. target: {
  3966. videoId: videoId
  3967. }
  3968. };
  3969. if (doTask) {
  3970. if (likeParams) {
  3971. likeVideoData.params = likeParams;
  3972. } else {
  3973. logStatus.error('Empty likeParams');
  3974. return false;
  3975. }
  3976. }
  3977. const {
  3978. result,
  3979. statusText,
  3980. status,
  3981. data
  3982. } = await tools_httpRequest({
  3983. url: `https://www.youtube.com/youtubei/v1/like/${doTask ? '' : 'remove'}like?key=${apiKey}`,
  3984. method: 'POST',
  3985. headers: {
  3986. origin: 'https://www.youtube.com',
  3987. referer: `https://www.youtube.com/watch?v=${videoId}`,
  3988. 'content-type': 'application/json',
  3989. 'x-goog-authuser': '0',
  3990. 'x-goog-visitor-id': client.visitorData,
  3991. 'x-origin': 'https://www.youtube.com',
  3992. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  3993. },
  3994. data: JSON.stringify(likeVideoData)
  3995. });
  3996. if (result === 'Success') {
  3997. if (data?.status === 200) {
  3998. if (doTask && data.responseText.includes('Added to Liked videos') || !doTask && (data.responseText.includes('Removed from Liked videos') || data.responseText.includes('Dislike removed'))) {
  3999. logStatus.success();
  4000. if (doTask) {
  4001. this.tasks.likes = unique([ ...this.tasks.likes, link ]);
  4002. }
  4003. return true;
  4004. }
  4005. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  4006. return false;
  4007. }
  4008. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4009. return false;
  4010. }
  4011. logStatus.error(`${result}:${statusText}(${status})`);
  4012. return false;
  4013. } catch (error) {
  4014. throwError(error, 'Youtube.toggleLikeVideo');
  4015. return false;
  4016. }
  4017. }
  4018. async toggle({
  4019. doTask = true,
  4020. channelLinks = [],
  4021. videoLinks = []
  4022. }) {
  4023. try {
  4024. if (!this.#initialized) {
  4025. scripts_echoLog({
  4026. text: i18n('needInit')
  4027. });
  4028. return false;
  4029. }
  4030. const prom = [];
  4031. if (doTask && !globalOptions.doTask.youtube.channels || !doTask && !globalOptions.undoTask.youtube.channels) {
  4032. scripts_echoLog({
  4033. type: 'globalOptionsSkip',
  4034. text: 'youtube.channels'
  4035. });
  4036. } else {
  4037. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => {
  4038. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4039. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4040. }
  4041. return link;
  4042. });
  4043. if (realChannels.length > 0) {
  4044. for (const channel of realChannels) {
  4045. prom.push(this.#toggleChannel({
  4046. link: channel,
  4047. doTask: doTask
  4048. }));
  4049. await delay(1e3);
  4050. }
  4051. }
  4052. }
  4053. if (doTask && !globalOptions.doTask.youtube.likes || !doTask && !globalOptions.undoTask.youtube.likes) {
  4054. scripts_echoLog({
  4055. type: 'globalOptionsSkip',
  4056. text: 'youtube.likes'
  4057. });
  4058. } else {
  4059. const realLikes = this.getRealParams('likes', videoLinks, doTask, link => {
  4060. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4061. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4062. }
  4063. return link;
  4064. });
  4065. if (realLikes.length > 0) {
  4066. for (const video of realLikes) {
  4067. prom.push(this.#toggleLikeVideo({
  4068. link: video,
  4069. doTask: doTask
  4070. }));
  4071. await delay(1e3);
  4072. }
  4073. }
  4074. }
  4075. return Promise.all(prom).then(() => true);
  4076. } catch (error) {
  4077. throwError(error, 'Youtube.toggle');
  4078. return false;
  4079. }
  4080. }
  4081. }
  4082. class SteamASF {
  4083. #asfOptions;
  4084. #botName = 'asf';
  4085. #groupInfo;
  4086. async init() {
  4087. try {
  4088. const asfCommandsUrl = new URL('/Api/Command/', globalOptions.ASF.AsfIpcUrl);
  4089. this.#asfOptions = {
  4090. url: asfCommandsUrl.href,
  4091. method: 'POST',
  4092. responseType: 'json',
  4093. headers: {
  4094. accept: 'application/json',
  4095. 'Content-Type': 'application/json',
  4096. Host: asfCommandsUrl.host,
  4097. Origin: asfCommandsUrl.origin,
  4098. Referer: asfCommandsUrl.href,
  4099. Authentication: globalOptions.ASF.AsfIpcPassword
  4100. }
  4101. };
  4102. if (globalOptions.ASF.AsfBotname) {
  4103. this.#botName = globalOptions.ASF.AsfBotname;
  4104. }
  4105. const logStatus = scripts_echoLog({
  4106. text: i18n('initingASF')
  4107. });
  4108. const {
  4109. result,
  4110. statusText,
  4111. status,
  4112. data
  4113. } = await tools_httpRequest({
  4114. ...this.#asfOptions,
  4115. data: '{"Command":"!stats"}'
  4116. });
  4117. if (result === 'Success') {
  4118. if (data?.response?.Success === true && data.response.Message === 'OK' && data.response.Result) {
  4119. logStatus.success();
  4120. return true;
  4121. }
  4122. if (data?.response?.Result || data?.response?.Message) {
  4123. logStatus.error(data?.response?.Result || data.response.Message);
  4124. return false;
  4125. }
  4126. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4127. return false;
  4128. }
  4129. logStatus.error(`${result}:${statusText}(${status})`);
  4130. return false;
  4131. } catch (error) {
  4132. throwError(error, 'SteamASF.init');
  4133. return false;
  4134. }
  4135. }
  4136. async joinGroup(groupName) {
  4137. try {
  4138. const logStatus = scripts_echoLog({
  4139. type: 'joiningSteamGroup',
  4140. text: groupName
  4141. });
  4142. const {
  4143. result,
  4144. statusText,
  4145. status,
  4146. data
  4147. } = await tools_httpRequest({
  4148. ...this.#asfOptions,
  4149. data: JSON.stringify({
  4150. Command: `!JOINGROUP ${this.#botName} ${groupName}`
  4151. })
  4152. });
  4153. if (result === 'Success') {
  4154. if (data?.status === 200 && [ '已加入', '已申请', 'Joined', 'Applied', 'Присоединился', 'costs' ].find(text => data.response?.Result?.includes(text))) {
  4155. logStatus.success();
  4156. return true;
  4157. }
  4158. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4159. return false;
  4160. }
  4161. logStatus.error(`${result}:${statusText}(${status})`);
  4162. return false;
  4163. } catch (error) {
  4164. throwError(error, 'SteamASF.joinGroup');
  4165. return false;
  4166. }
  4167. }
  4168. async leaveGroup(groupName) {
  4169. try {
  4170. if (!this.#groupInfo) {
  4171. if (!await this.#getGroupId()) {
  4172. return false;
  4173. }
  4174. }
  4175. const groupId = await this.#groupInfo[groupName];
  4176. if (!groupId) {
  4177. return false;
  4178. }
  4179. const logStatus = scripts_echoLog({
  4180. type: 'leavingSteamGroup',
  4181. text: groupName
  4182. });
  4183. const {
  4184. result,
  4185. statusText,
  4186. status,
  4187. data
  4188. } = await tools_httpRequest({
  4189. ...this.#asfOptions,
  4190. data: JSON.stringify({
  4191. Command: `!LEAVEGROUP ${this.#botName} ${groupId}`
  4192. })
  4193. });
  4194. if (result === 'Success') {
  4195. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4196. logStatus.success();
  4197. return true;
  4198. }
  4199. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4200. return false;
  4201. }
  4202. logStatus.error(`${result}:${statusText}(${status})`);
  4203. return false;
  4204. } catch (error) {
  4205. throwError(error, 'SteamASF.leaveGroup');
  4206. return false;
  4207. }
  4208. }
  4209. async #getGroupId() {
  4210. try {
  4211. const logStatus = scripts_echoLog({
  4212. type: 'gettingSteamGroupId',
  4213. text: 'All'
  4214. });
  4215. const {
  4216. result,
  4217. statusText,
  4218. status,
  4219. data
  4220. } = await tools_httpRequest({
  4221. ...this.#asfOptions,
  4222. data: JSON.stringify({
  4223. Command: `!GROUPLIST ${this.#botName}`
  4224. })
  4225. });
  4226. if (result === 'Success') {
  4227. if (data?.status === 200 && data.response?.Result?.includes('|')) {
  4228. this.#groupInfo = Object.fromEntries(data.response.Result.split('\n').map(line => {
  4229. const [ , name, id ] = line.trim().split('|');
  4230. if (name && id) {
  4231. return [ name, id ];
  4232. }
  4233. return null;
  4234. }).filter(ele => ele));
  4235. logStatus.success();
  4236. return true;
  4237. }
  4238. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4239. return false;
  4240. }
  4241. logStatus.error(`${result}:${statusText}(${status})`);
  4242. return false;
  4243. } catch (error) {
  4244. throwError(error, 'SteamASF.getGroupID');
  4245. return false;
  4246. }
  4247. }
  4248. async addToWishlist(gameId) {
  4249. try {
  4250. const logStatus = scripts_echoLog({
  4251. type: 'addingToWishlist',
  4252. text: gameId
  4253. });
  4254. const {
  4255. result,
  4256. statusText,
  4257. status,
  4258. data
  4259. } = await tools_httpRequest({
  4260. ...this.#asfOptions,
  4261. data: JSON.stringify({
  4262. Command: `!ADDWISHLIST ${this.#botName} ${gameId}`
  4263. })
  4264. });
  4265. if (result === 'Success') {
  4266. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4267. logStatus.success();
  4268. return true;
  4269. }
  4270. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4271. return false;
  4272. }
  4273. logStatus.error(`${result}:${statusText}(${status})`);
  4274. return false;
  4275. } catch (error) {
  4276. throwError(error, 'SteamASF.addToWishlist');
  4277. return false;
  4278. }
  4279. }
  4280. async removeFromWishlist(gameId) {
  4281. try {
  4282. const logStatus = scripts_echoLog({
  4283. type: 'removingFromWishlist',
  4284. text: gameId
  4285. });
  4286. const {
  4287. result,
  4288. statusText,
  4289. status,
  4290. data
  4291. } = await tools_httpRequest({
  4292. ...this.#asfOptions,
  4293. data: JSON.stringify({
  4294. Command: `!REMOVEWISHLIST ${this.#botName} ${gameId}`
  4295. })
  4296. });
  4297. if (result === 'Success') {
  4298. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4299. logStatus.success();
  4300. return true;
  4301. }
  4302. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4303. return false;
  4304. }
  4305. logStatus.error(`${result}:${statusText}(${status})`);
  4306. return false;
  4307. } catch (error) {
  4308. throwError(error, 'SteamASF.removeFromWishlist');
  4309. return false;
  4310. }
  4311. }
  4312. async toggleFollowGame(gameId, doTask) {
  4313. try {
  4314. const logStatus = scripts_echoLog({
  4315. type: `${doTask ? '' : 'un'}followingGame`,
  4316. text: gameId
  4317. });
  4318. const {
  4319. result,
  4320. statusText,
  4321. status,
  4322. data
  4323. } = await tools_httpRequest({
  4324. ...this.#asfOptions,
  4325. data: JSON.stringify({
  4326. Command: `!${doTask ? '' : 'UN'}FOLLOWGAME ${this.#botName} ${gameId}`
  4327. })
  4328. });
  4329. if (result === 'Success') {
  4330. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4331. logStatus.success();
  4332. return true;
  4333. }
  4334. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4335. return false;
  4336. }
  4337. logStatus.error(`${result}:${statusText}(${status})`);
  4338. return false;
  4339. } catch (error) {
  4340. throwError(error, 'SteamASF.toggleFollowGame');
  4341. return false;
  4342. }
  4343. }
  4344. async toggleCurator(curatorId, doTask = true) {
  4345. try {
  4346. const logStatus = scripts_echoLog({
  4347. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  4348. text: curatorId
  4349. });
  4350. const {
  4351. result,
  4352. statusText,
  4353. status,
  4354. data
  4355. } = await tools_httpRequest({
  4356. ...this.#asfOptions,
  4357. data: JSON.stringify({
  4358. Command: `!${doTask ? '' : 'UN'}FOLLOWCURATOR ${this.#botName} ${curatorId}`
  4359. })
  4360. });
  4361. if (result === 'Success') {
  4362. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4363. logStatus.success();
  4364. return true;
  4365. }
  4366. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4367. return false;
  4368. }
  4369. logStatus.error(`${result}:${statusText}(${status})`);
  4370. return false;
  4371. } catch (error) {
  4372. throwError(error, 'Steam.toggleCurator');
  4373. return false;
  4374. }
  4375. }
  4376. async addLicense(id) {
  4377. try {
  4378. const [ type, ids ] = id.split('-');
  4379. if (type === 'appid') {
  4380. const logStatus = scripts_echoLog({
  4381. type: 'addingFreeLicense',
  4382. text: ids
  4383. });
  4384. const {
  4385. result,
  4386. statusText,
  4387. status,
  4388. data
  4389. } = await tools_httpRequest({
  4390. ...this.#asfOptions,
  4391. data: JSON.stringify({
  4392. Command: `!addlicense ${this.#botName} app/${ids}`
  4393. })
  4394. });
  4395. if (result === 'Success') {
  4396. if (data?.status === 200 && [ 'AlreadyPurchased', 'OK' ].find(text => data.response?.Result?.includes(text))) {
  4397. logStatus.success();
  4398. return true;
  4399. }
  4400. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4401. return false;
  4402. }
  4403. logStatus.error(`${result}:${statusText}(${status})`);
  4404. return false;
  4405. } else if (type === 'subid') {
  4406. const idsArr = ids.split(',');
  4407. const logStatus = scripts_echoLog({
  4408. type: 'addingFreeLicenseSubid',
  4409. text: ids
  4410. });
  4411. const {
  4412. result,
  4413. statusText,
  4414. status,
  4415. data
  4416. } = await tools_httpRequest({
  4417. ...this.#asfOptions,
  4418. data: JSON.stringify({
  4419. Command: `!addlicense ${this.#botName} ${idsArr.map(id => `sub/${id}`).join(',')}`
  4420. })
  4421. });
  4422. if (result === 'Success') {
  4423. if (data?.status === 200 && data.response?.Result) {
  4424. const resultLines = data.response.Result.split('\n');
  4425. idsArr.forEach(subid => {
  4426. const targetLine = resultLines.find(text => text.includes(subid));
  4427. if (targetLine && [ '成功', 'Success', 'Успех' ].find(text => targetLine.includes(text))) {
  4428. scripts_echoLog({}).success(targetLine);
  4429. } else {
  4430. scripts_echoLog({}).error(targetLine);
  4431. }
  4432. });
  4433. return true;
  4434. }
  4435. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4436. return false;
  4437. }
  4438. logStatus.error(`${result}:${statusText}(${status})`);
  4439. return false;
  4440. }
  4441. return false;
  4442. } catch (error) {
  4443. throwError(error, 'SteamASF.addLicense');
  4444. return false;
  4445. }
  4446. }
  4447. async requestPlayTestAccess(id) {
  4448. try {
  4449. const logStatus = scripts_echoLog({
  4450. type: 'requestingPlayTestAccess',
  4451. text: id
  4452. });
  4453. const {
  4454. result,
  4455. statusText,
  4456. status,
  4457. data
  4458. } = await tools_httpRequest({
  4459. ...this.#asfOptions,
  4460. data: JSON.stringify({
  4461. Command: `!REQUESTACCESS ${this.#botName} ${id}`
  4462. })
  4463. });
  4464. if (result === 'Success') {
  4465. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4466. logStatus.success();
  4467. return true;
  4468. }
  4469. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4470. return false;
  4471. }
  4472. logStatus.error(`${result}:${statusText}(${status})`);
  4473. return false;
  4474. } catch (error) {
  4475. throwError(error, 'Steam.requestPlayTestAccess');
  4476. return false;
  4477. }
  4478. }
  4479. }
  4480. const social_SteamASF = SteamASF;
  4481. class Steam extends social_Social {
  4482. tasks;
  4483. whiteList;
  4484. #cache = {
  4485. ...{
  4486. group: {},
  4487. officialGroup: {},
  4488. forum: {},
  4489. workshop: {},
  4490. curator: {}
  4491. },
  4492. ...GM_getValue('steamCache')
  4493. };
  4494. #auth = {};
  4495. #storeInitialized = false;
  4496. #communityInitialized = false;
  4497. #area = 'CN';
  4498. #areaStatus = 'end';
  4499. #ASF;
  4500. constructor() {
  4501. super();
  4502. const defaultTasksTemplate = {
  4503. groups: [],
  4504. officialGroups: [],
  4505. wishlists: [],
  4506. follows: [],
  4507. forums: [],
  4508. workshops: [],
  4509. workshopVotes: [],
  4510. curators: [],
  4511. curatorLikes: [],
  4512. announcements: [],
  4513. licenses: [],
  4514. playtests: []
  4515. };
  4516. this.tasks = defaultTasksTemplate;
  4517. this.whiteList = {
  4518. ...defaultTasksTemplate,
  4519. ...GM_getValue('whiteList')?.steam || {}
  4520. };
  4521. }
  4522. async init(type = 'all') {
  4523. try {
  4524. if (globalOptions.ASF.AsfEnabled && globalOptions.ASF.AsfIpcUrl && globalOptions.ASF.AsfIpcPassword) {
  4525. this.#ASF = new social_SteamASF();
  4526. if (await this.#ASF.init()) {
  4527. this.#storeInitialized = true;
  4528. this.#communityInitialized = true;
  4529. return true;
  4530. }
  4531. return false;
  4532. }
  4533. if (type === 'store') {
  4534. if (this.#storeInitialized) {
  4535. return true;
  4536. }
  4537. this.#storeInitialized = await this.#updateStoreAuth();
  4538. if (!this.#storeInitialized) {
  4539. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4540. return false;
  4541. }
  4542. scripts_echoLog({}).success(i18n('initSuccess', 'SteamStore'));
  4543. return true;
  4544. }
  4545. if (type === 'community') {
  4546. if (this.#communityInitialized) {
  4547. return true;
  4548. }
  4549. this.#communityInitialized = await this.#updateCommunityAuth();
  4550. if (!this.#communityInitialized) {
  4551. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4552. return false;
  4553. }
  4554. scripts_echoLog({}).success(i18n('initSuccess', 'SteamCommunity'));
  4555. return true;
  4556. }
  4557. this.#storeInitialized = await this.#updateStoreAuth();
  4558. this.#communityInitialized = await this.#updateCommunityAuth();
  4559. if (this.#storeInitialized && this.#communityInitialized) {
  4560. scripts_echoLog({}).success(i18n('initSuccess', 'Steam'));
  4561. return true;
  4562. }
  4563. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4564. return false;
  4565. } catch (error) {
  4566. throwError(error, 'Steam.init');
  4567. return false;
  4568. }
  4569. }
  4570. async #refreshStoreToken() {
  4571. try {
  4572. const logStatus = scripts_echoLog({
  4573. text: i18n('refreshingToken', i18n('steamStore'))
  4574. });
  4575. const formData = new FormData();
  4576. formData.append('redir', 'https://store.steampowered.com/');
  4577. const {
  4578. result,
  4579. statusText,
  4580. status,
  4581. data
  4582. } = await tools_httpRequest({
  4583. url: 'https://login.steampowered.com/jwt/ajaxrefresh',
  4584. method: 'POST',
  4585. responseType: 'json',
  4586. headers: {
  4587. Host: 'login.steampowered.com',
  4588. Origin: 'https://store.steampowered.com',
  4589. Referer: 'https://store.steampowered.com/'
  4590. },
  4591. data: formData
  4592. });
  4593. if (result === 'Success') {
  4594. if (data?.response?.success) {
  4595. if (await this.#setStoreToken(data.response)) {
  4596. logStatus.success();
  4597. return true;
  4598. }
  4599. logStatus.error('Error');
  4600. return false;
  4601. }
  4602. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4603. return false;
  4604. }
  4605. logStatus.error(`${result}:${statusText}(${status})`);
  4606. return false;
  4607. } catch (error) {
  4608. throwError(error, 'Steam.refreshStoreToken');
  4609. return false;
  4610. }
  4611. }
  4612. async #setStoreToken(param) {
  4613. try {
  4614. const logStatus = scripts_echoLog({
  4615. text: i18n('settingToken', i18n('steamStore'))
  4616. });
  4617. const formData = new FormData();
  4618. formData.append('steamID', param.steamID);
  4619. formData.append('nonce', param.nonce);
  4620. formData.append('redir', param.redir);
  4621. formData.append('auth', param.auth);
  4622. const {
  4623. result,
  4624. statusText,
  4625. status,
  4626. data
  4627. } = await tools_httpRequest({
  4628. url: 'https://store.steampowered.com/login/settoken',
  4629. method: 'POST',
  4630. headers: {
  4631. Accept: 'application/json, text/plain, */*',
  4632. Host: 'store.steampowered.com',
  4633. Origin: 'https://store.steampowered.com',
  4634. Referer: 'https://store.steampowered.com/login'
  4635. },
  4636. data: formData
  4637. });
  4638. if (result === 'Success') {
  4639. if (data?.status === 200) {
  4640. logStatus.success();
  4641. return true;
  4642. }
  4643. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4644. return false;
  4645. }
  4646. logStatus.error(`${result}:${statusText}(${status})`);
  4647. return false;
  4648. } catch (error) {
  4649. throwError(error, 'Steam.setStoreToken');
  4650. return false;
  4651. }
  4652. }
  4653. async #updateStoreAuth() {
  4654. try {
  4655. const logStatus = scripts_echoLog({
  4656. text: i18n('updatingAuth', i18n('steamStore'))
  4657. });
  4658. const {
  4659. result,
  4660. statusText,
  4661. status,
  4662. data
  4663. } = await tools_httpRequest({
  4664. url: 'https://store.steampowered.com/',
  4665. method: 'GET',
  4666. headers: {
  4667. 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',
  4668. 'Cache-Control': 'max-age=0',
  4669. 'Sec-Fetch-Dest': 'document',
  4670. 'Sec-Fetch-Mode': 'navigate',
  4671. 'Upgrade-Insecure-Requests': '1'
  4672. }
  4673. });
  4674. if (result === 'Success') {
  4675. if (data?.status === 200) {
  4676. if (!data.responseText.includes('data-miniprofile=')) {
  4677. await this.#refreshStoreToken();
  4678. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4679. return false;
  4680. }
  4681. const storeSessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4682. if (storeSessionID) {
  4683. this.#auth.storeSessionID = storeSessionID;
  4684. logStatus.success();
  4685. return true;
  4686. }
  4687. logStatus.error('Error: Get "sessionID" failed');
  4688. return false;
  4689. }
  4690. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4691. return false;
  4692. }
  4693. logStatus.error(`${result}:${statusText}(${status})`);
  4694. return false;
  4695. } catch (error) {
  4696. throwError(error, 'Steam.updateStoreAuth');
  4697. return false;
  4698. }
  4699. }
  4700. async #updateCommunityAuth() {
  4701. try {
  4702. const logStatus = scripts_echoLog({
  4703. text: i18n('updatingAuth', i18n('steamCommunity'))
  4704. });
  4705. const {
  4706. result,
  4707. statusText,
  4708. status,
  4709. data
  4710. } = await tools_httpRequest({
  4711. url: 'https://steamcommunity.com/my',
  4712. method: 'GET',
  4713. headers: {
  4714. 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',
  4715. 'Cache-Control': 'max-age=0',
  4716. 'Sec-Fetch-Dest': 'document',
  4717. 'Sec-Fetch-Mode': 'navigate',
  4718. 'Upgrade-Insecure-Requests': '1'
  4719. }
  4720. });
  4721. if (result === 'Success') {
  4722. if (data?.status === 200) {
  4723. if (data.responseText.includes('href="https://steamcommunity.com/login/home/')) {
  4724. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4725. return false;
  4726. }
  4727. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4728. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4729. const userName = data.responseText.match(/steamcommunity.com\/id\/(.+?)\/friends\//)?.[1];
  4730. if (steam64Id) {
  4731. this.#auth.steam64Id = steam64Id;
  4732. }
  4733. if (userName) {
  4734. this.#auth.userName = userName;
  4735. }
  4736. if (communitySessionID) {
  4737. this.#auth.communitySessionID = communitySessionID;
  4738. logStatus.success();
  4739. return true;
  4740. }
  4741. logStatus.error('Error: Get "sessionID" failed');
  4742. return false;
  4743. }
  4744. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4745. return false;
  4746. }
  4747. logStatus.error(`${result}:${statusText}(${status})`);
  4748. return false;
  4749. } catch (error) {
  4750. throwError(error, 'Steam.updateCommunityAuth');
  4751. return false;
  4752. }
  4753. }
  4754. async #getAreaInfo() {
  4755. try {
  4756. const logStatus = scripts_echoLog({
  4757. text: i18n('gettingAreaInfo')
  4758. });
  4759. const {
  4760. result,
  4761. statusText,
  4762. status,
  4763. data
  4764. } = await tools_httpRequest({
  4765. url: 'https://store.steampowered.com/cart/',
  4766. method: 'GET'
  4767. });
  4768. if (result === 'Success') {
  4769. if (data?.status === 200) {
  4770. const cartConfigRaw = data.responseText.match(/data-cart_config="(.*?)"/)?.[1];
  4771. const temp = document.createElement('div');
  4772. temp.innerHTML = cartConfigRaw || '{}';
  4773. const cartConfigStr = temp.textContent || temp.innerText;
  4774. let cartConfig;
  4775. try {
  4776. cartConfig = JSON.parse(cartConfigStr);
  4777. } catch (error) {
  4778. logStatus.error('Error: get country info filed');
  4779. console.error(error);
  4780. return {};
  4781. }
  4782. if (!cartConfig.rgUserCountryOptions) {
  4783. logStatus.warning('Warning: Area cannot be changed');
  4784. return {};
  4785. }
  4786. const userInfoRaw = data.responseText.match(/data-userinfo="(.*?)"/)?.[1];
  4787. const temp1 = document.createElement('div');
  4788. temp1.innerHTML = userInfoRaw || '{}';
  4789. const userInfoStr = temp1.textContent || temp1.innerText;
  4790. let userInfo;
  4791. try {
  4792. userInfo = JSON.parse(userInfoStr);
  4793. } catch (error) {
  4794. logStatus.error('Error: get country info filed');
  4795. console.error(error);
  4796. return {};
  4797. }
  4798. const currentArea = userInfo.country_code;
  4799. const areas = Object.keys(cartConfig.rgUserCountryOptions).filter(area => area !== 'help');
  4800. if (currentArea && areas.length > 0) {
  4801. this.#area = currentArea;
  4802. logStatus.success();
  4803. return {
  4804. currentArea: currentArea,
  4805. areas: areas
  4806. };
  4807. }
  4808. logStatus.error('Error: get country info filed');
  4809. return {};
  4810. }
  4811. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4812. return {};
  4813. }
  4814. logStatus.error(`${result}:${statusText}(${status})`);
  4815. return {};
  4816. } catch (error) {
  4817. throwError(error, 'Steam.getAreaInfo');
  4818. return {};
  4819. }
  4820. }
  4821. async #changeArea(area) {
  4822. try {
  4823. if (this.#areaStatus === 'waiting') {
  4824. await new Promise(resolve => {
  4825. const checker = setInterval(() => {
  4826. if (this.#areaStatus !== 'waiting') {
  4827. clearInterval(checker);
  4828. resolve(true);
  4829. }
  4830. });
  4831. });
  4832. }
  4833. if (this.#area === area || !area && this.#area !== 'CN') {
  4834. return true;
  4835. }
  4836. this.#areaStatus = 'waiting';
  4837. let aimedArea = area;
  4838. if (!aimedArea) {
  4839. const {
  4840. currentArea,
  4841. areas
  4842. } = await this.#getAreaInfo();
  4843. if (!currentArea || !areas) {
  4844. this.#areaStatus = 'error';
  4845. return false;
  4846. }
  4847. if (currentArea !== 'CN') {
  4848. this.#areaStatus = 'skip';
  4849. scripts_echoLog({
  4850. text: 'notNeededChangeArea'
  4851. });
  4852. return 'skip';
  4853. }
  4854. const anotherArea = areas.filter(area => area && area !== 'CN');
  4855. if (!anotherArea || anotherArea.length === 0) {
  4856. this.#areaStatus = 'noAnotherArea';
  4857. scripts_echoLog({
  4858. text: 'noAnotherArea'
  4859. });
  4860. return false;
  4861. }
  4862. [ aimedArea ] = anotherArea;
  4863. }
  4864. const logStatus = scripts_echoLog({
  4865. text: i18n('changingArea', aimedArea)
  4866. });
  4867. const {
  4868. result,
  4869. statusText,
  4870. status,
  4871. data
  4872. } = await tools_httpRequest({
  4873. url: 'https://store.steampowered.com/country/setcountry',
  4874. method: 'POST',
  4875. headers: {
  4876. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  4877. },
  4878. data: $.param({
  4879. cc: aimedArea,
  4880. sessionid: this.#auth.storeSessionID
  4881. })
  4882. });
  4883. if (result === 'Success') {
  4884. if (data?.status === 200 && data.responseText === 'true') {
  4885. const {
  4886. currentArea
  4887. } = await this.#getAreaInfo();
  4888. if (currentArea === aimedArea) {
  4889. this.#areaStatus = 'success';
  4890. logStatus.success();
  4891. return currentArea;
  4892. }
  4893. this.#areaStatus = 'error';
  4894. logStatus.error('Error: change country filed');
  4895. return 'CN';
  4896. }
  4897. this.#areaStatus = 'error';
  4898. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4899. return 'CN';
  4900. }
  4901. this.#areaStatus = 'error';
  4902. logStatus.error(`${result}:${statusText}(${status})`);
  4903. return 'CN';
  4904. } catch (error) {
  4905. this.#areaStatus = 'error';
  4906. throwError(error, 'Steam.changeArea');
  4907. return false;
  4908. }
  4909. }
  4910. async #joinGroup(groupName) {
  4911. try {
  4912. if (this.#ASF) {
  4913. if (await this.#ASF.joinGroup(groupName)) {
  4914. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  4915. return true;
  4916. }
  4917. return false;
  4918. }
  4919. const logStatus = scripts_echoLog({
  4920. type: 'joiningSteamGroup',
  4921. text: groupName
  4922. });
  4923. const {
  4924. result,
  4925. statusText,
  4926. status,
  4927. data
  4928. } = await tools_httpRequest({
  4929. url: `https://steamcommunity.com/groups/${groupName}`,
  4930. method: 'POST',
  4931. headers: {
  4932. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  4933. },
  4934. data: $.param({
  4935. action: 'join',
  4936. sessionID: this.#auth.communitySessionID
  4937. })
  4938. });
  4939. if (result === 'Success') {
  4940. if (data?.status === 200 && !data.responseText.includes('grouppage_join_area')) {
  4941. logStatus.success();
  4942. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  4943. return true;
  4944. }
  4945. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4946. return false;
  4947. }
  4948. logStatus.error(`${result}:${statusText}(${status})`);
  4949. return false;
  4950. } catch (error) {
  4951. throwError(error, 'Steam.joinGroup');
  4952. return false;
  4953. }
  4954. }
  4955. async #leaveGroup(groupName) {
  4956. try {
  4957. if (this.whiteList.groups.includes(groupName)) {
  4958. scripts_echoLog({
  4959. type: 'whiteList',
  4960. text: 'Steam.leaveGroup',
  4961. id: groupName
  4962. });
  4963. return true;
  4964. }
  4965. if (this.#ASF) {
  4966. return await this.#ASF.leaveGroup(groupName);
  4967. }
  4968. const groupId = await this.#getGroupId(groupName);
  4969. if (!groupId) {
  4970. return false;
  4971. }
  4972. const logStatus = scripts_echoLog({
  4973. type: 'leavingSteamGroup',
  4974. text: groupName
  4975. });
  4976. const {
  4977. result,
  4978. statusText,
  4979. status,
  4980. data
  4981. } = await tools_httpRequest({
  4982. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  4983. method: 'POST',
  4984. headers: {
  4985. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  4986. },
  4987. data: $.param({
  4988. sessionID: this.#auth.communitySessionID,
  4989. action: 'leaveGroup',
  4990. groupId: groupId
  4991. })
  4992. });
  4993. if (result === 'Success') {
  4994. 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) {
  4995. logStatus.success();
  4996. return true;
  4997. }
  4998. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4999. return false;
  5000. }
  5001. logStatus.error(`${result}:${statusText}(${status})`);
  5002. return false;
  5003. } catch (error) {
  5004. throwError(error, 'Steam.leaveGroup');
  5005. return false;
  5006. }
  5007. }
  5008. async #getGroupId(groupName) {
  5009. try {
  5010. const logStatus = scripts_echoLog({
  5011. type: 'gettingSteamGroupId',
  5012. text: groupName
  5013. });
  5014. const groupId = this.#cache.group[groupName];
  5015. if (groupId) {
  5016. logStatus.success();
  5017. return groupId;
  5018. }
  5019. const {
  5020. result,
  5021. statusText,
  5022. status,
  5023. data
  5024. } = await tools_httpRequest({
  5025. url: `https://steamcommunity.com/groups/${groupName}`,
  5026. method: 'GET',
  5027. headers: {
  5028. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5029. }
  5030. });
  5031. if (result === 'Success') {
  5032. if (data?.status === 200) {
  5033. const groupId = data.responseText.match(/OpenGroupChat\( '([0-9]+)'/)?.[1];
  5034. if (groupId) {
  5035. this.#setCache('group', groupName, groupId);
  5036. logStatus.success();
  5037. return groupId;
  5038. }
  5039. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5040. return false;
  5041. }
  5042. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5043. return false;
  5044. }
  5045. logStatus.error(`${result}:${statusText}(${status})`);
  5046. return false;
  5047. } catch (error) {
  5048. throwError(error, 'Steam.getGroupID');
  5049. return false;
  5050. }
  5051. }
  5052. async #joinOfficialGroup(gameId) {
  5053. try {
  5054. if (this.#ASF) {
  5055. if (await this.#ASF.joinGroup(gameId)) {
  5056. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5057. return true;
  5058. }
  5059. return false;
  5060. }
  5061. const logStatus = scripts_echoLog({
  5062. type: 'joiningSteamOfficialGroup',
  5063. text: gameId
  5064. });
  5065. const {
  5066. result,
  5067. statusText,
  5068. status,
  5069. data
  5070. } = await tools_httpRequest({
  5071. url: `https://steamcommunity.com/games/${gameId}?action=join&sessionID=${this.#auth.communitySessionID}`,
  5072. method: 'GET',
  5073. headers: {
  5074. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5075. }
  5076. });
  5077. if (result === 'Success') {
  5078. if (data?.status === 200 && !data.responseText.includes('id="publicGroupJoin"')) {
  5079. logStatus.success();
  5080. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5081. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5082. if (groupId) {
  5083. this.#setCache('officialGroup', gameId, groupId);
  5084. }
  5085. return true;
  5086. }
  5087. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5088. return false;
  5089. }
  5090. logStatus.error(`${result}:${statusText}(${status})`);
  5091. return false;
  5092. } catch (error) {
  5093. throwError(error, 'Steam.joinOfficialGroup');
  5094. return false;
  5095. }
  5096. }
  5097. async #leaveOfficialGroup(gameId) {
  5098. try {
  5099. if (this.whiteList.officialGroups.includes(gameId)) {
  5100. scripts_echoLog({
  5101. type: 'whiteList',
  5102. text: 'Steam.leaveOfficialGroup',
  5103. id: gameId
  5104. });
  5105. return true;
  5106. }
  5107. if (this.#ASF) {
  5108. return await this.#ASF.leaveGroup(gameId);
  5109. }
  5110. const groupId = await this.#getOfficialGroupId(gameId);
  5111. if (!groupId) {
  5112. return false;
  5113. }
  5114. const logStatus = scripts_echoLog({
  5115. type: 'leavingSteamOfficialGroup',
  5116. text: gameId
  5117. });
  5118. const {
  5119. result,
  5120. statusText,
  5121. status,
  5122. data
  5123. } = await tools_httpRequest({
  5124. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5125. method: 'POST',
  5126. headers: {
  5127. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5128. },
  5129. data: $.param({
  5130. sessionID: this.#auth.communitySessionID,
  5131. action: 'leaveGroup',
  5132. groupId: groupId
  5133. })
  5134. });
  5135. if (result === 'Success') {
  5136. if (data?.status === 200) {
  5137. const {
  5138. result: resultR,
  5139. statusText: statusTextR,
  5140. status: statusR,
  5141. data: dataR
  5142. } = await tools_httpRequest({
  5143. url: `https://steamcommunity.com/games/${gameId}`,
  5144. method: 'GET',
  5145. headers: {
  5146. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5147. }
  5148. });
  5149. if (resultR === 'Success') {
  5150. if (dataR?.status === 200 && dataR.responseText.includes('id="publicGroupJoin"')) {
  5151. logStatus.success();
  5152. return true;
  5153. }
  5154. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5155. return false;
  5156. }
  5157. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5158. return false;
  5159. }
  5160. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5161. return false;
  5162. }
  5163. logStatus.error(`${result}:${statusText}(${status})`);
  5164. return false;
  5165. } catch (error) {
  5166. throwError(error, 'Steam.leaveOfficialGroup');
  5167. return false;
  5168. }
  5169. }
  5170. async #getOfficialGroupId(gameId) {
  5171. try {
  5172. const logStatus = scripts_echoLog({
  5173. type: 'gettingSteamOfficialGroupId',
  5174. text: gameId
  5175. });
  5176. const groupId = this.#cache.officialGroup[gameId];
  5177. if (groupId) {
  5178. logStatus.success();
  5179. return groupId;
  5180. }
  5181. const {
  5182. result,
  5183. statusText,
  5184. status,
  5185. data
  5186. } = await tools_httpRequest({
  5187. url: `https://steamcommunity.com/games/${gameId}`,
  5188. method: 'GET',
  5189. headers: {
  5190. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5191. }
  5192. });
  5193. if (result === 'Success') {
  5194. if (data?.status === 200) {
  5195. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5196. if (groupId) {
  5197. this.#setCache('officialGroup', gameId, groupId);
  5198. logStatus.success();
  5199. return groupId;
  5200. }
  5201. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5202. return false;
  5203. }
  5204. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5205. return false;
  5206. }
  5207. logStatus.error(`${result}:${statusText}(${status})`);
  5208. return false;
  5209. } catch (error) {
  5210. throwError(error, 'Steam.getGroupID');
  5211. return false;
  5212. }
  5213. }
  5214. async #addToWishlist(gameId) {
  5215. try {
  5216. if (this.#ASF) {
  5217. if (await this.#ASF.addToWishlist(gameId)) {
  5218. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5219. return true;
  5220. }
  5221. return false;
  5222. }
  5223. const logStatus = scripts_echoLog({
  5224. type: 'addingToWishlist',
  5225. text: gameId
  5226. });
  5227. const {
  5228. result,
  5229. data
  5230. } = await tools_httpRequest({
  5231. url: 'https://store.steampowered.com/api/addtowishlist',
  5232. method: 'POST',
  5233. headers: {
  5234. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5235. },
  5236. data: $.param({
  5237. sessionid: this.#auth.storeSessionID,
  5238. appid: gameId
  5239. }),
  5240. dataType: 'json'
  5241. });
  5242. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5243. logStatus.success();
  5244. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5245. return true;
  5246. }
  5247. const {
  5248. result: resultR,
  5249. statusText: statusTextR,
  5250. status: statusR,
  5251. data: dataR
  5252. } = await tools_httpRequest({
  5253. url: `https://store.steampowered.com/app/${gameId}`,
  5254. method: 'GET'
  5255. });
  5256. if (resultR === 'Success') {
  5257. if (dataR?.status === 200) {
  5258. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5259. logStatus.warning(i18n('changeAreaNotice'));
  5260. if (!await this.#changeArea()) {
  5261. return false;
  5262. }
  5263. return await this.#addToWishlist(gameId);
  5264. }
  5265. if (dataR.responseText.includes('class="queue_actions_ctn"') && dataR.responseText.includes('class="already_in_library"')) {
  5266. logStatus.success();
  5267. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5268. return true;
  5269. } 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"')) {
  5270. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5271. return false;
  5272. }
  5273. logStatus.success();
  5274. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5275. return true;
  5276. }
  5277. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5278. return false;
  5279. }
  5280. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5281. return false;
  5282. } catch (error) {
  5283. throwError(error, 'Steam.addToWishlist');
  5284. return false;
  5285. }
  5286. }
  5287. async #removeFromWishlist(gameId) {
  5288. try {
  5289. if (this.whiteList.wishlists.includes(gameId)) {
  5290. scripts_echoLog({
  5291. type: 'whiteList',
  5292. text: 'Steam.removeFromWishlist',
  5293. id: gameId
  5294. });
  5295. return true;
  5296. }
  5297. if (this.#ASF) {
  5298. return await this.#ASF.removeFromWishlist(gameId);
  5299. }
  5300. const logStatus = scripts_echoLog({
  5301. type: 'removingFromWishlist',
  5302. text: gameId
  5303. });
  5304. const {
  5305. result,
  5306. data
  5307. } = await tools_httpRequest({
  5308. url: 'https://store.steampowered.com/api/removefromwishlist',
  5309. method: 'POST',
  5310. headers: {
  5311. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5312. },
  5313. data: $.param({
  5314. sessionid: this.#auth.storeSessionID,
  5315. appid: gameId
  5316. }),
  5317. dataType: 'json'
  5318. });
  5319. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5320. logStatus.success();
  5321. return true;
  5322. }
  5323. const {
  5324. result: resultR,
  5325. statusText: statusTextR,
  5326. status: statusR,
  5327. data: dataR
  5328. } = await tools_httpRequest({
  5329. url: `https://store.steampowered.com/app/${gameId}`,
  5330. method: 'GET'
  5331. });
  5332. if (resultR === 'Success') {
  5333. if (dataR?.status === 200) {
  5334. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5335. logStatus.warning(i18n('changeAreaNotice'));
  5336. const result = await this.#changeArea();
  5337. if (!result || result === 'CN' || result === 'skip') {
  5338. return false;
  5339. }
  5340. return await this.#removeFromWishlist(gameId);
  5341. }
  5342. if (dataR.responseText.includes('class="queue_actions_ctn"') && (dataR.responseText.includes('ds_owned_flag ds_flag') || dataR.responseText.includes('add_to_wishlist_area'))) {
  5343. logStatus.success();
  5344. return true;
  5345. }
  5346. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5347. return false;
  5348. }
  5349. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5350. return false;
  5351. }
  5352. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5353. return false;
  5354. } catch (error) {
  5355. throwError(error, 'Steam.removeFromWishlist');
  5356. return false;
  5357. }
  5358. }
  5359. async #toggleFollowGame(gameId, doTask) {
  5360. try {
  5361. if (!doTask && this.whiteList.follows.includes(gameId)) {
  5362. scripts_echoLog({
  5363. type: 'whiteList',
  5364. text: 'Steam.unfollowGame',
  5365. id: gameId
  5366. });
  5367. return true;
  5368. }
  5369. if (this.#ASF) {
  5370. if (await this.#ASF.toggleFollowGame(gameId, doTask)) {
  5371. if (doTask) {
  5372. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5373. }
  5374. return true;
  5375. }
  5376. return false;
  5377. }
  5378. const logStatus = scripts_echoLog({
  5379. type: `${doTask ? '' : 'un'}followingGame`,
  5380. text: gameId
  5381. });
  5382. const requestData = {
  5383. sessionid: this.#auth.storeSessionID,
  5384. appid: gameId
  5385. };
  5386. if (!doTask) {
  5387. requestData.unfollow = '1';
  5388. }
  5389. const {
  5390. result,
  5391. data
  5392. } = await tools_httpRequest({
  5393. url: 'https://store.steampowered.com/explore/followgame/',
  5394. method: 'POST',
  5395. headers: {
  5396. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5397. },
  5398. data: $.param(requestData)
  5399. });
  5400. if (result === 'Success' && data?.status === 200 && data.responseText === 'true') {
  5401. logStatus.success();
  5402. return true;
  5403. }
  5404. const followed = await this.#isFollowedGame(gameId);
  5405. if (this.#area === 'CN' && followed === 'areaLocked') {
  5406. logStatus.warning(i18n('changeAreaNotice'));
  5407. if (!await this.#changeArea()) {
  5408. return false;
  5409. }
  5410. return await this.#removeFromWishlist(gameId);
  5411. }
  5412. if (doTask === followed) {
  5413. logStatus.success();
  5414. if (doTask) {
  5415. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5416. }
  5417. return true;
  5418. }
  5419. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5420. return false;
  5421. } catch (error) {
  5422. throwError(error, 'Steam.toggleFollowGame');
  5423. return false;
  5424. }
  5425. }
  5426. async #isFollowedGame(gameId) {
  5427. try {
  5428. const {
  5429. result,
  5430. data
  5431. } = await tools_httpRequest({
  5432. url: `https://store.steampowered.com/app/${gameId}`,
  5433. method: 'GET'
  5434. });
  5435. if (result === 'Success') {
  5436. if (data?.status === 200) {
  5437. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  5438. return 'areaLocked';
  5439. }
  5440. if ($(data.responseText.replace(/<img.*?>/g, '')).find('.queue_control_button.queue_btn_follow>.btnv6_blue_hoverfade.btn_medium.queue_btn_active').css('display') !== 'none') {
  5441. return true;
  5442. }
  5443. return false;
  5444. }
  5445. return false;
  5446. }
  5447. return false;
  5448. } catch (error) {
  5449. throwError(error, 'Steam.isFollowedGame');
  5450. return false;
  5451. }
  5452. }
  5453. async #toggleForum(gameId, doTask = true) {
  5454. try {
  5455. if (!doTask && this.whiteList.forums.includes(gameId)) {
  5456. scripts_echoLog({
  5457. type: 'whiteList',
  5458. text: 'Steam.unsubscribeForum',
  5459. id: gameId
  5460. });
  5461. return true;
  5462. }
  5463. const forumId = await this.#getForumId(gameId);
  5464. if (!forumId) {
  5465. return false;
  5466. }
  5467. const logStatus = scripts_echoLog({
  5468. type: `${doTask ? '' : 'un'}subscribingForum`,
  5469. text: gameId
  5470. });
  5471. const [ id, feature ] = forumId.split('_');
  5472. const {
  5473. result,
  5474. statusText,
  5475. status,
  5476. data
  5477. } = await tools_httpRequest({
  5478. url: `https://steamcommunity.com/forum/${id}/General/${doTask ? '' : 'un'}subscribe/${feature || '0'}/`,
  5479. method: 'POST',
  5480. responseType: 'json',
  5481. headers: {
  5482. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5483. },
  5484. data: $.param({
  5485. sessionid: this.#auth.communitySessionID
  5486. })
  5487. });
  5488. if (result === 'Success') {
  5489. if (data?.status === 200 && (data.response?.success === 1 || data.response?.success === 29)) {
  5490. if (doTask) {
  5491. this.tasks.forums = unique([ ...this.tasks.forums, gameId ]);
  5492. }
  5493. logStatus.success();
  5494. return true;
  5495. }
  5496. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5497. return true;
  5498. }
  5499. logStatus.error(`${result}:${statusText}(${status})`);
  5500. return true;
  5501. } catch (error) {
  5502. throwError(error, 'Steam.toggleForum');
  5503. return true;
  5504. }
  5505. }
  5506. async #getForumId(gameId) {
  5507. try {
  5508. const logStatus = scripts_echoLog({
  5509. type: 'gettingForumId',
  5510. text: gameId
  5511. });
  5512. const forumId = this.#cache.forum[gameId];
  5513. if (forumId) {
  5514. logStatus.success();
  5515. return forumId;
  5516. }
  5517. const {
  5518. result,
  5519. statusText,
  5520. status,
  5521. data
  5522. } = await tools_httpRequest({
  5523. url: `https://steamcommunity.com/app/${gameId}/discussions/`,
  5524. method: 'GET'
  5525. });
  5526. if (result === 'Success') {
  5527. if (data?.status === 200) {
  5528. const forumId = data.responseText?.match(/General_([\d]+(_[\d]+)?)/)?.[1];
  5529. if (forumId) {
  5530. this.#setCache('forum', gameId, forumId);
  5531. logStatus.success();
  5532. return forumId;
  5533. }
  5534. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5535. return false;
  5536. }
  5537. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5538. return false;
  5539. }
  5540. logStatus.error(`${result}:${statusText}(${status})`);
  5541. return false;
  5542. } catch (error) {
  5543. throwError(error, 'Steam.getForumId');
  5544. return false;
  5545. }
  5546. }
  5547. async #toggleFavoriteWorkshop(id, doTask = true) {
  5548. try {
  5549. if (!doTask && this.whiteList.workshops.includes(id)) {
  5550. scripts_echoLog({
  5551. type: 'whiteList',
  5552. text: 'Steam.unfavoriteWorkshop',
  5553. id: id
  5554. });
  5555. return true;
  5556. }
  5557. const appid = await this.#getWorkshopAppId(id);
  5558. if (!appid) {
  5559. return false;
  5560. }
  5561. const logStatus = scripts_echoLog({
  5562. type: doTask ? 'favoritingWorkshop' : 'unfavoritingWorkshop',
  5563. text: id
  5564. });
  5565. const {
  5566. result,
  5567. statusText,
  5568. status,
  5569. data
  5570. } = await tools_httpRequest({
  5571. url: `https://steamcommunity.com/sharedfiles/${doTask ? '' : 'un'}favorite`,
  5572. method: 'POST',
  5573. headers: {
  5574. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5575. },
  5576. data: $.param({
  5577. id: id,
  5578. appid: appid,
  5579. sessionid: this.#auth.communitySessionID
  5580. })
  5581. });
  5582. if (result === 'Success') {
  5583. if (data?.status === 200 && !data.responseText) {
  5584. if (doTask) {
  5585. this.tasks.workshops = unique([ ...this.tasks.workshops, id ]);
  5586. }
  5587. logStatus.success();
  5588. return true;
  5589. }
  5590. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5591. return false;
  5592. }
  5593. logStatus.error(`${result}:${statusText}(${status})`);
  5594. return false;
  5595. } catch (error) {
  5596. throwError(error, 'Steam.toggleFavoriteWorkshop');
  5597. return false;
  5598. }
  5599. }
  5600. async #getWorkshopAppId(id) {
  5601. try {
  5602. const logStatus = scripts_echoLog({
  5603. type: 'gettingWorkshopAppId',
  5604. text: id
  5605. });
  5606. const appId = this.#cache.workshop[id];
  5607. if (appId) {
  5608. logStatus.success();
  5609. return appId;
  5610. }
  5611. const {
  5612. result,
  5613. statusText,
  5614. status,
  5615. data
  5616. } = await tools_httpRequest({
  5617. url: `https://steamcommunity.com/sharedfiles/filedetails/?id=${id}`,
  5618. method: 'GET'
  5619. });
  5620. if (result === 'Success') {
  5621. if (data?.status === 200) {
  5622. const appId = data.responseText.match(/<input type="hidden" name="appid" value="([\d]+?)" \/>/)?.[1];
  5623. if (appId) {
  5624. this.#setCache('workshop', id, appId);
  5625. logStatus.success();
  5626. return appId;
  5627. }
  5628. logStatus.error('Error: getWorkshopAppId failed');
  5629. return false;
  5630. }
  5631. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5632. return false;
  5633. }
  5634. logStatus.error(`${result}:${statusText}(${status})`);
  5635. return false;
  5636. } catch (error) {
  5637. throwError(error, 'Steam.getWorkshopAppId');
  5638. return false;
  5639. }
  5640. }
  5641. async #voteUpWorkshop(id) {
  5642. try {
  5643. const logStatus = scripts_echoLog({
  5644. type: 'votingUpWorkshop',
  5645. text: id
  5646. });
  5647. const {
  5648. result,
  5649. statusText,
  5650. status,
  5651. data
  5652. } = await tools_httpRequest({
  5653. url: 'https://steamcommunity.com/sharedfiles/voteup',
  5654. method: 'POST',
  5655. responseType: 'json',
  5656. headers: {
  5657. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5658. },
  5659. data: $.param({
  5660. id: id,
  5661. sessionid: this.#auth.communitySessionID
  5662. })
  5663. });
  5664. if (result === 'Success') {
  5665. if (data?.status === 200 && data.response?.success === 1) {
  5666. logStatus.success();
  5667. return true;
  5668. }
  5669. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5670. return true;
  5671. }
  5672. logStatus.error(`${result}:${statusText}(${status})`);
  5673. return true;
  5674. } catch (error) {
  5675. throwError(error, 'Steam.voteupWorkshop');
  5676. return true;
  5677. }
  5678. }
  5679. async #toggleCurator(curatorId, doTask = true) {
  5680. try {
  5681. if (!doTask && this.whiteList.curators.includes(curatorId)) {
  5682. scripts_echoLog({
  5683. type: 'whiteList',
  5684. text: 'Steam.unfollowCurator',
  5685. id: curatorId
  5686. });
  5687. return true;
  5688. }
  5689. if (this.#ASF) {
  5690. return await this.#ASF.toggleCurator(curatorId, doTask);
  5691. }
  5692. const logStatus = scripts_echoLog({
  5693. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  5694. text: curatorId
  5695. });
  5696. const {
  5697. result,
  5698. statusText,
  5699. status,
  5700. data
  5701. } = await tools_httpRequest({
  5702. url: 'https://store.steampowered.com/curators/ajaxfollow',
  5703. method: 'POST',
  5704. headers: {
  5705. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5706. },
  5707. data: $.param({
  5708. clanid: curatorId,
  5709. sessionid: this.#auth.storeSessionID,
  5710. follow: doTask
  5711. }),
  5712. dataType: 'json'
  5713. });
  5714. if (result === 'Success') {
  5715. if (data?.status === 200 && data.response?.success?.success === 1) {
  5716. logStatus.success();
  5717. return true;
  5718. }
  5719. logStatus.error(`Error:${data?.statusText}(${data?.response?.success}` || `${data?.status})`);
  5720. return false;
  5721. }
  5722. logStatus.error(`${result}:${statusText}(${status})`);
  5723. return false;
  5724. } catch (error) {
  5725. throwError(error, 'Steam.toggleCurator');
  5726. return false;
  5727. }
  5728. }
  5729. async getCuratorId(path, name) {
  5730. try {
  5731. const logStatus = scripts_echoLog({
  5732. type: 'gettingCuratorId',
  5733. text: `${path}/${name}`
  5734. });
  5735. const curatorId = this.#cache.curator[`${path}/${name}`];
  5736. if (curatorId) {
  5737. logStatus.success();
  5738. return curatorId;
  5739. }
  5740. const {
  5741. result,
  5742. statusText,
  5743. status,
  5744. data
  5745. } = await tools_httpRequest({
  5746. url: `https://store.steampowered.com/${path}/${name}`,
  5747. method: 'GET',
  5748. headers: {
  5749. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5750. }
  5751. });
  5752. if (result === 'Success') {
  5753. if (data?.status === 200) {
  5754. const curatorId = data.responseText.match(/g_pagingData.*?"clanid":([\d]+)/)?.[1];
  5755. if (curatorId) {
  5756. this.#setCache('curator', `${path}/${name}`, curatorId);
  5757. logStatus.success();
  5758. return curatorId;
  5759. }
  5760. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5761. return false;
  5762. }
  5763. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5764. return false;
  5765. }
  5766. logStatus.error(`${result}:${statusText}(${status})`);
  5767. return false;
  5768. } catch (error) {
  5769. throwError(error, 'Steam.getCuratorID');
  5770. return false;
  5771. }
  5772. }
  5773. async #toggleCuratorLike(link, doTask = true) {
  5774. try {
  5775. const [ path, name ] = link.split('/');
  5776. if (!(path && name)) {
  5777. scripts_echoLog({
  5778. text: i18n('errorLink', link)
  5779. });
  5780. return false;
  5781. }
  5782. const curatorId = await this.getCuratorId(path, name);
  5783. if (curatorId) {
  5784. return await this.#toggleCurator(curatorId, doTask);
  5785. }
  5786. return false;
  5787. } catch (error) {
  5788. throwError(error, 'Steam.toggleCuratorLike');
  5789. return false;
  5790. }
  5791. }
  5792. async #getAnnouncementParams(appId, viewId) {
  5793. try {
  5794. const logStatus = scripts_echoLog({
  5795. type: 'gettingAnnouncementParams',
  5796. text: appId,
  5797. id: viewId
  5798. });
  5799. const {
  5800. result,
  5801. statusText,
  5802. status,
  5803. data
  5804. } = await tools_httpRequest({
  5805. 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`,
  5806. method: 'GET',
  5807. responseType: 'json',
  5808. headers: {
  5809. Host: 'store.steampowered.com',
  5810. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  5811. }
  5812. });
  5813. if (result === 'Success') {
  5814. if (data?.status === 200 && data?.response?.success === 1) {
  5815. const {
  5816. clanid,
  5817. gid
  5818. } = data.response.event?.announcement_body || {};
  5819. if (clanid) {
  5820. logStatus.success();
  5821. return {
  5822. clanId: clanid,
  5823. gid: gid
  5824. };
  5825. }
  5826. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5827. return {};
  5828. }
  5829. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5830. return {};
  5831. }
  5832. logStatus.error(`${result}:${statusText}(${status})`);
  5833. return {};
  5834. } catch (error) {
  5835. throwError(error, 'Steam.likeAnnouncement');
  5836. return {};
  5837. }
  5838. }
  5839. async #likeAnnouncement(id) {
  5840. try {
  5841. const [ appId, viewId ] = id.split('/');
  5842. if (!(appId && viewId)) {
  5843. scripts_echoLog({}).error(`${i18n('missParams')}(id)`);
  5844. return false;
  5845. }
  5846. const {
  5847. clanId,
  5848. gid
  5849. } = await this.#getAnnouncementParams(appId, viewId);
  5850. if (!clanId) {
  5851. return false;
  5852. }
  5853. const logStatus = scripts_echoLog({
  5854. type: 'likingAnnouncement',
  5855. text: appId,
  5856. id: viewId
  5857. });
  5858. const {
  5859. result,
  5860. statusText,
  5861. status,
  5862. data
  5863. } = await tools_httpRequest({
  5864. url: `https://store.steampowered.com/updated/ajaxrateupdate/${gid || viewId}`,
  5865. method: 'POST',
  5866. headers: {
  5867. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  5868. Host: 'store.steampowered.com',
  5869. Origin: 'https://store.steampowered.com',
  5870. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  5871. },
  5872. data: $.param({
  5873. sessionid: this.#auth.storeSessionID,
  5874. voteup: 1,
  5875. clanid: clanId,
  5876. ajax: 1
  5877. }),
  5878. dataType: 'json'
  5879. });
  5880. if (result === 'Success') {
  5881. if (data?.status === 200 && data.response.success === 1) {
  5882. logStatus.success();
  5883. return true;
  5884. }
  5885. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5886. return false;
  5887. }
  5888. logStatus.error(`${result}:${statusText}(${status})`);
  5889. return false;
  5890. } catch (error) {
  5891. throwError(error, 'Steam.likeAnnouncement');
  5892. return false;
  5893. }
  5894. }
  5895. async #appid2subid(id) {
  5896. try {
  5897. const logStatus = scripts_echoLog({
  5898. type: 'gettingSubid',
  5899. text: id
  5900. });
  5901. const {
  5902. result,
  5903. statusText,
  5904. status,
  5905. data
  5906. } = await tools_httpRequest({
  5907. url: `https://store.steampowered.com/app/${id}`,
  5908. method: 'GET',
  5909. headers: {
  5910. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5911. }
  5912. });
  5913. if (result === 'Success') {
  5914. if (data?.status === 200) {
  5915. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  5916. logStatus.warning(i18n('changeAreaNotice'));
  5917. const result = await this.#changeArea();
  5918. if (!result || result === 'CN' || result === 'skip') {
  5919. return false;
  5920. }
  5921. return await this.#appid2subid(id);
  5922. }
  5923. const subid = data.responseText.match(/name="subid" value="([\d]+?)"/)?.[1];
  5924. if (subid) {
  5925. logStatus.success();
  5926. return subid;
  5927. }
  5928. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5929. return false;
  5930. }
  5931. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5932. return false;
  5933. }
  5934. logStatus.error(`${result}:${statusText}(${status})`);
  5935. return false;
  5936. } catch (error) {
  5937. throwError(error, 'Steam.appid2subid');
  5938. return false;
  5939. }
  5940. }
  5941. async #getLicenses() {
  5942. try {
  5943. const logStatus = scripts_echoLog({
  5944. text: i18n('gettingLicenses')
  5945. });
  5946. const {
  5947. result,
  5948. statusText,
  5949. status,
  5950. data
  5951. } = await tools_httpRequest({
  5952. url: `https://store.steampowered.com/dynamicstore/userdata/?t=${new Date().getTime()}`,
  5953. method: 'GET',
  5954. responseType: 'json'
  5955. });
  5956. if (result === 'Success') {
  5957. if (data?.status === 200) {
  5958. logStatus.success();
  5959. return data.response?.rgOwnedPackages;
  5960. }
  5961. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5962. return false;
  5963. }
  5964. logStatus.error(`${result}:${statusText}(${status})`);
  5965. return false;
  5966. } catch (error) {
  5967. throwError(error, 'Steam.getLicenses');
  5968. return false;
  5969. }
  5970. }
  5971. async #addLicense(id) {
  5972. try {
  5973. if (this.#ASF) {
  5974. return await this.#ASF.addLicense(id);
  5975. }
  5976. const [ type, ids ] = id.split('-');
  5977. if (type === 'appid') {
  5978. const subid = await this.#appid2subid(ids);
  5979. if (!subid) {
  5980. return false;
  5981. }
  5982. const logStatus = scripts_echoLog({
  5983. type: 'addingFreeLicense',
  5984. text: ids
  5985. });
  5986. if (!await this.#addFreeLicense(subid, logStatus)) {
  5987. return false;
  5988. }
  5989. const {
  5990. result,
  5991. statusText,
  5992. status,
  5993. data
  5994. } = await tools_httpRequest({
  5995. url: `https://store.steampowered.com/app/${ids}`,
  5996. method: 'GET'
  5997. });
  5998. if (result === 'Success') {
  5999. if (data?.status === 200) {
  6000. if (data.responseText.includes('ds_owned_flag ds_flag') || data.responseText.includes('class="already_in_library"')) {
  6001. logStatus.success();
  6002. return true;
  6003. }
  6004. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6005. return false;
  6006. }
  6007. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6008. return false;
  6009. }
  6010. logStatus.error(`${result}:${statusText}(${status})`);
  6011. return false;
  6012. } else if (type === 'subid') {
  6013. if (this.#area === 'CN') {
  6014. scripts_echoLog({}).success(i18n('tryChangeAreaNotice'));
  6015. await this.#changeArea();
  6016. }
  6017. const logStatusArr = {};
  6018. const idsArr = ids.split(',');
  6019. for (const subid of idsArr) {
  6020. const logStatus = scripts_echoLog({
  6021. type: 'addingFreeLicenseSubid',
  6022. text: subid
  6023. });
  6024. if (!await this.#addFreeLicense(subid, logStatus)) {
  6025. return false;
  6026. }
  6027. logStatusArr[subid] = logStatus;
  6028. }
  6029. const licenses = await this.#getLicenses();
  6030. if (!licenses) {
  6031. return false;
  6032. }
  6033. for (const subid of idsArr) {
  6034. if (licenses.includes(parseInt(subid, 10))) {
  6035. logStatusArr[subid].success();
  6036. } else {
  6037. logStatusArr[subid].error();
  6038. }
  6039. }
  6040. return true;
  6041. }
  6042. return false;
  6043. } catch (error) {
  6044. throwError(error, 'Steam.addLicense');
  6045. return false;
  6046. }
  6047. }
  6048. async #addFreeLicense(id, logStatusPre) {
  6049. try {
  6050. const logStatus = logStatusPre || scripts_echoLog({
  6051. type: 'addingFreeLicenseSubid',
  6052. text: id
  6053. });
  6054. const {
  6055. result,
  6056. statusText,
  6057. status,
  6058. data
  6059. } = await tools_httpRequest({
  6060. url: 'https://store.steampowered.com/checkout/addfreelicense',
  6061. method: 'POST',
  6062. headers: {
  6063. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6064. Host: 'store.steampowered.com',
  6065. Origin: 'https://store.steampowered.com',
  6066. Referer: 'https://store.steampowered.com/account/licenses/'
  6067. },
  6068. data: $.param({
  6069. action: 'add_to_cart',
  6070. sessionid: this.#auth.storeSessionID,
  6071. subid: id
  6072. }),
  6073. dataType: 'json'
  6074. });
  6075. if (result === 'Success') {
  6076. if (data?.status === 200) {
  6077. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6078. logStatus.warning(i18n('changeAreaNotice'));
  6079. const result = await this.#changeArea();
  6080. if (!result || result === 'CN') {
  6081. return false;
  6082. }
  6083. return await this.#addFreeLicense(id);
  6084. }
  6085. logStatus.success();
  6086. return true;
  6087. }
  6088. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6089. return false;
  6090. }
  6091. logStatus.error(`${result}:${statusText}(${status})`);
  6092. return false;
  6093. } catch (error) {
  6094. throwError(error, 'Steam.addFreeLicense');
  6095. return false;
  6096. }
  6097. }
  6098. async #requestPlayTestAccess(id) {
  6099. try {
  6100. if (this.#ASF) {
  6101. return await this.#ASF.requestPlayTestAccess(id);
  6102. }
  6103. const logStatus = scripts_echoLog({
  6104. type: 'requestingPlayTestAccess',
  6105. text: id
  6106. });
  6107. const {
  6108. result,
  6109. statusText,
  6110. status,
  6111. data
  6112. } = await tools_httpRequest({
  6113. url: `https://store.steampowered.com/ajaxrequestplaytestaccess/${id}`,
  6114. method: 'POST',
  6115. headers: {
  6116. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6117. Host: 'store.steampowered.com',
  6118. Origin: 'https://store.steampowered.com',
  6119. Referer: `https://store.steampowered.com/app/${id}`
  6120. },
  6121. data: $.param({
  6122. sessionid: this.#auth.storeSessionID
  6123. }),
  6124. dataType: 'json'
  6125. });
  6126. if (result === 'Success') {
  6127. if (data?.status === 200 && data?.response?.success === 1) {
  6128. logStatus.success();
  6129. return true;
  6130. }
  6131. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6132. return false;
  6133. }
  6134. logStatus.error(`${result}:${statusText}(${status})`);
  6135. return false;
  6136. } catch (error) {
  6137. throwError(error, 'Steam.requestPlayTestAccess');
  6138. return false;
  6139. }
  6140. }
  6141. async toggle({
  6142. doTask = true,
  6143. groupLinks = [],
  6144. officialGroupLinks = [],
  6145. wishlistLinks = [],
  6146. followLinks = [],
  6147. forumLinks = [],
  6148. workshopLinks = [],
  6149. workshopVoteLinks = [],
  6150. curatorLinks = [],
  6151. curatorLikeLinks = [],
  6152. announcementLinks = [],
  6153. licenseLinks = [],
  6154. playtestLinks = []
  6155. }) {
  6156. try {
  6157. if ([ ...groupLinks, ...officialGroupLinks, ...forumLinks, ...workshopLinks, ...workshopVoteLinks ].length > 0 && !this.#communityInitialized) {
  6158. scripts_echoLog({
  6159. text: i18n('needInit')
  6160. });
  6161. return false;
  6162. }
  6163. if ([ ...wishlistLinks, ...followLinks, ...curatorLinks, ...curatorLikeLinks, ...announcementLinks, ...licenseLinks, ...playtestLinks ].length > 0 && !this.#storeInitialized) {
  6164. scripts_echoLog({
  6165. text: i18n('needInit')
  6166. });
  6167. return false;
  6168. }
  6169. const prom = [];
  6170. if (doTask && !globalOptions.doTask.steam.groups || !doTask && !globalOptions.undoTask.steam.groups) {
  6171. scripts_echoLog({
  6172. type: 'globalOptionsSkip',
  6173. text: 'steam.groups'
  6174. });
  6175. } else {
  6176. const realGroups = this.getRealParams('groups', groupLinks, doTask, link => link.match(/groups\/(.+)\/?/)?.[1]);
  6177. if (realGroups.length > 0) {
  6178. for (const group of realGroups) {
  6179. if (doTask) {
  6180. prom.push(this.#joinGroup(group));
  6181. } else {
  6182. prom.push(this.#leaveGroup(group));
  6183. }
  6184. await delay(1e3);
  6185. }
  6186. }
  6187. }
  6188. if (doTask && !globalOptions.doTask.steam.officialGroups || !doTask && !globalOptions.undoTask.steam.officialGroups) {
  6189. scripts_echoLog({
  6190. type: 'globalOptionsSkip',
  6191. text: 'steam.officialGroups'
  6192. });
  6193. } else {
  6194. const realOfficialGroups = this.getRealParams('officialGroups', officialGroupLinks, doTask, link => link.match(/games\/(.+)\/?/)?.[1]);
  6195. if (realOfficialGroups.length > 0) {
  6196. for (const officialGroup of realOfficialGroups) {
  6197. if (doTask) {
  6198. prom.push(this.#joinOfficialGroup(officialGroup));
  6199. } else {
  6200. prom.push(this.#leaveOfficialGroup(officialGroup));
  6201. }
  6202. await delay(1e3);
  6203. }
  6204. }
  6205. }
  6206. if (doTask && !globalOptions.doTask.steam.wishlists || !doTask && !globalOptions.undoTask.steam.wishlists) {
  6207. scripts_echoLog({
  6208. type: 'globalOptionsSkip',
  6209. text: 'steam.wishlists'
  6210. });
  6211. } else {
  6212. const realWishlists = this.getRealParams('wishlists', wishlistLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6213. if (realWishlists.length > 0) {
  6214. for (const game of realWishlists) {
  6215. if (doTask) {
  6216. prom.push(this.#addToWishlist(game));
  6217. } else {
  6218. prom.push(this.#removeFromWishlist(game));
  6219. }
  6220. await delay(1e3);
  6221. }
  6222. }
  6223. }
  6224. if (doTask && !globalOptions.doTask.steam.follows || !doTask && !globalOptions.undoTask.steam.follows) {
  6225. scripts_echoLog({
  6226. type: 'globalOptionsSkip',
  6227. text: 'steam.follows'
  6228. });
  6229. } else {
  6230. const realFollows = this.getRealParams('follows', followLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6231. if (realFollows.length > 0) {
  6232. for (const game of realFollows) {
  6233. prom.push(this.#toggleFollowGame(game, doTask));
  6234. await delay(1e3);
  6235. }
  6236. }
  6237. }
  6238. if (doTask && !globalOptions.doTask.steam.forums || !doTask && !globalOptions.undoTask.steam.forums) {
  6239. scripts_echoLog({
  6240. type: 'globalOptionsSkip',
  6241. text: 'steam.forums'
  6242. });
  6243. } else {
  6244. const realForums = this.getRealParams('forums', forumLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6245. if (realForums.length > 0) {
  6246. for (const forum of realForums) {
  6247. prom.push(this.#toggleForum(forum, doTask));
  6248. await delay(1e3);
  6249. }
  6250. }
  6251. }
  6252. if (doTask && !globalOptions.doTask.steam.workshops || !doTask && !globalOptions.undoTask.steam.workshops) {
  6253. scripts_echoLog({
  6254. type: 'globalOptionsSkip',
  6255. text: 'steam.workshops'
  6256. });
  6257. } else {
  6258. const realWorkshops = this.getRealParams('workshops', workshopLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6259. if (realWorkshops.length > 0) {
  6260. for (const workshop of realWorkshops) {
  6261. prom.push(this.#toggleFavoriteWorkshop(workshop, doTask));
  6262. await delay(1e3);
  6263. }
  6264. }
  6265. }
  6266. if (doTask && !globalOptions.doTask.steam.workshopVotes) {
  6267. scripts_echoLog({
  6268. type: 'globalOptionsSkip',
  6269. text: 'steam.workshopVotes'
  6270. });
  6271. } else {
  6272. const realworkshopVotes = this.getRealParams('workshopVotes', workshopVoteLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6273. if (doTask && realworkshopVotes.length > 0) {
  6274. for (const workshop of realworkshopVotes) {
  6275. prom.push(this.#voteUpWorkshop(workshop));
  6276. await delay(1e3);
  6277. }
  6278. }
  6279. }
  6280. if (doTask && !globalOptions.doTask.steam.curators || !doTask && !globalOptions.undoTask.steam.curators) {
  6281. scripts_echoLog({
  6282. type: 'globalOptionsSkip',
  6283. text: 'steam.curators'
  6284. });
  6285. } else {
  6286. const realCurators = this.getRealParams('curators', curatorLinks, doTask, link => link.match(/curator\/([\d]+)/)?.[1]);
  6287. const realCuratorLikes = this.getRealParams('curatorLikes', curatorLikeLinks, doTask, link => link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3).join('/'));
  6288. if (realCurators.length > 0) {
  6289. for (const curator of realCurators) {
  6290. prom.push(this.#toggleCurator(curator, doTask));
  6291. await delay(1e3);
  6292. }
  6293. }
  6294. if (realCuratorLikes.length > 0) {
  6295. for (const curatorLike of realCuratorLikes) {
  6296. prom.push(this.#toggleCuratorLike(curatorLike, doTask));
  6297. await delay(1e3);
  6298. }
  6299. }
  6300. }
  6301. if (doTask && !globalOptions.doTask.steam.announcements) {
  6302. scripts_echoLog({
  6303. type: 'globalOptionsSkip',
  6304. text: 'steam.announcements'
  6305. });
  6306. } else {
  6307. const realAnnouncements = this.getRealParams('announcements', announcementLinks, doTask, link => {
  6308. if (link.includes('store.steampowered.com')) {
  6309. return link.match(/store\.steampowered\.com\/news\/app\/([\d]+)\/view\/([\d]+)/)?.slice(1, 3).join('/');
  6310. }
  6311. return link.match(/steamcommunity\.com\/games\/([\d]+)\/announcements\/detail\/([\d]+)/)?.slice(1, 3).join('/');
  6312. });
  6313. if (doTask && realAnnouncements.length > 0) {
  6314. for (const id of realAnnouncements) {
  6315. prom.push(this.#likeAnnouncement(id));
  6316. await delay(1e3);
  6317. }
  6318. }
  6319. }
  6320. if (doTask && !globalOptions.doTask.steam.licenses) {
  6321. scripts_echoLog({
  6322. type: 'globalOptionsSkip',
  6323. text: 'steam.licenses'
  6324. });
  6325. } else if (doTask && globalOptions.doTask.steam.licenses && licenseLinks.length > 0) {
  6326. for (const id of licenseLinks) {
  6327. prom.push(this.#addLicense(id));
  6328. await delay(1e3);
  6329. }
  6330. }
  6331. if (doTask && !globalOptions.doTask.steam.playtests) {
  6332. scripts_echoLog({
  6333. type: 'globalOptionsSkip',
  6334. text: 'steam.playtests'
  6335. });
  6336. } else {
  6337. const realPlaytests = this.getRealParams('playtests', playtestLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6338. if (doTask && globalOptions.doTask.steam.playtests && realPlaytests.length > 0) {
  6339. for (const id of realPlaytests) {
  6340. prom.push(this.#requestPlayTestAccess(id));
  6341. await delay(1e3);
  6342. }
  6343. }
  6344. }
  6345. return Promise.all(prom).then(async () => {
  6346. if (this.#area !== 'CN') {
  6347. scripts_echoLog({}).warning(i18n('steamFinishNotice'));
  6348. await this.#changeArea('CN');
  6349. }
  6350. return true;
  6351. });
  6352. } catch (error) {
  6353. throwError(error, 'Steam.toggle');
  6354. return false;
  6355. }
  6356. }
  6357. #setCache(type, name, id) {
  6358. try {
  6359. this.#cache[type][name] = id;
  6360. GM_setValue('steamCache', this.#cache);
  6361. } catch (error) {
  6362. throwError(error, 'Steam.setCache');
  6363. }
  6364. }
  6365. }
  6366. const social_Steam = Steam;
  6367. class Website {
  6368. undoneTasks;
  6369. socialTasks;
  6370. giveawayId;
  6371. socialInitialized = {
  6372. discord: false,
  6373. instagram: false,
  6374. reddit: false,
  6375. twitch: false,
  6376. twitter: false,
  6377. vk: false,
  6378. youtube: false,
  6379. steamStore: false,
  6380. steamCommunity: false
  6381. };
  6382. initialized = false;
  6383. social = {};
  6384. async #bind(name, init) {
  6385. try {
  6386. return {
  6387. name: name,
  6388. result: await init
  6389. };
  6390. } catch (error) {
  6391. throwError(error, 'Website.bind');
  6392. return {
  6393. name: name,
  6394. result: false
  6395. };
  6396. }
  6397. }
  6398. async initSocial(action) {
  6399. try {
  6400. const pro = [];
  6401. const tasks = action === 'do' ? this.undoneTasks : this.socialTasks;
  6402. if (tasks.discord) {
  6403. const hasDiscord = Object.values(tasks.discord).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6404. if (hasDiscord && (!this.socialInitialized.discord || !this.social.discord)) {
  6405. this.social.discord = new social_Discord();
  6406. pro.push(this.#bind('discord', this.social.discord.init()));
  6407. }
  6408. }
  6409. if (tasks.instagram) {
  6410. const hasInstagram = Object.values(tasks.instagram).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6411. if (hasInstagram && (!this.socialInitialized.instagram || !this.social.instagram)) {
  6412. this.social.instagram = new social_Instagram();
  6413. pro.push(this.#bind('instagram', this.social.instagram.init()));
  6414. }
  6415. }
  6416. if (tasks.reddit) {
  6417. const hasReddit = Object.values(tasks.reddit).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6418. if (hasReddit && (!this.socialInitialized.reddit || !this.social.reddit)) {
  6419. this.social.reddit = new social_Reddit();
  6420. pro.push(this.#bind('reddit', this.social.reddit.init()));
  6421. }
  6422. }
  6423. if (tasks.twitch) {
  6424. const hasTwitch = Object.values(tasks.twitch).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6425. if (hasTwitch && (!this.socialInitialized.twitch || !this.social.twitch)) {
  6426. this.social.twitch = new social_Twitch();
  6427. pro.push(this.#bind('twitch', this.social.twitch.init()));
  6428. }
  6429. }
  6430. if (tasks.twitter) {
  6431. const hasTwitter = Object.values(tasks.twitter).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6432. if (hasTwitter && (!this.socialInitialized.twitter || !this.social.twitter)) {
  6433. this.social.twitter = new social_Twitter();
  6434. pro.push(this.#bind('twitter', this.social.twitter.init()));
  6435. }
  6436. }
  6437. if (tasks.vk) {
  6438. const hasVk = Object.values(tasks.vk).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6439. if (hasVk && (!this.socialInitialized.vk || !this.social.vk)) {
  6440. this.social.vk = new social_Vk();
  6441. pro.push(this.#bind('vk', this.social.vk.init()));
  6442. }
  6443. }
  6444. if (tasks.youtube) {
  6445. const hasYoutube = Object.values(tasks.youtube).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6446. if (hasYoutube && (!this.socialInitialized.youtube || !this.social.youtube)) {
  6447. this.social.youtube = new Youtube();
  6448. pro.push(this.#bind('youtube', this.social.youtube.init()));
  6449. }
  6450. }
  6451. if (tasks.steam) {
  6452. const steamLength = Object.values(tasks.steam).reduce((total, arr) => [ ...total, ...arr ]).length;
  6453. if (steamLength > 0) {
  6454. if (!this.social.steam) {
  6455. this.social.steam = new social_Steam();
  6456. }
  6457. 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);
  6458. if (steamLength - steamCommunityLength > 0 && !this.socialInitialized.steamStore) {
  6459. pro.push(this.#bind('steamStore', this.social.steam.init('store')));
  6460. }
  6461. if (steamCommunityLength > 0 && !this.socialInitialized.steamCommunity) {
  6462. pro.push(this.#bind('steamCommunity', this.social.steam.init('community')));
  6463. }
  6464. }
  6465. }
  6466. if (tasks.links && tasks.links.length > 0) {
  6467. this.social.visitLink = visitLink;
  6468. }
  6469. return await Promise.all(pro).then(result => {
  6470. let checked = true;
  6471. for (const data of result) {
  6472. if (data.result) {
  6473. this.socialInitialized[data.name] = data.result;
  6474. } else {
  6475. checked = false;
  6476. }
  6477. }
  6478. return checked;
  6479. });
  6480. } catch (error) {
  6481. throwError(error, 'Website.initSocial');
  6482. return false;
  6483. }
  6484. }
  6485. uniqueTasks(allTasks) {
  6486. const result = {};
  6487. for (const [ social, types ] of Object.entries(allTasks)) {
  6488. result[social] = {};
  6489. for (const [ type, tasks ] of Object.entries(types)) {
  6490. result[social][type] = unique(tasks);
  6491. }
  6492. }
  6493. return result;
  6494. }
  6495. async toggleTask(action) {
  6496. try {
  6497. if (!this.initialized && !this.init()) {
  6498. return false;
  6499. }
  6500. if (!await this.classifyTask(action)) {
  6501. return false;
  6502. }
  6503. if (!await this.initSocial(action)) {
  6504. return false;
  6505. }
  6506. const pro = [];
  6507. const doTask = action === 'do';
  6508. const tasks = doTask ? this.undoneTasks : this.socialTasks;
  6509. if (this.socialInitialized.discord !== 'skip' && this.social.discord) {
  6510. pro.push(this.social.discord.toggle({
  6511. doTask: doTask,
  6512. ...tasks.discord
  6513. }));
  6514. }
  6515. if (this.social.instagram) {
  6516. pro.push(this.social.instagram.toggle({
  6517. doTask: doTask,
  6518. ...tasks.instagram
  6519. }));
  6520. }
  6521. if (this.social.reddit) {
  6522. pro.push(this.social.reddit.toggle({
  6523. doTask: doTask,
  6524. ...tasks.reddit
  6525. }));
  6526. }
  6527. if (this.social.twitch) {
  6528. pro.push(this.social.twitch.toggle({
  6529. doTask: doTask,
  6530. ...tasks.twitch
  6531. }));
  6532. }
  6533. if (this.social.twitter) {
  6534. pro.push(this.social.twitter.toggle({
  6535. doTask: doTask,
  6536. ...tasks.twitter
  6537. }));
  6538. }
  6539. if (this.social.vk) {
  6540. pro.push(this.social.vk.toggle({
  6541. doTask: doTask,
  6542. ...tasks.vk
  6543. }));
  6544. }
  6545. if (this.social.youtube) {
  6546. pro.push(this.social.youtube.toggle({
  6547. doTask: doTask,
  6548. ...tasks.youtube
  6549. }));
  6550. }
  6551. if (this.social.steam) {
  6552. pro.push(this.social.steam.toggle({
  6553. doTask: doTask,
  6554. ...tasks.steam
  6555. }));
  6556. }
  6557. if (this.social.visitLink && tasks.links && doTask) {
  6558. for (const link of tasks.links) {
  6559. pro.push(this.social.visitLink(link));
  6560. }
  6561. }
  6562. if (doTask && tasks.extra && this.extraDoTask) {
  6563. const hasExtra = Object.values(tasks.extra).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6564. if (hasExtra) {
  6565. pro.push(this.extraDoTask(tasks.extra));
  6566. }
  6567. }
  6568. await Promise.all(pro);
  6569. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6570. return true;
  6571. } catch (error) {
  6572. throwError(error, 'Website.toggleTask');
  6573. return false;
  6574. }
  6575. }
  6576. async doTask() {
  6577. try {
  6578. return await this.toggleTask('do');
  6579. } catch (error) {
  6580. throwError(error, 'Website.doTask');
  6581. return false;
  6582. }
  6583. }
  6584. async undoTask() {
  6585. try {
  6586. return await this.toggleTask('undo');
  6587. } catch (error) {
  6588. throwError(error, 'Website.undoTask');
  6589. return false;
  6590. }
  6591. }
  6592. }
  6593. const website_Website = Website;
  6594. const defaultTasksTemplate = {
  6595. steam: {
  6596. groupLinks: [],
  6597. wishlistLinks: [],
  6598. curatorLinks: [],
  6599. followLinks: []
  6600. },
  6601. vk: {
  6602. nameLinks: []
  6603. }
  6604. };
  6605. const defaultTasks = JSON.stringify(defaultTasksTemplate);
  6606. class FreeAnyWhere extends website_Website {
  6607. name = 'FreeAnyWhere';
  6608. tasks = [];
  6609. socialTasks = JSON.parse(defaultTasks);
  6610. undoneTasks = JSON.parse(defaultTasks);
  6611. buttons = [ 'doTask', 'undoTask', 'verifyTask', 'getKey' ];
  6612. static test() {
  6613. return window.location.host === 'freeanywhere.net';
  6614. }
  6615. async init() {
  6616. try {
  6617. const logStatus = scripts_echoLog({
  6618. text: i18n('initing')
  6619. });
  6620. if ($('a[href="#/login"]').length > 0) {
  6621. window.open('/#/login', '_self');
  6622. logStatus.warning(i18n('needLogin'));
  6623. return false;
  6624. }
  6625. if (window.location.href.includes('/login')) {
  6626. logStatus.warning(i18n('needLogin'));
  6627. return false;
  6628. }
  6629. if (!/^https?:\/\/freeanywhere\.net\/#\/giveaway\/[\d]+/.test(window.location.href)) {
  6630. const id = window.location.href.match(/https?:\/\/freeanywhere\.net\/.*?#\/giveaway\/([\d]+)/)?.[1];
  6631. if (!id) {
  6632. logStatus.error(i18n('getFailed', 'Id'));
  6633. return false;
  6634. }
  6635. window.location.href = `https://freeanywhere.net/#/giveaway/${id}`;
  6636. }
  6637. if (!this.#getGiveawayId()) {
  6638. return false;
  6639. }
  6640. if (!await this.#checkLeftKey()) {
  6641. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  6642. }
  6643. this.initialized = true;
  6644. logStatus.success();
  6645. return true;
  6646. } catch (error) {
  6647. throwError(error, 'Freeanywhere.init');
  6648. return false;
  6649. }
  6650. }
  6651. async classifyTask(action) {
  6652. try {
  6653. const logStatus = scripts_echoLog({
  6654. text: i18n('getTasksInfo')
  6655. });
  6656. if (action === 'undo') {
  6657. this.socialTasks = GM_getValue(`fawTasks-${this.giveawayId}`)?.tasks || JSON.parse(defaultTasks);
  6658. }
  6659. const {
  6660. result,
  6661. statusText,
  6662. status,
  6663. data
  6664. } = await tools_httpRequest({
  6665. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/?format=json`,
  6666. method: 'GET',
  6667. headers: {
  6668. authorization: `Token ${window.localStorage.getItem('token')}`,
  6669. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  6670. },
  6671. responseType: 'json'
  6672. });
  6673. if (result === 'Success') {
  6674. const tasks = data?.response?.challenges;
  6675. if (tasks) {
  6676. if (action === 'verify') {
  6677. this.tasks = [];
  6678. }
  6679. for (const task of tasks) {
  6680. const type = task.challenge;
  6681. const social = task.challenge_provider;
  6682. const taskInfo = {
  6683. id: task.id,
  6684. title: task.title
  6685. };
  6686. if (action === 'verify' && !task.is_success) {
  6687. this.tasks.push(taskInfo);
  6688. continue;
  6689. }
  6690. switch (social) {
  6691. case 'steam':
  6692. taskInfo.social = 'steam';
  6693. switch (type) {
  6694. case 'WL':
  6695. if (action === 'undo') {
  6696. this.socialTasks.steam.wishlistLinks.push(task.link);
  6697. }
  6698. if (action === 'do' && !task.is_success) {
  6699. this.undoneTasks.steam.wishlistLinks.push(task.link);
  6700. }
  6701. break;
  6702.  
  6703. case 'JTG':
  6704. if (action === 'undo') {
  6705. this.socialTasks.steam.groupLinks.push(task.link);
  6706. }
  6707. if (action === 'do' && !task.is_success) {
  6708. this.undoneTasks.steam.groupLinks.push(task.link);
  6709. }
  6710. break;
  6711.  
  6712. case 'STC':
  6713. if (action === 'undo') {
  6714. this.socialTasks.steam.curatorLinks.push(task.link);
  6715. }
  6716. if (action === 'do' && !task.is_success) {
  6717. this.undoneTasks.steam.curatorLinks.push(task.link);
  6718. }
  6719. break;
  6720.  
  6721. case 'GF':
  6722. if (action === 'undo') {
  6723. this.socialTasks.steam.followLinks.push(task.link);
  6724. }
  6725. if (action === 'do' && !task.is_success) {
  6726. this.undoneTasks.steam.followLinks.push(task.link);
  6727. }
  6728. break;
  6729. }
  6730. break;
  6731.  
  6732. case 'vk-oauth2':
  6733. if (action === 'undo') {
  6734. this.socialTasks.vk.nameLinks.push(task.link);
  6735. }
  6736. if (action === 'do' && !task.is_success) {
  6737. this.undoneTasks.vk.nameLinks.push(task.link);
  6738. }
  6739. break;
  6740.  
  6741. case 'website':
  6742. break;
  6743.  
  6744. default:
  6745. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${social}`);
  6746. break;
  6747. }
  6748. }
  6749. logStatus.success();
  6750. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  6751. this.socialTasks = this.uniqueTasks(this.socialTasks);
  6752. if (window.DEBUG) {
  6753. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  6754. }
  6755. GM_setValue(`fawTasks-${this.giveawayId}`, {
  6756. tasks: this.socialTasks,
  6757. time: new Date().getTime()
  6758. });
  6759. return true;
  6760. }
  6761. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6762. return false;
  6763. }
  6764. logStatus.error(`${result}:${statusText}(${status})`);
  6765. return false;
  6766. } catch (error) {
  6767. throwError(error, 'Freeanywhere.classifyTask');
  6768. return false;
  6769. }
  6770. }
  6771. async verifyTask() {
  6772. try {
  6773. if (!this.initialized && !this.init()) {
  6774. return false;
  6775. }
  6776. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  6777. return false;
  6778. }
  6779. const pro = [];
  6780. for (const task of this.tasks) {
  6781. pro.push(this.#verify(task));
  6782. await delay(1e3);
  6783. }
  6784. await Promise.all(pro);
  6785. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6786. return !!await this.getKey(true);
  6787. } catch (error) {
  6788. throwError(error, 'Freeanywhere.verifyTask');
  6789. return false;
  6790. }
  6791. }
  6792. async getKey(initialized) {
  6793. try {
  6794. if (!initialized && !this.initialized && !this.init()) {
  6795. return false;
  6796. }
  6797. const logStatus = scripts_echoLog({
  6798. text: i18n('gettingKey')
  6799. });
  6800. const {
  6801. result,
  6802. statusText,
  6803. status,
  6804. data
  6805. } = await tools_httpRequest({
  6806. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/reward/?format=json`,
  6807. method: 'GET',
  6808. dataType: 'json',
  6809. headers: {
  6810. authorization: `Token ${window.localStorage.getItem('token')}`
  6811. }
  6812. });
  6813. if (result === 'Success') {
  6814. if (data?.response?.reward) {
  6815. logStatus.success();
  6816. scripts_echoLog({}).success(data.response.reward);
  6817. return data.response.reward;
  6818. }
  6819. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6820. return false;
  6821. }
  6822. logStatus.error(`${result}:${statusText}(${status})`);
  6823. return false;
  6824. } catch (error) {
  6825. throwError(error, 'FreeAnyWhere.getGiveawayId');
  6826. return false;
  6827. }
  6828. }
  6829. #getGiveawayId() {
  6830. try {
  6831. const giveawayId = window.location.href.match(/\/giveaway\/([\d]+)/)?.[1];
  6832. if (giveawayId) {
  6833. this.giveawayId = giveawayId;
  6834. return true;
  6835. }
  6836. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  6837. return false;
  6838. } catch (error) {
  6839. throwError(error, 'FreeAnyWhere.getGiveawayId');
  6840. }
  6841. }
  6842. async #verify(task) {
  6843. try {
  6844. const logStatus = scripts_echoLog({
  6845. html: `<li>${i18n('verifyingTask')}${task.title.trim()}...<font></font></li>`
  6846. });
  6847. const {
  6848. result,
  6849. statusText,
  6850. status,
  6851. data
  6852. } = await tools_httpRequest({
  6853. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/challenge-status/${task.id}/?format=json`,
  6854. method: 'GET',
  6855. dataType: 'json',
  6856. headers: {
  6857. authorization: `Token ${window.localStorage.getItem('token')}`,
  6858. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  6859. }
  6860. });
  6861. if (result === 'Success') {
  6862. if (data?.response?.status) {
  6863. logStatus.success();
  6864. return true;
  6865. }
  6866. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6867. return false;
  6868. }
  6869. logStatus.error(`${result}:${statusText}(${status})`);
  6870. return false;
  6871. } catch (error) {
  6872. throwError(error, 'Freeanywhere.verify');
  6873. return false;
  6874. }
  6875. }
  6876. async #checkLeftKey() {
  6877. try {
  6878. if (!globalOptions.other.checkLeftKey) {
  6879. return true;
  6880. }
  6881. const {
  6882. data
  6883. } = await tools_httpRequest({
  6884. url: 'https://freeanywhere.net/api/v1/widget/?format=json',
  6885. method: 'GET',
  6886. dataType: 'json',
  6887. headers: {
  6888. authorization: `Token ${window.localStorage.getItem('token')}`
  6889. }
  6890. });
  6891. if (data?.response?.giveaways.find(giveaway => `${giveaway?.id}` === this.giveawayId)) {
  6892. return true;
  6893. }
  6894. await external_Swal_default().fire({
  6895. icon: 'warning',
  6896. title: i18n('notice'),
  6897. text: i18n('noKeysLeft'),
  6898. confirmButtonText: i18n('confirm'),
  6899. cancelButtonText: i18n('cancel'),
  6900. showCancelButton: true
  6901. }).then(({
  6902. value
  6903. }) => {
  6904. if (value) {
  6905. window.close();
  6906. }
  6907. });
  6908. return true;
  6909. } catch (error) {
  6910. throwError(error, 'Giveawaysu.checkLeftKey');
  6911. return false;
  6912. }
  6913. }
  6914. }
  6915. const website_FreeAnyWhere = FreeAnyWhere;
  6916. const GiveawaySu_defaultTasks = {
  6917. steam: {
  6918. groupLinks: [],
  6919. wishlistLinks: [],
  6920. curatorLinks: [],
  6921. curatorLikeLinks: [],
  6922. followLinks: [],
  6923. forumLinks: [],
  6924. announcementLinks: [],
  6925. workshopVoteLinks: [],
  6926. playtestLinks: []
  6927. },
  6928. discord: {
  6929. serverLinks: []
  6930. },
  6931. instagram: {
  6932. userLinks: []
  6933. },
  6934. vk: {
  6935. nameLinks: []
  6936. },
  6937. twitch: {
  6938. channelLinks: []
  6939. },
  6940. reddit: {
  6941. redditLinks: []
  6942. },
  6943. youtube: {
  6944. channelLinks: [],
  6945. likeLinks: []
  6946. },
  6947. twitter: {
  6948. userLinks: [],
  6949. retweetLinks: []
  6950. }
  6951. };
  6952. class GiveawaySu extends website_Website {
  6953. name = 'GiveawaySu';
  6954. socialTasks = GiveawaySu_defaultTasks;
  6955. undoneTasks = GiveawaySu_defaultTasks;
  6956. buttons = [ 'doTask', 'undoTask' ];
  6957. static test() {
  6958. return /^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(window.location.href);
  6959. }
  6960. async after() {
  6961. try {
  6962. if (!this.#checkLogin()) {
  6963. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  6964. }
  6965. if (!await this.#checkLeftKey()) {
  6966. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  6967. }
  6968. scripts_echoLog({}).warning(i18n('gsNotice'));
  6969. } catch (error) {
  6970. throwError(error, 'Giveawaysu.after');
  6971. }
  6972. }
  6973. init() {
  6974. try {
  6975. const logStatus = scripts_echoLog({
  6976. text: i18n('initing')
  6977. });
  6978. if ($('a.steam-login').length > 0) {
  6979. window.open('/steam/redirect', '_self');
  6980. logStatus.warning(i18n('needLogin'));
  6981. return false;
  6982. }
  6983. if (!this.#getGiveawayId()) {
  6984. return false;
  6985. }
  6986. this.initialized = true;
  6987. logStatus.success();
  6988. return true;
  6989. } catch (error) {
  6990. throwError(error, 'Giveawaysu.init');
  6991. return false;
  6992. }
  6993. }
  6994. async classifyTask(action) {
  6995. try {
  6996. const logStatus = scripts_echoLog({
  6997. text: i18n('getTasksInfo')
  6998. });
  6999. if (action === 'undo') {
  7000. this.socialTasks = GM_getValue(`gasTasks-${this.giveawayId}`)?.tasks || GiveawaySu_defaultTasks;
  7001. return true;
  7002. }
  7003. const pro = [];
  7004. const tasks = $('#actions tr');
  7005. if ($('div.bind-discord').is(':visible')) {
  7006. $('div.bind-discord a')[0].click();
  7007. }
  7008. if ($('div.bind-twitch').is(':visible')) {
  7009. $('div.bind-twitch a')[0].click();
  7010. }
  7011. for (const task of tasks) {
  7012. pro.push(new Promise(resolve => {
  7013. const td = $(task).find('td:not(".hidden")');
  7014. const colorfulTask = td.eq(1).find('a:not([data-trigger="link"])');
  7015. const colorlessTask = td.eq(2).find('a:not([data-trigger="link"])');
  7016. const taskDes = colorfulTask.length > 0 ? colorfulTask : colorlessTask;
  7017. const taskIcon = td.eq(0).find('i').attr('class') || '';
  7018. const taskName = taskDes.text().trim();
  7019. if (taskIcon.includes('ban') || /disable adblock/gi.test(taskName)) {
  7020. return resolve(true);
  7021. }
  7022. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  7023. if (!taskLink) {
  7024. return resolve(false);
  7025. }
  7026. if (taskIcon.includes('steam') && /join/gi.test(taskName)) {
  7027. this.undoneTasks.steam.groupLinks.push(taskLink);
  7028. } else if (/like.*announcement/gi.test(taskName)) {
  7029. this.undoneTasks.steam.announcementLinks.push(taskLink);
  7030. } else if (/(follow|subscribe).*curator/gim.test(taskName) && /^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  7031. this.undoneTasks.steam.curatorLinks.push(taskLink);
  7032. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  7033. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  7034. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  7035. this.undoneTasks.steam.forumLinks.push(taskLink);
  7036. } else if (taskIcon.includes('thumbs-up') && /^https?:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=[\d]+/.test(taskLink)) {
  7037. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7038. } else if (taskIcon.includes('plus') && /request.*playtest/gim.test(taskName)) {
  7039. this.undoneTasks.steam.playtestLinks.push(taskLink);
  7040. } else if (taskIcon.includes('discord') || /join.*discord/gim.test(taskName)) {
  7041. this.undoneTasks.discord.serverLinks.push(taskLink);
  7042. } else if (taskIcon.includes('instagram') || /follow.*instagram/gim.test(taskName)) {
  7043. this.undoneTasks.instagram.userLinks.push(taskLink);
  7044. } else if (taskIcon.includes('twitch') || /follow.*twitch.*channel/gim.test(taskName)) {
  7045. this.undoneTasks.twitch.channelLinks.push(taskLink);
  7046. } else if (taskIcon.includes('reddit') || /subscribe.*subreddit/gim.test(taskName) || /follow.*reddit/gim.test(taskName)) {
  7047. this.undoneTasks.reddit.redditLinks.push(taskLink);
  7048. } else if (/watch.*art/gim.test(taskName)) {
  7049. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7050. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  7051. this.undoneTasks.youtube.channelLinks.push(taskLink);
  7052. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  7053. this.undoneTasks.youtube.likeLinks.push(taskLink);
  7054. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  7055. this.undoneTasks.vk.nameLinks.push(taskLink);
  7056. } else {
  7057. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  7058. if (/wishlist.*game|add.*wishlist/gim.test(taskName)) {
  7059. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  7060. }
  7061. if (/follow.*button/gim.test(taskName)) {
  7062. this.undoneTasks.steam.followLinks.push(taskLink);
  7063. }
  7064. }
  7065. }
  7066. resolve(true);
  7067. }).catch(error => {
  7068. throwError(error, 'Giveawaysu.classifyTask->getRedirectLink');
  7069. return false;
  7070. });
  7071. }));
  7072. }
  7073. await Promise.all(pro);
  7074. logStatus.success();
  7075. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7076. this.socialTasks = this.undoneTasks;
  7077. if (window.DEBUG) {
  7078. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7079. }
  7080. GM_setValue(`gasTasks-${this.giveawayId}`, {
  7081. tasks: this.socialTasks,
  7082. time: new Date().getTime()
  7083. });
  7084. return true;
  7085. } catch (error) {
  7086. throwError(error, 'Giveawaysu.classifyTask');
  7087. return false;
  7088. }
  7089. }
  7090. #checkLogin() {
  7091. try {
  7092. if (!globalOptions.other.checkLogin) {
  7093. return true;
  7094. }
  7095. if ($('a.steam-login').length > 0) {
  7096. window.open('/steam/redirect', '_self');
  7097. }
  7098. return true;
  7099. } catch (error) {
  7100. throwError(error, 'Giveawaysu.checkLogin');
  7101. return false;
  7102. }
  7103. }
  7104. async #checkLeftKey() {
  7105. try {
  7106. if (!globalOptions.other.checkLeftKey) {
  7107. return true;
  7108. }
  7109. if ($('.giveaway-ended').length > 0 && $('.giveaway-key').length === 0) {
  7110. await external_Swal_default().fire({
  7111. icon: 'warning',
  7112. title: i18n('notice'),
  7113. text: i18n('noKeysLeft'),
  7114. confirmButtonText: i18n('confirm'),
  7115. cancelButtonText: i18n('cancel'),
  7116. showCancelButton: true
  7117. }).then(({
  7118. value
  7119. }) => {
  7120. if (value) {
  7121. window.close();
  7122. }
  7123. });
  7124. }
  7125. return true;
  7126. } catch (error) {
  7127. throwError(error, 'Giveawaysu.checkLeftKey');
  7128. return false;
  7129. }
  7130. }
  7131. #getGiveawayId() {
  7132. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  7133. if (giveawayId) {
  7134. this.giveawayId = giveawayId;
  7135. return true;
  7136. }
  7137. scripts_echoLog({
  7138. text: i18n('getFailed', 'GiveawayId')
  7139. });
  7140. return false;
  7141. }
  7142. }
  7143. class Indiedb {
  7144. name = 'Indiedb';
  7145. buttons = [ 'doTask' ];
  7146. static test() {
  7147. return window.location.host === 'www.indiedb.com';
  7148. }
  7149. async after() {
  7150. try {
  7151. if (!this.#checkLogin()) {
  7152. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7153. }
  7154. if (!await this.#checkLeftKey()) {
  7155. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7156. }
  7157. } catch (error) {
  7158. throwError(error, 'Indiedb.after');
  7159. }
  7160. }
  7161. async doTask() {
  7162. try {
  7163. if (!await this.#join()) {
  7164. return false;
  7165. }
  7166. return await this.#do();
  7167. } catch (error) {
  7168. throwError(error, 'Indiedb.doTask');
  7169. return false;
  7170. }
  7171. }
  7172. async #join() {
  7173. try {
  7174. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7175. scripts_echoLog({}).error(i18n('needLogin'));
  7176. return false;
  7177. }
  7178. const currentoption = $('a.buttonenter.buttongiveaway');
  7179. if (/join giveaway/gim.test(currentoption.text())) {
  7180. const logStatus = scripts_echoLog({
  7181. text: `${i18n('joiningGiveaway')}...`
  7182. });
  7183. const {
  7184. result,
  7185. statusText,
  7186. status,
  7187. data
  7188. } = await tools_httpRequest({
  7189. url: currentoption.attr('href'),
  7190. method: 'POST',
  7191. data: 'ajax=t',
  7192. dataType: 'json',
  7193. headers: {
  7194. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  7195. accept: 'application/json, text/javascript, */*; q=0.01',
  7196. origin: window.location.origin
  7197. }
  7198. });
  7199. if (result === 'Success') {
  7200. if (data?.status === 200) {
  7201. if (data.response?.success) {
  7202. currentoption.addClass('buttonentered').text('Success - Giveaway joined');
  7203. $('#giveawaysjoined').slideDown();
  7204. $('#giveawaysrecommend').slideDown();
  7205. logStatus.success(`Success${data.response?.text ? `:${data.response?.text}` : ''}`);
  7206. return true;
  7207. }
  7208. logStatus.error(`Error${data.response?.text ? `:${data.response?.text}` : ''}`);
  7209. return false;
  7210. }
  7211. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7212. return false;
  7213. }
  7214. logStatus.error(`${result}:${statusText}(${status})`);
  7215. return false;
  7216. } else if (/success/gim.test($('a.buttonenter.buttongiveaway').text())) {
  7217. return true;
  7218. }
  7219. scripts_echoLog({}).warning(i18n('needJoinGiveaway'));
  7220. return false;
  7221. } catch (error) {
  7222. throwError(error, 'Indiedb.init');
  7223. return false;
  7224. }
  7225. }
  7226. async #do() {
  7227. try {
  7228. const id = $('script').map((index, script) => {
  7229. if (/\$\(document\)/gim.test(script.innerHTML)) {
  7230. return [ script.innerHTML.match(/"\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0], script.innerHTML.match(/"\/newsletter\/ajax\/subscribeprofile\/optin\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0] ];
  7231. }
  7232. return null;
  7233. });
  7234. if (id.length === 2) {
  7235. const pro = [];
  7236. const tasks = $('#giveawaysjoined a[class*=promo]');
  7237. for (const task of tasks) {
  7238. const promo = $(task);
  7239. if (!promo.hasClass('buttonentered')) {
  7240. const status = scripts_echoLog({
  7241. text: `${i18n('doing')}:${promo.parents('p').text()}...`
  7242. });
  7243. if (/facebookpromo|twitterpromo|visitpromo/gim.test(task.className)) {
  7244. let text = '';
  7245. if (promo.hasClass('facebookpromo')) {
  7246. text = 'facebookpromo';
  7247. } else if (promo.hasClass('twitterpromo')) {
  7248. text = 'twitterpromo';
  7249. } else {
  7250. text = 'visitpromo';
  7251. }
  7252. pro.push(new Promise(resolve => {
  7253. $.ajax({
  7254. type: 'POST',
  7255. url: urlPath(`/giveaways/ajax/${text}/${id[0]}`),
  7256. timeout: 6e4,
  7257. dataType: 'json',
  7258. data: {
  7259. ajax: 't'
  7260. },
  7261. error(response, error, exception) {
  7262. if (window.DEBUG) {
  7263. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7264. response: response,
  7265. error: error,
  7266. exception: exception
  7267. });
  7268. }
  7269. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7270. resolve(true);
  7271. },
  7272. success(response) {
  7273. if (response.success) {
  7274. status.success(`Success:${response.text}`);
  7275. promo.addClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7276. resolve(true);
  7277. } else {
  7278. status.error(`Error:${response.text}`);
  7279. resolve(true);
  7280. }
  7281. }
  7282. });
  7283. }));
  7284. } else if (promo.hasClass('emailoptinpromo')) {
  7285. pro.push(new Promise(resolve => {
  7286. $.ajax({
  7287. type: 'POST',
  7288. url: urlPath(`/newsletter/ajax/subscribeprofile/optin/${id[1]}`),
  7289. timeout: 6e4,
  7290. dataType: 'json',
  7291. data: {
  7292. ajax: 't',
  7293. emailsystoggle: 4
  7294. },
  7295. error(response, error, exception) {
  7296. if (window.DEBUG) {
  7297. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7298. response: response,
  7299. error: error,
  7300. exception: exception
  7301. });
  7302. }
  7303. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7304. resolve(true);
  7305. },
  7306. success(response) {
  7307. if (response.success) {
  7308. status.success(`Success:${response.text}`);
  7309. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7310. resolve(true);
  7311. } else {
  7312. status.error(`Error:${response.text}`);
  7313. resolve(true);
  7314. }
  7315. }
  7316. });
  7317. }));
  7318. } else if (promo.hasClass('watchingpromo')) {
  7319. pro.push(new Promise(resolve => {
  7320. const data = getUrlQuery(promo.attr('href'));
  7321. data.ajax = 't';
  7322. $.ajax({
  7323. type: 'POST',
  7324. url: urlPath(promo.attr('href')?.split(/[?#]/)[0]),
  7325. timeout: 6e4,
  7326. dataType: 'json',
  7327. data: data,
  7328. error(response, error, exception) {
  7329. if (window.DEBUG) {
  7330. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7331. response: response,
  7332. error: error,
  7333. exception: exception
  7334. });
  7335. }
  7336. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7337. resolve(true);
  7338. },
  7339. success(response) {
  7340. if (response.success) {
  7341. status.success(`Success:${response.text}`);
  7342. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7343. resolve(true);
  7344. } else {
  7345. status.error(`Error:${response.text}`);
  7346. resolve(true);
  7347. }
  7348. }
  7349. });
  7350. }));
  7351. } else if (!/the-challenge-of-adblock/gim.test(promo.attr('href'))) {
  7352. pro.push(new Promise(resolve => {
  7353. $.ajax({
  7354. type: 'POST',
  7355. url: urlPath(promo.attr('href')),
  7356. timeout: 6e4,
  7357. dataType: 'json',
  7358. data: {
  7359. ajax: 't'
  7360. },
  7361. error(response, error, exception) {
  7362. if (window.DEBUG) {
  7363. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7364. response: response,
  7365. error: error,
  7366. exception: exception
  7367. });
  7368. }
  7369. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7370. resolve(true);
  7371. },
  7372. success(response) {
  7373. if (response.success) {
  7374. status.success(`Success:${response.text}`);
  7375. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7376. resolve(true);
  7377. } else {
  7378. status.error(`Error:${response.text}`);
  7379. resolve(true);
  7380. }
  7381. }
  7382. });
  7383. }));
  7384. } else {
  7385. status.error(`Error:${i18n('unKnownTaskType')}`);
  7386. }
  7387. }
  7388. }
  7389. await Promise.all(pro);
  7390. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7391. return true;
  7392. }
  7393. scripts_echoLog({}).error(i18n('getFailed', 'TaskId'));
  7394. return false;
  7395. } catch (error) {
  7396. throwError(error, 'Indiedb.classifyTask');
  7397. return false;
  7398. }
  7399. }
  7400. #checkLogin() {
  7401. try {
  7402. if (!globalOptions.other.checkLogin) {
  7403. return true;
  7404. }
  7405. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7406. window.open('/members/login', '_self');
  7407. }
  7408. return true;
  7409. } catch (error) {
  7410. throwError(error, 'Indiedb.checkLogin');
  7411. return false;
  7412. }
  7413. }
  7414. async #checkLeftKey() {
  7415. try {
  7416. if (!globalOptions.other.checkLeftKey) {
  7417. return true;
  7418. }
  7419. if ($('a.buttonenter:contains("next time"),a.buttonenter:contains("Giveaway is closed")').length > 0) {
  7420. await external_Swal_default().fire({
  7421. icon: 'warning',
  7422. title: i18n('notice'),
  7423. text: i18n('giveawayEnded'),
  7424. confirmButtonText: i18n('confirm'),
  7425. cancelButtonText: i18n('cancel'),
  7426. showCancelButton: true
  7427. }).then(({
  7428. value
  7429. }) => {
  7430. if (value) {
  7431. window.close();
  7432. }
  7433. });
  7434. }
  7435. return true;
  7436. } catch (error) {
  7437. throwError(error, 'Indiedb.checkLeftKey');
  7438. return false;
  7439. }
  7440. }
  7441. }
  7442. const website_Indiedb = Indiedb;
  7443. const Keyhub_defaultTasksTemplate = {
  7444. steam: {
  7445. groupLinks: [],
  7446. officialGroupLinks: [],
  7447. wishlistLinks: [],
  7448. curatorLinks: []
  7449. },
  7450. discord: {
  7451. serverLinks: []
  7452. },
  7453. extra: {
  7454. videoTasks: []
  7455. },
  7456. links: []
  7457. };
  7458. const Keyhub_defaultTasks = JSON.stringify(Keyhub_defaultTasksTemplate);
  7459. class Keyhub extends website_Website {
  7460. name = 'Keyhub';
  7461. socialTasks = JSON.parse(Keyhub_defaultTasks);
  7462. undoneTasks = JSON.parse(Keyhub_defaultTasks);
  7463. buttons = [ 'doTask', 'undoTask' ];
  7464. static test() {
  7465. return window.location.host === 'key-hub.eu';
  7466. }
  7467. async after() {
  7468. try {
  7469. if (!this.#checkLogin()) {
  7470. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7471. }
  7472. if (!await this.#checkLeftKey()) {
  7473. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7474. }
  7475. $('.NSFW').hide();
  7476. } catch (error) {
  7477. throwError(error, 'Keyhub.after');
  7478. }
  7479. }
  7480. init() {
  7481. try {
  7482. const logStatus = scripts_echoLog({
  7483. text: i18n('initing')
  7484. });
  7485. if ($('a[href*="/connect/steam"]').length > 0) {
  7486. window.open('/connect/steam', '_self');
  7487. logStatus.warning(i18n('needLogin'));
  7488. return false;
  7489. }
  7490. if (!this.#getGiveawayId()) {
  7491. return false;
  7492. }
  7493. $('#VPNoverlay').hide();
  7494. $('#mainArticleSection').show();
  7495. this.initialized = true;
  7496. logStatus.success();
  7497. return true;
  7498. } catch (error) {
  7499. throwError(error, 'Keyhub.init');
  7500. return false;
  7501. }
  7502. }
  7503. async classifyTask(action) {
  7504. try {
  7505. const logStatus = scripts_echoLog({
  7506. text: i18n('getTasksInfo')
  7507. });
  7508. if (action === 'undo') {
  7509. this.socialTasks = GM_getValue(`khTasks-${this.giveawayId}`)?.tasks || JSON.parse(Keyhub_defaultTasks);
  7510. }
  7511. const tasks = $('.task:not(".googleads")').filter((index, element) => action === 'do' ? $(element).find('i.fa-check-circle:visible').length === 0 : true).find('a');
  7512. for (const task of tasks) {
  7513. let link = $(task).attr('href');
  7514. const taskDes = $(task).text().trim();
  7515. if (!link) {
  7516. continue;
  7517. }
  7518. if (/\/away\?data=/.test(link) || /steamcommunity\.com\/gid\//.test(link)) {
  7519. link = await getRedirectLink(link) || link;
  7520. }
  7521. if (/https?:\/\/key-hub\.eu\/connect\/discord/.test(link)) {
  7522. window.open(link, '_blank');
  7523. } else if (/steamcommunity\.com\/groups\//.test(link)) {
  7524. if (action === 'undo') {
  7525. this.socialTasks.steam.groupLinks.push(link);
  7526. }
  7527. if (action === 'do') {
  7528. this.undoneTasks.steam.groupLinks.push(link);
  7529. }
  7530. } else if (/steamcommunity\.com\/games\/[\d]+/.test(link)) {
  7531. if (action === 'undo') {
  7532. this.socialTasks.steam.officialGroupLinks.push(link);
  7533. }
  7534. if (action === 'do') {
  7535. this.undoneTasks.steam.officialGroupLinks.push(link);
  7536. }
  7537. } else if (/store\.steampowered\.com\/app\//.test(link) && /wishlist/gim.test(taskDes)) {
  7538. if (action === 'undo') {
  7539. this.socialTasks.steam.wishlistLinks.push(link);
  7540. }
  7541. if (action === 'do') {
  7542. this.undoneTasks.steam.wishlistLinks.push(link);
  7543. }
  7544. } else if (/store\.steampowered\.com\/curator\//.test(link)) {
  7545. if (action === 'undo') {
  7546. this.socialTasks.steam.curatorLinks.push(link);
  7547. }
  7548. if (action === 'do') {
  7549. this.undoneTasks.steam.curatorLinks.push(link);
  7550. }
  7551. } else if (/^https?:\/\/discord\.com\/invite\//.test(link)) {
  7552. if (action === 'undo') {
  7553. this.socialTasks.discord.serverLinks.push(link);
  7554. }
  7555. if (action === 'do') {
  7556. this.undoneTasks.discord.serverLinks.push(link);
  7557. }
  7558. } else if (/^javascript:videoTask.+/.test(link)) {
  7559. if (action === 'do') {
  7560. const taskData = link.match(/javascript:videoTask\('.+?','(.+?)'/)?.[1];
  7561. if (taskData) {
  7562. this.undoneTasks.extra.videoTasks.push(taskData);
  7563. }
  7564. }
  7565. } 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 {
  7566. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  7567. }
  7568. }
  7569. logStatus.success();
  7570. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7571. this.socialTasks = this.uniqueTasks(this.socialTasks);
  7572. if (window.DEBUG) {
  7573. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7574. }
  7575. GM_setValue(`khTasks-${this.giveawayId}`, {
  7576. tasks: this.socialTasks,
  7577. time: new Date().getTime()
  7578. });
  7579. return true;
  7580. } catch (error) {
  7581. throwError(error, 'Keyhub.classifyTask');
  7582. return false;
  7583. }
  7584. }
  7585. async #doScriptTask(data) {
  7586. try {
  7587. const logStatus = scripts_echoLog({
  7588. text: i18n('doingKeyhubTask')
  7589. });
  7590. const {
  7591. result,
  7592. statusText,
  7593. status,
  7594. data: response
  7595. } = await tools_httpRequest({
  7596. url: `/away?data=${data}`,
  7597. method: 'GET',
  7598. headers: {
  7599. origin: 'https://key-hub.eu',
  7600. referer: 'https://key-hub.eu/'
  7601. }
  7602. });
  7603. if (result === 'Success') {
  7604. if (response?.status === 200) {
  7605. logStatus.success();
  7606. return true;
  7607. }
  7608. logStatus.error(`Error:${response?.statusText}(${response?.status})`);
  7609. return false;
  7610. }
  7611. logStatus.error(`${result}:${statusText}(${status})`);
  7612. return false;
  7613. } catch (error) {
  7614. throwError(error, 'Keyhub.doScriptTask');
  7615. return false;
  7616. }
  7617. }
  7618. async extraDoTask({
  7619. videoTasks
  7620. }) {
  7621. try {
  7622. const pro = [];
  7623. for (const data of videoTasks) {
  7624. pro.push(this.#doScriptTask(data));
  7625. }
  7626. return Promise.all(pro).then(() => true);
  7627. } catch (error) {
  7628. throwError(error, 'Keyhub.extraDoTask');
  7629. return false;
  7630. }
  7631. }
  7632. #getGiveawayId() {
  7633. try {
  7634. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  7635. if (giveawayId) {
  7636. this.giveawayId = giveawayId;
  7637. return true;
  7638. }
  7639. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7640. return false;
  7641. } catch (error) {
  7642. throwError(error, 'Keyhub.getGiveawayId');
  7643. return false;
  7644. }
  7645. }
  7646. async #checkLeftKey() {
  7647. try {
  7648. if (!globalOptions.other.checkLeftKey) {
  7649. return true;
  7650. }
  7651. const leftKey = $('#keysleft').text().trim();
  7652. if (leftKey === '0') {
  7653. await external_Swal_default().fire({
  7654. icon: 'warning',
  7655. title: i18n('notice'),
  7656. text: i18n('noKeysLeft'),
  7657. confirmButtonText: i18n('confirm'),
  7658. cancelButtonText: i18n('cancel'),
  7659. showCancelButton: true
  7660. }).then(({
  7661. value
  7662. }) => {
  7663. if (value) {
  7664. window.close();
  7665. }
  7666. });
  7667. }
  7668. return true;
  7669. } catch (error) {
  7670. throwError(error, 'Keyhub.checkLeftKey');
  7671. return false;
  7672. }
  7673. }
  7674. #checkLogin() {
  7675. try {
  7676. if (!globalOptions.other.checkLogin) {
  7677. return true;
  7678. }
  7679. if ($('a[href*="/connect/steam"]').length > 0) {
  7680. window.open('/connect/steam', '_self');
  7681. }
  7682. return true;
  7683. } catch (error) {
  7684. throwError(error, 'Keyhub.checkLogin');
  7685. return false;
  7686. }
  7687. }
  7688. }
  7689. const website_Keyhub = Keyhub;
  7690. const Givekey_defaultTasksTemplate = {
  7691. steam: {
  7692. groupLinks: [],
  7693. wishlistLinks: [],
  7694. curatorLinks: [],
  7695. curatorLikeLinks: []
  7696. },
  7697. twitter: {
  7698. userLinks: []
  7699. },
  7700. vk: {
  7701. nameLinks: []
  7702. },
  7703. discord: {
  7704. serverLinks: []
  7705. }
  7706. };
  7707. const Givekey_defaultTasks = JSON.stringify(Givekey_defaultTasksTemplate);
  7708. class Givekey extends website_Website {
  7709. name = 'Givekey';
  7710. tasks = [];
  7711. socialTasks = JSON.parse(Givekey_defaultTasks);
  7712. undoneTasks = JSON.parse(Givekey_defaultTasks);
  7713. userId;
  7714. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  7715. static test() {
  7716. return window.location.host === 'givekey.ru';
  7717. }
  7718. async after() {
  7719. try {
  7720. await new Promise(resolve => {
  7721. const checker = setInterval(() => {
  7722. if ($('#navbarDropdown').length > 0) {
  7723. clearInterval(checker);
  7724. resolve(true);
  7725. }
  7726. });
  7727. });
  7728. if (!await this.#checkLeftKey()) {
  7729. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7730. }
  7731. } catch (error) {
  7732. throwError(error, 'Givekey.after');
  7733. return false;
  7734. }
  7735. }
  7736. init() {
  7737. try {
  7738. const logStatus = scripts_echoLog({
  7739. text: i18n('initing')
  7740. });
  7741. if ($('a[href*="/auth/steam"]').length > 0) {
  7742. window.open('/auth/steam', '_self');
  7743. logStatus.warning(i18n('needLogin'));
  7744. return false;
  7745. }
  7746. if (!this.#getGiveawayId()) {
  7747. return false;
  7748. }
  7749. const userId = $('meta[name="user-id"]').attr('content');
  7750. if (!userId) {
  7751. logStatus.error(i18n('getFailed', i18n('userId')));
  7752. return false;
  7753. }
  7754. this.userId = userId;
  7755. this.initialized = true;
  7756. logStatus.success();
  7757. return true;
  7758. } catch (error) {
  7759. throwError(error, 'Givekey.init');
  7760. return false;
  7761. }
  7762. }
  7763. async classifyTask(action) {
  7764. try {
  7765. const logStatus = scripts_echoLog({
  7766. text: i18n('getTasksInfo')
  7767. });
  7768. if (action === 'undo') {
  7769. this.socialTasks = GM_getValue(`gkTasks-${this.giveawayId}`)?.tasks || JSON.parse(Givekey_defaultTasks);
  7770. }
  7771. const tasks = $('.card-body:has("button") .row');
  7772. for (const task of tasks) {
  7773. const taskEle = $(task);
  7774. const isSuccess = /Complete/i.test(taskEle.find('button').text().trim());
  7775. if (isSuccess && action !== 'undo') {
  7776. continue;
  7777. }
  7778. const checkButton = taskEle.find('#task_check');
  7779. const taskId = checkButton.attr('data-id');
  7780. if (taskId) {
  7781. this.tasks.push(taskId);
  7782. }
  7783. if (action === 'verify') {
  7784. continue;
  7785. }
  7786. let href = taskEle.find('a').attr('href') || null;
  7787. const text = taskEle.find('a').text().trim();
  7788. const icon = taskEle.find('i');
  7789. if (!href || !text) {
  7790. continue;
  7791. }
  7792. if (/^https?:\/\/givekey\.ru\/giveaway\/[\d]+\/execution_task/.test(href)) {
  7793. href = await getRedirectLink(href);
  7794. }
  7795. if (!href) {
  7796. continue;
  7797. }
  7798. if (/^https?:\/\/vk\.com\//.test(href)) {
  7799. this.socialTasks.vk.nameLinks.push(href);
  7800. if (action === 'do' && !isSuccess) {
  7801. this.undoneTasks.vk.nameLinks.push(href);
  7802. }
  7803. } else if (/^https?:\/\/steamcommunity\.com\/groups/.test(href)) {
  7804. this.socialTasks.steam.groupLinks.push(href);
  7805. if (action === 'do' && !isSuccess) {
  7806. this.undoneTasks.steam.groupLinks.push(href);
  7807. }
  7808. } else if (/^https?:\/\/store\.steampowered\.com\/app\//.test(href)) {
  7809. this.socialTasks.steam.wishlistLinks.push(href);
  7810. if (action === 'do' && !isSuccess) {
  7811. this.undoneTasks.steam.wishlistLinks.push(href);
  7812. }
  7813. } else if (/Subscribe/gi.test(text) && icon.hasClass('fa-steam-square')) {
  7814. if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(href)) {
  7815. this.socialTasks.steam.curatorLinks.push(href);
  7816. if (action === 'do' && !isSuccess) {
  7817. this.undoneTasks.steam.curatorLinks.push(href);
  7818. }
  7819. } else {
  7820. this.socialTasks.steam.curatorLikeLinks.push(href);
  7821. if (action === 'do' && !isSuccess) {
  7822. this.undoneTasks.steam.curatorLikeLinks.push(href);
  7823. }
  7824. }
  7825. } else if (/^https?:\/\/twitter\.com\//.test(href) && /Subscribe/gi.test(text)) {
  7826. this.socialTasks.twitter.userLinks.push(href);
  7827. if (action === 'do' && !isSuccess) {
  7828. this.undoneTasks.twitter.userLinks.push(href);
  7829. }
  7830. } else if (icon.hasClass('fa-discord') || /^https?:\/\/discord\.com\/invite\//.test(href)) {
  7831. this.socialTasks.discord.serverLinks.push(href);
  7832. if (action === 'do' && !isSuccess) {
  7833. this.undoneTasks.discord.serverLinks.push(href);
  7834. }
  7835. } else {
  7836. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${text}(${href})`);
  7837. }
  7838. }
  7839. logStatus.success();
  7840. this.tasks = unique(this.tasks);
  7841. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7842. this.socialTasks = this.uniqueTasks(this.socialTasks);
  7843. if (window.DEBUG) {
  7844. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7845. }
  7846. GM_setValue(`gkTasks-${this.giveawayId}`, {
  7847. tasks: this.socialTasks,
  7848. time: new Date().getTime()
  7849. });
  7850. return true;
  7851. } catch (error) {
  7852. throwError(error, 'Givekey.classifyTask');
  7853. return false;
  7854. }
  7855. }
  7856. async verifyTask() {
  7857. try {
  7858. if (!this.initialized && !this.init()) {
  7859. return false;
  7860. }
  7861. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  7862. return false;
  7863. }
  7864. scripts_echoLog({}).warning(i18n('giveKeyNoticeBefore'));
  7865. const taskLength = this.tasks.length;
  7866. for (let i = 0; i < taskLength; i++) {
  7867. await this.#verify(this.tasks[i]);
  7868. if (i < taskLength - 1) {
  7869. await delay(15e3);
  7870. }
  7871. }
  7872. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7873. scripts_echoLog({
  7874. html: `<li><font class="warning">${i18n('giveKeyNoticeAfter')}</font></li>`
  7875. });
  7876. return true;
  7877. } catch (error) {
  7878. throwError(error, 'Givekey.verifyTask');
  7879. return false;
  7880. }
  7881. }
  7882. async #verify(task) {
  7883. try {
  7884. const logStatus = scripts_echoLog({
  7885. html: `<li>${i18n('verifyingTask')}${task}...<font></font></li>`
  7886. });
  7887. return await new Promise(resolve => {
  7888. $.ajax({
  7889. url: 'https://givekey.ru/giveaway/task',
  7890. method: 'POST',
  7891. data: `id=${task}&user_id=${this.userId}`,
  7892. dataType: 'json',
  7893. headers: {
  7894. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  7895. },
  7896. success: data => {
  7897. if (data.btn) {
  7898. $(`button[data-id=${this.userId}]`).html(data.btn);
  7899. }
  7900. if (data.status === 'ok') {
  7901. $(`.task_check_${data.id}`).html(`<button class="btn btn-success mb-2 btn-block" disabled>${data.btn}</button>`);
  7902. logStatus.success();
  7903. resolve(true);
  7904. } else if (data.status === 'end') {
  7905. logStatus.success();
  7906. scripts_echoLog({}).success(data.key);
  7907. resolve(true);
  7908. } else {
  7909. logStatus.error(`Error:${data.msg}`);
  7910. resolve(false);
  7911. }
  7912. },
  7913. error: xhr => {
  7914. logStatus.error(`Error:${xhr.statusText}(${xhr.status})`);
  7915. resolve(false);
  7916. }
  7917. });
  7918. });
  7919. } catch (error) {
  7920. throwError(error, 'Givekey.verify');
  7921. return false;
  7922. }
  7923. }
  7924. #getGiveawayId() {
  7925. try {
  7926. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  7927. if (giveawayId) {
  7928. this.giveawayId = giveawayId;
  7929. return true;
  7930. }
  7931. scripts_echoLog({
  7932. text: i18n('getFailed', 'GiveawayId')
  7933. });
  7934. return false;
  7935. } catch (error) {
  7936. throwError(error, 'Givekey.getGiveawayId');
  7937. return false;
  7938. }
  7939. }
  7940. async #checkLeftKey() {
  7941. try {
  7942. if (!globalOptions.other.checkLeftKey) {
  7943. return true;
  7944. }
  7945. if (!$('#keys_count').text()) {
  7946. await external_Swal_default().fire({
  7947. icon: 'warning',
  7948. title: i18n('notice'),
  7949. text: i18n('noKeysLeft'),
  7950. confirmButtonText: i18n('confirm'),
  7951. cancelButtonText: i18n('cancel'),
  7952. showCancelButton: true
  7953. }).then(({
  7954. value
  7955. }) => {
  7956. if (value) {
  7957. window.close();
  7958. }
  7959. });
  7960. }
  7961. return true;
  7962. } catch (error) {
  7963. throwError(error, 'Givekey.checkLeftKey');
  7964. return false;
  7965. }
  7966. }
  7967. }
  7968. const website_Givekey = Givekey;
  7969. class GiveeClub extends GiveawaySu {
  7970. name = 'GiveeClub';
  7971. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  7972. static test() {
  7973. return /^https?:\/\/givee\.club\/.*?\/event\/[\d]+/.test(window.location.href);
  7974. }
  7975. async after() {
  7976. try {
  7977. if (!this.#checkLogin()) {
  7978. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7979. }
  7980. if (!await this.#checkLeftKey()) {
  7981. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7982. }
  7983. } catch (error) {
  7984. throwError(error, 'GiveeClub.after');
  7985. }
  7986. }
  7987. init() {
  7988. try {
  7989. const logStatus = scripts_echoLog({
  7990. text: i18n('initing')
  7991. });
  7992. if (!this.#checkLogin()) {
  7993. logStatus.warning(i18n('needLogin'));
  7994. return false;
  7995. }
  7996. if (!this.#getGiveawayId()) {
  7997. return false;
  7998. }
  7999. this.initialized = true;
  8000. logStatus.success();
  8001. return true;
  8002. } catch (error) {
  8003. throwError(error, 'GiveeClub.init');
  8004. return false;
  8005. }
  8006. }
  8007. async classifyTask(action) {
  8008. try {
  8009. const logStatus = scripts_echoLog({
  8010. text: i18n('getTasksInfo')
  8011. });
  8012. if (action === 'undo') {
  8013. this.socialTasks = GM_getValue(`gcTasks-${this.giveawayId}`)?.tasks || GiveawaySu_defaultTasks;
  8014. return true;
  8015. }
  8016. const pro = [];
  8017. const tasks = $('.event-actions tr');
  8018. for (const task of tasks) {
  8019. pro.push(new Promise(resolve => {
  8020. const taskDes = $(task).find('.event-action-label a');
  8021. const taskIcon = $(task).find('.event-action-icon i').attr('class') || '';
  8022. const taskName = taskDes.text().trim();
  8023. const taskType = $(task).find('button[data-type]')?.attr('data-type');
  8024. const taskFinished = $(task).find('.event-action-buttons .btn-success')?.length;
  8025. if (taskIcon.includes('ban') || /AdBlock/i.test(taskName) || taskIcon.includes('envelope') || taskFinished) {
  8026. return resolve(true);
  8027. }
  8028. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  8029. if (!taskLink) {
  8030. return resolve(false);
  8031. }
  8032. if (taskType === 'steam.group.join' && /^https?:\/\/steamcommunity\.com\/groups/.test(taskLink)) {
  8033. this.undoneTasks.steam.groupLinks.push(taskLink);
  8034. } else if (/like.*announcement/gi.test(taskName)) {
  8035. this.undoneTasks.steam.announcementLinks.push(taskLink);
  8036. } else if (taskType === 'steam.game.wishlist' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8037. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  8038. } else if (taskType === 'steam.game.wishlist' && taskDes.attr('data-steam-wishlist-appid')) {
  8039. this.undoneTasks.steam.wishlistLinks.push(`https://store.steampowered.com/app/${taskDes.attr('data-steam-wishlist-appid')}`);
  8040. } else if (taskType === 'steam.game.follow' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8041. this.undoneTasks.steam.followLinks.push(taskLink);
  8042. } else if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  8043. this.undoneTasks.steam.curatorLinks.push(taskLink);
  8044. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  8045. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  8046. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  8047. this.undoneTasks.steam.forumLinks.push(taskLink);
  8048. } else if (taskIcon.includes('discord')) {
  8049. this.undoneTasks.discord.serverLinks.push(taskLink);
  8050. } else if (taskIcon.includes('instagram')) {
  8051. this.undoneTasks.instagram.userLinks.push(taskLink);
  8052. } else if (taskIcon.includes('twitch')) {
  8053. this.undoneTasks.twitch.channelLinks.push(taskLink);
  8054. } else if (taskIcon.includes('reddit')) {
  8055. this.undoneTasks.reddit.redditLinks.push(taskLink);
  8056. } else if (/watch.*art/gim.test(taskName)) {
  8057. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8058. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  8059. this.undoneTasks.youtube.channelLinks.push(taskLink);
  8060. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  8061. this.undoneTasks.youtube.likeLinks.push(taskLink);
  8062. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  8063. this.undoneTasks.vk.nameLinks.push(taskLink);
  8064. } else if (taskIcon.includes('twitter')) {
  8065. if (/https?:\/\/twitter\.com\/[^/]+\/?$/gim.test(taskLink)) {
  8066. this.undoneTasks.twitter.userLinks.push(taskLink);
  8067. } else if (/https?:\/\/twitter\.com\/[^/]+?\/status\/[\d]+/gim.test(taskLink)) {
  8068. this.undoneTasks.twitter.retweetLinks.push(taskLink);
  8069. }
  8070. } else {
  8071. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  8072. if (/follow.*button/gim.test(taskName)) {
  8073. this.undoneTasks.steam.followLinks.push(taskLink);
  8074. }
  8075. }
  8076. }
  8077. resolve(true);
  8078. }).catch(error => {
  8079. throwError(error, 'GiveeClub.classifyTask->getRedirectLink');
  8080. return false;
  8081. });
  8082. }));
  8083. }
  8084. await Promise.all(pro);
  8085. logStatus.success();
  8086. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8087. this.socialTasks = this.undoneTasks;
  8088. if (window.DEBUG) {
  8089. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8090. }
  8091. GM_setValue(`gcTasks-${this.giveawayId}`, {
  8092. tasks: this.socialTasks,
  8093. time: new Date().getTime()
  8094. });
  8095. return true;
  8096. } catch (error) {
  8097. throwError(error, 'GiveeClub.classifyTask');
  8098. return false;
  8099. }
  8100. }
  8101. async verifyTask() {
  8102. try {
  8103. const logStatus = scripts_echoLog({
  8104. text: i18n('giveeClubVerifyNotice')
  8105. });
  8106. const taskButtons = $('.event-actions tr button').has('i.glyphicon-refresh').not('[data-type="user.adblock"]');
  8107. for (const button of taskButtons) {
  8108. button.click();
  8109. if ($(button).attr('data-type') !== 'steam.game.wishlist') {
  8110. await delay(1e3);
  8111. }
  8112. }
  8113. logStatus.warning(i18n('giveeClubVerifyFinished'));
  8114. return true;
  8115. } catch (error) {
  8116. throwError(error, 'Givekey.verifyTask');
  8117. return false;
  8118. }
  8119. }
  8120. #checkLogin() {
  8121. try {
  8122. if (!globalOptions.other.checkLogin) {
  8123. return true;
  8124. }
  8125. if ($('a[href*="/account/auth"]').length > 0) {
  8126. window.open($('a[href*="/account/auth"]').attr('href'), '_self');
  8127. }
  8128. return true;
  8129. } catch (error) {
  8130. throwError(error, 'GiveeClub.checkLogin');
  8131. return false;
  8132. }
  8133. }
  8134. #getGiveawayId() {
  8135. const giveawayId = window.location.href.match(/\/event\/([\d]+)/)?.[1];
  8136. if (giveawayId) {
  8137. this.giveawayId = giveawayId;
  8138. return true;
  8139. }
  8140. scripts_echoLog({
  8141. text: i18n('getFailed', 'GiveawayId')
  8142. });
  8143. return false;
  8144. }
  8145. async #checkLeftKey() {
  8146. try {
  8147. if (!globalOptions.other.checkLeftKey) {
  8148. return true;
  8149. }
  8150. if ($('.event-ended').length > 0 && $('.event-winner').length === 0) {
  8151. await external_Swal_default().fire({
  8152. icon: 'warning',
  8153. title: i18n('notice'),
  8154. text: i18n('giveawayEnded'),
  8155. confirmButtonText: i18n('confirm'),
  8156. cancelButtonText: i18n('cancel'),
  8157. showCancelButton: true
  8158. }).then(({
  8159. value
  8160. }) => {
  8161. if (value) {
  8162. window.close();
  8163. }
  8164. });
  8165. }
  8166. return true;
  8167. } catch (error) {
  8168. throwError(error, 'Giveawaysu.checkLeftKey');
  8169. return false;
  8170. }
  8171. }
  8172. }
  8173. const website_GiveeClub = GiveeClub;
  8174. const defaultOptions = {
  8175. maxPoint: '99999999'
  8176. };
  8177. class OpiumPulses {
  8178. name = 'OpiumPulses';
  8179. options = {
  8180. ...defaultOptions,
  8181. ...GM_getValue('OpiumPulsesOptions')
  8182. };
  8183. maxPoints = 99999999;
  8184. myPoints = 0;
  8185. buttons = [ 'doFreeTask', 'doPointTask' ];
  8186. static test() {
  8187. return window.location.host === 'www.opiumpulses.com';
  8188. }
  8189. async after() {
  8190. try {
  8191. if (!this.#checkLogin()) {
  8192. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8193. }
  8194. this.maxPoints = parseInt(this.options.maxPoint, 10);
  8195. } catch (error) {
  8196. throwError(error, 'OpiumPulses.after');
  8197. }
  8198. }
  8199. async doFreeTask() {
  8200. try {
  8201. this.#toggleTask('FREE');
  8202. } catch (error) {
  8203. throwError(error, 'OpiumPulses.doFreeTask');
  8204. }
  8205. }
  8206. async doPointTask() {
  8207. try {
  8208. this.myPoints = parseInt($('.page-header__nav-func-user-nav-items.points-items').text().match(/[\d]+/gim)?.[0] || '0', 10);
  8209. this.#toggleTask('points');
  8210. } catch (error) {
  8211. throwError(error, 'OpiumPulses.doPointTask');
  8212. }
  8213. }
  8214. async #toggleTask(type) {
  8215. try {
  8216. const items = $(`.giveaways-page-item:contains('${type}'):not(:contains('ENTERED'))`);
  8217. for (const item of items) {
  8218. const needPoints = parseInt($(item).find('.giveaways-page-item-header-points').text().match(/[\d]+/gim)?.[0] || '999999', 10);
  8219. const name = $(item).find('.giveaways-page-item-footer-name').text().trim();
  8220. if (type === 'points' && needPoints > this.myPoints) {
  8221. scripts_echoLog({}).warning(`${i18n('noPoints')}: ${name}`);
  8222. } else if (type === 'points' && !needPoints) {
  8223. scripts_echoLog({}).warning(`${i18n('getNeedPointsFailed')}: ${name}`);
  8224. } else if (!(type === 'points' && needPoints > this.maxPoints)) {
  8225. const logStatus = scripts_echoLog({
  8226. text: `${i18n('joiningLottery')}<a href="${$(item).find('a.giveaways-page-item-img-btn-more').attr('href')}" target="_blank">${name}</a>...`
  8227. });
  8228. const aElement = $(item).find('a.giveaways-page-item-img-btn-enter:contains(\'enter\')');
  8229. if (aElement?.attr('onclick')?.includes('checkUser')) {
  8230. const giveawayId = aElement.attr('onclick')?.match(/[\d]+/)?.[0];
  8231. if (giveawayId) {
  8232. checkUser(giveawayId);
  8233. }
  8234. }
  8235. if (!aElement.attr('href')) {
  8236. logStatus.error('Error: No "href".');
  8237. continue;
  8238. }
  8239. const {
  8240. result,
  8241. statusText,
  8242. status,
  8243. data
  8244. } = await tools_httpRequest({
  8245. url: aElement.attr('href'),
  8246. method: 'GET'
  8247. });
  8248. if (result === 'Success') {
  8249. if (data?.responseText && /You've entered this giveaway/gim.test(data.responseText)) {
  8250. logStatus.success();
  8251. const points = data.responseText.match(/Points:[\s]*?([\d]+)/)?.[1];
  8252. if (type === 'points' && points) {
  8253. this.myPoints = parseInt(points, 10);
  8254. }
  8255. } else {
  8256. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  8257. }
  8258. } else {
  8259. logStatus.error(`${result}:${statusText}(${status})`);
  8260. }
  8261. }
  8262. }
  8263. scripts_echoLog({
  8264. text: '-----END-----'
  8265. });
  8266. } catch (error) {
  8267. throwError(error, 'OpiumPulses.toggleTask');
  8268. }
  8269. }
  8270. init() {
  8271. return true;
  8272. }
  8273. classifyTask() {
  8274. return true;
  8275. }
  8276. #checkLogin() {
  8277. try {
  8278. if (!globalOptions.other.checkLogin) {
  8279. return true;
  8280. }
  8281. if ($('a[href*="/site/login"]').length > 1) {
  8282. window.open('/site/login', '_self');
  8283. }
  8284. return true;
  8285. } catch (error) {
  8286. throwError(error, 'OpiumPulses.checkLogin');
  8287. return false;
  8288. }
  8289. }
  8290. }
  8291. const website_OpiumPulses = OpiumPulses;
  8292. const external_dayjs_namespaceObject = dayjs;
  8293. var external_dayjs_default = __webpack_require__.n(external_dayjs_namespaceObject);
  8294. const leftKeyChecker = {
  8295. async classify(link) {
  8296. try {
  8297. if (/^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(link)) {
  8298. return await this.giveawaySu(link);
  8299. }
  8300. if (/^https?:\/\/givee\.club\/[\w]+?\/event\/[\d]+/.test(link)) {
  8301. return await this.giveeClub(link);
  8302. }
  8303. if (/^https?:\/\/gleam\.io\/.+?\/.+/.test(link)) {
  8304. return await this.gleam(link);
  8305. }
  8306. if (/^https?:\/\/www\.indiedb\.com\/giveaways\/.+/.test(link)) {
  8307. return await this.indieDb(link);
  8308. }
  8309. if (/^https?:\/\/key-hub\.eu\/giveaway\/[\d]+/.test(link)) {
  8310. return await this.keyhub(link);
  8311. }
  8312. if (/^https?:\/\/opquests\.com\/quests\/[\d]+/.test(link)) {
  8313. return await this.opquests(link);
  8314. }
  8315. if (/^https?:\/\/itch\.io\/s\/[\d]+?\/.*/.test(link)) {
  8316. return await this.itch(link);
  8317. }
  8318. return false;
  8319. } catch (error) {
  8320. throwError(error, 'leftKeyChecker.classify');
  8321. return false;
  8322. }
  8323. },
  8324. async giveawaySu(link) {
  8325. try {
  8326. const {
  8327. result,
  8328. data
  8329. } = await tools_httpRequest({
  8330. url: link,
  8331. method: 'GET'
  8332. });
  8333. if (result === 'Success' && data?.status === 200) {
  8334. if (data.responseText.includes('class="steam-login"')) {
  8335. return false;
  8336. }
  8337. if (data.responseText.includes('class="giveaway-ended"')) {
  8338. return 'Ended';
  8339. }
  8340. return 'Active';
  8341. }
  8342. return false;
  8343. } catch (error) {
  8344. throwError(error, 'leftKeyChecker.giveawaySu');
  8345. return false;
  8346. }
  8347. },
  8348. async giveeClub(link) {
  8349. try {
  8350. const {
  8351. result,
  8352. data
  8353. } = await tools_httpRequest({
  8354. url: link,
  8355. method: 'GET'
  8356. });
  8357. if (result === 'Success' && data?.status === 200) {
  8358. if (data.responseText.includes('class="event-winner"')) {
  8359. return 'Won';
  8360. }
  8361. if (data.responseText.includes('class="event-ended"')) {
  8362. return 'Ended';
  8363. }
  8364. return 'Active';
  8365. }
  8366. return false;
  8367. } catch (error) {
  8368. throwError(error, 'leftKeyChecker.giveeClub');
  8369. return false;
  8370. }
  8371. },
  8372. async gleam(link) {
  8373. try {
  8374. const {
  8375. result,
  8376. data
  8377. } = await tools_httpRequest({
  8378. url: link,
  8379. method: 'GET'
  8380. });
  8381. if (result === 'Success' && data?.status === 200) {
  8382. if (/incentives&quot;:{&quot;[\d]+?&quot;:\[&quot;.+?&quot;\]/.test(data.responseText)) {
  8383. return 'Won';
  8384. }
  8385. const campaignDiv = data.responseText.match(/<div class='popup-blocks-container'[\w\W]+?'>/)?.[0];
  8386. if (!campaignDiv) {
  8387. return false;
  8388. }
  8389. const campaignString = $(campaignDiv).attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  8390. if (!campaignString) {
  8391. return false;
  8392. }
  8393. const {
  8394. campaign
  8395. } = JSON.parse(campaignString);
  8396. if (campaign.banned) {
  8397. return 'Banned';
  8398. }
  8399. if (campaign.finished) {
  8400. return 'Ended';
  8401. }
  8402. if (campaign.paused) {
  8403. return 'Paused';
  8404. }
  8405. if (new Date().getTime() < campaign.starts_at * 1e3) {
  8406. return 'NotStart';
  8407. }
  8408. return 'Active';
  8409. }
  8410. return false;
  8411. } catch (error) {
  8412. throwError(error, 'leftKeyChecker.gleam');
  8413. return false;
  8414. }
  8415. },
  8416. async indieDb(link) {
  8417. try {
  8418. const {
  8419. result,
  8420. data
  8421. } = await tools_httpRequest({
  8422. url: link,
  8423. method: 'GET'
  8424. });
  8425. if (result === 'Success' && data?.status === 200) {
  8426. if (data.responseText.includes('Congrats you WON')) {
  8427. return 'Won';
  8428. }
  8429. if (data.responseText.includes('Giveaway is closed') || data.responseText.includes('next time')) {
  8430. return 'Ended';
  8431. }
  8432. return 'Active';
  8433. }
  8434. return false;
  8435. } catch (error) {
  8436. throwError(error, 'leftKeyChecker.indieDb');
  8437. return false;
  8438. }
  8439. },
  8440. async keyhub(link) {
  8441. try {
  8442. const {
  8443. result,
  8444. data
  8445. } = await tools_httpRequest({
  8446. url: link,
  8447. method: 'GET'
  8448. });
  8449. if (result === 'Success' && data?.status === 200) {
  8450. const keysleft = data.responseText.match(/<span id="keysleft">([\d]+?)<\/span>/)?.[1];
  8451. if (!keysleft) {
  8452. return false;
  8453. }
  8454. if (keysleft === '0') {
  8455. return 'Ended';
  8456. }
  8457. return `Active(${keysleft})`;
  8458. }
  8459. return false;
  8460. } catch (error) {
  8461. throwError(error, 'leftKeyChecker.keyhub');
  8462. return false;
  8463. }
  8464. },
  8465. async opquests(link) {
  8466. try {
  8467. const {
  8468. result,
  8469. data
  8470. } = await tools_httpRequest({
  8471. url: link,
  8472. method: 'GET'
  8473. });
  8474. if (result === 'Success' && data?.status === 200) {
  8475. const keysleft = data.responseText.match(/<div class="">[\s]*?([\d]+?)[\s]*?of/)?.[1];
  8476. if (!keysleft) {
  8477. return false;
  8478. }
  8479. if (keysleft === '0') {
  8480. return 'Ended';
  8481. }
  8482. return `Active(${keysleft})`;
  8483. } else if (data?.status === 404) {
  8484. return 'Ended';
  8485. }
  8486. return false;
  8487. } catch (error) {
  8488. throwError(error, 'leftKeyChecker.opquests');
  8489. return false;
  8490. }
  8491. },
  8492. async itch(link) {
  8493. try {
  8494. const {
  8495. result,
  8496. data
  8497. } = await tools_httpRequest({
  8498. url: link,
  8499. method: 'GET'
  8500. });
  8501. if (result === 'Success' && data?.status === 200) {
  8502. const endDate = data.responseText.match(/{"start_date":"[0-9A-Z-:]+?".*?"end_date":"([0-9A-Z-:]+?)".*?}/)?.[1];
  8503. if (!endDate) {
  8504. return false;
  8505. }
  8506. if (new Date().getTime() > new Date(endDate).getTime()) {
  8507. return 'Ended';
  8508. }
  8509. return `Active(${external_dayjs_default()(endDate).format('YYYY-MM-DD HH:mm:ss')})`;
  8510. }
  8511. return false;
  8512. } catch (error) {
  8513. throwError(error, 'leftKeyChecker.opquests');
  8514. return false;
  8515. }
  8516. }
  8517. };
  8518. const website_leftKeyChecker = leftKeyChecker;
  8519. const Keylol_defaultTasksTemplate = {
  8520. steam: {
  8521. groupLinks: [],
  8522. wishlistLinks: [],
  8523. curatorLinks: [],
  8524. curatorLikeLinks: [],
  8525. followLinks: [],
  8526. forumLinks: [],
  8527. announcementLinks: [],
  8528. workshopVoteLinks: [],
  8529. licenseLinks: []
  8530. },
  8531. discord: {
  8532. serverLinks: []
  8533. },
  8534. instagram: {
  8535. userLinks: []
  8536. },
  8537. vk: {
  8538. nameLinks: []
  8539. },
  8540. twitch: {
  8541. channelLinks: []
  8542. },
  8543. reddit: {
  8544. redditLinks: []
  8545. },
  8546. twitter: {
  8547. userLinks: [],
  8548. retweetLinks: []
  8549. },
  8550. youtube: {
  8551. channelLinks: [],
  8552. likeLinks: []
  8553. }
  8554. };
  8555. const Keylol_defaultTasks = JSON.stringify(Keylol_defaultTasksTemplate);
  8556. class Keylol extends website_Website {
  8557. name = 'Keylol';
  8558. socialTasks = JSON.parse(Keylol_defaultTasks);
  8559. undoneTasks = JSON.parse(Keylol_defaultTasks);
  8560. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect' ];
  8561. static test() {
  8562. 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'));
  8563. }
  8564. init() {
  8565. return true;
  8566. }
  8567. after() {
  8568. try {
  8569. const selector = this.name === 'Keylol' ? '#postlist>div[id^="post_"]:first' : 'div.container';
  8570. const mainPost = $(selector);
  8571. const discordLinks = mainPost.find('a[href*="discord.com"]:visible');
  8572. const redditLinks = mainPost.find('a[href*="reddit.com"]:visible');
  8573. const insLinks = mainPost.find('a[href*="instagram.com"]:visible');
  8574. const twitterLinks = mainPost.find('a[href*="twitter.com"]:visible');
  8575. const twitchLinks = mainPost.find('a[href*="twitch.tv"]:visible');
  8576. const vkLinks = mainPost.find('a[href*="vk.com"]:visible');
  8577. const steamStoreLinks = mainPost.find('a[href*="store.steampowered.com"]:visible');
  8578. const steamCommunityLinks = mainPost.find('a[href*="steamcommunity.com"]:visible');
  8579. const ytbLinks = mainPost.find('a[href*="youtube.com"]:visible');
  8580. if (discordLinks.length > 0) {
  8581. for (const discordLink of discordLinks) {
  8582. const link = $(discordLink).attr('href');
  8583. if (!(link && /^https?:\/\/discord\.com\/invite\/.+/.test(link))) {
  8584. continue;
  8585. }
  8586. this.#addBtn(discordLink, 'discord', 'serverLinks', link);
  8587. }
  8588. }
  8589. if (redditLinks.length > 0) {
  8590. for (const redditLink of redditLinks) {
  8591. const link = $(redditLink).attr('href');
  8592. if (!(link && /^https?:\/\/www\.reddit\.com\/(r|user)\/.+/.test(link))) {
  8593. continue;
  8594. }
  8595. this.#addBtn(redditLink, 'reddit', 'redditLinks', link);
  8596. }
  8597. }
  8598. if (insLinks.length > 0) {
  8599. for (const insLink of insLinks) {
  8600. const link = $(insLink).attr('href');
  8601. if (!(link && /^https:\/\/www\.instagram\.com\/.+/.test(link))) {
  8602. continue;
  8603. }
  8604. this.#addBtn(insLink, 'instagram', 'userLinks', link);
  8605. }
  8606. }
  8607. if (twitterLinks.length > 0) {
  8608. for (const twitterLink of twitterLinks) {
  8609. const link = $(twitterLink).attr('href');
  8610. if (!(link && /^https:\/\/twitter\.com\/.+/.test(link))) {
  8611. continue;
  8612. }
  8613. if (/https:\/\/twitter\.com\/.*?\/status\/[\d]+/.test(link)) {
  8614. this.#addBtn(twitterLink, 'twitter', 'retweetLinks', link);
  8615. } else {
  8616. this.#addBtn(twitterLink, 'twitter', 'userLinks', link);
  8617. }
  8618. }
  8619. }
  8620. if (twitchLinks.length > 0) {
  8621. for (const twitchLink of twitchLinks) {
  8622. const link = $(twitchLink).attr('href');
  8623. if (!(link && /^https:\/\/(www\.)?twitch\.tv\/.+/.test(link))) {
  8624. continue;
  8625. }
  8626. this.#addBtn(twitchLink, 'twitch', 'channelLinks', link);
  8627. }
  8628. }
  8629. if (vkLinks.length > 0) {
  8630. for (const vkLink of vkLinks) {
  8631. const link = $(vkLink).attr('href');
  8632. if (!(link && /^https:\/\/vk\.com\/.+/.test(link))) {
  8633. continue;
  8634. }
  8635. this.#addBtn(vkLink, 'vk', 'nameLinks', link);
  8636. }
  8637. }
  8638. if (steamStoreLinks.length > 0) {
  8639. for (const steamStoreLink of steamStoreLinks) {
  8640. const link = $(steamStoreLink).attr('href');
  8641. if (!link) {
  8642. continue;
  8643. }
  8644. if (/curator\/[\d]+/.test(link)) {
  8645. this.#addBtn(steamStoreLink, 'steam', 'curatorLinks', link);
  8646. } else if (/(publisher|developer|franchise)\/.+/.test(link)) {
  8647. this.#addBtn(steamStoreLink, 'steam', 'curatorLikeLinks', link);
  8648. } else if (/news(hub)?\/app\/[\d]+\/view\/[\d]+/.test(link)) {
  8649. this.#addBtn(steamStoreLink, 'steam', 'announcementLinks', link);
  8650. } else if (/app\/[\d]+/.test(link)) {
  8651. this.#addBtn(steamStoreLink, 'steam', 'followLinks', link);
  8652. this.#addBtn(steamStoreLink, 'steam', 'wishlistLinks', link);
  8653. }
  8654. }
  8655. }
  8656. if (steamCommunityLinks.length > 0) {
  8657. for (const steamCommunityLink of steamCommunityLinks) {
  8658. const link = $(steamCommunityLink).attr('href');
  8659. if (!link) {
  8660. continue;
  8661. }
  8662. if (/groups\/.+/.test(link)) {
  8663. this.#addBtn(steamCommunityLink, 'steam', 'groupLinks', link);
  8664. } else if (/announcements\/detail\/[\d]+/.test(link)) {
  8665. this.#addBtn(steamCommunityLink, 'steam', 'announcementLinks', link);
  8666. }
  8667. }
  8668. }
  8669. if (ytbLinks.length > 0) {
  8670. for (const ytbLink of ytbLinks) {
  8671. const link = $(ytbLink).attr('href');
  8672. if (!link) {
  8673. continue;
  8674. }
  8675. this.#addBtn(ytbLink, 'youtube', 'channelLinks', link);
  8676. this.#addBtn(ytbLink, 'youtube', 'likeLinks', link);
  8677. }
  8678. }
  8679. 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');
  8680. if (giveawayLinks.length > 0) {
  8681. for (const giveawayLink of giveawayLinks) {
  8682. const link = $(giveawayLink).attr('href');
  8683. if (!link) {
  8684. continue;
  8685. }
  8686. website_leftKeyChecker.classify(link).then(status => {
  8687. if (!status) {
  8688. return;
  8689. }
  8690. if (/^Active/.test(status)) {
  8691. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status active" title="${i18n('Active')}">${status}</font>`);
  8692. return;
  8693. }
  8694. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status not-active" title="${i18n(status)}">${status}</font>`);
  8695. }).catch(error => {
  8696. throwError(error, 'keylol.after -> leftKeyChecker');
  8697. });
  8698. }
  8699. }
  8700. if (this.name === 'Keylol') {
  8701. const asfLinks = mainPost.find('a[href^="#asf"]:visible');
  8702. if (asfLinks.length > 0) {
  8703. for (const asfLink of asfLinks) {
  8704. const link = $(asfLink).attr('href');
  8705. if (!link) {
  8706. continue;
  8707. }
  8708. this.#addBtn($(`a[href="${link}"]`).after('<span style="color: #ccc; margin: 0 -5px 0 5px"> | </span>').next()[0], 'steam', 'licenseLinks', `appid-${link.replace('#asf', '')}`);
  8709. }
  8710. }
  8711. const subLinks = mainPost.find('a[href*="steamdb.info/sub/"]:visible');
  8712. if (subLinks.length > 0) {
  8713. for (const subLink of subLinks) {
  8714. const link = $(subLink).attr('href');
  8715. if (!link) {
  8716. continue;
  8717. }
  8718. const subid = link.match(/^https:\/\/steamdb\.info\/sub\/([\d]+)/)?.[1];
  8719. if (!subid) {
  8720. continue;
  8721. }
  8722. this.#addBtn(subLink, 'steam', 'licenseLinks', `subid-${subid}`);
  8723. }
  8724. }
  8725. const asfLinks2 = mainPost.find('.blockcode:contains("addlicense"):visible');
  8726. if (asfLinks2.length > 0) {
  8727. for (const asfLink of asfLinks2) {
  8728. const subid = asfLink.innerText.match(/[\d]+/g);
  8729. if (!subid || subid.length === 0) {
  8730. continue;
  8731. }
  8732. this.#addBtn($(asfLink).children('em')[0], 'steam', 'licenseLinks', `subid-${subid.join(',')}`);
  8733. }
  8734. }
  8735. }
  8736. } catch (error) {
  8737. throwError(error, 'keylol.after');
  8738. }
  8739. }
  8740. classifyTask(action) {
  8741. try {
  8742. this.socialTasks = JSON.parse(Keylol_defaultTasks);
  8743. this.undoneTasks = JSON.parse(Keylol_defaultTasks);
  8744. const selectedBtns = $('.auto-task-keylol[selected="selected"]:visible');
  8745. for (const btn of selectedBtns) {
  8746. const button = $(btn);
  8747. const social = button.attr('data-social');
  8748. const type = button.attr('data-type');
  8749. const link = button.attr('data-link');
  8750. if (!(social && type && link)) {
  8751. continue;
  8752. }
  8753. if (action === 'do') {
  8754. this.undoneTasks[social][type].push(link);
  8755. }
  8756. if (action === 'undo') {
  8757. this.socialTasks[social][type].push(link);
  8758. }
  8759. }
  8760. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8761. this.socialTasks = this.uniqueTasks(this.socialTasks);
  8762. if (window.DEBUG) {
  8763. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8764. }
  8765. return true;
  8766. } catch (error) {
  8767. throwError(error, 'Keylol.classifyTask');
  8768. return false;
  8769. }
  8770. }
  8771. selectAll() {
  8772. try {
  8773. $('.auto-task-keylol:visible').attr('selected', 'selected');
  8774. } catch (error) {
  8775. throwError(error, 'Keylol.selectAll');
  8776. }
  8777. }
  8778. selectNone() {
  8779. try {
  8780. $('.auto-task-keylol:visible').removeAttr('selected');
  8781. } catch (error) {
  8782. throwError(error, 'Keylol.selectNone');
  8783. }
  8784. }
  8785. invertSelect() {
  8786. try {
  8787. $('.auto-task-keylol:visible').each((index, element) => {
  8788. element.getAttribute('selected') ? element.removeAttribute('selected') : element.setAttribute('selected', 'selected');
  8789. });
  8790. } catch (error) {
  8791. throwError(error, 'Keylol.invertSelect');
  8792. }
  8793. }
  8794. #addBtn(before, social, linkType, link) {
  8795. try {
  8796. $(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>`);
  8797. } catch (error) {
  8798. throwError(error, 'keylol.addBtn');
  8799. }
  8800. }
  8801. }
  8802. const website_Keylol = Keylol;
  8803. const Opquests_defaultTasks = {
  8804. steam: {
  8805. groupLinks: [],
  8806. wishlistLinks: [],
  8807. followLinks: [],
  8808. curatorLikeLinks: []
  8809. }
  8810. };
  8811. class Opquests extends website_Website {
  8812. name = 'Opquests';
  8813. undoneTasks = {
  8814. ...Opquests_defaultTasks
  8815. };
  8816. buttons = [ 'doTask', 'verifyTask', 'getKey' ];
  8817. static test() {
  8818. return window.location.host === 'opquests.com';
  8819. }
  8820. async after() {
  8821. try {
  8822. if (!this.#checkLogin()) {
  8823. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8824. }
  8825. } catch (error) {
  8826. throwError(error, 'Opquests.after');
  8827. }
  8828. }
  8829. init() {
  8830. try {
  8831. const logStatus = scripts_echoLog({
  8832. text: i18n('initing')
  8833. });
  8834. if ($('a[href*="/auth/redirect"]').length > 0) {
  8835. window.open('/auth/redirect', '_self');
  8836. logStatus.warning(i18n('needLogin'));
  8837. return false;
  8838. }
  8839. if (!this.#getGiveawayId()) {
  8840. return false;
  8841. }
  8842. this.initialized = true;
  8843. logStatus.success();
  8844. return true;
  8845. } catch (error) {
  8846. throwError(error, 'Opquests.init');
  8847. return false;
  8848. }
  8849. }
  8850. async classifyTask(action) {
  8851. try {
  8852. if (action === 'undo') {
  8853. scripts_echoLog({
  8854. text: i18n('cannotUndo')
  8855. });
  8856. return false;
  8857. }
  8858. const logStatus = scripts_echoLog({
  8859. text: i18n('getTasksInfo')
  8860. });
  8861. const tasks = $('.w-full:contains("Validate") .items-center');
  8862. for (const task of tasks) {
  8863. const link = $(task).find('a:contains("Open")').attr('href');
  8864. const taskDes = $(task).find('div').eq(1).text().trim();
  8865. if (!link) {
  8866. continue;
  8867. }
  8868. if (/steamcommunity\.com\/groups\//.test(link)) {
  8869. this.undoneTasks.steam.groupLinks.push(link);
  8870. } else if (/store\.steampowered\.com\/app\//.test(link)) {
  8871. if (/wishlist/gim.test(taskDes)) {
  8872. this.undoneTasks.steam.wishlistLinks.push(link);
  8873. } else if (/follow/gim.test(taskDes)) {
  8874. this.undoneTasks.steam.followLinks.push(link);
  8875. }
  8876. } else if (/store\.steampowered\.com\/(publisher|developer|curator)\//.test(link) && /follow/gim.test(taskDes)) {
  8877. this.undoneTasks.steam.curatorLikeLinks.push(link);
  8878. } else {
  8879. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  8880. }
  8881. }
  8882. logStatus.success();
  8883. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8884. if (window.DEBUG) {
  8885. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8886. }
  8887. return true;
  8888. } catch (error) {
  8889. throwError(error, 'Opquests.classifyTask');
  8890. return false;
  8891. }
  8892. }
  8893. async verifyTask() {
  8894. try {
  8895. if (!this.initialized) {
  8896. this.init();
  8897. }
  8898. const tasks = $.makeArray($('div.w-full').find('.items-center').has('button.submit-loader')).map(ele => ({
  8899. token: $(ele).find('input[name="_token"]').val(),
  8900. taskId: $(ele).find('input[name="task_id"]').val(),
  8901. title: $(ele).find('span.text-sm').text().trim()
  8902. }));
  8903. await this.#confirm();
  8904. const pro = [];
  8905. for (const task of tasks) {
  8906. pro.push(this.#verify(task));
  8907. await delay(1e3);
  8908. }
  8909. await Promise.all(pro);
  8910. scripts_echoLog({}).success(i18n('allTasksComplete'));
  8911. if (await this.getKey()) {
  8912. return true;
  8913. }
  8914. window.location.reload();
  8915. return false;
  8916. } catch (error) {
  8917. throwError(error, 'Opquests.verifyTask');
  8918. return false;
  8919. }
  8920. }
  8921. async #confirm() {
  8922. try {
  8923. const logStatus = scripts_echoLog({
  8924. html: `<li>${i18n('confirmingTask')}...<font></font></li>`
  8925. });
  8926. const {
  8927. result,
  8928. statusText,
  8929. status,
  8930. data
  8931. } = await tools_httpRequest({
  8932. url: `https://opquests.com/quests/${this.giveawayId}?confirm=1`,
  8933. method: 'GET',
  8934. nochche: true,
  8935. headers: {
  8936. origin: 'https://opquests.com',
  8937. referer: `https://opquests.com/warning?id=${this.giveawayId}`
  8938. }
  8939. });
  8940. if (result === 'Success') {
  8941. if (data?.status === 200) {
  8942. logStatus.success();
  8943. return true;
  8944. }
  8945. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  8946. return false;
  8947. }
  8948. logStatus.error(`${result}:${statusText}(${status})`);
  8949. return false;
  8950. } catch (error) {
  8951. throwError(error, 'Opquests.confirm');
  8952. return false;
  8953. }
  8954. }
  8955. async #verify(task) {
  8956. try {
  8957. const logStatus = scripts_echoLog({
  8958. html: `<li>${i18n('verifyingTask')}${task.title.trim()}...<font></font></li>`
  8959. });
  8960. const {
  8961. result,
  8962. statusText,
  8963. status,
  8964. data
  8965. } = await tools_httpRequest({
  8966. url: 'https://opquests.com/entries',
  8967. method: 'POST',
  8968. dataType: 'json',
  8969. nochche: true,
  8970. headers: {
  8971. origin: 'https://opquests.com',
  8972. pragma: 'no-cache',
  8973. referer: window.location.href,
  8974. 'content-type': 'application/x-www-form-urlencoded'
  8975. },
  8976. data: `_token=${task.token}&task_id=${task.taskId}`
  8977. });
  8978. if (result === 'Success') {
  8979. if (data?.responseText?.includes('Successfully completed task') || data?.responseText?.includes('unlocked the key')) {
  8980. logStatus.success();
  8981. return true;
  8982. }
  8983. const key = $(data?.responseText || '').find('button[data-clipboard-text]:contains("Copy")').attr('data-clipboard-text')?.trim();
  8984. if (key) {
  8985. logStatus.success();
  8986. scripts_echoLog({}).success(key);
  8987. return true;
  8988. }
  8989. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  8990. return false;
  8991. }
  8992. logStatus.error(`${result}:${statusText}(${status})`);
  8993. return false;
  8994. } catch (error) {
  8995. throwError(error, 'Opquests.verify');
  8996. return false;
  8997. }
  8998. }
  8999. async getKey(isButton) {
  9000. try {
  9001. const logStatus = scripts_echoLog({
  9002. text: i18n('gettingKey')
  9003. });
  9004. const {
  9005. result,
  9006. statusText,
  9007. status,
  9008. data
  9009. } = await tools_httpRequest({
  9010. url: 'https://opquests.com/keys',
  9011. method: 'GET'
  9012. });
  9013. if (result === 'Success') {
  9014. if (data?.responseText) {
  9015. const key = $(data?.responseText).find(`div.items-center:contains("${$('h1.font-bold').text().trim().replace(' Quest', '')}")`).find('div.font-bold').next().text();
  9016. if (!key) {
  9017. logStatus.error('Error: Key was not found');
  9018. if (isButton) {
  9019. window.open('https://opquests.com/keys', '_self');
  9020. }
  9021. return false;
  9022. }
  9023. logStatus.success();
  9024. scripts_echoLog({}).success(key);
  9025. return true;
  9026. }
  9027. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9028. return false;
  9029. }
  9030. logStatus.error(`${result}:${statusText}(${status})`);
  9031. return false;
  9032. } catch (error) {
  9033. throwError(error, 'Opquests.getGiveawayId');
  9034. return false;
  9035. }
  9036. }
  9037. #getGiveawayId() {
  9038. try {
  9039. const giveawayId = window.location.href.match(/quests\/([\d]+)/)?.[1];
  9040. if (giveawayId) {
  9041. this.giveawayId = giveawayId;
  9042. return true;
  9043. }
  9044. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  9045. return false;
  9046. } catch (error) {
  9047. throwError(error, 'Opquests.getGiveawayId');
  9048. return false;
  9049. }
  9050. }
  9051. #checkLogin() {
  9052. try {
  9053. if (!globalOptions.other.checkLogin) {
  9054. return true;
  9055. }
  9056. if ($('a[href*="/auth/redirect"]').length > 0) {
  9057. window.open('/auth/redirect', '_self');
  9058. }
  9059. return true;
  9060. } catch (error) {
  9061. throwError(error, 'Opquests.checkLogin');
  9062. return false;
  9063. }
  9064. }
  9065. }
  9066. const website_Opquests = Opquests;
  9067. const Gleam_defaultTasksTemplate = {
  9068. steam: {
  9069. groupLinks: [],
  9070. wishlistLinks: [],
  9071. followLinks: [],
  9072. curatorLinks: [],
  9073. curatorLikeLinks: []
  9074. },
  9075. twitter: {
  9076. userLinks: [],
  9077. retweetLinks: []
  9078. },
  9079. twitch: {
  9080. channelLinks: []
  9081. },
  9082. discord: {
  9083. serverLinks: []
  9084. },
  9085. youtube: {
  9086. channelLinks: []
  9087. },
  9088. extra: {
  9089. gleam: []
  9090. }
  9091. };
  9092. const Gleam_defaultTasks = JSON.stringify(Gleam_defaultTasksTemplate);
  9093. const Gleam_defaultOptions = {
  9094. vlootUsername: '',
  9095. gameroundUsername: ''
  9096. };
  9097. class Gleam extends website_Website {
  9098. name = 'Gleam';
  9099. undoneTasks = JSON.parse(Gleam_defaultTasks);
  9100. socialTasks = JSON.parse(Gleam_defaultTasks);
  9101. options = {
  9102. ...Gleam_defaultOptions,
  9103. ...GM_getValue('GleamOptions')
  9104. };
  9105. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  9106. static test() {
  9107. return window.location.host === 'gleam.io';
  9108. }
  9109. async after() {
  9110. try {
  9111. if (window.location.search.includes('8b07d23f4bfa65f9')) {
  9112. const checkComplete = setInterval(() => {
  9113. if ($('.entry-content .entry-method i.fa-check').length > 0) {
  9114. clearInterval(checkComplete);
  9115. window.close();
  9116. }
  9117. });
  9118. for (const task of $('.entry-content .entry-method')) {
  9119. const taskInfo = $(task).find('.user-links');
  9120. const expandInfo = $(task).find('.expandable');
  9121. const aElements = expandInfo.find('a.btn,a:contains(Continue),button:contains(Continue)');
  9122. if (aElements.length > 0) {
  9123. for (const element of aElements) {
  9124. const $element = $(element);
  9125. const href = $element.attr('href');
  9126. $element.removeAttr('href')[0].click();
  9127. $element.attr('href', href);
  9128. await delay(1e3);
  9129. }
  9130. }
  9131. taskInfo[0].click();
  9132. await delay(1e3);
  9133. }
  9134. scripts_echoLog({}).warning(i18n('gleamTaskNotice'));
  9135. } else if (!await this.#checkLeftKey()) {
  9136. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  9137. }
  9138. } catch (error) {
  9139. throwError(error, 'Gleam.after');
  9140. return false;
  9141. }
  9142. }
  9143. init() {
  9144. try {
  9145. const logStatus = scripts_echoLog({
  9146. text: i18n('initing')
  9147. });
  9148. if (!this.#getGiveawayId()) {
  9149. return false;
  9150. }
  9151. this.initialized = true;
  9152. logStatus.success();
  9153. return true;
  9154. } catch (error) {
  9155. throwError(error, 'Gleam.init');
  9156. return false;
  9157. }
  9158. }
  9159. async classifyTask(action) {
  9160. try {
  9161. const logStatus = scripts_echoLog({
  9162. text: i18n('getTasksInfo')
  9163. });
  9164. if (action === 'undo') {
  9165. this.socialTasks = GM_getValue(`gleamTasks-${this.giveawayId}`)?.tasks || JSON.parse(Gleam_defaultTasks);
  9166. }
  9167. const tasks = $('.entry-content .entry-method');
  9168. for (const task of tasks) {
  9169. const $task = $(task);
  9170. if (action === 'do' && $task.find('i.fa-question').length === 0) {
  9171. continue;
  9172. }
  9173. const socialIcon = $task.find('.icon-wrapper i');
  9174. const taskInfo = $task.find('.user-links');
  9175. const taskText = taskInfo.text().trim();
  9176. const expandInfo = $task.find('.expandable');
  9177. const aElements = expandInfo.find('a.btn');
  9178. if (aElements.length > 0) {
  9179. for (const element of aElements) {
  9180. const $element = $(element);
  9181. const href = $element.attr('href');
  9182. $element.removeAttr('href')[0].click();
  9183. $element.attr('href', href);
  9184. }
  9185. }
  9186. if (socialIcon.hasClass('fa-twitter')) {
  9187. const link = $task.find('a[href^="https://twitter.com/"]').attr('href');
  9188. if (!link) {
  9189. continue;
  9190. }
  9191. if (/follow/gi.test(taskText)) {
  9192. if (action === 'undo') {
  9193. this.socialTasks.twitter.userLinks.push(link);
  9194. }
  9195. if (action === 'do') {
  9196. this.undoneTasks.twitter.userLinks.push(link);
  9197. }
  9198. } else if (/retweet/gim.test(taskText)) {
  9199. if (action === 'undo') {
  9200. this.socialTasks.twitter.retweetLinks.push(link);
  9201. }
  9202. if (action === 'do') {
  9203. this.undoneTasks.twitter.retweetLinks.push(link);
  9204. }
  9205. }
  9206. } else if (socialIcon.hasClass('fa-twitch')) {
  9207. if (/follow/gim.test(taskText)) {
  9208. const link = $task.find('a[href^="https://twitch.tv/"]').attr('href');
  9209. if (!link) {
  9210. continue;
  9211. }
  9212. if (action === 'undo') {
  9213. this.socialTasks.twitch.channelLinks.push(link);
  9214. }
  9215. if (action === 'do') {
  9216. this.undoneTasks.twitch.channelLinks.push(link);
  9217. }
  9218. }
  9219. } else if (socialIcon.hasClass('fa-discord')) {
  9220. if (/join/gim.test(taskText)) {
  9221. let link = $task.find('a[href^="https://discord.com/invite/"]').attr('href');
  9222. if (!link) {
  9223. const ggLink = $task.find('a[href^="https://discord.gg/"]').attr('href')?.match(/discord\.gg\/([^/]+)/)?.[1];
  9224. if (!ggLink) {
  9225. continue;
  9226. }
  9227. link = `https://discord.com/invite/${ggLink}`;
  9228. }
  9229. if (action === 'undo') {
  9230. this.socialTasks.discord.serverLinks.push(link);
  9231. }
  9232. if (action === 'do') {
  9233. this.undoneTasks.discord.serverLinks.push(link);
  9234. }
  9235. }
  9236. } else if (socialIcon.hasClass('fa-external-link-square-alt')) {
  9237. continue;
  9238. } else if (socialIcon.hasClass('fa-youtube')) {
  9239. if (/subscribe/gim.test(taskText)) {
  9240. const link = $task.find('a[href^="https://www.youtube.com/channel/"]').attr('href');
  9241. if (!link) {
  9242. continue;
  9243. }
  9244. if (action === 'undo') {
  9245. this.socialTasks.youtube.channelLinks.push(link);
  9246. }
  9247. if (action === 'do') {
  9248. this.undoneTasks.youtube.channelLinks.push(link);
  9249. }
  9250. }
  9251. } else if (socialIcon.attr('class')?.includes('steam')) {
  9252. if (/join.*group/gi.test(taskText)) {
  9253. const link = $task.find('a[href^="https://steamcommunity.com/groups/"]').attr('href');
  9254. if (!link) {
  9255. continue;
  9256. }
  9257. if (action === 'undo') {
  9258. this.socialTasks.steam.groupLinks.push(link);
  9259. }
  9260. if (action === 'do') {
  9261. this.undoneTasks.steam.groupLinks.push(link);
  9262. }
  9263. } else if (/follow.*curator/gi.test(taskText)) {
  9264. const link = $task.find('a[href^="https://store.steampowered.com/curator/"]').attr('href');
  9265. if (!link) {
  9266. continue;
  9267. }
  9268. if (action === 'undo') {
  9269. this.socialTasks.steam.curatorLinks.push(link);
  9270. }
  9271. if (action === 'do') {
  9272. this.undoneTasks.steam.curatorLinks.push(link);
  9273. }
  9274. }
  9275. } else if (socialIcon.hasClass('fa-shield') && taskText.includes('vloot.io') || socialIcon.hasClass('fa-tiktok')) {
  9276. const continueBtn = expandInfo.find('span:contains(Continue),button:contains(Continue)');
  9277. for (const button of continueBtn) {
  9278. button.click();
  9279. await delay(500);
  9280. expandInfo.find('input').val(this.options.vlootUsername);
  9281. }
  9282. } else if (socialIcon.hasClass('fa-gamepad-alt') && taskText.includes('Gameround')) {
  9283. const continueBtn = expandInfo.find('span:contains(Continue),button:contains(Continue)');
  9284. for (const button of continueBtn) {
  9285. button.click();
  9286. await delay(500);
  9287. expandInfo.find('input').val(this.options.gameroundUsername);
  9288. }
  9289. } else if (socialIcon.hasClass('fa-bullhorn') && /Complete/gi.test(taskText)) {
  9290. if (action !== 'do') {
  9291. continue;
  9292. }
  9293. const gleamLink = await this.#getGleamLink(taskText);
  9294. if (!gleamLink) {
  9295. continue;
  9296. }
  9297. this.undoneTasks.extra.gleam.push(gleamLink);
  9298. } 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-shield') && taskText.includes('one of our giveaways') || socialIcon.hasClass('fa-shield') && taskText.includes('Check out')) {} else {
  9299. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskText}`);
  9300. }
  9301. }
  9302. logStatus.success();
  9303. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9304. this.socialTasks = this.uniqueTasks(this.socialTasks);
  9305. if (window.DEBUG) {
  9306. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9307. }
  9308. GM_setValue(`gleamTasks-${this.giveawayId}`, {
  9309. tasks: this.socialTasks,
  9310. time: new Date().getTime()
  9311. });
  9312. return true;
  9313. } catch (error) {
  9314. throwError(error, 'Gleam.classifyTask');
  9315. return false;
  9316. }
  9317. }
  9318. async extraDoTask({
  9319. gleam
  9320. }) {
  9321. try {
  9322. const pro = [];
  9323. for (const link of gleam) {
  9324. pro.push(this.#doGleamTask(link));
  9325. }
  9326. return Promise.all(pro).then(() => true);
  9327. } catch (error) {
  9328. throwError(error, 'Gleam.extraDoTask');
  9329. return false;
  9330. }
  9331. }
  9332. async verifyTask() {
  9333. try {
  9334. scripts_echoLog({
  9335. text: `${i18n('verifyingTask')}...`
  9336. });
  9337. const tasks = $('.entry-content .entry-method');
  9338. unsafeWindow._OxA = '_OxA';
  9339. for (const task of tasks) {
  9340. if ($('[campaign-key="campaign.key"]').length > 0) {
  9341. return scripts_echoLog({
  9342. text: i18n('campaign')
  9343. });
  9344. }
  9345. const $task = $(task);
  9346. if ($task.find('i.fa-question').length === 0) {
  9347. continue;
  9348. }
  9349. const taskInfo = $task.find('.user-links');
  9350. taskInfo[0].click();
  9351. unsafeWindow.$hookTimer?.setSpeed(1e3);
  9352. await delay(3e3);
  9353. unsafeWindow.$hookTimer?.setSpeed(1);
  9354. await this.#checkSync();
  9355. const continueBtn = $task.find('.expandable').find('span:contains(Continue),button:contains(Continue)');
  9356. for (const button of continueBtn) {
  9357. button.click();
  9358. await delay(500);
  9359. await this.#checkSync();
  9360. }
  9361. }
  9362. scripts_echoLog({
  9363. text: i18n('verifiedGleamTasks')
  9364. });
  9365. } catch (error) {
  9366. throwError(error, 'Gleam.verifyTask');
  9367. return false;
  9368. }
  9369. }
  9370. async #checkSync() {
  9371. try {
  9372. return await new Promise(resolve => {
  9373. const checker = setInterval(() => {
  9374. if ($('.entry-content .entry-method i.fa-sync').length === 0) {
  9375. clearInterval(checker);
  9376. resolve(true);
  9377. }
  9378. }, 500);
  9379. });
  9380. } catch (error) {
  9381. throwError(error, 'Gleam.checkSync');
  9382. return false;
  9383. }
  9384. }
  9385. async #doGleamTask(link) {
  9386. try {
  9387. const logStatus = scripts_echoLog({
  9388. text: i18n('doingGleamTask')
  9389. });
  9390. return await new Promise(resolve => {
  9391. GM_openInTab(`${link}?8b07d23f4bfa65f9`, {
  9392. active: true,
  9393. insert: true,
  9394. setParent: true
  9395. }).onclose = () => {
  9396. logStatus.success();
  9397. resolve(true);
  9398. };
  9399. });
  9400. } catch (error) {
  9401. throwError(error, 'Gleam.doGleamTask');
  9402. return false;
  9403. }
  9404. }
  9405. #getGiveawayId() {
  9406. try {
  9407. const giveawayId = window.location.pathname;
  9408. if (giveawayId) {
  9409. this.giveawayId = giveawayId;
  9410. return true;
  9411. }
  9412. scripts_echoLog({
  9413. text: i18n('getFailed', 'GiveawayId')
  9414. });
  9415. return false;
  9416. } catch (error) {
  9417. throwError(error, 'Gleam.getGiveawayId');
  9418. return false;
  9419. }
  9420. }
  9421. async #getGleamLink(title) {
  9422. try {
  9423. const logStatus = scripts_echoLog({
  9424. text: i18n('gettingGleamLink')
  9425. });
  9426. const {
  9427. result,
  9428. statusText,
  9429. status,
  9430. data
  9431. } = await tools_httpRequest({
  9432. url: 'https://www.vloot.io/api/v1/giveaways',
  9433. method: 'GET',
  9434. responseType: 'json'
  9435. });
  9436. if (result === 'Success') {
  9437. if (data?.status === 200 && data?.response?.Success === true && data?.response?.Data) {
  9438. const {
  9439. link
  9440. } = data.response.Data.find(giveaway => title.replace(/[\s]/g, '').toLowerCase().includes(giveaway.title.replace(/[\s]/g, '').toLowerCase())) || {};
  9441. if (link) {
  9442. logStatus.success();
  9443. return link;
  9444. }
  9445. logStatus.error(`Error:${i18n('getLinkFailed')}`);
  9446. return false;
  9447. }
  9448. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9449. return false;
  9450. }
  9451. logStatus.error(`${result}:${statusText}(${status})`);
  9452. return false;
  9453. } catch (error) {
  9454. throwError(error, 'Gleam.getGleamLink');
  9455. return false;
  9456. }
  9457. }
  9458. async #checkLeftKey() {
  9459. try {
  9460. if (!globalOptions.other.checkLeftKey) {
  9461. return true;
  9462. }
  9463. const campaignString = $('div.popup-blocks-container').attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  9464. if (!campaignString) {
  9465. return false;
  9466. }
  9467. const {
  9468. campaign,
  9469. incentive
  9470. } = JSON.parse(campaignString);
  9471. const controllerString = $('div.campaign.reward').attr('ng-init')?.match(/initContestant\(([\w\W]+?)\);/)?.[1];
  9472. let ownedKey = false;
  9473. if (controllerString) {
  9474. if (JSON.parse(controllerString).contestant?.claims?.incentives?.[incentive.id]?.length) {
  9475. ownedKey = true;
  9476. }
  9477. }
  9478. if (campaign.banned || campaign.finished && !ownedKey || campaign.paused || new Date().getTime() < campaign.starts_at * 1e3) {
  9479. await external_Swal_default().fire({
  9480. icon: 'warning',
  9481. title: i18n('notice'),
  9482. text: i18n('giveawayNotWork'),
  9483. confirmButtonText: i18n('confirm'),
  9484. cancelButtonText: i18n('cancel'),
  9485. showCancelButton: true
  9486. }).then(({
  9487. value
  9488. }) => {
  9489. if (value) {
  9490. window.close();
  9491. }
  9492. });
  9493. }
  9494. return true;
  9495. } catch (error) {
  9496. throwError(error, 'Gleam.checkLeftKey');
  9497. return false;
  9498. }
  9499. }
  9500. }
  9501. const website_Gleam = Gleam;
  9502. const SweepWidget_defaultOptions = {
  9503. username: '',
  9504. email: ''
  9505. };
  9506. class SweepWidget extends website_Website {
  9507. name = 'SweepWidget';
  9508. options = {
  9509. ...SweepWidget_defaultOptions,
  9510. ...GM_getValue('SweepWidgetOptions')
  9511. };
  9512. buttons = [ 'doTask' ];
  9513. static test() {
  9514. return /^https?:\/\/sweepwidget\.com\/view\/[\d]+/.test(window.location.href);
  9515. }
  9516. async after() {
  9517. try {
  9518. if (!this.#checkLogin()) {
  9519. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9520. }
  9521. } catch (error) {
  9522. throwError(error, 'SweepWidget.after');
  9523. }
  9524. }
  9525. init() {
  9526. try {
  9527. const logStatus = scripts_echoLog({
  9528. text: i18n('initing')
  9529. });
  9530. if (!this.#checkLogin()) {
  9531. logStatus.warning(i18n('needLogin'));
  9532. return false;
  9533. }
  9534. if (!this.#getGiveawayId()) {
  9535. return false;
  9536. }
  9537. this.initialized = true;
  9538. logStatus.success();
  9539. return true;
  9540. } catch (error) {
  9541. throwError(error, 'SweepWidget.init');
  9542. return false;
  9543. }
  9544. }
  9545. classifyTask() {
  9546. return true;
  9547. }
  9548. async doTask() {
  9549. try {
  9550. if ($('#unlock_rewards_main_wrapper').length === 0) {
  9551. if ($('input[name="sw__login_name"]:visible').length > 0) {
  9552. $('input[name="sw__login_name"]').val(this.options.username);
  9553. }
  9554. if ($('input[name="sw__login_email"]:visible').length > 0) {
  9555. $('input[name="sw__login_email"]').val(this.options.email);
  9556. }
  9557. if ($('#sw_login_button:visible').length > 0) {
  9558. $('#sw_login_button')[0].click();
  9559. }
  9560. if (!await this.#checkEnter()) {
  9561. return false;
  9562. }
  9563. }
  9564. const logStatus = scripts_echoLog({
  9565. text: i18n('SweepWidgetNotice')
  9566. });
  9567. const tasks = $('#sw_inner_entry_methods_l2_wrapper>div.sw_entry');
  9568. for (const task of tasks) {
  9569. const $task = $(task);
  9570. if ($task.find('i.fa-check:visible').length > 0) {
  9571. continue;
  9572. }
  9573. const title = $task.find('.sw_text_inner');
  9574. title[0].click();
  9575. const aElement = $task.find('a.sw_link');
  9576. const link = aElement.attr('href');
  9577. aElement.attr('href', '#a').attr('target', '_self');
  9578. aElement[0]?.click();
  9579. await delay(300);
  9580. aElement.attr('href', link).attr('target', '_blank');
  9581. $task.find('input[type="text"]').val('test');
  9582. const verifyBtn = $task.find('input.sw_verify');
  9583. if (verifyBtn.prop('disabled') === true) {
  9584. title[0].click();
  9585. await delay(300);
  9586. title[0].click();
  9587. await delay(300);
  9588. }
  9589. $task.find('input.sw_verify').removeAttr('disabled')[0]?.click();
  9590. await this.#checkFinish($task);
  9591. await delay(parseInt(`${Math.random() * (3e3 - 1e3 + 1) + 1e3}`, 10));
  9592. }
  9593. logStatus.success();
  9594. return true;
  9595. } catch (error) {
  9596. throwError(error, 'SweepWidget.doTask');
  9597. return false;
  9598. }
  9599. }
  9600. #checkLogin() {
  9601. try {
  9602. if ($('#twitter_login_button').length > 0) {
  9603. $('#twitter_login_button')[0].click();
  9604. }
  9605. return true;
  9606. } catch (error) {
  9607. throwError(error, 'SweepWidget.checkLogin');
  9608. return false;
  9609. }
  9610. }
  9611. #getGiveawayId() {
  9612. try {
  9613. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  9614. if (giveawayId) {
  9615. this.giveawayId = giveawayId;
  9616. return true;
  9617. }
  9618. scripts_echoLog({
  9619. text: i18n('getFailed', 'GiveawayId')
  9620. });
  9621. return false;
  9622. } catch (error) {
  9623. throwError(error, 'SweepWidget.getGiveawayId');
  9624. return false;
  9625. }
  9626. }
  9627. async #checkEnter() {
  9628. try {
  9629. return new Promise(resolve => {
  9630. const checker = setInterval(() => {
  9631. if ($('#unlock_rewards_main_wrapper').length > 0) {
  9632. clearInterval(checker);
  9633. resolve(true);
  9634. }
  9635. });
  9636. });
  9637. } catch (error) {
  9638. throwError(error, 'SweepWidget.checkEnter');
  9639. return false;
  9640. }
  9641. }
  9642. async #checkFinish($task) {
  9643. try {
  9644. return new Promise(resolve => {
  9645. const checker = setInterval(() => {
  9646. if ($task.find('i.fa-check:visible').length > 0 || $task.find('.sw_entry_input:visible').length === 0) {
  9647. clearInterval(checker);
  9648. resolve(true);
  9649. }
  9650. });
  9651. });
  9652. } catch (error) {
  9653. throwError(error, 'SweepWidget.checkFinish');
  9654. return false;
  9655. }
  9656. }
  9657. }
  9658. const website_SweepWidget = SweepWidget;
  9659. const defaultWhiteList = {
  9660. discord: {
  9661. servers: []
  9662. },
  9663. instagram: {
  9664. users: []
  9665. },
  9666. twitch: {
  9667. channels: []
  9668. },
  9669. twitter: {
  9670. users: [],
  9671. retweets: [],
  9672. likes: []
  9673. },
  9674. vk: {
  9675. names: []
  9676. },
  9677. youtube: {
  9678. channels: [],
  9679. likes: []
  9680. },
  9681. reddit: {
  9682. reddits: []
  9683. },
  9684. steam: {
  9685. groups: [],
  9686. officialGroups: [],
  9687. wishlists: [],
  9688. follows: [],
  9689. forums: [],
  9690. workshops: [],
  9691. curators: [],
  9692. workshopVotes: [],
  9693. curatorLikes: [],
  9694. announcements: [],
  9695. licenses: [],
  9696. playtests: []
  9697. }
  9698. };
  9699. const link2id = async function(type) {
  9700. try {
  9701. const link = $('#socialLink').val();
  9702. let id = '';
  9703. switch (type) {
  9704. case 'discord.servers':
  9705. id = link.match(/invite\/(.+)/)?.[1] || '';
  9706. break;
  9707.  
  9708. case 'instagram.users':
  9709. id = link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1] || '';
  9710. break;
  9711.  
  9712. case 'twitch.channels':
  9713. id = link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2] || '';
  9714. break;
  9715.  
  9716. case 'twitter.users':
  9717. id = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || '';
  9718. break;
  9719.  
  9720. case 'twitter.retweets':
  9721. id = link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1] || '';
  9722. break;
  9723.  
  9724. case 'vk.names':
  9725. id = link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1] || '';
  9726. break;
  9727.  
  9728. case 'youtube.channels':
  9729. id = (await getInfo(link, 'channel'))?.params?.channelId || '';
  9730. break;
  9731.  
  9732. case 'youtube.likes':
  9733. id = (await getInfo(link, 'likeVideo'))?.params?.videoId || '';
  9734. break;
  9735.  
  9736. case 'reddit.reddits':
  9737. id = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1] || link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1] || '';
  9738. break;
  9739.  
  9740. case 'steam.groups':
  9741. id = link.match(/groups\/(.+)\/?/)?.[1] || '';
  9742. break;
  9743.  
  9744. case 'steam.wishlists':
  9745. case 'steam.follows':
  9746. case 'steam.forums':
  9747. id = link.match(/app\/([\d]+)/)?.[1] || '';
  9748. break;
  9749.  
  9750. case 'steam.workshops':
  9751. id = link.match(/\?id=([\d]+)/)?.[1] || '';
  9752. break;
  9753.  
  9754. case 'steam.curators':
  9755. {
  9756. if (link.includes('curator')) {
  9757. id = link.match(/curator\/([\d]+)/)?.[1] || '';
  9758. } else {
  9759. const param = link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3);
  9760. if (!param || param.length !== 2) {
  9761. break;
  9762. }
  9763. const steam = new social_Steam();
  9764. if (await steam.init()) {
  9765. id = await steam.getCuratorId(param[0], param[1]) || '';
  9766. }
  9767. }
  9768. }
  9769. break;
  9770. }
  9771. return id;
  9772. } catch (error) {
  9773. throwError(error, 'link2id');
  9774. return i18n('getFailed', 'id');
  9775. }
  9776. };
  9777. const disabledType = {
  9778. steam: [ 'workshopVotes', 'curatorLikes', 'announcements' ],
  9779. twitter: [ 'likes' ]
  9780. };
  9781. const assignWhiteList = whiteList => {
  9782. try {
  9783. const newWhiteList = {};
  9784. for (const [ key, value ] of Object.entries(defaultWhiteList)) {
  9785. newWhiteList[key] = {
  9786. ...value,
  9787. ...whiteList[key]
  9788. };
  9789. }
  9790. return newWhiteList;
  9791. } catch (error) {
  9792. throwError(error, 'assignWhiteList');
  9793. return defaultWhiteList;
  9794. }
  9795. };
  9796. const whiteListOptions = function(showType) {
  9797. try {
  9798. const whiteList = assignWhiteList(GM_getValue('whiteList') || {});
  9799. let whiteListOptionsForm = `<form id="whiteListForm" class="auto-task-form">
  9800. <table class="auto-task-table"><thead><tr><td>${i18n('website')}</td><td>${i18n('type')}</td><td>${i18n('edit')}</td></tr></thead><tbody>`;
  9801. for (const [ social, types ] of Object.entries(whiteList)) {
  9802. 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('');
  9803. }
  9804. whiteListOptionsForm += '</tbody></table></form>';
  9805. if (showType === 'swal') {
  9806. external_Swal_default().fire({
  9807. title: i18n('whiteListOptions'),
  9808. html: whiteListOptionsForm,
  9809. showConfirmButton: false,
  9810. showCloseButton: true
  9811. });
  9812. } else {
  9813. $('body').append(`<h2>${i18n('whiteList')}</h2>${whiteListOptionsForm}`);
  9814. }
  9815. $('.editWhiteList').on('click', function() {
  9816. const value = $(this).attr('data-value');
  9817. if (!value) {
  9818. return;
  9819. }
  9820. const [ social, type ] = value.split('.');
  9821. if (!whiteList?.[social]?.[type]) {
  9822. scripts_echoLog({}).warning(i18n('whiteListNotFound', value));
  9823. return;
  9824. }
  9825. external_Swal_default().fire({
  9826. title: i18n('changeWhiteListOption', value),
  9827. input: 'textarea',
  9828. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  9829. <button id="link2id" data-type="${value}" class="swal2-confirm swal2-styled">获取id</button>
  9830. <p style="margin-bottom:0 !important;">在下方填写白名单,每行一个</p>`,
  9831. inputValue: whiteList[social][type].join('\n'),
  9832. showConfirmButton: true,
  9833. confirmButtonText: i18n('save'),
  9834. showCancelButton: true,
  9835. cancelButtonText: i18n('close'),
  9836. showDenyButton: true,
  9837. denyButtonText: i18n('return')
  9838. }).then(({
  9839. isDenied,
  9840. isConfirmed,
  9841. value
  9842. }) => {
  9843. if (isDenied) {
  9844. if (showType === 'swal') {
  9845. whiteListOptions(showType);
  9846. }
  9847. return;
  9848. } else if (isConfirmed) {
  9849. whiteList[social][type] = value.split('\n');
  9850. GM_setValue('whiteList', whiteList);
  9851. external_Swal_default().fire({
  9852. title: i18n('changeWhiteListSuccess'),
  9853. icon: 'success'
  9854. });
  9855. }
  9856. });
  9857. $('#link2id').on('click', async function() {
  9858. const type = $(this).attr('data-type');
  9859. $('#socialLink').val(await link2id(type));
  9860. });
  9861. });
  9862. } catch (error) {
  9863. throwError(error, 'whiteListOptions');
  9864. }
  9865. };
  9866. const whiteList = whiteListOptions;
  9867. const setGistData = async (token, gistId, fileName, content) => {
  9868. try {
  9869. const logStatus = scripts_echoLog({
  9870. text: i18n('settingData')
  9871. });
  9872. const contentData = JSON.stringify({
  9873. files: {
  9874. [fileName]: {
  9875. content: JSON.stringify(content)
  9876. }
  9877. }
  9878. });
  9879. const {
  9880. result,
  9881. statusText,
  9882. status,
  9883. data
  9884. } = await tools_httpRequest({
  9885. url: `https://api.github.com/gists/${gistId}`,
  9886. headers: {
  9887. Accept: 'application/vnd.github.v3+json',
  9888. Authorization: `token ${token}`
  9889. },
  9890. data: contentData,
  9891. responseType: 'json',
  9892. method: 'POST',
  9893. timeout: 3e4
  9894. });
  9895. if (result === 'Success') {
  9896. if (data?.status === 200 && data.response.files?.[fileName]?.content === JSON.stringify(content)) {
  9897. logStatus.success();
  9898. return true;
  9899. }
  9900. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9901. return false;
  9902. }
  9903. logStatus.error(`${result}:${statusText}(${status})`);
  9904. return false;
  9905. } catch (error) {
  9906. throwError(error, 'setGistData');
  9907. return false;
  9908. }
  9909. };
  9910. const getGistData = async (token, gistId, fileName, test = false) => {
  9911. try {
  9912. const logStatus = scripts_echoLog({
  9913. text: i18n('gettingData')
  9914. });
  9915. const {
  9916. result,
  9917. statusText,
  9918. status,
  9919. data
  9920. } = await tools_httpRequest({
  9921. url: `https://api.github.com/gists/${gistId}`,
  9922. headers: {
  9923. Accept: 'application/vnd.github.v3+json',
  9924. Authorization: `token ${token}`
  9925. },
  9926. responseType: 'json',
  9927. method: 'GET',
  9928. timeout: 3e4
  9929. });
  9930. if (result === 'Success') {
  9931. if (data?.status === 200) {
  9932. const content = data.response?.files?.[fileName]?.content;
  9933. let formatedContent;
  9934. if (!content) {
  9935. logStatus.error(`Error:${i18n('noRemoteData')}`);
  9936. return false;
  9937. }
  9938. if (test) {
  9939. logStatus.success();
  9940. return true;
  9941. }
  9942. try {
  9943. formatedContent = JSON.parse(content);
  9944. } catch (error) {
  9945. logStatus.error(`Error:${i18n('errorRemoteDataFormat')}`);
  9946. return false;
  9947. }
  9948. logStatus.success();
  9949. return formatedContent;
  9950. }
  9951. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9952. return false;
  9953. }
  9954. logStatus.error(`${result}:${statusText}(${status})`);
  9955. return false;
  9956. } catch (error) {
  9957. throwError(error, 'getGistData');
  9958. return false;
  9959. }
  9960. };
  9961. const syncOptions = () => {
  9962. try {
  9963. const {
  9964. TOKEN,
  9965. GIST_ID,
  9966. FILE_NAME,
  9967. SYNC_HISTORY
  9968. } = GM_getValue('gistOptions') || {
  9969. TOKEN: '',
  9970. GIST_ID: '',
  9971. FILE_NAME: '',
  9972. SYNC_HISTORY: true
  9973. };
  9974. external_Swal_default().fire({
  9975. title: i18n('gistOptions'),
  9976. 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;">
  9977. ${i18n('upload2gist')}</button>` + `<button id="download-data" type="button" class="swal2-confirm swal2-styled" style="display: inline-block;">
  9978. ${i18n('downloadFromGist')}</button></p>`,
  9979. focusConfirm: false,
  9980. showLoaderOnConfirm: true,
  9981. 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>`,
  9982. preConfirm: async () => {
  9983. const token = $('#github-token').val();
  9984. const gistId = $('#gist-id').val();
  9985. const fileName = $('#file-name').val();
  9986. const syncHistory = $('#sync-history').prop('checked');
  9987. GM_setValue('gistOptions', {
  9988. TOKEN: token,
  9989. GIST_ID: gistId,
  9990. FILE_NAME: fileName,
  9991. SYNC_HISTORY: syncHistory
  9992. });
  9993. return await getGistData(token, gistId, fileName, true);
  9994. },
  9995. allowOutsideClick: () => !external_Swal_default().isLoading(),
  9996. confirmButtonText: i18n('saveAndTest'),
  9997. showCancelButton: true,
  9998. cancelButtonText: i18n('close')
  9999. }).then(({
  10000. value
  10001. }) => {
  10002. if (value) {
  10003. external_Swal_default().fire({
  10004. icon: 'success',
  10005. title: i18n('testSuccess')
  10006. }).then(syncOptions);
  10007. } else if (value !== undefined) {
  10008. external_Swal_default().fire({
  10009. icon: 'error',
  10010. title: i18n('testFailed')
  10011. }).then(syncOptions);
  10012. }
  10013. });
  10014. $('#upload-data').on('click', async () => {
  10015. const {
  10016. TOKEN,
  10017. GIST_ID,
  10018. FILE_NAME
  10019. } = GM_getValue('gistOptions') || {};
  10020. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10021. return external_Swal_default().fire({
  10022. icon: 'error',
  10023. title: i18n('saveAndTestNotice')
  10024. }).then(syncOptions);
  10025. }
  10026. external_Swal_default().fire({
  10027. icon: 'info',
  10028. title: i18n('processingData')
  10029. });
  10030. const data = {};
  10031. const names = GM_listValues();
  10032. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10033. for (const name of names) {
  10034. if (name === 'gistOptions' || /^[\w]+?Auth$/.test(name)) {
  10035. continue;
  10036. }
  10037. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10038. continue;
  10039. }
  10040. data[name] = GM_getValue(name);
  10041. }
  10042. external_Swal_default().update({
  10043. icon: 'info',
  10044. title: i18n('updatingData')
  10045. });
  10046. if (await setGistData(TOKEN, GIST_ID, FILE_NAME, data)) {
  10047. external_Swal_default().fire({
  10048. icon: 'success',
  10049. title: i18n('syncDataSuccess')
  10050. });
  10051. } else {
  10052. external_Swal_default().fire({
  10053. icon: 'error',
  10054. title: i18n('syncDataFailed')
  10055. });
  10056. }
  10057. });
  10058. $('#download-data').on('click', async () => {
  10059. const {
  10060. TOKEN,
  10061. GIST_ID,
  10062. FILE_NAME
  10063. } = GM_getValue('gistOptions') || {};
  10064. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10065. return external_Swal_default().fire({
  10066. icon: 'error',
  10067. title: i18n('saveAndTestNotice')
  10068. }).then(syncOptions);
  10069. }
  10070. external_Swal_default().fire({
  10071. icon: 'info',
  10072. title: i18n('downloadingData')
  10073. });
  10074. const data = await getGistData(TOKEN, GIST_ID, FILE_NAME);
  10075. if (!data) {
  10076. return external_Swal_default().fire({
  10077. icon: 'error',
  10078. title: i18n('checkedNoData')
  10079. }).then(syncOptions);
  10080. }
  10081. external_Swal_default().update({
  10082. icon: 'info',
  10083. title: i18n('savingData')
  10084. });
  10085. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10086. for (const [ name, value ] of Object.entries(data)) {
  10087. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10088. continue;
  10089. }
  10090. GM_setValue(name, value);
  10091. }
  10092. external_Swal_default().fire({
  10093. icon: 'success',
  10094. title: i18n('syncDataSuccess')
  10095. });
  10096. });
  10097. } catch (error) {
  10098. throwError(error, 'syncOptions');
  10099. }
  10100. };
  10101. const dataSync = syncOptions;
  10102. class Setting {
  10103. name = 'Setting';
  10104. buttons = [ 'saveGlobalOptions', 'syncData', 'tasksHistory' ];
  10105. syncData = dataSync;
  10106. tasksHistory() {
  10107. window.open('https://auto-task-v4.hclonely.com/history.html', '_blank');
  10108. }
  10109. static test() {
  10110. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/setting.html';
  10111. }
  10112. before() {
  10113. $('body').html('').addClass('auto-task-options');
  10114. }
  10115. after() {
  10116. try {
  10117. this.#environment();
  10118. changeGlobalOptions('page');
  10119. whiteList('page');
  10120. $('input[name="other.twitterVerifyId"]').after(`<button id="getTwitterUserId" type="button">${i18n('getTwitterUserId')}</button>`);
  10121. $('#getTwitterUserId').on('click', () => {
  10122. this.#getId('twitterUser');
  10123. });
  10124. $('input[name="other.youtubeVerifyChannel"]').after(`<button id="getYoutubeChannelId" type="button">${i18n('getYoutubeChannelId')}</button>`);
  10125. $('#getYoutubeChannelId').on('click', () => {
  10126. this.#getId('youtubeChannel');
  10127. });
  10128. $('input[name^="position"]').on('input', function() {
  10129. const type = $(this).attr('name').replace('position.', '');
  10130. const xLabel = 'rightleft';
  10131. const yLabel = 'topbottpm';
  10132. switch (type) {
  10133. case 'buttonSideX':
  10134. case 'buttonSideY':
  10135. case 'buttonDistance':
  10136. {
  10137. const distance = $('input[name="position.buttonDistance"]').val();
  10138. const sideX = $('input[name="position.buttonSideX"]').val();
  10139. const sideY = $('input[name="position.buttonSideY"]').val();
  10140. if (![ 'right', 'left' ].includes(sideX)) {
  10141. break;
  10142. }
  10143. if (![ 'top', 'bottom' ].includes(sideY)) {
  10144. break;
  10145. }
  10146. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10147. break;
  10148. }
  10149. const distanceArr = distance.split(',');
  10150. $('#auto-task-buttons').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10151. break;
  10152. }
  10153.  
  10154. case 'showButtonSideX':
  10155. case 'showButtonSideY':
  10156. case 'showButtonDistance':
  10157. {
  10158. const distance = $('input[name="position.showButtonDistance"]').val();
  10159. const sideX = $('input[name="position.showButtonSideX"]').val();
  10160. const sideY = $('input[name="position.showButtonSideY"]').val();
  10161. if (![ 'right', 'left' ].includes(sideX)) {
  10162. break;
  10163. }
  10164. if (![ 'top', 'bottom' ].includes(sideY)) {
  10165. break;
  10166. }
  10167. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10168. break;
  10169. }
  10170. const distanceArr = distance.split(',');
  10171. $('div.show-button-div').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10172. break;
  10173. }
  10174.  
  10175. case 'logSideX':
  10176. case 'logSideY':
  10177. case 'logDistance':
  10178. {
  10179. const distance = $('input[name="position.logDistance"]').val();
  10180. const sideX = $('input[name="position.logSideX"]').val();
  10181. const sideY = $('input[name="position.logSideY"]').val();
  10182. if (![ 'right', 'left' ].includes(sideX)) {
  10183. break;
  10184. }
  10185. if (![ 'top', 'bottom' ].includes(sideY)) {
  10186. break;
  10187. }
  10188. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10189. break;
  10190. }
  10191. const distanceArr = distance.split(',');
  10192. $('#auto-task-info').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10193. break;
  10194. }
  10195.  
  10196. default:
  10197. break;
  10198. }
  10199. });
  10200. $('input[name^="hotKey"]').attr('readonly', 'readonly').off('keydown').on('keydown', function(event) {
  10201. let functionKey = '';
  10202. if (event.altKey) {
  10203. functionKey += 'alt + ';
  10204. } else if (event.ctrlKey) {
  10205. functionKey += 'ctrl + ';
  10206. } else if (event.shiftKey) {
  10207. functionKey += 'shift + ';
  10208. }
  10209. $(this).val(functionKey + (event.key.length === 1 ? event.key.toLowerCase() : ''));
  10210. });
  10211. } catch (error) {
  10212. throwError(error, 'Setting.after');
  10213. }
  10214. }
  10215. saveGlobalOptions() {
  10216. saveData();
  10217. }
  10218. #getId(social) {
  10219. try {
  10220. external_Swal_default().fire({
  10221. title: i18n('getId', i18n(social)),
  10222. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10223. <button id="link2id" data-type="${social}" class="swal2-confirm swal2-styled">获取id</button>`,
  10224. showCancelButton: true,
  10225. cancelButtonText: i18n('close'),
  10226. showConfirmButton: false
  10227. });
  10228. $('#link2id').on('click', async function() {
  10229. const link = $('#socialLink').val();
  10230. if (!link) {
  10231. return;
  10232. }
  10233. const type = $(this).attr('data-type');
  10234. if (type === 'twitterUser') {
  10235. const name = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || link;
  10236. $('#socialLink').val(await new social_Twitter().userName2id(name) || '');
  10237. } else if (type === 'youtubeChannel') {
  10238. const name = /^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www.youtube.com\/.*/.test(link) ? link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1] : link;
  10239. $('#socialLink').val((await getInfo(name, 'channel'))?.params?.channelId || '');
  10240. }
  10241. });
  10242. } catch (error) {
  10243. throwError(error, 'Setting.getId');
  10244. }
  10245. }
  10246. #environment() {
  10247. try {
  10248. const userAgent = (0, javascript_utils_umd_min.ua)();
  10249. const environmentForm = `<form id="environmentForm" class="auto-task-form">
  10250. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('name')}</td><td>${i18n('version')}</td></tr></thead><tbody>
  10251. <tr><td>${i18n('os')}</td><td>${userAgent.os}</td><td>${userAgent.osVersion}</td></tr>
  10252. <tr><td>${i18n('browser')}</td><td>${userAgent.browserZH}</td><td>${userAgent.browserVersion}</td></tr>
  10253. <tr><td>${i18n('scriptManager')}</td><td>${GM_info.scriptHandler}</td><td>${GM_info.version}</td></tr>
  10254. <tr><td>${i18n('script')}</td><td>${GM_info.script.name}</td><td>${GM_info.script.version}</td></tr>
  10255. </tbody></table></form>`;
  10256. $('body').append(`<h2>${i18n('environment')}</h2>${environmentForm}`);
  10257. } catch (error) {
  10258. throwError(error, 'Setting.environment');
  10259. }
  10260. }
  10261. }
  10262. const website_Setting = Setting;
  10263. class History extends website_Keylol {
  10264. name = 'History';
  10265. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect', 'clearHistory' ];
  10266. static test() {
  10267. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/history.html';
  10268. }
  10269. before() {
  10270. try {
  10271. $('body').html('<div class="container"></div>').addClass('auto-task-history');
  10272. const data = GM_listValues() || [];
  10273. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10274. for (const item of tasksHistory) {
  10275. this.#addItem(item);
  10276. }
  10277. } catch (error) {
  10278. throwError(error, 'History.before');
  10279. }
  10280. }
  10281. clearHistory() {
  10282. try {
  10283. const data = GM_listValues() || [];
  10284. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10285. for (const item of tasksHistory) {
  10286. GM_deleteValue(item);
  10287. }
  10288. external_Swal_default().fire({
  10289. title: i18n('clearHistoryFinished'),
  10290. icon: 'success'
  10291. });
  10292. } catch (error) {
  10293. throwError(error, 'History.after');
  10294. }
  10295. }
  10296. #addItem(item) {
  10297. try {
  10298. const tasksData = GM_getValue(item);
  10299. if (!tasksData?.tasks) {
  10300. return;
  10301. }
  10302. let html = '';
  10303. let title = '';
  10304. let link = '';
  10305. const [ website, id ] = item.split('-');
  10306. switch (website) {
  10307. case 'fawTasks':
  10308. title = `Freeanywhere[${id}]`;
  10309. link = `https://freeanywhere.net/#/giveaway/${id}`;
  10310. break;
  10311.  
  10312. case 'gasTasks':
  10313. title = `Giveawaysu[${id}]`;
  10314. link = `https://giveaway.su/giveaway/view/${id}`;
  10315. break;
  10316.  
  10317. case 'gcTasks':
  10318. title = `GiveeClub[${id}]`;
  10319. link = `https://givee.club/event/${id}`;
  10320. break;
  10321.  
  10322. case 'gkTasks':
  10323. title = `Givekey[${id}]`;
  10324. link = `https://givekey.ru/giveaway/${id}`;
  10325. break;
  10326.  
  10327. case 'gleamTasks':
  10328. title = `Gleam[${id}]`;
  10329. link = `https://gleam.io${id}`;
  10330. break;
  10331.  
  10332. case 'khTasks':
  10333. title = `keyhub[${id}]`;
  10334. link = `https://key-hub.eu/giveaway/${id}`;
  10335. break;
  10336.  
  10337. case 'prysTasks':
  10338. title = `Prys[${id}]`;
  10339. link = `https://prys.revadike.com/giveaway/?id=${id}`;
  10340. break;
  10341.  
  10342. default:
  10343. return;
  10344. }
  10345. for (const [ social, types ] of Object.entries(tasksData.tasks)) {
  10346. for (const [ type, tasks ] of Object.entries(types)) {
  10347. for (const task of tasks) {
  10348. 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>`;
  10349. }
  10350. }
  10351. }
  10352. $('.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>`);
  10353. $('span.delete-task').on('click', function() {
  10354. const itemName = $(this).attr('data-name');
  10355. if (itemName) {
  10356. GM_deleteValue(itemName);
  10357. $(`div.card[data-name="${itemName}"]`).remove();
  10358. external_Swal_default().fire({
  10359. title: i18n('clearTaskFinished'),
  10360. text: itemName,
  10361. icon: 'success'
  10362. });
  10363. } else {
  10364. external_Swal_default().fire({
  10365. title: i18n('clearTaskFailed'),
  10366. icon: 'error'
  10367. });
  10368. }
  10369. });
  10370. } catch (error) {
  10371. throwError(error, 'History.addItem');
  10372. }
  10373. }
  10374. }
  10375. const website_History = History;
  10376. const Websites = [ website_FreeAnyWhere, GiveawaySu, website_Indiedb, website_Keyhub, website_Givekey, website_GiveeClub, website_OpiumPulses, website_Keylol, website_Opquests, website_Gleam, website_SweepWidget, website_Setting, website_History ];
  10377. const websiteOptions = function(website, options) {
  10378. try {
  10379. let websiteOptionsForm = `<form id="websiteOptionsForm" class="auto-task-form">
  10380. <table class="auto-task-table"><thead><tr><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  10381. for (const [ option, value ] of Object.entries(options)) {
  10382. websiteOptionsForm += `<tr><td>${option}</td><td><input class="editOption" type="text" name="${option}" value="${value}"/></td></tr>`;
  10383. }
  10384. websiteOptionsForm += '</tbody></table></form>';
  10385. external_Swal_default().fire({
  10386. title: i18n('websiteOptions'),
  10387. html: websiteOptionsForm,
  10388. showConfirmButton: true,
  10389. confirmButtonText: i18n('save'),
  10390. showCancelButton: true,
  10391. cancelButtonText: i18n('close')
  10392. }).then(({
  10393. isConfirmed
  10394. }) => {
  10395. if (isConfirmed) {
  10396. $('#websiteOptionsForm').serializeArray().map(value => {
  10397. options[value.name] = value.value;
  10398. return value;
  10399. });
  10400. GM_setValue(`${website}Options`, options);
  10401. external_Swal_default().fire({
  10402. title: i18n('changeWebsiteOptionsSuccess'),
  10403. icon: 'success'
  10404. });
  10405. }
  10406. });
  10407. } catch (error) {
  10408. throwError(error, 'websiteOptions');
  10409. }
  10410. };
  10411. const options = websiteOptions;
  10412. const external_keyboardJS_namespaceObject = keyboardJS;
  10413. var external_keyboardJS_default = __webpack_require__.n(external_keyboardJS_namespaceObject);
  10414. const checkUpdate = async (updateLink, auto) => {
  10415. try {
  10416. const checkUrl = `${updateLink}package.json?time=${new Date().getTime()}`;
  10417. const {
  10418. result,
  10419. statusText,
  10420. status,
  10421. data
  10422. } = await tools_httpRequest({
  10423. url: checkUrl,
  10424. responseType: 'json',
  10425. method: 'GET',
  10426. timeout: 3e4
  10427. });
  10428. if (result === 'Success') {
  10429. if (data?.response?.version) {
  10430. return data.response;
  10431. }
  10432. if (!auto) {
  10433. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${data?.statusText}(${data?.status})]`);
  10434. }
  10435. return false;
  10436. }
  10437. if (!auto) {
  10438. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${result}:${statusText}(${status})]`);
  10439. }
  10440. return false;
  10441. } catch (error) {
  10442. throwError(error, 'checkUpdate');
  10443. return false;
  10444. }
  10445. };
  10446. const hasNewVersion = (currentVersion, remoteVersion) => {
  10447. try {
  10448. const [ currentRealVersion ] = currentVersion.split('-');
  10449. const [ remoteRealVersion, isPreview ] = remoteVersion.split('-');
  10450. if (isPreview && !globalOptions.other.receivePreview) {
  10451. return false;
  10452. }
  10453. const [ currentVersion1, currentVersion2, currentVersion3 ] = currentRealVersion.split('.').map(value => parseInt(value, 10));
  10454. const [ remoteVersion1, remoteVersion2, remoteVersion3 ] = remoteRealVersion.split('.').map(value => parseInt(value, 10));
  10455. if (remoteVersion1 > currentVersion1) {
  10456. return true;
  10457. }
  10458. if (remoteVersion1 < currentVersion1) {
  10459. return false;
  10460. }
  10461. if (remoteVersion2 > currentVersion2) {
  10462. return true;
  10463. }
  10464. if (remoteVersion2 < currentVersion2) {
  10465. return false;
  10466. }
  10467. if (remoteVersion3 > currentVersion3) {
  10468. return true;
  10469. }
  10470. return false;
  10471. } catch (error) {
  10472. throwError(error, 'compareVersion');
  10473. return false;
  10474. }
  10475. };
  10476. const updateChecker = async () => {
  10477. try {
  10478. const currentVersion = GM_info.script.version;
  10479. const updateSource = globalOptions.other.autoUpdateSource.toLowerCase();
  10480. const updateLinks = {
  10481. github: 'https://github.com/HCLonely/auto-task-new/raw/main/',
  10482. jsdelivr: 'https://cdn.jsdelivr.net/gh/HCLonely/auto-task-v4@main/',
  10483. standby: 'https://auto-task-v4.hclonely.com/'
  10484. };
  10485. let version;
  10486. let updateLink = '';
  10487. let packageData;
  10488. if ([ 'github', 'jsdelivr', 'standby' ].includes(updateSource)) {
  10489. updateLink = updateLinks[updateSource];
  10490. packageData = await checkUpdate(updateLink, false);
  10491. } else {
  10492. updateLink = updateLinks.github;
  10493. packageData = await checkUpdate(updateLink, true);
  10494. if (!packageData) {
  10495. updateLink = updateLinks.jsdelivr;
  10496. packageData = await checkUpdate(updateLink, true);
  10497. if (!packageData) {
  10498. updateLink = updateLinks.standby;
  10499. packageData = await checkUpdate(updateLink, true);
  10500. }
  10501. }
  10502. }
  10503. if (packageData) {
  10504. version = packageData.version || currentVersion;
  10505. } else {
  10506. version = currentVersion;
  10507. scripts_echoLog({}).error(i18n('checkUpdateFailed'));
  10508. }
  10509. if (packageData && hasNewVersion(currentVersion, version)) {
  10510. scripts_echoLog({
  10511. html: `<li><font>${i18n('newVersionNotice', version, `${updateLink}dist/${GM_info.script.name}.user.js`)}</font></li>`
  10512. });
  10513. scripts_echoLog({
  10514. html: `<li>${i18n('updateText', version)}</li><ol class="update-text">${packageData.change?.map(change => `<li>${change}</li>`).join('')}<li>${i18n('updateHistory')}</li></ol>`
  10515. });
  10516. }
  10517. } catch (error) {
  10518. throwError(error, 'updateChecker');
  10519. }
  10520. };
  10521. const scripts_updateChecker = updateChecker;
  10522. window.STYLE = GM_addStyle(auto_task.Z + GM_getResourceText('style'));
  10523. window.DEBUG = !!globalOptions.other.debug;
  10524. window.TRACE = !!globalOptions.other.debug && typeof console.trace === 'function';
  10525. const loadScript = async () => {
  10526. if (window.location.hostname === 'www.twitch.tv' && window.location.hash === '#auth') {
  10527. const authToken = external_Cookies_namespaceObject.get('auth-token');
  10528. const isLogin = !!external_Cookies_namespaceObject.get('login');
  10529. if (isLogin) {
  10530. GM_setValue('twitchAuth', {
  10531. authToken: authToken,
  10532. clientVersion: __twilightBuildID,
  10533. clientId: commonOptions?.headers?.['Client-ID'],
  10534. deviceId: commonOptions?.headers?.['Device-ID'],
  10535. clientSessionId: window.localStorage.local_storage_app_session_id.replace(/"/g, '')
  10536. });
  10537. window.close();
  10538. external_Swal_default().fire('', i18n('closePageNotice'));
  10539. } else {
  10540. external_Swal_default().fire('', i18n('needLogin'));
  10541. }
  10542. return;
  10543. }
  10544. if (window.location.hostname === 'twitter.com' && window.location.hash === '#auth') {
  10545. const ct0 = external_Cookies_namespaceObject.get('ct0');
  10546. const isLogin = !!external_Cookies_namespaceObject.get('twid');
  10547. if (isLogin && ct0) {
  10548. GM_setValue('twitterAuth', {
  10549. ct0: ct0
  10550. });
  10551. window.close();
  10552. external_Swal_default().fire('', i18n('closePageNotice'));
  10553. } else {
  10554. external_Swal_default().fire('', i18n('needLogin'));
  10555. }
  10556. return;
  10557. }
  10558. if (window.location.hostname === 'www.youtube.com' && window.location.hash === '#auth') {
  10559. const PAPISID = external_Cookies_namespaceObject.get('__Secure-3PAPISID');
  10560. if (PAPISID) {
  10561. GM_setValue('youtubeAuth', {
  10562. PAPISID: PAPISID
  10563. });
  10564. window.close();
  10565. external_Swal_default().fire('', i18n('closePageNotice'));
  10566. } else {
  10567. external_Swal_default().fire('', i18n('needLogin'));
  10568. }
  10569. return;
  10570. }
  10571. if (window.location.hostname === 'www.reddit.com' && (window.location.hash === '#auth' || GM_getValue('redditAuth') === '#auth')) {
  10572. const betaButton = $('#redesign-beta-optin-btn');
  10573. if (betaButton.length > 0) {
  10574. GM_setValue('redditAuth', '#auth');
  10575. return betaButton[0].click();
  10576. }
  10577. GM_setValue('redditAuth', null);
  10578. window.close();
  10579. external_Swal_default().fire('', i18n('closePageNotice'));
  10580. return;
  10581. }
  10582. let website;
  10583. for (const Website of Websites) {
  10584. if (Website.test()) {
  10585. website = new Website();
  10586. break;
  10587. }
  10588. }
  10589. if (!website) {
  10590. console.log('%c%s', 'color:#ff0000', 'Auto-Task[Warning]: 脚本停止加载,当前网站不支持!');
  10591. return;
  10592. }
  10593. if (website?.before) {
  10594. await website?.before();
  10595. }
  10596. $('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>`);
  10597. $('div.show-button-div').on('click', () => {
  10598. $('#auto-task-buttons').show();
  10599. $('div.show-button-div').hide();
  10600. });
  10601. const toggleLog = () => {
  10602. const $this = $('#toggle-log');
  10603. const status = $this.attr('data-status');
  10604. if (status === 'show') {
  10605. $('#auto-task-info').hide();
  10606. $this.attr('data-status', 'hide').text(i18n('showLog'));
  10607. } else {
  10608. $('#auto-task-info').show();
  10609. $this.attr('data-status', 'show').text(i18n('hideLog'));
  10610. }
  10611. };
  10612. external_keyboardJS_default().bind(globalOptions.hotKey.doTaskKey, () => {
  10613. if (website.doTask) {
  10614. website.doTask();
  10615. }
  10616. });
  10617. external_keyboardJS_default().bind(globalOptions.hotKey.undoTaskKey, () => {
  10618. if (website.undoTask) {
  10619. website.doTask();
  10620. }
  10621. });
  10622. external_keyboardJS_default().bind(globalOptions.hotKey.toggleLogKey, toggleLog);
  10623. if (website?.after) {
  10624. await website?.after();
  10625. }
  10626. if (website?.buttons && $('#auto-task-buttons').children().length === 0) {
  10627. $('#auto-task-buttons').addClass(`${website.name}-buttons`);
  10628. for (const button of website.buttons) {
  10629. if (website[button]) {
  10630. const btnElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">${i18n(button)}</a></p>`);
  10631. btnElement.find('a.auto-task-website-btn').on('click', () => {
  10632. website[button]();
  10633. });
  10634. $('#auto-task-buttons').append(btnElement);
  10635. }
  10636. }
  10637. }
  10638. const hideButtonElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">
  10639. ${i18n('hideButton')}</a></p>`);
  10640. hideButtonElement.find('a.auto-task-website-btn').on('click', () => {
  10641. $('#auto-task-buttons').hide();
  10642. $('div.show-button-div').show();
  10643. });
  10644. 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'}">
  10645. ${globalOptions.other.defaultShowLog ? i18n('hideLog') : i18n('showLog')}</a></p>`);
  10646. toggleLogElement.find('a.auto-task-website-btn').on('click', toggleLog);
  10647. $('#auto-task-buttons').append(hideButtonElement).append(toggleLogElement);
  10648. if (website?.options) {
  10649. GM_registerMenuCommand(i18n('changeWebsiteOptions'), () => {
  10650. options(website.name, website.options);
  10651. });
  10652. }
  10653. if (website.name !== 'Setting') {
  10654. GM_registerMenuCommand(i18n('changeGlobalOptions'), () => {
  10655. changeGlobalOptions('swal');
  10656. });
  10657. GM_registerMenuCommand(i18n('settingPage'), () => {
  10658. window.open('https://auto-task-v4.hclonely.com/setting.html', '_blank');
  10659. });
  10660. }
  10661. console.log('%c%s', 'color:#1bbe1a', 'Auto-Task[Load]: 脚本加载完成');
  10662. if (!GM_getValue('notice')) {
  10663. external_Swal_default().fire({
  10664. title: i18n('swalNotice'),
  10665. icon: 'warning'
  10666. }).then(() => {
  10667. window.open(i18n('noticeLink'), '_blank');
  10668. GM_setValue('notice', new Date().getTime());
  10669. });
  10670. scripts_echoLog({
  10671. html: `<li><font class="warning">${i18n('echoNotice', i18n('noticeLink'))}</font></li>`
  10672. }).font?.find('a').on('click', () => {
  10673. GM_setValue('notice', new Date().getTime());
  10674. });
  10675. }
  10676. scripts_updateChecker();
  10677. };
  10678. if (window.location.hostname === 'discord.com') {
  10679. const LocalStorage = window.localStorage;
  10680. if (window.location.hash === '#auth') {
  10681. window.localStorage.removeItem = () => true;
  10682. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10683. if (discordAuth && discordAuth.length > 0) {
  10684. GM_setValue('discordAuth', {
  10685. auth: discordAuth
  10686. });
  10687. window.close();
  10688. external_Swal_default().fire('', i18n('closePageNotice'));
  10689. } else {
  10690. external_Swal_default().fire({
  10691. text: i18n('getDiscordAuthFailed'),
  10692. icon: 'error'
  10693. });
  10694. }
  10695. } else {
  10696. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10697. if (discordAuth && discordAuth.length > 0) {
  10698. GM_setValue('discordAuth', {
  10699. auth: discordAuth
  10700. });
  10701. }
  10702. }
  10703. } else if (window.location.hostname === 'opquests.com') {
  10704. loadScript();
  10705. } else {
  10706. if (window.location.hostname === 'key-hub.eu') {
  10707. unsafeWindow.keyhubtracker = 1;
  10708. unsafeWindow.gaData = {};
  10709. }
  10710. $(loadScript);
  10711. }
  10712. }();
  10713. })();