auto-task-v4

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

当前为 2024-08-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name auto-task-v4
  3. // @namespace auto-task-v4
  4. // @version 4.4.7
  5. // @description 自动完成 Freeanywhere,Giveawaysu,GiveeClub,Givekey,Gleam,Indiedb,keyhub,OpiumPulses,Opquests,SweepWidget 等网站的任务。
  6. // @description:en Automatically complete the tasks of FreeAnyWhere, GiveawaySu, GiveeClub, Givekey, Gleam, Indiedb, keyhub, OpiumPulses, Opquests, SweepWidget websites.
  7. // @author HCLonely
  8. // @license MIT
  9. // @run-at document-start
  10. // @homepage https://auto-task-doc.js.org/
  11. // @supportURL https://github.com/HCLonely/auto-task-v4/issues
  12. // @icon https://auto-task-v4.hclonely.com/favicon.ico
  13.  
  14. // @include *://freeanywhere.net/*
  15. // @include *://giveaway.su/giveaway/view/*
  16. // @include *://givee.club/*/event/*
  17. // @include *://givekey.ru/giveaway/*
  18. // @include *://www.indiedb.com/giveaways*
  19. // @include *://key-hub.eu/giveaway/*
  20. // @include *://keylol.com/*
  21. // @include *://www.opiumpulses.com/giveaways
  22. // @include *://prys.revadike.com/giveaway/?id=*
  23. // @include *://opquests.com/quests/*
  24. // @include *://gleam.io/*
  25. // @include *://sweepwidget.com/view/*
  26. // @include *://discord.com/*
  27. // @include *://www.twitch.tv/*
  28. // @include *://www.youtube.com/*
  29. // @include *://*.reddit.com/*
  30. // @include *://twitter.com/settings/account?k*
  31. // @include *://x.com/settings/account*
  32. // @include https://auto-task-v4.hclonely.com/setting.html
  33. // @include https://auto-task-v4.hclonely.com/history.html
  34.  
  35. // @grant GM_setValue
  36. // @grant GM_getValue
  37. // @grant GM_listValues
  38. // @grant GM_deleteValue
  39. // @grant GM_addStyle
  40. // @grant GM_xmlhttpRequest
  41. // @grant GM_registerMenuCommand
  42. // @grant GM_info
  43. // @grant GM_openInTab
  44. // @grant GM_setClipboard
  45. // @grant GM_getResourceText
  46. // @grant GM_cookie
  47. // @grant GM_addValueChangeListener
  48. // @grant GM_removeValueChangeListener
  49. // @grant unsafeWindow
  50. // @grant window.close
  51. // @grant window.localStorage
  52.  
  53. // @connect cdn.jsdelivr.net
  54. // @connect store.steampowered.com
  55. // @connect steamcommunity.com
  56. // @connect login.steampowered.com
  57. // @connect twitter.com
  58. // @connect x.com
  59. // @connect api.twitter.com
  60. // @connect youtube.com
  61. // @connect www.youtube.com
  62. // @connect facebook.com
  63. // @connect instagram.com
  64. // @connect vk.com
  65. // @connect twitch.tv
  66. // @connect www.twitch.tv
  67. // @connect gql.twitch.tv
  68. // @connect github.com
  69. // @connect discordapp.com
  70. // @connect discord.gg
  71. // @connect discord.com
  72. // @connect www.reddit.com
  73. // @connect oauth.reddit.com
  74. // @connect raw.githubusercontent.com
  75. // @connect t.me
  76. // @connect bit.ly
  77. // @connect giveaway.su
  78. // @connect google.com
  79. // @connect www.vloot.io
  80. // @connect givee.club
  81. // @connect gleam.io
  82. // @connect www.indiedb.com
  83. // @connect key-hub.eu
  84. // @connect opquests.com
  85. // @connect itch.io
  86. // @connect auto-task-v4.hclonely.com
  87. // @connect *
  88. // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js
  89. // @require https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js
  90. // @require https://cdn.jsdelivr.net/npm/regenerator-runtime@0.13.5/runtime.min.js
  91. // @require https://cdn.jsdelivr.net/npm/js-sha1@0.6.0/src/sha1.min.js
  92. // @require https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js
  93. // @resource style https://cdn.jsdelivr.net/npm/sweetalert2@11.3.5/dist/sweetalert2.min.css
  94. // @require https://cdn.jsdelivr.net/npm/keyboardjs@2.6.4/dist/keyboard.min.js
  95. // @require https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js
  96.  
  97. // @noframes
  98. // ==/UserScript==
  99.  
  100. console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
  101.  
  102. (function() {
  103. var __webpack_modules__ = {
  104. 108: function(__unused_webpack_module, exports) {
  105. !function(e, n) {
  106. true ? n(exports) : 0;
  107. }(this, function(e) {
  108. 'use strict';
  109. var t = function() {
  110. return (t = Object.assign || function(e) {
  111. for (var n, o = 1, t = arguments.length; o < t; o++) {
  112. for (var r in n = arguments[o]) {
  113. Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r]);
  114. }
  115. }
  116. return e;
  117. }).apply(this, arguments);
  118. };
  119. function r(e, n, o) {
  120. if (o || 2 === arguments.length) {
  121. for (var t, r = 0, i = n.length; r < i; r++) {
  122. !t && r in n || ((t = t || Array.prototype.slice.call(n, 0, r))[r] = n[r]);
  123. }
  124. }
  125. return e.concat(t || Array.prototype.slice.call(n));
  126. }
  127. function d(e) {
  128. return '[object Object]' === n(e);
  129. }
  130. function l(e, n) {
  131. var o = r(r([], n || [], !0), [ '_' ], !1).join('|');
  132. return e.replace(new RegExp('(('.concat(o, ')[a-z])+'), 'g'), function(e, n) {
  133. return n.replace(new RegExp(o), '').toLocaleUpperCase();
  134. });
  135. }
  136. var n = function(e) {
  137. return Object.prototype.toString.call(e);
  138. };
  139. var o = (i.prototype.init = function() {
  140. try {
  141. this.getSystemName(), this.getBrowserName();
  142. } catch (e) {
  143. console.warn('[UA formatter error] '.concat(e));
  144. }
  145. }, i.prototype.getEngine = function() {
  146. var e = this.agent;
  147. return -1 !== e.indexOf('Trident') ? 'Trident' : -1 !== e.indexOf('Firefox') ? 'Gecko' : -1 !== e.indexOf('Presto') ? 'Presto' : 'WebKit';
  148. }, i.prototype.getSystemName = function() {
  149. var e, n = (this.agent.match(/^[a-z]+\/\d+\.\d+\s?\(([a-z\d\s:;./_-]+)\)/i) || [])[1];
  150. try {
  151. var o = '';
  152. if (/Windows/i.test(n)) {
  153. var t = (n.match(/NT\s(\d+\.\d+)/) || [])[1];
  154. switch (this.info.os = 'Windows', t) {
  155. case '6.3':
  156. o = '8.1';
  157. break;
  158.  
  159. case '6.2':
  160. o = '8';
  161. break;
  162.  
  163. case '6.1':
  164. o = '7';
  165. break;
  166.  
  167. case '5.2':
  168. case '5.1':
  169. o = 'XP';
  170. break;
  171.  
  172. default:
  173. o = t;
  174. }
  175. return this.info.device = 'PC', void (this.info.osVersion = o);
  176. }
  177. if (/^Macintosh/i.test(n)) {
  178. return o = (n.match(/X\s((\d+(_|\.))+\d+)/) || [])[1], this.info.os = 'Macintosh',
  179. this.info.device = 'PC', void (this.info.osVersion = null !== (e = null == o ? void 0 : o.replace(/_/g, '.')) && void 0 !== e ? e : 'Unknown');
  180. }
  181. if (/^iPad/i.test(n)) {
  182. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPad', this.info.device = 'Tablet',
  183. void (this.info.osVersion = o.replace(/_/g, '.'));
  184. }
  185. if (/^iPhone/i.test(n)) {
  186. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPhone', this.info.device = 'Mobile',
  187. void (this.info.osVersion = o.replace(/_/g, '.'));
  188. }
  189. if (-1 !== n.indexOf('Android')) {
  190. var r = (n.match(/Android\s((\d+\.?)+\d?)/) || [])[1];
  191. return this.info.device = 'Mobile', this.info.os = 'Android', void (this.info.osVersion = r);
  192. }
  193. if (/Linux\s[a-z\d_]+/.test(n)) {
  194. return this.info.os = 'Linux', void (this.info.osVersion = 'Unknown');
  195. }
  196. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  197. } catch (e) {
  198. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  199. }
  200. }, i.prototype.getBrowserName = function() {
  201. var e = Object.keys(this.browserNameMap).map(function(e) {
  202. return new RegExp(''.concat(e, '(\\/|\\s)(\\d+\\.)+\\d+'));
  203. }), n = 1 < (n = (this.agent.match(/[a-z\d]+(\/|\s)(\d+\.)+\d+/gi) || []).filter(function(n) {
  204. return -1 !== e.findIndex(function(e) {
  205. return e.test(n);
  206. });
  207. })).length && !/^Safari/.test(n[n.length - 1]) ? n.reverse() : n;
  208. this.info = t(t({}, this.info), this._formatBrowserVersion(n[0]));
  209. }, i.prototype._formatBrowserVersion = function(e) {
  210. var n, o, t, r;
  211. try {
  212. 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++) {
  213. var d = u[f], l = d[0], h = d[1];
  214. if (new RegExp(l).test(s)) {
  215. c = h;
  216. break;
  217. }
  218. }
  219. var p = {
  220. browserVersion: null != a ? a : 'Unknown',
  221. browser: null !== (t = c.en) && void 0 !== t ? t : 'Unknown',
  222. browserZH: null !== (r = (null == c ? void 0 : c.zh) || c.en) && void 0 !== r ? r : 'Unknown'
  223. };
  224. return 'Trident' === s && (p.browserVersion = {
  225. '4.0': 8,
  226. '5.0': 9,
  227. '6.0': 10,
  228. '7.0': 11
  229. }[a]), p;
  230. } catch (e) {
  231. return console.warn('[UA formatter error] '.concat(e)), {
  232. browser: 'Unknown',
  233. browserVersion: 'Unknown'
  234. };
  235. }
  236. }, i);
  237. function i(e) {
  238. this.agent = '', this.info = {
  239. browser: '',
  240. browserZH: '',
  241. browserVersion: '',
  242. os: '',
  243. osVersion: '',
  244. device: 'Unknown',
  245. engine: 'WebKit'
  246. }, this.browserNameMap = {
  247. MicroMessenger: {
  248. en: 'MicroMessenger',
  249. zh: '微信'
  250. },
  251. MetaSr: {
  252. en: 'MetaSr',
  253. zh: '搜狗浏览器'
  254. },
  255. 'QQ(Browser)?': {
  256. en: 'QQBrowser',
  257. zh: 'QQ浏览器'
  258. },
  259. UCBrowser: {
  260. en: 'UCBrowser',
  261. zh: 'UC浏览器'
  262. },
  263. '2345Explorer': {
  264. en: '2345Explorer',
  265. zh: '2345极速浏览器'
  266. },
  267. Mb2345Browser: {
  268. en: 'Mb2345Browser',
  269. zh: '2345手机浏览器'
  270. },
  271. Trident: {
  272. en: 'Internet Explorer'
  273. },
  274. 'Edge?': {
  275. en: 'Edge'
  276. },
  277. OPR: {
  278. en: 'Opera'
  279. },
  280. Vivaldi: {
  281. en: 'Vivaldi'
  282. },
  283. Firefox: {
  284. en: 'Firefox'
  285. },
  286. Chrome: {
  287. en: 'Chrome'
  288. },
  289. Safari: {
  290. en: 'Safari'
  291. }
  292. }, this.agent = e, this.init();
  293. var n = this.info, o = n.browser, e = n.browserVersion, n = n.osVersion;
  294. this.info = t(t({}, this.info), {
  295. engine: this.getEngine(),
  296. browserVersion: 'Safari' === o ? n : e
  297. });
  298. }
  299. function s() {
  300. this.cookies = {}, this.init();
  301. }
  302. var a = new (s.prototype.init = function() {
  303. var o = {};
  304. document.cookie.split(/;\s/).forEach(function(e) {
  305. var n = e.split(/=/), e = n[0], n = n[1];
  306. o[e] = n;
  307. }), this.cookies = o;
  308. }, s.prototype.getItem = function(e) {
  309. return this.cookies[e];
  310. }, s.prototype.getAllItems = function() {
  311. return this.cookies;
  312. }, s.prototype.setItem = function(e, n, o, t, r, i) {
  313. document.cookie = ''.concat(e, '=').concat(n).concat(o ? '; expires='.concat(o) : '').concat(t ? '; path='.concat(t) : '').concat(r ? '; domain='.concat(r) : '').concat(i ? '; secure' : '');
  314. }, s)();
  315. e.countDown = function e(n, o, t, r) {
  316. if (!window) {
  317. throw new Error('window is not defind.');
  318. }
  319. if (0 < n) {
  320. return r && r(), n--, window[o] = window.setTimeout(function() {
  321. e(n, o, t, r);
  322. }, 1e3), function() {
  323. return clearTimeout(window[o]);
  324. };
  325. }
  326. clearTimeout(window[o]), t && t();
  327. }, e.createRandomID = function(e) {
  328. void 0 === e && (e = 12);
  329. for (var n = [], o = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''), t = o.length, r = 0; r < e; r++) {
  330. n.push(o[Math.round(Math.random() * t)]);
  331. }
  332. return n.join('');
  333. }, e.dCookie = a, e.debounce = function(o, t, r) {
  334. var i;
  335. void 0 === t && (t = 0);
  336. var s = r = void 0 === r ? !1 : r;
  337. return function() {
  338. var e = this, n = arguments;
  339. s && (o.apply(this, arguments), s = !1), clearTimeout(i), i = setTimeout(function() {
  340. r ? s = !0 : o.apply(e, n);
  341. }, t);
  342. };
  343. }, e.deepCopy = function e(n) {
  344. if (d(n) || Array.isArray(n)) {
  345. var o, t = Array.isArray(n) ? [] : {};
  346. for (o in n) {
  347. t[o] = e(n[o]);
  348. }
  349. return t;
  350. }
  351. return n;
  352. }, e.formatQueryParams = function(e) {
  353. e = null === (e = /\?(?<params>(.*)=.+)/.exec(decodeURIComponent(e))) || void 0 === e ? void 0 : e.groups;
  354. if (!e) {
  355. return {};
  356. }
  357. for (var n = e.params.split('&'), t = {}, o = 0; o < n.length; o++) {
  358. n[o].replace(/([^?&]*)=([^?&]*)/, function(e, n, o) {
  359. return t[n] = o, e;
  360. });
  361. }
  362. return t;
  363. }, e.formatThousandth = function(e) {
  364. 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, '$&,');
  365. return ''.concat(e).concat(n ? '.'.concat(n) : '');
  366. }, e.generateTree = function e(n, o, t, r) {
  367. for (var i = [], s = 0; s < n.length; s++) {
  368. var a = n[s];
  369. a[t] === o && (i.push(a), a.children = e(n, a[null != r ? r : 'id'], t, r));
  370. }
  371. return i;
  372. }, e.isEmpty = function(e) {
  373. 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);
  374. }, e.isFunction = function(e) {
  375. return '[object Function]' === n(e);
  376. }, e.isImageUrl = function(e) {
  377. return /\.((png)|(jpe?g)|(gif)|(svg)|(webp))$/gi.test(e);
  378. }, e.isObject = d, e.isRegexp = function(e) {
  379. return '[object RegExp]' === n(e);
  380. }, e.objectKeyToCamelCase = function e(n, o, t) {
  381. if (Array.isArray(n)) {
  382. for (var r = [], i = 0; i < n.length; i++) {
  383. r[i] = e(o && n[i][o] ? n[i][o] : n[i], o, t);
  384. }
  385. } else if (d(n)) {
  386. r = {};
  387. for (var s = o && n[o] ? n[o] : n, a = 0, c = Object.entries(s); a < c.length; a++) {
  388. var f = (u = c[a])[0], u = u[1];
  389. Array.isArray(u) || d(s) ? r[l(f, t)] = e(u, o, t) : r[l(f, t)] = u;
  390. }
  391. } else {
  392. r = n;
  393. }
  394. return r;
  395. }, e.realType = n, e.searchParams = function(e, n) {
  396. return void 0 === e && (e = null === location || void 0 === location ? void 0 : location.search),
  397. new URLSearchParams(e).get(n);
  398. }, e.toLowerCamelCase = l, e.toUnderline = function(e) {
  399. return e.replace(/([A-Z])/g, function(e) {
  400. return '_'.concat(e.toLocaleLowerCase());
  401. });
  402. }, e.ua = function(e) {
  403. return void 0 === e && (e = navigator.userAgent), new o(e).info;
  404. }, Object.defineProperty(e, '__esModule', {
  405. value: !0
  406. });
  407. });
  408. },
  409. 221: function(module, __webpack_exports__, __webpack_require__) {
  410. 'use strict';
  411. __webpack_require__.d(__webpack_exports__, {
  412. Z: function() {
  413. return __WEBPACK_DEFAULT_EXPORT__;
  414. }
  415. });
  416. 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);
  417. 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__);
  418. 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);
  419. 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__);
  420. 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());
  421. ___CSS_LOADER_EXPORT___.push([ module.id, '.colorful-button,#auto-task-buttons a.auto-task-website-btn,.show-button-div a.auto-task-website-btn,body.auto-task-options .auto-task-form table button{position:relative;padding:5px 10px;text-align:center;color:#fff;text-decoration:none;background:linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);border-radius:30px;background-size:400%;text-transform:capitalize}.colorful-button:hover,#auto-task-buttons a.auto-task-website-btn:hover,.show-button-div a.auto-task-website-btn:hover,body.auto-task-options .auto-task-form table button:hover{transform:scale(1.05);box-shadow:0 6px 20px rgba(0,0,0,.3);cursor:pointer}.colorful-button:hover::before,#auto-task-buttons a.auto-task-website-btn:hover::before,.show-button-div a.auto-task-website-btn:hover::before,body.auto-task-options .auto-task-form table button:hover::before{filter:blur(10px);opacity:1}.colorful-button::before,#auto-task-buttons a.auto-task-website-btn::before,.show-button-div a.auto-task-website-btn::before,body.auto-task-options .auto-task-form table button::before{content:"";position:absolute;top:-5px;left:-5px;right:-5px;bottom:-5px;z-index:-1;background:linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);border-radius:40px;background-size:400%;opacity:-1}#auto-task-info{position:fixed;bottom:10px;right:10px;width:60%;max-width:500px;max-height:60%;overflow-y:auto;color:#000;background-color:#fff;padding-left:5px;z-index:999999999 !important;border:solid 2px #add8e6;border-radius:10px}#auto-task-info li{text-align:left}#auto-task-info li a.high-light{color:#00aeff;font-weight:bold}#auto-task-info .success{color:green}#auto-task-info .error{color:red}#auto-task-info .warning{color:blue}#auto-task-info .info{color:#ff0}#auto-task-info .update-text{color:green;border:solid 2px #8dcb69;margin:5px 10px 5px 20px;border-radius:10px;padding:5px 20px}.auto-task-keylol{display:inline-block;text-transform:capitalize;margin-left:10px;text-decoration:none !important;border:solid 1px;border-radius:5px;padding:0 2px}.auto-task-keylol[selected=selected]{background-color:blue !important;color:#fff !important}.auto-task-form table{font-family:verdana,arial,sans-serif;font-size:11px;color:#333;border-width:1px;border-color:#999;border-collapse:collapse;width:100%}.auto-task-form table thead td{border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9;font-weight:bold;background-color:#fff}.auto-task-form table tbody tr{background-color:#d4e3e5}.auto-task-form table tbody tr:hover{background-color:#ff6 !important}.auto-task-form table tbody tr th{background-color:#c3dde0;border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9;text-transform:capitalize}.auto-task-form table tbody tr td{border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9}.swal2-modal{width:70% !important;max-width:1000px !important}body.auto-task-options{padding-top:10px;text-align:center}body.auto-task-options .auto-task-form{width:80%;max-width:1000px;margin:0 auto;padding-bottom:20px}body.auto-task-options .auto-task-form table input.editOption{width:80%}body.auto-task-options .auto-task-form table #getTwitterUserId,body.auto-task-options .auto-task-form table #getYoutubeChannelId{margin-top:5px}body.auto-task-options .auto-task-form table button{z-index:1}body.auto-task-options .auto-task-form table input[type=text]{outline-style:none;border:1px solid #ccc;border-radius:3px;padding:5px 10px;font-size:14px}body.auto-task-options .auto-task-form table input[type=text]:focus{border-color:#66afe9;outline:0;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}body.auto-task-options .auto-task-form table label{position:relative;width:160px;height:80px;cursor:pointer;transform:scale(0.25);margin:-25% 0;top:-30px;display:inline-block}body.auto-task-options .auto-task-form table label input{position:relative;z-index:1;appearance:none}body.auto-task-options .auto-task-form table label input:checked~span{background:#05be05;box-shadow:0 15px 25px #05be0566}body.auto-task-options .auto-task-form table label input:checked~span i{left:84px}body.auto-task-options .auto-task-form table label input:checked~span i::before{background:#05be05;box-shadow:35px 0 0 #05be05}body.auto-task-options .auto-task-form table label input:checked~span i::after{bottom:12px;height:15px;border-bottom-left-radius:15px;border-bottom-right-radius:15px;background:#05be05}body.auto-task-options .auto-task-form table label span{position:absolute;top:0;left:0;width:100%;height:100%;background:#fe0000;border-radius:80px;transition:.5s;box-shadow:0 15px 25px #fe000066}body.auto-task-options .auto-task-form table label span i{position:absolute;top:4px;left:4px;width:72px;height:72px;background:#fff;border-radius:50%}body.auto-task-options .auto-task-form table label span i::before{content:"";position:absolute;top:22px;left:12px;width:12px;height:12px;border-radius:50%;background:#fe0000;box-shadow:35px 0 0 #fe0000;transition:.5s}body.auto-task-options .auto-task-form table label span i::after{content:"";position:absolute;bottom:15px;left:calc(50% - 15px);width:30px;height:6px;border-radius:6px;background:#fe0000;transition:.5s}body.auto-task-history{font-size:15px;font-weight:400;line-height:1.5}body.auto-task-history .container a{color:#007bff;text-decoration:none;background-color:transparent}body.auto-task-history .container .card{width:80%;max-width:800px;border-radius:10px;background:#7676761a;border-top:1px solid #ffffff80;-webkit-backdrop-filter:blur(20px);backdrop-filter:blur(20px);box-shadow:0 15px 25px #0000001a;margin:20px auto;position:relative;display:flex;flex-direction:column;word-wrap:break-word;-webkit-background-clip:border-box;background-clip:border-box;border:1px solid rgba(0,0,0,.125);border-radius:.25rem}body.auto-task-history .container .card .title{text-align:center;font-size:30px;font-weight:bold;margin:5px 0}body.auto-task-history .container .card .title a:hover{text-decoration:none;background:#93e1ff;border-radius:10px;padding:3px}body.auto-task-history .container .card ul{margin-bottom:25px}body.auto-task-history .container .card ul li{margin-bottom:5px;line-height:20px}body.auto-task-history .container .card ul a:hover{text-decoration:underline}body.auto-task-history .container .card .delete-task{right:10px;width:38px;height:35px;position:absolute;font-size:24px;cursor:pointer;border-radius:10px}body.auto-task-history .container .card .delete-task:hover{background:#fff}body.auto-task-history .container .card .time{right:5px;position:absolute;bottom:0;color:#e83e8c;font-family:\'SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace\';font-size:15px}#auto-task-buttons,.show-button-div{position:fixed;top:30px;right:15px;width:124px;z-index:999999999 !important;transform:scale(0.85)}#auto-task-buttons p,.show-button-div p{line-height:30px;height:40px;text-align:center;margin:5px !important}#auto-task-buttons a.auto-task-website-btn,.show-button-div a.auto-task-website-btn{width:105px;line-height:27px;font-size:20px;display:block}.show-button-div{width:20px}.auto-task-capitalize{text-transform:capitalize !important}.swal2-file:focus,.swal2-input:focus,.swal2-textarea:focus{box-shadow:inset 0px 0px 4px 1px rgba(100,150,200,.5) !important}.swal2-checkbox-custom{align-items:center;justify-content:center;background:#fff;color:inherit;margin:1em auto}.swal2-checkbox-custom input{flex-shrink:0;margin:0 .4em}.giveaway-actions #getKey{display:none !important}.auto-task-giveaway-status{color:#fff;border-radius:10px;padding:0 5px;margin-left:5px}.auto-task-giveaway-status.active{background-color:#5cb85c}.auto-task-giveaway-status.not-active{background-color:#d9534f}', '' ]);
  422. const __WEBPACK_DEFAULT_EXPORT__ = ___CSS_LOADER_EXPORT___.toString();
  423. },
  424. 1: function(module) {
  425. 'use strict';
  426. module.exports = function(cssWithMappingToString) {
  427. var list = [];
  428. list.toString = function toString() {
  429. return this.map(function(item) {
  430. var content = '';
  431. var needLayer = typeof item[5] !== 'undefined';
  432. if (item[4]) {
  433. content += '@supports ('.concat(item[4], ') {');
  434. }
  435. if (item[2]) {
  436. content += '@media '.concat(item[2], ' {');
  437. }
  438. if (needLayer) {
  439. content += '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {');
  440. }
  441. content += cssWithMappingToString(item);
  442. if (needLayer) {
  443. content += '}';
  444. }
  445. if (item[2]) {
  446. content += '}';
  447. }
  448. if (item[4]) {
  449. content += '}';
  450. }
  451. return content;
  452. }).join('');
  453. };
  454. list.i = function i(modules, media, dedupe, supports, layer) {
  455. if (typeof modules === 'string') {
  456. modules = [ [ null, modules, undefined ] ];
  457. }
  458. var alreadyImportedModules = {};
  459. if (dedupe) {
  460. for (var k = 0; k < this.length; k++) {
  461. var id = this[k][0];
  462. if (id != null) {
  463. alreadyImportedModules[id] = true;
  464. }
  465. }
  466. }
  467. for (var _k = 0; _k < modules.length; _k++) {
  468. var item = [].concat(modules[_k]);
  469. if (dedupe && alreadyImportedModules[item[0]]) {
  470. continue;
  471. }
  472. if (typeof layer !== 'undefined') {
  473. if (typeof item[5] === 'undefined') {
  474. item[5] = layer;
  475. } else {
  476. item[1] = '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {').concat(item[1], '}');
  477. item[5] = layer;
  478. }
  479. }
  480. if (media) {
  481. if (!item[2]) {
  482. item[2] = media;
  483. } else {
  484. item[1] = '@media '.concat(item[2], ' {').concat(item[1], '}');
  485. item[2] = media;
  486. }
  487. }
  488. if (supports) {
  489. if (!item[4]) {
  490. item[4] = ''.concat(supports);
  491. } else {
  492. item[1] = '@supports ('.concat(item[4], ') {').concat(item[1], '}');
  493. item[4] = supports;
  494. }
  495. }
  496. list.push(item);
  497. }
  498. };
  499. return list;
  500. };
  501. },
  502. 398: function(module) {
  503. 'use strict';
  504. module.exports = function(i) {
  505. return i[1];
  506. };
  507. }
  508. };
  509. var __webpack_module_cache__ = {};
  510. function __webpack_require__(moduleId) {
  511. var cachedModule = __webpack_module_cache__[moduleId];
  512. if (cachedModule !== undefined) {
  513. return cachedModule.exports;
  514. }
  515. var module = __webpack_module_cache__[moduleId] = {
  516. id: moduleId,
  517. exports: {}
  518. };
  519. __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  520. return module.exports;
  521. }
  522. !function() {
  523. __webpack_require__.n = function(module) {
  524. var getter = module && module.__esModule ? function() {
  525. return module['default'];
  526. } : function() {
  527. return module;
  528. };
  529. __webpack_require__.d(getter, {
  530. a: getter
  531. });
  532. return getter;
  533. };
  534. }();
  535. !function() {
  536. __webpack_require__.d = function(exports, definition) {
  537. for (var key in definition) {
  538. if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  539. Object.defineProperty(exports, key, {
  540. enumerable: true,
  541. get: definition[key]
  542. });
  543. }
  544. }
  545. };
  546. }();
  547. !function() {
  548. __webpack_require__.o = function(obj, prop) {
  549. return Object.prototype.hasOwnProperty.call(obj, prop);
  550. };
  551. }();
  552. var __webpack_exports__ = {};
  553. !function() {
  554. 'use strict';
  555. const external_Swal_namespaceObject = Swal;
  556. var external_Swal_default = __webpack_require__.n(external_Swal_namespaceObject);
  557. const external_Cookies_namespaceObject = Cookies;
  558. var auto_task = __webpack_require__(221);
  559. var javascript_utils_umd_min = __webpack_require__(108);
  560. const httpRequest = async (options, times = 0) => {
  561. if (window.TRACE) {
  562. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  563. }
  564. try {
  565. const result = await new Promise(resolve => {
  566. if (options.dataType) {
  567. options.responseType = options.dataType;
  568. }
  569. const requestObj = {
  570. ...{
  571. timeout: 3e4,
  572. ontimeout(data) {
  573. resolve({
  574. result: 'Error',
  575. statusText: 'Timeout',
  576. status: 601,
  577. data: data,
  578. options: options
  579. });
  580. },
  581. onabort(data) {
  582. resolve({
  583. result: 'Error',
  584. statusText: 'Aborted',
  585. status: 602,
  586. data: data,
  587. options: options
  588. });
  589. },
  590. onerror(data) {
  591. resolve({
  592. result: 'Error',
  593. statusText: 'Error',
  594. status: 603,
  595. data: data,
  596. options: options
  597. });
  598. },
  599. onload(data) {
  600. if (options.responseType === 'json' && data?.response && typeof data.response !== 'object') {
  601. try {
  602. data.response = JSON.parse(data.responseText);
  603. } catch (error) {}
  604. }
  605. resolve({
  606. result: 'Success',
  607. statusText: 'Load',
  608. status: 600,
  609. data: data,
  610. options: options
  611. });
  612. }
  613. },
  614. ...options
  615. };
  616. GM_xmlhttpRequest(requestObj);
  617. });
  618. if (window.DEBUG) {
  619. console.log('%cAuto-Task[httpRequest]:', 'color:blue', JSON.stringify(result));
  620. }
  621. if (result.status !== 600 && times < 2) {
  622. return await httpRequest(options, times + 1);
  623. }
  624. return result;
  625. } catch (error) {
  626. console.log('%cAuto-Task[httpRequest]:', 'color:red', JSON.stringify({
  627. errorMsg: error,
  628. options: options
  629. }));
  630. throwError(error, 'httpRequest');
  631. return {
  632. result: 'JsError',
  633. statusText: 'Error',
  634. status: 604,
  635. error: error,
  636. options: options
  637. };
  638. }
  639. };
  640. const tools_httpRequest = httpRequest;
  641. const echoLog = ({
  642. type,
  643. text,
  644. html,
  645. id
  646. }) => {
  647. const emptyStatus = {
  648. success: () => emptyStatus,
  649. error: () => emptyStatus,
  650. warning: () => emptyStatus,
  651. info: () => emptyStatus,
  652. view: () => emptyStatus
  653. };
  654. try {
  655. let ele;
  656. if (type) {
  657. switch (type) {
  658. case 'joiningSteamGroup':
  659. case 'leavingSteamGroup':
  660. case 'gettingSteamGroupId':
  661. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/groups/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  662. break;
  663.  
  664. case 'joiningSteamOfficialGroup':
  665. case 'leavingSteamOfficialGroup':
  666. case 'gettingSteamOfficialGroupId':
  667. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/games/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  668. break;
  669.  
  670. case 'subscribingForum':
  671. case 'unsubscribingForum':
  672. case 'gettingForumId':
  673. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/app/${text}/discussions/" target="_blank">${text}</a>]...<font></font></li>`);
  674. break;
  675.  
  676. case 'followingCurator':
  677. case 'unfollowingCurator':
  678. case 'gettingCuratorId':
  679. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/${text?.includes('/') ? text : `curator/${text}`}" target="_blank">${text}</a>]...<font></font></li>`);
  680. break;
  681.  
  682. case 'addingToWishlist':
  683. case 'removingFromWishlist':
  684. case 'followingGame':
  685. case 'unfollowingGame':
  686. case 'gettingSubid':
  687. case 'addingFreeLicense':
  688. case 'requestingPlayTestAccess':
  689. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/app/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  690. break;
  691.  
  692. case 'addingFreeLicenseSubid':
  693. ele = $(`<li>${i18n('addingFreeLicense')}[<a href="https://steamdb.info/sub/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  694. break;
  695.  
  696. case 'favoritingWorkshop':
  697. case 'unfavoritingWorkshop':
  698. case 'gettingWorkshopAppId':
  699. case 'votingUpWorkshop':
  700. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/sharedfiles/filedetails/?id=${text}" target="_blank">
  701. ${text}</a>]...<font></font></li>`);
  702. break;
  703.  
  704. case 'gettingAnnouncementParams':
  705. case 'likingAnnouncement':
  706. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/news/app/${text}/view/${id}" target="_blank">
  707. ${id}</a>]...<font></font></li>`);
  708. break;
  709.  
  710. case 'joiningDiscordServer':
  711. case 'gettingDiscordGuild':
  712. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/invite/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  713. break;
  714.  
  715. case 'leavingDiscordServer':
  716. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/channels/@me/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  717. break;
  718.  
  719. case 'updateDiscordAuth':
  720. ele = $(`<li style="color:red;">${i18n('updateDiscordAuth')}</li>`);
  721. break;
  722.  
  723. case 'followingTwitchChannel':
  724. case 'unfollowingTwitchChannel':
  725. case 'gettingTwitchChannelId':
  726. ele = $(`<li>${i18n(type)}[<a href="https://www.twitch.tv/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  727. break;
  728.  
  729. case 'gettingInsUserId':
  730. case 'followingIns':
  731. case 'unfollowingIns':
  732. ele = $(`<li>${i18n(type)}[<a href="https://www.instagram.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  733. break;
  734.  
  735. case 'gettingTwitterUserId':
  736. case 'followingTwitterUser':
  737. case 'unfollowingTwitterUser':
  738. ele = $(`<li>${i18n(type)}[<a href="https://x.com/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  739. break;
  740.  
  741. case 'retweetting':
  742. case 'unretweetting':
  743. ele = $(`<li>${i18n(type)}${text}...<font></font></li>`);
  744. break;
  745.  
  746. case 'joiningReddit':
  747. case 'leavingReddit':
  748. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/r/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  749. break;
  750.  
  751. case 'followingRedditUser':
  752. case 'unfollowingRedditUser':
  753. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/user/${text?.replace('u_', '')}" target="_blank">
  754. ${text?.replace('u_', '')}</a>]...<font></font></li>`);
  755. break;
  756.  
  757. case 'followingYtbChannel':
  758. case 'unfollowingYtbChannel':
  759. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/channel/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  760. break;
  761.  
  762. case 'likingYtbVideo':
  763. case 'unlikingYtbVideo':
  764. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/watch?v=${text}" target="_blank">${text}</a>]...<font></font></li>`);
  765. break;
  766.  
  767. case 'gettingVkId':
  768. case 'joiningVkGroup':
  769. case 'leavingVkGroup':
  770. case 'joiningVkPublic':
  771. case 'leavingVkPublic':
  772. case 'sendingVkWall':
  773. case 'deletingVkWall':
  774. ele = $(`<li>${i18n(type)}[<a href="https://vk.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  775. break;
  776.  
  777. case 'visitingLink':
  778. ele = $(`<li>${i18n('visitingLink')}[<a href="${text}" target="_blank">${text}</a>]...<font></font></li>`);
  779. break;
  780.  
  781. case 'verifyingInsAuth':
  782. case 'text':
  783. ele = $(`<li>${i18n(text)}<font></font></li>`);
  784. break;
  785.  
  786. case 'html':
  787. ele = $(text || html);
  788. break;
  789.  
  790. case 'whiteList':
  791. ele = $(`<li><font class="warning">${i18n('skipTask')}[${text}(${id})](${i18n('whiteList')})</font></li>`);
  792. break;
  793.  
  794. case 'globalOptionsSkip':
  795. ele = $(`<li>${i18n('skipTaskOption')}<font class="warning">${text}</font></li>`);
  796. break;
  797.  
  798. default:
  799. ele = $(`<li>${i18n('unKnown')}:${type}(${text})...<font></font></li>`);
  800. break;
  801. }
  802. } else if (text) {
  803. ele = $(`<li>${i18n(text)}<font></font></li>`);
  804. } else if (html) {
  805. ele = $(html);
  806. } else {
  807. ele = $('<li><font></font></li>');
  808. }
  809. ele.addClass('card-text');
  810. $('#auto-task-info').append(ele);
  811. ele[0]?.scrollIntoView();
  812. const font = ele.find('font');
  813. const status = {
  814. font: font,
  815. success(text = 'Success', html = false) {
  816. this.font?.attr('class', '').addClass('success');
  817. html ? this.font?.html(text) : this.font?.text(text);
  818. return this;
  819. },
  820. error(text = 'Error', html = false) {
  821. this.font?.attr('class', '').addClass('error');
  822. html ? this.font?.html(text) : this.font?.text(text);
  823. return this;
  824. },
  825. warning(text = 'Warning', html = false) {
  826. this.font?.attr('class', '').addClass('warning');
  827. html ? this.font?.html(text) : this.font?.text(text);
  828. return this;
  829. },
  830. info(text = 'Info', html = false) {
  831. this.font?.attr('class', '').addClass('info');
  832. html ? this.font?.html(text) : this.font?.text(text);
  833. return this;
  834. },
  835. view() {
  836. this.font?.[0].scrollIntoView();
  837. return this;
  838. }
  839. };
  840. return status;
  841. } catch (error) {
  842. throwError(error, 'echoLog');
  843. return emptyStatus;
  844. }
  845. };
  846. const scripts_echoLog = echoLog;
  847. const unique = array => {
  848. try {
  849. return [ ...new Set(array) ];
  850. } catch (error) {
  851. throwError(error, 'unique');
  852. return [];
  853. }
  854. };
  855. const delay = (time = 1e3) => new Promise(resolve => {
  856. setTimeout(() => {
  857. resolve(true);
  858. }, time);
  859. });
  860. const getRedirectLink = async link => {
  861. try {
  862. if (!link) {
  863. return null;
  864. }
  865. const redirectLinksCache = GM_getValue('redirectLinks') || {};
  866. if (redirectLinksCache[link]) {
  867. redirectLinksCache[link];
  868. }
  869. return await tools_httpRequest({
  870. url: link,
  871. method: 'GET'
  872. }).then(({
  873. data
  874. }) => {
  875. if (data?.finalUrl) {
  876. redirectLinksCache[link] = data.finalUrl;
  877. GM_setValue('redirectLinks', redirectLinksCache);
  878. return data.finalUrl;
  879. }
  880. return null;
  881. });
  882. } catch (error) {
  883. throwError(error, 'getRedirectLink');
  884. return null;
  885. }
  886. };
  887. const visitLink = async (link, options) => {
  888. try {
  889. const logStatus = scripts_echoLog({
  890. type: 'visitLink',
  891. text: link
  892. });
  893. return await tools_httpRequest({
  894. url: link,
  895. method: 'GET',
  896. ...options
  897. }).then(({
  898. result,
  899. statusText,
  900. status
  901. }) => {
  902. if (result === 'Success') {
  903. logStatus.success();
  904. return true;
  905. }
  906. logStatus.error(`${result}:${statusText}(${status})`);
  907. return false;
  908. });
  909. } catch (error) {
  910. throwError(error, 'visitLink');
  911. return false;
  912. }
  913. };
  914. const getUrlQuery = url => {
  915. try {
  916. const query = {};
  917. if (url) {
  918. if (url.includes('?')) {
  919. url.split('?')[1].replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  920. query[key] = value;
  921. return str;
  922. });
  923. }
  924. } else {
  925. window.location.search.replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  926. query[key] = value;
  927. return str;
  928. });
  929. }
  930. return query;
  931. } catch (error) {
  932. throwError(error, 'getUrlQuery');
  933. return {};
  934. }
  935. };
  936. const getUuid = () => {
  937. const uuidUrl = URL.createObjectURL(new Blob()).toString();
  938. return uuidUrl.slice(uuidUrl.lastIndexOf('/') + 1);
  939. };
  940. const stringToColour = str => {
  941. try {
  942. let hash = 0;
  943. for (let i = 0; i < str.length; i++) {
  944. hash = str.charCodeAt(i) + ((hash << 5) - hash);
  945. }
  946. let colour = '#';
  947. for (let i = 0; i < 3; i++) {
  948. const value = hash >> i * 8 & 255;
  949. colour += `00${value.toString(16)}`.slice(-2);
  950. }
  951. return colour;
  952. } catch (error) {
  953. throwError(error, 'stringToColour');
  954. return '#fff';
  955. }
  956. };
  957. const defaultGlobalOptions = {
  958. doTask: {
  959. discord: {
  960. servers: true
  961. },
  962. instagram: {
  963. users: true
  964. },
  965. twitch: {
  966. channels: true
  967. },
  968. twitter: {
  969. users: true,
  970. retweets: true
  971. },
  972. vk: {
  973. names: true
  974. },
  975. youtube: {
  976. channels: true,
  977. likes: true
  978. },
  979. reddit: {
  980. reddits: true
  981. },
  982. steam: {
  983. groups: true,
  984. officialGroups: true,
  985. wishlists: true,
  986. follows: true,
  987. forums: true,
  988. workshops: true,
  989. curators: true,
  990. workshopVotes: true,
  991. announcements: true,
  992. licenses: true,
  993. playtests: true
  994. }
  995. },
  996. undoTask: {
  997. discord: {
  998. servers: true
  999. },
  1000. instagram: {
  1001. users: true
  1002. },
  1003. twitch: {
  1004. channels: true
  1005. },
  1006. twitter: {
  1007. users: true,
  1008. retweets: true
  1009. },
  1010. vk: {
  1011. names: true
  1012. },
  1013. youtube: {
  1014. channels: true,
  1015. likes: true
  1016. },
  1017. reddit: {
  1018. reddits: true
  1019. },
  1020. steam: {
  1021. groups: true,
  1022. officialGroups: true,
  1023. wishlists: true,
  1024. follows: true,
  1025. forums: true,
  1026. workshops: true,
  1027. curators: true
  1028. }
  1029. },
  1030. ASF: {
  1031. AsfEnabled: false,
  1032. AsfIpcUrl: '',
  1033. AsfIpcPassword: '',
  1034. AsfBotname: 'asf'
  1035. },
  1036. position: {
  1037. buttonSideX: 'right',
  1038. buttonSideY: 'top',
  1039. buttonDistance: '15,30',
  1040. showButtonSideX: 'right',
  1041. showButtonSideY: 'top',
  1042. showButtonDistance: '15,30',
  1043. logSideX: 'right',
  1044. logSideY: 'bottom',
  1045. logDistance: '10,10'
  1046. },
  1047. hotKey: {
  1048. doTaskKey: 'alt + d',
  1049. undoTaskKey: 'alt + u',
  1050. toggleLogKey: 'alt + l'
  1051. },
  1052. other: {
  1053. twitterVerifyId: '783214',
  1054. youtubeVerifyChannel: 'UCrXUsMBcfTVqwAS7DKg9C0Q',
  1055. autoUpdateSource: 'jsdelivr',
  1056. language: 'zh',
  1057. checkLogin: true,
  1058. checkLeftKey: true,
  1059. defaultShowButton: true,
  1060. defaultShowLog: true,
  1061. debug: false,
  1062. receivePreview: true
  1063. }
  1064. };
  1065. const userDefinedGlobalOptions = GM_getValue('globalOptions') || {};
  1066. const assignObject = (obj1, obj2) => {
  1067. try {
  1068. const newObj = {};
  1069. for (const [ key, value ] of Object.entries(obj1)) {
  1070. if (Object.prototype.toString.call(value) === '[object Object]' && Object.prototype.toString.call(obj2[key]) === '[object Object]') {
  1071. newObj[key] = assignObject(value, obj2[key]);
  1072. } else {
  1073. newObj[key] = obj2[key] ?? value;
  1074. }
  1075. }
  1076. return newObj;
  1077. } catch (error) {
  1078. throwError(error, 'assignObject');
  1079. return defaultGlobalOptions;
  1080. }
  1081. };
  1082. const globalOptions = assignObject(defaultGlobalOptions, userDefinedGlobalOptions);
  1083. const saveData = () => {
  1084. try {
  1085. const data = {};
  1086. $('#globalOptionsForm').serializeArray().map(value => {
  1087. data[value.name] = value.value;
  1088. return value;
  1089. });
  1090. $.makeArray($('#globalOptionsForm input')).map(element => {
  1091. const name = $(element).attr('name');
  1092. const keys = name.split('.');
  1093. if (keys.length === 3) {
  1094. globalOptions[keys[0]][keys[1]][keys[2]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1095. } else if (keys.length === 2) {
  1096. globalOptions[keys[0]][keys[1]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1097. }
  1098. return element;
  1099. });
  1100. GM_setValue('globalOptions', globalOptions);
  1101. external_Swal_default().fire({
  1102. title: i18n('changeGlobalOptionsSuccess'),
  1103. icon: 'success'
  1104. });
  1105. } catch (error) {
  1106. throwError(error, 'saveData');
  1107. }
  1108. };
  1109. const changeGlobalOptions = showType => {
  1110. try {
  1111. let globalOptionsForm = `<form id="globalOptionsForm" class="auto-task-form">
  1112. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  1113. for (const [ type, data1 ] of Object.entries(globalOptions)) {
  1114. for (const [ option, data2 ] of Object.entries(data1)) {
  1115. if ([ 'other', 'position', 'hotKey', 'ASF' ].includes(type)) {
  1116. if (typeof data2 === 'boolean') {
  1117. 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>`;
  1118. } else {
  1119. 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>`;
  1120. }
  1121. } else {
  1122. for (const [ socialType, data3 ] of Object.entries(data2)) {
  1123. 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>`;
  1124. }
  1125. }
  1126. }
  1127. }
  1128. globalOptionsForm += '</tbody></table></form>';
  1129. if (showType === 'swal') {
  1130. external_Swal_default().fire({
  1131. title: i18n('globalOptions'),
  1132. html: globalOptionsForm,
  1133. showConfirmButton: true,
  1134. confirmButtonText: i18n('save'),
  1135. showCancelButton: true,
  1136. cancelButtonText: i18n('close')
  1137. }).then(({
  1138. isConfirmed
  1139. }) => {
  1140. if (isConfirmed) {
  1141. saveData();
  1142. }
  1143. });
  1144. } else {
  1145. $('body').append(`<h2>${i18n('globalOptions')}</h2>${globalOptionsForm}`);
  1146. }
  1147. } catch (error) {
  1148. throwError(error, 'changeGlobalOptions');
  1149. }
  1150. };
  1151. const data = {
  1152. website: '网站',
  1153. type: '类型',
  1154. edit: '编辑',
  1155. whiteList: '白名单',
  1156. skipTask: '跳过撤销任务',
  1157. whiteListOptions: '白名单设置',
  1158. changeWhiteListOption: '设置白名单(%0)',
  1159. whiteListNotFound: '找不到此项白名单: %0',
  1160. changeWhiteListSuccess: '白名单修改成功,刷新生效!',
  1161. changeWebsiteOptions: '网站设置',
  1162. changeGlobalOptions: '全局设置',
  1163. ok: '是',
  1164. save: '保存',
  1165. close: '关闭',
  1166. return: '返回',
  1167. option: '选项',
  1168. value: '值',
  1169. websiteOptions: '当前网站设置',
  1170. changeWebsiteOptionsSuccess: '更改当前网站设置成功,刷新生效!',
  1171. changeGlobalOptionsSuccess: '更改全局设置成功,刷新生效!',
  1172. needLogin: '请先登录!',
  1173. getTasksInfo: '正在获取并处理任务信息...',
  1174. gettingKey: '正在获取Key...',
  1175. verifyingTask: '正在验证任务',
  1176. notice: '自动任务脚本提醒',
  1177. noKeysLeft: '此页面已经没有剩余key了,是否关闭?',
  1178. giveawayEnded: '此活动已结束,是否关闭?',
  1179. giveawayNotWork: '此活动因某些原因(已结束/暂停/未开始...)不可用(如果是脚本误判请及时反馈),是否关闭?',
  1180. confirm: '确定',
  1181. cancel: '取消',
  1182. unKnown: '未知',
  1183. unKnownTaskType: '未识别的任务',
  1184. doing: '正在做任务',
  1185. allTasksComplete: '所有任务已完成!',
  1186. getTaskIdFailed: '获取任务Id失败!',
  1187. initSuccess: '%0 初始化成功!',
  1188. initFailed: '%0 初始化失败!',
  1189. errorLink: '链接错误: %0',
  1190. needInit: '请先初始化',
  1191. verifyingAuth: '正在验证%0凭证...',
  1192. updatingAuth: '正在更新%0凭证...',
  1193. refreshingToken: '正在刷新%0凭证...',
  1194. settingToken: '正在设置%0凭证...',
  1195. initing: '正在初始化...',
  1196. getFailed: '获取%0失败!',
  1197. checkLoginFailed: '检测登录状态失败!',
  1198. checkLeftKeyFailed: '检测剩余Key失败!',
  1199. userId: '用户Id',
  1200. joiningGiveaway: '正在加入赠Key',
  1201. needJoinGiveaway: '需要先加入赠Key',
  1202. cannotUndo: '此网站不支持取消任务',
  1203. verifyAuth: '正在验证 %0 凭证...',
  1204. closePageNotice: '如果此页面没有自动关闭,请自行关闭本页面。',
  1205. errorReport: '检测到脚本报错,是否前往反馈BUG?',
  1206. visitingLink: '正在访问链接: ',
  1207. doTask: '做任务',
  1208. undoTask: '撤销任务',
  1209. verifyTask: '验证任务',
  1210. getKey: '获取Key',
  1211. selectAll: '全选',
  1212. selectNone: '全不选',
  1213. invertSelect: '反选',
  1214. doFreeTask: '加入免费赠品',
  1215. doPointTask: '加入点数赠品',
  1216. skipTaskOption: '设置中已配置跳过任务',
  1217. other: '其他',
  1218. globalOptions: '全局设置',
  1219. checkLogin: '登录检测</br>需要登录的网站自动登录,部分本网站支持',
  1220. checkLeftKey: '剩余Key检测</br>赠Key活动结束提示是否关闭,部分本网站支持',
  1221. twitterVerifyId: '通过尝试关注该账号验证Twitter凭证</br>默认为Twitter官方帐号 783214</br>不想关注官方账号可以改为自己的帐号',
  1222. youtubeVerifyChannel: '通过尝试订阅该频道验证YouTube凭证</br>默认为YouTube官方频道 UCrXUsMBcfTVqwAS7DKg9C0Q</br>不想关注官方频道可以改为自己的频道',
  1223. autoUpdateSource: '更新源</br>github: 需代理,实时更新</br>jsdelivr: 可不用代理,更新有延迟</br>standby: 备用</br>auto: 依次使用github, jsdelivr, standby源进行尝试更新',
  1224. saveGlobalOptions: '保存全局设置',
  1225. settingPage: '设置页面',
  1226. name: '名称',
  1227. version: '版本',
  1228. scriptManager: '脚本管理器',
  1229. script: '脚本',
  1230. environment: '环境',
  1231. os: '系统',
  1232. browser: '浏览器',
  1233. getId: '获取 %0 id',
  1234. getTwitterUserId: '获取Twitter用户id(获取id功能仅在设置页面可用)',
  1235. getYoutubeChannelId: '获取Youtube频道id(获取id功能仅在设置页面可用)',
  1236. showButton: '显示按钮',
  1237. hideButton: '隐藏按钮',
  1238. showLog: '显示日志',
  1239. hideLog: '隐藏日志',
  1240. defaultShowButton: '默认显示按钮',
  1241. defaultShowLog: '默认显示日志',
  1242. debug: '输出调试日志,不要开启此选项!',
  1243. receivePreview: '接收预览版更新',
  1244. position: '组件位置',
  1245. buttonSideX: '按钮区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1246. buttonSideY: '按钮区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1247. buttonDistance: '按钮区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1248. showButtonSideX: '显示按钮水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1249. showButtonSideY: '显示按钮垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1250. showButtonDistance: '显示按钮距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1251. logSideX: '日志区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1252. logSideY: '日志区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1253. logDistance: '日志区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1254. hotKey: '快捷键',
  1255. doTaskKey: '做任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1256. undoTaskKey: '撤销任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1257. toggleLogKey: '显示/隐藏日志快捷键</br>(实时预览功能仅在设置页面可用)',
  1258. tasksHistory: '任务历史',
  1259. clearHistory: '清空历史',
  1260. clearHistoryFinished: '已清空任务历史!',
  1261. deleteTask: '删除任务',
  1262. lastChangeTime: '最后一次修改时间',
  1263. clearTaskFinished: '删除以下任务完成!',
  1264. clearTaskFailed: '删除任务失败,没有找到任务名!',
  1265. syncData: '数据同步',
  1266. settingData: '正在上传数据...',
  1267. gettingData: '正在获取数据...',
  1268. help: '帮助',
  1269. fileName: '文件名',
  1270. upload2gist: '同步到Gist',
  1271. downloadFromGist: '从Gist同步',
  1272. saveAndTest: '保存配置并测试',
  1273. testSuccess: '测试成功!',
  1274. testFailed: '测试失败!',
  1275. saveAndTestNotice: '请先保存配置并测试!',
  1276. processingData: '正在处理数据...',
  1277. updatingData: '正在上传数据...',
  1278. syncDataSuccess: '同步数据成功!',
  1279. syncDataFailed: '同步数据失败,请在控制台查看错误信息!',
  1280. downloadingData: '正在下载数据...',
  1281. checkedNoData: '没有检测到远程数据,请确认配置是否正确!',
  1282. savingData: '正在保存数据...',
  1283. syncHistory: '同步任务历史',
  1284. checkUpdateFailed: '检测更新失败',
  1285. newVersionNotice: '检测到新版本V%0, <a class="high-light" href="%1" target="_blank">点此更新</a>',
  1286. language: '语言</br>目前仅支持zh: 中文, en: 英文',
  1287. gistOptions: 'Gist 设置',
  1288. swalNotice: '检测到您第一次安装V4版本脚本,请前往阅读用前必读内容!',
  1289. echoNotice: '检测到您第一次安装V4版本脚本,请<a class="high-light" href="%0" target="_blank">点此前往</a>阅读用前必读内容!',
  1290. noticeLink: 'https://auto-task-doc.js.org/guide/#用前必读',
  1291. toGithub: '前往Github反馈',
  1292. toKeylol: '前往其乐论坛反馈',
  1293. copySuccess: '错误信息已复制到剪切板,是否前往其乐论坛反馈?',
  1294. copyFailed: '请复制下方错误信息后前往Keylol论坛反馈!',
  1295. updateText: '%0 版本更新内容:',
  1296. Active: '进行中',
  1297. Ended: '已结束',
  1298. Banned: '已封禁',
  1299. Paused: '已暂停',
  1300. notStart: '未开始',
  1301. noRemoteData: '检测到远程无数据',
  1302. errorRemoteDataFormat: '远程数据格式错误',
  1303. updateHistory: '历史更新记录<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">点此查看</a>',
  1304. AsfEnabled: '使用ASF做Steam相关任务(需<a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a>插件)',
  1305. AsfIpcUrl: 'ASF IPC 地址',
  1306. AsfIpcPassword: 'ASF IPC 密码',
  1307. versionNotMatched: '脚本管理器版本过低,需TamperMonkey >= 5.2.0或TamperMonkey Beta >= 5.2.6196',
  1308. groups: '组',
  1309. officialGroups: '官方组',
  1310. wishlists: '愿望单',
  1311. follows: '游戏关注',
  1312. forums: '论坛',
  1313. workshops: '创意工坊收藏',
  1314. curators: '鉴赏家',
  1315. workshopVotes: '创意工坊点赞',
  1316. announcements: '社区通知',
  1317. steamCommunity: 'Steam社区',
  1318. steamStore: 'Steam商店',
  1319. licenses: '入库免费游戏',
  1320. playtests: '请求访问权限',
  1321. needLoginSteamStore: '请先<a href="https://store.steampowered.com/login/" target="_blank">登录Steam商店</a>',
  1322. needLoginSteamCommunity: '请先<a href="https://steamcommunity.com/login/home/" target="_blank">登录Steam社区</a>',
  1323. joiningSteamGroup: '正在加入Steam组',
  1324. leavingSteamGroup: '正在退出Steam组',
  1325. gettingSteamGroupId: '正在获取Steam组Id',
  1326. joiningSteamOfficialGroup: '正在加入Steam官方组',
  1327. leavingSteamOfficialGroup: '正在退出Steam官方组',
  1328. gettingSteamOfficialGroupId: '正在获取Steam官方组Id',
  1329. subscribingForum: '正在订阅Steam论坛',
  1330. unsubscribingForum: '正在取消订阅Steam论坛',
  1331. gettingForumId: '正在获取Steam论坛Id',
  1332. followingCurator: '正在关注Steam鉴赏家',
  1333. unfollowingCurator: '正在取关Steam鉴赏家',
  1334. gettingCuratorId: '正在获取Steam鉴赏家Id',
  1335. addingToWishlist: '正在添加游戏到Steam愿望单',
  1336. removingFromWishlist: '正在从Steam愿望单移除游戏',
  1337. followingGame: '正在关注Steam游戏',
  1338. unfollowingGame: '正在取关Steam游戏',
  1339. favoritingWorkshop: '正在收藏Steam创意工坊物品',
  1340. unfavoritingWorkshop: '正在取消收藏Steam创意工坊物品',
  1341. gettingWorkshopAppId: '正在获取Steam创意工坊物品Id',
  1342. votingUpWorkshop: '正在点赞Steam创意工坊物品',
  1343. gettingAnnouncementParams: '正在获取Steam通知信息',
  1344. likingAnnouncement: '正在点赞Steam通知',
  1345. changingArea: '正在更换Steam地区: %0...',
  1346. notNeededChangeArea: '当前地区不需要更换',
  1347. noAnotherArea: '请检测是否开启正确开启代理',
  1348. gettingAreaInfo: '正在获取Steam地区信息...',
  1349. changeAreaNotice: '疑似锁区游戏,尝试换区执行',
  1350. steamFinishNotice: 'Steam任务完成,尝试将购物车地区换回CN',
  1351. gettingSubid: '正在获取游戏subid',
  1352. addingFreeLicense: '正在入库',
  1353. missParams: '缺少参数',
  1354. gettingLicenses: '正在获取Licenses...',
  1355. requestingPlayTestAccess: '正在请求访问权限',
  1356. tryChangeAreaNotice: '此功能无法检测游戏是否限区,因此会尝试换区后再入库,换区失败也不影响后续入库',
  1357. gettingUserLink: '正在获取Steam用户社区链接...',
  1358. retry: '重试',
  1359. initingASF: '正在初始化ASF...',
  1360. servers: '服务器',
  1361. joiningDiscordServer: '正在加入Discord服务器',
  1362. leavingDiscordServer: '正在退出Discord服务器',
  1363. gettingDiscordGuild: '正在获取Discord服务器Id',
  1364. getDiscordAuthFailed: '获取Discord凭证失败,请检测Discord帐号是否已登录',
  1365. discordImportantNotice: '重要提醒!!!',
  1366. discordImportantNoticeText: '由于Discord网站后台更新,目前使用此脚本加组后可能会导致Discord帐号被强制退出,且需要两步验证才能正常登录,请谨慎使用!!!',
  1367. continue: '继续',
  1368. skipDiscordTask: '跳过Discord任务',
  1369. continueAndDontRemindAgain: '继续且不再提醒',
  1370. users: '用户',
  1371. loginIns: '请先<a href="https://www.instagram.com/accounts/login/" target="_blank">登录Instagram</a>',
  1372. insBanned: '您的Instagram账户已被封禁',
  1373. verifyingInsAuth: '正在验证Instagram凭证...',
  1374. gettingInsUserId: '正在获取Instagram用户Id',
  1375. followingIns: '正在关注Instagram用户',
  1376. unfollowingIns: '正在取关Instagram用户',
  1377. reddits: '社区/用户',
  1378. loginReddit: '请先<a href="https://www.reddit.com/login/" target="_blank">登录Reddit</a>',
  1379. changingRedditVersion: '正在切换Reddit为新版页面...',
  1380. joiningReddit: '正在加入Reddit社区',
  1381. leavingReddit: '正在退出Reddit社区',
  1382. followingRedditUser: '正在关注Reddit用户',
  1383. unfollowingRedditUser: '正在取关Reddit用户',
  1384. channels: '频道',
  1385. followingTwitchChannel: '正在关注Twitch频道',
  1386. unfollowingTwitchChannel: '正在取关Twitch频道',
  1387. gettingTwitchChannelId: '正在获取Twitch频道Id',
  1388. checkingTwitchIntegrity: '正在检查Twitch完整性...',
  1389. twitterUser: '推特用户',
  1390. retweets: '转推',
  1391. gettingTwitterUserId: '正在获取推特用户Id',
  1392. followingTwitterUser: '正在关注推特用户',
  1393. unfollowingTwitterUser: '正在取关推特用户',
  1394. retweetting: '正在转推',
  1395. unretweetting: '正在撤销转推',
  1396. names: '组/社区/动态',
  1397. loginVk: '请先<a href="https://vk.com/login/" target="_blank">登录Vk</a>',
  1398. gettingVkId: '正在获取Vk任务Id',
  1399. joiningVkGroup: '正在加入Vk组',
  1400. leavingVkGroup: '正在退出Vk组',
  1401. joiningVkPublic: '正在加入Vk社区',
  1402. leavingVkPublic: '正在退出Vk社区',
  1403. sendingVkWall: '正在转发Vk动态',
  1404. deletingVkWall: '正在撤销转发Vk动态',
  1405. youtubeChannel: 'YouTube频道',
  1406. likes: '点赞',
  1407. loginYtb: '请先<a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">登录YouTube</a>',
  1408. tryUpdateYtbAuth: '请尝试<a href="https://www.youtube.com/#auth" target="_blank">更新YouTube凭证</a>',
  1409. gettingYtbToken: '正在获取YouTube Token...',
  1410. followingYtbChannel: '正在订阅YouTube频道',
  1411. unfollowingYtbChannel: '正在退订YouTube频道',
  1412. likingYtbVideo: '正在点赞YouTube视频',
  1413. unlikingYtbVideo: '正在取消点赞YouTube视频',
  1414. giveKeyNoticeBefore: '每次验证间隔15s',
  1415. giveKeyNoticeAfter: '如果没有key, 请在<a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>查看',
  1416. noPoints: '点数不够,跳过抽奖',
  1417. getNeedPointsFailed: '获取所需点数失败,跳过抽奖',
  1418. joiningLottery: '正在加入抽奖',
  1419. doingGleamTask: '正在做Gleam任务...',
  1420. gettingGleamLink: '正在获取Gleam任务链接...',
  1421. gleamTaskNotice: '如果此页面长时间未关闭,请完成任一任务后自行关闭!',
  1422. verifiedGleamTasks: '已尝试验证所有任务,验证失败的任务请尝试手动验证或完成!',
  1423. campaign: '检测到人机验证,请完成验证后重新验证任务!',
  1424. gsNotice: '为避免得到"0000-0000-0000"key, 已自动屏蔽"Grab Key"按钮,获取key时请关闭脚本!',
  1425. giveeClubVerifyNotice: '正在验证任务...',
  1426. giveeClubVerifyFinished: '请等待验证完成后自行加入赠Key',
  1427. doingKeyhubTask: '正在做Keyhub任务...',
  1428. SweepWidgetNotice: '正在处理并验证任务,每次验证任务有1~3s间隔防止触发验证过快警告...',
  1429. tasksNotCompleted: '任务未完成',
  1430. confirmingTask: '正在跳过警告页面...'
  1431. };
  1432. const zh_CN = data;
  1433. const en_US_data = {
  1434. website: 'Website',
  1435. type: 'Type',
  1436. edit: 'Edit',
  1437. whiteList: 'Whitelist',
  1438. skipTask: 'Skip undo task',
  1439. whiteListOptions: 'Whitelist options',
  1440. changeWhiteListOption: 'Whitelist option(%0)',
  1441. whiteListNotFound: 'Cannot find this whitelist: %0',
  1442. changeWhiteListSuccess: 'The whitelist is successfully modified, and the page refresh will take effect!',
  1443. changeWebsiteOptions: 'Website options',
  1444. changeGlobalOptions: 'Global options',
  1445. ok: 'OK',
  1446. save: 'Save',
  1447. close: 'Close',
  1448. return: 'Return',
  1449. option: 'Option',
  1450. value: 'Value',
  1451. websiteOptions: 'Current website settings',
  1452. changeWebsiteOptionsSuccess: 'The current website setting is changed successfully, and the page refresh will take effect!',
  1453. changeGlobalOptionsSuccess: 'The global setting is changed successfully, and the refresh will take effect!',
  1454. needLogin: 'Please log in first!',
  1455. getTasksInfo: 'Obtaining and processing task information...',
  1456. gettingKey: 'Getting Key...',
  1457. verifyingTask: 'Verifying task',
  1458. notice: 'Automatic task script notice',
  1459. noKeysLeft: 'There are no more keys left on this page. Do you want to close it?',
  1460. giveawayEnded: 'This event has ended, do you want to close it?',
  1461. 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?',
  1462. confirm: 'Confirm',
  1463. cancel: 'Cancel',
  1464. unKnown: 'Unknown',
  1465. unKnownTaskType: 'Unrecognized task',
  1466. doing: 'Doing a task',
  1467. allTasksComplete: 'All tasks have been completed!',
  1468. getTaskIdFailed: 'Failed to obtain task Id!',
  1469. initSuccess: '%0 was initialized successfully!',
  1470. initFailed: '%0 initialization failed!',
  1471. errorLink: 'Link error: %0',
  1472. needInit: 'Please initialize first',
  1473. verifyingAuth: 'Verifying %0 token...',
  1474. updatingAuth: 'Update %0 token...',
  1475. initing: 'Initializing...',
  1476. getFailed: 'Failed to get %0!',
  1477. checkLoginFailed: 'Failed to detect login status!',
  1478. checkLeftKeyFailed: 'Failed to detect the remaining keys!',
  1479. userId: 'User Id',
  1480. joiningGiveaway: 'Joining giveaway',
  1481. needJoinGiveaway: 'Need to join the giveaway first',
  1482. cannotUndo: 'This website does not support canceling tasks',
  1483. verifyAuth: 'Verifying %0 token...',
  1484. closePageNotice: 'f this page does not close automatically, please close this page yourself.',
  1485. errorReport: 'A script error is detected, do you want to report the BUG?',
  1486. visitingLink: 'Visiting link: ',
  1487. doTask: 'DoTask',
  1488. undoTask: 'UndoTask',
  1489. verifyTask: 'Verify',
  1490. getKey: 'GetKey',
  1491. selectAll: 'SelectAll',
  1492. selectNone: 'SelectNone',
  1493. invertSelect: 'InvertSelect',
  1494. doFreeTask: 'FreeTask',
  1495. doPointTask: 'PointTask',
  1496. skipTaskOption: 'Skip task has been configured in the settings',
  1497. other: 'Other',
  1498. globalOptions: 'Global Options',
  1499. checkLogin: 'Login detection</br>Need to log in to the website automatically log in, part of this website supports.',
  1500. checkLeftKey: 'Key remaining detection</br>The end of the giveaway event prompts whether to close or not, part of this website supports.',
  1501. 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.',
  1502. 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.',
  1503. 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.',
  1504. saveGlobalOptions: 'SaveSettings',
  1505. settingPage: 'Setting Page',
  1506. name: 'Name',
  1507. version: 'Version',
  1508. scriptManager: 'Script Manager',
  1509. script: 'Script',
  1510. environment: 'Environment',
  1511. os: 'OS',
  1512. browser: 'Browser',
  1513. getId: 'Get %0 id',
  1514. getTwitterUserId: 'Get Twitter user id (Get id function is only available on the settings page).',
  1515. getYoutubeChannelId: 'Get Youtube channel id (Get id function is only available on the settings page).',
  1516. showButton: 'ShowButton',
  1517. hideButton: 'HideButton',
  1518. showLog: 'ShowLog',
  1519. hideLog: 'HideLog',
  1520. defaultShowButton: 'Default display button',
  1521. defaultShowLog: 'Display log by default',
  1522. debug: 'Output debug log, do not enable this option!',
  1523. receivePreview: 'Receive preview updates',
  1524. position: 'Component position',
  1525. buttonSideX: 'Horizontal positioning of the button area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1526. 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',
  1527. 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',
  1528. showButtonSideX: 'ShowButton horizontal positioning (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1529. showButtonSideY: 'ShowButton vertical positioning (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1530. 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',
  1531. logSideX: 'Horizontal positioning of the log area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1532. logSideY: 'Vertical positioning of the log area (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1533. 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',
  1534. hotKey: 'Shortcut key',
  1535. doTaskKey: 'DoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1536. undoTaskKey: 'UndoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1537. toggleLogKey: 'ShowLog/HideLog shortcut keys</br> (real-time preview function is only available on the settings page).',
  1538. tasksHistory: 'TasksHistory',
  1539. clearHistory: 'Clear history',
  1540. clearHistoryFinished: 'The mission history has been cleared!',
  1541. deleteTask: 'Delete task',
  1542. lastChangeTime: 'Last Change Time',
  1543. clearTaskFinished: 'Delete the following tasks completed!',
  1544. clearTaskFailed: 'Failed to delete the task, the task name was not found!',
  1545. syncData: 'DataSync',
  1546. settingData: 'Uploading data...',
  1547. gettingData: 'Getting data...',
  1548. help: 'Help',
  1549. fileName: 'Filename',
  1550. upload2gist: 'Sync to Gist',
  1551. downloadFromGist: 'Sync from Gist',
  1552. saveAndTest: 'Save configuration and test',
  1553. testSuccess: 'Test success!',
  1554. testFailed: 'Test failed!',
  1555. saveAndTestNotice: 'Please save the configuration and test first!',
  1556. processingData: 'Processing data...',
  1557. updatingData: 'Uploading data...',
  1558. syncDataSuccess: 'Synchronized data successfully!',
  1559. syncDataFailed: 'Failed to synchronize data, please check the error message on the console!',
  1560. downloadingData: 'Downloading data...',
  1561. checkedNoData: 'No remote data is detected, please confirm whether the configuration is correct!',
  1562. savingData: 'Saving data...',
  1563. syncHistory: 'Synchronize tasks history',
  1564. checkUpdateFailed: 'Check update failed',
  1565. newVersionNotice: 'Checked a new version V%0, <a class="high-light" href="%1" target="_blank">click to update</a>',
  1566. language: 'Language</br> Currently only supports zh: Chinese, en: English',
  1567. gistOptions: 'Gist Settings',
  1568. 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!',
  1569. 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!',
  1570. noticeLink: 'https://auto-task-doc.js.org/en/guide/#read-me-first',
  1571. toGithub: 'Feedback(Github)',
  1572. toKeylol: 'Feedback(Keylol)',
  1573. copySuccess: 'The error message has been copied to the clipboard. Do you want to go to the Keylol forum to give feedback?',
  1574. copyFailed: 'Please copy the error information below and report back to the Keylol forum!',
  1575. updateText: 'Updates in version %0:',
  1576. Active: 'Active',
  1577. Ended: 'Ended',
  1578. Banned: 'Banned',
  1579. Paused: 'Paused',
  1580. notStart: 'notStart',
  1581. noRemoteData: 'No data remotely',
  1582. errorRemoteDataFormat: 'Remote data has wrong format',
  1583. updateHistory: '<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">Click here</a>' + ' to view the historical update record.',
  1584. AsfEnabled: 'Use ASF to do Steam related tasks (requires <a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a> plugin)',
  1585. AsfIpcUrl: 'ASF IPC URL',
  1586. AsfIpcPassword: 'ASF IPC Password',
  1587. groups: 'Group',
  1588. officialGroups: 'Official Group',
  1589. wishlists: 'Wishlist',
  1590. follows: 'Follow Game',
  1591. forums: 'Forum',
  1592. workshops: 'Favorite Workshop',
  1593. curators: 'Curator',
  1594. workshopVotes: 'Voteup Workshop',
  1595. announcements: 'Announcement',
  1596. steamCommunity: 'Steam Community',
  1597. steamStore: 'Steam Store',
  1598. licenses: 'Add License',
  1599. playtests: 'Playtest Access',
  1600. needLoginSteamStore: 'Please <a href="https://store.steampowered.com/login/" target="_blank">log in to the Steam Store</a>',
  1601. needLoginSteamCommunity: 'Please <a href="https://steamcommunity.com/login/home/" target="_blank">log in to the Steam Community</a>',
  1602. joiningSteamGroup: 'Joining Steam Group',
  1603. leavingSteamGroup: 'Leaving Steam Group',
  1604. gettingSteamGroupId: 'Getting Steam Group Id',
  1605. joiningSteamOfficialGroup: 'Joining Steam Official Group',
  1606. leavingSteamOfficialGroup: 'Leaving Steam Official Group',
  1607. gettingSteamOfficialGroupId: 'Getting Steam Official Group Id',
  1608. subscribingForum: 'Subscribing the Steam Forum',
  1609. unsubscribingForum: 'Unsubscribing the Steam Forum',
  1610. gettingForumId: 'Getting Steam Forum Id',
  1611. followingCurator: 'Following Steam Curator',
  1612. unfollowingCurator: 'Unfollowing Steam Curator',
  1613. gettingCuratorId: 'Getting Steam Curator Id',
  1614. addingToWishlist: 'Adding the game to the Steam wishlist',
  1615. removingFromWishlist: 'Removing the game from the Steam wishlist',
  1616. followingGame: 'Following Steam games',
  1617. unfollowingGame: 'Unfollowing Steam games',
  1618. favoritingWorkshop: 'Favouring Steam Workshop Items',
  1619. unfavoritingWorkshop: 'Unfavoriting Steam Workshop Items',
  1620. gettingWorkshopAppId: 'Getting Steam Workshop Item Id',
  1621. votingUpWorkshop: 'Liking Steam workshop items',
  1622. gettingAnnouncementParams: 'Getting Steam announcement information',
  1623. likingAnnouncement: 'Liking Steam announcement',
  1624. changingArea: 'Changing Steam area: %0...',
  1625. notNeededChangeArea: 'The current area does not need to be changed',
  1626. noAnotherArea: 'Please check whether the proxy is turned on correctly',
  1627. gettingAreaInfo: 'Getting Steam area information...',
  1628. changeAreaNotice: 'Suspected of a locked zone game, try to change the zone to execute',
  1629. steamFinishNotice: 'Steam task completed, try to change the shopping cart area back to CN',
  1630. gettingSubid: 'Getting subid',
  1631. addingFreeLicense: 'Adding free license',
  1632. missParams: 'Missing parameters',
  1633. gettingLicenses: 'Getting licenses...',
  1634. requestingPlayTestAccess: 'Requesting play test access',
  1635. 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.',
  1636. versionNotMatched: 'The script manager version is too low, requiring TamperMonkey >= 5.2.0 or TamperMonkey Beta >= 5.2.6196',
  1637. gettingUserLink: 'Getting steam user community link...',
  1638. retry: 'Retry',
  1639. initingASF: 'Initing ASF...',
  1640. servers: 'Server',
  1641. joiningDiscordServer: 'Joining Discord Server',
  1642. leavingDiscordServer: 'Leaving Discord Server',
  1643. gettingDiscordGuild: 'Getting Discord server Id',
  1644. getDiscordAuthFailed: 'Failed to get Discord token, please check whether the Discord account is logged in',
  1645. discordImportantNotice: 'Important Reminder! ! !',
  1646. 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! ! !',
  1647. continue: 'Continue',
  1648. skipDiscordTask: 'Skip',
  1649. continueAndDontRemindAgain: 'Continue without Reminders',
  1650. users: 'User',
  1651. loginIns: 'Please <a href="https://www.instagram.com/accounts/login/" target="_blank">log in to Instagram</a>',
  1652. insBanned: 'Your Instagram account has been banned',
  1653. verifyingInsAuth: 'Verifying Instagram token...',
  1654. gettingInsUserId: 'Getting Instagram user Id',
  1655. followingIns: 'Following Instagram user',
  1656. unfollowingIns: 'Unfollowing Instagram user',
  1657. reddits: 'Reddit/User',
  1658. loginReddit: 'Please <a href="https://www.reddit.com/login/" target="_blank">log in to Reddit</a>',
  1659. changingRedditVersion: 'Switching Reddit to a new version page...',
  1660. joiningReddit: 'Joining the Reddit',
  1661. leavingReddit: 'Leaving the Reddit',
  1662. followingRedditUser: 'Following Reddit User',
  1663. unfollowingRedditUser: 'Unfollowing Reddit User',
  1664. channels: 'Channel',
  1665. followingTwitchChannel: 'Following Twitch Channel',
  1666. unfollowingTwitchChannel: 'Unfollowing Twitch Channel',
  1667. gettingTwitchChannelId: 'Getting Twitch Channel Id',
  1668. checkingTwitchIntegrity: 'Checking Twitch integrity...',
  1669. twitterUser: 'Twitter User',
  1670. retweets: 'Retweet',
  1671. gettingTwitterUserId: 'Getting Twitter User Id',
  1672. followingTwitterUser: 'Following Twitter User',
  1673. unfollowingTwitterUser: 'Unfollowing Twitter User',
  1674. retweetting: 'Retweetting',
  1675. unretweetting: 'Unretweetting',
  1676. names: 'Group/Public/Wall',
  1677. loginVk: 'Please <a href="https://vk.com/login/" target="_blank">log in to Vk</a>',
  1678. gettingVkId: 'Getting Vk task Id',
  1679. joiningVkGroup: 'Joining Vk Group',
  1680. leavingVkGroup: 'Leaving Vk Group',
  1681. joiningVkPublic: 'Joining Vk Public',
  1682. leavingVkPublic: 'Leaving Vk Public',
  1683. sendingVkWall: 'Sending Vk Wall',
  1684. deletingVkWall: 'Deleting Vk Wall',
  1685. youtubeChannel: 'YouTube Channel',
  1686. likes: 'Like',
  1687. loginYtb: 'Please <a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">log in to YouTube</a>',
  1688. tryUpdateYtbAuth: 'Please try to <a href="https://www.youtube.com/#auth" target="_blank">update YouTube token</a>',
  1689. gettingYtbToken: 'Getting YouTube Token...',
  1690. followingYtbChannel: 'Subscribing to YouTube channel',
  1691. unfollowingYtbChannel: 'Unsubscribing to YouTube channel',
  1692. likingYtbVideo: 'Liking YouTube video',
  1693. unlikingYtbVideo: 'Unliking YouTube video',
  1694. giveKeyNoticeBefore: 'Each verification interval is 15s',
  1695. giveKeyNoticeAfter: 'If there is no key, please check at <a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>',
  1696. noPoints: 'Not enough points, skip the lottery',
  1697. getNeedPointsFailed: 'ailed to obtain the required points, skip the lottery',
  1698. joiningLottery: 'Joining the lottery',
  1699. doingGleamTask: 'Doing Gleam Task...',
  1700. gettingGleamLink: 'Getting Gleam task link...',
  1701. gleamTaskNotice: 'If this page has not been closed for a long time, please close it yourself after completing any task!',
  1702. verifiedGleamTasks: 'Attempted to verify all tasks. If the verification fails, please try to verify manually or complete it!',
  1703. campaign: 'ReCAPTCHA detected, please complete it and re-verify the tasks!',
  1704. 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!',
  1705. giveeClubVerifyNotice: 'Verifying task...',
  1706. giveeClubVerifyFinished: 'Wait for the verification to complete and join it by yourself',
  1707. doingKeyhubTask: 'Doing Keyhub Task...',
  1708. 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...',
  1709. tasksNotCompleted: 'Tasks Not Completed',
  1710. confirmingTask: 'Confirming task...'
  1711. };
  1712. const en_US = en_US_data;
  1713. const languages = {
  1714. zh: zh_CN,
  1715. en: en_US
  1716. };
  1717. const language = [ 'zh', 'en' ].includes(globalOptions.other.language) ? globalOptions.other.language : 'en';
  1718. const I18n = (key, ...argvs) => {
  1719. if (!languages[language]?.[key]) {
  1720. return key;
  1721. }
  1722. return languages[language][key].replace(/%([\d]+)/g, (match, index) => argvs[parseInt(index, 10)]);
  1723. };
  1724. const i18n = I18n;
  1725. function throwError(error, name) {
  1726. if (window.TRACE) {
  1727. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  1728. }
  1729. external_Swal_default().fire({
  1730. title: i18n('errorReport'),
  1731. icon: 'error',
  1732. showCancelButton: true,
  1733. confirmButtonText: i18n('toGithub'),
  1734. showDenyButton: true,
  1735. denyButtonText: i18n('toKeylol'),
  1736. cancelButtonText: i18n('close')
  1737. }).then(({
  1738. isDenied,
  1739. isConfirmed
  1740. }) => {
  1741. if (isConfirmed) {
  1742. 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,
  1743. 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');
  1744. } else if (isDenied) {
  1745. const text = `错误链接: [url=${window.location.href}]${window.location.href}[/url]
  1746.  
  1747. 环境:
  1748.  
  1749. [code]${JSON.stringify((0, javascript_utils_umd_min.ua)(), null, 4)}[/code]
  1750.  
  1751. 脚本管理器: ${GM_info.scriptHandler} ${GM_info.version}
  1752. 脚本版本: ${GM_info.script.version}
  1753.  
  1754. 报错信息:
  1755. [code]${error.stack}[/code]
  1756.  
  1757. 执行日志:
  1758. [code]${$.makeArray($('#auto-task-info>li')).map(element => element.innerText).join('\n')}[/code]`;
  1759. GM_setClipboard(text);
  1760. external_Swal_default().fire({
  1761. title: i18n('copySuccess'),
  1762. icon: 'success',
  1763. confirmButtonText: i18n('ok')
  1764. }).then(() => {
  1765. window.open('https://keylol.com/forum.php?mod=post&action=reply&fid=319&tid=777450', '_blank');
  1766. });
  1767. }
  1768. });
  1769. console.log('%c%s', 'color:white;background:red', `Auto-Task[Error]: ${name}\n${error.stack}`);
  1770. }
  1771. class Social {
  1772. tasks;
  1773. getRealParams(name, links, doTask, link2param) {
  1774. try {
  1775. let realParams = [];
  1776. if (links.length > 0) {
  1777. realParams = [ ...realParams, ...links.map(link => link2param(link)).filter(link => link) ];
  1778. }
  1779. if (!doTask && this.tasks[name].length > 0) {
  1780. realParams = [ ...realParams, ...this.tasks[name] ];
  1781. }
  1782. return unique(realParams);
  1783. } catch (error) {
  1784. throwError(error, 'Social.getRealParams');
  1785. return [];
  1786. }
  1787. }
  1788. }
  1789. const social_Social = Social;
  1790. class Discord extends social_Social {
  1791. tasks;
  1792. whiteList;
  1793. #auth = GM_getValue('discordAuth') || {};
  1794. #cache = GM_getValue('discordCache') || {};
  1795. #initialized = false;
  1796. constructor() {
  1797. super();
  1798. const defaultTasksTemplate = {
  1799. servers: []
  1800. };
  1801. this.tasks = defaultTasksTemplate;
  1802. this.whiteList = {
  1803. ...defaultTasksTemplate,
  1804. ...GM_getValue('whiteList')?.discord || {}
  1805. };
  1806. }
  1807. async init(action) {
  1808. try {
  1809. if (!GM_getValue('dontRemindDiscordAgain')) {
  1810. const result = await external_Swal_default().fire({
  1811. title: i18n('discordImportantNotice'),
  1812. text: i18n('discordImportantNoticeText'),
  1813. showCancelButton: true,
  1814. showDenyButton: true,
  1815. confirmButtonText: i18n('continue'),
  1816. cancelButtonText: i18n('skipDiscordTask'),
  1817. denyButtonText: i18n('continueAndDontRemindAgain')
  1818. }).then(({
  1819. isConfirmed,
  1820. isDenied
  1821. }) => {
  1822. if (isConfirmed) {
  1823. return true;
  1824. }
  1825. if (isDenied) {
  1826. GM_setValue('dontRemindDiscordAgain', true);
  1827. return true;
  1828. }
  1829. return false;
  1830. });
  1831. if (!result) {
  1832. this.#initialized = false;
  1833. return 'skip';
  1834. }
  1835. }
  1836. if (GM_getValue('dontRemindDiscordAgain') || action === 'do' && !globalOptions.doTask.discord.servers || action === 'undo' && !globalOptions.undoTask.discord.servers) {
  1837. this.#initialized = false;
  1838. return 'skip';
  1839. }
  1840. if (this.#initialized) {
  1841. return true;
  1842. }
  1843. if (!this.#auth.auth) {
  1844. if (await this.#updateAuth()) {
  1845. this.#initialized = true;
  1846. return true;
  1847. }
  1848. return false;
  1849. }
  1850. const isVerified = await this.#verifyAuth();
  1851. if (isVerified) {
  1852. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1853. this.#initialized = true;
  1854. return true;
  1855. }
  1856. GM_setValue('discordAuth', {
  1857. auth: null
  1858. });
  1859. if (await this.#updateAuth()) {
  1860. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1861. this.#initialized = true;
  1862. return true;
  1863. }
  1864. scripts_echoLog({}).error(i18n('initFailed', 'Discord'));
  1865. return false;
  1866. } catch (error) {
  1867. throwError(error, 'Discord.init');
  1868. return false;
  1869. }
  1870. }
  1871. async #verifyAuth() {
  1872. try {
  1873. const logStatus = scripts_echoLog({
  1874. text: i18n('verifyingAuth', 'Discord')
  1875. });
  1876. const {
  1877. result,
  1878. statusText,
  1879. status,
  1880. data
  1881. } = await tools_httpRequest({
  1882. url: 'https://discord.com/api/v6/users/@me',
  1883. method: 'HEAD',
  1884. headers: {
  1885. authorization: this.#auth.auth
  1886. }
  1887. });
  1888. if (result === 'Success') {
  1889. if (data?.status === 200) {
  1890. logStatus.success();
  1891. return true;
  1892. }
  1893. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  1894. return false;
  1895. }
  1896. logStatus.error(`${result}:${statusText}(${status})`);
  1897. return false;
  1898. } catch (error) {
  1899. throwError(error, 'Discord.verifyAuth');
  1900. return false;
  1901. }
  1902. }
  1903. async #updateAuth() {
  1904. try {
  1905. const logStatus = scripts_echoLog({
  1906. text: i18n('updatingAuth', 'Discord')
  1907. });
  1908. return await new Promise(resolve => {
  1909. const newTab = GM_openInTab('https://discord.com/channels/@me#auth', {
  1910. active: true,
  1911. insert: true,
  1912. setParent: true
  1913. });
  1914. newTab.onclose = async () => {
  1915. const auth = GM_getValue('discordAuth')?.auth;
  1916. if (auth) {
  1917. this.#auth = {
  1918. auth: auth
  1919. };
  1920. logStatus.success();
  1921. resolve(await this.#verifyAuth());
  1922. } else {
  1923. logStatus.error('Error: Update discord auth failed!');
  1924. resolve(false);
  1925. }
  1926. };
  1927. });
  1928. } catch (error) {
  1929. throwError(error, 'Discord.updateAuth');
  1930. return false;
  1931. }
  1932. }
  1933. async #joinServer(inviteId) {
  1934. try {
  1935. const logStatus = scripts_echoLog({
  1936. type: 'joiningDiscordServer',
  1937. text: inviteId
  1938. });
  1939. const {
  1940. result,
  1941. statusText,
  1942. status,
  1943. data
  1944. } = await tools_httpRequest({
  1945. url: `https://discord.com/api/v9/invites/${inviteId}`,
  1946. method: 'POST',
  1947. dataType: 'json',
  1948. headers: {
  1949. authorization: this.#auth.auth,
  1950. origin: 'https://discord.com',
  1951. referer: `https://discord.com/invite/${inviteId}`
  1952. }
  1953. });
  1954. if (result === 'Success' && data?.status === 200) {
  1955. logStatus.success();
  1956. const guild = String(data.response?.guild?.id);
  1957. if (guild) {
  1958. this.#setCache(inviteId, guild);
  1959. this.tasks.servers = unique([ ...this.tasks.servers, inviteId ]);
  1960. }
  1961. return true;
  1962. }
  1963. logStatus.error(`${result}:${statusText}(${status})`);
  1964. return false;
  1965. } catch (error) {
  1966. throwError(error, 'Discord.joinServer');
  1967. return false;
  1968. }
  1969. }
  1970. async #leaveServer(inviteId) {
  1971. try {
  1972. if (this.whiteList.servers.includes(inviteId)) {
  1973. scripts_echoLog({
  1974. type: 'whiteList',
  1975. text: 'Discord.leaveServer',
  1976. id: inviteId
  1977. });
  1978. return true;
  1979. }
  1980. const guild = await this.#getGuild(inviteId);
  1981. if (!guild) {
  1982. return false;
  1983. }
  1984. const logStatus = scripts_echoLog({
  1985. type: 'leavingDiscordServer',
  1986. text: guild
  1987. });
  1988. const {
  1989. result,
  1990. statusText,
  1991. status,
  1992. data
  1993. } = await tools_httpRequest({
  1994. url: `https://discord.com/api/v9/users/@me/guilds/${guild}`,
  1995. method: 'DELETE',
  1996. headers: {
  1997. authorization: this.#auth.auth
  1998. }
  1999. });
  2000. if (result === 'Success' && data?.status === 204) {
  2001. logStatus.success();
  2002. return true;
  2003. }
  2004. logStatus.error(`${result}:${statusText}(${status})`);
  2005. return false;
  2006. } catch (error) {
  2007. throwError(error, 'Discord.leaveServer');
  2008. return false;
  2009. }
  2010. }
  2011. async #getGuild(inviteId) {
  2012. try {
  2013. const logStatus = scripts_echoLog({
  2014. type: 'gettingDiscordGuild',
  2015. text: inviteId
  2016. });
  2017. const guild = this.#cache[inviteId];
  2018. if (guild) {
  2019. logStatus.success();
  2020. return guild;
  2021. }
  2022. const {
  2023. result,
  2024. statusText,
  2025. status,
  2026. data
  2027. } = await tools_httpRequest({
  2028. url: `https://discord.com/api/v9/invites/${inviteId}`,
  2029. responseType: 'json',
  2030. method: 'GET'
  2031. });
  2032. if (result === 'Success' && data?.status === 200) {
  2033. const guild = data.response?.guild?.id;
  2034. if (guild) {
  2035. logStatus.success();
  2036. this.#setCache(inviteId, guild);
  2037. return guild;
  2038. }
  2039. logStatus.error(`${result}:${statusText}(${status})`);
  2040. return false;
  2041. }
  2042. logStatus.error(`${result}:${statusText}(${status})`);
  2043. return false;
  2044. } catch (error) {
  2045. throwError(error, 'Discord.getGuild');
  2046. return false;
  2047. }
  2048. }
  2049. async toggle({
  2050. doTask = true,
  2051. serverLinks = []
  2052. }) {
  2053. try {
  2054. if (!this.#initialized) {
  2055. scripts_echoLog({
  2056. text: i18n('needInit')
  2057. });
  2058. return false;
  2059. }
  2060. const prom = [];
  2061. if (doTask && !globalOptions.doTask.discord.servers || !doTask && !globalOptions.undoTask.discord.servers) {
  2062. scripts_echoLog({
  2063. type: 'globalOptionsSkip',
  2064. text: 'discord.servers'
  2065. });
  2066. } else {
  2067. const realServers = this.getRealParams('servers', serverLinks, doTask, link => link.match(/invite\/(.+)/)?.[1]);
  2068. if (realServers.length > 0) {
  2069. for (const server of realServers) {
  2070. if (doTask) {
  2071. prom.push(this.#joinServer(server));
  2072. } else {
  2073. prom.push(this.#leaveServer(server));
  2074. }
  2075. await delay(1e3);
  2076. }
  2077. }
  2078. }
  2079. return await Promise.all(prom).then(() => true);
  2080. } catch (error) {
  2081. throwError(error, 'Discord.toggleServers');
  2082. return false;
  2083. }
  2084. }
  2085. #setCache(inviteId, guild) {
  2086. try {
  2087. this.#cache[inviteId] = guild;
  2088. GM_setValue('discordCache', this.#cache);
  2089. } catch (error) {
  2090. throwError(error, 'Discord.setCache');
  2091. }
  2092. }
  2093. }
  2094. const social_Discord = Discord;
  2095. class Instagram extends social_Social {
  2096. tasks;
  2097. whiteList;
  2098. #cache = GM_getValue('instagramCache') || {};
  2099. #auth = {};
  2100. #initialized = false;
  2101. constructor() {
  2102. super();
  2103. const defaultTasksTemplate = {
  2104. users: []
  2105. };
  2106. this.tasks = defaultTasksTemplate;
  2107. this.whiteList = {
  2108. ...defaultTasksTemplate,
  2109. ...GM_getValue('whiteList')?.instagram || {}
  2110. };
  2111. }
  2112. async init() {
  2113. try {
  2114. if (this.#initialized) {
  2115. return true;
  2116. }
  2117. const isVerified = await this.#getUserInfo();
  2118. if (isVerified) {
  2119. scripts_echoLog({}).success(i18n('initSuccess', 'Instagram'));
  2120. this.#initialized = true;
  2121. return true;
  2122. }
  2123. scripts_echoLog({}).error(i18n('initFailed', 'Instagram'));
  2124. return false;
  2125. } catch (error) {
  2126. throwError(error, 'Instagram.init');
  2127. return false;
  2128. }
  2129. }
  2130. async #getUserInfo(name = 'instagram') {
  2131. try {
  2132. const logStatus = scripts_echoLog({
  2133. type: name === 'instagram' ? 'verifyingInsAuth' : 'gettingInsUserId',
  2134. text: name
  2135. });
  2136. const userId = this.#cache[name];
  2137. if (userId && name !== 'instagram') {
  2138. logStatus.success();
  2139. return userId;
  2140. }
  2141. const {
  2142. result,
  2143. statusText,
  2144. status,
  2145. data
  2146. } = await tools_httpRequest({
  2147. url: `https://www.instagram.com/${name}/`,
  2148. method: 'GET'
  2149. });
  2150. if (result === 'Success') {
  2151. if (data?.finalUrl.includes('accounts/login')) {
  2152. logStatus.error(`Error:${i18n('loginIns')}`, true);
  2153. return false;
  2154. } else if (data?.finalUrl.includes('www.instagram.com/challenge')) {
  2155. logStatus.error(`Error:${i18n('insBanned')}`);
  2156. return false;
  2157. }
  2158. if (data?.status === 200) {
  2159. const csrftoken = data.responseText.match(/"csrf_token":"(.+?)"/)?.[1];
  2160. const hash = data.responseText.match(/"rollout_hash":"(.+?)"/)?.[1];
  2161. if (name === 'instagram') {
  2162. if (csrftoken && hash) {
  2163. this.#auth = {
  2164. csrftoken: csrftoken,
  2165. hash: hash
  2166. };
  2167. return true;
  2168. }
  2169. return false;
  2170. }
  2171. const id = data.responseText.match(/"profilePage_([\d]+?)"/)?.[1];
  2172. if (id) {
  2173. this.#setCache(name, id);
  2174. logStatus.success();
  2175. return id;
  2176. }
  2177. logStatus.error('Error: Get ins data error!');
  2178. return false;
  2179. }
  2180. logStatus.error(`${result}:${statusText}(${status})`);
  2181. return false;
  2182. }
  2183. return false;
  2184. } catch (error) {
  2185. throwError(error, 'Instagram.getUserInfo');
  2186. return false;
  2187. }
  2188. }
  2189. async #followUser(name) {
  2190. try {
  2191. const id = await this.#getUserInfo(name);
  2192. if (!id) {
  2193. return false;
  2194. }
  2195. const logStatus = scripts_echoLog({
  2196. type: 'followingIns',
  2197. text: name
  2198. });
  2199. const {
  2200. result,
  2201. statusText,
  2202. status,
  2203. data
  2204. } = await tools_httpRequest({
  2205. url: `https://www.instagram.com/web/friendships/${id}/follow/`,
  2206. method: 'POST',
  2207. dataType: 'json',
  2208. headers: {
  2209. 'x-csrftoken': this.#auth.csrftoken,
  2210. origin: 'https://www.instagram.com',
  2211. referer: `https://www.instagram.com/${name}/`,
  2212. 'content-type': 'application/x-www-form-urlencoded',
  2213. 'sec-fetch-site': 'same-origin',
  2214. 'x-instagram-ajax': this.#auth.hash
  2215. }
  2216. });
  2217. if (result === 'Success') {
  2218. if (data?.status === 200 && data.response?.result === 'following') {
  2219. logStatus.success();
  2220. this.tasks.users = unique([ ...this.tasks.users, name ]);
  2221. return true;
  2222. }
  2223. logStatus.error(`Error:${data?.response?.feedback_message || `${data?.statusText}(${data?.status})`}`);
  2224. return false;
  2225. }
  2226. logStatus.error(`${result}:${statusText}(${status})`);
  2227. return false;
  2228. } catch (error) {
  2229. throwError(error, 'Instagram.followUser');
  2230. return false;
  2231. }
  2232. }
  2233. async #unfollowUser(name) {
  2234. try {
  2235. if (this.whiteList.users.includes(name)) {
  2236. scripts_echoLog({
  2237. type: 'whiteList',
  2238. text: 'Instagram.unfollowUser',
  2239. id: name
  2240. });
  2241. return true;
  2242. }
  2243. const id = await this.#getUserInfo(name);
  2244. if (!id) {
  2245. return false;
  2246. }
  2247. const logStatus = scripts_echoLog({
  2248. type: 'unfollowingIns',
  2249. text: name
  2250. });
  2251. const {
  2252. result,
  2253. statusText,
  2254. status,
  2255. data
  2256. } = await tools_httpRequest({
  2257. url: `https://www.instagram.com/web/friendships/${id}/unfollow/`,
  2258. method: 'POST',
  2259. dataType: 'json',
  2260. headers: {
  2261. 'x-csrftoken': this.#auth.csrftoken,
  2262. origin: 'https://www.instagram.com',
  2263. referer: `https://www.instagram.com/${name}/`,
  2264. 'content-type': 'application/x-www-form-urlencoded',
  2265. 'sec-fetch-site': 'same-origin',
  2266. 'x-instagram-ajax': this.#auth.hash
  2267. }
  2268. });
  2269. if (result === 'Success') {
  2270. if (data?.status === 200 && data.response?.status === 'ok') {
  2271. logStatus.success();
  2272. return true;
  2273. }
  2274. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2275. return false;
  2276. }
  2277. logStatus.error(`${result}:${statusText}(${status})`);
  2278. return false;
  2279. } catch (error) {
  2280. throwError(error, 'Instagram.unfollowUser');
  2281. return false;
  2282. }
  2283. }
  2284. async toggle({
  2285. doTask = true,
  2286. userLinks = []
  2287. }) {
  2288. try {
  2289. if (!this.#initialized) {
  2290. scripts_echoLog({
  2291. text: i18n('needInit')
  2292. });
  2293. return false;
  2294. }
  2295. const prom = [];
  2296. if (doTask && !globalOptions.doTask.instagram.users || !doTask && !globalOptions.undoTask.instagram.users) {
  2297. scripts_echoLog({
  2298. type: 'globalOptionsSkip',
  2299. text: 'instagram.users'
  2300. });
  2301. } else {
  2302. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1]);
  2303. if (realUsers.length > 0) {
  2304. for (const username of realUsers) {
  2305. if (doTask) {
  2306. prom.push(this.#followUser(username));
  2307. } else {
  2308. prom.push(this.#unfollowUser(username));
  2309. }
  2310. await delay(1e3);
  2311. }
  2312. }
  2313. }
  2314. return await Promise.all(prom).then(() => true);
  2315. } catch (error) {
  2316. throwError(error, 'Instagram.toggleUsers');
  2317. return false;
  2318. }
  2319. }
  2320. #setCache(name, id) {
  2321. try {
  2322. this.#cache[name] = id;
  2323. GM_setValue('instagramCache', this.#cache);
  2324. } catch (error) {
  2325. throwError(error, 'Instagram.setCache');
  2326. }
  2327. }
  2328. }
  2329. const social_Instagram = Instagram;
  2330. class Reddit extends social_Social {
  2331. tasks;
  2332. whiteList;
  2333. #auth;
  2334. #initialized = false;
  2335. constructor() {
  2336. super();
  2337. const defaultTasksTemplate = {
  2338. reddits: []
  2339. };
  2340. this.tasks = defaultTasksTemplate;
  2341. this.whiteList = {
  2342. ...defaultTasksTemplate,
  2343. ...GM_getValue('whiteList')?.reddit || {}
  2344. };
  2345. }
  2346. async init() {
  2347. try {
  2348. if (this.#initialized) {
  2349. return true;
  2350. }
  2351. const isVerified = await this.#updateAuth();
  2352. if (isVerified) {
  2353. scripts_echoLog({}).success(i18n('initSuccess', 'Reddit'));
  2354. this.#initialized = true;
  2355. return true;
  2356. }
  2357. scripts_echoLog({}).error(i18n('initFailed', 'Reddit'));
  2358. return false;
  2359. } catch (error) {
  2360. throwError(error, 'Reddit.init');
  2361. return false;
  2362. }
  2363. }
  2364. async #useBeta() {
  2365. try {
  2366. const logStatus = scripts_echoLog({
  2367. text: i18n('changingRedditVersion')
  2368. });
  2369. GM_setValue('redditAuth', null);
  2370. return await new Promise(resolve => {
  2371. const newTab = GM_openInTab('https://www.reddit.com/#auth', {
  2372. active: true,
  2373. insert: true,
  2374. setParent: true
  2375. });
  2376. newTab.onclose = async () => {
  2377. logStatus.success();
  2378. resolve(await this.#updateAuth(true));
  2379. };
  2380. });
  2381. } catch (error) {
  2382. throwError(error, 'Reddit.useBeta');
  2383. return false;
  2384. }
  2385. }
  2386. async #updateAuth(beta = false) {
  2387. try {
  2388. const logStatus = scripts_echoLog({
  2389. text: i18n('updatingAuth', 'Reddit')
  2390. });
  2391. const {
  2392. result,
  2393. statusText,
  2394. status,
  2395. data
  2396. } = await tools_httpRequest({
  2397. url: 'https://www.reddit.com/',
  2398. method: 'GET',
  2399. nochche: true,
  2400. headers: {
  2401. 'Cache-Control': 'no-cache'
  2402. }
  2403. });
  2404. if (result === 'Success') {
  2405. if (data?.responseText.includes('www.reddit.com/login/')) {
  2406. logStatus.error(`Error:${i18n('loginReddit')}`, true);
  2407. return false;
  2408. }
  2409. if (data?.status === 200) {
  2410. if (data.responseText.includes('redesign-beta-optin-btn') && !beta) {
  2411. return await this.#useBeta();
  2412. }
  2413. const accessToken = data.responseText.match(/"accessToken":"(.*?)","expires":"(.*?)"/)?.[1];
  2414. if (accessToken) {
  2415. this.#auth = {
  2416. token: accessToken
  2417. };
  2418. logStatus.success();
  2419. return true;
  2420. }
  2421. logStatus.error('Error: Parameter "accessToken" not found!');
  2422. return false;
  2423. }
  2424. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2425. return false;
  2426. }
  2427. logStatus.error(`${result}:${statusText}(${status})`);
  2428. return false;
  2429. } catch (error) {
  2430. throwError(error, 'Reddit.updateAuth');
  2431. return false;
  2432. }
  2433. }
  2434. async toggleTask({
  2435. name,
  2436. doTask = true
  2437. }) {
  2438. try {
  2439. if (!doTask && this.whiteList.reddits.includes(name)) {
  2440. scripts_echoLog({
  2441. type: 'whiteList',
  2442. text: 'Reddit.undoTask',
  2443. id: name
  2444. });
  2445. return true;
  2446. }
  2447. let type = doTask ? 'joiningReddit' : 'leavingReddit';
  2448. if (/^u_/.test(name)) {
  2449. type = doTask ? 'followingRedditUser' : 'unfollowingRedditUser';
  2450. }
  2451. const logStatus = scripts_echoLog({
  2452. type: type,
  2453. text: name
  2454. });
  2455. const {
  2456. result,
  2457. statusText,
  2458. status,
  2459. data
  2460. } = await tools_httpRequest({
  2461. url: 'https://oauth.reddit.com/api/subscribe?redditWebClient=desktop2x&app=desktop2x-client-production&raw_json=1&gilding_detail=1',
  2462. method: 'POST',
  2463. headers: {
  2464. authorization: `Bearer ${this.#auth.token}`,
  2465. 'content-type': 'application/x-www-form-urlencoded'
  2466. },
  2467. data: $.param({
  2468. action: doTask ? 'sub' : 'unsub',
  2469. sr_name: name,
  2470. api_type: 'json'
  2471. })
  2472. });
  2473. if (result === 'Success') {
  2474. if (data?.status === 200) {
  2475. logStatus.success();
  2476. if (doTask) {
  2477. this.tasks.reddits = unique([ ...this.tasks.reddits, name ]);
  2478. }
  2479. return true;
  2480. }
  2481. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2482. return false;
  2483. }
  2484. logStatus.error(`${result}:${statusText}(${status})`);
  2485. return false;
  2486. } catch (error) {
  2487. throwError(error, 'Reddit.toggleTask');
  2488. return false;
  2489. }
  2490. }
  2491. async toggle({
  2492. doTask = true,
  2493. redditLinks = []
  2494. }) {
  2495. try {
  2496. if (!this.#initialized) {
  2497. scripts_echoLog({
  2498. text: i18n('needInit')
  2499. });
  2500. return false;
  2501. }
  2502. const prom = [];
  2503. if (doTask && !globalOptions.doTask.reddit.reddits || !doTask && !globalOptions.undoTask.reddit.reddits) {
  2504. scripts_echoLog({
  2505. type: 'globalOptionsSkip',
  2506. text: 'reddit.reddits'
  2507. });
  2508. } else {
  2509. const realReddits = this.getRealParams('reddits', redditLinks, doTask, link => {
  2510. const name = link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1];
  2511. const userName = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1];
  2512. if (userName) {
  2513. return name || userName;
  2514. }
  2515. return name;
  2516. });
  2517. if (realReddits.length > 0) {
  2518. for (const name of realReddits) {
  2519. prom.push(this.toggleTask({
  2520. name: name,
  2521. doTask: doTask
  2522. }));
  2523. await delay(1e3);
  2524. }
  2525. }
  2526. }
  2527. return await Promise.all(prom).then(() => true);
  2528. } catch (error) {
  2529. throwError(error, 'Reddit.toggle');
  2530. return false;
  2531. }
  2532. }
  2533. }
  2534. const social_Reddit = Reddit;
  2535. class Twitch extends social_Social {
  2536. tasks;
  2537. whiteList;
  2538. #auth = GM_getValue('twitchAuth') || {};
  2539. #cache = GM_getValue('twitchCache') || {};
  2540. #initialized = false;
  2541. #integrityToken;
  2542. constructor() {
  2543. super();
  2544. const defaultTasksTemplate = {
  2545. channels: []
  2546. };
  2547. this.tasks = defaultTasksTemplate;
  2548. this.whiteList = {
  2549. ...defaultTasksTemplate,
  2550. ...GM_getValue('whiteList')?.twitch || {}
  2551. };
  2552. }
  2553. async init() {
  2554. try {
  2555. if (this.#initialized) {
  2556. return true;
  2557. }
  2558. if (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId) {
  2559. if (await this.#updateAuth()) {
  2560. this.#initialized = true;
  2561. return true;
  2562. }
  2563. return false;
  2564. }
  2565. const isVerified = await this.#verifyAuth(true);
  2566. if (isVerified) {
  2567. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2568. this.#initialized = true;
  2569. return true;
  2570. }
  2571. GM_setValue('twitchAuth', null);
  2572. if (await this.#updateAuth()) {
  2573. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2574. this.#initialized = true;
  2575. return true;
  2576. }
  2577. scripts_echoLog({}).error(i18n('initFailed', 'Twitch'));
  2578. return false;
  2579. } catch (error) {
  2580. throwError(error, 'Twitch.init');
  2581. return false;
  2582. }
  2583. }
  2584. async #verifyAuth(isFirst) {
  2585. try {
  2586. const logStatus = scripts_echoLog({
  2587. text: i18n('verifyingAuth', 'Twitch')
  2588. });
  2589. const {
  2590. result,
  2591. statusText,
  2592. status,
  2593. data
  2594. } = await tools_httpRequest({
  2595. url: 'https://gql.twitch.tv/gql',
  2596. method: 'POST',
  2597. dataType: 'json',
  2598. headers: {
  2599. Authorization: `OAuth ${this.#auth.authToken}`,
  2600. 'Client-Id': this.#auth.clientId
  2601. },
  2602. data: '[{"operationName":"FrontPageNew_User","variables":{"limit":1},"extensions":{"persistedQuery":{"version":1,' + '"sha256Hash":"64bd07a2cbaca80699d62636d966cf6395a5d14a1f0a14282067dcb28b13eb11"}}}]'
  2603. });
  2604. if (result === 'Success') {
  2605. if (data?.status === 200 && data.response?.[0]?.data?.currentUser) {
  2606. await this.#integrity(isFirst);
  2607. logStatus.success();
  2608. return true;
  2609. }
  2610. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2611. return false;
  2612. }
  2613. logStatus.error(`${result}:${statusText}(${status})`);
  2614. return false;
  2615. } catch (error) {
  2616. throwError(error, 'Twitch.verifyAuth');
  2617. return false;
  2618. }
  2619. }
  2620. async #integrity(isFirst = true, ct = '') {
  2621. try {
  2622. const logStatus = scripts_echoLog({
  2623. text: i18n('checkingTwitchIntegrity')
  2624. });
  2625. if (isFirst && (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId)) {
  2626. return await this.#updateAuth(false);
  2627. }
  2628. const {
  2629. result,
  2630. statusText,
  2631. status,
  2632. data
  2633. } = await tools_httpRequest({
  2634. url: 'https://gql.twitch.tv/integrity',
  2635. method: 'POST',
  2636. dataType: 'json',
  2637. anonymous: true,
  2638. headers: {
  2639. Origin: 'https://www.twitch.tv',
  2640. Referer: 'https://www.twitch.tv/',
  2641. Authorization: `OAuth ${this.#auth.authToken}`,
  2642. 'Client-Id': this.#auth.clientId,
  2643. 'Client-Version': this.#auth.clientVersion,
  2644. 'X-Device-Id': this.#auth.deviceId,
  2645. 'Client-Session-Id': this.#auth.clientSessionId,
  2646. 'x-kpsdk-ct': ct
  2647. }
  2648. });
  2649. if (result === 'Success') {
  2650. if (!ct && data?.responseHeaders?.['x-kpsdk-ct']) {
  2651. return await this.#integrity(isFirst, data.responseHeaders['x-kpsdk-ct']);
  2652. }
  2653. if (data?.status === 200 && data.response?.token) {
  2654. this.#integrityToken = data.response.token;
  2655. logStatus.success();
  2656. return true;
  2657. }
  2658. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2659. return false;
  2660. }
  2661. logStatus.error(`${result}:${statusText}(${status})`);
  2662. return false;
  2663. } catch (error) {
  2664. throwError(error, 'Twitch.integrity');
  2665. return false;
  2666. }
  2667. }
  2668. async #updateAuth(isFirst = true) {
  2669. try {
  2670. const logStatus = scripts_echoLog({
  2671. text: i18n('updatingAuth', 'Twitch')
  2672. });
  2673. return await new Promise(resolve => {
  2674. const newTab = GM_openInTab('https://www.twitch.tv/#auth', {
  2675. active: true,
  2676. insert: true,
  2677. setParent: true
  2678. });
  2679. newTab.onclose = async () => {
  2680. const auth = GM_getValue('twitchAuth');
  2681. if (auth) {
  2682. this.#auth = auth;
  2683. logStatus.success();
  2684. resolve(await this.#verifyAuth(isFirst));
  2685. } else {
  2686. logStatus.error('Error: Update twitch auth failed!');
  2687. resolve(false);
  2688. }
  2689. };
  2690. });
  2691. } catch (error) {
  2692. throwError(error, 'Twitch.updateAuth');
  2693. return false;
  2694. }
  2695. }
  2696. async #toggleChannel({
  2697. name,
  2698. doTask = true
  2699. }) {
  2700. try {
  2701. if (!doTask && this.whiteList.channels.includes(name)) {
  2702. scripts_echoLog({
  2703. type: 'whiteList',
  2704. text: 'Twitch.unfollowChannel',
  2705. id: name
  2706. });
  2707. return true;
  2708. }
  2709. const channelId = await this.#getChannelId(name);
  2710. if (!channelId) {
  2711. return false;
  2712. }
  2713. const logStatus = scripts_echoLog({
  2714. type: `${doTask ? '' : 'un'}followingTwitchChannel`,
  2715. text: name
  2716. });
  2717. const followData = `[{"operationName":"FollowButton_FollowUser","variables":{"input":{"disableNotifications":false,"targetID":"${channelId}` + '"}},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"800e7346bdf7e5278a3c1d3f21b2b56e2639928f86815677a7126b093b2fdd08"}}}]';
  2718. const unfollowData = `[{"operationName":"FollowButton_UnfollowUser","variables":{"input":{"targetID":"${channelId}"}},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"f7dae976ebf41c755ae2d758546bfd176b4eeb856656098bb40e0a672ca0d880"}}}]';
  2719. const {
  2720. result,
  2721. statusText,
  2722. status,
  2723. data
  2724. } = await tools_httpRequest({
  2725. url: 'https://gql.twitch.tv/gql',
  2726. method: 'POST',
  2727. dataType: 'json',
  2728. anonymous: true,
  2729. headers: {
  2730. Origin: 'https://www.twitch.tv',
  2731. Referer: 'https://www.twitch.tv/',
  2732. Authorization: `OAuth ${this.#auth.authToken}`,
  2733. 'Client-Id': this.#auth.clientId,
  2734. 'Client-Version': this.#auth.clientVersion,
  2735. 'X-Device-Id': this.#auth.deviceId,
  2736. 'Client-Session-Id': this.#auth.clientSessionId,
  2737. 'Client-Integrity': this.#integrityToken
  2738. },
  2739. data: doTask ? followData : unfollowData
  2740. });
  2741. if (result === 'Success') {
  2742. if (data?.status === 200 && data.response?.[0] && !data.response[0].errors) {
  2743. logStatus.success();
  2744. if (doTask) {
  2745. this.tasks.channels = unique([ ...this.tasks.channels, name ]);
  2746. }
  2747. return true;
  2748. }
  2749. logStatus.error(`Error:${data?.response?.[0].errors?.[0]?.message || `${data?.statusText}(${data?.status})`}`);
  2750. return false;
  2751. }
  2752. logStatus.error(`${result}:${statusText}(${status})`);
  2753. return false;
  2754. } catch (error) {
  2755. throwError(error, 'Twitch.toggleChannel');
  2756. return false;
  2757. }
  2758. }
  2759. async #getChannelId(name) {
  2760. try {
  2761. const logStatus = scripts_echoLog({
  2762. type: 'gettingTwitchChannelId',
  2763. text: name
  2764. });
  2765. const channelId = this.#cache[name];
  2766. if (channelId) {
  2767. logStatus.success();
  2768. return channelId;
  2769. }
  2770. const {
  2771. result,
  2772. statusText,
  2773. status,
  2774. data
  2775. } = await tools_httpRequest({
  2776. url: 'https://gql.twitch.tv/gql',
  2777. method: 'POST',
  2778. headers: {
  2779. Authorization: `OAuth ${this.#auth.authToken}`,
  2780. 'Client-Id': this.#auth.clientId
  2781. },
  2782. responseType: 'json',
  2783. data: `[{"operationName":"ActiveWatchParty","variables":{"channelLogin":"${name}"},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"4a8156c97b19e3a36e081cf6d6ddb5dbf9f9b02ae60e4d2ff26ed70aebc80a30"}}}]'
  2784. });
  2785. if (result === 'Success') {
  2786. if (data?.status === 200) {
  2787. const channelId = data.response?.[0]?.data?.user?.id;
  2788. if (channelId) {
  2789. this.#setCache(name, String(channelId));
  2790. logStatus.success();
  2791. return channelId;
  2792. }
  2793. logStatus.error(`Error:${data.statusText}(${data.status})`);
  2794. return false;
  2795. }
  2796. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2797. return false;
  2798. }
  2799. logStatus.error(`${result}:${statusText}(${status})`);
  2800. return false;
  2801. } catch (error) {
  2802. throwError(error, 'Twitch.getChannelId');
  2803. return false;
  2804. }
  2805. }
  2806. async toggle({
  2807. doTask = true,
  2808. channelLinks = []
  2809. }) {
  2810. try {
  2811. if (!this.#initialized) {
  2812. scripts_echoLog({
  2813. text: i18n('needInit')
  2814. });
  2815. return false;
  2816. }
  2817. const prom = [];
  2818. if (doTask && !globalOptions.doTask.twitch.channels || !doTask && !globalOptions.undoTask.twitch.channels) {
  2819. scripts_echoLog({
  2820. type: 'globalOptionsSkip',
  2821. text: 'twitch.channels'
  2822. });
  2823. } else {
  2824. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2]);
  2825. if (realChannels.length > 0) {
  2826. for (const channel of realChannels) {
  2827. prom.push(this.#toggleChannel({
  2828. name: channel,
  2829. doTask: doTask
  2830. }));
  2831. await delay(1e3);
  2832. }
  2833. }
  2834. }
  2835. return Promise.all(prom).then(() => true);
  2836. } catch (error) {
  2837. throwError(error, 'Twitch.toggle');
  2838. return false;
  2839. }
  2840. }
  2841. #setCache(name, id) {
  2842. try {
  2843. this.#cache[name] = id;
  2844. GM_setValue('twitchCache', this.#cache);
  2845. } catch (error) {
  2846. throwError(error, 'Twitch.setCache');
  2847. }
  2848. }
  2849. }
  2850. const social_Twitch = Twitch;
  2851. class Twitter extends social_Social {
  2852. tasks;
  2853. whiteList;
  2854. #verifyId = globalOptions.other.twitterVerifyId;
  2855. #auth = GM_getValue('twitterAuth') || {};
  2856. #cache = GM_getValue('twitterCache') || {};
  2857. #initialized = false;
  2858. constructor() {
  2859. super();
  2860. const defaultTasksTemplate = {
  2861. users: [],
  2862. retweets: [],
  2863. likes: []
  2864. };
  2865. this.tasks = defaultTasksTemplate;
  2866. this.whiteList = {
  2867. ...defaultTasksTemplate,
  2868. ...GM_getValue('whiteList')?.twitter || {}
  2869. };
  2870. }
  2871. async init() {
  2872. try {
  2873. if (this.#initialized) {
  2874. return true;
  2875. }
  2876. if (!this.#auth.ct0) {
  2877. if (await this.#updateAuth()) {
  2878. this.#initialized = true;
  2879. return true;
  2880. }
  2881. return false;
  2882. }
  2883. const isVerified = await this.#verifyAuth();
  2884. if (isVerified) {
  2885. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2886. this.#initialized = true;
  2887. return true;
  2888. }
  2889. GM_setValue('twitterAuth', null);
  2890. if (await this.#updateAuth()) {
  2891. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2892. this.#initialized = true;
  2893. return true;
  2894. }
  2895. scripts_echoLog({}).error(i18n('initFailed', 'Twitter'));
  2896. return false;
  2897. } catch (error) {
  2898. throwError(error, 'Twitter.init');
  2899. return false;
  2900. }
  2901. }
  2902. async #verifyAuth() {
  2903. try {
  2904. return await this.#toggleUser({
  2905. name: 'verify',
  2906. doTask: true,
  2907. verify: true
  2908. });
  2909. } catch (error) {
  2910. throwError(error, 'Twitter.verifyAuth');
  2911. return false;
  2912. }
  2913. }
  2914. async #updateAuth() {
  2915. try {
  2916. const logStatus = scripts_echoLog({
  2917. text: i18n('updatingAuth', 'Twitter')
  2918. });
  2919. return await new Promise(resolve => {
  2920. GM_cookie.list({
  2921. url: 'https://x.com/settings/account'
  2922. }, async (cookies, error) => {
  2923. if (!error) {
  2924. const [ ct0, isLogin ] = cookies.map(cookie => [ 'ct0', 'twid' ].includes(cookie.name) ? cookie.value : null).filter(cookie => cookie);
  2925. if (isLogin && ct0) {
  2926. GM_setValue('twitterAuth', {
  2927. ct0: ct0
  2928. });
  2929. this.#auth = {
  2930. ct0: ct0
  2931. };
  2932. logStatus.success();
  2933. resolve(await this.#verifyAuth());
  2934. } else {
  2935. logStatus.error(i18n('needLogin'));
  2936. resolve(false);
  2937. }
  2938. } else {
  2939. logStatus.error('Error: Update twitter auth failed!');
  2940. resolve(false);
  2941. }
  2942. });
  2943. });
  2944. } catch (error) {
  2945. throwError(error, 'Twitter.updateToken');
  2946. return false;
  2947. }
  2948. }
  2949. async #toggleUser({
  2950. name,
  2951. doTask = true,
  2952. verify = false
  2953. }) {
  2954. try {
  2955. if (!doTask && !verify && this.whiteList.users.includes(name)) {
  2956. scripts_echoLog({
  2957. type: 'whiteList',
  2958. text: 'Twitter.unfollowUser',
  2959. id: name
  2960. });
  2961. return true;
  2962. }
  2963. const userId = verify ? this.#verifyId : await this.userName2id(name);
  2964. if (!userId) {
  2965. return false;
  2966. }
  2967. const logStatus = verify ? scripts_echoLog({
  2968. text: i18n('verifyingAuth', 'Twitter')
  2969. }) : scripts_echoLog({
  2970. type: `${doTask ? '' : 'un'}followingTwitterUser`,
  2971. text: name
  2972. });
  2973. const {
  2974. result,
  2975. statusText,
  2976. status,
  2977. data
  2978. } = await tools_httpRequest({
  2979. url: `https://x.com/i/api/1.1/friendships/${doTask ? 'create' : 'destroy'}.json`,
  2980. method: 'POST',
  2981. headers: {
  2982. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  2983. 'Content-Type': 'application/x-www-form-urlencoded',
  2984. 'x-csrf-token': this.#auth.ct0
  2985. },
  2986. responseType: 'json',
  2987. data: $.param({
  2988. include_profile_interstitial_type: 1,
  2989. include_blocking: 1,
  2990. include_blocked_by: 1,
  2991. include_followed_by: 1,
  2992. include_want_retweets: 1,
  2993. include_mute_edge: 1,
  2994. include_can_dm: 1,
  2995. include_can_media_tag: 1,
  2996. skip_status: 1,
  2997. id: userId
  2998. })
  2999. });
  3000. if (result === 'Success') {
  3001. if (data?.status === 200) {
  3002. logStatus.success();
  3003. if (doTask && !verify) {
  3004. this.tasks.users = unique([ ...this.tasks.users, name ]);
  3005. }
  3006. return true;
  3007. }
  3008. if (verify && data?.status === 403 && data.response?.errors?.[0]?.code === 158) {
  3009. logStatus.success();
  3010. return true;
  3011. }
  3012. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3013. return false;
  3014. }
  3015. logStatus.error(`${result}:${statusText}(${status})`);
  3016. return false;
  3017. } catch (error) {
  3018. throwError(error, 'Twitter.toggleUser');
  3019. return false;
  3020. }
  3021. }
  3022. async userName2id(name) {
  3023. try {
  3024. const logStatus = scripts_echoLog({
  3025. type: 'gettingTwitterUserId',
  3026. text: name
  3027. });
  3028. const userId = this.#cache[name];
  3029. if (userId) {
  3030. logStatus.success();
  3031. return userId;
  3032. }
  3033. const {
  3034. result,
  3035. statusText,
  3036. status,
  3037. data
  3038. } = await tools_httpRequest({
  3039. url: 'https://x.com/i/api/graphql/mCbpQvZAw6zu_4PvuAUVVQ/UserByScreenName' + `?variables=%7B%22screen_name%22%3A%22${name}%22%2C%22withSafetyModeUserFields%22%3Atrue%2C%22withSuperFollowsUserFields%22%3Atrue%7D`,
  3040. method: 'GET',
  3041. headers: {
  3042. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3043. 'content-type': 'application/json',
  3044. referer: `https://x.com/${name}`,
  3045. 'x-csrf-token': this.#auth.ct0
  3046. },
  3047. responseType: 'json'
  3048. });
  3049. if (result === 'Success') {
  3050. if (data?.status === 200) {
  3051. let response = data.response || (typeof data.responseText === 'object' ? data.responseText : null);
  3052. if (!response) {
  3053. try {
  3054. response = JSON.parse(data.responseText);
  3055. } catch (error) {
  3056. response = null;
  3057. }
  3058. }
  3059. const userId = String(response?.data?.user?.result?.rest_id);
  3060. if (userId) {
  3061. this.#setCache(name, userId);
  3062. logStatus.success();
  3063. return userId;
  3064. }
  3065. logStatus.error(`Error:${data.statusText}(${data.status})`);
  3066. return false;
  3067. }
  3068. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3069. return false;
  3070. }
  3071. logStatus.error(`${result}:${statusText}(${status})`);
  3072. return false;
  3073. } catch (error) {
  3074. throwError(error, 'Twitter.getUserId');
  3075. return false;
  3076. }
  3077. }
  3078. async #toggleRetweet({
  3079. retweetId,
  3080. doTask = true
  3081. }) {
  3082. try {
  3083. if (!doTask && this.whiteList.retweets.includes(retweetId)) {
  3084. scripts_echoLog({
  3085. type: 'whiteList',
  3086. text: 'Twitter.unretweet',
  3087. id: retweetId
  3088. });
  3089. return true;
  3090. }
  3091. const logStatus = scripts_echoLog({
  3092. type: `${doTask ? '' : 'un'}retweetting`,
  3093. text: retweetId
  3094. });
  3095. const {
  3096. result,
  3097. statusText,
  3098. status,
  3099. data
  3100. } = await tools_httpRequest({
  3101. url: `https://x.com/i/api/graphql/${doTask ? 'ojPdsZsimiJrUGLR1sjUtA/CreateRetweet' : 'iQtK4dl5hBmXewYZuEOKVw/DeleteRetweet'}`,
  3102. method: 'POST',
  3103. headers: {
  3104. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3105. 'Content-Type': 'application/json',
  3106. 'x-csrf-token': this.#auth.ct0
  3107. },
  3108. data: `{"variables":{"tweet_id":"${retweetId}","dark_request":false},"queryId":"${doTask ? 'ojPdsZsimiJrUGLR1sjUtA' : 'iQtK4dl5hBmXewYZuEOKVw'}"}`,
  3109. responseType: 'json'
  3110. });
  3111. if (result === 'Success') {
  3112. if (data?.status === 200 || data?.status === 403 && data.response?.errors?.[0]?.code === 327) {
  3113. logStatus.success();
  3114. if (doTask) {
  3115. this.tasks.retweets = unique([ ...this.tasks.retweets, retweetId ]);
  3116. }
  3117. return true;
  3118. }
  3119. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3120. return false;
  3121. }
  3122. logStatus.error(`${result}:${statusText}(${status})`);
  3123. return false;
  3124. } catch (error) {
  3125. throwError(error, 'Twitter.toggleRetweet');
  3126. return false;
  3127. }
  3128. }
  3129. async toggle({
  3130. doTask = true,
  3131. userLinks = [],
  3132. retweetLinks = []
  3133. }) {
  3134. try {
  3135. if (!this.#initialized) {
  3136. scripts_echoLog({
  3137. text: i18n('needInit')
  3138. });
  3139. return false;
  3140. }
  3141. const prom = [];
  3142. if (doTask && !globalOptions.doTask.twitter.users || !doTask && !globalOptions.undoTask.twitter.users) {
  3143. scripts_echoLog({
  3144. type: 'globalOptionsSkip',
  3145. text: 'twitter.users'
  3146. });
  3147. } else {
  3148. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/x\.com\/(.+)/)?.[1] || link.match(/https:\/\/twitter\.com\/(.+)/)?.[1]);
  3149. if (realUsers.length > 0) {
  3150. for (const user of realUsers) {
  3151. prom.push(this.#toggleUser({
  3152. name: user,
  3153. doTask: doTask
  3154. }));
  3155. await delay(1e3);
  3156. }
  3157. }
  3158. }
  3159. if (doTask && !globalOptions.doTask.twitter.retweets || !doTask && !globalOptions.undoTask.twitter.retweets) {
  3160. scripts_echoLog({
  3161. type: 'globalOptionsSkip',
  3162. text: 'twitter.retweets'
  3163. });
  3164. } else {
  3165. const realRetweets = this.getRealParams('retweets', retweetLinks, doTask, link => link.match(/https:\/\/x\.com\/.*?\/status\/([\d]+)/)?.[1] || link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1]);
  3166. if (realRetweets.length > 0) {
  3167. for (const retweet of realRetweets) {
  3168. prom.push(this.#toggleRetweet({
  3169. retweetId: retweet,
  3170. doTask: doTask
  3171. }));
  3172. await delay(1e3);
  3173. }
  3174. }
  3175. }
  3176. return Promise.all(prom).then(() => true);
  3177. } catch (error) {
  3178. throwError(error, 'Twitter.toggle');
  3179. return false;
  3180. }
  3181. }
  3182. #setCache(name, id) {
  3183. try {
  3184. this.#cache[name] = id;
  3185. GM_setValue('twitterCache', this.#cache);
  3186. } catch (error) {
  3187. throwError(error, 'Twitter.setCache');
  3188. }
  3189. }
  3190. }
  3191. const social_Twitter = Twitter;
  3192. class Vk extends social_Social {
  3193. tasks;
  3194. whiteList;
  3195. #username = '';
  3196. #cache = GM_getValue('vkCache') || {};
  3197. #initialized = false;
  3198. constructor() {
  3199. super();
  3200. const defaultTasksTemplate = {
  3201. names: []
  3202. };
  3203. this.tasks = defaultTasksTemplate;
  3204. this.whiteList = {
  3205. ...defaultTasksTemplate,
  3206. ...GM_getValue('whiteList')?.vk || {}
  3207. };
  3208. }
  3209. async init() {
  3210. try {
  3211. if (this.#initialized) {
  3212. return true;
  3213. }
  3214. const isVerified = await this.#verifyAuth();
  3215. if (isVerified) {
  3216. scripts_echoLog({}).success(i18n('initSuccess', 'Vk'));
  3217. this.#initialized = true;
  3218. return true;
  3219. }
  3220. scripts_echoLog({}).error(i18n('initFailed', 'Vk'));
  3221. return false;
  3222. } catch (error) {
  3223. throwError(error, 'Vk.init');
  3224. return false;
  3225. }
  3226. }
  3227. async #verifyAuth() {
  3228. try {
  3229. const logStatus = scripts_echoLog({
  3230. text: i18n('verifyAuth', 'Vk')
  3231. });
  3232. const {
  3233. result,
  3234. statusText,
  3235. status,
  3236. data
  3237. } = await tools_httpRequest({
  3238. url: 'https://vk.com/im',
  3239. method: 'GET'
  3240. });
  3241. if (result === 'Success') {
  3242. if (data?.finalUrl.includes('vk.com/login')) {
  3243. logStatus.error(`Error:${i18n('loginVk')}`, true);
  3244. return false;
  3245. }
  3246. if (data?.status === 200) {
  3247. this.#username = data.responseText.match(/TopNavBtn__profileLink" href="\/(.*?)"/)?.[1] || '';
  3248. logStatus.success();
  3249. return true;
  3250. }
  3251. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3252. return false;
  3253. }
  3254. logStatus.error(`${result}:${statusText}(${status})`);
  3255. return false;
  3256. } catch (error) {
  3257. throwError(error, 'Vk.verifyAuth');
  3258. return false;
  3259. }
  3260. }
  3261. async #toggleGroup(name, dataParam, doTask = true) {
  3262. try {
  3263. const logStatus = scripts_echoLog({
  3264. type: doTask ? 'joiningVkGroup' : 'leavingVkGroup',
  3265. text: name
  3266. });
  3267. if (dataParam.groupAct === 'enter' && !doTask || dataParam.groupAct === 'leave' && doTask) {
  3268. logStatus.success();
  3269. return true;
  3270. }
  3271. const reqData = {
  3272. act: doTask ? 'enter' : 'leave',
  3273. al: 1,
  3274. gid: dataParam.groupId,
  3275. hash: dataParam.groupHash
  3276. };
  3277. if (doTask) {
  3278. reqData.context = '_';
  3279. }
  3280. const {
  3281. result,
  3282. statusText,
  3283. status,
  3284. data
  3285. } = await tools_httpRequest({
  3286. url: 'https://vk.com/al_groups.php',
  3287. method: 'POST',
  3288. headers: {
  3289. origin: 'https://vk.com',
  3290. referer: `https://vk.com/${name}`,
  3291. 'content-type': 'application/x-www-form-urlencoded'
  3292. },
  3293. data: $.param(reqData)
  3294. });
  3295. if (result === 'Success') {
  3296. if (data?.status === 200) {
  3297. logStatus.success();
  3298. if (doTask) {
  3299. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3300. }
  3301. return true;
  3302. }
  3303. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3304. return false;
  3305. }
  3306. logStatus.error(`${result}:${statusText}(${status})`);
  3307. return false;
  3308. } catch (error) {
  3309. throwError(error, 'Vk.toggleGroup');
  3310. return false;
  3311. }
  3312. }
  3313. async #togglePublic(name, dataParam, doTask = true) {
  3314. try {
  3315. const logStatus = scripts_echoLog({
  3316. type: doTask ? 'joiningVkPublic' : 'leavingVkPublic',
  3317. text: name
  3318. });
  3319. if (dataParam.publicJoined && doTask || !dataParam.publicJoined && !doTask) {
  3320. logStatus.success();
  3321. return true;
  3322. }
  3323. const {
  3324. result,
  3325. statusText,
  3326. status,
  3327. data
  3328. } = await tools_httpRequest({
  3329. url: 'https://vk.com/al_public.php',
  3330. method: 'POST',
  3331. headers: {
  3332. origin: 'https://vk.com',
  3333. referer: `https://vk.com/${name}`,
  3334. 'content-type': 'application/x-www-form-urlencoded'
  3335. },
  3336. data: $.param({
  3337. act: doTask ? 'a_enter' : 'a_leave',
  3338. al: 1,
  3339. pid: dataParam.publicPid,
  3340. hash: dataParam.publicHash
  3341. })
  3342. });
  3343. if (result === 'Success') {
  3344. if (data?.status === 200) {
  3345. logStatus.success();
  3346. if (doTask) {
  3347. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3348. }
  3349. return true;
  3350. }
  3351. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3352. return false;
  3353. }
  3354. logStatus.error(`${result}:${statusText}(${status})`);
  3355. return false;
  3356. } catch (error) {
  3357. throwError(error, 'Vk.togglePublic');
  3358. return false;
  3359. }
  3360. }
  3361. async #sendWall(name) {
  3362. try {
  3363. const logStatus = scripts_echoLog({
  3364. type: 'sendingVkWall',
  3365. text: name
  3366. });
  3367. const {
  3368. result,
  3369. statusText,
  3370. status,
  3371. data
  3372. } = await tools_httpRequest({
  3373. url: 'https://vk.com/like.php',
  3374. method: 'POST',
  3375. headers: {
  3376. origin: 'https://vk.com',
  3377. referer: `https://vk.com/${name}`,
  3378. 'content-type': 'application/x-www-form-urlencoded'
  3379. },
  3380. data: $.param({
  3381. act: 'publish_box',
  3382. al: 1,
  3383. object: name
  3384. })
  3385. });
  3386. if (result === 'Success') {
  3387. if (data?.status === 200) {
  3388. const hash = data.responseText.match(/shHash:[\s]*'(.*?)'/)?.[1];
  3389. if (hash) {
  3390. const {
  3391. result: resultR,
  3392. statusText: statusTextR,
  3393. status: statusR,
  3394. data: dataR
  3395. } = await tools_httpRequest({
  3396. url: 'https://vk.com/like.php',
  3397. method: 'POST',
  3398. headers: {
  3399. origin: 'https://vk.com',
  3400. referer: `https://vk.com/${name}`,
  3401. 'content-type': 'application/x-www-form-urlencoded'
  3402. },
  3403. data: $.param({
  3404. Message: '',
  3405. act: 'a_do_publish',
  3406. al: 1,
  3407. close_comments: 0,
  3408. friends_only: 0,
  3409. from: 'box',
  3410. hash: hash,
  3411. list: '',
  3412. mark_as_ads: 0,
  3413. mute_notifications: 0,
  3414. object: name,
  3415. ret_data: 1,
  3416. to: 0
  3417. })
  3418. });
  3419. if (resultR === 'Success') {
  3420. if (dataR?.status === 200) {
  3421. const jsonData = JSON.parse(dataR.responseText?.replace('\x3c!--', '') || '{}');
  3422. if (jsonData?.payload?.[1]?.[1]?.share_my === true) {
  3423. logStatus.success();
  3424. const postId = String(jsonData?.payload?.[1]?.[1]?.post_id);
  3425. const ownerId = String(jsonData?.payload?.[1]?.[1]?.owner_id);
  3426. if (postId && ownerId) {
  3427. this.#setCache(name, `${ownerId}_${postId}`);
  3428. }
  3429. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3430. return true;
  3431. }
  3432. }
  3433. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  3434. return false;
  3435. }
  3436. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  3437. return false;
  3438. }
  3439. logStatus.error('Error: Get "hash" failed');
  3440. return false;
  3441. }
  3442. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3443. return false;
  3444. }
  3445. logStatus.error(`${result}:${statusText}(${status})`);
  3446. return false;
  3447. } catch (error) {
  3448. throwError(error, 'Vk.sendWall');
  3449. return false;
  3450. }
  3451. }
  3452. async #deleteWall(name, dataParams) {
  3453. try {
  3454. const logStatus = scripts_echoLog({
  3455. type: 'deletingVkWall',
  3456. text: name
  3457. });
  3458. const {
  3459. result,
  3460. statusText,
  3461. status,
  3462. data
  3463. } = await tools_httpRequest({
  3464. url: 'https://vk.com/al_wall.php?act=delete',
  3465. method: 'POST',
  3466. headers: {
  3467. origin: 'https://vk.com',
  3468. referer: `https://vk.com/${this.#username}?w=wall${this.#cache[name]}%2Fall`,
  3469. 'content-type': 'application/x-www-form-urlencoded'
  3470. },
  3471. data: $.param({
  3472. act: 'delete',
  3473. al: 1,
  3474. confirm: 0,
  3475. from: 'wkview',
  3476. hash: dataParams.wallHash,
  3477. post: this.#cache[name]
  3478. })
  3479. });
  3480. if (result === 'Success') {
  3481. if (data?.status === 200) {
  3482. const jsonData = JSON.parse(data.responseText?.replace('\x3c!--', '') || '{}');
  3483. if (jsonData?.payload?.[1]?.[1]) {
  3484. logStatus.success();
  3485. return true;
  3486. }
  3487. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3488. return false;
  3489. }
  3490. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3491. return false;
  3492. }
  3493. logStatus.error(`${result}:${statusText}(${status})`);
  3494. return false;
  3495. } catch (error) {
  3496. throwError(error, 'Vk.deleteWall');
  3497. return false;
  3498. }
  3499. }
  3500. async #getId(name, doTask) {
  3501. try {
  3502. let url = `https://vk.com/${name}`;
  3503. if (/^wall-/.test(name)) {
  3504. if (doTask) {
  3505. return {
  3506. type: 'sendWall'
  3507. };
  3508. }
  3509. if (!this.#cache[name]) {
  3510. return {
  3511. type: 'unSupport'
  3512. };
  3513. }
  3514. url = `https://vk.com/${this.#username}?w=wall${this.#cache[name]}`;
  3515. }
  3516. const logStatus = scripts_echoLog({
  3517. type: 'gettingVkId',
  3518. text: name
  3519. });
  3520. const {
  3521. result,
  3522. statusText,
  3523. status,
  3524. data
  3525. } = await tools_httpRequest({
  3526. url: url,
  3527. method: 'GET'
  3528. });
  3529. if (result === 'Success') {
  3530. if (data?.status === 200) {
  3531. const [ , groupAct, groupId, , groupHash ] = data.responseText.match(/Groups.(enter|leave)\(.*?,.*?([\d]+?), (&#39;|')(.*?)(&#39;|')/) || [];
  3532. const publicHash = data.responseText.match(/"enterHash":"(.*?)"/)?.[1];
  3533. const publicPid = data.responseText.match(/"public_id":([\d]+?),/)?.[1];
  3534. const publicJoined = !data.responseText.includes('Public.subscribe');
  3535. if (groupAct && groupId && groupHash) {
  3536. logStatus.success();
  3537. return {
  3538. groupAct: groupAct,
  3539. groupId: groupId,
  3540. groupHash: groupHash,
  3541. type: 'group'
  3542. };
  3543. } else if (publicHash && publicPid) {
  3544. logStatus.success();
  3545. return {
  3546. publicHash: publicHash,
  3547. publicPid: publicPid,
  3548. publicJoined: publicJoined,
  3549. type: 'public'
  3550. };
  3551. } else if (data.responseText.includes('wall.deletePost') && !doTask) {
  3552. const wallHash = data.responseText.match(/wall\.deletePost\(this, '.*?', '(.*?)'\)/)?.[1];
  3553. if (wallHash) {
  3554. logStatus.success();
  3555. return {
  3556. type: 'deleteWall',
  3557. wallHash: wallHash
  3558. };
  3559. }
  3560. } else if (name.includes('wall') && doTask) {
  3561. logStatus.success();
  3562. return {
  3563. type: 'sendWall'
  3564. };
  3565. }
  3566. logStatus.error('Error: Parameters not found!');
  3567. return false;
  3568. }
  3569. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3570. return false;
  3571. }
  3572. logStatus.error(`${result}:${statusText}(${status})`);
  3573. return false;
  3574. } catch (error) {
  3575. throwError(error, 'Vk.getId');
  3576. return false;
  3577. }
  3578. }
  3579. async #toggleVk({
  3580. name,
  3581. doTask = true
  3582. }) {
  3583. try {
  3584. if (!doTask && this.whiteList.names.includes(name)) {
  3585. scripts_echoLog({
  3586. type: 'whiteList',
  3587. text: 'Vk.undoTask',
  3588. id: name
  3589. });
  3590. return true;
  3591. }
  3592. const formatName = name.replace(/\/$/, '');
  3593. const data = await this.#getId(formatName, doTask);
  3594. if (!data) {
  3595. return false;
  3596. }
  3597. switch (data.type) {
  3598. case 'group':
  3599. return await this.#toggleGroup(formatName, data, doTask);
  3600.  
  3601. case 'public':
  3602. return await this.#togglePublic(formatName, data, doTask);
  3603.  
  3604. case 'sendWall':
  3605. return doTask ? await this.#sendWall(formatName) : true;
  3606.  
  3607. case 'deleteWall':
  3608. return doTask ? true : await this.#deleteWall(formatName, data);
  3609.  
  3610. default:
  3611. return false;
  3612. }
  3613. } catch (error) {
  3614. throwError(error, 'Vk.toggleVk');
  3615. return false;
  3616. }
  3617. }
  3618. async toggle({
  3619. doTask = true,
  3620. nameLinks = []
  3621. }) {
  3622. try {
  3623. if (!this.#initialized) {
  3624. scripts_echoLog({
  3625. text: i18n('needInit')
  3626. });
  3627. return false;
  3628. }
  3629. const prom = [];
  3630. if (doTask && !globalOptions.doTask.vk.names || !doTask && !globalOptions.undoTask.vk.names) {
  3631. scripts_echoLog({
  3632. type: 'globalOptionsSkip',
  3633. text: 'vk.names'
  3634. });
  3635. } else {
  3636. const realNames = this.getRealParams('names', nameLinks, doTask, link => link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1]);
  3637. if (realNames.length > 0) {
  3638. for (const name of realNames) {
  3639. prom.push(this.#toggleVk({
  3640. name: name,
  3641. doTask: doTask
  3642. }));
  3643. await delay(1e3);
  3644. }
  3645. }
  3646. }
  3647. return Promise.all(prom).then(() => true);
  3648. } catch (error) {
  3649. throwError(error, 'Vk.toggle');
  3650. return false;
  3651. }
  3652. }
  3653. #setCache(name, postId) {
  3654. try {
  3655. this.#cache[name] = postId;
  3656. GM_setValue('vkCache', this.#cache);
  3657. } catch (error) {
  3658. throwError(error, 'Vk.setCache');
  3659. }
  3660. }
  3661. }
  3662. const social_Vk = Vk;
  3663. const getInfo = async function(link, type) {
  3664. try {
  3665. const logStatus = scripts_echoLog({
  3666. text: i18n('gettingYtbToken')
  3667. });
  3668. const {
  3669. result,
  3670. statusText,
  3671. status,
  3672. data
  3673. } = await tools_httpRequest({
  3674. url: link,
  3675. method: 'GET'
  3676. });
  3677. if (result === 'Success') {
  3678. if (data?.status === 200) {
  3679. if (data.responseText.includes('accounts.google.com/ServiceLogin?service=youtube')) {
  3680. logStatus.error(`Error:${i18n('loginYtb')}`, true);
  3681. return {
  3682. needLogin: true
  3683. };
  3684. }
  3685. const apiKey = data.responseText.match(/"INNERTUBE_API_KEY":"(.*?)"/)?.[1];
  3686. const context = (data.responseText.match(/\(\{"INNERTUBE_CONTEXT":([\w\W]*?)\}\)/) || data.responseText.match(/"INNERTUBE_CONTEXT":([\w\W]*?\}),"INNERTUBE/))?.[1] || '{}';
  3687. const {
  3688. client,
  3689. request
  3690. } = JSON.parse(context);
  3691. if (apiKey && client && request) {
  3692. client.hl = 'en';
  3693. if (type === 'channel') {
  3694. const channelId = data.responseText.match(/"channelId":"(.+?)"/)?.[1];
  3695. if (channelId) {
  3696. logStatus.success();
  3697. return {
  3698. params: {
  3699. apiKey: apiKey,
  3700. client: client,
  3701. request: request,
  3702. channelId: channelId
  3703. }
  3704. };
  3705. }
  3706. logStatus.error('Error: Get "channelId" failed!');
  3707. return {};
  3708. } else if (type === 'likeVideo') {
  3709. const videoId = data.responseText.match(/<link rel="shortlinkUrl" href="https:\/\/youtu\.be\/(.*?)">/)?.[1];
  3710. const likeParams = data.responseText.match(/"likeParams":"(.*?)"/)?.[1];
  3711. if (videoId) {
  3712. logStatus.success();
  3713. return {
  3714. params: {
  3715. apiKey: apiKey,
  3716. client: client,
  3717. request: request,
  3718. videoId: videoId,
  3719. likeParams: likeParams
  3720. }
  3721. };
  3722. }
  3723. logStatus.error('Error: Get "videoId" failed!');
  3724. return {};
  3725. }
  3726. logStatus.error('Error: Unknown type');
  3727. return {};
  3728. }
  3729. logStatus.error('Error: Parameter "apiKey" not found!');
  3730. return {};
  3731. }
  3732. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3733. return {};
  3734. }
  3735. logStatus.error(`${result}:${statusText}(${status})`);
  3736. return {};
  3737. } catch (error) {
  3738. throwError(error, 'Youtube.getInfo');
  3739. return {};
  3740. }
  3741. };
  3742. class Youtube extends social_Social {
  3743. tasks;
  3744. whiteList;
  3745. #auth = GM_getValue('youtubeAuth') || {};
  3746. #initialized = false;
  3747. #verifyChannel = `https://www.youtube.com/channel/${globalOptions.other.youtubeVerifyChannel}`;
  3748. constructor() {
  3749. super();
  3750. const defaultTasksTemplate = {
  3751. channels: [],
  3752. likes: []
  3753. };
  3754. this.tasks = defaultTasksTemplate;
  3755. this.whiteList = {
  3756. ...defaultTasksTemplate,
  3757. ...GM_getValue('whiteList')?.youtube || {}
  3758. };
  3759. }
  3760. async init() {
  3761. try {
  3762. if (this.#initialized) {
  3763. return true;
  3764. }
  3765. if (!this.#auth.PAPISID) {
  3766. if (await this.#updateAuth()) {
  3767. this.#initialized = true;
  3768. return true;
  3769. }
  3770. return false;
  3771. }
  3772. const isVerified = await this.#verifyAuth();
  3773. if (isVerified) {
  3774. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3775. this.#initialized = true;
  3776. return true;
  3777. }
  3778. GM_setValue('youtubeAuth', null);
  3779. if (await this.#updateAuth()) {
  3780. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3781. this.#initialized = true;
  3782. return true;
  3783. }
  3784. scripts_echoLog({}).error(i18n('initFailed', 'Youtube'));
  3785. return false;
  3786. } catch (error) {
  3787. throwError(error, 'Youtube.init');
  3788. return false;
  3789. }
  3790. }
  3791. async #verifyAuth() {
  3792. try {
  3793. return await this.#toggleChannel({
  3794. link: this.#verifyChannel,
  3795. doTask: true,
  3796. verify: true
  3797. });
  3798. } catch (error) {
  3799. throwError(error, 'Youtube.verifyAuth');
  3800. return false;
  3801. }
  3802. }
  3803. async #updateAuth() {
  3804. try {
  3805. const logStatus = scripts_echoLog({
  3806. text: i18n('updatingAuth', 'Youtube')
  3807. });
  3808. return await new Promise(resolve => {
  3809. GM_cookie.list({
  3810. url: 'https://www.youtube.com/@YouTube'
  3811. }, async (cookies, error) => {
  3812. if (!error) {
  3813. const PAPISID = cookies.find(cookie => cookie.name === '__Secure-3PAPISID')?.value;
  3814. if (PAPISID) {
  3815. GM_setValue('youtubeAuth', {
  3816. PAPISID: PAPISID
  3817. });
  3818. this.#auth = {
  3819. PAPISID: PAPISID
  3820. };
  3821. logStatus.success();
  3822. resolve(await this.#verifyAuth());
  3823. } else {
  3824. logStatus.error(i18n('needLogin'));
  3825. resolve(false);
  3826. }
  3827. } else {
  3828. logStatus.error('Error: Update youtube auth failed!');
  3829. resolve(false);
  3830. }
  3831. });
  3832. });
  3833. } catch (error) {
  3834. throwError(error, 'Youtube.updateAuth');
  3835. return false;
  3836. }
  3837. }
  3838. #getInfo(link, type) {
  3839. return getInfo(link, type);
  3840. }
  3841. async #toggleChannel({
  3842. link,
  3843. doTask = true,
  3844. verify = false
  3845. }) {
  3846. try {
  3847. const {
  3848. params,
  3849. needLogin
  3850. } = await this.#getInfo(link, 'channel');
  3851. const {
  3852. apiKey,
  3853. client,
  3854. request,
  3855. channelId
  3856. } = params || {};
  3857. if (needLogin) {
  3858. scripts_echoLog({
  3859. html: i18n('loginYtb')
  3860. });
  3861. return false;
  3862. }
  3863. if (!(apiKey && client && request && channelId)) {
  3864. scripts_echoLog({
  3865. text: '"getYtbToken" failed'
  3866. });
  3867. return false;
  3868. }
  3869. if (!doTask && !verify && this.whiteList.channels.includes(channelId)) {
  3870. scripts_echoLog({
  3871. type: 'whiteList',
  3872. text: 'Youtube.unfollowChannel',
  3873. id: channelId
  3874. });
  3875. return true;
  3876. }
  3877. const logStatus = verify ? scripts_echoLog({
  3878. text: i18n('verifyingAuth', 'Youtube')
  3879. }) : scripts_echoLog({
  3880. type: doTask ? 'followingYtbChannel' : 'unfollowingYtbChannel',
  3881. text: channelId
  3882. });
  3883. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3884. const {
  3885. result,
  3886. statusText,
  3887. status,
  3888. data
  3889. } = await tools_httpRequest({
  3890. url: `https://www.youtube.com/youtubei/v1/subscription/${doTask ? '' : 'un'}subscribe?key=${apiKey}&prettyPrint=false`,
  3891. method: 'POST',
  3892. headers: {
  3893. origin: 'https://www.youtube.com',
  3894. referer: `https://www.youtube.com/channel/${channelId}`,
  3895. 'content-type': 'application/json',
  3896. 'x-goog-authuser': '0',
  3897. 'x-goog-visitor-id': client?.visitorData,
  3898. 'x-origin': 'https://www.youtube.com',
  3899. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  3900. },
  3901. data: JSON.stringify({
  3902. context: {
  3903. client: client,
  3904. request: {
  3905. sessionId: request?.sessionId,
  3906. internalExperimentFlags: [],
  3907. consistencyTokenJars: []
  3908. },
  3909. user: {}
  3910. },
  3911. channelIds: [ channelId ],
  3912. params: doTask ? 'EgIIAhgA' : 'CgIIAhgA'
  3913. })
  3914. });
  3915. if (result === 'Success') {
  3916. if (data?.status === 200) {
  3917. if (doTask && (/"subscribed":true/.test(data.responseText) || data.responseText.includes('The subscription already exists')) || !doTask && /"subscribed":false/.test(data.responseText)) {
  3918. logStatus.success();
  3919. if (doTask && !verify) {
  3920. this.tasks.channels = unique([ ...this.tasks.channels, link ]);
  3921. }
  3922. return true;
  3923. }
  3924. if (verify && data.responseText.includes('You may not subscribe to yourself')) {
  3925. logStatus.success();
  3926. return true;
  3927. }
  3928. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  3929. return false;
  3930. }
  3931. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3932. return false;
  3933. }
  3934. logStatus.error(`${result}:${statusText}(${status})`);
  3935. return false;
  3936. } catch (error) {
  3937. throwError(error, 'Youtube.toggleChannel');
  3938. return false;
  3939. }
  3940. }
  3941. async #toggleLikeVideo({
  3942. link,
  3943. doTask = true
  3944. }) {
  3945. try {
  3946. const {
  3947. params,
  3948. needLogin
  3949. } = await this.#getInfo(link, 'likeVideo');
  3950. const {
  3951. apiKey,
  3952. client,
  3953. request,
  3954. videoId,
  3955. likeParams
  3956. } = params || {};
  3957. if (needLogin) {
  3958. scripts_echoLog({
  3959. html: `${i18n('loginYtb')}`
  3960. });
  3961. return false;
  3962. }
  3963. if (!(apiKey && client && request && videoId && likeParams)) {
  3964. scripts_echoLog({
  3965. text: '"getYtbToken" failed'
  3966. });
  3967. return false;
  3968. }
  3969. if (!doTask && this.whiteList.likes.includes(videoId)) {
  3970. scripts_echoLog({
  3971. type: 'whiteList',
  3972. text: 'Youtube.unlikeVideo',
  3973. id: videoId
  3974. });
  3975. return true;
  3976. }
  3977. const logStatus = scripts_echoLog({
  3978. type: doTask ? 'likingYtbVideo' : 'unlikingYtbVideo',
  3979. text: videoId
  3980. });
  3981. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3982. const likeVideoData = {
  3983. context: {
  3984. client: client,
  3985. request: {
  3986. sessionId: request.sessionId,
  3987. internalExperimentFlags: [],
  3988. consistencyTokenJars: []
  3989. },
  3990. user: {}
  3991. },
  3992. target: {
  3993. videoId: videoId
  3994. }
  3995. };
  3996. if (doTask) {
  3997. if (likeParams) {
  3998. likeVideoData.params = likeParams;
  3999. } else {
  4000. logStatus.error('Empty likeParams');
  4001. return false;
  4002. }
  4003. }
  4004. const {
  4005. result,
  4006. statusText,
  4007. status,
  4008. data
  4009. } = await tools_httpRequest({
  4010. url: `https://www.youtube.com/youtubei/v1/like/${doTask ? '' : 'remove'}like?key=${apiKey}`,
  4011. method: 'POST',
  4012. headers: {
  4013. origin: 'https://www.youtube.com',
  4014. referer: `https://www.youtube.com/watch?v=${videoId}`,
  4015. 'content-type': 'application/json',
  4016. 'x-goog-authuser': '0',
  4017. 'x-goog-visitor-id': client.visitorData,
  4018. 'x-origin': 'https://www.youtube.com',
  4019. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  4020. },
  4021. data: JSON.stringify(likeVideoData)
  4022. });
  4023. if (result === 'Success') {
  4024. if (data?.status === 200) {
  4025. if (doTask && data.responseText.includes('Added to Liked videos') || !doTask && (data.responseText.includes('Removed from Liked videos') || data.responseText.includes('Dislike removed'))) {
  4026. logStatus.success();
  4027. if (doTask) {
  4028. this.tasks.likes = unique([ ...this.tasks.likes, link ]);
  4029. }
  4030. return true;
  4031. }
  4032. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  4033. return false;
  4034. }
  4035. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4036. return false;
  4037. }
  4038. logStatus.error(`${result}:${statusText}(${status})`);
  4039. return false;
  4040. } catch (error) {
  4041. throwError(error, 'Youtube.toggleLikeVideo');
  4042. return false;
  4043. }
  4044. }
  4045. async toggle({
  4046. doTask = true,
  4047. channelLinks = [],
  4048. videoLinks = []
  4049. }) {
  4050. try {
  4051. if (!this.#initialized) {
  4052. scripts_echoLog({
  4053. text: i18n('needInit')
  4054. });
  4055. return false;
  4056. }
  4057. const prom = [];
  4058. if (doTask && !globalOptions.doTask.youtube.channels || !doTask && !globalOptions.undoTask.youtube.channels) {
  4059. scripts_echoLog({
  4060. type: 'globalOptionsSkip',
  4061. text: 'youtube.channels'
  4062. });
  4063. } else {
  4064. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => {
  4065. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4066. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4067. }
  4068. return link;
  4069. });
  4070. if (realChannels.length > 0) {
  4071. for (const channel of realChannels) {
  4072. prom.push(this.#toggleChannel({
  4073. link: channel,
  4074. doTask: doTask
  4075. }));
  4076. await delay(1e3);
  4077. }
  4078. }
  4079. }
  4080. if (doTask && !globalOptions.doTask.youtube.likes || !doTask && !globalOptions.undoTask.youtube.likes) {
  4081. scripts_echoLog({
  4082. type: 'globalOptionsSkip',
  4083. text: 'youtube.likes'
  4084. });
  4085. } else {
  4086. const realLikes = this.getRealParams('likes', videoLinks, doTask, link => {
  4087. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4088. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4089. }
  4090. return link;
  4091. });
  4092. if (realLikes.length > 0) {
  4093. for (const video of realLikes) {
  4094. prom.push(this.#toggleLikeVideo({
  4095. link: video,
  4096. doTask: doTask
  4097. }));
  4098. await delay(1e3);
  4099. }
  4100. }
  4101. }
  4102. return Promise.all(prom).then(() => true);
  4103. } catch (error) {
  4104. throwError(error, 'Youtube.toggle');
  4105. return false;
  4106. }
  4107. }
  4108. }
  4109. class SteamASF {
  4110. #asfOptions;
  4111. #botName = 'asf';
  4112. #groupInfo;
  4113. async init() {
  4114. try {
  4115. const asfCommandsUrl = new URL('/Api/Command/', globalOptions.ASF.AsfIpcUrl);
  4116. this.#asfOptions = {
  4117. url: asfCommandsUrl.href,
  4118. method: 'POST',
  4119. responseType: 'json',
  4120. headers: {
  4121. accept: 'application/json',
  4122. 'Content-Type': 'application/json',
  4123. Host: asfCommandsUrl.host,
  4124. Origin: asfCommandsUrl.origin,
  4125. Referer: asfCommandsUrl.href,
  4126. Authentication: globalOptions.ASF.AsfIpcPassword
  4127. }
  4128. };
  4129. if (globalOptions.ASF.AsfBotname) {
  4130. this.#botName = globalOptions.ASF.AsfBotname;
  4131. }
  4132. const logStatus = scripts_echoLog({
  4133. text: i18n('initingASF')
  4134. });
  4135. const {
  4136. result,
  4137. statusText,
  4138. status,
  4139. data
  4140. } = await tools_httpRequest({
  4141. ...this.#asfOptions,
  4142. data: '{"Command":"!stats"}'
  4143. });
  4144. if (result === 'Success') {
  4145. if (data?.response?.Success === true && data.response.Message === 'OK' && data.response.Result) {
  4146. logStatus.success();
  4147. return true;
  4148. }
  4149. if (data?.response?.Result || data?.response?.Message) {
  4150. logStatus.error(data?.response?.Result || data.response.Message);
  4151. return false;
  4152. }
  4153. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4154. return false;
  4155. }
  4156. logStatus.error(`${result}:${statusText}(${status})`);
  4157. return false;
  4158. } catch (error) {
  4159. throwError(error, 'SteamASF.init');
  4160. return false;
  4161. }
  4162. }
  4163. async joinGroup(groupName) {
  4164. try {
  4165. const logStatus = scripts_echoLog({
  4166. type: 'joiningSteamGroup',
  4167. text: groupName
  4168. });
  4169. const {
  4170. result,
  4171. statusText,
  4172. status,
  4173. data
  4174. } = await tools_httpRequest({
  4175. ...this.#asfOptions,
  4176. data: JSON.stringify({
  4177. Command: `!JOINGROUP ${this.#botName} ${groupName}`
  4178. })
  4179. });
  4180. if (result === 'Success') {
  4181. if (data?.status === 200 && [ '已加入', '已申请', 'Joined', 'Applied', 'Присоединился', 'costs' ].find(text => data.response?.Result?.includes(text))) {
  4182. logStatus.success();
  4183. return true;
  4184. }
  4185. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4186. return false;
  4187. }
  4188. logStatus.error(`${result}:${statusText}(${status})`);
  4189. return false;
  4190. } catch (error) {
  4191. throwError(error, 'SteamASF.joinGroup');
  4192. return false;
  4193. }
  4194. }
  4195. async leaveGroup(groupName) {
  4196. try {
  4197. if (!this.#groupInfo) {
  4198. if (!await this.#getGroupId()) {
  4199. return false;
  4200. }
  4201. }
  4202. const groupId = await this.#groupInfo[groupName];
  4203. if (!groupId) {
  4204. return false;
  4205. }
  4206. const logStatus = scripts_echoLog({
  4207. type: 'leavingSteamGroup',
  4208. text: groupName
  4209. });
  4210. const {
  4211. result,
  4212. statusText,
  4213. status,
  4214. data
  4215. } = await tools_httpRequest({
  4216. ...this.#asfOptions,
  4217. data: JSON.stringify({
  4218. Command: `!LEAVEGROUP ${this.#botName} ${groupId}`
  4219. })
  4220. });
  4221. if (result === 'Success') {
  4222. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4223. logStatus.success();
  4224. return true;
  4225. }
  4226. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4227. return false;
  4228. }
  4229. logStatus.error(`${result}:${statusText}(${status})`);
  4230. return false;
  4231. } catch (error) {
  4232. throwError(error, 'SteamASF.leaveGroup');
  4233. return false;
  4234. }
  4235. }
  4236. async #getGroupId() {
  4237. try {
  4238. const logStatus = scripts_echoLog({
  4239. type: 'gettingSteamGroupId',
  4240. text: 'All'
  4241. });
  4242. const {
  4243. result,
  4244. statusText,
  4245. status,
  4246. data
  4247. } = await tools_httpRequest({
  4248. ...this.#asfOptions,
  4249. data: JSON.stringify({
  4250. Command: `!GROUPLIST ${this.#botName}`
  4251. })
  4252. });
  4253. if (result === 'Success') {
  4254. if (data?.status === 200 && data.response?.Result?.includes('|')) {
  4255. this.#groupInfo = Object.fromEntries(data.response.Result.split('\n').map(line => {
  4256. const [ , name, id ] = line.trim().split('|');
  4257. if (name && id) {
  4258. return [ name, id ];
  4259. }
  4260. return null;
  4261. }).filter(ele => ele));
  4262. logStatus.success();
  4263. return true;
  4264. }
  4265. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4266. return false;
  4267. }
  4268. logStatus.error(`${result}:${statusText}(${status})`);
  4269. return false;
  4270. } catch (error) {
  4271. throwError(error, 'SteamASF.getGroupID');
  4272. return false;
  4273. }
  4274. }
  4275. async addToWishlist(gameId) {
  4276. try {
  4277. const logStatus = scripts_echoLog({
  4278. type: 'addingToWishlist',
  4279. text: gameId
  4280. });
  4281. const {
  4282. result,
  4283. statusText,
  4284. status,
  4285. data
  4286. } = await tools_httpRequest({
  4287. ...this.#asfOptions,
  4288. data: JSON.stringify({
  4289. Command: `!ADDWISHLIST ${this.#botName} ${gameId}`
  4290. })
  4291. });
  4292. if (result === 'Success') {
  4293. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4294. logStatus.success();
  4295. return true;
  4296. }
  4297. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4298. return false;
  4299. }
  4300. logStatus.error(`${result}:${statusText}(${status})`);
  4301. return false;
  4302. } catch (error) {
  4303. throwError(error, 'SteamASF.addToWishlist');
  4304. return false;
  4305. }
  4306. }
  4307. async removeFromWishlist(gameId) {
  4308. try {
  4309. const logStatus = scripts_echoLog({
  4310. type: 'removingFromWishlist',
  4311. text: gameId
  4312. });
  4313. const {
  4314. result,
  4315. statusText,
  4316. status,
  4317. data
  4318. } = await tools_httpRequest({
  4319. ...this.#asfOptions,
  4320. data: JSON.stringify({
  4321. Command: `!REMOVEWISHLIST ${this.#botName} ${gameId}`
  4322. })
  4323. });
  4324. if (result === 'Success') {
  4325. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4326. logStatus.success();
  4327. return true;
  4328. }
  4329. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4330. return false;
  4331. }
  4332. logStatus.error(`${result}:${statusText}(${status})`);
  4333. return false;
  4334. } catch (error) {
  4335. throwError(error, 'SteamASF.removeFromWishlist');
  4336. return false;
  4337. }
  4338. }
  4339. async toggleFollowGame(gameId, doTask) {
  4340. try {
  4341. const logStatus = scripts_echoLog({
  4342. type: `${doTask ? '' : 'un'}followingGame`,
  4343. text: gameId
  4344. });
  4345. const {
  4346. result,
  4347. statusText,
  4348. status,
  4349. data
  4350. } = await tools_httpRequest({
  4351. ...this.#asfOptions,
  4352. data: JSON.stringify({
  4353. Command: `!${doTask ? '' : 'UN'}FOLLOWGAME ${this.#botName} ${gameId}`
  4354. })
  4355. });
  4356. if (result === 'Success') {
  4357. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4358. logStatus.success();
  4359. return true;
  4360. }
  4361. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4362. return false;
  4363. }
  4364. logStatus.error(`${result}:${statusText}(${status})`);
  4365. return false;
  4366. } catch (error) {
  4367. throwError(error, 'SteamASF.toggleFollowGame');
  4368. return false;
  4369. }
  4370. }
  4371. async toggleCurator(curatorId, doTask = true) {
  4372. try {
  4373. const logStatus = scripts_echoLog({
  4374. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  4375. text: curatorId
  4376. });
  4377. const {
  4378. result,
  4379. statusText,
  4380. status,
  4381. data
  4382. } = await tools_httpRequest({
  4383. ...this.#asfOptions,
  4384. data: JSON.stringify({
  4385. Command: `!${doTask ? '' : 'UN'}FOLLOWCURATOR ${this.#botName} ${curatorId}`
  4386. })
  4387. });
  4388. if (result === 'Success') {
  4389. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4390. logStatus.success();
  4391. return true;
  4392. }
  4393. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4394. return false;
  4395. }
  4396. logStatus.error(`${result}:${statusText}(${status})`);
  4397. return false;
  4398. } catch (error) {
  4399. throwError(error, 'Steam.toggleCurator');
  4400. return false;
  4401. }
  4402. }
  4403. async addLicense(id) {
  4404. try {
  4405. const [ type, ids ] = id.split('-');
  4406. if (type === 'appid') {
  4407. const logStatus = scripts_echoLog({
  4408. type: 'addingFreeLicense',
  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} app/${ids}`
  4420. })
  4421. });
  4422. if (result === 'Success') {
  4423. if (data?.status === 200 && [ 'AlreadyPurchased', 'OK' ].find(text => data.response?.Result?.includes(text))) {
  4424. logStatus.success();
  4425. return true;
  4426. }
  4427. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4428. return false;
  4429. }
  4430. logStatus.error(`${result}:${statusText}(${status})`);
  4431. return false;
  4432. } else if (type === 'subid') {
  4433. const idsArr = ids.split(',');
  4434. const logStatus = scripts_echoLog({
  4435. type: 'addingFreeLicenseSubid',
  4436. text: ids
  4437. });
  4438. const {
  4439. result,
  4440. statusText,
  4441. status,
  4442. data
  4443. } = await tools_httpRequest({
  4444. ...this.#asfOptions,
  4445. data: JSON.stringify({
  4446. Command: `!addlicense ${this.#botName} ${idsArr.map(id => `sub/${id}`).join(',')}`
  4447. })
  4448. });
  4449. if (result === 'Success') {
  4450. if (data?.status === 200 && data.response?.Result) {
  4451. const resultLines = data.response.Result.split('\n');
  4452. idsArr.forEach(subid => {
  4453. const targetLine = resultLines.find(text => text.includes(subid));
  4454. if (targetLine && [ '成功', 'Success', 'Успех' ].find(text => targetLine.includes(text))) {
  4455. scripts_echoLog({}).success(targetLine);
  4456. } else {
  4457. scripts_echoLog({}).error(targetLine);
  4458. }
  4459. });
  4460. return true;
  4461. }
  4462. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4463. return false;
  4464. }
  4465. logStatus.error(`${result}:${statusText}(${status})`);
  4466. return false;
  4467. }
  4468. return false;
  4469. } catch (error) {
  4470. throwError(error, 'SteamASF.addLicense');
  4471. return false;
  4472. }
  4473. }
  4474. async requestPlayTestAccess(id) {
  4475. try {
  4476. const logStatus = scripts_echoLog({
  4477. type: 'requestingPlayTestAccess',
  4478. text: id
  4479. });
  4480. const {
  4481. result,
  4482. statusText,
  4483. status,
  4484. data
  4485. } = await tools_httpRequest({
  4486. ...this.#asfOptions,
  4487. data: JSON.stringify({
  4488. Command: `!REQUESTACCESS ${this.#botName} ${id}`
  4489. })
  4490. });
  4491. if (result === 'Success') {
  4492. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4493. logStatus.success();
  4494. return true;
  4495. }
  4496. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4497. return false;
  4498. }
  4499. logStatus.error(`${result}:${statusText}(${status})`);
  4500. return false;
  4501. } catch (error) {
  4502. throwError(error, 'Steam.requestPlayTestAccess');
  4503. return false;
  4504. }
  4505. }
  4506. }
  4507. const social_SteamASF = SteamASF;
  4508. class Steam extends social_Social {
  4509. tasks;
  4510. whiteList;
  4511. #cache = {
  4512. ...{
  4513. group: {},
  4514. officialGroup: {},
  4515. forum: {},
  4516. workshop: {},
  4517. curator: {}
  4518. },
  4519. ...GM_getValue('steamCache')
  4520. };
  4521. #auth = {};
  4522. #storeInitialized = false;
  4523. #communityInitialized = false;
  4524. #area = 'CN';
  4525. #areaStatus = 'end';
  4526. #ASF;
  4527. constructor() {
  4528. super();
  4529. const defaultTasksTemplate = {
  4530. groups: [],
  4531. officialGroups: [],
  4532. wishlists: [],
  4533. follows: [],
  4534. forums: [],
  4535. workshops: [],
  4536. workshopVotes: [],
  4537. curators: [],
  4538. curatorLikes: [],
  4539. announcements: [],
  4540. licenses: [],
  4541. playtests: []
  4542. };
  4543. this.tasks = defaultTasksTemplate;
  4544. this.whiteList = {
  4545. ...defaultTasksTemplate,
  4546. ...GM_getValue('whiteList')?.steam || {}
  4547. };
  4548. }
  4549. async init(type = 'all') {
  4550. try {
  4551. if (globalOptions.ASF.AsfEnabled && globalOptions.ASF.AsfIpcUrl && globalOptions.ASF.AsfIpcPassword) {
  4552. this.#ASF = new social_SteamASF();
  4553. if (await this.#ASF.init()) {
  4554. this.#storeInitialized = true;
  4555. this.#communityInitialized = true;
  4556. return true;
  4557. }
  4558. return false;
  4559. }
  4560. if (type === 'store') {
  4561. if (this.#storeInitialized) {
  4562. return true;
  4563. }
  4564. let storeInitialized = await this.#updateStoreAuth();
  4565. if (!storeInitialized) {
  4566. storeInitialized = await this.#updateStoreAuthTab();
  4567. }
  4568. this.#storeInitialized = storeInitialized;
  4569. if (!this.#storeInitialized) {
  4570. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4571. return false;
  4572. }
  4573. scripts_echoLog({}).success(i18n('initSuccess', 'SteamStore'));
  4574. return true;
  4575. }
  4576. if (type === 'community') {
  4577. if (this.#communityInitialized) {
  4578. return true;
  4579. }
  4580. let communityInitialized = await this.#getUserLink();
  4581. if (!communityInitialized) {
  4582. communityInitialized = await this.#updateCommunityAuthTab();
  4583. }
  4584. this.#communityInitialized = communityInitialized;
  4585. if (!this.#communityInitialized) {
  4586. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4587. return false;
  4588. }
  4589. scripts_echoLog({}).success(i18n('initSuccess', 'SteamCommunity'));
  4590. return true;
  4591. }
  4592. if (this.#storeInitialized && this.#communityInitialized) {
  4593. scripts_echoLog({}).success(i18n('initSuccess', 'Steam'));
  4594. return true;
  4595. }
  4596. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4597. return false;
  4598. } catch (error) {
  4599. throwError(error, 'Steam.init');
  4600. return false;
  4601. }
  4602. }
  4603. async #refreshToken(type = 'steamStore') {
  4604. try {
  4605. const host = {
  4606. steamStore: 'store.steampowered.com',
  4607. steamCommunity: 'steamcommunity.com'
  4608. };
  4609. const logStatus = scripts_echoLog({
  4610. text: i18n('refreshingToken', i18n(type))
  4611. });
  4612. const formData = new FormData();
  4613. formData.append('redir', `https://${host[type]}/`);
  4614. const {
  4615. result,
  4616. statusText,
  4617. status,
  4618. data
  4619. } = await tools_httpRequest({
  4620. url: 'https://login.steampowered.com/jwt/ajaxrefresh',
  4621. method: 'POST',
  4622. responseType: 'json',
  4623. headers: {
  4624. Host: 'login.steampowered.com',
  4625. Origin: `https://${host[type]}`,
  4626. Referer: `https://${host[type]}/`
  4627. },
  4628. data: formData
  4629. });
  4630. if (result === 'Success') {
  4631. if (data?.response?.success) {
  4632. if (await this.#setStoreToken(data.response, type)) {
  4633. logStatus.success();
  4634. return true;
  4635. }
  4636. logStatus.error('Error');
  4637. return false;
  4638. }
  4639. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4640. return false;
  4641. }
  4642. logStatus.error(`${result}:${statusText}(${status})`);
  4643. return false;
  4644. } catch (error) {
  4645. throwError(error, 'Steam.refreshToken');
  4646. return false;
  4647. }
  4648. }
  4649. async #setStoreToken(param, type) {
  4650. try {
  4651. const host = {
  4652. steamStore: 'store.steampowered.com',
  4653. steamCommunity: 'steamcommunity.com'
  4654. };
  4655. const logStatus = scripts_echoLog({
  4656. text: i18n('settingToken', i18n(type))
  4657. });
  4658. const formData = new FormData();
  4659. formData.append('steamID', param.steamID);
  4660. formData.append('nonce', param.nonce);
  4661. formData.append('redir', param.redir);
  4662. formData.append('auth', param.auth);
  4663. const {
  4664. result,
  4665. statusText,
  4666. status,
  4667. data
  4668. } = await tools_httpRequest({
  4669. url: `https://${host[type]}/login/settoken`,
  4670. method: 'POST',
  4671. headers: {
  4672. Accept: 'application/json, text/plain, */*',
  4673. Host: host[type],
  4674. Origin: `https://${host[type]}`
  4675. },
  4676. data: formData
  4677. });
  4678. if (result === 'Success') {
  4679. if (data?.status === 200) {
  4680. logStatus.success();
  4681. return true;
  4682. }
  4683. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4684. return false;
  4685. }
  4686. logStatus.error(`${result}:${statusText}(${status})`);
  4687. return false;
  4688. } catch (error) {
  4689. throwError(error, 'Steam.setStoreToken');
  4690. return false;
  4691. }
  4692. }
  4693. async #updateStoreAuth(retry = false) {
  4694. try {
  4695. const logStatus = scripts_echoLog({
  4696. text: i18n('updatingAuth', i18n('steamStore'))
  4697. });
  4698. const {
  4699. result,
  4700. statusText,
  4701. status,
  4702. data
  4703. } = await tools_httpRequest({
  4704. url: 'https://store.steampowered.com/',
  4705. method: 'GET',
  4706. headers: {
  4707. 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',
  4708. 'Cache-Control': 'max-age=0',
  4709. 'Sec-Fetch-Dest': 'document',
  4710. 'Sec-Fetch-Mode': 'navigate',
  4711. 'Upgrade-Insecure-Requests': '1'
  4712. },
  4713. fetch: false,
  4714. redirect: 'manual'
  4715. });
  4716. if (data?.status === 200) {
  4717. if (!data.responseText.includes('data-miniprofile=')) {
  4718. if (await this.#refreshToken('steamStore')) {
  4719. logStatus.warning(i18n('retry'));
  4720. if (retry) {
  4721. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4722. return false;
  4723. }
  4724. return this.#updateStoreAuth(true);
  4725. }
  4726. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4727. return false;
  4728. }
  4729. const storeSessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4730. if (storeSessionID) {
  4731. this.#auth.storeSessionID = storeSessionID;
  4732. logStatus.success();
  4733. return true;
  4734. }
  4735. logStatus.error('Error: Get "sessionID" failed');
  4736. return false;
  4737. }
  4738. if ([ 301, 302 ].includes(data?.status)) {
  4739. if (await this.#refreshToken('steamStore')) {
  4740. logStatus.warning(i18n('retry'));
  4741. if (retry) {
  4742. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4743. return false;
  4744. }
  4745. return this.#updateStoreAuth(true);
  4746. }
  4747. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4748. return false;
  4749. }
  4750. logStatus.error(`${result}:${statusText}(${status})`);
  4751. return false;
  4752. } catch (error) {
  4753. throwError(error, 'Steam.updateStoreAuth');
  4754. return false;
  4755. }
  4756. }
  4757. async #updateStoreAuthTab() {
  4758. try {
  4759. const logStatus = scripts_echoLog({
  4760. text: i18n('updatingAuth', i18n('steamStore'))
  4761. });
  4762. return await new Promise(resolve => {
  4763. const newTab = window.open('https://store.steampowered.com/', 'mozillaWindow', 'pop=1;');
  4764. GM_setValue('steamStoreAuth', 'update');
  4765. const listenerId = GM_addValueChangeListener('steamStoreAuth', (key, oldValue, newValue, remote) => {
  4766. GM_removeValueChangeListener(listenerId);
  4767. newTab?.close();
  4768. if (newValue && JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
  4769. this.#auth.storeSessionID = newValue.storeSessionID;
  4770. logStatus.success();
  4771. resolve(true);
  4772. return;
  4773. }
  4774. logStatus.error('Failed');
  4775. resolve(false);
  4776. });
  4777. });
  4778. } catch (error) {
  4779. throwError(error, 'Steam.updateStoreAuthTab');
  4780. return false;
  4781. }
  4782. }
  4783. async #updateCommunityAuthTab() {
  4784. try {
  4785. const logStatus = scripts_echoLog({
  4786. text: i18n('updatingAuth', i18n('steamCommunity'))
  4787. });
  4788. return await new Promise(resolve => {
  4789. const newTab = window.open('https://steamcommunity.com/my', 'mozillaWindow', 'pop=1;');
  4790. GM_setValue('steamCommunityAuth', 'update');
  4791. const listenerId = GM_addValueChangeListener('steamCommunityAuth', (key, oldValue, newValue, remote) => {
  4792. GM_removeValueChangeListener(listenerId);
  4793. newTab?.close();
  4794. if (newValue && JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
  4795. this.#auth.steam64Id = newValue.steam64Id;
  4796. this.#auth.userName = newValue.userName;
  4797. this.#auth.communitySessionID = newValue.communitySessionID;
  4798. logStatus.success();
  4799. resolve(true);
  4800. return;
  4801. }
  4802. logStatus.error('Failed');
  4803. resolve(false);
  4804. });
  4805. });
  4806. } catch (error) {
  4807. throwError(error, 'Steam.updateCommunityAuthTab');
  4808. return false;
  4809. }
  4810. }
  4811. async #getUserLink(retry = false) {
  4812. try {
  4813. const logStatus = scripts_echoLog({
  4814. text: i18n('gettingUserLink')
  4815. });
  4816. const {
  4817. result,
  4818. statusText,
  4819. status,
  4820. data
  4821. } = await tools_httpRequest({
  4822. url: 'https://steamcommunity.com/my',
  4823. method: 'GET',
  4824. headers: {
  4825. 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',
  4826. 'Cache-Control': 'max-age=0',
  4827. 'Sec-Fetch-Dest': 'document',
  4828. 'Sec-Fetch-Mode': 'navigate',
  4829. 'Upgrade-Insecure-Requests': '1'
  4830. },
  4831. fetch: false,
  4832. redirect: 'manual'
  4833. });
  4834. if (data?.status === 200) {
  4835. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4836. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4837. return false;
  4838. }
  4839. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4840. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4841. const userName = data.responseText.match(/steamcommunity.com\/id\/(.+?)\/friends\//)?.[1];
  4842. if (steam64Id) {
  4843. this.#auth.steam64Id = steam64Id;
  4844. }
  4845. if (userName) {
  4846. this.#auth.userName = userName;
  4847. }
  4848. if (communitySessionID) {
  4849. this.#auth.communitySessionID = communitySessionID;
  4850. logStatus.success();
  4851. return true;
  4852. }
  4853. logStatus.error('Error: Get "sessionID" failed');
  4854. return false;
  4855. }
  4856. if (data?.status === 302) {
  4857. if (await this.#refreshToken('steamCommunity')) {
  4858. if (retry) {
  4859. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4860. return false;
  4861. }
  4862. logStatus.warning(i18n('retry'));
  4863. return this.#getUserLink(true);
  4864. }
  4865. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4866. return false;
  4867. }
  4868. const location = data?.responseHeaders?.split('\n')?.find(header => header.includes('location') ? header.replace('loctation:', '').trim() : null);
  4869. if (data?.status === 301 && location?.includes('steamcommunity.com/id')) {
  4870. logStatus.success();
  4871. return await this.#updateCommunityAuth(data.finalUrl);
  4872. }
  4873. if (data?.status === 301 && location?.includes('https://steamcommunity.com/login/home')) {
  4874. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4875. return false;
  4876. }
  4877. logStatus.error(`${result}:${statusText}(${status})`);
  4878. return false;
  4879. } catch (error) {
  4880. throwError(error, 'Steam.updateCommunityAuth');
  4881. return false;
  4882. }
  4883. }
  4884. async #updateCommunityAuth(url) {
  4885. try {
  4886. const logStatus = scripts_echoLog({
  4887. text: i18n('updatingAuth', i18n('steamCommunity'))
  4888. });
  4889. const {
  4890. result,
  4891. statusText,
  4892. status,
  4893. data
  4894. } = await tools_httpRequest({
  4895. url: url,
  4896. method: 'GET',
  4897. headers: {
  4898. 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',
  4899. 'Cache-Control': 'max-age=0',
  4900. 'Sec-Fetch-Dest': 'document',
  4901. 'Sec-Fetch-Mode': 'navigate',
  4902. 'Upgrade-Insecure-Requests': '1'
  4903. }
  4904. });
  4905. if (result === 'Success') {
  4906. if (data?.status === 200) {
  4907. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4908. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4909. return false;
  4910. }
  4911. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4912. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4913. const userName = data.responseText.match(/steamcommunity.com\/id\/(.+?)\/friends\//)?.[1];
  4914. if (steam64Id) {
  4915. this.#auth.steam64Id = steam64Id;
  4916. }
  4917. if (userName) {
  4918. this.#auth.userName = userName;
  4919. }
  4920. if (communitySessionID) {
  4921. this.#auth.communitySessionID = communitySessionID;
  4922. logStatus.success();
  4923. return true;
  4924. }
  4925. logStatus.error('Error: Get "sessionID" failed');
  4926. return false;
  4927. }
  4928. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4929. return false;
  4930. }
  4931. logStatus.error(`${result}:${statusText}(${status})`);
  4932. return false;
  4933. } catch (error) {
  4934. throwError(error, 'Steam.updateCommunityAuth');
  4935. return false;
  4936. }
  4937. }
  4938. async #getAreaInfo() {
  4939. try {
  4940. const logStatus = scripts_echoLog({
  4941. text: i18n('gettingAreaInfo')
  4942. });
  4943. const {
  4944. result,
  4945. statusText,
  4946. status,
  4947. data
  4948. } = await tools_httpRequest({
  4949. url: 'https://store.steampowered.com/cart/',
  4950. method: 'GET'
  4951. });
  4952. if (result === 'Success') {
  4953. if (data?.status === 200) {
  4954. const cartConfigRaw = data.responseText.match(/data-cart_config="(.*?)"/)?.[1];
  4955. const temp = document.createElement('div');
  4956. temp.innerHTML = cartConfigRaw || '{}';
  4957. const cartConfigStr = temp.textContent || temp.innerText;
  4958. let cartConfig;
  4959. try {
  4960. cartConfig = JSON.parse(cartConfigStr);
  4961. } catch (error) {
  4962. logStatus.error('Error: get country info filed');
  4963. console.error(error);
  4964. return {};
  4965. }
  4966. if (!cartConfig.rgUserCountryOptions) {
  4967. logStatus.warning('Warning: Area cannot be changed');
  4968. return {};
  4969. }
  4970. const userInfoRaw = data.responseText.match(/data-userinfo="(.*?)"/)?.[1];
  4971. const temp1 = document.createElement('div');
  4972. temp1.innerHTML = userInfoRaw || '{}';
  4973. const userInfoStr = temp1.textContent || temp1.innerText;
  4974. let userInfo;
  4975. try {
  4976. userInfo = JSON.parse(userInfoStr);
  4977. } catch (error) {
  4978. logStatus.error('Error: get country info filed');
  4979. console.error(error);
  4980. return {};
  4981. }
  4982. const currentArea = userInfo.country_code;
  4983. const areas = Object.keys(cartConfig.rgUserCountryOptions).filter(area => area !== 'help');
  4984. if (currentArea && areas.length > 0) {
  4985. this.#area = currentArea;
  4986. logStatus.success();
  4987. return {
  4988. currentArea: currentArea,
  4989. areas: areas
  4990. };
  4991. }
  4992. logStatus.error('Error: get country info filed');
  4993. return {};
  4994. }
  4995. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4996. return {};
  4997. }
  4998. logStatus.error(`${result}:${statusText}(${status})`);
  4999. return {};
  5000. } catch (error) {
  5001. throwError(error, 'Steam.getAreaInfo');
  5002. return {};
  5003. }
  5004. }
  5005. async #changeArea(area) {
  5006. try {
  5007. if (this.#areaStatus === 'waiting') {
  5008. await new Promise(resolve => {
  5009. const checker = setInterval(() => {
  5010. if (this.#areaStatus !== 'waiting') {
  5011. clearInterval(checker);
  5012. resolve(true);
  5013. }
  5014. });
  5015. });
  5016. }
  5017. if (this.#area === area || !area && this.#area !== 'CN') {
  5018. return true;
  5019. }
  5020. this.#areaStatus = 'waiting';
  5021. let aimedArea = area;
  5022. if (!aimedArea) {
  5023. const {
  5024. currentArea,
  5025. areas
  5026. } = await this.#getAreaInfo();
  5027. if (!currentArea || !areas) {
  5028. this.#areaStatus = 'error';
  5029. return false;
  5030. }
  5031. if (currentArea !== 'CN') {
  5032. this.#areaStatus = 'skip';
  5033. scripts_echoLog({
  5034. text: 'notNeededChangeArea'
  5035. });
  5036. return 'skip';
  5037. }
  5038. const anotherArea = areas.filter(area => area && area !== 'CN');
  5039. if (!anotherArea || anotherArea.length === 0) {
  5040. this.#areaStatus = 'noAnotherArea';
  5041. scripts_echoLog({
  5042. text: 'noAnotherArea'
  5043. });
  5044. return false;
  5045. }
  5046. [ aimedArea ] = anotherArea;
  5047. }
  5048. const logStatus = scripts_echoLog({
  5049. text: i18n('changingArea', aimedArea)
  5050. });
  5051. const {
  5052. result,
  5053. statusText,
  5054. status,
  5055. data
  5056. } = await tools_httpRequest({
  5057. url: 'https://store.steampowered.com/country/setcountry',
  5058. method: 'POST',
  5059. headers: {
  5060. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5061. },
  5062. data: $.param({
  5063. cc: aimedArea,
  5064. sessionid: this.#auth.storeSessionID
  5065. })
  5066. });
  5067. if (result === 'Success') {
  5068. if (data?.status === 200 && data.responseText === 'true') {
  5069. const {
  5070. currentArea
  5071. } = await this.#getAreaInfo();
  5072. if (currentArea === aimedArea) {
  5073. this.#areaStatus = 'success';
  5074. logStatus.success();
  5075. return currentArea;
  5076. }
  5077. this.#areaStatus = 'error';
  5078. logStatus.error('Error: change country filed');
  5079. return 'CN';
  5080. }
  5081. this.#areaStatus = 'error';
  5082. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5083. return 'CN';
  5084. }
  5085. this.#areaStatus = 'error';
  5086. logStatus.error(`${result}:${statusText}(${status})`);
  5087. return 'CN';
  5088. } catch (error) {
  5089. this.#areaStatus = 'error';
  5090. throwError(error, 'Steam.changeArea');
  5091. return false;
  5092. }
  5093. }
  5094. async #joinGroup(groupName) {
  5095. try {
  5096. if (this.#ASF) {
  5097. if (await this.#ASF.joinGroup(groupName)) {
  5098. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5099. return true;
  5100. }
  5101. return false;
  5102. }
  5103. const logStatus = scripts_echoLog({
  5104. type: 'joiningSteamGroup',
  5105. text: groupName
  5106. });
  5107. const {
  5108. result,
  5109. statusText,
  5110. status,
  5111. data
  5112. } = await tools_httpRequest({
  5113. url: `https://steamcommunity.com/groups/${groupName}`,
  5114. method: 'POST',
  5115. headers: {
  5116. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5117. },
  5118. data: $.param({
  5119. action: 'join',
  5120. sessionID: this.#auth.communitySessionID
  5121. })
  5122. });
  5123. if (result === 'Success') {
  5124. if (data?.status === 200 && !data.responseText.includes('grouppage_join_area')) {
  5125. logStatus.success();
  5126. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5127. return true;
  5128. }
  5129. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5130. return false;
  5131. }
  5132. logStatus.error(`${result}:${statusText}(${status})`);
  5133. return false;
  5134. } catch (error) {
  5135. throwError(error, 'Steam.joinGroup');
  5136. return false;
  5137. }
  5138. }
  5139. async #leaveGroup(groupName) {
  5140. try {
  5141. if (this.whiteList.groups.includes(groupName)) {
  5142. scripts_echoLog({
  5143. type: 'whiteList',
  5144. text: 'Steam.leaveGroup',
  5145. id: groupName
  5146. });
  5147. return true;
  5148. }
  5149. if (this.#ASF) {
  5150. return await this.#ASF.leaveGroup(groupName);
  5151. }
  5152. const groupId = await this.#getGroupId(groupName);
  5153. if (!groupId) {
  5154. return false;
  5155. }
  5156. const logStatus = scripts_echoLog({
  5157. type: 'leavingSteamGroup',
  5158. text: groupName
  5159. });
  5160. const {
  5161. result,
  5162. statusText,
  5163. status,
  5164. data
  5165. } = await tools_httpRequest({
  5166. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5167. method: 'POST',
  5168. headers: {
  5169. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5170. },
  5171. data: $.param({
  5172. sessionID: this.#auth.communitySessionID,
  5173. action: 'leaveGroup',
  5174. groupId: groupId
  5175. })
  5176. });
  5177. if (result === 'Success') {
  5178. 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) {
  5179. logStatus.success();
  5180. return true;
  5181. }
  5182. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5183. return false;
  5184. }
  5185. logStatus.error(`${result}:${statusText}(${status})`);
  5186. return false;
  5187. } catch (error) {
  5188. throwError(error, 'Steam.leaveGroup');
  5189. return false;
  5190. }
  5191. }
  5192. async #getGroupId(groupName) {
  5193. try {
  5194. const logStatus = scripts_echoLog({
  5195. type: 'gettingSteamGroupId',
  5196. text: groupName
  5197. });
  5198. const groupId = this.#cache.group[groupName];
  5199. if (groupId) {
  5200. logStatus.success();
  5201. return groupId;
  5202. }
  5203. const {
  5204. result,
  5205. statusText,
  5206. status,
  5207. data
  5208. } = await tools_httpRequest({
  5209. url: `https://steamcommunity.com/groups/${groupName}`,
  5210. method: 'GET',
  5211. headers: {
  5212. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5213. }
  5214. });
  5215. if (result === 'Success') {
  5216. if (data?.status === 200) {
  5217. const groupId = data.responseText.match(/OpenGroupChat\( '([0-9]+)'/)?.[1];
  5218. if (groupId) {
  5219. this.#setCache('group', groupName, groupId);
  5220. logStatus.success();
  5221. return groupId;
  5222. }
  5223. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5224. return false;
  5225. }
  5226. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5227. return false;
  5228. }
  5229. logStatus.error(`${result}:${statusText}(${status})`);
  5230. return false;
  5231. } catch (error) {
  5232. throwError(error, 'Steam.getGroupID');
  5233. return false;
  5234. }
  5235. }
  5236. async #joinOfficialGroup(gameId) {
  5237. try {
  5238. if (this.#ASF) {
  5239. if (await this.#ASF.joinGroup(gameId)) {
  5240. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5241. return true;
  5242. }
  5243. return false;
  5244. }
  5245. const logStatus = scripts_echoLog({
  5246. type: 'joiningSteamOfficialGroup',
  5247. text: gameId
  5248. });
  5249. const {
  5250. result,
  5251. statusText,
  5252. status,
  5253. data
  5254. } = await tools_httpRequest({
  5255. url: `https://steamcommunity.com/games/${gameId}?action=join&sessionID=${this.#auth.communitySessionID}`,
  5256. method: 'GET',
  5257. headers: {
  5258. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5259. }
  5260. });
  5261. if (result === 'Success') {
  5262. if (data?.status === 200 && !data.responseText.includes('id="publicGroupJoin"')) {
  5263. logStatus.success();
  5264. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5265. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5266. if (groupId) {
  5267. this.#setCache('officialGroup', gameId, groupId);
  5268. }
  5269. return true;
  5270. }
  5271. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5272. return false;
  5273. }
  5274. logStatus.error(`${result}:${statusText}(${status})`);
  5275. return false;
  5276. } catch (error) {
  5277. throwError(error, 'Steam.joinOfficialGroup');
  5278. return false;
  5279. }
  5280. }
  5281. async #leaveOfficialGroup(gameId) {
  5282. try {
  5283. if (this.whiteList.officialGroups.includes(gameId)) {
  5284. scripts_echoLog({
  5285. type: 'whiteList',
  5286. text: 'Steam.leaveOfficialGroup',
  5287. id: gameId
  5288. });
  5289. return true;
  5290. }
  5291. if (this.#ASF) {
  5292. return await this.#ASF.leaveGroup(gameId);
  5293. }
  5294. const groupId = await this.#getOfficialGroupId(gameId);
  5295. if (!groupId) {
  5296. return false;
  5297. }
  5298. const logStatus = scripts_echoLog({
  5299. type: 'leavingSteamOfficialGroup',
  5300. text: gameId
  5301. });
  5302. const {
  5303. result,
  5304. statusText,
  5305. status,
  5306. data
  5307. } = await tools_httpRequest({
  5308. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5309. method: 'POST',
  5310. headers: {
  5311. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5312. },
  5313. data: $.param({
  5314. sessionID: this.#auth.communitySessionID,
  5315. action: 'leaveGroup',
  5316. groupId: groupId
  5317. })
  5318. });
  5319. if (result === 'Success') {
  5320. if (data?.status === 200) {
  5321. const {
  5322. result: resultR,
  5323. statusText: statusTextR,
  5324. status: statusR,
  5325. data: dataR
  5326. } = await tools_httpRequest({
  5327. url: `https://steamcommunity.com/games/${gameId}`,
  5328. method: 'GET',
  5329. headers: {
  5330. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5331. }
  5332. });
  5333. if (resultR === 'Success') {
  5334. if (dataR?.status === 200 && dataR.responseText.includes('id="publicGroupJoin"')) {
  5335. logStatus.success();
  5336. return true;
  5337. }
  5338. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5339. return false;
  5340. }
  5341. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5342. return false;
  5343. }
  5344. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5345. return false;
  5346. }
  5347. logStatus.error(`${result}:${statusText}(${status})`);
  5348. return false;
  5349. } catch (error) {
  5350. throwError(error, 'Steam.leaveOfficialGroup');
  5351. return false;
  5352. }
  5353. }
  5354. async #getOfficialGroupId(gameId) {
  5355. try {
  5356. const logStatus = scripts_echoLog({
  5357. type: 'gettingSteamOfficialGroupId',
  5358. text: gameId
  5359. });
  5360. const groupId = this.#cache.officialGroup[gameId];
  5361. if (groupId) {
  5362. logStatus.success();
  5363. return groupId;
  5364. }
  5365. const {
  5366. result,
  5367. statusText,
  5368. status,
  5369. data
  5370. } = await tools_httpRequest({
  5371. url: `https://steamcommunity.com/games/${gameId}`,
  5372. method: 'GET',
  5373. headers: {
  5374. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5375. }
  5376. });
  5377. if (result === 'Success') {
  5378. if (data?.status === 200) {
  5379. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5380. if (groupId) {
  5381. this.#setCache('officialGroup', gameId, groupId);
  5382. logStatus.success();
  5383. return groupId;
  5384. }
  5385. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5386. return false;
  5387. }
  5388. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5389. return false;
  5390. }
  5391. logStatus.error(`${result}:${statusText}(${status})`);
  5392. return false;
  5393. } catch (error) {
  5394. throwError(error, 'Steam.getGroupID');
  5395. return false;
  5396. }
  5397. }
  5398. async #addToWishlist(gameId) {
  5399. try {
  5400. if (this.#ASF) {
  5401. if (await this.#ASF.addToWishlist(gameId)) {
  5402. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5403. return true;
  5404. }
  5405. return false;
  5406. }
  5407. const logStatus = scripts_echoLog({
  5408. type: 'addingToWishlist',
  5409. text: gameId
  5410. });
  5411. const {
  5412. result,
  5413. data
  5414. } = await tools_httpRequest({
  5415. url: 'https://store.steampowered.com/api/addtowishlist',
  5416. method: 'POST',
  5417. headers: {
  5418. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5419. },
  5420. data: $.param({
  5421. sessionid: this.#auth.storeSessionID,
  5422. appid: gameId
  5423. }),
  5424. dataType: 'json'
  5425. });
  5426. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5427. logStatus.success();
  5428. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5429. return true;
  5430. }
  5431. const {
  5432. result: resultR,
  5433. statusText: statusTextR,
  5434. status: statusR,
  5435. data: dataR
  5436. } = await tools_httpRequest({
  5437. url: `https://store.steampowered.com/app/${gameId}`,
  5438. method: 'GET'
  5439. });
  5440. if (resultR === 'Success') {
  5441. if (dataR?.status === 200) {
  5442. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5443. logStatus.warning(i18n('changeAreaNotice'));
  5444. if (!await this.#changeArea()) {
  5445. return false;
  5446. }
  5447. return await this.#addToWishlist(gameId);
  5448. }
  5449. if (dataR.responseText.includes('class="queue_actions_ctn"') && dataR.responseText.includes('class="already_in_library"')) {
  5450. logStatus.success();
  5451. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5452. return true;
  5453. } 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"')) {
  5454. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5455. return false;
  5456. }
  5457. logStatus.success();
  5458. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5459. return true;
  5460. }
  5461. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5462. return false;
  5463. }
  5464. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5465. return false;
  5466. } catch (error) {
  5467. throwError(error, 'Steam.addToWishlist');
  5468. return false;
  5469. }
  5470. }
  5471. async #removeFromWishlist(gameId) {
  5472. try {
  5473. if (this.whiteList.wishlists.includes(gameId)) {
  5474. scripts_echoLog({
  5475. type: 'whiteList',
  5476. text: 'Steam.removeFromWishlist',
  5477. id: gameId
  5478. });
  5479. return true;
  5480. }
  5481. if (this.#ASF) {
  5482. return await this.#ASF.removeFromWishlist(gameId);
  5483. }
  5484. const logStatus = scripts_echoLog({
  5485. type: 'removingFromWishlist',
  5486. text: gameId
  5487. });
  5488. const {
  5489. result,
  5490. data
  5491. } = await tools_httpRequest({
  5492. url: 'https://store.steampowered.com/api/removefromwishlist',
  5493. method: 'POST',
  5494. headers: {
  5495. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5496. },
  5497. data: $.param({
  5498. sessionid: this.#auth.storeSessionID,
  5499. appid: gameId
  5500. }),
  5501. dataType: 'json'
  5502. });
  5503. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5504. logStatus.success();
  5505. return true;
  5506. }
  5507. const {
  5508. result: resultR,
  5509. statusText: statusTextR,
  5510. status: statusR,
  5511. data: dataR
  5512. } = await tools_httpRequest({
  5513. url: `https://store.steampowered.com/app/${gameId}`,
  5514. method: 'GET'
  5515. });
  5516. if (resultR === 'Success') {
  5517. if (dataR?.status === 200) {
  5518. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5519. logStatus.warning(i18n('changeAreaNotice'));
  5520. const result = await this.#changeArea();
  5521. if (!result || result === 'CN' || result === 'skip') {
  5522. return false;
  5523. }
  5524. return await this.#removeFromWishlist(gameId);
  5525. }
  5526. if (dataR.responseText.includes('class="queue_actions_ctn"') && (dataR.responseText.includes('ds_owned_flag ds_flag') || dataR.responseText.includes('add_to_wishlist_area'))) {
  5527. logStatus.success();
  5528. return true;
  5529. }
  5530. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5531. return false;
  5532. }
  5533. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5534. return false;
  5535. }
  5536. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5537. return false;
  5538. } catch (error) {
  5539. throwError(error, 'Steam.removeFromWishlist');
  5540. return false;
  5541. }
  5542. }
  5543. async #toggleFollowGame(gameId, doTask) {
  5544. try {
  5545. if (!doTask && this.whiteList.follows.includes(gameId)) {
  5546. scripts_echoLog({
  5547. type: 'whiteList',
  5548. text: 'Steam.unfollowGame',
  5549. id: gameId
  5550. });
  5551. return true;
  5552. }
  5553. if (this.#ASF) {
  5554. if (await this.#ASF.toggleFollowGame(gameId, doTask)) {
  5555. if (doTask) {
  5556. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5557. }
  5558. return true;
  5559. }
  5560. return false;
  5561. }
  5562. const logStatus = scripts_echoLog({
  5563. type: `${doTask ? '' : 'un'}followingGame`,
  5564. text: gameId
  5565. });
  5566. const requestData = {
  5567. sessionid: this.#auth.storeSessionID,
  5568. appid: gameId
  5569. };
  5570. if (!doTask) {
  5571. requestData.unfollow = '1';
  5572. }
  5573. const {
  5574. result,
  5575. data
  5576. } = await tools_httpRequest({
  5577. url: 'https://store.steampowered.com/explore/followgame/',
  5578. method: 'POST',
  5579. headers: {
  5580. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5581. },
  5582. data: $.param(requestData)
  5583. });
  5584. if (result === 'Success' && data?.status === 200 && data.responseText === 'true') {
  5585. logStatus.success();
  5586. return true;
  5587. }
  5588. const followed = await this.#isFollowedGame(gameId);
  5589. if (this.#area === 'CN' && followed === 'areaLocked') {
  5590. logStatus.warning(i18n('changeAreaNotice'));
  5591. if (!await this.#changeArea()) {
  5592. return false;
  5593. }
  5594. return await this.#removeFromWishlist(gameId);
  5595. }
  5596. if (doTask === followed) {
  5597. logStatus.success();
  5598. if (doTask) {
  5599. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5600. }
  5601. return true;
  5602. }
  5603. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5604. return false;
  5605. } catch (error) {
  5606. throwError(error, 'Steam.toggleFollowGame');
  5607. return false;
  5608. }
  5609. }
  5610. async #isFollowedGame(gameId) {
  5611. try {
  5612. const {
  5613. result,
  5614. data
  5615. } = await tools_httpRequest({
  5616. url: `https://store.steampowered.com/app/${gameId}`,
  5617. method: 'GET'
  5618. });
  5619. if (result === 'Success') {
  5620. if (data?.status === 200) {
  5621. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  5622. return 'areaLocked';
  5623. }
  5624. if ($(data.responseText.replace(/<img.*?>/g, '')).find('.queue_control_button.queue_btn_follow>.btnv6_blue_hoverfade.btn_medium.queue_btn_active').css('display') !== 'none') {
  5625. return true;
  5626. }
  5627. return false;
  5628. }
  5629. return false;
  5630. }
  5631. return false;
  5632. } catch (error) {
  5633. throwError(error, 'Steam.isFollowedGame');
  5634. return false;
  5635. }
  5636. }
  5637. async #toggleForum(gameId, doTask = true) {
  5638. try {
  5639. if (!doTask && this.whiteList.forums.includes(gameId)) {
  5640. scripts_echoLog({
  5641. type: 'whiteList',
  5642. text: 'Steam.unsubscribeForum',
  5643. id: gameId
  5644. });
  5645. return true;
  5646. }
  5647. const forumId = await this.#getForumId(gameId);
  5648. if (!forumId) {
  5649. return false;
  5650. }
  5651. const logStatus = scripts_echoLog({
  5652. type: `${doTask ? '' : 'un'}subscribingForum`,
  5653. text: gameId
  5654. });
  5655. const [ id, feature ] = forumId.split('_');
  5656. const {
  5657. result,
  5658. statusText,
  5659. status,
  5660. data
  5661. } = await tools_httpRequest({
  5662. url: `https://steamcommunity.com/forum/${id}/General/${doTask ? '' : 'un'}subscribe/${feature || '0'}/`,
  5663. method: 'POST',
  5664. responseType: 'json',
  5665. headers: {
  5666. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5667. },
  5668. data: $.param({
  5669. sessionid: this.#auth.communitySessionID
  5670. })
  5671. });
  5672. if (result === 'Success') {
  5673. if (data?.status === 200 && (data.response?.success === 1 || data.response?.success === 29)) {
  5674. if (doTask) {
  5675. this.tasks.forums = unique([ ...this.tasks.forums, gameId ]);
  5676. }
  5677. logStatus.success();
  5678. return true;
  5679. }
  5680. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5681. return true;
  5682. }
  5683. logStatus.error(`${result}:${statusText}(${status})`);
  5684. return true;
  5685. } catch (error) {
  5686. throwError(error, 'Steam.toggleForum');
  5687. return true;
  5688. }
  5689. }
  5690. async #getForumId(gameId) {
  5691. try {
  5692. const logStatus = scripts_echoLog({
  5693. type: 'gettingForumId',
  5694. text: gameId
  5695. });
  5696. const forumId = this.#cache.forum[gameId];
  5697. if (forumId) {
  5698. logStatus.success();
  5699. return forumId;
  5700. }
  5701. const {
  5702. result,
  5703. statusText,
  5704. status,
  5705. data
  5706. } = await tools_httpRequest({
  5707. url: `https://steamcommunity.com/app/${gameId}/discussions/`,
  5708. method: 'GET'
  5709. });
  5710. if (result === 'Success') {
  5711. if (data?.status === 200) {
  5712. const forumId = data.responseText?.match(/General_([\d]+(_[\d]+)?)/)?.[1];
  5713. if (forumId) {
  5714. this.#setCache('forum', gameId, forumId);
  5715. logStatus.success();
  5716. return forumId;
  5717. }
  5718. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5719. return false;
  5720. }
  5721. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5722. return false;
  5723. }
  5724. logStatus.error(`${result}:${statusText}(${status})`);
  5725. return false;
  5726. } catch (error) {
  5727. throwError(error, 'Steam.getForumId');
  5728. return false;
  5729. }
  5730. }
  5731. async #toggleFavoriteWorkshop(id, doTask = true) {
  5732. try {
  5733. if (!doTask && this.whiteList.workshops.includes(id)) {
  5734. scripts_echoLog({
  5735. type: 'whiteList',
  5736. text: 'Steam.unfavoriteWorkshop',
  5737. id: id
  5738. });
  5739. return true;
  5740. }
  5741. const appid = await this.#getWorkshopAppId(id);
  5742. if (!appid) {
  5743. return false;
  5744. }
  5745. const logStatus = scripts_echoLog({
  5746. type: doTask ? 'favoritingWorkshop' : 'unfavoritingWorkshop',
  5747. text: id
  5748. });
  5749. const {
  5750. result,
  5751. statusText,
  5752. status,
  5753. data
  5754. } = await tools_httpRequest({
  5755. url: `https://steamcommunity.com/sharedfiles/${doTask ? '' : 'un'}favorite`,
  5756. method: 'POST',
  5757. headers: {
  5758. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5759. },
  5760. data: $.param({
  5761. id: id,
  5762. appid: appid,
  5763. sessionid: this.#auth.communitySessionID
  5764. })
  5765. });
  5766. if (result === 'Success') {
  5767. if (data?.status === 200 && !data.responseText) {
  5768. if (doTask) {
  5769. this.tasks.workshops = unique([ ...this.tasks.workshops, id ]);
  5770. }
  5771. logStatus.success();
  5772. return true;
  5773. }
  5774. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5775. return false;
  5776. }
  5777. logStatus.error(`${result}:${statusText}(${status})`);
  5778. return false;
  5779. } catch (error) {
  5780. throwError(error, 'Steam.toggleFavoriteWorkshop');
  5781. return false;
  5782. }
  5783. }
  5784. async #getWorkshopAppId(id) {
  5785. try {
  5786. const logStatus = scripts_echoLog({
  5787. type: 'gettingWorkshopAppId',
  5788. text: id
  5789. });
  5790. const appId = this.#cache.workshop[id];
  5791. if (appId) {
  5792. logStatus.success();
  5793. return appId;
  5794. }
  5795. const {
  5796. result,
  5797. statusText,
  5798. status,
  5799. data
  5800. } = await tools_httpRequest({
  5801. url: `https://steamcommunity.com/sharedfiles/filedetails/?id=${id}`,
  5802. method: 'GET'
  5803. });
  5804. if (result === 'Success') {
  5805. if (data?.status === 200) {
  5806. const appId = data.responseText.match(/<input type="hidden" name="appid" value="([\d]+?)" \/>/)?.[1];
  5807. if (appId) {
  5808. this.#setCache('workshop', id, appId);
  5809. logStatus.success();
  5810. return appId;
  5811. }
  5812. logStatus.error('Error: getWorkshopAppId failed');
  5813. return false;
  5814. }
  5815. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5816. return false;
  5817. }
  5818. logStatus.error(`${result}:${statusText}(${status})`);
  5819. return false;
  5820. } catch (error) {
  5821. throwError(error, 'Steam.getWorkshopAppId');
  5822. return false;
  5823. }
  5824. }
  5825. async #voteUpWorkshop(id) {
  5826. try {
  5827. const logStatus = scripts_echoLog({
  5828. type: 'votingUpWorkshop',
  5829. text: id
  5830. });
  5831. const {
  5832. result,
  5833. statusText,
  5834. status,
  5835. data
  5836. } = await tools_httpRequest({
  5837. url: 'https://steamcommunity.com/sharedfiles/voteup',
  5838. method: 'POST',
  5839. responseType: 'json',
  5840. headers: {
  5841. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5842. },
  5843. data: $.param({
  5844. id: id,
  5845. sessionid: this.#auth.communitySessionID
  5846. })
  5847. });
  5848. if (result === 'Success') {
  5849. if (data?.status === 200 && data.response?.success === 1) {
  5850. logStatus.success();
  5851. return true;
  5852. }
  5853. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5854. return true;
  5855. }
  5856. logStatus.error(`${result}:${statusText}(${status})`);
  5857. return true;
  5858. } catch (error) {
  5859. throwError(error, 'Steam.voteupWorkshop');
  5860. return true;
  5861. }
  5862. }
  5863. async #toggleCurator(curatorId, doTask = true) {
  5864. try {
  5865. if (!doTask && this.whiteList.curators.includes(curatorId)) {
  5866. scripts_echoLog({
  5867. type: 'whiteList',
  5868. text: 'Steam.unfollowCurator',
  5869. id: curatorId
  5870. });
  5871. return true;
  5872. }
  5873. if (this.#ASF) {
  5874. return await this.#ASF.toggleCurator(curatorId, doTask);
  5875. }
  5876. const logStatus = scripts_echoLog({
  5877. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  5878. text: curatorId
  5879. });
  5880. const {
  5881. result,
  5882. statusText,
  5883. status,
  5884. data
  5885. } = await tools_httpRequest({
  5886. url: 'https://store.steampowered.com/curators/ajaxfollow',
  5887. method: 'POST',
  5888. headers: {
  5889. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5890. },
  5891. data: $.param({
  5892. clanid: curatorId,
  5893. sessionid: this.#auth.storeSessionID,
  5894. follow: doTask
  5895. }),
  5896. dataType: 'json'
  5897. });
  5898. if (result === 'Success') {
  5899. if (data?.status === 200 && data.response?.success?.success === 1) {
  5900. logStatus.success();
  5901. return true;
  5902. }
  5903. logStatus.error(`Error:${data?.statusText}(${data?.response?.success}` || `${data?.status})`);
  5904. return false;
  5905. }
  5906. logStatus.error(`${result}:${statusText}(${status})`);
  5907. return false;
  5908. } catch (error) {
  5909. throwError(error, 'Steam.toggleCurator');
  5910. return false;
  5911. }
  5912. }
  5913. async getCuratorId(path, name) {
  5914. try {
  5915. const logStatus = scripts_echoLog({
  5916. type: 'gettingCuratorId',
  5917. text: `${path}/${name}`
  5918. });
  5919. const curatorId = this.#cache.curator[`${path}/${name}`];
  5920. if (curatorId) {
  5921. logStatus.success();
  5922. return curatorId;
  5923. }
  5924. const {
  5925. result,
  5926. statusText,
  5927. status,
  5928. data
  5929. } = await tools_httpRequest({
  5930. url: `https://store.steampowered.com/${path}/${name}`,
  5931. method: 'GET',
  5932. headers: {
  5933. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5934. }
  5935. });
  5936. if (result === 'Success') {
  5937. if (data?.status === 200) {
  5938. const curatorId = data.responseText.match(/g_pagingData.*?"clanid":([\d]+)/)?.[1];
  5939. if (curatorId) {
  5940. this.#setCache('curator', `${path}/${name}`, curatorId);
  5941. logStatus.success();
  5942. return curatorId;
  5943. }
  5944. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5945. return false;
  5946. }
  5947. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5948. return false;
  5949. }
  5950. logStatus.error(`${result}:${statusText}(${status})`);
  5951. return false;
  5952. } catch (error) {
  5953. throwError(error, 'Steam.getCuratorID');
  5954. return false;
  5955. }
  5956. }
  5957. async #toggleCuratorLike(link, doTask = true) {
  5958. try {
  5959. const [ path, name ] = link.split('/');
  5960. if (!(path && name)) {
  5961. scripts_echoLog({
  5962. text: i18n('errorLink', link)
  5963. });
  5964. return false;
  5965. }
  5966. const curatorId = await this.getCuratorId(path, name);
  5967. if (curatorId) {
  5968. return await this.#toggleCurator(curatorId, doTask);
  5969. }
  5970. return false;
  5971. } catch (error) {
  5972. throwError(error, 'Steam.toggleCuratorLike');
  5973. return false;
  5974. }
  5975. }
  5976. async #getAnnouncementParams(appId, viewId) {
  5977. try {
  5978. const logStatus = scripts_echoLog({
  5979. type: 'gettingAnnouncementParams',
  5980. text: appId,
  5981. id: viewId
  5982. });
  5983. const {
  5984. result,
  5985. statusText,
  5986. status,
  5987. data
  5988. } = await tools_httpRequest({
  5989. 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`,
  5990. method: 'GET',
  5991. responseType: 'json',
  5992. headers: {
  5993. Host: 'store.steampowered.com',
  5994. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  5995. }
  5996. });
  5997. if (result === 'Success') {
  5998. if (data?.status === 200 && data?.response?.success === 1) {
  5999. const {
  6000. clanid,
  6001. gid
  6002. } = data.response.event?.announcement_body || {};
  6003. if (clanid) {
  6004. logStatus.success();
  6005. return {
  6006. clanId: clanid,
  6007. gid: gid
  6008. };
  6009. }
  6010. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6011. return {};
  6012. }
  6013. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6014. return {};
  6015. }
  6016. logStatus.error(`${result}:${statusText}(${status})`);
  6017. return {};
  6018. } catch (error) {
  6019. throwError(error, 'Steam.likeAnnouncement');
  6020. return {};
  6021. }
  6022. }
  6023. async #likeAnnouncement(id) {
  6024. try {
  6025. const [ appId, viewId ] = id.split('/');
  6026. if (!(appId && viewId)) {
  6027. scripts_echoLog({}).error(`${i18n('missParams')}(id)`);
  6028. return false;
  6029. }
  6030. const {
  6031. clanId,
  6032. gid
  6033. } = await this.#getAnnouncementParams(appId, viewId);
  6034. if (!clanId) {
  6035. return false;
  6036. }
  6037. const logStatus = scripts_echoLog({
  6038. type: 'likingAnnouncement',
  6039. text: appId,
  6040. id: viewId
  6041. });
  6042. const {
  6043. result,
  6044. statusText,
  6045. status,
  6046. data
  6047. } = await tools_httpRequest({
  6048. url: `https://store.steampowered.com/updated/ajaxrateupdate/${gid || viewId}`,
  6049. method: 'POST',
  6050. headers: {
  6051. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6052. Host: 'store.steampowered.com',
  6053. Origin: 'https://store.steampowered.com',
  6054. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  6055. },
  6056. data: $.param({
  6057. sessionid: this.#auth.storeSessionID,
  6058. voteup: 1,
  6059. clanid: clanId,
  6060. ajax: 1
  6061. }),
  6062. dataType: 'json'
  6063. });
  6064. if (result === 'Success') {
  6065. if (data?.status === 200 && data.response.success === 1) {
  6066. logStatus.success();
  6067. return true;
  6068. }
  6069. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6070. return false;
  6071. }
  6072. logStatus.error(`${result}:${statusText}(${status})`);
  6073. return false;
  6074. } catch (error) {
  6075. throwError(error, 'Steam.likeAnnouncement');
  6076. return false;
  6077. }
  6078. }
  6079. async #appid2subid(id) {
  6080. try {
  6081. const logStatus = scripts_echoLog({
  6082. type: 'gettingSubid',
  6083. text: id
  6084. });
  6085. const {
  6086. result,
  6087. statusText,
  6088. status,
  6089. data
  6090. } = await tools_httpRequest({
  6091. url: `https://store.steampowered.com/app/${id}`,
  6092. method: 'GET',
  6093. headers: {
  6094. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  6095. }
  6096. });
  6097. if (result === 'Success') {
  6098. if (data?.status === 200) {
  6099. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6100. logStatus.warning(i18n('changeAreaNotice'));
  6101. const result = await this.#changeArea();
  6102. if (!result || result === 'CN' || result === 'skip') {
  6103. return false;
  6104. }
  6105. return await this.#appid2subid(id);
  6106. }
  6107. const subid = data.responseText.match(/name="subid" value="([\d]+?)"/)?.[1];
  6108. if (subid) {
  6109. logStatus.success();
  6110. return subid;
  6111. }
  6112. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6113. return false;
  6114. }
  6115. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6116. return false;
  6117. }
  6118. logStatus.error(`${result}:${statusText}(${status})`);
  6119. return false;
  6120. } catch (error) {
  6121. throwError(error, 'Steam.appid2subid');
  6122. return false;
  6123. }
  6124. }
  6125. async #getLicenses() {
  6126. try {
  6127. const logStatus = scripts_echoLog({
  6128. text: i18n('gettingLicenses')
  6129. });
  6130. const {
  6131. result,
  6132. statusText,
  6133. status,
  6134. data
  6135. } = await tools_httpRequest({
  6136. url: `https://store.steampowered.com/dynamicstore/userdata/?t=${new Date().getTime()}`,
  6137. method: 'GET',
  6138. responseType: 'json'
  6139. });
  6140. if (result === 'Success') {
  6141. if (data?.status === 200) {
  6142. logStatus.success();
  6143. return data.response?.rgOwnedPackages;
  6144. }
  6145. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6146. return false;
  6147. }
  6148. logStatus.error(`${result}:${statusText}(${status})`);
  6149. return false;
  6150. } catch (error) {
  6151. throwError(error, 'Steam.getLicenses');
  6152. return false;
  6153. }
  6154. }
  6155. async #addLicense(id) {
  6156. try {
  6157. if (this.#ASF) {
  6158. return await this.#ASF.addLicense(id);
  6159. }
  6160. const [ type, ids ] = id.split('-');
  6161. if (type === 'appid') {
  6162. const subid = await this.#appid2subid(ids);
  6163. if (!subid) {
  6164. return false;
  6165. }
  6166. const logStatus = scripts_echoLog({
  6167. type: 'addingFreeLicense',
  6168. text: ids
  6169. });
  6170. if (!await this.#addFreeLicense(subid, logStatus)) {
  6171. return false;
  6172. }
  6173. const {
  6174. result,
  6175. statusText,
  6176. status,
  6177. data
  6178. } = await tools_httpRequest({
  6179. url: `https://store.steampowered.com/app/${ids}`,
  6180. method: 'GET'
  6181. });
  6182. if (result === 'Success') {
  6183. if (data?.status === 200) {
  6184. if (data.responseText.includes('ds_owned_flag ds_flag') || data.responseText.includes('class="already_in_library"')) {
  6185. logStatus.success();
  6186. return true;
  6187. }
  6188. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6189. return false;
  6190. }
  6191. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6192. return false;
  6193. }
  6194. logStatus.error(`${result}:${statusText}(${status})`);
  6195. return false;
  6196. } else if (type === 'subid') {
  6197. if (this.#area === 'CN') {
  6198. scripts_echoLog({}).success(i18n('tryChangeAreaNotice'));
  6199. await this.#changeArea();
  6200. }
  6201. const logStatusArr = {};
  6202. const idsArr = ids.split(',');
  6203. for (const subid of idsArr) {
  6204. const logStatus = scripts_echoLog({
  6205. type: 'addingFreeLicenseSubid',
  6206. text: subid
  6207. });
  6208. if (!await this.#addFreeLicense(subid, logStatus)) {
  6209. return false;
  6210. }
  6211. logStatusArr[subid] = logStatus;
  6212. }
  6213. const licenses = await this.#getLicenses();
  6214. if (!licenses) {
  6215. return false;
  6216. }
  6217. for (const subid of idsArr) {
  6218. if (licenses.includes(parseInt(subid, 10))) {
  6219. logStatusArr[subid].success();
  6220. } else {
  6221. logStatusArr[subid].error();
  6222. }
  6223. }
  6224. return true;
  6225. }
  6226. return false;
  6227. } catch (error) {
  6228. throwError(error, 'Steam.addLicense');
  6229. return false;
  6230. }
  6231. }
  6232. async #addFreeLicense(id, logStatusPre) {
  6233. try {
  6234. const logStatus = logStatusPre || scripts_echoLog({
  6235. type: 'addingFreeLicenseSubid',
  6236. text: id
  6237. });
  6238. const {
  6239. result,
  6240. statusText,
  6241. status,
  6242. data
  6243. } = await tools_httpRequest({
  6244. url: 'https://store.steampowered.com/checkout/addfreelicense',
  6245. method: 'POST',
  6246. headers: {
  6247. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6248. Host: 'store.steampowered.com',
  6249. Origin: 'https://store.steampowered.com',
  6250. Referer: 'https://store.steampowered.com/account/licenses/'
  6251. },
  6252. data: $.param({
  6253. action: 'add_to_cart',
  6254. sessionid: this.#auth.storeSessionID,
  6255. subid: id
  6256. }),
  6257. dataType: 'json'
  6258. });
  6259. if (result === 'Success') {
  6260. if (data?.status === 200) {
  6261. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6262. logStatus.warning(i18n('changeAreaNotice'));
  6263. const result = await this.#changeArea();
  6264. if (!result || result === 'CN') {
  6265. return false;
  6266. }
  6267. return await this.#addFreeLicense(id);
  6268. }
  6269. logStatus.success();
  6270. return true;
  6271. }
  6272. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6273. return false;
  6274. }
  6275. logStatus.error(`${result}:${statusText}(${status})`);
  6276. return false;
  6277. } catch (error) {
  6278. throwError(error, 'Steam.addFreeLicense');
  6279. return false;
  6280. }
  6281. }
  6282. async #requestPlayTestAccess(id) {
  6283. try {
  6284. if (this.#ASF) {
  6285. return await this.#ASF.requestPlayTestAccess(id);
  6286. }
  6287. const logStatus = scripts_echoLog({
  6288. type: 'requestingPlayTestAccess',
  6289. text: id
  6290. });
  6291. const {
  6292. result,
  6293. statusText,
  6294. status,
  6295. data
  6296. } = await tools_httpRequest({
  6297. url: `https://store.steampowered.com/ajaxrequestplaytestaccess/${id}`,
  6298. method: 'POST',
  6299. headers: {
  6300. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6301. Host: 'store.steampowered.com',
  6302. Origin: 'https://store.steampowered.com',
  6303. Referer: `https://store.steampowered.com/app/${id}`
  6304. },
  6305. data: $.param({
  6306. sessionid: this.#auth.storeSessionID
  6307. }),
  6308. dataType: 'json'
  6309. });
  6310. if (result === 'Success') {
  6311. if (data?.status === 200 && data?.response?.success === 1) {
  6312. logStatus.success();
  6313. return true;
  6314. }
  6315. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6316. return false;
  6317. }
  6318. logStatus.error(`${result}:${statusText}(${status})`);
  6319. return false;
  6320. } catch (error) {
  6321. throwError(error, 'Steam.requestPlayTestAccess');
  6322. return false;
  6323. }
  6324. }
  6325. async toggle({
  6326. doTask = true,
  6327. groupLinks = [],
  6328. officialGroupLinks = [],
  6329. wishlistLinks = [],
  6330. followLinks = [],
  6331. forumLinks = [],
  6332. workshopLinks = [],
  6333. workshopVoteLinks = [],
  6334. curatorLinks = [],
  6335. curatorLikeLinks = [],
  6336. announcementLinks = [],
  6337. licenseLinks = [],
  6338. playtestLinks = []
  6339. }) {
  6340. try {
  6341. if ([ ...groupLinks, ...officialGroupLinks, ...forumLinks, ...workshopLinks, ...workshopVoteLinks ].length > 0 && !this.#communityInitialized) {
  6342. scripts_echoLog({
  6343. text: i18n('needInit')
  6344. });
  6345. return false;
  6346. }
  6347. if ([ ...wishlistLinks, ...followLinks, ...curatorLinks, ...curatorLikeLinks, ...announcementLinks, ...licenseLinks, ...playtestLinks ].length > 0 && !this.#storeInitialized) {
  6348. scripts_echoLog({
  6349. text: i18n('needInit')
  6350. });
  6351. return false;
  6352. }
  6353. const prom = [];
  6354. if (doTask && !globalOptions.doTask.steam.groups || !doTask && !globalOptions.undoTask.steam.groups) {
  6355. scripts_echoLog({
  6356. type: 'globalOptionsSkip',
  6357. text: 'steam.groups'
  6358. });
  6359. } else {
  6360. const realGroups = this.getRealParams('groups', groupLinks, doTask, link => link.match(/groups\/(.+)\/?/)?.[1]);
  6361. if (realGroups.length > 0) {
  6362. for (const group of realGroups) {
  6363. if (doTask) {
  6364. prom.push(this.#joinGroup(group));
  6365. } else {
  6366. prom.push(this.#leaveGroup(group));
  6367. }
  6368. await delay(1e3);
  6369. }
  6370. }
  6371. }
  6372. if (doTask && !globalOptions.doTask.steam.officialGroups || !doTask && !globalOptions.undoTask.steam.officialGroups) {
  6373. scripts_echoLog({
  6374. type: 'globalOptionsSkip',
  6375. text: 'steam.officialGroups'
  6376. });
  6377. } else {
  6378. const realOfficialGroups = this.getRealParams('officialGroups', officialGroupLinks, doTask, link => link.match(/games\/(.+)\/?/)?.[1]);
  6379. if (realOfficialGroups.length > 0) {
  6380. for (const officialGroup of realOfficialGroups) {
  6381. if (doTask) {
  6382. prom.push(this.#joinOfficialGroup(officialGroup));
  6383. } else {
  6384. prom.push(this.#leaveOfficialGroup(officialGroup));
  6385. }
  6386. await delay(1e3);
  6387. }
  6388. }
  6389. }
  6390. if (doTask && !globalOptions.doTask.steam.wishlists || !doTask && !globalOptions.undoTask.steam.wishlists) {
  6391. scripts_echoLog({
  6392. type: 'globalOptionsSkip',
  6393. text: 'steam.wishlists'
  6394. });
  6395. } else {
  6396. const realWishlists = this.getRealParams('wishlists', wishlistLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6397. if (realWishlists.length > 0) {
  6398. for (const game of realWishlists) {
  6399. if (doTask) {
  6400. prom.push(this.#addToWishlist(game));
  6401. } else {
  6402. prom.push(this.#removeFromWishlist(game));
  6403. }
  6404. await delay(1e3);
  6405. }
  6406. }
  6407. }
  6408. if (doTask && !globalOptions.doTask.steam.follows || !doTask && !globalOptions.undoTask.steam.follows) {
  6409. scripts_echoLog({
  6410. type: 'globalOptionsSkip',
  6411. text: 'steam.follows'
  6412. });
  6413. } else {
  6414. const realFollows = this.getRealParams('follows', followLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6415. if (realFollows.length > 0) {
  6416. for (const game of realFollows) {
  6417. prom.push(this.#toggleFollowGame(game, doTask));
  6418. await delay(1e3);
  6419. }
  6420. }
  6421. }
  6422. if (doTask && !globalOptions.doTask.steam.forums || !doTask && !globalOptions.undoTask.steam.forums) {
  6423. scripts_echoLog({
  6424. type: 'globalOptionsSkip',
  6425. text: 'steam.forums'
  6426. });
  6427. } else {
  6428. const realForums = this.getRealParams('forums', forumLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6429. if (realForums.length > 0) {
  6430. for (const forum of realForums) {
  6431. prom.push(this.#toggleForum(forum, doTask));
  6432. await delay(1e3);
  6433. }
  6434. }
  6435. }
  6436. if (doTask && !globalOptions.doTask.steam.workshops || !doTask && !globalOptions.undoTask.steam.workshops) {
  6437. scripts_echoLog({
  6438. type: 'globalOptionsSkip',
  6439. text: 'steam.workshops'
  6440. });
  6441. } else {
  6442. const realWorkshops = this.getRealParams('workshops', workshopLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6443. if (realWorkshops.length > 0) {
  6444. for (const workshop of realWorkshops) {
  6445. prom.push(this.#toggleFavoriteWorkshop(workshop, doTask));
  6446. await delay(1e3);
  6447. }
  6448. }
  6449. }
  6450. if (doTask && !globalOptions.doTask.steam.workshopVotes) {
  6451. scripts_echoLog({
  6452. type: 'globalOptionsSkip',
  6453. text: 'steam.workshopVotes'
  6454. });
  6455. } else {
  6456. const realworkshopVotes = this.getRealParams('workshopVotes', workshopVoteLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6457. if (doTask && realworkshopVotes.length > 0) {
  6458. for (const workshop of realworkshopVotes) {
  6459. prom.push(this.#voteUpWorkshop(workshop));
  6460. await delay(1e3);
  6461. }
  6462. }
  6463. }
  6464. if (doTask && !globalOptions.doTask.steam.curators || !doTask && !globalOptions.undoTask.steam.curators) {
  6465. scripts_echoLog({
  6466. type: 'globalOptionsSkip',
  6467. text: 'steam.curators'
  6468. });
  6469. } else {
  6470. const realCurators = this.getRealParams('curators', curatorLinks, doTask, link => link.match(/curator\/([\d]+)/)?.[1]);
  6471. const realCuratorLikes = this.getRealParams('curatorLikes', curatorLikeLinks, doTask, link => link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3).join('/'));
  6472. if (realCurators.length > 0) {
  6473. for (const curator of realCurators) {
  6474. prom.push(this.#toggleCurator(curator, doTask));
  6475. await delay(1e3);
  6476. }
  6477. }
  6478. if (realCuratorLikes.length > 0) {
  6479. for (const curatorLike of realCuratorLikes) {
  6480. prom.push(this.#toggleCuratorLike(curatorLike, doTask));
  6481. await delay(1e3);
  6482. }
  6483. }
  6484. }
  6485. if (doTask && !globalOptions.doTask.steam.announcements) {
  6486. scripts_echoLog({
  6487. type: 'globalOptionsSkip',
  6488. text: 'steam.announcements'
  6489. });
  6490. } else {
  6491. const realAnnouncements = this.getRealParams('announcements', announcementLinks, doTask, link => {
  6492. if (link.includes('store.steampowered.com')) {
  6493. return link.match(/store\.steampowered\.com\/news\/app\/([\d]+)\/view\/([\d]+)/)?.slice(1, 3).join('/');
  6494. }
  6495. return link.match(/steamcommunity\.com\/games\/([\d]+)\/announcements\/detail\/([\d]+)/)?.slice(1, 3).join('/');
  6496. });
  6497. if (doTask && realAnnouncements.length > 0) {
  6498. for (const id of realAnnouncements) {
  6499. prom.push(this.#likeAnnouncement(id));
  6500. await delay(1e3);
  6501. }
  6502. }
  6503. }
  6504. if (doTask && !globalOptions.doTask.steam.licenses) {
  6505. scripts_echoLog({
  6506. type: 'globalOptionsSkip',
  6507. text: 'steam.licenses'
  6508. });
  6509. } else if (doTask && globalOptions.doTask.steam.licenses && licenseLinks.length > 0) {
  6510. for (const id of licenseLinks) {
  6511. prom.push(this.#addLicense(id));
  6512. await delay(1e3);
  6513. }
  6514. }
  6515. if (doTask && !globalOptions.doTask.steam.playtests) {
  6516. scripts_echoLog({
  6517. type: 'globalOptionsSkip',
  6518. text: 'steam.playtests'
  6519. });
  6520. } else {
  6521. const realPlaytests = this.getRealParams('playtests', playtestLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6522. if (doTask && globalOptions.doTask.steam.playtests && realPlaytests.length > 0) {
  6523. for (const id of realPlaytests) {
  6524. prom.push(this.#requestPlayTestAccess(id));
  6525. await delay(1e3);
  6526. }
  6527. }
  6528. }
  6529. return Promise.all(prom).then(async () => {
  6530. if (this.#area !== 'CN') {
  6531. scripts_echoLog({}).warning(i18n('steamFinishNotice'));
  6532. await this.#changeArea('CN');
  6533. }
  6534. return true;
  6535. });
  6536. } catch (error) {
  6537. throwError(error, 'Steam.toggle');
  6538. return false;
  6539. }
  6540. }
  6541. #setCache(type, name, id) {
  6542. try {
  6543. this.#cache[type][name] = id;
  6544. GM_setValue('steamCache', this.#cache);
  6545. } catch (error) {
  6546. throwError(error, 'Steam.setCache');
  6547. }
  6548. }
  6549. }
  6550. const social_Steam = Steam;
  6551. class Website {
  6552. undoneTasks;
  6553. socialTasks;
  6554. giveawayId;
  6555. socialInitialized = {
  6556. discord: false,
  6557. instagram: false,
  6558. reddit: false,
  6559. twitch: false,
  6560. twitter: false,
  6561. vk: false,
  6562. youtube: false,
  6563. steamStore: false,
  6564. steamCommunity: false
  6565. };
  6566. initialized = false;
  6567. social = {};
  6568. async #bind(name, init) {
  6569. try {
  6570. return {
  6571. name: name,
  6572. result: await init
  6573. };
  6574. } catch (error) {
  6575. throwError(error, 'Website.bind');
  6576. return {
  6577. name: name,
  6578. result: false
  6579. };
  6580. }
  6581. }
  6582. async initSocial(action) {
  6583. try {
  6584. const pro = [];
  6585. const tasks = action === 'do' ? this.undoneTasks : this.socialTasks;
  6586. if (tasks.discord) {
  6587. const hasDiscord = Object.values(tasks.discord).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6588. if (hasDiscord && (!this.socialInitialized.discord || !this.social.discord)) {
  6589. this.social.discord = new social_Discord();
  6590. pro.push(this.#bind('discord', this.social.discord.init(action)));
  6591. }
  6592. }
  6593. if (tasks.instagram) {
  6594. const hasInstagram = Object.values(tasks.instagram).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6595. if (hasInstagram && (!this.socialInitialized.instagram || !this.social.instagram)) {
  6596. this.social.instagram = new social_Instagram();
  6597. pro.push(this.#bind('instagram', this.social.instagram.init()));
  6598. }
  6599. }
  6600. if (tasks.reddit) {
  6601. const hasReddit = Object.values(tasks.reddit).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6602. if (hasReddit && (!this.socialInitialized.reddit || !this.social.reddit)) {
  6603. this.social.reddit = new social_Reddit();
  6604. pro.push(this.#bind('reddit', this.social.reddit.init()));
  6605. }
  6606. }
  6607. if (tasks.twitch) {
  6608. const hasTwitch = Object.values(tasks.twitch).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6609. if (hasTwitch && (!this.socialInitialized.twitch || !this.social.twitch)) {
  6610. this.social.twitch = new social_Twitch();
  6611. pro.push(this.#bind('twitch', this.social.twitch.init()));
  6612. }
  6613. }
  6614. if (tasks.twitter) {
  6615. const hasTwitter = Object.values(tasks.twitter).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6616. if (hasTwitter && (!this.socialInitialized.twitter || !this.social.twitter)) {
  6617. this.social.twitter = new social_Twitter();
  6618. pro.push(this.#bind('twitter', this.social.twitter.init()));
  6619. }
  6620. }
  6621. if (tasks.vk) {
  6622. const hasVk = Object.values(tasks.vk).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6623. if (hasVk && (!this.socialInitialized.vk || !this.social.vk)) {
  6624. this.social.vk = new social_Vk();
  6625. pro.push(this.#bind('vk', this.social.vk.init()));
  6626. }
  6627. }
  6628. if (tasks.youtube) {
  6629. const hasYoutube = Object.values(tasks.youtube).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6630. if (hasYoutube && (!this.socialInitialized.youtube || !this.social.youtube)) {
  6631. this.social.youtube = new Youtube();
  6632. pro.push(this.#bind('youtube', this.social.youtube.init()));
  6633. }
  6634. }
  6635. if (tasks.steam) {
  6636. const steamLength = Object.values(tasks.steam).reduce((total, arr) => [ ...total, ...arr ]).length;
  6637. if (steamLength > 0) {
  6638. if (!this.social.steam) {
  6639. this.social.steam = new social_Steam();
  6640. }
  6641. 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);
  6642. if (steamLength - steamCommunityLength > 0 && !this.socialInitialized.steamStore) {
  6643. pro.push(this.#bind('steamStore', this.social.steam.init('store')));
  6644. }
  6645. if (steamCommunityLength > 0 && !this.socialInitialized.steamCommunity) {
  6646. pro.push(this.#bind('steamCommunity', this.social.steam.init('community')));
  6647. }
  6648. }
  6649. }
  6650. if (tasks.links && tasks.links.length > 0) {
  6651. this.social.visitLink = visitLink;
  6652. }
  6653. return await Promise.all(pro).then(result => {
  6654. let checked = true;
  6655. for (const data of result) {
  6656. if (data.result) {
  6657. this.socialInitialized[data.name] = data.result;
  6658. } else {
  6659. checked = false;
  6660. }
  6661. }
  6662. return checked;
  6663. });
  6664. } catch (error) {
  6665. throwError(error, 'Website.initSocial');
  6666. return false;
  6667. }
  6668. }
  6669. uniqueTasks(allTasks) {
  6670. const result = {};
  6671. for (const [ social, types ] of Object.entries(allTasks)) {
  6672. result[social] = {};
  6673. for (const [ type, tasks ] of Object.entries(types)) {
  6674. result[social][type] = unique(tasks);
  6675. }
  6676. }
  6677. return result;
  6678. }
  6679. async toggleTask(action) {
  6680. try {
  6681. if (!this.initialized && !this.init()) {
  6682. return false;
  6683. }
  6684. if (!await this.classifyTask(action)) {
  6685. return false;
  6686. }
  6687. if (!await this.initSocial(action)) {
  6688. return false;
  6689. }
  6690. const pro = [];
  6691. const doTask = action === 'do';
  6692. const tasks = doTask ? this.undoneTasks : this.socialTasks;
  6693. if (this.socialInitialized.discord !== 'skip' && this.social.discord) {
  6694. pro.push(this.social.discord.toggle({
  6695. doTask: doTask,
  6696. ...tasks.discord
  6697. }));
  6698. }
  6699. if (this.social.instagram) {
  6700. pro.push(this.social.instagram.toggle({
  6701. doTask: doTask,
  6702. ...tasks.instagram
  6703. }));
  6704. }
  6705. if (this.social.reddit) {
  6706. pro.push(this.social.reddit.toggle({
  6707. doTask: doTask,
  6708. ...tasks.reddit
  6709. }));
  6710. }
  6711. if (this.social.twitch) {
  6712. pro.push(this.social.twitch.toggle({
  6713. doTask: doTask,
  6714. ...tasks.twitch
  6715. }));
  6716. }
  6717. if (this.social.twitter) {
  6718. pro.push(this.social.twitter.toggle({
  6719. doTask: doTask,
  6720. ...tasks.twitter
  6721. }));
  6722. }
  6723. if (this.social.vk) {
  6724. pro.push(this.social.vk.toggle({
  6725. doTask: doTask,
  6726. ...tasks.vk
  6727. }));
  6728. }
  6729. if (this.social.youtube) {
  6730. pro.push(this.social.youtube.toggle({
  6731. doTask: doTask,
  6732. ...tasks.youtube
  6733. }));
  6734. }
  6735. if (this.social.steam) {
  6736. pro.push(this.social.steam.toggle({
  6737. doTask: doTask,
  6738. ...tasks.steam
  6739. }));
  6740. }
  6741. if (this.social.visitLink && tasks.links && doTask) {
  6742. for (const link of tasks.links) {
  6743. pro.push(this.social.visitLink(link));
  6744. }
  6745. }
  6746. if (doTask && tasks.extra && this.extraDoTask) {
  6747. const hasExtra = Object.values(tasks.extra).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6748. if (hasExtra) {
  6749. pro.push(this.extraDoTask(tasks.extra));
  6750. }
  6751. }
  6752. await Promise.all(pro);
  6753. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6754. return true;
  6755. } catch (error) {
  6756. throwError(error, 'Website.toggleTask');
  6757. return false;
  6758. }
  6759. }
  6760. async doTask() {
  6761. try {
  6762. return await this.toggleTask('do');
  6763. } catch (error) {
  6764. throwError(error, 'Website.doTask');
  6765. return false;
  6766. }
  6767. }
  6768. async undoTask() {
  6769. try {
  6770. return await this.toggleTask('undo');
  6771. } catch (error) {
  6772. throwError(error, 'Website.undoTask');
  6773. return false;
  6774. }
  6775. }
  6776. }
  6777. const website_Website = Website;
  6778. const defaultTasksTemplate = {
  6779. steam: {
  6780. groupLinks: [],
  6781. wishlistLinks: [],
  6782. curatorLinks: [],
  6783. followLinks: []
  6784. },
  6785. vk: {
  6786. nameLinks: []
  6787. }
  6788. };
  6789. const defaultTasks = JSON.stringify(defaultTasksTemplate);
  6790. class FreeAnyWhere extends website_Website {
  6791. name = 'FreeAnyWhere';
  6792. tasks = [];
  6793. socialTasks = JSON.parse(defaultTasks);
  6794. undoneTasks = JSON.parse(defaultTasks);
  6795. buttons = [ 'doTask', 'undoTask', 'verifyTask', 'getKey' ];
  6796. static test() {
  6797. return window.location.host === 'freeanywhere.net';
  6798. }
  6799. async init() {
  6800. try {
  6801. const logStatus = scripts_echoLog({
  6802. text: i18n('initing')
  6803. });
  6804. if ($('a[href="#/login"]').length > 0) {
  6805. window.open('/#/login', '_self');
  6806. logStatus.warning(i18n('needLogin'));
  6807. return false;
  6808. }
  6809. if (window.location.href.includes('/login')) {
  6810. logStatus.warning(i18n('needLogin'));
  6811. return false;
  6812. }
  6813. if (!/^https?:\/\/freeanywhere\.net\/#\/giveaway\/[\d]+/.test(window.location.href)) {
  6814. const id = window.location.href.match(/https?:\/\/freeanywhere\.net\/.*?#\/giveaway\/([\d]+)/)?.[1];
  6815. if (!id) {
  6816. logStatus.error(i18n('getFailed', 'Id'));
  6817. return false;
  6818. }
  6819. window.location.href = `https://freeanywhere.net/#/giveaway/${id}`;
  6820. }
  6821. if (!this.#getGiveawayId()) {
  6822. return false;
  6823. }
  6824. if (!await this.#checkLeftKey()) {
  6825. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  6826. }
  6827. this.initialized = true;
  6828. logStatus.success();
  6829. return true;
  6830. } catch (error) {
  6831. throwError(error, 'Freeanywhere.init');
  6832. return false;
  6833. }
  6834. }
  6835. async classifyTask(action) {
  6836. try {
  6837. const logStatus = scripts_echoLog({
  6838. text: i18n('getTasksInfo')
  6839. });
  6840. if (action === 'undo') {
  6841. this.socialTasks = GM_getValue(`fawTasks-${this.giveawayId}`)?.tasks || JSON.parse(defaultTasks);
  6842. }
  6843. const {
  6844. result,
  6845. statusText,
  6846. status,
  6847. data
  6848. } = await tools_httpRequest({
  6849. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/?format=json`,
  6850. method: 'GET',
  6851. headers: {
  6852. authorization: `Token ${window.localStorage.getItem('token')}`,
  6853. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  6854. },
  6855. responseType: 'json'
  6856. });
  6857. if (result === 'Success') {
  6858. const tasks = data?.response?.challenges;
  6859. if (tasks) {
  6860. if (action === 'verify') {
  6861. this.tasks = [];
  6862. }
  6863. for (const task of tasks) {
  6864. const type = task.challenge;
  6865. const social = task.challenge_provider;
  6866. const taskInfo = {
  6867. id: task.id,
  6868. title: task.title
  6869. };
  6870. if (action === 'verify' && !task.is_success) {
  6871. this.tasks.push(taskInfo);
  6872. continue;
  6873. }
  6874. switch (social) {
  6875. case 'steam':
  6876. taskInfo.social = 'steam';
  6877. switch (type) {
  6878. case 'WL':
  6879. if (action === 'undo') {
  6880. this.socialTasks.steam.wishlistLinks.push(task.link);
  6881. }
  6882. if (action === 'do' && !task.is_success) {
  6883. this.undoneTasks.steam.wishlistLinks.push(task.link);
  6884. }
  6885. break;
  6886.  
  6887. case 'JTG':
  6888. if (action === 'undo') {
  6889. this.socialTasks.steam.groupLinks.push(task.link);
  6890. }
  6891. if (action === 'do' && !task.is_success) {
  6892. this.undoneTasks.steam.groupLinks.push(task.link);
  6893. }
  6894. break;
  6895.  
  6896. case 'STC':
  6897. if (action === 'undo') {
  6898. this.socialTasks.steam.curatorLinks.push(task.link);
  6899. }
  6900. if (action === 'do' && !task.is_success) {
  6901. this.undoneTasks.steam.curatorLinks.push(task.link);
  6902. }
  6903. break;
  6904.  
  6905. case 'GF':
  6906. if (action === 'undo') {
  6907. this.socialTasks.steam.followLinks.push(task.link);
  6908. }
  6909. if (action === 'do' && !task.is_success) {
  6910. this.undoneTasks.steam.followLinks.push(task.link);
  6911. }
  6912. break;
  6913. }
  6914. break;
  6915.  
  6916. case 'vk-oauth2':
  6917. if (action === 'undo') {
  6918. this.socialTasks.vk.nameLinks.push(task.link);
  6919. }
  6920. if (action === 'do' && !task.is_success) {
  6921. this.undoneTasks.vk.nameLinks.push(task.link);
  6922. }
  6923. break;
  6924.  
  6925. case 'website':
  6926. break;
  6927.  
  6928. default:
  6929. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${social}`);
  6930. break;
  6931. }
  6932. }
  6933. logStatus.success();
  6934. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  6935. this.socialTasks = this.uniqueTasks(this.socialTasks);
  6936. if (window.DEBUG) {
  6937. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  6938. }
  6939. GM_setValue(`fawTasks-${this.giveawayId}`, {
  6940. tasks: this.socialTasks,
  6941. time: new Date().getTime()
  6942. });
  6943. return true;
  6944. }
  6945. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6946. return false;
  6947. }
  6948. logStatus.error(`${result}:${statusText}(${status})`);
  6949. return false;
  6950. } catch (error) {
  6951. throwError(error, 'Freeanywhere.classifyTask');
  6952. return false;
  6953. }
  6954. }
  6955. async verifyTask() {
  6956. try {
  6957. if (!this.initialized && !this.init()) {
  6958. return false;
  6959. }
  6960. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  6961. return false;
  6962. }
  6963. const pro = [];
  6964. for (const task of this.tasks) {
  6965. pro.push(this.#verify(task));
  6966. await delay(1e3);
  6967. }
  6968. await Promise.all(pro);
  6969. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6970. return !!await this.getKey(true);
  6971. } catch (error) {
  6972. throwError(error, 'Freeanywhere.verifyTask');
  6973. return false;
  6974. }
  6975. }
  6976. async getKey(initialized) {
  6977. try {
  6978. if (!initialized && !this.initialized && !this.init()) {
  6979. return false;
  6980. }
  6981. const logStatus = scripts_echoLog({
  6982. text: i18n('gettingKey')
  6983. });
  6984. const {
  6985. result,
  6986. statusText,
  6987. status,
  6988. data
  6989. } = await tools_httpRequest({
  6990. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/reward/?format=json`,
  6991. method: 'GET',
  6992. dataType: 'json',
  6993. headers: {
  6994. authorization: `Token ${window.localStorage.getItem('token')}`
  6995. }
  6996. });
  6997. if (result === 'Success') {
  6998. if (data?.response?.reward) {
  6999. logStatus.success();
  7000. scripts_echoLog({}).success(data.response.reward);
  7001. return data.response.reward;
  7002. }
  7003. if (data?.response?.completed === false) {
  7004. logStatus.error(i18n('tasksNotCompleted'));
  7005. return false;
  7006. }
  7007. if (data?.response?.completed === true) {
  7008. await this.#checkLeftKey();
  7009. }
  7010. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7011. return false;
  7012. }
  7013. logStatus.error(`${result}:${statusText}(${status})`);
  7014. return false;
  7015. } catch (error) {
  7016. throwError(error, 'FreeAnyWhere.getGiveawayId');
  7017. return false;
  7018. }
  7019. }
  7020. #getGiveawayId() {
  7021. try {
  7022. const giveawayId = window.location.href.match(/\/giveaway\/([\d]+)/)?.[1];
  7023. if (giveawayId) {
  7024. this.giveawayId = giveawayId;
  7025. return true;
  7026. }
  7027. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7028. return false;
  7029. } catch (error) {
  7030. throwError(error, 'FreeAnyWhere.getGiveawayId');
  7031. }
  7032. }
  7033. async #verify(task) {
  7034. try {
  7035. const logStatus = scripts_echoLog({
  7036. html: `<li>${i18n('verifyingTask')}${task.title.trim()}...<font></font></li>`
  7037. });
  7038. const {
  7039. result,
  7040. statusText,
  7041. status,
  7042. data
  7043. } = await tools_httpRequest({
  7044. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/challenge-status/${task.id}/?format=json`,
  7045. method: 'GET',
  7046. dataType: 'json',
  7047. headers: {
  7048. authorization: `Token ${window.localStorage.getItem('token')}`,
  7049. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  7050. }
  7051. });
  7052. if (result === 'Success') {
  7053. if (data?.response?.status) {
  7054. logStatus.success();
  7055. return true;
  7056. }
  7057. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7058. return false;
  7059. }
  7060. logStatus.error(`${result}:${statusText}(${status})`);
  7061. return false;
  7062. } catch (error) {
  7063. throwError(error, 'Freeanywhere.verify');
  7064. return false;
  7065. }
  7066. }
  7067. async #checkLeftKey() {
  7068. try {
  7069. if (!globalOptions.other.checkLeftKey) {
  7070. return true;
  7071. }
  7072. const {
  7073. data
  7074. } = await tools_httpRequest({
  7075. url: 'https://freeanywhere.net/api/v1/widget/?format=json',
  7076. method: 'GET',
  7077. dataType: 'json',
  7078. headers: {
  7079. authorization: `Token ${window.localStorage.getItem('token')}`
  7080. }
  7081. });
  7082. if (data?.response?.giveaways.find(giveaway => `${giveaway?.id}` === this.giveawayId)) {
  7083. return true;
  7084. }
  7085. await external_Swal_default().fire({
  7086. icon: 'warning',
  7087. title: i18n('notice'),
  7088. text: i18n('noKeysLeft'),
  7089. confirmButtonText: i18n('confirm'),
  7090. cancelButtonText: i18n('cancel'),
  7091. showCancelButton: true
  7092. }).then(({
  7093. value
  7094. }) => {
  7095. if (value) {
  7096. window.close();
  7097. }
  7098. });
  7099. return true;
  7100. } catch (error) {
  7101. throwError(error, 'Giveawaysu.checkLeftKey');
  7102. return false;
  7103. }
  7104. }
  7105. }
  7106. const Freeanywhere = FreeAnyWhere;
  7107. const Giveawaysu_defaultTasks = {
  7108. steam: {
  7109. groupLinks: [],
  7110. wishlistLinks: [],
  7111. curatorLinks: [],
  7112. curatorLikeLinks: [],
  7113. followLinks: [],
  7114. forumLinks: [],
  7115. announcementLinks: [],
  7116. workshopVoteLinks: [],
  7117. playtestLinks: []
  7118. },
  7119. discord: {
  7120. serverLinks: []
  7121. },
  7122. instagram: {
  7123. userLinks: []
  7124. },
  7125. vk: {
  7126. nameLinks: []
  7127. },
  7128. twitch: {
  7129. channelLinks: []
  7130. },
  7131. reddit: {
  7132. redditLinks: []
  7133. },
  7134. youtube: {
  7135. channelLinks: [],
  7136. likeLinks: []
  7137. },
  7138. twitter: {
  7139. userLinks: [],
  7140. retweetLinks: []
  7141. }
  7142. };
  7143. class GiveawaySu extends website_Website {
  7144. name = 'GiveawaySu';
  7145. socialTasks = Giveawaysu_defaultTasks;
  7146. undoneTasks = Giveawaysu_defaultTasks;
  7147. buttons = [ 'doTask', 'undoTask' ];
  7148. static test() {
  7149. return /^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(window.location.href);
  7150. }
  7151. async after() {
  7152. try {
  7153. if (!this.#checkLogin()) {
  7154. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7155. }
  7156. if (!await this.#checkLeftKey()) {
  7157. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7158. }
  7159. scripts_echoLog({}).warning(i18n('gsNotice'));
  7160. } catch (error) {
  7161. throwError(error, 'Giveawaysu.after');
  7162. }
  7163. }
  7164. init() {
  7165. try {
  7166. const logStatus = scripts_echoLog({
  7167. text: i18n('initing')
  7168. });
  7169. if ($('a.steam-login').length > 0) {
  7170. window.open('/steam/redirect', '_self');
  7171. logStatus.warning(i18n('needLogin'));
  7172. return false;
  7173. }
  7174. if (!this.#getGiveawayId()) {
  7175. return false;
  7176. }
  7177. this.initialized = true;
  7178. logStatus.success();
  7179. return true;
  7180. } catch (error) {
  7181. throwError(error, 'Giveawaysu.init');
  7182. return false;
  7183. }
  7184. }
  7185. async classifyTask(action) {
  7186. try {
  7187. const logStatus = scripts_echoLog({
  7188. text: i18n('getTasksInfo')
  7189. });
  7190. if (action === 'undo') {
  7191. this.socialTasks = GM_getValue(`gasTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  7192. return true;
  7193. }
  7194. const pro = [];
  7195. const tasks = $('#actions tr');
  7196. if ($('div.bind-discord').is(':visible')) {
  7197. $('div.bind-discord a')[0].click();
  7198. }
  7199. if ($('div.bind-twitch').is(':visible')) {
  7200. $('div.bind-twitch a')[0].click();
  7201. }
  7202. for (const task of tasks) {
  7203. pro.push(new Promise(resolve => {
  7204. const td = $(task).find('td:not(".hidden")');
  7205. const colorfulTask = td.eq(1).find('a:not([data-trigger="link"])');
  7206. const colorlessTask = td.eq(2).find('a:not([data-trigger="link"])');
  7207. const taskDes = colorfulTask.length > 0 ? colorfulTask : colorlessTask;
  7208. const taskIcon = td.eq(0).find('i').attr('class') || '';
  7209. const taskName = taskDes.text().trim();
  7210. if (taskIcon.includes('ban') || /disable adblock/gi.test(taskName)) {
  7211. return resolve(true);
  7212. }
  7213. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  7214. if (!taskLink) {
  7215. return resolve(false);
  7216. }
  7217. if (taskIcon.includes('steam') && /join/gi.test(taskName)) {
  7218. this.undoneTasks.steam.groupLinks.push(taskLink);
  7219. } else if (/like.*announcement/gi.test(taskName)) {
  7220. this.undoneTasks.steam.announcementLinks.push(taskLink);
  7221. } else if (/(follow|subscribe).*curator/gim.test(taskName) && /^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  7222. this.undoneTasks.steam.curatorLinks.push(taskLink);
  7223. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  7224. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  7225. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  7226. this.undoneTasks.steam.forumLinks.push(taskLink);
  7227. } else if (taskIcon.includes('thumbs-up') && /^https?:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=[\d]+/.test(taskLink)) {
  7228. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7229. } else if (taskIcon.includes('plus') && /request.*playtest/gim.test(taskName)) {
  7230. this.undoneTasks.steam.playtestLinks.push(taskLink);
  7231. } else if (taskIcon.includes('discord') || /join.*discord/gim.test(taskName)) {
  7232. this.undoneTasks.discord.serverLinks.push(taskLink);
  7233. } else if (taskIcon.includes('instagram') || /follow.*instagram/gim.test(taskName)) {
  7234. this.undoneTasks.instagram.userLinks.push(taskLink);
  7235. } else if (taskIcon.includes('twitch') || /follow.*twitch.*channel/gim.test(taskName)) {
  7236. this.undoneTasks.twitch.channelLinks.push(taskLink);
  7237. } else if (taskIcon.includes('reddit') || /subscribe.*subreddit/gim.test(taskName) || /follow.*reddit/gim.test(taskName)) {
  7238. this.undoneTasks.reddit.redditLinks.push(taskLink);
  7239. } else if (/watch.*art/gim.test(taskName)) {
  7240. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7241. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  7242. this.undoneTasks.youtube.channelLinks.push(taskLink);
  7243. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  7244. this.undoneTasks.youtube.likeLinks.push(taskLink);
  7245. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  7246. this.undoneTasks.vk.nameLinks.push(taskLink);
  7247. } else {
  7248. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  7249. if (/wishlist.*game|add.*wishlist/gim.test(taskName)) {
  7250. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  7251. }
  7252. if (/follow.*button/gim.test(taskName)) {
  7253. this.undoneTasks.steam.followLinks.push(taskLink);
  7254. }
  7255. }
  7256. }
  7257. resolve(true);
  7258. }).catch(error => {
  7259. throwError(error, 'Giveawaysu.classifyTask->getRedirectLink');
  7260. return false;
  7261. });
  7262. }));
  7263. }
  7264. await Promise.all(pro);
  7265. logStatus.success();
  7266. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7267. this.socialTasks = this.undoneTasks;
  7268. if (window.DEBUG) {
  7269. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7270. }
  7271. GM_setValue(`gasTasks-${this.giveawayId}`, {
  7272. tasks: this.socialTasks,
  7273. time: new Date().getTime()
  7274. });
  7275. return true;
  7276. } catch (error) {
  7277. throwError(error, 'Giveawaysu.classifyTask');
  7278. return false;
  7279. }
  7280. }
  7281. #checkLogin() {
  7282. try {
  7283. if (!globalOptions.other.checkLogin) {
  7284. return true;
  7285. }
  7286. if ($('a.steam-login').length > 0) {
  7287. window.open('/steam/redirect', '_self');
  7288. }
  7289. return true;
  7290. } catch (error) {
  7291. throwError(error, 'Giveawaysu.checkLogin');
  7292. return false;
  7293. }
  7294. }
  7295. async #checkLeftKey() {
  7296. try {
  7297. if (!globalOptions.other.checkLeftKey) {
  7298. return true;
  7299. }
  7300. if ($('.giveaway-ended').length > 0 && $('.giveaway-key').length === 0) {
  7301. await external_Swal_default().fire({
  7302. icon: 'warning',
  7303. title: i18n('notice'),
  7304. text: i18n('noKeysLeft'),
  7305. confirmButtonText: i18n('confirm'),
  7306. cancelButtonText: i18n('cancel'),
  7307. showCancelButton: true
  7308. }).then(({
  7309. value
  7310. }) => {
  7311. if (value) {
  7312. window.close();
  7313. }
  7314. });
  7315. }
  7316. return true;
  7317. } catch (error) {
  7318. throwError(error, 'Giveawaysu.checkLeftKey');
  7319. return false;
  7320. }
  7321. }
  7322. #getGiveawayId() {
  7323. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  7324. if (giveawayId) {
  7325. this.giveawayId = giveawayId;
  7326. return true;
  7327. }
  7328. scripts_echoLog({
  7329. text: i18n('getFailed', 'GiveawayId')
  7330. });
  7331. return false;
  7332. }
  7333. }
  7334. class Indiedb {
  7335. name = 'Indiedb';
  7336. buttons = [ 'doTask' ];
  7337. static test() {
  7338. return window.location.host === 'www.indiedb.com';
  7339. }
  7340. async after() {
  7341. try {
  7342. if (!this.#checkLogin()) {
  7343. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7344. }
  7345. if (!await this.#checkLeftKey()) {
  7346. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7347. }
  7348. } catch (error) {
  7349. throwError(error, 'Indiedb.after');
  7350. }
  7351. }
  7352. async doTask() {
  7353. try {
  7354. if (!await this.#join()) {
  7355. return false;
  7356. }
  7357. return await this.#do();
  7358. } catch (error) {
  7359. throwError(error, 'Indiedb.doTask');
  7360. return false;
  7361. }
  7362. }
  7363. async #join() {
  7364. try {
  7365. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7366. scripts_echoLog({}).error(i18n('needLogin'));
  7367. return false;
  7368. }
  7369. const currentoption = $('a.buttonenter.buttongiveaway');
  7370. if (/join giveaway/gim.test(currentoption.text())) {
  7371. const logStatus = scripts_echoLog({
  7372. text: `${i18n('joiningGiveaway')}...`
  7373. });
  7374. const {
  7375. result,
  7376. statusText,
  7377. status,
  7378. data
  7379. } = await tools_httpRequest({
  7380. url: currentoption.attr('href'),
  7381. method: 'POST',
  7382. data: 'ajax=t',
  7383. dataType: 'json',
  7384. headers: {
  7385. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  7386. accept: 'application/json, text/javascript, */*; q=0.01',
  7387. origin: window.location.origin
  7388. }
  7389. });
  7390. if (result === 'Success') {
  7391. if (data?.status === 200) {
  7392. if (data.response?.success) {
  7393. currentoption.addClass('buttonentered').text('Success - Giveaway joined');
  7394. $('#giveawaysjoined').slideDown();
  7395. $('#giveawaysrecommend').slideDown();
  7396. logStatus.success(`Success${data.response?.text ? `:${data.response?.text}` : ''}`);
  7397. return true;
  7398. }
  7399. logStatus.error(`Error${data.response?.text ? `:${data.response?.text}` : ''}`);
  7400. return false;
  7401. }
  7402. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7403. return false;
  7404. }
  7405. logStatus.error(`${result}:${statusText}(${status})`);
  7406. return false;
  7407. } else if (/success/gim.test($('a.buttonenter.buttongiveaway').text())) {
  7408. return true;
  7409. }
  7410. scripts_echoLog({}).warning(i18n('needJoinGiveaway'));
  7411. return false;
  7412. } catch (error) {
  7413. throwError(error, 'Indiedb.init');
  7414. return false;
  7415. }
  7416. }
  7417. async #do() {
  7418. try {
  7419. const id = $('script').map((index, script) => {
  7420. if (/\$\(document\)/gim.test(script.innerHTML)) {
  7421. return [ script.innerHTML.match(/"\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0], script.innerHTML.match(/"\/newsletter\/ajax\/subscribeprofile\/optin\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0] ];
  7422. }
  7423. return null;
  7424. });
  7425. if (id.length === 2) {
  7426. const pro = [];
  7427. const tasks = $('#giveawaysjoined a[class*=promo]');
  7428. for (const task of tasks) {
  7429. const promo = $(task);
  7430. if (!promo.hasClass('buttonentered')) {
  7431. const status = scripts_echoLog({
  7432. text: `${i18n('doing')}:${promo.parents('p').text()}...`
  7433. });
  7434. if (/facebookpromo|twitterpromo|visitpromo/gim.test(task.className)) {
  7435. let text = '';
  7436. if (promo.hasClass('facebookpromo')) {
  7437. text = 'facebookpromo';
  7438. } else if (promo.hasClass('twitterpromo')) {
  7439. text = 'twitterpromo';
  7440. } else {
  7441. text = 'visitpromo';
  7442. }
  7443. pro.push(new Promise(resolve => {
  7444. $.ajax({
  7445. type: 'POST',
  7446. url: urlPath(`/giveaways/ajax/${text}/${id[0]}`),
  7447. timeout: 6e4,
  7448. dataType: 'json',
  7449. data: {
  7450. ajax: 't'
  7451. },
  7452. error(response, error, exception) {
  7453. if (window.DEBUG) {
  7454. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7455. response: response,
  7456. error: error,
  7457. exception: exception
  7458. });
  7459. }
  7460. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7461. resolve(true);
  7462. },
  7463. success(response) {
  7464. if (response.success) {
  7465. status.success(`Success:${response.text}`);
  7466. promo.addClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7467. resolve(true);
  7468. } else {
  7469. status.error(`Error:${response.text}`);
  7470. resolve(true);
  7471. }
  7472. }
  7473. });
  7474. }));
  7475. } else if (promo.hasClass('emailoptinpromo')) {
  7476. pro.push(new Promise(resolve => {
  7477. $.ajax({
  7478. type: 'POST',
  7479. url: urlPath(`/newsletter/ajax/subscribeprofile/optin/${id[1]}`),
  7480. timeout: 6e4,
  7481. dataType: 'json',
  7482. data: {
  7483. ajax: 't',
  7484. emailsystoggle: 4
  7485. },
  7486. error(response, error, exception) {
  7487. if (window.DEBUG) {
  7488. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7489. response: response,
  7490. error: error,
  7491. exception: exception
  7492. });
  7493. }
  7494. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7495. resolve(true);
  7496. },
  7497. success(response) {
  7498. if (response.success) {
  7499. status.success(`Success:${response.text}`);
  7500. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7501. resolve(true);
  7502. } else {
  7503. status.error(`Error:${response.text}`);
  7504. resolve(true);
  7505. }
  7506. }
  7507. });
  7508. }));
  7509. } else if (promo.hasClass('watchingpromo')) {
  7510. pro.push(new Promise(resolve => {
  7511. const data = getUrlQuery(promo.attr('href'));
  7512. data.ajax = 't';
  7513. $.ajax({
  7514. type: 'POST',
  7515. url: urlPath(promo.attr('href')?.split(/[?#]/)[0]),
  7516. timeout: 6e4,
  7517. dataType: 'json',
  7518. data: data,
  7519. error(response, error, exception) {
  7520. if (window.DEBUG) {
  7521. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7522. response: response,
  7523. error: error,
  7524. exception: exception
  7525. });
  7526. }
  7527. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7528. resolve(true);
  7529. },
  7530. success(response) {
  7531. if (response.success) {
  7532. status.success(`Success:${response.text}`);
  7533. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7534. resolve(true);
  7535. } else {
  7536. status.error(`Error:${response.text}`);
  7537. resolve(true);
  7538. }
  7539. }
  7540. });
  7541. }));
  7542. } else if (!/the-challenge-of-adblock/gim.test(promo.attr('href'))) {
  7543. pro.push(new Promise(resolve => {
  7544. $.ajax({
  7545. type: 'POST',
  7546. url: urlPath(promo.attr('href')),
  7547. timeout: 6e4,
  7548. dataType: 'json',
  7549. data: {
  7550. ajax: 't'
  7551. },
  7552. error(response, error, exception) {
  7553. if (window.DEBUG) {
  7554. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7555. response: response,
  7556. error: error,
  7557. exception: exception
  7558. });
  7559. }
  7560. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7561. resolve(true);
  7562. },
  7563. success(response) {
  7564. if (response.success) {
  7565. status.success(`Success:${response.text}`);
  7566. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7567. resolve(true);
  7568. } else {
  7569. status.error(`Error:${response.text}`);
  7570. resolve(true);
  7571. }
  7572. }
  7573. });
  7574. }));
  7575. } else {
  7576. status.error(`Error:${i18n('unKnownTaskType')}`);
  7577. }
  7578. }
  7579. }
  7580. await Promise.all(pro);
  7581. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7582. return true;
  7583. }
  7584. scripts_echoLog({}).error(i18n('getFailed', 'TaskId'));
  7585. return false;
  7586. } catch (error) {
  7587. throwError(error, 'Indiedb.classifyTask');
  7588. return false;
  7589. }
  7590. }
  7591. #checkLogin() {
  7592. try {
  7593. if (!globalOptions.other.checkLogin) {
  7594. return true;
  7595. }
  7596. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7597. window.open('/members/login', '_self');
  7598. }
  7599. return true;
  7600. } catch (error) {
  7601. throwError(error, 'Indiedb.checkLogin');
  7602. return false;
  7603. }
  7604. }
  7605. async #checkLeftKey() {
  7606. try {
  7607. if (!globalOptions.other.checkLeftKey) {
  7608. return true;
  7609. }
  7610. if ($('a.buttonenter:contains("next time"),a.buttonenter:contains("Giveaway is closed")').length > 0) {
  7611. await external_Swal_default().fire({
  7612. icon: 'warning',
  7613. title: i18n('notice'),
  7614. text: i18n('giveawayEnded'),
  7615. confirmButtonText: i18n('confirm'),
  7616. cancelButtonText: i18n('cancel'),
  7617. showCancelButton: true
  7618. }).then(({
  7619. value
  7620. }) => {
  7621. if (value) {
  7622. window.close();
  7623. }
  7624. });
  7625. }
  7626. return true;
  7627. } catch (error) {
  7628. throwError(error, 'Indiedb.checkLeftKey');
  7629. return false;
  7630. }
  7631. }
  7632. }
  7633. const website_Indiedb = Indiedb;
  7634. const Keyhub_defaultTasksTemplate = {
  7635. steam: {
  7636. groupLinks: [],
  7637. officialGroupLinks: [],
  7638. wishlistLinks: [],
  7639. curatorLinks: []
  7640. },
  7641. discord: {
  7642. serverLinks: []
  7643. },
  7644. extra: {
  7645. videoTasks: []
  7646. },
  7647. links: []
  7648. };
  7649. const Keyhub_defaultTasks = JSON.stringify(Keyhub_defaultTasksTemplate);
  7650. class Keyhub extends website_Website {
  7651. name = 'Keyhub';
  7652. socialTasks = JSON.parse(Keyhub_defaultTasks);
  7653. undoneTasks = JSON.parse(Keyhub_defaultTasks);
  7654. buttons = [ 'doTask', 'undoTask' ];
  7655. static test() {
  7656. return window.location.host === 'key-hub.eu';
  7657. }
  7658. async after() {
  7659. try {
  7660. if (!this.#checkLogin()) {
  7661. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7662. }
  7663. if (!await this.#checkLeftKey()) {
  7664. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7665. }
  7666. $('.NSFW').hide();
  7667. } catch (error) {
  7668. throwError(error, 'Keyhub.after');
  7669. }
  7670. }
  7671. init() {
  7672. try {
  7673. const logStatus = scripts_echoLog({
  7674. text: i18n('initing')
  7675. });
  7676. if ($('a[href*="/connect/steam"]').length > 0) {
  7677. window.open('/connect/steam', '_self');
  7678. logStatus.warning(i18n('needLogin'));
  7679. return false;
  7680. }
  7681. if (!this.#getGiveawayId()) {
  7682. return false;
  7683. }
  7684. $('#VPNoverlay').hide();
  7685. $('#mainArticleSection').show();
  7686. this.initialized = true;
  7687. logStatus.success();
  7688. return true;
  7689. } catch (error) {
  7690. throwError(error, 'Keyhub.init');
  7691. return false;
  7692. }
  7693. }
  7694. async classifyTask(action) {
  7695. try {
  7696. const logStatus = scripts_echoLog({
  7697. text: i18n('getTasksInfo')
  7698. });
  7699. if (action === 'undo') {
  7700. this.socialTasks = GM_getValue(`khTasks-${this.giveawayId}`)?.tasks || JSON.parse(Keyhub_defaultTasks);
  7701. }
  7702. const tasks = $('.task:not(".googleads")').filter((index, element) => action === 'do' ? $(element).find('i.fa-check-circle:visible').length === 0 : true).find('a');
  7703. for (const task of tasks) {
  7704. let link = $(task).attr('href');
  7705. const taskDes = $(task).text().trim();
  7706. if (!link) {
  7707. continue;
  7708. }
  7709. if (/\/away\?data=/.test(link) || /steamcommunity\.com\/gid\//.test(link)) {
  7710. link = await getRedirectLink(link) || link;
  7711. }
  7712. if (/https?:\/\/key-hub\.eu\/connect\/discord/.test(link)) {
  7713. window.open(link, '_blank');
  7714. } else if (/steamcommunity\.com\/groups\//.test(link)) {
  7715. if (action === 'undo') {
  7716. this.socialTasks.steam.groupLinks.push(link);
  7717. }
  7718. if (action === 'do') {
  7719. this.undoneTasks.steam.groupLinks.push(link);
  7720. }
  7721. } else if (/steamcommunity\.com\/games\/[\d]+/.test(link)) {
  7722. if (action === 'undo') {
  7723. this.socialTasks.steam.officialGroupLinks.push(link);
  7724. }
  7725. if (action === 'do') {
  7726. this.undoneTasks.steam.officialGroupLinks.push(link);
  7727. }
  7728. } else if (/store\.steampowered\.com\/app\//.test(link) && /wishlist/gim.test(taskDes)) {
  7729. if (action === 'undo') {
  7730. this.socialTasks.steam.wishlistLinks.push(link);
  7731. }
  7732. if (action === 'do') {
  7733. this.undoneTasks.steam.wishlistLinks.push(link);
  7734. }
  7735. } else if (/store\.steampowered\.com\/curator\//.test(link)) {
  7736. if (action === 'undo') {
  7737. this.socialTasks.steam.curatorLinks.push(link);
  7738. }
  7739. if (action === 'do') {
  7740. this.undoneTasks.steam.curatorLinks.push(link);
  7741. }
  7742. } else if (/^https?:\/\/discord\.com\/invite\//.test(link)) {
  7743. if (action === 'undo') {
  7744. this.socialTasks.discord.serverLinks.push(link);
  7745. }
  7746. if (action === 'do') {
  7747. this.undoneTasks.discord.serverLinks.push(link);
  7748. }
  7749. } else if (/^javascript:videoTask.+/.test(link)) {
  7750. if (action === 'do') {
  7751. const taskData = link.match(/javascript:videoTask\('.+?','(.+?)'/)?.[1];
  7752. if (taskData) {
  7753. this.undoneTasks.extra.videoTasks.push(taskData);
  7754. }
  7755. }
  7756. } 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 {
  7757. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  7758. }
  7759. }
  7760. logStatus.success();
  7761. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7762. this.socialTasks = this.uniqueTasks(this.socialTasks);
  7763. if (window.DEBUG) {
  7764. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7765. }
  7766. GM_setValue(`khTasks-${this.giveawayId}`, {
  7767. tasks: this.socialTasks,
  7768. time: new Date().getTime()
  7769. });
  7770. return true;
  7771. } catch (error) {
  7772. throwError(error, 'Keyhub.classifyTask');
  7773. return false;
  7774. }
  7775. }
  7776. async #doScriptTask(data) {
  7777. try {
  7778. const logStatus = scripts_echoLog({
  7779. text: i18n('doingKeyhubTask')
  7780. });
  7781. const {
  7782. result,
  7783. statusText,
  7784. status,
  7785. data: response
  7786. } = await tools_httpRequest({
  7787. url: `/away?data=${data}`,
  7788. method: 'GET',
  7789. headers: {
  7790. origin: 'https://key-hub.eu',
  7791. referer: 'https://key-hub.eu/'
  7792. }
  7793. });
  7794. if (result === 'Success') {
  7795. if (response?.status === 200) {
  7796. logStatus.success();
  7797. return true;
  7798. }
  7799. logStatus.error(`Error:${response?.statusText}(${response?.status})`);
  7800. return false;
  7801. }
  7802. logStatus.error(`${result}:${statusText}(${status})`);
  7803. return false;
  7804. } catch (error) {
  7805. throwError(error, 'Keyhub.doScriptTask');
  7806. return false;
  7807. }
  7808. }
  7809. async extraDoTask({
  7810. videoTasks
  7811. }) {
  7812. try {
  7813. const pro = [];
  7814. for (const data of videoTasks) {
  7815. pro.push(this.#doScriptTask(data));
  7816. }
  7817. return Promise.all(pro).then(() => true);
  7818. } catch (error) {
  7819. throwError(error, 'Keyhub.extraDoTask');
  7820. return false;
  7821. }
  7822. }
  7823. #getGiveawayId() {
  7824. try {
  7825. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  7826. if (giveawayId) {
  7827. this.giveawayId = giveawayId;
  7828. return true;
  7829. }
  7830. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7831. return false;
  7832. } catch (error) {
  7833. throwError(error, 'Keyhub.getGiveawayId');
  7834. return false;
  7835. }
  7836. }
  7837. async #checkLeftKey() {
  7838. try {
  7839. if (!globalOptions.other.checkLeftKey) {
  7840. return true;
  7841. }
  7842. const leftKey = $('#keysleft').text().trim();
  7843. if (leftKey === '0') {
  7844. await external_Swal_default().fire({
  7845. icon: 'warning',
  7846. title: i18n('notice'),
  7847. text: i18n('noKeysLeft'),
  7848. confirmButtonText: i18n('confirm'),
  7849. cancelButtonText: i18n('cancel'),
  7850. showCancelButton: true
  7851. }).then(({
  7852. value
  7853. }) => {
  7854. if (value) {
  7855. window.close();
  7856. }
  7857. });
  7858. }
  7859. return true;
  7860. } catch (error) {
  7861. throwError(error, 'Keyhub.checkLeftKey');
  7862. return false;
  7863. }
  7864. }
  7865. #checkLogin() {
  7866. try {
  7867. if (!globalOptions.other.checkLogin) {
  7868. return true;
  7869. }
  7870. if ($('a[href*="/connect/steam"]').length > 0) {
  7871. window.open('/connect/steam', '_self');
  7872. }
  7873. return true;
  7874. } catch (error) {
  7875. throwError(error, 'Keyhub.checkLogin');
  7876. return false;
  7877. }
  7878. }
  7879. }
  7880. const website_Keyhub = Keyhub;
  7881. const Givekey_defaultTasksTemplate = {
  7882. steam: {
  7883. groupLinks: [],
  7884. wishlistLinks: [],
  7885. curatorLinks: [],
  7886. curatorLikeLinks: []
  7887. },
  7888. twitter: {
  7889. userLinks: []
  7890. },
  7891. vk: {
  7892. nameLinks: []
  7893. },
  7894. discord: {
  7895. serverLinks: []
  7896. }
  7897. };
  7898. const Givekey_defaultTasks = JSON.stringify(Givekey_defaultTasksTemplate);
  7899. class Givekey extends website_Website {
  7900. name = 'Givekey';
  7901. tasks = [];
  7902. socialTasks = JSON.parse(Givekey_defaultTasks);
  7903. undoneTasks = JSON.parse(Givekey_defaultTasks);
  7904. userId;
  7905. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  7906. static test() {
  7907. return window.location.host === 'givekey.ru';
  7908. }
  7909. async after() {
  7910. try {
  7911. await new Promise(resolve => {
  7912. const checker = setInterval(() => {
  7913. if ($('#navbarDropdown').length > 0) {
  7914. clearInterval(checker);
  7915. resolve(true);
  7916. }
  7917. });
  7918. });
  7919. if (!await this.#checkLeftKey()) {
  7920. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7921. }
  7922. } catch (error) {
  7923. throwError(error, 'Givekey.after');
  7924. return false;
  7925. }
  7926. }
  7927. init() {
  7928. try {
  7929. const logStatus = scripts_echoLog({
  7930. text: i18n('initing')
  7931. });
  7932. if ($('a[href*="/auth/steam"]').length > 0) {
  7933. window.open('/auth/steam', '_self');
  7934. logStatus.warning(i18n('needLogin'));
  7935. return false;
  7936. }
  7937. if (!this.#getGiveawayId()) {
  7938. return false;
  7939. }
  7940. const userId = $('meta[name="user-id"]').attr('content');
  7941. if (!userId) {
  7942. logStatus.error(i18n('getFailed', i18n('userId')));
  7943. return false;
  7944. }
  7945. this.userId = userId;
  7946. this.initialized = true;
  7947. logStatus.success();
  7948. return true;
  7949. } catch (error) {
  7950. throwError(error, 'Givekey.init');
  7951. return false;
  7952. }
  7953. }
  7954. async classifyTask(action) {
  7955. try {
  7956. const logStatus = scripts_echoLog({
  7957. text: i18n('getTasksInfo')
  7958. });
  7959. if (action === 'undo') {
  7960. this.socialTasks = GM_getValue(`gkTasks-${this.giveawayId}`)?.tasks || JSON.parse(Givekey_defaultTasks);
  7961. }
  7962. const tasks = $('.card-body:has("button") .row');
  7963. for (const task of tasks) {
  7964. const taskEle = $(task);
  7965. const isSuccess = /Complete/i.test(taskEle.find('button').text().trim());
  7966. if (isSuccess && action !== 'undo') {
  7967. continue;
  7968. }
  7969. const checkButton = taskEle.find('#task_check');
  7970. const taskId = checkButton.attr('data-id');
  7971. if (taskId) {
  7972. this.tasks.push(taskId);
  7973. }
  7974. if (action === 'verify') {
  7975. continue;
  7976. }
  7977. let href = taskEle.find('a').attr('href') || null;
  7978. const text = taskEle.find('a').text().trim();
  7979. const icon = taskEle.find('i');
  7980. if (!href || !text) {
  7981. continue;
  7982. }
  7983. if (/^https?:\/\/givekey\.ru\/giveaway\/[\d]+\/execution_task/.test(href)) {
  7984. href = await getRedirectLink(href);
  7985. }
  7986. if (!href) {
  7987. continue;
  7988. }
  7989. if (/^https?:\/\/vk\.com\//.test(href)) {
  7990. this.socialTasks.vk.nameLinks.push(href);
  7991. if (action === 'do' && !isSuccess) {
  7992. this.undoneTasks.vk.nameLinks.push(href);
  7993. }
  7994. } else if (/^https?:\/\/steamcommunity\.com\/groups/.test(href)) {
  7995. this.socialTasks.steam.groupLinks.push(href);
  7996. if (action === 'do' && !isSuccess) {
  7997. this.undoneTasks.steam.groupLinks.push(href);
  7998. }
  7999. } else if (/^https?:\/\/store\.steampowered\.com\/app\//.test(href)) {
  8000. this.socialTasks.steam.wishlistLinks.push(href);
  8001. if (action === 'do' && !isSuccess) {
  8002. this.undoneTasks.steam.wishlistLinks.push(href);
  8003. }
  8004. } else if (/Subscribe/gi.test(text) && icon.hasClass('fa-steam-square')) {
  8005. if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(href)) {
  8006. this.socialTasks.steam.curatorLinks.push(href);
  8007. if (action === 'do' && !isSuccess) {
  8008. this.undoneTasks.steam.curatorLinks.push(href);
  8009. }
  8010. } else {
  8011. this.socialTasks.steam.curatorLikeLinks.push(href);
  8012. if (action === 'do' && !isSuccess) {
  8013. this.undoneTasks.steam.curatorLikeLinks.push(href);
  8014. }
  8015. }
  8016. } else if (/^https?:\/\/twitter\.com\//.test(href) && /Subscribe/gi.test(text)) {
  8017. this.socialTasks.twitter.userLinks.push(href);
  8018. if (action === 'do' && !isSuccess) {
  8019. this.undoneTasks.twitter.userLinks.push(href);
  8020. }
  8021. } else if (icon.hasClass('fa-discord') || /^https?:\/\/discord\.com\/invite\//.test(href)) {
  8022. this.socialTasks.discord.serverLinks.push(href);
  8023. if (action === 'do' && !isSuccess) {
  8024. this.undoneTasks.discord.serverLinks.push(href);
  8025. }
  8026. } else {
  8027. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${text}(${href})`);
  8028. }
  8029. }
  8030. logStatus.success();
  8031. this.tasks = unique(this.tasks);
  8032. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8033. this.socialTasks = this.uniqueTasks(this.socialTasks);
  8034. if (window.DEBUG) {
  8035. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8036. }
  8037. GM_setValue(`gkTasks-${this.giveawayId}`, {
  8038. tasks: this.socialTasks,
  8039. time: new Date().getTime()
  8040. });
  8041. return true;
  8042. } catch (error) {
  8043. throwError(error, 'Givekey.classifyTask');
  8044. return false;
  8045. }
  8046. }
  8047. async verifyTask() {
  8048. try {
  8049. if (!this.initialized && !this.init()) {
  8050. return false;
  8051. }
  8052. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  8053. return false;
  8054. }
  8055. scripts_echoLog({}).warning(i18n('giveKeyNoticeBefore'));
  8056. const taskLength = this.tasks.length;
  8057. for (let i = 0; i < taskLength; i++) {
  8058. await this.#verify(this.tasks[i]);
  8059. if (i < taskLength - 1) {
  8060. await delay(15e3);
  8061. }
  8062. }
  8063. scripts_echoLog({}).success(i18n('allTasksComplete'));
  8064. scripts_echoLog({
  8065. html: `<li><font class="warning">${i18n('giveKeyNoticeAfter')}</font></li>`
  8066. });
  8067. return true;
  8068. } catch (error) {
  8069. throwError(error, 'Givekey.verifyTask');
  8070. return false;
  8071. }
  8072. }
  8073. async #verify(task) {
  8074. try {
  8075. const logStatus = scripts_echoLog({
  8076. html: `<li>${i18n('verifyingTask')}${task}...<font></font></li>`
  8077. });
  8078. return await new Promise(resolve => {
  8079. $.ajax({
  8080. url: 'https://givekey.ru/giveaway/task',
  8081. method: 'POST',
  8082. data: `id=${task}&user_id=${this.userId}`,
  8083. dataType: 'json',
  8084. headers: {
  8085. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  8086. },
  8087. success: data => {
  8088. if (data.btn) {
  8089. $(`button[data-id=${this.userId}]`).html(data.btn);
  8090. }
  8091. if (data.status === 'ok') {
  8092. $(`.task_check_${data.id}`).html(`<button class="btn btn-success mb-2 btn-block" disabled>${data.btn}</button>`);
  8093. logStatus.success();
  8094. resolve(true);
  8095. } else if (data.status === 'end') {
  8096. logStatus.success();
  8097. scripts_echoLog({}).success(data.key);
  8098. resolve(true);
  8099. } else {
  8100. logStatus.error(`Error:${data.msg}`);
  8101. resolve(false);
  8102. }
  8103. },
  8104. error: xhr => {
  8105. logStatus.error(`Error:${xhr.statusText}(${xhr.status})`);
  8106. resolve(false);
  8107. }
  8108. });
  8109. });
  8110. } catch (error) {
  8111. throwError(error, 'Givekey.verify');
  8112. return false;
  8113. }
  8114. }
  8115. #getGiveawayId() {
  8116. try {
  8117. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  8118. if (giveawayId) {
  8119. this.giveawayId = giveawayId;
  8120. return true;
  8121. }
  8122. scripts_echoLog({
  8123. text: i18n('getFailed', 'GiveawayId')
  8124. });
  8125. return false;
  8126. } catch (error) {
  8127. throwError(error, 'Givekey.getGiveawayId');
  8128. return false;
  8129. }
  8130. }
  8131. async #checkLeftKey() {
  8132. try {
  8133. if (!globalOptions.other.checkLeftKey) {
  8134. return true;
  8135. }
  8136. if (!$('#keys_count').text()) {
  8137. await external_Swal_default().fire({
  8138. icon: 'warning',
  8139. title: i18n('notice'),
  8140. text: i18n('noKeysLeft'),
  8141. confirmButtonText: i18n('confirm'),
  8142. cancelButtonText: i18n('cancel'),
  8143. showCancelButton: true
  8144. }).then(({
  8145. value
  8146. }) => {
  8147. if (value) {
  8148. window.close();
  8149. }
  8150. });
  8151. }
  8152. return true;
  8153. } catch (error) {
  8154. throwError(error, 'Givekey.checkLeftKey');
  8155. return false;
  8156. }
  8157. }
  8158. }
  8159. const website_Givekey = Givekey;
  8160. class GiveeClub extends GiveawaySu {
  8161. name = 'GiveeClub';
  8162. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  8163. static test() {
  8164. return /^https?:\/\/givee\.club\/.*?\/event\/[\d]+/.test(window.location.href);
  8165. }
  8166. async after() {
  8167. try {
  8168. if (!this.#checkLogin()) {
  8169. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8170. }
  8171. if (!await this.#checkLeftKey()) {
  8172. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  8173. }
  8174. } catch (error) {
  8175. throwError(error, 'GiveeClub.after');
  8176. }
  8177. }
  8178. init() {
  8179. try {
  8180. const logStatus = scripts_echoLog({
  8181. text: i18n('initing')
  8182. });
  8183. if (!this.#checkLogin()) {
  8184. logStatus.warning(i18n('needLogin'));
  8185. return false;
  8186. }
  8187. if (!this.#getGiveawayId()) {
  8188. return false;
  8189. }
  8190. this.initialized = true;
  8191. logStatus.success();
  8192. return true;
  8193. } catch (error) {
  8194. throwError(error, 'GiveeClub.init');
  8195. return false;
  8196. }
  8197. }
  8198. async classifyTask(action) {
  8199. try {
  8200. const logStatus = scripts_echoLog({
  8201. text: i18n('getTasksInfo')
  8202. });
  8203. if (action === 'undo') {
  8204. this.socialTasks = GM_getValue(`gcTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  8205. return true;
  8206. }
  8207. const pro = [];
  8208. const tasks = $('.event-actions tr');
  8209. for (const task of tasks) {
  8210. pro.push(new Promise(resolve => {
  8211. const taskDes = $(task).find('.event-action-label a');
  8212. const taskIcon = $(task).find('.event-action-icon i').attr('class') || '';
  8213. const taskName = taskDes.text().trim();
  8214. const taskType = $(task).find('button[data-type]')?.attr('data-type');
  8215. const taskFinished = $(task).find('.event-action-buttons .btn-success')?.length;
  8216. if (taskIcon.includes('ban') || /AdBlock/i.test(taskName) || taskIcon.includes('envelope') || taskFinished) {
  8217. return resolve(true);
  8218. }
  8219. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  8220. if (!taskLink) {
  8221. return resolve(false);
  8222. }
  8223. if (taskType === 'steam.group.join' && /^https?:\/\/steamcommunity\.com\/groups/.test(taskLink)) {
  8224. this.undoneTasks.steam.groupLinks.push(taskLink);
  8225. } else if (/like.*announcement/gi.test(taskName)) {
  8226. this.undoneTasks.steam.announcementLinks.push(taskLink);
  8227. } else if (taskType === 'steam.game.wishlist' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8228. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  8229. } else if (taskType === 'steam.game.wishlist' && taskDes.attr('data-steam-wishlist-appid')) {
  8230. this.undoneTasks.steam.wishlistLinks.push(`https://store.steampowered.com/app/${taskDes.attr('data-steam-wishlist-appid')}`);
  8231. } else if (taskType === 'steam.game.follow' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8232. this.undoneTasks.steam.followLinks.push(taskLink);
  8233. } else if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  8234. this.undoneTasks.steam.curatorLinks.push(taskLink);
  8235. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  8236. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  8237. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  8238. this.undoneTasks.steam.forumLinks.push(taskLink);
  8239. } else if (taskIcon.includes('discord')) {
  8240. this.undoneTasks.discord.serverLinks.push(taskLink);
  8241. } else if (taskIcon.includes('instagram')) {
  8242. this.undoneTasks.instagram.userLinks.push(taskLink);
  8243. } else if (taskIcon.includes('twitch')) {
  8244. this.undoneTasks.twitch.channelLinks.push(taskLink);
  8245. } else if (taskIcon.includes('reddit')) {
  8246. this.undoneTasks.reddit.redditLinks.push(taskLink);
  8247. } else if (/watch.*art/gim.test(taskName)) {
  8248. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8249. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  8250. this.undoneTasks.youtube.channelLinks.push(taskLink);
  8251. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  8252. this.undoneTasks.youtube.likeLinks.push(taskLink);
  8253. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  8254. this.undoneTasks.vk.nameLinks.push(taskLink);
  8255. } else if (taskIcon.includes('twitter')) {
  8256. if (/https?:\/\/twitter\.com\/[^/]+\/?$/gim.test(taskLink)) {
  8257. this.undoneTasks.twitter.userLinks.push(taskLink);
  8258. } else if (/https?:\/\/twitter\.com\/[^/]+?\/status\/[\d]+/gim.test(taskLink)) {
  8259. this.undoneTasks.twitter.retweetLinks.push(taskLink);
  8260. }
  8261. } else {
  8262. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  8263. if (/follow.*button/gim.test(taskName)) {
  8264. this.undoneTasks.steam.followLinks.push(taskLink);
  8265. }
  8266. }
  8267. }
  8268. resolve(true);
  8269. }).catch(error => {
  8270. throwError(error, 'GiveeClub.classifyTask->getRedirectLink');
  8271. return false;
  8272. });
  8273. }));
  8274. }
  8275. await Promise.all(pro);
  8276. logStatus.success();
  8277. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8278. this.socialTasks = this.undoneTasks;
  8279. if (window.DEBUG) {
  8280. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8281. }
  8282. GM_setValue(`gcTasks-${this.giveawayId}`, {
  8283. tasks: this.socialTasks,
  8284. time: new Date().getTime()
  8285. });
  8286. return true;
  8287. } catch (error) {
  8288. throwError(error, 'GiveeClub.classifyTask');
  8289. return false;
  8290. }
  8291. }
  8292. async verifyTask() {
  8293. try {
  8294. const logStatus = scripts_echoLog({
  8295. text: i18n('giveeClubVerifyNotice')
  8296. });
  8297. const taskButtons = $('.event-actions tr button').has('i.glyphicon-refresh').not('[data-type="user.adblock"]');
  8298. for (const button of taskButtons) {
  8299. button.click();
  8300. if ($(button).attr('data-type') !== 'steam.game.wishlist') {
  8301. await delay(1e3);
  8302. }
  8303. }
  8304. logStatus.warning(i18n('giveeClubVerifyFinished'));
  8305. return true;
  8306. } catch (error) {
  8307. throwError(error, 'Givekey.verifyTask');
  8308. return false;
  8309. }
  8310. }
  8311. #checkLogin() {
  8312. try {
  8313. if (!globalOptions.other.checkLogin) {
  8314. return true;
  8315. }
  8316. if ($('a[href*="/account/auth"]').length > 0) {
  8317. window.open($('a[href*="/account/auth"]').attr('href'), '_self');
  8318. }
  8319. return true;
  8320. } catch (error) {
  8321. throwError(error, 'GiveeClub.checkLogin');
  8322. return false;
  8323. }
  8324. }
  8325. #getGiveawayId() {
  8326. const giveawayId = window.location.href.match(/\/event\/([\d]+)/)?.[1];
  8327. if (giveawayId) {
  8328. this.giveawayId = giveawayId;
  8329. return true;
  8330. }
  8331. scripts_echoLog({
  8332. text: i18n('getFailed', 'GiveawayId')
  8333. });
  8334. return false;
  8335. }
  8336. async #checkLeftKey() {
  8337. try {
  8338. if (!globalOptions.other.checkLeftKey) {
  8339. return true;
  8340. }
  8341. if ($('.event-ended').length > 0 && $('.event-winner').length === 0) {
  8342. await external_Swal_default().fire({
  8343. icon: 'warning',
  8344. title: i18n('notice'),
  8345. text: i18n('giveawayEnded'),
  8346. confirmButtonText: i18n('confirm'),
  8347. cancelButtonText: i18n('cancel'),
  8348. showCancelButton: true
  8349. }).then(({
  8350. value
  8351. }) => {
  8352. if (value) {
  8353. window.close();
  8354. }
  8355. });
  8356. }
  8357. return true;
  8358. } catch (error) {
  8359. throwError(error, 'Giveawaysu.checkLeftKey');
  8360. return false;
  8361. }
  8362. }
  8363. }
  8364. const website_GiveeClub = GiveeClub;
  8365. const defaultOptions = {
  8366. maxPoint: '99999999'
  8367. };
  8368. class OpiumPulses {
  8369. name = 'OpiumPulses';
  8370. options = {
  8371. ...defaultOptions,
  8372. ...GM_getValue('OpiumPulsesOptions')
  8373. };
  8374. maxPoints = 99999999;
  8375. myPoints = 0;
  8376. buttons = [ 'doFreeTask', 'doPointTask' ];
  8377. static test() {
  8378. return window.location.host === 'www.opiumpulses.com';
  8379. }
  8380. async after() {
  8381. try {
  8382. if (!this.#checkLogin()) {
  8383. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8384. }
  8385. this.maxPoints = parseInt(this.options.maxPoint, 10);
  8386. } catch (error) {
  8387. throwError(error, 'OpiumPulses.after');
  8388. }
  8389. }
  8390. async doFreeTask() {
  8391. try {
  8392. this.#toggleTask('FREE');
  8393. } catch (error) {
  8394. throwError(error, 'OpiumPulses.doFreeTask');
  8395. }
  8396. }
  8397. async doPointTask() {
  8398. try {
  8399. this.myPoints = parseInt($('.page-header__nav-func-user-nav-items.points-items').text().match(/[\d]+/gim)?.[0] || '0', 10);
  8400. this.#toggleTask('points');
  8401. } catch (error) {
  8402. throwError(error, 'OpiumPulses.doPointTask');
  8403. }
  8404. }
  8405. async #toggleTask(type) {
  8406. try {
  8407. const items = $(`.giveaways-page-item:contains('${type}'):not(:contains('ENTERED'))`);
  8408. for (const item of items) {
  8409. const needPoints = parseInt($(item).find('.giveaways-page-item-header-points').text().match(/[\d]+/gim)?.[0] || '999999', 10);
  8410. const name = $(item).find('.giveaways-page-item-footer-name').text().trim();
  8411. if (type === 'points' && needPoints > this.myPoints) {
  8412. scripts_echoLog({}).warning(`${i18n('noPoints')}: ${name}`);
  8413. } else if (type === 'points' && !needPoints) {
  8414. scripts_echoLog({}).warning(`${i18n('getNeedPointsFailed')}: ${name}`);
  8415. } else if (!(type === 'points' && needPoints > this.maxPoints)) {
  8416. const logStatus = scripts_echoLog({
  8417. text: `${i18n('joiningLottery')}<a href="${$(item).find('a.giveaways-page-item-img-btn-more').attr('href')}" target="_blank">${name}</a>...`
  8418. });
  8419. const aElement = $(item).find('a.giveaways-page-item-img-btn-enter:contains(\'enter\')');
  8420. if (aElement?.attr('onclick')?.includes('checkUser')) {
  8421. const giveawayId = aElement.attr('onclick')?.match(/[\d]+/)?.[0];
  8422. if (giveawayId) {
  8423. checkUser(giveawayId);
  8424. }
  8425. }
  8426. if (!aElement.attr('href')) {
  8427. logStatus.error('Error: No "href".');
  8428. continue;
  8429. }
  8430. const {
  8431. result,
  8432. statusText,
  8433. status,
  8434. data
  8435. } = await tools_httpRequest({
  8436. url: aElement.attr('href'),
  8437. method: 'GET'
  8438. });
  8439. if (result === 'Success') {
  8440. const {
  8441. result: result0,
  8442. statusText: statusText0,
  8443. status: status0,
  8444. data: data0
  8445. } = await tools_httpRequest({
  8446. url: data?.finalUrl,
  8447. method: 'GET'
  8448. });
  8449. if (data0?.responseText && /You've entered this giveaway/gim.test(data0.responseText)) {
  8450. logStatus.success();
  8451. const points = data0.responseText.match(/Points:[\s]*?([\d]+)/)?.[1];
  8452. if (type === 'points' && points) {
  8453. this.myPoints = parseInt(points, 10);
  8454. }
  8455. } else if (data0?.responseText && /You're not eligible to enter/gim.test(data0.responseText)) {
  8456. logStatus.error('You\'re not eligible to enter');
  8457. } else {
  8458. logStatus.error(`${result0}:${statusText0}(${status0})`);
  8459. }
  8460. } else {
  8461. logStatus.error(`${result}:${statusText}(${status})`);
  8462. }
  8463. }
  8464. }
  8465. scripts_echoLog({
  8466. text: '-----END-----'
  8467. });
  8468. } catch (error) {
  8469. throwError(error, 'OpiumPulses.toggleTask');
  8470. }
  8471. }
  8472. init() {
  8473. return true;
  8474. }
  8475. classifyTask() {
  8476. return true;
  8477. }
  8478. #checkLogin() {
  8479. try {
  8480. if (!globalOptions.other.checkLogin) {
  8481. return true;
  8482. }
  8483. if ($('a[href*="/site/login"]').length > 1) {
  8484. window.open('/site/login', '_self');
  8485. }
  8486. return true;
  8487. } catch (error) {
  8488. throwError(error, 'OpiumPulses.checkLogin');
  8489. return false;
  8490. }
  8491. }
  8492. }
  8493. const website_OpiumPulses = OpiumPulses;
  8494. const external_dayjs_namespaceObject = dayjs;
  8495. var external_dayjs_default = __webpack_require__.n(external_dayjs_namespaceObject);
  8496. const leftKeyChecker = {
  8497. async classify(link) {
  8498. try {
  8499. if (/^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(link)) {
  8500. return await this.giveawaySu(link);
  8501. }
  8502. if (/^https?:\/\/givee\.club\/[\w]+?\/event\/[\d]+/.test(link)) {
  8503. return await this.giveeClub(link);
  8504. }
  8505. if (/^https?:\/\/gleam\.io\/.+?\/.+/.test(link)) {
  8506. return await this.gleam(link);
  8507. }
  8508. if (/^https?:\/\/www\.indiedb\.com\/giveaways\/.+/.test(link)) {
  8509. return await this.indieDb(link);
  8510. }
  8511. if (/^https?:\/\/key-hub\.eu\/giveaway\/[\d]+/.test(link)) {
  8512. return await this.keyhub(link);
  8513. }
  8514. if (/^https?:\/\/opquests\.com\/quests\/[\d]+/.test(link)) {
  8515. return await this.opquests(link);
  8516. }
  8517. if (/^https?:\/\/itch\.io\/s\/[\d]+?\/.*/.test(link)) {
  8518. return await this.itch(link);
  8519. }
  8520. return false;
  8521. } catch (error) {
  8522. throwError(error, 'leftKeyChecker.classify');
  8523. return false;
  8524. }
  8525. },
  8526. async giveawaySu(link) {
  8527. try {
  8528. const {
  8529. result,
  8530. data
  8531. } = await tools_httpRequest({
  8532. url: link,
  8533. method: 'GET'
  8534. });
  8535. if (result === 'Success' && data?.status === 200) {
  8536. if (data.responseText.includes('class="steam-login"')) {
  8537. return false;
  8538. }
  8539. if (data.responseText.includes('class="giveaway-ended"')) {
  8540. return 'Ended';
  8541. }
  8542. return 'Active';
  8543. }
  8544. return false;
  8545. } catch (error) {
  8546. throwError(error, 'leftKeyChecker.giveawaySu');
  8547. return false;
  8548. }
  8549. },
  8550. async giveeClub(link) {
  8551. try {
  8552. const {
  8553. result,
  8554. data
  8555. } = await tools_httpRequest({
  8556. url: link,
  8557. method: 'GET'
  8558. });
  8559. if (result === 'Success' && data?.status === 200) {
  8560. if (data.responseText.includes('class="event-winner"')) {
  8561. return 'Won';
  8562. }
  8563. if (data.responseText.includes('class="event-ended"')) {
  8564. return 'Ended';
  8565. }
  8566. return 'Active';
  8567. }
  8568. return false;
  8569. } catch (error) {
  8570. throwError(error, 'leftKeyChecker.giveeClub');
  8571. return false;
  8572. }
  8573. },
  8574. async gleam(link) {
  8575. try {
  8576. const {
  8577. result,
  8578. data
  8579. } = await tools_httpRequest({
  8580. url: link,
  8581. method: 'GET'
  8582. });
  8583. if (result === 'Success' && data?.status === 200) {
  8584. if (/incentives&quot;:{&quot;[\d]+?&quot;:\[&quot;.+?&quot;\]/.test(data.responseText)) {
  8585. return 'Won';
  8586. }
  8587. const campaignDiv = data.responseText.match(/<div class='popup-blocks-container'[\w\W]+?'>/)?.[0];
  8588. if (!campaignDiv) {
  8589. return false;
  8590. }
  8591. const campaignString = $(campaignDiv).attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  8592. if (!campaignString) {
  8593. return false;
  8594. }
  8595. const {
  8596. campaign
  8597. } = JSON.parse(campaignString);
  8598. if (campaign.banned) {
  8599. return 'Banned';
  8600. }
  8601. if (campaign.finished) {
  8602. return 'Ended';
  8603. }
  8604. if (campaign.paused) {
  8605. return 'Paused';
  8606. }
  8607. if (new Date().getTime() < campaign.starts_at * 1e3) {
  8608. return 'NotStart';
  8609. }
  8610. return 'Active';
  8611. }
  8612. return false;
  8613. } catch (error) {
  8614. throwError(error, 'leftKeyChecker.gleam');
  8615. return false;
  8616. }
  8617. },
  8618. async indieDb(link) {
  8619. try {
  8620. const {
  8621. result,
  8622. data
  8623. } = await tools_httpRequest({
  8624. url: link,
  8625. method: 'GET'
  8626. });
  8627. if (result === 'Success' && data?.status === 200) {
  8628. if (data.responseText.includes('Congrats you WON')) {
  8629. return 'Won';
  8630. }
  8631. if (data.responseText.includes('Giveaway is closed') || data.responseText.includes('next time')) {
  8632. return 'Ended';
  8633. }
  8634. return 'Active';
  8635. }
  8636. return false;
  8637. } catch (error) {
  8638. throwError(error, 'leftKeyChecker.indieDb');
  8639. return false;
  8640. }
  8641. },
  8642. async keyhub(link) {
  8643. try {
  8644. const {
  8645. result,
  8646. data
  8647. } = await tools_httpRequest({
  8648. url: link,
  8649. method: 'GET'
  8650. });
  8651. if (result === 'Success' && data?.status === 200) {
  8652. const keysleft = data.responseText.match(/<span id="keysleft">([\d]+?)<\/span>/)?.[1];
  8653. if (!keysleft) {
  8654. return false;
  8655. }
  8656. if (keysleft === '0') {
  8657. return 'Ended';
  8658. }
  8659. return `Active(${keysleft})`;
  8660. }
  8661. return false;
  8662. } catch (error) {
  8663. throwError(error, 'leftKeyChecker.keyhub');
  8664. return false;
  8665. }
  8666. },
  8667. async opquests(link) {
  8668. try {
  8669. const {
  8670. result,
  8671. data
  8672. } = await tools_httpRequest({
  8673. url: link,
  8674. method: 'GET'
  8675. });
  8676. if (result === 'Success' && data?.status === 200) {
  8677. const keysleft = data.responseText.match(/<div class="">[\s]*?([\d]+?)[\s]*?of/)?.[1];
  8678. if (!keysleft) {
  8679. return false;
  8680. }
  8681. if (keysleft === '0') {
  8682. return 'Ended';
  8683. }
  8684. return `Active(${keysleft})`;
  8685. } else if (data?.status === 404) {
  8686. return 'Ended';
  8687. }
  8688. return false;
  8689. } catch (error) {
  8690. throwError(error, 'leftKeyChecker.opquests');
  8691. return false;
  8692. }
  8693. },
  8694. async itch(link) {
  8695. try {
  8696. const {
  8697. result,
  8698. data
  8699. } = await tools_httpRequest({
  8700. url: link,
  8701. method: 'GET'
  8702. });
  8703. if (result === 'Success' && data?.status === 200) {
  8704. const endDate = data.responseText.match(/{"start_date":"[0-9A-Z-:]+?".*?"end_date":"([0-9A-Z-:]+?)".*?}/)?.[1];
  8705. if (!endDate) {
  8706. return false;
  8707. }
  8708. if (new Date().getTime() > new Date(endDate).getTime()) {
  8709. return 'Ended';
  8710. }
  8711. return `Active(${external_dayjs_default()(endDate).format('YYYY-MM-DD HH:mm:ss')})`;
  8712. }
  8713. return false;
  8714. } catch (error) {
  8715. throwError(error, 'leftKeyChecker.opquests');
  8716. return false;
  8717. }
  8718. }
  8719. };
  8720. const website_leftKeyChecker = leftKeyChecker;
  8721. const Keylol_defaultTasksTemplate = {
  8722. steam: {
  8723. groupLinks: [],
  8724. wishlistLinks: [],
  8725. curatorLinks: [],
  8726. curatorLikeLinks: [],
  8727. followLinks: [],
  8728. forumLinks: [],
  8729. announcementLinks: [],
  8730. workshopVoteLinks: [],
  8731. licenseLinks: []
  8732. },
  8733. discord: {
  8734. serverLinks: []
  8735. },
  8736. instagram: {
  8737. userLinks: []
  8738. },
  8739. vk: {
  8740. nameLinks: []
  8741. },
  8742. twitch: {
  8743. channelLinks: []
  8744. },
  8745. reddit: {
  8746. redditLinks: []
  8747. },
  8748. twitter: {
  8749. userLinks: [],
  8750. retweetLinks: []
  8751. },
  8752. youtube: {
  8753. channelLinks: [],
  8754. likeLinks: []
  8755. }
  8756. };
  8757. const Keylol_defaultTasks = JSON.stringify(Keylol_defaultTasksTemplate);
  8758. class Keylol extends website_Website {
  8759. name = 'Keylol';
  8760. socialTasks = JSON.parse(Keylol_defaultTasks);
  8761. undoneTasks = JSON.parse(Keylol_defaultTasks);
  8762. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect' ];
  8763. static test() {
  8764. 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'));
  8765. }
  8766. init() {
  8767. return true;
  8768. }
  8769. after() {
  8770. try {
  8771. const selector = this.name === 'Keylol' ? '#postlist>div[id^="post_"]:first' : 'div.container';
  8772. const mainPost = $(selector);
  8773. const discordLinks = mainPost.find('a[href*="discord.com"]:visible');
  8774. const redditLinks = mainPost.find('a[href*="reddit.com"]:visible');
  8775. const insLinks = mainPost.find('a[href*="instagram.com"]:visible');
  8776. const twitterLinks = mainPost.find('a[href*="twitter.com"]:visible,a[href*="x.com"]:visible');
  8777. const twitchLinks = mainPost.find('a[href*="twitch.tv"]:visible');
  8778. const vkLinks = mainPost.find('a[href*="vk.com"]:visible');
  8779. const steamStoreLinks = mainPost.find('a[href*="store.steampowered.com"]:visible');
  8780. const steamCommunityLinks = mainPost.find('a[href*="steamcommunity.com"]:visible');
  8781. const ytbLinks = mainPost.find('a[href*="youtube.com"]:visible');
  8782. if (discordLinks.length > 0) {
  8783. for (const discordLink of discordLinks) {
  8784. const link = $(discordLink).attr('href');
  8785. if (!(link && /^https?:\/\/discord\.com\/invite\/.+/.test(link))) {
  8786. continue;
  8787. }
  8788. this.#addBtn(discordLink, 'discord', 'serverLinks', link);
  8789. }
  8790. }
  8791. if (redditLinks.length > 0) {
  8792. for (const redditLink of redditLinks) {
  8793. const link = $(redditLink).attr('href');
  8794. if (!(link && /^https?:\/\/www\.reddit\.com\/(r|user)\/.+/.test(link))) {
  8795. continue;
  8796. }
  8797. this.#addBtn(redditLink, 'reddit', 'redditLinks', link);
  8798. }
  8799. }
  8800. if (insLinks.length > 0) {
  8801. for (const insLink of insLinks) {
  8802. const link = $(insLink).attr('href');
  8803. if (!(link && /^https:\/\/www\.instagram\.com\/.+/.test(link))) {
  8804. continue;
  8805. }
  8806. this.#addBtn(insLink, 'instagram', 'userLinks', link);
  8807. }
  8808. }
  8809. if (twitterLinks.length > 0) {
  8810. for (const twitterLink of twitterLinks) {
  8811. const link = $(twitterLink).attr('href');
  8812. if (!(link && /^https:\/\/twitter\.com\/.+/.test(link))) {
  8813. continue;
  8814. }
  8815. if (/https:\/\/twitter\.com\/.*?\/status\/[\d]+/.test(link)) {
  8816. this.#addBtn(twitterLink, 'twitter', 'retweetLinks', link);
  8817. } else {
  8818. this.#addBtn(twitterLink, 'twitter', 'userLinks', link);
  8819. }
  8820. }
  8821. }
  8822. if (twitchLinks.length > 0) {
  8823. for (const twitchLink of twitchLinks) {
  8824. const link = $(twitchLink).attr('href');
  8825. if (!(link && /^https:\/\/(www\.)?twitch\.tv\/.+/.test(link))) {
  8826. continue;
  8827. }
  8828. this.#addBtn(twitchLink, 'twitch', 'channelLinks', link);
  8829. }
  8830. }
  8831. if (vkLinks.length > 0) {
  8832. for (const vkLink of vkLinks) {
  8833. const link = $(vkLink).attr('href');
  8834. if (!(link && /^https:\/\/vk\.com\/.+/.test(link))) {
  8835. continue;
  8836. }
  8837. this.#addBtn(vkLink, 'vk', 'nameLinks', link);
  8838. }
  8839. }
  8840. if (steamStoreLinks.length > 0) {
  8841. for (const steamStoreLink of steamStoreLinks) {
  8842. const link = $(steamStoreLink).attr('href');
  8843. if (!link) {
  8844. continue;
  8845. }
  8846. if (/curator\/[\d]+/.test(link)) {
  8847. this.#addBtn(steamStoreLink, 'steam', 'curatorLinks', link);
  8848. } else if (/(publisher|developer|franchise)\/.+/.test(link)) {
  8849. this.#addBtn(steamStoreLink, 'steam', 'curatorLikeLinks', link);
  8850. } else if (/news(hub)?\/app\/[\d]+\/view\/[\d]+/.test(link)) {
  8851. this.#addBtn(steamStoreLink, 'steam', 'announcementLinks', link);
  8852. } else if (/app\/[\d]+/.test(link)) {
  8853. this.#addBtn(steamStoreLink, 'steam', 'followLinks', link);
  8854. this.#addBtn(steamStoreLink, 'steam', 'wishlistLinks', link);
  8855. }
  8856. }
  8857. }
  8858. if (steamCommunityLinks.length > 0) {
  8859. for (const steamCommunityLink of steamCommunityLinks) {
  8860. const link = $(steamCommunityLink).attr('href');
  8861. if (!link) {
  8862. continue;
  8863. }
  8864. if (/groups\/.+/.test(link)) {
  8865. this.#addBtn(steamCommunityLink, 'steam', 'groupLinks', link);
  8866. } else if (/announcements\/detail\/[\d]+/.test(link)) {
  8867. this.#addBtn(steamCommunityLink, 'steam', 'announcementLinks', link);
  8868. }
  8869. }
  8870. }
  8871. if (ytbLinks.length > 0) {
  8872. for (const ytbLink of ytbLinks) {
  8873. const link = $(ytbLink).attr('href');
  8874. if (!link) {
  8875. continue;
  8876. }
  8877. this.#addBtn(ytbLink, 'youtube', 'channelLinks', link);
  8878. this.#addBtn(ytbLink, 'youtube', 'likeLinks', link);
  8879. }
  8880. }
  8881. 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');
  8882. if (giveawayLinks.length > 0) {
  8883. for (const giveawayLink of giveawayLinks) {
  8884. const link = $(giveawayLink).attr('href');
  8885. if (!link) {
  8886. continue;
  8887. }
  8888. website_leftKeyChecker.classify(link).then(status => {
  8889. if (!status) {
  8890. return;
  8891. }
  8892. if (/^Active/.test(status)) {
  8893. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status active" title="${i18n('Active')}">${status}</font>`);
  8894. return;
  8895. }
  8896. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status not-active" title="${i18n(status)}">${status}</font>`);
  8897. }).catch(error => {
  8898. throwError(error, 'keylol.after -> leftKeyChecker');
  8899. });
  8900. }
  8901. }
  8902. if (this.name === 'Keylol') {
  8903. const asfLinks = mainPost.find('a[href^="#asf"]:visible');
  8904. if (asfLinks.length > 0) {
  8905. for (const asfLink of asfLinks) {
  8906. const link = $(asfLink).attr('href');
  8907. if (!link) {
  8908. continue;
  8909. }
  8910. this.#addBtn($(`a[href="${link}"]`).after('<span style="color: #ccc; margin: 0 -5px 0 5px"> | </span>').next()[0], 'steam', 'licenseLinks', `appid-${link.replace('#asf', '')}`);
  8911. }
  8912. }
  8913. const subLinks = mainPost.find('a[href*="steamdb.info/sub/"]:visible');
  8914. if (subLinks.length > 0) {
  8915. for (const subLink of subLinks) {
  8916. const link = $(subLink).attr('href');
  8917. if (!link) {
  8918. continue;
  8919. }
  8920. const subid = link.match(/^https:\/\/steamdb\.info\/sub\/([\d]+)/)?.[1];
  8921. if (!subid) {
  8922. continue;
  8923. }
  8924. this.#addBtn(subLink, 'steam', 'licenseLinks', `subid-${subid}`);
  8925. }
  8926. }
  8927. const asfLinks2 = mainPost.find('.blockcode:contains("addlicense"):visible');
  8928. if (asfLinks2.length > 0) {
  8929. for (const asfLink of asfLinks2) {
  8930. const subid = asfLink.innerText.match(/[\d]+/g);
  8931. if (!subid || subid.length === 0) {
  8932. continue;
  8933. }
  8934. this.#addBtn($(asfLink).children('em')[0], 'steam', 'licenseLinks', `subid-${subid.join(',')}`);
  8935. }
  8936. }
  8937. }
  8938. } catch (error) {
  8939. throwError(error, 'keylol.after');
  8940. }
  8941. }
  8942. classifyTask(action) {
  8943. try {
  8944. this.socialTasks = JSON.parse(Keylol_defaultTasks);
  8945. this.undoneTasks = JSON.parse(Keylol_defaultTasks);
  8946. const selectedBtns = $('.auto-task-keylol[selected="selected"]:visible');
  8947. for (const btn of selectedBtns) {
  8948. const button = $(btn);
  8949. const social = button.attr('data-social');
  8950. const type = button.attr('data-type');
  8951. const link = button.attr('data-link');
  8952. if (!(social && type && link)) {
  8953. continue;
  8954. }
  8955. if (action === 'do') {
  8956. this.undoneTasks[social][type].push(link);
  8957. }
  8958. if (action === 'undo') {
  8959. this.socialTasks[social][type].push(link);
  8960. }
  8961. }
  8962. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8963. this.socialTasks = this.uniqueTasks(this.socialTasks);
  8964. if (window.DEBUG) {
  8965. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8966. }
  8967. return true;
  8968. } catch (error) {
  8969. throwError(error, 'Keylol.classifyTask');
  8970. return false;
  8971. }
  8972. }
  8973. selectAll() {
  8974. try {
  8975. $('.auto-task-keylol:visible').attr('selected', 'selected');
  8976. } catch (error) {
  8977. throwError(error, 'Keylol.selectAll');
  8978. }
  8979. }
  8980. selectNone() {
  8981. try {
  8982. $('.auto-task-keylol:visible').removeAttr('selected');
  8983. } catch (error) {
  8984. throwError(error, 'Keylol.selectNone');
  8985. }
  8986. }
  8987. invertSelect() {
  8988. try {
  8989. $('.auto-task-keylol:visible').each((index, element) => {
  8990. element.getAttribute('selected') ? element.removeAttribute('selected') : element.setAttribute('selected', 'selected');
  8991. });
  8992. } catch (error) {
  8993. throwError(error, 'Keylol.invertSelect');
  8994. }
  8995. }
  8996. #addBtn(before, social, linkType, link) {
  8997. try {
  8998. $(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>`);
  8999. } catch (error) {
  9000. throwError(error, 'keylol.addBtn');
  9001. }
  9002. }
  9003. }
  9004. const website_Keylol = Keylol;
  9005. const Opquests_defaultTasks = {
  9006. steam: {
  9007. groupLinks: [],
  9008. wishlistLinks: [],
  9009. followLinks: [],
  9010. curatorLikeLinks: []
  9011. }
  9012. };
  9013. class Opquests extends website_Website {
  9014. name = 'Opquests';
  9015. undoneTasks = {
  9016. ...Opquests_defaultTasks
  9017. };
  9018. buttons = [ 'doTask', 'verifyTask', 'getKey' ];
  9019. static test() {
  9020. return window.location.host === 'opquests.com';
  9021. }
  9022. async before() {
  9023. const opquestsVerifyTasks = GM_getValue('opquestsVerifyTasks') || [];
  9024. if (opquestsVerifyTasks.length > 0) {
  9025. const taskId = opquestsVerifyTasks.pop();
  9026. GM_setValue('opquestsVerifyTasks', opquestsVerifyTasks);
  9027. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9028. } else {
  9029. if (GM_getValue('opquestsVerifyTasks')) {
  9030. GM_deleteValue('opquestsVerifyTasks');
  9031. }
  9032. }
  9033. }
  9034. async after() {
  9035. try {
  9036. if (!this.#checkLogin()) {
  9037. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9038. }
  9039. } catch (error) {
  9040. throwError(error, 'Opquests.after');
  9041. }
  9042. }
  9043. init() {
  9044. try {
  9045. const logStatus = scripts_echoLog({
  9046. text: i18n('initing')
  9047. });
  9048. if ($('a[href*="/auth/redirect"]').length > 0) {
  9049. window.open('/auth/redirect', '_self');
  9050. logStatus.warning(i18n('needLogin'));
  9051. return false;
  9052. }
  9053. if (!this.#getGiveawayId()) {
  9054. return false;
  9055. }
  9056. this.initialized = true;
  9057. logStatus.success();
  9058. return true;
  9059. } catch (error) {
  9060. throwError(error, 'Opquests.init');
  9061. return false;
  9062. }
  9063. }
  9064. async classifyTask(action) {
  9065. try {
  9066. if (action === 'undo') {
  9067. scripts_echoLog({
  9068. text: i18n('cannotUndo')
  9069. });
  9070. return false;
  9071. }
  9072. const logStatus = scripts_echoLog({
  9073. text: i18n('getTasksInfo')
  9074. });
  9075. const tasks = $('.w-full:contains("Validate") .items-center');
  9076. for (const task of tasks) {
  9077. const link = $(task).find('a:contains("Open")').attr('href');
  9078. const taskDes = $(task).find('div').eq(1).text().trim();
  9079. if (!link) {
  9080. continue;
  9081. }
  9082. if (/steamcommunity\.com\/groups\//.test(link)) {
  9083. this.undoneTasks.steam.groupLinks.push(link);
  9084. } else if (/store\.steampowered\.com\/app\//.test(link)) {
  9085. if (/wishlist/gim.test(taskDes)) {
  9086. this.undoneTasks.steam.wishlistLinks.push(link);
  9087. } else if (/follow/gim.test(taskDes)) {
  9088. this.undoneTasks.steam.followLinks.push(link);
  9089. }
  9090. } else if (/store\.steampowered\.com\/(publisher|developer|curator)\//.test(link) && /follow/gim.test(taskDes)) {
  9091. this.undoneTasks.steam.curatorLikeLinks.push(link);
  9092. } else {
  9093. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  9094. }
  9095. }
  9096. logStatus.success();
  9097. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9098. if (window.DEBUG) {
  9099. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9100. }
  9101. return true;
  9102. } catch (error) {
  9103. throwError(error, 'Opquests.classifyTask');
  9104. return false;
  9105. }
  9106. }
  9107. async verifyTask() {
  9108. try {
  9109. if (!this.initialized) {
  9110. this.init();
  9111. }
  9112. const tasks = $.makeArray($('div.w-full').find('.items-center').has('button.submit-loader')).map(ele => $(ele).find('input[name="task_id"]').val());
  9113. await this.#confirm();
  9114. const taskId = tasks.pop();
  9115. GM_setValue('opquestsVerifyTasks', tasks);
  9116. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9117. return true;
  9118. } catch (error) {
  9119. throwError(error, 'Opquests.verifyTask');
  9120. return false;
  9121. }
  9122. }
  9123. async #confirm() {
  9124. try {
  9125. const logStatus = scripts_echoLog({
  9126. html: `<li>${i18n('confirmingTask')}...<font></font></li>`
  9127. });
  9128. const {
  9129. result,
  9130. statusText,
  9131. status,
  9132. data
  9133. } = await tools_httpRequest({
  9134. url: `https://opquests.com/quests/${this.giveawayId}?confirm=1`,
  9135. method: 'GET',
  9136. nochche: true,
  9137. headers: {
  9138. origin: 'https://opquests.com',
  9139. referer: `https://opquests.com/warning?id=${this.giveawayId}`
  9140. }
  9141. });
  9142. if (result === 'Success') {
  9143. if (data?.status === 200) {
  9144. logStatus.success();
  9145. return true;
  9146. }
  9147. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9148. return false;
  9149. }
  9150. logStatus.error(`${result}:${statusText}(${status})`);
  9151. return false;
  9152. } catch (error) {
  9153. throwError(error, 'Opquests.confirm');
  9154. return false;
  9155. }
  9156. }
  9157. async getKey(isButton) {
  9158. try {
  9159. const logStatus = scripts_echoLog({
  9160. text: i18n('gettingKey')
  9161. });
  9162. const {
  9163. result,
  9164. statusText,
  9165. status,
  9166. data
  9167. } = await tools_httpRequest({
  9168. url: 'https://opquests.com/keys',
  9169. method: 'GET'
  9170. });
  9171. if (result === 'Success') {
  9172. if (data?.responseText) {
  9173. const key = $(data?.responseText).find(`div.items-center:contains("${$('h1.font-bold').text().trim().replace(' Quest', '')}")`).find('div.font-bold').next().text();
  9174. if (!key) {
  9175. logStatus.error('Error: Key was not found');
  9176. if (isButton) {
  9177. window.open('https://opquests.com/keys', '_self');
  9178. }
  9179. return false;
  9180. }
  9181. logStatus.success();
  9182. scripts_echoLog({}).success(key);
  9183. return true;
  9184. }
  9185. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9186. return false;
  9187. }
  9188. logStatus.error(`${result}:${statusText}(${status})`);
  9189. return false;
  9190. } catch (error) {
  9191. throwError(error, 'Opquests.getGiveawayId');
  9192. return false;
  9193. }
  9194. }
  9195. #getGiveawayId() {
  9196. try {
  9197. const giveawayId = window.location.href.match(/quests\/([\d]+)/)?.[1];
  9198. if (giveawayId) {
  9199. this.giveawayId = giveawayId;
  9200. return true;
  9201. }
  9202. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  9203. return false;
  9204. } catch (error) {
  9205. throwError(error, 'Opquests.getGiveawayId');
  9206. return false;
  9207. }
  9208. }
  9209. #checkLogin() {
  9210. try {
  9211. if (!globalOptions.other.checkLogin) {
  9212. return true;
  9213. }
  9214. if ($('a[href*="/auth/redirect"]').length > 0) {
  9215. window.open('/auth/redirect', '_self');
  9216. }
  9217. return true;
  9218. } catch (error) {
  9219. throwError(error, 'Opquests.checkLogin');
  9220. return false;
  9221. }
  9222. }
  9223. }
  9224. const website_Opquests = Opquests;
  9225. const Gleam_defaultTasksTemplate = {
  9226. steam: {
  9227. groupLinks: [],
  9228. wishlistLinks: [],
  9229. followLinks: [],
  9230. curatorLinks: [],
  9231. curatorLikeLinks: []
  9232. },
  9233. twitter: {
  9234. userLinks: [],
  9235. retweetLinks: []
  9236. },
  9237. twitch: {
  9238. channelLinks: []
  9239. },
  9240. discord: {
  9241. serverLinks: []
  9242. },
  9243. youtube: {
  9244. channelLinks: []
  9245. },
  9246. extra: {
  9247. gleam: []
  9248. }
  9249. };
  9250. const Gleam_defaultTasks = JSON.stringify(Gleam_defaultTasksTemplate);
  9251. const Gleam_defaultOptions = {
  9252. vlootUsername: '',
  9253. gameroundUsername: ''
  9254. };
  9255. class Gleam extends website_Website {
  9256. name = 'Gleam';
  9257. undoneTasks = JSON.parse(Gleam_defaultTasks);
  9258. socialTasks = JSON.parse(Gleam_defaultTasks);
  9259. options = {
  9260. ...Gleam_defaultOptions,
  9261. ...GM_getValue('GleamOptions')
  9262. };
  9263. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  9264. static test() {
  9265. return window.location.host === 'gleam.io';
  9266. }
  9267. async after() {
  9268. try {
  9269. if (window.location.search.includes('8b07d23f4bfa65f9')) {
  9270. const checkComplete = setInterval(() => {
  9271. if ($('.entry-content .entry-method i.fa-check').length > 0) {
  9272. clearInterval(checkComplete);
  9273. window.close();
  9274. }
  9275. });
  9276. for (const task of $('.entry-content .entry-method')) {
  9277. const taskInfo = $(task).find('.user-links');
  9278. const expandInfo = $(task).find('.expandable');
  9279. const aElements = expandInfo.find('a.btn,a:contains(Continue),button:contains(Continue)');
  9280. if (aElements.length > 0) {
  9281. for (const element of aElements) {
  9282. const $element = $(element);
  9283. const href = $element.attr('href');
  9284. $element.removeAttr('href')[0].click();
  9285. $element.attr('href', href);
  9286. await delay(1e3);
  9287. }
  9288. }
  9289. taskInfo[0].click();
  9290. await delay(1e3);
  9291. }
  9292. scripts_echoLog({}).warning(i18n('gleamTaskNotice'));
  9293. } else if (!await this.#checkLeftKey()) {
  9294. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  9295. }
  9296. } catch (error) {
  9297. throwError(error, 'Gleam.after');
  9298. return false;
  9299. }
  9300. }
  9301. init() {
  9302. try {
  9303. const logStatus = scripts_echoLog({
  9304. text: i18n('initing')
  9305. });
  9306. if (!this.#getGiveawayId()) {
  9307. return false;
  9308. }
  9309. this.initialized = true;
  9310. logStatus.success();
  9311. return true;
  9312. } catch (error) {
  9313. throwError(error, 'Gleam.init');
  9314. return false;
  9315. }
  9316. }
  9317. async classifyTask(action) {
  9318. try {
  9319. const logStatus = scripts_echoLog({
  9320. text: i18n('getTasksInfo')
  9321. });
  9322. if (action === 'undo') {
  9323. this.socialTasks = GM_getValue(`gleamTasks-${this.giveawayId}`)?.tasks || JSON.parse(Gleam_defaultTasks);
  9324. }
  9325. const tasks = $('.entry-content .entry-method');
  9326. for (const task of tasks) {
  9327. const $task = $(task);
  9328. if (action === 'do' && $task.find('i.fa-question').length === 0) {
  9329. continue;
  9330. }
  9331. const socialIcon = $task.find('.icon-wrapper i');
  9332. const taskInfo = $task.find('.user-links');
  9333. const taskText = taskInfo.text().trim();
  9334. const expandInfo = $task.find('.expandable');
  9335. const aElements = expandInfo.find('a.btn');
  9336. if (aElements.length > 0) {
  9337. for (const element of aElements) {
  9338. const $element = $(element);
  9339. const href = $element.attr('href');
  9340. $element.removeAttr('href')[0].click();
  9341. $element.attr('href', href);
  9342. }
  9343. }
  9344. if (socialIcon.hasClass('fa-twitter')) {
  9345. const link = $task.find('a[href^="https://twitter.com/"],a[href^="https://x.com/"]').attr('href');
  9346. if (!link) {
  9347. continue;
  9348. }
  9349. if (/follow/gi.test(taskText)) {
  9350. if (action === 'undo') {
  9351. this.socialTasks.twitter.userLinks.push(link);
  9352. }
  9353. if (action === 'do') {
  9354. this.undoneTasks.twitter.userLinks.push(link);
  9355. }
  9356. } else if (/retweet/gim.test(taskText)) {
  9357. if (action === 'undo') {
  9358. this.socialTasks.twitter.retweetLinks.push(link);
  9359. }
  9360. if (action === 'do') {
  9361. this.undoneTasks.twitter.retweetLinks.push(link);
  9362. }
  9363. }
  9364. } else if (socialIcon.hasClass('fa-twitch')) {
  9365. if (/follow/gim.test(taskText)) {
  9366. const link = $task.find('a[href^="https://twitch.tv/"]').attr('href');
  9367. if (!link) {
  9368. continue;
  9369. }
  9370. if (action === 'undo') {
  9371. this.socialTasks.twitch.channelLinks.push(link);
  9372. }
  9373. if (action === 'do') {
  9374. this.undoneTasks.twitch.channelLinks.push(link);
  9375. }
  9376. }
  9377. } else if (socialIcon.hasClass('fa-discord')) {
  9378. if (/join/gim.test(taskText)) {
  9379. let link = $task.find('a[href^="https://discord.com/invite/"]').attr('href');
  9380. if (!link) {
  9381. const ggLink = $task.find('a[href^="https://discord.gg/"]').attr('href')?.match(/discord\.gg\/([^/]+)/)?.[1];
  9382. if (!ggLink) {
  9383. continue;
  9384. }
  9385. link = `https://discord.com/invite/${ggLink}`;
  9386. }
  9387. if (action === 'undo') {
  9388. this.socialTasks.discord.serverLinks.push(link);
  9389. }
  9390. if (action === 'do') {
  9391. this.undoneTasks.discord.serverLinks.push(link);
  9392. }
  9393. }
  9394. } else if (socialIcon.hasClass('fa-external-link-square-alt')) {
  9395. continue;
  9396. } else if (socialIcon.hasClass('fa-youtube')) {
  9397. if (/subscribe/gim.test(taskText)) {
  9398. const link = $task.find('a[href^="https://www.youtube.com/channel/"]').attr('href');
  9399. if (!link) {
  9400. continue;
  9401. }
  9402. if (action === 'undo') {
  9403. this.socialTasks.youtube.channelLinks.push(link);
  9404. }
  9405. if (action === 'do') {
  9406. this.undoneTasks.youtube.channelLinks.push(link);
  9407. }
  9408. }
  9409. } else if (socialIcon.attr('class')?.includes('steam')) {
  9410. if (/join.*group/gi.test(taskText)) {
  9411. const link = $task.find('a[href^="https://steamcommunity.com/groups/"]').attr('href');
  9412. if (!link) {
  9413. continue;
  9414. }
  9415. if (action === 'undo') {
  9416. this.socialTasks.steam.groupLinks.push(link);
  9417. }
  9418. if (action === 'do') {
  9419. this.undoneTasks.steam.groupLinks.push(link);
  9420. }
  9421. } else if (/follow.*curator/gi.test(taskText)) {
  9422. const link = $task.find('a[href^="https://store.steampowered.com/curator/"]').attr('href');
  9423. if (!link) {
  9424. continue;
  9425. }
  9426. if (action === 'undo') {
  9427. this.socialTasks.steam.curatorLinks.push(link);
  9428. }
  9429. if (action === 'do') {
  9430. this.undoneTasks.steam.curatorLinks.push(link);
  9431. }
  9432. }
  9433. } else if (socialIcon.hasClass('fa-shield') && taskText.includes('vloot.io') || socialIcon.hasClass('fa-tiktok')) {
  9434. const continueBtn = expandInfo.find('span:contains(Continue),button:contains(Continue)');
  9435. for (const button of continueBtn) {
  9436. button.click();
  9437. await delay(500);
  9438. expandInfo.find('input').val(this.options.vlootUsername);
  9439. }
  9440. } else if (socialIcon.hasClass('fa-gamepad-alt') && taskText.includes('Gameround')) {
  9441. const continueBtn = expandInfo.find('span:contains(Continue),button:contains(Continue)');
  9442. for (const button of continueBtn) {
  9443. button.click();
  9444. await delay(500);
  9445. expandInfo.find('input').val(this.options.gameroundUsername);
  9446. }
  9447. } else if (socialIcon.hasClass('fa-bullhorn') && /Complete/gi.test(taskText)) {
  9448. if (action !== 'do') {
  9449. continue;
  9450. }
  9451. const gleamLink = await this.#getGleamLink(taskText);
  9452. if (!gleamLink) {
  9453. continue;
  9454. }
  9455. this.undoneTasks.extra.gleam.push(gleamLink);
  9456. } else if (socialIcon.hasClass('fa-question') || socialIcon.hasClass('fa-reddit') || socialIcon.hasClass('fa-instagram') || socialIcon.hasClass('fa-facebook-f') || socialIcon.hasClass('fa-telegram-plane') || socialIcon.hasClass('fa-telegram') || socialIcon.hasClass('fa-vk') || socialIcon.hasClass('fa-envelope') || socialIcon.hasClass('fa-gift') || socialIcon.hasClass('fa-square-up-right') || socialIcon.hasClass('fa-gamepad-modern') || socialIcon.hasClass('fa-shield') && taskText.includes('one of our giveaways') || socialIcon.hasClass('fa-shield') && taskText.includes('Check out')) {} else {
  9457. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskText}`);
  9458. }
  9459. }
  9460. logStatus.success();
  9461. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9462. this.socialTasks = this.uniqueTasks(this.socialTasks);
  9463. if (window.DEBUG) {
  9464. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9465. }
  9466. GM_setValue(`gleamTasks-${this.giveawayId}`, {
  9467. tasks: this.socialTasks,
  9468. time: new Date().getTime()
  9469. });
  9470. return true;
  9471. } catch (error) {
  9472. throwError(error, 'Gleam.classifyTask');
  9473. return false;
  9474. }
  9475. }
  9476. async extraDoTask({
  9477. gleam
  9478. }) {
  9479. try {
  9480. const pro = [];
  9481. for (const link of gleam) {
  9482. pro.push(this.#doGleamTask(link));
  9483. }
  9484. return Promise.all(pro).then(() => true);
  9485. } catch (error) {
  9486. throwError(error, 'Gleam.extraDoTask');
  9487. return false;
  9488. }
  9489. }
  9490. async verifyTask() {
  9491. try {
  9492. scripts_echoLog({
  9493. text: `${i18n('verifyingTask')}...`
  9494. });
  9495. const tasks = $('.entry-content .entry-method');
  9496. unsafeWindow._OxA = '_OxA';
  9497. for (const task of tasks) {
  9498. if ($('[campaign-key="campaign.key"]').length > 0) {
  9499. return scripts_echoLog({
  9500. text: i18n('campaign')
  9501. });
  9502. }
  9503. const $task = $(task);
  9504. if ($task.find('i.fa-question').length === 0) {
  9505. continue;
  9506. }
  9507. const taskInfo = $task.find('.user-links');
  9508. taskInfo[0].click();
  9509. unsafeWindow.$hookTimer?.setSpeed(1e3);
  9510. await delay(3e3);
  9511. unsafeWindow.$hookTimer?.setSpeed(1);
  9512. await this.#checkSync();
  9513. const continueBtn = $task.find('.expandable').find('span:contains(Continue),button:contains(Continue)');
  9514. for (const button of continueBtn) {
  9515. button.click();
  9516. await delay(500);
  9517. await this.#checkSync();
  9518. }
  9519. }
  9520. scripts_echoLog({
  9521. text: i18n('verifiedGleamTasks')
  9522. });
  9523. } catch (error) {
  9524. throwError(error, 'Gleam.verifyTask');
  9525. return false;
  9526. }
  9527. }
  9528. async #checkSync() {
  9529. try {
  9530. return await new Promise(resolve => {
  9531. const checker = setInterval(() => {
  9532. if ($('.entry-content .entry-method i.fa-sync').length === 0) {
  9533. clearInterval(checker);
  9534. resolve(true);
  9535. }
  9536. }, 500);
  9537. });
  9538. } catch (error) {
  9539. throwError(error, 'Gleam.checkSync');
  9540. return false;
  9541. }
  9542. }
  9543. async #doGleamTask(link) {
  9544. try {
  9545. const logStatus = scripts_echoLog({
  9546. text: i18n('doingGleamTask')
  9547. });
  9548. return await new Promise(resolve => {
  9549. GM_openInTab(`${link}?8b07d23f4bfa65f9`, {
  9550. active: true,
  9551. insert: true,
  9552. setParent: true
  9553. }).onclose = () => {
  9554. logStatus.success();
  9555. resolve(true);
  9556. };
  9557. });
  9558. } catch (error) {
  9559. throwError(error, 'Gleam.doGleamTask');
  9560. return false;
  9561. }
  9562. }
  9563. #getGiveawayId() {
  9564. try {
  9565. const giveawayId = window.location.pathname;
  9566. if (giveawayId) {
  9567. this.giveawayId = giveawayId;
  9568. return true;
  9569. }
  9570. scripts_echoLog({
  9571. text: i18n('getFailed', 'GiveawayId')
  9572. });
  9573. return false;
  9574. } catch (error) {
  9575. throwError(error, 'Gleam.getGiveawayId');
  9576. return false;
  9577. }
  9578. }
  9579. async #getGleamLink(title) {
  9580. try {
  9581. const logStatus = scripts_echoLog({
  9582. text: i18n('gettingGleamLink')
  9583. });
  9584. const {
  9585. result,
  9586. statusText,
  9587. status,
  9588. data
  9589. } = await tools_httpRequest({
  9590. url: 'https://www.vloot.io/api/v1/giveaways',
  9591. method: 'GET',
  9592. responseType: 'json'
  9593. });
  9594. if (result === 'Success') {
  9595. if (data?.status === 200 && data?.response?.Success === true && data?.response?.Data) {
  9596. const {
  9597. link
  9598. } = data.response.Data.find(giveaway => title.replace(/[\s]/g, '').toLowerCase().includes(giveaway.title.replace(/[\s]/g, '').toLowerCase())) || {};
  9599. if (link) {
  9600. logStatus.success();
  9601. return link;
  9602. }
  9603. logStatus.error(`Error:${i18n('getLinkFailed')}`);
  9604. return false;
  9605. }
  9606. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9607. return false;
  9608. }
  9609. logStatus.error(`${result}:${statusText}(${status})`);
  9610. return false;
  9611. } catch (error) {
  9612. throwError(error, 'Gleam.getGleamLink');
  9613. return false;
  9614. }
  9615. }
  9616. async #checkLeftKey() {
  9617. try {
  9618. if (!globalOptions.other.checkLeftKey) {
  9619. return true;
  9620. }
  9621. const campaignString = $('div.popup-blocks-container').attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  9622. if (!campaignString) {
  9623. return false;
  9624. }
  9625. const {
  9626. campaign,
  9627. incentive
  9628. } = JSON.parse(campaignString);
  9629. const controllerString = $('div.campaign.reward').attr('ng-init')?.match(/initContestant\(([\w\W]+?)\);/)?.[1];
  9630. let ownedKey = false;
  9631. if (controllerString) {
  9632. if (JSON.parse(controllerString).contestant?.claims?.incentives?.[incentive.id]?.length) {
  9633. ownedKey = true;
  9634. }
  9635. }
  9636. if (campaign.banned || campaign.finished && !ownedKey || campaign.paused || new Date().getTime() < campaign.starts_at * 1e3) {
  9637. await external_Swal_default().fire({
  9638. icon: 'warning',
  9639. title: i18n('notice'),
  9640. text: i18n('giveawayNotWork'),
  9641. confirmButtonText: i18n('confirm'),
  9642. cancelButtonText: i18n('cancel'),
  9643. showCancelButton: true
  9644. }).then(({
  9645. value
  9646. }) => {
  9647. if (value) {
  9648. window.close();
  9649. }
  9650. });
  9651. }
  9652. return true;
  9653. } catch (error) {
  9654. throwError(error, 'Gleam.checkLeftKey');
  9655. return false;
  9656. }
  9657. }
  9658. }
  9659. const website_Gleam = Gleam;
  9660. const SweepWidget_defaultOptions = {
  9661. username: '',
  9662. email: ''
  9663. };
  9664. class SweepWidget extends website_Website {
  9665. name = 'SweepWidget';
  9666. options = {
  9667. ...SweepWidget_defaultOptions,
  9668. ...GM_getValue('SweepWidgetOptions')
  9669. };
  9670. buttons = [ 'doTask' ];
  9671. static test() {
  9672. return /^https?:\/\/sweepwidget\.com\/view\/[\d]+/.test(window.location.href);
  9673. }
  9674. async after() {
  9675. try {
  9676. if (!this.#checkLogin()) {
  9677. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9678. }
  9679. } catch (error) {
  9680. throwError(error, 'SweepWidget.after');
  9681. }
  9682. }
  9683. init() {
  9684. try {
  9685. const logStatus = scripts_echoLog({
  9686. text: i18n('initing')
  9687. });
  9688. if (!this.#checkLogin()) {
  9689. logStatus.warning(i18n('needLogin'));
  9690. return false;
  9691. }
  9692. if (!this.#getGiveawayId()) {
  9693. return false;
  9694. }
  9695. this.initialized = true;
  9696. logStatus.success();
  9697. return true;
  9698. } catch (error) {
  9699. throwError(error, 'SweepWidget.init');
  9700. return false;
  9701. }
  9702. }
  9703. classifyTask() {
  9704. return true;
  9705. }
  9706. async doTask() {
  9707. try {
  9708. if ($('#unlock_rewards_main_wrapper').length === 0) {
  9709. if ($('input[name="sw__login_name"]:visible').length > 0) {
  9710. $('input[name="sw__login_name"]').val(this.options.username);
  9711. }
  9712. if ($('input[name="sw__login_email"]:visible').length > 0) {
  9713. $('input[name="sw__login_email"]').val(this.options.email);
  9714. }
  9715. if ($('#sw_login_button:visible').length > 0) {
  9716. $('#sw_login_button')[0].click();
  9717. }
  9718. if (!await this.#checkEnter()) {
  9719. return false;
  9720. }
  9721. }
  9722. const logStatus = scripts_echoLog({
  9723. text: i18n('SweepWidgetNotice')
  9724. });
  9725. const tasks = $('#sw_inner_entry_methods_l2_wrapper>div.sw_entry');
  9726. for (const task of tasks) {
  9727. const $task = $(task);
  9728. if ($task.find('i.fa-check:visible').length > 0) {
  9729. continue;
  9730. }
  9731. const title = $task.find('.sw_text_inner');
  9732. title[0].click();
  9733. const aElement = $task.find('a.sw_link');
  9734. const link = aElement.attr('href');
  9735. aElement.attr('href', '#a').attr('target', '_self');
  9736. aElement[0]?.click();
  9737. await delay(300);
  9738. aElement.attr('href', link).attr('target', '_blank');
  9739. $task.find('input[type="text"]').val('test');
  9740. const verifyBtn = $task.find('input.sw_verify');
  9741. if (verifyBtn.prop('disabled') === true) {
  9742. title[0].click();
  9743. await delay(300);
  9744. title[0].click();
  9745. await delay(300);
  9746. }
  9747. $task.find('input.sw_verify').removeAttr('disabled')[0]?.click();
  9748. await this.#checkFinish($task);
  9749. await delay(parseInt(`${Math.random() * (3e3 - 1e3 + 1) + 1e3}`, 10));
  9750. }
  9751. logStatus.success();
  9752. return true;
  9753. } catch (error) {
  9754. throwError(error, 'SweepWidget.doTask');
  9755. return false;
  9756. }
  9757. }
  9758. #checkLogin() {
  9759. try {
  9760. if ($('#twitter_login_button').length > 0) {
  9761. $('#twitter_login_button')[0].click();
  9762. }
  9763. return true;
  9764. } catch (error) {
  9765. throwError(error, 'SweepWidget.checkLogin');
  9766. return false;
  9767. }
  9768. }
  9769. #getGiveawayId() {
  9770. try {
  9771. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  9772. if (giveawayId) {
  9773. this.giveawayId = giveawayId;
  9774. return true;
  9775. }
  9776. scripts_echoLog({
  9777. text: i18n('getFailed', 'GiveawayId')
  9778. });
  9779. return false;
  9780. } catch (error) {
  9781. throwError(error, 'SweepWidget.getGiveawayId');
  9782. return false;
  9783. }
  9784. }
  9785. async #checkEnter() {
  9786. try {
  9787. return new Promise(resolve => {
  9788. const checker = setInterval(() => {
  9789. if ($('#unlock_rewards_main_wrapper').length > 0) {
  9790. clearInterval(checker);
  9791. resolve(true);
  9792. }
  9793. });
  9794. });
  9795. } catch (error) {
  9796. throwError(error, 'SweepWidget.checkEnter');
  9797. return false;
  9798. }
  9799. }
  9800. async #checkFinish($task) {
  9801. try {
  9802. return new Promise(resolve => {
  9803. const checker = setInterval(() => {
  9804. if ($task.find('i.fa-check:visible').length > 0 || $task.find('.sw_entry_input:visible').length === 0) {
  9805. clearInterval(checker);
  9806. resolve(true);
  9807. }
  9808. });
  9809. });
  9810. } catch (error) {
  9811. throwError(error, 'SweepWidget.checkFinish');
  9812. return false;
  9813. }
  9814. }
  9815. }
  9816. const website_SweepWidget = SweepWidget;
  9817. const defaultWhiteList = {
  9818. discord: {
  9819. servers: []
  9820. },
  9821. instagram: {
  9822. users: []
  9823. },
  9824. twitch: {
  9825. channels: []
  9826. },
  9827. twitter: {
  9828. users: [],
  9829. retweets: [],
  9830. likes: []
  9831. },
  9832. vk: {
  9833. names: []
  9834. },
  9835. youtube: {
  9836. channels: [],
  9837. likes: []
  9838. },
  9839. reddit: {
  9840. reddits: []
  9841. },
  9842. steam: {
  9843. groups: [],
  9844. officialGroups: [],
  9845. wishlists: [],
  9846. follows: [],
  9847. forums: [],
  9848. workshops: [],
  9849. curators: [],
  9850. workshopVotes: [],
  9851. curatorLikes: [],
  9852. announcements: [],
  9853. licenses: [],
  9854. playtests: []
  9855. }
  9856. };
  9857. const link2id = async function(type) {
  9858. try {
  9859. const link = $('#socialLink').val();
  9860. let id = '';
  9861. switch (type) {
  9862. case 'discord.servers':
  9863. id = link.match(/invite\/(.+)/)?.[1] || '';
  9864. break;
  9865.  
  9866. case 'instagram.users':
  9867. id = link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1] || '';
  9868. break;
  9869.  
  9870. case 'twitch.channels':
  9871. id = link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2] || '';
  9872. break;
  9873.  
  9874. case 'twitter.users':
  9875. id = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || '';
  9876. break;
  9877.  
  9878. case 'twitter.retweets':
  9879. id = link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1] || '';
  9880. break;
  9881.  
  9882. case 'vk.names':
  9883. id = link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1] || '';
  9884. break;
  9885.  
  9886. case 'youtube.channels':
  9887. id = (await getInfo(link, 'channel'))?.params?.channelId || '';
  9888. break;
  9889.  
  9890. case 'youtube.likes':
  9891. id = (await getInfo(link, 'likeVideo'))?.params?.videoId || '';
  9892. break;
  9893.  
  9894. case 'reddit.reddits':
  9895. id = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1] || link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1] || '';
  9896. break;
  9897.  
  9898. case 'steam.groups':
  9899. id = link.match(/groups\/(.+)\/?/)?.[1] || '';
  9900. break;
  9901.  
  9902. case 'steam.wishlists':
  9903. case 'steam.follows':
  9904. case 'steam.forums':
  9905. id = link.match(/app\/([\d]+)/)?.[1] || '';
  9906. break;
  9907.  
  9908. case 'steam.workshops':
  9909. id = link.match(/\?id=([\d]+)/)?.[1] || '';
  9910. break;
  9911.  
  9912. case 'steam.curators':
  9913. {
  9914. if (link.includes('curator')) {
  9915. id = link.match(/curator\/([\d]+)/)?.[1] || '';
  9916. } else {
  9917. const param = link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3);
  9918. if (!param || param.length !== 2) {
  9919. break;
  9920. }
  9921. const steam = new social_Steam();
  9922. if (await steam.init()) {
  9923. id = await steam.getCuratorId(param[0], param[1]) || '';
  9924. }
  9925. }
  9926. }
  9927. break;
  9928. }
  9929. return id;
  9930. } catch (error) {
  9931. throwError(error, 'link2id');
  9932. return i18n('getFailed', 'id');
  9933. }
  9934. };
  9935. const disabledType = {
  9936. steam: [ 'workshopVotes', 'curatorLikes', 'announcements' ],
  9937. twitter: [ 'likes' ]
  9938. };
  9939. const assignWhiteList = whiteList => {
  9940. try {
  9941. const newWhiteList = {};
  9942. for (const [ key, value ] of Object.entries(defaultWhiteList)) {
  9943. newWhiteList[key] = {
  9944. ...value,
  9945. ...whiteList[key]
  9946. };
  9947. }
  9948. return newWhiteList;
  9949. } catch (error) {
  9950. throwError(error, 'assignWhiteList');
  9951. return defaultWhiteList;
  9952. }
  9953. };
  9954. const whiteListOptions = function(showType) {
  9955. try {
  9956. const whiteList = assignWhiteList(GM_getValue('whiteList') || {});
  9957. let whiteListOptionsForm = `<form id="whiteListForm" class="auto-task-form">
  9958. <table class="auto-task-table"><thead><tr><td>${i18n('website')}</td><td>${i18n('type')}</td><td>${i18n('edit')}</td></tr></thead><tbody>`;
  9959. for (const [ social, types ] of Object.entries(whiteList)) {
  9960. 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('');
  9961. }
  9962. whiteListOptionsForm += '</tbody></table></form>';
  9963. if (showType === 'swal') {
  9964. external_Swal_default().fire({
  9965. title: i18n('whiteListOptions'),
  9966. html: whiteListOptionsForm,
  9967. showConfirmButton: false,
  9968. showCloseButton: true
  9969. });
  9970. } else {
  9971. $('body').append(`<h2>${i18n('whiteList')}</h2>${whiteListOptionsForm}`);
  9972. }
  9973. $('.editWhiteList').on('click', function() {
  9974. const value = $(this).attr('data-value');
  9975. if (!value) {
  9976. return;
  9977. }
  9978. const [ social, type ] = value.split('.');
  9979. if (!whiteList?.[social]?.[type]) {
  9980. scripts_echoLog({}).warning(i18n('whiteListNotFound', value));
  9981. return;
  9982. }
  9983. external_Swal_default().fire({
  9984. title: i18n('changeWhiteListOption', value),
  9985. input: 'textarea',
  9986. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  9987. <button id="link2id" data-type="${value}" class="swal2-confirm swal2-styled">获取id</button>
  9988. <p style="margin-bottom:0 !important;">在下方填写白名单,每行一个</p>`,
  9989. inputValue: whiteList[social][type].join('\n'),
  9990. showConfirmButton: true,
  9991. confirmButtonText: i18n('save'),
  9992. showCancelButton: true,
  9993. cancelButtonText: i18n('close'),
  9994. showDenyButton: true,
  9995. denyButtonText: i18n('return')
  9996. }).then(({
  9997. isDenied,
  9998. isConfirmed,
  9999. value
  10000. }) => {
  10001. if (isDenied) {
  10002. if (showType === 'swal') {
  10003. whiteListOptions(showType);
  10004. }
  10005. return;
  10006. } else if (isConfirmed) {
  10007. whiteList[social][type] = value.split('\n');
  10008. GM_setValue('whiteList', whiteList);
  10009. external_Swal_default().fire({
  10010. title: i18n('changeWhiteListSuccess'),
  10011. icon: 'success'
  10012. });
  10013. }
  10014. });
  10015. $('#link2id').on('click', async function() {
  10016. const type = $(this).attr('data-type');
  10017. $('#socialLink').val(await link2id(type));
  10018. });
  10019. });
  10020. } catch (error) {
  10021. throwError(error, 'whiteListOptions');
  10022. }
  10023. };
  10024. const whiteList = whiteListOptions;
  10025. const setGistData = async (token, gistId, fileName, content) => {
  10026. try {
  10027. const logStatus = scripts_echoLog({
  10028. text: i18n('settingData')
  10029. });
  10030. const contentData = JSON.stringify({
  10031. files: {
  10032. [fileName]: {
  10033. content: JSON.stringify(content)
  10034. }
  10035. }
  10036. });
  10037. const {
  10038. result,
  10039. statusText,
  10040. status,
  10041. data
  10042. } = await tools_httpRequest({
  10043. url: `https://api.github.com/gists/${gistId}`,
  10044. headers: {
  10045. Accept: 'application/vnd.github.v3+json',
  10046. Authorization: `token ${token}`
  10047. },
  10048. data: contentData,
  10049. responseType: 'json',
  10050. method: 'POST',
  10051. timeout: 3e4
  10052. });
  10053. if (result === 'Success') {
  10054. if (data?.status === 200 && data.response.files?.[fileName]?.content === JSON.stringify(content)) {
  10055. logStatus.success();
  10056. return true;
  10057. }
  10058. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10059. return false;
  10060. }
  10061. logStatus.error(`${result}:${statusText}(${status})`);
  10062. return false;
  10063. } catch (error) {
  10064. throwError(error, 'setGistData');
  10065. return false;
  10066. }
  10067. };
  10068. const getGistData = async (token, gistId, fileName, test = false) => {
  10069. try {
  10070. const logStatus = scripts_echoLog({
  10071. text: i18n('gettingData')
  10072. });
  10073. const {
  10074. result,
  10075. statusText,
  10076. status,
  10077. data
  10078. } = await tools_httpRequest({
  10079. url: `https://api.github.com/gists/${gistId}`,
  10080. headers: {
  10081. Accept: 'application/vnd.github.v3+json',
  10082. Authorization: `token ${token}`
  10083. },
  10084. responseType: 'json',
  10085. method: 'GET',
  10086. timeout: 3e4
  10087. });
  10088. if (result === 'Success') {
  10089. if (data?.status === 200) {
  10090. const content = data.response?.files?.[fileName]?.content;
  10091. let formatedContent;
  10092. if (!content) {
  10093. logStatus.error(`Error:${i18n('noRemoteData')}`);
  10094. return false;
  10095. }
  10096. if (test) {
  10097. logStatus.success();
  10098. return true;
  10099. }
  10100. try {
  10101. formatedContent = JSON.parse(content);
  10102. } catch (error) {
  10103. logStatus.error(`Error:${i18n('errorRemoteDataFormat')}`);
  10104. return false;
  10105. }
  10106. logStatus.success();
  10107. return formatedContent;
  10108. }
  10109. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10110. return false;
  10111. }
  10112. logStatus.error(`${result}:${statusText}(${status})`);
  10113. return false;
  10114. } catch (error) {
  10115. throwError(error, 'getGistData');
  10116. return false;
  10117. }
  10118. };
  10119. const syncOptions = () => {
  10120. try {
  10121. const {
  10122. TOKEN,
  10123. GIST_ID,
  10124. FILE_NAME,
  10125. SYNC_HISTORY
  10126. } = GM_getValue('gistOptions') || {
  10127. TOKEN: '',
  10128. GIST_ID: '',
  10129. FILE_NAME: '',
  10130. SYNC_HISTORY: true
  10131. };
  10132. external_Swal_default().fire({
  10133. title: i18n('gistOptions'),
  10134. 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;">
  10135. ${i18n('upload2gist')}</button>` + `<button id="download-data" type="button" class="swal2-confirm swal2-styled" style="display: inline-block;">
  10136. ${i18n('downloadFromGist')}</button></p>`,
  10137. focusConfirm: false,
  10138. showLoaderOnConfirm: true,
  10139. 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>`,
  10140. preConfirm: async () => {
  10141. const token = $('#github-token').val();
  10142. const gistId = $('#gist-id').val();
  10143. const fileName = $('#file-name').val();
  10144. const syncHistory = $('#sync-history').prop('checked');
  10145. GM_setValue('gistOptions', {
  10146. TOKEN: token,
  10147. GIST_ID: gistId,
  10148. FILE_NAME: fileName,
  10149. SYNC_HISTORY: syncHistory
  10150. });
  10151. return await getGistData(token, gistId, fileName, true);
  10152. },
  10153. allowOutsideClick: () => !external_Swal_default().isLoading(),
  10154. confirmButtonText: i18n('saveAndTest'),
  10155. showCancelButton: true,
  10156. cancelButtonText: i18n('close')
  10157. }).then(({
  10158. value
  10159. }) => {
  10160. if (value) {
  10161. external_Swal_default().fire({
  10162. icon: 'success',
  10163. title: i18n('testSuccess')
  10164. }).then(syncOptions);
  10165. } else if (value !== undefined) {
  10166. external_Swal_default().fire({
  10167. icon: 'error',
  10168. title: i18n('testFailed')
  10169. }).then(syncOptions);
  10170. }
  10171. });
  10172. $('#upload-data').on('click', async () => {
  10173. const {
  10174. TOKEN,
  10175. GIST_ID,
  10176. FILE_NAME
  10177. } = GM_getValue('gistOptions') || {};
  10178. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10179. return external_Swal_default().fire({
  10180. icon: 'error',
  10181. title: i18n('saveAndTestNotice')
  10182. }).then(syncOptions);
  10183. }
  10184. external_Swal_default().fire({
  10185. icon: 'info',
  10186. title: i18n('processingData')
  10187. });
  10188. const data = {};
  10189. const names = GM_listValues();
  10190. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10191. for (const name of names) {
  10192. if (name === 'gistOptions' || /^[\w]+?Auth$/.test(name)) {
  10193. continue;
  10194. }
  10195. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10196. continue;
  10197. }
  10198. data[name] = GM_getValue(name);
  10199. }
  10200. external_Swal_default().update({
  10201. icon: 'info',
  10202. title: i18n('updatingData')
  10203. });
  10204. if (await setGistData(TOKEN, GIST_ID, FILE_NAME, data)) {
  10205. external_Swal_default().fire({
  10206. icon: 'success',
  10207. title: i18n('syncDataSuccess')
  10208. });
  10209. } else {
  10210. external_Swal_default().fire({
  10211. icon: 'error',
  10212. title: i18n('syncDataFailed')
  10213. });
  10214. }
  10215. });
  10216. $('#download-data').on('click', async () => {
  10217. const {
  10218. TOKEN,
  10219. GIST_ID,
  10220. FILE_NAME
  10221. } = GM_getValue('gistOptions') || {};
  10222. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10223. return external_Swal_default().fire({
  10224. icon: 'error',
  10225. title: i18n('saveAndTestNotice')
  10226. }).then(syncOptions);
  10227. }
  10228. external_Swal_default().fire({
  10229. icon: 'info',
  10230. title: i18n('downloadingData')
  10231. });
  10232. const data = await getGistData(TOKEN, GIST_ID, FILE_NAME);
  10233. if (!data) {
  10234. return external_Swal_default().fire({
  10235. icon: 'error',
  10236. title: i18n('checkedNoData')
  10237. }).then(syncOptions);
  10238. }
  10239. external_Swal_default().update({
  10240. icon: 'info',
  10241. title: i18n('savingData')
  10242. });
  10243. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10244. for (const [ name, value ] of Object.entries(data)) {
  10245. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10246. continue;
  10247. }
  10248. GM_setValue(name, value);
  10249. }
  10250. external_Swal_default().fire({
  10251. icon: 'success',
  10252. title: i18n('syncDataSuccess')
  10253. });
  10254. });
  10255. } catch (error) {
  10256. throwError(error, 'syncOptions');
  10257. }
  10258. };
  10259. const dataSync = syncOptions;
  10260. class Setting {
  10261. name = 'Setting';
  10262. buttons = [ 'saveGlobalOptions', 'syncData', 'tasksHistory' ];
  10263. syncData = dataSync;
  10264. tasksHistory() {
  10265. window.open('https://auto-task-v4.hclonely.com/history.html', '_blank');
  10266. }
  10267. static test() {
  10268. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/setting.html';
  10269. }
  10270. before() {
  10271. $('body').html('').addClass('auto-task-options');
  10272. }
  10273. after() {
  10274. try {
  10275. this.#environment();
  10276. changeGlobalOptions('page');
  10277. whiteList('page');
  10278. $('input[name="other.twitterVerifyId"]').after(`<button id="getTwitterUserId" type="button">${i18n('getTwitterUserId')}</button>`);
  10279. $('#getTwitterUserId').on('click', () => {
  10280. this.#getId('twitterUser');
  10281. });
  10282. $('input[name="other.youtubeVerifyChannel"]').after(`<button id="getYoutubeChannelId" type="button">${i18n('getYoutubeChannelId')}</button>`);
  10283. $('#getYoutubeChannelId').on('click', () => {
  10284. this.#getId('youtubeChannel');
  10285. });
  10286. $('input[name^="position"]').on('input', function() {
  10287. const type = $(this).attr('name').replace('position.', '');
  10288. const xLabel = 'rightleft';
  10289. const yLabel = 'topbottpm';
  10290. switch (type) {
  10291. case 'buttonSideX':
  10292. case 'buttonSideY':
  10293. case 'buttonDistance':
  10294. {
  10295. const distance = $('input[name="position.buttonDistance"]').val();
  10296. const sideX = $('input[name="position.buttonSideX"]').val();
  10297. const sideY = $('input[name="position.buttonSideY"]').val();
  10298. if (![ 'right', 'left' ].includes(sideX)) {
  10299. break;
  10300. }
  10301. if (![ 'top', 'bottom' ].includes(sideY)) {
  10302. break;
  10303. }
  10304. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10305. break;
  10306. }
  10307. const distanceArr = distance.split(',');
  10308. $('#auto-task-buttons').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10309. break;
  10310. }
  10311.  
  10312. case 'showButtonSideX':
  10313. case 'showButtonSideY':
  10314. case 'showButtonDistance':
  10315. {
  10316. const distance = $('input[name="position.showButtonDistance"]').val();
  10317. const sideX = $('input[name="position.showButtonSideX"]').val();
  10318. const sideY = $('input[name="position.showButtonSideY"]').val();
  10319. if (![ 'right', 'left' ].includes(sideX)) {
  10320. break;
  10321. }
  10322. if (![ 'top', 'bottom' ].includes(sideY)) {
  10323. break;
  10324. }
  10325. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10326. break;
  10327. }
  10328. const distanceArr = distance.split(',');
  10329. $('div.show-button-div').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10330. break;
  10331. }
  10332.  
  10333. case 'logSideX':
  10334. case 'logSideY':
  10335. case 'logDistance':
  10336. {
  10337. const distance = $('input[name="position.logDistance"]').val();
  10338. const sideX = $('input[name="position.logSideX"]').val();
  10339. const sideY = $('input[name="position.logSideY"]').val();
  10340. if (![ 'right', 'left' ].includes(sideX)) {
  10341. break;
  10342. }
  10343. if (![ 'top', 'bottom' ].includes(sideY)) {
  10344. break;
  10345. }
  10346. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10347. break;
  10348. }
  10349. const distanceArr = distance.split(',');
  10350. $('#auto-task-info').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10351. break;
  10352. }
  10353.  
  10354. default:
  10355. break;
  10356. }
  10357. });
  10358. $('input[name^="hotKey"]').attr('readonly', 'readonly').off('keydown').on('keydown', function(event) {
  10359. let functionKey = '';
  10360. if (event.altKey) {
  10361. functionKey += 'alt + ';
  10362. } else if (event.ctrlKey) {
  10363. functionKey += 'ctrl + ';
  10364. } else if (event.shiftKey) {
  10365. functionKey += 'shift + ';
  10366. }
  10367. $(this).val(functionKey + (event.key.length === 1 ? event.key.toLowerCase() : ''));
  10368. });
  10369. } catch (error) {
  10370. throwError(error, 'Setting.after');
  10371. }
  10372. }
  10373. saveGlobalOptions() {
  10374. saveData();
  10375. }
  10376. #getId(social) {
  10377. try {
  10378. external_Swal_default().fire({
  10379. title: i18n('getId', i18n(social)),
  10380. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10381. <button id="link2id" data-type="${social}" class="swal2-confirm swal2-styled">获取id</button>`,
  10382. showCancelButton: true,
  10383. cancelButtonText: i18n('close'),
  10384. showConfirmButton: false
  10385. });
  10386. $('#link2id').on('click', async function() {
  10387. const link = $('#socialLink').val();
  10388. if (!link) {
  10389. return;
  10390. }
  10391. const type = $(this).attr('data-type');
  10392. if (type === 'twitterUser') {
  10393. const name = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || link;
  10394. $('#socialLink').val(await new social_Twitter().userName2id(name) || '');
  10395. } else if (type === 'youtubeChannel') {
  10396. const name = /^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www.youtube.com\/.*/.test(link) ? link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1] : link;
  10397. $('#socialLink').val((await getInfo(name, 'channel'))?.params?.channelId || '');
  10398. }
  10399. });
  10400. } catch (error) {
  10401. throwError(error, 'Setting.getId');
  10402. }
  10403. }
  10404. #environment() {
  10405. try {
  10406. const userAgent = (0, javascript_utils_umd_min.ua)();
  10407. const environmentForm = `<form id="environmentForm" class="auto-task-form">
  10408. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('name')}</td><td>${i18n('version')}</td></tr></thead><tbody>
  10409. <tr><td>${i18n('os')}</td><td>${userAgent.os}</td><td>${userAgent.osVersion}</td></tr>
  10410. <tr><td>${i18n('browser')}</td><td>${userAgent.browserZH}</td><td>${userAgent.browserVersion}</td></tr>
  10411. <tr><td>${i18n('scriptManager')}</td><td>${GM_info.scriptHandler}</td><td>${GM_info.version}</td></tr>
  10412. <tr><td>${i18n('script')}</td><td>${GM_info.script.name}</td><td>${GM_info.script.version}</td></tr>
  10413. </tbody></table></form>`;
  10414. $('body').append(`<h2>${i18n('environment')}</h2>${environmentForm}`);
  10415. } catch (error) {
  10416. throwError(error, 'Setting.environment');
  10417. }
  10418. }
  10419. }
  10420. const website_Setting = Setting;
  10421. class History extends website_Keylol {
  10422. name = 'History';
  10423. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect', 'clearHistory' ];
  10424. static test() {
  10425. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/history.html';
  10426. }
  10427. before() {
  10428. try {
  10429. $('body').html('<div class="container"></div>').addClass('auto-task-history');
  10430. const data = GM_listValues() || [];
  10431. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10432. for (const item of tasksHistory) {
  10433. this.#addItem(item);
  10434. }
  10435. } catch (error) {
  10436. throwError(error, 'History.before');
  10437. }
  10438. }
  10439. clearHistory() {
  10440. try {
  10441. const data = GM_listValues() || [];
  10442. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10443. for (const item of tasksHistory) {
  10444. GM_deleteValue(item);
  10445. }
  10446. external_Swal_default().fire({
  10447. title: i18n('clearHistoryFinished'),
  10448. icon: 'success'
  10449. });
  10450. } catch (error) {
  10451. throwError(error, 'History.after');
  10452. }
  10453. }
  10454. #addItem(item) {
  10455. try {
  10456. const tasksData = GM_getValue(item);
  10457. if (!tasksData?.tasks) {
  10458. return;
  10459. }
  10460. let html = '';
  10461. let title = '';
  10462. let link = '';
  10463. const [ website, id ] = item.split('-');
  10464. switch (website) {
  10465. case 'fawTasks':
  10466. title = `Freeanywhere[${id}]`;
  10467. link = `https://freeanywhere.net/#/giveaway/${id}`;
  10468. break;
  10469.  
  10470. case 'gasTasks':
  10471. title = `Giveawaysu[${id}]`;
  10472. link = `https://giveaway.su/giveaway/view/${id}`;
  10473. break;
  10474.  
  10475. case 'gcTasks':
  10476. title = `GiveeClub[${id}]`;
  10477. link = `https://givee.club/event/${id}`;
  10478. break;
  10479.  
  10480. case 'gkTasks':
  10481. title = `Givekey[${id}]`;
  10482. link = `https://givekey.ru/giveaway/${id}`;
  10483. break;
  10484.  
  10485. case 'gleamTasks':
  10486. title = `Gleam[${id}]`;
  10487. link = `https://gleam.io${id}`;
  10488. break;
  10489.  
  10490. case 'khTasks':
  10491. title = `keyhub[${id}]`;
  10492. link = `https://key-hub.eu/giveaway/${id}`;
  10493. break;
  10494.  
  10495. case 'prysTasks':
  10496. title = `Prys[${id}]`;
  10497. link = `https://prys.revadike.com/giveaway/?id=${id}`;
  10498. break;
  10499.  
  10500. default:
  10501. return;
  10502. }
  10503. for (const [ social, types ] of Object.entries(tasksData.tasks)) {
  10504. for (const [ type, tasks ] of Object.entries(types)) {
  10505. for (const task of tasks) {
  10506. 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>`;
  10507. }
  10508. }
  10509. }
  10510. $('.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>`);
  10511. $('span.delete-task').on('click', function() {
  10512. const itemName = $(this).attr('data-name');
  10513. if (itemName) {
  10514. GM_deleteValue(itemName);
  10515. $(`div.card[data-name="${itemName}"]`).remove();
  10516. external_Swal_default().fire({
  10517. title: i18n('clearTaskFinished'),
  10518. text: itemName,
  10519. icon: 'success'
  10520. });
  10521. } else {
  10522. external_Swal_default().fire({
  10523. title: i18n('clearTaskFailed'),
  10524. icon: 'error'
  10525. });
  10526. }
  10527. });
  10528. } catch (error) {
  10529. throwError(error, 'History.addItem');
  10530. }
  10531. }
  10532. }
  10533. const website_History = History;
  10534. const Websites = [ Freeanywhere, GiveawaySu, website_Indiedb, website_Keyhub, website_Givekey, website_GiveeClub, website_OpiumPulses, website_Keylol, website_Opquests, website_Gleam, website_SweepWidget, website_Setting, website_History ];
  10535. const websiteOptions = function(website, options) {
  10536. try {
  10537. let websiteOptionsForm = `<form id="websiteOptionsForm" class="auto-task-form">
  10538. <table class="auto-task-table"><thead><tr><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  10539. for (const [ option, value ] of Object.entries(options)) {
  10540. websiteOptionsForm += `<tr><td>${option}</td><td><input class="editOption" type="text" name="${option}" value="${value}"/></td></tr>`;
  10541. }
  10542. websiteOptionsForm += '</tbody></table></form>';
  10543. external_Swal_default().fire({
  10544. title: i18n('websiteOptions'),
  10545. html: websiteOptionsForm,
  10546. showConfirmButton: true,
  10547. confirmButtonText: i18n('save'),
  10548. showCancelButton: true,
  10549. cancelButtonText: i18n('close')
  10550. }).then(({
  10551. isConfirmed
  10552. }) => {
  10553. if (isConfirmed) {
  10554. $('#websiteOptionsForm').serializeArray().map(value => {
  10555. options[value.name] = value.value;
  10556. return value;
  10557. });
  10558. GM_setValue(`${website}Options`, options);
  10559. external_Swal_default().fire({
  10560. title: i18n('changeWebsiteOptionsSuccess'),
  10561. icon: 'success'
  10562. });
  10563. }
  10564. });
  10565. } catch (error) {
  10566. throwError(error, 'websiteOptions');
  10567. }
  10568. };
  10569. const options = websiteOptions;
  10570. const external_keyboardJS_namespaceObject = keyboardJS;
  10571. var external_keyboardJS_default = __webpack_require__.n(external_keyboardJS_namespaceObject);
  10572. const checkUpdate = async (updateLink, auto) => {
  10573. try {
  10574. const checkUrl = `${updateLink}package.json?time=${new Date().getTime()}`;
  10575. const {
  10576. result,
  10577. statusText,
  10578. status,
  10579. data
  10580. } = await tools_httpRequest({
  10581. url: checkUrl,
  10582. responseType: 'json',
  10583. method: 'GET',
  10584. timeout: 3e4
  10585. });
  10586. if (result === 'Success') {
  10587. if (data?.response?.version) {
  10588. return data.response;
  10589. }
  10590. if (!auto) {
  10591. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${data?.statusText}(${data?.status})]`);
  10592. }
  10593. return false;
  10594. }
  10595. if (!auto) {
  10596. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${result}:${statusText}(${status})]`);
  10597. }
  10598. return false;
  10599. } catch (error) {
  10600. throwError(error, 'checkUpdate');
  10601. return false;
  10602. }
  10603. };
  10604. const hasNewVersion = (currentVersion, remoteVersion) => {
  10605. try {
  10606. const [ currentRealVersion ] = currentVersion.split('-');
  10607. const [ remoteRealVersion, isPreview ] = remoteVersion.split('-');
  10608. if (isPreview && !globalOptions.other.receivePreview) {
  10609. return false;
  10610. }
  10611. const [ currentVersion1, currentVersion2, currentVersion3 ] = currentRealVersion.split('.').map(value => parseInt(value, 10));
  10612. const [ remoteVersion1, remoteVersion2, remoteVersion3 ] = remoteRealVersion.split('.').map(value => parseInt(value, 10));
  10613. if (remoteVersion1 > currentVersion1) {
  10614. return true;
  10615. }
  10616. if (remoteVersion1 < currentVersion1) {
  10617. return false;
  10618. }
  10619. if (remoteVersion2 > currentVersion2) {
  10620. return true;
  10621. }
  10622. if (remoteVersion2 < currentVersion2) {
  10623. return false;
  10624. }
  10625. if (remoteVersion3 > currentVersion3) {
  10626. return true;
  10627. }
  10628. return false;
  10629. } catch (error) {
  10630. throwError(error, 'compareVersion');
  10631. return false;
  10632. }
  10633. };
  10634. const updateChecker = async () => {
  10635. try {
  10636. const currentVersion = GM_info.script.version;
  10637. const updateSource = globalOptions.other.autoUpdateSource.toLowerCase();
  10638. const updateLinks = {
  10639. github: 'https://github.com/HCLonely/auto-task-new/raw/main/',
  10640. jsdelivr: 'https://cdn.jsdelivr.net/gh/HCLonely/auto-task-v4@main/',
  10641. standby: 'https://auto-task-v4.hclonely.com/'
  10642. };
  10643. let version;
  10644. let updateLink = '';
  10645. let packageData;
  10646. if ([ 'github', 'jsdelivr', 'standby' ].includes(updateSource)) {
  10647. updateLink = updateLinks[updateSource];
  10648. packageData = await checkUpdate(updateLink, false);
  10649. } else {
  10650. updateLink = updateLinks.github;
  10651. packageData = await checkUpdate(updateLink, true);
  10652. if (!packageData) {
  10653. updateLink = updateLinks.jsdelivr;
  10654. packageData = await checkUpdate(updateLink, true);
  10655. if (!packageData) {
  10656. updateLink = updateLinks.standby;
  10657. packageData = await checkUpdate(updateLink, true);
  10658. }
  10659. }
  10660. }
  10661. if (packageData) {
  10662. version = packageData.version || currentVersion;
  10663. } else {
  10664. version = currentVersion;
  10665. scripts_echoLog({}).error(i18n('checkUpdateFailed'));
  10666. }
  10667. if (packageData && hasNewVersion(currentVersion, version)) {
  10668. scripts_echoLog({
  10669. html: `<li><font>${i18n('newVersionNotice', version, `${updateLink}dist/${GM_info.script.name}.user.js`)}</font></li>`
  10670. });
  10671. scripts_echoLog({
  10672. html: `<li>${i18n('updateText', version)}</li><ol class="update-text">${packageData.change?.map(change => `<li>${change}</li>`).join('')}<li>${i18n('updateHistory')}</li></ol>`
  10673. });
  10674. }
  10675. } catch (error) {
  10676. throwError(error, 'updateChecker');
  10677. }
  10678. };
  10679. const scripts_updateChecker = updateChecker;
  10680. window.STYLE = GM_addStyle(auto_task.Z + GM_getResourceText('style'));
  10681. window.DEBUG = !!globalOptions.other.debug;
  10682. window.TRACE = !!globalOptions.other.debug && typeof console.trace === 'function';
  10683. const loadScript = async () => {
  10684. if (window.location.hostname === 'www.twitch.tv' && window.location.hash === '#auth') {
  10685. const authToken = external_Cookies_namespaceObject.get('auth-token');
  10686. const isLogin = !!external_Cookies_namespaceObject.get('login');
  10687. if (isLogin) {
  10688. GM_setValue('twitchAuth', {
  10689. authToken: authToken,
  10690. clientVersion: __twilightBuildID,
  10691. clientId: commonOptions?.headers?.['Client-ID'],
  10692. deviceId: commonOptions?.headers?.['Device-ID'],
  10693. clientSessionId: window.localStorage.local_storage_app_session_id.replace(/"/g, '')
  10694. });
  10695. window.close();
  10696. external_Swal_default().fire('', i18n('closePageNotice'));
  10697. } else {
  10698. external_Swal_default().fire('', i18n('needLogin'));
  10699. }
  10700. return;
  10701. }
  10702. if (window.location.hostname === 'www.reddit.com' && (window.location.hash === '#auth' || GM_getValue('redditAuth') === '#auth')) {
  10703. const betaButton = $('#redesign-beta-optin-btn');
  10704. if (betaButton.length > 0) {
  10705. GM_setValue('redditAuth', '#auth');
  10706. return betaButton[0].click();
  10707. }
  10708. GM_setValue('redditAuth', null);
  10709. window.close();
  10710. external_Swal_default().fire('', i18n('closePageNotice'));
  10711. return;
  10712. }
  10713. let website;
  10714. for (const Website of Websites) {
  10715. if (Website.test()) {
  10716. website = new Website();
  10717. break;
  10718. }
  10719. }
  10720. if (!website) {
  10721. console.log('%c%s', 'color:#ff0000', 'Auto-Task[Warning]: 脚本停止加载,当前网站不支持!');
  10722. return;
  10723. }
  10724. if (website?.before) {
  10725. await website?.before();
  10726. }
  10727. $('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>`);
  10728. $('div.show-button-div').on('click', () => {
  10729. $('#auto-task-buttons').show();
  10730. $('div.show-button-div').hide();
  10731. });
  10732. const toggleLog = () => {
  10733. const $this = $('#toggle-log');
  10734. const status = $this.attr('data-status');
  10735. if (status === 'show') {
  10736. $('#auto-task-info').hide();
  10737. $this.attr('data-status', 'hide').text(i18n('showLog'));
  10738. } else {
  10739. $('#auto-task-info').show();
  10740. $this.attr('data-status', 'show').text(i18n('hideLog'));
  10741. }
  10742. };
  10743. external_keyboardJS_default().bind(globalOptions.hotKey.doTaskKey, () => {
  10744. if (website.doTask) {
  10745. website.doTask();
  10746. }
  10747. });
  10748. external_keyboardJS_default().bind(globalOptions.hotKey.undoTaskKey, () => {
  10749. if (website.undoTask) {
  10750. website.doTask();
  10751. }
  10752. });
  10753. external_keyboardJS_default().bind(globalOptions.hotKey.toggleLogKey, toggleLog);
  10754. if (website?.after) {
  10755. await website?.after();
  10756. }
  10757. if (website?.buttons && $('#auto-task-buttons').children().length === 0) {
  10758. $('#auto-task-buttons').addClass(`${website.name}-buttons`);
  10759. for (const button of website.buttons) {
  10760. if (website[button]) {
  10761. const btnElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">${i18n(button)}</a></p>`);
  10762. btnElement.find('a.auto-task-website-btn').on('click', () => {
  10763. website[button]();
  10764. });
  10765. $('#auto-task-buttons').append(btnElement);
  10766. }
  10767. }
  10768. }
  10769. const hideButtonElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">
  10770. ${i18n('hideButton')}</a></p>`);
  10771. hideButtonElement.find('a.auto-task-website-btn').on('click', () => {
  10772. $('#auto-task-buttons').hide();
  10773. $('div.show-button-div').show();
  10774. });
  10775. 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'}">
  10776. ${globalOptions.other.defaultShowLog ? i18n('hideLog') : i18n('showLog')}</a></p>`);
  10777. toggleLogElement.find('a.auto-task-website-btn').on('click', toggleLog);
  10778. $('#auto-task-buttons').append(hideButtonElement).append(toggleLogElement);
  10779. if (website?.options) {
  10780. GM_registerMenuCommand(i18n('changeWebsiteOptions'), () => {
  10781. options(website.name, website.options);
  10782. });
  10783. }
  10784. if (website.name !== 'Setting') {
  10785. GM_registerMenuCommand(i18n('changeGlobalOptions'), () => {
  10786. changeGlobalOptions('swal');
  10787. });
  10788. GM_registerMenuCommand(i18n('settingPage'), () => {
  10789. window.open('https://auto-task-v4.hclonely.com/setting.html', '_blank');
  10790. });
  10791. }
  10792. console.log('%c%s', 'color:#1bbe1a', 'Auto-Task[Load]: 脚本加载完成');
  10793. const [ v1, v2 ] = GM_info.version.split('.');
  10794. if (!(parseInt(v1, 10) >= 5 && parseInt(v2, 10) >= 2)) {
  10795. scripts_echoLog({}).error(i18n('versionNotMatched'));
  10796. }
  10797. if (!GM_getValue('notice')) {
  10798. external_Swal_default().fire({
  10799. title: i18n('swalNotice'),
  10800. icon: 'warning'
  10801. }).then(() => {
  10802. window.open(i18n('noticeLink'), '_blank');
  10803. GM_setValue('notice', new Date().getTime());
  10804. });
  10805. scripts_echoLog({
  10806. html: `<li><font class="warning">${i18n('echoNotice', i18n('noticeLink'))}</font></li>`
  10807. }).font?.find('a').on('click', () => {
  10808. GM_setValue('notice', new Date().getTime());
  10809. });
  10810. }
  10811. scripts_updateChecker();
  10812. };
  10813. if (window.location.hostname === 'discord.com') {
  10814. const LocalStorage = window.localStorage;
  10815. if (window.location.hash === '#auth') {
  10816. window.localStorage.removeItem = () => true;
  10817. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10818. if (discordAuth && discordAuth.length > 0) {
  10819. GM_setValue('discordAuth', {
  10820. auth: discordAuth
  10821. });
  10822. window.close();
  10823. external_Swal_default().fire('', i18n('closePageNotice'));
  10824. } else {
  10825. external_Swal_default().fire({
  10826. text: i18n('getDiscordAuthFailed'),
  10827. icon: 'error'
  10828. });
  10829. }
  10830. } else {
  10831. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10832. if (discordAuth && discordAuth.length > 0) {
  10833. GM_setValue('discordAuth', {
  10834. auth: discordAuth
  10835. });
  10836. }
  10837. }
  10838. } else if (window.location.hostname === 'opquests.com') {
  10839. loadScript();
  10840. } else if (window.opener && window.location.host === 'store.steampowered.com' && window.location.pathname === '/') {
  10841. $(() => {
  10842. if ($('[data-miniprofile]').length === 0) {
  10843. return;
  10844. }
  10845. window.onbeforeunload = function(event) {
  10846. GM_setValue('steamStoreAuth', null);
  10847. return null;
  10848. };
  10849. const storeSessionID = document.body.innerHTML.match(/g_sessionID = "(.+?)";/)?.[1];
  10850. if (storeSessionID) {
  10851. GM_setValue('steamStoreAuth', {
  10852. storeSessionID: storeSessionID
  10853. });
  10854. return true;
  10855. }
  10856. });
  10857. } else if (window.opener && window.location.host === 'steamcommunity.com' && window.location.pathname.includes('/id/')) {
  10858. $(() => {
  10859. window.onbeforeunload = function(event) {
  10860. GM_setValue('steamCommunityAuth', null);
  10861. return null;
  10862. };
  10863. const steam64Id = document.body.innerHTML.match(/g_steamID = "(.+?)";/)?.[1];
  10864. const communitySessionID = document.body.innerHTML.match(/g_sessionID = "(.+?)";/)?.[1];
  10865. const userName = document.body.innerHTML.match(/steamcommunity.com\/id\/(.+?)\/friends\//)?.[1];
  10866. const data = {};
  10867. if (steam64Id) {
  10868. data.steam64Id = steam64Id;
  10869. }
  10870. if (userName) {
  10871. data.userName = userName;
  10872. }
  10873. if (communitySessionID) {
  10874. data.communitySessionID = communitySessionID;
  10875. GM_setValue('steamCommunityAuth', data);
  10876. return true;
  10877. }
  10878. });
  10879. } else {
  10880. if (window.location.hostname === 'key-hub.eu') {
  10881. unsafeWindow.keyhubtracker = 1;
  10882. unsafeWindow.gaData = {};
  10883. }
  10884. $(loadScript);
  10885. }
  10886. }();
  10887. })();