auto-task-v4

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

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

  1. // ==UserScript==
  2. // @name auto-task-v4
  3. // @namespace auto-task-v4
  4. // @version 4.4.12
  5. // @description 自动完成 Freeanywhere,Giveawaysu,GiveeClub,Givekey,Gleam,Indiedb,keyhub,OpiumPulses,Opquests,SweepWidget 等网站的任务。
  6. // @description:en Automatically complete the tasks of FreeAnyWhere, GiveawaySu, GiveeClub, Givekey, Gleam, Indiedb, keyhub, OpiumPulses, Opquests, SweepWidget websites.
  7. // @author HCLonely
  8. // @license MIT
  9. // @run-at document-start
  10. // @homepage https://auto-task-doc.js.org/
  11. // @supportURL https://github.com/HCLonely/auto-task-v4/issues
  12. // @icon https://auto-task-v4.hclonely.com/favicon.ico
  13.  
  14. // @include *://freeanywhere.net/*
  15. // @include *://giveaway.su/giveaway/view/*
  16. // @include *://givee.club/*/event/*
  17. // @include *://givekey.ru/giveaway/*
  18. // @include *://www.indiedb.com/giveaways*
  19. // @include *://key-hub.eu/giveaway/*
  20. // @include *://keylol.com/*
  21. // @include *://www.opiumpulses.com/giveaways
  22. // @include *://prys.revadike.com/giveaway/?id=*
  23. // @include *://opquests.com/quests/*
  24. // @include *://gleam.io/*
  25. // @include *://sweepwidget.com/view/*
  26. // @include *://discord.com/*
  27. // @include *://www.twitch.tv/*
  28. // @include *://www.youtube.com/*
  29. // @include *://*.reddit.com/*
  30. // @include *://twitter.com/settings/account?k*
  31. // @include *://x.com/settings/account*
  32. // @include *://steamcommunity.com/id/*
  33. // @include *://store.steampowered.com/*
  34. // @include https://auto-task-v4.hclonely.com/setting.html
  35. // @include https://auto-task-v4.hclonely.com/history.html
  36.  
  37. // @grant GM_setValue
  38. // @grant GM_getValue
  39. // @grant GM_listValues
  40. // @grant GM_deleteValue
  41. // @grant GM_addStyle
  42. // @grant GM_xmlhttpRequest
  43. // @grant GM_registerMenuCommand
  44. // @grant GM_info
  45. // @grant GM_openInTab
  46. // @grant GM_setClipboard
  47. // @grant GM_getResourceText
  48. // @grant GM_cookie
  49. // @grant GM_addValueChangeListener
  50. // @grant GM_removeValueChangeListener
  51. // @grant unsafeWindow
  52. // @grant window.close
  53. // @grant window.localStorage
  54.  
  55. // @connect cdn.jsdelivr.net
  56. // @connect store.steampowered.com
  57. // @connect steamcommunity.com
  58. // @connect login.steampowered.com
  59. // @connect twitter.com
  60. // @connect x.com
  61. // @connect api.twitter.com
  62. // @connect youtube.com
  63. // @connect www.youtube.com
  64. // @connect facebook.com
  65. // @connect instagram.com
  66. // @connect vk.com
  67. // @connect twitch.tv
  68. // @connect www.twitch.tv
  69. // @connect gql.twitch.tv
  70. // @connect github.com
  71. // @connect discordapp.com
  72. // @connect discord.gg
  73. // @connect discord.com
  74. // @connect www.reddit.com
  75. // @connect oauth.reddit.com
  76. // @connect raw.githubusercontent.com
  77. // @connect t.me
  78. // @connect bit.ly
  79. // @connect giveaway.su
  80. // @connect google.com
  81. // @connect www.vloot.io
  82. // @connect givee.club
  83. // @connect gleam.io
  84. // @connect www.indiedb.com
  85. // @connect key-hub.eu
  86. // @connect opquests.com
  87. // @connect itch.io
  88. // @connect auto-task-v4.hclonely.com
  89. // @connect *
  90. // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js
  91. // @require https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js
  92. // @require https://cdn.jsdelivr.net/npm/regenerator-runtime@0.13.5/runtime.min.js
  93. // @require https://cdn.jsdelivr.net/npm/js-sha1@0.6.0/src/sha1.min.js
  94. // @require https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js
  95. // @resource style https://cdn.jsdelivr.net/npm/sweetalert2@11.3.5/dist/sweetalert2.min.css
  96. // @require https://cdn.jsdelivr.net/npm/keyboardjs@2.6.4/dist/keyboard.min.js
  97. // @require https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js
  98.  
  99. // @noframes
  100. // ==/UserScript==
  101.  
  102. console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
  103. (function() {
  104. var __webpack_modules__ = {
  105. 991: function(__unused_webpack_module, exports) {
  106. !function(e, n) {
  107. true ? n(exports) : 0;
  108. }(this, function(e) {
  109. 'use strict';
  110. var t = function() {
  111. return (t = Object.assign || function(e) {
  112. for (var n, o = 1, t = arguments.length; o < t; o++) {
  113. for (var r in n = arguments[o]) {
  114. Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r]);
  115. }
  116. }
  117. return e;
  118. }).apply(this, arguments);
  119. };
  120. function r(e, n, o) {
  121. if (o || 2 === arguments.length) {
  122. for (var t, r = 0, i = n.length; r < i; r++) {
  123. !t && r in n || ((t = t || Array.prototype.slice.call(n, 0, r))[r] = n[r]);
  124. }
  125. }
  126. return e.concat(t || Array.prototype.slice.call(n));
  127. }
  128. function d(e) {
  129. return '[object Object]' === n(e);
  130. }
  131. function l(e, n) {
  132. var o = r(r([], n || [], !0), [ '_' ], !1).join('|');
  133. return e.replace(new RegExp('(('.concat(o, ')[a-z])+'), 'g'), function(e, n) {
  134. return n.replace(new RegExp(o), '').toLocaleUpperCase();
  135. });
  136. }
  137. var n = function(e) {
  138. return Object.prototype.toString.call(e);
  139. };
  140. var o = (i.prototype.init = function() {
  141. try {
  142. this.getSystemName(), this.getBrowserName();
  143. } catch (e) {
  144. console.warn('[UA formatter error] '.concat(e));
  145. }
  146. }, i.prototype.getEngine = function() {
  147. var e = this.agent;
  148. return -1 !== e.indexOf('Trident') ? 'Trident' : -1 !== e.indexOf('Firefox') ? 'Gecko' : -1 !== e.indexOf('Presto') ? 'Presto' : 'WebKit';
  149. }, i.prototype.getSystemName = function() {
  150. var e, n = (this.agent.match(/^[a-z]+\/\d+\.\d+\s?\(([a-z\d\s:;./_-]+)\)/i) || [])[1];
  151. try {
  152. var o = '';
  153. if (/Windows/i.test(n)) {
  154. var t = (n.match(/NT\s(\d+\.\d+)/) || [])[1];
  155. switch (this.info.os = 'Windows', t) {
  156. case '6.3':
  157. o = '8.1';
  158. break;
  159.  
  160. case '6.2':
  161. o = '8';
  162. break;
  163.  
  164. case '6.1':
  165. o = '7';
  166. break;
  167.  
  168. case '5.2':
  169. case '5.1':
  170. o = 'XP';
  171. break;
  172.  
  173. default:
  174. o = t;
  175. }
  176. return this.info.device = 'PC', void (this.info.osVersion = o);
  177. }
  178. if (/^Macintosh/i.test(n)) {
  179. return o = (n.match(/X\s((\d+(_|\.))+\d+)/) || [])[1], this.info.os = 'Macintosh',
  180. this.info.device = 'PC', void (this.info.osVersion = null !== (e = null == o ? void 0 : o.replace(/_/g, '.')) && void 0 !== e ? e : 'Unknown');
  181. }
  182. if (/^iPad/i.test(n)) {
  183. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPad',
  184. this.info.device = 'Tablet', void (this.info.osVersion = o.replace(/_/g, '.'));
  185. }
  186. if (/^iPhone/i.test(n)) {
  187. return o = (n.match(/((\d+_)+\d+)/) || [])[1], this.info.os = 'iPhone',
  188. this.info.device = 'Mobile', void (this.info.osVersion = o.replace(/_/g, '.'));
  189. }
  190. if (-1 !== n.indexOf('Android')) {
  191. var r = (n.match(/Android\s((\d+\.?)+\d?)/) || [])[1];
  192. return this.info.device = 'Mobile', this.info.os = 'Android', void (this.info.osVersion = r);
  193. }
  194. if (/Linux\s[a-z\d_]+/.test(n)) {
  195. return this.info.os = 'Linux', void (this.info.osVersion = 'Unknown');
  196. }
  197. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  198. } catch (e) {
  199. this.info.os = 'Unknown', this.info.osVersion = 'Unknown';
  200. }
  201. }, i.prototype.getBrowserName = function() {
  202. var e = Object.keys(this.browserNameMap).map(function(e) {
  203. return new RegExp(''.concat(e, '(\\/|\\s)(\\d+\\.)+\\d+'));
  204. }), n = 1 < (n = (this.agent.match(/[a-z\d]+(\/|\s)(\d+\.)+\d+/gi) || []).filter(function(n) {
  205. return -1 !== e.findIndex(function(e) {
  206. return e.test(n);
  207. });
  208. })).length && !/^Safari/.test(n[n.length - 1]) ? n.reverse() : n;
  209. this.info = t(t({}, this.info), this._formatBrowserVersion(n[0]));
  210. }, i.prototype._formatBrowserVersion = function(e) {
  211. var n, o, t, r;
  212. try {
  213. 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++) {
  214. var d = u[f], l = d[0], h = d[1];
  215. if (new RegExp(l).test(s)) {
  216. c = h;
  217. break;
  218. }
  219. }
  220. var p = {
  221. browserVersion: null != a ? a : 'Unknown',
  222. browser: null !== (t = c.en) && void 0 !== t ? t : 'Unknown',
  223. browserZH: null !== (r = (null == c ? void 0 : c.zh) || c.en) && void 0 !== r ? r : 'Unknown'
  224. };
  225. return 'Trident' === s && (p.browserVersion = {
  226. '4.0': 8,
  227. '5.0': 9,
  228. '6.0': 10,
  229. '7.0': 11
  230. }[a]), p;
  231. } catch (e) {
  232. return console.warn('[UA formatter error] '.concat(e)), {
  233. browser: 'Unknown',
  234. browserVersion: 'Unknown'
  235. };
  236. }
  237. }, i);
  238. function i(e) {
  239. this.agent = '', this.info = {
  240. browser: '',
  241. browserZH: '',
  242. browserVersion: '',
  243. os: '',
  244. osVersion: '',
  245. device: 'Unknown',
  246. engine: 'WebKit'
  247. }, this.browserNameMap = {
  248. MicroMessenger: {
  249. en: 'MicroMessenger',
  250. zh: '微信'
  251. },
  252. MetaSr: {
  253. en: 'MetaSr',
  254. zh: '搜狗浏览器'
  255. },
  256. 'QQ(Browser)?': {
  257. en: 'QQBrowser',
  258. zh: 'QQ浏览器'
  259. },
  260. UCBrowser: {
  261. en: 'UCBrowser',
  262. zh: 'UC浏览器'
  263. },
  264. '2345Explorer': {
  265. en: '2345Explorer',
  266. zh: '2345极速浏览器'
  267. },
  268. Mb2345Browser: {
  269. en: 'Mb2345Browser',
  270. zh: '2345手机浏览器'
  271. },
  272. Trident: {
  273. en: 'Internet Explorer'
  274. },
  275. 'Edge?': {
  276. en: 'Edge'
  277. },
  278. OPR: {
  279. en: 'Opera'
  280. },
  281. Vivaldi: {
  282. en: 'Vivaldi'
  283. },
  284. Firefox: {
  285. en: 'Firefox'
  286. },
  287. Chrome: {
  288. en: 'Chrome'
  289. },
  290. Safari: {
  291. en: 'Safari'
  292. }
  293. }, this.agent = e, this.init();
  294. var n = this.info, o = n.browser, e = n.browserVersion, n = n.osVersion;
  295. this.info = t(t({}, this.info), {
  296. engine: this.getEngine(),
  297. browserVersion: 'Safari' === o ? n : e
  298. });
  299. }
  300. function s() {
  301. this.cookies = {}, this.init();
  302. }
  303. var a = new (s.prototype.init = function() {
  304. var o = {};
  305. document.cookie.split(/;\s/).forEach(function(e) {
  306. var n = e.split(/=/), e = n[0], n = n[1];
  307. o[e] = n;
  308. }), this.cookies = o;
  309. }, s.prototype.getItem = function(e) {
  310. return this.cookies[e];
  311. }, s.prototype.getAllItems = function() {
  312. return this.cookies;
  313. }, s.prototype.setItem = function(e, n, o, t, r, i) {
  314. document.cookie = ''.concat(e, '=').concat(n).concat(o ? '; expires='.concat(o) : '').concat(t ? '; path='.concat(t) : '').concat(r ? '; domain='.concat(r) : '').concat(i ? '; secure' : '');
  315. }, s)();
  316. e.countDown = function e(n, o, t, r) {
  317. if (!window) {
  318. throw new Error('window is not defind.');
  319. }
  320. if (0 < n) {
  321. return r && r(), n--, window[o] = window.setTimeout(function() {
  322. e(n, o, t, r);
  323. }, 1e3), function() {
  324. return clearTimeout(window[o]);
  325. };
  326. }
  327. clearTimeout(window[o]), t && t();
  328. }, e.createRandomID = function(e) {
  329. void 0 === e && (e = 12);
  330. for (var n = [], o = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''), t = o.length, r = 0; r < e; r++) {
  331. n.push(o[Math.round(Math.random() * t)]);
  332. }
  333. return n.join('');
  334. }, e.dCookie = a, e.debounce = function(o, t, r) {
  335. var i;
  336. void 0 === t && (t = 0);
  337. var s = r = void 0 === r ? !1 : r;
  338. return function() {
  339. var e = this, n = arguments;
  340. s && (o.apply(this, arguments), s = !1), clearTimeout(i), i = setTimeout(function() {
  341. r ? s = !0 : o.apply(e, n);
  342. }, t);
  343. };
  344. }, e.deepCopy = function e(n) {
  345. if (d(n) || Array.isArray(n)) {
  346. var o, t = Array.isArray(n) ? [] : {};
  347. for (o in n) {
  348. t[o] = e(n[o]);
  349. }
  350. return t;
  351. }
  352. return n;
  353. }, e.formatQueryParams = function(e) {
  354. e = null === (e = /\?(?<params>(.*)=.+)/.exec(decodeURIComponent(e))) || void 0 === e ? void 0 : e.groups;
  355. if (!e) {
  356. return {};
  357. }
  358. for (var n = e.params.split('&'), t = {}, o = 0; o < n.length; o++) {
  359. n[o].replace(/([^?&]*)=([^?&]*)/, function(e, n, o) {
  360. return t[n] = o, e;
  361. });
  362. }
  363. return t;
  364. }, e.formatThousandth = function(e) {
  365. 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, '$&,');
  366. return ''.concat(e).concat(n ? '.'.concat(n) : '');
  367. }, e.generateTree = function e(n, o, t, r) {
  368. for (var i = [], s = 0; s < n.length; s++) {
  369. var a = n[s];
  370. a[t] === o && (i.push(a), a.children = e(n, a[null != r ? r : 'id'], t, r));
  371. }
  372. return i;
  373. }, e.isEmpty = function(e) {
  374. 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);
  375. }, e.isFunction = function(e) {
  376. return '[object Function]' === n(e);
  377. }, e.isImageUrl = function(e) {
  378. return /\.((png)|(jpe?g)|(gif)|(svg)|(webp))$/gi.test(e);
  379. }, e.isObject = d, e.isRegexp = function(e) {
  380. return '[object RegExp]' === n(e);
  381. }, e.objectKeyToCamelCase = function e(n, o, t) {
  382. if (Array.isArray(n)) {
  383. for (var r = [], i = 0; i < n.length; i++) {
  384. r[i] = e(o && n[i][o] ? n[i][o] : n[i], o, t);
  385. }
  386. } else if (d(n)) {
  387. r = {};
  388. for (var s = o && n[o] ? n[o] : n, a = 0, c = Object.entries(s); a < c.length; a++) {
  389. var f = (u = c[a])[0], u = u[1];
  390. Array.isArray(u) || d(s) ? r[l(f, t)] = e(u, o, t) : r[l(f, t)] = u;
  391. }
  392. } else {
  393. r = n;
  394. }
  395. return r;
  396. }, e.realType = n, e.searchParams = function(e, n) {
  397. return void 0 === e && (e = null === location || void 0 === location ? void 0 : location.search),
  398. new URLSearchParams(e).get(n);
  399. }, e.toLowerCamelCase = l, e.toUnderline = function(e) {
  400. return e.replace(/([A-Z])/g, function(e) {
  401. return '_'.concat(e.toLocaleLowerCase());
  402. });
  403. }, e.ua = function(e) {
  404. return void 0 === e && (e = navigator.userAgent), new o(e).info;
  405. }, Object.defineProperty(e, '__esModule', {
  406. value: !0
  407. });
  408. });
  409. },
  410. 675: function(module, __webpack_exports__, __webpack_require__) {
  411. 'use strict';
  412. __webpack_require__.d(__webpack_exports__, {
  413. A: function() {
  414. return __WEBPACK_DEFAULT_EXPORT__;
  415. }
  416. });
  417. var _node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(601);
  418. var _node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = __webpack_require__.n(_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__);
  419. var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(314);
  420. var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default = __webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__);
  421. var ___CSS_LOADER_EXPORT___ = _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default()(_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default());
  422. ___CSS_LOADER_EXPORT___.push([ module.id, `.colorful-button,#auto-task-buttons a.auto-task-website-btn,.show-button-div a.auto-task-website-btn,body.auto-task-options .auto-task-form table button{position:relative;padding:5px 10px;text-align:center;color:#fff;text-decoration:none;background:linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);border-radius:30px;background-size:400%;text-transform:capitalize}.colorful-button:hover,#auto-task-buttons a.auto-task-website-btn:hover,.show-button-div a.auto-task-website-btn:hover,body.auto-task-options .auto-task-form table button:hover{transform:scale(1.05);box-shadow:0 6px 20px rgba(0,0,0,.3);cursor:pointer}.colorful-button:hover::before,#auto-task-buttons a.auto-task-website-btn:hover::before,.show-button-div a.auto-task-website-btn:hover::before,body.auto-task-options .auto-task-form table button:hover::before{filter:blur(10px);opacity:1}.colorful-button::before,#auto-task-buttons a.auto-task-website-btn::before,.show-button-div a.auto-task-website-btn::before,body.auto-task-options .auto-task-form table button::before{content:"";position:absolute;top:-5px;left:-5px;right:-5px;bottom:-5px;z-index:-1;background:linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);border-radius:40px;background-size:400%;opacity:-1}#auto-task-info{z-index:999999999 !important}#auto-task-info{position:fixed;bottom:10px;right:10px;width:60%;max-width:500px;max-height:60%;overflow-y:auto;color:#000;background-color:#fff;padding-left:5px;border:solid 2px #add8e6;border-radius:10px}#auto-task-info li{text-align:left}#auto-task-info li a.high-light{color:#00aeff;font-weight:bold}#auto-task-info .success{color:green}#auto-task-info .error{color:red}#auto-task-info .warning{color:blue}#auto-task-info .info{color:#ff0}#auto-task-info .update-text{color:green;border:solid 2px #8dcb69;margin:5px 10px 5px 20px;border-radius:10px;padding:5px 20px}.auto-task-keylol{text-decoration:none !important}.auto-task-keylol{display:inline-block;text-transform:capitalize;margin-left:10px;border:solid 1px;border-radius:5px;padding:0 2px}.auto-task-keylol[selected=selected]{background-color:blue !important;color:#fff !important}.auto-task-form table{font-family:verdana,arial,sans-serif;font-size:11px;color:#333;border-width:1px;border-color:#999;border-collapse:collapse;width:100%}.auto-task-form table thead td{border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9;font-weight:bold;background-color:#fff}.auto-task-form table tbody tr{background-color:#d4e3e5}.auto-task-form table tbody tr:hover{background-color:#ff6 !important}.auto-task-form table tbody tr th{background-color:#c3dde0;border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9;text-transform:capitalize}.auto-task-form table tbody tr td{border-width:1px;padding:8px;border-style:solid;border-color:#a9c6c9}.swal2-modal{width:70% !important;max-width:1000px !important}body.auto-task-options{padding-top:10px;text-align:center}body.auto-task-options .auto-task-form{width:80%;max-width:1000px;margin:0 auto;padding-bottom:20px}body.auto-task-options .auto-task-form table input.editOption{width:80%}body.auto-task-options .auto-task-form table #getTwitterUserId,body.auto-task-options .auto-task-form table #getYoutubeChannelId{margin-top:5px}body.auto-task-options .auto-task-form table button{z-index:1}body.auto-task-options .auto-task-form table input[type=text]{outline-style:none;border:1px solid #ccc;border-radius:3px;padding:5px 10px;font-size:14px}body.auto-task-options .auto-task-form table input[type=text]:focus{border-color:#66afe9;outline:0;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}body.auto-task-options .auto-task-form table label{position:relative;width:160px;height:80px;cursor:pointer;transform:scale(0.25);margin:-25% 0;top:-30px;display:inline-block}body.auto-task-options .auto-task-form table label input{position:relative;z-index:1;appearance:none}body.auto-task-options .auto-task-form table label input:checked~span{background:#05be05;box-shadow:0 15px 25px rgba(5,190,5,.4)}body.auto-task-options .auto-task-form table label input:checked~span i{left:84px}body.auto-task-options .auto-task-form table label input:checked~span i::before{background:#05be05;box-shadow:35px 0 0 #05be05}body.auto-task-options .auto-task-form table label input:checked~span i::after{bottom:12px;height:15px;border-bottom-left-radius:15px;border-bottom-right-radius:15px;background:#05be05}body.auto-task-options .auto-task-form table label span{position:absolute;top:0;left:0;width:100%;height:100%;background:#fe0000;border-radius:80px;transition:.5s;box-shadow:0 15px 25px rgba(254,0,0,.4)}body.auto-task-options .auto-task-form table label span i{position:absolute;top:4px;left:4px;width:72px;height:72px;background:#fff;border-radius:50%}body.auto-task-options .auto-task-form table label span i::before{content:"";position:absolute;top:22px;left:12px;width:12px;height:12px;border-radius:50%;background:#fe0000;box-shadow:35px 0 0 #fe0000;transition:.5s}body.auto-task-options .auto-task-form table label span i::after{content:"";position:absolute;bottom:15px;left:calc(50% - 15px);width:30px;height:6px;border-radius:6px;background:#fe0000;transition:.5s}body.auto-task-history{font-size:15px;font-weight:400;line-height:1.5}body.auto-task-history .container a{color:#007bff;text-decoration:none;background-color:rgba(0,0,0,0)}body.auto-task-history .container .card{width:80%;max-width:800px;border-radius:10px;background:rgba(118,118,118,.1019607843);border-top:1px solid rgba(255,255,255,.5019607843);-webkit-backdrop-filter:blur(20px);backdrop-filter:blur(20px);box-shadow:0 15px 25px rgba(0,0,0,.1019607843);margin:20px auto;position:relative;display:flex;flex-direction:column;word-wrap:break-word;-webkit-background-clip:border-box;background-clip:border-box;border:1px solid rgba(0,0,0,.125);border-radius:.25rem}body.auto-task-history .container .card .title{text-align:center;font-size:30px;font-weight:bold;margin:5px 0}body.auto-task-history .container .card .title a:hover{text-decoration:none;background:#93e1ff;border-radius:10px;padding:3px}body.auto-task-history .container .card ul{margin-bottom:25px}body.auto-task-history .container .card ul li{margin-bottom:5px;line-height:20px}body.auto-task-history .container .card ul a:hover{text-decoration:underline}body.auto-task-history .container .card .delete-task{right:10px;width:38px;height:35px;position:absolute;font-size:24px;cursor:pointer;border-radius:10px}body.auto-task-history .container .card .delete-task:hover{background:#fff}body.auto-task-history .container .card .time{right:5px;position:absolute;bottom:0;color:#e83e8c;font-family:'SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace';font-size:15px}#auto-task-buttons,.show-button-div{z-index:999999999 !important}#auto-task-buttons,.show-button-div{position:fixed;top:30px;right:15px;width:124px;transform:scale(0.85)}#auto-task-buttons p,.show-button-div p{margin:5px !important}#auto-task-buttons p,.show-button-div p{line-height:30px;height:40px;text-align:center}#auto-task-buttons a.auto-task-website-btn,.show-button-div a.auto-task-website-btn{width:105px;line-height:27px;font-size:20px;display:block}.show-button-div{width:20px}.auto-task-capitalize{text-transform:capitalize !important}.swal2-file:focus,.swal2-input:focus,.swal2-textarea:focus{box-shadow:inset 0px 0px 4px 1px rgba(100,150,200,.5) !important}.swal2-checkbox-custom{align-items:center;justify-content:center;background:#fff;color:inherit;margin:1em auto}.swal2-checkbox-custom input{flex-shrink:0;margin:0 .4em}.giveaway-actions #getKey{display:none !important}.auto-task-giveaway-status{color:#fff;border-radius:10px;padding:0 5px;margin-left:5px}.auto-task-giveaway-status.active{background-color:#5cb85c}.auto-task-giveaway-status.not-active{background-color:#d9534f}`, '' ]);
  423. const __WEBPACK_DEFAULT_EXPORT__ = ___CSS_LOADER_EXPORT___.toString();
  424. },
  425. 314: function(module) {
  426. 'use strict';
  427. module.exports = function(cssWithMappingToString) {
  428. var list = [];
  429. list.toString = function toString() {
  430. return this.map(function(item) {
  431. var content = '';
  432. var needLayer = typeof item[5] !== 'undefined';
  433. if (item[4]) {
  434. content += '@supports ('.concat(item[4], ') {');
  435. }
  436. if (item[2]) {
  437. content += '@media '.concat(item[2], ' {');
  438. }
  439. if (needLayer) {
  440. content += '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {');
  441. }
  442. content += cssWithMappingToString(item);
  443. if (needLayer) {
  444. content += '}';
  445. }
  446. if (item[2]) {
  447. content += '}';
  448. }
  449. if (item[4]) {
  450. content += '}';
  451. }
  452. return content;
  453. }).join('');
  454. };
  455. list.i = function i(modules, media, dedupe, supports, layer) {
  456. if (typeof modules === 'string') {
  457. modules = [ [ null, modules, undefined ] ];
  458. }
  459. var alreadyImportedModules = {};
  460. if (dedupe) {
  461. for (var k = 0; k < this.length; k++) {
  462. var id = this[k][0];
  463. if (id != null) {
  464. alreadyImportedModules[id] = true;
  465. }
  466. }
  467. }
  468. for (var _k = 0; _k < modules.length; _k++) {
  469. var item = [].concat(modules[_k]);
  470. if (dedupe && alreadyImportedModules[item[0]]) {
  471. continue;
  472. }
  473. if (typeof layer !== 'undefined') {
  474. if (typeof item[5] === 'undefined') {
  475. item[5] = layer;
  476. } else {
  477. item[1] = '@layer'.concat(item[5].length > 0 ? ' '.concat(item[5]) : '', ' {').concat(item[1], '}');
  478. item[5] = layer;
  479. }
  480. }
  481. if (media) {
  482. if (!item[2]) {
  483. item[2] = media;
  484. } else {
  485. item[1] = '@media '.concat(item[2], ' {').concat(item[1], '}');
  486. item[2] = media;
  487. }
  488. }
  489. if (supports) {
  490. if (!item[4]) {
  491. item[4] = ''.concat(supports);
  492. } else {
  493. item[1] = '@supports ('.concat(item[4], ') {').concat(item[1], '}');
  494. item[4] = supports;
  495. }
  496. }
  497. list.push(item);
  498. }
  499. };
  500. return list;
  501. };
  502. },
  503. 601: function(module) {
  504. 'use strict';
  505. module.exports = function(i) {
  506. return i[1];
  507. };
  508. }
  509. };
  510. var __webpack_module_cache__ = {};
  511. function __webpack_require__(moduleId) {
  512. var cachedModule = __webpack_module_cache__[moduleId];
  513. if (cachedModule !== undefined) {
  514. return cachedModule.exports;
  515. }
  516. var module = __webpack_module_cache__[moduleId] = {
  517. id: moduleId,
  518. exports: {}
  519. };
  520. __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  521. return module.exports;
  522. }
  523. !function() {
  524. __webpack_require__.n = function(module) {
  525. var getter = module && module.__esModule ? function() {
  526. return module['default'];
  527. } : function() {
  528. return module;
  529. };
  530. __webpack_require__.d(getter, {
  531. a: getter
  532. });
  533. return getter;
  534. };
  535. }();
  536. !function() {
  537. __webpack_require__.d = function(exports, definition) {
  538. for (var key in definition) {
  539. if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  540. Object.defineProperty(exports, key, {
  541. enumerable: true,
  542. get: definition[key]
  543. });
  544. }
  545. }
  546. };
  547. }();
  548. !function() {
  549. __webpack_require__.o = function(obj, prop) {
  550. return Object.prototype.hasOwnProperty.call(obj, prop);
  551. };
  552. }();
  553. var __webpack_exports__ = {};
  554. !function() {
  555. 'use strict';
  556. const external_Swal_namespaceObject = Swal;
  557. var external_Swal_default = __webpack_require__.n(external_Swal_namespaceObject);
  558. const external_Cookies_namespaceObject = Cookies;
  559. var auto_task = __webpack_require__(675);
  560. var javascript_utils_umd_min = __webpack_require__(991);
  561. const httpRequest = async (options, times = 0) => {
  562. if (window.TRACE) {
  563. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  564. }
  565. try {
  566. const result = await new Promise(resolve => {
  567. if (options.dataType) {
  568. options.responseType = options.dataType;
  569. }
  570. const requestObj = {
  571. ...{
  572. timeout: 3e4,
  573. ontimeout(data) {
  574. resolve({
  575. result: 'Error',
  576. statusText: 'Timeout',
  577. status: 601,
  578. data: data,
  579. options: options
  580. });
  581. },
  582. onabort(data) {
  583. resolve({
  584. result: 'Error',
  585. statusText: 'Aborted',
  586. status: 602,
  587. data: data,
  588. options: options
  589. });
  590. },
  591. onerror(data) {
  592. resolve({
  593. result: 'Error',
  594. statusText: 'Error',
  595. status: 603,
  596. data: data,
  597. options: options
  598. });
  599. },
  600. onload(data) {
  601. if (options.responseType === 'json' && data?.response && typeof data.response !== 'object') {
  602. try {
  603. data.response = JSON.parse(data.responseText);
  604. } catch (error) {}
  605. }
  606. resolve({
  607. result: 'Success',
  608. statusText: 'Load',
  609. status: 600,
  610. data: data,
  611. options: options
  612. });
  613. }
  614. },
  615. ...options
  616. };
  617. GM_xmlhttpRequest(requestObj);
  618. });
  619. if (window.DEBUG) {
  620. console.log('%cAuto-Task[httpRequest]:', 'color:blue', JSON.stringify(result));
  621. }
  622. if (result.status !== 600 && times < 2) {
  623. return await httpRequest(options, times + 1);
  624. }
  625. return result;
  626. } catch (error) {
  627. console.log('%cAuto-Task[httpRequest]:', 'color:red', JSON.stringify({
  628. errorMsg: error,
  629. options: options
  630. }));
  631. throwError(error, 'httpRequest');
  632. return {
  633. result: 'JsError',
  634. statusText: 'Error',
  635. status: 604,
  636. error: error,
  637. options: options
  638. };
  639. }
  640. };
  641. const tools_httpRequest = httpRequest;
  642. const echoLog = ({
  643. type,
  644. text,
  645. html,
  646. id
  647. }) => {
  648. const emptyStatus = {
  649. success: () => emptyStatus,
  650. error: () => emptyStatus,
  651. warning: () => emptyStatus,
  652. info: () => emptyStatus,
  653. view: () => emptyStatus
  654. };
  655. try {
  656. let ele;
  657. if (type) {
  658. switch (type) {
  659. case 'joiningSteamGroup':
  660. case 'leavingSteamGroup':
  661. case 'gettingSteamGroupId':
  662. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/groups/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  663. break;
  664.  
  665. case 'joiningSteamOfficialGroup':
  666. case 'leavingSteamOfficialGroup':
  667. case 'gettingSteamOfficialGroupId':
  668. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/games/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  669. break;
  670.  
  671. case 'subscribingForum':
  672. case 'unsubscribingForum':
  673. case 'gettingForumId':
  674. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/app/${text}/discussions/" target="_blank">${text}</a>]...<font></font></li>`);
  675. break;
  676.  
  677. case 'followingCurator':
  678. case 'unfollowingCurator':
  679. case 'gettingCuratorId':
  680. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/${text?.includes('/') ? text : `curator/${text}`}" target="_blank">${text}</a>]...<font></font></li>`);
  681. break;
  682.  
  683. case 'addingToWishlist':
  684. case 'removingFromWishlist':
  685. case 'followingGame':
  686. case 'unfollowingGame':
  687. case 'gettingSubid':
  688. case 'addingFreeLicense':
  689. case 'requestingPlayTestAccess':
  690. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/app/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  691. break;
  692.  
  693. case 'addingFreeLicenseSubid':
  694. ele = $(`<li>${i18n('addingFreeLicense')}[<a href="https://steamdb.info/sub/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  695. break;
  696.  
  697. case 'favoritingWorkshop':
  698. case 'unfavoritingWorkshop':
  699. case 'gettingWorkshopAppId':
  700. case 'votingUpWorkshop':
  701. ele = $(`<li>${i18n(type)}[<a href="https://steamcommunity.com/sharedfiles/filedetails/?id=${text}" target="_blank">
  702. ${text}</a>]...<font></font></li>`);
  703. break;
  704.  
  705. case 'gettingAnnouncementParams':
  706. case 'likingAnnouncement':
  707. ele = $(`<li>${i18n(type)}[<a href="https://store.steampowered.com/news/app/${text}/view/${id}" target="_blank">
  708. ${id}</a>]...<font></font></li>`);
  709. break;
  710.  
  711. case 'joiningDiscordServer':
  712. case 'gettingDiscordGuild':
  713. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/invite/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  714. break;
  715.  
  716. case 'leavingDiscordServer':
  717. ele = $(`<li>${i18n(type)}[<a href="https://discord.com/channels/@me/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  718. break;
  719.  
  720. case 'updateDiscordAuth':
  721. ele = $(`<li style="color:red;">${i18n('updateDiscordAuth')}</li>`);
  722. break;
  723.  
  724. case 'followingTwitchChannel':
  725. case 'unfollowingTwitchChannel':
  726. case 'gettingTwitchChannelId':
  727. ele = $(`<li>${i18n(type)}[<a href="https://www.twitch.tv/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  728. break;
  729.  
  730. case 'gettingInsUserId':
  731. case 'followingIns':
  732. case 'unfollowingIns':
  733. ele = $(`<li>${i18n(type)}[<a href="https://www.instagram.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  734. break;
  735.  
  736. case 'gettingTwitterUserId':
  737. case 'followingTwitterUser':
  738. case 'unfollowingTwitterUser':
  739. ele = $(`<li>${i18n(type)}[<a href="https://x.com/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  740. break;
  741.  
  742. case 'retweetting':
  743. case 'unretweetting':
  744. ele = $(`<li>${i18n(type)}${text}...<font></font></li>`);
  745. break;
  746.  
  747. case 'joiningReddit':
  748. case 'leavingReddit':
  749. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/r/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  750. break;
  751.  
  752. case 'followingRedditUser':
  753. case 'unfollowingRedditUser':
  754. ele = $(`<li>${i18n(type)}[<a href="https://www.reddit.com/user/${text?.replace('u_', '')}" target="_blank">
  755. ${text?.replace('u_', '')}</a>]...<font></font></li>`);
  756. break;
  757.  
  758. case 'followingYtbChannel':
  759. case 'unfollowingYtbChannel':
  760. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/channel/${text}" target="_blank">${text}</a>]...<font></font></li>`);
  761. break;
  762.  
  763. case 'likingYtbVideo':
  764. case 'unlikingYtbVideo':
  765. ele = $(`<li>${i18n(type)}[<a href="https://www.youtube.com/watch?v=${text}" target="_blank">${text}</a>]...<font></font></li>`);
  766. break;
  767.  
  768. case 'gettingVkId':
  769. case 'joiningVkGroup':
  770. case 'leavingVkGroup':
  771. case 'joiningVkPublic':
  772. case 'leavingVkPublic':
  773. case 'sendingVkWall':
  774. case 'deletingVkWall':
  775. ele = $(`<li>${i18n(type)}[<a href="https://vk.com/${text}/" target="_blank">${text}</a>]...<font></font></li>`);
  776. break;
  777.  
  778. case 'visitingLink':
  779. ele = $(`<li>${i18n('visitingLink')}[<a href="${text}" target="_blank">${text}</a>]...<font></font></li>`);
  780. break;
  781.  
  782. case 'verifyingInsAuth':
  783. case 'text':
  784. ele = $(`<li>${i18n(text)}<font></font></li>`);
  785. break;
  786.  
  787. case 'html':
  788. ele = $(text || html);
  789. break;
  790.  
  791. case 'whiteList':
  792. ele = $(`<li><font class="warning">${i18n('skipTask')}[${text}(${id})](${i18n('whiteList')})</font></li>`);
  793. break;
  794.  
  795. case 'globalOptionsSkip':
  796. ele = $(`<li>${i18n('skipTaskOption')}<font class="warning">${text}</font></li>`);
  797. break;
  798.  
  799. default:
  800. ele = $(`<li>${i18n('unKnown')}:${type}(${text})...<font></font></li>`);
  801. break;
  802. }
  803. } else if (text) {
  804. ele = $(`<li>${i18n(text)}<font></font></li>`);
  805. } else if (html) {
  806. ele = $(html);
  807. } else {
  808. ele = $('<li><font></font></li>');
  809. }
  810. ele.addClass('card-text');
  811. $('#auto-task-info').append(ele);
  812. ele[0]?.scrollIntoView();
  813. const font = ele.find('font');
  814. const status = {
  815. font: font,
  816. success(text = 'Success', html = false) {
  817. this.font?.attr('class', '').addClass('success');
  818. html ? this.font?.html(text) : this.font?.text(text);
  819. return this;
  820. },
  821. error(text = 'Error', html = false) {
  822. this.font?.attr('class', '').addClass('error');
  823. html ? this.font?.html(text) : this.font?.text(text);
  824. return this;
  825. },
  826. warning(text = 'Warning', html = false) {
  827. this.font?.attr('class', '').addClass('warning');
  828. html ? this.font?.html(text) : this.font?.text(text);
  829. return this;
  830. },
  831. info(text = 'Info', html = false) {
  832. this.font?.attr('class', '').addClass('info');
  833. html ? this.font?.html(text) : this.font?.text(text);
  834. return this;
  835. },
  836. view() {
  837. this.font?.[0].scrollIntoView();
  838. return this;
  839. }
  840. };
  841. return status;
  842. } catch (error) {
  843. throwError(error, 'echoLog');
  844. return emptyStatus;
  845. }
  846. };
  847. const scripts_echoLog = echoLog;
  848. const unique = array => {
  849. try {
  850. return [ ...new Set(array) ];
  851. } catch (error) {
  852. throwError(error, 'unique');
  853. return [];
  854. }
  855. };
  856. const delay = (time = 1e3) => new Promise(resolve => {
  857. setTimeout(() => {
  858. resolve(true);
  859. }, time);
  860. });
  861. const getRedirectLink = async link => {
  862. try {
  863. if (!link) {
  864. return null;
  865. }
  866. const redirectLinksCache = GM_getValue('redirectLinks') || {};
  867. if (redirectLinksCache[link]) {
  868. redirectLinksCache[link];
  869. }
  870. return await tools_httpRequest({
  871. url: link,
  872. method: 'GET'
  873. }).then(({
  874. data
  875. }) => {
  876. if (data?.finalUrl) {
  877. redirectLinksCache[link] = data.finalUrl;
  878. GM_setValue('redirectLinks', redirectLinksCache);
  879. return data.finalUrl;
  880. }
  881. return null;
  882. });
  883. } catch (error) {
  884. throwError(error, 'getRedirectLink');
  885. return null;
  886. }
  887. };
  888. const visitLink = async (link, options) => {
  889. try {
  890. const logStatus = scripts_echoLog({
  891. type: 'visitLink',
  892. text: link
  893. });
  894. return await tools_httpRequest({
  895. url: link,
  896. method: 'GET',
  897. ...options
  898. }).then(({
  899. result,
  900. statusText,
  901. status
  902. }) => {
  903. if (result === 'Success') {
  904. logStatus.success();
  905. return true;
  906. }
  907. logStatus.error(`${result}:${statusText}(${status})`);
  908. return false;
  909. });
  910. } catch (error) {
  911. throwError(error, 'visitLink');
  912. return false;
  913. }
  914. };
  915. const getUrlQuery = url => {
  916. try {
  917. const query = {};
  918. if (url) {
  919. if (url.includes('?')) {
  920. url.split('?')[1].replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  921. query[key] = value;
  922. return str;
  923. });
  924. }
  925. } else {
  926. window.location.search.replace(/([^?&=]+)=([^&]+)/g, (str, key, value) => {
  927. query[key] = value;
  928. return str;
  929. });
  930. }
  931. return query;
  932. } catch (error) {
  933. throwError(error, 'getUrlQuery');
  934. return {};
  935. }
  936. };
  937. const getUuid = () => {
  938. const uuidUrl = URL.createObjectURL(new Blob()).toString();
  939. return uuidUrl.slice(uuidUrl.lastIndexOf('/') + 1);
  940. };
  941. const stringToColour = str => {
  942. try {
  943. let hash = 0;
  944. for (let i = 0; i < str.length; i++) {
  945. hash = str.charCodeAt(i) + ((hash << 5) - hash);
  946. }
  947. let colour = '#';
  948. for (let i = 0; i < 3; i++) {
  949. const value = hash >> i * 8 & 255;
  950. colour += `00${value.toString(16)}`.slice(-2);
  951. }
  952. return colour;
  953. } catch (error) {
  954. throwError(error, 'stringToColour');
  955. return '#fff';
  956. }
  957. };
  958. const defaultGlobalOptions = {
  959. doTask: {
  960. discord: {
  961. servers: true
  962. },
  963. instagram: {
  964. users: true
  965. },
  966. twitch: {
  967. channels: true
  968. },
  969. twitter: {
  970. users: true,
  971. retweets: true
  972. },
  973. vk: {
  974. names: true
  975. },
  976. youtube: {
  977. channels: true,
  978. likes: true
  979. },
  980. reddit: {
  981. reddits: true
  982. },
  983. steam: {
  984. groups: true,
  985. officialGroups: true,
  986. wishlists: true,
  987. follows: true,
  988. forums: true,
  989. workshops: true,
  990. curators: true,
  991. workshopVotes: true,
  992. announcements: true,
  993. licenses: true,
  994. playtests: true
  995. }
  996. },
  997. undoTask: {
  998. discord: {
  999. servers: true
  1000. },
  1001. instagram: {
  1002. users: true
  1003. },
  1004. twitch: {
  1005. channels: true
  1006. },
  1007. twitter: {
  1008. users: true,
  1009. retweets: true
  1010. },
  1011. vk: {
  1012. names: true
  1013. },
  1014. youtube: {
  1015. channels: true,
  1016. likes: true
  1017. },
  1018. reddit: {
  1019. reddits: true
  1020. },
  1021. steam: {
  1022. groups: true,
  1023. officialGroups: true,
  1024. wishlists: true,
  1025. follows: true,
  1026. forums: true,
  1027. workshops: true,
  1028. curators: true
  1029. }
  1030. },
  1031. ASF: {
  1032. AsfEnabled: false,
  1033. AsfIpcUrl: '',
  1034. AsfIpcPassword: '',
  1035. AsfBotname: 'asf'
  1036. },
  1037. position: {
  1038. buttonSideX: 'right',
  1039. buttonSideY: 'top',
  1040. buttonDistance: '15,30',
  1041. showButtonSideX: 'right',
  1042. showButtonSideY: 'top',
  1043. showButtonDistance: '15,30',
  1044. logSideX: 'right',
  1045. logSideY: 'bottom',
  1046. logDistance: '10,10'
  1047. },
  1048. hotKey: {
  1049. doTaskKey: 'alt + d',
  1050. undoTaskKey: 'alt + u',
  1051. toggleLogKey: 'alt + l'
  1052. },
  1053. other: {
  1054. twitterVerifyId: '783214',
  1055. youtubeVerifyChannel: 'UCrXUsMBcfTVqwAS7DKg9C0Q',
  1056. autoUpdateSource: 'jsdelivr',
  1057. language: 'zh',
  1058. checkLogin: true,
  1059. checkLeftKey: true,
  1060. defaultShowButton: true,
  1061. defaultShowLog: true,
  1062. debug: false,
  1063. receivePreview: true
  1064. }
  1065. };
  1066. const userDefinedGlobalOptions = GM_getValue('globalOptions') || {};
  1067. const assignObject = (obj1, obj2) => {
  1068. try {
  1069. const newObj = {};
  1070. for (const [ key, value ] of Object.entries(obj1)) {
  1071. if (Object.prototype.toString.call(value) === '[object Object]' && Object.prototype.toString.call(obj2[key]) === '[object Object]') {
  1072. newObj[key] = assignObject(value, obj2[key]);
  1073. } else {
  1074. newObj[key] = obj2[key] ?? value;
  1075. }
  1076. }
  1077. return newObj;
  1078. } catch (error) {
  1079. throwError(error, 'assignObject');
  1080. return defaultGlobalOptions;
  1081. }
  1082. };
  1083. const globalOptions = assignObject(defaultGlobalOptions, userDefinedGlobalOptions);
  1084. const saveData = () => {
  1085. try {
  1086. const data = {};
  1087. $('#globalOptionsForm').serializeArray().map(value => {
  1088. data[value.name] = value.value;
  1089. return value;
  1090. });
  1091. $.makeArray($('#globalOptionsForm input')).map(element => {
  1092. const name = $(element).attr('name');
  1093. const keys = name.split('.');
  1094. if (keys.length === 3) {
  1095. globalOptions[keys[0]][keys[1]][keys[2]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1096. } else if (keys.length === 2) {
  1097. globalOptions[keys[0]][keys[1]] = data[name] ? data[name] === 'on' ? true : data[name] : false;
  1098. }
  1099. return element;
  1100. });
  1101. GM_setValue('globalOptions', globalOptions);
  1102. external_Swal_default().fire({
  1103. title: i18n('changeGlobalOptionsSuccess'),
  1104. icon: 'success'
  1105. });
  1106. } catch (error) {
  1107. throwError(error, 'saveData');
  1108. }
  1109. };
  1110. const changeGlobalOptions = showType => {
  1111. try {
  1112. let globalOptionsForm = `<form id="globalOptionsForm" class="auto-task-form">
  1113. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  1114. for (const [ type, data1 ] of Object.entries(globalOptions)) {
  1115. for (const [ option, data2 ] of Object.entries(data1)) {
  1116. if ([ 'other', 'position', 'hotKey', 'ASF' ].includes(type)) {
  1117. if (typeof data2 === 'boolean') {
  1118. 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>`;
  1119. } else {
  1120. 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>`;
  1121. }
  1122. } else {
  1123. for (const [ socialType, data3 ] of Object.entries(data2)) {
  1124. 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>`;
  1125. }
  1126. }
  1127. }
  1128. }
  1129. globalOptionsForm += '</tbody></table></form>';
  1130. if (showType === 'swal') {
  1131. external_Swal_default().fire({
  1132. title: i18n('globalOptions'),
  1133. html: globalOptionsForm,
  1134. showConfirmButton: true,
  1135. confirmButtonText: i18n('save'),
  1136. showCancelButton: true,
  1137. cancelButtonText: i18n('close')
  1138. }).then(({
  1139. isConfirmed
  1140. }) => {
  1141. if (isConfirmed) {
  1142. saveData();
  1143. }
  1144. });
  1145. } else {
  1146. $('body').append(`<h2>${i18n('globalOptions')}</h2>${globalOptionsForm}`);
  1147. }
  1148. } catch (error) {
  1149. throwError(error, 'changeGlobalOptions');
  1150. }
  1151. };
  1152. const data = {
  1153. website: '网站',
  1154. type: '类型',
  1155. edit: '编辑',
  1156. whiteList: '白名单',
  1157. skipTask: '跳过撤销任务',
  1158. whiteListOptions: '白名单设置',
  1159. changeWhiteListOption: '设置白名单(%0)',
  1160. whiteListNotFound: '找不到此项白名单: %0',
  1161. changeWhiteListSuccess: '白名单修改成功,刷新生效!',
  1162. changeWebsiteOptions: '网站设置',
  1163. changeGlobalOptions: '全局设置',
  1164. ok: '是',
  1165. save: '保存',
  1166. close: '关闭',
  1167. return: '返回',
  1168. option: '选项',
  1169. value: '值',
  1170. websiteOptions: '当前网站设置',
  1171. changeWebsiteOptionsSuccess: '更改当前网站设置成功,刷新生效!',
  1172. changeGlobalOptionsSuccess: '更改全局设置成功,刷新生效!',
  1173. needLogin: '请先登录!',
  1174. getTasksInfo: '正在获取并处理任务信息...',
  1175. gettingKey: '正在获取Key...',
  1176. verifyingTask: '正在验证任务',
  1177. notice: '自动任务脚本提醒',
  1178. noKeysLeft: '此页面已经没有剩余key了,是否关闭?',
  1179. giveawayEnded: '此活动已结束,是否关闭?',
  1180. giveawayNotWork: '此活动因某些原因(已结束/暂停/未开始...)不可用(如果是脚本误判请及时反馈),是否关闭?',
  1181. confirm: '确定',
  1182. cancel: '取消',
  1183. unKnown: '未知',
  1184. unKnownTaskType: '未识别的任务',
  1185. doing: '正在做任务',
  1186. allTasksComplete: '所有任务已完成!',
  1187. getTaskIdFailed: '获取任务Id失败!',
  1188. initSuccess: '%0 初始化成功!',
  1189. initFailed: '%0 初始化失败!',
  1190. errorLink: '链接错误: %0',
  1191. needInit: '请先初始化',
  1192. verifyingAuth: '正在验证%0凭证...',
  1193. updatingAuth: '正在更新%0凭证...',
  1194. refreshingToken: '正在刷新%0凭证...',
  1195. settingToken: '正在设置%0凭证...',
  1196. initing: '正在初始化...',
  1197. getFailed: '获取%0失败!',
  1198. checkLoginFailed: '检测登录状态失败!',
  1199. checkLeftKeyFailed: '检测剩余Key失败!',
  1200. userId: '用户Id',
  1201. joiningGiveaway: '正在加入赠Key',
  1202. needJoinGiveaway: '需要先加入赠Key',
  1203. cannotUndo: '此网站不支持取消任务',
  1204. verifyAuth: '正在验证 %0 凭证...',
  1205. closePageNotice: '如果此页面没有自动关闭,请自行关闭本页面。',
  1206. errorReport: '检测到脚本报错,是否前往反馈BUG?',
  1207. visitingLink: '正在访问链接: ',
  1208. doTask: '做任务',
  1209. undoTask: '撤销任务',
  1210. verifyTask: '验证任务',
  1211. getKey: '获取Key',
  1212. selectAll: '全选',
  1213. selectNone: '全不选',
  1214. invertSelect: '反选',
  1215. doFreeTask: '加入免费赠品',
  1216. doPointTask: '加入点数赠品',
  1217. skipTaskOption: '设置中已配置跳过任务',
  1218. other: '其他',
  1219. globalOptions: '全局设置',
  1220. checkLogin: '登录检测</br>需要登录的网站自动登录,部分本网站支持',
  1221. checkLeftKey: '剩余Key检测</br>赠Key活动结束提示是否关闭,部分本网站支持',
  1222. twitterVerifyId: '通过尝试关注该账号验证Twitter凭证</br>默认为Twitter官方帐号 783214</br>不想关注官方账号可以改为自己的帐号',
  1223. youtubeVerifyChannel: '通过尝试订阅该频道验证YouTube凭证</br>默认为YouTube官方频道 UCrXUsMBcfTVqwAS7DKg9C0Q</br>不想关注官方频道可以改为自己的频道',
  1224. autoUpdateSource: '更新源</br>github: 需代理,实时更新</br>jsdelivr: 可不用代理,更新有延迟</br>standby: 备用</br>auto: 依次使用github, jsdelivr, standby源进行尝试更新',
  1225. saveGlobalOptions: '保存全局设置',
  1226. settingPage: '设置页面',
  1227. name: '名称',
  1228. version: '版本',
  1229. scriptManager: '脚本管理器',
  1230. script: '脚本',
  1231. environment: '环境',
  1232. os: '系统',
  1233. browser: '浏览器',
  1234. getId: '获取 %0 id',
  1235. getTwitterUserId: '获取Twitter用户id(获取id功能仅在设置页面可用)',
  1236. getYoutubeChannelId: '获取Youtube频道id(获取id功能仅在设置页面可用)',
  1237. showButton: '显示按钮',
  1238. hideButton: '隐藏按钮',
  1239. showLog: '显示日志',
  1240. hideLog: '隐藏日志',
  1241. defaultShowButton: '默认显示按钮',
  1242. defaultShowLog: '默认显示日志',
  1243. debug: '输出调试日志,不要开启此选项!',
  1244. receivePreview: '接收预览版更新',
  1245. position: '组件位置',
  1246. buttonSideX: '按钮区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1247. buttonSideY: '按钮区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1248. buttonDistance: '按钮区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1249. showButtonSideX: '显示按钮水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1250. showButtonSideY: '显示按钮垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1251. showButtonDistance: '显示按钮距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1252. logSideX: '日志区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
  1253. logSideY: '日志区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
  1254. logDistance: '日志区域距边缘的距离(实时预览功能仅在设置页面可用)</br>格式: X距离,Y距离',
  1255. hotKey: '快捷键',
  1256. doTaskKey: '做任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1257. undoTaskKey: '撤销任务快捷键</br>(实时预览功能仅在设置页面可用)',
  1258. toggleLogKey: '显示/隐藏日志快捷键</br>(实时预览功能仅在设置页面可用)',
  1259. tasksHistory: '任务历史',
  1260. clearHistory: '清空历史',
  1261. clearHistoryFinished: '已清空任务历史!',
  1262. deleteTask: '删除任务',
  1263. lastChangeTime: '最后一次修改时间',
  1264. clearTaskFinished: '删除以下任务完成!',
  1265. clearTaskFailed: '删除任务失败,没有找到任务名!',
  1266. syncData: '数据同步',
  1267. settingData: '正在上传数据...',
  1268. gettingData: '正在获取数据...',
  1269. help: '帮助',
  1270. fileName: '文件名',
  1271. upload2gist: '同步到Gist',
  1272. downloadFromGist: '从Gist同步',
  1273. saveAndTest: '保存配置并测试',
  1274. testSuccess: '测试成功!',
  1275. testFailed: '测试失败!',
  1276. saveAndTestNotice: '请先保存配置并测试!',
  1277. processingData: '正在处理数据...',
  1278. updatingData: '正在上传数据...',
  1279. syncDataSuccess: '同步数据成功!',
  1280. syncDataFailed: '同步数据失败,请在控制台查看错误信息!',
  1281. downloadingData: '正在下载数据...',
  1282. checkedNoData: '没有检测到远程数据,请确认配置是否正确!',
  1283. savingData: '正在保存数据...',
  1284. syncHistory: '同步任务历史',
  1285. checkUpdateFailed: '检测更新失败',
  1286. newVersionNotice: '检测到新版本V%0, <a class="high-light" href="%1" target="_blank">点此更新</a>',
  1287. language: '语言</br>目前仅支持zh: 中文, en: 英文',
  1288. gistOptions: 'Gist 设置',
  1289. swalNotice: '检测到您第一次安装V4版本脚本,请前往阅读用前必读内容!',
  1290. echoNotice: '检测到您第一次安装V4版本脚本,请<a class="high-light" href="%0" target="_blank">点此前往</a>阅读用前必读内容!',
  1291. noticeLink: 'https://auto-task-doc.js.org/guide/#用前必读',
  1292. toGithub: '前往Github反馈',
  1293. toKeylol: '前往其乐论坛反馈',
  1294. copySuccess: '错误信息已复制到剪切板,是否前往其乐论坛反馈?',
  1295. copyFailed: '请复制下方错误信息后前往Keylol论坛反馈!',
  1296. updateText: '%0 版本更新内容:',
  1297. Active: '进行中',
  1298. Ended: '已结束',
  1299. Banned: '已封禁',
  1300. Paused: '已暂停',
  1301. notStart: '未开始',
  1302. noRemoteData: '检测到远程无数据',
  1303. errorRemoteDataFormat: '远程数据格式错误',
  1304. updateHistory: '历史更新记录<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">点此查看</a>',
  1305. AsfEnabled: '使用ASF做Steam相关任务(需<a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a>插件)',
  1306. AsfIpcUrl: 'ASF IPC 地址',
  1307. AsfIpcPassword: 'ASF IPC 密码',
  1308. versionNotMatched: '脚本管理器版本过低,需TamperMonkey >= 5.2.0或TamperMonkey Beta >= 5.2.6196',
  1309. groups: '组',
  1310. officialGroups: '官方组',
  1311. wishlists: '愿望单',
  1312. follows: '游戏关注',
  1313. forums: '论坛',
  1314. workshops: '创意工坊收藏',
  1315. curators: '鉴赏家',
  1316. workshopVotes: '创意工坊点赞',
  1317. announcements: '社区通知',
  1318. steamCommunity: 'Steam社区',
  1319. steamStore: 'Steam商店',
  1320. licenses: '入库免费游戏',
  1321. playtests: '请求访问权限',
  1322. needLoginSteamStore: '请先<a href="https://store.steampowered.com/login/" target="_blank">登录Steam商店</a>',
  1323. needLoginSteamCommunity: '请先<a href="https://steamcommunity.com/login/home/" target="_blank">登录Steam社区</a>',
  1324. joiningSteamGroup: '正在加入Steam组',
  1325. leavingSteamGroup: '正在退出Steam组',
  1326. gettingSteamGroupId: '正在获取Steam组Id',
  1327. joiningSteamOfficialGroup: '正在加入Steam官方组',
  1328. leavingSteamOfficialGroup: '正在退出Steam官方组',
  1329. gettingSteamOfficialGroupId: '正在获取Steam官方组Id',
  1330. subscribingForum: '正在订阅Steam论坛',
  1331. unsubscribingForum: '正在取消订阅Steam论坛',
  1332. gettingForumId: '正在获取Steam论坛Id',
  1333. followingCurator: '正在关注Steam鉴赏家',
  1334. unfollowingCurator: '正在取关Steam鉴赏家',
  1335. gettingCuratorId: '正在获取Steam鉴赏家Id',
  1336. addingToWishlist: '正在添加游戏到Steam愿望单',
  1337. removingFromWishlist: '正在从Steam愿望单移除游戏',
  1338. followingGame: '正在关注Steam游戏',
  1339. unfollowingGame: '正在取关Steam游戏',
  1340. favoritingWorkshop: '正在收藏Steam创意工坊物品',
  1341. unfavoritingWorkshop: '正在取消收藏Steam创意工坊物品',
  1342. gettingWorkshopAppId: '正在获取Steam创意工坊物品Id',
  1343. votingUpWorkshop: '正在点赞Steam创意工坊物品',
  1344. gettingAnnouncementParams: '正在获取Steam通知信息',
  1345. likingAnnouncement: '正在点赞Steam通知',
  1346. changingArea: '正在更换Steam地区: %0...',
  1347. notNeededChangeArea: '当前地区不需要更换',
  1348. noAnotherArea: '请检测是否开启正确开启代理',
  1349. gettingAreaInfo: '正在获取Steam地区信息...',
  1350. changeAreaNotice: '疑似锁区游戏,尝试换区执行',
  1351. steamFinishNotice: 'Steam任务完成,尝试将购物车地区换回CN',
  1352. gettingSubid: '正在获取游戏subid',
  1353. addingFreeLicense: '正在入库',
  1354. missParams: '缺少参数',
  1355. gettingLicenses: '正在获取Licenses...',
  1356. requestingPlayTestAccess: '正在请求访问权限',
  1357. tryChangeAreaNotice: '此功能无法检测游戏是否限区,因此会尝试换区后再入库,换区失败也不影响后续入库',
  1358. gettingUserLink: '正在获取Steam用户社区链接...',
  1359. retry: '重试',
  1360. initingASF: '正在初始化ASF...',
  1361. servers: '服务器',
  1362. joiningDiscordServer: '正在加入Discord服务器',
  1363. leavingDiscordServer: '正在退出Discord服务器',
  1364. gettingDiscordGuild: '正在获取Discord服务器Id',
  1365. getDiscordAuthFailed: '获取Discord凭证失败,请检测Discord帐号是否已登录',
  1366. discordImportantNotice: '重要提醒!!!',
  1367. discordImportantNoticeText: '由于Discord网站后台更新,目前使用此脚本加组后可能会导致Discord帐号被强制退出,且需要两步验证才能正常登录,请谨慎使用!!!',
  1368. continue: '继续',
  1369. skipDiscordTask: '跳过Discord任务',
  1370. continueAndDontRemindAgain: '继续且不再提醒',
  1371. users: '用户',
  1372. loginIns: '请先<a href="https://www.instagram.com/accounts/login/" target="_blank">登录Instagram</a>',
  1373. insBanned: '您的Instagram账户已被封禁',
  1374. verifyingInsAuth: '正在验证Instagram凭证...',
  1375. gettingInsUserId: '正在获取Instagram用户Id',
  1376. followingIns: '正在关注Instagram用户',
  1377. unfollowingIns: '正在取关Instagram用户',
  1378. reddits: '社区/用户',
  1379. loginReddit: '请先<a href="https://www.reddit.com/login/" target="_blank">登录Reddit</a>',
  1380. changingRedditVersion: '正在切换Reddit为新版页面...',
  1381. joiningReddit: '正在加入Reddit社区',
  1382. leavingReddit: '正在退出Reddit社区',
  1383. followingRedditUser: '正在关注Reddit用户',
  1384. unfollowingRedditUser: '正在取关Reddit用户',
  1385. channels: '频道',
  1386. followingTwitchChannel: '正在关注Twitch频道',
  1387. unfollowingTwitchChannel: '正在取关Twitch频道',
  1388. gettingTwitchChannelId: '正在获取Twitch频道Id',
  1389. checkingTwitchIntegrity: '正在检查Twitch完整性...',
  1390. twitterUser: '推特用户',
  1391. retweets: '转推',
  1392. gettingTwitterUserId: '正在获取推特用户Id',
  1393. followingTwitterUser: '正在关注推特用户',
  1394. unfollowingTwitterUser: '正在取关推特用户',
  1395. retweetting: '正在转推',
  1396. unretweetting: '正在撤销转推',
  1397. names: '组/社区/动态',
  1398. loginVk: '请先<a href="https://vk.com/login/" target="_blank">登录Vk</a>',
  1399. gettingVkId: '正在获取Vk任务Id',
  1400. joiningVkGroup: '正在加入Vk组',
  1401. leavingVkGroup: '正在退出Vk组',
  1402. joiningVkPublic: '正在加入Vk社区',
  1403. leavingVkPublic: '正在退出Vk社区',
  1404. sendingVkWall: '正在转发Vk动态',
  1405. deletingVkWall: '正在撤销转发Vk动态',
  1406. youtubeChannel: 'YouTube频道',
  1407. likes: '点赞',
  1408. loginYtb: '请先<a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">登录YouTube</a>',
  1409. tryUpdateYtbAuth: '请尝试<a href="https://www.youtube.com/#auth" target="_blank">更新YouTube凭证</a>',
  1410. gettingYtbToken: '正在获取YouTube Token...',
  1411. followingYtbChannel: '正在订阅YouTube频道',
  1412. unfollowingYtbChannel: '正在退订YouTube频道',
  1413. likingYtbVideo: '正在点赞YouTube视频',
  1414. unlikingYtbVideo: '正在取消点赞YouTube视频',
  1415. giveKeyNoticeBefore: '每次验证间隔15s',
  1416. giveKeyNoticeAfter: '如果没有key, 请在<a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>查看',
  1417. noPoints: '点数不够,跳过抽奖',
  1418. getNeedPointsFailed: '获取所需点数失败,跳过抽奖',
  1419. joiningLottery: '正在加入抽奖',
  1420. doingGleamTask: '正在做Gleam任务...',
  1421. gettingGleamLink: '正在获取Gleam任务链接...',
  1422. gleamTaskNotice: '如果此页面长时间未关闭,请完成任一任务后自行关闭!',
  1423. verifiedGleamTasks: '已尝试验证所有任务,验证失败的任务请尝试手动验证或完成!',
  1424. campaign: '检测到人机验证,请完成验证后重新验证任务!',
  1425. gsNotice: '为避免得到"0000-0000-0000"key, 已自动屏蔽"Grab Key"按钮,获取key时请关闭脚本!',
  1426. giveeClubVerifyNotice: '正在验证任务...',
  1427. giveeClubVerifyFinished: '请等待验证完成后自行加入赠Key',
  1428. doingKeyhubTask: '正在做Keyhub任务...',
  1429. SweepWidgetNotice: '正在处理并验证任务,每次验证任务有1~3s间隔防止触发验证过快警告...',
  1430. tasksNotCompleted: '任务未完成',
  1431. confirmingTask: '正在跳过警告页面...'
  1432. };
  1433. const zh_CN = data;
  1434. const en_US_data = {
  1435. website: 'Website',
  1436. type: 'Type',
  1437. edit: 'Edit',
  1438. whiteList: 'Whitelist',
  1439. skipTask: 'Skip undo task',
  1440. whiteListOptions: 'Whitelist options',
  1441. changeWhiteListOption: 'Whitelist option(%0)',
  1442. whiteListNotFound: 'Cannot find this whitelist: %0',
  1443. changeWhiteListSuccess: 'The whitelist is successfully modified, and the page refresh will take effect!',
  1444. changeWebsiteOptions: 'Website options',
  1445. changeGlobalOptions: 'Global options',
  1446. ok: 'OK',
  1447. save: 'Save',
  1448. close: 'Close',
  1449. return: 'Return',
  1450. option: 'Option',
  1451. value: 'Value',
  1452. websiteOptions: 'Current website settings',
  1453. changeWebsiteOptionsSuccess: 'The current website setting is changed successfully, and the page refresh will take effect!',
  1454. changeGlobalOptionsSuccess: 'The global setting is changed successfully, and the refresh will take effect!',
  1455. needLogin: 'Please log in first!',
  1456. getTasksInfo: 'Obtaining and processing task information...',
  1457. gettingKey: 'Getting Key...',
  1458. verifyingTask: 'Verifying task',
  1459. notice: 'Automatic task script notice',
  1460. noKeysLeft: 'There are no more keys left on this page. Do you want to close it?',
  1461. giveawayEnded: 'This event has ended, do you want to close it?',
  1462. 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?',
  1463. confirm: 'Confirm',
  1464. cancel: 'Cancel',
  1465. unKnown: 'Unknown',
  1466. unKnownTaskType: 'Unrecognized task',
  1467. doing: 'Doing a task',
  1468. allTasksComplete: 'All tasks have been completed!',
  1469. getTaskIdFailed: 'Failed to obtain task Id!',
  1470. initSuccess: '%0 was initialized successfully!',
  1471. initFailed: '%0 initialization failed!',
  1472. errorLink: 'Link error: %0',
  1473. needInit: 'Please initialize first',
  1474. verifyingAuth: 'Verifying %0 token...',
  1475. updatingAuth: 'Update %0 token...',
  1476. initing: 'Initializing...',
  1477. getFailed: 'Failed to get %0!',
  1478. checkLoginFailed: 'Failed to detect login status!',
  1479. checkLeftKeyFailed: 'Failed to detect the remaining keys!',
  1480. userId: 'User Id',
  1481. joiningGiveaway: 'Joining giveaway',
  1482. needJoinGiveaway: 'Need to join the giveaway first',
  1483. cannotUndo: 'This website does not support canceling tasks',
  1484. verifyAuth: 'Verifying %0 token...',
  1485. closePageNotice: 'f this page does not close automatically, please close this page yourself.',
  1486. errorReport: 'A script error is detected, do you want to report the BUG?',
  1487. visitingLink: 'Visiting link: ',
  1488. doTask: 'DoTask',
  1489. undoTask: 'UndoTask',
  1490. verifyTask: 'Verify',
  1491. getKey: 'GetKey',
  1492. selectAll: 'SelectAll',
  1493. selectNone: 'SelectNone',
  1494. invertSelect: 'InvertSelect',
  1495. doFreeTask: 'FreeTask',
  1496. doPointTask: 'PointTask',
  1497. skipTaskOption: 'Skip task has been configured in the settings',
  1498. other: 'Other',
  1499. globalOptions: 'Global Options',
  1500. checkLogin: 'Login detection</br>Need to log in to the website automatically log in, part of this website supports.',
  1501. checkLeftKey: 'Key remaining detection</br>The end of the giveaway event prompts whether to close or not, part of this website supports.',
  1502. 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.',
  1503. 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.',
  1504. 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.',
  1505. saveGlobalOptions: 'SaveSettings',
  1506. settingPage: 'Setting Page',
  1507. name: 'Name',
  1508. version: 'Version',
  1509. scriptManager: 'Script Manager',
  1510. script: 'Script',
  1511. environment: 'Environment',
  1512. os: 'OS',
  1513. browser: 'Browser',
  1514. getId: 'Get %0 id',
  1515. getTwitterUserId: 'Get Twitter user id (Get id function is only available on the settings page).',
  1516. getYoutubeChannelId: 'Get Youtube channel id (Get id function is only available on the settings page).',
  1517. showButton: 'ShowButton',
  1518. hideButton: 'HideButton',
  1519. showLog: 'ShowLog',
  1520. hideLog: 'HideLog',
  1521. defaultShowButton: 'Default display button',
  1522. defaultShowLog: 'Display log by default',
  1523. debug: 'Output debug log, do not enable this option!',
  1524. receivePreview: 'Receive preview updates',
  1525. position: 'Component position',
  1526. buttonSideX: 'Horizontal positioning of the button area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1527. 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',
  1528. 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',
  1529. showButtonSideX: 'ShowButton horizontal positioning (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1530. showButtonSideY: 'ShowButton vertical positioning (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1531. 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',
  1532. logSideX: 'Horizontal positioning of the log area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1533. logSideY: 'Vertical positioning of the log area (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1534. 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',
  1535. hotKey: 'Shortcut key',
  1536. doTaskKey: 'DoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1537. undoTaskKey: 'UndoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1538. toggleLogKey: 'ShowLog/HideLog shortcut keys</br> (real-time preview function is only available on the settings page).',
  1539. tasksHistory: 'TasksHistory',
  1540. clearHistory: 'Clear history',
  1541. clearHistoryFinished: 'The mission history has been cleared!',
  1542. deleteTask: 'Delete task',
  1543. lastChangeTime: 'Last Change Time',
  1544. clearTaskFinished: 'Delete the following tasks completed!',
  1545. clearTaskFailed: 'Failed to delete the task, the task name was not found!',
  1546. syncData: 'DataSync',
  1547. settingData: 'Uploading data...',
  1548. gettingData: 'Getting data...',
  1549. help: 'Help',
  1550. fileName: 'Filename',
  1551. upload2gist: 'Sync to Gist',
  1552. downloadFromGist: 'Sync from Gist',
  1553. saveAndTest: 'Save configuration and test',
  1554. testSuccess: 'Test success!',
  1555. testFailed: 'Test failed!',
  1556. saveAndTestNotice: 'Please save the configuration and test first!',
  1557. processingData: 'Processing data...',
  1558. updatingData: 'Uploading data...',
  1559. syncDataSuccess: 'Synchronized data successfully!',
  1560. syncDataFailed: 'Failed to synchronize data, please check the error message on the console!',
  1561. downloadingData: 'Downloading data...',
  1562. checkedNoData: 'No remote data is detected, please confirm whether the configuration is correct!',
  1563. savingData: 'Saving data...',
  1564. syncHistory: 'Synchronize tasks history',
  1565. checkUpdateFailed: 'Check update failed',
  1566. newVersionNotice: 'Checked a new version V%0, <a class="high-light" href="%1" target="_blank">click to update</a>',
  1567. language: 'Language</br> Currently only supports zh: Chinese, en: English',
  1568. gistOptions: 'Gist Settings',
  1569. 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!',
  1570. 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!',
  1571. noticeLink: 'https://auto-task-doc.js.org/en/guide/#read-me-first',
  1572. toGithub: 'Feedback(Github)',
  1573. toKeylol: 'Feedback(Keylol)',
  1574. copySuccess: 'The error message has been copied to the clipboard. Do you want to go to the Keylol forum to give feedback?',
  1575. copyFailed: 'Please copy the error information below and report back to the Keylol forum!',
  1576. updateText: 'Updates in version %0:',
  1577. Active: 'Active',
  1578. Ended: 'Ended',
  1579. Banned: 'Banned',
  1580. Paused: 'Paused',
  1581. notStart: 'notStart',
  1582. noRemoteData: 'No data remotely',
  1583. errorRemoteDataFormat: 'Remote data has wrong format',
  1584. updateHistory: '<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">Click here</a>' + ' to view the historical update record.',
  1585. AsfEnabled: 'Use ASF to do Steam related tasks (requires <a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a> plugin)',
  1586. AsfIpcUrl: 'ASF IPC URL',
  1587. AsfIpcPassword: 'ASF IPC Password',
  1588. groups: 'Group',
  1589. officialGroups: 'Official Group',
  1590. wishlists: 'Wishlist',
  1591. follows: 'Follow Game',
  1592. forums: 'Forum',
  1593. workshops: 'Favorite Workshop',
  1594. curators: 'Curator',
  1595. workshopVotes: 'Voteup Workshop',
  1596. announcements: 'Announcement',
  1597. steamCommunity: 'Steam Community',
  1598. steamStore: 'Steam Store',
  1599. licenses: 'Add License',
  1600. playtests: 'Playtest Access',
  1601. needLoginSteamStore: 'Please <a href="https://store.steampowered.com/login/" target="_blank">log in to the Steam Store</a>',
  1602. needLoginSteamCommunity: 'Please <a href="https://steamcommunity.com/login/home/" target="_blank">log in to the Steam Community</a>',
  1603. joiningSteamGroup: 'Joining Steam Group',
  1604. leavingSteamGroup: 'Leaving Steam Group',
  1605. gettingSteamGroupId: 'Getting Steam Group Id',
  1606. joiningSteamOfficialGroup: 'Joining Steam Official Group',
  1607. leavingSteamOfficialGroup: 'Leaving Steam Official Group',
  1608. gettingSteamOfficialGroupId: 'Getting Steam Official Group Id',
  1609. subscribingForum: 'Subscribing the Steam Forum',
  1610. unsubscribingForum: 'Unsubscribing the Steam Forum',
  1611. gettingForumId: 'Getting Steam Forum Id',
  1612. followingCurator: 'Following Steam Curator',
  1613. unfollowingCurator: 'Unfollowing Steam Curator',
  1614. gettingCuratorId: 'Getting Steam Curator Id',
  1615. addingToWishlist: 'Adding the game to the Steam wishlist',
  1616. removingFromWishlist: 'Removing the game from the Steam wishlist',
  1617. followingGame: 'Following Steam games',
  1618. unfollowingGame: 'Unfollowing Steam games',
  1619. favoritingWorkshop: 'Favouring Steam Workshop Items',
  1620. unfavoritingWorkshop: 'Unfavoriting Steam Workshop Items',
  1621. gettingWorkshopAppId: 'Getting Steam Workshop Item Id',
  1622. votingUpWorkshop: 'Liking Steam workshop items',
  1623. gettingAnnouncementParams: 'Getting Steam announcement information',
  1624. likingAnnouncement: 'Liking Steam announcement',
  1625. changingArea: 'Changing Steam area: %0...',
  1626. notNeededChangeArea: 'The current area does not need to be changed',
  1627. noAnotherArea: 'Please check whether the proxy is turned on correctly',
  1628. gettingAreaInfo: 'Getting Steam area information...',
  1629. changeAreaNotice: 'Suspected of a locked zone game, try to change the zone to execute',
  1630. steamFinishNotice: 'Steam task completed, try to change the shopping cart area back to CN',
  1631. gettingSubid: 'Getting subid',
  1632. addingFreeLicense: 'Adding free license',
  1633. missParams: 'Missing parameters',
  1634. gettingLicenses: 'Getting licenses...',
  1635. requestingPlayTestAccess: 'Requesting play test access',
  1636. 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.',
  1637. versionNotMatched: 'The script manager version is too low, requiring TamperMonkey >= 5.2.0 or TamperMonkey Beta >= 5.2.6196',
  1638. gettingUserLink: 'Getting steam user community link...',
  1639. retry: 'Retry',
  1640. initingASF: 'Initing ASF...',
  1641. servers: 'Server',
  1642. joiningDiscordServer: 'Joining Discord Server',
  1643. leavingDiscordServer: 'Leaving Discord Server',
  1644. gettingDiscordGuild: 'Getting Discord server Id',
  1645. getDiscordAuthFailed: 'Failed to get Discord token, please check whether the Discord account is logged in',
  1646. discordImportantNotice: 'Important Reminder! ! !',
  1647. 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! ! !',
  1648. continue: 'Continue',
  1649. skipDiscordTask: 'Skip',
  1650. continueAndDontRemindAgain: 'Continue without Reminders',
  1651. users: 'User',
  1652. loginIns: 'Please <a href="https://www.instagram.com/accounts/login/" target="_blank">log in to Instagram</a>',
  1653. insBanned: 'Your Instagram account has been banned',
  1654. verifyingInsAuth: 'Verifying Instagram token...',
  1655. gettingInsUserId: 'Getting Instagram user Id',
  1656. followingIns: 'Following Instagram user',
  1657. unfollowingIns: 'Unfollowing Instagram user',
  1658. reddits: 'Reddit/User',
  1659. loginReddit: 'Please <a href="https://www.reddit.com/login/" target="_blank">log in to Reddit</a>',
  1660. changingRedditVersion: 'Switching Reddit to a new version page...',
  1661. joiningReddit: 'Joining the Reddit',
  1662. leavingReddit: 'Leaving the Reddit',
  1663. followingRedditUser: 'Following Reddit User',
  1664. unfollowingRedditUser: 'Unfollowing Reddit User',
  1665. channels: 'Channel',
  1666. followingTwitchChannel: 'Following Twitch Channel',
  1667. unfollowingTwitchChannel: 'Unfollowing Twitch Channel',
  1668. gettingTwitchChannelId: 'Getting Twitch Channel Id',
  1669. checkingTwitchIntegrity: 'Checking Twitch integrity...',
  1670. twitterUser: 'Twitter User',
  1671. retweets: 'Retweet',
  1672. gettingTwitterUserId: 'Getting Twitter User Id',
  1673. followingTwitterUser: 'Following Twitter User',
  1674. unfollowingTwitterUser: 'Unfollowing Twitter User',
  1675. retweetting: 'Retweetting',
  1676. unretweetting: 'Unretweetting',
  1677. names: 'Group/Public/Wall',
  1678. loginVk: 'Please <a href="https://vk.com/login/" target="_blank">log in to Vk</a>',
  1679. gettingVkId: 'Getting Vk task Id',
  1680. joiningVkGroup: 'Joining Vk Group',
  1681. leavingVkGroup: 'Leaving Vk Group',
  1682. joiningVkPublic: 'Joining Vk Public',
  1683. leavingVkPublic: 'Leaving Vk Public',
  1684. sendingVkWall: 'Sending Vk Wall',
  1685. deletingVkWall: 'Deleting Vk Wall',
  1686. youtubeChannel: 'YouTube Channel',
  1687. likes: 'Like',
  1688. loginYtb: 'Please <a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">log in to YouTube</a>',
  1689. tryUpdateYtbAuth: 'Please try to <a href="https://www.youtube.com/#auth" target="_blank">update YouTube token</a>',
  1690. gettingYtbToken: 'Getting YouTube Token...',
  1691. followingYtbChannel: 'Subscribing to YouTube channel',
  1692. unfollowingYtbChannel: 'Unsubscribing to YouTube channel',
  1693. likingYtbVideo: 'Liking YouTube video',
  1694. unlikingYtbVideo: 'Unliking YouTube video',
  1695. giveKeyNoticeBefore: 'Each verification interval is 15s',
  1696. giveKeyNoticeAfter: 'If there is no key, please check at <a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>',
  1697. noPoints: 'Not enough points, skip the lottery',
  1698. getNeedPointsFailed: 'ailed to obtain the required points, skip the lottery',
  1699. joiningLottery: 'Joining the lottery',
  1700. doingGleamTask: 'Doing Gleam Task...',
  1701. gettingGleamLink: 'Getting Gleam task link...',
  1702. gleamTaskNotice: 'If this page has not been closed for a long time, please close it yourself after completing any task!',
  1703. verifiedGleamTasks: 'Attempted to verify all tasks. If the verification fails, please try to verify manually or complete it!',
  1704. campaign: 'ReCAPTCHA detected, please complete it and re-verify the tasks!',
  1705. 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!',
  1706. giveeClubVerifyNotice: 'Verifying task...',
  1707. giveeClubVerifyFinished: 'Wait for the verification to complete and join it by yourself',
  1708. doingKeyhubTask: 'Doing Keyhub Task...',
  1709. 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...',
  1710. tasksNotCompleted: 'Tasks Not Completed',
  1711. confirmingTask: 'Confirming task...'
  1712. };
  1713. const en_US = en_US_data;
  1714. const languages = {
  1715. zh: zh_CN,
  1716. en: en_US
  1717. };
  1718. const language = [ 'zh', 'en' ].includes(globalOptions.other.language) ? globalOptions.other.language : 'en';
  1719. const I18n = (key, ...argvs) => {
  1720. if (!languages[language]?.[key]) {
  1721. return key;
  1722. }
  1723. return languages[language][key].replace(/%([\d]+)/g, (match, index) => argvs[parseInt(index, 10)]);
  1724. };
  1725. const i18n = I18n;
  1726. function throwError(error, name) {
  1727. if (window.TRACE) {
  1728. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  1729. }
  1730. external_Swal_default().fire({
  1731. title: i18n('errorReport'),
  1732. icon: 'error',
  1733. showCancelButton: true,
  1734. confirmButtonText: i18n('toGithub'),
  1735. showDenyButton: true,
  1736. denyButtonText: i18n('toKeylol'),
  1737. cancelButtonText: i18n('close')
  1738. }).then(({
  1739. isDenied,
  1740. isConfirmed
  1741. }) => {
  1742. if (isConfirmed) {
  1743. 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,
  1744. 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');
  1745. } else if (isDenied) {
  1746. const text = `错误链接: [url=${window.location.href}]${window.location.href}[/url]
  1747.  
  1748. 环境:
  1749.  
  1750. [code]${JSON.stringify((0, javascript_utils_umd_min.ua)(), null, 4)}[/code]
  1751.  
  1752. 脚本管理器: ${GM_info.scriptHandler} ${GM_info.version}
  1753. 脚本版本: ${GM_info.script.version}
  1754.  
  1755. 报错信息:
  1756. [code]${error.stack}[/code]
  1757.  
  1758. 执行日志:
  1759. [code]${$.makeArray($('#auto-task-info>li')).map(element => element.innerText).join('\n')}[/code]`;
  1760. GM_setClipboard(text);
  1761. external_Swal_default().fire({
  1762. title: i18n('copySuccess'),
  1763. icon: 'success',
  1764. confirmButtonText: i18n('ok')
  1765. }).then(() => {
  1766. window.open('https://keylol.com/forum.php?mod=post&action=reply&fid=319&tid=777450', '_blank');
  1767. });
  1768. }
  1769. });
  1770. console.log('%c%s', 'color:white;background:red', `Auto-Task[Error]: ${name}\n${error.stack}`);
  1771. }
  1772. class Social {
  1773. tasks;
  1774. getRealParams(name, links, doTask, link2param) {
  1775. try {
  1776. let realParams = [];
  1777. if (links.length > 0) {
  1778. realParams = [ ...realParams, ...links.map(link => link2param(link)).filter(link => link) ];
  1779. }
  1780. if (!doTask && this.tasks[name].length > 0) {
  1781. realParams = [ ...realParams, ...this.tasks[name] ];
  1782. }
  1783. return unique(realParams);
  1784. } catch (error) {
  1785. throwError(error, 'Social.getRealParams');
  1786. return [];
  1787. }
  1788. }
  1789. }
  1790. const social_Social = Social;
  1791. class Discord extends social_Social {
  1792. tasks;
  1793. whiteList;
  1794. #auth = GM_getValue('discordAuth') || {};
  1795. #cache = GM_getValue('discordCache') || {};
  1796. #initialized = false;
  1797. constructor() {
  1798. super();
  1799. const defaultTasksTemplate = {
  1800. servers: []
  1801. };
  1802. this.tasks = defaultTasksTemplate;
  1803. this.whiteList = {
  1804. ...defaultTasksTemplate,
  1805. ...GM_getValue('whiteList')?.discord || {}
  1806. };
  1807. }
  1808. async init(action) {
  1809. try {
  1810. if (!GM_getValue('dontRemindDiscordAgain')) {
  1811. const result = await external_Swal_default().fire({
  1812. title: i18n('discordImportantNotice'),
  1813. text: i18n('discordImportantNoticeText'),
  1814. showCancelButton: true,
  1815. showDenyButton: true,
  1816. confirmButtonText: i18n('continue'),
  1817. cancelButtonText: i18n('skipDiscordTask'),
  1818. denyButtonText: i18n('continueAndDontRemindAgain')
  1819. }).then(({
  1820. isConfirmed,
  1821. isDenied
  1822. }) => {
  1823. if (isConfirmed) {
  1824. return true;
  1825. }
  1826. if (isDenied) {
  1827. GM_setValue('dontRemindDiscordAgain', true);
  1828. return true;
  1829. }
  1830. return false;
  1831. });
  1832. if (!result) {
  1833. this.#initialized = false;
  1834. return 'skip';
  1835. }
  1836. }
  1837. if (GM_getValue('dontRemindDiscordAgain') || action === 'do' && !globalOptions.doTask.discord.servers || action === 'undo' && !globalOptions.undoTask.discord.servers) {
  1838. this.#initialized = false;
  1839. return 'skip';
  1840. }
  1841. if (this.#initialized) {
  1842. return true;
  1843. }
  1844. if (!this.#auth.auth) {
  1845. if (await this.#updateAuth()) {
  1846. this.#initialized = true;
  1847. return true;
  1848. }
  1849. return false;
  1850. }
  1851. const isVerified = await this.#verifyAuth();
  1852. if (isVerified) {
  1853. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1854. this.#initialized = true;
  1855. return true;
  1856. }
  1857. GM_setValue('discordAuth', {
  1858. auth: null
  1859. });
  1860. if (await this.#updateAuth()) {
  1861. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1862. this.#initialized = true;
  1863. return true;
  1864. }
  1865. scripts_echoLog({}).error(i18n('initFailed', 'Discord'));
  1866. return false;
  1867. } catch (error) {
  1868. throwError(error, 'Discord.init');
  1869. return false;
  1870. }
  1871. }
  1872. async #verifyAuth() {
  1873. try {
  1874. const logStatus = scripts_echoLog({
  1875. text: i18n('verifyingAuth', 'Discord')
  1876. });
  1877. const {
  1878. result,
  1879. statusText,
  1880. status,
  1881. data
  1882. } = await tools_httpRequest({
  1883. url: 'https://discord.com/api/v6/users/@me',
  1884. method: 'HEAD',
  1885. headers: {
  1886. authorization: this.#auth.auth
  1887. }
  1888. });
  1889. if (result === 'Success') {
  1890. if (data?.status === 200) {
  1891. logStatus.success();
  1892. return true;
  1893. }
  1894. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  1895. return false;
  1896. }
  1897. logStatus.error(`${result}:${statusText}(${status})`);
  1898. return false;
  1899. } catch (error) {
  1900. throwError(error, 'Discord.verifyAuth');
  1901. return false;
  1902. }
  1903. }
  1904. async #updateAuth() {
  1905. try {
  1906. const logStatus = scripts_echoLog({
  1907. text: i18n('updatingAuth', 'Discord')
  1908. });
  1909. return await new Promise(resolve => {
  1910. const newTab = GM_openInTab('https://discord.com/channels/@me#auth', {
  1911. active: true,
  1912. insert: true,
  1913. setParent: true
  1914. });
  1915. newTab.onclose = async () => {
  1916. const auth = GM_getValue('discordAuth')?.auth;
  1917. if (auth) {
  1918. this.#auth = {
  1919. auth: auth
  1920. };
  1921. logStatus.success();
  1922. resolve(await this.#verifyAuth());
  1923. } else {
  1924. logStatus.error('Error: Update discord auth failed!');
  1925. resolve(false);
  1926. }
  1927. };
  1928. });
  1929. } catch (error) {
  1930. throwError(error, 'Discord.updateAuth');
  1931. return false;
  1932. }
  1933. }
  1934. async #joinServer(inviteId) {
  1935. try {
  1936. const logStatus = scripts_echoLog({
  1937. type: 'joiningDiscordServer',
  1938. text: inviteId
  1939. });
  1940. const {
  1941. result,
  1942. statusText,
  1943. status,
  1944. data
  1945. } = await tools_httpRequest({
  1946. url: `https://discord.com/api/v9/invites/${inviteId}`,
  1947. method: 'POST',
  1948. dataType: 'json',
  1949. headers: {
  1950. authorization: this.#auth.auth,
  1951. origin: 'https://discord.com',
  1952. referer: `https://discord.com/invite/${inviteId}`
  1953. }
  1954. });
  1955. if (result === 'Success' && data?.status === 200) {
  1956. logStatus.success();
  1957. const guild = String(data.response?.guild?.id);
  1958. if (guild) {
  1959. this.#setCache(inviteId, guild);
  1960. this.tasks.servers = unique([ ...this.tasks.servers, inviteId ]);
  1961. }
  1962. return true;
  1963. }
  1964. logStatus.error(`${result}:${statusText}(${status})`);
  1965. return false;
  1966. } catch (error) {
  1967. throwError(error, 'Discord.joinServer');
  1968. return false;
  1969. }
  1970. }
  1971. async #leaveServer(inviteId) {
  1972. try {
  1973. if (this.whiteList.servers.includes(inviteId)) {
  1974. scripts_echoLog({
  1975. type: 'whiteList',
  1976. text: 'Discord.leaveServer',
  1977. id: inviteId
  1978. });
  1979. return true;
  1980. }
  1981. const guild = await this.#getGuild(inviteId);
  1982. if (!guild) {
  1983. return false;
  1984. }
  1985. const logStatus = scripts_echoLog({
  1986. type: 'leavingDiscordServer',
  1987. text: guild
  1988. });
  1989. const {
  1990. result,
  1991. statusText,
  1992. status,
  1993. data
  1994. } = await tools_httpRequest({
  1995. url: `https://discord.com/api/v9/users/@me/guilds/${guild}`,
  1996. method: 'DELETE',
  1997. headers: {
  1998. authorization: this.#auth.auth
  1999. }
  2000. });
  2001. if (result === 'Success' && data?.status === 204) {
  2002. logStatus.success();
  2003. return true;
  2004. }
  2005. logStatus.error(`${result}:${statusText}(${status})`);
  2006. return false;
  2007. } catch (error) {
  2008. throwError(error, 'Discord.leaveServer');
  2009. return false;
  2010. }
  2011. }
  2012. async #getGuild(inviteId) {
  2013. try {
  2014. const logStatus = scripts_echoLog({
  2015. type: 'gettingDiscordGuild',
  2016. text: inviteId
  2017. });
  2018. const guild = this.#cache[inviteId];
  2019. if (guild) {
  2020. logStatus.success();
  2021. return guild;
  2022. }
  2023. const {
  2024. result,
  2025. statusText,
  2026. status,
  2027. data
  2028. } = await tools_httpRequest({
  2029. url: `https://discord.com/api/v9/invites/${inviteId}`,
  2030. responseType: 'json',
  2031. method: 'GET'
  2032. });
  2033. if (result === 'Success' && data?.status === 200) {
  2034. const guild = data.response?.guild?.id;
  2035. if (guild) {
  2036. logStatus.success();
  2037. this.#setCache(inviteId, guild);
  2038. return guild;
  2039. }
  2040. logStatus.error(`${result}:${statusText}(${status})`);
  2041. return false;
  2042. }
  2043. logStatus.error(`${result}:${statusText}(${status})`);
  2044. return false;
  2045. } catch (error) {
  2046. throwError(error, 'Discord.getGuild');
  2047. return false;
  2048. }
  2049. }
  2050. async toggle({
  2051. doTask = true,
  2052. serverLinks = []
  2053. }) {
  2054. try {
  2055. if (!this.#initialized) {
  2056. scripts_echoLog({
  2057. text: i18n('needInit')
  2058. });
  2059. return false;
  2060. }
  2061. const prom = [];
  2062. if (doTask && !globalOptions.doTask.discord.servers || !doTask && !globalOptions.undoTask.discord.servers) {
  2063. scripts_echoLog({
  2064. type: 'globalOptionsSkip',
  2065. text: 'discord.servers'
  2066. });
  2067. } else {
  2068. const realServers = this.getRealParams('servers', serverLinks, doTask, link => link.match(/invite\/(.+)/)?.[1]);
  2069. if (realServers.length > 0) {
  2070. for (const server of realServers) {
  2071. if (doTask) {
  2072. prom.push(this.#joinServer(server));
  2073. } else {
  2074. prom.push(this.#leaveServer(server));
  2075. }
  2076. await delay(1e3);
  2077. }
  2078. }
  2079. }
  2080. return await Promise.all(prom).then(() => true);
  2081. } catch (error) {
  2082. throwError(error, 'Discord.toggleServers');
  2083. return false;
  2084. }
  2085. }
  2086. #setCache(inviteId, guild) {
  2087. try {
  2088. this.#cache[inviteId] = guild;
  2089. GM_setValue('discordCache', this.#cache);
  2090. } catch (error) {
  2091. throwError(error, 'Discord.setCache');
  2092. }
  2093. }
  2094. }
  2095. const social_Discord = Discord;
  2096. class Instagram extends social_Social {
  2097. tasks;
  2098. whiteList;
  2099. #cache = GM_getValue('instagramCache') || {};
  2100. #auth = {};
  2101. #initialized = false;
  2102. constructor() {
  2103. super();
  2104. const defaultTasksTemplate = {
  2105. users: []
  2106. };
  2107. this.tasks = defaultTasksTemplate;
  2108. this.whiteList = {
  2109. ...defaultTasksTemplate,
  2110. ...GM_getValue('whiteList')?.instagram || {}
  2111. };
  2112. }
  2113. async init() {
  2114. try {
  2115. if (this.#initialized) {
  2116. return true;
  2117. }
  2118. const isVerified = await this.#getUserInfo();
  2119. if (isVerified) {
  2120. scripts_echoLog({}).success(i18n('initSuccess', 'Instagram'));
  2121. this.#initialized = true;
  2122. return true;
  2123. }
  2124. scripts_echoLog({}).error(i18n('initFailed', 'Instagram'));
  2125. return false;
  2126. } catch (error) {
  2127. throwError(error, 'Instagram.init');
  2128. return false;
  2129. }
  2130. }
  2131. async #getUserInfo(name = 'instagram') {
  2132. try {
  2133. const logStatus = scripts_echoLog({
  2134. type: name === 'instagram' ? 'verifyingInsAuth' : 'gettingInsUserId',
  2135. text: name
  2136. });
  2137. const userId = this.#cache[name];
  2138. if (userId && name !== 'instagram') {
  2139. logStatus.success();
  2140. return userId;
  2141. }
  2142. const {
  2143. result,
  2144. statusText,
  2145. status,
  2146. data
  2147. } = await tools_httpRequest({
  2148. url: `https://www.instagram.com/${name}/`,
  2149. method: 'GET'
  2150. });
  2151. if (result === 'Success') {
  2152. if (data?.finalUrl.includes('accounts/login')) {
  2153. logStatus.error(`Error:${i18n('loginIns')}`, true);
  2154. return false;
  2155. } else if (data?.finalUrl.includes('www.instagram.com/challenge')) {
  2156. logStatus.error(`Error:${i18n('insBanned')}`);
  2157. return false;
  2158. }
  2159. if (data?.status === 200) {
  2160. const csrftoken = data.responseText.match(/"csrf_token":"(.+?)"/)?.[1];
  2161. const hash = data.responseText.match(/"rollout_hash":"(.+?)"/)?.[1];
  2162. if (name === 'instagram') {
  2163. if (csrftoken && hash) {
  2164. this.#auth = {
  2165. csrftoken: csrftoken,
  2166. hash: hash
  2167. };
  2168. return true;
  2169. }
  2170. return false;
  2171. }
  2172. const id = data.responseText.match(/"profilePage_([\d]+?)"/)?.[1];
  2173. if (id) {
  2174. this.#setCache(name, id);
  2175. logStatus.success();
  2176. return id;
  2177. }
  2178. logStatus.error('Error: Get ins data error!');
  2179. return false;
  2180. }
  2181. logStatus.error(`${result}:${statusText}(${status})`);
  2182. return false;
  2183. }
  2184. return false;
  2185. } catch (error) {
  2186. throwError(error, 'Instagram.getUserInfo');
  2187. return false;
  2188. }
  2189. }
  2190. async #followUser(name) {
  2191. try {
  2192. const id = await this.#getUserInfo(name);
  2193. if (!id) {
  2194. return false;
  2195. }
  2196. const logStatus = scripts_echoLog({
  2197. type: 'followingIns',
  2198. text: name
  2199. });
  2200. const {
  2201. result,
  2202. statusText,
  2203. status,
  2204. data
  2205. } = await tools_httpRequest({
  2206. url: `https://www.instagram.com/web/friendships/${id}/follow/`,
  2207. method: 'POST',
  2208. dataType: 'json',
  2209. headers: {
  2210. 'x-csrftoken': this.#auth.csrftoken,
  2211. origin: 'https://www.instagram.com',
  2212. referer: `https://www.instagram.com/${name}/`,
  2213. 'content-type': 'application/x-www-form-urlencoded',
  2214. 'sec-fetch-site': 'same-origin',
  2215. 'x-instagram-ajax': this.#auth.hash
  2216. }
  2217. });
  2218. if (result === 'Success') {
  2219. if (data?.status === 200 && data.response?.result === 'following') {
  2220. logStatus.success();
  2221. this.tasks.users = unique([ ...this.tasks.users, name ]);
  2222. return true;
  2223. }
  2224. logStatus.error(`Error:${data?.response?.feedback_message || `${data?.statusText}(${data?.status})`}`);
  2225. return false;
  2226. }
  2227. logStatus.error(`${result}:${statusText}(${status})`);
  2228. return false;
  2229. } catch (error) {
  2230. throwError(error, 'Instagram.followUser');
  2231. return false;
  2232. }
  2233. }
  2234. async #unfollowUser(name) {
  2235. try {
  2236. if (this.whiteList.users.includes(name)) {
  2237. scripts_echoLog({
  2238. type: 'whiteList',
  2239. text: 'Instagram.unfollowUser',
  2240. id: name
  2241. });
  2242. return true;
  2243. }
  2244. const id = await this.#getUserInfo(name);
  2245. if (!id) {
  2246. return false;
  2247. }
  2248. const logStatus = scripts_echoLog({
  2249. type: 'unfollowingIns',
  2250. text: name
  2251. });
  2252. const {
  2253. result,
  2254. statusText,
  2255. status,
  2256. data
  2257. } = await tools_httpRequest({
  2258. url: `https://www.instagram.com/web/friendships/${id}/unfollow/`,
  2259. method: 'POST',
  2260. dataType: 'json',
  2261. headers: {
  2262. 'x-csrftoken': this.#auth.csrftoken,
  2263. origin: 'https://www.instagram.com',
  2264. referer: `https://www.instagram.com/${name}/`,
  2265. 'content-type': 'application/x-www-form-urlencoded',
  2266. 'sec-fetch-site': 'same-origin',
  2267. 'x-instagram-ajax': this.#auth.hash
  2268. }
  2269. });
  2270. if (result === 'Success') {
  2271. if (data?.status === 200 && data.response?.status === 'ok') {
  2272. logStatus.success();
  2273. return true;
  2274. }
  2275. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2276. return false;
  2277. }
  2278. logStatus.error(`${result}:${statusText}(${status})`);
  2279. return false;
  2280. } catch (error) {
  2281. throwError(error, 'Instagram.unfollowUser');
  2282. return false;
  2283. }
  2284. }
  2285. async toggle({
  2286. doTask = true,
  2287. userLinks = []
  2288. }) {
  2289. try {
  2290. if (!this.#initialized) {
  2291. scripts_echoLog({
  2292. text: i18n('needInit')
  2293. });
  2294. return false;
  2295. }
  2296. const prom = [];
  2297. if (doTask && !globalOptions.doTask.instagram.users || !doTask && !globalOptions.undoTask.instagram.users) {
  2298. scripts_echoLog({
  2299. type: 'globalOptionsSkip',
  2300. text: 'instagram.users'
  2301. });
  2302. } else {
  2303. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1]);
  2304. if (realUsers.length > 0) {
  2305. for (const username of realUsers) {
  2306. if (doTask) {
  2307. prom.push(this.#followUser(username));
  2308. } else {
  2309. prom.push(this.#unfollowUser(username));
  2310. }
  2311. await delay(1e3);
  2312. }
  2313. }
  2314. }
  2315. return await Promise.all(prom).then(() => true);
  2316. } catch (error) {
  2317. throwError(error, 'Instagram.toggleUsers');
  2318. return false;
  2319. }
  2320. }
  2321. #setCache(name, id) {
  2322. try {
  2323. this.#cache[name] = id;
  2324. GM_setValue('instagramCache', this.#cache);
  2325. } catch (error) {
  2326. throwError(error, 'Instagram.setCache');
  2327. }
  2328. }
  2329. }
  2330. const social_Instagram = Instagram;
  2331. class Reddit extends social_Social {
  2332. tasks;
  2333. whiteList;
  2334. #auth;
  2335. #initialized = false;
  2336. constructor() {
  2337. super();
  2338. const defaultTasksTemplate = {
  2339. reddits: []
  2340. };
  2341. this.tasks = defaultTasksTemplate;
  2342. this.whiteList = {
  2343. ...defaultTasksTemplate,
  2344. ...GM_getValue('whiteList')?.reddit || {}
  2345. };
  2346. }
  2347. async init() {
  2348. try {
  2349. if (this.#initialized) {
  2350. return true;
  2351. }
  2352. const isVerified = await this.#updateAuth();
  2353. if (isVerified) {
  2354. scripts_echoLog({}).success(i18n('initSuccess', 'Reddit'));
  2355. this.#initialized = true;
  2356. return true;
  2357. }
  2358. scripts_echoLog({}).error(i18n('initFailed', 'Reddit'));
  2359. return false;
  2360. } catch (error) {
  2361. throwError(error, 'Reddit.init');
  2362. return false;
  2363. }
  2364. }
  2365. async #useBeta() {
  2366. try {
  2367. const logStatus = scripts_echoLog({
  2368. text: i18n('changingRedditVersion')
  2369. });
  2370. GM_setValue('redditAuth', null);
  2371. return await new Promise(resolve => {
  2372. const newTab = GM_openInTab('https://www.reddit.com/#auth', {
  2373. active: true,
  2374. insert: true,
  2375. setParent: true
  2376. });
  2377. newTab.onclose = async () => {
  2378. logStatus.success();
  2379. resolve(await this.#updateAuth(true));
  2380. };
  2381. });
  2382. } catch (error) {
  2383. throwError(error, 'Reddit.useBeta');
  2384. return false;
  2385. }
  2386. }
  2387. async #updateAuth(beta = false) {
  2388. try {
  2389. const logStatus = scripts_echoLog({
  2390. text: i18n('updatingAuth', 'Reddit')
  2391. });
  2392. const {
  2393. result,
  2394. statusText,
  2395. status,
  2396. data
  2397. } = await tools_httpRequest({
  2398. url: 'https://www.reddit.com/',
  2399. method: 'GET',
  2400. nochche: true,
  2401. headers: {
  2402. 'Cache-Control': 'no-cache'
  2403. }
  2404. });
  2405. if (result === 'Success') {
  2406. if (data?.responseText.includes('www.reddit.com/login/')) {
  2407. logStatus.error(`Error:${i18n('loginReddit')}`, true);
  2408. return false;
  2409. }
  2410. if (data?.status === 200) {
  2411. if (data.responseText.includes('redesign-beta-optin-btn') && !beta) {
  2412. return await this.#useBeta();
  2413. }
  2414. const accessToken = data.responseText.match(/"accessToken":"(.*?)","expires":"(.*?)"/)?.[1];
  2415. if (accessToken) {
  2416. this.#auth = {
  2417. token: accessToken
  2418. };
  2419. logStatus.success();
  2420. return true;
  2421. }
  2422. logStatus.error('Error: Parameter "accessToken" not found!');
  2423. return false;
  2424. }
  2425. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2426. return false;
  2427. }
  2428. logStatus.error(`${result}:${statusText}(${status})`);
  2429. return false;
  2430. } catch (error) {
  2431. throwError(error, 'Reddit.updateAuth');
  2432. return false;
  2433. }
  2434. }
  2435. async toggleTask({
  2436. name,
  2437. doTask = true
  2438. }) {
  2439. try {
  2440. if (!doTask && this.whiteList.reddits.includes(name)) {
  2441. scripts_echoLog({
  2442. type: 'whiteList',
  2443. text: 'Reddit.undoTask',
  2444. id: name
  2445. });
  2446. return true;
  2447. }
  2448. let type = doTask ? 'joiningReddit' : 'leavingReddit';
  2449. if (/^u_/.test(name)) {
  2450. type = doTask ? 'followingRedditUser' : 'unfollowingRedditUser';
  2451. }
  2452. const logStatus = scripts_echoLog({
  2453. type: type,
  2454. text: name
  2455. });
  2456. const {
  2457. result,
  2458. statusText,
  2459. status,
  2460. data
  2461. } = await tools_httpRequest({
  2462. url: 'https://oauth.reddit.com/api/subscribe?redditWebClient=desktop2x&app=desktop2x-client-production&raw_json=1&gilding_detail=1',
  2463. method: 'POST',
  2464. headers: {
  2465. authorization: `Bearer ${this.#auth.token}`,
  2466. 'content-type': 'application/x-www-form-urlencoded'
  2467. },
  2468. data: $.param({
  2469. action: doTask ? 'sub' : 'unsub',
  2470. sr_name: name,
  2471. api_type: 'json'
  2472. })
  2473. });
  2474. if (result === 'Success') {
  2475. if (data?.status === 200) {
  2476. logStatus.success();
  2477. if (doTask) {
  2478. this.tasks.reddits = unique([ ...this.tasks.reddits, name ]);
  2479. }
  2480. return true;
  2481. }
  2482. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2483. return false;
  2484. }
  2485. logStatus.error(`${result}:${statusText}(${status})`);
  2486. return false;
  2487. } catch (error) {
  2488. throwError(error, 'Reddit.toggleTask');
  2489. return false;
  2490. }
  2491. }
  2492. async toggle({
  2493. doTask = true,
  2494. redditLinks = []
  2495. }) {
  2496. try {
  2497. if (!this.#initialized) {
  2498. scripts_echoLog({
  2499. text: i18n('needInit')
  2500. });
  2501. return false;
  2502. }
  2503. const prom = [];
  2504. if (doTask && !globalOptions.doTask.reddit.reddits || !doTask && !globalOptions.undoTask.reddit.reddits) {
  2505. scripts_echoLog({
  2506. type: 'globalOptionsSkip',
  2507. text: 'reddit.reddits'
  2508. });
  2509. } else {
  2510. const realReddits = this.getRealParams('reddits', redditLinks, doTask, link => {
  2511. const name = link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1];
  2512. const userName = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1];
  2513. if (userName) {
  2514. return name || userName;
  2515. }
  2516. return name;
  2517. });
  2518. if (realReddits.length > 0) {
  2519. for (const name of realReddits) {
  2520. prom.push(this.toggleTask({
  2521. name: name,
  2522. doTask: doTask
  2523. }));
  2524. await delay(1e3);
  2525. }
  2526. }
  2527. }
  2528. return await Promise.all(prom).then(() => true);
  2529. } catch (error) {
  2530. throwError(error, 'Reddit.toggle');
  2531. return false;
  2532. }
  2533. }
  2534. }
  2535. const social_Reddit = Reddit;
  2536. class Twitch extends social_Social {
  2537. tasks;
  2538. whiteList;
  2539. #auth = GM_getValue('twitchAuth') || {};
  2540. #cache = GM_getValue('twitchCache') || {};
  2541. #initialized = false;
  2542. #integrityToken;
  2543. constructor() {
  2544. super();
  2545. const defaultTasksTemplate = {
  2546. channels: []
  2547. };
  2548. this.tasks = defaultTasksTemplate;
  2549. this.whiteList = {
  2550. ...defaultTasksTemplate,
  2551. ...GM_getValue('whiteList')?.twitch || {}
  2552. };
  2553. }
  2554. async init() {
  2555. try {
  2556. if (this.#initialized) {
  2557. return true;
  2558. }
  2559. if (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId) {
  2560. if (await this.#updateAuth()) {
  2561. this.#initialized = true;
  2562. return true;
  2563. }
  2564. return false;
  2565. }
  2566. const isVerified = await this.#verifyAuth(true);
  2567. if (isVerified) {
  2568. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2569. this.#initialized = true;
  2570. return true;
  2571. }
  2572. GM_setValue('twitchAuth', null);
  2573. if (await this.#updateAuth()) {
  2574. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2575. this.#initialized = true;
  2576. return true;
  2577. }
  2578. scripts_echoLog({}).error(i18n('initFailed', 'Twitch'));
  2579. return false;
  2580. } catch (error) {
  2581. throwError(error, 'Twitch.init');
  2582. return false;
  2583. }
  2584. }
  2585. async #verifyAuth(isFirst) {
  2586. try {
  2587. const logStatus = scripts_echoLog({
  2588. text: i18n('verifyingAuth', 'Twitch')
  2589. });
  2590. const {
  2591. result,
  2592. statusText,
  2593. status,
  2594. data
  2595. } = await tools_httpRequest({
  2596. url: 'https://gql.twitch.tv/gql',
  2597. method: 'POST',
  2598. dataType: 'json',
  2599. headers: {
  2600. Authorization: `OAuth ${this.#auth.authToken}`,
  2601. 'Client-Id': this.#auth.clientId
  2602. },
  2603. data: '[{"operationName":"FrontPageNew_User","variables":{"limit":1},"extensions":{"persistedQuery":{"version":1,' + '"sha256Hash":"64bd07a2cbaca80699d62636d966cf6395a5d14a1f0a14282067dcb28b13eb11"}}}]'
  2604. });
  2605. if (result === 'Success') {
  2606. if (data?.status === 200 && data.response?.[0]?.data?.currentUser) {
  2607. await this.#integrity(isFirst);
  2608. logStatus.success();
  2609. return true;
  2610. }
  2611. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2612. return false;
  2613. }
  2614. logStatus.error(`${result}:${statusText}(${status})`);
  2615. return false;
  2616. } catch (error) {
  2617. throwError(error, 'Twitch.verifyAuth');
  2618. return false;
  2619. }
  2620. }
  2621. async #integrity(isFirst = true, ct = '') {
  2622. try {
  2623. const logStatus = scripts_echoLog({
  2624. text: i18n('checkingTwitchIntegrity')
  2625. });
  2626. if (isFirst && (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId)) {
  2627. return await this.#updateAuth(false);
  2628. }
  2629. const {
  2630. result,
  2631. statusText,
  2632. status,
  2633. data
  2634. } = await tools_httpRequest({
  2635. url: 'https://gql.twitch.tv/integrity',
  2636. method: 'POST',
  2637. dataType: 'json',
  2638. anonymous: true,
  2639. headers: {
  2640. Origin: 'https://www.twitch.tv',
  2641. Referer: 'https://www.twitch.tv/',
  2642. Authorization: `OAuth ${this.#auth.authToken}`,
  2643. 'Client-Id': this.#auth.clientId,
  2644. 'Client-Version': this.#auth.clientVersion,
  2645. 'X-Device-Id': this.#auth.deviceId,
  2646. 'Client-Session-Id': this.#auth.clientSessionId,
  2647. 'x-kpsdk-ct': ct
  2648. }
  2649. });
  2650. if (result === 'Success') {
  2651. if (!ct && data?.responseHeaders?.['x-kpsdk-ct']) {
  2652. return await this.#integrity(isFirst, data.responseHeaders['x-kpsdk-ct']);
  2653. }
  2654. if (data?.status === 200 && data.response?.token) {
  2655. this.#integrityToken = data.response.token;
  2656. logStatus.success();
  2657. return true;
  2658. }
  2659. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2660. return false;
  2661. }
  2662. logStatus.error(`${result}:${statusText}(${status})`);
  2663. return false;
  2664. } catch (error) {
  2665. throwError(error, 'Twitch.integrity');
  2666. return false;
  2667. }
  2668. }
  2669. async #updateAuth(isFirst = true) {
  2670. try {
  2671. const logStatus = scripts_echoLog({
  2672. text: i18n('updatingAuth', 'Twitch')
  2673. });
  2674. return await new Promise(resolve => {
  2675. const newTab = GM_openInTab('https://www.twitch.tv/#auth', {
  2676. active: true,
  2677. insert: true,
  2678. setParent: true
  2679. });
  2680. newTab.onclose = async () => {
  2681. const auth = GM_getValue('twitchAuth');
  2682. if (auth) {
  2683. this.#auth = auth;
  2684. logStatus.success();
  2685. resolve(await this.#verifyAuth(isFirst));
  2686. } else {
  2687. logStatus.error('Error: Update twitch auth failed!');
  2688. resolve(false);
  2689. }
  2690. };
  2691. });
  2692. } catch (error) {
  2693. throwError(error, 'Twitch.updateAuth');
  2694. return false;
  2695. }
  2696. }
  2697. async #toggleChannel({
  2698. name,
  2699. doTask = true
  2700. }) {
  2701. try {
  2702. if (!doTask && this.whiteList.channels.includes(name)) {
  2703. scripts_echoLog({
  2704. type: 'whiteList',
  2705. text: 'Twitch.unfollowChannel',
  2706. id: name
  2707. });
  2708. return true;
  2709. }
  2710. const channelId = await this.#getChannelId(name);
  2711. if (!channelId) {
  2712. return false;
  2713. }
  2714. const logStatus = scripts_echoLog({
  2715. type: `${doTask ? '' : 'un'}followingTwitchChannel`,
  2716. text: name
  2717. });
  2718. const followData = `[{"operationName":"FollowButton_FollowUser","variables":{"input":{"disableNotifications":false,"targetID":"${channelId}` + '"}},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"800e7346bdf7e5278a3c1d3f21b2b56e2639928f86815677a7126b093b2fdd08"}}}]';
  2719. const unfollowData = `[{"operationName":"FollowButton_UnfollowUser","variables":{"input":{"targetID":"${channelId}"}},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"f7dae976ebf41c755ae2d758546bfd176b4eeb856656098bb40e0a672ca0d880"}}}]';
  2720. const {
  2721. result,
  2722. statusText,
  2723. status,
  2724. data
  2725. } = await tools_httpRequest({
  2726. url: 'https://gql.twitch.tv/gql',
  2727. method: 'POST',
  2728. dataType: 'json',
  2729. anonymous: true,
  2730. headers: {
  2731. Origin: 'https://www.twitch.tv',
  2732. Referer: 'https://www.twitch.tv/',
  2733. Authorization: `OAuth ${this.#auth.authToken}`,
  2734. 'Client-Id': this.#auth.clientId,
  2735. 'Client-Version': this.#auth.clientVersion,
  2736. 'X-Device-Id': this.#auth.deviceId,
  2737. 'Client-Session-Id': this.#auth.clientSessionId,
  2738. 'Client-Integrity': this.#integrityToken
  2739. },
  2740. data: doTask ? followData : unfollowData
  2741. });
  2742. if (result === 'Success') {
  2743. if (data?.status === 200 && data.response?.[0] && !data.response[0].errors) {
  2744. logStatus.success();
  2745. if (doTask) {
  2746. this.tasks.channels = unique([ ...this.tasks.channels, name ]);
  2747. }
  2748. return true;
  2749. }
  2750. logStatus.error(`Error:${data?.response?.[0].errors?.[0]?.message || `${data?.statusText}(${data?.status})`}`);
  2751. return false;
  2752. }
  2753. logStatus.error(`${result}:${statusText}(${status})`);
  2754. return false;
  2755. } catch (error) {
  2756. throwError(error, 'Twitch.toggleChannel');
  2757. return false;
  2758. }
  2759. }
  2760. async #getChannelId(name) {
  2761. try {
  2762. const logStatus = scripts_echoLog({
  2763. type: 'gettingTwitchChannelId',
  2764. text: name
  2765. });
  2766. const channelId = this.#cache[name];
  2767. if (channelId) {
  2768. logStatus.success();
  2769. return channelId;
  2770. }
  2771. const {
  2772. result,
  2773. statusText,
  2774. status,
  2775. data
  2776. } = await tools_httpRequest({
  2777. url: 'https://gql.twitch.tv/gql',
  2778. method: 'POST',
  2779. headers: {
  2780. Authorization: `OAuth ${this.#auth.authToken}`,
  2781. 'Client-Id': this.#auth.clientId
  2782. },
  2783. responseType: 'json',
  2784. data: `[{"operationName":"ActiveWatchParty","variables":{"channelLogin":"${name}"},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"4a8156c97b19e3a36e081cf6d6ddb5dbf9f9b02ae60e4d2ff26ed70aebc80a30"}}}]'
  2785. });
  2786. if (result === 'Success') {
  2787. if (data?.status === 200) {
  2788. const channelId = data.response?.[0]?.data?.user?.id;
  2789. if (channelId) {
  2790. this.#setCache(name, String(channelId));
  2791. logStatus.success();
  2792. return channelId;
  2793. }
  2794. logStatus.error(`Error:${data.statusText}(${data.status})`);
  2795. return false;
  2796. }
  2797. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2798. return false;
  2799. }
  2800. logStatus.error(`${result}:${statusText}(${status})`);
  2801. return false;
  2802. } catch (error) {
  2803. throwError(error, 'Twitch.getChannelId');
  2804. return false;
  2805. }
  2806. }
  2807. async toggle({
  2808. doTask = true,
  2809. channelLinks = []
  2810. }) {
  2811. try {
  2812. if (!this.#initialized) {
  2813. scripts_echoLog({
  2814. text: i18n('needInit')
  2815. });
  2816. return false;
  2817. }
  2818. const prom = [];
  2819. if (doTask && !globalOptions.doTask.twitch.channels || !doTask && !globalOptions.undoTask.twitch.channels) {
  2820. scripts_echoLog({
  2821. type: 'globalOptionsSkip',
  2822. text: 'twitch.channels'
  2823. });
  2824. } else {
  2825. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2]);
  2826. if (realChannels.length > 0) {
  2827. for (const channel of realChannels) {
  2828. prom.push(this.#toggleChannel({
  2829. name: channel,
  2830. doTask: doTask
  2831. }));
  2832. await delay(1e3);
  2833. }
  2834. }
  2835. }
  2836. return Promise.all(prom).then(() => true);
  2837. } catch (error) {
  2838. throwError(error, 'Twitch.toggle');
  2839. return false;
  2840. }
  2841. }
  2842. #setCache(name, id) {
  2843. try {
  2844. this.#cache[name] = id;
  2845. GM_setValue('twitchCache', this.#cache);
  2846. } catch (error) {
  2847. throwError(error, 'Twitch.setCache');
  2848. }
  2849. }
  2850. }
  2851. const social_Twitch = Twitch;
  2852. class Twitter extends social_Social {
  2853. tasks;
  2854. whiteList;
  2855. #verifyId = globalOptions.other.twitterVerifyId;
  2856. #auth = GM_getValue('twitterAuth') || {};
  2857. #cache = GM_getValue('twitterCache') || {};
  2858. #initialized = false;
  2859. constructor() {
  2860. super();
  2861. const defaultTasksTemplate = {
  2862. users: [],
  2863. retweets: [],
  2864. likes: []
  2865. };
  2866. this.tasks = defaultTasksTemplate;
  2867. this.whiteList = {
  2868. ...defaultTasksTemplate,
  2869. ...GM_getValue('whiteList')?.twitter || {}
  2870. };
  2871. }
  2872. async init() {
  2873. try {
  2874. if (this.#initialized) {
  2875. return true;
  2876. }
  2877. if (!this.#auth.ct0) {
  2878. if (await this.#updateAuth()) {
  2879. this.#initialized = true;
  2880. return true;
  2881. }
  2882. return false;
  2883. }
  2884. const isVerified = await this.#verifyAuth();
  2885. if (isVerified) {
  2886. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2887. this.#initialized = true;
  2888. return true;
  2889. }
  2890. GM_setValue('twitterAuth', null);
  2891. if (await this.#updateAuth()) {
  2892. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2893. this.#initialized = true;
  2894. return true;
  2895. }
  2896. scripts_echoLog({}).error(i18n('initFailed', 'Twitter'));
  2897. return false;
  2898. } catch (error) {
  2899. throwError(error, 'Twitter.init');
  2900. return false;
  2901. }
  2902. }
  2903. async #verifyAuth() {
  2904. try {
  2905. return await this.#toggleUser({
  2906. name: 'verify',
  2907. doTask: true,
  2908. verify: true
  2909. });
  2910. } catch (error) {
  2911. throwError(error, 'Twitter.verifyAuth');
  2912. return false;
  2913. }
  2914. }
  2915. async #updateAuth() {
  2916. try {
  2917. const logStatus = scripts_echoLog({
  2918. text: i18n('updatingAuth', 'Twitter')
  2919. });
  2920. return await new Promise(resolve => {
  2921. GM_cookie.list({
  2922. url: 'https://x.com/settings/account'
  2923. }, async (cookies, error) => {
  2924. if (!error) {
  2925. const [ ct0, isLogin ] = cookies.map(cookie => [ 'ct0', 'twid' ].includes(cookie.name) ? cookie.value : null).filter(cookie => cookie);
  2926. if (isLogin && ct0) {
  2927. GM_setValue('twitterAuth', {
  2928. ct0: ct0
  2929. });
  2930. this.#auth = {
  2931. ct0: ct0
  2932. };
  2933. logStatus.success();
  2934. resolve(await this.#verifyAuth());
  2935. } else {
  2936. logStatus.error(i18n('needLogin'));
  2937. resolve(false);
  2938. }
  2939. } else {
  2940. logStatus.error('Error: Update twitter auth failed!');
  2941. resolve(false);
  2942. }
  2943. });
  2944. });
  2945. } catch (error) {
  2946. throwError(error, 'Twitter.updateToken');
  2947. return false;
  2948. }
  2949. }
  2950. async #toggleUser({
  2951. name,
  2952. doTask = true,
  2953. verify = false
  2954. }) {
  2955. try {
  2956. if (!doTask && !verify && this.whiteList.users.includes(name)) {
  2957. scripts_echoLog({
  2958. type: 'whiteList',
  2959. text: 'Twitter.unfollowUser',
  2960. id: name
  2961. });
  2962. return true;
  2963. }
  2964. const userId = verify ? this.#verifyId : await this.userName2id(name);
  2965. if (!userId) {
  2966. return false;
  2967. }
  2968. const logStatus = verify ? scripts_echoLog({
  2969. text: i18n('verifyingAuth', 'Twitter')
  2970. }) : scripts_echoLog({
  2971. type: `${doTask ? '' : 'un'}followingTwitterUser`,
  2972. text: name
  2973. });
  2974. const {
  2975. result,
  2976. statusText,
  2977. status,
  2978. data
  2979. } = await tools_httpRequest({
  2980. url: `https://x.com/i/api/1.1/friendships/${doTask ? 'create' : 'destroy'}.json`,
  2981. method: 'POST',
  2982. headers: {
  2983. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  2984. 'Content-Type': 'application/x-www-form-urlencoded',
  2985. 'x-csrf-token': this.#auth.ct0
  2986. },
  2987. responseType: 'json',
  2988. data: $.param({
  2989. include_profile_interstitial_type: 1,
  2990. include_blocking: 1,
  2991. include_blocked_by: 1,
  2992. include_followed_by: 1,
  2993. include_want_retweets: 1,
  2994. include_mute_edge: 1,
  2995. include_can_dm: 1,
  2996. include_can_media_tag: 1,
  2997. skip_status: 1,
  2998. id: userId
  2999. })
  3000. });
  3001. if (result === 'Success') {
  3002. if (data?.status === 200) {
  3003. logStatus.success();
  3004. if (doTask && !verify) {
  3005. this.tasks.users = unique([ ...this.tasks.users, name ]);
  3006. }
  3007. return true;
  3008. }
  3009. if (verify && data?.status === 403 && data.response?.errors?.[0]?.code === 158) {
  3010. logStatus.success();
  3011. return true;
  3012. }
  3013. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3014. return false;
  3015. }
  3016. logStatus.error(`${result}:${statusText}(${status})`);
  3017. return false;
  3018. } catch (error) {
  3019. throwError(error, 'Twitter.toggleUser');
  3020. return false;
  3021. }
  3022. }
  3023. async userName2id(name) {
  3024. try {
  3025. const logStatus = scripts_echoLog({
  3026. type: 'gettingTwitterUserId',
  3027. text: name
  3028. });
  3029. const userId = this.#cache[name];
  3030. if (userId) {
  3031. logStatus.success();
  3032. return userId;
  3033. }
  3034. const {
  3035. result,
  3036. statusText,
  3037. status,
  3038. data
  3039. } = await tools_httpRequest({
  3040. 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`,
  3041. method: 'GET',
  3042. headers: {
  3043. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3044. 'content-type': 'application/json',
  3045. referer: `https://x.com/${name}`,
  3046. 'x-csrf-token': this.#auth.ct0
  3047. },
  3048. responseType: 'json'
  3049. });
  3050. if (result === 'Success') {
  3051. if (data?.status === 200) {
  3052. let response = data.response || (typeof data.responseText === 'object' ? data.responseText : null);
  3053. if (!response) {
  3054. try {
  3055. response = JSON.parse(data.responseText);
  3056. } catch (error) {
  3057. response = null;
  3058. }
  3059. }
  3060. const userId = String(response?.data?.user?.result?.rest_id);
  3061. if (userId) {
  3062. this.#setCache(name, userId);
  3063. logStatus.success();
  3064. return userId;
  3065. }
  3066. logStatus.error(`Error:${data.statusText}(${data.status})`);
  3067. return false;
  3068. }
  3069. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3070. return false;
  3071. }
  3072. logStatus.error(`${result}:${statusText}(${status})`);
  3073. return false;
  3074. } catch (error) {
  3075. throwError(error, 'Twitter.getUserId');
  3076. return false;
  3077. }
  3078. }
  3079. async #toggleRetweet({
  3080. retweetId,
  3081. doTask = true
  3082. }) {
  3083. try {
  3084. if (!doTask && this.whiteList.retweets.includes(retweetId)) {
  3085. scripts_echoLog({
  3086. type: 'whiteList',
  3087. text: 'Twitter.unretweet',
  3088. id: retweetId
  3089. });
  3090. return true;
  3091. }
  3092. const logStatus = scripts_echoLog({
  3093. type: `${doTask ? '' : 'un'}retweetting`,
  3094. text: retweetId
  3095. });
  3096. const {
  3097. result,
  3098. statusText,
  3099. status,
  3100. data
  3101. } = await tools_httpRequest({
  3102. url: `https://x.com/i/api/graphql/${doTask ? 'ojPdsZsimiJrUGLR1sjUtA/CreateRetweet' : 'iQtK4dl5hBmXewYZuEOKVw/DeleteRetweet'}`,
  3103. method: 'POST',
  3104. headers: {
  3105. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3106. 'Content-Type': 'application/json',
  3107. 'x-csrf-token': this.#auth.ct0
  3108. },
  3109. data: `{"variables":{"tweet_id":"${retweetId}","dark_request":false},"queryId":"${doTask ? 'ojPdsZsimiJrUGLR1sjUtA' : 'iQtK4dl5hBmXewYZuEOKVw'}"}`,
  3110. responseType: 'json'
  3111. });
  3112. if (result === 'Success') {
  3113. if (data?.status === 200 || data?.status === 403 && data.response?.errors?.[0]?.code === 327) {
  3114. logStatus.success();
  3115. if (doTask) {
  3116. this.tasks.retweets = unique([ ...this.tasks.retweets, retweetId ]);
  3117. }
  3118. return true;
  3119. }
  3120. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3121. return false;
  3122. }
  3123. logStatus.error(`${result}:${statusText}(${status})`);
  3124. return false;
  3125. } catch (error) {
  3126. throwError(error, 'Twitter.toggleRetweet');
  3127. return false;
  3128. }
  3129. }
  3130. async toggle({
  3131. doTask = true,
  3132. userLinks = [],
  3133. retweetLinks = []
  3134. }) {
  3135. try {
  3136. if (!this.#initialized) {
  3137. scripts_echoLog({
  3138. text: i18n('needInit')
  3139. });
  3140. return false;
  3141. }
  3142. const prom = [];
  3143. if (doTask && !globalOptions.doTask.twitter.users || !doTask && !globalOptions.undoTask.twitter.users) {
  3144. scripts_echoLog({
  3145. type: 'globalOptionsSkip',
  3146. text: 'twitter.users'
  3147. });
  3148. } else {
  3149. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/x\.com\/(.+)/)?.[1] || link.match(/https:\/\/twitter\.com\/(.+)/)?.[1]);
  3150. if (realUsers.length > 0) {
  3151. for (const user of realUsers) {
  3152. prom.push(this.#toggleUser({
  3153. name: user,
  3154. doTask: doTask
  3155. }));
  3156. await delay(1e3);
  3157. }
  3158. }
  3159. }
  3160. if (doTask && !globalOptions.doTask.twitter.retweets || !doTask && !globalOptions.undoTask.twitter.retweets) {
  3161. scripts_echoLog({
  3162. type: 'globalOptionsSkip',
  3163. text: 'twitter.retweets'
  3164. });
  3165. } else {
  3166. const realRetweets = this.getRealParams('retweets', retweetLinks, doTask, link => link.match(/https:\/\/x\.com\/.*?\/status\/([\d]+)/)?.[1] || link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1]);
  3167. if (realRetweets.length > 0) {
  3168. for (const retweet of realRetweets) {
  3169. prom.push(this.#toggleRetweet({
  3170. retweetId: retweet,
  3171. doTask: doTask
  3172. }));
  3173. await delay(1e3);
  3174. }
  3175. }
  3176. }
  3177. return Promise.all(prom).then(() => true);
  3178. } catch (error) {
  3179. throwError(error, 'Twitter.toggle');
  3180. return false;
  3181. }
  3182. }
  3183. #setCache(name, id) {
  3184. try {
  3185. this.#cache[name] = id;
  3186. GM_setValue('twitterCache', this.#cache);
  3187. } catch (error) {
  3188. throwError(error, 'Twitter.setCache');
  3189. }
  3190. }
  3191. }
  3192. const social_Twitter = Twitter;
  3193. class Vk extends social_Social {
  3194. tasks;
  3195. whiteList;
  3196. #username = '';
  3197. #cache = GM_getValue('vkCache') || {};
  3198. #initialized = false;
  3199. constructor() {
  3200. super();
  3201. const defaultTasksTemplate = {
  3202. names: []
  3203. };
  3204. this.tasks = defaultTasksTemplate;
  3205. this.whiteList = {
  3206. ...defaultTasksTemplate,
  3207. ...GM_getValue('whiteList')?.vk || {}
  3208. };
  3209. }
  3210. async init() {
  3211. try {
  3212. if (this.#initialized) {
  3213. return true;
  3214. }
  3215. const isVerified = await this.#verifyAuth();
  3216. if (isVerified) {
  3217. scripts_echoLog({}).success(i18n('initSuccess', 'Vk'));
  3218. this.#initialized = true;
  3219. return true;
  3220. }
  3221. scripts_echoLog({}).error(i18n('initFailed', 'Vk'));
  3222. return false;
  3223. } catch (error) {
  3224. throwError(error, 'Vk.init');
  3225. return false;
  3226. }
  3227. }
  3228. async #verifyAuth() {
  3229. try {
  3230. const logStatus = scripts_echoLog({
  3231. text: i18n('verifyAuth', 'Vk')
  3232. });
  3233. const {
  3234. result,
  3235. statusText,
  3236. status,
  3237. data
  3238. } = await tools_httpRequest({
  3239. url: 'https://vk.com/im',
  3240. method: 'GET'
  3241. });
  3242. if (result === 'Success') {
  3243. if (data?.finalUrl.includes('vk.com/login')) {
  3244. logStatus.error(`Error:${i18n('loginVk')}`, true);
  3245. return false;
  3246. }
  3247. if (data?.status === 200) {
  3248. this.#username = data.responseText.match(/TopNavBtn__profileLink" href="\/(.*?)"/)?.[1] || '';
  3249. logStatus.success();
  3250. return true;
  3251. }
  3252. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3253. return false;
  3254. }
  3255. logStatus.error(`${result}:${statusText}(${status})`);
  3256. return false;
  3257. } catch (error) {
  3258. throwError(error, 'Vk.verifyAuth');
  3259. return false;
  3260. }
  3261. }
  3262. async #toggleGroup(name, dataParam, doTask = true) {
  3263. try {
  3264. const logStatus = scripts_echoLog({
  3265. type: doTask ? 'joiningVkGroup' : 'leavingVkGroup',
  3266. text: name
  3267. });
  3268. if (dataParam.groupAct === 'enter' && !doTask || dataParam.groupAct === 'leave' && doTask) {
  3269. logStatus.success();
  3270. return true;
  3271. }
  3272. const reqData = {
  3273. act: doTask ? 'enter' : 'leave',
  3274. al: 1,
  3275. gid: dataParam.groupId,
  3276. hash: dataParam.groupHash
  3277. };
  3278. if (doTask) {
  3279. reqData.context = '_';
  3280. }
  3281. const {
  3282. result,
  3283. statusText,
  3284. status,
  3285. data
  3286. } = await tools_httpRequest({
  3287. url: 'https://vk.com/al_groups.php',
  3288. method: 'POST',
  3289. headers: {
  3290. origin: 'https://vk.com',
  3291. referer: `https://vk.com/${name}`,
  3292. 'content-type': 'application/x-www-form-urlencoded'
  3293. },
  3294. data: $.param(reqData)
  3295. });
  3296. if (result === 'Success') {
  3297. if (data?.status === 200) {
  3298. logStatus.success();
  3299. if (doTask) {
  3300. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3301. }
  3302. return true;
  3303. }
  3304. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3305. return false;
  3306. }
  3307. logStatus.error(`${result}:${statusText}(${status})`);
  3308. return false;
  3309. } catch (error) {
  3310. throwError(error, 'Vk.toggleGroup');
  3311. return false;
  3312. }
  3313. }
  3314. async #togglePublic(name, dataParam, doTask = true) {
  3315. try {
  3316. const logStatus = scripts_echoLog({
  3317. type: doTask ? 'joiningVkPublic' : 'leavingVkPublic',
  3318. text: name
  3319. });
  3320. if (dataParam.publicJoined && doTask || !dataParam.publicJoined && !doTask) {
  3321. logStatus.success();
  3322. return true;
  3323. }
  3324. const {
  3325. result,
  3326. statusText,
  3327. status,
  3328. data
  3329. } = await tools_httpRequest({
  3330. url: 'https://vk.com/al_public.php',
  3331. method: 'POST',
  3332. headers: {
  3333. origin: 'https://vk.com',
  3334. referer: `https://vk.com/${name}`,
  3335. 'content-type': 'application/x-www-form-urlencoded'
  3336. },
  3337. data: $.param({
  3338. act: doTask ? 'a_enter' : 'a_leave',
  3339. al: 1,
  3340. pid: dataParam.publicPid,
  3341. hash: dataParam.publicHash
  3342. })
  3343. });
  3344. if (result === 'Success') {
  3345. if (data?.status === 200) {
  3346. logStatus.success();
  3347. if (doTask) {
  3348. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3349. }
  3350. return true;
  3351. }
  3352. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3353. return false;
  3354. }
  3355. logStatus.error(`${result}:${statusText}(${status})`);
  3356. return false;
  3357. } catch (error) {
  3358. throwError(error, 'Vk.togglePublic');
  3359. return false;
  3360. }
  3361. }
  3362. async #sendWall(name) {
  3363. try {
  3364. const logStatus = scripts_echoLog({
  3365. type: 'sendingVkWall',
  3366. text: name
  3367. });
  3368. const {
  3369. result,
  3370. statusText,
  3371. status,
  3372. data
  3373. } = await tools_httpRequest({
  3374. url: 'https://vk.com/like.php',
  3375. method: 'POST',
  3376. headers: {
  3377. origin: 'https://vk.com',
  3378. referer: `https://vk.com/${name}`,
  3379. 'content-type': 'application/x-www-form-urlencoded'
  3380. },
  3381. data: $.param({
  3382. act: 'publish_box',
  3383. al: 1,
  3384. object: name
  3385. })
  3386. });
  3387. if (result === 'Success') {
  3388. if (data?.status === 200) {
  3389. const hash = data.responseText.match(/shHash:[\s]*'(.*?)'/)?.[1];
  3390. if (hash) {
  3391. const {
  3392. result: resultR,
  3393. statusText: statusTextR,
  3394. status: statusR,
  3395. data: dataR
  3396. } = await tools_httpRequest({
  3397. url: 'https://vk.com/like.php',
  3398. method: 'POST',
  3399. headers: {
  3400. origin: 'https://vk.com',
  3401. referer: `https://vk.com/${name}`,
  3402. 'content-type': 'application/x-www-form-urlencoded'
  3403. },
  3404. data: $.param({
  3405. Message: '',
  3406. act: 'a_do_publish',
  3407. al: 1,
  3408. close_comments: 0,
  3409. friends_only: 0,
  3410. from: 'box',
  3411. hash: hash,
  3412. list: '',
  3413. mark_as_ads: 0,
  3414. mute_notifications: 0,
  3415. object: name,
  3416. ret_data: 1,
  3417. to: 0
  3418. })
  3419. });
  3420. if (resultR === 'Success') {
  3421. if (dataR?.status === 200) {
  3422. const jsonData = JSON.parse(dataR.responseText?.replace('\x3c!--', '') || '{}');
  3423. if (jsonData?.payload?.[1]?.[1]?.share_my === true) {
  3424. logStatus.success();
  3425. const postId = String(jsonData?.payload?.[1]?.[1]?.post_id);
  3426. const ownerId = String(jsonData?.payload?.[1]?.[1]?.owner_id);
  3427. if (postId && ownerId) {
  3428. this.#setCache(name, `${ownerId}_${postId}`);
  3429. }
  3430. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3431. return true;
  3432. }
  3433. }
  3434. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  3435. return false;
  3436. }
  3437. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  3438. return false;
  3439. }
  3440. logStatus.error('Error: Get "hash" failed');
  3441. return false;
  3442. }
  3443. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3444. return false;
  3445. }
  3446. logStatus.error(`${result}:${statusText}(${status})`);
  3447. return false;
  3448. } catch (error) {
  3449. throwError(error, 'Vk.sendWall');
  3450. return false;
  3451. }
  3452. }
  3453. async #deleteWall(name, dataParams) {
  3454. try {
  3455. const logStatus = scripts_echoLog({
  3456. type: 'deletingVkWall',
  3457. text: name
  3458. });
  3459. const {
  3460. result,
  3461. statusText,
  3462. status,
  3463. data
  3464. } = await tools_httpRequest({
  3465. url: 'https://vk.com/al_wall.php?act=delete',
  3466. method: 'POST',
  3467. headers: {
  3468. origin: 'https://vk.com',
  3469. referer: `https://vk.com/${this.#username}?w=wall${this.#cache[name]}%2Fall`,
  3470. 'content-type': 'application/x-www-form-urlencoded'
  3471. },
  3472. data: $.param({
  3473. act: 'delete',
  3474. al: 1,
  3475. confirm: 0,
  3476. from: 'wkview',
  3477. hash: dataParams.wallHash,
  3478. post: this.#cache[name]
  3479. })
  3480. });
  3481. if (result === 'Success') {
  3482. if (data?.status === 200) {
  3483. const jsonData = JSON.parse(data.responseText?.replace('\x3c!--', '') || '{}');
  3484. if (jsonData?.payload?.[1]?.[1]) {
  3485. logStatus.success();
  3486. return true;
  3487. }
  3488. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3489. return false;
  3490. }
  3491. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3492. return false;
  3493. }
  3494. logStatus.error(`${result}:${statusText}(${status})`);
  3495. return false;
  3496. } catch (error) {
  3497. throwError(error, 'Vk.deleteWall');
  3498. return false;
  3499. }
  3500. }
  3501. async #getId(name, doTask) {
  3502. try {
  3503. let url = `https://vk.com/${name}`;
  3504. if (/^wall-/.test(name)) {
  3505. if (doTask) {
  3506. return {
  3507. type: 'sendWall'
  3508. };
  3509. }
  3510. if (!this.#cache[name]) {
  3511. return {
  3512. type: 'unSupport'
  3513. };
  3514. }
  3515. url = `https://vk.com/${this.#username}?w=wall${this.#cache[name]}`;
  3516. }
  3517. const logStatus = scripts_echoLog({
  3518. type: 'gettingVkId',
  3519. text: name
  3520. });
  3521. const {
  3522. result,
  3523. statusText,
  3524. status,
  3525. data
  3526. } = await tools_httpRequest({
  3527. url: url,
  3528. method: 'GET'
  3529. });
  3530. if (result === 'Success') {
  3531. if (data?.status === 200) {
  3532. const [ , groupAct, groupId, , groupHash ] = data.responseText.match(/Groups.(enter|leave)\(.*?,.*?([\d]+?), (&#39;|')(.*?)(&#39;|')/) || [];
  3533. const publicHash = data.responseText.match(/"enterHash":"(.*?)"/)?.[1];
  3534. const publicPid = data.responseText.match(/"public_id":([\d]+?),/)?.[1];
  3535. const publicJoined = !data.responseText.includes('Public.subscribe');
  3536. if (groupAct && groupId && groupHash) {
  3537. logStatus.success();
  3538. return {
  3539. groupAct: groupAct,
  3540. groupId: groupId,
  3541. groupHash: groupHash,
  3542. type: 'group'
  3543. };
  3544. } else if (publicHash && publicPid) {
  3545. logStatus.success();
  3546. return {
  3547. publicHash: publicHash,
  3548. publicPid: publicPid,
  3549. publicJoined: publicJoined,
  3550. type: 'public'
  3551. };
  3552. } else if (data.responseText.includes('wall.deletePost') && !doTask) {
  3553. const wallHash = data.responseText.match(/wall\.deletePost\(this, '.*?', '(.*?)'\)/)?.[1];
  3554. if (wallHash) {
  3555. logStatus.success();
  3556. return {
  3557. type: 'deleteWall',
  3558. wallHash: wallHash
  3559. };
  3560. }
  3561. } else if (name.includes('wall') && doTask) {
  3562. logStatus.success();
  3563. return {
  3564. type: 'sendWall'
  3565. };
  3566. }
  3567. logStatus.error('Error: Parameters not found!');
  3568. return false;
  3569. }
  3570. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3571. return false;
  3572. }
  3573. logStatus.error(`${result}:${statusText}(${status})`);
  3574. return false;
  3575. } catch (error) {
  3576. throwError(error, 'Vk.getId');
  3577. return false;
  3578. }
  3579. }
  3580. async #toggleVk({
  3581. name,
  3582. doTask = true
  3583. }) {
  3584. try {
  3585. if (!doTask && this.whiteList.names.includes(name)) {
  3586. scripts_echoLog({
  3587. type: 'whiteList',
  3588. text: 'Vk.undoTask',
  3589. id: name
  3590. });
  3591. return true;
  3592. }
  3593. const formatName = name.replace(/\/$/, '');
  3594. const data = await this.#getId(formatName, doTask);
  3595. if (!data) {
  3596. return false;
  3597. }
  3598. switch (data.type) {
  3599. case 'group':
  3600. return await this.#toggleGroup(formatName, data, doTask);
  3601.  
  3602. case 'public':
  3603. return await this.#togglePublic(formatName, data, doTask);
  3604.  
  3605. case 'sendWall':
  3606. return doTask ? await this.#sendWall(formatName) : true;
  3607.  
  3608. case 'deleteWall':
  3609. return doTask ? true : await this.#deleteWall(formatName, data);
  3610.  
  3611. default:
  3612. return false;
  3613. }
  3614. } catch (error) {
  3615. throwError(error, 'Vk.toggleVk');
  3616. return false;
  3617. }
  3618. }
  3619. async toggle({
  3620. doTask = true,
  3621. nameLinks = []
  3622. }) {
  3623. try {
  3624. if (!this.#initialized) {
  3625. scripts_echoLog({
  3626. text: i18n('needInit')
  3627. });
  3628. return false;
  3629. }
  3630. const prom = [];
  3631. if (doTask && !globalOptions.doTask.vk.names || !doTask && !globalOptions.undoTask.vk.names) {
  3632. scripts_echoLog({
  3633. type: 'globalOptionsSkip',
  3634. text: 'vk.names'
  3635. });
  3636. } else {
  3637. const realNames = this.getRealParams('names', nameLinks, doTask, link => link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1]);
  3638. if (realNames.length > 0) {
  3639. for (const name of realNames) {
  3640. prom.push(this.#toggleVk({
  3641. name: name,
  3642. doTask: doTask
  3643. }));
  3644. await delay(1e3);
  3645. }
  3646. }
  3647. }
  3648. return Promise.all(prom).then(() => true);
  3649. } catch (error) {
  3650. throwError(error, 'Vk.toggle');
  3651. return false;
  3652. }
  3653. }
  3654. #setCache(name, postId) {
  3655. try {
  3656. this.#cache[name] = postId;
  3657. GM_setValue('vkCache', this.#cache);
  3658. } catch (error) {
  3659. throwError(error, 'Vk.setCache');
  3660. }
  3661. }
  3662. }
  3663. const social_Vk = Vk;
  3664. const getInfo = async function(link, type) {
  3665. try {
  3666. const logStatus = scripts_echoLog({
  3667. text: i18n('gettingYtbToken')
  3668. });
  3669. const {
  3670. result,
  3671. statusText,
  3672. status,
  3673. data
  3674. } = await tools_httpRequest({
  3675. url: link,
  3676. method: 'GET'
  3677. });
  3678. if (result === 'Success') {
  3679. if (data?.status === 200) {
  3680. if (data.responseText.includes('accounts.google.com/ServiceLogin?service=youtube')) {
  3681. logStatus.error(`Error:${i18n('loginYtb')}`, true);
  3682. return {
  3683. needLogin: true
  3684. };
  3685. }
  3686. const apiKey = data.responseText.match(/"INNERTUBE_API_KEY":"(.*?)"/)?.[1];
  3687. const context = (data.responseText.match(/\(\{"INNERTUBE_CONTEXT":([\w\W]*?)\}\)/) || data.responseText.match(/"INNERTUBE_CONTEXT":([\w\W]*?\}),"INNERTUBE/))?.[1] || '{}';
  3688. const {
  3689. client,
  3690. request
  3691. } = JSON.parse(context);
  3692. if (apiKey && client && request) {
  3693. client.hl = 'en';
  3694. if (type === 'channel') {
  3695. const channelId = data.responseText.match(/"channelId":"(.+?)"/)?.[1];
  3696. if (channelId) {
  3697. logStatus.success();
  3698. return {
  3699. params: {
  3700. apiKey: apiKey,
  3701. client: client,
  3702. request: request,
  3703. channelId: channelId
  3704. }
  3705. };
  3706. }
  3707. logStatus.error('Error: Get "channelId" failed!');
  3708. return {};
  3709. } else if (type === 'likeVideo') {
  3710. const videoId = data.responseText.match(/<link rel="shortlinkUrl" href="https:\/\/youtu\.be\/(.*?)">/)?.[1];
  3711. const likeParams = data.responseText.match(/"likeParams":"(.*?)"/)?.[1];
  3712. if (videoId) {
  3713. logStatus.success();
  3714. return {
  3715. params: {
  3716. apiKey: apiKey,
  3717. client: client,
  3718. request: request,
  3719. videoId: videoId,
  3720. likeParams: likeParams
  3721. }
  3722. };
  3723. }
  3724. logStatus.error('Error: Get "videoId" failed!');
  3725. return {};
  3726. }
  3727. logStatus.error('Error: Unknown type');
  3728. return {};
  3729. }
  3730. logStatus.error('Error: Parameter "apiKey" not found!');
  3731. return {};
  3732. }
  3733. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3734. return {};
  3735. }
  3736. logStatus.error(`${result}:${statusText}(${status})`);
  3737. return {};
  3738. } catch (error) {
  3739. throwError(error, 'Youtube.getInfo');
  3740. return {};
  3741. }
  3742. };
  3743. class Youtube extends social_Social {
  3744. tasks;
  3745. whiteList;
  3746. #auth = GM_getValue('youtubeAuth') || {};
  3747. #initialized = false;
  3748. #verifyChannel = `https://www.youtube.com/channel/${globalOptions.other.youtubeVerifyChannel}`;
  3749. constructor() {
  3750. super();
  3751. const defaultTasksTemplate = {
  3752. channels: [],
  3753. likes: []
  3754. };
  3755. this.tasks = defaultTasksTemplate;
  3756. this.whiteList = {
  3757. ...defaultTasksTemplate,
  3758. ...GM_getValue('whiteList')?.youtube || {}
  3759. };
  3760. }
  3761. async init() {
  3762. try {
  3763. if (this.#initialized) {
  3764. return true;
  3765. }
  3766. if (!this.#auth.PAPISID) {
  3767. if (await this.#updateAuth()) {
  3768. this.#initialized = true;
  3769. return true;
  3770. }
  3771. return false;
  3772. }
  3773. const isVerified = await this.#verifyAuth();
  3774. if (isVerified) {
  3775. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3776. this.#initialized = true;
  3777. return true;
  3778. }
  3779. GM_setValue('youtubeAuth', null);
  3780. if (await this.#updateAuth()) {
  3781. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3782. this.#initialized = true;
  3783. return true;
  3784. }
  3785. scripts_echoLog({}).error(i18n('initFailed', 'Youtube'));
  3786. return false;
  3787. } catch (error) {
  3788. throwError(error, 'Youtube.init');
  3789. return false;
  3790. }
  3791. }
  3792. async #verifyAuth() {
  3793. try {
  3794. return await this.#toggleChannel({
  3795. link: this.#verifyChannel,
  3796. doTask: true,
  3797. verify: true
  3798. });
  3799. } catch (error) {
  3800. throwError(error, 'Youtube.verifyAuth');
  3801. return false;
  3802. }
  3803. }
  3804. async #updateAuth() {
  3805. try {
  3806. const logStatus = scripts_echoLog({
  3807. text: i18n('updatingAuth', 'Youtube')
  3808. });
  3809. return await new Promise(resolve => {
  3810. GM_cookie.list({
  3811. url: 'https://www.youtube.com/@YouTube'
  3812. }, async (cookies, error) => {
  3813. if (!error) {
  3814. const PAPISID = cookies.find(cookie => cookie.name === '__Secure-3PAPISID')?.value;
  3815. if (PAPISID) {
  3816. GM_setValue('youtubeAuth', {
  3817. PAPISID: PAPISID
  3818. });
  3819. this.#auth = {
  3820. PAPISID: PAPISID
  3821. };
  3822. logStatus.success();
  3823. resolve(await this.#verifyAuth());
  3824. } else {
  3825. logStatus.error(i18n('needLogin'));
  3826. resolve(false);
  3827. }
  3828. } else {
  3829. logStatus.error('Error: Update youtube auth failed!');
  3830. resolve(false);
  3831. }
  3832. });
  3833. });
  3834. } catch (error) {
  3835. throwError(error, 'Youtube.updateAuth');
  3836. return false;
  3837. }
  3838. }
  3839. #getInfo(link, type) {
  3840. return getInfo(link, type);
  3841. }
  3842. async #toggleChannel({
  3843. link,
  3844. doTask = true,
  3845. verify = false
  3846. }) {
  3847. try {
  3848. const {
  3849. params,
  3850. needLogin
  3851. } = await this.#getInfo(link, 'channel');
  3852. const {
  3853. apiKey,
  3854. client,
  3855. request,
  3856. channelId
  3857. } = params || {};
  3858. if (needLogin) {
  3859. scripts_echoLog({
  3860. html: i18n('loginYtb')
  3861. });
  3862. return false;
  3863. }
  3864. if (!(apiKey && client && request && channelId)) {
  3865. scripts_echoLog({
  3866. text: '"getYtbToken" failed'
  3867. });
  3868. return false;
  3869. }
  3870. if (!doTask && !verify && this.whiteList.channels.includes(channelId)) {
  3871. scripts_echoLog({
  3872. type: 'whiteList',
  3873. text: 'Youtube.unfollowChannel',
  3874. id: channelId
  3875. });
  3876. return true;
  3877. }
  3878. const logStatus = verify ? scripts_echoLog({
  3879. text: i18n('verifyingAuth', 'Youtube')
  3880. }) : scripts_echoLog({
  3881. type: doTask ? 'followingYtbChannel' : 'unfollowingYtbChannel',
  3882. text: channelId
  3883. });
  3884. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3885. const {
  3886. result,
  3887. statusText,
  3888. status,
  3889. data
  3890. } = await tools_httpRequest({
  3891. url: `https://www.youtube.com/youtubei/v1/subscription/${doTask ? '' : 'un'}subscribe?key=${apiKey}&prettyPrint=false`,
  3892. method: 'POST',
  3893. headers: {
  3894. origin: 'https://www.youtube.com',
  3895. referer: `https://www.youtube.com/channel/${channelId}`,
  3896. 'content-type': 'application/json',
  3897. 'x-goog-authuser': '0',
  3898. 'x-goog-visitor-id': client?.visitorData,
  3899. 'x-origin': 'https://www.youtube.com',
  3900. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  3901. },
  3902. data: JSON.stringify({
  3903. context: {
  3904. client: client,
  3905. request: {
  3906. sessionId: request?.sessionId,
  3907. internalExperimentFlags: [],
  3908. consistencyTokenJars: []
  3909. },
  3910. user: {}
  3911. },
  3912. channelIds: [ channelId ],
  3913. params: doTask ? 'EgIIAhgA' : 'CgIIAhgA'
  3914. })
  3915. });
  3916. if (result === 'Success') {
  3917. if (data?.status === 200) {
  3918. if (doTask && (/"subscribed":true/.test(data.responseText) || data.responseText.includes('The subscription already exists')) || !doTask && /"subscribed":false/.test(data.responseText)) {
  3919. logStatus.success();
  3920. if (doTask && !verify) {
  3921. this.tasks.channels = unique([ ...this.tasks.channels, link ]);
  3922. }
  3923. return true;
  3924. }
  3925. if (verify && data.responseText.includes('You may not subscribe to yourself')) {
  3926. logStatus.success();
  3927. return true;
  3928. }
  3929. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  3930. return false;
  3931. }
  3932. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3933. return false;
  3934. }
  3935. logStatus.error(`${result}:${statusText}(${status})`);
  3936. return false;
  3937. } catch (error) {
  3938. throwError(error, 'Youtube.toggleChannel');
  3939. return false;
  3940. }
  3941. }
  3942. async #toggleLikeVideo({
  3943. link,
  3944. doTask = true
  3945. }) {
  3946. try {
  3947. const {
  3948. params,
  3949. needLogin
  3950. } = await this.#getInfo(link, 'likeVideo');
  3951. const {
  3952. apiKey,
  3953. client,
  3954. request,
  3955. videoId,
  3956. likeParams
  3957. } = params || {};
  3958. if (needLogin) {
  3959. scripts_echoLog({
  3960. html: `${i18n('loginYtb')}`
  3961. });
  3962. return false;
  3963. }
  3964. if (!(apiKey && client && request && videoId && likeParams)) {
  3965. scripts_echoLog({
  3966. text: '"getYtbToken" failed'
  3967. });
  3968. return false;
  3969. }
  3970. if (!doTask && this.whiteList.likes.includes(videoId)) {
  3971. scripts_echoLog({
  3972. type: 'whiteList',
  3973. text: 'Youtube.unlikeVideo',
  3974. id: videoId
  3975. });
  3976. return true;
  3977. }
  3978. const logStatus = scripts_echoLog({
  3979. type: doTask ? 'likingYtbVideo' : 'unlikingYtbVideo',
  3980. text: videoId
  3981. });
  3982. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3983. const likeVideoData = {
  3984. context: {
  3985. client: client,
  3986. request: {
  3987. sessionId: request.sessionId,
  3988. internalExperimentFlags: [],
  3989. consistencyTokenJars: []
  3990. },
  3991. user: {}
  3992. },
  3993. target: {
  3994. videoId: videoId
  3995. }
  3996. };
  3997. if (doTask) {
  3998. if (likeParams) {
  3999. likeVideoData.params = likeParams;
  4000. } else {
  4001. logStatus.error('Empty likeParams');
  4002. return false;
  4003. }
  4004. }
  4005. const {
  4006. result,
  4007. statusText,
  4008. status,
  4009. data
  4010. } = await tools_httpRequest({
  4011. url: `https://www.youtube.com/youtubei/v1/like/${doTask ? '' : 'remove'}like?key=${apiKey}`,
  4012. method: 'POST',
  4013. headers: {
  4014. origin: 'https://www.youtube.com',
  4015. referer: `https://www.youtube.com/watch?v=${videoId}`,
  4016. 'content-type': 'application/json',
  4017. 'x-goog-authuser': '0',
  4018. 'x-goog-visitor-id': client.visitorData,
  4019. 'x-origin': 'https://www.youtube.com',
  4020. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  4021. },
  4022. data: JSON.stringify(likeVideoData)
  4023. });
  4024. if (result === 'Success') {
  4025. if (data?.status === 200) {
  4026. if (doTask && data.responseText.includes('Added to Liked videos') || !doTask && (data.responseText.includes('Removed from Liked videos') || data.responseText.includes('Dislike removed'))) {
  4027. logStatus.success();
  4028. if (doTask) {
  4029. this.tasks.likes = unique([ ...this.tasks.likes, link ]);
  4030. }
  4031. return true;
  4032. }
  4033. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  4034. return false;
  4035. }
  4036. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4037. return false;
  4038. }
  4039. logStatus.error(`${result}:${statusText}(${status})`);
  4040. return false;
  4041. } catch (error) {
  4042. throwError(error, 'Youtube.toggleLikeVideo');
  4043. return false;
  4044. }
  4045. }
  4046. async toggle({
  4047. doTask = true,
  4048. channelLinks = [],
  4049. videoLinks = []
  4050. }) {
  4051. try {
  4052. if (!this.#initialized) {
  4053. scripts_echoLog({
  4054. text: i18n('needInit')
  4055. });
  4056. return false;
  4057. }
  4058. const prom = [];
  4059. if (doTask && !globalOptions.doTask.youtube.channels || !doTask && !globalOptions.undoTask.youtube.channels) {
  4060. scripts_echoLog({
  4061. type: 'globalOptionsSkip',
  4062. text: 'youtube.channels'
  4063. });
  4064. } else {
  4065. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => {
  4066. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4067. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4068. }
  4069. return link;
  4070. });
  4071. if (realChannels.length > 0) {
  4072. for (const channel of realChannels) {
  4073. prom.push(this.#toggleChannel({
  4074. link: channel,
  4075. doTask: doTask
  4076. }));
  4077. await delay(1e3);
  4078. }
  4079. }
  4080. }
  4081. if (doTask && !globalOptions.doTask.youtube.likes || !doTask && !globalOptions.undoTask.youtube.likes) {
  4082. scripts_echoLog({
  4083. type: 'globalOptionsSkip',
  4084. text: 'youtube.likes'
  4085. });
  4086. } else {
  4087. const realLikes = this.getRealParams('likes', videoLinks, doTask, link => {
  4088. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4089. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4090. }
  4091. return link;
  4092. });
  4093. if (realLikes.length > 0) {
  4094. for (const video of realLikes) {
  4095. prom.push(this.#toggleLikeVideo({
  4096. link: video,
  4097. doTask: doTask
  4098. }));
  4099. await delay(1e3);
  4100. }
  4101. }
  4102. }
  4103. return Promise.all(prom).then(() => true);
  4104. } catch (error) {
  4105. throwError(error, 'Youtube.toggle');
  4106. return false;
  4107. }
  4108. }
  4109. }
  4110. class SteamASF {
  4111. #asfOptions;
  4112. #botName = 'asf';
  4113. #groupInfo;
  4114. async init() {
  4115. try {
  4116. const asfCommandsUrl = new URL('/Api/Command/', globalOptions.ASF.AsfIpcUrl);
  4117. this.#asfOptions = {
  4118. url: asfCommandsUrl.href,
  4119. method: 'POST',
  4120. responseType: 'json',
  4121. headers: {
  4122. accept: 'application/json',
  4123. 'Content-Type': 'application/json',
  4124. Host: asfCommandsUrl.host,
  4125. Origin: asfCommandsUrl.origin,
  4126. Referer: asfCommandsUrl.href,
  4127. Authentication: globalOptions.ASF.AsfIpcPassword
  4128. }
  4129. };
  4130. if (globalOptions.ASF.AsfBotname) {
  4131. this.#botName = globalOptions.ASF.AsfBotname;
  4132. }
  4133. const logStatus = scripts_echoLog({
  4134. text: i18n('initingASF')
  4135. });
  4136. const {
  4137. result,
  4138. statusText,
  4139. status,
  4140. data
  4141. } = await tools_httpRequest({
  4142. ...this.#asfOptions,
  4143. data: '{"Command":"!stats"}'
  4144. });
  4145. if (result === 'Success') {
  4146. if (data?.response?.Success === true && data.response.Message === 'OK' && data.response.Result) {
  4147. logStatus.success();
  4148. return true;
  4149. }
  4150. if (data?.response?.Result || data?.response?.Message) {
  4151. logStatus.error(data?.response?.Result || data.response.Message);
  4152. return false;
  4153. }
  4154. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4155. return false;
  4156. }
  4157. logStatus.error(`${result}:${statusText}(${status})`);
  4158. return false;
  4159. } catch (error) {
  4160. throwError(error, 'SteamASF.init');
  4161. return false;
  4162. }
  4163. }
  4164. async joinGroup(groupName) {
  4165. try {
  4166. const logStatus = scripts_echoLog({
  4167. type: 'joiningSteamGroup',
  4168. text: groupName
  4169. });
  4170. const {
  4171. result,
  4172. statusText,
  4173. status,
  4174. data
  4175. } = await tools_httpRequest({
  4176. ...this.#asfOptions,
  4177. data: JSON.stringify({
  4178. Command: `!JOINGROUP ${this.#botName} ${groupName}`
  4179. })
  4180. });
  4181. if (result === 'Success') {
  4182. if (data?.status === 200 && [ '已加入', '已申请', 'Joined', 'Applied', 'Присоединился', 'costs' ].find(text => data.response?.Result?.includes(text))) {
  4183. logStatus.success();
  4184. return true;
  4185. }
  4186. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4187. return false;
  4188. }
  4189. logStatus.error(`${result}:${statusText}(${status})`);
  4190. return false;
  4191. } catch (error) {
  4192. throwError(error, 'SteamASF.joinGroup');
  4193. return false;
  4194. }
  4195. }
  4196. async leaveGroup(groupName) {
  4197. try {
  4198. if (!this.#groupInfo) {
  4199. if (!await this.#getGroupId()) {
  4200. return false;
  4201. }
  4202. }
  4203. const groupId = await this.#groupInfo[groupName];
  4204. if (!groupId) {
  4205. return false;
  4206. }
  4207. const logStatus = scripts_echoLog({
  4208. type: 'leavingSteamGroup',
  4209. text: groupName
  4210. });
  4211. const {
  4212. result,
  4213. statusText,
  4214. status,
  4215. data
  4216. } = await tools_httpRequest({
  4217. ...this.#asfOptions,
  4218. data: JSON.stringify({
  4219. Command: `!LEAVEGROUP ${this.#botName} ${groupId}`
  4220. })
  4221. });
  4222. if (result === 'Success') {
  4223. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4224. logStatus.success();
  4225. return true;
  4226. }
  4227. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4228. return false;
  4229. }
  4230. logStatus.error(`${result}:${statusText}(${status})`);
  4231. return false;
  4232. } catch (error) {
  4233. throwError(error, 'SteamASF.leaveGroup');
  4234. return false;
  4235. }
  4236. }
  4237. async #getGroupId() {
  4238. try {
  4239. const logStatus = scripts_echoLog({
  4240. type: 'gettingSteamGroupId',
  4241. text: 'All'
  4242. });
  4243. const {
  4244. result,
  4245. statusText,
  4246. status,
  4247. data
  4248. } = await tools_httpRequest({
  4249. ...this.#asfOptions,
  4250. data: JSON.stringify({
  4251. Command: `!GROUPLIST ${this.#botName}`
  4252. })
  4253. });
  4254. if (result === 'Success') {
  4255. if (data?.status === 200 && data.response?.Result?.includes('|')) {
  4256. this.#groupInfo = Object.fromEntries(data.response.Result.split('\n').map(line => {
  4257. const [ , name, id ] = line.trim().split('|');
  4258. if (name && id) {
  4259. return [ name, id ];
  4260. }
  4261. return null;
  4262. }).filter(ele => ele));
  4263. logStatus.success();
  4264. return true;
  4265. }
  4266. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4267. return false;
  4268. }
  4269. logStatus.error(`${result}:${statusText}(${status})`);
  4270. return false;
  4271. } catch (error) {
  4272. throwError(error, 'SteamASF.getGroupID');
  4273. return false;
  4274. }
  4275. }
  4276. async addToWishlist(gameId) {
  4277. try {
  4278. const logStatus = scripts_echoLog({
  4279. type: 'addingToWishlist',
  4280. text: gameId
  4281. });
  4282. const {
  4283. result,
  4284. statusText,
  4285. status,
  4286. data
  4287. } = await tools_httpRequest({
  4288. ...this.#asfOptions,
  4289. data: JSON.stringify({
  4290. Command: `!ADDWISHLIST ${this.#botName} ${gameId}`
  4291. })
  4292. });
  4293. if (result === 'Success') {
  4294. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4295. logStatus.success();
  4296. return true;
  4297. }
  4298. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4299. return false;
  4300. }
  4301. logStatus.error(`${result}:${statusText}(${status})`);
  4302. return false;
  4303. } catch (error) {
  4304. throwError(error, 'SteamASF.addToWishlist');
  4305. return false;
  4306. }
  4307. }
  4308. async removeFromWishlist(gameId) {
  4309. try {
  4310. const logStatus = scripts_echoLog({
  4311. type: 'removingFromWishlist',
  4312. text: gameId
  4313. });
  4314. const {
  4315. result,
  4316. statusText,
  4317. status,
  4318. data
  4319. } = await tools_httpRequest({
  4320. ...this.#asfOptions,
  4321. data: JSON.stringify({
  4322. Command: `!REMOVEWISHLIST ${this.#botName} ${gameId}`
  4323. })
  4324. });
  4325. if (result === 'Success') {
  4326. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4327. logStatus.success();
  4328. return true;
  4329. }
  4330. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4331. return false;
  4332. }
  4333. logStatus.error(`${result}:${statusText}(${status})`);
  4334. return false;
  4335. } catch (error) {
  4336. throwError(error, 'SteamASF.removeFromWishlist');
  4337. return false;
  4338. }
  4339. }
  4340. async toggleFollowGame(gameId, doTask) {
  4341. try {
  4342. const logStatus = scripts_echoLog({
  4343. type: `${doTask ? '' : 'un'}followingGame`,
  4344. text: gameId
  4345. });
  4346. const {
  4347. result,
  4348. statusText,
  4349. status,
  4350. data
  4351. } = await tools_httpRequest({
  4352. ...this.#asfOptions,
  4353. data: JSON.stringify({
  4354. Command: `!${doTask ? '' : 'UN'}FOLLOWGAME ${this.#botName} ${gameId}`
  4355. })
  4356. });
  4357. if (result === 'Success') {
  4358. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4359. logStatus.success();
  4360. return true;
  4361. }
  4362. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4363. return false;
  4364. }
  4365. logStatus.error(`${result}:${statusText}(${status})`);
  4366. return false;
  4367. } catch (error) {
  4368. throwError(error, 'SteamASF.toggleFollowGame');
  4369. return false;
  4370. }
  4371. }
  4372. async toggleCurator(curatorId, doTask = true) {
  4373. try {
  4374. const logStatus = scripts_echoLog({
  4375. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  4376. text: curatorId
  4377. });
  4378. const {
  4379. result,
  4380. statusText,
  4381. status,
  4382. data
  4383. } = await tools_httpRequest({
  4384. ...this.#asfOptions,
  4385. data: JSON.stringify({
  4386. Command: `!${doTask ? '' : 'UN'}FOLLOWCURATOR ${this.#botName} ${curatorId}`
  4387. })
  4388. });
  4389. if (result === 'Success') {
  4390. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4391. logStatus.success();
  4392. return true;
  4393. }
  4394. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4395. return false;
  4396. }
  4397. logStatus.error(`${result}:${statusText}(${status})`);
  4398. return false;
  4399. } catch (error) {
  4400. throwError(error, 'Steam.toggleCurator');
  4401. return false;
  4402. }
  4403. }
  4404. async addLicense(id) {
  4405. try {
  4406. const [ type, ids ] = id.split('-');
  4407. if (type === 'appid') {
  4408. const logStatus = scripts_echoLog({
  4409. type: 'addingFreeLicense',
  4410. text: ids
  4411. });
  4412. const {
  4413. result,
  4414. statusText,
  4415. status,
  4416. data
  4417. } = await tools_httpRequest({
  4418. ...this.#asfOptions,
  4419. data: JSON.stringify({
  4420. Command: `!addlicense ${this.#botName} app/${ids}`
  4421. })
  4422. });
  4423. if (result === 'Success') {
  4424. if (data?.status === 200 && [ 'AlreadyPurchased', 'OK' ].find(text => data.response?.Result?.includes(text))) {
  4425. logStatus.success();
  4426. return true;
  4427. }
  4428. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4429. return false;
  4430. }
  4431. logStatus.error(`${result}:${statusText}(${status})`);
  4432. return false;
  4433. } else if (type === 'subid') {
  4434. const idsArr = ids.split(',');
  4435. const logStatus = scripts_echoLog({
  4436. type: 'addingFreeLicenseSubid',
  4437. text: ids
  4438. });
  4439. const {
  4440. result,
  4441. statusText,
  4442. status,
  4443. data
  4444. } = await tools_httpRequest({
  4445. ...this.#asfOptions,
  4446. data: JSON.stringify({
  4447. Command: `!addlicense ${this.#botName} ${idsArr.map(id => `sub/${id}`).join(',')}`
  4448. })
  4449. });
  4450. if (result === 'Success') {
  4451. if (data?.status === 200 && data.response?.Result) {
  4452. const resultLines = data.response.Result.split('\n');
  4453. idsArr.forEach(subid => {
  4454. const targetLine = resultLines.find(text => text.includes(subid));
  4455. if (targetLine && [ '成功', 'Success', 'Успех' ].find(text => targetLine.includes(text))) {
  4456. scripts_echoLog({}).success(targetLine);
  4457. } else {
  4458. scripts_echoLog({}).error(targetLine);
  4459. }
  4460. });
  4461. return true;
  4462. }
  4463. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4464. return false;
  4465. }
  4466. logStatus.error(`${result}:${statusText}(${status})`);
  4467. return false;
  4468. }
  4469. return false;
  4470. } catch (error) {
  4471. throwError(error, 'SteamASF.addLicense');
  4472. return false;
  4473. }
  4474. }
  4475. async requestPlayTestAccess(id) {
  4476. try {
  4477. const logStatus = scripts_echoLog({
  4478. type: 'requestingPlayTestAccess',
  4479. text: id
  4480. });
  4481. const {
  4482. result,
  4483. statusText,
  4484. status,
  4485. data
  4486. } = await tools_httpRequest({
  4487. ...this.#asfOptions,
  4488. data: JSON.stringify({
  4489. Command: `!REQUESTACCESS ${this.#botName} ${id}`
  4490. })
  4491. });
  4492. if (result === 'Success') {
  4493. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4494. logStatus.success();
  4495. return true;
  4496. }
  4497. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4498. return false;
  4499. }
  4500. logStatus.error(`${result}:${statusText}(${status})`);
  4501. return false;
  4502. } catch (error) {
  4503. throwError(error, 'Steam.requestPlayTestAccess');
  4504. return false;
  4505. }
  4506. }
  4507. }
  4508. const social_SteamASF = SteamASF;
  4509. class Steam extends social_Social {
  4510. tasks;
  4511. whiteList;
  4512. #cache = {
  4513. ...{
  4514. group: {},
  4515. officialGroup: {},
  4516. forum: {},
  4517. workshop: {},
  4518. curator: {}
  4519. },
  4520. ...GM_getValue('steamCache')
  4521. };
  4522. #auth = {};
  4523. #storeInitialized = false;
  4524. #communityInitialized = false;
  4525. #area = 'CN';
  4526. #areaStatus = 'end';
  4527. #ASF;
  4528. constructor() {
  4529. super();
  4530. const defaultTasksTemplate = {
  4531. groups: [],
  4532. officialGroups: [],
  4533. wishlists: [],
  4534. follows: [],
  4535. forums: [],
  4536. workshops: [],
  4537. workshopVotes: [],
  4538. curators: [],
  4539. curatorLikes: [],
  4540. announcements: [],
  4541. licenses: [],
  4542. playtests: []
  4543. };
  4544. this.tasks = defaultTasksTemplate;
  4545. this.whiteList = {
  4546. ...defaultTasksTemplate,
  4547. ...GM_getValue('whiteList')?.steam || {}
  4548. };
  4549. }
  4550. async init(type = 'all') {
  4551. try {
  4552. if (globalOptions.ASF.AsfEnabled && globalOptions.ASF.AsfIpcUrl && globalOptions.ASF.AsfIpcPassword) {
  4553. this.#ASF = new social_SteamASF();
  4554. if (await this.#ASF.init()) {
  4555. this.#storeInitialized = true;
  4556. this.#communityInitialized = true;
  4557. return true;
  4558. }
  4559. return false;
  4560. }
  4561. if (type === 'store') {
  4562. if (this.#storeInitialized) {
  4563. return true;
  4564. }
  4565. let storeInitialized = await this.#updateStoreAuth();
  4566. if (!storeInitialized) {
  4567. storeInitialized = await this.#updateStoreAuthTab();
  4568. }
  4569. this.#storeInitialized = storeInitialized;
  4570. if (!this.#storeInitialized) {
  4571. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4572. return false;
  4573. }
  4574. scripts_echoLog({}).success(i18n('initSuccess', 'SteamStore'));
  4575. return true;
  4576. }
  4577. if (type === 'community') {
  4578. if (this.#communityInitialized) {
  4579. return true;
  4580. }
  4581. let communityInitialized = await this.#getUserLink();
  4582. if (!communityInitialized) {
  4583. communityInitialized = await this.#updateCommunityAuthTab();
  4584. GM_setValue('steamCommunityAuth', null);
  4585. }
  4586. this.#communityInitialized = communityInitialized;
  4587. if (!this.#communityInitialized) {
  4588. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4589. return false;
  4590. }
  4591. scripts_echoLog({}).success(i18n('initSuccess', 'SteamCommunity'));
  4592. return true;
  4593. }
  4594. if (this.#storeInitialized && this.#communityInitialized) {
  4595. scripts_echoLog({}).success(i18n('initSuccess', 'Steam'));
  4596. return true;
  4597. }
  4598. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4599. return false;
  4600. } catch (error) {
  4601. throwError(error, 'Steam.init');
  4602. return false;
  4603. }
  4604. }
  4605. async #refreshToken(type = 'steamStore') {
  4606. try {
  4607. const host = {
  4608. steamStore: 'store.steampowered.com',
  4609. steamCommunity: 'steamcommunity.com'
  4610. };
  4611. const logStatus = scripts_echoLog({
  4612. text: i18n('refreshingToken', i18n(type))
  4613. });
  4614. const formData = new FormData();
  4615. formData.append('redir', `https://${host[type]}/`);
  4616. const {
  4617. result,
  4618. statusText,
  4619. status,
  4620. data
  4621. } = await tools_httpRequest({
  4622. url: 'https://login.steampowered.com/jwt/ajaxrefresh',
  4623. method: 'POST',
  4624. responseType: 'json',
  4625. headers: {
  4626. Host: 'login.steampowered.com',
  4627. Origin: `https://${host[type]}`,
  4628. Referer: `https://${host[type]}/`
  4629. },
  4630. data: formData
  4631. });
  4632. if (result === 'Success') {
  4633. if (data?.response?.success) {
  4634. if (await this.#setStoreToken(data.response, type)) {
  4635. logStatus.success();
  4636. return true;
  4637. }
  4638. logStatus.error('Error');
  4639. return false;
  4640. }
  4641. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4642. return false;
  4643. }
  4644. logStatus.error(`${result}:${statusText}(${status})`);
  4645. return false;
  4646. } catch (error) {
  4647. throwError(error, 'Steam.refreshToken');
  4648. return false;
  4649. }
  4650. }
  4651. async #setStoreToken(param, type) {
  4652. try {
  4653. const host = {
  4654. steamStore: 'store.steampowered.com',
  4655. steamCommunity: 'steamcommunity.com'
  4656. };
  4657. const logStatus = scripts_echoLog({
  4658. text: i18n('settingToken', i18n(type))
  4659. });
  4660. const formData = new FormData();
  4661. formData.append('steamID', param.steamID);
  4662. formData.append('nonce', param.nonce);
  4663. formData.append('redir', param.redir);
  4664. formData.append('auth', param.auth);
  4665. const {
  4666. result,
  4667. statusText,
  4668. status,
  4669. data
  4670. } = await tools_httpRequest({
  4671. url: `https://${host[type]}/login/settoken`,
  4672. method: 'POST',
  4673. headers: {
  4674. Accept: 'application/json, text/plain, */*',
  4675. Host: host[type],
  4676. Origin: `https://${host[type]}`
  4677. },
  4678. data: formData
  4679. });
  4680. if (result === 'Success') {
  4681. if (data?.status === 200) {
  4682. logStatus.success();
  4683. return true;
  4684. }
  4685. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4686. return false;
  4687. }
  4688. logStatus.error(`${result}:${statusText}(${status})`);
  4689. return false;
  4690. } catch (error) {
  4691. throwError(error, 'Steam.setStoreToken');
  4692. return false;
  4693. }
  4694. }
  4695. async #updateStoreAuth(retry = false) {
  4696. try {
  4697. const logStatus = scripts_echoLog({
  4698. text: i18n('updatingAuth', i18n('steamStore'))
  4699. });
  4700. const {
  4701. result,
  4702. statusText,
  4703. status,
  4704. data
  4705. } = await tools_httpRequest({
  4706. url: 'https://store.steampowered.com/',
  4707. method: 'GET',
  4708. headers: {
  4709. 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',
  4710. 'Cache-Control': 'max-age=0',
  4711. 'Sec-Fetch-Dest': 'document',
  4712. 'Sec-Fetch-Mode': 'navigate',
  4713. 'Upgrade-Insecure-Requests': '1'
  4714. },
  4715. fetch: false,
  4716. redirect: 'manual'
  4717. });
  4718. if (data?.status === 200) {
  4719. if (!data.responseText.includes('data-miniprofile=')) {
  4720. if (await this.#refreshToken('steamStore')) {
  4721. logStatus.warning(i18n('retry'));
  4722. if (retry) {
  4723. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4724. return false;
  4725. }
  4726. return this.#updateStoreAuth(true);
  4727. }
  4728. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4729. return false;
  4730. }
  4731. const storeSessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4732. if (storeSessionID) {
  4733. this.#auth.storeSessionID = storeSessionID;
  4734. logStatus.success();
  4735. return true;
  4736. }
  4737. logStatus.error('Error: Get "sessionID" failed');
  4738. return false;
  4739. }
  4740. if ([ 301, 302 ].includes(data?.status)) {
  4741. if (await this.#refreshToken('steamStore')) {
  4742. logStatus.warning(i18n('retry'));
  4743. if (retry) {
  4744. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4745. return false;
  4746. }
  4747. return this.#updateStoreAuth(true);
  4748. }
  4749. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4750. return false;
  4751. }
  4752. logStatus.error(`${result}:${statusText}(${status})`);
  4753. return false;
  4754. } catch (error) {
  4755. throwError(error, 'Steam.updateStoreAuth');
  4756. return false;
  4757. }
  4758. }
  4759. async #updateStoreAuthTab() {
  4760. try {
  4761. const logStatus = scripts_echoLog({
  4762. text: i18n('updatingAuth', i18n('steamStore'))
  4763. });
  4764. return await new Promise(resolve => {
  4765. const newTab = window.open('https://store.steampowered.com/', 'mozillaWindow', 'pop=1;');
  4766. GM_setValue('steamStoreAuth', 'update');
  4767. const listenerId = GM_addValueChangeListener('steamStoreAuth', (key, oldValue, newValue, remote) => {
  4768. GM_removeValueChangeListener(listenerId);
  4769. newTab?.close();
  4770. if (newValue && JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
  4771. this.#auth.storeSessionID = newValue.storeSessionID;
  4772. logStatus.success();
  4773. resolve(true);
  4774. return;
  4775. }
  4776. logStatus.error('Failed');
  4777. resolve(false);
  4778. });
  4779. });
  4780. } catch (error) {
  4781. throwError(error, 'Steam.updateStoreAuthTab');
  4782. return false;
  4783. }
  4784. }
  4785. async #updateCommunityAuthTab() {
  4786. try {
  4787. const logStatus = scripts_echoLog({
  4788. text: i18n('updatingAuth', i18n('steamCommunity'))
  4789. });
  4790. return await new Promise(resolve => {
  4791. const newTab = window.open('https://steamcommunity.com/my', 'mozillaWindow', 'pop=1;');
  4792. GM_setValue('steamCommunityAuth', 'update');
  4793. const listenerId = GM_addValueChangeListener('steamCommunityAuth', (key, oldValue, newValue, remote) => {
  4794. GM_removeValueChangeListener(listenerId);
  4795. newTab?.close();
  4796. if (newValue && JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
  4797. this.#auth.steam64Id = newValue.steam64Id;
  4798. this.#auth.userName = newValue.userName;
  4799. this.#auth.communitySessionID = newValue.communitySessionID;
  4800. logStatus.success();
  4801. resolve(true);
  4802. return;
  4803. }
  4804. logStatus.error('Failed');
  4805. resolve(false);
  4806. });
  4807. });
  4808. } catch (error) {
  4809. throwError(error, 'Steam.updateCommunityAuthTab');
  4810. return false;
  4811. }
  4812. }
  4813. async #getUserLink(retry = false) {
  4814. try {
  4815. const logStatus = scripts_echoLog({
  4816. text: i18n('gettingUserLink')
  4817. });
  4818. const {
  4819. result,
  4820. statusText,
  4821. status,
  4822. data
  4823. } = await tools_httpRequest({
  4824. url: 'https://steamcommunity.com/my',
  4825. method: 'GET',
  4826. headers: {
  4827. 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',
  4828. 'Cache-Control': 'max-age=0',
  4829. 'Sec-Fetch-Dest': 'document',
  4830. 'Sec-Fetch-Mode': 'navigate',
  4831. 'Upgrade-Insecure-Requests': '1'
  4832. },
  4833. fetch: false,
  4834. redirect: 'manual'
  4835. });
  4836. if (data?.status === 200) {
  4837. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4838. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4839. return false;
  4840. }
  4841. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4842. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4843. const userName = data.responseText.match(/steamcommunity.com\/id\/(.+?)\/friends\//)?.[1];
  4844. if (steam64Id) {
  4845. this.#auth.steam64Id = steam64Id;
  4846. }
  4847. if (userName) {
  4848. this.#auth.userName = userName;
  4849. }
  4850. if (communitySessionID) {
  4851. this.#auth.communitySessionID = communitySessionID;
  4852. logStatus.success();
  4853. return true;
  4854. }
  4855. logStatus.error('Error: Get "sessionID" failed');
  4856. return false;
  4857. }
  4858. if (data?.status === 302) {
  4859. if (await this.#refreshToken('steamCommunity')) {
  4860. if (retry) {
  4861. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4862. return false;
  4863. }
  4864. logStatus.warning(i18n('retry'));
  4865. return this.#getUserLink(true);
  4866. }
  4867. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4868. return false;
  4869. }
  4870. const location = data?.responseHeaders?.split('\n')?.find(header => header.includes('location') ? header.replace('loctation:', '').trim() : null);
  4871. if (data?.status === 301 && location?.includes('steamcommunity.com/id')) {
  4872. logStatus.success();
  4873. return await this.#updateCommunityAuth(data.finalUrl);
  4874. }
  4875. if (data?.status === 301 && location?.includes('https://steamcommunity.com/login/home')) {
  4876. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4877. return false;
  4878. }
  4879. logStatus.error(`${result}:${statusText}(${status})`);
  4880. return false;
  4881. } catch (error) {
  4882. throwError(error, 'Steam.updateCommunityAuth');
  4883. return false;
  4884. }
  4885. }
  4886. async #updateCommunityAuth(url) {
  4887. try {
  4888. const logStatus = scripts_echoLog({
  4889. text: i18n('updatingAuth', i18n('steamCommunity'))
  4890. });
  4891. const {
  4892. result,
  4893. statusText,
  4894. status,
  4895. data
  4896. } = await tools_httpRequest({
  4897. url: url,
  4898. method: 'GET',
  4899. headers: {
  4900. 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',
  4901. 'Cache-Control': 'max-age=0',
  4902. 'Sec-Fetch-Dest': 'document',
  4903. 'Sec-Fetch-Mode': 'navigate',
  4904. 'Upgrade-Insecure-Requests': '1'
  4905. }
  4906. });
  4907. if (result === 'Success') {
  4908. if (data?.status === 200) {
  4909. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4910. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4911. return false;
  4912. }
  4913. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4914. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4915. const userName = data.responseText.match(/steamcommunity.com\/id\/(.+?)\/friends\//)?.[1];
  4916. if (steam64Id) {
  4917. this.#auth.steam64Id = steam64Id;
  4918. }
  4919. if (userName) {
  4920. this.#auth.userName = userName;
  4921. }
  4922. if (communitySessionID) {
  4923. this.#auth.communitySessionID = communitySessionID;
  4924. logStatus.success();
  4925. return true;
  4926. }
  4927. logStatus.error('Error: Get "sessionID" failed');
  4928. return false;
  4929. }
  4930. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4931. return false;
  4932. }
  4933. logStatus.error(`${result}:${statusText}(${status})`);
  4934. return false;
  4935. } catch (error) {
  4936. throwError(error, 'Steam.updateCommunityAuth');
  4937. return false;
  4938. }
  4939. }
  4940. async #getAreaInfo() {
  4941. try {
  4942. const logStatus = scripts_echoLog({
  4943. text: i18n('gettingAreaInfo')
  4944. });
  4945. const {
  4946. result,
  4947. statusText,
  4948. status,
  4949. data
  4950. } = await tools_httpRequest({
  4951. url: 'https://store.steampowered.com/cart/',
  4952. method: 'GET'
  4953. });
  4954. if (result === 'Success') {
  4955. if (data?.status === 200) {
  4956. const cartConfigRaw = data.responseText.match(/data-cart_config="(.*?)"/)?.[1];
  4957. const temp = document.createElement('div');
  4958. temp.innerHTML = cartConfigRaw || '{}';
  4959. const cartConfigStr = temp.textContent || temp.innerText;
  4960. let cartConfig;
  4961. try {
  4962. cartConfig = JSON.parse(cartConfigStr);
  4963. } catch (error) {
  4964. logStatus.error('Error: get country info filed');
  4965. console.error(error);
  4966. return {};
  4967. }
  4968. if (!cartConfig.rgUserCountryOptions) {
  4969. logStatus.warning('Warning: Area cannot be changed');
  4970. return {};
  4971. }
  4972. const userInfoRaw = data.responseText.match(/data-userinfo="(.*?)"/)?.[1];
  4973. const temp1 = document.createElement('div');
  4974. temp1.innerHTML = userInfoRaw || '{}';
  4975. const userInfoStr = temp1.textContent || temp1.innerText;
  4976. let userInfo;
  4977. try {
  4978. userInfo = JSON.parse(userInfoStr);
  4979. } catch (error) {
  4980. logStatus.error('Error: get country info filed');
  4981. console.error(error);
  4982. return {};
  4983. }
  4984. const currentArea = userInfo.country_code;
  4985. const areas = Object.keys(cartConfig.rgUserCountryOptions).filter(area => area !== 'help');
  4986. if (currentArea && areas.length > 0) {
  4987. this.#area = currentArea;
  4988. logStatus.success();
  4989. return {
  4990. currentArea: currentArea,
  4991. areas: areas
  4992. };
  4993. }
  4994. logStatus.error('Error: get country info filed');
  4995. return {};
  4996. }
  4997. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4998. return {};
  4999. }
  5000. logStatus.error(`${result}:${statusText}(${status})`);
  5001. return {};
  5002. } catch (error) {
  5003. throwError(error, 'Steam.getAreaInfo');
  5004. return {};
  5005. }
  5006. }
  5007. async #changeArea(area) {
  5008. try {
  5009. if (this.#areaStatus === 'waiting') {
  5010. await new Promise(resolve => {
  5011. const checker = setInterval(() => {
  5012. if (this.#areaStatus !== 'waiting') {
  5013. clearInterval(checker);
  5014. resolve(true);
  5015. }
  5016. });
  5017. });
  5018. }
  5019. if (this.#area === area || !area && this.#area !== 'CN') {
  5020. return true;
  5021. }
  5022. this.#areaStatus = 'waiting';
  5023. let aimedArea = area;
  5024. if (!aimedArea) {
  5025. const {
  5026. currentArea,
  5027. areas
  5028. } = await this.#getAreaInfo();
  5029. if (!currentArea || !areas) {
  5030. this.#areaStatus = 'error';
  5031. return false;
  5032. }
  5033. if (currentArea !== 'CN') {
  5034. this.#areaStatus = 'skip';
  5035. scripts_echoLog({
  5036. text: 'notNeededChangeArea'
  5037. });
  5038. return 'skip';
  5039. }
  5040. const anotherArea = areas.filter(area => area && area !== 'CN');
  5041. if (!anotherArea || anotherArea.length === 0) {
  5042. this.#areaStatus = 'noAnotherArea';
  5043. scripts_echoLog({
  5044. text: 'noAnotherArea'
  5045. });
  5046. return false;
  5047. }
  5048. [ aimedArea ] = anotherArea;
  5049. }
  5050. const logStatus = scripts_echoLog({
  5051. text: i18n('changingArea', aimedArea)
  5052. });
  5053. const {
  5054. result,
  5055. statusText,
  5056. status,
  5057. data
  5058. } = await tools_httpRequest({
  5059. url: 'https://store.steampowered.com/country/setcountry',
  5060. method: 'POST',
  5061. headers: {
  5062. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5063. },
  5064. data: $.param({
  5065. cc: aimedArea,
  5066. sessionid: this.#auth.storeSessionID
  5067. })
  5068. });
  5069. if (result === 'Success') {
  5070. if (data?.status === 200 && data.responseText === 'true') {
  5071. const {
  5072. currentArea
  5073. } = await this.#getAreaInfo();
  5074. if (currentArea === aimedArea) {
  5075. this.#areaStatus = 'success';
  5076. logStatus.success();
  5077. return currentArea;
  5078. }
  5079. this.#areaStatus = 'error';
  5080. logStatus.error('Error: change country filed');
  5081. return 'CN';
  5082. }
  5083. this.#areaStatus = 'error';
  5084. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5085. return 'CN';
  5086. }
  5087. this.#areaStatus = 'error';
  5088. logStatus.error(`${result}:${statusText}(${status})`);
  5089. return 'CN';
  5090. } catch (error) {
  5091. this.#areaStatus = 'error';
  5092. throwError(error, 'Steam.changeArea');
  5093. return false;
  5094. }
  5095. }
  5096. async #joinGroup(groupName) {
  5097. try {
  5098. if (this.#ASF) {
  5099. if (await this.#ASF.joinGroup(groupName)) {
  5100. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5101. return true;
  5102. }
  5103. return false;
  5104. }
  5105. const logStatus = scripts_echoLog({
  5106. type: 'joiningSteamGroup',
  5107. text: groupName
  5108. });
  5109. const {
  5110. result,
  5111. statusText,
  5112. status,
  5113. data
  5114. } = await tools_httpRequest({
  5115. url: `https://steamcommunity.com/groups/${groupName}`,
  5116. method: 'POST',
  5117. headers: {
  5118. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5119. },
  5120. data: $.param({
  5121. action: 'join',
  5122. sessionID: this.#auth.communitySessionID
  5123. })
  5124. });
  5125. if (result === 'Success') {
  5126. if (data?.status === 200 && !data.responseText.includes('grouppage_join_area')) {
  5127. logStatus.success();
  5128. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5129. return true;
  5130. }
  5131. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5132. return false;
  5133. }
  5134. logStatus.error(`${result}:${statusText}(${status})`);
  5135. return false;
  5136. } catch (error) {
  5137. throwError(error, 'Steam.joinGroup');
  5138. return false;
  5139. }
  5140. }
  5141. async #leaveGroup(groupName) {
  5142. try {
  5143. if (this.whiteList.groups.includes(groupName)) {
  5144. scripts_echoLog({
  5145. type: 'whiteList',
  5146. text: 'Steam.leaveGroup',
  5147. id: groupName
  5148. });
  5149. return true;
  5150. }
  5151. if (this.#ASF) {
  5152. return await this.#ASF.leaveGroup(groupName);
  5153. }
  5154. const groupId = await this.#getGroupId(groupName);
  5155. if (!groupId) {
  5156. return false;
  5157. }
  5158. const logStatus = scripts_echoLog({
  5159. type: 'leavingSteamGroup',
  5160. text: groupName
  5161. });
  5162. const {
  5163. result,
  5164. statusText,
  5165. status,
  5166. data
  5167. } = await tools_httpRequest({
  5168. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5169. method: 'POST',
  5170. headers: {
  5171. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5172. },
  5173. data: $.param({
  5174. sessionID: this.#auth.communitySessionID,
  5175. action: 'leaveGroup',
  5176. groupId: groupId
  5177. })
  5178. });
  5179. if (result === 'Success') {
  5180. 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) {
  5181. logStatus.success();
  5182. return true;
  5183. }
  5184. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5185. return false;
  5186. }
  5187. logStatus.error(`${result}:${statusText}(${status})`);
  5188. return false;
  5189. } catch (error) {
  5190. throwError(error, 'Steam.leaveGroup');
  5191. return false;
  5192. }
  5193. }
  5194. async #getGroupId(groupName) {
  5195. try {
  5196. const logStatus = scripts_echoLog({
  5197. type: 'gettingSteamGroupId',
  5198. text: groupName
  5199. });
  5200. const groupId = this.#cache.group[groupName];
  5201. if (groupId) {
  5202. logStatus.success();
  5203. return groupId;
  5204. }
  5205. const {
  5206. result,
  5207. statusText,
  5208. status,
  5209. data
  5210. } = await tools_httpRequest({
  5211. url: `https://steamcommunity.com/groups/${groupName}`,
  5212. method: 'GET',
  5213. headers: {
  5214. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5215. }
  5216. });
  5217. if (result === 'Success') {
  5218. if (data?.status === 200) {
  5219. const groupId = data.responseText.match(/OpenGroupChat\( '([0-9]+)'/)?.[1];
  5220. if (groupId) {
  5221. this.#setCache('group', groupName, groupId);
  5222. logStatus.success();
  5223. return groupId;
  5224. }
  5225. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5226. return false;
  5227. }
  5228. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5229. return false;
  5230. }
  5231. logStatus.error(`${result}:${statusText}(${status})`);
  5232. return false;
  5233. } catch (error) {
  5234. throwError(error, 'Steam.getGroupID');
  5235. return false;
  5236. }
  5237. }
  5238. async #joinOfficialGroup(gameId) {
  5239. try {
  5240. if (this.#ASF) {
  5241. if (await this.#ASF.joinGroup(gameId)) {
  5242. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5243. return true;
  5244. }
  5245. return false;
  5246. }
  5247. const logStatus = scripts_echoLog({
  5248. type: 'joiningSteamOfficialGroup',
  5249. text: gameId
  5250. });
  5251. const {
  5252. result,
  5253. statusText,
  5254. status,
  5255. data
  5256. } = await tools_httpRequest({
  5257. url: `https://steamcommunity.com/games/${gameId}?action=join&sessionID=${this.#auth.communitySessionID}`,
  5258. method: 'GET',
  5259. headers: {
  5260. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5261. }
  5262. });
  5263. if (result === 'Success') {
  5264. if (data?.status === 200 && !data.responseText.includes('id="publicGroupJoin"')) {
  5265. logStatus.success();
  5266. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5267. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5268. if (groupId) {
  5269. this.#setCache('officialGroup', gameId, groupId);
  5270. }
  5271. return true;
  5272. }
  5273. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5274. return false;
  5275. }
  5276. logStatus.error(`${result}:${statusText}(${status})`);
  5277. return false;
  5278. } catch (error) {
  5279. throwError(error, 'Steam.joinOfficialGroup');
  5280. return false;
  5281. }
  5282. }
  5283. async #leaveOfficialGroup(gameId) {
  5284. try {
  5285. if (this.whiteList.officialGroups.includes(gameId)) {
  5286. scripts_echoLog({
  5287. type: 'whiteList',
  5288. text: 'Steam.leaveOfficialGroup',
  5289. id: gameId
  5290. });
  5291. return true;
  5292. }
  5293. if (this.#ASF) {
  5294. return await this.#ASF.leaveGroup(gameId);
  5295. }
  5296. const groupId = await this.#getOfficialGroupId(gameId);
  5297. if (!groupId) {
  5298. return false;
  5299. }
  5300. const logStatus = scripts_echoLog({
  5301. type: 'leavingSteamOfficialGroup',
  5302. text: gameId
  5303. });
  5304. const {
  5305. result,
  5306. statusText,
  5307. status,
  5308. data
  5309. } = await tools_httpRequest({
  5310. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5311. method: 'POST',
  5312. headers: {
  5313. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5314. },
  5315. data: $.param({
  5316. sessionID: this.#auth.communitySessionID,
  5317. action: 'leaveGroup',
  5318. groupId: groupId
  5319. })
  5320. });
  5321. if (result === 'Success') {
  5322. if (data?.status === 200) {
  5323. const {
  5324. result: resultR,
  5325. statusText: statusTextR,
  5326. status: statusR,
  5327. data: dataR
  5328. } = await tools_httpRequest({
  5329. url: `https://steamcommunity.com/games/${gameId}`,
  5330. method: 'GET',
  5331. headers: {
  5332. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5333. }
  5334. });
  5335. if (resultR === 'Success') {
  5336. if (dataR?.status === 200 && dataR.responseText.includes('id="publicGroupJoin"')) {
  5337. logStatus.success();
  5338. return true;
  5339. }
  5340. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5341. return false;
  5342. }
  5343. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5344. return false;
  5345. }
  5346. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5347. return false;
  5348. }
  5349. logStatus.error(`${result}:${statusText}(${status})`);
  5350. return false;
  5351. } catch (error) {
  5352. throwError(error, 'Steam.leaveOfficialGroup');
  5353. return false;
  5354. }
  5355. }
  5356. async #getOfficialGroupId(gameId) {
  5357. try {
  5358. const logStatus = scripts_echoLog({
  5359. type: 'gettingSteamOfficialGroupId',
  5360. text: gameId
  5361. });
  5362. const groupId = this.#cache.officialGroup[gameId];
  5363. if (groupId) {
  5364. logStatus.success();
  5365. return groupId;
  5366. }
  5367. const {
  5368. result,
  5369. statusText,
  5370. status,
  5371. data
  5372. } = await tools_httpRequest({
  5373. url: `https://steamcommunity.com/games/${gameId}`,
  5374. method: 'GET',
  5375. headers: {
  5376. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5377. }
  5378. });
  5379. if (result === 'Success') {
  5380. if (data?.status === 200) {
  5381. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5382. if (groupId) {
  5383. this.#setCache('officialGroup', gameId, groupId);
  5384. logStatus.success();
  5385. return groupId;
  5386. }
  5387. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5388. return false;
  5389. }
  5390. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5391. return false;
  5392. }
  5393. logStatus.error(`${result}:${statusText}(${status})`);
  5394. return false;
  5395. } catch (error) {
  5396. throwError(error, 'Steam.getGroupID');
  5397. return false;
  5398. }
  5399. }
  5400. async #addToWishlist(gameId) {
  5401. try {
  5402. if (this.#ASF) {
  5403. if (await this.#ASF.addToWishlist(gameId)) {
  5404. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5405. return true;
  5406. }
  5407. return false;
  5408. }
  5409. const logStatus = scripts_echoLog({
  5410. type: 'addingToWishlist',
  5411. text: gameId
  5412. });
  5413. const {
  5414. result,
  5415. data
  5416. } = await tools_httpRequest({
  5417. url: 'https://store.steampowered.com/api/addtowishlist',
  5418. method: 'POST',
  5419. headers: {
  5420. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5421. },
  5422. data: $.param({
  5423. sessionid: this.#auth.storeSessionID,
  5424. appid: gameId
  5425. }),
  5426. dataType: 'json'
  5427. });
  5428. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5429. logStatus.success();
  5430. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5431. return true;
  5432. }
  5433. const {
  5434. result: resultR,
  5435. statusText: statusTextR,
  5436. status: statusR,
  5437. data: dataR
  5438. } = await tools_httpRequest({
  5439. url: `https://store.steampowered.com/app/${gameId}`,
  5440. method: 'GET'
  5441. });
  5442. if (resultR === 'Success') {
  5443. if (dataR?.status === 200) {
  5444. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5445. logStatus.warning(i18n('changeAreaNotice'));
  5446. if (!await this.#changeArea()) {
  5447. return false;
  5448. }
  5449. return await this.#addToWishlist(gameId);
  5450. }
  5451. if (dataR.responseText.includes('class="queue_actions_ctn"') && dataR.responseText.includes('class="already_in_library"')) {
  5452. logStatus.success();
  5453. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5454. return true;
  5455. } 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"')) {
  5456. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5457. return false;
  5458. }
  5459. logStatus.success();
  5460. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5461. return true;
  5462. }
  5463. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5464. return false;
  5465. }
  5466. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5467. return false;
  5468. } catch (error) {
  5469. throwError(error, 'Steam.addToWishlist');
  5470. return false;
  5471. }
  5472. }
  5473. async #removeFromWishlist(gameId) {
  5474. try {
  5475. if (this.whiteList.wishlists.includes(gameId)) {
  5476. scripts_echoLog({
  5477. type: 'whiteList',
  5478. text: 'Steam.removeFromWishlist',
  5479. id: gameId
  5480. });
  5481. return true;
  5482. }
  5483. if (this.#ASF) {
  5484. return await this.#ASF.removeFromWishlist(gameId);
  5485. }
  5486. const logStatus = scripts_echoLog({
  5487. type: 'removingFromWishlist',
  5488. text: gameId
  5489. });
  5490. const {
  5491. result,
  5492. data
  5493. } = await tools_httpRequest({
  5494. url: 'https://store.steampowered.com/api/removefromwishlist',
  5495. method: 'POST',
  5496. headers: {
  5497. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5498. },
  5499. data: $.param({
  5500. sessionid: this.#auth.storeSessionID,
  5501. appid: gameId
  5502. }),
  5503. dataType: 'json'
  5504. });
  5505. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5506. logStatus.success();
  5507. return true;
  5508. }
  5509. const {
  5510. result: resultR,
  5511. statusText: statusTextR,
  5512. status: statusR,
  5513. data: dataR
  5514. } = await tools_httpRequest({
  5515. url: `https://store.steampowered.com/app/${gameId}`,
  5516. method: 'GET'
  5517. });
  5518. if (resultR === 'Success') {
  5519. if (dataR?.status === 200) {
  5520. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5521. logStatus.warning(i18n('changeAreaNotice'));
  5522. const result = await this.#changeArea();
  5523. if (!result || result === 'CN' || result === 'skip') {
  5524. return false;
  5525. }
  5526. return await this.#removeFromWishlist(gameId);
  5527. }
  5528. if (dataR.responseText.includes('class="queue_actions_ctn"') && (dataR.responseText.includes('ds_owned_flag ds_flag') || dataR.responseText.includes('add_to_wishlist_area'))) {
  5529. logStatus.success();
  5530. return true;
  5531. }
  5532. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5533. return false;
  5534. }
  5535. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5536. return false;
  5537. }
  5538. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5539. return false;
  5540. } catch (error) {
  5541. throwError(error, 'Steam.removeFromWishlist');
  5542. return false;
  5543. }
  5544. }
  5545. async #toggleFollowGame(gameId, doTask) {
  5546. try {
  5547. if (!doTask && this.whiteList.follows.includes(gameId)) {
  5548. scripts_echoLog({
  5549. type: 'whiteList',
  5550. text: 'Steam.unfollowGame',
  5551. id: gameId
  5552. });
  5553. return true;
  5554. }
  5555. if (this.#ASF) {
  5556. if (await this.#ASF.toggleFollowGame(gameId, doTask)) {
  5557. if (doTask) {
  5558. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5559. }
  5560. return true;
  5561. }
  5562. return false;
  5563. }
  5564. const logStatus = scripts_echoLog({
  5565. type: `${doTask ? '' : 'un'}followingGame`,
  5566. text: gameId
  5567. });
  5568. const requestData = {
  5569. sessionid: this.#auth.storeSessionID,
  5570. appid: gameId
  5571. };
  5572. if (!doTask) {
  5573. requestData.unfollow = '1';
  5574. }
  5575. const {
  5576. result,
  5577. data
  5578. } = await tools_httpRequest({
  5579. url: 'https://store.steampowered.com/explore/followgame/',
  5580. method: 'POST',
  5581. headers: {
  5582. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5583. },
  5584. data: $.param(requestData)
  5585. });
  5586. if (result === 'Success' && data?.status === 200 && data.responseText === 'true') {
  5587. logStatus.success();
  5588. return true;
  5589. }
  5590. const followed = await this.#isFollowedGame(gameId);
  5591. if (this.#area === 'CN' && followed === 'areaLocked') {
  5592. logStatus.warning(i18n('changeAreaNotice'));
  5593. if (!await this.#changeArea()) {
  5594. return false;
  5595. }
  5596. return await this.#removeFromWishlist(gameId);
  5597. }
  5598. if (doTask === followed) {
  5599. logStatus.success();
  5600. if (doTask) {
  5601. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5602. }
  5603. return true;
  5604. }
  5605. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5606. return false;
  5607. } catch (error) {
  5608. throwError(error, 'Steam.toggleFollowGame');
  5609. return false;
  5610. }
  5611. }
  5612. async #isFollowedGame(gameId) {
  5613. try {
  5614. const {
  5615. result,
  5616. data
  5617. } = await tools_httpRequest({
  5618. url: `https://store.steampowered.com/app/${gameId}`,
  5619. method: 'GET'
  5620. });
  5621. if (result === 'Success') {
  5622. if (data?.status === 200) {
  5623. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  5624. return 'areaLocked';
  5625. }
  5626. if ($(data.responseText.replace(/<img.*?>/g, '')).find('.queue_control_button.queue_btn_follow>.btnv6_blue_hoverfade.btn_medium.queue_btn_active').css('display') !== 'none') {
  5627. return true;
  5628. }
  5629. return false;
  5630. }
  5631. return false;
  5632. }
  5633. return false;
  5634. } catch (error) {
  5635. throwError(error, 'Steam.isFollowedGame');
  5636. return false;
  5637. }
  5638. }
  5639. async #toggleForum(gameId, doTask = true) {
  5640. try {
  5641. if (!doTask && this.whiteList.forums.includes(gameId)) {
  5642. scripts_echoLog({
  5643. type: 'whiteList',
  5644. text: 'Steam.unsubscribeForum',
  5645. id: gameId
  5646. });
  5647. return true;
  5648. }
  5649. const forumId = await this.#getForumId(gameId);
  5650. if (!forumId) {
  5651. return false;
  5652. }
  5653. const logStatus = scripts_echoLog({
  5654. type: `${doTask ? '' : 'un'}subscribingForum`,
  5655. text: gameId
  5656. });
  5657. const [ id, feature ] = forumId.split('_');
  5658. const {
  5659. result,
  5660. statusText,
  5661. status,
  5662. data
  5663. } = await tools_httpRequest({
  5664. url: `https://steamcommunity.com/forum/${id}/General/${doTask ? '' : 'un'}subscribe/${feature || '0'}/`,
  5665. method: 'POST',
  5666. responseType: 'json',
  5667. headers: {
  5668. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5669. },
  5670. data: $.param({
  5671. sessionid: this.#auth.communitySessionID
  5672. })
  5673. });
  5674. if (result === 'Success') {
  5675. if (data?.status === 200 && (data.response?.success === 1 || data.response?.success === 29)) {
  5676. if (doTask) {
  5677. this.tasks.forums = unique([ ...this.tasks.forums, gameId ]);
  5678. }
  5679. logStatus.success();
  5680. return true;
  5681. }
  5682. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5683. return true;
  5684. }
  5685. logStatus.error(`${result}:${statusText}(${status})`);
  5686. return true;
  5687. } catch (error) {
  5688. throwError(error, 'Steam.toggleForum');
  5689. return true;
  5690. }
  5691. }
  5692. async #getForumId(gameId) {
  5693. try {
  5694. const logStatus = scripts_echoLog({
  5695. type: 'gettingForumId',
  5696. text: gameId
  5697. });
  5698. const forumId = this.#cache.forum[gameId];
  5699. if (forumId) {
  5700. logStatus.success();
  5701. return forumId;
  5702. }
  5703. const {
  5704. result,
  5705. statusText,
  5706. status,
  5707. data
  5708. } = await tools_httpRequest({
  5709. url: `https://steamcommunity.com/app/${gameId}/discussions/`,
  5710. method: 'GET'
  5711. });
  5712. if (result === 'Success') {
  5713. if (data?.status === 200) {
  5714. const forumId = data.responseText?.match(/General_([\d]+(_[\d]+)?)/)?.[1];
  5715. if (forumId) {
  5716. this.#setCache('forum', gameId, forumId);
  5717. logStatus.success();
  5718. return forumId;
  5719. }
  5720. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5721. return false;
  5722. }
  5723. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5724. return false;
  5725. }
  5726. logStatus.error(`${result}:${statusText}(${status})`);
  5727. return false;
  5728. } catch (error) {
  5729. throwError(error, 'Steam.getForumId');
  5730. return false;
  5731. }
  5732. }
  5733. async #toggleFavoriteWorkshop(id, doTask = true) {
  5734. try {
  5735. if (!doTask && this.whiteList.workshops.includes(id)) {
  5736. scripts_echoLog({
  5737. type: 'whiteList',
  5738. text: 'Steam.unfavoriteWorkshop',
  5739. id: id
  5740. });
  5741. return true;
  5742. }
  5743. const appid = await this.#getWorkshopAppId(id);
  5744. if (!appid) {
  5745. return false;
  5746. }
  5747. const logStatus = scripts_echoLog({
  5748. type: doTask ? 'favoritingWorkshop' : 'unfavoritingWorkshop',
  5749. text: id
  5750. });
  5751. const {
  5752. result,
  5753. statusText,
  5754. status,
  5755. data
  5756. } = await tools_httpRequest({
  5757. url: `https://steamcommunity.com/sharedfiles/${doTask ? '' : 'un'}favorite`,
  5758. method: 'POST',
  5759. headers: {
  5760. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5761. },
  5762. data: $.param({
  5763. id: id,
  5764. appid: appid,
  5765. sessionid: this.#auth.communitySessionID
  5766. })
  5767. });
  5768. if (result === 'Success') {
  5769. if (data?.status === 200 && !data.responseText) {
  5770. if (doTask) {
  5771. this.tasks.workshops = unique([ ...this.tasks.workshops, id ]);
  5772. }
  5773. logStatus.success();
  5774. return true;
  5775. }
  5776. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5777. return false;
  5778. }
  5779. logStatus.error(`${result}:${statusText}(${status})`);
  5780. return false;
  5781. } catch (error) {
  5782. throwError(error, 'Steam.toggleFavoriteWorkshop');
  5783. return false;
  5784. }
  5785. }
  5786. async #getWorkshopAppId(id) {
  5787. try {
  5788. const logStatus = scripts_echoLog({
  5789. type: 'gettingWorkshopAppId',
  5790. text: id
  5791. });
  5792. const appId = this.#cache.workshop[id];
  5793. if (appId) {
  5794. logStatus.success();
  5795. return appId;
  5796. }
  5797. const {
  5798. result,
  5799. statusText,
  5800. status,
  5801. data
  5802. } = await tools_httpRequest({
  5803. url: `https://steamcommunity.com/sharedfiles/filedetails/?id=${id}`,
  5804. method: 'GET'
  5805. });
  5806. if (result === 'Success') {
  5807. if (data?.status === 200) {
  5808. const appId = data.responseText.match(/<input type="hidden" name="appid" value="([\d]+?)" \/>/)?.[1];
  5809. if (appId) {
  5810. this.#setCache('workshop', id, appId);
  5811. logStatus.success();
  5812. return appId;
  5813. }
  5814. logStatus.error('Error: getWorkshopAppId failed');
  5815. return false;
  5816. }
  5817. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5818. return false;
  5819. }
  5820. logStatus.error(`${result}:${statusText}(${status})`);
  5821. return false;
  5822. } catch (error) {
  5823. throwError(error, 'Steam.getWorkshopAppId');
  5824. return false;
  5825. }
  5826. }
  5827. async #voteUpWorkshop(id) {
  5828. try {
  5829. const logStatus = scripts_echoLog({
  5830. type: 'votingUpWorkshop',
  5831. text: id
  5832. });
  5833. const {
  5834. result,
  5835. statusText,
  5836. status,
  5837. data
  5838. } = await tools_httpRequest({
  5839. url: 'https://steamcommunity.com/sharedfiles/voteup',
  5840. method: 'POST',
  5841. responseType: 'json',
  5842. headers: {
  5843. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5844. },
  5845. data: $.param({
  5846. id: id,
  5847. sessionid: this.#auth.communitySessionID
  5848. })
  5849. });
  5850. if (result === 'Success') {
  5851. if (data?.status === 200 && data.response?.success === 1) {
  5852. logStatus.success();
  5853. return true;
  5854. }
  5855. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5856. return true;
  5857. }
  5858. logStatus.error(`${result}:${statusText}(${status})`);
  5859. return true;
  5860. } catch (error) {
  5861. throwError(error, 'Steam.voteupWorkshop');
  5862. return true;
  5863. }
  5864. }
  5865. async #toggleCurator(curatorId, doTask = true) {
  5866. try {
  5867. if (!doTask && this.whiteList.curators.includes(curatorId)) {
  5868. scripts_echoLog({
  5869. type: 'whiteList',
  5870. text: 'Steam.unfollowCurator',
  5871. id: curatorId
  5872. });
  5873. return true;
  5874. }
  5875. if (this.#ASF) {
  5876. return await this.#ASF.toggleCurator(curatorId, doTask);
  5877. }
  5878. const logStatus = scripts_echoLog({
  5879. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  5880. text: curatorId
  5881. });
  5882. const {
  5883. result,
  5884. statusText,
  5885. status,
  5886. data
  5887. } = await tools_httpRequest({
  5888. url: 'https://store.steampowered.com/curators/ajaxfollow',
  5889. method: 'POST',
  5890. headers: {
  5891. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5892. },
  5893. data: $.param({
  5894. clanid: curatorId,
  5895. sessionid: this.#auth.storeSessionID,
  5896. follow: doTask
  5897. }),
  5898. dataType: 'json'
  5899. });
  5900. if (result === 'Success') {
  5901. if (data?.status === 200 && data.response?.success?.success === 1) {
  5902. logStatus.success();
  5903. return true;
  5904. }
  5905. logStatus.error(`Error:${data?.statusText}(${data?.response?.success}` || `${data?.status})`);
  5906. return false;
  5907. }
  5908. logStatus.error(`${result}:${statusText}(${status})`);
  5909. return false;
  5910. } catch (error) {
  5911. throwError(error, 'Steam.toggleCurator');
  5912. return false;
  5913. }
  5914. }
  5915. async getCuratorId(path, name) {
  5916. try {
  5917. const logStatus = scripts_echoLog({
  5918. type: 'gettingCuratorId',
  5919. text: `${path}/${name}`
  5920. });
  5921. const curatorId = this.#cache.curator[`${path}/${name}`];
  5922. if (curatorId) {
  5923. logStatus.success();
  5924. return curatorId;
  5925. }
  5926. const {
  5927. result,
  5928. statusText,
  5929. status,
  5930. data
  5931. } = await tools_httpRequest({
  5932. url: `https://store.steampowered.com/${path}/${name}`,
  5933. method: 'GET',
  5934. headers: {
  5935. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5936. }
  5937. });
  5938. if (result === 'Success') {
  5939. if (data?.status === 200) {
  5940. const curatorId = data.responseText.match(/g_pagingData.*?"clanid":([\d]+)/)?.[1];
  5941. if (curatorId) {
  5942. this.#setCache('curator', `${path}/${name}`, curatorId);
  5943. logStatus.success();
  5944. return curatorId;
  5945. }
  5946. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5947. return false;
  5948. }
  5949. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5950. return false;
  5951. }
  5952. logStatus.error(`${result}:${statusText}(${status})`);
  5953. return false;
  5954. } catch (error) {
  5955. throwError(error, 'Steam.getCuratorID');
  5956. return false;
  5957. }
  5958. }
  5959. async #toggleCuratorLike(link, doTask = true) {
  5960. try {
  5961. const [ path, name ] = link.split('/');
  5962. if (!(path && name)) {
  5963. scripts_echoLog({
  5964. text: i18n('errorLink', link)
  5965. });
  5966. return false;
  5967. }
  5968. const curatorId = await this.getCuratorId(path, name);
  5969. if (curatorId) {
  5970. return await this.#toggleCurator(curatorId, doTask);
  5971. }
  5972. return false;
  5973. } catch (error) {
  5974. throwError(error, 'Steam.toggleCuratorLike');
  5975. return false;
  5976. }
  5977. }
  5978. async #getAnnouncementParams(appId, viewId) {
  5979. try {
  5980. const logStatus = scripts_echoLog({
  5981. type: 'gettingAnnouncementParams',
  5982. text: appId,
  5983. id: viewId
  5984. });
  5985. const {
  5986. result,
  5987. statusText,
  5988. status,
  5989. data
  5990. } = await tools_httpRequest({
  5991. 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`,
  5992. method: 'GET',
  5993. responseType: 'json',
  5994. headers: {
  5995. Host: 'store.steampowered.com',
  5996. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  5997. }
  5998. });
  5999. if (result === 'Success') {
  6000. if (data?.status === 200 && data?.response?.success === 1) {
  6001. const {
  6002. clanid,
  6003. gid
  6004. } = data.response.event?.announcement_body || {};
  6005. if (clanid) {
  6006. logStatus.success();
  6007. return {
  6008. clanId: clanid,
  6009. gid: gid
  6010. };
  6011. }
  6012. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6013. return {};
  6014. }
  6015. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6016. return {};
  6017. }
  6018. logStatus.error(`${result}:${statusText}(${status})`);
  6019. return {};
  6020. } catch (error) {
  6021. throwError(error, 'Steam.likeAnnouncement');
  6022. return {};
  6023. }
  6024. }
  6025. async #likeAnnouncement(id) {
  6026. try {
  6027. const [ appId, viewId ] = id.split('/');
  6028. if (!(appId && viewId)) {
  6029. scripts_echoLog({}).error(`${i18n('missParams')}(id)`);
  6030. return false;
  6031. }
  6032. const {
  6033. clanId,
  6034. gid
  6035. } = await this.#getAnnouncementParams(appId, viewId);
  6036. if (!clanId) {
  6037. return false;
  6038. }
  6039. const logStatus = scripts_echoLog({
  6040. type: 'likingAnnouncement',
  6041. text: appId,
  6042. id: viewId
  6043. });
  6044. const {
  6045. result,
  6046. statusText,
  6047. status,
  6048. data
  6049. } = await tools_httpRequest({
  6050. url: `https://store.steampowered.com/updated/ajaxrateupdate/${gid || viewId}`,
  6051. method: 'POST',
  6052. headers: {
  6053. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6054. Host: 'store.steampowered.com',
  6055. Origin: 'https://store.steampowered.com',
  6056. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  6057. },
  6058. data: $.param({
  6059. sessionid: this.#auth.storeSessionID,
  6060. voteup: 1,
  6061. clanid: clanId,
  6062. ajax: 1
  6063. }),
  6064. dataType: 'json'
  6065. });
  6066. if (result === 'Success') {
  6067. if (data?.status === 200 && data.response.success === 1) {
  6068. logStatus.success();
  6069. return true;
  6070. }
  6071. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6072. return false;
  6073. }
  6074. logStatus.error(`${result}:${statusText}(${status})`);
  6075. return false;
  6076. } catch (error) {
  6077. throwError(error, 'Steam.likeAnnouncement');
  6078. return false;
  6079. }
  6080. }
  6081. async #appid2subid(id) {
  6082. try {
  6083. const logStatus = scripts_echoLog({
  6084. type: 'gettingSubid',
  6085. text: id
  6086. });
  6087. const {
  6088. result,
  6089. statusText,
  6090. status,
  6091. data
  6092. } = await tools_httpRequest({
  6093. url: `https://store.steampowered.com/app/${id}`,
  6094. method: 'GET',
  6095. headers: {
  6096. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  6097. }
  6098. });
  6099. if (result === 'Success') {
  6100. if (data?.status === 200) {
  6101. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6102. logStatus.warning(i18n('changeAreaNotice'));
  6103. const result = await this.#changeArea();
  6104. if (!result || result === 'CN' || result === 'skip') {
  6105. return false;
  6106. }
  6107. return await this.#appid2subid(id);
  6108. }
  6109. const subid = data.responseText.match(/name="subid" value="([\d]+?)"/)?.[1];
  6110. if (subid) {
  6111. logStatus.success();
  6112. return subid;
  6113. }
  6114. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6115. return false;
  6116. }
  6117. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6118. return false;
  6119. }
  6120. logStatus.error(`${result}:${statusText}(${status})`);
  6121. return false;
  6122. } catch (error) {
  6123. throwError(error, 'Steam.appid2subid');
  6124. return false;
  6125. }
  6126. }
  6127. async #getLicenses() {
  6128. try {
  6129. const logStatus = scripts_echoLog({
  6130. text: i18n('gettingLicenses')
  6131. });
  6132. const {
  6133. result,
  6134. statusText,
  6135. status,
  6136. data
  6137. } = await tools_httpRequest({
  6138. url: `https://store.steampowered.com/dynamicstore/userdata/?t=${new Date().getTime()}`,
  6139. method: 'GET',
  6140. responseType: 'json'
  6141. });
  6142. if (result === 'Success') {
  6143. if (data?.status === 200) {
  6144. logStatus.success();
  6145. return data.response?.rgOwnedPackages;
  6146. }
  6147. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6148. return false;
  6149. }
  6150. logStatus.error(`${result}:${statusText}(${status})`);
  6151. return false;
  6152. } catch (error) {
  6153. throwError(error, 'Steam.getLicenses');
  6154. return false;
  6155. }
  6156. }
  6157. async #addLicense(id) {
  6158. try {
  6159. if (this.#ASF) {
  6160. return await this.#ASF.addLicense(id);
  6161. }
  6162. const [ type, ids ] = id.split('-');
  6163. if (type === 'appid') {
  6164. const subid = await this.#appid2subid(ids);
  6165. if (!subid) {
  6166. return false;
  6167. }
  6168. const logStatus = scripts_echoLog({
  6169. type: 'addingFreeLicense',
  6170. text: ids
  6171. });
  6172. if (!await this.#addFreeLicense(subid, logStatus)) {
  6173. return false;
  6174. }
  6175. const {
  6176. result,
  6177. statusText,
  6178. status,
  6179. data
  6180. } = await tools_httpRequest({
  6181. url: `https://store.steampowered.com/app/${ids}`,
  6182. method: 'GET'
  6183. });
  6184. if (result === 'Success') {
  6185. if (data?.status === 200) {
  6186. if (data.responseText.includes('ds_owned_flag ds_flag') || data.responseText.includes('class="already_in_library"')) {
  6187. logStatus.success();
  6188. return true;
  6189. }
  6190. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6191. return false;
  6192. }
  6193. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6194. return false;
  6195. }
  6196. logStatus.error(`${result}:${statusText}(${status})`);
  6197. return false;
  6198. } else if (type === 'subid') {
  6199. if (this.#area === 'CN') {
  6200. scripts_echoLog({}).success(i18n('tryChangeAreaNotice'));
  6201. await this.#changeArea();
  6202. }
  6203. const logStatusArr = {};
  6204. const idsArr = ids.split(',');
  6205. for (const subid of idsArr) {
  6206. const logStatus = scripts_echoLog({
  6207. type: 'addingFreeLicenseSubid',
  6208. text: subid
  6209. });
  6210. if (!await this.#addFreeLicense(subid, logStatus)) {
  6211. return false;
  6212. }
  6213. logStatusArr[subid] = logStatus;
  6214. }
  6215. const licenses = await this.#getLicenses();
  6216. if (!licenses) {
  6217. return false;
  6218. }
  6219. for (const subid of idsArr) {
  6220. if (licenses.includes(parseInt(subid, 10))) {
  6221. logStatusArr[subid].success();
  6222. } else {
  6223. logStatusArr[subid].error();
  6224. }
  6225. }
  6226. return true;
  6227. }
  6228. return false;
  6229. } catch (error) {
  6230. throwError(error, 'Steam.addLicense');
  6231. return false;
  6232. }
  6233. }
  6234. async #addFreeLicense(id, logStatusPre) {
  6235. try {
  6236. const logStatus = logStatusPre || scripts_echoLog({
  6237. type: 'addingFreeLicenseSubid',
  6238. text: id
  6239. });
  6240. const {
  6241. result,
  6242. statusText,
  6243. status,
  6244. data
  6245. } = await tools_httpRequest({
  6246. url: 'https://store.steampowered.com/checkout/addfreelicense',
  6247. method: 'POST',
  6248. headers: {
  6249. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6250. Host: 'store.steampowered.com',
  6251. Origin: 'https://store.steampowered.com',
  6252. Referer: 'https://store.steampowered.com/account/licenses/'
  6253. },
  6254. data: $.param({
  6255. action: 'add_to_cart',
  6256. sessionid: this.#auth.storeSessionID,
  6257. subid: id
  6258. }),
  6259. dataType: 'json'
  6260. });
  6261. if (result === 'Success') {
  6262. if (data?.status === 200) {
  6263. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6264. logStatus.warning(i18n('changeAreaNotice'));
  6265. const result = await this.#changeArea();
  6266. if (!result || result === 'CN') {
  6267. return false;
  6268. }
  6269. return await this.#addFreeLicense(id);
  6270. }
  6271. logStatus.success();
  6272. return true;
  6273. }
  6274. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6275. return false;
  6276. }
  6277. logStatus.error(`${result}:${statusText}(${status})`);
  6278. return false;
  6279. } catch (error) {
  6280. throwError(error, 'Steam.addFreeLicense');
  6281. return false;
  6282. }
  6283. }
  6284. async #requestPlayTestAccess(id) {
  6285. try {
  6286. if (this.#ASF) {
  6287. return await this.#ASF.requestPlayTestAccess(id);
  6288. }
  6289. const logStatus = scripts_echoLog({
  6290. type: 'requestingPlayTestAccess',
  6291. text: id
  6292. });
  6293. const {
  6294. result,
  6295. statusText,
  6296. status,
  6297. data
  6298. } = await tools_httpRequest({
  6299. url: `https://store.steampowered.com/ajaxrequestplaytestaccess/${id}`,
  6300. method: 'POST',
  6301. headers: {
  6302. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6303. Host: 'store.steampowered.com',
  6304. Origin: 'https://store.steampowered.com',
  6305. Referer: `https://store.steampowered.com/app/${id}`
  6306. },
  6307. data: $.param({
  6308. sessionid: this.#auth.storeSessionID
  6309. }),
  6310. dataType: 'json'
  6311. });
  6312. if (result === 'Success') {
  6313. if (data?.status === 200 && data?.response?.success === 1) {
  6314. logStatus.success();
  6315. return true;
  6316. }
  6317. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6318. return false;
  6319. }
  6320. logStatus.error(`${result}:${statusText}(${status})`);
  6321. return false;
  6322. } catch (error) {
  6323. throwError(error, 'Steam.requestPlayTestAccess');
  6324. return false;
  6325. }
  6326. }
  6327. async toggle({
  6328. doTask = true,
  6329. groupLinks = [],
  6330. officialGroupLinks = [],
  6331. wishlistLinks = [],
  6332. followLinks = [],
  6333. forumLinks = [],
  6334. workshopLinks = [],
  6335. workshopVoteLinks = [],
  6336. curatorLinks = [],
  6337. curatorLikeLinks = [],
  6338. announcementLinks = [],
  6339. licenseLinks = [],
  6340. playtestLinks = []
  6341. }) {
  6342. try {
  6343. if ([ ...groupLinks, ...officialGroupLinks, ...forumLinks, ...workshopLinks, ...workshopVoteLinks ].length > 0 && !this.#communityInitialized) {
  6344. scripts_echoLog({
  6345. text: i18n('needInit')
  6346. });
  6347. return false;
  6348. }
  6349. if ([ ...wishlistLinks, ...followLinks, ...curatorLinks, ...curatorLikeLinks, ...announcementLinks, ...licenseLinks, ...playtestLinks ].length > 0 && !this.#storeInitialized) {
  6350. scripts_echoLog({
  6351. text: i18n('needInit')
  6352. });
  6353. return false;
  6354. }
  6355. const prom = [];
  6356. if (doTask && !globalOptions.doTask.steam.groups || !doTask && !globalOptions.undoTask.steam.groups) {
  6357. scripts_echoLog({
  6358. type: 'globalOptionsSkip',
  6359. text: 'steam.groups'
  6360. });
  6361. } else {
  6362. const realGroups = this.getRealParams('groups', groupLinks, doTask, link => link.match(/groups\/(.+)\/?/)?.[1]);
  6363. if (realGroups.length > 0) {
  6364. for (const group of realGroups) {
  6365. if (doTask) {
  6366. prom.push(this.#joinGroup(group));
  6367. } else {
  6368. prom.push(this.#leaveGroup(group));
  6369. }
  6370. await delay(1e3);
  6371. }
  6372. }
  6373. }
  6374. if (doTask && !globalOptions.doTask.steam.officialGroups || !doTask && !globalOptions.undoTask.steam.officialGroups) {
  6375. scripts_echoLog({
  6376. type: 'globalOptionsSkip',
  6377. text: 'steam.officialGroups'
  6378. });
  6379. } else {
  6380. const realOfficialGroups = this.getRealParams('officialGroups', officialGroupLinks, doTask, link => link.match(/games\/(.+)\/?/)?.[1]);
  6381. if (realOfficialGroups.length > 0) {
  6382. for (const officialGroup of realOfficialGroups) {
  6383. if (doTask) {
  6384. prom.push(this.#joinOfficialGroup(officialGroup));
  6385. } else {
  6386. prom.push(this.#leaveOfficialGroup(officialGroup));
  6387. }
  6388. await delay(1e3);
  6389. }
  6390. }
  6391. }
  6392. if (doTask && !globalOptions.doTask.steam.wishlists || !doTask && !globalOptions.undoTask.steam.wishlists) {
  6393. scripts_echoLog({
  6394. type: 'globalOptionsSkip',
  6395. text: 'steam.wishlists'
  6396. });
  6397. } else {
  6398. const realWishlists = this.getRealParams('wishlists', wishlistLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6399. if (realWishlists.length > 0) {
  6400. for (const game of realWishlists) {
  6401. if (doTask) {
  6402. prom.push(this.#addToWishlist(game));
  6403. } else {
  6404. prom.push(this.#removeFromWishlist(game));
  6405. }
  6406. await delay(1e3);
  6407. }
  6408. }
  6409. }
  6410. if (doTask && !globalOptions.doTask.steam.follows || !doTask && !globalOptions.undoTask.steam.follows) {
  6411. scripts_echoLog({
  6412. type: 'globalOptionsSkip',
  6413. text: 'steam.follows'
  6414. });
  6415. } else {
  6416. const realFollows = this.getRealParams('follows', followLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6417. if (realFollows.length > 0) {
  6418. for (const game of realFollows) {
  6419. prom.push(this.#toggleFollowGame(game, doTask));
  6420. await delay(1e3);
  6421. }
  6422. }
  6423. }
  6424. if (doTask && !globalOptions.doTask.steam.forums || !doTask && !globalOptions.undoTask.steam.forums) {
  6425. scripts_echoLog({
  6426. type: 'globalOptionsSkip',
  6427. text: 'steam.forums'
  6428. });
  6429. } else {
  6430. const realForums = this.getRealParams('forums', forumLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6431. if (realForums.length > 0) {
  6432. for (const forum of realForums) {
  6433. prom.push(this.#toggleForum(forum, doTask));
  6434. await delay(1e3);
  6435. }
  6436. }
  6437. }
  6438. if (doTask && !globalOptions.doTask.steam.workshops || !doTask && !globalOptions.undoTask.steam.workshops) {
  6439. scripts_echoLog({
  6440. type: 'globalOptionsSkip',
  6441. text: 'steam.workshops'
  6442. });
  6443. } else {
  6444. const realWorkshops = this.getRealParams('workshops', workshopLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6445. if (realWorkshops.length > 0) {
  6446. for (const workshop of realWorkshops) {
  6447. prom.push(this.#toggleFavoriteWorkshop(workshop, doTask));
  6448. await delay(1e3);
  6449. }
  6450. }
  6451. }
  6452. if (doTask && !globalOptions.doTask.steam.workshopVotes) {
  6453. scripts_echoLog({
  6454. type: 'globalOptionsSkip',
  6455. text: 'steam.workshopVotes'
  6456. });
  6457. } else {
  6458. const realworkshopVotes = this.getRealParams('workshopVotes', workshopVoteLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6459. if (doTask && realworkshopVotes.length > 0) {
  6460. for (const workshop of realworkshopVotes) {
  6461. prom.push(this.#voteUpWorkshop(workshop));
  6462. await delay(1e3);
  6463. }
  6464. }
  6465. }
  6466. if (doTask && !globalOptions.doTask.steam.curators || !doTask && !globalOptions.undoTask.steam.curators) {
  6467. scripts_echoLog({
  6468. type: 'globalOptionsSkip',
  6469. text: 'steam.curators'
  6470. });
  6471. } else {
  6472. const realCurators = this.getRealParams('curators', curatorLinks, doTask, link => link.match(/curator\/([\d]+)/)?.[1]);
  6473. const realCuratorLikes = this.getRealParams('curatorLikes', curatorLikeLinks, doTask, link => link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3).join('/'));
  6474. if (realCurators.length > 0) {
  6475. for (const curator of realCurators) {
  6476. prom.push(this.#toggleCurator(curator, doTask));
  6477. await delay(1e3);
  6478. }
  6479. }
  6480. if (realCuratorLikes.length > 0) {
  6481. for (const curatorLike of realCuratorLikes) {
  6482. prom.push(this.#toggleCuratorLike(curatorLike, doTask));
  6483. await delay(1e3);
  6484. }
  6485. }
  6486. }
  6487. if (doTask && !globalOptions.doTask.steam.announcements) {
  6488. scripts_echoLog({
  6489. type: 'globalOptionsSkip',
  6490. text: 'steam.announcements'
  6491. });
  6492. } else {
  6493. const realAnnouncements = this.getRealParams('announcements', announcementLinks, doTask, link => {
  6494. if (link.includes('store.steampowered.com')) {
  6495. return link.match(/store\.steampowered\.com\/news\/app\/([\d]+)\/view\/([\d]+)/)?.slice(1, 3).join('/');
  6496. }
  6497. return link.match(/steamcommunity\.com\/games\/([\d]+)\/announcements\/detail\/([\d]+)/)?.slice(1, 3).join('/');
  6498. });
  6499. if (doTask && realAnnouncements.length > 0) {
  6500. for (const id of realAnnouncements) {
  6501. prom.push(this.#likeAnnouncement(id));
  6502. await delay(1e3);
  6503. }
  6504. }
  6505. }
  6506. if (doTask && !globalOptions.doTask.steam.licenses) {
  6507. scripts_echoLog({
  6508. type: 'globalOptionsSkip',
  6509. text: 'steam.licenses'
  6510. });
  6511. } else if (doTask && globalOptions.doTask.steam.licenses && licenseLinks.length > 0) {
  6512. for (const id of licenseLinks) {
  6513. prom.push(this.#addLicense(id));
  6514. await delay(1e3);
  6515. }
  6516. }
  6517. if (doTask && !globalOptions.doTask.steam.playtests) {
  6518. scripts_echoLog({
  6519. type: 'globalOptionsSkip',
  6520. text: 'steam.playtests'
  6521. });
  6522. } else {
  6523. const realPlaytests = this.getRealParams('playtests', playtestLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6524. if (doTask && globalOptions.doTask.steam.playtests && realPlaytests.length > 0) {
  6525. for (const id of realPlaytests) {
  6526. prom.push(this.#requestPlayTestAccess(id));
  6527. await delay(1e3);
  6528. }
  6529. }
  6530. }
  6531. return Promise.all(prom).then(async () => {
  6532. if (this.#area !== 'CN') {
  6533. scripts_echoLog({}).warning(i18n('steamFinishNotice'));
  6534. await this.#changeArea('CN');
  6535. }
  6536. return true;
  6537. });
  6538. } catch (error) {
  6539. throwError(error, 'Steam.toggle');
  6540. return false;
  6541. }
  6542. }
  6543. #setCache(type, name, id) {
  6544. try {
  6545. this.#cache[type][name] = id;
  6546. GM_setValue('steamCache', this.#cache);
  6547. } catch (error) {
  6548. throwError(error, 'Steam.setCache');
  6549. }
  6550. }
  6551. }
  6552. const social_Steam = Steam;
  6553. class Website {
  6554. undoneTasks;
  6555. socialTasks;
  6556. giveawayId;
  6557. socialInitialized = {
  6558. discord: false,
  6559. instagram: false,
  6560. reddit: false,
  6561. twitch: false,
  6562. twitter: false,
  6563. vk: false,
  6564. youtube: false,
  6565. steamStore: false,
  6566. steamCommunity: false
  6567. };
  6568. initialized = false;
  6569. social = {};
  6570. async #bind(name, init) {
  6571. try {
  6572. return {
  6573. name: name,
  6574. result: await init
  6575. };
  6576. } catch (error) {
  6577. throwError(error, 'Website.bind');
  6578. return {
  6579. name: name,
  6580. result: false
  6581. };
  6582. }
  6583. }
  6584. async initSocial(action) {
  6585. try {
  6586. const pro = [];
  6587. const tasks = action === 'do' ? this.undoneTasks : this.socialTasks;
  6588. if (tasks.discord) {
  6589. const hasDiscord = Object.values(tasks.discord).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6590. if (hasDiscord && (!this.socialInitialized.discord || !this.social.discord)) {
  6591. this.social.discord = new social_Discord();
  6592. pro.push(this.#bind('discord', this.social.discord.init(action)));
  6593. }
  6594. }
  6595. if (tasks.instagram) {
  6596. const hasInstagram = Object.values(tasks.instagram).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6597. if (hasInstagram && (!this.socialInitialized.instagram || !this.social.instagram)) {
  6598. this.social.instagram = new social_Instagram();
  6599. pro.push(this.#bind('instagram', this.social.instagram.init()));
  6600. }
  6601. }
  6602. if (tasks.reddit) {
  6603. const hasReddit = Object.values(tasks.reddit).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6604. if (hasReddit && (!this.socialInitialized.reddit || !this.social.reddit)) {
  6605. this.social.reddit = new social_Reddit();
  6606. pro.push(this.#bind('reddit', this.social.reddit.init()));
  6607. }
  6608. }
  6609. if (tasks.twitch) {
  6610. const hasTwitch = Object.values(tasks.twitch).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6611. if (hasTwitch && (!this.socialInitialized.twitch || !this.social.twitch)) {
  6612. this.social.twitch = new social_Twitch();
  6613. pro.push(this.#bind('twitch', this.social.twitch.init()));
  6614. }
  6615. }
  6616. if (tasks.twitter) {
  6617. const hasTwitter = Object.values(tasks.twitter).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6618. if (hasTwitter && (!this.socialInitialized.twitter || !this.social.twitter)) {
  6619. this.social.twitter = new social_Twitter();
  6620. pro.push(this.#bind('twitter', this.social.twitter.init()));
  6621. }
  6622. }
  6623. if (tasks.vk) {
  6624. const hasVk = Object.values(tasks.vk).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6625. if (hasVk && (!this.socialInitialized.vk || !this.social.vk)) {
  6626. this.social.vk = new social_Vk();
  6627. pro.push(this.#bind('vk', this.social.vk.init()));
  6628. }
  6629. }
  6630. if (tasks.youtube) {
  6631. const hasYoutube = Object.values(tasks.youtube).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6632. if (hasYoutube && (!this.socialInitialized.youtube || !this.social.youtube)) {
  6633. this.social.youtube = new Youtube();
  6634. pro.push(this.#bind('youtube', this.social.youtube.init()));
  6635. }
  6636. }
  6637. if (tasks.steam) {
  6638. const steamLength = Object.values(tasks.steam).reduce((total, arr) => [ ...total, ...arr ]).length;
  6639. if (steamLength > 0) {
  6640. if (!this.social.steam) {
  6641. this.social.steam = new social_Steam();
  6642. }
  6643. 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);
  6644. if (steamLength - steamCommunityLength > 0 && !this.socialInitialized.steamStore) {
  6645. pro.push(this.#bind('steamStore', this.social.steam.init('store')));
  6646. }
  6647. if (steamCommunityLength > 0 && !this.socialInitialized.steamCommunity) {
  6648. pro.push(this.#bind('steamCommunity', this.social.steam.init('community')));
  6649. }
  6650. }
  6651. }
  6652. if (tasks.links && tasks.links.length > 0) {
  6653. this.social.visitLink = visitLink;
  6654. }
  6655. return await Promise.all(pro).then(result => {
  6656. let checked = true;
  6657. for (const data of result) {
  6658. if (data.result) {
  6659. this.socialInitialized[data.name] = data.result;
  6660. } else {
  6661. checked = false;
  6662. }
  6663. }
  6664. return checked;
  6665. });
  6666. } catch (error) {
  6667. throwError(error, 'Website.initSocial');
  6668. return false;
  6669. }
  6670. }
  6671. uniqueTasks(allTasks) {
  6672. const result = {};
  6673. for (const [ social, types ] of Object.entries(allTasks)) {
  6674. result[social] = {};
  6675. for (const [ type, tasks ] of Object.entries(types)) {
  6676. result[social][type] = unique(tasks);
  6677. }
  6678. }
  6679. return result;
  6680. }
  6681. async toggleTask(action) {
  6682. try {
  6683. if (!this.initialized && !this.init()) {
  6684. return false;
  6685. }
  6686. if (!await this.classifyTask(action)) {
  6687. return false;
  6688. }
  6689. if (!await this.initSocial(action)) {
  6690. return false;
  6691. }
  6692. const pro = [];
  6693. const doTask = action === 'do';
  6694. const tasks = doTask ? this.undoneTasks : this.socialTasks;
  6695. if (this.socialInitialized.discord !== 'skip' && this.social.discord) {
  6696. pro.push(this.social.discord.toggle({
  6697. doTask: doTask,
  6698. ...tasks.discord
  6699. }));
  6700. }
  6701. if (this.social.instagram) {
  6702. pro.push(this.social.instagram.toggle({
  6703. doTask: doTask,
  6704. ...tasks.instagram
  6705. }));
  6706. }
  6707. if (this.social.reddit) {
  6708. pro.push(this.social.reddit.toggle({
  6709. doTask: doTask,
  6710. ...tasks.reddit
  6711. }));
  6712. }
  6713. if (this.social.twitch) {
  6714. pro.push(this.social.twitch.toggle({
  6715. doTask: doTask,
  6716. ...tasks.twitch
  6717. }));
  6718. }
  6719. if (this.social.twitter) {
  6720. pro.push(this.social.twitter.toggle({
  6721. doTask: doTask,
  6722. ...tasks.twitter
  6723. }));
  6724. }
  6725. if (this.social.vk) {
  6726. pro.push(this.social.vk.toggle({
  6727. doTask: doTask,
  6728. ...tasks.vk
  6729. }));
  6730. }
  6731. if (this.social.youtube) {
  6732. pro.push(this.social.youtube.toggle({
  6733. doTask: doTask,
  6734. ...tasks.youtube
  6735. }));
  6736. }
  6737. if (this.social.steam) {
  6738. pro.push(this.social.steam.toggle({
  6739. doTask: doTask,
  6740. ...tasks.steam
  6741. }));
  6742. }
  6743. if (this.social.visitLink && tasks.links && doTask) {
  6744. for (const link of tasks.links) {
  6745. pro.push(this.social.visitLink(link));
  6746. }
  6747. }
  6748. if (doTask && tasks.extra && this.extraDoTask) {
  6749. const hasExtra = Object.values(tasks.extra).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6750. if (hasExtra) {
  6751. pro.push(this.extraDoTask(tasks.extra));
  6752. }
  6753. }
  6754. await Promise.all(pro);
  6755. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6756. return true;
  6757. } catch (error) {
  6758. throwError(error, 'Website.toggleTask');
  6759. return false;
  6760. }
  6761. }
  6762. async doTask() {
  6763. try {
  6764. return await this.toggleTask('do');
  6765. } catch (error) {
  6766. throwError(error, 'Website.doTask');
  6767. return false;
  6768. }
  6769. }
  6770. async undoTask() {
  6771. try {
  6772. return await this.toggleTask('undo');
  6773. } catch (error) {
  6774. throwError(error, 'Website.undoTask');
  6775. return false;
  6776. }
  6777. }
  6778. }
  6779. const website_Website = Website;
  6780. const defaultTasksTemplate = {
  6781. steam: {
  6782. groupLinks: [],
  6783. wishlistLinks: [],
  6784. curatorLinks: [],
  6785. followLinks: []
  6786. },
  6787. vk: {
  6788. nameLinks: []
  6789. }
  6790. };
  6791. const defaultTasks = JSON.stringify(defaultTasksTemplate);
  6792. class FreeAnyWhere extends website_Website {
  6793. name = 'FreeAnyWhere';
  6794. tasks = [];
  6795. socialTasks = JSON.parse(defaultTasks);
  6796. undoneTasks = JSON.parse(defaultTasks);
  6797. buttons = [ 'doTask', 'undoTask', 'verifyTask', 'getKey' ];
  6798. static test() {
  6799. return window.location.host === 'freeanywhere.net';
  6800. }
  6801. async init() {
  6802. try {
  6803. const logStatus = scripts_echoLog({
  6804. text: i18n('initing')
  6805. });
  6806. if ($('a[href="#/login"]').length > 0) {
  6807. window.open('/#/login', '_self');
  6808. logStatus.warning(i18n('needLogin'));
  6809. return false;
  6810. }
  6811. if (window.location.href.includes('/login')) {
  6812. logStatus.warning(i18n('needLogin'));
  6813. return false;
  6814. }
  6815. if (!/^https?:\/\/freeanywhere\.net\/#\/giveaway\/[\d]+/.test(window.location.href)) {
  6816. const id = window.location.href.match(/https?:\/\/freeanywhere\.net\/.*?#\/giveaway\/([\d]+)/)?.[1];
  6817. if (!id) {
  6818. logStatus.error(i18n('getFailed', 'Id'));
  6819. return false;
  6820. }
  6821. window.location.href = `https://freeanywhere.net/#/giveaway/${id}`;
  6822. }
  6823. if (!this.#getGiveawayId()) {
  6824. return false;
  6825. }
  6826. if (!await this.#checkLeftKey()) {
  6827. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  6828. }
  6829. this.initialized = true;
  6830. logStatus.success();
  6831. return true;
  6832. } catch (error) {
  6833. throwError(error, 'Freeanywhere.init');
  6834. return false;
  6835. }
  6836. }
  6837. async classifyTask(action) {
  6838. try {
  6839. const logStatus = scripts_echoLog({
  6840. text: i18n('getTasksInfo')
  6841. });
  6842. if (action === 'undo') {
  6843. this.socialTasks = GM_getValue(`fawTasks-${this.giveawayId}`)?.tasks || JSON.parse(defaultTasks);
  6844. }
  6845. const {
  6846. result,
  6847. statusText,
  6848. status,
  6849. data
  6850. } = await tools_httpRequest({
  6851. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/?format=json`,
  6852. method: 'GET',
  6853. headers: {
  6854. authorization: `Token ${window.localStorage.getItem('token')}`,
  6855. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  6856. },
  6857. responseType: 'json'
  6858. });
  6859. if (result === 'Success') {
  6860. const tasks = data?.response?.challenges;
  6861. if (tasks) {
  6862. if (action === 'verify') {
  6863. this.tasks = [];
  6864. }
  6865. for (const task of tasks) {
  6866. const type = task.challenge;
  6867. const social = task.challenge_provider;
  6868. const taskInfo = {
  6869. id: task.id,
  6870. title: task.title
  6871. };
  6872. if (action === 'verify' && !task.is_success) {
  6873. this.tasks.push(taskInfo);
  6874. continue;
  6875. }
  6876. switch (social) {
  6877. case 'steam':
  6878. taskInfo.social = 'steam';
  6879. switch (type) {
  6880. case 'WL':
  6881. if (action === 'undo') {
  6882. this.socialTasks.steam.wishlistLinks.push(task.link);
  6883. }
  6884. if (action === 'do' && !task.is_success) {
  6885. this.undoneTasks.steam.wishlistLinks.push(task.link);
  6886. }
  6887. break;
  6888.  
  6889. case 'JTG':
  6890. if (action === 'undo') {
  6891. this.socialTasks.steam.groupLinks.push(task.link);
  6892. }
  6893. if (action === 'do' && !task.is_success) {
  6894. this.undoneTasks.steam.groupLinks.push(task.link);
  6895. }
  6896. break;
  6897.  
  6898. case 'STC':
  6899. if (action === 'undo') {
  6900. this.socialTasks.steam.curatorLinks.push(task.link);
  6901. }
  6902. if (action === 'do' && !task.is_success) {
  6903. this.undoneTasks.steam.curatorLinks.push(task.link);
  6904. }
  6905. break;
  6906.  
  6907. case 'GF':
  6908. if (action === 'undo') {
  6909. this.socialTasks.steam.followLinks.push(task.link);
  6910. }
  6911. if (action === 'do' && !task.is_success) {
  6912. this.undoneTasks.steam.followLinks.push(task.link);
  6913. }
  6914. break;
  6915. }
  6916. break;
  6917.  
  6918. case 'vk-oauth2':
  6919. if (action === 'undo') {
  6920. this.socialTasks.vk.nameLinks.push(task.link);
  6921. }
  6922. if (action === 'do' && !task.is_success) {
  6923. this.undoneTasks.vk.nameLinks.push(task.link);
  6924. }
  6925. break;
  6926.  
  6927. case 'website':
  6928. break;
  6929.  
  6930. default:
  6931. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${social}`);
  6932. break;
  6933. }
  6934. }
  6935. logStatus.success();
  6936. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  6937. this.socialTasks = this.uniqueTasks(this.socialTasks);
  6938. if (window.DEBUG) {
  6939. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  6940. }
  6941. GM_setValue(`fawTasks-${this.giveawayId}`, {
  6942. tasks: this.socialTasks,
  6943. time: new Date().getTime()
  6944. });
  6945. return true;
  6946. }
  6947. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6948. return false;
  6949. }
  6950. logStatus.error(`${result}:${statusText}(${status})`);
  6951. return false;
  6952. } catch (error) {
  6953. throwError(error, 'Freeanywhere.classifyTask');
  6954. return false;
  6955. }
  6956. }
  6957. async verifyTask() {
  6958. try {
  6959. if (!this.initialized && !this.init()) {
  6960. return false;
  6961. }
  6962. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  6963. return false;
  6964. }
  6965. const pro = [];
  6966. for (const task of this.tasks) {
  6967. pro.push(this.#verify(task));
  6968. await delay(1e3);
  6969. }
  6970. await Promise.all(pro);
  6971. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6972. return !!await this.getKey(true);
  6973. } catch (error) {
  6974. throwError(error, 'Freeanywhere.verifyTask');
  6975. return false;
  6976. }
  6977. }
  6978. async getKey(initialized) {
  6979. try {
  6980. if (!initialized && !this.initialized && !this.init()) {
  6981. return false;
  6982. }
  6983. const logStatus = scripts_echoLog({
  6984. text: i18n('gettingKey')
  6985. });
  6986. const {
  6987. result,
  6988. statusText,
  6989. status,
  6990. data
  6991. } = await tools_httpRequest({
  6992. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/reward/?format=json`,
  6993. method: 'GET',
  6994. dataType: 'json',
  6995. headers: {
  6996. authorization: `Token ${window.localStorage.getItem('token')}`
  6997. }
  6998. });
  6999. if (result === 'Success') {
  7000. if (data?.response?.reward) {
  7001. logStatus.success();
  7002. scripts_echoLog({}).success(data.response.reward);
  7003. return data.response.reward;
  7004. }
  7005. if (data?.response?.completed === false) {
  7006. logStatus.error(i18n('tasksNotCompleted'));
  7007. return false;
  7008. }
  7009. if (data?.response?.completed === true) {
  7010. await this.#checkLeftKey();
  7011. }
  7012. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7013. return false;
  7014. }
  7015. logStatus.error(`${result}:${statusText}(${status})`);
  7016. return false;
  7017. } catch (error) {
  7018. throwError(error, 'FreeAnyWhere.getGiveawayId');
  7019. return false;
  7020. }
  7021. }
  7022. #getGiveawayId() {
  7023. try {
  7024. const giveawayId = window.location.href.match(/\/giveaway\/([\d]+)/)?.[1];
  7025. if (giveawayId) {
  7026. this.giveawayId = giveawayId;
  7027. return true;
  7028. }
  7029. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7030. return false;
  7031. } catch (error) {
  7032. throwError(error, 'FreeAnyWhere.getGiveawayId');
  7033. }
  7034. }
  7035. async #verify(task) {
  7036. try {
  7037. const logStatus = scripts_echoLog({
  7038. html: `<li>${i18n('verifyingTask')}${task.title.trim()}...<font></font></li>`
  7039. });
  7040. const {
  7041. result,
  7042. statusText,
  7043. status,
  7044. data
  7045. } = await tools_httpRequest({
  7046. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/challenge-status/${task.id}/?format=json`,
  7047. method: 'GET',
  7048. dataType: 'json',
  7049. headers: {
  7050. authorization: `Token ${window.localStorage.getItem('token')}`,
  7051. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  7052. }
  7053. });
  7054. if (result === 'Success') {
  7055. if (data?.response?.status) {
  7056. logStatus.success();
  7057. return true;
  7058. }
  7059. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7060. return false;
  7061. }
  7062. logStatus.error(`${result}:${statusText}(${status})`);
  7063. return false;
  7064. } catch (error) {
  7065. throwError(error, 'Freeanywhere.verify');
  7066. return false;
  7067. }
  7068. }
  7069. async #checkLeftKey() {
  7070. try {
  7071. if (!globalOptions.other.checkLeftKey) {
  7072. return true;
  7073. }
  7074. const {
  7075. data
  7076. } = await tools_httpRequest({
  7077. url: 'https://freeanywhere.net/api/v1/widget/?format=json',
  7078. method: 'GET',
  7079. dataType: 'json',
  7080. headers: {
  7081. authorization: `Token ${window.localStorage.getItem('token')}`
  7082. }
  7083. });
  7084. if (data?.response?.giveaways.find(giveaway => `${giveaway?.id}` === this.giveawayId)) {
  7085. return true;
  7086. }
  7087. await external_Swal_default().fire({
  7088. icon: 'warning',
  7089. title: i18n('notice'),
  7090. text: i18n('noKeysLeft'),
  7091. confirmButtonText: i18n('confirm'),
  7092. cancelButtonText: i18n('cancel'),
  7093. showCancelButton: true
  7094. }).then(({
  7095. value
  7096. }) => {
  7097. if (value) {
  7098. window.close();
  7099. }
  7100. });
  7101. return true;
  7102. } catch (error) {
  7103. throwError(error, 'Giveawaysu.checkLeftKey');
  7104. return false;
  7105. }
  7106. }
  7107. }
  7108. const Freeanywhere = FreeAnyWhere;
  7109. const Giveawaysu_defaultTasks = {
  7110. steam: {
  7111. groupLinks: [],
  7112. wishlistLinks: [],
  7113. curatorLinks: [],
  7114. curatorLikeLinks: [],
  7115. followLinks: [],
  7116. forumLinks: [],
  7117. announcementLinks: [],
  7118. workshopVoteLinks: [],
  7119. playtestLinks: []
  7120. },
  7121. discord: {
  7122. serverLinks: []
  7123. },
  7124. instagram: {
  7125. userLinks: []
  7126. },
  7127. vk: {
  7128. nameLinks: []
  7129. },
  7130. twitch: {
  7131. channelLinks: []
  7132. },
  7133. reddit: {
  7134. redditLinks: []
  7135. },
  7136. youtube: {
  7137. channelLinks: [],
  7138. likeLinks: []
  7139. },
  7140. twitter: {
  7141. userLinks: [],
  7142. retweetLinks: []
  7143. }
  7144. };
  7145. class GiveawaySu extends website_Website {
  7146. name = 'GiveawaySu';
  7147. socialTasks = Giveawaysu_defaultTasks;
  7148. undoneTasks = Giveawaysu_defaultTasks;
  7149. buttons = [ 'doTask', 'undoTask' ];
  7150. static test() {
  7151. return /^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(window.location.href);
  7152. }
  7153. async after() {
  7154. try {
  7155. if (!this.#checkLogin()) {
  7156. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7157. }
  7158. if (!await this.#checkLeftKey()) {
  7159. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7160. }
  7161. scripts_echoLog({}).warning(i18n('gsNotice'));
  7162. } catch (error) {
  7163. throwError(error, 'Giveawaysu.after');
  7164. }
  7165. }
  7166. init() {
  7167. try {
  7168. const logStatus = scripts_echoLog({
  7169. text: i18n('initing')
  7170. });
  7171. if ($('a.steam-login').length > 0) {
  7172. window.open('/steam/redirect', '_self');
  7173. logStatus.warning(i18n('needLogin'));
  7174. return false;
  7175. }
  7176. if (!this.#getGiveawayId()) {
  7177. return false;
  7178. }
  7179. this.initialized = true;
  7180. logStatus.success();
  7181. return true;
  7182. } catch (error) {
  7183. throwError(error, 'Giveawaysu.init');
  7184. return false;
  7185. }
  7186. }
  7187. async classifyTask(action) {
  7188. try {
  7189. const logStatus = scripts_echoLog({
  7190. text: i18n('getTasksInfo')
  7191. });
  7192. if (action === 'undo') {
  7193. this.socialTasks = GM_getValue(`gasTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  7194. return true;
  7195. }
  7196. const pro = [];
  7197. const tasks = $('#actions tr');
  7198. if ($('div.bind-discord').is(':visible')) {
  7199. $('div.bind-discord a')[0].click();
  7200. }
  7201. if ($('div.bind-twitch').is(':visible')) {
  7202. $('div.bind-twitch a')[0].click();
  7203. }
  7204. for (const task of tasks) {
  7205. pro.push(new Promise(resolve => {
  7206. const td = $(task).find('td:not(".hidden")');
  7207. const colorfulTask = td.eq(1).find('a:not([data-trigger="link"])');
  7208. const colorlessTask = td.eq(2).find('a:not([data-trigger="link"])');
  7209. const taskDes = colorfulTask.length > 0 ? colorfulTask : colorlessTask;
  7210. const taskIcon = td.eq(0).find('i').attr('class') || '';
  7211. const taskName = taskDes.text().trim();
  7212. if (taskIcon.includes('ban') || /disable adblock/gi.test(taskName)) {
  7213. return resolve(true);
  7214. }
  7215. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  7216. if (!taskLink) {
  7217. return resolve(false);
  7218. }
  7219. if (taskIcon.includes('steam') && /join/gi.test(taskName)) {
  7220. this.undoneTasks.steam.groupLinks.push(taskLink);
  7221. } else if (/like.*announcement/gi.test(taskName)) {
  7222. this.undoneTasks.steam.announcementLinks.push(taskLink);
  7223. } else if (/(follow|subscribe).*curator/gim.test(taskName) && /^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  7224. this.undoneTasks.steam.curatorLinks.push(taskLink);
  7225. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  7226. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  7227. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  7228. this.undoneTasks.steam.forumLinks.push(taskLink);
  7229. } else if (taskIcon.includes('thumbs-up') && /^https?:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=[\d]+/.test(taskLink)) {
  7230. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7231. } else if (taskIcon.includes('plus') && /request.*playtest/gim.test(taskName)) {
  7232. this.undoneTasks.steam.playtestLinks.push(taskLink);
  7233. } else if (taskIcon.includes('discord') || /join.*discord/gim.test(taskName)) {
  7234. this.undoneTasks.discord.serverLinks.push(taskLink);
  7235. } else if (taskIcon.includes('instagram') || /follow.*instagram/gim.test(taskName)) {
  7236. this.undoneTasks.instagram.userLinks.push(taskLink);
  7237. } else if (taskIcon.includes('twitch') || /follow.*twitch.*channel/gim.test(taskName)) {
  7238. this.undoneTasks.twitch.channelLinks.push(taskLink);
  7239. } else if (taskIcon.includes('reddit') || /subscribe.*subreddit/gim.test(taskName) || /follow.*reddit/gim.test(taskName)) {
  7240. this.undoneTasks.reddit.redditLinks.push(taskLink);
  7241. } else if (/watch.*art/gim.test(taskName)) {
  7242. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7243. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  7244. this.undoneTasks.youtube.channelLinks.push(taskLink);
  7245. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  7246. this.undoneTasks.youtube.likeLinks.push(taskLink);
  7247. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  7248. this.undoneTasks.vk.nameLinks.push(taskLink);
  7249. } else {
  7250. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  7251. if (/wishlist.*game|add.*wishlist/gim.test(taskName)) {
  7252. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  7253. }
  7254. if (/follow.*button/gim.test(taskName)) {
  7255. this.undoneTasks.steam.followLinks.push(taskLink);
  7256. }
  7257. }
  7258. }
  7259. resolve(true);
  7260. }).catch(error => {
  7261. throwError(error, 'Giveawaysu.classifyTask->getRedirectLink');
  7262. return false;
  7263. });
  7264. }));
  7265. }
  7266. await Promise.all(pro);
  7267. logStatus.success();
  7268. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7269. this.socialTasks = this.undoneTasks;
  7270. if (window.DEBUG) {
  7271. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7272. }
  7273. GM_setValue(`gasTasks-${this.giveawayId}`, {
  7274. tasks: this.socialTasks,
  7275. time: new Date().getTime()
  7276. });
  7277. return true;
  7278. } catch (error) {
  7279. throwError(error, 'Giveawaysu.classifyTask');
  7280. return false;
  7281. }
  7282. }
  7283. #checkLogin() {
  7284. try {
  7285. if (!globalOptions.other.checkLogin) {
  7286. return true;
  7287. }
  7288. if ($('a.steam-login').length > 0) {
  7289. window.open('/steam/redirect', '_self');
  7290. }
  7291. return true;
  7292. } catch (error) {
  7293. throwError(error, 'Giveawaysu.checkLogin');
  7294. return false;
  7295. }
  7296. }
  7297. async #checkLeftKey() {
  7298. try {
  7299. if (!globalOptions.other.checkLeftKey) {
  7300. return true;
  7301. }
  7302. if ($('.giveaway-ended').length > 0 && $('.giveaway-key').length === 0) {
  7303. await external_Swal_default().fire({
  7304. icon: 'warning',
  7305. title: i18n('notice'),
  7306. text: i18n('noKeysLeft'),
  7307. confirmButtonText: i18n('confirm'),
  7308. cancelButtonText: i18n('cancel'),
  7309. showCancelButton: true
  7310. }).then(({
  7311. value
  7312. }) => {
  7313. if (value) {
  7314. window.close();
  7315. }
  7316. });
  7317. }
  7318. return true;
  7319. } catch (error) {
  7320. throwError(error, 'Giveawaysu.checkLeftKey');
  7321. return false;
  7322. }
  7323. }
  7324. #getGiveawayId() {
  7325. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  7326. if (giveawayId) {
  7327. this.giveawayId = giveawayId;
  7328. return true;
  7329. }
  7330. scripts_echoLog({
  7331. text: i18n('getFailed', 'GiveawayId')
  7332. });
  7333. return false;
  7334. }
  7335. }
  7336. class Indiedb {
  7337. name = 'Indiedb';
  7338. buttons = [ 'doTask' ];
  7339. static test() {
  7340. return window.location.host === 'www.indiedb.com';
  7341. }
  7342. async after() {
  7343. try {
  7344. if (!this.#checkLogin()) {
  7345. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7346. }
  7347. if (!await this.#checkLeftKey()) {
  7348. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7349. }
  7350. } catch (error) {
  7351. throwError(error, 'Indiedb.after');
  7352. }
  7353. }
  7354. async doTask() {
  7355. try {
  7356. if (!await this.#join()) {
  7357. return false;
  7358. }
  7359. return await this.#do();
  7360. } catch (error) {
  7361. throwError(error, 'Indiedb.doTask');
  7362. return false;
  7363. }
  7364. }
  7365. async #join() {
  7366. try {
  7367. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7368. scripts_echoLog({}).error(i18n('needLogin'));
  7369. return false;
  7370. }
  7371. const currentoption = $('a.buttonenter.buttongiveaway');
  7372. if (/join giveaway/gim.test(currentoption.text())) {
  7373. const logStatus = scripts_echoLog({
  7374. text: `${i18n('joiningGiveaway')}...`
  7375. });
  7376. const {
  7377. result,
  7378. statusText,
  7379. status,
  7380. data
  7381. } = await tools_httpRequest({
  7382. url: currentoption.attr('href'),
  7383. method: 'POST',
  7384. data: 'ajax=t',
  7385. dataType: 'json',
  7386. headers: {
  7387. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  7388. accept: 'application/json, text/javascript, */*; q=0.01',
  7389. origin: window.location.origin
  7390. }
  7391. });
  7392. if (result === 'Success') {
  7393. if (data?.status === 200) {
  7394. if (data.response?.success) {
  7395. currentoption.addClass('buttonentered').text('Success - Giveaway joined');
  7396. $('#giveawaysjoined').slideDown();
  7397. $('#giveawaysrecommend').slideDown();
  7398. logStatus.success(`Success${data.response?.text ? `:${data.response?.text}` : ''}`);
  7399. return true;
  7400. }
  7401. logStatus.error(`Error${data.response?.text ? `:${data.response?.text}` : ''}`);
  7402. return false;
  7403. }
  7404. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7405. return false;
  7406. }
  7407. logStatus.error(`${result}:${statusText}(${status})`);
  7408. return false;
  7409. } else if (/success/gim.test($('a.buttonenter.buttongiveaway').text())) {
  7410. return true;
  7411. }
  7412. scripts_echoLog({}).warning(i18n('needJoinGiveaway'));
  7413. return false;
  7414. } catch (error) {
  7415. throwError(error, 'Indiedb.init');
  7416. return false;
  7417. }
  7418. }
  7419. async #do() {
  7420. try {
  7421. const id = $('script').map((index, script) => {
  7422. if (/\$\(document\)/gim.test(script.innerHTML)) {
  7423. return [ script.innerHTML.match(/"\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0], script.innerHTML.match(/"\/newsletter\/ajax\/subscribeprofile\/optin\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0] ];
  7424. }
  7425. return null;
  7426. });
  7427. if (id.length === 2) {
  7428. const pro = [];
  7429. const tasks = $('#giveawaysjoined a[class*=promo]');
  7430. for (const task of tasks) {
  7431. const promo = $(task);
  7432. if (!promo.hasClass('buttonentered')) {
  7433. const status = scripts_echoLog({
  7434. text: `${i18n('doing')}:${promo.parents('p').text()}...`
  7435. });
  7436. if (/facebookpromo|twitterpromo|visitpromo/gim.test(task.className)) {
  7437. let text = '';
  7438. if (promo.hasClass('facebookpromo')) {
  7439. text = 'facebookpromo';
  7440. } else if (promo.hasClass('twitterpromo')) {
  7441. text = 'twitterpromo';
  7442. } else {
  7443. text = 'visitpromo';
  7444. }
  7445. pro.push(new Promise(resolve => {
  7446. $.ajax({
  7447. type: 'POST',
  7448. url: urlPath(`/giveaways/ajax/${text}/${id[0]}`),
  7449. timeout: 6e4,
  7450. dataType: 'json',
  7451. data: {
  7452. ajax: 't'
  7453. },
  7454. error(response, error, exception) {
  7455. if (window.DEBUG) {
  7456. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7457. response: response,
  7458. error: error,
  7459. exception: exception
  7460. });
  7461. }
  7462. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7463. resolve(true);
  7464. },
  7465. success(response) {
  7466. if (response.success) {
  7467. status.success(`Success:${response.text}`);
  7468. promo.addClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7469. resolve(true);
  7470. } else {
  7471. status.error(`Error:${response.text}`);
  7472. resolve(true);
  7473. }
  7474. }
  7475. });
  7476. }));
  7477. } else if (promo.hasClass('emailoptinpromo')) {
  7478. pro.push(new Promise(resolve => {
  7479. $.ajax({
  7480. type: 'POST',
  7481. url: urlPath(`/newsletter/ajax/subscribeprofile/optin/${id[1]}`),
  7482. timeout: 6e4,
  7483. dataType: 'json',
  7484. data: {
  7485. ajax: 't',
  7486. emailsystoggle: 4
  7487. },
  7488. error(response, error, exception) {
  7489. if (window.DEBUG) {
  7490. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7491. response: response,
  7492. error: error,
  7493. exception: exception
  7494. });
  7495. }
  7496. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7497. resolve(true);
  7498. },
  7499. success(response) {
  7500. if (response.success) {
  7501. status.success(`Success:${response.text}`);
  7502. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7503. resolve(true);
  7504. } else {
  7505. status.error(`Error:${response.text}`);
  7506. resolve(true);
  7507. }
  7508. }
  7509. });
  7510. }));
  7511. } else if (promo.hasClass('watchingpromo')) {
  7512. pro.push(new Promise(resolve => {
  7513. const data = getUrlQuery(promo.attr('href'));
  7514. data.ajax = 't';
  7515. $.ajax({
  7516. type: 'POST',
  7517. url: urlPath(promo.attr('href')?.split(/[?#]/)[0]),
  7518. timeout: 6e4,
  7519. dataType: 'json',
  7520. data: data,
  7521. error(response, error, exception) {
  7522. if (window.DEBUG) {
  7523. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7524. response: response,
  7525. error: error,
  7526. exception: exception
  7527. });
  7528. }
  7529. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7530. resolve(true);
  7531. },
  7532. success(response) {
  7533. if (response.success) {
  7534. status.success(`Success:${response.text}`);
  7535. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7536. resolve(true);
  7537. } else {
  7538. status.error(`Error:${response.text}`);
  7539. resolve(true);
  7540. }
  7541. }
  7542. });
  7543. }));
  7544. } else if (!/the-challenge-of-adblock/gim.test(promo.attr('href'))) {
  7545. pro.push(new Promise(resolve => {
  7546. $.ajax({
  7547. type: 'POST',
  7548. url: urlPath(promo.attr('href')),
  7549. timeout: 6e4,
  7550. dataType: 'json',
  7551. data: {
  7552. ajax: 't'
  7553. },
  7554. error(response, error, exception) {
  7555. if (window.DEBUG) {
  7556. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7557. response: response,
  7558. error: error,
  7559. exception: exception
  7560. });
  7561. }
  7562. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7563. resolve(true);
  7564. },
  7565. success(response) {
  7566. if (response.success) {
  7567. status.success(`Success:${response.text}`);
  7568. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7569. resolve(true);
  7570. } else {
  7571. status.error(`Error:${response.text}`);
  7572. resolve(true);
  7573. }
  7574. }
  7575. });
  7576. }));
  7577. } else {
  7578. status.error(`Error:${i18n('unKnownTaskType')}`);
  7579. }
  7580. }
  7581. }
  7582. await Promise.all(pro);
  7583. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7584. return true;
  7585. }
  7586. scripts_echoLog({}).error(i18n('getFailed', 'TaskId'));
  7587. return false;
  7588. } catch (error) {
  7589. throwError(error, 'Indiedb.classifyTask');
  7590. return false;
  7591. }
  7592. }
  7593. #checkLogin() {
  7594. try {
  7595. if (!globalOptions.other.checkLogin) {
  7596. return true;
  7597. }
  7598. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7599. window.open('/members/login', '_self');
  7600. }
  7601. return true;
  7602. } catch (error) {
  7603. throwError(error, 'Indiedb.checkLogin');
  7604. return false;
  7605. }
  7606. }
  7607. async #checkLeftKey() {
  7608. try {
  7609. if (!globalOptions.other.checkLeftKey) {
  7610. return true;
  7611. }
  7612. if ($('a.buttonenter:contains("next time"),a.buttonenter:contains("Giveaway is closed")').length > 0) {
  7613. await external_Swal_default().fire({
  7614. icon: 'warning',
  7615. title: i18n('notice'),
  7616. text: i18n('giveawayEnded'),
  7617. confirmButtonText: i18n('confirm'),
  7618. cancelButtonText: i18n('cancel'),
  7619. showCancelButton: true
  7620. }).then(({
  7621. value
  7622. }) => {
  7623. if (value) {
  7624. window.close();
  7625. }
  7626. });
  7627. }
  7628. return true;
  7629. } catch (error) {
  7630. throwError(error, 'Indiedb.checkLeftKey');
  7631. return false;
  7632. }
  7633. }
  7634. }
  7635. const website_Indiedb = Indiedb;
  7636. const Keyhub_defaultTasksTemplate = {
  7637. steam: {
  7638. groupLinks: [],
  7639. officialGroupLinks: [],
  7640. wishlistLinks: [],
  7641. curatorLinks: []
  7642. },
  7643. discord: {
  7644. serverLinks: []
  7645. },
  7646. extra: {
  7647. videoTasks: []
  7648. },
  7649. links: []
  7650. };
  7651. const Keyhub_defaultTasks = JSON.stringify(Keyhub_defaultTasksTemplate);
  7652. class Keyhub extends website_Website {
  7653. name = 'Keyhub';
  7654. socialTasks = JSON.parse(Keyhub_defaultTasks);
  7655. undoneTasks = JSON.parse(Keyhub_defaultTasks);
  7656. buttons = [ 'doTask', 'undoTask' ];
  7657. static test() {
  7658. return window.location.host === 'key-hub.eu';
  7659. }
  7660. async after() {
  7661. try {
  7662. if (!this.#checkLogin()) {
  7663. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7664. }
  7665. if (!await this.#checkLeftKey()) {
  7666. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7667. }
  7668. $('.NSFW').hide();
  7669. } catch (error) {
  7670. throwError(error, 'Keyhub.after');
  7671. }
  7672. }
  7673. init() {
  7674. try {
  7675. const logStatus = scripts_echoLog({
  7676. text: i18n('initing')
  7677. });
  7678. if ($('a[href*="/connect/steam"]').length > 0) {
  7679. window.open('/connect/steam', '_self');
  7680. logStatus.warning(i18n('needLogin'));
  7681. return false;
  7682. }
  7683. if (!this.#getGiveawayId()) {
  7684. return false;
  7685. }
  7686. $('#VPNoverlay').hide();
  7687. $('#mainArticleSection').show();
  7688. this.initialized = true;
  7689. logStatus.success();
  7690. return true;
  7691. } catch (error) {
  7692. throwError(error, 'Keyhub.init');
  7693. return false;
  7694. }
  7695. }
  7696. async classifyTask(action) {
  7697. try {
  7698. const logStatus = scripts_echoLog({
  7699. text: i18n('getTasksInfo')
  7700. });
  7701. if (action === 'undo') {
  7702. this.socialTasks = GM_getValue(`khTasks-${this.giveawayId}`)?.tasks || JSON.parse(Keyhub_defaultTasks);
  7703. }
  7704. const tasks = $('.task:not(".googleads")').filter((index, element) => action === 'do' ? $(element).find('i.fa-check-circle:visible').length === 0 : true).find('a');
  7705. for (const task of tasks) {
  7706. let link = $(task).attr('href');
  7707. const taskDes = $(task).text().trim();
  7708. if (!link) {
  7709. continue;
  7710. }
  7711. if (/\/away\?data=/.test(link) || /steamcommunity\.com\/gid\//.test(link)) {
  7712. link = await getRedirectLink(link) || link;
  7713. }
  7714. if (/https?:\/\/key-hub\.eu\/connect\/discord/.test(link)) {
  7715. window.open(link, '_blank');
  7716. } else if (/steamcommunity\.com\/groups\//.test(link)) {
  7717. if (action === 'undo') {
  7718. this.socialTasks.steam.groupLinks.push(link);
  7719. }
  7720. if (action === 'do') {
  7721. this.undoneTasks.steam.groupLinks.push(link);
  7722. }
  7723. } else if (/steamcommunity\.com\/games\/[\d]+/.test(link)) {
  7724. if (action === 'undo') {
  7725. this.socialTasks.steam.officialGroupLinks.push(link);
  7726. }
  7727. if (action === 'do') {
  7728. this.undoneTasks.steam.officialGroupLinks.push(link);
  7729. }
  7730. } else if (/store\.steampowered\.com\/app\//.test(link) && /wishlist/gim.test(taskDes)) {
  7731. if (action === 'undo') {
  7732. this.socialTasks.steam.wishlistLinks.push(link);
  7733. }
  7734. if (action === 'do') {
  7735. this.undoneTasks.steam.wishlistLinks.push(link);
  7736. }
  7737. } else if (/store\.steampowered\.com\/curator\//.test(link)) {
  7738. if (action === 'undo') {
  7739. this.socialTasks.steam.curatorLinks.push(link);
  7740. }
  7741. if (action === 'do') {
  7742. this.undoneTasks.steam.curatorLinks.push(link);
  7743. }
  7744. } else if (/^https?:\/\/discord\.com\/invite\//.test(link)) {
  7745. if (action === 'undo') {
  7746. this.socialTasks.discord.serverLinks.push(link);
  7747. }
  7748. if (action === 'do') {
  7749. this.undoneTasks.discord.serverLinks.push(link);
  7750. }
  7751. } else if (/^javascript:videoTask.+/.test(link)) {
  7752. if (action === 'do') {
  7753. const taskData = link.match(/javascript:videoTask\('.+?','(.+?)'/)?.[1];
  7754. if (taskData) {
  7755. this.undoneTasks.extra.videoTasks.push(taskData);
  7756. }
  7757. }
  7758. } 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 {
  7759. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  7760. }
  7761. }
  7762. logStatus.success();
  7763. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7764. this.socialTasks = this.uniqueTasks(this.socialTasks);
  7765. if (window.DEBUG) {
  7766. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7767. }
  7768. GM_setValue(`khTasks-${this.giveawayId}`, {
  7769. tasks: this.socialTasks,
  7770. time: new Date().getTime()
  7771. });
  7772. return true;
  7773. } catch (error) {
  7774. throwError(error, 'Keyhub.classifyTask');
  7775. return false;
  7776. }
  7777. }
  7778. async #doScriptTask(data) {
  7779. try {
  7780. const logStatus = scripts_echoLog({
  7781. text: i18n('doingKeyhubTask')
  7782. });
  7783. const {
  7784. result,
  7785. statusText,
  7786. status,
  7787. data: response
  7788. } = await tools_httpRequest({
  7789. url: `/away?data=${data}`,
  7790. method: 'GET',
  7791. headers: {
  7792. origin: 'https://key-hub.eu',
  7793. referer: 'https://key-hub.eu/'
  7794. }
  7795. });
  7796. if (result === 'Success') {
  7797. if (response?.status === 200) {
  7798. logStatus.success();
  7799. return true;
  7800. }
  7801. logStatus.error(`Error:${response?.statusText}(${response?.status})`);
  7802. return false;
  7803. }
  7804. logStatus.error(`${result}:${statusText}(${status})`);
  7805. return false;
  7806. } catch (error) {
  7807. throwError(error, 'Keyhub.doScriptTask');
  7808. return false;
  7809. }
  7810. }
  7811. async extraDoTask({
  7812. videoTasks
  7813. }) {
  7814. try {
  7815. const pro = [];
  7816. for (const data of videoTasks) {
  7817. pro.push(this.#doScriptTask(data));
  7818. }
  7819. return Promise.all(pro).then(() => true);
  7820. } catch (error) {
  7821. throwError(error, 'Keyhub.extraDoTask');
  7822. return false;
  7823. }
  7824. }
  7825. #getGiveawayId() {
  7826. try {
  7827. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  7828. if (giveawayId) {
  7829. this.giveawayId = giveawayId;
  7830. return true;
  7831. }
  7832. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7833. return false;
  7834. } catch (error) {
  7835. throwError(error, 'Keyhub.getGiveawayId');
  7836. return false;
  7837. }
  7838. }
  7839. async #checkLeftKey() {
  7840. try {
  7841. if (!globalOptions.other.checkLeftKey) {
  7842. return true;
  7843. }
  7844. const leftKey = $('#keysleft').text().trim();
  7845. if (leftKey === '0') {
  7846. await external_Swal_default().fire({
  7847. icon: 'warning',
  7848. title: i18n('notice'),
  7849. text: i18n('noKeysLeft'),
  7850. confirmButtonText: i18n('confirm'),
  7851. cancelButtonText: i18n('cancel'),
  7852. showCancelButton: true
  7853. }).then(({
  7854. value
  7855. }) => {
  7856. if (value) {
  7857. window.close();
  7858. }
  7859. });
  7860. }
  7861. return true;
  7862. } catch (error) {
  7863. throwError(error, 'Keyhub.checkLeftKey');
  7864. return false;
  7865. }
  7866. }
  7867. #checkLogin() {
  7868. try {
  7869. if (!globalOptions.other.checkLogin) {
  7870. return true;
  7871. }
  7872. if ($('a[href*="/connect/steam"]').length > 0) {
  7873. window.open('/connect/steam', '_self');
  7874. }
  7875. return true;
  7876. } catch (error) {
  7877. throwError(error, 'Keyhub.checkLogin');
  7878. return false;
  7879. }
  7880. }
  7881. }
  7882. const website_Keyhub = Keyhub;
  7883. const Givekey_defaultTasksTemplate = {
  7884. steam: {
  7885. groupLinks: [],
  7886. wishlistLinks: [],
  7887. curatorLinks: [],
  7888. curatorLikeLinks: []
  7889. },
  7890. twitter: {
  7891. userLinks: []
  7892. },
  7893. vk: {
  7894. nameLinks: []
  7895. },
  7896. discord: {
  7897. serverLinks: []
  7898. }
  7899. };
  7900. const Givekey_defaultTasks = JSON.stringify(Givekey_defaultTasksTemplate);
  7901. class Givekey extends website_Website {
  7902. name = 'Givekey';
  7903. tasks = [];
  7904. socialTasks = JSON.parse(Givekey_defaultTasks);
  7905. undoneTasks = JSON.parse(Givekey_defaultTasks);
  7906. userId;
  7907. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  7908. static test() {
  7909. return window.location.host === 'givekey.ru';
  7910. }
  7911. async after() {
  7912. try {
  7913. await new Promise(resolve => {
  7914. const checker = setInterval(() => {
  7915. if ($('#navbarDropdown').length > 0) {
  7916. clearInterval(checker);
  7917. resolve(true);
  7918. }
  7919. });
  7920. });
  7921. if (!await this.#checkLeftKey()) {
  7922. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7923. }
  7924. } catch (error) {
  7925. throwError(error, 'Givekey.after');
  7926. return false;
  7927. }
  7928. }
  7929. init() {
  7930. try {
  7931. const logStatus = scripts_echoLog({
  7932. text: i18n('initing')
  7933. });
  7934. if ($('a[href*="/auth/steam"]').length > 0) {
  7935. window.open('/auth/steam', '_self');
  7936. logStatus.warning(i18n('needLogin'));
  7937. return false;
  7938. }
  7939. if (!this.#getGiveawayId()) {
  7940. return false;
  7941. }
  7942. const userId = $('meta[name="user-id"]').attr('content');
  7943. if (!userId) {
  7944. logStatus.error(i18n('getFailed', i18n('userId')));
  7945. return false;
  7946. }
  7947. this.userId = userId;
  7948. this.initialized = true;
  7949. logStatus.success();
  7950. return true;
  7951. } catch (error) {
  7952. throwError(error, 'Givekey.init');
  7953. return false;
  7954. }
  7955. }
  7956. async classifyTask(action) {
  7957. try {
  7958. const logStatus = scripts_echoLog({
  7959. text: i18n('getTasksInfo')
  7960. });
  7961. if (action === 'undo') {
  7962. this.socialTasks = GM_getValue(`gkTasks-${this.giveawayId}`)?.tasks || JSON.parse(Givekey_defaultTasks);
  7963. }
  7964. const tasks = $('.card-body:has("button") .row');
  7965. for (const task of tasks) {
  7966. const taskEle = $(task);
  7967. const isSuccess = /Complete/i.test(taskEle.find('button').text().trim());
  7968. if (isSuccess && action !== 'undo') {
  7969. continue;
  7970. }
  7971. const checkButton = taskEle.find('#task_check');
  7972. const taskId = checkButton.attr('data-id');
  7973. if (taskId) {
  7974. this.tasks.push(taskId);
  7975. }
  7976. if (action === 'verify') {
  7977. continue;
  7978. }
  7979. let href = taskEle.find('a').attr('href') || null;
  7980. const text = taskEle.find('a').text().trim();
  7981. const icon = taskEle.find('i');
  7982. if (!href || !text) {
  7983. continue;
  7984. }
  7985. if (/^https?:\/\/givekey\.ru\/giveaway\/[\d]+\/execution_task/.test(href)) {
  7986. href = await getRedirectLink(href);
  7987. }
  7988. if (!href) {
  7989. continue;
  7990. }
  7991. if (/^https?:\/\/vk\.com\//.test(href)) {
  7992. this.socialTasks.vk.nameLinks.push(href);
  7993. if (action === 'do' && !isSuccess) {
  7994. this.undoneTasks.vk.nameLinks.push(href);
  7995. }
  7996. } else if (/^https?:\/\/steamcommunity\.com\/groups/.test(href)) {
  7997. this.socialTasks.steam.groupLinks.push(href);
  7998. if (action === 'do' && !isSuccess) {
  7999. this.undoneTasks.steam.groupLinks.push(href);
  8000. }
  8001. } else if (/^https?:\/\/store\.steampowered\.com\/app\//.test(href)) {
  8002. this.socialTasks.steam.wishlistLinks.push(href);
  8003. if (action === 'do' && !isSuccess) {
  8004. this.undoneTasks.steam.wishlistLinks.push(href);
  8005. }
  8006. } else if (/Subscribe/gi.test(text) && icon.hasClass('fa-steam-square')) {
  8007. if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(href)) {
  8008. this.socialTasks.steam.curatorLinks.push(href);
  8009. if (action === 'do' && !isSuccess) {
  8010. this.undoneTasks.steam.curatorLinks.push(href);
  8011. }
  8012. } else {
  8013. this.socialTasks.steam.curatorLikeLinks.push(href);
  8014. if (action === 'do' && !isSuccess) {
  8015. this.undoneTasks.steam.curatorLikeLinks.push(href);
  8016. }
  8017. }
  8018. } else if (/^https?:\/\/twitter\.com\//.test(href) && /Subscribe/gi.test(text)) {
  8019. this.socialTasks.twitter.userLinks.push(href);
  8020. if (action === 'do' && !isSuccess) {
  8021. this.undoneTasks.twitter.userLinks.push(href);
  8022. }
  8023. } else if (icon.hasClass('fa-discord') || /^https?:\/\/discord\.com\/invite\//.test(href)) {
  8024. this.socialTasks.discord.serverLinks.push(href);
  8025. if (action === 'do' && !isSuccess) {
  8026. this.undoneTasks.discord.serverLinks.push(href);
  8027. }
  8028. } else {
  8029. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${text}(${href})`);
  8030. }
  8031. }
  8032. logStatus.success();
  8033. this.tasks = unique(this.tasks);
  8034. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8035. this.socialTasks = this.uniqueTasks(this.socialTasks);
  8036. if (window.DEBUG) {
  8037. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8038. }
  8039. GM_setValue(`gkTasks-${this.giveawayId}`, {
  8040. tasks: this.socialTasks,
  8041. time: new Date().getTime()
  8042. });
  8043. return true;
  8044. } catch (error) {
  8045. throwError(error, 'Givekey.classifyTask');
  8046. return false;
  8047. }
  8048. }
  8049. async verifyTask() {
  8050. try {
  8051. if (!this.initialized && !this.init()) {
  8052. return false;
  8053. }
  8054. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  8055. return false;
  8056. }
  8057. scripts_echoLog({}).warning(i18n('giveKeyNoticeBefore'));
  8058. const taskLength = this.tasks.length;
  8059. for (let i = 0; i < taskLength; i++) {
  8060. await this.#verify(this.tasks[i]);
  8061. if (i < taskLength - 1) {
  8062. await delay(15e3);
  8063. }
  8064. }
  8065. scripts_echoLog({}).success(i18n('allTasksComplete'));
  8066. scripts_echoLog({
  8067. html: `<li><font class="warning">${i18n('giveKeyNoticeAfter')}</font></li>`
  8068. });
  8069. return true;
  8070. } catch (error) {
  8071. throwError(error, 'Givekey.verifyTask');
  8072. return false;
  8073. }
  8074. }
  8075. async #verify(task) {
  8076. try {
  8077. const logStatus = scripts_echoLog({
  8078. html: `<li>${i18n('verifyingTask')}${task}...<font></font></li>`
  8079. });
  8080. return await new Promise(resolve => {
  8081. $.ajax({
  8082. url: 'https://givekey.ru/giveaway/task',
  8083. method: 'POST',
  8084. data: `id=${task}&user_id=${this.userId}`,
  8085. dataType: 'json',
  8086. headers: {
  8087. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  8088. },
  8089. success: data => {
  8090. if (data.btn) {
  8091. $(`button[data-id=${this.userId}]`).html(data.btn);
  8092. }
  8093. if (data.status === 'ok') {
  8094. $(`.task_check_${data.id}`).html(`<button class="btn btn-success mb-2 btn-block" disabled>${data.btn}</button>`);
  8095. logStatus.success();
  8096. resolve(true);
  8097. } else if (data.status === 'end') {
  8098. logStatus.success();
  8099. scripts_echoLog({}).success(data.key);
  8100. resolve(true);
  8101. } else {
  8102. logStatus.error(`Error:${data.msg}`);
  8103. resolve(false);
  8104. }
  8105. },
  8106. error: xhr => {
  8107. logStatus.error(`Error:${xhr.statusText}(${xhr.status})`);
  8108. resolve(false);
  8109. }
  8110. });
  8111. });
  8112. } catch (error) {
  8113. throwError(error, 'Givekey.verify');
  8114. return false;
  8115. }
  8116. }
  8117. #getGiveawayId() {
  8118. try {
  8119. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  8120. if (giveawayId) {
  8121. this.giveawayId = giveawayId;
  8122. return true;
  8123. }
  8124. scripts_echoLog({
  8125. text: i18n('getFailed', 'GiveawayId')
  8126. });
  8127. return false;
  8128. } catch (error) {
  8129. throwError(error, 'Givekey.getGiveawayId');
  8130. return false;
  8131. }
  8132. }
  8133. async #checkLeftKey() {
  8134. try {
  8135. if (!globalOptions.other.checkLeftKey) {
  8136. return true;
  8137. }
  8138. if (!$('#keys_count').text()) {
  8139. await external_Swal_default().fire({
  8140. icon: 'warning',
  8141. title: i18n('notice'),
  8142. text: i18n('noKeysLeft'),
  8143. confirmButtonText: i18n('confirm'),
  8144. cancelButtonText: i18n('cancel'),
  8145. showCancelButton: true
  8146. }).then(({
  8147. value
  8148. }) => {
  8149. if (value) {
  8150. window.close();
  8151. }
  8152. });
  8153. }
  8154. return true;
  8155. } catch (error) {
  8156. throwError(error, 'Givekey.checkLeftKey');
  8157. return false;
  8158. }
  8159. }
  8160. }
  8161. const website_Givekey = Givekey;
  8162. class GiveeClub extends GiveawaySu {
  8163. name = 'GiveeClub';
  8164. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  8165. static test() {
  8166. return /^https?:\/\/givee\.club\/.*?\/event\/[\d]+/.test(window.location.href);
  8167. }
  8168. async after() {
  8169. try {
  8170. if (!this.#checkLogin()) {
  8171. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8172. }
  8173. if (!await this.#checkLeftKey()) {
  8174. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  8175. }
  8176. } catch (error) {
  8177. throwError(error, 'GiveeClub.after');
  8178. }
  8179. }
  8180. init() {
  8181. try {
  8182. const logStatus = scripts_echoLog({
  8183. text: i18n('initing')
  8184. });
  8185. if (!this.#checkLogin()) {
  8186. logStatus.warning(i18n('needLogin'));
  8187. return false;
  8188. }
  8189. if (!this.#getGiveawayId()) {
  8190. return false;
  8191. }
  8192. this.initialized = true;
  8193. logStatus.success();
  8194. return true;
  8195. } catch (error) {
  8196. throwError(error, 'GiveeClub.init');
  8197. return false;
  8198. }
  8199. }
  8200. async classifyTask(action) {
  8201. try {
  8202. const logStatus = scripts_echoLog({
  8203. text: i18n('getTasksInfo')
  8204. });
  8205. if (action === 'undo') {
  8206. this.socialTasks = GM_getValue(`gcTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  8207. return true;
  8208. }
  8209. const pro = [];
  8210. const tasks = $('.event-actions tr');
  8211. for (const task of tasks) {
  8212. pro.push(new Promise(resolve => {
  8213. const taskDes = $(task).find('.event-action-label a');
  8214. const taskIcon = $(task).find('.event-action-icon i').attr('class') || '';
  8215. const taskName = taskDes.text().trim();
  8216. const taskType = $(task).find('button[data-type]')?.attr('data-type');
  8217. const taskFinished = $(task).find('.event-action-buttons .btn-success')?.length;
  8218. if (taskIcon.includes('ban') || /AdBlock/i.test(taskName) || taskIcon.includes('envelope') || taskFinished) {
  8219. return resolve(true);
  8220. }
  8221. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  8222. if (!taskLink) {
  8223. return resolve(false);
  8224. }
  8225. if (taskType === 'steam.group.join' && /^https?:\/\/steamcommunity\.com\/groups/.test(taskLink)) {
  8226. this.undoneTasks.steam.groupLinks.push(taskLink);
  8227. } else if (/like.*announcement/gi.test(taskName)) {
  8228. this.undoneTasks.steam.announcementLinks.push(taskLink);
  8229. } else if (taskType === 'steam.game.wishlist' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8230. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  8231. } else if (taskType === 'steam.game.wishlist' && taskDes.attr('data-steam-wishlist-appid')) {
  8232. this.undoneTasks.steam.wishlistLinks.push(`https://store.steampowered.com/app/${taskDes.attr('data-steam-wishlist-appid')}`);
  8233. } else if (taskType === 'steam.game.follow' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8234. this.undoneTasks.steam.followLinks.push(taskLink);
  8235. } else if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  8236. this.undoneTasks.steam.curatorLinks.push(taskLink);
  8237. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  8238. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  8239. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  8240. this.undoneTasks.steam.forumLinks.push(taskLink);
  8241. } else if (taskIcon.includes('discord')) {
  8242. this.undoneTasks.discord.serverLinks.push(taskLink);
  8243. } else if (taskIcon.includes('instagram')) {
  8244. this.undoneTasks.instagram.userLinks.push(taskLink);
  8245. } else if (taskIcon.includes('twitch')) {
  8246. this.undoneTasks.twitch.channelLinks.push(taskLink);
  8247. } else if (taskIcon.includes('reddit')) {
  8248. this.undoneTasks.reddit.redditLinks.push(taskLink);
  8249. } else if (/watch.*art/gim.test(taskName)) {
  8250. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8251. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  8252. this.undoneTasks.youtube.channelLinks.push(taskLink);
  8253. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  8254. this.undoneTasks.youtube.likeLinks.push(taskLink);
  8255. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  8256. this.undoneTasks.vk.nameLinks.push(taskLink);
  8257. } else if (taskIcon.includes('twitter')) {
  8258. if (/https?:\/\/twitter\.com\/[^/]+\/?$/gim.test(taskLink)) {
  8259. this.undoneTasks.twitter.userLinks.push(taskLink);
  8260. } else if (/https?:\/\/twitter\.com\/[^/]+?\/status\/[\d]+/gim.test(taskLink)) {
  8261. this.undoneTasks.twitter.retweetLinks.push(taskLink);
  8262. }
  8263. } else {
  8264. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  8265. if (/follow.*button/gim.test(taskName)) {
  8266. this.undoneTasks.steam.followLinks.push(taskLink);
  8267. }
  8268. }
  8269. }
  8270. resolve(true);
  8271. }).catch(error => {
  8272. throwError(error, 'GiveeClub.classifyTask->getRedirectLink');
  8273. return false;
  8274. });
  8275. }));
  8276. }
  8277. await Promise.all(pro);
  8278. logStatus.success();
  8279. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8280. this.socialTasks = this.undoneTasks;
  8281. if (window.DEBUG) {
  8282. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8283. }
  8284. GM_setValue(`gcTasks-${this.giveawayId}`, {
  8285. tasks: this.socialTasks,
  8286. time: new Date().getTime()
  8287. });
  8288. return true;
  8289. } catch (error) {
  8290. throwError(error, 'GiveeClub.classifyTask');
  8291. return false;
  8292. }
  8293. }
  8294. async verifyTask() {
  8295. try {
  8296. const logStatus = scripts_echoLog({
  8297. text: i18n('giveeClubVerifyNotice')
  8298. });
  8299. const taskButtons = $('.event-actions tr button').has('i.glyphicon-refresh').not('[data-type="user.adblock"]');
  8300. for (const button of taskButtons) {
  8301. button.click();
  8302. if ($(button).attr('data-type') !== 'steam.game.wishlist') {
  8303. await delay(1e3);
  8304. }
  8305. }
  8306. logStatus.warning(i18n('giveeClubVerifyFinished'));
  8307. return true;
  8308. } catch (error) {
  8309. throwError(error, 'Givekey.verifyTask');
  8310. return false;
  8311. }
  8312. }
  8313. #checkLogin() {
  8314. try {
  8315. if (!globalOptions.other.checkLogin) {
  8316. return true;
  8317. }
  8318. if ($('a[href*="/account/auth"]').length > 0) {
  8319. window.open($('a[href*="/account/auth"]').attr('href'), '_self');
  8320. }
  8321. return true;
  8322. } catch (error) {
  8323. throwError(error, 'GiveeClub.checkLogin');
  8324. return false;
  8325. }
  8326. }
  8327. #getGiveawayId() {
  8328. const giveawayId = window.location.href.match(/\/event\/([\d]+)/)?.[1];
  8329. if (giveawayId) {
  8330. this.giveawayId = giveawayId;
  8331. return true;
  8332. }
  8333. scripts_echoLog({
  8334. text: i18n('getFailed', 'GiveawayId')
  8335. });
  8336. return false;
  8337. }
  8338. async #checkLeftKey() {
  8339. try {
  8340. if (!globalOptions.other.checkLeftKey) {
  8341. return true;
  8342. }
  8343. if ($('.event-ended').length > 0 && $('.event-winner').length === 0) {
  8344. await external_Swal_default().fire({
  8345. icon: 'warning',
  8346. title: i18n('notice'),
  8347. text: i18n('giveawayEnded'),
  8348. confirmButtonText: i18n('confirm'),
  8349. cancelButtonText: i18n('cancel'),
  8350. showCancelButton: true
  8351. }).then(({
  8352. value
  8353. }) => {
  8354. if (value) {
  8355. window.close();
  8356. }
  8357. });
  8358. }
  8359. return true;
  8360. } catch (error) {
  8361. throwError(error, 'Giveawaysu.checkLeftKey');
  8362. return false;
  8363. }
  8364. }
  8365. }
  8366. const website_GiveeClub = GiveeClub;
  8367. const defaultOptions = {
  8368. maxPoint: '99999999'
  8369. };
  8370. class OpiumPulses {
  8371. name = 'OpiumPulses';
  8372. options = {
  8373. ...defaultOptions,
  8374. ...GM_getValue('OpiumPulsesOptions')
  8375. };
  8376. maxPoints = 99999999;
  8377. myPoints = 0;
  8378. buttons = [ 'doFreeTask', 'doPointTask' ];
  8379. static test() {
  8380. return window.location.host === 'www.opiumpulses.com';
  8381. }
  8382. async after() {
  8383. try {
  8384. if (!this.#checkLogin()) {
  8385. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8386. }
  8387. this.maxPoints = parseInt(this.options.maxPoint, 10);
  8388. } catch (error) {
  8389. throwError(error, 'OpiumPulses.after');
  8390. }
  8391. }
  8392. async doFreeTask() {
  8393. try {
  8394. this.#toggleTask('FREE');
  8395. } catch (error) {
  8396. throwError(error, 'OpiumPulses.doFreeTask');
  8397. }
  8398. }
  8399. async doPointTask() {
  8400. try {
  8401. this.myPoints = parseInt($('.page-header__nav-func-user-nav-items.points-items').text().match(/[\d]+/gim)?.[0] || '0', 10);
  8402. this.#toggleTask('points');
  8403. } catch (error) {
  8404. throwError(error, 'OpiumPulses.doPointTask');
  8405. }
  8406. }
  8407. async #toggleTask(type) {
  8408. try {
  8409. const items = $(`.giveaways-page-item:contains('${type}'):not(:contains('ENTERED'))`);
  8410. for (const item of items) {
  8411. const needPoints = parseInt($(item).find('.giveaways-page-item-header-points').text().match(/[\d]+/gim)?.[0] || '999999', 10);
  8412. const name = $(item).find('.giveaways-page-item-footer-name').text().trim();
  8413. if (type === 'points' && needPoints > this.myPoints) {
  8414. scripts_echoLog({}).warning(`${i18n('noPoints')}: ${name}`);
  8415. } else if (type === 'points' && !needPoints) {
  8416. scripts_echoLog({}).warning(`${i18n('getNeedPointsFailed')}: ${name}`);
  8417. } else if (!(type === 'points' && needPoints > this.maxPoints)) {
  8418. const logStatus = scripts_echoLog({
  8419. text: `${i18n('joiningLottery')}<a href="${$(item).find('a.giveaways-page-item-img-btn-more').attr('href')}" target="_blank">${name}</a>...`
  8420. });
  8421. const aElement = $(item).find('a.giveaways-page-item-img-btn-enter:contains(\'enter\')');
  8422. if (aElement?.attr('onclick')?.includes('checkUser')) {
  8423. const giveawayId = aElement.attr('onclick')?.match(/[\d]+/)?.[0];
  8424. if (giveawayId) {
  8425. checkUser(giveawayId);
  8426. }
  8427. }
  8428. if (!aElement.attr('href')) {
  8429. logStatus.error('Error: No "href".');
  8430. continue;
  8431. }
  8432. const {
  8433. result,
  8434. statusText,
  8435. status,
  8436. data
  8437. } = await tools_httpRequest({
  8438. url: aElement.attr('href'),
  8439. method: 'GET'
  8440. });
  8441. if (result === 'Success') {
  8442. const {
  8443. result: result0,
  8444. statusText: statusText0,
  8445. status: status0,
  8446. data: data0
  8447. } = await tools_httpRequest({
  8448. url: data?.finalUrl,
  8449. method: 'GET'
  8450. });
  8451. if (data0?.responseText && /You've entered this giveaway/gim.test(data0.responseText)) {
  8452. logStatus.success();
  8453. const points = data0.responseText.match(/Points:[\s]*?([\d]+)/)?.[1];
  8454. if (type === 'points' && points) {
  8455. this.myPoints = parseInt(points, 10);
  8456. }
  8457. } else if (data0?.responseText && /You're not eligible to enter/gim.test(data0.responseText)) {
  8458. logStatus.error('You\'re not eligible to enter');
  8459. } else {
  8460. logStatus.error(`${result0}:${statusText0}(${status0})`);
  8461. }
  8462. } else {
  8463. logStatus.error(`${result}:${statusText}(${status})`);
  8464. }
  8465. }
  8466. }
  8467. scripts_echoLog({
  8468. text: '-----END-----'
  8469. });
  8470. } catch (error) {
  8471. throwError(error, 'OpiumPulses.toggleTask');
  8472. }
  8473. }
  8474. init() {
  8475. return true;
  8476. }
  8477. classifyTask() {
  8478. return true;
  8479. }
  8480. #checkLogin() {
  8481. try {
  8482. if (!globalOptions.other.checkLogin) {
  8483. return true;
  8484. }
  8485. if ($('a[href*="/site/login"]').length > 1) {
  8486. window.open('/site/login', '_self');
  8487. }
  8488. return true;
  8489. } catch (error) {
  8490. throwError(error, 'OpiumPulses.checkLogin');
  8491. return false;
  8492. }
  8493. }
  8494. }
  8495. const website_OpiumPulses = OpiumPulses;
  8496. const external_dayjs_namespaceObject = dayjs;
  8497. var external_dayjs_default = __webpack_require__.n(external_dayjs_namespaceObject);
  8498. const leftKeyChecker = {
  8499. async classify(link) {
  8500. try {
  8501. if (/^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(link)) {
  8502. return await this.giveawaySu(link);
  8503. }
  8504. if (/^https?:\/\/givee\.club\/[\w]+?\/event\/[\d]+/.test(link)) {
  8505. return await this.giveeClub(link);
  8506. }
  8507. if (/^https?:\/\/gleam\.io\/.+?\/.+/.test(link)) {
  8508. return await this.gleam(link);
  8509. }
  8510. if (/^https?:\/\/www\.indiedb\.com\/giveaways\/.+/.test(link)) {
  8511. return await this.indieDb(link);
  8512. }
  8513. if (/^https?:\/\/key-hub\.eu\/giveaway\/[\d]+/.test(link)) {
  8514. return await this.keyhub(link);
  8515. }
  8516. if (/^https?:\/\/opquests\.com\/quests\/[\d]+/.test(link)) {
  8517. return await this.opquests(link);
  8518. }
  8519. if (/^https?:\/\/itch\.io\/s\/[\d]+?\/.*/.test(link)) {
  8520. return await this.itch(link);
  8521. }
  8522. return false;
  8523. } catch (error) {
  8524. throwError(error, 'leftKeyChecker.classify');
  8525. return false;
  8526. }
  8527. },
  8528. async giveawaySu(link) {
  8529. try {
  8530. const {
  8531. result,
  8532. data
  8533. } = await tools_httpRequest({
  8534. url: link,
  8535. method: 'GET'
  8536. });
  8537. if (result === 'Success' && data?.status === 200) {
  8538. if (data.responseText.includes('class="steam-login"')) {
  8539. return false;
  8540. }
  8541. if (data.responseText.includes('class="giveaway-ended"')) {
  8542. return 'Ended';
  8543. }
  8544. return 'Active';
  8545. }
  8546. return false;
  8547. } catch (error) {
  8548. throwError(error, 'leftKeyChecker.giveawaySu');
  8549. return false;
  8550. }
  8551. },
  8552. async giveeClub(link) {
  8553. try {
  8554. const {
  8555. result,
  8556. data
  8557. } = await tools_httpRequest({
  8558. url: link,
  8559. method: 'GET'
  8560. });
  8561. if (result === 'Success' && data?.status === 200) {
  8562. if (data.responseText.includes('class="event-winner"')) {
  8563. return 'Won';
  8564. }
  8565. if (data.responseText.includes('class="event-ended"')) {
  8566. return 'Ended';
  8567. }
  8568. return 'Active';
  8569. }
  8570. return false;
  8571. } catch (error) {
  8572. throwError(error, 'leftKeyChecker.giveeClub');
  8573. return false;
  8574. }
  8575. },
  8576. async gleam(link) {
  8577. try {
  8578. const {
  8579. result,
  8580. data
  8581. } = await tools_httpRequest({
  8582. url: link,
  8583. method: 'GET'
  8584. });
  8585. if (result === 'Success' && data?.status === 200) {
  8586. if (/incentives&quot;:{&quot;[\d]+?&quot;:\[&quot;.+?&quot;\]/.test(data.responseText)) {
  8587. return 'Won';
  8588. }
  8589. const campaignDiv = data.responseText.match(/<div class='popup-blocks-container'[\w\W]+?'>/)?.[0];
  8590. if (!campaignDiv) {
  8591. return false;
  8592. }
  8593. const campaignString = $(campaignDiv).attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  8594. if (!campaignString) {
  8595. return false;
  8596. }
  8597. const {
  8598. campaign
  8599. } = JSON.parse(campaignString);
  8600. if (campaign.banned) {
  8601. return 'Banned';
  8602. }
  8603. if (campaign.finished) {
  8604. return 'Ended';
  8605. }
  8606. if (campaign.paused) {
  8607. return 'Paused';
  8608. }
  8609. if (new Date().getTime() < campaign.starts_at * 1e3) {
  8610. return 'NotStart';
  8611. }
  8612. return 'Active';
  8613. }
  8614. return false;
  8615. } catch (error) {
  8616. throwError(error, 'leftKeyChecker.gleam');
  8617. return false;
  8618. }
  8619. },
  8620. async indieDb(link) {
  8621. try {
  8622. const {
  8623. result,
  8624. data
  8625. } = await tools_httpRequest({
  8626. url: link,
  8627. method: 'GET'
  8628. });
  8629. if (result === 'Success' && data?.status === 200) {
  8630. if (data.responseText.includes('Congrats you WON')) {
  8631. return 'Won';
  8632. }
  8633. if (data.responseText.includes('Giveaway is closed') || data.responseText.includes('next time')) {
  8634. return 'Ended';
  8635. }
  8636. return 'Active';
  8637. }
  8638. return false;
  8639. } catch (error) {
  8640. throwError(error, 'leftKeyChecker.indieDb');
  8641. return false;
  8642. }
  8643. },
  8644. async keyhub(link) {
  8645. try {
  8646. const {
  8647. result,
  8648. data
  8649. } = await tools_httpRequest({
  8650. url: link,
  8651. method: 'GET'
  8652. });
  8653. if (result === 'Success' && data?.status === 200) {
  8654. const keysleft = data.responseText.match(/<span id="keysleft">([\d]+?)<\/span>/)?.[1];
  8655. if (!keysleft) {
  8656. return false;
  8657. }
  8658. if (keysleft === '0') {
  8659. return 'Ended';
  8660. }
  8661. return `Active(${keysleft})`;
  8662. }
  8663. return false;
  8664. } catch (error) {
  8665. throwError(error, 'leftKeyChecker.keyhub');
  8666. return false;
  8667. }
  8668. },
  8669. async opquests(link) {
  8670. try {
  8671. const {
  8672. result,
  8673. data
  8674. } = await tools_httpRequest({
  8675. url: link,
  8676. method: 'GET'
  8677. });
  8678. if (result === 'Success' && data?.status === 200) {
  8679. const keysleft = data.responseText.match(/<div class="">[\s]*?([\d]+?)[\s]*?of/)?.[1];
  8680. if (!keysleft) {
  8681. return false;
  8682. }
  8683. if (keysleft === '0') {
  8684. return 'Ended';
  8685. }
  8686. return `Active(${keysleft})`;
  8687. } else if (data?.status === 404) {
  8688. return 'Ended';
  8689. }
  8690. return false;
  8691. } catch (error) {
  8692. throwError(error, 'leftKeyChecker.opquests');
  8693. return false;
  8694. }
  8695. },
  8696. async itch(link) {
  8697. try {
  8698. const {
  8699. result,
  8700. data
  8701. } = await tools_httpRequest({
  8702. url: link,
  8703. method: 'GET'
  8704. });
  8705. if (result === 'Success' && data?.status === 200) {
  8706. const endDate = data.responseText.match(/{"start_date":"[0-9A-Z-:]+?".*?"end_date":"([0-9A-Z-:]+?)".*?}/)?.[1];
  8707. if (!endDate) {
  8708. return false;
  8709. }
  8710. if (new Date().getTime() > new Date(endDate).getTime()) {
  8711. return 'Ended';
  8712. }
  8713. return `Active(${external_dayjs_default()(endDate).format('YYYY-MM-DD HH:mm:ss')})`;
  8714. }
  8715. return false;
  8716. } catch (error) {
  8717. throwError(error, 'leftKeyChecker.opquests');
  8718. return false;
  8719. }
  8720. }
  8721. };
  8722. const website_leftKeyChecker = leftKeyChecker;
  8723. const Keylol_defaultTasksTemplate = {
  8724. steam: {
  8725. groupLinks: [],
  8726. wishlistLinks: [],
  8727. curatorLinks: [],
  8728. curatorLikeLinks: [],
  8729. followLinks: [],
  8730. forumLinks: [],
  8731. announcementLinks: [],
  8732. workshopVoteLinks: [],
  8733. licenseLinks: []
  8734. },
  8735. discord: {
  8736. serverLinks: []
  8737. },
  8738. instagram: {
  8739. userLinks: []
  8740. },
  8741. vk: {
  8742. nameLinks: []
  8743. },
  8744. twitch: {
  8745. channelLinks: []
  8746. },
  8747. reddit: {
  8748. redditLinks: []
  8749. },
  8750. twitter: {
  8751. userLinks: [],
  8752. retweetLinks: []
  8753. },
  8754. youtube: {
  8755. channelLinks: [],
  8756. likeLinks: []
  8757. }
  8758. };
  8759. const Keylol_defaultTasks = JSON.stringify(Keylol_defaultTasksTemplate);
  8760. class Keylol extends website_Website {
  8761. name = 'Keylol';
  8762. socialTasks = JSON.parse(Keylol_defaultTasks);
  8763. undoneTasks = JSON.parse(Keylol_defaultTasks);
  8764. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect' ];
  8765. static test() {
  8766. 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'));
  8767. }
  8768. init() {
  8769. return true;
  8770. }
  8771. after() {
  8772. try {
  8773. const selector = this.name === 'Keylol' ? '#postlist>div[id^="post_"]:first' : 'div.container';
  8774. const mainPost = $(selector);
  8775. const discordLinks = mainPost.find('a[href*="discord.com"]:visible');
  8776. const redditLinks = mainPost.find('a[href*="reddit.com"]:visible');
  8777. const insLinks = mainPost.find('a[href*="instagram.com"]:visible');
  8778. const twitterLinks = mainPost.find('a[href*="twitter.com"]:visible,a[href*="x.com"]:visible');
  8779. const twitchLinks = mainPost.find('a[href*="twitch.tv"]:visible');
  8780. const vkLinks = mainPost.find('a[href*="vk.com"]:visible');
  8781. const steamStoreLinks = mainPost.find('a[href*="store.steampowered.com"]:visible');
  8782. const steamCommunityLinks = mainPost.find('a[href*="steamcommunity.com"]:visible');
  8783. const ytbLinks = mainPost.find('a[href*="youtube.com"]:visible');
  8784. if (discordLinks.length > 0) {
  8785. for (const discordLink of discordLinks) {
  8786. const link = $(discordLink).attr('href');
  8787. if (!(link && /^https?:\/\/discord\.com\/invite\/.+/.test(link))) {
  8788. continue;
  8789. }
  8790. this.#addBtn(discordLink, 'discord', 'serverLinks', link);
  8791. }
  8792. }
  8793. if (redditLinks.length > 0) {
  8794. for (const redditLink of redditLinks) {
  8795. const link = $(redditLink).attr('href');
  8796. if (!(link && /^https?:\/\/www\.reddit\.com\/(r|user)\/.+/.test(link))) {
  8797. continue;
  8798. }
  8799. this.#addBtn(redditLink, 'reddit', 'redditLinks', link);
  8800. }
  8801. }
  8802. if (insLinks.length > 0) {
  8803. for (const insLink of insLinks) {
  8804. const link = $(insLink).attr('href');
  8805. if (!(link && /^https:\/\/www\.instagram\.com\/.+/.test(link))) {
  8806. continue;
  8807. }
  8808. this.#addBtn(insLink, 'instagram', 'userLinks', link);
  8809. }
  8810. }
  8811. if (twitterLinks.length > 0) {
  8812. for (const twitterLink of twitterLinks) {
  8813. const link = $(twitterLink).attr('href');
  8814. if (!(link && /^https:\/\/twitter\.com\/.+/.test(link))) {
  8815. continue;
  8816. }
  8817. if (/https:\/\/twitter\.com\/.*?\/status\/[\d]+/.test(link)) {
  8818. this.#addBtn(twitterLink, 'twitter', 'retweetLinks', link);
  8819. } else {
  8820. this.#addBtn(twitterLink, 'twitter', 'userLinks', link);
  8821. }
  8822. }
  8823. }
  8824. if (twitchLinks.length > 0) {
  8825. for (const twitchLink of twitchLinks) {
  8826. const link = $(twitchLink).attr('href');
  8827. if (!(link && /^https:\/\/(www\.)?twitch\.tv\/.+/.test(link))) {
  8828. continue;
  8829. }
  8830. this.#addBtn(twitchLink, 'twitch', 'channelLinks', link);
  8831. }
  8832. }
  8833. if (vkLinks.length > 0) {
  8834. for (const vkLink of vkLinks) {
  8835. const link = $(vkLink).attr('href');
  8836. if (!(link && /^https:\/\/vk\.com\/.+/.test(link))) {
  8837. continue;
  8838. }
  8839. this.#addBtn(vkLink, 'vk', 'nameLinks', link);
  8840. }
  8841. }
  8842. if (steamStoreLinks.length > 0) {
  8843. for (const steamStoreLink of steamStoreLinks) {
  8844. const link = $(steamStoreLink).attr('href');
  8845. if (!link) {
  8846. continue;
  8847. }
  8848. if (/curator\/[\d]+/.test(link)) {
  8849. this.#addBtn(steamStoreLink, 'steam', 'curatorLinks', link);
  8850. } else if (/(publisher|developer|franchise)\/.+/.test(link)) {
  8851. this.#addBtn(steamStoreLink, 'steam', 'curatorLikeLinks', link);
  8852. } else if (/news(hub)?\/app\/[\d]+\/view\/[\d]+/.test(link)) {
  8853. this.#addBtn(steamStoreLink, 'steam', 'announcementLinks', link);
  8854. } else if (/app\/[\d]+/.test(link)) {
  8855. this.#addBtn(steamStoreLink, 'steam', 'followLinks', link);
  8856. this.#addBtn(steamStoreLink, 'steam', 'wishlistLinks', link);
  8857. }
  8858. }
  8859. }
  8860. if (steamCommunityLinks.length > 0) {
  8861. for (const steamCommunityLink of steamCommunityLinks) {
  8862. const link = $(steamCommunityLink).attr('href');
  8863. if (!link) {
  8864. continue;
  8865. }
  8866. if (/groups\/.+/.test(link)) {
  8867. this.#addBtn(steamCommunityLink, 'steam', 'groupLinks', link);
  8868. } else if (/announcements\/detail\/[\d]+/.test(link)) {
  8869. this.#addBtn(steamCommunityLink, 'steam', 'announcementLinks', link);
  8870. }
  8871. }
  8872. }
  8873. if (ytbLinks.length > 0) {
  8874. for (const ytbLink of ytbLinks) {
  8875. const link = $(ytbLink).attr('href');
  8876. if (!link) {
  8877. continue;
  8878. }
  8879. this.#addBtn(ytbLink, 'youtube', 'channelLinks', link);
  8880. this.#addBtn(ytbLink, 'youtube', 'likeLinks', link);
  8881. }
  8882. }
  8883. 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');
  8884. if (giveawayLinks.length > 0) {
  8885. for (const giveawayLink of giveawayLinks) {
  8886. const link = $(giveawayLink).attr('href');
  8887. if (!link) {
  8888. continue;
  8889. }
  8890. website_leftKeyChecker.classify(link).then(status => {
  8891. if (!status) {
  8892. return;
  8893. }
  8894. if (/^Active/.test(status)) {
  8895. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status active" title="${i18n('Active')}">${status}</font>`);
  8896. return;
  8897. }
  8898. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status not-active" title="${i18n(status)}">${status}</font>`);
  8899. }).catch(error => {
  8900. throwError(error, 'keylol.after -> leftKeyChecker');
  8901. });
  8902. }
  8903. }
  8904. if (this.name === 'Keylol') {
  8905. const asfLinks = mainPost.find('a[href^="#asf"]:visible');
  8906. if (asfLinks.length > 0) {
  8907. for (const asfLink of asfLinks) {
  8908. const link = $(asfLink).attr('href');
  8909. if (!link) {
  8910. continue;
  8911. }
  8912. this.#addBtn($(`a[href="${link}"]`).after('<span style="color: #ccc; margin: 0 -5px 0 5px"> | </span>').next()[0], 'steam', 'licenseLinks', `appid-${link.replace('#asf', '')}`);
  8913. }
  8914. }
  8915. const subLinks = mainPost.find('a[href*="steamdb.info/sub/"]:visible');
  8916. if (subLinks.length > 0) {
  8917. for (const subLink of subLinks) {
  8918. const link = $(subLink).attr('href');
  8919. if (!link) {
  8920. continue;
  8921. }
  8922. const subid = link.match(/^https:\/\/steamdb\.info\/sub\/([\d]+)/)?.[1];
  8923. if (!subid) {
  8924. continue;
  8925. }
  8926. this.#addBtn(subLink, 'steam', 'licenseLinks', `subid-${subid}`);
  8927. }
  8928. }
  8929. const asfLinks2 = mainPost.find('.blockcode:contains("addlicense"):visible');
  8930. if (asfLinks2.length > 0) {
  8931. for (const asfLink of asfLinks2) {
  8932. const subid = asfLink.innerText.match(/[\d]+/g);
  8933. if (!subid || subid.length === 0) {
  8934. continue;
  8935. }
  8936. this.#addBtn($(asfLink).children('em')[0], 'steam', 'licenseLinks', `subid-${subid.join(',')}`);
  8937. }
  8938. }
  8939. }
  8940. } catch (error) {
  8941. throwError(error, 'keylol.after');
  8942. }
  8943. }
  8944. classifyTask(action) {
  8945. try {
  8946. this.socialTasks = JSON.parse(Keylol_defaultTasks);
  8947. this.undoneTasks = JSON.parse(Keylol_defaultTasks);
  8948. const selectedBtns = $('.auto-task-keylol[selected="selected"]:visible');
  8949. for (const btn of selectedBtns) {
  8950. const button = $(btn);
  8951. const social = button.attr('data-social');
  8952. const type = button.attr('data-type');
  8953. const link = button.attr('data-link');
  8954. if (!(social && type && link)) {
  8955. continue;
  8956. }
  8957. if (action === 'do') {
  8958. this.undoneTasks[social][type].push(link);
  8959. }
  8960. if (action === 'undo') {
  8961. this.socialTasks[social][type].push(link);
  8962. }
  8963. }
  8964. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8965. this.socialTasks = this.uniqueTasks(this.socialTasks);
  8966. if (window.DEBUG) {
  8967. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8968. }
  8969. return true;
  8970. } catch (error) {
  8971. throwError(error, 'Keylol.classifyTask');
  8972. return false;
  8973. }
  8974. }
  8975. selectAll() {
  8976. try {
  8977. $('.auto-task-keylol:visible').attr('selected', 'selected');
  8978. } catch (error) {
  8979. throwError(error, 'Keylol.selectAll');
  8980. }
  8981. }
  8982. selectNone() {
  8983. try {
  8984. $('.auto-task-keylol:visible').removeAttr('selected');
  8985. } catch (error) {
  8986. throwError(error, 'Keylol.selectNone');
  8987. }
  8988. }
  8989. invertSelect() {
  8990. try {
  8991. $('.auto-task-keylol:visible').each((index, element) => {
  8992. element.getAttribute('selected') ? element.removeAttribute('selected') : element.setAttribute('selected', 'selected');
  8993. });
  8994. } catch (error) {
  8995. throwError(error, 'Keylol.invertSelect');
  8996. }
  8997. }
  8998. #addBtn(before, social, linkType, link) {
  8999. try {
  9000. $(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>`);
  9001. } catch (error) {
  9002. throwError(error, 'keylol.addBtn');
  9003. }
  9004. }
  9005. }
  9006. const website_Keylol = Keylol;
  9007. const Opquests_defaultTasks = {
  9008. steam: {
  9009. groupLinks: [],
  9010. wishlistLinks: [],
  9011. followLinks: [],
  9012. curatorLikeLinks: []
  9013. }
  9014. };
  9015. class Opquests extends website_Website {
  9016. name = 'Opquests';
  9017. undoneTasks = {
  9018. ...Opquests_defaultTasks
  9019. };
  9020. buttons = [ 'doTask', 'verifyTask', 'getKey' ];
  9021. static test() {
  9022. return window.location.host === 'opquests.com';
  9023. }
  9024. async before() {
  9025. const opquestsVerifyTasks = GM_getValue('opquestsVerifyTasks') || [];
  9026. if (opquestsVerifyTasks.length > 0) {
  9027. const taskId = opquestsVerifyTasks.pop();
  9028. GM_setValue('opquestsVerifyTasks', opquestsVerifyTasks);
  9029. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9030. } else {
  9031. if (GM_getValue('opquestsVerifyTasks')) {
  9032. GM_deleteValue('opquestsVerifyTasks');
  9033. }
  9034. }
  9035. }
  9036. async after() {
  9037. try {
  9038. if (!this.#checkLogin()) {
  9039. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9040. }
  9041. } catch (error) {
  9042. throwError(error, 'Opquests.after');
  9043. }
  9044. }
  9045. init() {
  9046. try {
  9047. const logStatus = scripts_echoLog({
  9048. text: i18n('initing')
  9049. });
  9050. if ($('a[href*="/auth/redirect"]').length > 0) {
  9051. window.open('/auth/redirect', '_self');
  9052. logStatus.warning(i18n('needLogin'));
  9053. return false;
  9054. }
  9055. if (!this.#getGiveawayId()) {
  9056. return false;
  9057. }
  9058. this.initialized = true;
  9059. logStatus.success();
  9060. return true;
  9061. } catch (error) {
  9062. throwError(error, 'Opquests.init');
  9063. return false;
  9064. }
  9065. }
  9066. async classifyTask(action) {
  9067. try {
  9068. if (action === 'undo') {
  9069. scripts_echoLog({
  9070. text: i18n('cannotUndo')
  9071. });
  9072. return false;
  9073. }
  9074. const logStatus = scripts_echoLog({
  9075. text: i18n('getTasksInfo')
  9076. });
  9077. const tasks = $('.w-full:contains("Validate") .items-center');
  9078. for (const task of tasks) {
  9079. const link = $(task).find('a:contains("Open")').attr('href');
  9080. const taskDes = $(task).find('div').eq(1).text().trim();
  9081. if (!link) {
  9082. continue;
  9083. }
  9084. if (/steamcommunity\.com\/groups\//.test(link)) {
  9085. this.undoneTasks.steam.groupLinks.push(link);
  9086. } else if (/store\.steampowered\.com\/app\//.test(link)) {
  9087. if (/wishlist/gim.test(taskDes)) {
  9088. this.undoneTasks.steam.wishlistLinks.push(link);
  9089. } else if (/follow/gim.test(taskDes)) {
  9090. this.undoneTasks.steam.followLinks.push(link);
  9091. }
  9092. } else if (/store\.steampowered\.com\/(publisher|developer|curator)\//.test(link) && /follow/gim.test(taskDes)) {
  9093. this.undoneTasks.steam.curatorLikeLinks.push(link);
  9094. } else {
  9095. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  9096. }
  9097. }
  9098. logStatus.success();
  9099. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9100. if (window.DEBUG) {
  9101. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9102. }
  9103. return true;
  9104. } catch (error) {
  9105. throwError(error, 'Opquests.classifyTask');
  9106. return false;
  9107. }
  9108. }
  9109. async verifyTask() {
  9110. try {
  9111. if (!this.initialized) {
  9112. this.init();
  9113. }
  9114. const tasks = $.makeArray($('div.w-full').find('.items-center').has('button.submit-loader')).map(ele => $(ele).find('input[name="task_id"]').val());
  9115. await this.#confirm();
  9116. const taskId = tasks.pop();
  9117. GM_setValue('opquestsVerifyTasks', tasks);
  9118. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9119. return true;
  9120. } catch (error) {
  9121. throwError(error, 'Opquests.verifyTask');
  9122. return false;
  9123. }
  9124. }
  9125. async #confirm() {
  9126. try {
  9127. const logStatus = scripts_echoLog({
  9128. html: `<li>${i18n('confirmingTask')}...<font></font></li>`
  9129. });
  9130. const {
  9131. result,
  9132. statusText,
  9133. status,
  9134. data
  9135. } = await tools_httpRequest({
  9136. url: `https://opquests.com/quests/${this.giveawayId}?confirm=1`,
  9137. method: 'GET',
  9138. nochche: true,
  9139. headers: {
  9140. origin: 'https://opquests.com',
  9141. referer: `https://opquests.com/warning?id=${this.giveawayId}`
  9142. }
  9143. });
  9144. if (result === 'Success') {
  9145. if (data?.status === 200) {
  9146. logStatus.success();
  9147. return true;
  9148. }
  9149. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9150. return false;
  9151. }
  9152. logStatus.error(`${result}:${statusText}(${status})`);
  9153. return false;
  9154. } catch (error) {
  9155. throwError(error, 'Opquests.confirm');
  9156. return false;
  9157. }
  9158. }
  9159. async getKey(isButton) {
  9160. try {
  9161. const logStatus = scripts_echoLog({
  9162. text: i18n('gettingKey')
  9163. });
  9164. const {
  9165. result,
  9166. statusText,
  9167. status,
  9168. data
  9169. } = await tools_httpRequest({
  9170. url: 'https://opquests.com/keys',
  9171. method: 'GET'
  9172. });
  9173. if (result === 'Success') {
  9174. if (data?.responseText) {
  9175. const key = $(data?.responseText).find(`div.items-center:contains("${$('h1.font-bold').text().trim().replace(' Quest', '')}")`).find('div.font-bold').next().text();
  9176. if (!key) {
  9177. logStatus.error('Error: Key was not found');
  9178. if (isButton) {
  9179. window.open('https://opquests.com/keys', '_self');
  9180. }
  9181. return false;
  9182. }
  9183. logStatus.success();
  9184. scripts_echoLog({}).success(key);
  9185. return true;
  9186. }
  9187. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9188. return false;
  9189. }
  9190. logStatus.error(`${result}:${statusText}(${status})`);
  9191. return false;
  9192. } catch (error) {
  9193. throwError(error, 'Opquests.getGiveawayId');
  9194. return false;
  9195. }
  9196. }
  9197. #getGiveawayId() {
  9198. try {
  9199. const giveawayId = window.location.href.match(/quests\/([\d]+)/)?.[1];
  9200. if (giveawayId) {
  9201. this.giveawayId = giveawayId;
  9202. return true;
  9203. }
  9204. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  9205. return false;
  9206. } catch (error) {
  9207. throwError(error, 'Opquests.getGiveawayId');
  9208. return false;
  9209. }
  9210. }
  9211. #checkLogin() {
  9212. try {
  9213. if (!globalOptions.other.checkLogin) {
  9214. return true;
  9215. }
  9216. if ($('a[href*="/auth/redirect"]').length > 0) {
  9217. window.open('/auth/redirect', '_self');
  9218. }
  9219. return true;
  9220. } catch (error) {
  9221. throwError(error, 'Opquests.checkLogin');
  9222. return false;
  9223. }
  9224. }
  9225. }
  9226. const website_Opquests = Opquests;
  9227. const Gleam_defaultTasksTemplate = {
  9228. steam: {
  9229. groupLinks: [],
  9230. wishlistLinks: [],
  9231. followLinks: [],
  9232. curatorLinks: [],
  9233. curatorLikeLinks: []
  9234. },
  9235. twitter: {
  9236. userLinks: [],
  9237. retweetLinks: []
  9238. },
  9239. twitch: {
  9240. channelLinks: []
  9241. },
  9242. discord: {
  9243. serverLinks: []
  9244. },
  9245. youtube: {
  9246. channelLinks: []
  9247. },
  9248. extra: {
  9249. gleam: []
  9250. }
  9251. };
  9252. const Gleam_defaultTasks = JSON.stringify(Gleam_defaultTasksTemplate);
  9253. class Gleam extends website_Website {
  9254. name = 'Gleam';
  9255. undoneTasks = JSON.parse(Gleam_defaultTasks);
  9256. socialTasks = JSON.parse(Gleam_defaultTasks);
  9257. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  9258. static test() {
  9259. return window.location.host === 'gleam.io';
  9260. }
  9261. before() {
  9262. unsafeWindow.confirm = () => {};
  9263. unsafeWindow.alert = () => {};
  9264. unsafeWindow.prompt = () => {};
  9265. }
  9266. async after() {
  9267. try {
  9268. if (window.location.search.includes('8b07d23f4bfa65f9')) {
  9269. const checkComplete = setInterval(() => {
  9270. if ($('.entry-content .entry-method i.fa-check').length > 0) {
  9271. clearInterval(checkComplete);
  9272. window.close();
  9273. }
  9274. });
  9275. for (const task of $('.entry-content .entry-method')) {
  9276. const taskInfo = $(task).find('.user-links');
  9277. const expandInfo = $(task).find('.expandable');
  9278. const aElements = expandInfo.find('a.btn,a:contains(Continue),button:contains(Continue)');
  9279. if (aElements.length > 0) {
  9280. for (const element of aElements) {
  9281. const $element = $(element);
  9282. const href = $element.attr('href');
  9283. $element.removeAttr('href')[0].click();
  9284. $element.attr('href', href);
  9285. await delay(1e3);
  9286. }
  9287. }
  9288. taskInfo[0].click();
  9289. await delay(1e3);
  9290. }
  9291. scripts_echoLog({}).warning(i18n('gleamTaskNotice'));
  9292. } else if (!await this.#checkLeftKey()) {
  9293. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  9294. }
  9295. } catch (error) {
  9296. throwError(error, 'Gleam.after');
  9297. return false;
  9298. }
  9299. }
  9300. init() {
  9301. try {
  9302. const logStatus = scripts_echoLog({
  9303. text: i18n('initing')
  9304. });
  9305. if (!this.#getGiveawayId()) {
  9306. return false;
  9307. }
  9308. this.initialized = true;
  9309. logStatus.success();
  9310. return true;
  9311. } catch (error) {
  9312. throwError(error, 'Gleam.init');
  9313. return false;
  9314. }
  9315. }
  9316. async classifyTask(action) {
  9317. try {
  9318. const logStatus = scripts_echoLog({
  9319. text: i18n('getTasksInfo')
  9320. });
  9321. if (action === 'undo') {
  9322. this.socialTasks = GM_getValue(`gleamTasks-${this.giveawayId}`)?.tasks || JSON.parse(Gleam_defaultTasks);
  9323. }
  9324. const tasks = $('.entry-content .entry-method');
  9325. for (const task of tasks) {
  9326. const $task = $(task);
  9327. if (action === 'do' && $task.find('i.fa-question').length === 0) {
  9328. continue;
  9329. }
  9330. const socialIcon = $task.find('.icon-wrapper i');
  9331. const taskInfo = $task.find('.user-links');
  9332. const taskText = taskInfo.text().trim();
  9333. const expandInfo = $task.find('.expandable');
  9334. const aElements = expandInfo.find('a.btn');
  9335. if (aElements.length > 0) {
  9336. for (const element of aElements) {
  9337. const $element = $(element);
  9338. const href = $element.attr('href');
  9339. $element.removeAttr('href')[0].click();
  9340. $element.attr('href', href);
  9341. }
  9342. }
  9343. if (socialIcon.hasClass('fa-twitter') || socialIcon.hasClass('fa-x-twitter')) {
  9344. const link = $task.find('a[href^="https://twitter.com/"],a[href^="https://x.com/"]').attr('href');
  9345. if (!link) {
  9346. continue;
  9347. }
  9348. if (/follow/gi.test(taskText)) {
  9349. if (action === 'undo') {
  9350. this.socialTasks.twitter.userLinks.push(link);
  9351. }
  9352. if (action === 'do') {
  9353. this.undoneTasks.twitter.userLinks.push(link);
  9354. }
  9355. } else if (/retweet/gim.test(taskText)) {
  9356. if (action === 'undo') {
  9357. this.socialTasks.twitter.retweetLinks.push(link);
  9358. }
  9359. if (action === 'do') {
  9360. this.undoneTasks.twitter.retweetLinks.push(link);
  9361. }
  9362. }
  9363. } else if (socialIcon.hasClass('fa-twitch')) {
  9364. if (/follow/gim.test(taskText)) {
  9365. const link = $task.find('a[href^="https://twitch.tv/"]').attr('href');
  9366. if (!link) {
  9367. continue;
  9368. }
  9369. if (action === 'undo') {
  9370. this.socialTasks.twitch.channelLinks.push(link);
  9371. }
  9372. if (action === 'do') {
  9373. this.undoneTasks.twitch.channelLinks.push(link);
  9374. }
  9375. }
  9376. } else if (socialIcon.hasClass('fa-discord')) {
  9377. if (/join/gim.test(taskText)) {
  9378. let link = $task.find('a[href^="https://discord.com/invite/"]').attr('href');
  9379. if (!link) {
  9380. const ggLink = $task.find('a[href^="https://discord.gg/"]').attr('href')?.match(/discord\.gg\/([^/]+)/)?.[1];
  9381. if (!ggLink) {
  9382. continue;
  9383. }
  9384. link = `https://discord.com/invite/${ggLink}`;
  9385. }
  9386. if (action === 'undo') {
  9387. this.socialTasks.discord.serverLinks.push(link);
  9388. }
  9389. if (action === 'do') {
  9390. this.undoneTasks.discord.serverLinks.push(link);
  9391. }
  9392. }
  9393. } else if (socialIcon.hasClass('fa-external-link-square-alt')) {
  9394. continue;
  9395. } else if (socialIcon.hasClass('fa-youtube')) {
  9396. if (/subscribe/gim.test(taskText)) {
  9397. const link = $task.find('a[href^="https://www.youtube.com/channel/"]').attr('href');
  9398. if (!link) {
  9399. continue;
  9400. }
  9401. if (action === 'undo') {
  9402. this.socialTasks.youtube.channelLinks.push(link);
  9403. }
  9404. if (action === 'do') {
  9405. this.undoneTasks.youtube.channelLinks.push(link);
  9406. }
  9407. }
  9408. } else if (socialIcon.attr('class')?.includes('steam')) {
  9409. if (/join.*group/gi.test(taskText)) {
  9410. const link = $task.find('a[href^="https://steamcommunity.com/groups/"]').attr('href');
  9411. if (!link) {
  9412. continue;
  9413. }
  9414. if (action === 'undo') {
  9415. this.socialTasks.steam.groupLinks.push(link);
  9416. }
  9417. if (action === 'do') {
  9418. this.undoneTasks.steam.groupLinks.push(link);
  9419. }
  9420. } else if (/follow.*curator/gi.test(taskText)) {
  9421. const link = $task.find('a[href^="https://store.steampowered.com/curator/"]').attr('href');
  9422. if (!link) {
  9423. continue;
  9424. }
  9425. if (action === 'undo') {
  9426. this.socialTasks.steam.curatorLinks.push(link);
  9427. }
  9428. if (action === 'do') {
  9429. this.undoneTasks.steam.curatorLinks.push(link);
  9430. }
  9431. }
  9432. } else if (socialIcon.hasClass('fa-bullhorn') && /Complete/gi.test(taskText)) {
  9433. if (action !== 'do') {
  9434. continue;
  9435. }
  9436. const gleamLink = await this.#getGleamLink(taskText);
  9437. if (!gleamLink) {
  9438. continue;
  9439. }
  9440. this.undoneTasks.extra.gleam.push(gleamLink);
  9441. } else if (socialIcon.hasClass('fa-question') || socialIcon.hasClass('fa-reddit') || socialIcon.hasClass('fa-instagram') || socialIcon.hasClass('fa-facebook-f') || socialIcon.hasClass('fa-telegram-plane') || socialIcon.hasClass('fa-telegram') || socialIcon.hasClass('fa-vk') || socialIcon.hasClass('fa-envelope') || socialIcon.hasClass('fa-gift') || socialIcon.hasClass('fa-square-up-right') || socialIcon.hasClass('fa-gamepad-modern') || socialIcon.hasClass('fa-dollar-sign') || socialIcon.hasClass('fa-tiktok') || socialIcon.hasClass('fa-gamepad-alt') || socialIcon.hasClass('fa-shield') && taskText.includes('one of our giveaways') || socialIcon.hasClass('fa-shield') && taskText.includes('Check out') || socialIcon.hasClass('fa-shield') && taskText.includes('vloot.io')) {} else {
  9442. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskText}`);
  9443. }
  9444. }
  9445. logStatus.success();
  9446. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9447. this.socialTasks = this.uniqueTasks(this.socialTasks);
  9448. if (window.DEBUG) {
  9449. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9450. }
  9451. GM_setValue(`gleamTasks-${this.giveawayId}`, {
  9452. tasks: this.socialTasks,
  9453. time: new Date().getTime()
  9454. });
  9455. return true;
  9456. } catch (error) {
  9457. throwError(error, 'Gleam.classifyTask');
  9458. return false;
  9459. }
  9460. }
  9461. async extraDoTask({
  9462. gleam
  9463. }) {
  9464. try {
  9465. const pro = [];
  9466. for (const link of gleam) {
  9467. pro.push(this.#doGleamTask(link));
  9468. }
  9469. return Promise.all(pro).then(() => true);
  9470. } catch (error) {
  9471. throwError(error, 'Gleam.extraDoTask');
  9472. return false;
  9473. }
  9474. }
  9475. async verifyTask() {
  9476. try {
  9477. scripts_echoLog({
  9478. text: `${i18n('verifyingTask')}...`
  9479. });
  9480. const tasks = $('.entry-content .entry-method');
  9481. unsafeWindow._OxA = '_OxA';
  9482. for (const task of tasks) {
  9483. if ($('[campaign-key="campaign.key"]').length > 0) {
  9484. return scripts_echoLog({
  9485. text: i18n('campaign')
  9486. });
  9487. }
  9488. const $task = $(task);
  9489. if ($task.find('i.fa-question').length === 0) {
  9490. continue;
  9491. }
  9492. const taskInfo = $task.find('.user-links');
  9493. taskInfo[0].click();
  9494. unsafeWindow.$hookTimer?.setSpeed(1e3);
  9495. await delay(3e3);
  9496. unsafeWindow.$hookTimer?.setSpeed(1);
  9497. const expandInfo = $task.find('.expandable');
  9498. const input = expandInfo.find('input')[0];
  9499. if (input) {
  9500. const evt = new Event('input', {
  9501. bubbles: true,
  9502. cancelable: true,
  9503. composed: true
  9504. });
  9505. const valuelimit = [ ...expandInfo.text().matchAll(/"(.+?)"/g) ].at(-1)?.[1];
  9506. input.value = valuelimit || 'vloot';
  9507. input.dispatchEvent(evt);
  9508. await delay(1e3);
  9509. }
  9510. await this.#checkSync();
  9511. const continueBtn = $task.find('.expandable').find('span:contains(Continue),button:contains(Continue)');
  9512. for (const button of continueBtn) {
  9513. button.click();
  9514. await delay(500);
  9515. await this.#checkSync();
  9516. }
  9517. }
  9518. scripts_echoLog({
  9519. text: i18n('verifiedGleamTasks')
  9520. });
  9521. } catch (error) {
  9522. throwError(error, 'Gleam.verifyTask');
  9523. return false;
  9524. }
  9525. }
  9526. async #checkSync() {
  9527. try {
  9528. return await new Promise(resolve => {
  9529. const checker = setInterval(() => {
  9530. if ($('.entry-content .entry-method i.fa-sync').length === 0) {
  9531. clearInterval(checker);
  9532. resolve(true);
  9533. }
  9534. }, 500);
  9535. });
  9536. } catch (error) {
  9537. throwError(error, 'Gleam.checkSync');
  9538. return false;
  9539. }
  9540. }
  9541. async #doGleamTask(link) {
  9542. try {
  9543. const logStatus = scripts_echoLog({
  9544. text: i18n('doingGleamTask')
  9545. });
  9546. return await new Promise(resolve => {
  9547. GM_openInTab(`${link}?8b07d23f4bfa65f9`, {
  9548. active: true,
  9549. insert: true,
  9550. setParent: true
  9551. }).onclose = () => {
  9552. logStatus.success();
  9553. resolve(true);
  9554. };
  9555. });
  9556. } catch (error) {
  9557. throwError(error, 'Gleam.doGleamTask');
  9558. return false;
  9559. }
  9560. }
  9561. #getGiveawayId() {
  9562. try {
  9563. const giveawayId = window.location.pathname;
  9564. if (giveawayId) {
  9565. this.giveawayId = giveawayId;
  9566. return true;
  9567. }
  9568. scripts_echoLog({
  9569. text: i18n('getFailed', 'GiveawayId')
  9570. });
  9571. return false;
  9572. } catch (error) {
  9573. throwError(error, 'Gleam.getGiveawayId');
  9574. return false;
  9575. }
  9576. }
  9577. async #getGleamLink(title) {
  9578. try {
  9579. const logStatus = scripts_echoLog({
  9580. text: i18n('gettingGleamLink')
  9581. });
  9582. const {
  9583. result,
  9584. statusText,
  9585. status,
  9586. data
  9587. } = await tools_httpRequest({
  9588. url: 'https://www.vloot.io/api/v1/giveaways',
  9589. method: 'GET',
  9590. responseType: 'json'
  9591. });
  9592. if (result === 'Success') {
  9593. if (data?.status === 200 && data?.response?.Success === true && data?.response?.Data) {
  9594. const {
  9595. link
  9596. } = data.response.Data.find(giveaway => title.replace(/[\s]/g, '').toLowerCase().includes(giveaway.title.replace(/[\s]/g, '').toLowerCase())) || {};
  9597. if (link) {
  9598. logStatus.success();
  9599. return link;
  9600. }
  9601. logStatus.error(`Error:${i18n('getLinkFailed')}`);
  9602. return false;
  9603. }
  9604. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9605. return false;
  9606. }
  9607. logStatus.error(`${result}:${statusText}(${status})`);
  9608. return false;
  9609. } catch (error) {
  9610. throwError(error, 'Gleam.getGleamLink');
  9611. return false;
  9612. }
  9613. }
  9614. async #checkLeftKey() {
  9615. try {
  9616. if (!globalOptions.other.checkLeftKey) {
  9617. return true;
  9618. }
  9619. const campaignString = $('div.popup-blocks-container').attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  9620. if (!campaignString) {
  9621. return false;
  9622. }
  9623. const {
  9624. campaign,
  9625. incentive
  9626. } = JSON.parse(campaignString);
  9627. const controllerString = $('div.campaign.reward').attr('ng-init')?.match(/initContestant\(([\w\W]+?)\);/)?.[1];
  9628. let ownedKey = false;
  9629. if (controllerString) {
  9630. if (JSON.parse(controllerString).contestant?.claims?.incentives?.[incentive.id]?.length) {
  9631. ownedKey = true;
  9632. }
  9633. }
  9634. if (campaign.banned || campaign.finished && !ownedKey || campaign.paused || new Date().getTime() < campaign.starts_at * 1e3) {
  9635. await external_Swal_default().fire({
  9636. icon: 'warning',
  9637. title: i18n('notice'),
  9638. text: i18n('giveawayNotWork'),
  9639. confirmButtonText: i18n('confirm'),
  9640. cancelButtonText: i18n('cancel'),
  9641. showCancelButton: true
  9642. }).then(({
  9643. value
  9644. }) => {
  9645. if (value) {
  9646. window.close();
  9647. }
  9648. });
  9649. }
  9650. return true;
  9651. } catch (error) {
  9652. throwError(error, 'Gleam.checkLeftKey');
  9653. return false;
  9654. }
  9655. }
  9656. }
  9657. const website_Gleam = Gleam;
  9658. const SweepWidget_defaultOptions = {
  9659. username: '',
  9660. email: ''
  9661. };
  9662. class SweepWidget extends website_Website {
  9663. name = 'SweepWidget';
  9664. options = {
  9665. ...SweepWidget_defaultOptions,
  9666. ...GM_getValue('SweepWidgetOptions')
  9667. };
  9668. buttons = [ 'doTask' ];
  9669. static test() {
  9670. return /^https?:\/\/sweepwidget\.com\/view\/[\d]+/.test(window.location.href);
  9671. }
  9672. async after() {
  9673. try {
  9674. if (!this.#checkLogin()) {
  9675. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9676. }
  9677. } catch (error) {
  9678. throwError(error, 'SweepWidget.after');
  9679. }
  9680. }
  9681. init() {
  9682. try {
  9683. const logStatus = scripts_echoLog({
  9684. text: i18n('initing')
  9685. });
  9686. if (!this.#checkLogin()) {
  9687. logStatus.warning(i18n('needLogin'));
  9688. return false;
  9689. }
  9690. if (!this.#getGiveawayId()) {
  9691. return false;
  9692. }
  9693. this.initialized = true;
  9694. logStatus.success();
  9695. return true;
  9696. } catch (error) {
  9697. throwError(error, 'SweepWidget.init');
  9698. return false;
  9699. }
  9700. }
  9701. classifyTask() {
  9702. return true;
  9703. }
  9704. async doTask() {
  9705. try {
  9706. if ($('#unlock_rewards_main_wrapper').length === 0) {
  9707. if ($('input[name="sw__login_name"]:visible').length > 0) {
  9708. $('input[name="sw__login_name"]').val(this.options.username);
  9709. }
  9710. if ($('input[name="sw__login_email"]:visible').length > 0) {
  9711. $('input[name="sw__login_email"]').val(this.options.email);
  9712. }
  9713. if ($('#sw_login_button:visible').length > 0) {
  9714. $('#sw_login_button')[0].click();
  9715. }
  9716. if (!await this.#checkEnter()) {
  9717. return false;
  9718. }
  9719. }
  9720. const logStatus = scripts_echoLog({
  9721. text: i18n('SweepWidgetNotice')
  9722. });
  9723. const tasks = $('#sw_inner_entry_methods_l2_wrapper>div.sw_entry');
  9724. for (const task of tasks) {
  9725. const $task = $(task);
  9726. if ($task.find('i.fa-check:visible').length > 0) {
  9727. continue;
  9728. }
  9729. const title = $task.find('.sw_text_inner');
  9730. title[0].click();
  9731. const aElement = $task.find('a.sw_link');
  9732. const link = aElement.attr('href');
  9733. aElement.attr('href', '#a').attr('target', '_self');
  9734. aElement[0]?.click();
  9735. await delay(300);
  9736. aElement.attr('href', link).attr('target', '_blank');
  9737. $task.find('input[type="text"]').val('test');
  9738. const verifyBtn = $task.find('input.sw_verify');
  9739. if (verifyBtn.prop('disabled') === true) {
  9740. title[0].click();
  9741. await delay(300);
  9742. title[0].click();
  9743. await delay(300);
  9744. }
  9745. $task.find('input.sw_verify').removeAttr('disabled')[0]?.click();
  9746. await this.#checkFinish($task);
  9747. await delay(parseInt(`${Math.random() * (3e3 - 1e3 + 1) + 1e3}`, 10));
  9748. }
  9749. logStatus.success();
  9750. return true;
  9751. } catch (error) {
  9752. throwError(error, 'SweepWidget.doTask');
  9753. return false;
  9754. }
  9755. }
  9756. #checkLogin() {
  9757. try {
  9758. if ($('#twitter_login_button').length > 0) {
  9759. $('#twitter_login_button')[0].click();
  9760. }
  9761. return true;
  9762. } catch (error) {
  9763. throwError(error, 'SweepWidget.checkLogin');
  9764. return false;
  9765. }
  9766. }
  9767. #getGiveawayId() {
  9768. try {
  9769. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  9770. if (giveawayId) {
  9771. this.giveawayId = giveawayId;
  9772. return true;
  9773. }
  9774. scripts_echoLog({
  9775. text: i18n('getFailed', 'GiveawayId')
  9776. });
  9777. return false;
  9778. } catch (error) {
  9779. throwError(error, 'SweepWidget.getGiveawayId');
  9780. return false;
  9781. }
  9782. }
  9783. async #checkEnter() {
  9784. try {
  9785. return new Promise(resolve => {
  9786. const checker = setInterval(() => {
  9787. if ($('#unlock_rewards_main_wrapper').length > 0) {
  9788. clearInterval(checker);
  9789. resolve(true);
  9790. }
  9791. });
  9792. });
  9793. } catch (error) {
  9794. throwError(error, 'SweepWidget.checkEnter');
  9795. return false;
  9796. }
  9797. }
  9798. async #checkFinish($task) {
  9799. try {
  9800. return new Promise(resolve => {
  9801. const checker = setInterval(() => {
  9802. if ($task.find('i.fa-check:visible').length > 0 || $task.find('.sw_entry_input:visible').length === 0) {
  9803. clearInterval(checker);
  9804. resolve(true);
  9805. }
  9806. });
  9807. });
  9808. } catch (error) {
  9809. throwError(error, 'SweepWidget.checkFinish');
  9810. return false;
  9811. }
  9812. }
  9813. }
  9814. const website_SweepWidget = SweepWidget;
  9815. const defaultWhiteList = {
  9816. discord: {
  9817. servers: []
  9818. },
  9819. instagram: {
  9820. users: []
  9821. },
  9822. twitch: {
  9823. channels: []
  9824. },
  9825. twitter: {
  9826. users: [],
  9827. retweets: [],
  9828. likes: []
  9829. },
  9830. vk: {
  9831. names: []
  9832. },
  9833. youtube: {
  9834. channels: [],
  9835. likes: []
  9836. },
  9837. reddit: {
  9838. reddits: []
  9839. },
  9840. steam: {
  9841. groups: [],
  9842. officialGroups: [],
  9843. wishlists: [],
  9844. follows: [],
  9845. forums: [],
  9846. workshops: [],
  9847. curators: [],
  9848. workshopVotes: [],
  9849. curatorLikes: [],
  9850. announcements: [],
  9851. licenses: [],
  9852. playtests: []
  9853. }
  9854. };
  9855. const link2id = async function(type) {
  9856. try {
  9857. const link = $('#socialLink').val();
  9858. let id = '';
  9859. switch (type) {
  9860. case 'discord.servers':
  9861. id = link.match(/invite\/(.+)/)?.[1] || '';
  9862. break;
  9863.  
  9864. case 'instagram.users':
  9865. id = link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1] || '';
  9866. break;
  9867.  
  9868. case 'twitch.channels':
  9869. id = link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2] || '';
  9870. break;
  9871.  
  9872. case 'twitter.users':
  9873. id = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || '';
  9874. break;
  9875.  
  9876. case 'twitter.retweets':
  9877. id = link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1] || '';
  9878. break;
  9879.  
  9880. case 'vk.names':
  9881. id = link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1] || '';
  9882. break;
  9883.  
  9884. case 'youtube.channels':
  9885. id = (await getInfo(link, 'channel'))?.params?.channelId || '';
  9886. break;
  9887.  
  9888. case 'youtube.likes':
  9889. id = (await getInfo(link, 'likeVideo'))?.params?.videoId || '';
  9890. break;
  9891.  
  9892. case 'reddit.reddits':
  9893. id = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1] || link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1] || '';
  9894. break;
  9895.  
  9896. case 'steam.groups':
  9897. id = link.match(/groups\/(.+)\/?/)?.[1] || '';
  9898. break;
  9899.  
  9900. case 'steam.wishlists':
  9901. case 'steam.follows':
  9902. case 'steam.forums':
  9903. id = link.match(/app\/([\d]+)/)?.[1] || '';
  9904. break;
  9905.  
  9906. case 'steam.workshops':
  9907. id = link.match(/\?id=([\d]+)/)?.[1] || '';
  9908. break;
  9909.  
  9910. case 'steam.curators':
  9911. {
  9912. if (link.includes('curator')) {
  9913. id = link.match(/curator\/([\d]+)/)?.[1] || '';
  9914. } else {
  9915. const param = link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3);
  9916. if (!param || param.length !== 2) {
  9917. break;
  9918. }
  9919. const steam = new social_Steam();
  9920. if (await steam.init()) {
  9921. id = await steam.getCuratorId(param[0], param[1]) || '';
  9922. }
  9923. }
  9924. }
  9925. break;
  9926. }
  9927. return id;
  9928. } catch (error) {
  9929. throwError(error, 'link2id');
  9930. return i18n('getFailed', 'id');
  9931. }
  9932. };
  9933. const disabledType = {
  9934. steam: [ 'workshopVotes', 'curatorLikes', 'announcements' ],
  9935. twitter: [ 'likes' ]
  9936. };
  9937. const assignWhiteList = whiteList => {
  9938. try {
  9939. const newWhiteList = {};
  9940. for (const [ key, value ] of Object.entries(defaultWhiteList)) {
  9941. newWhiteList[key] = {
  9942. ...value,
  9943. ...whiteList[key]
  9944. };
  9945. }
  9946. return newWhiteList;
  9947. } catch (error) {
  9948. throwError(error, 'assignWhiteList');
  9949. return defaultWhiteList;
  9950. }
  9951. };
  9952. const whiteListOptions = function(showType) {
  9953. try {
  9954. const whiteList = assignWhiteList(GM_getValue('whiteList') || {});
  9955. let whiteListOptionsForm = `<form id="whiteListForm" class="auto-task-form">
  9956. <table class="auto-task-table"><thead><tr><td>${i18n('website')}</td><td>${i18n('type')}</td><td>${i18n('edit')}</td></tr></thead><tbody>`;
  9957. for (const [ social, types ] of Object.entries(whiteList)) {
  9958. 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('');
  9959. }
  9960. whiteListOptionsForm += '</tbody></table></form>';
  9961. if (showType === 'swal') {
  9962. external_Swal_default().fire({
  9963. title: i18n('whiteListOptions'),
  9964. html: whiteListOptionsForm,
  9965. showConfirmButton: false,
  9966. showCloseButton: true
  9967. });
  9968. } else {
  9969. $('body').append(`<h2>${i18n('whiteList')}</h2>${whiteListOptionsForm}`);
  9970. }
  9971. $('.editWhiteList').on('click', function() {
  9972. const value = $(this).attr('data-value');
  9973. if (!value) {
  9974. return;
  9975. }
  9976. const [ social, type ] = value.split('.');
  9977. if (!whiteList?.[social]?.[type]) {
  9978. scripts_echoLog({}).warning(i18n('whiteListNotFound', value));
  9979. return;
  9980. }
  9981. external_Swal_default().fire({
  9982. title: i18n('changeWhiteListOption', value),
  9983. input: 'textarea',
  9984. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  9985. <button id="link2id" data-type="${value}" class="swal2-confirm swal2-styled">获取id</button>
  9986. <p style="margin-bottom:0 !important;">在下方填写白名单,每行一个</p>`,
  9987. inputValue: whiteList[social][type].join('\n'),
  9988. showConfirmButton: true,
  9989. confirmButtonText: i18n('save'),
  9990. showCancelButton: true,
  9991. cancelButtonText: i18n('close'),
  9992. showDenyButton: true,
  9993. denyButtonText: i18n('return')
  9994. }).then(({
  9995. isDenied,
  9996. isConfirmed,
  9997. value
  9998. }) => {
  9999. if (isDenied) {
  10000. if (showType === 'swal') {
  10001. whiteListOptions(showType);
  10002. }
  10003. return;
  10004. } else if (isConfirmed) {
  10005. whiteList[social][type] = value.split('\n');
  10006. GM_setValue('whiteList', whiteList);
  10007. external_Swal_default().fire({
  10008. title: i18n('changeWhiteListSuccess'),
  10009. icon: 'success'
  10010. });
  10011. }
  10012. });
  10013. $('#link2id').on('click', async function() {
  10014. const type = $(this).attr('data-type');
  10015. $('#socialLink').val(await link2id(type));
  10016. });
  10017. });
  10018. } catch (error) {
  10019. throwError(error, 'whiteListOptions');
  10020. }
  10021. };
  10022. const whiteList = whiteListOptions;
  10023. const setGistData = async (token, gistId, fileName, content) => {
  10024. try {
  10025. const logStatus = scripts_echoLog({
  10026. text: i18n('settingData')
  10027. });
  10028. const contentData = JSON.stringify({
  10029. files: {
  10030. [fileName]: {
  10031. content: JSON.stringify(content)
  10032. }
  10033. }
  10034. });
  10035. const {
  10036. result,
  10037. statusText,
  10038. status,
  10039. data
  10040. } = await tools_httpRequest({
  10041. url: `https://api.github.com/gists/${gistId}`,
  10042. headers: {
  10043. Accept: 'application/vnd.github.v3+json',
  10044. Authorization: `token ${token}`
  10045. },
  10046. data: contentData,
  10047. responseType: 'json',
  10048. method: 'POST',
  10049. timeout: 3e4
  10050. });
  10051. if (result === 'Success') {
  10052. if (data?.status === 200 && data.response.files?.[fileName]?.content === JSON.stringify(content)) {
  10053. logStatus.success();
  10054. return true;
  10055. }
  10056. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10057. return false;
  10058. }
  10059. logStatus.error(`${result}:${statusText}(${status})`);
  10060. return false;
  10061. } catch (error) {
  10062. throwError(error, 'setGistData');
  10063. return false;
  10064. }
  10065. };
  10066. const getGistData = async (token, gistId, fileName, test = false) => {
  10067. try {
  10068. const logStatus = scripts_echoLog({
  10069. text: i18n('gettingData')
  10070. });
  10071. const {
  10072. result,
  10073. statusText,
  10074. status,
  10075. data
  10076. } = await tools_httpRequest({
  10077. url: `https://api.github.com/gists/${gistId}`,
  10078. headers: {
  10079. Accept: 'application/vnd.github.v3+json',
  10080. Authorization: `token ${token}`
  10081. },
  10082. responseType: 'json',
  10083. method: 'GET',
  10084. timeout: 3e4
  10085. });
  10086. if (result === 'Success') {
  10087. if (data?.status === 200) {
  10088. const content = data.response?.files?.[fileName]?.content;
  10089. let formatedContent;
  10090. if (!content) {
  10091. logStatus.error(`Error:${i18n('noRemoteData')}`);
  10092. return false;
  10093. }
  10094. if (test) {
  10095. logStatus.success();
  10096. return true;
  10097. }
  10098. try {
  10099. formatedContent = JSON.parse(content);
  10100. } catch (error) {
  10101. logStatus.error(`Error:${i18n('errorRemoteDataFormat')}`);
  10102. return false;
  10103. }
  10104. logStatus.success();
  10105. return formatedContent;
  10106. }
  10107. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10108. return false;
  10109. }
  10110. logStatus.error(`${result}:${statusText}(${status})`);
  10111. return false;
  10112. } catch (error) {
  10113. throwError(error, 'getGistData');
  10114. return false;
  10115. }
  10116. };
  10117. const syncOptions = () => {
  10118. try {
  10119. const {
  10120. TOKEN,
  10121. GIST_ID,
  10122. FILE_NAME,
  10123. SYNC_HISTORY
  10124. } = GM_getValue('gistOptions') || {
  10125. TOKEN: '',
  10126. GIST_ID: '',
  10127. FILE_NAME: '',
  10128. SYNC_HISTORY: true
  10129. };
  10130. external_Swal_default().fire({
  10131. title: i18n('gistOptions'),
  10132. 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;">
  10133. ${i18n('upload2gist')}</button>` + `<button id="download-data" type="button" class="swal2-confirm swal2-styled" style="display: inline-block;">
  10134. ${i18n('downloadFromGist')}</button></p>`,
  10135. focusConfirm: false,
  10136. showLoaderOnConfirm: true,
  10137. 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>`,
  10138. preConfirm: async () => {
  10139. const token = $('#github-token').val();
  10140. const gistId = $('#gist-id').val();
  10141. const fileName = $('#file-name').val();
  10142. const syncHistory = $('#sync-history').prop('checked');
  10143. GM_setValue('gistOptions', {
  10144. TOKEN: token,
  10145. GIST_ID: gistId,
  10146. FILE_NAME: fileName,
  10147. SYNC_HISTORY: syncHistory
  10148. });
  10149. return await getGistData(token, gistId, fileName, true);
  10150. },
  10151. allowOutsideClick: () => !external_Swal_default().isLoading(),
  10152. confirmButtonText: i18n('saveAndTest'),
  10153. showCancelButton: true,
  10154. cancelButtonText: i18n('close')
  10155. }).then(({
  10156. value
  10157. }) => {
  10158. if (value) {
  10159. external_Swal_default().fire({
  10160. icon: 'success',
  10161. title: i18n('testSuccess')
  10162. }).then(syncOptions);
  10163. } else if (value !== undefined) {
  10164. external_Swal_default().fire({
  10165. icon: 'error',
  10166. title: i18n('testFailed')
  10167. }).then(syncOptions);
  10168. }
  10169. });
  10170. $('#upload-data').on('click', async () => {
  10171. const {
  10172. TOKEN,
  10173. GIST_ID,
  10174. FILE_NAME
  10175. } = GM_getValue('gistOptions') || {};
  10176. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10177. return external_Swal_default().fire({
  10178. icon: 'error',
  10179. title: i18n('saveAndTestNotice')
  10180. }).then(syncOptions);
  10181. }
  10182. external_Swal_default().fire({
  10183. icon: 'info',
  10184. title: i18n('processingData')
  10185. });
  10186. const data = {};
  10187. const names = GM_listValues();
  10188. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10189. for (const name of names) {
  10190. if (name === 'gistOptions' || /^[\w]+?Auth$/.test(name)) {
  10191. continue;
  10192. }
  10193. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10194. continue;
  10195. }
  10196. data[name] = GM_getValue(name);
  10197. }
  10198. external_Swal_default().update({
  10199. icon: 'info',
  10200. title: i18n('updatingData')
  10201. });
  10202. if (await setGistData(TOKEN, GIST_ID, FILE_NAME, data)) {
  10203. external_Swal_default().fire({
  10204. icon: 'success',
  10205. title: i18n('syncDataSuccess')
  10206. });
  10207. } else {
  10208. external_Swal_default().fire({
  10209. icon: 'error',
  10210. title: i18n('syncDataFailed')
  10211. });
  10212. }
  10213. });
  10214. $('#download-data').on('click', async () => {
  10215. const {
  10216. TOKEN,
  10217. GIST_ID,
  10218. FILE_NAME
  10219. } = GM_getValue('gistOptions') || {};
  10220. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10221. return external_Swal_default().fire({
  10222. icon: 'error',
  10223. title: i18n('saveAndTestNotice')
  10224. }).then(syncOptions);
  10225. }
  10226. external_Swal_default().fire({
  10227. icon: 'info',
  10228. title: i18n('downloadingData')
  10229. });
  10230. const data = await getGistData(TOKEN, GIST_ID, FILE_NAME);
  10231. if (!data) {
  10232. return external_Swal_default().fire({
  10233. icon: 'error',
  10234. title: i18n('checkedNoData')
  10235. }).then(syncOptions);
  10236. }
  10237. external_Swal_default().update({
  10238. icon: 'info',
  10239. title: i18n('savingData')
  10240. });
  10241. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10242. for (const [ name, value ] of Object.entries(data)) {
  10243. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10244. continue;
  10245. }
  10246. GM_setValue(name, value);
  10247. }
  10248. external_Swal_default().fire({
  10249. icon: 'success',
  10250. title: i18n('syncDataSuccess')
  10251. });
  10252. });
  10253. } catch (error) {
  10254. throwError(error, 'syncOptions');
  10255. }
  10256. };
  10257. const dataSync = syncOptions;
  10258. class Setting {
  10259. name = 'Setting';
  10260. buttons = [ 'saveGlobalOptions', 'syncData', 'tasksHistory' ];
  10261. syncData = dataSync;
  10262. tasksHistory() {
  10263. window.open('https://auto-task-v4.hclonely.com/history.html', '_blank');
  10264. }
  10265. static test() {
  10266. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/setting.html';
  10267. }
  10268. before() {
  10269. $('body').html('').addClass('auto-task-options');
  10270. }
  10271. after() {
  10272. try {
  10273. this.#environment();
  10274. changeGlobalOptions('page');
  10275. whiteList('page');
  10276. $('input[name="other.twitterVerifyId"]').after(`<button id="getTwitterUserId" type="button">${i18n('getTwitterUserId')}</button>`);
  10277. $('#getTwitterUserId').on('click', () => {
  10278. this.#getId('twitterUser');
  10279. });
  10280. $('input[name="other.youtubeVerifyChannel"]').after(`<button id="getYoutubeChannelId" type="button">${i18n('getYoutubeChannelId')}</button>`);
  10281. $('#getYoutubeChannelId').on('click', () => {
  10282. this.#getId('youtubeChannel');
  10283. });
  10284. $('input[name^="position"]').on('input', function() {
  10285. const type = $(this).attr('name').replace('position.', '');
  10286. const xLabel = 'rightleft';
  10287. const yLabel = 'topbottpm';
  10288. switch (type) {
  10289. case 'buttonSideX':
  10290. case 'buttonSideY':
  10291. case 'buttonDistance':
  10292. {
  10293. const distance = $('input[name="position.buttonDistance"]').val();
  10294. const sideX = $('input[name="position.buttonSideX"]').val();
  10295. const sideY = $('input[name="position.buttonSideY"]').val();
  10296. if (![ 'right', 'left' ].includes(sideX)) {
  10297. break;
  10298. }
  10299. if (![ 'top', 'bottom' ].includes(sideY)) {
  10300. break;
  10301. }
  10302. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10303. break;
  10304. }
  10305. const distanceArr = distance.split(',');
  10306. $('#auto-task-buttons').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10307. break;
  10308. }
  10309.  
  10310. case 'showButtonSideX':
  10311. case 'showButtonSideY':
  10312. case 'showButtonDistance':
  10313. {
  10314. const distance = $('input[name="position.showButtonDistance"]').val();
  10315. const sideX = $('input[name="position.showButtonSideX"]').val();
  10316. const sideY = $('input[name="position.showButtonSideY"]').val();
  10317. if (![ 'right', 'left' ].includes(sideX)) {
  10318. break;
  10319. }
  10320. if (![ 'top', 'bottom' ].includes(sideY)) {
  10321. break;
  10322. }
  10323. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10324. break;
  10325. }
  10326. const distanceArr = distance.split(',');
  10327. $('div.show-button-div').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10328. break;
  10329. }
  10330.  
  10331. case 'logSideX':
  10332. case 'logSideY':
  10333. case 'logDistance':
  10334. {
  10335. const distance = $('input[name="position.logDistance"]').val();
  10336. const sideX = $('input[name="position.logSideX"]').val();
  10337. const sideY = $('input[name="position.logSideY"]').val();
  10338. if (![ 'right', 'left' ].includes(sideX)) {
  10339. break;
  10340. }
  10341. if (![ 'top', 'bottom' ].includes(sideY)) {
  10342. break;
  10343. }
  10344. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10345. break;
  10346. }
  10347. const distanceArr = distance.split(',');
  10348. $('#auto-task-info').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10349. break;
  10350. }
  10351.  
  10352. default:
  10353. break;
  10354. }
  10355. });
  10356. $('input[name^="hotKey"]').attr('readonly', 'readonly').off('keydown').on('keydown', function(event) {
  10357. let functionKey = '';
  10358. if (event.altKey) {
  10359. functionKey += 'alt + ';
  10360. } else if (event.ctrlKey) {
  10361. functionKey += 'ctrl + ';
  10362. } else if (event.shiftKey) {
  10363. functionKey += 'shift + ';
  10364. }
  10365. $(this).val(functionKey + (event.key.length === 1 ? event.key.toLowerCase() : ''));
  10366. });
  10367. } catch (error) {
  10368. throwError(error, 'Setting.after');
  10369. }
  10370. }
  10371. saveGlobalOptions() {
  10372. saveData();
  10373. }
  10374. #getId(social) {
  10375. try {
  10376. external_Swal_default().fire({
  10377. title: i18n('getId', i18n(social)),
  10378. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10379. <button id="link2id" data-type="${social}" class="swal2-confirm swal2-styled">获取id</button>`,
  10380. showCancelButton: true,
  10381. cancelButtonText: i18n('close'),
  10382. showConfirmButton: false
  10383. });
  10384. $('#link2id').on('click', async function() {
  10385. const link = $('#socialLink').val();
  10386. if (!link) {
  10387. return;
  10388. }
  10389. const type = $(this).attr('data-type');
  10390. if (type === 'twitterUser') {
  10391. const name = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || link;
  10392. $('#socialLink').val(await new social_Twitter().userName2id(name) || '');
  10393. } else if (type === 'youtubeChannel') {
  10394. const name = /^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www.youtube.com\/.*/.test(link) ? link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1] : link;
  10395. $('#socialLink').val((await getInfo(name, 'channel'))?.params?.channelId || '');
  10396. }
  10397. });
  10398. } catch (error) {
  10399. throwError(error, 'Setting.getId');
  10400. }
  10401. }
  10402. #environment() {
  10403. try {
  10404. const userAgent = (0, javascript_utils_umd_min.ua)();
  10405. const environmentForm = `<form id="environmentForm" class="auto-task-form">
  10406. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('name')}</td><td>${i18n('version')}</td></tr></thead><tbody>
  10407. <tr><td>${i18n('os')}</td><td>${userAgent.os}</td><td>${userAgent.osVersion}</td></tr>
  10408. <tr><td>${i18n('browser')}</td><td>${userAgent.browserZH}</td><td>${userAgent.browserVersion}</td></tr>
  10409. <tr><td>${i18n('scriptManager')}</td><td>${GM_info.scriptHandler}</td><td>${GM_info.version}</td></tr>
  10410. <tr><td>${i18n('script')}</td><td>${GM_info.script.name}</td><td>${GM_info.script.version}</td></tr>
  10411. </tbody></table></form>`;
  10412. $('body').append(`<h2>${i18n('environment')}</h2>${environmentForm}`);
  10413. } catch (error) {
  10414. throwError(error, 'Setting.environment');
  10415. }
  10416. }
  10417. }
  10418. const website_Setting = Setting;
  10419. class History extends website_Keylol {
  10420. name = 'History';
  10421. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect', 'clearHistory' ];
  10422. static test() {
  10423. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/history.html';
  10424. }
  10425. before() {
  10426. try {
  10427. $('body').html('<div class="container"></div>').addClass('auto-task-history');
  10428. const data = GM_listValues() || [];
  10429. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10430. for (const item of tasksHistory) {
  10431. this.#addItem(item);
  10432. }
  10433. } catch (error) {
  10434. throwError(error, 'History.before');
  10435. }
  10436. }
  10437. clearHistory() {
  10438. try {
  10439. const data = GM_listValues() || [];
  10440. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10441. for (const item of tasksHistory) {
  10442. GM_deleteValue(item);
  10443. }
  10444. external_Swal_default().fire({
  10445. title: i18n('clearHistoryFinished'),
  10446. icon: 'success'
  10447. });
  10448. } catch (error) {
  10449. throwError(error, 'History.after');
  10450. }
  10451. }
  10452. #addItem(item) {
  10453. try {
  10454. const tasksData = GM_getValue(item);
  10455. if (!tasksData?.tasks) {
  10456. return;
  10457. }
  10458. let html = '';
  10459. let title = '';
  10460. let link = '';
  10461. const [ website, id ] = item.split('-');
  10462. switch (website) {
  10463. case 'fawTasks':
  10464. title = `Freeanywhere[${id}]`;
  10465. link = `https://freeanywhere.net/#/giveaway/${id}`;
  10466. break;
  10467.  
  10468. case 'gasTasks':
  10469. title = `Giveawaysu[${id}]`;
  10470. link = `https://giveaway.su/giveaway/view/${id}`;
  10471. break;
  10472.  
  10473. case 'gcTasks':
  10474. title = `GiveeClub[${id}]`;
  10475. link = `https://givee.club/event/${id}`;
  10476. break;
  10477.  
  10478. case 'gkTasks':
  10479. title = `Givekey[${id}]`;
  10480. link = `https://givekey.ru/giveaway/${id}`;
  10481. break;
  10482.  
  10483. case 'gleamTasks':
  10484. title = `Gleam[${id}]`;
  10485. link = `https://gleam.io${id}`;
  10486. break;
  10487.  
  10488. case 'khTasks':
  10489. title = `keyhub[${id}]`;
  10490. link = `https://key-hub.eu/giveaway/${id}`;
  10491. break;
  10492.  
  10493. case 'prysTasks':
  10494. title = `Prys[${id}]`;
  10495. link = `https://prys.revadike.com/giveaway/?id=${id}`;
  10496. break;
  10497.  
  10498. default:
  10499. return;
  10500. }
  10501. for (const [ social, types ] of Object.entries(tasksData.tasks)) {
  10502. for (const [ type, tasks ] of Object.entries(types)) {
  10503. for (const task of tasks) {
  10504. 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>`;
  10505. }
  10506. }
  10507. }
  10508. $('.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>`);
  10509. $('span.delete-task').on('click', function() {
  10510. const itemName = $(this).attr('data-name');
  10511. if (itemName) {
  10512. GM_deleteValue(itemName);
  10513. $(`div.card[data-name="${itemName}"]`).remove();
  10514. external_Swal_default().fire({
  10515. title: i18n('clearTaskFinished'),
  10516. text: itemName,
  10517. icon: 'success'
  10518. });
  10519. } else {
  10520. external_Swal_default().fire({
  10521. title: i18n('clearTaskFailed'),
  10522. icon: 'error'
  10523. });
  10524. }
  10525. });
  10526. } catch (error) {
  10527. throwError(error, 'History.addItem');
  10528. }
  10529. }
  10530. }
  10531. const website_History = History;
  10532. 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 ];
  10533. const websiteOptions = function(website, options) {
  10534. try {
  10535. let websiteOptionsForm = `<form id="websiteOptionsForm" class="auto-task-form">
  10536. <table class="auto-task-table"><thead><tr><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  10537. for (const [ option, value ] of Object.entries(options)) {
  10538. websiteOptionsForm += `<tr><td>${option}</td><td><input class="editOption" type="text" name="${option}" value="${value}"/></td></tr>`;
  10539. }
  10540. websiteOptionsForm += '</tbody></table></form>';
  10541. external_Swal_default().fire({
  10542. title: i18n('websiteOptions'),
  10543. html: websiteOptionsForm,
  10544. showConfirmButton: true,
  10545. confirmButtonText: i18n('save'),
  10546. showCancelButton: true,
  10547. cancelButtonText: i18n('close')
  10548. }).then(({
  10549. isConfirmed
  10550. }) => {
  10551. if (isConfirmed) {
  10552. $('#websiteOptionsForm').serializeArray().map(value => {
  10553. options[value.name] = value.value;
  10554. return value;
  10555. });
  10556. GM_setValue(`${website}Options`, options);
  10557. external_Swal_default().fire({
  10558. title: i18n('changeWebsiteOptionsSuccess'),
  10559. icon: 'success'
  10560. });
  10561. }
  10562. });
  10563. } catch (error) {
  10564. throwError(error, 'websiteOptions');
  10565. }
  10566. };
  10567. const options = websiteOptions;
  10568. const external_keyboardJS_namespaceObject = keyboardJS;
  10569. var external_keyboardJS_default = __webpack_require__.n(external_keyboardJS_namespaceObject);
  10570. const checkUpdate = async (updateLink, auto) => {
  10571. try {
  10572. const checkUrl = `${updateLink}package.json?time=${new Date().getTime()}`;
  10573. const {
  10574. result,
  10575. statusText,
  10576. status,
  10577. data
  10578. } = await tools_httpRequest({
  10579. url: checkUrl,
  10580. responseType: 'json',
  10581. method: 'GET',
  10582. timeout: 3e4
  10583. });
  10584. if (result === 'Success') {
  10585. if (data?.response?.version) {
  10586. return data.response;
  10587. }
  10588. if (!auto) {
  10589. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${data?.statusText}(${data?.status})]`);
  10590. }
  10591. return false;
  10592. }
  10593. if (!auto) {
  10594. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${result}:${statusText}(${status})]`);
  10595. }
  10596. return false;
  10597. } catch (error) {
  10598. throwError(error, 'checkUpdate');
  10599. return false;
  10600. }
  10601. };
  10602. const hasNewVersion = (currentVersion, remoteVersion) => {
  10603. try {
  10604. const [ currentRealVersion ] = currentVersion.split('-');
  10605. const [ remoteRealVersion, isPreview ] = remoteVersion.split('-');
  10606. if (isPreview && !globalOptions.other.receivePreview) {
  10607. return false;
  10608. }
  10609. const [ currentVersion1, currentVersion2, currentVersion3 ] = currentRealVersion.split('.').map(value => parseInt(value, 10));
  10610. const [ remoteVersion1, remoteVersion2, remoteVersion3 ] = remoteRealVersion.split('.').map(value => parseInt(value, 10));
  10611. if (remoteVersion1 > currentVersion1) {
  10612. return true;
  10613. }
  10614. if (remoteVersion1 < currentVersion1) {
  10615. return false;
  10616. }
  10617. if (remoteVersion2 > currentVersion2) {
  10618. return true;
  10619. }
  10620. if (remoteVersion2 < currentVersion2) {
  10621. return false;
  10622. }
  10623. if (remoteVersion3 > currentVersion3) {
  10624. return true;
  10625. }
  10626. return false;
  10627. } catch (error) {
  10628. throwError(error, 'compareVersion');
  10629. return false;
  10630. }
  10631. };
  10632. const updateChecker = async () => {
  10633. try {
  10634. const currentVersion = GM_info.script.version;
  10635. const updateSource = globalOptions.other.autoUpdateSource.toLowerCase();
  10636. const updateLinks = {
  10637. github: 'https://github.com/HCLonely/auto-task-new/raw/main/',
  10638. jsdelivr: 'https://cdn.jsdelivr.net/gh/HCLonely/auto-task-v4@main/',
  10639. standby: 'https://auto-task-v4.hclonely.com/'
  10640. };
  10641. let version;
  10642. let updateLink = '';
  10643. let packageData;
  10644. if ([ 'github', 'jsdelivr', 'standby' ].includes(updateSource)) {
  10645. updateLink = updateLinks[updateSource];
  10646. packageData = await checkUpdate(updateLink, false);
  10647. } else {
  10648. updateLink = updateLinks.github;
  10649. packageData = await checkUpdate(updateLink, true);
  10650. if (!packageData) {
  10651. updateLink = updateLinks.jsdelivr;
  10652. packageData = await checkUpdate(updateLink, true);
  10653. if (!packageData) {
  10654. updateLink = updateLinks.standby;
  10655. packageData = await checkUpdate(updateLink, true);
  10656. }
  10657. }
  10658. }
  10659. if (packageData) {
  10660. version = packageData.version || currentVersion;
  10661. } else {
  10662. version = currentVersion;
  10663. scripts_echoLog({}).error(i18n('checkUpdateFailed'));
  10664. }
  10665. if (packageData && hasNewVersion(currentVersion, version)) {
  10666. scripts_echoLog({
  10667. html: `<li><font>${i18n('newVersionNotice', version, `${updateLink}dist/${GM_info.script.name}.user.js`)}</font></li>`
  10668. });
  10669. scripts_echoLog({
  10670. html: `<li>${i18n('updateText', version)}</li><ol class="update-text">${packageData.change?.map(change => `<li>${change}</li>`).join('')}<li>${i18n('updateHistory')}</li></ol>`
  10671. });
  10672. }
  10673. } catch (error) {
  10674. throwError(error, 'updateChecker');
  10675. }
  10676. };
  10677. const scripts_updateChecker = updateChecker;
  10678. window.STYLE = GM_addStyle(auto_task.A + GM_getResourceText('style'));
  10679. window.DEBUG = !!globalOptions.other?.debug;
  10680. window.TRACE = !!globalOptions.other?.debug && typeof console.trace === 'function';
  10681. const loadScript = async () => {
  10682. if (window.location.hostname === 'www.twitch.tv' && window.location.hash === '#auth') {
  10683. const authToken = external_Cookies_namespaceObject.get('auth-token');
  10684. const isLogin = !!external_Cookies_namespaceObject.get('login');
  10685. if (isLogin) {
  10686. GM_setValue('twitchAuth', {
  10687. authToken: authToken,
  10688. clientVersion: __twilightBuildID,
  10689. clientId: commonOptions?.headers?.['Client-ID'],
  10690. deviceId: commonOptions?.headers?.['Device-ID'],
  10691. clientSessionId: window.localStorage.local_storage_app_session_id.replace(/"/g, '')
  10692. });
  10693. window.close();
  10694. external_Swal_default().fire('', i18n('closePageNotice'));
  10695. } else {
  10696. external_Swal_default().fire('', i18n('needLogin'));
  10697. }
  10698. return;
  10699. }
  10700. if (window.location.hostname === 'www.reddit.com' && (window.location.hash === '#auth' || GM_getValue('redditAuth') === '#auth')) {
  10701. const betaButton = $('#redesign-beta-optin-btn');
  10702. if (betaButton.length > 0) {
  10703. GM_setValue('redditAuth', '#auth');
  10704. return betaButton[0].click();
  10705. }
  10706. GM_setValue('redditAuth', null);
  10707. window.close();
  10708. external_Swal_default().fire('', i18n('closePageNotice'));
  10709. return;
  10710. }
  10711. let website;
  10712. for (const Website of Websites) {
  10713. if (Website.test()) {
  10714. website = new Website();
  10715. break;
  10716. }
  10717. }
  10718. if (!website) {
  10719. console.log('%c%s', 'color:#ff0000', 'Auto-Task[Warning]: 脚本停止加载,当前网站不支持!');
  10720. return;
  10721. }
  10722. if (website?.before) {
  10723. await website?.before();
  10724. }
  10725. $('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>`);
  10726. $('div.show-button-div').on('click', () => {
  10727. $('#auto-task-buttons').show();
  10728. $('div.show-button-div').hide();
  10729. });
  10730. const toggleLog = () => {
  10731. const $this = $('#toggle-log');
  10732. const status = $this.attr('data-status');
  10733. if (status === 'show') {
  10734. $('#auto-task-info').hide();
  10735. $this.attr('data-status', 'hide').text(i18n('showLog'));
  10736. } else {
  10737. $('#auto-task-info').show();
  10738. $this.attr('data-status', 'show').text(i18n('hideLog'));
  10739. }
  10740. };
  10741. external_keyboardJS_default().bind(globalOptions.hotKey.doTaskKey, () => {
  10742. if (website.doTask) {
  10743. website.doTask();
  10744. }
  10745. });
  10746. external_keyboardJS_default().bind(globalOptions.hotKey.undoTaskKey, () => {
  10747. if (website.undoTask) {
  10748. website.doTask();
  10749. }
  10750. });
  10751. external_keyboardJS_default().bind(globalOptions.hotKey.toggleLogKey, toggleLog);
  10752. if (website?.after) {
  10753. await website?.after();
  10754. }
  10755. if (website?.buttons && $('#auto-task-buttons').children().length === 0) {
  10756. $('#auto-task-buttons').addClass(`${website.name}-buttons`);
  10757. for (const button of website.buttons) {
  10758. if (website[button]) {
  10759. const btnElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">${i18n(button)}</a></p>`);
  10760. btnElement.find('a.auto-task-website-btn').on('click', () => {
  10761. website[button]();
  10762. });
  10763. $('#auto-task-buttons').append(btnElement);
  10764. }
  10765. }
  10766. }
  10767. const hideButtonElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">
  10768. ${i18n('hideButton')}</a></p>`);
  10769. hideButtonElement.find('a.auto-task-website-btn').on('click', () => {
  10770. $('#auto-task-buttons').hide();
  10771. $('div.show-button-div').show();
  10772. });
  10773. 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'}">
  10774. ${globalOptions.other.defaultShowLog ? i18n('hideLog') : i18n('showLog')}</a></p>`);
  10775. toggleLogElement.find('a.auto-task-website-btn').on('click', toggleLog);
  10776. $('#auto-task-buttons').append(hideButtonElement).append(toggleLogElement);
  10777. if (website?.options) {
  10778. GM_registerMenuCommand(i18n('changeWebsiteOptions'), () => {
  10779. options(website.name, website.options);
  10780. });
  10781. }
  10782. if (website.name !== 'Setting') {
  10783. GM_registerMenuCommand(i18n('changeGlobalOptions'), () => {
  10784. changeGlobalOptions('swal');
  10785. });
  10786. GM_registerMenuCommand(i18n('settingPage'), () => {
  10787. window.open('https://auto-task-v4.hclonely.com/setting.html', '_blank');
  10788. });
  10789. }
  10790. console.log('%c%s', 'color:#1bbe1a', 'Auto-Task[Load]: 脚本加载完成');
  10791. const [ v1, v2 ] = GM_info.version.split('.');
  10792. if (!(parseInt(v1, 10) >= 5 && parseInt(v2, 10) >= 2)) {
  10793. scripts_echoLog({}).error(i18n('versionNotMatched'));
  10794. }
  10795. if (!GM_getValue('notice')) {
  10796. external_Swal_default().fire({
  10797. title: i18n('swalNotice'),
  10798. icon: 'warning'
  10799. }).then(() => {
  10800. window.open(i18n('noticeLink'), '_blank');
  10801. GM_setValue('notice', new Date().getTime());
  10802. });
  10803. scripts_echoLog({
  10804. html: `<li><font class="warning">${i18n('echoNotice', i18n('noticeLink'))}</font></li>`
  10805. }).font?.find('a').on('click', () => {
  10806. GM_setValue('notice', new Date().getTime());
  10807. });
  10808. }
  10809. scripts_updateChecker();
  10810. };
  10811. if (window.location.hostname === 'discord.com') {
  10812. const LocalStorage = window.localStorage;
  10813. if (window.location.hash === '#auth') {
  10814. window.localStorage.removeItem = () => true;
  10815. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10816. if (discordAuth && discordAuth.length > 0) {
  10817. GM_setValue('discordAuth', {
  10818. auth: discordAuth
  10819. });
  10820. window.close();
  10821. external_Swal_default().fire('', i18n('closePageNotice'));
  10822. } else {
  10823. external_Swal_default().fire({
  10824. text: i18n('getDiscordAuthFailed'),
  10825. icon: 'error'
  10826. });
  10827. }
  10828. } else {
  10829. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10830. if (discordAuth && discordAuth.length > 0) {
  10831. GM_setValue('discordAuth', {
  10832. auth: discordAuth
  10833. });
  10834. }
  10835. }
  10836. } else if (window.location.hostname === 'opquests.com') {
  10837. loadScript();
  10838. } else if (window.opener && window.location.host === 'store.steampowered.com' && window.location.pathname === '/') {
  10839. $(() => {
  10840. if ($('[data-miniprofile]').length === 0) {
  10841. return;
  10842. }
  10843. window.onbeforeunload = function(event) {
  10844. GM_setValue('steamStoreAuth', null);
  10845. return null;
  10846. };
  10847. const storeSessionID = document.body.innerHTML.match(/g_sessionID = "(.+?)";/)?.[1];
  10848. if (storeSessionID) {
  10849. GM_setValue('steamStoreAuth', {
  10850. storeSessionID: storeSessionID
  10851. });
  10852. return true;
  10853. }
  10854. });
  10855. } else if (window.opener && window.location.host === 'steamcommunity.com') {
  10856. $(() => {
  10857. window.onbeforeunload = function(event) {
  10858. GM_setValue('steamCommunityAuth', null);
  10859. return null;
  10860. };
  10861. const steam64Id = document.body.innerHTML.match(/g_steamID = "(.+?)";/)?.[1];
  10862. const communitySessionID = document.body.innerHTML.match(/g_sessionID = "(.+?)";/)?.[1];
  10863. const userName = document.body.innerHTML.match(/steamcommunity.com\/id\/(.+?)\//)?.[1];
  10864. const data = {};
  10865. if (steam64Id) {
  10866. data.steam64Id = steam64Id;
  10867. }
  10868. if (userName) {
  10869. data.userName = userName;
  10870. }
  10871. if (communitySessionID) {
  10872. data.communitySessionID = communitySessionID;
  10873. GM_setValue('steamCommunityAuth', data);
  10874. if (GM_getValue('steamCommunityAuth') === 'update') {
  10875. window.close();
  10876. }
  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. })();