auto-task-v4

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

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

  1. // ==UserScript==
  2. // @name auto-task-v4
  3. // @namespace auto-task-v4
  4. // @version 4.4.15
  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. owned: '已拥有',
  1361. initingASF: '正在初始化ASF...',
  1362. servers: '服务器',
  1363. joiningDiscordServer: '正在加入Discord服务器',
  1364. leavingDiscordServer: '正在退出Discord服务器',
  1365. gettingDiscordGuild: '正在获取Discord服务器Id',
  1366. getDiscordAuthFailed: '获取Discord凭证失败,请检测Discord帐号是否已登录',
  1367. discordImportantNotice: '重要提醒!!!',
  1368. discordImportantNoticeText: '由于Discord网站后台更新,目前使用此脚本加组后可能会导致Discord帐号被强制退出,且需要两步验证才能正常登录,请谨慎使用!!!',
  1369. continue: '继续',
  1370. skipDiscordTask: '跳过Discord任务',
  1371. continueAndDontRemindAgain: '继续且不再提醒',
  1372. users: '用户',
  1373. loginIns: '请先<a href="https://www.instagram.com/accounts/login/" target="_blank">登录Instagram</a>',
  1374. insBanned: '您的Instagram账户已被封禁',
  1375. verifyingInsAuth: '正在验证Instagram凭证...',
  1376. gettingInsUserId: '正在获取Instagram用户Id',
  1377. followingIns: '正在关注Instagram用户',
  1378. unfollowingIns: '正在取关Instagram用户',
  1379. reddits: '社区/用户',
  1380. loginReddit: '请先<a href="https://www.reddit.com/login/" target="_blank">登录Reddit</a>',
  1381. changingRedditVersion: '正在切换Reddit为新版页面...',
  1382. joiningReddit: '正在加入Reddit社区',
  1383. leavingReddit: '正在退出Reddit社区',
  1384. followingRedditUser: '正在关注Reddit用户',
  1385. unfollowingRedditUser: '正在取关Reddit用户',
  1386. channels: '频道',
  1387. followingTwitchChannel: '正在关注Twitch频道',
  1388. unfollowingTwitchChannel: '正在取关Twitch频道',
  1389. gettingTwitchChannelId: '正在获取Twitch频道Id',
  1390. checkingTwitchIntegrity: '正在检查Twitch完整性...',
  1391. twitterUser: '推特用户',
  1392. retweets: '转推',
  1393. gettingTwitterUserId: '正在获取推特用户Id',
  1394. followingTwitterUser: '正在关注推特用户',
  1395. unfollowingTwitterUser: '正在取关推特用户',
  1396. retweetting: '正在转推',
  1397. unretweetting: '正在撤销转推',
  1398. names: '组/社区/动态',
  1399. loginVk: '请先<a href="https://vk.com/login/" target="_blank">登录Vk</a>',
  1400. gettingVkId: '正在获取Vk任务Id',
  1401. joiningVkGroup: '正在加入Vk组',
  1402. leavingVkGroup: '正在退出Vk组',
  1403. joiningVkPublic: '正在加入Vk社区',
  1404. leavingVkPublic: '正在退出Vk社区',
  1405. sendingVkWall: '正在转发Vk动态',
  1406. deletingVkWall: '正在撤销转发Vk动态',
  1407. youtubeChannel: 'YouTube频道',
  1408. likes: '点赞',
  1409. loginYtb: '请先<a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">登录YouTube</a>',
  1410. tryUpdateYtbAuth: '请尝试<a href="https://www.youtube.com/#auth" target="_blank">更新YouTube凭证</a>',
  1411. gettingYtbToken: '正在获取YouTube Token...',
  1412. followingYtbChannel: '正在订阅YouTube频道',
  1413. unfollowingYtbChannel: '正在退订YouTube频道',
  1414. likingYtbVideo: '正在点赞YouTube视频',
  1415. unlikingYtbVideo: '正在取消点赞YouTube视频',
  1416. giveKeyNoticeBefore: '每次验证间隔15s',
  1417. giveKeyNoticeAfter: '如果没有key, 请在<a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>查看',
  1418. noPoints: '点数不够,跳过抽奖',
  1419. getNeedPointsFailed: '获取所需点数失败,跳过抽奖',
  1420. joiningLottery: '正在加入抽奖',
  1421. doingGleamTask: '正在做Gleam任务...',
  1422. gettingGleamLink: '正在获取Gleam任务链接...',
  1423. gleamTaskNotice: '如果此页面长时间未关闭,请完成任一任务后自行关闭!',
  1424. verifiedGleamTasks: '已尝试验证所有任务,验证失败的任务请尝试手动验证或完成!',
  1425. campaign: '检测到人机验证,请完成验证后重新验证任务!',
  1426. gsNotice: '为避免得到"0000-0000-0000"key, 已自动屏蔽"Grab Key"按钮,获取key时请关闭脚本!',
  1427. giveeClubVerifyNotice: '正在验证任务...',
  1428. giveeClubVerifyFinished: '请等待验证完成后自行加入赠Key',
  1429. doingKeyhubTask: '正在做Keyhub任务...',
  1430. SweepWidgetNotice: '正在处理并验证任务,每次验证任务有1~3s间隔防止触发验证过快警告...',
  1431. tasksNotCompleted: '任务未完成',
  1432. confirmingTask: '正在跳过警告页面...'
  1433. };
  1434. const zh_CN = data;
  1435. const en_US_data = {
  1436. website: 'Website',
  1437. type: 'Type',
  1438. edit: 'Edit',
  1439. whiteList: 'Whitelist',
  1440. skipTask: 'Skip undo task',
  1441. whiteListOptions: 'Whitelist options',
  1442. changeWhiteListOption: 'Whitelist option(%0)',
  1443. whiteListNotFound: 'Cannot find this whitelist: %0',
  1444. changeWhiteListSuccess: 'The whitelist is successfully modified, and the page refresh will take effect!',
  1445. changeWebsiteOptions: 'Website options',
  1446. changeGlobalOptions: 'Global options',
  1447. ok: 'OK',
  1448. save: 'Save',
  1449. close: 'Close',
  1450. return: 'Return',
  1451. option: 'Option',
  1452. value: 'Value',
  1453. websiteOptions: 'Current website settings',
  1454. changeWebsiteOptionsSuccess: 'The current website setting is changed successfully, and the page refresh will take effect!',
  1455. changeGlobalOptionsSuccess: 'The global setting is changed successfully, and the refresh will take effect!',
  1456. needLogin: 'Please log in first!',
  1457. getTasksInfo: 'Obtaining and processing task information...',
  1458. gettingKey: 'Getting Key...',
  1459. verifyingTask: 'Verifying task',
  1460. notice: 'Automatic task script notice',
  1461. noKeysLeft: 'There are no more keys left on this page. Do you want to close it?',
  1462. giveawayEnded: 'This event has ended, do you want to close it?',
  1463. 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?',
  1464. confirm: 'Confirm',
  1465. cancel: 'Cancel',
  1466. unKnown: 'Unknown',
  1467. unKnownTaskType: 'Unrecognized task',
  1468. doing: 'Doing a task',
  1469. allTasksComplete: 'All tasks have been completed!',
  1470. getTaskIdFailed: 'Failed to obtain task Id!',
  1471. initSuccess: '%0 was initialized successfully!',
  1472. initFailed: '%0 initialization failed!',
  1473. errorLink: 'Link error: %0',
  1474. needInit: 'Please initialize first',
  1475. verifyingAuth: 'Verifying %0 token...',
  1476. updatingAuth: 'Update %0 token...',
  1477. initing: 'Initializing...',
  1478. getFailed: 'Failed to get %0!',
  1479. checkLoginFailed: 'Failed to detect login status!',
  1480. checkLeftKeyFailed: 'Failed to detect the remaining keys!',
  1481. userId: 'User Id',
  1482. joiningGiveaway: 'Joining giveaway',
  1483. needJoinGiveaway: 'Need to join the giveaway first',
  1484. cannotUndo: 'This website does not support canceling tasks',
  1485. verifyAuth: 'Verifying %0 token...',
  1486. closePageNotice: 'f this page does not close automatically, please close this page yourself.',
  1487. errorReport: 'A script error is detected, do you want to report the BUG?',
  1488. visitingLink: 'Visiting link: ',
  1489. doTask: 'DoTask',
  1490. undoTask: 'UndoTask',
  1491. verifyTask: 'Verify',
  1492. getKey: 'GetKey',
  1493. selectAll: 'SelectAll',
  1494. selectNone: 'SelectNone',
  1495. invertSelect: 'InvertSelect',
  1496. doFreeTask: 'FreeTask',
  1497. doPointTask: 'PointTask',
  1498. skipTaskOption: 'Skip task has been configured in the settings',
  1499. other: 'Other',
  1500. globalOptions: 'Global Options',
  1501. checkLogin: 'Login detection</br>Need to log in to the website automatically log in, part of this website supports.',
  1502. checkLeftKey: 'Key remaining detection</br>The end of the giveaway event prompts whether to close or not, part of this website supports.',
  1503. 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.',
  1504. 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.',
  1505. 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.',
  1506. saveGlobalOptions: 'SaveSettings',
  1507. settingPage: 'Setting Page',
  1508. name: 'Name',
  1509. version: 'Version',
  1510. scriptManager: 'Script Manager',
  1511. script: 'Script',
  1512. environment: 'Environment',
  1513. os: 'OS',
  1514. browser: 'Browser',
  1515. getId: 'Get %0 id',
  1516. getTwitterUserId: 'Get Twitter user id (Get id function is only available on the settings page).',
  1517. getYoutubeChannelId: 'Get Youtube channel id (Get id function is only available on the settings page).',
  1518. showButton: 'ShowButton',
  1519. hideButton: 'HideButton',
  1520. showLog: 'ShowLog',
  1521. hideLog: 'HideLog',
  1522. defaultShowButton: 'Default display button',
  1523. defaultShowLog: 'Display log by default',
  1524. debug: 'Output debug log, do not enable this option!',
  1525. receivePreview: 'Receive preview updates',
  1526. position: 'Component position',
  1527. buttonSideX: 'Horizontal positioning of the button area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1528. 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',
  1529. 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',
  1530. showButtonSideX: 'ShowButton horizontal positioning (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1531. showButtonSideY: 'ShowButton vertical positioning (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1532. 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',
  1533. logSideX: 'Horizontal positioning of the log area (real-time preview function is only available on the setting page).' + '</br>left: left | right: right',
  1534. logSideY: 'Vertical positioning of the log area (real-time preview function is only available on the setting page).' + '</br>top: top | bottom: bottom',
  1535. 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',
  1536. hotKey: 'Shortcut key',
  1537. doTaskKey: 'DoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1538. undoTaskKey: 'UndoTask shortcut keys</br> (real-time preview function is only available on the settings page).',
  1539. toggleLogKey: 'ShowLog/HideLog shortcut keys</br> (real-time preview function is only available on the settings page).',
  1540. tasksHistory: 'TasksHistory',
  1541. clearHistory: 'Clear history',
  1542. clearHistoryFinished: 'The mission history has been cleared!',
  1543. deleteTask: 'Delete task',
  1544. lastChangeTime: 'Last Change Time',
  1545. clearTaskFinished: 'Delete the following tasks completed!',
  1546. clearTaskFailed: 'Failed to delete the task, the task name was not found!',
  1547. syncData: 'DataSync',
  1548. settingData: 'Uploading data...',
  1549. gettingData: 'Getting data...',
  1550. help: 'Help',
  1551. fileName: 'Filename',
  1552. upload2gist: 'Sync to Gist',
  1553. downloadFromGist: 'Sync from Gist',
  1554. saveAndTest: 'Save configuration and test',
  1555. testSuccess: 'Test success!',
  1556. testFailed: 'Test failed!',
  1557. saveAndTestNotice: 'Please save the configuration and test first!',
  1558. processingData: 'Processing data...',
  1559. updatingData: 'Uploading data...',
  1560. syncDataSuccess: 'Synchronized data successfully!',
  1561. syncDataFailed: 'Failed to synchronize data, please check the error message on the console!',
  1562. downloadingData: 'Downloading data...',
  1563. checkedNoData: 'No remote data is detected, please confirm whether the configuration is correct!',
  1564. savingData: 'Saving data...',
  1565. syncHistory: 'Synchronize tasks history',
  1566. checkUpdateFailed: 'Check update failed',
  1567. newVersionNotice: 'Checked a new version V%0, <a class="high-light" href="%1" target="_blank">click to update</a>',
  1568. language: 'Language</br> Currently only supports zh: Chinese, en: English',
  1569. gistOptions: 'Gist Settings',
  1570. 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!',
  1571. 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!',
  1572. noticeLink: 'https://auto-task-doc.js.org/en/guide/#read-me-first',
  1573. toGithub: 'Feedback(Github)',
  1574. toKeylol: 'Feedback(Keylol)',
  1575. copySuccess: 'The error message has been copied to the clipboard. Do you want to go to the Keylol forum to give feedback?',
  1576. copyFailed: 'Please copy the error information below and report back to the Keylol forum!',
  1577. updateText: 'Updates in version %0:',
  1578. Active: 'Active',
  1579. Ended: 'Ended',
  1580. Banned: 'Banned',
  1581. Paused: 'Paused',
  1582. notStart: 'notStart',
  1583. noRemoteData: 'No data remotely',
  1584. errorRemoteDataFormat: 'Remote data has wrong format',
  1585. updateHistory: '<a class="high-light" href="https://auto-task-doc.js.org/logs/" target="_blank">Click here</a>' + ' to view the historical update record.',
  1586. AsfEnabled: 'Use ASF to do Steam related tasks (requires <a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a> plugin)',
  1587. AsfIpcUrl: 'ASF IPC URL',
  1588. AsfIpcPassword: 'ASF IPC Password',
  1589. groups: 'Group',
  1590. officialGroups: 'Official Group',
  1591. wishlists: 'Wishlist',
  1592. follows: 'Follow Game',
  1593. forums: 'Forum',
  1594. workshops: 'Favorite Workshop',
  1595. curators: 'Curator',
  1596. workshopVotes: 'Voteup Workshop',
  1597. announcements: 'Announcement',
  1598. steamCommunity: 'Steam Community',
  1599. steamStore: 'Steam Store',
  1600. licenses: 'Add License',
  1601. playtests: 'Playtest Access',
  1602. needLoginSteamStore: 'Please <a href="https://store.steampowered.com/login/" target="_blank">log in to the Steam Store</a>',
  1603. needLoginSteamCommunity: 'Please <a href="https://steamcommunity.com/login/home/" target="_blank">log in to the Steam Community</a>',
  1604. joiningSteamGroup: 'Joining Steam Group',
  1605. leavingSteamGroup: 'Leaving Steam Group',
  1606. gettingSteamGroupId: 'Getting Steam Group Id',
  1607. joiningSteamOfficialGroup: 'Joining Steam Official Group',
  1608. leavingSteamOfficialGroup: 'Leaving Steam Official Group',
  1609. gettingSteamOfficialGroupId: 'Getting Steam Official Group Id',
  1610. subscribingForum: 'Subscribing the Steam Forum',
  1611. unsubscribingForum: 'Unsubscribing the Steam Forum',
  1612. gettingForumId: 'Getting Steam Forum Id',
  1613. followingCurator: 'Following Steam Curator',
  1614. unfollowingCurator: 'Unfollowing Steam Curator',
  1615. gettingCuratorId: 'Getting Steam Curator Id',
  1616. addingToWishlist: 'Adding the game to the Steam wishlist',
  1617. removingFromWishlist: 'Removing the game from the Steam wishlist',
  1618. followingGame: 'Following Steam games',
  1619. unfollowingGame: 'Unfollowing Steam games',
  1620. favoritingWorkshop: 'Favouring Steam Workshop Items',
  1621. unfavoritingWorkshop: 'Unfavoriting Steam Workshop Items',
  1622. gettingWorkshopAppId: 'Getting Steam Workshop Item Id',
  1623. votingUpWorkshop: 'Liking Steam workshop items',
  1624. gettingAnnouncementParams: 'Getting Steam announcement information',
  1625. likingAnnouncement: 'Liking Steam announcement',
  1626. changingArea: 'Changing Steam area: %0...',
  1627. notNeededChangeArea: 'The current area does not need to be changed',
  1628. noAnotherArea: 'Please check whether the proxy is turned on correctly',
  1629. gettingAreaInfo: 'Getting Steam area information...',
  1630. changeAreaNotice: 'Suspected of a locked zone game, try to change the zone to execute',
  1631. steamFinishNotice: 'Steam task completed, try to change the shopping cart area back to CN',
  1632. gettingSubid: 'Getting subid',
  1633. addingFreeLicense: 'Adding free license',
  1634. missParams: 'Missing parameters',
  1635. gettingLicenses: 'Getting licenses...',
  1636. requestingPlayTestAccess: 'Requesting play test access',
  1637. 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.',
  1638. versionNotMatched: 'The script manager version is too low, requiring TamperMonkey >= 5.2.0 or TamperMonkey Beta >= 5.2.6196',
  1639. gettingUserLink: 'Getting steam user community link...',
  1640. retry: 'Retry',
  1641. owned: 'Owned',
  1642. initingASF: 'Initing ASF...',
  1643. servers: 'Server',
  1644. joiningDiscordServer: 'Joining Discord Server',
  1645. leavingDiscordServer: 'Leaving Discord Server',
  1646. gettingDiscordGuild: 'Getting Discord server Id',
  1647. getDiscordAuthFailed: 'Failed to get Discord token, please check whether the Discord account is logged in',
  1648. discordImportantNotice: 'Important Reminder! ! !',
  1649. 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! ! !',
  1650. continue: 'Continue',
  1651. skipDiscordTask: 'Skip',
  1652. continueAndDontRemindAgain: 'Continue without Reminders',
  1653. users: 'User',
  1654. loginIns: 'Please <a href="https://www.instagram.com/accounts/login/" target="_blank">log in to Instagram</a>',
  1655. insBanned: 'Your Instagram account has been banned',
  1656. verifyingInsAuth: 'Verifying Instagram token...',
  1657. gettingInsUserId: 'Getting Instagram user Id',
  1658. followingIns: 'Following Instagram user',
  1659. unfollowingIns: 'Unfollowing Instagram user',
  1660. reddits: 'Reddit/User',
  1661. loginReddit: 'Please <a href="https://www.reddit.com/login/" target="_blank">log in to Reddit</a>',
  1662. changingRedditVersion: 'Switching Reddit to a new version page...',
  1663. joiningReddit: 'Joining the Reddit',
  1664. leavingReddit: 'Leaving the Reddit',
  1665. followingRedditUser: 'Following Reddit User',
  1666. unfollowingRedditUser: 'Unfollowing Reddit User',
  1667. channels: 'Channel',
  1668. followingTwitchChannel: 'Following Twitch Channel',
  1669. unfollowingTwitchChannel: 'Unfollowing Twitch Channel',
  1670. gettingTwitchChannelId: 'Getting Twitch Channel Id',
  1671. checkingTwitchIntegrity: 'Checking Twitch integrity...',
  1672. twitterUser: 'Twitter User',
  1673. retweets: 'Retweet',
  1674. gettingTwitterUserId: 'Getting Twitter User Id',
  1675. followingTwitterUser: 'Following Twitter User',
  1676. unfollowingTwitterUser: 'Unfollowing Twitter User',
  1677. retweetting: 'Retweetting',
  1678. unretweetting: 'Unretweetting',
  1679. names: 'Group/Public/Wall',
  1680. loginVk: 'Please <a href="https://vk.com/login/" target="_blank">log in to Vk</a>',
  1681. gettingVkId: 'Getting Vk task Id',
  1682. joiningVkGroup: 'Joining Vk Group',
  1683. leavingVkGroup: 'Leaving Vk Group',
  1684. joiningVkPublic: 'Joining Vk Public',
  1685. leavingVkPublic: 'Leaving Vk Public',
  1686. sendingVkWall: 'Sending Vk Wall',
  1687. deletingVkWall: 'Deleting Vk Wall',
  1688. youtubeChannel: 'YouTube Channel',
  1689. likes: 'Like',
  1690. loginYtb: 'Please <a href="https://accounts.google.com/ServiceLogin?service=youtube" target="_blank">log in to YouTube</a>',
  1691. tryUpdateYtbAuth: 'Please try to <a href="https://www.youtube.com/#auth" target="_blank">update YouTube token</a>',
  1692. gettingYtbToken: 'Getting YouTube Token...',
  1693. followingYtbChannel: 'Subscribing to YouTube channel',
  1694. unfollowingYtbChannel: 'Unsubscribing to YouTube channel',
  1695. likingYtbVideo: 'Liking YouTube video',
  1696. unlikingYtbVideo: 'Unliking YouTube video',
  1697. giveKeyNoticeBefore: 'Each verification interval is 15s',
  1698. giveKeyNoticeAfter: 'If there is no key, please check at <a href="https://givekey.ru/profile" target="_blank">https://givekey.ru/profile</a>',
  1699. noPoints: 'Not enough points, skip the lottery',
  1700. getNeedPointsFailed: 'ailed to obtain the required points, skip the lottery',
  1701. joiningLottery: 'Joining the lottery',
  1702. doingGleamTask: 'Doing Gleam Task...',
  1703. gettingGleamLink: 'Getting Gleam task link...',
  1704. gleamTaskNotice: 'If this page has not been closed for a long time, please close it yourself after completing any task!',
  1705. verifiedGleamTasks: 'Attempted to verify all tasks. If the verification fails, please try to verify manually or complete it!',
  1706. campaign: 'ReCAPTCHA detected, please complete it and re-verify the tasks!',
  1707. 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!',
  1708. giveeClubVerifyNotice: 'Verifying task...',
  1709. giveeClubVerifyFinished: 'Wait for the verification to complete and join it by yourself',
  1710. doingKeyhubTask: 'Doing Keyhub Task...',
  1711. 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...',
  1712. tasksNotCompleted: 'Tasks Not Completed',
  1713. confirmingTask: 'Confirming task...'
  1714. };
  1715. const en_US = en_US_data;
  1716. const languages = {
  1717. zh: zh_CN,
  1718. en: en_US
  1719. };
  1720. const language = [ 'zh', 'en' ].includes(globalOptions.other.language) ? globalOptions.other.language : 'en';
  1721. const I18n = (key, ...argvs) => {
  1722. if (!languages[language]?.[key]) {
  1723. return key;
  1724. }
  1725. return languages[language][key].replace(/%([\d]+)/g, (match, index) => argvs[parseInt(index, 10)]);
  1726. };
  1727. const i18n = I18n;
  1728. function throwError(error, name) {
  1729. if (window.TRACE) {
  1730. console.trace('%cAuto-Task[Debug]:', 'color:blue');
  1731. }
  1732. external_Swal_default().fire({
  1733. title: i18n('errorReport'),
  1734. icon: 'error',
  1735. showCancelButton: true,
  1736. confirmButtonText: i18n('toGithub'),
  1737. showDenyButton: true,
  1738. denyButtonText: i18n('toKeylol'),
  1739. cancelButtonText: i18n('close')
  1740. }).then(({
  1741. isDenied,
  1742. isConfirmed
  1743. }) => {
  1744. if (isConfirmed) {
  1745. 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,
  1746. 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');
  1747. } else if (isDenied) {
  1748. const text = `错误链接: [url=${window.location.href}]${window.location.href}[/url]
  1749.  
  1750. 环境:
  1751.  
  1752. [code]${JSON.stringify((0, javascript_utils_umd_min.ua)(), null, 4)}[/code]
  1753.  
  1754. 脚本管理器: ${GM_info.scriptHandler} ${GM_info.version}
  1755. 脚本版本: ${GM_info.script.version}
  1756.  
  1757. 报错信息:
  1758. [code]${error.stack}[/code]
  1759.  
  1760. 执行日志:
  1761. [code]${$.makeArray($('#auto-task-info>li')).map(element => element.innerText).join('\n')}[/code]`;
  1762. GM_setClipboard(text);
  1763. external_Swal_default().fire({
  1764. title: i18n('copySuccess'),
  1765. icon: 'success',
  1766. confirmButtonText: i18n('ok')
  1767. }).then(() => {
  1768. window.open('https://keylol.com/forum.php?mod=post&action=reply&fid=319&tid=777450', '_blank');
  1769. });
  1770. }
  1771. });
  1772. console.log('%c%s', 'color:white;background:red', `Auto-Task[Error]: ${name}\n${error.stack}`);
  1773. }
  1774. class Social {
  1775. tasks;
  1776. getRealParams(name, links, doTask, link2param) {
  1777. try {
  1778. let realParams = [];
  1779. if (links.length > 0) {
  1780. realParams = [ ...realParams, ...links.map(link => link2param(link)).filter(link => link) ];
  1781. }
  1782. if (!doTask && this.tasks[name].length > 0) {
  1783. realParams = [ ...realParams, ...this.tasks[name] ];
  1784. }
  1785. return unique(realParams);
  1786. } catch (error) {
  1787. throwError(error, 'Social.getRealParams');
  1788. return [];
  1789. }
  1790. }
  1791. }
  1792. const social_Social = Social;
  1793. class Discord extends social_Social {
  1794. tasks;
  1795. whiteList;
  1796. #auth = GM_getValue('discordAuth') || {};
  1797. #cache = GM_getValue('discordCache') || {};
  1798. #initialized = false;
  1799. constructor() {
  1800. super();
  1801. const defaultTasksTemplate = {
  1802. servers: []
  1803. };
  1804. this.tasks = defaultTasksTemplate;
  1805. this.whiteList = {
  1806. ...defaultTasksTemplate,
  1807. ...GM_getValue('whiteList')?.discord || {}
  1808. };
  1809. }
  1810. async init(action) {
  1811. try {
  1812. if (!GM_getValue('dontRemindDiscordAgain')) {
  1813. const result = await external_Swal_default().fire({
  1814. title: i18n('discordImportantNotice'),
  1815. text: i18n('discordImportantNoticeText'),
  1816. showCancelButton: true,
  1817. showDenyButton: true,
  1818. confirmButtonText: i18n('continue'),
  1819. cancelButtonText: i18n('skipDiscordTask'),
  1820. denyButtonText: i18n('continueAndDontRemindAgain')
  1821. }).then(({
  1822. isConfirmed,
  1823. isDenied
  1824. }) => {
  1825. if (isConfirmed) {
  1826. return true;
  1827. }
  1828. if (isDenied) {
  1829. GM_setValue('dontRemindDiscordAgain', true);
  1830. return true;
  1831. }
  1832. return false;
  1833. });
  1834. if (!result) {
  1835. this.#initialized = false;
  1836. return 'skip';
  1837. }
  1838. }
  1839. if (GM_getValue('dontRemindDiscordAgain') || action === 'do' && !globalOptions.doTask.discord.servers || action === 'undo' && !globalOptions.undoTask.discord.servers) {
  1840. this.#initialized = false;
  1841. return 'skip';
  1842. }
  1843. if (this.#initialized) {
  1844. return true;
  1845. }
  1846. if (!this.#auth.auth) {
  1847. if (await this.#updateAuth()) {
  1848. this.#initialized = true;
  1849. return true;
  1850. }
  1851. return false;
  1852. }
  1853. const isVerified = await this.#verifyAuth();
  1854. if (isVerified) {
  1855. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1856. this.#initialized = true;
  1857. return true;
  1858. }
  1859. GM_setValue('discordAuth', {
  1860. auth: null
  1861. });
  1862. if (await this.#updateAuth()) {
  1863. scripts_echoLog({}).success(i18n('initSuccess', 'Discord'));
  1864. this.#initialized = true;
  1865. return true;
  1866. }
  1867. scripts_echoLog({}).error(i18n('initFailed', 'Discord'));
  1868. return false;
  1869. } catch (error) {
  1870. throwError(error, 'Discord.init');
  1871. return false;
  1872. }
  1873. }
  1874. async #verifyAuth() {
  1875. try {
  1876. const logStatus = scripts_echoLog({
  1877. text: i18n('verifyingAuth', 'Discord')
  1878. });
  1879. const {
  1880. result,
  1881. statusText,
  1882. status,
  1883. data
  1884. } = await tools_httpRequest({
  1885. url: 'https://discord.com/api/v6/users/@me',
  1886. method: 'HEAD',
  1887. headers: {
  1888. authorization: this.#auth.auth
  1889. }
  1890. });
  1891. if (result === 'Success') {
  1892. if (data?.status === 200) {
  1893. logStatus.success();
  1894. return true;
  1895. }
  1896. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  1897. return false;
  1898. }
  1899. logStatus.error(`${result}:${statusText}(${status})`);
  1900. return false;
  1901. } catch (error) {
  1902. throwError(error, 'Discord.verifyAuth');
  1903. return false;
  1904. }
  1905. }
  1906. async #updateAuth() {
  1907. try {
  1908. const logStatus = scripts_echoLog({
  1909. text: i18n('updatingAuth', 'Discord')
  1910. });
  1911. return await new Promise(resolve => {
  1912. const newTab = GM_openInTab('https://discord.com/channels/@me#auth', {
  1913. active: true,
  1914. insert: true,
  1915. setParent: true
  1916. });
  1917. newTab.onclose = async () => {
  1918. const auth = GM_getValue('discordAuth')?.auth;
  1919. if (auth) {
  1920. this.#auth = {
  1921. auth: auth
  1922. };
  1923. logStatus.success();
  1924. resolve(await this.#verifyAuth());
  1925. } else {
  1926. logStatus.error('Error: Update discord auth failed!');
  1927. resolve(false);
  1928. }
  1929. };
  1930. });
  1931. } catch (error) {
  1932. throwError(error, 'Discord.updateAuth');
  1933. return false;
  1934. }
  1935. }
  1936. async #joinServer(inviteId) {
  1937. try {
  1938. const logStatus = scripts_echoLog({
  1939. type: 'joiningDiscordServer',
  1940. text: inviteId
  1941. });
  1942. const {
  1943. result,
  1944. statusText,
  1945. status,
  1946. data
  1947. } = await tools_httpRequest({
  1948. url: `https://discord.com/api/v9/invites/${inviteId}`,
  1949. method: 'POST',
  1950. dataType: 'json',
  1951. headers: {
  1952. authorization: this.#auth.auth,
  1953. origin: 'https://discord.com',
  1954. referer: `https://discord.com/invite/${inviteId}`
  1955. }
  1956. });
  1957. if (result === 'Success' && data?.status === 200) {
  1958. logStatus.success();
  1959. const guild = String(data.response?.guild?.id);
  1960. if (guild) {
  1961. this.#setCache(inviteId, guild);
  1962. this.tasks.servers = unique([ ...this.tasks.servers, inviteId ]);
  1963. }
  1964. return true;
  1965. }
  1966. logStatus.error(`${result}:${statusText}(${status})`);
  1967. return false;
  1968. } catch (error) {
  1969. throwError(error, 'Discord.joinServer');
  1970. return false;
  1971. }
  1972. }
  1973. async #leaveServer(inviteId) {
  1974. try {
  1975. if (this.whiteList.servers.includes(inviteId)) {
  1976. scripts_echoLog({
  1977. type: 'whiteList',
  1978. text: 'Discord.leaveServer',
  1979. id: inviteId
  1980. });
  1981. return true;
  1982. }
  1983. const guild = await this.#getGuild(inviteId);
  1984. if (!guild) {
  1985. return false;
  1986. }
  1987. const logStatus = scripts_echoLog({
  1988. type: 'leavingDiscordServer',
  1989. text: guild
  1990. });
  1991. const {
  1992. result,
  1993. statusText,
  1994. status,
  1995. data
  1996. } = await tools_httpRequest({
  1997. url: `https://discord.com/api/v9/users/@me/guilds/${guild}`,
  1998. method: 'DELETE',
  1999. headers: {
  2000. authorization: this.#auth.auth
  2001. }
  2002. });
  2003. if (result === 'Success' && data?.status === 204) {
  2004. logStatus.success();
  2005. return true;
  2006. }
  2007. logStatus.error(`${result}:${statusText}(${status})`);
  2008. return false;
  2009. } catch (error) {
  2010. throwError(error, 'Discord.leaveServer');
  2011. return false;
  2012. }
  2013. }
  2014. async #getGuild(inviteId) {
  2015. try {
  2016. const logStatus = scripts_echoLog({
  2017. type: 'gettingDiscordGuild',
  2018. text: inviteId
  2019. });
  2020. const guild = this.#cache[inviteId];
  2021. if (guild) {
  2022. logStatus.success();
  2023. return guild;
  2024. }
  2025. const {
  2026. result,
  2027. statusText,
  2028. status,
  2029. data
  2030. } = await tools_httpRequest({
  2031. url: `https://discord.com/api/v9/invites/${inviteId}`,
  2032. responseType: 'json',
  2033. method: 'GET'
  2034. });
  2035. if (result === 'Success' && data?.status === 200) {
  2036. const guild = data.response?.guild?.id;
  2037. if (guild) {
  2038. logStatus.success();
  2039. this.#setCache(inviteId, guild);
  2040. return guild;
  2041. }
  2042. logStatus.error(`${result}:${statusText}(${status})`);
  2043. return false;
  2044. }
  2045. logStatus.error(`${result}:${statusText}(${status})`);
  2046. return false;
  2047. } catch (error) {
  2048. throwError(error, 'Discord.getGuild');
  2049. return false;
  2050. }
  2051. }
  2052. async toggle({
  2053. doTask = true,
  2054. serverLinks = []
  2055. }) {
  2056. try {
  2057. if (!this.#initialized) {
  2058. scripts_echoLog({
  2059. text: i18n('needInit')
  2060. });
  2061. return false;
  2062. }
  2063. const prom = [];
  2064. if (doTask && !globalOptions.doTask.discord.servers || !doTask && !globalOptions.undoTask.discord.servers) {
  2065. scripts_echoLog({
  2066. type: 'globalOptionsSkip',
  2067. text: 'discord.servers'
  2068. });
  2069. } else {
  2070. const realServers = this.getRealParams('servers', serverLinks, doTask, link => link.match(/invite\/(.+)/)?.[1]);
  2071. if (realServers.length > 0) {
  2072. for (const server of realServers) {
  2073. if (doTask) {
  2074. prom.push(this.#joinServer(server));
  2075. } else {
  2076. prom.push(this.#leaveServer(server));
  2077. }
  2078. await delay(1e3);
  2079. }
  2080. }
  2081. }
  2082. return await Promise.all(prom).then(() => true);
  2083. } catch (error) {
  2084. throwError(error, 'Discord.toggleServers');
  2085. return false;
  2086. }
  2087. }
  2088. #setCache(inviteId, guild) {
  2089. try {
  2090. this.#cache[inviteId] = guild;
  2091. GM_setValue('discordCache', this.#cache);
  2092. } catch (error) {
  2093. throwError(error, 'Discord.setCache');
  2094. }
  2095. }
  2096. }
  2097. const social_Discord = Discord;
  2098. class Instagram extends social_Social {
  2099. tasks;
  2100. whiteList;
  2101. #cache = GM_getValue('instagramCache') || {};
  2102. #auth = {};
  2103. #initialized = false;
  2104. constructor() {
  2105. super();
  2106. const defaultTasksTemplate = {
  2107. users: []
  2108. };
  2109. this.tasks = defaultTasksTemplate;
  2110. this.whiteList = {
  2111. ...defaultTasksTemplate,
  2112. ...GM_getValue('whiteList')?.instagram || {}
  2113. };
  2114. }
  2115. async init() {
  2116. try {
  2117. if (this.#initialized) {
  2118. return true;
  2119. }
  2120. const isVerified = await this.#getUserInfo();
  2121. if (isVerified) {
  2122. scripts_echoLog({}).success(i18n('initSuccess', 'Instagram'));
  2123. this.#initialized = true;
  2124. return true;
  2125. }
  2126. scripts_echoLog({}).error(i18n('initFailed', 'Instagram'));
  2127. return false;
  2128. } catch (error) {
  2129. throwError(error, 'Instagram.init');
  2130. return false;
  2131. }
  2132. }
  2133. async #getUserInfo(name = 'instagram') {
  2134. try {
  2135. const logStatus = scripts_echoLog({
  2136. type: name === 'instagram' ? 'verifyingInsAuth' : 'gettingInsUserId',
  2137. text: name
  2138. });
  2139. const userId = this.#cache[name];
  2140. if (userId && name !== 'instagram') {
  2141. logStatus.success();
  2142. return userId;
  2143. }
  2144. const {
  2145. result,
  2146. statusText,
  2147. status,
  2148. data
  2149. } = await tools_httpRequest({
  2150. url: `https://www.instagram.com/${name}/`,
  2151. method: 'GET'
  2152. });
  2153. if (result === 'Success') {
  2154. if (data?.finalUrl.includes('accounts/login')) {
  2155. logStatus.error(`Error:${i18n('loginIns')}`, true);
  2156. return false;
  2157. } else if (data?.finalUrl.includes('www.instagram.com/challenge')) {
  2158. logStatus.error(`Error:${i18n('insBanned')}`);
  2159. return false;
  2160. }
  2161. if (data?.status === 200) {
  2162. const csrftoken = data.responseText.match(/"csrf_token":"(.+?)"/)?.[1];
  2163. const hash = data.responseText.match(/"rollout_hash":"(.+?)"/)?.[1];
  2164. if (name === 'instagram') {
  2165. if (csrftoken && hash) {
  2166. this.#auth = {
  2167. csrftoken: csrftoken,
  2168. hash: hash
  2169. };
  2170. return true;
  2171. }
  2172. return false;
  2173. }
  2174. const id = data.responseText.match(/"profilePage_([\d]+?)"/)?.[1];
  2175. if (id) {
  2176. this.#setCache(name, id);
  2177. logStatus.success();
  2178. return id;
  2179. }
  2180. logStatus.error('Error: Get ins data error!');
  2181. return false;
  2182. }
  2183. logStatus.error(`${result}:${statusText}(${status})`);
  2184. return false;
  2185. }
  2186. return false;
  2187. } catch (error) {
  2188. throwError(error, 'Instagram.getUserInfo');
  2189. return false;
  2190. }
  2191. }
  2192. async #followUser(name) {
  2193. try {
  2194. const id = await this.#getUserInfo(name);
  2195. if (!id) {
  2196. return false;
  2197. }
  2198. const logStatus = scripts_echoLog({
  2199. type: 'followingIns',
  2200. text: name
  2201. });
  2202. const {
  2203. result,
  2204. statusText,
  2205. status,
  2206. data
  2207. } = await tools_httpRequest({
  2208. url: `https://www.instagram.com/web/friendships/${id}/follow/`,
  2209. method: 'POST',
  2210. dataType: 'json',
  2211. headers: {
  2212. 'x-csrftoken': this.#auth.csrftoken,
  2213. origin: 'https://www.instagram.com',
  2214. referer: `https://www.instagram.com/${name}/`,
  2215. 'content-type': 'application/x-www-form-urlencoded',
  2216. 'sec-fetch-site': 'same-origin',
  2217. 'x-instagram-ajax': this.#auth.hash
  2218. }
  2219. });
  2220. if (result === 'Success') {
  2221. if (data?.status === 200 && data.response?.result === 'following') {
  2222. logStatus.success();
  2223. this.tasks.users = unique([ ...this.tasks.users, name ]);
  2224. return true;
  2225. }
  2226. logStatus.error(`Error:${data?.response?.feedback_message || `${data?.statusText}(${data?.status})`}`);
  2227. return false;
  2228. }
  2229. logStatus.error(`${result}:${statusText}(${status})`);
  2230. return false;
  2231. } catch (error) {
  2232. throwError(error, 'Instagram.followUser');
  2233. return false;
  2234. }
  2235. }
  2236. async #unfollowUser(name) {
  2237. try {
  2238. if (this.whiteList.users.includes(name)) {
  2239. scripts_echoLog({
  2240. type: 'whiteList',
  2241. text: 'Instagram.unfollowUser',
  2242. id: name
  2243. });
  2244. return true;
  2245. }
  2246. const id = await this.#getUserInfo(name);
  2247. if (!id) {
  2248. return false;
  2249. }
  2250. const logStatus = scripts_echoLog({
  2251. type: 'unfollowingIns',
  2252. text: name
  2253. });
  2254. const {
  2255. result,
  2256. statusText,
  2257. status,
  2258. data
  2259. } = await tools_httpRequest({
  2260. url: `https://www.instagram.com/web/friendships/${id}/unfollow/`,
  2261. method: 'POST',
  2262. dataType: 'json',
  2263. headers: {
  2264. 'x-csrftoken': this.#auth.csrftoken,
  2265. origin: 'https://www.instagram.com',
  2266. referer: `https://www.instagram.com/${name}/`,
  2267. 'content-type': 'application/x-www-form-urlencoded',
  2268. 'sec-fetch-site': 'same-origin',
  2269. 'x-instagram-ajax': this.#auth.hash
  2270. }
  2271. });
  2272. if (result === 'Success') {
  2273. if (data?.status === 200 && data.response?.status === 'ok') {
  2274. logStatus.success();
  2275. return true;
  2276. }
  2277. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2278. return false;
  2279. }
  2280. logStatus.error(`${result}:${statusText}(${status})`);
  2281. return false;
  2282. } catch (error) {
  2283. throwError(error, 'Instagram.unfollowUser');
  2284. return false;
  2285. }
  2286. }
  2287. async toggle({
  2288. doTask = true,
  2289. userLinks = []
  2290. }) {
  2291. try {
  2292. if (!this.#initialized) {
  2293. scripts_echoLog({
  2294. text: i18n('needInit')
  2295. });
  2296. return false;
  2297. }
  2298. const prom = [];
  2299. if (doTask && !globalOptions.doTask.instagram.users || !doTask && !globalOptions.undoTask.instagram.users) {
  2300. scripts_echoLog({
  2301. type: 'globalOptionsSkip',
  2302. text: 'instagram.users'
  2303. });
  2304. } else {
  2305. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1]);
  2306. if (realUsers.length > 0) {
  2307. for (const username of realUsers) {
  2308. if (doTask) {
  2309. prom.push(this.#followUser(username));
  2310. } else {
  2311. prom.push(this.#unfollowUser(username));
  2312. }
  2313. await delay(1e3);
  2314. }
  2315. }
  2316. }
  2317. return await Promise.all(prom).then(() => true);
  2318. } catch (error) {
  2319. throwError(error, 'Instagram.toggleUsers');
  2320. return false;
  2321. }
  2322. }
  2323. #setCache(name, id) {
  2324. try {
  2325. this.#cache[name] = id;
  2326. GM_setValue('instagramCache', this.#cache);
  2327. } catch (error) {
  2328. throwError(error, 'Instagram.setCache');
  2329. }
  2330. }
  2331. }
  2332. const social_Instagram = Instagram;
  2333. class Reddit extends social_Social {
  2334. tasks;
  2335. whiteList;
  2336. #auth;
  2337. #initialized = false;
  2338. constructor() {
  2339. super();
  2340. const defaultTasksTemplate = {
  2341. reddits: []
  2342. };
  2343. this.tasks = defaultTasksTemplate;
  2344. this.whiteList = {
  2345. ...defaultTasksTemplate,
  2346. ...GM_getValue('whiteList')?.reddit || {}
  2347. };
  2348. }
  2349. async init() {
  2350. try {
  2351. if (this.#initialized) {
  2352. return true;
  2353. }
  2354. const isVerified = await this.#updateAuth();
  2355. if (isVerified) {
  2356. scripts_echoLog({}).success(i18n('initSuccess', 'Reddit'));
  2357. this.#initialized = true;
  2358. return true;
  2359. }
  2360. scripts_echoLog({}).error(i18n('initFailed', 'Reddit'));
  2361. return false;
  2362. } catch (error) {
  2363. throwError(error, 'Reddit.init');
  2364. return false;
  2365. }
  2366. }
  2367. async #useBeta() {
  2368. try {
  2369. const logStatus = scripts_echoLog({
  2370. text: i18n('changingRedditVersion')
  2371. });
  2372. GM_setValue('redditAuth', null);
  2373. return await new Promise(resolve => {
  2374. const newTab = GM_openInTab('https://www.reddit.com/#auth', {
  2375. active: true,
  2376. insert: true,
  2377. setParent: true
  2378. });
  2379. newTab.onclose = async () => {
  2380. logStatus.success();
  2381. resolve(await this.#updateAuth(true));
  2382. };
  2383. });
  2384. } catch (error) {
  2385. throwError(error, 'Reddit.useBeta');
  2386. return false;
  2387. }
  2388. }
  2389. async #updateAuth(beta = false) {
  2390. try {
  2391. const logStatus = scripts_echoLog({
  2392. text: i18n('updatingAuth', 'Reddit')
  2393. });
  2394. const {
  2395. result,
  2396. statusText,
  2397. status,
  2398. data
  2399. } = await tools_httpRequest({
  2400. url: 'https://www.reddit.com/',
  2401. method: 'GET',
  2402. nochche: true,
  2403. headers: {
  2404. 'Cache-Control': 'no-cache'
  2405. }
  2406. });
  2407. if (result === 'Success') {
  2408. if (data?.responseText.includes('www.reddit.com/login/')) {
  2409. logStatus.error(`Error:${i18n('loginReddit')}`, true);
  2410. return false;
  2411. }
  2412. if (data?.status === 200) {
  2413. if (data.responseText.includes('redesign-beta-optin-btn') && !beta) {
  2414. return await this.#useBeta();
  2415. }
  2416. const accessToken = data.responseText.match(/"accessToken":"(.*?)","expires":"(.*?)"/)?.[1];
  2417. if (accessToken) {
  2418. this.#auth = {
  2419. token: accessToken
  2420. };
  2421. logStatus.success();
  2422. return true;
  2423. }
  2424. logStatus.error('Error: Parameter "accessToken" not found!');
  2425. return false;
  2426. }
  2427. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2428. return false;
  2429. }
  2430. logStatus.error(`${result}:${statusText}(${status})`);
  2431. return false;
  2432. } catch (error) {
  2433. throwError(error, 'Reddit.updateAuth');
  2434. return false;
  2435. }
  2436. }
  2437. async toggleTask({
  2438. name,
  2439. doTask = true
  2440. }) {
  2441. try {
  2442. if (!doTask && this.whiteList.reddits.includes(name)) {
  2443. scripts_echoLog({
  2444. type: 'whiteList',
  2445. text: 'Reddit.undoTask',
  2446. id: name
  2447. });
  2448. return true;
  2449. }
  2450. let type = doTask ? 'joiningReddit' : 'leavingReddit';
  2451. if (/^u_/.test(name)) {
  2452. type = doTask ? 'followingRedditUser' : 'unfollowingRedditUser';
  2453. }
  2454. const logStatus = scripts_echoLog({
  2455. type: type,
  2456. text: name
  2457. });
  2458. const {
  2459. result,
  2460. statusText,
  2461. status,
  2462. data
  2463. } = await tools_httpRequest({
  2464. url: 'https://oauth.reddit.com/api/subscribe?redditWebClient=desktop2x&app=desktop2x-client-production&raw_json=1&gilding_detail=1',
  2465. method: 'POST',
  2466. headers: {
  2467. authorization: `Bearer ${this.#auth.token}`,
  2468. 'content-type': 'application/x-www-form-urlencoded'
  2469. },
  2470. data: $.param({
  2471. action: doTask ? 'sub' : 'unsub',
  2472. sr_name: name,
  2473. api_type: 'json'
  2474. })
  2475. });
  2476. if (result === 'Success') {
  2477. if (data?.status === 200) {
  2478. logStatus.success();
  2479. if (doTask) {
  2480. this.tasks.reddits = unique([ ...this.tasks.reddits, name ]);
  2481. }
  2482. return true;
  2483. }
  2484. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2485. return false;
  2486. }
  2487. logStatus.error(`${result}:${statusText}(${status})`);
  2488. return false;
  2489. } catch (error) {
  2490. throwError(error, 'Reddit.toggleTask');
  2491. return false;
  2492. }
  2493. }
  2494. async toggle({
  2495. doTask = true,
  2496. redditLinks = []
  2497. }) {
  2498. try {
  2499. if (!this.#initialized) {
  2500. scripts_echoLog({
  2501. text: i18n('needInit')
  2502. });
  2503. return false;
  2504. }
  2505. const prom = [];
  2506. if (doTask && !globalOptions.doTask.reddit.reddits || !doTask && !globalOptions.undoTask.reddit.reddits) {
  2507. scripts_echoLog({
  2508. type: 'globalOptionsSkip',
  2509. text: 'reddit.reddits'
  2510. });
  2511. } else {
  2512. const realReddits = this.getRealParams('reddits', redditLinks, doTask, link => {
  2513. const name = link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1];
  2514. const userName = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1];
  2515. if (userName) {
  2516. return name || userName;
  2517. }
  2518. return name;
  2519. });
  2520. if (realReddits.length > 0) {
  2521. for (const name of realReddits) {
  2522. prom.push(this.toggleTask({
  2523. name: name,
  2524. doTask: doTask
  2525. }));
  2526. await delay(1e3);
  2527. }
  2528. }
  2529. }
  2530. return await Promise.all(prom).then(() => true);
  2531. } catch (error) {
  2532. throwError(error, 'Reddit.toggle');
  2533. return false;
  2534. }
  2535. }
  2536. }
  2537. const social_Reddit = Reddit;
  2538. class Twitch extends social_Social {
  2539. tasks;
  2540. whiteList;
  2541. #auth = GM_getValue('twitchAuth') || {};
  2542. #cache = GM_getValue('twitchCache') || {};
  2543. #initialized = false;
  2544. #integrityToken;
  2545. constructor() {
  2546. super();
  2547. const defaultTasksTemplate = {
  2548. channels: []
  2549. };
  2550. this.tasks = defaultTasksTemplate;
  2551. this.whiteList = {
  2552. ...defaultTasksTemplate,
  2553. ...GM_getValue('whiteList')?.twitch || {}
  2554. };
  2555. }
  2556. async init() {
  2557. try {
  2558. if (this.#initialized) {
  2559. return true;
  2560. }
  2561. if (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId) {
  2562. if (await this.#updateAuth()) {
  2563. this.#initialized = true;
  2564. return true;
  2565. }
  2566. return false;
  2567. }
  2568. const isVerified = await this.#verifyAuth(true);
  2569. if (isVerified) {
  2570. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2571. this.#initialized = true;
  2572. return true;
  2573. }
  2574. GM_setValue('twitchAuth', null);
  2575. if (await this.#updateAuth()) {
  2576. scripts_echoLog({}).success(i18n('initSuccess', 'Twitch'));
  2577. this.#initialized = true;
  2578. return true;
  2579. }
  2580. scripts_echoLog({}).error(i18n('initFailed', 'Twitch'));
  2581. return false;
  2582. } catch (error) {
  2583. throwError(error, 'Twitch.init');
  2584. return false;
  2585. }
  2586. }
  2587. async #verifyAuth(isFirst) {
  2588. try {
  2589. const logStatus = scripts_echoLog({
  2590. text: i18n('verifyingAuth', 'Twitch')
  2591. });
  2592. const {
  2593. result,
  2594. statusText,
  2595. status,
  2596. data
  2597. } = await tools_httpRequest({
  2598. url: 'https://gql.twitch.tv/gql',
  2599. method: 'POST',
  2600. dataType: 'json',
  2601. headers: {
  2602. Authorization: `OAuth ${this.#auth.authToken}`,
  2603. 'Client-Id': this.#auth.clientId
  2604. },
  2605. data: '[{"operationName":"FrontPageNew_User","variables":{"limit":1},"extensions":{"persistedQuery":{"version":1,' + '"sha256Hash":"64bd07a2cbaca80699d62636d966cf6395a5d14a1f0a14282067dcb28b13eb11"}}}]'
  2606. });
  2607. if (result === 'Success') {
  2608. if (data?.status === 200 && data.response?.[0]?.data?.currentUser) {
  2609. await this.#integrity(isFirst);
  2610. logStatus.success();
  2611. return true;
  2612. }
  2613. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2614. return false;
  2615. }
  2616. logStatus.error(`${result}:${statusText}(${status})`);
  2617. return false;
  2618. } catch (error) {
  2619. throwError(error, 'Twitch.verifyAuth');
  2620. return false;
  2621. }
  2622. }
  2623. async #integrity(isFirst = true, ct = '') {
  2624. try {
  2625. const logStatus = scripts_echoLog({
  2626. text: i18n('checkingTwitchIntegrity')
  2627. });
  2628. if (isFirst && (!this.#auth.authToken || !this.#auth.clientId || !this.#auth.clientVersion || !this.#auth.deviceId || !this.#auth.clientSessionId)) {
  2629. return await this.#updateAuth(false);
  2630. }
  2631. const {
  2632. result,
  2633. statusText,
  2634. status,
  2635. data
  2636. } = await tools_httpRequest({
  2637. url: 'https://gql.twitch.tv/integrity',
  2638. method: 'POST',
  2639. dataType: 'json',
  2640. anonymous: true,
  2641. headers: {
  2642. Origin: 'https://www.twitch.tv',
  2643. Referer: 'https://www.twitch.tv/',
  2644. Authorization: `OAuth ${this.#auth.authToken}`,
  2645. 'Client-Id': this.#auth.clientId,
  2646. 'Client-Version': this.#auth.clientVersion,
  2647. 'X-Device-Id': this.#auth.deviceId,
  2648. 'Client-Session-Id': this.#auth.clientSessionId,
  2649. 'x-kpsdk-ct': ct
  2650. }
  2651. });
  2652. if (result === 'Success') {
  2653. if (!ct && data?.responseHeaders?.['x-kpsdk-ct']) {
  2654. return await this.#integrity(isFirst, data.responseHeaders['x-kpsdk-ct']);
  2655. }
  2656. if (data?.status === 200 && data.response?.token) {
  2657. this.#integrityToken = data.response.token;
  2658. logStatus.success();
  2659. return true;
  2660. }
  2661. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2662. return false;
  2663. }
  2664. logStatus.error(`${result}:${statusText}(${status})`);
  2665. return false;
  2666. } catch (error) {
  2667. throwError(error, 'Twitch.integrity');
  2668. return false;
  2669. }
  2670. }
  2671. async #updateAuth(isFirst = true) {
  2672. try {
  2673. const logStatus = scripts_echoLog({
  2674. text: i18n('updatingAuth', 'Twitch')
  2675. });
  2676. return await new Promise(resolve => {
  2677. const newTab = GM_openInTab('https://www.twitch.tv/#auth', {
  2678. active: true,
  2679. insert: true,
  2680. setParent: true
  2681. });
  2682. newTab.onclose = async () => {
  2683. const auth = GM_getValue('twitchAuth');
  2684. if (auth) {
  2685. this.#auth = auth;
  2686. logStatus.success();
  2687. resolve(await this.#verifyAuth(isFirst));
  2688. } else {
  2689. logStatus.error('Error: Update twitch auth failed!');
  2690. resolve(false);
  2691. }
  2692. };
  2693. });
  2694. } catch (error) {
  2695. throwError(error, 'Twitch.updateAuth');
  2696. return false;
  2697. }
  2698. }
  2699. async #toggleChannel({
  2700. name,
  2701. doTask = true
  2702. }) {
  2703. try {
  2704. if (!doTask && this.whiteList.channels.includes(name)) {
  2705. scripts_echoLog({
  2706. type: 'whiteList',
  2707. text: 'Twitch.unfollowChannel',
  2708. id: name
  2709. });
  2710. return true;
  2711. }
  2712. const channelId = await this.#getChannelId(name);
  2713. if (!channelId) {
  2714. return false;
  2715. }
  2716. const logStatus = scripts_echoLog({
  2717. type: `${doTask ? '' : 'un'}followingTwitchChannel`,
  2718. text: name
  2719. });
  2720. const followData = `[{"operationName":"FollowButton_FollowUser","variables":{"input":{"disableNotifications":false,"targetID":"${channelId}` + '"}},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"800e7346bdf7e5278a3c1d3f21b2b56e2639928f86815677a7126b093b2fdd08"}}}]';
  2721. const unfollowData = `[{"operationName":"FollowButton_UnfollowUser","variables":{"input":{"targetID":"${channelId}"}},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"f7dae976ebf41c755ae2d758546bfd176b4eeb856656098bb40e0a672ca0d880"}}}]';
  2722. const {
  2723. result,
  2724. statusText,
  2725. status,
  2726. data
  2727. } = await tools_httpRequest({
  2728. url: 'https://gql.twitch.tv/gql',
  2729. method: 'POST',
  2730. dataType: 'json',
  2731. anonymous: true,
  2732. headers: {
  2733. Origin: 'https://www.twitch.tv',
  2734. Referer: 'https://www.twitch.tv/',
  2735. Authorization: `OAuth ${this.#auth.authToken}`,
  2736. 'Client-Id': this.#auth.clientId,
  2737. 'Client-Version': this.#auth.clientVersion,
  2738. 'X-Device-Id': this.#auth.deviceId,
  2739. 'Client-Session-Id': this.#auth.clientSessionId,
  2740. 'Client-Integrity': this.#integrityToken
  2741. },
  2742. data: doTask ? followData : unfollowData
  2743. });
  2744. if (result === 'Success') {
  2745. if (data?.status === 200 && data.response?.[0] && !data.response[0].errors) {
  2746. logStatus.success();
  2747. if (doTask) {
  2748. this.tasks.channels = unique([ ...this.tasks.channels, name ]);
  2749. }
  2750. return true;
  2751. }
  2752. logStatus.error(`Error:${data?.response?.[0].errors?.[0]?.message || `${data?.statusText}(${data?.status})`}`);
  2753. return false;
  2754. }
  2755. logStatus.error(`${result}:${statusText}(${status})`);
  2756. return false;
  2757. } catch (error) {
  2758. throwError(error, 'Twitch.toggleChannel');
  2759. return false;
  2760. }
  2761. }
  2762. async #getChannelId(name) {
  2763. try {
  2764. const logStatus = scripts_echoLog({
  2765. type: 'gettingTwitchChannelId',
  2766. text: name
  2767. });
  2768. const channelId = this.#cache[name];
  2769. if (channelId) {
  2770. logStatus.success();
  2771. return channelId;
  2772. }
  2773. const {
  2774. result,
  2775. statusText,
  2776. status,
  2777. data
  2778. } = await tools_httpRequest({
  2779. url: 'https://gql.twitch.tv/gql',
  2780. method: 'POST',
  2781. headers: {
  2782. Authorization: `OAuth ${this.#auth.authToken}`,
  2783. 'Client-Id': this.#auth.clientId
  2784. },
  2785. responseType: 'json',
  2786. data: `[{"operationName":"ActiveWatchParty","variables":{"channelLogin":"${name}"},` + '"extensions":{"persistedQuery":{"version":1,"sha256Hash":"4a8156c97b19e3a36e081cf6d6ddb5dbf9f9b02ae60e4d2ff26ed70aebc80a30"}}}]'
  2787. });
  2788. if (result === 'Success') {
  2789. if (data?.status === 200) {
  2790. const channelId = data.response?.[0]?.data?.user?.id;
  2791. if (channelId) {
  2792. this.#setCache(name, String(channelId));
  2793. logStatus.success();
  2794. return channelId;
  2795. }
  2796. logStatus.error(`Error:${data.statusText}(${data.status})`);
  2797. return false;
  2798. }
  2799. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  2800. return false;
  2801. }
  2802. logStatus.error(`${result}:${statusText}(${status})`);
  2803. return false;
  2804. } catch (error) {
  2805. throwError(error, 'Twitch.getChannelId');
  2806. return false;
  2807. }
  2808. }
  2809. async toggle({
  2810. doTask = true,
  2811. channelLinks = []
  2812. }) {
  2813. try {
  2814. if (!this.#initialized) {
  2815. scripts_echoLog({
  2816. text: i18n('needInit')
  2817. });
  2818. return false;
  2819. }
  2820. const prom = [];
  2821. if (doTask && !globalOptions.doTask.twitch.channels || !doTask && !globalOptions.undoTask.twitch.channels) {
  2822. scripts_echoLog({
  2823. type: 'globalOptionsSkip',
  2824. text: 'twitch.channels'
  2825. });
  2826. } else {
  2827. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2]);
  2828. if (realChannels.length > 0) {
  2829. for (const channel of realChannels) {
  2830. prom.push(this.#toggleChannel({
  2831. name: channel,
  2832. doTask: doTask
  2833. }));
  2834. await delay(1e3);
  2835. }
  2836. }
  2837. }
  2838. return Promise.all(prom).then(() => true);
  2839. } catch (error) {
  2840. throwError(error, 'Twitch.toggle');
  2841. return false;
  2842. }
  2843. }
  2844. #setCache(name, id) {
  2845. try {
  2846. this.#cache[name] = id;
  2847. GM_setValue('twitchCache', this.#cache);
  2848. } catch (error) {
  2849. throwError(error, 'Twitch.setCache');
  2850. }
  2851. }
  2852. }
  2853. const social_Twitch = Twitch;
  2854. class Twitter extends social_Social {
  2855. tasks;
  2856. whiteList;
  2857. #verifyId = globalOptions.other.twitterVerifyId;
  2858. #auth = GM_getValue('twitterAuth') || {};
  2859. #cache = GM_getValue('twitterCache') || {};
  2860. #initialized = false;
  2861. constructor() {
  2862. super();
  2863. const defaultTasksTemplate = {
  2864. users: [],
  2865. retweets: [],
  2866. likes: []
  2867. };
  2868. this.tasks = defaultTasksTemplate;
  2869. this.whiteList = {
  2870. ...defaultTasksTemplate,
  2871. ...GM_getValue('whiteList')?.twitter || {}
  2872. };
  2873. }
  2874. async init() {
  2875. try {
  2876. if (this.#initialized) {
  2877. return true;
  2878. }
  2879. if (!this.#auth.ct0) {
  2880. if (await this.#updateAuth()) {
  2881. this.#initialized = true;
  2882. return true;
  2883. }
  2884. return false;
  2885. }
  2886. const isVerified = await this.#verifyAuth();
  2887. if (isVerified) {
  2888. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2889. this.#initialized = true;
  2890. return true;
  2891. }
  2892. GM_setValue('twitterAuth', null);
  2893. if (await this.#updateAuth()) {
  2894. scripts_echoLog({}).success(i18n('initSuccess', 'Twitter'));
  2895. this.#initialized = true;
  2896. return true;
  2897. }
  2898. scripts_echoLog({}).error(i18n('initFailed', 'Twitter'));
  2899. return false;
  2900. } catch (error) {
  2901. throwError(error, 'Twitter.init');
  2902. return false;
  2903. }
  2904. }
  2905. async #verifyAuth() {
  2906. try {
  2907. return await this.#toggleUser({
  2908. name: 'verify',
  2909. doTask: true,
  2910. verify: true
  2911. });
  2912. } catch (error) {
  2913. throwError(error, 'Twitter.verifyAuth');
  2914. return false;
  2915. }
  2916. }
  2917. async #updateAuth() {
  2918. try {
  2919. const logStatus = scripts_echoLog({
  2920. text: i18n('updatingAuth', 'Twitter')
  2921. });
  2922. return await new Promise(resolve => {
  2923. GM_cookie.list({
  2924. url: 'https://x.com/settings/account'
  2925. }, async (cookies, error) => {
  2926. if (!error) {
  2927. const [ ct0, isLogin ] = cookies.map(cookie => [ 'ct0', 'twid' ].includes(cookie.name) ? cookie.value : null).filter(cookie => cookie);
  2928. if (isLogin && ct0) {
  2929. GM_setValue('twitterAuth', {
  2930. ct0: ct0
  2931. });
  2932. this.#auth = {
  2933. ct0: ct0
  2934. };
  2935. logStatus.success();
  2936. resolve(await this.#verifyAuth());
  2937. } else {
  2938. logStatus.error(i18n('needLogin'));
  2939. resolve(false);
  2940. }
  2941. } else {
  2942. logStatus.error('Error: Update twitter auth failed!');
  2943. resolve(false);
  2944. }
  2945. });
  2946. });
  2947. } catch (error) {
  2948. throwError(error, 'Twitter.updateToken');
  2949. return false;
  2950. }
  2951. }
  2952. async #toggleUser({
  2953. name,
  2954. doTask = true,
  2955. verify = false
  2956. }) {
  2957. try {
  2958. if (!doTask && !verify && this.whiteList.users.includes(name)) {
  2959. scripts_echoLog({
  2960. type: 'whiteList',
  2961. text: 'Twitter.unfollowUser',
  2962. id: name
  2963. });
  2964. return true;
  2965. }
  2966. const userId = verify ? this.#verifyId : await this.userName2id(name);
  2967. if (!userId) {
  2968. return false;
  2969. }
  2970. const logStatus = verify ? scripts_echoLog({
  2971. text: i18n('verifyingAuth', 'Twitter')
  2972. }) : scripts_echoLog({
  2973. type: `${doTask ? '' : 'un'}followingTwitterUser`,
  2974. text: name
  2975. });
  2976. const {
  2977. result,
  2978. statusText,
  2979. status,
  2980. data
  2981. } = await tools_httpRequest({
  2982. url: `https://x.com/i/api/1.1/friendships/${doTask ? 'create' : 'destroy'}.json`,
  2983. method: 'POST',
  2984. headers: {
  2985. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  2986. 'Content-Type': 'application/x-www-form-urlencoded',
  2987. 'x-csrf-token': this.#auth.ct0
  2988. },
  2989. responseType: 'json',
  2990. data: $.param({
  2991. include_profile_interstitial_type: 1,
  2992. include_blocking: 1,
  2993. include_blocked_by: 1,
  2994. include_followed_by: 1,
  2995. include_want_retweets: 1,
  2996. include_mute_edge: 1,
  2997. include_can_dm: 1,
  2998. include_can_media_tag: 1,
  2999. skip_status: 1,
  3000. id: userId
  3001. })
  3002. });
  3003. if (result === 'Success') {
  3004. if (data?.status === 200) {
  3005. logStatus.success();
  3006. if (doTask && !verify) {
  3007. this.tasks.users = unique([ ...this.tasks.users, name ]);
  3008. }
  3009. return true;
  3010. }
  3011. if (verify && data?.status === 403 && data.response?.errors?.[0]?.code === 158) {
  3012. logStatus.success();
  3013. return true;
  3014. }
  3015. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3016. return false;
  3017. }
  3018. logStatus.error(`${result}:${statusText}(${status})`);
  3019. return false;
  3020. } catch (error) {
  3021. throwError(error, 'Twitter.toggleUser');
  3022. return false;
  3023. }
  3024. }
  3025. async userName2id(name) {
  3026. try {
  3027. const logStatus = scripts_echoLog({
  3028. type: 'gettingTwitterUserId',
  3029. text: name
  3030. });
  3031. const userId = this.#cache[name];
  3032. if (userId) {
  3033. logStatus.success();
  3034. return userId;
  3035. }
  3036. const {
  3037. result,
  3038. statusText,
  3039. status,
  3040. data
  3041. } = await tools_httpRequest({
  3042. 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`,
  3043. method: 'GET',
  3044. headers: {
  3045. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3046. 'content-type': 'application/json',
  3047. referer: `https://x.com/${name}`,
  3048. 'x-csrf-token': this.#auth.ct0
  3049. },
  3050. responseType: 'json'
  3051. });
  3052. if (result === 'Success') {
  3053. if (data?.status === 200) {
  3054. let response = data.response || (typeof data.responseText === 'object' ? data.responseText : null);
  3055. if (!response) {
  3056. try {
  3057. response = JSON.parse(data.responseText);
  3058. } catch (error) {
  3059. response = null;
  3060. }
  3061. }
  3062. const userId = String(response?.data?.user?.result?.rest_id);
  3063. if (userId) {
  3064. this.#setCache(name, userId);
  3065. logStatus.success();
  3066. return userId;
  3067. }
  3068. logStatus.error(`Error:${data.statusText}(${data.status})`);
  3069. return false;
  3070. }
  3071. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3072. return false;
  3073. }
  3074. logStatus.error(`${result}:${statusText}(${status})`);
  3075. return false;
  3076. } catch (error) {
  3077. throwError(error, 'Twitter.getUserId');
  3078. return false;
  3079. }
  3080. }
  3081. async #toggleRetweet({
  3082. retweetId,
  3083. doTask = true
  3084. }) {
  3085. try {
  3086. if (!doTask && this.whiteList.retweets.includes(retweetId)) {
  3087. scripts_echoLog({
  3088. type: 'whiteList',
  3089. text: 'Twitter.unretweet',
  3090. id: retweetId
  3091. });
  3092. return true;
  3093. }
  3094. const logStatus = scripts_echoLog({
  3095. type: `${doTask ? '' : 'un'}retweetting`,
  3096. text: retweetId
  3097. });
  3098. const {
  3099. result,
  3100. statusText,
  3101. status,
  3102. data
  3103. } = await tools_httpRequest({
  3104. url: `https://x.com/i/api/graphql/${doTask ? 'ojPdsZsimiJrUGLR1sjUtA/CreateRetweet' : 'iQtK4dl5hBmXewYZuEOKVw/DeleteRetweet'}`,
  3105. method: 'POST',
  3106. headers: {
  3107. authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  3108. 'Content-Type': 'application/json',
  3109. 'x-csrf-token': this.#auth.ct0
  3110. },
  3111. data: `{"variables":{"tweet_id":"${retweetId}","dark_request":false},"queryId":"${doTask ? 'ojPdsZsimiJrUGLR1sjUtA' : 'iQtK4dl5hBmXewYZuEOKVw'}"}`,
  3112. responseType: 'json'
  3113. });
  3114. if (result === 'Success') {
  3115. if (data?.status === 200 || data?.status === 403 && data.response?.errors?.[0]?.code === 327) {
  3116. logStatus.success();
  3117. if (doTask) {
  3118. this.tasks.retweets = unique([ ...this.tasks.retweets, retweetId ]);
  3119. }
  3120. return true;
  3121. }
  3122. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3123. return false;
  3124. }
  3125. logStatus.error(`${result}:${statusText}(${status})`);
  3126. return false;
  3127. } catch (error) {
  3128. throwError(error, 'Twitter.toggleRetweet');
  3129. return false;
  3130. }
  3131. }
  3132. async toggle({
  3133. doTask = true,
  3134. userLinks = [],
  3135. retweetLinks = []
  3136. }) {
  3137. try {
  3138. if (!this.#initialized) {
  3139. scripts_echoLog({
  3140. text: i18n('needInit')
  3141. });
  3142. return false;
  3143. }
  3144. const prom = [];
  3145. if (doTask && !globalOptions.doTask.twitter.users || !doTask && !globalOptions.undoTask.twitter.users) {
  3146. scripts_echoLog({
  3147. type: 'globalOptionsSkip',
  3148. text: 'twitter.users'
  3149. });
  3150. } else {
  3151. const realUsers = this.getRealParams('users', userLinks, doTask, link => link.match(/https:\/\/x\.com\/(.+)/)?.[1] || link.match(/https:\/\/twitter\.com\/(.+)/)?.[1]);
  3152. if (realUsers.length > 0) {
  3153. for (const user of realUsers) {
  3154. prom.push(this.#toggleUser({
  3155. name: user,
  3156. doTask: doTask
  3157. }));
  3158. await delay(1e3);
  3159. }
  3160. }
  3161. }
  3162. if (doTask && !globalOptions.doTask.twitter.retweets || !doTask && !globalOptions.undoTask.twitter.retweets) {
  3163. scripts_echoLog({
  3164. type: 'globalOptionsSkip',
  3165. text: 'twitter.retweets'
  3166. });
  3167. } else {
  3168. const realRetweets = this.getRealParams('retweets', retweetLinks, doTask, link => link.match(/https:\/\/x\.com\/.*?\/status\/([\d]+)/)?.[1] || link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1]);
  3169. if (realRetweets.length > 0) {
  3170. for (const retweet of realRetweets) {
  3171. prom.push(this.#toggleRetweet({
  3172. retweetId: retweet,
  3173. doTask: doTask
  3174. }));
  3175. await delay(1e3);
  3176. }
  3177. }
  3178. }
  3179. return Promise.all(prom).then(() => true);
  3180. } catch (error) {
  3181. throwError(error, 'Twitter.toggle');
  3182. return false;
  3183. }
  3184. }
  3185. #setCache(name, id) {
  3186. try {
  3187. this.#cache[name] = id;
  3188. GM_setValue('twitterCache', this.#cache);
  3189. } catch (error) {
  3190. throwError(error, 'Twitter.setCache');
  3191. }
  3192. }
  3193. }
  3194. const social_Twitter = Twitter;
  3195. class Vk extends social_Social {
  3196. tasks;
  3197. whiteList;
  3198. #username = '';
  3199. #cache = GM_getValue('vkCache') || {};
  3200. #initialized = false;
  3201. constructor() {
  3202. super();
  3203. const defaultTasksTemplate = {
  3204. names: []
  3205. };
  3206. this.tasks = defaultTasksTemplate;
  3207. this.whiteList = {
  3208. ...defaultTasksTemplate,
  3209. ...GM_getValue('whiteList')?.vk || {}
  3210. };
  3211. }
  3212. async init() {
  3213. try {
  3214. if (this.#initialized) {
  3215. return true;
  3216. }
  3217. const isVerified = await this.#verifyAuth();
  3218. if (isVerified) {
  3219. scripts_echoLog({}).success(i18n('initSuccess', 'Vk'));
  3220. this.#initialized = true;
  3221. return true;
  3222. }
  3223. scripts_echoLog({}).error(i18n('initFailed', 'Vk'));
  3224. return false;
  3225. } catch (error) {
  3226. throwError(error, 'Vk.init');
  3227. return false;
  3228. }
  3229. }
  3230. async #verifyAuth() {
  3231. try {
  3232. const logStatus = scripts_echoLog({
  3233. text: i18n('verifyAuth', 'Vk')
  3234. });
  3235. const {
  3236. result,
  3237. statusText,
  3238. status,
  3239. data
  3240. } = await tools_httpRequest({
  3241. url: 'https://vk.com/im',
  3242. method: 'GET'
  3243. });
  3244. if (result === 'Success') {
  3245. if (data?.finalUrl.includes('vk.com/login')) {
  3246. logStatus.error(`Error:${i18n('loginVk')}`, true);
  3247. return false;
  3248. }
  3249. if (data?.status === 200) {
  3250. this.#username = data.responseText.match(/TopNavBtn__profileLink" href="\/(.*?)"/)?.[1] || '';
  3251. logStatus.success();
  3252. return true;
  3253. }
  3254. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3255. return false;
  3256. }
  3257. logStatus.error(`${result}:${statusText}(${status})`);
  3258. return false;
  3259. } catch (error) {
  3260. throwError(error, 'Vk.verifyAuth');
  3261. return false;
  3262. }
  3263. }
  3264. async #toggleGroup(name, dataParam, doTask = true) {
  3265. try {
  3266. const logStatus = scripts_echoLog({
  3267. type: doTask ? 'joiningVkGroup' : 'leavingVkGroup',
  3268. text: name
  3269. });
  3270. if (dataParam.groupAct === 'enter' && !doTask || dataParam.groupAct === 'leave' && doTask) {
  3271. logStatus.success();
  3272. return true;
  3273. }
  3274. const reqData = {
  3275. act: doTask ? 'enter' : 'leave',
  3276. al: 1,
  3277. gid: dataParam.groupId,
  3278. hash: dataParam.groupHash
  3279. };
  3280. if (doTask) {
  3281. reqData.context = '_';
  3282. }
  3283. const {
  3284. result,
  3285. statusText,
  3286. status,
  3287. data
  3288. } = await tools_httpRequest({
  3289. url: 'https://vk.com/al_groups.php',
  3290. method: 'POST',
  3291. headers: {
  3292. origin: 'https://vk.com',
  3293. referer: `https://vk.com/${name}`,
  3294. 'content-type': 'application/x-www-form-urlencoded'
  3295. },
  3296. data: $.param(reqData)
  3297. });
  3298. if (result === 'Success') {
  3299. if (data?.status === 200) {
  3300. logStatus.success();
  3301. if (doTask) {
  3302. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3303. }
  3304. return true;
  3305. }
  3306. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3307. return false;
  3308. }
  3309. logStatus.error(`${result}:${statusText}(${status})`);
  3310. return false;
  3311. } catch (error) {
  3312. throwError(error, 'Vk.toggleGroup');
  3313. return false;
  3314. }
  3315. }
  3316. async #togglePublic(name, dataParam, doTask = true) {
  3317. try {
  3318. const logStatus = scripts_echoLog({
  3319. type: doTask ? 'joiningVkPublic' : 'leavingVkPublic',
  3320. text: name
  3321. });
  3322. if (dataParam.publicJoined && doTask || !dataParam.publicJoined && !doTask) {
  3323. logStatus.success();
  3324. return true;
  3325. }
  3326. const {
  3327. result,
  3328. statusText,
  3329. status,
  3330. data
  3331. } = await tools_httpRequest({
  3332. url: 'https://vk.com/al_public.php',
  3333. method: 'POST',
  3334. headers: {
  3335. origin: 'https://vk.com',
  3336. referer: `https://vk.com/${name}`,
  3337. 'content-type': 'application/x-www-form-urlencoded'
  3338. },
  3339. data: $.param({
  3340. act: doTask ? 'a_enter' : 'a_leave',
  3341. al: 1,
  3342. pid: dataParam.publicPid,
  3343. hash: dataParam.publicHash
  3344. })
  3345. });
  3346. if (result === 'Success') {
  3347. if (data?.status === 200) {
  3348. logStatus.success();
  3349. if (doTask) {
  3350. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3351. }
  3352. return true;
  3353. }
  3354. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3355. return false;
  3356. }
  3357. logStatus.error(`${result}:${statusText}(${status})`);
  3358. return false;
  3359. } catch (error) {
  3360. throwError(error, 'Vk.togglePublic');
  3361. return false;
  3362. }
  3363. }
  3364. async #sendWall(name) {
  3365. try {
  3366. const logStatus = scripts_echoLog({
  3367. type: 'sendingVkWall',
  3368. text: name
  3369. });
  3370. const {
  3371. result,
  3372. statusText,
  3373. status,
  3374. data
  3375. } = await tools_httpRequest({
  3376. url: 'https://vk.com/like.php',
  3377. method: 'POST',
  3378. headers: {
  3379. origin: 'https://vk.com',
  3380. referer: `https://vk.com/${name}`,
  3381. 'content-type': 'application/x-www-form-urlencoded'
  3382. },
  3383. data: $.param({
  3384. act: 'publish_box',
  3385. al: 1,
  3386. object: name
  3387. })
  3388. });
  3389. if (result === 'Success') {
  3390. if (data?.status === 200) {
  3391. const hash = data.responseText.match(/shHash:[\s]*'(.*?)'/)?.[1];
  3392. if (hash) {
  3393. const {
  3394. result: resultR,
  3395. statusText: statusTextR,
  3396. status: statusR,
  3397. data: dataR
  3398. } = await tools_httpRequest({
  3399. url: 'https://vk.com/like.php',
  3400. method: 'POST',
  3401. headers: {
  3402. origin: 'https://vk.com',
  3403. referer: `https://vk.com/${name}`,
  3404. 'content-type': 'application/x-www-form-urlencoded'
  3405. },
  3406. data: $.param({
  3407. Message: '',
  3408. act: 'a_do_publish',
  3409. al: 1,
  3410. close_comments: 0,
  3411. friends_only: 0,
  3412. from: 'box',
  3413. hash: hash,
  3414. list: '',
  3415. mark_as_ads: 0,
  3416. mute_notifications: 0,
  3417. object: name,
  3418. ret_data: 1,
  3419. to: 0
  3420. })
  3421. });
  3422. if (resultR === 'Success') {
  3423. if (dataR?.status === 200) {
  3424. const jsonData = JSON.parse(dataR.responseText?.replace('\x3c!--', '') || '{}');
  3425. if (jsonData?.payload?.[1]?.[1]?.share_my === true) {
  3426. logStatus.success();
  3427. const postId = String(jsonData?.payload?.[1]?.[1]?.post_id);
  3428. const ownerId = String(jsonData?.payload?.[1]?.[1]?.owner_id);
  3429. if (postId && ownerId) {
  3430. this.#setCache(name, `${ownerId}_${postId}`);
  3431. }
  3432. this.tasks.names = unique([ ...this.tasks.names, name ]);
  3433. return true;
  3434. }
  3435. }
  3436. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  3437. return false;
  3438. }
  3439. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  3440. return false;
  3441. }
  3442. logStatus.error('Error: Get "hash" failed');
  3443. return false;
  3444. }
  3445. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3446. return false;
  3447. }
  3448. logStatus.error(`${result}:${statusText}(${status})`);
  3449. return false;
  3450. } catch (error) {
  3451. throwError(error, 'Vk.sendWall');
  3452. return false;
  3453. }
  3454. }
  3455. async #deleteWall(name, dataParams) {
  3456. try {
  3457. const logStatus = scripts_echoLog({
  3458. type: 'deletingVkWall',
  3459. text: name
  3460. });
  3461. const {
  3462. result,
  3463. statusText,
  3464. status,
  3465. data
  3466. } = await tools_httpRequest({
  3467. url: 'https://vk.com/al_wall.php?act=delete',
  3468. method: 'POST',
  3469. headers: {
  3470. origin: 'https://vk.com',
  3471. referer: `https://vk.com/${this.#username}?w=wall${this.#cache[name]}%2Fall`,
  3472. 'content-type': 'application/x-www-form-urlencoded'
  3473. },
  3474. data: $.param({
  3475. act: 'delete',
  3476. al: 1,
  3477. confirm: 0,
  3478. from: 'wkview',
  3479. hash: dataParams.wallHash,
  3480. post: this.#cache[name]
  3481. })
  3482. });
  3483. if (result === 'Success') {
  3484. if (data?.status === 200) {
  3485. const jsonData = JSON.parse(data.responseText?.replace('\x3c!--', '') || '{}');
  3486. if (jsonData?.payload?.[1]?.[1]) {
  3487. logStatus.success();
  3488. return true;
  3489. }
  3490. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3491. return false;
  3492. }
  3493. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3494. return false;
  3495. }
  3496. logStatus.error(`${result}:${statusText}(${status})`);
  3497. return false;
  3498. } catch (error) {
  3499. throwError(error, 'Vk.deleteWall');
  3500. return false;
  3501. }
  3502. }
  3503. async #getId(name, doTask) {
  3504. try {
  3505. let url = `https://vk.com/${name}`;
  3506. if (/^wall-/.test(name)) {
  3507. if (doTask) {
  3508. return {
  3509. type: 'sendWall'
  3510. };
  3511. }
  3512. if (!this.#cache[name]) {
  3513. return {
  3514. type: 'unSupport'
  3515. };
  3516. }
  3517. url = `https://vk.com/${this.#username}?w=wall${this.#cache[name]}`;
  3518. }
  3519. const logStatus = scripts_echoLog({
  3520. type: 'gettingVkId',
  3521. text: name
  3522. });
  3523. const {
  3524. result,
  3525. statusText,
  3526. status,
  3527. data
  3528. } = await tools_httpRequest({
  3529. url: url,
  3530. method: 'GET'
  3531. });
  3532. if (result === 'Success') {
  3533. if (data?.status === 200) {
  3534. const [ , groupAct, groupId, , groupHash ] = data.responseText.match(/Groups.(enter|leave)\(.*?,.*?([\d]+?), (&#39;|')(.*?)(&#39;|')/) || [];
  3535. const publicHash = data.responseText.match(/"enterHash":"(.*?)"/)?.[1];
  3536. const publicPid = data.responseText.match(/"public_id":([\d]+?),/)?.[1];
  3537. const publicJoined = !data.responseText.includes('Public.subscribe');
  3538. if (groupAct && groupId && groupHash) {
  3539. logStatus.success();
  3540. return {
  3541. groupAct: groupAct,
  3542. groupId: groupId,
  3543. groupHash: groupHash,
  3544. type: 'group'
  3545. };
  3546. } else if (publicHash && publicPid) {
  3547. logStatus.success();
  3548. return {
  3549. publicHash: publicHash,
  3550. publicPid: publicPid,
  3551. publicJoined: publicJoined,
  3552. type: 'public'
  3553. };
  3554. } else if (data.responseText.includes('wall.deletePost') && !doTask) {
  3555. const wallHash = data.responseText.match(/wall\.deletePost\(this, '.*?', '(.*?)'\)/)?.[1];
  3556. if (wallHash) {
  3557. logStatus.success();
  3558. return {
  3559. type: 'deleteWall',
  3560. wallHash: wallHash
  3561. };
  3562. }
  3563. } else if (name.includes('wall') && doTask) {
  3564. logStatus.success();
  3565. return {
  3566. type: 'sendWall'
  3567. };
  3568. }
  3569. logStatus.error('Error: Parameters not found!');
  3570. return false;
  3571. }
  3572. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3573. return false;
  3574. }
  3575. logStatus.error(`${result}:${statusText}(${status})`);
  3576. return false;
  3577. } catch (error) {
  3578. throwError(error, 'Vk.getId');
  3579. return false;
  3580. }
  3581. }
  3582. async #toggleVk({
  3583. name,
  3584. doTask = true
  3585. }) {
  3586. try {
  3587. if (!doTask && this.whiteList.names.includes(name)) {
  3588. scripts_echoLog({
  3589. type: 'whiteList',
  3590. text: 'Vk.undoTask',
  3591. id: name
  3592. });
  3593. return true;
  3594. }
  3595. const formatName = name.replace(/\/$/, '');
  3596. const data = await this.#getId(formatName, doTask);
  3597. if (!data) {
  3598. return false;
  3599. }
  3600. switch (data.type) {
  3601. case 'group':
  3602. return await this.#toggleGroup(formatName, data, doTask);
  3603.  
  3604. case 'public':
  3605. return await this.#togglePublic(formatName, data, doTask);
  3606.  
  3607. case 'sendWall':
  3608. return doTask ? await this.#sendWall(formatName) : true;
  3609.  
  3610. case 'deleteWall':
  3611. return doTask ? true : await this.#deleteWall(formatName, data);
  3612.  
  3613. default:
  3614. return false;
  3615. }
  3616. } catch (error) {
  3617. throwError(error, 'Vk.toggleVk');
  3618. return false;
  3619. }
  3620. }
  3621. async toggle({
  3622. doTask = true,
  3623. nameLinks = []
  3624. }) {
  3625. try {
  3626. if (!this.#initialized) {
  3627. scripts_echoLog({
  3628. text: i18n('needInit')
  3629. });
  3630. return false;
  3631. }
  3632. const prom = [];
  3633. if (doTask && !globalOptions.doTask.vk.names || !doTask && !globalOptions.undoTask.vk.names) {
  3634. scripts_echoLog({
  3635. type: 'globalOptionsSkip',
  3636. text: 'vk.names'
  3637. });
  3638. } else {
  3639. const realNames = this.getRealParams('names', nameLinks, doTask, link => link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1]);
  3640. if (realNames.length > 0) {
  3641. for (const name of realNames) {
  3642. prom.push(this.#toggleVk({
  3643. name: name,
  3644. doTask: doTask
  3645. }));
  3646. await delay(1e3);
  3647. }
  3648. }
  3649. }
  3650. return Promise.all(prom).then(() => true);
  3651. } catch (error) {
  3652. throwError(error, 'Vk.toggle');
  3653. return false;
  3654. }
  3655. }
  3656. #setCache(name, postId) {
  3657. try {
  3658. this.#cache[name] = postId;
  3659. GM_setValue('vkCache', this.#cache);
  3660. } catch (error) {
  3661. throwError(error, 'Vk.setCache');
  3662. }
  3663. }
  3664. }
  3665. const social_Vk = Vk;
  3666. const getInfo = async function(link, type) {
  3667. try {
  3668. const logStatus = scripts_echoLog({
  3669. text: i18n('gettingYtbToken')
  3670. });
  3671. const {
  3672. result,
  3673. statusText,
  3674. status,
  3675. data
  3676. } = await tools_httpRequest({
  3677. url: link,
  3678. method: 'GET'
  3679. });
  3680. if (result === 'Success') {
  3681. if (data?.status === 200) {
  3682. if (data.responseText.includes('accounts.google.com/ServiceLogin?service=youtube')) {
  3683. logStatus.error(`Error:${i18n('loginYtb')}`, true);
  3684. return {
  3685. needLogin: true
  3686. };
  3687. }
  3688. const apiKey = data.responseText.match(/"INNERTUBE_API_KEY":"(.*?)"/)?.[1];
  3689. const context = (data.responseText.match(/\(\{"INNERTUBE_CONTEXT":([\w\W]*?)\}\)/) || data.responseText.match(/"INNERTUBE_CONTEXT":([\w\W]*?\}),"INNERTUBE/))?.[1] || '{}';
  3690. const {
  3691. client,
  3692. request
  3693. } = JSON.parse(context);
  3694. if (apiKey && client && request) {
  3695. client.hl = 'en';
  3696. if (type === 'channel') {
  3697. const channelId = data.responseText.match(/"channelId":"(.+?)"/)?.[1];
  3698. if (channelId) {
  3699. logStatus.success();
  3700. return {
  3701. params: {
  3702. apiKey: apiKey,
  3703. client: client,
  3704. request: request,
  3705. channelId: channelId
  3706. }
  3707. };
  3708. }
  3709. logStatus.error('Error: Get "channelId" failed!');
  3710. return {};
  3711. } else if (type === 'likeVideo') {
  3712. const videoId = data.responseText.match(/<link rel="shortlinkUrl" href="https:\/\/youtu\.be\/(.*?)">/)?.[1];
  3713. const likeParams = data.responseText.match(/"likeParams":"(.*?)"/)?.[1];
  3714. if (videoId) {
  3715. logStatus.success();
  3716. return {
  3717. params: {
  3718. apiKey: apiKey,
  3719. client: client,
  3720. request: request,
  3721. videoId: videoId,
  3722. likeParams: likeParams
  3723. }
  3724. };
  3725. }
  3726. logStatus.error('Error: Get "videoId" failed!');
  3727. return {};
  3728. }
  3729. logStatus.error('Error: Unknown type');
  3730. return {};
  3731. }
  3732. logStatus.error('Error: Parameter "apiKey" not found!');
  3733. return {};
  3734. }
  3735. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3736. return {};
  3737. }
  3738. logStatus.error(`${result}:${statusText}(${status})`);
  3739. return {};
  3740. } catch (error) {
  3741. throwError(error, 'Youtube.getInfo');
  3742. return {};
  3743. }
  3744. };
  3745. class Youtube extends social_Social {
  3746. tasks;
  3747. whiteList;
  3748. #auth = GM_getValue('youtubeAuth') || {};
  3749. #initialized = false;
  3750. #verifyChannel = `https://www.youtube.com/channel/${globalOptions.other.youtubeVerifyChannel}`;
  3751. constructor() {
  3752. super();
  3753. const defaultTasksTemplate = {
  3754. channels: [],
  3755. likes: []
  3756. };
  3757. this.tasks = defaultTasksTemplate;
  3758. this.whiteList = {
  3759. ...defaultTasksTemplate,
  3760. ...GM_getValue('whiteList')?.youtube || {}
  3761. };
  3762. }
  3763. async init() {
  3764. try {
  3765. if (this.#initialized) {
  3766. return true;
  3767. }
  3768. if (!this.#auth.PAPISID) {
  3769. if (await this.#updateAuth()) {
  3770. this.#initialized = true;
  3771. return true;
  3772. }
  3773. return false;
  3774. }
  3775. const isVerified = await this.#verifyAuth();
  3776. if (isVerified) {
  3777. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3778. this.#initialized = true;
  3779. return true;
  3780. }
  3781. GM_setValue('youtubeAuth', null);
  3782. if (await this.#updateAuth()) {
  3783. scripts_echoLog({}).success(i18n('initSuccess', 'Youtube'));
  3784. this.#initialized = true;
  3785. return true;
  3786. }
  3787. scripts_echoLog({}).error(i18n('initFailed', 'Youtube'));
  3788. return false;
  3789. } catch (error) {
  3790. throwError(error, 'Youtube.init');
  3791. return false;
  3792. }
  3793. }
  3794. async #verifyAuth() {
  3795. try {
  3796. return await this.#toggleChannel({
  3797. link: this.#verifyChannel,
  3798. doTask: true,
  3799. verify: true
  3800. });
  3801. } catch (error) {
  3802. throwError(error, 'Youtube.verifyAuth');
  3803. return false;
  3804. }
  3805. }
  3806. async #updateAuth() {
  3807. try {
  3808. const logStatus = scripts_echoLog({
  3809. text: i18n('updatingAuth', 'Youtube')
  3810. });
  3811. return await new Promise(resolve => {
  3812. GM_cookie.list({
  3813. url: 'https://www.youtube.com/@YouTube'
  3814. }, async (cookies, error) => {
  3815. if (!error) {
  3816. const PAPISID = cookies.find(cookie => cookie.name === '__Secure-3PAPISID')?.value;
  3817. if (PAPISID) {
  3818. GM_setValue('youtubeAuth', {
  3819. PAPISID: PAPISID
  3820. });
  3821. this.#auth = {
  3822. PAPISID: PAPISID
  3823. };
  3824. logStatus.success();
  3825. resolve(await this.#verifyAuth());
  3826. } else {
  3827. logStatus.error(i18n('needLogin'));
  3828. resolve(false);
  3829. }
  3830. } else {
  3831. logStatus.error('Error: Update youtube auth failed!');
  3832. resolve(false);
  3833. }
  3834. });
  3835. });
  3836. } catch (error) {
  3837. throwError(error, 'Youtube.updateAuth');
  3838. return false;
  3839. }
  3840. }
  3841. #getInfo(link, type) {
  3842. return getInfo(link, type);
  3843. }
  3844. async #toggleChannel({
  3845. link,
  3846. doTask = true,
  3847. verify = false
  3848. }) {
  3849. try {
  3850. const {
  3851. params,
  3852. needLogin
  3853. } = await this.#getInfo(link, 'channel');
  3854. const {
  3855. apiKey,
  3856. client,
  3857. request,
  3858. channelId
  3859. } = params || {};
  3860. if (needLogin) {
  3861. scripts_echoLog({
  3862. html: i18n('loginYtb')
  3863. });
  3864. return false;
  3865. }
  3866. if (!(apiKey && client && request && channelId)) {
  3867. scripts_echoLog({
  3868. text: '"getYtbToken" failed'
  3869. });
  3870. return false;
  3871. }
  3872. if (!doTask && !verify && this.whiteList.channels.includes(channelId)) {
  3873. scripts_echoLog({
  3874. type: 'whiteList',
  3875. text: 'Youtube.unfollowChannel',
  3876. id: channelId
  3877. });
  3878. return true;
  3879. }
  3880. const logStatus = verify ? scripts_echoLog({
  3881. text: i18n('verifyingAuth', 'Youtube')
  3882. }) : scripts_echoLog({
  3883. type: doTask ? 'followingYtbChannel' : 'unfollowingYtbChannel',
  3884. text: channelId
  3885. });
  3886. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3887. const {
  3888. result,
  3889. statusText,
  3890. status,
  3891. data
  3892. } = await tools_httpRequest({
  3893. url: `https://www.youtube.com/youtubei/v1/subscription/${doTask ? '' : 'un'}subscribe?key=${apiKey}&prettyPrint=false`,
  3894. method: 'POST',
  3895. headers: {
  3896. origin: 'https://www.youtube.com',
  3897. referer: `https://www.youtube.com/channel/${channelId}`,
  3898. 'content-type': 'application/json',
  3899. 'x-goog-authuser': '0',
  3900. 'x-goog-visitor-id': client?.visitorData,
  3901. 'x-origin': 'https://www.youtube.com',
  3902. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  3903. },
  3904. data: JSON.stringify({
  3905. context: {
  3906. client: client,
  3907. request: {
  3908. sessionId: request?.sessionId,
  3909. internalExperimentFlags: [],
  3910. consistencyTokenJars: []
  3911. },
  3912. user: {}
  3913. },
  3914. channelIds: [ channelId ],
  3915. params: doTask ? 'EgIIAhgA' : 'CgIIAhgA'
  3916. })
  3917. });
  3918. if (result === 'Success') {
  3919. if (data?.status === 200) {
  3920. if (doTask && (/"subscribed":true/.test(data.responseText) || data.responseText.includes('The subscription already exists')) || !doTask && /"subscribed":false/.test(data.responseText)) {
  3921. logStatus.success();
  3922. if (doTask && !verify) {
  3923. this.tasks.channels = unique([ ...this.tasks.channels, link ]);
  3924. }
  3925. return true;
  3926. }
  3927. if (verify && data.responseText.includes('You may not subscribe to yourself')) {
  3928. logStatus.success();
  3929. return true;
  3930. }
  3931. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  3932. return false;
  3933. }
  3934. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  3935. return false;
  3936. }
  3937. logStatus.error(`${result}:${statusText}(${status})`);
  3938. return false;
  3939. } catch (error) {
  3940. throwError(error, 'Youtube.toggleChannel');
  3941. return false;
  3942. }
  3943. }
  3944. async #toggleLikeVideo({
  3945. link,
  3946. doTask = true
  3947. }) {
  3948. try {
  3949. const {
  3950. params,
  3951. needLogin
  3952. } = await this.#getInfo(link, 'likeVideo');
  3953. const {
  3954. apiKey,
  3955. client,
  3956. request,
  3957. videoId,
  3958. likeParams
  3959. } = params || {};
  3960. if (needLogin) {
  3961. scripts_echoLog({
  3962. html: `${i18n('loginYtb')}`
  3963. });
  3964. return false;
  3965. }
  3966. if (!(apiKey && client && request && videoId && likeParams)) {
  3967. scripts_echoLog({
  3968. text: '"getYtbToken" failed'
  3969. });
  3970. return false;
  3971. }
  3972. if (!doTask && this.whiteList.likes.includes(videoId)) {
  3973. scripts_echoLog({
  3974. type: 'whiteList',
  3975. text: 'Youtube.unlikeVideo',
  3976. id: videoId
  3977. });
  3978. return true;
  3979. }
  3980. const logStatus = scripts_echoLog({
  3981. type: doTask ? 'likingYtbVideo' : 'unlikingYtbVideo',
  3982. text: videoId
  3983. });
  3984. const nowTime = parseInt(String(new Date().getTime() / 1e3), 10);
  3985. const likeVideoData = {
  3986. context: {
  3987. client: client,
  3988. request: {
  3989. sessionId: request.sessionId,
  3990. internalExperimentFlags: [],
  3991. consistencyTokenJars: []
  3992. },
  3993. user: {}
  3994. },
  3995. target: {
  3996. videoId: videoId
  3997. }
  3998. };
  3999. if (doTask) {
  4000. if (likeParams) {
  4001. likeVideoData.params = likeParams;
  4002. } else {
  4003. logStatus.error('Empty likeParams');
  4004. return false;
  4005. }
  4006. }
  4007. const {
  4008. result,
  4009. statusText,
  4010. status,
  4011. data
  4012. } = await tools_httpRequest({
  4013. url: `https://www.youtube.com/youtubei/v1/like/${doTask ? '' : 'remove'}like?key=${apiKey}`,
  4014. method: 'POST',
  4015. headers: {
  4016. origin: 'https://www.youtube.com',
  4017. referer: `https://www.youtube.com/watch?v=${videoId}`,
  4018. 'content-type': 'application/json',
  4019. 'x-goog-authuser': '0',
  4020. 'x-goog-visitor-id': client.visitorData,
  4021. 'x-origin': 'https://www.youtube.com',
  4022. authorization: `SAPISIDHASH ${nowTime}_${sha1(`${nowTime} ${this.#auth.PAPISID} https://www.youtube.com`)}`
  4023. },
  4024. data: JSON.stringify(likeVideoData)
  4025. });
  4026. if (result === 'Success') {
  4027. if (data?.status === 200) {
  4028. if (doTask && data.responseText.includes('Added to Liked videos') || !doTask && (data.responseText.includes('Removed from Liked videos') || data.responseText.includes('Dislike removed'))) {
  4029. logStatus.success();
  4030. if (doTask) {
  4031. this.tasks.likes = unique([ ...this.tasks.likes, link ]);
  4032. }
  4033. return true;
  4034. }
  4035. logStatus.error(i18n('tryUpdateYtbAuth'), true);
  4036. return false;
  4037. }
  4038. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4039. return false;
  4040. }
  4041. logStatus.error(`${result}:${statusText}(${status})`);
  4042. return false;
  4043. } catch (error) {
  4044. throwError(error, 'Youtube.toggleLikeVideo');
  4045. return false;
  4046. }
  4047. }
  4048. async toggle({
  4049. doTask = true,
  4050. channelLinks = [],
  4051. videoLinks = []
  4052. }) {
  4053. try {
  4054. if (!this.#initialized) {
  4055. scripts_echoLog({
  4056. text: i18n('needInit')
  4057. });
  4058. return false;
  4059. }
  4060. const prom = [];
  4061. if (doTask && !globalOptions.doTask.youtube.channels || !doTask && !globalOptions.undoTask.youtube.channels) {
  4062. scripts_echoLog({
  4063. type: 'globalOptionsSkip',
  4064. text: 'youtube.channels'
  4065. });
  4066. } else {
  4067. const realChannels = this.getRealParams('channels', channelLinks, doTask, link => {
  4068. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4069. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4070. }
  4071. return link;
  4072. });
  4073. if (realChannels.length > 0) {
  4074. for (const channel of realChannels) {
  4075. prom.push(this.#toggleChannel({
  4076. link: channel,
  4077. doTask: doTask
  4078. }));
  4079. await delay(1e3);
  4080. }
  4081. }
  4082. }
  4083. if (doTask && !globalOptions.doTask.youtube.likes || !doTask && !globalOptions.undoTask.youtube.likes) {
  4084. scripts_echoLog({
  4085. type: 'globalOptionsSkip',
  4086. text: 'youtube.likes'
  4087. });
  4088. } else {
  4089. const realLikes = this.getRealParams('likes', videoLinks, doTask, link => {
  4090. if (/^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www\.youtube\.com\/.*/.test(link)) {
  4091. return link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1];
  4092. }
  4093. return link;
  4094. });
  4095. if (realLikes.length > 0) {
  4096. for (const video of realLikes) {
  4097. prom.push(this.#toggleLikeVideo({
  4098. link: video,
  4099. doTask: doTask
  4100. }));
  4101. await delay(1e3);
  4102. }
  4103. }
  4104. }
  4105. return Promise.all(prom).then(() => true);
  4106. } catch (error) {
  4107. throwError(error, 'Youtube.toggle');
  4108. return false;
  4109. }
  4110. }
  4111. }
  4112. class SteamASF {
  4113. #asfOptions;
  4114. #botName = 'asf';
  4115. #groupInfo;
  4116. async init() {
  4117. try {
  4118. const asfCommandsUrl = new URL('/Api/Command/', globalOptions.ASF.AsfIpcUrl);
  4119. this.#asfOptions = {
  4120. url: asfCommandsUrl.href,
  4121. method: 'POST',
  4122. responseType: 'json',
  4123. headers: {
  4124. accept: 'application/json',
  4125. 'Content-Type': 'application/json',
  4126. Host: asfCommandsUrl.host,
  4127. Origin: asfCommandsUrl.origin,
  4128. Referer: asfCommandsUrl.href,
  4129. Authentication: globalOptions.ASF.AsfIpcPassword
  4130. }
  4131. };
  4132. if (globalOptions.ASF.AsfBotname) {
  4133. this.#botName = globalOptions.ASF.AsfBotname;
  4134. }
  4135. const logStatus = scripts_echoLog({
  4136. text: i18n('initingASF')
  4137. });
  4138. const {
  4139. result,
  4140. statusText,
  4141. status,
  4142. data
  4143. } = await tools_httpRequest({
  4144. ...this.#asfOptions,
  4145. data: '{"Command":"!stats"}'
  4146. });
  4147. if (result === 'Success') {
  4148. if (data?.response?.Success === true && data.response.Message === 'OK' && data.response.Result) {
  4149. logStatus.success();
  4150. return true;
  4151. }
  4152. if (data?.response?.Result || data?.response?.Message) {
  4153. logStatus.error(data?.response?.Result || data.response.Message);
  4154. return false;
  4155. }
  4156. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4157. return false;
  4158. }
  4159. logStatus.error(`${result}:${statusText}(${status})`);
  4160. return false;
  4161. } catch (error) {
  4162. throwError(error, 'SteamASF.init');
  4163. return false;
  4164. }
  4165. }
  4166. async joinGroup(groupName) {
  4167. try {
  4168. const logStatus = scripts_echoLog({
  4169. type: 'joiningSteamGroup',
  4170. text: groupName
  4171. });
  4172. const {
  4173. result,
  4174. statusText,
  4175. status,
  4176. data
  4177. } = await tools_httpRequest({
  4178. ...this.#asfOptions,
  4179. data: JSON.stringify({
  4180. Command: `!JOINGROUP ${this.#botName} ${groupName}`
  4181. })
  4182. });
  4183. if (result === 'Success') {
  4184. if (data?.status === 200 && [ '已加入', '已申请', 'Joined', 'Applied', 'Присоединился', 'costs' ].find(text => data.response?.Result?.includes(text))) {
  4185. logStatus.success();
  4186. return true;
  4187. }
  4188. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4189. return false;
  4190. }
  4191. logStatus.error(`${result}:${statusText}(${status})`);
  4192. return false;
  4193. } catch (error) {
  4194. throwError(error, 'SteamASF.joinGroup');
  4195. return false;
  4196. }
  4197. }
  4198. async leaveGroup(groupName) {
  4199. try {
  4200. if (!this.#groupInfo) {
  4201. if (!await this.#getGroupId()) {
  4202. return false;
  4203. }
  4204. }
  4205. const groupId = await this.#groupInfo[groupName];
  4206. if (!groupId) {
  4207. return false;
  4208. }
  4209. const logStatus = scripts_echoLog({
  4210. type: 'leavingSteamGroup',
  4211. text: groupName
  4212. });
  4213. const {
  4214. result,
  4215. statusText,
  4216. status,
  4217. data
  4218. } = await tools_httpRequest({
  4219. ...this.#asfOptions,
  4220. data: JSON.stringify({
  4221. Command: `!LEAVEGROUP ${this.#botName} ${groupId}`
  4222. })
  4223. });
  4224. if (result === 'Success') {
  4225. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4226. logStatus.success();
  4227. return true;
  4228. }
  4229. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4230. return false;
  4231. }
  4232. logStatus.error(`${result}:${statusText}(${status})`);
  4233. return false;
  4234. } catch (error) {
  4235. throwError(error, 'SteamASF.leaveGroup');
  4236. return false;
  4237. }
  4238. }
  4239. async #getGroupId() {
  4240. try {
  4241. const logStatus = scripts_echoLog({
  4242. type: 'gettingSteamGroupId',
  4243. text: 'All'
  4244. });
  4245. const {
  4246. result,
  4247. statusText,
  4248. status,
  4249. data
  4250. } = await tools_httpRequest({
  4251. ...this.#asfOptions,
  4252. data: JSON.stringify({
  4253. Command: `!GROUPLIST ${this.#botName}`
  4254. })
  4255. });
  4256. if (result === 'Success') {
  4257. if (data?.status === 200 && data.response?.Result?.includes('|')) {
  4258. this.#groupInfo = Object.fromEntries(data.response.Result.split('\n').map(line => {
  4259. const [ , name, id ] = line.trim().split('|');
  4260. if (name && id) {
  4261. return [ name, id ];
  4262. }
  4263. return null;
  4264. }).filter(ele => ele));
  4265. logStatus.success();
  4266. return true;
  4267. }
  4268. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4269. return false;
  4270. }
  4271. logStatus.error(`${result}:${statusText}(${status})`);
  4272. return false;
  4273. } catch (error) {
  4274. throwError(error, 'SteamASF.getGroupID');
  4275. return false;
  4276. }
  4277. }
  4278. async addToWishlist(gameId) {
  4279. try {
  4280. const logStatus = scripts_echoLog({
  4281. type: 'addingToWishlist',
  4282. text: gameId
  4283. });
  4284. const {
  4285. result,
  4286. statusText,
  4287. status,
  4288. data
  4289. } = await tools_httpRequest({
  4290. ...this.#asfOptions,
  4291. data: JSON.stringify({
  4292. Command: `!ADDWISHLIST ${this.#botName} ${gameId}`
  4293. })
  4294. });
  4295. if (result === 'Success') {
  4296. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4297. logStatus.success();
  4298. return true;
  4299. }
  4300. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4301. return false;
  4302. }
  4303. logStatus.error(`${result}:${statusText}(${status})`);
  4304. return false;
  4305. } catch (error) {
  4306. throwError(error, 'SteamASF.addToWishlist');
  4307. return false;
  4308. }
  4309. }
  4310. async removeFromWishlist(gameId) {
  4311. try {
  4312. const logStatus = scripts_echoLog({
  4313. type: 'removingFromWishlist',
  4314. text: gameId
  4315. });
  4316. const {
  4317. result,
  4318. statusText,
  4319. status,
  4320. data
  4321. } = await tools_httpRequest({
  4322. ...this.#asfOptions,
  4323. data: JSON.stringify({
  4324. Command: `!REMOVEWISHLIST ${this.#botName} ${gameId}`
  4325. })
  4326. });
  4327. if (result === 'Success') {
  4328. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4329. logStatus.success();
  4330. return true;
  4331. }
  4332. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4333. return false;
  4334. }
  4335. logStatus.error(`${result}:${statusText}(${status})`);
  4336. return false;
  4337. } catch (error) {
  4338. throwError(error, 'SteamASF.removeFromWishlist');
  4339. return false;
  4340. }
  4341. }
  4342. async toggleFollowGame(gameId, doTask) {
  4343. try {
  4344. const logStatus = scripts_echoLog({
  4345. type: `${doTask ? '' : 'un'}followingGame`,
  4346. text: gameId
  4347. });
  4348. const {
  4349. result,
  4350. statusText,
  4351. status,
  4352. data
  4353. } = await tools_httpRequest({
  4354. ...this.#asfOptions,
  4355. data: JSON.stringify({
  4356. Command: `!${doTask ? '' : 'UN'}FOLLOWGAME ${this.#botName} ${gameId}`
  4357. })
  4358. });
  4359. if (result === 'Success') {
  4360. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4361. logStatus.success();
  4362. return true;
  4363. }
  4364. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4365. return false;
  4366. }
  4367. logStatus.error(`${result}:${statusText}(${status})`);
  4368. return false;
  4369. } catch (error) {
  4370. throwError(error, 'SteamASF.toggleFollowGame');
  4371. return false;
  4372. }
  4373. }
  4374. async toggleCurator(curatorId, doTask = true) {
  4375. try {
  4376. const logStatus = scripts_echoLog({
  4377. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  4378. text: curatorId
  4379. });
  4380. const {
  4381. result,
  4382. statusText,
  4383. status,
  4384. data
  4385. } = await tools_httpRequest({
  4386. ...this.#asfOptions,
  4387. data: JSON.stringify({
  4388. Command: `!${doTask ? '' : 'UN'}FOLLOWCURATOR ${this.#botName} ${curatorId}`
  4389. })
  4390. });
  4391. if (result === 'Success') {
  4392. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4393. logStatus.success();
  4394. return true;
  4395. }
  4396. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4397. return false;
  4398. }
  4399. logStatus.error(`${result}:${statusText}(${status})`);
  4400. return false;
  4401. } catch (error) {
  4402. throwError(error, 'Steam.toggleCurator');
  4403. return false;
  4404. }
  4405. }
  4406. async addLicense(id) {
  4407. try {
  4408. const [ type, ids ] = id.split('-');
  4409. if (type === 'appid') {
  4410. const logStatus = scripts_echoLog({
  4411. type: 'addingFreeLicense',
  4412. text: ids
  4413. });
  4414. const {
  4415. result,
  4416. statusText,
  4417. status,
  4418. data
  4419. } = await tools_httpRequest({
  4420. ...this.#asfOptions,
  4421. data: JSON.stringify({
  4422. Command: `!addlicense ${this.#botName} app/${ids}`
  4423. })
  4424. });
  4425. if (result === 'Success') {
  4426. if (data?.status === 200 && [ 'AlreadyPurchased', 'OK' ].find(text => data.response?.Result?.includes(text))) {
  4427. logStatus.success();
  4428. return true;
  4429. }
  4430. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4431. return false;
  4432. }
  4433. logStatus.error(`${result}:${statusText}(${status})`);
  4434. return false;
  4435. } else if (type === 'subid') {
  4436. const idsArr = ids.split(',');
  4437. const logStatus = scripts_echoLog({
  4438. type: 'addingFreeLicenseSubid',
  4439. text: ids
  4440. });
  4441. const {
  4442. result,
  4443. statusText,
  4444. status,
  4445. data
  4446. } = await tools_httpRequest({
  4447. ...this.#asfOptions,
  4448. data: JSON.stringify({
  4449. Command: `!addlicense ${this.#botName} ${idsArr.map(id => `sub/${id}`).join(',')}`
  4450. })
  4451. });
  4452. if (result === 'Success') {
  4453. if (data?.status === 200 && data.response?.Result) {
  4454. const resultLines = data.response.Result.split('\n');
  4455. idsArr.forEach(subid => {
  4456. const targetLine = resultLines.find(text => text.includes(subid));
  4457. if (targetLine && [ '成功', 'Success', 'Успех' ].find(text => targetLine.includes(text))) {
  4458. scripts_echoLog({}).success(targetLine);
  4459. } else {
  4460. scripts_echoLog({}).error(targetLine);
  4461. }
  4462. });
  4463. return true;
  4464. }
  4465. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4466. return false;
  4467. }
  4468. logStatus.error(`${result}:${statusText}(${status})`);
  4469. return false;
  4470. }
  4471. return false;
  4472. } catch (error) {
  4473. throwError(error, 'SteamASF.addLicense');
  4474. return false;
  4475. }
  4476. }
  4477. async requestPlayTestAccess(id) {
  4478. try {
  4479. const logStatus = scripts_echoLog({
  4480. type: 'requestingPlayTestAccess',
  4481. text: id
  4482. });
  4483. const {
  4484. result,
  4485. statusText,
  4486. status,
  4487. data
  4488. } = await tools_httpRequest({
  4489. ...this.#asfOptions,
  4490. data: JSON.stringify({
  4491. Command: `!REQUESTACCESS ${this.#botName} ${id}`
  4492. })
  4493. });
  4494. if (result === 'Success') {
  4495. if (data?.status === 200 && [ '成功', 'Success', 'Успех' ].find(text => data.response?.Result?.includes(text))) {
  4496. logStatus.success();
  4497. return true;
  4498. }
  4499. logStatus.error(`Error:${data?.response?.Result || data?.response?.Message || data?.statusText}(${data?.status})`);
  4500. return false;
  4501. }
  4502. logStatus.error(`${result}:${statusText}(${status})`);
  4503. return false;
  4504. } catch (error) {
  4505. throwError(error, 'Steam.requestPlayTestAccess');
  4506. return false;
  4507. }
  4508. }
  4509. }
  4510. const social_SteamASF = SteamASF;
  4511. class Steam extends social_Social {
  4512. tasks;
  4513. whiteList;
  4514. #cache = {
  4515. ...{
  4516. group: {},
  4517. officialGroup: {},
  4518. forum: {},
  4519. workshop: {},
  4520. curator: {}
  4521. },
  4522. ...GM_getValue('steamCache')
  4523. };
  4524. #auth = {};
  4525. #storeInitialized = false;
  4526. #communityInitialized = false;
  4527. #area = 'CN';
  4528. #areaStatus = 'end';
  4529. #ASF;
  4530. constructor() {
  4531. super();
  4532. const defaultTasksTemplate = {
  4533. groups: [],
  4534. officialGroups: [],
  4535. wishlists: [],
  4536. follows: [],
  4537. forums: [],
  4538. workshops: [],
  4539. workshopVotes: [],
  4540. curators: [],
  4541. curatorLikes: [],
  4542. announcements: [],
  4543. licenses: [],
  4544. playtests: []
  4545. };
  4546. this.tasks = defaultTasksTemplate;
  4547. this.whiteList = {
  4548. ...defaultTasksTemplate,
  4549. ...GM_getValue('whiteList')?.steam || {}
  4550. };
  4551. }
  4552. async init(type = 'all') {
  4553. try {
  4554. if (globalOptions.ASF.AsfEnabled && globalOptions.ASF.AsfIpcUrl && globalOptions.ASF.AsfIpcPassword) {
  4555. this.#ASF = new social_SteamASF();
  4556. if (await this.#ASF.init()) {
  4557. this.#storeInitialized = true;
  4558. this.#communityInitialized = true;
  4559. return true;
  4560. }
  4561. return false;
  4562. }
  4563. if (type === 'store') {
  4564. if (this.#storeInitialized) {
  4565. return true;
  4566. }
  4567. let storeInitialized = await this.#updateStoreAuth();
  4568. if (!storeInitialized) {
  4569. storeInitialized = await this.#updateStoreAuthTab();
  4570. }
  4571. this.#storeInitialized = storeInitialized;
  4572. if (!this.#storeInitialized) {
  4573. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4574. return false;
  4575. }
  4576. scripts_echoLog({}).success(i18n('initSuccess', 'SteamStore'));
  4577. return true;
  4578. }
  4579. if (type === 'community') {
  4580. if (this.#communityInitialized) {
  4581. return true;
  4582. }
  4583. let communityInitialized = await this.#getUserLink();
  4584. if (!communityInitialized) {
  4585. communityInitialized = await this.#updateCommunityAuthTab();
  4586. GM_setValue('steamCommunityAuth', null);
  4587. }
  4588. this.#communityInitialized = communityInitialized;
  4589. if (!this.#communityInitialized) {
  4590. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4591. return false;
  4592. }
  4593. scripts_echoLog({}).success(i18n('initSuccess', 'SteamCommunity'));
  4594. return true;
  4595. }
  4596. if (this.#storeInitialized && this.#communityInitialized) {
  4597. scripts_echoLog({}).success(i18n('initSuccess', 'Steam'));
  4598. return true;
  4599. }
  4600. scripts_echoLog({}).error(i18n('initFailed', 'Steam'));
  4601. return false;
  4602. } catch (error) {
  4603. throwError(error, 'Steam.init');
  4604. return false;
  4605. }
  4606. }
  4607. async #refreshToken(type = 'steamStore') {
  4608. try {
  4609. const host = {
  4610. steamStore: 'store.steampowered.com',
  4611. steamCommunity: 'steamcommunity.com'
  4612. };
  4613. const logStatus = scripts_echoLog({
  4614. text: i18n('refreshingToken', i18n(type))
  4615. });
  4616. const formData = new FormData();
  4617. formData.append('redir', `https://${host[type]}/`);
  4618. const {
  4619. result,
  4620. statusText,
  4621. status,
  4622. data
  4623. } = await tools_httpRequest({
  4624. url: 'https://login.steampowered.com/jwt/ajaxrefresh',
  4625. method: 'POST',
  4626. responseType: 'json',
  4627. headers: {
  4628. Host: 'login.steampowered.com',
  4629. Origin: `https://${host[type]}`,
  4630. Referer: `https://${host[type]}/`
  4631. },
  4632. data: formData
  4633. });
  4634. if (result === 'Success') {
  4635. if (data?.response?.success) {
  4636. if (await this.#setStoreToken(data.response, type)) {
  4637. logStatus.success();
  4638. return true;
  4639. }
  4640. logStatus.error('Error');
  4641. return false;
  4642. }
  4643. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4644. return false;
  4645. }
  4646. logStatus.error(`${result}:${statusText}(${status})`);
  4647. return false;
  4648. } catch (error) {
  4649. throwError(error, 'Steam.refreshToken');
  4650. return false;
  4651. }
  4652. }
  4653. async #setStoreToken(param, type) {
  4654. try {
  4655. const host = {
  4656. steamStore: 'store.steampowered.com',
  4657. steamCommunity: 'steamcommunity.com'
  4658. };
  4659. const logStatus = scripts_echoLog({
  4660. text: i18n('settingToken', i18n(type))
  4661. });
  4662. const formData = new FormData();
  4663. formData.append('steamID', param.steamID);
  4664. formData.append('nonce', param.nonce);
  4665. formData.append('redir', param.redir);
  4666. formData.append('auth', param.auth);
  4667. const {
  4668. result,
  4669. statusText,
  4670. status,
  4671. data
  4672. } = await tools_httpRequest({
  4673. url: `https://${host[type]}/login/settoken`,
  4674. method: 'POST',
  4675. headers: {
  4676. Accept: 'application/json, text/plain, */*',
  4677. Host: host[type],
  4678. Origin: `https://${host[type]}`
  4679. },
  4680. data: formData
  4681. });
  4682. if (result === 'Success') {
  4683. if (data?.status === 200) {
  4684. logStatus.success();
  4685. return true;
  4686. }
  4687. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4688. return false;
  4689. }
  4690. logStatus.error(`${result}:${statusText}(${status})`);
  4691. return false;
  4692. } catch (error) {
  4693. throwError(error, 'Steam.setStoreToken');
  4694. return false;
  4695. }
  4696. }
  4697. async #updateStoreAuth(retry = false) {
  4698. try {
  4699. const logStatus = scripts_echoLog({
  4700. text: i18n('updatingAuth', i18n('steamStore'))
  4701. });
  4702. const {
  4703. result,
  4704. statusText,
  4705. status,
  4706. data
  4707. } = await tools_httpRequest({
  4708. url: 'https://store.steampowered.com/',
  4709. method: 'GET',
  4710. headers: {
  4711. 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',
  4712. 'Cache-Control': 'max-age=0',
  4713. 'Sec-Fetch-Dest': 'document',
  4714. 'Sec-Fetch-Mode': 'navigate',
  4715. 'Upgrade-Insecure-Requests': '1'
  4716. },
  4717. fetch: false,
  4718. redirect: 'manual'
  4719. });
  4720. if (data?.status === 200) {
  4721. if (!data.responseText.includes('data-miniprofile=')) {
  4722. if (await this.#refreshToken('steamStore')) {
  4723. logStatus.warning(i18n('retry'));
  4724. if (retry) {
  4725. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4726. return false;
  4727. }
  4728. return this.#updateStoreAuth(true);
  4729. }
  4730. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4731. return false;
  4732. }
  4733. const storeSessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4734. if (storeSessionID) {
  4735. this.#auth.storeSessionID = storeSessionID;
  4736. logStatus.success();
  4737. return true;
  4738. }
  4739. logStatus.error('Error: Get "sessionID" failed');
  4740. return false;
  4741. }
  4742. if ([ 301, 302 ].includes(data?.status)) {
  4743. if (await this.#refreshToken('steamStore')) {
  4744. logStatus.warning(i18n('retry'));
  4745. if (retry) {
  4746. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4747. return false;
  4748. }
  4749. return this.#updateStoreAuth(true);
  4750. }
  4751. logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
  4752. return false;
  4753. }
  4754. logStatus.error(`${result}:${statusText}(${status})`);
  4755. return false;
  4756. } catch (error) {
  4757. throwError(error, 'Steam.updateStoreAuth');
  4758. return false;
  4759. }
  4760. }
  4761. async #updateStoreAuthTab() {
  4762. try {
  4763. const logStatus = scripts_echoLog({
  4764. text: i18n('updatingAuth', i18n('steamStore'))
  4765. });
  4766. return await new Promise(resolve => {
  4767. const newTab = window.open('https://store.steampowered.com/', 'mozillaWindow', 'pop=1;');
  4768. GM_setValue('steamStoreAuth', 'update');
  4769. const listenerId = GM_addValueChangeListener('steamStoreAuth', (key, oldValue, newValue, remote) => {
  4770. GM_removeValueChangeListener(listenerId);
  4771. newTab?.close();
  4772. if (newValue && JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
  4773. this.#auth.storeSessionID = newValue.storeSessionID;
  4774. logStatus.success();
  4775. resolve(true);
  4776. return;
  4777. }
  4778. logStatus.error('Failed');
  4779. resolve(false);
  4780. });
  4781. });
  4782. } catch (error) {
  4783. throwError(error, 'Steam.updateStoreAuthTab');
  4784. return false;
  4785. }
  4786. }
  4787. async #updateCommunityAuthTab() {
  4788. try {
  4789. const logStatus = scripts_echoLog({
  4790. text: i18n('updatingAuth', i18n('steamCommunity'))
  4791. });
  4792. return await new Promise(resolve => {
  4793. const newTab = window.open('https://steamcommunity.com/my', 'mozillaWindow', 'pop=1;');
  4794. GM_setValue('steamCommunityAuth', 'update');
  4795. const listenerId = GM_addValueChangeListener('steamCommunityAuth', (key, oldValue, newValue, remote) => {
  4796. GM_removeValueChangeListener(listenerId);
  4797. newTab?.close();
  4798. if (newValue && JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
  4799. this.#auth.steam64Id = newValue.steam64Id;
  4800. this.#auth.userName = newValue.userName;
  4801. this.#auth.communitySessionID = newValue.communitySessionID;
  4802. logStatus.success();
  4803. resolve(true);
  4804. return;
  4805. }
  4806. logStatus.error('Failed');
  4807. resolve(false);
  4808. });
  4809. });
  4810. } catch (error) {
  4811. throwError(error, 'Steam.updateCommunityAuthTab');
  4812. return false;
  4813. }
  4814. }
  4815. async #getUserLink(retry = false) {
  4816. try {
  4817. const logStatus = scripts_echoLog({
  4818. text: i18n('gettingUserLink')
  4819. });
  4820. const {
  4821. result,
  4822. statusText,
  4823. status,
  4824. data
  4825. } = await tools_httpRequest({
  4826. url: 'https://steamcommunity.com/my',
  4827. method: 'GET',
  4828. headers: {
  4829. 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',
  4830. 'Cache-Control': 'max-age=0',
  4831. 'Sec-Fetch-Dest': 'document',
  4832. 'Sec-Fetch-Mode': 'navigate',
  4833. 'Upgrade-Insecure-Requests': '1'
  4834. },
  4835. fetch: false,
  4836. redirect: 'manual'
  4837. });
  4838. if (data?.status === 200) {
  4839. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4840. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4841. return false;
  4842. }
  4843. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4844. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4845. const userName = data.responseText.match(/steamcommunity.com\/id\/(.+?)\/friends\//)?.[1];
  4846. if (steam64Id) {
  4847. this.#auth.steam64Id = steam64Id;
  4848. }
  4849. if (userName) {
  4850. this.#auth.userName = userName;
  4851. }
  4852. if (communitySessionID) {
  4853. this.#auth.communitySessionID = communitySessionID;
  4854. logStatus.success();
  4855. return true;
  4856. }
  4857. logStatus.error('Error: Get "sessionID" failed');
  4858. return false;
  4859. }
  4860. if (data?.status === 302) {
  4861. if (await this.#refreshToken('steamCommunity')) {
  4862. if (retry) {
  4863. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4864. return false;
  4865. }
  4866. logStatus.warning(i18n('retry'));
  4867. return this.#getUserLink(true);
  4868. }
  4869. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4870. return false;
  4871. }
  4872. const location = data?.finalUrl || data?.responseHeaders?.split('\n')?.find(header => header.includes('location') ? header.replace('loctation:', '').trim() : null);
  4873. if (data?.status === 301) {
  4874. if (location?.includes('steamcommunity.com/id')) {
  4875. logStatus.success();
  4876. return await this.#updateCommunityAuth(location);
  4877. }
  4878. if (location?.includes('https://steamcommunity.com/login/home')) {
  4879. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4880. return false;
  4881. }
  4882. logStatus.error(`Error: 301 (${location})`, true);
  4883. return false;
  4884. }
  4885. logStatus.error(`${result}:${statusText}(${status})`);
  4886. return false;
  4887. } catch (error) {
  4888. throwError(error, 'Steam.updateCommunityAuth');
  4889. return false;
  4890. }
  4891. }
  4892. async #updateCommunityAuth(url) {
  4893. try {
  4894. const logStatus = scripts_echoLog({
  4895. text: i18n('updatingAuth', i18n('steamCommunity'))
  4896. });
  4897. const {
  4898. result,
  4899. statusText,
  4900. status,
  4901. data
  4902. } = await tools_httpRequest({
  4903. url: url,
  4904. method: 'GET',
  4905. headers: {
  4906. 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',
  4907. 'Cache-Control': 'max-age=0',
  4908. 'Sec-Fetch-Dest': 'document',
  4909. 'Sec-Fetch-Mode': 'navigate',
  4910. 'Upgrade-Insecure-Requests': '1'
  4911. }
  4912. });
  4913. if (result === 'Success') {
  4914. if (data?.status === 200) {
  4915. if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
  4916. logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
  4917. return false;
  4918. }
  4919. const steam64Id = data.responseText.match(/g_steamID = "(.+?)";/)?.[1];
  4920. const communitySessionID = data.responseText.match(/g_sessionID = "(.+?)";/)?.[1];
  4921. const userName = data.responseText.match(/steamcommunity.com\/id\/(.+?)\/friends\//)?.[1];
  4922. if (steam64Id) {
  4923. this.#auth.steam64Id = steam64Id;
  4924. }
  4925. if (userName) {
  4926. this.#auth.userName = userName;
  4927. }
  4928. if (communitySessionID) {
  4929. this.#auth.communitySessionID = communitySessionID;
  4930. logStatus.success();
  4931. return true;
  4932. }
  4933. logStatus.error('Error: Get "sessionID" failed');
  4934. return false;
  4935. }
  4936. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  4937. return false;
  4938. }
  4939. logStatus.error(`${result}:${statusText}(${status})`);
  4940. return false;
  4941. } catch (error) {
  4942. throwError(error, 'Steam.updateCommunityAuth');
  4943. return false;
  4944. }
  4945. }
  4946. async #getAreaInfo() {
  4947. try {
  4948. const logStatus = scripts_echoLog({
  4949. text: i18n('gettingAreaInfo')
  4950. });
  4951. const {
  4952. result,
  4953. statusText,
  4954. status,
  4955. data
  4956. } = await tools_httpRequest({
  4957. url: 'https://store.steampowered.com/cart/',
  4958. method: 'GET'
  4959. });
  4960. if (result === 'Success') {
  4961. if (data?.status === 200) {
  4962. const cartConfigRaw = data.responseText.match(/data-cart_config="(.*?)"/)?.[1];
  4963. const temp = document.createElement('div');
  4964. temp.innerHTML = cartConfigRaw || '{}';
  4965. const cartConfigStr = temp.textContent || temp.innerText;
  4966. let cartConfig;
  4967. try {
  4968. cartConfig = JSON.parse(cartConfigStr);
  4969. } catch (error) {
  4970. logStatus.error('Error: get country info filed');
  4971. console.error(error);
  4972. return {};
  4973. }
  4974. if (!cartConfig.rgUserCountryOptions) {
  4975. logStatus.warning('Warning: Area cannot be changed');
  4976. return {};
  4977. }
  4978. const userInfoRaw = data.responseText.match(/data-userinfo="(.*?)"/)?.[1];
  4979. const temp1 = document.createElement('div');
  4980. temp1.innerHTML = userInfoRaw || '{}';
  4981. const userInfoStr = temp1.textContent || temp1.innerText;
  4982. let userInfo;
  4983. try {
  4984. userInfo = JSON.parse(userInfoStr);
  4985. } catch (error) {
  4986. logStatus.error('Error: get country info filed');
  4987. console.error(error);
  4988. return {};
  4989. }
  4990. const currentArea = userInfo.country_code;
  4991. const areas = Object.keys(cartConfig.rgUserCountryOptions).filter(area => area !== 'help');
  4992. if (currentArea && areas.length > 0) {
  4993. this.#area = currentArea;
  4994. logStatus.success();
  4995. return {
  4996. currentArea: currentArea,
  4997. areas: areas
  4998. };
  4999. }
  5000. logStatus.error('Error: get country info filed');
  5001. return {};
  5002. }
  5003. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5004. return {};
  5005. }
  5006. logStatus.error(`${result}:${statusText}(${status})`);
  5007. return {};
  5008. } catch (error) {
  5009. throwError(error, 'Steam.getAreaInfo');
  5010. return {};
  5011. }
  5012. }
  5013. async #changeArea(area) {
  5014. try {
  5015. if (this.#areaStatus === 'waiting') {
  5016. await new Promise(resolve => {
  5017. const checker = setInterval(() => {
  5018. if (this.#areaStatus !== 'waiting') {
  5019. clearInterval(checker);
  5020. resolve(true);
  5021. }
  5022. });
  5023. });
  5024. }
  5025. if (this.#area === area || !area && this.#area !== 'CN') {
  5026. return true;
  5027. }
  5028. this.#areaStatus = 'waiting';
  5029. let aimedArea = area;
  5030. if (!aimedArea) {
  5031. const {
  5032. currentArea,
  5033. areas
  5034. } = await this.#getAreaInfo();
  5035. if (!currentArea || !areas) {
  5036. this.#areaStatus = 'error';
  5037. return false;
  5038. }
  5039. if (currentArea !== 'CN') {
  5040. this.#areaStatus = 'skip';
  5041. scripts_echoLog({
  5042. text: 'notNeededChangeArea'
  5043. });
  5044. return 'skip';
  5045. }
  5046. const anotherArea = areas.filter(area => area && area !== 'CN');
  5047. if (!anotherArea || anotherArea.length === 0) {
  5048. this.#areaStatus = 'noAnotherArea';
  5049. scripts_echoLog({
  5050. text: 'noAnotherArea'
  5051. });
  5052. return false;
  5053. }
  5054. [ aimedArea ] = anotherArea;
  5055. }
  5056. const logStatus = scripts_echoLog({
  5057. text: i18n('changingArea', aimedArea)
  5058. });
  5059. const {
  5060. result,
  5061. statusText,
  5062. status,
  5063. data
  5064. } = await tools_httpRequest({
  5065. url: 'https://store.steampowered.com/country/setcountry',
  5066. method: 'POST',
  5067. headers: {
  5068. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5069. },
  5070. data: $.param({
  5071. cc: aimedArea,
  5072. sessionid: this.#auth.storeSessionID
  5073. })
  5074. });
  5075. if (result === 'Success') {
  5076. if (data?.status === 200 && data.responseText === 'true') {
  5077. const {
  5078. currentArea
  5079. } = await this.#getAreaInfo();
  5080. if (currentArea === aimedArea) {
  5081. this.#areaStatus = 'success';
  5082. logStatus.success();
  5083. return currentArea;
  5084. }
  5085. this.#areaStatus = 'error';
  5086. logStatus.error('Error: change country filed');
  5087. return 'CN';
  5088. }
  5089. this.#areaStatus = 'error';
  5090. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5091. return 'CN';
  5092. }
  5093. this.#areaStatus = 'error';
  5094. logStatus.error(`${result}:${statusText}(${status})`);
  5095. return 'CN';
  5096. } catch (error) {
  5097. this.#areaStatus = 'error';
  5098. throwError(error, 'Steam.changeArea');
  5099. return false;
  5100. }
  5101. }
  5102. async #joinGroup(groupName) {
  5103. try {
  5104. if (this.#ASF) {
  5105. if (await this.#ASF.joinGroup(groupName)) {
  5106. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5107. return true;
  5108. }
  5109. return false;
  5110. }
  5111. const logStatus = scripts_echoLog({
  5112. type: 'joiningSteamGroup',
  5113. text: groupName
  5114. });
  5115. const {
  5116. result,
  5117. statusText,
  5118. status,
  5119. data
  5120. } = await tools_httpRequest({
  5121. url: `https://steamcommunity.com/groups/${groupName}`,
  5122. method: 'POST',
  5123. headers: {
  5124. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5125. },
  5126. data: $.param({
  5127. action: 'join',
  5128. sessionID: this.#auth.communitySessionID
  5129. })
  5130. });
  5131. if (result === 'Success') {
  5132. if (data?.status === 200 && !data.responseText.includes('grouppage_join_area')) {
  5133. logStatus.success();
  5134. this.tasks.groups = unique([ ...this.tasks.groups, groupName ]);
  5135. return true;
  5136. }
  5137. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5138. return false;
  5139. }
  5140. logStatus.error(`${result}:${statusText}(${status})`);
  5141. return false;
  5142. } catch (error) {
  5143. throwError(error, 'Steam.joinGroup');
  5144. return false;
  5145. }
  5146. }
  5147. async #leaveGroup(groupName) {
  5148. try {
  5149. if (this.whiteList.groups.includes(groupName)) {
  5150. scripts_echoLog({
  5151. type: 'whiteList',
  5152. text: 'Steam.leaveGroup',
  5153. id: groupName
  5154. });
  5155. return true;
  5156. }
  5157. if (this.#ASF) {
  5158. return await this.#ASF.leaveGroup(groupName);
  5159. }
  5160. const groupId = await this.#getGroupId(groupName);
  5161. if (!groupId) {
  5162. return false;
  5163. }
  5164. const logStatus = scripts_echoLog({
  5165. type: 'leavingSteamGroup',
  5166. text: groupName
  5167. });
  5168. const {
  5169. result,
  5170. statusText,
  5171. status,
  5172. data
  5173. } = await tools_httpRequest({
  5174. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5175. method: 'POST',
  5176. headers: {
  5177. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5178. },
  5179. data: $.param({
  5180. sessionID: this.#auth.communitySessionID,
  5181. action: 'leaveGroup',
  5182. groupId: groupId
  5183. })
  5184. });
  5185. if (result === 'Success') {
  5186. 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) {
  5187. logStatus.success();
  5188. return true;
  5189. }
  5190. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5191. return false;
  5192. }
  5193. logStatus.error(`${result}:${statusText}(${status})`);
  5194. return false;
  5195. } catch (error) {
  5196. throwError(error, 'Steam.leaveGroup');
  5197. return false;
  5198. }
  5199. }
  5200. async #getGroupId(groupName) {
  5201. try {
  5202. const logStatus = scripts_echoLog({
  5203. type: 'gettingSteamGroupId',
  5204. text: groupName
  5205. });
  5206. const groupId = this.#cache.group[groupName];
  5207. if (groupId) {
  5208. logStatus.success();
  5209. return groupId;
  5210. }
  5211. const {
  5212. result,
  5213. statusText,
  5214. status,
  5215. data
  5216. } = await tools_httpRequest({
  5217. url: `https://steamcommunity.com/groups/${groupName}`,
  5218. method: 'GET',
  5219. headers: {
  5220. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5221. }
  5222. });
  5223. if (result === 'Success') {
  5224. if (data?.status === 200) {
  5225. const groupId = data.responseText.match(/OpenGroupChat\( '([0-9]+)'/)?.[1];
  5226. if (groupId) {
  5227. this.#setCache('group', groupName, groupId);
  5228. logStatus.success();
  5229. return groupId;
  5230. }
  5231. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5232. return false;
  5233. }
  5234. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5235. return false;
  5236. }
  5237. logStatus.error(`${result}:${statusText}(${status})`);
  5238. return false;
  5239. } catch (error) {
  5240. throwError(error, 'Steam.getGroupID');
  5241. return false;
  5242. }
  5243. }
  5244. async #joinOfficialGroup(gameId) {
  5245. try {
  5246. if (this.#ASF) {
  5247. if (await this.#ASF.joinGroup(gameId)) {
  5248. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5249. return true;
  5250. }
  5251. return false;
  5252. }
  5253. const logStatus = scripts_echoLog({
  5254. type: 'joiningSteamOfficialGroup',
  5255. text: gameId
  5256. });
  5257. const {
  5258. result,
  5259. statusText,
  5260. status,
  5261. data
  5262. } = await tools_httpRequest({
  5263. url: `https://steamcommunity.com/games/${gameId}?action=join&sessionID=${this.#auth.communitySessionID}`,
  5264. method: 'GET',
  5265. headers: {
  5266. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5267. }
  5268. });
  5269. if (result === 'Success') {
  5270. if (data?.status === 200 && !data.responseText.includes('id="publicGroupJoin"')) {
  5271. logStatus.success();
  5272. this.tasks.officialGroups = unique([ ...this.tasks.officialGroups, gameId ]);
  5273. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5274. if (groupId) {
  5275. this.#setCache('officialGroup', gameId, groupId);
  5276. }
  5277. return true;
  5278. }
  5279. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5280. return false;
  5281. }
  5282. logStatus.error(`${result}:${statusText}(${status})`);
  5283. return false;
  5284. } catch (error) {
  5285. throwError(error, 'Steam.joinOfficialGroup');
  5286. return false;
  5287. }
  5288. }
  5289. async #leaveOfficialGroup(gameId) {
  5290. try {
  5291. if (this.whiteList.officialGroups.includes(gameId)) {
  5292. scripts_echoLog({
  5293. type: 'whiteList',
  5294. text: 'Steam.leaveOfficialGroup',
  5295. id: gameId
  5296. });
  5297. return true;
  5298. }
  5299. if (this.#ASF) {
  5300. return await this.#ASF.leaveGroup(gameId);
  5301. }
  5302. const groupId = await this.#getOfficialGroupId(gameId);
  5303. if (!groupId) {
  5304. return false;
  5305. }
  5306. const logStatus = scripts_echoLog({
  5307. type: 'leavingSteamOfficialGroup',
  5308. text: gameId
  5309. });
  5310. const {
  5311. result,
  5312. statusText,
  5313. status,
  5314. data
  5315. } = await tools_httpRequest({
  5316. url: `https://steamcommunity.com/id/${this.#auth.userName}/home_process`,
  5317. method: 'POST',
  5318. headers: {
  5319. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5320. },
  5321. data: $.param({
  5322. sessionID: this.#auth.communitySessionID,
  5323. action: 'leaveGroup',
  5324. groupId: groupId
  5325. })
  5326. });
  5327. if (result === 'Success') {
  5328. if (data?.status === 200) {
  5329. const {
  5330. result: resultR,
  5331. statusText: statusTextR,
  5332. status: statusR,
  5333. data: dataR
  5334. } = await tools_httpRequest({
  5335. url: `https://steamcommunity.com/games/${gameId}`,
  5336. method: 'GET',
  5337. headers: {
  5338. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5339. }
  5340. });
  5341. if (resultR === 'Success') {
  5342. if (dataR?.status === 200 && dataR.responseText.includes('id="publicGroupJoin"')) {
  5343. logStatus.success();
  5344. return true;
  5345. }
  5346. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5347. return false;
  5348. }
  5349. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5350. return false;
  5351. }
  5352. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5353. return false;
  5354. }
  5355. logStatus.error(`${result}:${statusText}(${status})`);
  5356. return false;
  5357. } catch (error) {
  5358. throwError(error, 'Steam.leaveOfficialGroup');
  5359. return false;
  5360. }
  5361. }
  5362. async #getOfficialGroupId(gameId) {
  5363. try {
  5364. const logStatus = scripts_echoLog({
  5365. type: 'gettingSteamOfficialGroupId',
  5366. text: gameId
  5367. });
  5368. const groupId = this.#cache.officialGroup[gameId];
  5369. if (groupId) {
  5370. logStatus.success();
  5371. return groupId;
  5372. }
  5373. const {
  5374. result,
  5375. statusText,
  5376. status,
  5377. data
  5378. } = await tools_httpRequest({
  5379. url: `https://steamcommunity.com/games/${gameId}`,
  5380. method: 'GET',
  5381. headers: {
  5382. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5383. }
  5384. });
  5385. if (result === 'Success') {
  5386. if (data?.status === 200) {
  5387. const groupId = data.responseText.match(/steam:\/\/friends\/joinchat\/([0-9]+)/)?.[1];
  5388. if (groupId) {
  5389. this.#setCache('officialGroup', gameId, groupId);
  5390. logStatus.success();
  5391. return groupId;
  5392. }
  5393. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5394. return false;
  5395. }
  5396. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5397. return false;
  5398. }
  5399. logStatus.error(`${result}:${statusText}(${status})`);
  5400. return false;
  5401. } catch (error) {
  5402. throwError(error, 'Steam.getGroupID');
  5403. return false;
  5404. }
  5405. }
  5406. async #addToWishlist(gameId) {
  5407. try {
  5408. if (this.#ASF) {
  5409. if (await this.#ASF.addToWishlist(gameId)) {
  5410. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5411. return true;
  5412. }
  5413. return false;
  5414. }
  5415. const logStatus = scripts_echoLog({
  5416. type: 'addingToWishlist',
  5417. text: gameId
  5418. });
  5419. const {
  5420. result,
  5421. data
  5422. } = await tools_httpRequest({
  5423. url: 'https://store.steampowered.com/api/addtowishlist',
  5424. method: 'POST',
  5425. headers: {
  5426. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5427. },
  5428. data: $.param({
  5429. sessionid: this.#auth.storeSessionID,
  5430. appid: gameId
  5431. }),
  5432. dataType: 'json'
  5433. });
  5434. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5435. logStatus.success();
  5436. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5437. return true;
  5438. }
  5439. const {
  5440. result: resultR,
  5441. statusText: statusTextR,
  5442. status: statusR,
  5443. data: dataR
  5444. } = await tools_httpRequest({
  5445. url: `https://store.steampowered.com/app/${gameId}`,
  5446. method: 'GET'
  5447. });
  5448. if (resultR === 'Success') {
  5449. if (dataR?.status === 200) {
  5450. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5451. logStatus.warning(i18n('changeAreaNotice'));
  5452. if (!await this.#changeArea()) {
  5453. return false;
  5454. }
  5455. return await this.#addToWishlist(gameId);
  5456. }
  5457. if (dataR.responseText.includes('class="queue_actions_ctn"') && dataR.responseText.includes('class="already_in_library"')) {
  5458. logStatus.success();
  5459. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5460. return true;
  5461. } 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"')) {
  5462. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5463. return false;
  5464. }
  5465. logStatus.success();
  5466. this.tasks.wishlists = unique([ ...this.tasks.wishlists, gameId ]);
  5467. return true;
  5468. }
  5469. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5470. return false;
  5471. }
  5472. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5473. return false;
  5474. } catch (error) {
  5475. throwError(error, 'Steam.addToWishlist');
  5476. return false;
  5477. }
  5478. }
  5479. async #removeFromWishlist(gameId) {
  5480. try {
  5481. if (this.whiteList.wishlists.includes(gameId)) {
  5482. scripts_echoLog({
  5483. type: 'whiteList',
  5484. text: 'Steam.removeFromWishlist',
  5485. id: gameId
  5486. });
  5487. return true;
  5488. }
  5489. if (this.#ASF) {
  5490. return await this.#ASF.removeFromWishlist(gameId);
  5491. }
  5492. const logStatus = scripts_echoLog({
  5493. type: 'removingFromWishlist',
  5494. text: gameId
  5495. });
  5496. const {
  5497. result,
  5498. data
  5499. } = await tools_httpRequest({
  5500. url: 'https://store.steampowered.com/api/removefromwishlist',
  5501. method: 'POST',
  5502. headers: {
  5503. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5504. },
  5505. data: $.param({
  5506. sessionid: this.#auth.storeSessionID,
  5507. appid: gameId
  5508. }),
  5509. dataType: 'json'
  5510. });
  5511. if (result === 'Success' && data?.status === 200 && data.response?.success === true) {
  5512. logStatus.success();
  5513. return true;
  5514. }
  5515. const {
  5516. result: resultR,
  5517. statusText: statusTextR,
  5518. status: statusR,
  5519. data: dataR
  5520. } = await tools_httpRequest({
  5521. url: `https://store.steampowered.com/app/${gameId}`,
  5522. method: 'GET'
  5523. });
  5524. if (resultR === 'Success') {
  5525. if (dataR?.status === 200) {
  5526. if (this.#area === 'CN' && dataR.responseText.includes('id="error_box"')) {
  5527. logStatus.warning(i18n('changeAreaNotice'));
  5528. const result = await this.#changeArea();
  5529. if (!result || result === 'CN' || result === 'skip') {
  5530. return false;
  5531. }
  5532. return await this.#removeFromWishlist(gameId);
  5533. }
  5534. if (dataR.responseText.includes('class="queue_actions_ctn"') && (dataR.responseText.includes('ds_owned_flag ds_flag') || dataR.responseText.includes('add_to_wishlist_area'))) {
  5535. logStatus.success();
  5536. return true;
  5537. }
  5538. logStatus.error(`Error:${dataR.statusText}(${dataR.status})`);
  5539. return false;
  5540. }
  5541. logStatus.error(`Error:${dataR?.statusText}(${dataR?.status})`);
  5542. return false;
  5543. }
  5544. logStatus.error(`${resultR}:${statusTextR}(${statusR})`);
  5545. return false;
  5546. } catch (error) {
  5547. throwError(error, 'Steam.removeFromWishlist');
  5548. return false;
  5549. }
  5550. }
  5551. async #toggleFollowGame(gameId, doTask) {
  5552. try {
  5553. if (!doTask && this.whiteList.follows.includes(gameId)) {
  5554. scripts_echoLog({
  5555. type: 'whiteList',
  5556. text: 'Steam.unfollowGame',
  5557. id: gameId
  5558. });
  5559. return true;
  5560. }
  5561. if (this.#ASF) {
  5562. if (await this.#ASF.toggleFollowGame(gameId, doTask)) {
  5563. if (doTask) {
  5564. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5565. }
  5566. return true;
  5567. }
  5568. return false;
  5569. }
  5570. const logStatus = scripts_echoLog({
  5571. type: `${doTask ? '' : 'un'}followingGame`,
  5572. text: gameId
  5573. });
  5574. const requestData = {
  5575. sessionid: this.#auth.storeSessionID,
  5576. appid: gameId
  5577. };
  5578. if (!doTask) {
  5579. requestData.unfollow = '1';
  5580. }
  5581. const {
  5582. result,
  5583. data
  5584. } = await tools_httpRequest({
  5585. url: 'https://store.steampowered.com/explore/followgame/',
  5586. method: 'POST',
  5587. headers: {
  5588. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5589. },
  5590. data: $.param(requestData)
  5591. });
  5592. if (result === 'Success' && data?.status === 200 && data.responseText === 'true') {
  5593. logStatus.success();
  5594. return true;
  5595. }
  5596. const followed = await this.#isFollowedGame(gameId);
  5597. if (this.#area === 'CN' && followed === 'areaLocked') {
  5598. logStatus.warning(i18n('changeAreaNotice'));
  5599. if (!await this.#changeArea()) {
  5600. return false;
  5601. }
  5602. return await this.#removeFromWishlist(gameId);
  5603. }
  5604. if (doTask === followed) {
  5605. logStatus.success();
  5606. if (doTask) {
  5607. this.tasks.follows = unique([ ...this.tasks.follows, gameId ]);
  5608. }
  5609. return true;
  5610. }
  5611. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5612. return false;
  5613. } catch (error) {
  5614. throwError(error, 'Steam.toggleFollowGame');
  5615. return false;
  5616. }
  5617. }
  5618. async #isFollowedGame(gameId) {
  5619. try {
  5620. const {
  5621. result,
  5622. data
  5623. } = await tools_httpRequest({
  5624. url: `https://store.steampowered.com/app/${gameId}`,
  5625. method: 'GET'
  5626. });
  5627. if (result === 'Success') {
  5628. if (data?.status === 200) {
  5629. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  5630. return 'areaLocked';
  5631. }
  5632. if ($(data.responseText.replace(/<img.*?>/g, '')).find('.queue_control_button.queue_btn_follow>.btnv6_blue_hoverfade.btn_medium.queue_btn_active').css('display') !== 'none') {
  5633. return true;
  5634. }
  5635. return false;
  5636. }
  5637. return false;
  5638. }
  5639. return false;
  5640. } catch (error) {
  5641. throwError(error, 'Steam.isFollowedGame');
  5642. return false;
  5643. }
  5644. }
  5645. async #toggleForum(gameId, doTask = true) {
  5646. try {
  5647. if (!doTask && this.whiteList.forums.includes(gameId)) {
  5648. scripts_echoLog({
  5649. type: 'whiteList',
  5650. text: 'Steam.unsubscribeForum',
  5651. id: gameId
  5652. });
  5653. return true;
  5654. }
  5655. const forumId = await this.#getForumId(gameId);
  5656. if (!forumId) {
  5657. return false;
  5658. }
  5659. const logStatus = scripts_echoLog({
  5660. type: `${doTask ? '' : 'un'}subscribingForum`,
  5661. text: gameId
  5662. });
  5663. const [ id, feature ] = forumId.split('_');
  5664. const {
  5665. result,
  5666. statusText,
  5667. status,
  5668. data
  5669. } = await tools_httpRequest({
  5670. url: `https://steamcommunity.com/forum/${id}/General/${doTask ? '' : 'un'}subscribe/${feature || '0'}/`,
  5671. method: 'POST',
  5672. responseType: 'json',
  5673. headers: {
  5674. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5675. },
  5676. data: $.param({
  5677. sessionid: this.#auth.communitySessionID
  5678. })
  5679. });
  5680. if (result === 'Success') {
  5681. if (data?.status === 200 && (data.response?.success === 1 || data.response?.success === 29)) {
  5682. if (doTask) {
  5683. this.tasks.forums = unique([ ...this.tasks.forums, gameId ]);
  5684. }
  5685. logStatus.success();
  5686. return true;
  5687. }
  5688. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5689. return true;
  5690. }
  5691. logStatus.error(`${result}:${statusText}(${status})`);
  5692. return true;
  5693. } catch (error) {
  5694. throwError(error, 'Steam.toggleForum');
  5695. return true;
  5696. }
  5697. }
  5698. async #getForumId(gameId) {
  5699. try {
  5700. const logStatus = scripts_echoLog({
  5701. type: 'gettingForumId',
  5702. text: gameId
  5703. });
  5704. const forumId = this.#cache.forum[gameId];
  5705. if (forumId) {
  5706. logStatus.success();
  5707. return forumId;
  5708. }
  5709. const {
  5710. result,
  5711. statusText,
  5712. status,
  5713. data
  5714. } = await tools_httpRequest({
  5715. url: `https://steamcommunity.com/app/${gameId}/discussions/`,
  5716. method: 'GET'
  5717. });
  5718. if (result === 'Success') {
  5719. if (data?.status === 200) {
  5720. const forumId = data.responseText?.match(/General_([\d]+(_[\d]+)?)/)?.[1];
  5721. if (forumId) {
  5722. this.#setCache('forum', gameId, forumId);
  5723. logStatus.success();
  5724. return forumId;
  5725. }
  5726. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5727. return false;
  5728. }
  5729. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5730. return false;
  5731. }
  5732. logStatus.error(`${result}:${statusText}(${status})`);
  5733. return false;
  5734. } catch (error) {
  5735. throwError(error, 'Steam.getForumId');
  5736. return false;
  5737. }
  5738. }
  5739. async #toggleFavoriteWorkshop(id, doTask = true) {
  5740. try {
  5741. if (!doTask && this.whiteList.workshops.includes(id)) {
  5742. scripts_echoLog({
  5743. type: 'whiteList',
  5744. text: 'Steam.unfavoriteWorkshop',
  5745. id: id
  5746. });
  5747. return true;
  5748. }
  5749. const appid = await this.#getWorkshopAppId(id);
  5750. if (!appid) {
  5751. return false;
  5752. }
  5753. const logStatus = scripts_echoLog({
  5754. type: doTask ? 'favoritingWorkshop' : 'unfavoritingWorkshop',
  5755. text: id
  5756. });
  5757. const {
  5758. result,
  5759. statusText,
  5760. status,
  5761. data
  5762. } = await tools_httpRequest({
  5763. url: `https://steamcommunity.com/sharedfiles/${doTask ? '' : 'un'}favorite`,
  5764. method: 'POST',
  5765. headers: {
  5766. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5767. },
  5768. data: $.param({
  5769. id: id,
  5770. appid: appid,
  5771. sessionid: this.#auth.communitySessionID
  5772. })
  5773. });
  5774. if (result === 'Success') {
  5775. if (data?.status === 200 && !data.responseText) {
  5776. if (doTask) {
  5777. this.tasks.workshops = unique([ ...this.tasks.workshops, id ]);
  5778. }
  5779. logStatus.success();
  5780. return true;
  5781. }
  5782. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5783. return false;
  5784. }
  5785. logStatus.error(`${result}:${statusText}(${status})`);
  5786. return false;
  5787. } catch (error) {
  5788. throwError(error, 'Steam.toggleFavoriteWorkshop');
  5789. return false;
  5790. }
  5791. }
  5792. async #getWorkshopAppId(id) {
  5793. try {
  5794. const logStatus = scripts_echoLog({
  5795. type: 'gettingWorkshopAppId',
  5796. text: id
  5797. });
  5798. const appId = this.#cache.workshop[id];
  5799. if (appId) {
  5800. logStatus.success();
  5801. return appId;
  5802. }
  5803. const {
  5804. result,
  5805. statusText,
  5806. status,
  5807. data
  5808. } = await tools_httpRequest({
  5809. url: `https://steamcommunity.com/sharedfiles/filedetails/?id=${id}`,
  5810. method: 'GET'
  5811. });
  5812. if (result === 'Success') {
  5813. if (data?.status === 200) {
  5814. const appId = data.responseText.match(/<input type="hidden" name="appid" value="([\d]+?)" \/>/)?.[1];
  5815. if (appId) {
  5816. this.#setCache('workshop', id, appId);
  5817. logStatus.success();
  5818. return appId;
  5819. }
  5820. logStatus.error('Error: getWorkshopAppId failed');
  5821. return false;
  5822. }
  5823. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5824. return false;
  5825. }
  5826. logStatus.error(`${result}:${statusText}(${status})`);
  5827. return false;
  5828. } catch (error) {
  5829. throwError(error, 'Steam.getWorkshopAppId');
  5830. return false;
  5831. }
  5832. }
  5833. async #voteUpWorkshop(id) {
  5834. try {
  5835. const logStatus = scripts_echoLog({
  5836. type: 'votingUpWorkshop',
  5837. text: id
  5838. });
  5839. const {
  5840. result,
  5841. statusText,
  5842. status,
  5843. data
  5844. } = await tools_httpRequest({
  5845. url: 'https://steamcommunity.com/sharedfiles/voteup',
  5846. method: 'POST',
  5847. responseType: 'json',
  5848. headers: {
  5849. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5850. },
  5851. data: $.param({
  5852. id: id,
  5853. sessionid: this.#auth.communitySessionID
  5854. })
  5855. });
  5856. if (result === 'Success') {
  5857. if (data?.status === 200 && data.response?.success === 1) {
  5858. logStatus.success();
  5859. return true;
  5860. }
  5861. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5862. return true;
  5863. }
  5864. logStatus.error(`${result}:${statusText}(${status})`);
  5865. return true;
  5866. } catch (error) {
  5867. throwError(error, 'Steam.voteupWorkshop');
  5868. return true;
  5869. }
  5870. }
  5871. async #toggleCurator(curatorId, doTask = true) {
  5872. try {
  5873. if (!doTask && this.whiteList.curators.includes(curatorId)) {
  5874. scripts_echoLog({
  5875. type: 'whiteList',
  5876. text: 'Steam.unfollowCurator',
  5877. id: curatorId
  5878. });
  5879. return true;
  5880. }
  5881. if (this.#ASF) {
  5882. return await this.#ASF.toggleCurator(curatorId, doTask);
  5883. }
  5884. const logStatus = scripts_echoLog({
  5885. type: doTask ? 'followingCurator' : 'unfollowingCurator',
  5886. text: curatorId
  5887. });
  5888. const {
  5889. result,
  5890. statusText,
  5891. status,
  5892. data
  5893. } = await tools_httpRequest({
  5894. url: 'https://store.steampowered.com/curators/ajaxfollow',
  5895. method: 'POST',
  5896. headers: {
  5897. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5898. },
  5899. data: $.param({
  5900. clanid: curatorId,
  5901. sessionid: this.#auth.storeSessionID,
  5902. follow: doTask
  5903. }),
  5904. dataType: 'json'
  5905. });
  5906. if (result === 'Success') {
  5907. if (data?.status === 200 && data.response?.success?.success === 1) {
  5908. logStatus.success();
  5909. return true;
  5910. }
  5911. logStatus.error(`Error:${data?.statusText}(${data?.response?.success}` || `${data?.status})`);
  5912. return false;
  5913. }
  5914. logStatus.error(`${result}:${statusText}(${status})`);
  5915. return false;
  5916. } catch (error) {
  5917. throwError(error, 'Steam.toggleCurator');
  5918. return false;
  5919. }
  5920. }
  5921. async getCuratorId(path, name) {
  5922. try {
  5923. const logStatus = scripts_echoLog({
  5924. type: 'gettingCuratorId',
  5925. text: `${path}/${name}`
  5926. });
  5927. const curatorId = this.#cache.curator[`${path}/${name}`];
  5928. if (curatorId) {
  5929. logStatus.success();
  5930. return curatorId;
  5931. }
  5932. const {
  5933. result,
  5934. statusText,
  5935. status,
  5936. data
  5937. } = await tools_httpRequest({
  5938. url: `https://store.steampowered.com/${path}/${name}`,
  5939. method: 'GET',
  5940. headers: {
  5941. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  5942. }
  5943. });
  5944. if (result === 'Success') {
  5945. if (data?.status === 200) {
  5946. const curatorId = data.responseText.match(/g_pagingData.*?"clanid":([\d]+)/)?.[1];
  5947. if (curatorId) {
  5948. this.#setCache('curator', `${path}/${name}`, curatorId);
  5949. logStatus.success();
  5950. return curatorId;
  5951. }
  5952. logStatus.error(`Error:${data.statusText}(${data.status})`);
  5953. return false;
  5954. }
  5955. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  5956. return false;
  5957. }
  5958. logStatus.error(`${result}:${statusText}(${status})`);
  5959. return false;
  5960. } catch (error) {
  5961. throwError(error, 'Steam.getCuratorID');
  5962. return false;
  5963. }
  5964. }
  5965. async #toggleCuratorLike(link, doTask = true) {
  5966. try {
  5967. const [ path, name ] = link.split('/');
  5968. if (!(path && name)) {
  5969. scripts_echoLog({
  5970. text: i18n('errorLink', link)
  5971. });
  5972. return false;
  5973. }
  5974. const curatorId = await this.getCuratorId(path, name);
  5975. if (curatorId) {
  5976. return await this.#toggleCurator(curatorId, doTask);
  5977. }
  5978. return false;
  5979. } catch (error) {
  5980. throwError(error, 'Steam.toggleCuratorLike');
  5981. return false;
  5982. }
  5983. }
  5984. async #getAnnouncementParams(appId, viewId) {
  5985. try {
  5986. const logStatus = scripts_echoLog({
  5987. type: 'gettingAnnouncementParams',
  5988. text: appId,
  5989. id: viewId
  5990. });
  5991. const {
  5992. result,
  5993. statusText,
  5994. status,
  5995. data
  5996. } = await tools_httpRequest({
  5997. 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`,
  5998. method: 'GET',
  5999. responseType: 'json',
  6000. headers: {
  6001. Host: 'store.steampowered.com',
  6002. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  6003. }
  6004. });
  6005. if (result === 'Success') {
  6006. if (data?.status === 200 && data?.response?.success === 1) {
  6007. const {
  6008. clanid,
  6009. gid
  6010. } = data.response.event?.announcement_body || {};
  6011. if (clanid) {
  6012. logStatus.success();
  6013. return {
  6014. clanId: clanid,
  6015. gid: gid
  6016. };
  6017. }
  6018. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6019. return {};
  6020. }
  6021. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6022. return {};
  6023. }
  6024. logStatus.error(`${result}:${statusText}(${status})`);
  6025. return {};
  6026. } catch (error) {
  6027. throwError(error, 'Steam.likeAnnouncement');
  6028. return {};
  6029. }
  6030. }
  6031. async #likeAnnouncement(id) {
  6032. try {
  6033. const [ appId, viewId ] = id.split('/');
  6034. if (!(appId && viewId)) {
  6035. scripts_echoLog({}).error(`${i18n('missParams')}(id)`);
  6036. return false;
  6037. }
  6038. const {
  6039. clanId,
  6040. gid
  6041. } = await this.#getAnnouncementParams(appId, viewId);
  6042. if (!clanId) {
  6043. return false;
  6044. }
  6045. const logStatus = scripts_echoLog({
  6046. type: 'likingAnnouncement',
  6047. text: appId,
  6048. id: viewId
  6049. });
  6050. const {
  6051. result,
  6052. statusText,
  6053. status,
  6054. data
  6055. } = await tools_httpRequest({
  6056. url: `https://store.steampowered.com/updated/ajaxrateupdate/${gid || viewId}`,
  6057. method: 'POST',
  6058. headers: {
  6059. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6060. Host: 'store.steampowered.com',
  6061. Origin: 'https://store.steampowered.com',
  6062. Referer: `https://store.steampowered.com/news/app/${appId}/view/${viewId}`
  6063. },
  6064. data: $.param({
  6065. sessionid: this.#auth.storeSessionID,
  6066. voteup: 1,
  6067. clanid: clanId,
  6068. ajax: 1
  6069. }),
  6070. dataType: 'json'
  6071. });
  6072. if (result === 'Success') {
  6073. if (data?.status === 200 && data.response.success === 1) {
  6074. logStatus.success();
  6075. return true;
  6076. }
  6077. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6078. return false;
  6079. }
  6080. logStatus.error(`${result}:${statusText}(${status})`);
  6081. return false;
  6082. } catch (error) {
  6083. throwError(error, 'Steam.likeAnnouncement');
  6084. return false;
  6085. }
  6086. }
  6087. async #appid2subid(id) {
  6088. try {
  6089. const logStatus = scripts_echoLog({
  6090. type: 'gettingSubid',
  6091. text: id
  6092. });
  6093. const {
  6094. result,
  6095. statusText,
  6096. status,
  6097. data
  6098. } = await tools_httpRequest({
  6099. url: `https://store.steampowered.com/app/${id}`,
  6100. method: 'GET',
  6101. headers: {
  6102. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  6103. }
  6104. });
  6105. if (result === 'Success') {
  6106. if (data?.status === 200) {
  6107. if (data.responseText.includes('ds_owned_flag ds_flag') || data.responseText.includes('class="already_in_library"')) {
  6108. logStatus.success(i18n('owned'));
  6109. return false;
  6110. }
  6111. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6112. logStatus.warning(i18n('changeAreaNotice'));
  6113. const result = await this.#changeArea();
  6114. if (!result || result === 'CN' || result === 'skip') {
  6115. return false;
  6116. }
  6117. return await this.#appid2subid(id);
  6118. }
  6119. let subid = data.responseText.match(/name="subid" value="([\d]+?)"/)?.[1];
  6120. if (subid) {
  6121. logStatus.success();
  6122. return subid;
  6123. }
  6124. subid = data.responseText.match(/AddFreeLicense\(\s*(\d+)/)?.[1];
  6125. if (subid) {
  6126. logStatus.success();
  6127. return subid;
  6128. }
  6129. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6130. return false;
  6131. }
  6132. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6133. return false;
  6134. }
  6135. logStatus.error(`${result}:${statusText}(${status})`);
  6136. return false;
  6137. } catch (error) {
  6138. throwError(error, 'Steam.appid2subid');
  6139. return false;
  6140. }
  6141. }
  6142. async #getLicenses() {
  6143. try {
  6144. const logStatus = scripts_echoLog({
  6145. text: i18n('gettingLicenses')
  6146. });
  6147. const {
  6148. result,
  6149. statusText,
  6150. status,
  6151. data
  6152. } = await tools_httpRequest({
  6153. url: `https://store.steampowered.com/dynamicstore/userdata/?t=${new Date().getTime()}`,
  6154. method: 'GET',
  6155. responseType: 'json'
  6156. });
  6157. if (result === 'Success') {
  6158. if (data?.status === 200) {
  6159. logStatus.success();
  6160. return data.response?.rgOwnedPackages;
  6161. }
  6162. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6163. return false;
  6164. }
  6165. logStatus.error(`${result}:${statusText}(${status})`);
  6166. return false;
  6167. } catch (error) {
  6168. throwError(error, 'Steam.getLicenses');
  6169. return false;
  6170. }
  6171. }
  6172. async #addLicense(id) {
  6173. try {
  6174. if (this.#ASF) {
  6175. return await this.#ASF.addLicense(id);
  6176. }
  6177. const [ type, ids ] = id.split('-');
  6178. if (type === 'appid') {
  6179. const subid = await this.#appid2subid(ids);
  6180. if (!subid) {
  6181. return false;
  6182. }
  6183. const logStatus = scripts_echoLog({
  6184. type: 'addingFreeLicense',
  6185. text: ids
  6186. });
  6187. if (!await this.#addFreeLicense(subid, logStatus)) {
  6188. return false;
  6189. }
  6190. const {
  6191. result,
  6192. statusText,
  6193. status,
  6194. data
  6195. } = await tools_httpRequest({
  6196. url: `https://store.steampowered.com/app/${ids}`,
  6197. method: 'GET'
  6198. });
  6199. if (result === 'Success') {
  6200. if (data?.status === 200) {
  6201. if (data.responseText.includes('ds_owned_flag ds_flag') || data.responseText.includes('class="already_in_library"')) {
  6202. logStatus.success();
  6203. return true;
  6204. }
  6205. logStatus.error(`Error:${data.statusText}(${data.status})`);
  6206. return false;
  6207. }
  6208. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6209. return false;
  6210. }
  6211. logStatus.error(`${result}:${statusText}(${status})`);
  6212. return false;
  6213. } else if (type === 'subid') {
  6214. if (this.#area === 'CN') {
  6215. scripts_echoLog({}).success(i18n('tryChangeAreaNotice'));
  6216. await this.#changeArea();
  6217. }
  6218. const logStatusArr = {};
  6219. const idsArr = ids.split(',');
  6220. for (const subid of idsArr) {
  6221. const logStatus = scripts_echoLog({
  6222. type: 'addingFreeLicenseSubid',
  6223. text: subid
  6224. });
  6225. if (!await this.#addFreeLicense(subid, logStatus)) {
  6226. return false;
  6227. }
  6228. logStatusArr[subid] = logStatus;
  6229. }
  6230. const licenses = await this.#getLicenses();
  6231. if (!licenses) {
  6232. return false;
  6233. }
  6234. for (const subid of idsArr) {
  6235. if (licenses.includes(parseInt(subid, 10))) {
  6236. logStatusArr[subid].success();
  6237. } else {
  6238. logStatusArr[subid].error();
  6239. }
  6240. }
  6241. return true;
  6242. }
  6243. return false;
  6244. } catch (error) {
  6245. throwError(error, 'Steam.addLicense');
  6246. return false;
  6247. }
  6248. }
  6249. async #addFreeLicense(id, logStatusPre) {
  6250. try {
  6251. const logStatus = logStatusPre || scripts_echoLog({
  6252. type: 'addingFreeLicenseSubid',
  6253. text: id
  6254. });
  6255. const {
  6256. result,
  6257. statusText,
  6258. status,
  6259. data
  6260. } = await tools_httpRequest({
  6261. url: `https://store.steampowered.com/freelicense/addfreelicense/${id}`,
  6262. method: 'POST',
  6263. headers: {
  6264. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6265. Host: 'store.steampowered.com',
  6266. Origin: 'https://store.steampowered.com',
  6267. Referer: 'https://store.steampowered.com/account/licenses/'
  6268. },
  6269. data: $.param({
  6270. ajax: true,
  6271. sessionid: this.#auth.storeSessionID
  6272. }),
  6273. dataType: 'json'
  6274. });
  6275. if (result === 'Success') {
  6276. if (data?.status === 200) {
  6277. if (this.#area === 'CN' && data.responseText.includes('id="error_box"')) {
  6278. logStatus.warning(i18n('changeAreaNotice'));
  6279. const result = await this.#changeArea();
  6280. if (!result || result === 'CN') {
  6281. return false;
  6282. }
  6283. return await this.#addFreeLicense(id);
  6284. }
  6285. logStatus.success();
  6286. return true;
  6287. }
  6288. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6289. return false;
  6290. }
  6291. logStatus.error(`${result}:${statusText}(${status})`);
  6292. return false;
  6293. } catch (error) {
  6294. throwError(error, 'Steam.addFreeLicense');
  6295. return false;
  6296. }
  6297. }
  6298. async #requestPlayTestAccess(id) {
  6299. try {
  6300. if (this.#ASF) {
  6301. return await this.#ASF.requestPlayTestAccess(id);
  6302. }
  6303. const logStatus = scripts_echoLog({
  6304. type: 'requestingPlayTestAccess',
  6305. text: id
  6306. });
  6307. const {
  6308. result,
  6309. statusText,
  6310. status,
  6311. data
  6312. } = await tools_httpRequest({
  6313. url: `https://store.steampowered.com/ajaxrequestplaytestaccess/${id}`,
  6314. method: 'POST',
  6315. headers: {
  6316. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  6317. Host: 'store.steampowered.com',
  6318. Origin: 'https://store.steampowered.com',
  6319. Referer: `https://store.steampowered.com/app/${id}`
  6320. },
  6321. data: $.param({
  6322. sessionid: this.#auth.storeSessionID
  6323. }),
  6324. dataType: 'json'
  6325. });
  6326. if (result === 'Success') {
  6327. if (data?.status === 200 && data?.response?.success === 1) {
  6328. logStatus.success();
  6329. return true;
  6330. }
  6331. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6332. return false;
  6333. }
  6334. logStatus.error(`${result}:${statusText}(${status})`);
  6335. return false;
  6336. } catch (error) {
  6337. throwError(error, 'Steam.requestPlayTestAccess');
  6338. return false;
  6339. }
  6340. }
  6341. async toggle({
  6342. doTask = true,
  6343. groupLinks = [],
  6344. officialGroupLinks = [],
  6345. wishlistLinks = [],
  6346. followLinks = [],
  6347. forumLinks = [],
  6348. workshopLinks = [],
  6349. workshopVoteLinks = [],
  6350. curatorLinks = [],
  6351. curatorLikeLinks = [],
  6352. announcementLinks = [],
  6353. licenseLinks = [],
  6354. playtestLinks = []
  6355. }) {
  6356. try {
  6357. if ([ ...groupLinks, ...officialGroupLinks, ...forumLinks, ...workshopLinks, ...workshopVoteLinks ].length > 0 && !this.#communityInitialized) {
  6358. scripts_echoLog({
  6359. text: i18n('needInit')
  6360. });
  6361. return false;
  6362. }
  6363. if ([ ...wishlistLinks, ...followLinks, ...curatorLinks, ...curatorLikeLinks, ...announcementLinks, ...licenseLinks, ...playtestLinks ].length > 0 && !this.#storeInitialized) {
  6364. scripts_echoLog({
  6365. text: i18n('needInit')
  6366. });
  6367. return false;
  6368. }
  6369. const prom = [];
  6370. if (doTask && !globalOptions.doTask.steam.groups || !doTask && !globalOptions.undoTask.steam.groups) {
  6371. scripts_echoLog({
  6372. type: 'globalOptionsSkip',
  6373. text: 'steam.groups'
  6374. });
  6375. } else {
  6376. const realGroups = this.getRealParams('groups', groupLinks, doTask, link => link.match(/groups\/(.+)\/?/)?.[1]);
  6377. if (realGroups.length > 0) {
  6378. for (const group of realGroups) {
  6379. if (doTask) {
  6380. prom.push(this.#joinGroup(group));
  6381. } else {
  6382. prom.push(this.#leaveGroup(group));
  6383. }
  6384. await delay(1e3);
  6385. }
  6386. }
  6387. }
  6388. if (doTask && !globalOptions.doTask.steam.officialGroups || !doTask && !globalOptions.undoTask.steam.officialGroups) {
  6389. scripts_echoLog({
  6390. type: 'globalOptionsSkip',
  6391. text: 'steam.officialGroups'
  6392. });
  6393. } else {
  6394. const realOfficialGroups = this.getRealParams('officialGroups', officialGroupLinks, doTask, link => link.match(/games\/(.+)\/?/)?.[1]);
  6395. if (realOfficialGroups.length > 0) {
  6396. for (const officialGroup of realOfficialGroups) {
  6397. if (doTask) {
  6398. prom.push(this.#joinOfficialGroup(officialGroup));
  6399. } else {
  6400. prom.push(this.#leaveOfficialGroup(officialGroup));
  6401. }
  6402. await delay(1e3);
  6403. }
  6404. }
  6405. }
  6406. if (doTask && !globalOptions.doTask.steam.wishlists || !doTask && !globalOptions.undoTask.steam.wishlists) {
  6407. scripts_echoLog({
  6408. type: 'globalOptionsSkip',
  6409. text: 'steam.wishlists'
  6410. });
  6411. } else {
  6412. const realWishlists = this.getRealParams('wishlists', wishlistLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6413. if (realWishlists.length > 0) {
  6414. for (const game of realWishlists) {
  6415. if (doTask) {
  6416. prom.push(this.#addToWishlist(game));
  6417. } else {
  6418. prom.push(this.#removeFromWishlist(game));
  6419. }
  6420. await delay(1e3);
  6421. }
  6422. }
  6423. }
  6424. if (doTask && !globalOptions.doTask.steam.follows || !doTask && !globalOptions.undoTask.steam.follows) {
  6425. scripts_echoLog({
  6426. type: 'globalOptionsSkip',
  6427. text: 'steam.follows'
  6428. });
  6429. } else {
  6430. const realFollows = this.getRealParams('follows', followLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6431. if (realFollows.length > 0) {
  6432. for (const game of realFollows) {
  6433. prom.push(this.#toggleFollowGame(game, doTask));
  6434. await delay(1e3);
  6435. }
  6436. }
  6437. }
  6438. if (doTask && !globalOptions.doTask.steam.forums || !doTask && !globalOptions.undoTask.steam.forums) {
  6439. scripts_echoLog({
  6440. type: 'globalOptionsSkip',
  6441. text: 'steam.forums'
  6442. });
  6443. } else {
  6444. const realForums = this.getRealParams('forums', forumLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6445. if (realForums.length > 0) {
  6446. for (const forum of realForums) {
  6447. prom.push(this.#toggleForum(forum, doTask));
  6448. await delay(1e3);
  6449. }
  6450. }
  6451. }
  6452. if (doTask && !globalOptions.doTask.steam.workshops || !doTask && !globalOptions.undoTask.steam.workshops) {
  6453. scripts_echoLog({
  6454. type: 'globalOptionsSkip',
  6455. text: 'steam.workshops'
  6456. });
  6457. } else {
  6458. const realWorkshops = this.getRealParams('workshops', workshopLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6459. if (realWorkshops.length > 0) {
  6460. for (const workshop of realWorkshops) {
  6461. prom.push(this.#toggleFavoriteWorkshop(workshop, doTask));
  6462. await delay(1e3);
  6463. }
  6464. }
  6465. }
  6466. if (doTask && !globalOptions.doTask.steam.workshopVotes) {
  6467. scripts_echoLog({
  6468. type: 'globalOptionsSkip',
  6469. text: 'steam.workshopVotes'
  6470. });
  6471. } else {
  6472. const realworkshopVotes = this.getRealParams('workshopVotes', workshopVoteLinks, doTask, link => link.match(/\?id=([\d]+)/)?.[1]);
  6473. if (doTask && realworkshopVotes.length > 0) {
  6474. for (const workshop of realworkshopVotes) {
  6475. prom.push(this.#voteUpWorkshop(workshop));
  6476. await delay(1e3);
  6477. }
  6478. }
  6479. }
  6480. if (doTask && !globalOptions.doTask.steam.curators || !doTask && !globalOptions.undoTask.steam.curators) {
  6481. scripts_echoLog({
  6482. type: 'globalOptionsSkip',
  6483. text: 'steam.curators'
  6484. });
  6485. } else {
  6486. const realCurators = this.getRealParams('curators', curatorLinks, doTask, link => link.match(/curator\/([\d]+)/)?.[1]);
  6487. const realCuratorLikes = this.getRealParams('curatorLikes', curatorLikeLinks, doTask, link => link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3).join('/'));
  6488. if (realCurators.length > 0) {
  6489. for (const curator of realCurators) {
  6490. prom.push(this.#toggleCurator(curator, doTask));
  6491. await delay(1e3);
  6492. }
  6493. }
  6494. if (realCuratorLikes.length > 0) {
  6495. for (const curatorLike of realCuratorLikes) {
  6496. prom.push(this.#toggleCuratorLike(curatorLike, doTask));
  6497. await delay(1e3);
  6498. }
  6499. }
  6500. }
  6501. if (doTask && !globalOptions.doTask.steam.announcements) {
  6502. scripts_echoLog({
  6503. type: 'globalOptionsSkip',
  6504. text: 'steam.announcements'
  6505. });
  6506. } else {
  6507. const realAnnouncements = this.getRealParams('announcements', announcementLinks, doTask, link => {
  6508. if (link.includes('store.steampowered.com')) {
  6509. return link.match(/store\.steampowered\.com\/news\/app\/([\d]+)\/view\/([\d]+)/)?.slice(1, 3).join('/');
  6510. }
  6511. return link.match(/steamcommunity\.com\/games\/([\d]+)\/announcements\/detail\/([\d]+)/)?.slice(1, 3).join('/');
  6512. });
  6513. if (doTask && realAnnouncements.length > 0) {
  6514. for (const id of realAnnouncements) {
  6515. prom.push(this.#likeAnnouncement(id));
  6516. await delay(1e3);
  6517. }
  6518. }
  6519. }
  6520. if (doTask && !globalOptions.doTask.steam.licenses) {
  6521. scripts_echoLog({
  6522. type: 'globalOptionsSkip',
  6523. text: 'steam.licenses'
  6524. });
  6525. } else if (doTask && globalOptions.doTask.steam.licenses && licenseLinks.length > 0) {
  6526. for (const id of licenseLinks) {
  6527. prom.push(this.#addLicense(id));
  6528. await delay(1e3);
  6529. }
  6530. }
  6531. if (doTask && !globalOptions.doTask.steam.playtests) {
  6532. scripts_echoLog({
  6533. type: 'globalOptionsSkip',
  6534. text: 'steam.playtests'
  6535. });
  6536. } else {
  6537. const realPlaytests = this.getRealParams('playtests', playtestLinks, doTask, link => link.match(/app\/([\d]+)/)?.[1]);
  6538. if (doTask && globalOptions.doTask.steam.playtests && realPlaytests.length > 0) {
  6539. for (const id of realPlaytests) {
  6540. prom.push(this.#requestPlayTestAccess(id));
  6541. await delay(1e3);
  6542. }
  6543. }
  6544. }
  6545. return Promise.all(prom).then(async () => {
  6546. if (this.#area !== 'CN') {
  6547. scripts_echoLog({}).warning(i18n('steamFinishNotice'));
  6548. await this.#changeArea('CN');
  6549. }
  6550. return true;
  6551. });
  6552. } catch (error) {
  6553. throwError(error, 'Steam.toggle');
  6554. return false;
  6555. }
  6556. }
  6557. #setCache(type, name, id) {
  6558. try {
  6559. this.#cache[type][name] = id;
  6560. GM_setValue('steamCache', this.#cache);
  6561. } catch (error) {
  6562. throwError(error, 'Steam.setCache');
  6563. }
  6564. }
  6565. }
  6566. const social_Steam = Steam;
  6567. class Website {
  6568. undoneTasks;
  6569. socialTasks;
  6570. giveawayId;
  6571. socialInitialized = {
  6572. discord: false,
  6573. instagram: false,
  6574. reddit: false,
  6575. twitch: false,
  6576. twitter: false,
  6577. vk: false,
  6578. youtube: false,
  6579. steamStore: false,
  6580. steamCommunity: false
  6581. };
  6582. initialized = false;
  6583. social = {};
  6584. async #bind(name, init) {
  6585. try {
  6586. return {
  6587. name: name,
  6588. result: await init
  6589. };
  6590. } catch (error) {
  6591. throwError(error, 'Website.bind');
  6592. return {
  6593. name: name,
  6594. result: false
  6595. };
  6596. }
  6597. }
  6598. async initSocial(action) {
  6599. try {
  6600. const pro = [];
  6601. const tasks = action === 'do' ? this.undoneTasks : this.socialTasks;
  6602. if (tasks.discord) {
  6603. const hasDiscord = Object.values(tasks.discord).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6604. if (hasDiscord && (!this.socialInitialized.discord || !this.social.discord)) {
  6605. this.social.discord = new social_Discord();
  6606. pro.push(this.#bind('discord', this.social.discord.init(action)));
  6607. }
  6608. }
  6609. if (tasks.instagram) {
  6610. const hasInstagram = Object.values(tasks.instagram).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6611. if (hasInstagram && (!this.socialInitialized.instagram || !this.social.instagram)) {
  6612. this.social.instagram = new social_Instagram();
  6613. pro.push(this.#bind('instagram', this.social.instagram.init()));
  6614. }
  6615. }
  6616. if (tasks.reddit) {
  6617. const hasReddit = Object.values(tasks.reddit).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6618. if (hasReddit && (!this.socialInitialized.reddit || !this.social.reddit)) {
  6619. this.social.reddit = new social_Reddit();
  6620. pro.push(this.#bind('reddit', this.social.reddit.init()));
  6621. }
  6622. }
  6623. if (tasks.twitch) {
  6624. const hasTwitch = Object.values(tasks.twitch).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6625. if (hasTwitch && (!this.socialInitialized.twitch || !this.social.twitch)) {
  6626. this.social.twitch = new social_Twitch();
  6627. pro.push(this.#bind('twitch', this.social.twitch.init()));
  6628. }
  6629. }
  6630. if (tasks.twitter) {
  6631. const hasTwitter = Object.values(tasks.twitter).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6632. if (hasTwitter && (!this.socialInitialized.twitter || !this.social.twitter)) {
  6633. this.social.twitter = new social_Twitter();
  6634. pro.push(this.#bind('twitter', this.social.twitter.init()));
  6635. }
  6636. }
  6637. if (tasks.vk) {
  6638. const hasVk = Object.values(tasks.vk).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6639. if (hasVk && (!this.socialInitialized.vk || !this.social.vk)) {
  6640. this.social.vk = new social_Vk();
  6641. pro.push(this.#bind('vk', this.social.vk.init()));
  6642. }
  6643. }
  6644. if (tasks.youtube) {
  6645. const hasYoutube = Object.values(tasks.youtube).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6646. if (hasYoutube && (!this.socialInitialized.youtube || !this.social.youtube)) {
  6647. this.social.youtube = new Youtube();
  6648. pro.push(this.#bind('youtube', this.social.youtube.init()));
  6649. }
  6650. }
  6651. if (tasks.steam) {
  6652. const steamLength = Object.values(tasks.steam).reduce((total, arr) => [ ...total, ...arr ]).length;
  6653. if (steamLength > 0) {
  6654. if (!this.social.steam) {
  6655. this.social.steam = new social_Steam();
  6656. }
  6657. 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);
  6658. if (steamLength - steamCommunityLength > 0 && !this.socialInitialized.steamStore) {
  6659. pro.push(this.#bind('steamStore', this.social.steam.init('store')));
  6660. }
  6661. if (steamCommunityLength > 0 && !this.socialInitialized.steamCommunity) {
  6662. pro.push(this.#bind('steamCommunity', this.social.steam.init('community')));
  6663. }
  6664. }
  6665. }
  6666. if (tasks.links && tasks.links.length > 0) {
  6667. this.social.visitLink = visitLink;
  6668. }
  6669. return await Promise.all(pro).then(result => {
  6670. let checked = true;
  6671. for (const data of result) {
  6672. if (data.result) {
  6673. this.socialInitialized[data.name] = data.result;
  6674. } else {
  6675. checked = false;
  6676. }
  6677. }
  6678. return checked;
  6679. });
  6680. } catch (error) {
  6681. throwError(error, 'Website.initSocial');
  6682. return false;
  6683. }
  6684. }
  6685. uniqueTasks(allTasks) {
  6686. const result = {};
  6687. for (const [ social, types ] of Object.entries(allTasks)) {
  6688. result[social] = {};
  6689. for (const [ type, tasks ] of Object.entries(types)) {
  6690. result[social][type] = unique(tasks);
  6691. }
  6692. }
  6693. return result;
  6694. }
  6695. async toggleTask(action) {
  6696. try {
  6697. if (!this.initialized && !this.init()) {
  6698. return false;
  6699. }
  6700. if (!await this.classifyTask(action)) {
  6701. return false;
  6702. }
  6703. if (!await this.initSocial(action)) {
  6704. return false;
  6705. }
  6706. const pro = [];
  6707. const doTask = action === 'do';
  6708. const tasks = doTask ? this.undoneTasks : this.socialTasks;
  6709. if (this.socialInitialized.discord !== 'skip' && this.social.discord) {
  6710. pro.push(this.social.discord.toggle({
  6711. doTask: doTask,
  6712. ...tasks.discord
  6713. }));
  6714. }
  6715. if (this.social.instagram) {
  6716. pro.push(this.social.instagram.toggle({
  6717. doTask: doTask,
  6718. ...tasks.instagram
  6719. }));
  6720. }
  6721. if (this.social.reddit) {
  6722. pro.push(this.social.reddit.toggle({
  6723. doTask: doTask,
  6724. ...tasks.reddit
  6725. }));
  6726. }
  6727. if (this.social.twitch) {
  6728. pro.push(this.social.twitch.toggle({
  6729. doTask: doTask,
  6730. ...tasks.twitch
  6731. }));
  6732. }
  6733. if (this.social.twitter) {
  6734. pro.push(this.social.twitter.toggle({
  6735. doTask: doTask,
  6736. ...tasks.twitter
  6737. }));
  6738. }
  6739. if (this.social.vk) {
  6740. pro.push(this.social.vk.toggle({
  6741. doTask: doTask,
  6742. ...tasks.vk
  6743. }));
  6744. }
  6745. if (this.social.youtube) {
  6746. pro.push(this.social.youtube.toggle({
  6747. doTask: doTask,
  6748. ...tasks.youtube
  6749. }));
  6750. }
  6751. if (this.social.steam) {
  6752. pro.push(this.social.steam.toggle({
  6753. doTask: doTask,
  6754. ...tasks.steam
  6755. }));
  6756. }
  6757. if (this.social.visitLink && tasks.links && doTask) {
  6758. for (const link of tasks.links) {
  6759. pro.push(this.social.visitLink(link));
  6760. }
  6761. }
  6762. if (doTask && tasks.extra && this.extraDoTask) {
  6763. const hasExtra = Object.values(tasks.extra).reduce((total, arr) => [ ...total, ...arr ]).length > 0;
  6764. if (hasExtra) {
  6765. pro.push(this.extraDoTask(tasks.extra));
  6766. }
  6767. }
  6768. await Promise.all(pro);
  6769. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6770. return true;
  6771. } catch (error) {
  6772. throwError(error, 'Website.toggleTask');
  6773. return false;
  6774. }
  6775. }
  6776. async doTask() {
  6777. try {
  6778. return await this.toggleTask('do');
  6779. } catch (error) {
  6780. throwError(error, 'Website.doTask');
  6781. return false;
  6782. }
  6783. }
  6784. async undoTask() {
  6785. try {
  6786. return await this.toggleTask('undo');
  6787. } catch (error) {
  6788. throwError(error, 'Website.undoTask');
  6789. return false;
  6790. }
  6791. }
  6792. }
  6793. const website_Website = Website;
  6794. const defaultTasksTemplate = {
  6795. steam: {
  6796. groupLinks: [],
  6797. wishlistLinks: [],
  6798. curatorLinks: [],
  6799. followLinks: []
  6800. },
  6801. vk: {
  6802. nameLinks: []
  6803. }
  6804. };
  6805. const defaultTasks = JSON.stringify(defaultTasksTemplate);
  6806. class FreeAnyWhere extends website_Website {
  6807. name = 'FreeAnyWhere';
  6808. tasks = [];
  6809. socialTasks = JSON.parse(defaultTasks);
  6810. undoneTasks = JSON.parse(defaultTasks);
  6811. buttons = [ 'doTask', 'undoTask', 'verifyTask', 'getKey' ];
  6812. static test() {
  6813. return window.location.host === 'freeanywhere.net';
  6814. }
  6815. async init() {
  6816. try {
  6817. const logStatus = scripts_echoLog({
  6818. text: i18n('initing')
  6819. });
  6820. if ($('a[href="#/login"]').length > 0) {
  6821. window.open('/#/login', '_self');
  6822. logStatus.warning(i18n('needLogin'));
  6823. return false;
  6824. }
  6825. if (window.location.href.includes('/login')) {
  6826. logStatus.warning(i18n('needLogin'));
  6827. return false;
  6828. }
  6829. if (!/^https?:\/\/freeanywhere\.net\/#\/giveaway\/[\d]+/.test(window.location.href)) {
  6830. const id = window.location.href.match(/https?:\/\/freeanywhere\.net\/.*?#\/giveaway\/([\d]+)/)?.[1];
  6831. if (!id) {
  6832. logStatus.error(i18n('getFailed', 'Id'));
  6833. return false;
  6834. }
  6835. window.location.href = `https://freeanywhere.net/#/giveaway/${id}`;
  6836. }
  6837. if (!this.#getGiveawayId()) {
  6838. return false;
  6839. }
  6840. if (!await this.#checkLeftKey()) {
  6841. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  6842. }
  6843. this.initialized = true;
  6844. logStatus.success();
  6845. return true;
  6846. } catch (error) {
  6847. throwError(error, 'Freeanywhere.init');
  6848. return false;
  6849. }
  6850. }
  6851. async classifyTask(action) {
  6852. try {
  6853. const logStatus = scripts_echoLog({
  6854. text: i18n('getTasksInfo')
  6855. });
  6856. if (action === 'undo') {
  6857. this.socialTasks = GM_getValue(`fawTasks-${this.giveawayId}`)?.tasks || JSON.parse(defaultTasks);
  6858. }
  6859. const {
  6860. result,
  6861. statusText,
  6862. status,
  6863. data
  6864. } = await tools_httpRequest({
  6865. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/?format=json`,
  6866. method: 'GET',
  6867. headers: {
  6868. authorization: `Token ${window.localStorage.getItem('token')}`,
  6869. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  6870. },
  6871. responseType: 'json'
  6872. });
  6873. if (result === 'Success') {
  6874. const tasks = data?.response?.challenges;
  6875. if (tasks) {
  6876. if (action === 'verify') {
  6877. this.tasks = [];
  6878. }
  6879. for (const task of tasks) {
  6880. const type = task.challenge;
  6881. const social = task.challenge_provider;
  6882. const taskInfo = {
  6883. id: task.id,
  6884. title: task.title
  6885. };
  6886. if (action === 'verify' && !task.is_success) {
  6887. this.tasks.push(taskInfo);
  6888. continue;
  6889. }
  6890. switch (social) {
  6891. case 'steam':
  6892. taskInfo.social = 'steam';
  6893. switch (type) {
  6894. case 'WL':
  6895. if (action === 'undo') {
  6896. this.socialTasks.steam.wishlistLinks.push(task.link);
  6897. }
  6898. if (action === 'do' && !task.is_success) {
  6899. this.undoneTasks.steam.wishlistLinks.push(task.link);
  6900. }
  6901. break;
  6902.  
  6903. case 'JTG':
  6904. if (action === 'undo') {
  6905. this.socialTasks.steam.groupLinks.push(task.link);
  6906. }
  6907. if (action === 'do' && !task.is_success) {
  6908. this.undoneTasks.steam.groupLinks.push(task.link);
  6909. }
  6910. break;
  6911.  
  6912. case 'STC':
  6913. if (action === 'undo') {
  6914. this.socialTasks.steam.curatorLinks.push(task.link);
  6915. }
  6916. if (action === 'do' && !task.is_success) {
  6917. this.undoneTasks.steam.curatorLinks.push(task.link);
  6918. }
  6919. break;
  6920.  
  6921. case 'GF':
  6922. if (action === 'undo') {
  6923. this.socialTasks.steam.followLinks.push(task.link);
  6924. }
  6925. if (action === 'do' && !task.is_success) {
  6926. this.undoneTasks.steam.followLinks.push(task.link);
  6927. }
  6928. break;
  6929. }
  6930. break;
  6931.  
  6932. case 'vk-oauth2':
  6933. if (action === 'undo') {
  6934. this.socialTasks.vk.nameLinks.push(task.link);
  6935. }
  6936. if (action === 'do' && !task.is_success) {
  6937. this.undoneTasks.vk.nameLinks.push(task.link);
  6938. }
  6939. break;
  6940.  
  6941. case 'website':
  6942. break;
  6943.  
  6944. default:
  6945. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${social}`);
  6946. break;
  6947. }
  6948. }
  6949. logStatus.success();
  6950. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  6951. this.socialTasks = this.uniqueTasks(this.socialTasks);
  6952. if (window.DEBUG) {
  6953. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  6954. }
  6955. GM_setValue(`fawTasks-${this.giveawayId}`, {
  6956. tasks: this.socialTasks,
  6957. time: new Date().getTime()
  6958. });
  6959. return true;
  6960. }
  6961. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  6962. return false;
  6963. }
  6964. logStatus.error(`${result}:${statusText}(${status})`);
  6965. return false;
  6966. } catch (error) {
  6967. throwError(error, 'Freeanywhere.classifyTask');
  6968. return false;
  6969. }
  6970. }
  6971. async verifyTask() {
  6972. try {
  6973. if (!this.initialized && !this.init()) {
  6974. return false;
  6975. }
  6976. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  6977. return false;
  6978. }
  6979. const pro = [];
  6980. for (const task of this.tasks) {
  6981. pro.push(this.#verify(task));
  6982. await delay(1e3);
  6983. }
  6984. await Promise.all(pro);
  6985. scripts_echoLog({}).success(i18n('allTasksComplete'));
  6986. return !!await this.getKey(true);
  6987. } catch (error) {
  6988. throwError(error, 'Freeanywhere.verifyTask');
  6989. return false;
  6990. }
  6991. }
  6992. async getKey(initialized) {
  6993. try {
  6994. if (!initialized && !this.initialized && !this.init()) {
  6995. return false;
  6996. }
  6997. const logStatus = scripts_echoLog({
  6998. text: i18n('gettingKey')
  6999. });
  7000. const {
  7001. result,
  7002. statusText,
  7003. status,
  7004. data
  7005. } = await tools_httpRequest({
  7006. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/reward/?format=json`,
  7007. method: 'GET',
  7008. dataType: 'json',
  7009. headers: {
  7010. authorization: `Token ${window.localStorage.getItem('token')}`
  7011. }
  7012. });
  7013. if (result === 'Success') {
  7014. if (data?.response?.reward) {
  7015. logStatus.success();
  7016. scripts_echoLog({}).success(data.response.reward);
  7017. return data.response.reward;
  7018. }
  7019. if (data?.response?.completed === false) {
  7020. logStatus.error(i18n('tasksNotCompleted'));
  7021. return false;
  7022. }
  7023. if (data?.response?.completed === true) {
  7024. await this.#checkLeftKey();
  7025. }
  7026. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7027. return false;
  7028. }
  7029. logStatus.error(`${result}:${statusText}(${status})`);
  7030. return false;
  7031. } catch (error) {
  7032. throwError(error, 'FreeAnyWhere.getGiveawayId');
  7033. return false;
  7034. }
  7035. }
  7036. #getGiveawayId() {
  7037. try {
  7038. const giveawayId = window.location.href.match(/\/giveaway\/([\d]+)/)?.[1];
  7039. if (giveawayId) {
  7040. this.giveawayId = giveawayId;
  7041. return true;
  7042. }
  7043. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7044. return false;
  7045. } catch (error) {
  7046. throwError(error, 'FreeAnyWhere.getGiveawayId');
  7047. }
  7048. }
  7049. async #verify(task) {
  7050. try {
  7051. const logStatus = scripts_echoLog({
  7052. html: `<li>${i18n('verifyingTask')}${task.title.trim()}...<font></font></li>`
  7053. });
  7054. const {
  7055. result,
  7056. statusText,
  7057. status,
  7058. data
  7059. } = await tools_httpRequest({
  7060. url: `https://freeanywhere.net/api/v1/giveaway/${this.giveawayId}/challenge-status/${task.id}/?format=json`,
  7061. method: 'GET',
  7062. dataType: 'json',
  7063. headers: {
  7064. authorization: `Token ${window.localStorage.getItem('token')}`,
  7065. 'x-csrftoken': external_Cookies_namespaceObject.get('csrftoken')
  7066. }
  7067. });
  7068. if (result === 'Success') {
  7069. if (data?.response?.status) {
  7070. logStatus.success();
  7071. return true;
  7072. }
  7073. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7074. return false;
  7075. }
  7076. logStatus.error(`${result}:${statusText}(${status})`);
  7077. return false;
  7078. } catch (error) {
  7079. throwError(error, 'Freeanywhere.verify');
  7080. return false;
  7081. }
  7082. }
  7083. async #checkLeftKey() {
  7084. try {
  7085. if (!globalOptions.other.checkLeftKey) {
  7086. return true;
  7087. }
  7088. const {
  7089. data
  7090. } = await tools_httpRequest({
  7091. url: 'https://freeanywhere.net/api/v1/widget/?format=json',
  7092. method: 'GET',
  7093. dataType: 'json',
  7094. headers: {
  7095. authorization: `Token ${window.localStorage.getItem('token')}`
  7096. }
  7097. });
  7098. if (data?.response?.giveaways.find(giveaway => `${giveaway?.id}` === this.giveawayId)) {
  7099. return true;
  7100. }
  7101. await external_Swal_default().fire({
  7102. icon: 'warning',
  7103. title: i18n('notice'),
  7104. text: i18n('noKeysLeft'),
  7105. confirmButtonText: i18n('confirm'),
  7106. cancelButtonText: i18n('cancel'),
  7107. showCancelButton: true
  7108. }).then(({
  7109. value
  7110. }) => {
  7111. if (value) {
  7112. window.close();
  7113. }
  7114. });
  7115. return true;
  7116. } catch (error) {
  7117. throwError(error, 'Giveawaysu.checkLeftKey');
  7118. return false;
  7119. }
  7120. }
  7121. }
  7122. const Freeanywhere = FreeAnyWhere;
  7123. const Giveawaysu_defaultTasks = {
  7124. steam: {
  7125. groupLinks: [],
  7126. wishlistLinks: [],
  7127. curatorLinks: [],
  7128. curatorLikeLinks: [],
  7129. followLinks: [],
  7130. forumLinks: [],
  7131. announcementLinks: [],
  7132. workshopVoteLinks: [],
  7133. playtestLinks: []
  7134. },
  7135. discord: {
  7136. serverLinks: []
  7137. },
  7138. instagram: {
  7139. userLinks: []
  7140. },
  7141. vk: {
  7142. nameLinks: []
  7143. },
  7144. twitch: {
  7145. channelLinks: []
  7146. },
  7147. reddit: {
  7148. redditLinks: []
  7149. },
  7150. youtube: {
  7151. channelLinks: [],
  7152. likeLinks: []
  7153. },
  7154. twitter: {
  7155. userLinks: [],
  7156. retweetLinks: []
  7157. }
  7158. };
  7159. class GiveawaySu extends website_Website {
  7160. name = 'GiveawaySu';
  7161. socialTasks = Giveawaysu_defaultTasks;
  7162. undoneTasks = Giveawaysu_defaultTasks;
  7163. buttons = [ 'doTask', 'undoTask' ];
  7164. static test() {
  7165. return /^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(window.location.href);
  7166. }
  7167. async after() {
  7168. try {
  7169. if (!this.#checkLogin()) {
  7170. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7171. }
  7172. if (!await this.#checkLeftKey()) {
  7173. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7174. }
  7175. scripts_echoLog({}).warning(i18n('gsNotice'));
  7176. } catch (error) {
  7177. throwError(error, 'Giveawaysu.after');
  7178. }
  7179. }
  7180. init() {
  7181. try {
  7182. const logStatus = scripts_echoLog({
  7183. text: i18n('initing')
  7184. });
  7185. if ($('a.steam-login').length > 0) {
  7186. window.open('/steam/redirect', '_self');
  7187. logStatus.warning(i18n('needLogin'));
  7188. return false;
  7189. }
  7190. if (!this.#getGiveawayId()) {
  7191. return false;
  7192. }
  7193. this.initialized = true;
  7194. logStatus.success();
  7195. return true;
  7196. } catch (error) {
  7197. throwError(error, 'Giveawaysu.init');
  7198. return false;
  7199. }
  7200. }
  7201. async classifyTask(action) {
  7202. try {
  7203. const logStatus = scripts_echoLog({
  7204. text: i18n('getTasksInfo')
  7205. });
  7206. if (action === 'undo') {
  7207. this.socialTasks = GM_getValue(`gasTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  7208. return true;
  7209. }
  7210. const pro = [];
  7211. const tasks = $('#actions tr');
  7212. if ($('div.bind-discord').is(':visible')) {
  7213. $('div.bind-discord a')[0].click();
  7214. }
  7215. if ($('div.bind-twitch').is(':visible')) {
  7216. $('div.bind-twitch a')[0].click();
  7217. }
  7218. for (const task of tasks) {
  7219. pro.push(new Promise(resolve => {
  7220. const td = $(task).find('td:not(".hidden")');
  7221. const colorfulTask = td.eq(1).find('a:not([data-trigger="link"])');
  7222. const colorlessTask = td.eq(2).find('a:not([data-trigger="link"])');
  7223. const taskDes = colorfulTask.length > 0 ? colorfulTask : colorlessTask;
  7224. const taskIcon = td.eq(0).find('i').attr('class') || '';
  7225. const taskName = taskDes.text().trim();
  7226. if (taskIcon.includes('ban') || /disable adblock/gi.test(taskName)) {
  7227. return resolve(true);
  7228. }
  7229. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  7230. if (!taskLink) {
  7231. return resolve(false);
  7232. }
  7233. if (taskIcon.includes('steam') && /join/gi.test(taskName)) {
  7234. this.undoneTasks.steam.groupLinks.push(taskLink);
  7235. } else if (/like.*announcement/gi.test(taskName)) {
  7236. this.undoneTasks.steam.announcementLinks.push(taskLink);
  7237. } else if (/(follow|subscribe).*curator/gim.test(taskName) && /^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  7238. this.undoneTasks.steam.curatorLinks.push(taskLink);
  7239. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  7240. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  7241. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  7242. this.undoneTasks.steam.forumLinks.push(taskLink);
  7243. } else if (taskIcon.includes('thumbs-up') && /^https?:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=[\d]+/.test(taskLink)) {
  7244. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7245. } else if (taskIcon.includes('plus') && /request.*playtest/gim.test(taskName)) {
  7246. this.undoneTasks.steam.playtestLinks.push(taskLink);
  7247. } else if (taskIcon.includes('discord') || /join.*discord/gim.test(taskName)) {
  7248. this.undoneTasks.discord.serverLinks.push(taskLink);
  7249. } else if (taskIcon.includes('instagram') || /follow.*instagram/gim.test(taskName)) {
  7250. this.undoneTasks.instagram.userLinks.push(taskLink);
  7251. } else if (taskIcon.includes('twitch') || /follow.*twitch.*channel/gim.test(taskName)) {
  7252. this.undoneTasks.twitch.channelLinks.push(taskLink);
  7253. } else if (taskIcon.includes('reddit') || /subscribe.*subreddit/gim.test(taskName) || /follow.*reddit/gim.test(taskName)) {
  7254. this.undoneTasks.reddit.redditLinks.push(taskLink);
  7255. } else if (/watch.*art/gim.test(taskName)) {
  7256. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  7257. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  7258. this.undoneTasks.youtube.channelLinks.push(taskLink);
  7259. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  7260. this.undoneTasks.youtube.likeLinks.push(taskLink);
  7261. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  7262. this.undoneTasks.vk.nameLinks.push(taskLink);
  7263. } else {
  7264. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  7265. if (/wishlist.*game|add.*wishlist/gim.test(taskName)) {
  7266. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  7267. }
  7268. if (/follow.*button/gim.test(taskName)) {
  7269. this.undoneTasks.steam.followLinks.push(taskLink);
  7270. }
  7271. }
  7272. }
  7273. resolve(true);
  7274. }).catch(error => {
  7275. throwError(error, 'Giveawaysu.classifyTask->getRedirectLink');
  7276. return false;
  7277. });
  7278. }));
  7279. }
  7280. await Promise.all(pro);
  7281. logStatus.success();
  7282. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7283. this.socialTasks = this.undoneTasks;
  7284. if (window.DEBUG) {
  7285. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7286. }
  7287. GM_setValue(`gasTasks-${this.giveawayId}`, {
  7288. tasks: this.socialTasks,
  7289. time: new Date().getTime()
  7290. });
  7291. return true;
  7292. } catch (error) {
  7293. throwError(error, 'Giveawaysu.classifyTask');
  7294. return false;
  7295. }
  7296. }
  7297. #checkLogin() {
  7298. try {
  7299. if (!globalOptions.other.checkLogin) {
  7300. return true;
  7301. }
  7302. if ($('a.steam-login').length > 0) {
  7303. window.open('/steam/redirect', '_self');
  7304. }
  7305. return true;
  7306. } catch (error) {
  7307. throwError(error, 'Giveawaysu.checkLogin');
  7308. return false;
  7309. }
  7310. }
  7311. async #checkLeftKey() {
  7312. try {
  7313. if (!globalOptions.other.checkLeftKey) {
  7314. return true;
  7315. }
  7316. if ($('.giveaway-ended').length > 0 && $('.giveaway-key').length === 0) {
  7317. await external_Swal_default().fire({
  7318. icon: 'warning',
  7319. title: i18n('notice'),
  7320. text: i18n('noKeysLeft'),
  7321. confirmButtonText: i18n('confirm'),
  7322. cancelButtonText: i18n('cancel'),
  7323. showCancelButton: true
  7324. }).then(({
  7325. value
  7326. }) => {
  7327. if (value) {
  7328. window.close();
  7329. }
  7330. });
  7331. }
  7332. return true;
  7333. } catch (error) {
  7334. throwError(error, 'Giveawaysu.checkLeftKey');
  7335. return false;
  7336. }
  7337. }
  7338. #getGiveawayId() {
  7339. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  7340. if (giveawayId) {
  7341. this.giveawayId = giveawayId;
  7342. return true;
  7343. }
  7344. scripts_echoLog({
  7345. text: i18n('getFailed', 'GiveawayId')
  7346. });
  7347. return false;
  7348. }
  7349. }
  7350. class Indiedb {
  7351. name = 'Indiedb';
  7352. buttons = [ 'doTask' ];
  7353. static test() {
  7354. return window.location.host === 'www.indiedb.com';
  7355. }
  7356. async after() {
  7357. try {
  7358. if (!this.#checkLogin()) {
  7359. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7360. }
  7361. if (!await this.#checkLeftKey()) {
  7362. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7363. }
  7364. } catch (error) {
  7365. throwError(error, 'Indiedb.after');
  7366. }
  7367. }
  7368. async doTask() {
  7369. try {
  7370. if (!await this.#join()) {
  7371. return false;
  7372. }
  7373. return await this.#do();
  7374. } catch (error) {
  7375. throwError(error, 'Indiedb.doTask');
  7376. return false;
  7377. }
  7378. }
  7379. async #join() {
  7380. try {
  7381. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7382. scripts_echoLog({}).error(i18n('needLogin'));
  7383. return false;
  7384. }
  7385. const currentoption = $('a.buttonenter.buttongiveaway');
  7386. if (/join giveaway/gim.test(currentoption.text())) {
  7387. const logStatus = scripts_echoLog({
  7388. text: `${i18n('joiningGiveaway')}...`
  7389. });
  7390. const {
  7391. result,
  7392. statusText,
  7393. status,
  7394. data
  7395. } = await tools_httpRequest({
  7396. url: currentoption.attr('href'),
  7397. method: 'POST',
  7398. data: 'ajax=t',
  7399. dataType: 'json',
  7400. headers: {
  7401. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  7402. accept: 'application/json, text/javascript, */*; q=0.01',
  7403. origin: window.location.origin
  7404. }
  7405. });
  7406. if (result === 'Success') {
  7407. if (data?.status === 200) {
  7408. if (data.response?.success) {
  7409. currentoption.addClass('buttonentered').text('Success - Giveaway joined');
  7410. $('#giveawaysjoined').slideDown();
  7411. $('#giveawaysrecommend').slideDown();
  7412. logStatus.success(`Success${data.response?.text ? `:${data.response?.text}` : ''}`);
  7413. return true;
  7414. }
  7415. logStatus.error(`Error${data.response?.text ? `:${data.response?.text}` : ''}`);
  7416. return false;
  7417. }
  7418. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  7419. return false;
  7420. }
  7421. logStatus.error(`${result}:${statusText}(${status})`);
  7422. return false;
  7423. } else if (/success/gim.test($('a.buttonenter.buttongiveaway').text())) {
  7424. return true;
  7425. }
  7426. scripts_echoLog({}).warning(i18n('needJoinGiveaway'));
  7427. return false;
  7428. } catch (error) {
  7429. throwError(error, 'Indiedb.init');
  7430. return false;
  7431. }
  7432. }
  7433. async #do() {
  7434. try {
  7435. const id = $('script').map((index, script) => {
  7436. if (/\$\(document\)/gim.test(script.innerHTML)) {
  7437. return [ script.innerHTML.match(/"\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0], script.innerHTML.match(/"\/newsletter\/ajax\/subscribeprofile\/optin\/[\d]+"/gim)?.[0]?.match(/[\d]+/)?.[0] ];
  7438. }
  7439. return null;
  7440. });
  7441. if (id.length === 2) {
  7442. const pro = [];
  7443. const tasks = $('#giveawaysjoined a[class*=promo]');
  7444. for (const task of tasks) {
  7445. const promo = $(task);
  7446. if (!promo.hasClass('buttonentered')) {
  7447. const status = scripts_echoLog({
  7448. text: `${i18n('doing')}:${promo.parents('p').text()}...`
  7449. });
  7450. if (/facebookpromo|twitterpromo|visitpromo/gim.test(task.className)) {
  7451. let text = '';
  7452. if (promo.hasClass('facebookpromo')) {
  7453. text = 'facebookpromo';
  7454. } else if (promo.hasClass('twitterpromo')) {
  7455. text = 'twitterpromo';
  7456. } else {
  7457. text = 'visitpromo';
  7458. }
  7459. pro.push(new Promise(resolve => {
  7460. $.ajax({
  7461. type: 'POST',
  7462. url: urlPath(`/giveaways/ajax/${text}/${id[0]}`),
  7463. timeout: 6e4,
  7464. dataType: 'json',
  7465. data: {
  7466. ajax: 't'
  7467. },
  7468. error(response, error, exception) {
  7469. if (window.DEBUG) {
  7470. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7471. response: response,
  7472. error: error,
  7473. exception: exception
  7474. });
  7475. }
  7476. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7477. resolve(true);
  7478. },
  7479. success(response) {
  7480. if (response.success) {
  7481. status.success(`Success:${response.text}`);
  7482. promo.addClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7483. resolve(true);
  7484. } else {
  7485. status.error(`Error:${response.text}`);
  7486. resolve(true);
  7487. }
  7488. }
  7489. });
  7490. }));
  7491. } else if (promo.hasClass('emailoptinpromo')) {
  7492. pro.push(new Promise(resolve => {
  7493. $.ajax({
  7494. type: 'POST',
  7495. url: urlPath(`/newsletter/ajax/subscribeprofile/optin/${id[1]}`),
  7496. timeout: 6e4,
  7497. dataType: 'json',
  7498. data: {
  7499. ajax: 't',
  7500. emailsystoggle: 4
  7501. },
  7502. error(response, error, exception) {
  7503. if (window.DEBUG) {
  7504. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7505. response: response,
  7506. error: error,
  7507. exception: exception
  7508. });
  7509. }
  7510. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7511. resolve(true);
  7512. },
  7513. success(response) {
  7514. if (response.success) {
  7515. status.success(`Success:${response.text}`);
  7516. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7517. resolve(true);
  7518. } else {
  7519. status.error(`Error:${response.text}`);
  7520. resolve(true);
  7521. }
  7522. }
  7523. });
  7524. }));
  7525. } else if (promo.hasClass('watchingpromo')) {
  7526. pro.push(new Promise(resolve => {
  7527. const data = getUrlQuery(promo.attr('href'));
  7528. data.ajax = 't';
  7529. $.ajax({
  7530. type: 'POST',
  7531. url: urlPath(promo.attr('href')?.split(/[?#]/)[0]),
  7532. timeout: 6e4,
  7533. dataType: 'json',
  7534. data: data,
  7535. error(response, error, exception) {
  7536. if (window.DEBUG) {
  7537. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7538. response: response,
  7539. error: error,
  7540. exception: exception
  7541. });
  7542. }
  7543. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7544. resolve(true);
  7545. },
  7546. success(response) {
  7547. if (response.success) {
  7548. status.success(`Success:${response.text}`);
  7549. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7550. resolve(true);
  7551. } else {
  7552. status.error(`Error:${response.text}`);
  7553. resolve(true);
  7554. }
  7555. }
  7556. });
  7557. }));
  7558. } else if (!/the-challenge-of-adblock/gim.test(promo.attr('href'))) {
  7559. pro.push(new Promise(resolve => {
  7560. $.ajax({
  7561. type: 'POST',
  7562. url: urlPath(promo.attr('href')),
  7563. timeout: 6e4,
  7564. dataType: 'json',
  7565. data: {
  7566. ajax: 't'
  7567. },
  7568. error(response, error, exception) {
  7569. if (window.DEBUG) {
  7570. console.log('%cAuto-Task[Debug]:', 'color:red', {
  7571. response: response,
  7572. error: error,
  7573. exception: exception
  7574. });
  7575. }
  7576. status.error('Error:An error has occurred performing the action requested. Please try again shortly.');
  7577. resolve(true);
  7578. },
  7579. success(response) {
  7580. if (response.success) {
  7581. status.success(`Success:${response.text}`);
  7582. promo.toggleClass('buttonentered').closest('p').html(promo.closest('p').find('span').html());
  7583. resolve(true);
  7584. } else {
  7585. status.error(`Error:${response.text}`);
  7586. resolve(true);
  7587. }
  7588. }
  7589. });
  7590. }));
  7591. } else {
  7592. status.error(`Error:${i18n('unKnownTaskType')}`);
  7593. }
  7594. }
  7595. }
  7596. await Promise.all(pro);
  7597. scripts_echoLog({}).success(i18n('allTasksComplete'));
  7598. return true;
  7599. }
  7600. scripts_echoLog({}).error(i18n('getFailed', 'TaskId'));
  7601. return false;
  7602. } catch (error) {
  7603. throwError(error, 'Indiedb.classifyTask');
  7604. return false;
  7605. }
  7606. }
  7607. #checkLogin() {
  7608. try {
  7609. if (!globalOptions.other.checkLogin) {
  7610. return true;
  7611. }
  7612. if ($('a.buttonenter:contains(Register to join)').length > 0) {
  7613. window.open('/members/login', '_self');
  7614. }
  7615. return true;
  7616. } catch (error) {
  7617. throwError(error, 'Indiedb.checkLogin');
  7618. return false;
  7619. }
  7620. }
  7621. async #checkLeftKey() {
  7622. try {
  7623. if (!globalOptions.other.checkLeftKey) {
  7624. return true;
  7625. }
  7626. if ($('a.buttonenter:contains("next time"),a.buttonenter:contains("Giveaway is closed")').length > 0) {
  7627. await external_Swal_default().fire({
  7628. icon: 'warning',
  7629. title: i18n('notice'),
  7630. text: i18n('giveawayEnded'),
  7631. confirmButtonText: i18n('confirm'),
  7632. cancelButtonText: i18n('cancel'),
  7633. showCancelButton: true
  7634. }).then(({
  7635. value
  7636. }) => {
  7637. if (value) {
  7638. window.close();
  7639. }
  7640. });
  7641. }
  7642. return true;
  7643. } catch (error) {
  7644. throwError(error, 'Indiedb.checkLeftKey');
  7645. return false;
  7646. }
  7647. }
  7648. }
  7649. const website_Indiedb = Indiedb;
  7650. const Keyhub_defaultTasksTemplate = {
  7651. steam: {
  7652. groupLinks: [],
  7653. officialGroupLinks: [],
  7654. wishlistLinks: [],
  7655. curatorLinks: []
  7656. },
  7657. discord: {
  7658. serverLinks: []
  7659. },
  7660. extra: {
  7661. videoTasks: []
  7662. },
  7663. links: []
  7664. };
  7665. const Keyhub_defaultTasks = JSON.stringify(Keyhub_defaultTasksTemplate);
  7666. class Keyhub extends website_Website {
  7667. name = 'Keyhub';
  7668. socialTasks = JSON.parse(Keyhub_defaultTasks);
  7669. undoneTasks = JSON.parse(Keyhub_defaultTasks);
  7670. buttons = [ 'doTask', 'undoTask' ];
  7671. static test() {
  7672. return window.location.host === 'key-hub.eu';
  7673. }
  7674. async after() {
  7675. try {
  7676. if (!this.#checkLogin()) {
  7677. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  7678. }
  7679. if (!await this.#checkLeftKey()) {
  7680. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7681. }
  7682. $('.NSFW').hide();
  7683. } catch (error) {
  7684. throwError(error, 'Keyhub.after');
  7685. }
  7686. }
  7687. init() {
  7688. try {
  7689. const logStatus = scripts_echoLog({
  7690. text: i18n('initing')
  7691. });
  7692. if ($('a[href*="/connect/steam"]').length > 0) {
  7693. window.open('/connect/steam', '_self');
  7694. logStatus.warning(i18n('needLogin'));
  7695. return false;
  7696. }
  7697. if (!this.#getGiveawayId()) {
  7698. return false;
  7699. }
  7700. $('#VPNoverlay').hide();
  7701. $('#mainArticleSection').show();
  7702. this.initialized = true;
  7703. logStatus.success();
  7704. return true;
  7705. } catch (error) {
  7706. throwError(error, 'Keyhub.init');
  7707. return false;
  7708. }
  7709. }
  7710. async classifyTask(action) {
  7711. try {
  7712. const logStatus = scripts_echoLog({
  7713. text: i18n('getTasksInfo')
  7714. });
  7715. if (action === 'undo') {
  7716. this.socialTasks = GM_getValue(`khTasks-${this.giveawayId}`)?.tasks || JSON.parse(Keyhub_defaultTasks);
  7717. }
  7718. const tasks = $('.task:not(".googleads")').filter((index, element) => action === 'do' ? $(element).find('i.fa-check-circle:visible').length === 0 : true).find('a');
  7719. for (const task of tasks) {
  7720. let link = $(task).attr('href');
  7721. const taskDes = $(task).text().trim();
  7722. if (!link) {
  7723. continue;
  7724. }
  7725. if (/\/away\?data=/.test(link) || /steamcommunity\.com\/gid\//.test(link)) {
  7726. link = await getRedirectLink(link) || link;
  7727. }
  7728. if (/https?:\/\/key-hub\.eu\/connect\/discord/.test(link)) {
  7729. window.open(link, '_blank');
  7730. } else if (/steamcommunity\.com\/groups\//.test(link)) {
  7731. if (action === 'undo') {
  7732. this.socialTasks.steam.groupLinks.push(link);
  7733. }
  7734. if (action === 'do') {
  7735. this.undoneTasks.steam.groupLinks.push(link);
  7736. }
  7737. } else if (/steamcommunity\.com\/games\/[\d]+/.test(link)) {
  7738. if (action === 'undo') {
  7739. this.socialTasks.steam.officialGroupLinks.push(link);
  7740. }
  7741. if (action === 'do') {
  7742. this.undoneTasks.steam.officialGroupLinks.push(link);
  7743. }
  7744. } else if (/store\.steampowered\.com\/app\//.test(link) && /wishlist/gim.test(taskDes)) {
  7745. if (action === 'undo') {
  7746. this.socialTasks.steam.wishlistLinks.push(link);
  7747. }
  7748. if (action === 'do') {
  7749. this.undoneTasks.steam.wishlistLinks.push(link);
  7750. }
  7751. } else if (/store\.steampowered\.com\/curator\//.test(link)) {
  7752. if (action === 'undo') {
  7753. this.socialTasks.steam.curatorLinks.push(link);
  7754. }
  7755. if (action === 'do') {
  7756. this.undoneTasks.steam.curatorLinks.push(link);
  7757. }
  7758. } else if (/^https?:\/\/discord\.com\/invite\//.test(link)) {
  7759. if (action === 'undo') {
  7760. this.socialTasks.discord.serverLinks.push(link);
  7761. }
  7762. if (action === 'do') {
  7763. this.undoneTasks.discord.serverLinks.push(link);
  7764. }
  7765. } else if (/^javascript:videoTask.+/.test(link)) {
  7766. if (action === 'do') {
  7767. const taskData = link.match(/javascript:videoTask\('.+?','(.+?)'/)?.[1];
  7768. if (taskData) {
  7769. this.undoneTasks.extra.videoTasks.push(taskData);
  7770. }
  7771. }
  7772. } 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 {
  7773. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  7774. }
  7775. }
  7776. logStatus.success();
  7777. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  7778. this.socialTasks = this.uniqueTasks(this.socialTasks);
  7779. if (window.DEBUG) {
  7780. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  7781. }
  7782. GM_setValue(`khTasks-${this.giveawayId}`, {
  7783. tasks: this.socialTasks,
  7784. time: new Date().getTime()
  7785. });
  7786. return true;
  7787. } catch (error) {
  7788. throwError(error, 'Keyhub.classifyTask');
  7789. return false;
  7790. }
  7791. }
  7792. async #doScriptTask(data) {
  7793. try {
  7794. const logStatus = scripts_echoLog({
  7795. text: i18n('doingKeyhubTask')
  7796. });
  7797. const {
  7798. result,
  7799. statusText,
  7800. status,
  7801. data: response
  7802. } = await tools_httpRequest({
  7803. url: `/away?data=${data}`,
  7804. method: 'GET',
  7805. headers: {
  7806. origin: 'https://key-hub.eu',
  7807. referer: 'https://key-hub.eu/'
  7808. }
  7809. });
  7810. if (result === 'Success') {
  7811. if (response?.status === 200) {
  7812. logStatus.success();
  7813. return true;
  7814. }
  7815. logStatus.error(`Error:${response?.statusText}(${response?.status})`);
  7816. return false;
  7817. }
  7818. logStatus.error(`${result}:${statusText}(${status})`);
  7819. return false;
  7820. } catch (error) {
  7821. throwError(error, 'Keyhub.doScriptTask');
  7822. return false;
  7823. }
  7824. }
  7825. async extraDoTask({
  7826. videoTasks
  7827. }) {
  7828. try {
  7829. const pro = [];
  7830. for (const data of videoTasks) {
  7831. pro.push(this.#doScriptTask(data));
  7832. }
  7833. return Promise.all(pro).then(() => true);
  7834. } catch (error) {
  7835. throwError(error, 'Keyhub.extraDoTask');
  7836. return false;
  7837. }
  7838. }
  7839. #getGiveawayId() {
  7840. try {
  7841. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  7842. if (giveawayId) {
  7843. this.giveawayId = giveawayId;
  7844. return true;
  7845. }
  7846. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  7847. return false;
  7848. } catch (error) {
  7849. throwError(error, 'Keyhub.getGiveawayId');
  7850. return false;
  7851. }
  7852. }
  7853. async #checkLeftKey() {
  7854. try {
  7855. if (!globalOptions.other.checkLeftKey) {
  7856. return true;
  7857. }
  7858. const leftKey = $('#keysleft').text().trim();
  7859. if (leftKey === '0') {
  7860. await external_Swal_default().fire({
  7861. icon: 'warning',
  7862. title: i18n('notice'),
  7863. text: i18n('noKeysLeft'),
  7864. confirmButtonText: i18n('confirm'),
  7865. cancelButtonText: i18n('cancel'),
  7866. showCancelButton: true
  7867. }).then(({
  7868. value
  7869. }) => {
  7870. if (value) {
  7871. window.close();
  7872. }
  7873. });
  7874. }
  7875. return true;
  7876. } catch (error) {
  7877. throwError(error, 'Keyhub.checkLeftKey');
  7878. return false;
  7879. }
  7880. }
  7881. #checkLogin() {
  7882. try {
  7883. if (!globalOptions.other.checkLogin) {
  7884. return true;
  7885. }
  7886. if ($('a[href*="/connect/steam"]').length > 0) {
  7887. window.open('/connect/steam', '_self');
  7888. }
  7889. return true;
  7890. } catch (error) {
  7891. throwError(error, 'Keyhub.checkLogin');
  7892. return false;
  7893. }
  7894. }
  7895. }
  7896. const website_Keyhub = Keyhub;
  7897. const Givekey_defaultTasksTemplate = {
  7898. steam: {
  7899. groupLinks: [],
  7900. wishlistLinks: [],
  7901. curatorLinks: [],
  7902. curatorLikeLinks: []
  7903. },
  7904. twitter: {
  7905. userLinks: []
  7906. },
  7907. vk: {
  7908. nameLinks: []
  7909. },
  7910. discord: {
  7911. serverLinks: []
  7912. }
  7913. };
  7914. const Givekey_defaultTasks = JSON.stringify(Givekey_defaultTasksTemplate);
  7915. class Givekey extends website_Website {
  7916. name = 'Givekey';
  7917. tasks = [];
  7918. socialTasks = JSON.parse(Givekey_defaultTasks);
  7919. undoneTasks = JSON.parse(Givekey_defaultTasks);
  7920. userId;
  7921. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  7922. static test() {
  7923. return window.location.host === 'givekey.ru';
  7924. }
  7925. async after() {
  7926. try {
  7927. await new Promise(resolve => {
  7928. const checker = setInterval(() => {
  7929. if ($('#navbarDropdown').length > 0) {
  7930. clearInterval(checker);
  7931. resolve(true);
  7932. }
  7933. });
  7934. });
  7935. if (!await this.#checkLeftKey()) {
  7936. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  7937. }
  7938. } catch (error) {
  7939. throwError(error, 'Givekey.after');
  7940. return false;
  7941. }
  7942. }
  7943. init() {
  7944. try {
  7945. const logStatus = scripts_echoLog({
  7946. text: i18n('initing')
  7947. });
  7948. if ($('a[href*="/auth/steam"]').length > 0) {
  7949. window.open('/auth/steam', '_self');
  7950. logStatus.warning(i18n('needLogin'));
  7951. return false;
  7952. }
  7953. if (!this.#getGiveawayId()) {
  7954. return false;
  7955. }
  7956. const userId = $('meta[name="user-id"]').attr('content');
  7957. if (!userId) {
  7958. logStatus.error(i18n('getFailed', i18n('userId')));
  7959. return false;
  7960. }
  7961. this.userId = userId;
  7962. this.initialized = true;
  7963. logStatus.success();
  7964. return true;
  7965. } catch (error) {
  7966. throwError(error, 'Givekey.init');
  7967. return false;
  7968. }
  7969. }
  7970. async classifyTask(action) {
  7971. try {
  7972. const logStatus = scripts_echoLog({
  7973. text: i18n('getTasksInfo')
  7974. });
  7975. if (action === 'undo') {
  7976. this.socialTasks = GM_getValue(`gkTasks-${this.giveawayId}`)?.tasks || JSON.parse(Givekey_defaultTasks);
  7977. }
  7978. const tasks = $('.card-body:has("button") .row');
  7979. for (const task of tasks) {
  7980. const taskEle = $(task);
  7981. const isSuccess = /Complete/i.test(taskEle.find('button').text().trim());
  7982. if (isSuccess && action !== 'undo') {
  7983. continue;
  7984. }
  7985. const checkButton = taskEle.find('#task_check');
  7986. const taskId = checkButton.attr('data-id');
  7987. if (taskId) {
  7988. this.tasks.push(taskId);
  7989. }
  7990. if (action === 'verify') {
  7991. continue;
  7992. }
  7993. let href = taskEle.find('a').attr('href') || null;
  7994. const text = taskEle.find('a').text().trim();
  7995. const icon = taskEle.find('i');
  7996. if (!href || !text) {
  7997. continue;
  7998. }
  7999. if (/^https?:\/\/givekey\.ru\/giveaway\/[\d]+\/execution_task/.test(href)) {
  8000. href = await getRedirectLink(href);
  8001. }
  8002. if (!href) {
  8003. continue;
  8004. }
  8005. if (/^https?:\/\/vk\.com\//.test(href)) {
  8006. this.socialTasks.vk.nameLinks.push(href);
  8007. if (action === 'do' && !isSuccess) {
  8008. this.undoneTasks.vk.nameLinks.push(href);
  8009. }
  8010. } else if (/^https?:\/\/steamcommunity\.com\/groups/.test(href)) {
  8011. this.socialTasks.steam.groupLinks.push(href);
  8012. if (action === 'do' && !isSuccess) {
  8013. this.undoneTasks.steam.groupLinks.push(href);
  8014. }
  8015. } else if (/^https?:\/\/store\.steampowered\.com\/app\//.test(href)) {
  8016. this.socialTasks.steam.wishlistLinks.push(href);
  8017. if (action === 'do' && !isSuccess) {
  8018. this.undoneTasks.steam.wishlistLinks.push(href);
  8019. }
  8020. } else if (/Subscribe/gi.test(text) && icon.hasClass('fa-steam-square')) {
  8021. if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(href)) {
  8022. this.socialTasks.steam.curatorLinks.push(href);
  8023. if (action === 'do' && !isSuccess) {
  8024. this.undoneTasks.steam.curatorLinks.push(href);
  8025. }
  8026. } else {
  8027. this.socialTasks.steam.curatorLikeLinks.push(href);
  8028. if (action === 'do' && !isSuccess) {
  8029. this.undoneTasks.steam.curatorLikeLinks.push(href);
  8030. }
  8031. }
  8032. } else if (/^https?:\/\/twitter\.com\//.test(href) && /Subscribe/gi.test(text)) {
  8033. this.socialTasks.twitter.userLinks.push(href);
  8034. if (action === 'do' && !isSuccess) {
  8035. this.undoneTasks.twitter.userLinks.push(href);
  8036. }
  8037. } else if (icon.hasClass('fa-discord') || /^https?:\/\/discord\.com\/invite\//.test(href)) {
  8038. this.socialTasks.discord.serverLinks.push(href);
  8039. if (action === 'do' && !isSuccess) {
  8040. this.undoneTasks.discord.serverLinks.push(href);
  8041. }
  8042. } else {
  8043. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${text}(${href})`);
  8044. }
  8045. }
  8046. logStatus.success();
  8047. this.tasks = unique(this.tasks);
  8048. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8049. this.socialTasks = this.uniqueTasks(this.socialTasks);
  8050. if (window.DEBUG) {
  8051. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8052. }
  8053. GM_setValue(`gkTasks-${this.giveawayId}`, {
  8054. tasks: this.socialTasks,
  8055. time: new Date().getTime()
  8056. });
  8057. return true;
  8058. } catch (error) {
  8059. throwError(error, 'Givekey.classifyTask');
  8060. return false;
  8061. }
  8062. }
  8063. async verifyTask() {
  8064. try {
  8065. if (!this.initialized && !this.init()) {
  8066. return false;
  8067. }
  8068. if (this.tasks.length === 0 && !await this.classifyTask('verify')) {
  8069. return false;
  8070. }
  8071. scripts_echoLog({}).warning(i18n('giveKeyNoticeBefore'));
  8072. const taskLength = this.tasks.length;
  8073. for (let i = 0; i < taskLength; i++) {
  8074. await this.#verify(this.tasks[i]);
  8075. if (i < taskLength - 1) {
  8076. await delay(15e3);
  8077. }
  8078. }
  8079. scripts_echoLog({}).success(i18n('allTasksComplete'));
  8080. scripts_echoLog({
  8081. html: `<li><font class="warning">${i18n('giveKeyNoticeAfter')}</font></li>`
  8082. });
  8083. return true;
  8084. } catch (error) {
  8085. throwError(error, 'Givekey.verifyTask');
  8086. return false;
  8087. }
  8088. }
  8089. async #verify(task) {
  8090. try {
  8091. const logStatus = scripts_echoLog({
  8092. html: `<li>${i18n('verifyingTask')}${task}...<font></font></li>`
  8093. });
  8094. return await new Promise(resolve => {
  8095. $.ajax({
  8096. url: 'https://givekey.ru/giveaway/task',
  8097. method: 'POST',
  8098. data: `id=${task}&user_id=${this.userId}`,
  8099. dataType: 'json',
  8100. headers: {
  8101. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  8102. },
  8103. success: data => {
  8104. if (data.btn) {
  8105. $(`button[data-id=${this.userId}]`).html(data.btn);
  8106. }
  8107. if (data.status === 'ok') {
  8108. $(`.task_check_${data.id}`).html(`<button class="btn btn-success mb-2 btn-block" disabled>${data.btn}</button>`);
  8109. logStatus.success();
  8110. resolve(true);
  8111. } else if (data.status === 'end') {
  8112. logStatus.success();
  8113. scripts_echoLog({}).success(data.key);
  8114. resolve(true);
  8115. } else {
  8116. logStatus.error(`Error:${data.msg}`);
  8117. resolve(false);
  8118. }
  8119. },
  8120. error: xhr => {
  8121. logStatus.error(`Error:${xhr.statusText}(${xhr.status})`);
  8122. resolve(false);
  8123. }
  8124. });
  8125. });
  8126. } catch (error) {
  8127. throwError(error, 'Givekey.verify');
  8128. return false;
  8129. }
  8130. }
  8131. #getGiveawayId() {
  8132. try {
  8133. const giveawayId = window.location.href.match(/giveaway\/([\d]+)/)?.[1];
  8134. if (giveawayId) {
  8135. this.giveawayId = giveawayId;
  8136. return true;
  8137. }
  8138. scripts_echoLog({
  8139. text: i18n('getFailed', 'GiveawayId')
  8140. });
  8141. return false;
  8142. } catch (error) {
  8143. throwError(error, 'Givekey.getGiveawayId');
  8144. return false;
  8145. }
  8146. }
  8147. async #checkLeftKey() {
  8148. try {
  8149. if (!globalOptions.other.checkLeftKey) {
  8150. return true;
  8151. }
  8152. if (!$('#keys_count').text()) {
  8153. await external_Swal_default().fire({
  8154. icon: 'warning',
  8155. title: i18n('notice'),
  8156. text: i18n('noKeysLeft'),
  8157. confirmButtonText: i18n('confirm'),
  8158. cancelButtonText: i18n('cancel'),
  8159. showCancelButton: true
  8160. }).then(({
  8161. value
  8162. }) => {
  8163. if (value) {
  8164. window.close();
  8165. }
  8166. });
  8167. }
  8168. return true;
  8169. } catch (error) {
  8170. throwError(error, 'Givekey.checkLeftKey');
  8171. return false;
  8172. }
  8173. }
  8174. }
  8175. const website_Givekey = Givekey;
  8176. class GiveeClub extends GiveawaySu {
  8177. name = 'GiveeClub';
  8178. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  8179. static test() {
  8180. return /^https?:\/\/givee\.club\/.*?\/event\/[\d]+/.test(window.location.href);
  8181. }
  8182. async after() {
  8183. try {
  8184. if (!this.#checkLogin()) {
  8185. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8186. }
  8187. if (!await this.#checkLeftKey()) {
  8188. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  8189. }
  8190. } catch (error) {
  8191. throwError(error, 'GiveeClub.after');
  8192. }
  8193. }
  8194. init() {
  8195. try {
  8196. const logStatus = scripts_echoLog({
  8197. text: i18n('initing')
  8198. });
  8199. if (!this.#checkLogin()) {
  8200. logStatus.warning(i18n('needLogin'));
  8201. return false;
  8202. }
  8203. if (!this.#getGiveawayId()) {
  8204. return false;
  8205. }
  8206. this.initialized = true;
  8207. logStatus.success();
  8208. return true;
  8209. } catch (error) {
  8210. throwError(error, 'GiveeClub.init');
  8211. return false;
  8212. }
  8213. }
  8214. async classifyTask(action) {
  8215. try {
  8216. const logStatus = scripts_echoLog({
  8217. text: i18n('getTasksInfo')
  8218. });
  8219. if (action === 'undo') {
  8220. this.socialTasks = GM_getValue(`gcTasks-${this.giveawayId}`)?.tasks || Giveawaysu_defaultTasks;
  8221. return true;
  8222. }
  8223. const pro = [];
  8224. const tasks = $('.event-actions tr');
  8225. for (const task of tasks) {
  8226. pro.push(new Promise(resolve => {
  8227. const taskDes = $(task).find('.event-action-label a');
  8228. const taskIcon = $(task).find('.event-action-icon i').attr('class') || '';
  8229. const taskName = taskDes.text().trim();
  8230. const taskType = $(task).find('button[data-type]')?.attr('data-type');
  8231. const taskFinished = $(task).find('.event-action-buttons .btn-success')?.length;
  8232. if (taskIcon.includes('ban') || /AdBlock/i.test(taskName) || taskIcon.includes('envelope') || taskFinished) {
  8233. return resolve(true);
  8234. }
  8235. getRedirectLink(taskDes.attr('href')).then(taskLink => {
  8236. if (!taskLink) {
  8237. return resolve(false);
  8238. }
  8239. if (taskType === 'steam.group.join' && /^https?:\/\/steamcommunity\.com\/groups/.test(taskLink)) {
  8240. this.undoneTasks.steam.groupLinks.push(taskLink);
  8241. } else if (/like.*announcement/gi.test(taskName)) {
  8242. this.undoneTasks.steam.announcementLinks.push(taskLink);
  8243. } else if (taskType === 'steam.game.wishlist' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8244. this.undoneTasks.steam.wishlistLinks.push(taskLink);
  8245. } else if (taskType === 'steam.game.wishlist' && taskDes.attr('data-steam-wishlist-appid')) {
  8246. this.undoneTasks.steam.wishlistLinks.push(`https://store.steampowered.com/app/${taskDes.attr('data-steam-wishlist-appid')}`);
  8247. } else if (taskType === 'steam.game.follow' && /^https?:\/\/store\.steampowered\.com\/app\//.test(taskLink)) {
  8248. this.undoneTasks.steam.followLinks.push(taskLink);
  8249. } else if (/^https?:\/\/store\.steampowered\.com\/curator\//.test(taskLink)) {
  8250. this.undoneTasks.steam.curatorLinks.push(taskLink);
  8251. } else if (taskIcon.includes('steam') && /follow|subscribe/gim.test(taskName)) {
  8252. this.undoneTasks.steam.curatorLikeLinks.push(taskLink);
  8253. } else if (/subscribe.*steam.*forum/gim.test(taskName)) {
  8254. this.undoneTasks.steam.forumLinks.push(taskLink);
  8255. } else if (taskIcon.includes('discord')) {
  8256. this.undoneTasks.discord.serverLinks.push(taskLink);
  8257. } else if (taskIcon.includes('instagram')) {
  8258. this.undoneTasks.instagram.userLinks.push(taskLink);
  8259. } else if (taskIcon.includes('twitch')) {
  8260. this.undoneTasks.twitch.channelLinks.push(taskLink);
  8261. } else if (taskIcon.includes('reddit')) {
  8262. this.undoneTasks.reddit.redditLinks.push(taskLink);
  8263. } else if (/watch.*art/gim.test(taskName)) {
  8264. this.undoneTasks.steam.workshopVoteLinks.push(taskLink);
  8265. } else if (/subscribe.*youtube.*channel/gim.test(taskName)) {
  8266. this.undoneTasks.youtube.channelLinks.push(taskLink);
  8267. } else if (/(watch|like).*youtube.*video/gim.test(taskName) || (taskIcon.includes('youtube') || taskIcon.includes('thumbs-up')) && /(watch|like).*video/gim.test(taskName)) {
  8268. this.undoneTasks.youtube.likeLinks.push(taskLink);
  8269. } else if (taskIcon.includes('vk') || /join.*vk.*group/gim.test(taskName)) {
  8270. this.undoneTasks.vk.nameLinks.push(taskLink);
  8271. } else if (taskIcon.includes('twitter')) {
  8272. if (/https?:\/\/twitter\.com\/[^/]+\/?$/gim.test(taskLink)) {
  8273. this.undoneTasks.twitter.userLinks.push(taskLink);
  8274. } else if (/https?:\/\/twitter\.com\/[^/]+?\/status\/[\d]+/gim.test(taskLink)) {
  8275. this.undoneTasks.twitter.retweetLinks.push(taskLink);
  8276. }
  8277. } else {
  8278. if (/(on twitter)|(Follow.*on.*Facebook)/gim.test(taskName)) {} else {
  8279. if (/follow.*button/gim.test(taskName)) {
  8280. this.undoneTasks.steam.followLinks.push(taskLink);
  8281. }
  8282. }
  8283. }
  8284. resolve(true);
  8285. }).catch(error => {
  8286. throwError(error, 'GiveeClub.classifyTask->getRedirectLink');
  8287. return false;
  8288. });
  8289. }));
  8290. }
  8291. await Promise.all(pro);
  8292. logStatus.success();
  8293. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8294. this.socialTasks = this.undoneTasks;
  8295. if (window.DEBUG) {
  8296. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8297. }
  8298. GM_setValue(`gcTasks-${this.giveawayId}`, {
  8299. tasks: this.socialTasks,
  8300. time: new Date().getTime()
  8301. });
  8302. return true;
  8303. } catch (error) {
  8304. throwError(error, 'GiveeClub.classifyTask');
  8305. return false;
  8306. }
  8307. }
  8308. async verifyTask() {
  8309. try {
  8310. const logStatus = scripts_echoLog({
  8311. text: i18n('giveeClubVerifyNotice')
  8312. });
  8313. const taskButtons = $('.event-actions tr button').has('i.glyphicon-refresh').not('[data-type="user.adblock"]');
  8314. for (const button of taskButtons) {
  8315. button.click();
  8316. if ($(button).attr('data-type') !== 'steam.game.wishlist') {
  8317. await delay(1e3);
  8318. }
  8319. }
  8320. logStatus.warning(i18n('giveeClubVerifyFinished'));
  8321. return true;
  8322. } catch (error) {
  8323. throwError(error, 'Givekey.verifyTask');
  8324. return false;
  8325. }
  8326. }
  8327. #checkLogin() {
  8328. try {
  8329. if (!globalOptions.other.checkLogin) {
  8330. return true;
  8331. }
  8332. if ($('a[href*="/account/auth"]').length > 0) {
  8333. window.open($('a[href*="/account/auth"]').attr('href'), '_self');
  8334. }
  8335. return true;
  8336. } catch (error) {
  8337. throwError(error, 'GiveeClub.checkLogin');
  8338. return false;
  8339. }
  8340. }
  8341. #getGiveawayId() {
  8342. const giveawayId = window.location.href.match(/\/event\/([\d]+)/)?.[1];
  8343. if (giveawayId) {
  8344. this.giveawayId = giveawayId;
  8345. return true;
  8346. }
  8347. scripts_echoLog({
  8348. text: i18n('getFailed', 'GiveawayId')
  8349. });
  8350. return false;
  8351. }
  8352. async #checkLeftKey() {
  8353. try {
  8354. if (!globalOptions.other.checkLeftKey) {
  8355. return true;
  8356. }
  8357. if ($('.event-ended').length > 0 && $('.event-winner').length === 0) {
  8358. await external_Swal_default().fire({
  8359. icon: 'warning',
  8360. title: i18n('notice'),
  8361. text: i18n('giveawayEnded'),
  8362. confirmButtonText: i18n('confirm'),
  8363. cancelButtonText: i18n('cancel'),
  8364. showCancelButton: true
  8365. }).then(({
  8366. value
  8367. }) => {
  8368. if (value) {
  8369. window.close();
  8370. }
  8371. });
  8372. }
  8373. return true;
  8374. } catch (error) {
  8375. throwError(error, 'Giveawaysu.checkLeftKey');
  8376. return false;
  8377. }
  8378. }
  8379. }
  8380. const website_GiveeClub = GiveeClub;
  8381. const defaultOptions = {
  8382. maxPoint: '99999999'
  8383. };
  8384. class OpiumPulses {
  8385. name = 'OpiumPulses';
  8386. options = {
  8387. ...defaultOptions,
  8388. ...GM_getValue('OpiumPulsesOptions')
  8389. };
  8390. maxPoints = 99999999;
  8391. myPoints = 0;
  8392. buttons = [ 'doFreeTask', 'doPointTask' ];
  8393. static test() {
  8394. return window.location.host === 'www.opiumpulses.com';
  8395. }
  8396. async after() {
  8397. try {
  8398. if (!this.#checkLogin()) {
  8399. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  8400. }
  8401. this.maxPoints = parseInt(this.options.maxPoint, 10);
  8402. } catch (error) {
  8403. throwError(error, 'OpiumPulses.after');
  8404. }
  8405. }
  8406. async doFreeTask() {
  8407. try {
  8408. this.#toggleTask('FREE');
  8409. } catch (error) {
  8410. throwError(error, 'OpiumPulses.doFreeTask');
  8411. }
  8412. }
  8413. async doPointTask() {
  8414. try {
  8415. this.myPoints = parseInt($('.page-header__nav-func-user-nav-items.points-items').text().match(/[\d]+/gim)?.[0] || '0', 10);
  8416. this.#toggleTask('points');
  8417. } catch (error) {
  8418. throwError(error, 'OpiumPulses.doPointTask');
  8419. }
  8420. }
  8421. async #toggleTask(type) {
  8422. try {
  8423. const items = $(`.giveaways-page-item:contains('${type}'):not(:contains('ENTERED'))`);
  8424. for (const item of items) {
  8425. const needPoints = parseInt($(item).find('.giveaways-page-item-header-points').text().match(/[\d]+/gim)?.[0] || '999999', 10);
  8426. const name = $(item).find('.giveaways-page-item-footer-name').text().trim();
  8427. if (type === 'points' && needPoints > this.myPoints) {
  8428. scripts_echoLog({}).warning(`${i18n('noPoints')}: ${name}`);
  8429. } else if (type === 'points' && !needPoints) {
  8430. scripts_echoLog({}).warning(`${i18n('getNeedPointsFailed')}: ${name}`);
  8431. } else if (!(type === 'points' && needPoints > this.maxPoints)) {
  8432. const logStatus = scripts_echoLog({
  8433. text: `${i18n('joiningLottery')}<a href="${$(item).find('a.giveaways-page-item-img-btn-more').attr('href')}" target="_blank">${name}</a>...`
  8434. });
  8435. const aElement = $(item).find('a.giveaways-page-item-img-btn-enter:contains(\'enter\')');
  8436. if (aElement?.attr('onclick')?.includes('checkUser')) {
  8437. const giveawayId = aElement.attr('onclick')?.match(/[\d]+/)?.[0];
  8438. if (giveawayId) {
  8439. checkUser(giveawayId);
  8440. }
  8441. }
  8442. if (!aElement.attr('href')) {
  8443. logStatus.error('Error: No "href".');
  8444. continue;
  8445. }
  8446. const {
  8447. result,
  8448. statusText,
  8449. status,
  8450. data
  8451. } = await tools_httpRequest({
  8452. url: aElement.attr('href'),
  8453. method: 'GET'
  8454. });
  8455. if (result === 'Success') {
  8456. const {
  8457. result: result0,
  8458. statusText: statusText0,
  8459. status: status0,
  8460. data: data0
  8461. } = await tools_httpRequest({
  8462. url: data?.finalUrl,
  8463. method: 'GET'
  8464. });
  8465. if (data0?.responseText && /You've entered this giveaway/gim.test(data0.responseText)) {
  8466. logStatus.success();
  8467. const points = data0.responseText.match(/Points:[\s]*?([\d]+)/)?.[1];
  8468. if (type === 'points' && points) {
  8469. this.myPoints = parseInt(points, 10);
  8470. }
  8471. } else if (data0?.responseText && /You're not eligible to enter/gim.test(data0.responseText)) {
  8472. logStatus.error('You\'re not eligible to enter');
  8473. } else {
  8474. logStatus.error(`${result0}:${statusText0}(${status0})`);
  8475. }
  8476. } else {
  8477. logStatus.error(`${result}:${statusText}(${status})`);
  8478. }
  8479. }
  8480. }
  8481. scripts_echoLog({
  8482. text: '-----END-----'
  8483. });
  8484. } catch (error) {
  8485. throwError(error, 'OpiumPulses.toggleTask');
  8486. }
  8487. }
  8488. init() {
  8489. return true;
  8490. }
  8491. classifyTask() {
  8492. return true;
  8493. }
  8494. #checkLogin() {
  8495. try {
  8496. if (!globalOptions.other.checkLogin) {
  8497. return true;
  8498. }
  8499. if ($('a[href*="/site/login"]').length > 1) {
  8500. window.open('/site/login', '_self');
  8501. }
  8502. return true;
  8503. } catch (error) {
  8504. throwError(error, 'OpiumPulses.checkLogin');
  8505. return false;
  8506. }
  8507. }
  8508. }
  8509. const website_OpiumPulses = OpiumPulses;
  8510. const external_dayjs_namespaceObject = dayjs;
  8511. var external_dayjs_default = __webpack_require__.n(external_dayjs_namespaceObject);
  8512. const leftKeyChecker = {
  8513. async classify(link) {
  8514. try {
  8515. if (/^https?:\/\/giveaway\.su\/giveaway\/view\/[\d]+/.test(link)) {
  8516. return await this.giveawaySu(link);
  8517. }
  8518. if (/^https?:\/\/givee\.club\/[\w]+?\/event\/[\d]+/.test(link)) {
  8519. return await this.giveeClub(link);
  8520. }
  8521. if (/^https?:\/\/gleam\.io\/.+?\/.+/.test(link)) {
  8522. return await this.gleam(link);
  8523. }
  8524. if (/^https?:\/\/www\.indiedb\.com\/giveaways\/.+/.test(link)) {
  8525. return await this.indieDb(link);
  8526. }
  8527. if (/^https?:\/\/key-hub\.eu\/giveaway\/[\d]+/.test(link)) {
  8528. return await this.keyhub(link);
  8529. }
  8530. if (/^https?:\/\/opquests\.com\/quests\/[\d]+/.test(link)) {
  8531. return await this.opquests(link);
  8532. }
  8533. if (/^https?:\/\/itch\.io\/s\/[\d]+?\/.*/.test(link)) {
  8534. return await this.itch(link);
  8535. }
  8536. return false;
  8537. } catch (error) {
  8538. throwError(error, 'leftKeyChecker.classify');
  8539. return false;
  8540. }
  8541. },
  8542. async giveawaySu(link) {
  8543. try {
  8544. const {
  8545. result,
  8546. data
  8547. } = await tools_httpRequest({
  8548. url: link,
  8549. method: 'GET'
  8550. });
  8551. if (result === 'Success' && data?.status === 200) {
  8552. if (data.responseText.includes('class="steam-login"')) {
  8553. return false;
  8554. }
  8555. if (data.responseText.includes('class="giveaway-ended"')) {
  8556. return 'Ended';
  8557. }
  8558. return 'Active';
  8559. }
  8560. return false;
  8561. } catch (error) {
  8562. throwError(error, 'leftKeyChecker.giveawaySu');
  8563. return false;
  8564. }
  8565. },
  8566. async giveeClub(link) {
  8567. try {
  8568. const {
  8569. result,
  8570. data
  8571. } = await tools_httpRequest({
  8572. url: link,
  8573. method: 'GET'
  8574. });
  8575. if (result === 'Success' && data?.status === 200) {
  8576. if (data.responseText.includes('class="event-winner"')) {
  8577. return 'Won';
  8578. }
  8579. if (data.responseText.includes('class="event-ended"')) {
  8580. return 'Ended';
  8581. }
  8582. return 'Active';
  8583. }
  8584. return false;
  8585. } catch (error) {
  8586. throwError(error, 'leftKeyChecker.giveeClub');
  8587. return false;
  8588. }
  8589. },
  8590. async gleam(link) {
  8591. try {
  8592. const {
  8593. result,
  8594. data
  8595. } = await tools_httpRequest({
  8596. url: link,
  8597. method: 'GET'
  8598. });
  8599. if (result === 'Success' && data?.status === 200) {
  8600. if (/incentives&quot;:{&quot;[\d]+?&quot;:\[&quot;.+?&quot;\]/.test(data.responseText)) {
  8601. return 'Won';
  8602. }
  8603. const campaignDiv = data.responseText.match(/<div class='popup-blocks-container'[\w\W]+?'>/)?.[0];
  8604. if (!campaignDiv) {
  8605. return false;
  8606. }
  8607. const campaignString = $(campaignDiv).attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  8608. if (!campaignString) {
  8609. return false;
  8610. }
  8611. const {
  8612. campaign
  8613. } = JSON.parse(campaignString);
  8614. if (campaign.banned) {
  8615. return 'Banned';
  8616. }
  8617. if (campaign.finished) {
  8618. return 'Ended';
  8619. }
  8620. if (campaign.paused) {
  8621. return 'Paused';
  8622. }
  8623. if (new Date().getTime() < campaign.starts_at * 1e3) {
  8624. return 'NotStart';
  8625. }
  8626. return 'Active';
  8627. }
  8628. return false;
  8629. } catch (error) {
  8630. throwError(error, 'leftKeyChecker.gleam');
  8631. return false;
  8632. }
  8633. },
  8634. async indieDb(link) {
  8635. try {
  8636. const {
  8637. result,
  8638. data
  8639. } = await tools_httpRequest({
  8640. url: link,
  8641. method: 'GET'
  8642. });
  8643. if (result === 'Success' && data?.status === 200) {
  8644. if (data.responseText.includes('Congrats you WON')) {
  8645. return 'Won';
  8646. }
  8647. if (data.responseText.includes('Giveaway is closed') || data.responseText.includes('next time')) {
  8648. return 'Ended';
  8649. }
  8650. return 'Active';
  8651. }
  8652. return false;
  8653. } catch (error) {
  8654. throwError(error, 'leftKeyChecker.indieDb');
  8655. return false;
  8656. }
  8657. },
  8658. async keyhub(link) {
  8659. try {
  8660. const {
  8661. result,
  8662. data
  8663. } = await tools_httpRequest({
  8664. url: link,
  8665. method: 'GET'
  8666. });
  8667. if (result === 'Success' && data?.status === 200) {
  8668. const keysleft = data.responseText.match(/<span id="keysleft">([\d]+?)<\/span>/)?.[1];
  8669. if (!keysleft) {
  8670. return false;
  8671. }
  8672. if (keysleft === '0') {
  8673. return 'Ended';
  8674. }
  8675. return `Active(${keysleft})`;
  8676. }
  8677. return false;
  8678. } catch (error) {
  8679. throwError(error, 'leftKeyChecker.keyhub');
  8680. return false;
  8681. }
  8682. },
  8683. async opquests(link) {
  8684. try {
  8685. const {
  8686. result,
  8687. data
  8688. } = await tools_httpRequest({
  8689. url: link,
  8690. method: 'GET'
  8691. });
  8692. if (result === 'Success' && data?.status === 200) {
  8693. const keysleft = data.responseText.match(/<div class="">[\s]*?([\d]+?)[\s]*?of/)?.[1];
  8694. if (!keysleft) {
  8695. return false;
  8696. }
  8697. if (keysleft === '0') {
  8698. return 'Ended';
  8699. }
  8700. return `Active(${keysleft})`;
  8701. } else if (data?.status === 404) {
  8702. return 'Ended';
  8703. }
  8704. return false;
  8705. } catch (error) {
  8706. throwError(error, 'leftKeyChecker.opquests');
  8707. return false;
  8708. }
  8709. },
  8710. async itch(link) {
  8711. try {
  8712. const {
  8713. result,
  8714. data
  8715. } = await tools_httpRequest({
  8716. url: link,
  8717. method: 'GET'
  8718. });
  8719. if (result === 'Success' && data?.status === 200) {
  8720. const endDate = data.responseText.match(/{"start_date":"[0-9A-Z-:]+?".*?"end_date":"([0-9A-Z-:]+?)".*?}/)?.[1];
  8721. if (!endDate) {
  8722. return false;
  8723. }
  8724. if (new Date().getTime() > new Date(endDate).getTime()) {
  8725. return 'Ended';
  8726. }
  8727. return `Active(${external_dayjs_default()(endDate).format('YYYY-MM-DD HH:mm:ss')})`;
  8728. }
  8729. return false;
  8730. } catch (error) {
  8731. throwError(error, 'leftKeyChecker.opquests');
  8732. return false;
  8733. }
  8734. }
  8735. };
  8736. const website_leftKeyChecker = leftKeyChecker;
  8737. const Keylol_defaultTasksTemplate = {
  8738. steam: {
  8739. groupLinks: [],
  8740. wishlistLinks: [],
  8741. curatorLinks: [],
  8742. curatorLikeLinks: [],
  8743. followLinks: [],
  8744. forumLinks: [],
  8745. announcementLinks: [],
  8746. workshopVoteLinks: [],
  8747. licenseLinks: []
  8748. },
  8749. discord: {
  8750. serverLinks: []
  8751. },
  8752. instagram: {
  8753. userLinks: []
  8754. },
  8755. vk: {
  8756. nameLinks: []
  8757. },
  8758. twitch: {
  8759. channelLinks: []
  8760. },
  8761. reddit: {
  8762. redditLinks: []
  8763. },
  8764. twitter: {
  8765. userLinks: [],
  8766. retweetLinks: []
  8767. },
  8768. youtube: {
  8769. channelLinks: [],
  8770. likeLinks: []
  8771. }
  8772. };
  8773. const Keylol_defaultTasks = JSON.stringify(Keylol_defaultTasksTemplate);
  8774. class Keylol extends website_Website {
  8775. name = 'Keylol';
  8776. socialTasks = JSON.parse(Keylol_defaultTasks);
  8777. undoneTasks = JSON.parse(Keylol_defaultTasks);
  8778. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect' ];
  8779. static test() {
  8780. 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'));
  8781. }
  8782. init() {
  8783. return true;
  8784. }
  8785. after() {
  8786. try {
  8787. const selector = this.name === 'Keylol' ? '#postlist>div[id^="post_"]:first' : 'div.container';
  8788. const mainPost = $(selector);
  8789. const discordLinks = mainPost.find('a[href*="discord.com"]:visible');
  8790. const redditLinks = mainPost.find('a[href*="reddit.com"]:visible');
  8791. const insLinks = mainPost.find('a[href*="instagram.com"]:visible');
  8792. const twitterLinks = mainPost.find('a[href*="twitter.com"]:visible,a[href*="x.com"]:visible');
  8793. const twitchLinks = mainPost.find('a[href*="twitch.tv"]:visible');
  8794. const vkLinks = mainPost.find('a[href*="vk.com"]:visible');
  8795. const steamStoreLinks = mainPost.find('a[href*="store.steampowered.com"]:visible');
  8796. const steamCommunityLinks = mainPost.find('a[href*="steamcommunity.com"]:visible');
  8797. const ytbLinks = mainPost.find('a[href*="youtube.com"]:visible');
  8798. if (discordLinks.length > 0) {
  8799. for (const discordLink of discordLinks) {
  8800. const link = $(discordLink).attr('href');
  8801. if (!(link && /^https?:\/\/discord\.com\/invite\/.+/.test(link))) {
  8802. continue;
  8803. }
  8804. this.#addBtn(discordLink, 'discord', 'serverLinks', link);
  8805. }
  8806. }
  8807. if (redditLinks.length > 0) {
  8808. for (const redditLink of redditLinks) {
  8809. const link = $(redditLink).attr('href');
  8810. if (!(link && /^https?:\/\/www\.reddit\.com\/(r|user)\/.+/.test(link))) {
  8811. continue;
  8812. }
  8813. this.#addBtn(redditLink, 'reddit', 'redditLinks', link);
  8814. }
  8815. }
  8816. if (insLinks.length > 0) {
  8817. for (const insLink of insLinks) {
  8818. const link = $(insLink).attr('href');
  8819. if (!(link && /^https:\/\/www\.instagram\.com\/.+/.test(link))) {
  8820. continue;
  8821. }
  8822. this.#addBtn(insLink, 'instagram', 'userLinks', link);
  8823. }
  8824. }
  8825. if (twitterLinks.length > 0) {
  8826. for (const twitterLink of twitterLinks) {
  8827. const link = $(twitterLink).attr('href');
  8828. if (!(link && /^https:\/\/twitter\.com\/.+/.test(link))) {
  8829. continue;
  8830. }
  8831. if (/https:\/\/twitter\.com\/.*?\/status\/[\d]+/.test(link)) {
  8832. this.#addBtn(twitterLink, 'twitter', 'retweetLinks', link);
  8833. } else {
  8834. this.#addBtn(twitterLink, 'twitter', 'userLinks', link);
  8835. }
  8836. }
  8837. }
  8838. if (twitchLinks.length > 0) {
  8839. for (const twitchLink of twitchLinks) {
  8840. const link = $(twitchLink).attr('href');
  8841. if (!(link && /^https:\/\/(www\.)?twitch\.tv\/.+/.test(link))) {
  8842. continue;
  8843. }
  8844. this.#addBtn(twitchLink, 'twitch', 'channelLinks', link);
  8845. }
  8846. }
  8847. if (vkLinks.length > 0) {
  8848. for (const vkLink of vkLinks) {
  8849. const link = $(vkLink).attr('href');
  8850. if (!(link && /^https:\/\/vk\.com\/.+/.test(link))) {
  8851. continue;
  8852. }
  8853. this.#addBtn(vkLink, 'vk', 'nameLinks', link);
  8854. }
  8855. }
  8856. if (steamStoreLinks.length > 0) {
  8857. for (const steamStoreLink of steamStoreLinks) {
  8858. const link = $(steamStoreLink).attr('href');
  8859. if (!link) {
  8860. continue;
  8861. }
  8862. if (/curator\/[\d]+/.test(link)) {
  8863. this.#addBtn(steamStoreLink, 'steam', 'curatorLinks', link);
  8864. } else if (/(publisher|developer|franchise)\/.+/.test(link)) {
  8865. this.#addBtn(steamStoreLink, 'steam', 'curatorLikeLinks', link);
  8866. } else if (/news(hub)?\/app\/[\d]+\/view\/[\d]+/.test(link)) {
  8867. this.#addBtn(steamStoreLink, 'steam', 'announcementLinks', link);
  8868. } else if (/app\/[\d]+/.test(link)) {
  8869. this.#addBtn(steamStoreLink, 'steam', 'followLinks', link);
  8870. this.#addBtn(steamStoreLink, 'steam', 'wishlistLinks', link);
  8871. }
  8872. }
  8873. }
  8874. if (steamCommunityLinks.length > 0) {
  8875. for (const steamCommunityLink of steamCommunityLinks) {
  8876. const link = $(steamCommunityLink).attr('href');
  8877. if (!link) {
  8878. continue;
  8879. }
  8880. if (/groups\/.+/.test(link)) {
  8881. this.#addBtn(steamCommunityLink, 'steam', 'groupLinks', link);
  8882. } else if (/announcements\/detail\/[\d]+/.test(link)) {
  8883. this.#addBtn(steamCommunityLink, 'steam', 'announcementLinks', link);
  8884. }
  8885. }
  8886. }
  8887. if (ytbLinks.length > 0) {
  8888. for (const ytbLink of ytbLinks) {
  8889. const link = $(ytbLink).attr('href');
  8890. if (!link) {
  8891. continue;
  8892. }
  8893. this.#addBtn(ytbLink, 'youtube', 'channelLinks', link);
  8894. this.#addBtn(ytbLink, 'youtube', 'likeLinks', link);
  8895. }
  8896. }
  8897. 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');
  8898. if (giveawayLinks.length > 0) {
  8899. for (const giveawayLink of giveawayLinks) {
  8900. const link = $(giveawayLink).attr('href');
  8901. if (!link) {
  8902. continue;
  8903. }
  8904. website_leftKeyChecker.classify(link).then(status => {
  8905. if (!status) {
  8906. return;
  8907. }
  8908. if (/^Active/.test(status)) {
  8909. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status active" title="${i18n('Active')}">${status}</font>`);
  8910. return;
  8911. }
  8912. $(`a[href="${link}"]`).after(`<font class="auto-task-giveaway-status not-active" title="${i18n(status)}">${status}</font>`);
  8913. }).catch(error => {
  8914. throwError(error, 'keylol.after -> leftKeyChecker');
  8915. });
  8916. }
  8917. }
  8918. if (this.name === 'Keylol') {
  8919. const asfLinks = mainPost.find('a[href^="#asf"]:visible');
  8920. if (asfLinks.length > 0) {
  8921. for (const asfLink of asfLinks) {
  8922. const link = $(asfLink).attr('href');
  8923. if (!link) {
  8924. continue;
  8925. }
  8926. this.#addBtn($(`a[href="${link}"]`).after('<span style="color: #ccc; margin: 0 -5px 0 5px"> | </span>').next()[0], 'steam', 'licenseLinks', `appid-${link.replace('#asf', '')}`);
  8927. }
  8928. }
  8929. const subLinks = mainPost.find('a[href*="steamdb.info/sub/"]:visible');
  8930. if (subLinks.length > 0) {
  8931. for (const subLink of subLinks) {
  8932. const link = $(subLink).attr('href');
  8933. if (!link) {
  8934. continue;
  8935. }
  8936. const subid = link.match(/^https:\/\/steamdb\.info\/sub\/([\d]+)/)?.[1];
  8937. if (!subid) {
  8938. continue;
  8939. }
  8940. this.#addBtn(subLink, 'steam', 'licenseLinks', `subid-${subid}`);
  8941. }
  8942. }
  8943. const asfLinks2 = mainPost.find('.blockcode:contains("addlicense"):visible');
  8944. if (asfLinks2.length > 0) {
  8945. for (const asfLink of asfLinks2) {
  8946. const appid = [ ...asfLink.innerText.matchAll(/a(pp)?\/([\d]+)/g) ].map(matched => matched?.[2]).filter(id => id) || [];
  8947. if (appid.length > 0) {
  8948. this.#addBtn($(asfLink).children('em')[0], 'steam', 'licenseLinks', `appid-${appid.join(',')}`);
  8949. }
  8950. const subid = asfLink.innerText.match(/[\d]+/g)?.filter(matched => !appid.includes(matched));
  8951. if (!subid || subid.length === 0) {
  8952. continue;
  8953. }
  8954. this.#addBtn($(asfLink).children('em')[0], 'steam', 'licenseLinks', `subid-${subid.join(',')}`);
  8955. }
  8956. }
  8957. }
  8958. } catch (error) {
  8959. throwError(error, 'keylol.after');
  8960. }
  8961. }
  8962. classifyTask(action) {
  8963. try {
  8964. this.socialTasks = JSON.parse(Keylol_defaultTasks);
  8965. this.undoneTasks = JSON.parse(Keylol_defaultTasks);
  8966. const selectedBtns = $('.auto-task-keylol[selected="selected"]:visible');
  8967. for (const btn of selectedBtns) {
  8968. const button = $(btn);
  8969. const social = button.attr('data-social');
  8970. const type = button.attr('data-type');
  8971. const link = button.attr('data-link');
  8972. if (!(social && type && link)) {
  8973. continue;
  8974. }
  8975. if (action === 'do') {
  8976. this.undoneTasks[social][type].push(link);
  8977. }
  8978. if (action === 'undo') {
  8979. this.socialTasks[social][type].push(link);
  8980. }
  8981. }
  8982. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  8983. this.socialTasks = this.uniqueTasks(this.socialTasks);
  8984. if (window.DEBUG) {
  8985. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  8986. }
  8987. return true;
  8988. } catch (error) {
  8989. throwError(error, 'Keylol.classifyTask');
  8990. return false;
  8991. }
  8992. }
  8993. selectAll() {
  8994. try {
  8995. $('.auto-task-keylol:visible').attr('selected', 'selected');
  8996. } catch (error) {
  8997. throwError(error, 'Keylol.selectAll');
  8998. }
  8999. }
  9000. selectNone() {
  9001. try {
  9002. $('.auto-task-keylol:visible').removeAttr('selected');
  9003. } catch (error) {
  9004. throwError(error, 'Keylol.selectNone');
  9005. }
  9006. }
  9007. invertSelect() {
  9008. try {
  9009. $('.auto-task-keylol:visible').each((index, element) => {
  9010. element.getAttribute('selected') ? element.removeAttribute('selected') : element.setAttribute('selected', 'selected');
  9011. });
  9012. } catch (error) {
  9013. throwError(error, 'Keylol.invertSelect');
  9014. }
  9015. }
  9016. #addBtn(before, social, linkType, link) {
  9017. try {
  9018. $(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>`);
  9019. } catch (error) {
  9020. throwError(error, 'keylol.addBtn');
  9021. }
  9022. }
  9023. }
  9024. const website_Keylol = Keylol;
  9025. const Opquests_defaultTasks = {
  9026. steam: {
  9027. groupLinks: [],
  9028. wishlistLinks: [],
  9029. followLinks: [],
  9030. curatorLikeLinks: []
  9031. }
  9032. };
  9033. class Opquests extends website_Website {
  9034. name = 'Opquests';
  9035. undoneTasks = {
  9036. ...Opquests_defaultTasks
  9037. };
  9038. buttons = [ 'doTask', 'verifyTask', 'getKey' ];
  9039. static test() {
  9040. return window.location.host === 'opquests.com';
  9041. }
  9042. async before() {
  9043. const opquestsVerifyTasks = GM_getValue('opquestsVerifyTasks') || [];
  9044. if (opquestsVerifyTasks.length > 0) {
  9045. const taskId = opquestsVerifyTasks.pop();
  9046. GM_setValue('opquestsVerifyTasks', opquestsVerifyTasks);
  9047. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9048. } else {
  9049. if (GM_getValue('opquestsVerifyTasks')) {
  9050. GM_deleteValue('opquestsVerifyTasks');
  9051. }
  9052. }
  9053. }
  9054. async after() {
  9055. try {
  9056. if (!this.#checkLogin()) {
  9057. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9058. }
  9059. } catch (error) {
  9060. throwError(error, 'Opquests.after');
  9061. }
  9062. }
  9063. init() {
  9064. try {
  9065. const logStatus = scripts_echoLog({
  9066. text: i18n('initing')
  9067. });
  9068. if ($('a[href*="/auth/redirect"]').length > 0) {
  9069. window.open('/auth/redirect', '_self');
  9070. logStatus.warning(i18n('needLogin'));
  9071. return false;
  9072. }
  9073. if (!this.#getGiveawayId()) {
  9074. return false;
  9075. }
  9076. this.initialized = true;
  9077. logStatus.success();
  9078. return true;
  9079. } catch (error) {
  9080. throwError(error, 'Opquests.init');
  9081. return false;
  9082. }
  9083. }
  9084. async classifyTask(action) {
  9085. try {
  9086. if (action === 'undo') {
  9087. scripts_echoLog({
  9088. text: i18n('cannotUndo')
  9089. });
  9090. return false;
  9091. }
  9092. const logStatus = scripts_echoLog({
  9093. text: i18n('getTasksInfo')
  9094. });
  9095. const tasks = $('.w-full:contains("Validate") .items-center');
  9096. for (const task of tasks) {
  9097. const link = $(task).find('a:contains("Open")').attr('href');
  9098. const taskDes = $(task).find('div').eq(1).text().trim();
  9099. if (!link) {
  9100. continue;
  9101. }
  9102. if (/steamcommunity\.com\/groups\//.test(link)) {
  9103. this.undoneTasks.steam.groupLinks.push(link);
  9104. } else if (/store\.steampowered\.com\/app\//.test(link)) {
  9105. if (/wishlist/gim.test(taskDes)) {
  9106. this.undoneTasks.steam.wishlistLinks.push(link);
  9107. } else if (/follow/gim.test(taskDes)) {
  9108. this.undoneTasks.steam.followLinks.push(link);
  9109. }
  9110. } else if (/store\.steampowered\.com\/(publisher|developer|curator)\//.test(link) && /follow/gim.test(taskDes)) {
  9111. this.undoneTasks.steam.curatorLikeLinks.push(link);
  9112. } else {
  9113. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskDes}(${link})`);
  9114. }
  9115. }
  9116. logStatus.success();
  9117. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9118. if (window.DEBUG) {
  9119. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9120. }
  9121. return true;
  9122. } catch (error) {
  9123. throwError(error, 'Opquests.classifyTask');
  9124. return false;
  9125. }
  9126. }
  9127. async verifyTask() {
  9128. try {
  9129. if (!this.initialized) {
  9130. this.init();
  9131. }
  9132. const tasks = $.makeArray($('div.w-full').find('.items-center').has('button.submit-loader')).map(ele => $(ele).find('input[name="task_id"]').val());
  9133. await this.#confirm();
  9134. const taskId = tasks.pop();
  9135. GM_setValue('opquestsVerifyTasks', tasks);
  9136. $(`#task_id[value="${taskId}"]`).parent().children('button[type="submit"]')[0].click();
  9137. return true;
  9138. } catch (error) {
  9139. throwError(error, 'Opquests.verifyTask');
  9140. return false;
  9141. }
  9142. }
  9143. async #confirm() {
  9144. try {
  9145. const logStatus = scripts_echoLog({
  9146. html: `<li>${i18n('confirmingTask')}...<font></font></li>`
  9147. });
  9148. const {
  9149. result,
  9150. statusText,
  9151. status,
  9152. data
  9153. } = await tools_httpRequest({
  9154. url: `https://opquests.com/quests/${this.giveawayId}?confirm=1`,
  9155. method: 'GET',
  9156. nochche: true,
  9157. headers: {
  9158. origin: 'https://opquests.com',
  9159. referer: `https://opquests.com/warning?id=${this.giveawayId}`
  9160. }
  9161. });
  9162. if (result === 'Success') {
  9163. if (data?.status === 200) {
  9164. logStatus.success();
  9165. return true;
  9166. }
  9167. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9168. return false;
  9169. }
  9170. logStatus.error(`${result}:${statusText}(${status})`);
  9171. return false;
  9172. } catch (error) {
  9173. throwError(error, 'Opquests.confirm');
  9174. return false;
  9175. }
  9176. }
  9177. async getKey(isButton) {
  9178. try {
  9179. const logStatus = scripts_echoLog({
  9180. text: i18n('gettingKey')
  9181. });
  9182. const {
  9183. result,
  9184. statusText,
  9185. status,
  9186. data
  9187. } = await tools_httpRequest({
  9188. url: 'https://opquests.com/keys',
  9189. method: 'GET'
  9190. });
  9191. if (result === 'Success') {
  9192. if (data?.responseText) {
  9193. const key = $(data?.responseText).find(`div.items-center:contains("${$('h1.font-bold').text().trim().replace(' Quest', '')}")`).find('div.font-bold').next().text();
  9194. if (!key) {
  9195. logStatus.error('Error: Key was not found');
  9196. if (isButton) {
  9197. window.open('https://opquests.com/keys', '_self');
  9198. }
  9199. return false;
  9200. }
  9201. logStatus.success();
  9202. scripts_echoLog({}).success(key);
  9203. return true;
  9204. }
  9205. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9206. return false;
  9207. }
  9208. logStatus.error(`${result}:${statusText}(${status})`);
  9209. return false;
  9210. } catch (error) {
  9211. throwError(error, 'Opquests.getGiveawayId');
  9212. return false;
  9213. }
  9214. }
  9215. #getGiveawayId() {
  9216. try {
  9217. const giveawayId = window.location.href.match(/quests\/([\d]+)/)?.[1];
  9218. if (giveawayId) {
  9219. this.giveawayId = giveawayId;
  9220. return true;
  9221. }
  9222. scripts_echoLog({}).error(i18n('getFailed', 'GiveawayId'));
  9223. return false;
  9224. } catch (error) {
  9225. throwError(error, 'Opquests.getGiveawayId');
  9226. return false;
  9227. }
  9228. }
  9229. #checkLogin() {
  9230. try {
  9231. if (!globalOptions.other.checkLogin) {
  9232. return true;
  9233. }
  9234. if ($('a[href*="/auth/redirect"]').length > 0) {
  9235. window.open('/auth/redirect', '_self');
  9236. }
  9237. return true;
  9238. } catch (error) {
  9239. throwError(error, 'Opquests.checkLogin');
  9240. return false;
  9241. }
  9242. }
  9243. }
  9244. const website_Opquests = Opquests;
  9245. const Gleam_defaultTasksTemplate = {
  9246. steam: {
  9247. groupLinks: [],
  9248. wishlistLinks: [],
  9249. followLinks: [],
  9250. curatorLinks: [],
  9251. curatorLikeLinks: []
  9252. },
  9253. twitter: {
  9254. userLinks: [],
  9255. retweetLinks: []
  9256. },
  9257. twitch: {
  9258. channelLinks: []
  9259. },
  9260. discord: {
  9261. serverLinks: []
  9262. },
  9263. youtube: {
  9264. channelLinks: []
  9265. },
  9266. extra: {
  9267. gleam: []
  9268. }
  9269. };
  9270. const Gleam_defaultTasks = JSON.stringify(Gleam_defaultTasksTemplate);
  9271. class Gleam extends website_Website {
  9272. name = 'Gleam';
  9273. undoneTasks = JSON.parse(Gleam_defaultTasks);
  9274. socialTasks = JSON.parse(Gleam_defaultTasks);
  9275. buttons = [ 'doTask', 'undoTask', 'verifyTask' ];
  9276. static test() {
  9277. return window.location.host === 'gleam.io';
  9278. }
  9279. before() {
  9280. unsafeWindow.confirm = () => {};
  9281. unsafeWindow.alert = () => {};
  9282. unsafeWindow.prompt = () => {};
  9283. }
  9284. async after() {
  9285. try {
  9286. if (window.location.search.includes('8b07d23f4bfa65f9')) {
  9287. const checkComplete = setInterval(() => {
  9288. if ($('.entry-content .entry-method i.fa-check').length > 0) {
  9289. clearInterval(checkComplete);
  9290. window.close();
  9291. }
  9292. });
  9293. for (const task of $('.entry-content .entry-method')) {
  9294. const taskInfo = $(task).find('.user-links');
  9295. const expandInfo = $(task).find('.expandable');
  9296. const aElements = expandInfo.find('a.btn,a:contains(Continue),button:contains(Continue)');
  9297. if (aElements.length > 0) {
  9298. for (const element of aElements) {
  9299. const $element = $(element);
  9300. const href = $element.attr('href');
  9301. $element.removeAttr('href')[0].click();
  9302. $element.attr('href', href);
  9303. await delay(1e3);
  9304. }
  9305. }
  9306. taskInfo[0].click();
  9307. await delay(1e3);
  9308. }
  9309. scripts_echoLog({}).warning(i18n('gleamTaskNotice'));
  9310. } else if (!await this.#checkLeftKey()) {
  9311. scripts_echoLog({}).warning(i18n('checkLeftKeyFailed'));
  9312. }
  9313. } catch (error) {
  9314. throwError(error, 'Gleam.after');
  9315. return false;
  9316. }
  9317. }
  9318. init() {
  9319. try {
  9320. const logStatus = scripts_echoLog({
  9321. text: i18n('initing')
  9322. });
  9323. if (!this.#getGiveawayId()) {
  9324. return false;
  9325. }
  9326. this.initialized = true;
  9327. logStatus.success();
  9328. return true;
  9329. } catch (error) {
  9330. throwError(error, 'Gleam.init');
  9331. return false;
  9332. }
  9333. }
  9334. async classifyTask(action) {
  9335. try {
  9336. const logStatus = scripts_echoLog({
  9337. text: i18n('getTasksInfo')
  9338. });
  9339. if (action === 'undo') {
  9340. this.socialTasks = GM_getValue(`gleamTasks-${this.giveawayId}`)?.tasks || JSON.parse(Gleam_defaultTasks);
  9341. }
  9342. const tasks = $('.entry-content .entry-method');
  9343. for (const task of tasks) {
  9344. const $task = $(task);
  9345. if (action === 'do' && $task.find('i.fa-question').length === 0) {
  9346. continue;
  9347. }
  9348. const socialIcon = $task.find('.icon-wrapper i');
  9349. const taskInfo = $task.find('.user-links');
  9350. const taskText = taskInfo.text().trim();
  9351. const expandInfo = $task.find('.expandable');
  9352. const aElements = expandInfo.find('a.btn');
  9353. if (aElements.length > 0) {
  9354. for (const element of aElements) {
  9355. const $element = $(element);
  9356. const href = $element.attr('href');
  9357. $element.removeAttr('href')[0].click();
  9358. $element.attr('href', href);
  9359. }
  9360. }
  9361. if (socialIcon.hasClass('fa-twitter') || socialIcon.hasClass('fa-x-twitter')) {
  9362. const link = $task.find('a[href^="https://twitter.com/"],a[href^="https://x.com/"]').attr('href');
  9363. if (!link) {
  9364. continue;
  9365. }
  9366. if (/follow/gi.test(taskText)) {
  9367. if (action === 'undo') {
  9368. this.socialTasks.twitter.userLinks.push(link);
  9369. }
  9370. if (action === 'do') {
  9371. this.undoneTasks.twitter.userLinks.push(link);
  9372. }
  9373. } else if (/retweet/gim.test(taskText)) {
  9374. if (action === 'undo') {
  9375. this.socialTasks.twitter.retweetLinks.push(link);
  9376. }
  9377. if (action === 'do') {
  9378. this.undoneTasks.twitter.retweetLinks.push(link);
  9379. }
  9380. }
  9381. } else if (socialIcon.hasClass('fa-twitch')) {
  9382. if (/follow/gim.test(taskText)) {
  9383. const link = $task.find('a[href^="https://twitch.tv/"]').attr('href');
  9384. if (!link) {
  9385. continue;
  9386. }
  9387. if (action === 'undo') {
  9388. this.socialTasks.twitch.channelLinks.push(link);
  9389. }
  9390. if (action === 'do') {
  9391. this.undoneTasks.twitch.channelLinks.push(link);
  9392. }
  9393. }
  9394. } else if (socialIcon.hasClass('fa-discord')) {
  9395. if (/join/gim.test(taskText)) {
  9396. let link = $task.find('a[href^="https://discord.com/invite/"]').attr('href');
  9397. if (!link) {
  9398. const ggLink = $task.find('a[href^="https://discord.gg/"]').attr('href')?.match(/discord\.gg\/([^/]+)/)?.[1];
  9399. if (!ggLink) {
  9400. continue;
  9401. }
  9402. link = `https://discord.com/invite/${ggLink}`;
  9403. }
  9404. if (action === 'undo') {
  9405. this.socialTasks.discord.serverLinks.push(link);
  9406. }
  9407. if (action === 'do') {
  9408. this.undoneTasks.discord.serverLinks.push(link);
  9409. }
  9410. }
  9411. } else if (socialIcon.hasClass('fa-external-link-square-alt')) {
  9412. continue;
  9413. } else if (socialIcon.hasClass('fa-youtube')) {
  9414. if (/subscribe/gim.test(taskText)) {
  9415. const link = $task.find('a[href^="https://www.youtube.com/channel/"]').attr('href');
  9416. if (!link) {
  9417. continue;
  9418. }
  9419. if (action === 'undo') {
  9420. this.socialTasks.youtube.channelLinks.push(link);
  9421. }
  9422. if (action === 'do') {
  9423. this.undoneTasks.youtube.channelLinks.push(link);
  9424. }
  9425. }
  9426. } else if (socialIcon.attr('class')?.includes('steam')) {
  9427. if (/join.*group/gi.test(taskText)) {
  9428. const link = $task.find('a[href^="https://steamcommunity.com/groups/"]').attr('href');
  9429. if (!link) {
  9430. continue;
  9431. }
  9432. if (action === 'undo') {
  9433. this.socialTasks.steam.groupLinks.push(link);
  9434. }
  9435. if (action === 'do') {
  9436. this.undoneTasks.steam.groupLinks.push(link);
  9437. }
  9438. } else if (/follow.*curator/gi.test(taskText)) {
  9439. const link = $task.find('a[href^="https://store.steampowered.com/curator/"]').attr('href');
  9440. if (!link) {
  9441. continue;
  9442. }
  9443. if (action === 'undo') {
  9444. this.socialTasks.steam.curatorLinks.push(link);
  9445. }
  9446. if (action === 'do') {
  9447. this.undoneTasks.steam.curatorLinks.push(link);
  9448. }
  9449. }
  9450. } else if (socialIcon.hasClass('fa-bullhorn') && /Complete/gi.test(taskText)) {
  9451. if (action !== 'do') {
  9452. continue;
  9453. }
  9454. const gleamLink = await this.#getGleamLink(taskText);
  9455. if (!gleamLink) {
  9456. continue;
  9457. }
  9458. this.undoneTasks.extra.gleam.push(gleamLink);
  9459. } 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 {
  9460. scripts_echoLog({}).warning(`${i18n('unKnownTaskType')}: ${taskText}`);
  9461. }
  9462. }
  9463. logStatus.success();
  9464. this.undoneTasks = this.uniqueTasks(this.undoneTasks);
  9465. this.socialTasks = this.uniqueTasks(this.socialTasks);
  9466. if (window.DEBUG) {
  9467. console.log('%cAuto-Task[Debug]:', 'color:blue', JSON.stringify(this));
  9468. }
  9469. GM_setValue(`gleamTasks-${this.giveawayId}`, {
  9470. tasks: this.socialTasks,
  9471. time: new Date().getTime()
  9472. });
  9473. return true;
  9474. } catch (error) {
  9475. throwError(error, 'Gleam.classifyTask');
  9476. return false;
  9477. }
  9478. }
  9479. async extraDoTask({
  9480. gleam
  9481. }) {
  9482. try {
  9483. const pro = [];
  9484. for (const link of gleam) {
  9485. pro.push(this.#doGleamTask(link));
  9486. }
  9487. return Promise.all(pro).then(() => true);
  9488. } catch (error) {
  9489. throwError(error, 'Gleam.extraDoTask');
  9490. return false;
  9491. }
  9492. }
  9493. async verifyTask() {
  9494. try {
  9495. scripts_echoLog({
  9496. text: `${i18n('verifyingTask')}...`
  9497. });
  9498. const tasks = $('.entry-content .entry-method');
  9499. unsafeWindow._OxA = '_OxA';
  9500. for (const task of tasks) {
  9501. if ($('[campaign-key="campaign.key"]').length > 0) {
  9502. return scripts_echoLog({
  9503. text: i18n('campaign')
  9504. });
  9505. }
  9506. const $task = $(task);
  9507. if ($task.find('i.fa-question').length === 0) {
  9508. continue;
  9509. }
  9510. const taskInfo = $task.find('.user-links');
  9511. taskInfo[0].click();
  9512. const aElements = $task.find('.expandable').find('a.btn');
  9513. if (aElements.length > 0) {
  9514. for (const element of aElements) {
  9515. const $element = $(element);
  9516. const href = $element.attr('href');
  9517. $element.removeAttr('href')[0].click();
  9518. $element.attr('href', href);
  9519. }
  9520. }
  9521. unsafeWindow.$hookTimer?.setSpeed(1e3);
  9522. const visitBtn = $task.find('.expandable').find('span:contains(more seconds),button:contains(more seconds)').filter(':visible');
  9523. if (visitBtn.length > 0) {
  9524. const newTab = window.open('', '_blank');
  9525. newTab?.focus();
  9526. await delay(1e3);
  9527. newTab?.close();
  9528. }
  9529. await delay(3e3);
  9530. unsafeWindow.$hookTimer?.setSpeed(1);
  9531. const expandInfo = $task.find('.expandable');
  9532. const [ input ] = expandInfo.find('input');
  9533. if (input) {
  9534. const evt = new Event('input', {
  9535. bubbles: true,
  9536. cancelable: true,
  9537. composed: true
  9538. });
  9539. const valuelimit = [ ...expandInfo.text().matchAll(/"(.+?)"/g) ].at(-1)?.[1];
  9540. input.value = valuelimit || 'vloot';
  9541. input.dispatchEvent(evt);
  9542. await delay(1e3);
  9543. }
  9544. await this.#checkSync();
  9545. const continueBtn = $task.find('.expandable').find('span:contains(Continue),button:contains(Continue)');
  9546. for (const button of continueBtn) {
  9547. button.click();
  9548. await delay(500);
  9549. await this.#checkSync();
  9550. }
  9551. }
  9552. scripts_echoLog({
  9553. text: i18n('verifiedGleamTasks')
  9554. });
  9555. } catch (error) {
  9556. throwError(error, 'Gleam.verifyTask');
  9557. return false;
  9558. }
  9559. }
  9560. async #checkSync() {
  9561. try {
  9562. return await new Promise(resolve => {
  9563. const checker = setInterval(() => {
  9564. if ($('.entry-content .entry-method i.fa-sync').length === 0) {
  9565. clearInterval(checker);
  9566. resolve(true);
  9567. }
  9568. }, 500);
  9569. });
  9570. } catch (error) {
  9571. throwError(error, 'Gleam.checkSync');
  9572. return false;
  9573. }
  9574. }
  9575. async #doGleamTask(link) {
  9576. try {
  9577. const logStatus = scripts_echoLog({
  9578. text: i18n('doingGleamTask')
  9579. });
  9580. return await new Promise(resolve => {
  9581. GM_openInTab(`${link}?8b07d23f4bfa65f9`, {
  9582. active: true,
  9583. insert: true,
  9584. setParent: true
  9585. }).onclose = () => {
  9586. logStatus.success();
  9587. resolve(true);
  9588. };
  9589. });
  9590. } catch (error) {
  9591. throwError(error, 'Gleam.doGleamTask');
  9592. return false;
  9593. }
  9594. }
  9595. #getGiveawayId() {
  9596. try {
  9597. const giveawayId = window.location.pathname;
  9598. if (giveawayId) {
  9599. this.giveawayId = giveawayId;
  9600. return true;
  9601. }
  9602. scripts_echoLog({
  9603. text: i18n('getFailed', 'GiveawayId')
  9604. });
  9605. return false;
  9606. } catch (error) {
  9607. throwError(error, 'Gleam.getGiveawayId');
  9608. return false;
  9609. }
  9610. }
  9611. async #getGleamLink(title) {
  9612. try {
  9613. const logStatus = scripts_echoLog({
  9614. text: i18n('gettingGleamLink')
  9615. });
  9616. const {
  9617. result,
  9618. statusText,
  9619. status,
  9620. data
  9621. } = await tools_httpRequest({
  9622. url: 'https://www.vloot.io/api/v1/giveaways',
  9623. method: 'GET',
  9624. responseType: 'json'
  9625. });
  9626. if (result === 'Success') {
  9627. if (data?.status === 200 && data?.response?.Success === true && data?.response?.Data) {
  9628. const {
  9629. link
  9630. } = data.response.Data.find(giveaway => title.replace(/[\s]/g, '').toLowerCase().includes(giveaway.title.replace(/[\s]/g, '').toLowerCase())) || {};
  9631. if (link) {
  9632. logStatus.success();
  9633. return link;
  9634. }
  9635. logStatus.error(`Error:${i18n('getLinkFailed')}`);
  9636. return false;
  9637. }
  9638. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  9639. return false;
  9640. }
  9641. logStatus.error(`${result}:${statusText}(${status})`);
  9642. return false;
  9643. } catch (error) {
  9644. throwError(error, 'Gleam.getGleamLink');
  9645. return false;
  9646. }
  9647. }
  9648. async #checkLeftKey() {
  9649. try {
  9650. if (!globalOptions.other.checkLeftKey) {
  9651. return true;
  9652. }
  9653. const campaignString = $('div.popup-blocks-container').attr('ng-init')?.match(/initCampaign\(([\w\W]+?)\)$/)?.[1];
  9654. if (!campaignString) {
  9655. return false;
  9656. }
  9657. const {
  9658. campaign,
  9659. incentive
  9660. } = JSON.parse(campaignString);
  9661. const controllerString = $('div.campaign.reward').attr('ng-init')?.match(/initContestant\(([\w\W]+?)\);/)?.[1];
  9662. let ownedKey = false;
  9663. if (controllerString) {
  9664. if (JSON.parse(controllerString).contestant?.claims?.incentives?.[incentive.id]?.length) {
  9665. ownedKey = true;
  9666. }
  9667. }
  9668. if (campaign.banned || campaign.finished && !ownedKey || campaign.paused || new Date().getTime() < campaign.starts_at * 1e3) {
  9669. await external_Swal_default().fire({
  9670. icon: 'warning',
  9671. title: i18n('notice'),
  9672. text: i18n('giveawayNotWork'),
  9673. confirmButtonText: i18n('confirm'),
  9674. cancelButtonText: i18n('cancel'),
  9675. showCancelButton: true
  9676. }).then(({
  9677. value
  9678. }) => {
  9679. if (value) {
  9680. window.close();
  9681. }
  9682. });
  9683. }
  9684. return true;
  9685. } catch (error) {
  9686. throwError(error, 'Gleam.checkLeftKey');
  9687. return false;
  9688. }
  9689. }
  9690. }
  9691. const website_Gleam = Gleam;
  9692. const SweepWidget_defaultOptions = {
  9693. username: '',
  9694. email: ''
  9695. };
  9696. class SweepWidget extends website_Website {
  9697. name = 'SweepWidget';
  9698. options = {
  9699. ...SweepWidget_defaultOptions,
  9700. ...GM_getValue('SweepWidgetOptions')
  9701. };
  9702. buttons = [ 'doTask' ];
  9703. static test() {
  9704. return /^https?:\/\/sweepwidget\.com\/view\/[\d]+/.test(window.location.href);
  9705. }
  9706. async after() {
  9707. try {
  9708. if (!this.#checkLogin()) {
  9709. scripts_echoLog({}).warning(i18n('checkLoginFailed'));
  9710. }
  9711. } catch (error) {
  9712. throwError(error, 'SweepWidget.after');
  9713. }
  9714. }
  9715. init() {
  9716. try {
  9717. const logStatus = scripts_echoLog({
  9718. text: i18n('initing')
  9719. });
  9720. if (!this.#checkLogin()) {
  9721. logStatus.warning(i18n('needLogin'));
  9722. return false;
  9723. }
  9724. if (!this.#getGiveawayId()) {
  9725. return false;
  9726. }
  9727. this.initialized = true;
  9728. logStatus.success();
  9729. return true;
  9730. } catch (error) {
  9731. throwError(error, 'SweepWidget.init');
  9732. return false;
  9733. }
  9734. }
  9735. classifyTask() {
  9736. return true;
  9737. }
  9738. async doTask() {
  9739. try {
  9740. if ($('#unlock_rewards_main_wrapper').length === 0) {
  9741. if ($('input[name="sw__login_name"]:visible').length > 0) {
  9742. $('input[name="sw__login_name"]').val(this.options.username);
  9743. }
  9744. if ($('input[name="sw__login_email"]:visible').length > 0) {
  9745. $('input[name="sw__login_email"]').val(this.options.email);
  9746. }
  9747. if ($('#sw_login_button:visible').length > 0) {
  9748. $('#sw_login_button')[0].click();
  9749. }
  9750. if (!await this.#checkEnter()) {
  9751. return false;
  9752. }
  9753. }
  9754. const logStatus = scripts_echoLog({
  9755. text: i18n('SweepWidgetNotice')
  9756. });
  9757. const tasks = $('#sw_inner_entry_methods_l2_wrapper>div.sw_entry');
  9758. for (const task of tasks) {
  9759. const $task = $(task);
  9760. if ($task.find('i.fa-check:visible').length > 0) {
  9761. continue;
  9762. }
  9763. const title = $task.find('.sw_text_inner');
  9764. title[0].click();
  9765. const aElement = $task.find('a.sw_link');
  9766. const link = aElement.attr('href');
  9767. aElement.attr('href', '#a').attr('target', '_self');
  9768. aElement[0]?.click();
  9769. await delay(300);
  9770. aElement.attr('href', link).attr('target', '_blank');
  9771. $task.find('input[type="text"]').val('test');
  9772. const verifyBtn = $task.find('input.sw_verify');
  9773. if (verifyBtn.prop('disabled') === true) {
  9774. title[0].click();
  9775. await delay(300);
  9776. title[0].click();
  9777. await delay(300);
  9778. }
  9779. $task.find('input.sw_verify').removeAttr('disabled')[0]?.click();
  9780. await this.#checkFinish($task);
  9781. await delay(parseInt(`${Math.random() * (3e3 - 1e3 + 1) + 1e3}`, 10));
  9782. }
  9783. logStatus.success();
  9784. return true;
  9785. } catch (error) {
  9786. throwError(error, 'SweepWidget.doTask');
  9787. return false;
  9788. }
  9789. }
  9790. #checkLogin() {
  9791. try {
  9792. if ($('#twitter_login_button').length > 0) {
  9793. $('#twitter_login_button')[0].click();
  9794. }
  9795. return true;
  9796. } catch (error) {
  9797. throwError(error, 'SweepWidget.checkLogin');
  9798. return false;
  9799. }
  9800. }
  9801. #getGiveawayId() {
  9802. try {
  9803. const giveawayId = window.location.href.match(/\/view\/([\d]+)/)?.[1];
  9804. if (giveawayId) {
  9805. this.giveawayId = giveawayId;
  9806. return true;
  9807. }
  9808. scripts_echoLog({
  9809. text: i18n('getFailed', 'GiveawayId')
  9810. });
  9811. return false;
  9812. } catch (error) {
  9813. throwError(error, 'SweepWidget.getGiveawayId');
  9814. return false;
  9815. }
  9816. }
  9817. async #checkEnter() {
  9818. try {
  9819. return new Promise(resolve => {
  9820. const checker = setInterval(() => {
  9821. if ($('#unlock_rewards_main_wrapper').length > 0) {
  9822. clearInterval(checker);
  9823. resolve(true);
  9824. }
  9825. });
  9826. });
  9827. } catch (error) {
  9828. throwError(error, 'SweepWidget.checkEnter');
  9829. return false;
  9830. }
  9831. }
  9832. async #checkFinish($task) {
  9833. try {
  9834. return new Promise(resolve => {
  9835. const checker = setInterval(() => {
  9836. if ($task.find('i.fa-check:visible').length > 0 || $task.find('.sw_entry_input:visible').length === 0) {
  9837. clearInterval(checker);
  9838. resolve(true);
  9839. }
  9840. });
  9841. });
  9842. } catch (error) {
  9843. throwError(error, 'SweepWidget.checkFinish');
  9844. return false;
  9845. }
  9846. }
  9847. }
  9848. const website_SweepWidget = SweepWidget;
  9849. const defaultWhiteList = {
  9850. discord: {
  9851. servers: []
  9852. },
  9853. instagram: {
  9854. users: []
  9855. },
  9856. twitch: {
  9857. channels: []
  9858. },
  9859. twitter: {
  9860. users: [],
  9861. retweets: [],
  9862. likes: []
  9863. },
  9864. vk: {
  9865. names: []
  9866. },
  9867. youtube: {
  9868. channels: [],
  9869. likes: []
  9870. },
  9871. reddit: {
  9872. reddits: []
  9873. },
  9874. steam: {
  9875. groups: [],
  9876. officialGroups: [],
  9877. wishlists: [],
  9878. follows: [],
  9879. forums: [],
  9880. workshops: [],
  9881. curators: [],
  9882. workshopVotes: [],
  9883. curatorLikes: [],
  9884. announcements: [],
  9885. licenses: [],
  9886. playtests: []
  9887. }
  9888. };
  9889. const link2id = async function(type) {
  9890. try {
  9891. const link = $('#socialLink').val();
  9892. let id = '';
  9893. switch (type) {
  9894. case 'discord.servers':
  9895. id = link.match(/invite\/(.+)/)?.[1] || '';
  9896. break;
  9897.  
  9898. case 'instagram.users':
  9899. id = link.match(/https:\/\/www\.instagram\.com\/(.+)?\//)?.[1] || '';
  9900. break;
  9901.  
  9902. case 'twitch.channels':
  9903. id = link.match(/https:\/\/(www\.)?twitch\.tv\/(.+)/)?.[2] || '';
  9904. break;
  9905.  
  9906. case 'twitter.users':
  9907. id = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || '';
  9908. break;
  9909.  
  9910. case 'twitter.retweets':
  9911. id = link.match(/https:\/\/twitter\.com\/.*?\/status\/([\d]+)/)?.[1] || '';
  9912. break;
  9913.  
  9914. case 'vk.names':
  9915. id = link.match(/https:\/\/vk\.com\/([^/]+)/)?.[1] || '';
  9916. break;
  9917.  
  9918. case 'youtube.channels':
  9919. id = (await getInfo(link, 'channel'))?.params?.channelId || '';
  9920. break;
  9921.  
  9922. case 'youtube.likes':
  9923. id = (await getInfo(link, 'likeVideo'))?.params?.videoId || '';
  9924. break;
  9925.  
  9926. case 'reddit.reddits':
  9927. id = link.match(/https?:\/\/www\.reddit\.com\/user\/([^/]*)/)?.[1] || link.match(/https?:\/\/www\.reddit\.com\/r\/([^/]*)/)?.[1] || '';
  9928. break;
  9929.  
  9930. case 'steam.groups':
  9931. id = link.match(/groups\/(.+)\/?/)?.[1] || '';
  9932. break;
  9933.  
  9934. case 'steam.wishlists':
  9935. case 'steam.follows':
  9936. case 'steam.forums':
  9937. id = link.match(/app\/([\d]+)/)?.[1] || '';
  9938. break;
  9939.  
  9940. case 'steam.workshops':
  9941. id = link.match(/\?id=([\d]+)/)?.[1] || '';
  9942. break;
  9943.  
  9944. case 'steam.curators':
  9945. {
  9946. if (link.includes('curator')) {
  9947. id = link.match(/curator\/([\d]+)/)?.[1] || '';
  9948. } else {
  9949. const param = link.match(/https?:\/\/store\.steampowered\.com\/(.*?)\/([^/?]+)/)?.slice(1, 3);
  9950. if (!param || param.length !== 2) {
  9951. break;
  9952. }
  9953. const steam = new social_Steam();
  9954. if (await steam.init()) {
  9955. id = await steam.getCuratorId(param[0], param[1]) || '';
  9956. }
  9957. }
  9958. }
  9959. break;
  9960. }
  9961. return id;
  9962. } catch (error) {
  9963. throwError(error, 'link2id');
  9964. return i18n('getFailed', 'id');
  9965. }
  9966. };
  9967. const disabledType = {
  9968. steam: [ 'workshopVotes', 'curatorLikes', 'announcements' ],
  9969. twitter: [ 'likes' ]
  9970. };
  9971. const assignWhiteList = whiteList => {
  9972. try {
  9973. const newWhiteList = {};
  9974. for (const [ key, value ] of Object.entries(defaultWhiteList)) {
  9975. newWhiteList[key] = {
  9976. ...value,
  9977. ...whiteList[key]
  9978. };
  9979. }
  9980. return newWhiteList;
  9981. } catch (error) {
  9982. throwError(error, 'assignWhiteList');
  9983. return defaultWhiteList;
  9984. }
  9985. };
  9986. const whiteListOptions = function(showType) {
  9987. try {
  9988. const whiteList = assignWhiteList(GM_getValue('whiteList') || {});
  9989. let whiteListOptionsForm = `<form id="whiteListForm" class="auto-task-form">
  9990. <table class="auto-task-table"><thead><tr><td>${i18n('website')}</td><td>${i18n('type')}</td><td>${i18n('edit')}</td></tr></thead><tbody>`;
  9991. for (const [ social, types ] of Object.entries(whiteList)) {
  9992. 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('');
  9993. }
  9994. whiteListOptionsForm += '</tbody></table></form>';
  9995. if (showType === 'swal') {
  9996. external_Swal_default().fire({
  9997. title: i18n('whiteListOptions'),
  9998. html: whiteListOptionsForm,
  9999. showConfirmButton: false,
  10000. showCloseButton: true
  10001. });
  10002. } else {
  10003. $('body').append(`<h2>${i18n('whiteList')}</h2>${whiteListOptionsForm}`);
  10004. }
  10005. $('.editWhiteList').on('click', function() {
  10006. const value = $(this).attr('data-value');
  10007. if (!value) {
  10008. return;
  10009. }
  10010. const [ social, type ] = value.split('.');
  10011. if (!whiteList?.[social]?.[type]) {
  10012. scripts_echoLog({}).warning(i18n('whiteListNotFound', value));
  10013. return;
  10014. }
  10015. external_Swal_default().fire({
  10016. title: i18n('changeWhiteListOption', value),
  10017. input: 'textarea',
  10018. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10019. <button id="link2id" data-type="${value}" class="swal2-confirm swal2-styled">获取id</button>
  10020. <p style="margin-bottom:0 !important;">在下方填写白名单,每行一个</p>`,
  10021. inputValue: whiteList[social][type].join('\n'),
  10022. showConfirmButton: true,
  10023. confirmButtonText: i18n('save'),
  10024. showCancelButton: true,
  10025. cancelButtonText: i18n('close'),
  10026. showDenyButton: true,
  10027. denyButtonText: i18n('return')
  10028. }).then(({
  10029. isDenied,
  10030. isConfirmed,
  10031. value
  10032. }) => {
  10033. if (isDenied) {
  10034. if (showType === 'swal') {
  10035. whiteListOptions(showType);
  10036. }
  10037. return;
  10038. } else if (isConfirmed) {
  10039. whiteList[social][type] = value.split('\n');
  10040. GM_setValue('whiteList', whiteList);
  10041. external_Swal_default().fire({
  10042. title: i18n('changeWhiteListSuccess'),
  10043. icon: 'success'
  10044. });
  10045. }
  10046. });
  10047. $('#link2id').on('click', async function() {
  10048. const type = $(this).attr('data-type');
  10049. $('#socialLink').val(await link2id(type));
  10050. });
  10051. });
  10052. } catch (error) {
  10053. throwError(error, 'whiteListOptions');
  10054. }
  10055. };
  10056. const whiteList = whiteListOptions;
  10057. const setGistData = async (token, gistId, fileName, content) => {
  10058. try {
  10059. const logStatus = scripts_echoLog({
  10060. text: i18n('settingData')
  10061. });
  10062. const contentData = JSON.stringify({
  10063. files: {
  10064. [fileName]: {
  10065. content: JSON.stringify(content)
  10066. }
  10067. }
  10068. });
  10069. const {
  10070. result,
  10071. statusText,
  10072. status,
  10073. data
  10074. } = await tools_httpRequest({
  10075. url: `https://api.github.com/gists/${gistId}`,
  10076. headers: {
  10077. Accept: 'application/vnd.github.v3+json',
  10078. Authorization: `token ${token}`
  10079. },
  10080. data: contentData,
  10081. responseType: 'json',
  10082. method: 'POST',
  10083. timeout: 3e4
  10084. });
  10085. if (result === 'Success') {
  10086. if (data?.status === 200 && data.response.files?.[fileName]?.content === JSON.stringify(content)) {
  10087. logStatus.success();
  10088. return true;
  10089. }
  10090. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10091. return false;
  10092. }
  10093. logStatus.error(`${result}:${statusText}(${status})`);
  10094. return false;
  10095. } catch (error) {
  10096. throwError(error, 'setGistData');
  10097. return false;
  10098. }
  10099. };
  10100. const getGistData = async (token, gistId, fileName, test = false) => {
  10101. try {
  10102. const logStatus = scripts_echoLog({
  10103. text: i18n('gettingData')
  10104. });
  10105. const {
  10106. result,
  10107. statusText,
  10108. status,
  10109. data
  10110. } = await tools_httpRequest({
  10111. url: `https://api.github.com/gists/${gistId}`,
  10112. headers: {
  10113. Accept: 'application/vnd.github.v3+json',
  10114. Authorization: `token ${token}`
  10115. },
  10116. responseType: 'json',
  10117. method: 'GET',
  10118. timeout: 3e4
  10119. });
  10120. if (result === 'Success') {
  10121. if (data?.status === 200) {
  10122. const content = data.response?.files?.[fileName]?.content;
  10123. let formatedContent;
  10124. if (!content) {
  10125. logStatus.error(`Error:${i18n('noRemoteData')}`);
  10126. return false;
  10127. }
  10128. if (test) {
  10129. logStatus.success();
  10130. return true;
  10131. }
  10132. try {
  10133. formatedContent = JSON.parse(content);
  10134. } catch (error) {
  10135. logStatus.error(`Error:${i18n('errorRemoteDataFormat')}`);
  10136. return false;
  10137. }
  10138. logStatus.success();
  10139. return formatedContent;
  10140. }
  10141. logStatus.error(`Error:${data?.statusText}(${data?.status})`);
  10142. return false;
  10143. }
  10144. logStatus.error(`${result}:${statusText}(${status})`);
  10145. return false;
  10146. } catch (error) {
  10147. throwError(error, 'getGistData');
  10148. return false;
  10149. }
  10150. };
  10151. const syncOptions = () => {
  10152. try {
  10153. const {
  10154. TOKEN,
  10155. GIST_ID,
  10156. FILE_NAME,
  10157. SYNC_HISTORY
  10158. } = GM_getValue('gistOptions') || {
  10159. TOKEN: '',
  10160. GIST_ID: '',
  10161. FILE_NAME: '',
  10162. SYNC_HISTORY: true
  10163. };
  10164. external_Swal_default().fire({
  10165. title: i18n('gistOptions'),
  10166. 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;">
  10167. ${i18n('upload2gist')}</button>` + `<button id="download-data" type="button" class="swal2-confirm swal2-styled" style="display: inline-block;">
  10168. ${i18n('downloadFromGist')}</button></p>`,
  10169. focusConfirm: false,
  10170. showLoaderOnConfirm: true,
  10171. 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>`,
  10172. preConfirm: async () => {
  10173. const token = $('#github-token').val();
  10174. const gistId = $('#gist-id').val();
  10175. const fileName = $('#file-name').val();
  10176. const syncHistory = $('#sync-history').prop('checked');
  10177. GM_setValue('gistOptions', {
  10178. TOKEN: token,
  10179. GIST_ID: gistId,
  10180. FILE_NAME: fileName,
  10181. SYNC_HISTORY: syncHistory
  10182. });
  10183. return await getGistData(token, gistId, fileName, true);
  10184. },
  10185. allowOutsideClick: () => !external_Swal_default().isLoading(),
  10186. confirmButtonText: i18n('saveAndTest'),
  10187. showCancelButton: true,
  10188. cancelButtonText: i18n('close')
  10189. }).then(({
  10190. value
  10191. }) => {
  10192. if (value) {
  10193. external_Swal_default().fire({
  10194. icon: 'success',
  10195. title: i18n('testSuccess')
  10196. }).then(syncOptions);
  10197. } else if (value !== undefined) {
  10198. external_Swal_default().fire({
  10199. icon: 'error',
  10200. title: i18n('testFailed')
  10201. }).then(syncOptions);
  10202. }
  10203. });
  10204. $('#upload-data').on('click', async () => {
  10205. const {
  10206. TOKEN,
  10207. GIST_ID,
  10208. FILE_NAME
  10209. } = GM_getValue('gistOptions') || {};
  10210. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10211. return external_Swal_default().fire({
  10212. icon: 'error',
  10213. title: i18n('saveAndTestNotice')
  10214. }).then(syncOptions);
  10215. }
  10216. external_Swal_default().fire({
  10217. icon: 'info',
  10218. title: i18n('processingData')
  10219. });
  10220. const data = {};
  10221. const names = GM_listValues();
  10222. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10223. for (const name of names) {
  10224. if (name === 'gistOptions' || /^[\w]+?Auth$/.test(name)) {
  10225. continue;
  10226. }
  10227. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10228. continue;
  10229. }
  10230. data[name] = GM_getValue(name);
  10231. }
  10232. external_Swal_default().update({
  10233. icon: 'info',
  10234. title: i18n('updatingData')
  10235. });
  10236. if (await setGistData(TOKEN, GIST_ID, FILE_NAME, data)) {
  10237. external_Swal_default().fire({
  10238. icon: 'success',
  10239. title: i18n('syncDataSuccess')
  10240. });
  10241. } else {
  10242. external_Swal_default().fire({
  10243. icon: 'error',
  10244. title: i18n('syncDataFailed')
  10245. });
  10246. }
  10247. });
  10248. $('#download-data').on('click', async () => {
  10249. const {
  10250. TOKEN,
  10251. GIST_ID,
  10252. FILE_NAME
  10253. } = GM_getValue('gistOptions') || {};
  10254. if (!(TOKEN && GIST_ID && FILE_NAME)) {
  10255. return external_Swal_default().fire({
  10256. icon: 'error',
  10257. title: i18n('saveAndTestNotice')
  10258. }).then(syncOptions);
  10259. }
  10260. external_Swal_default().fire({
  10261. icon: 'info',
  10262. title: i18n('downloadingData')
  10263. });
  10264. const data = await getGistData(TOKEN, GIST_ID, FILE_NAME);
  10265. if (!data) {
  10266. return external_Swal_default().fire({
  10267. icon: 'error',
  10268. title: i18n('checkedNoData')
  10269. }).then(syncOptions);
  10270. }
  10271. external_Swal_default().update({
  10272. icon: 'info',
  10273. title: i18n('savingData')
  10274. });
  10275. const SYNC_HISTORY = $('#sync-history').prop('checked');
  10276. for (const [ name, value ] of Object.entries(data)) {
  10277. if (!SYNC_HISTORY && /^[\w]+?Tasks-/.test(name)) {
  10278. continue;
  10279. }
  10280. GM_setValue(name, value);
  10281. }
  10282. external_Swal_default().fire({
  10283. icon: 'success',
  10284. title: i18n('syncDataSuccess')
  10285. });
  10286. });
  10287. } catch (error) {
  10288. throwError(error, 'syncOptions');
  10289. }
  10290. };
  10291. const dataSync = syncOptions;
  10292. class Setting {
  10293. name = 'Setting';
  10294. buttons = [ 'saveGlobalOptions', 'syncData', 'tasksHistory' ];
  10295. syncData = dataSync;
  10296. tasksHistory() {
  10297. window.open('https://auto-task-v4.hclonely.com/history.html', '_blank');
  10298. }
  10299. static test() {
  10300. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/setting.html';
  10301. }
  10302. before() {
  10303. $('body').html('').addClass('auto-task-options');
  10304. }
  10305. after() {
  10306. try {
  10307. this.#environment();
  10308. changeGlobalOptions('page');
  10309. whiteList('page');
  10310. $('input[name="other.twitterVerifyId"]').after(`<button id="getTwitterUserId" type="button">${i18n('getTwitterUserId')}</button>`);
  10311. $('#getTwitterUserId').on('click', () => {
  10312. this.#getId('twitterUser');
  10313. });
  10314. $('input[name="other.youtubeVerifyChannel"]').after(`<button id="getYoutubeChannelId" type="button">${i18n('getYoutubeChannelId')}</button>`);
  10315. $('#getYoutubeChannelId').on('click', () => {
  10316. this.#getId('youtubeChannel');
  10317. });
  10318. $('input[name^="position"]').on('input', function() {
  10319. const type = $(this).attr('name').replace('position.', '');
  10320. const xLabel = 'rightleft';
  10321. const yLabel = 'topbottpm';
  10322. switch (type) {
  10323. case 'buttonSideX':
  10324. case 'buttonSideY':
  10325. case 'buttonDistance':
  10326. {
  10327. const distance = $('input[name="position.buttonDistance"]').val();
  10328. const sideX = $('input[name="position.buttonSideX"]').val();
  10329. const sideY = $('input[name="position.buttonSideY"]').val();
  10330. if (![ 'right', 'left' ].includes(sideX)) {
  10331. break;
  10332. }
  10333. if (![ 'top', 'bottom' ].includes(sideY)) {
  10334. break;
  10335. }
  10336. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10337. break;
  10338. }
  10339. const distanceArr = distance.split(',');
  10340. $('#auto-task-buttons').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10341. break;
  10342. }
  10343.  
  10344. case 'showButtonSideX':
  10345. case 'showButtonSideY':
  10346. case 'showButtonDistance':
  10347. {
  10348. const distance = $('input[name="position.showButtonDistance"]').val();
  10349. const sideX = $('input[name="position.showButtonSideX"]').val();
  10350. const sideY = $('input[name="position.showButtonSideY"]').val();
  10351. if (![ 'right', 'left' ].includes(sideX)) {
  10352. break;
  10353. }
  10354. if (![ 'top', 'bottom' ].includes(sideY)) {
  10355. break;
  10356. }
  10357. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10358. break;
  10359. }
  10360. const distanceArr = distance.split(',');
  10361. $('div.show-button-div').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10362. break;
  10363. }
  10364.  
  10365. case 'logSideX':
  10366. case 'logSideY':
  10367. case 'logDistance':
  10368. {
  10369. const distance = $('input[name="position.logDistance"]').val();
  10370. const sideX = $('input[name="position.logSideX"]').val();
  10371. const sideY = $('input[name="position.logSideY"]').val();
  10372. if (![ 'right', 'left' ].includes(sideX)) {
  10373. break;
  10374. }
  10375. if (![ 'top', 'bottom' ].includes(sideY)) {
  10376. break;
  10377. }
  10378. if (!/^[\d]+?,[\d]+$/.test(distance)) {
  10379. break;
  10380. }
  10381. const distanceArr = distance.split(',');
  10382. $('#auto-task-info').css(sideX, `${distanceArr[0]}px`).css(sideY, `${distanceArr[1]}px`).css(xLabel.replace(sideX, ''), '').css(yLabel.replace(sideY, ''), '');
  10383. break;
  10384. }
  10385.  
  10386. default:
  10387. break;
  10388. }
  10389. });
  10390. $('input[name^="hotKey"]').attr('readonly', 'readonly').off('keydown').on('keydown', function(event) {
  10391. let functionKey = '';
  10392. if (event.altKey) {
  10393. functionKey += 'alt + ';
  10394. } else if (event.ctrlKey) {
  10395. functionKey += 'ctrl + ';
  10396. } else if (event.shiftKey) {
  10397. functionKey += 'shift + ';
  10398. }
  10399. $(this).val(functionKey + (event.key.length === 1 ? event.key.toLowerCase() : ''));
  10400. });
  10401. } catch (error) {
  10402. throwError(error, 'Setting.after');
  10403. }
  10404. }
  10405. saveGlobalOptions() {
  10406. saveData();
  10407. }
  10408. #getId(social) {
  10409. try {
  10410. external_Swal_default().fire({
  10411. title: i18n('getId', i18n(social)),
  10412. html: `<input id="socialLink" class="swal2-input" placeholder="在此处输入链接获取id">
  10413. <button id="link2id" data-type="${social}" class="swal2-confirm swal2-styled">获取id</button>`,
  10414. showCancelButton: true,
  10415. cancelButtonText: i18n('close'),
  10416. showConfirmButton: false
  10417. });
  10418. $('#link2id').on('click', async function() {
  10419. const link = $('#socialLink').val();
  10420. if (!link) {
  10421. return;
  10422. }
  10423. const type = $(this).attr('data-type');
  10424. if (type === 'twitterUser') {
  10425. const name = link.match(/https:\/\/twitter\.com\/(.+)/)?.[1] || link;
  10426. $('#socialLink').val(await new social_Twitter().userName2id(name) || '');
  10427. } else if (type === 'youtubeChannel') {
  10428. const name = /^https:\/\/(www\.)?google\.com.*?\/url\?.*?url=https:\/\/www.youtube.com\/.*/.test(link) ? link.match(/url=(https:\/\/www\.youtube\.com\/.*)/)?.[1] : link;
  10429. $('#socialLink').val((await getInfo(name, 'channel'))?.params?.channelId || '');
  10430. }
  10431. });
  10432. } catch (error) {
  10433. throwError(error, 'Setting.getId');
  10434. }
  10435. }
  10436. #environment() {
  10437. try {
  10438. const userAgent = (0, javascript_utils_umd_min.ua)();
  10439. const environmentForm = `<form id="environmentForm" class="auto-task-form">
  10440. <table class="auto-task-table"><thead><tr><td>${i18n('type')}</td><td>${i18n('name')}</td><td>${i18n('version')}</td></tr></thead><tbody>
  10441. <tr><td>${i18n('os')}</td><td>${userAgent.os}</td><td>${userAgent.osVersion}</td></tr>
  10442. <tr><td>${i18n('browser')}</td><td>${userAgent.browserZH}</td><td>${userAgent.browserVersion}</td></tr>
  10443. <tr><td>${i18n('scriptManager')}</td><td>${GM_info.scriptHandler}</td><td>${GM_info.version}</td></tr>
  10444. <tr><td>${i18n('script')}</td><td>${GM_info.script.name}</td><td>${GM_info.script.version}</td></tr>
  10445. </tbody></table></form>`;
  10446. $('body').append(`<h2>${i18n('environment')}</h2>${environmentForm}`);
  10447. } catch (error) {
  10448. throwError(error, 'Setting.environment');
  10449. }
  10450. }
  10451. }
  10452. const website_Setting = Setting;
  10453. class History extends website_Keylol {
  10454. name = 'History';
  10455. buttons = [ 'doTask', 'undoTask', 'selectAll', 'selectNone', 'invertSelect', 'clearHistory' ];
  10456. static test() {
  10457. return window.location.host === 'auto-task-v4.hclonely.com' && window.location.pathname === '/history.html';
  10458. }
  10459. before() {
  10460. try {
  10461. $('body').html('<div class="container"></div>').addClass('auto-task-history');
  10462. const data = GM_listValues() || [];
  10463. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10464. for (const item of tasksHistory) {
  10465. this.#addItem(item);
  10466. }
  10467. } catch (error) {
  10468. throwError(error, 'History.before');
  10469. }
  10470. }
  10471. clearHistory() {
  10472. try {
  10473. const data = GM_listValues() || [];
  10474. const tasksHistory = data.map(value => /^[\w]+?Tasks-/.test(value) ? value : null).filter(value => value);
  10475. for (const item of tasksHistory) {
  10476. GM_deleteValue(item);
  10477. }
  10478. external_Swal_default().fire({
  10479. title: i18n('clearHistoryFinished'),
  10480. icon: 'success'
  10481. });
  10482. } catch (error) {
  10483. throwError(error, 'History.after');
  10484. }
  10485. }
  10486. #addItem(item) {
  10487. try {
  10488. const tasksData = GM_getValue(item);
  10489. if (!tasksData?.tasks) {
  10490. return;
  10491. }
  10492. let html = '';
  10493. let title = '';
  10494. let link = '';
  10495. const [ website, id ] = item.split('-');
  10496. switch (website) {
  10497. case 'fawTasks':
  10498. title = `Freeanywhere[${id}]`;
  10499. link = `https://freeanywhere.net/#/giveaway/${id}`;
  10500. break;
  10501.  
  10502. case 'gasTasks':
  10503. title = `Giveawaysu[${id}]`;
  10504. link = `https://giveaway.su/giveaway/view/${id}`;
  10505. break;
  10506.  
  10507. case 'gcTasks':
  10508. title = `GiveeClub[${id}]`;
  10509. link = `https://givee.club/event/${id}`;
  10510. break;
  10511.  
  10512. case 'gkTasks':
  10513. title = `Givekey[${id}]`;
  10514. link = `https://givekey.ru/giveaway/${id}`;
  10515. break;
  10516.  
  10517. case 'gleamTasks':
  10518. title = `Gleam[${id}]`;
  10519. link = `https://gleam.io${id}`;
  10520. break;
  10521.  
  10522. case 'khTasks':
  10523. title = `keyhub[${id}]`;
  10524. link = `https://key-hub.eu/giveaway/${id}`;
  10525. break;
  10526.  
  10527. case 'prysTasks':
  10528. title = `Prys[${id}]`;
  10529. link = `https://prys.revadike.com/giveaway/?id=${id}`;
  10530. break;
  10531.  
  10532. default:
  10533. return;
  10534. }
  10535. for (const [ social, types ] of Object.entries(tasksData.tasks)) {
  10536. for (const [ type, tasks ] of Object.entries(types)) {
  10537. for (const task of tasks) {
  10538. 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>`;
  10539. }
  10540. }
  10541. }
  10542. $('.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>`);
  10543. $('span.delete-task').on('click', function() {
  10544. const itemName = $(this).attr('data-name');
  10545. if (itemName) {
  10546. GM_deleteValue(itemName);
  10547. $(`div.card[data-name="${itemName}"]`).remove();
  10548. external_Swal_default().fire({
  10549. title: i18n('clearTaskFinished'),
  10550. text: itemName,
  10551. icon: 'success'
  10552. });
  10553. } else {
  10554. external_Swal_default().fire({
  10555. title: i18n('clearTaskFailed'),
  10556. icon: 'error'
  10557. });
  10558. }
  10559. });
  10560. } catch (error) {
  10561. throwError(error, 'History.addItem');
  10562. }
  10563. }
  10564. }
  10565. const website_History = History;
  10566. 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 ];
  10567. const websiteOptions = function(website, options) {
  10568. try {
  10569. let websiteOptionsForm = `<form id="websiteOptionsForm" class="auto-task-form">
  10570. <table class="auto-task-table"><thead><tr><td>${i18n('option')}</td><td>${i18n('value')}</td></tr></thead><tbody>`;
  10571. for (const [ option, value ] of Object.entries(options)) {
  10572. websiteOptionsForm += `<tr><td>${option}</td><td><input class="editOption" type="text" name="${option}" value="${value}"/></td></tr>`;
  10573. }
  10574. websiteOptionsForm += '</tbody></table></form>';
  10575. external_Swal_default().fire({
  10576. title: i18n('websiteOptions'),
  10577. html: websiteOptionsForm,
  10578. showConfirmButton: true,
  10579. confirmButtonText: i18n('save'),
  10580. showCancelButton: true,
  10581. cancelButtonText: i18n('close')
  10582. }).then(({
  10583. isConfirmed
  10584. }) => {
  10585. if (isConfirmed) {
  10586. $('#websiteOptionsForm').serializeArray().map(value => {
  10587. options[value.name] = value.value;
  10588. return value;
  10589. });
  10590. GM_setValue(`${website}Options`, options);
  10591. external_Swal_default().fire({
  10592. title: i18n('changeWebsiteOptionsSuccess'),
  10593. icon: 'success'
  10594. });
  10595. }
  10596. });
  10597. } catch (error) {
  10598. throwError(error, 'websiteOptions');
  10599. }
  10600. };
  10601. const options = websiteOptions;
  10602. const external_keyboardJS_namespaceObject = keyboardJS;
  10603. var external_keyboardJS_default = __webpack_require__.n(external_keyboardJS_namespaceObject);
  10604. const checkUpdate = async (updateLink, auto) => {
  10605. try {
  10606. const checkUrl = `${updateLink}package.json?time=${new Date().getTime()}`;
  10607. const {
  10608. result,
  10609. statusText,
  10610. status,
  10611. data
  10612. } = await tools_httpRequest({
  10613. url: checkUrl,
  10614. responseType: 'json',
  10615. method: 'GET',
  10616. timeout: 3e4
  10617. });
  10618. if (result === 'Success') {
  10619. if (data?.response?.version) {
  10620. return data.response;
  10621. }
  10622. if (!auto) {
  10623. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${data?.statusText}(${data?.status})]`);
  10624. }
  10625. return false;
  10626. }
  10627. if (!auto) {
  10628. scripts_echoLog({}).error(`${i18n('checkUpdateFailed')}[${result}:${statusText}(${status})]`);
  10629. }
  10630. return false;
  10631. } catch (error) {
  10632. throwError(error, 'checkUpdate');
  10633. return false;
  10634. }
  10635. };
  10636. const hasNewVersion = (currentVersion, remoteVersion) => {
  10637. try {
  10638. const [ currentRealVersion ] = currentVersion.split('-');
  10639. const [ remoteRealVersion, isPreview ] = remoteVersion.split('-');
  10640. if (isPreview && !globalOptions.other.receivePreview) {
  10641. return false;
  10642. }
  10643. const [ currentVersion1, currentVersion2, currentVersion3 ] = currentRealVersion.split('.').map(value => parseInt(value, 10));
  10644. const [ remoteVersion1, remoteVersion2, remoteVersion3 ] = remoteRealVersion.split('.').map(value => parseInt(value, 10));
  10645. if (remoteVersion1 > currentVersion1) {
  10646. return true;
  10647. }
  10648. if (remoteVersion1 < currentVersion1) {
  10649. return false;
  10650. }
  10651. if (remoteVersion2 > currentVersion2) {
  10652. return true;
  10653. }
  10654. if (remoteVersion2 < currentVersion2) {
  10655. return false;
  10656. }
  10657. if (remoteVersion3 > currentVersion3) {
  10658. return true;
  10659. }
  10660. return false;
  10661. } catch (error) {
  10662. throwError(error, 'compareVersion');
  10663. return false;
  10664. }
  10665. };
  10666. const updateChecker = async () => {
  10667. try {
  10668. const currentVersion = GM_info.script.version;
  10669. const updateSource = globalOptions.other.autoUpdateSource.toLowerCase();
  10670. const updateLinks = {
  10671. github: 'https://github.com/HCLonely/auto-task-new/raw/main/',
  10672. jsdelivr: 'https://cdn.jsdelivr.net/gh/HCLonely/auto-task-v4@main/',
  10673. standby: 'https://auto-task-v4.hclonely.com/'
  10674. };
  10675. let version;
  10676. let updateLink = '';
  10677. let packageData;
  10678. if ([ 'github', 'jsdelivr', 'standby' ].includes(updateSource)) {
  10679. updateLink = updateLinks[updateSource];
  10680. packageData = await checkUpdate(updateLink, false);
  10681. } else {
  10682. updateLink = updateLinks.github;
  10683. packageData = await checkUpdate(updateLink, true);
  10684. if (!packageData) {
  10685. updateLink = updateLinks.jsdelivr;
  10686. packageData = await checkUpdate(updateLink, true);
  10687. if (!packageData) {
  10688. updateLink = updateLinks.standby;
  10689. packageData = await checkUpdate(updateLink, true);
  10690. }
  10691. }
  10692. }
  10693. if (packageData) {
  10694. version = packageData.version || currentVersion;
  10695. } else {
  10696. version = currentVersion;
  10697. scripts_echoLog({}).error(i18n('checkUpdateFailed'));
  10698. }
  10699. if (packageData && hasNewVersion(currentVersion, version)) {
  10700. scripts_echoLog({
  10701. html: `<li><font>${i18n('newVersionNotice', version, `${updateLink}dist/${GM_info.script.name}.user.js`)}</font></li>`
  10702. });
  10703. scripts_echoLog({
  10704. html: `<li>${i18n('updateText', version)}</li><ol class="update-text">${packageData.change?.map(change => `<li>${change}</li>`).join('')}<li>${i18n('updateHistory')}</li></ol>`
  10705. });
  10706. }
  10707. } catch (error) {
  10708. throwError(error, 'updateChecker');
  10709. }
  10710. };
  10711. const scripts_updateChecker = updateChecker;
  10712. window.STYLE = GM_addStyle(auto_task.A + GM_getResourceText('style'));
  10713. window.DEBUG = !!globalOptions.other?.debug;
  10714. window.TRACE = !!globalOptions.other?.debug && typeof console.trace === 'function';
  10715. const loadScript = async () => {
  10716. if (window.location.hostname === 'www.twitch.tv' && window.location.hash === '#auth') {
  10717. const authToken = external_Cookies_namespaceObject.get('auth-token');
  10718. const isLogin = !!external_Cookies_namespaceObject.get('login');
  10719. if (isLogin) {
  10720. GM_setValue('twitchAuth', {
  10721. authToken: authToken,
  10722. clientVersion: __twilightBuildID,
  10723. clientId: commonOptions?.headers?.['Client-ID'],
  10724. deviceId: commonOptions?.headers?.['Device-ID'],
  10725. clientSessionId: window.localStorage.local_storage_app_session_id.replace(/"/g, '')
  10726. });
  10727. window.close();
  10728. external_Swal_default().fire('', i18n('closePageNotice'));
  10729. } else {
  10730. external_Swal_default().fire('', i18n('needLogin'));
  10731. }
  10732. return;
  10733. }
  10734. if (window.location.hostname === 'www.reddit.com' && (window.location.hash === '#auth' || GM_getValue('redditAuth') === '#auth')) {
  10735. const betaButton = $('#redesign-beta-optin-btn');
  10736. if (betaButton.length > 0) {
  10737. GM_setValue('redditAuth', '#auth');
  10738. return betaButton[0].click();
  10739. }
  10740. GM_setValue('redditAuth', null);
  10741. window.close();
  10742. external_Swal_default().fire('', i18n('closePageNotice'));
  10743. return;
  10744. }
  10745. let website;
  10746. for (const Website of Websites) {
  10747. if (Website.test()) {
  10748. website = new Website();
  10749. break;
  10750. }
  10751. }
  10752. if (!website) {
  10753. console.log('%c%s', 'color:#ff0000', 'Auto-Task[Warning]: 脚本停止加载,当前网站不支持!');
  10754. return;
  10755. }
  10756. if (website?.before) {
  10757. await website?.before();
  10758. }
  10759. $('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>`);
  10760. $('div.show-button-div').on('click', () => {
  10761. $('#auto-task-buttons').show();
  10762. $('div.show-button-div').hide();
  10763. });
  10764. const toggleLog = () => {
  10765. const $this = $('#toggle-log');
  10766. const status = $this.attr('data-status');
  10767. if (status === 'show') {
  10768. $('#auto-task-info').hide();
  10769. $this.attr('data-status', 'hide').text(i18n('showLog'));
  10770. } else {
  10771. $('#auto-task-info').show();
  10772. $this.attr('data-status', 'show').text(i18n('hideLog'));
  10773. }
  10774. };
  10775. external_keyboardJS_default().bind(globalOptions.hotKey.doTaskKey, () => {
  10776. if (website.doTask) {
  10777. website.doTask();
  10778. }
  10779. });
  10780. external_keyboardJS_default().bind(globalOptions.hotKey.undoTaskKey, () => {
  10781. if (website.undoTask) {
  10782. website.doTask();
  10783. }
  10784. });
  10785. external_keyboardJS_default().bind(globalOptions.hotKey.toggleLogKey, toggleLog);
  10786. if (website?.after) {
  10787. await website?.after();
  10788. }
  10789. if (website?.buttons && $('#auto-task-buttons').children().length === 0) {
  10790. $('#auto-task-buttons').addClass(`${website.name}-buttons`);
  10791. for (const button of website.buttons) {
  10792. if (website[button]) {
  10793. const btnElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">${i18n(button)}</a></p>`);
  10794. btnElement.find('a.auto-task-website-btn').on('click', () => {
  10795. website[button]();
  10796. });
  10797. $('#auto-task-buttons').append(btnElement);
  10798. }
  10799. }
  10800. }
  10801. const hideButtonElement = $(`<p><a class="auto-task-website-btn ${website.name}-button" href="javascript:void(0);" target="_self">
  10802. ${i18n('hideButton')}</a></p>`);
  10803. hideButtonElement.find('a.auto-task-website-btn').on('click', () => {
  10804. $('#auto-task-buttons').hide();
  10805. $('div.show-button-div').show();
  10806. });
  10807. 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'}">
  10808. ${globalOptions.other.defaultShowLog ? i18n('hideLog') : i18n('showLog')}</a></p>`);
  10809. toggleLogElement.find('a.auto-task-website-btn').on('click', toggleLog);
  10810. $('#auto-task-buttons').append(hideButtonElement).append(toggleLogElement);
  10811. if (website?.options) {
  10812. GM_registerMenuCommand(i18n('changeWebsiteOptions'), () => {
  10813. options(website.name, website.options);
  10814. });
  10815. }
  10816. if (website.name !== 'Setting') {
  10817. GM_registerMenuCommand(i18n('changeGlobalOptions'), () => {
  10818. changeGlobalOptions('swal');
  10819. });
  10820. GM_registerMenuCommand(i18n('settingPage'), () => {
  10821. window.open('https://auto-task-v4.hclonely.com/setting.html', '_blank');
  10822. });
  10823. }
  10824. console.log('%c%s', 'color:#1bbe1a', 'Auto-Task[Load]: 脚本加载完成');
  10825. const [ v1, v2 ] = GM_info.version.split('.');
  10826. if (!(parseInt(v1, 10) >= 5 && parseInt(v2, 10) >= 2)) {
  10827. scripts_echoLog({}).error(i18n('versionNotMatched'));
  10828. }
  10829. if (!GM_getValue('notice')) {
  10830. external_Swal_default().fire({
  10831. title: i18n('swalNotice'),
  10832. icon: 'warning'
  10833. }).then(() => {
  10834. window.open(i18n('noticeLink'), '_blank');
  10835. GM_setValue('notice', new Date().getTime());
  10836. });
  10837. scripts_echoLog({
  10838. html: `<li><font class="warning">${i18n('echoNotice', i18n('noticeLink'))}</font></li>`
  10839. }).font?.find('a').on('click', () => {
  10840. GM_setValue('notice', new Date().getTime());
  10841. });
  10842. }
  10843. scripts_updateChecker();
  10844. };
  10845. if (window.location.hostname === 'discord.com') {
  10846. const LocalStorage = window.localStorage;
  10847. if (window.location.hash === '#auth') {
  10848. window.localStorage.removeItem = () => true;
  10849. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10850. if (discordAuth && discordAuth.length > 0) {
  10851. GM_setValue('discordAuth', {
  10852. auth: discordAuth
  10853. });
  10854. window.close();
  10855. external_Swal_default().fire('', i18n('closePageNotice'));
  10856. } else {
  10857. external_Swal_default().fire({
  10858. text: i18n('getDiscordAuthFailed'),
  10859. icon: 'error'
  10860. });
  10861. }
  10862. } else {
  10863. const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
  10864. if (discordAuth && discordAuth.length > 0) {
  10865. GM_setValue('discordAuth', {
  10866. auth: discordAuth
  10867. });
  10868. }
  10869. }
  10870. } else if (window.location.hostname === 'opquests.com') {
  10871. loadScript();
  10872. } else if (window.opener && window.location.host === 'store.steampowered.com' && window.location.pathname === '/') {
  10873. $(() => {
  10874. if ($('[data-miniprofile]').length === 0) {
  10875. return;
  10876. }
  10877. window.onbeforeunload = function(event) {
  10878. GM_setValue('steamStoreAuth', null);
  10879. return null;
  10880. };
  10881. const storeSessionID = document.body.innerHTML.match(/g_sessionID = "(.+?)";/)?.[1];
  10882. if (storeSessionID) {
  10883. GM_setValue('steamStoreAuth', {
  10884. storeSessionID: storeSessionID
  10885. });
  10886. return true;
  10887. }
  10888. });
  10889. } else if (window.opener && window.location.host === 'steamcommunity.com') {
  10890. $(() => {
  10891. window.onbeforeunload = function(event) {
  10892. GM_setValue('steamCommunityAuth', null);
  10893. return null;
  10894. };
  10895. const steam64Id = document.body.innerHTML.match(/g_steamID = "(.+?)";/)?.[1];
  10896. const communitySessionID = document.body.innerHTML.match(/g_sessionID = "(.+?)";/)?.[1];
  10897. const userName = document.body.innerHTML.match(/steamcommunity.com\/id\/(.+?)\//)?.[1];
  10898. const data = {};
  10899. if (steam64Id) {
  10900. data.steam64Id = steam64Id;
  10901. }
  10902. if (userName) {
  10903. data.userName = userName;
  10904. }
  10905. if (communitySessionID) {
  10906. data.communitySessionID = communitySessionID;
  10907. GM_setValue('steamCommunityAuth', data);
  10908. if (GM_getValue('steamCommunityAuth') === 'update') {
  10909. window.close();
  10910. }
  10911. }
  10912. });
  10913. } else {
  10914. if (window.location.hostname === 'key-hub.eu') {
  10915. unsafeWindow.keyhubtracker = 1;
  10916. unsafeWindow.gaData = {};
  10917. }
  10918. $(loadScript);
  10919. }
  10920. }();
  10921. })();