IG-Owned

indiegala 检测游戏是否已拥有

目前為 2022-08-12 提交的版本,檢視 最新版本

  1. "use strict";
  2.  
  3. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  4.  
  5. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  6.  
  7. function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  8.  
  9. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  10.  
  11. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  12.  
  13. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  14.  
  15. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  16.  
  17. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  18.  
  19. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  20.  
  21. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  22.  
  23. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
  24.  
  25. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  26.  
  27. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  28.  
  29. // ==UserScript==
  30. // @name IG-Owned
  31. // @namespace IG-Owned
  32. // @version 1.1.2
  33. // @description indiegala 检测游戏是否已拥有
  34. // @author HCLonely
  35. // @license MIT
  36. // @iconURL https://auto-task-test.hclonely.com/img/favicon.ico
  37. // @homepage https://github.com/HCLonely/IG-Helper/
  38. // @supportURL https://github.com/HCLonely/IG-Helper/issues/
  39. // @include *://keylol.com/*
  40. // @include *://*.indiegala.com/*
  41. // @grant GM_setValue
  42. // @grant GM_getValue
  43. // @grant GM_addStyle
  44. // @grant GM_getResourceText
  45. // @grant GM_listValues
  46. // @grant GM_xmlhttpRequest
  47. // @grant GM_registerMenuCommand
  48. // @grant unsafeWindow
  49. // @grant window.open
  50. // @require https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js
  51. // @require https://cdn.jsdelivr.net/npm/jquery.easing@1.4.1/jquery.easing.min.js
  52. // @require https://cdn.jsdelivr.net/npm/regenerator-runtime@0.13.7/runtime.min.js
  53. // @require https://cdn.jsdelivr.net/npm/sweetalert2@9
  54. // @require https://cdn.jsdelivr.net/npm/promise-polyfill@8.1.3/dist/polyfill.min.js
  55. // @require https://gf.qytechs.cn/scripts/418102-tm-request/code/TM_request.js?version=902218
  56. // @require https://gf.qytechs.cn/scripts/426803-gistsync/code/gistSync.js?version=957824
  57. // @require https://cdn.jsdelivr.net/npm/overhang@1.0.8/dist/overhang.min.js
  58. // @resource overhang https://cdn.jsdelivr.net/npm/overhang@1.0.8/dist/overhang.min.css
  59. // @connect indiegala.com
  60. // @connect api.github.com
  61. // @run-at document-end
  62. // ==/UserScript==
  63.  
  64. /* global syncIgLib */
  65. (function () {
  66. if (/^https?:\/\/www\.indiegala\.com\/(library|showcase)/.test(window.location.href)) {
  67. var _GM_getValue;
  68.  
  69. var games = _toConsumableArray($.makeArray($('a.library-showcase-title,a.main-list-item-clicker')).map(function (e) {
  70. var _$$attr, _$$attr$match, _$$attr$match$;
  71.  
  72. return (_$$attr = $(e).attr('href')) === null || _$$attr === void 0 ? void 0 : (_$$attr$match = _$$attr.match(/https:\/\/.*?\.indiegala\.com\/(.*)/)) === null || _$$attr$match === void 0 ? void 0 : (_$$attr$match$ = _$$attr$match[1]) === null || _$$attr$match$ === void 0 ? void 0 : _$$attr$match$.toLowerCase();
  73. })).filter(function (e) {
  74. return e;
  75. });
  76.  
  77. var allGames = ((_GM_getValue = GM_getValue('IG-Owned')) === null || _GM_getValue === void 0 ? void 0 : _GM_getValue.games) || [];
  78. GM_setValue('IG-Owned', {
  79. time: new Date().getTime(),
  80. games: _toConsumableArray(new Set([].concat(_toConsumableArray(allGames), _toConsumableArray(games))))
  81. });
  82. }
  83.  
  84. if (window.location.hostname.includes('.indiegala.com')) {
  85. if ($('i.fa-download:visible').length > 0) {
  86. var _GM_getValue2;
  87.  
  88. var _allGames = ((_GM_getValue2 = GM_getValue('IG-Owned')) === null || _GM_getValue2 === void 0 ? void 0 : _GM_getValue2.games) || [];
  89.  
  90. GM_setValue('IG-Owned', {
  91. time: new Date().getTime(),
  92. games: _toConsumableArray(new Set([].concat(_toConsumableArray(_allGames), [window.location.pathname.replace('/', '')])))
  93. });
  94. }
  95. }
  96.  
  97. var loadTimes = 0;
  98. var observer = new MutationObserver(checkIgOwned);
  99. observer.observe(document.documentElement, {
  100. attributes: false,
  101. characterData: false,
  102. childList: true,
  103. subtree: true
  104. });
  105.  
  106. function checkIgOwned() {
  107. var _GM_getValue3;
  108.  
  109. var first = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  110. loadTimes++;
  111.  
  112. if (loadTimes > 1000) {
  113. observer.disconnect();
  114. return;
  115. }
  116.  
  117. var allGames = ((_GM_getValue3 = GM_getValue('IG-Owned')) === null || _GM_getValue3 === void 0 ? void 0 : _GM_getValue3.games) || [];
  118. var igLink = $('a[href*=".indiegala.com/"]:not(".ig-checked")');
  119. if (igLink.length === 0) return;
  120. if (first === true) syncIgLib(false, false);
  121.  
  122. var _iterator = _createForOfIteratorHelper($.makeArray(igLink)),
  123. _step;
  124.  
  125. try {
  126. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  127. var el = _step.value;
  128. var $this = $(el).addClass('ig-checked');
  129. var href = $this.attr('href');
  130.  
  131. if (/^https?:\/\/.+?\.indiegala\.com\/.+$/.test(href) && allGames.includes(new URL(href).pathname.replace(/\//g, '').toLowerCase())) {
  132. var itemContDiv = $this.parents('.item-cont');
  133.  
  134. if (window.location.hostname === 'www.indiegala.com' && itemContDiv.length > 0) {
  135. itemContDiv.addClass('ig-owned');
  136. } else {
  137. $this.addClass('ig-owned');
  138. }
  139. }
  140. }
  141. } catch (err) {
  142. _iterator.e(err);
  143. } finally {
  144. _iterator.f();
  145. }
  146. }
  147.  
  148. unsafeWindow.syncIgLib = /*#__PURE__*/function () {
  149. var _syncIgLib = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
  150. var _GM_getValue4;
  151.  
  152. var notice,
  153. update,
  154. allGames,
  155. _yield$getGames,
  156. _yield$getGames2,
  157. pages,
  158. games,
  159. i,
  160. _yield$getGames3,
  161. _yield$getGames4,
  162. _games,
  163. _args = arguments;
  164.  
  165. return regeneratorRuntime.wrap(function _callee$(_context) {
  166. while (1) {
  167. switch (_context.prev = _context.next) {
  168. case 0:
  169. notice = _args.length > 0 && _args[0] !== undefined ? _args[0] : false;
  170. update = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
  171.  
  172. if (GM_getValue('IG-Verified')) {
  173. _context.next = 5;
  174. break;
  175. }
  176.  
  177. if (notice) {
  178. Swal.fire({
  179. title: '请先完成验证!',
  180. icon: 'error',
  181. html: '<a href="https://www.indiegala.com/library" target="_blank">前往验证</a>',
  182. showCancelButton: true,
  183. confirmButtonText: '老子完成验证了',
  184. cancelButtonText: '关闭'
  185. }).then(function (_ref) {
  186. var value = _ref.value;
  187.  
  188. if (value) {
  189. GM_setValue('IG-Verified', true);
  190. }
  191. });
  192. } else if (!GM_getValue('IG-Ignore')) {
  193. Swal.fire({
  194. title: '[IG-Owned]提醒',
  195. icon: 'error',
  196. html: '获取IG游戏库失败,请<a href="https://www.indiegala.com/library" target="_blank">前往验证</a>',
  197. showCancelButton: true,
  198. showDenyButton: true,
  199. confirmButtonText: '老子完成验证了',
  200. cancelButtonText: '关闭',
  201. denyButtonText: '不再提醒'
  202. }).then(function (_ref2) {
  203. var value = _ref2.value,
  204. isDenied = _ref2.isDenied;
  205.  
  206. if (isDenied) {
  207. GM_setValue('IG-Ignore', true);
  208. return;
  209. }
  210.  
  211. if (value) {
  212. GM_setValue('IG-Verified', true);
  213. }
  214. });
  215. }
  216.  
  217. return _context.abrupt("return", []);
  218.  
  219. case 5:
  220. allGames = ((_GM_getValue4 = GM_getValue('IG-Owned')) === null || _GM_getValue4 === void 0 ? void 0 : _GM_getValue4.games) || [];
  221. _context.next = 8;
  222. return getGames(1, notice);
  223.  
  224. case 8:
  225. _yield$getGames = _context.sent;
  226. _yield$getGames2 = _slicedToArray(_yield$getGames, 2);
  227. pages = _yield$getGames2[0];
  228. games = _yield$getGames2[1];
  229.  
  230. if (!(pages === 0)) {
  231. _context.next = 14;
  232. break;
  233. }
  234.  
  235. return _context.abrupt("return");
  236.  
  237. case 14:
  238. allGames = [].concat(_toConsumableArray(allGames), _toConsumableArray(games));
  239.  
  240. if (!(pages > 1 && update)) {
  241. _context.next = 27;
  242. break;
  243. }
  244.  
  245. i = 2;
  246.  
  247. case 17:
  248. if (!(i <= pages)) {
  249. _context.next = 27;
  250. break;
  251. }
  252.  
  253. _context.next = 20;
  254. return getGames(i, notice);
  255.  
  256. case 20:
  257. _yield$getGames3 = _context.sent;
  258. _yield$getGames4 = _slicedToArray(_yield$getGames3, 2);
  259. _games = _yield$getGames4[1];
  260. allGames = [].concat(_toConsumableArray(allGames), _toConsumableArray(_games));
  261.  
  262. case 24:
  263. i++;
  264. _context.next = 17;
  265. break;
  266.  
  267. case 27:
  268. allGames = _toConsumableArray(new Set(allGames));
  269. GM_setValue('IG-Owned', {
  270. time: new Date().getTime(),
  271. games: allGames
  272. });
  273.  
  274. if (notice) {
  275. Swal.fire({
  276. title: '同步完成!',
  277. icon: 'success'
  278. });
  279. }
  280.  
  281. return _context.abrupt("return", allGames);
  282.  
  283. case 31:
  284. case "end":
  285. return _context.stop();
  286. }
  287. }
  288. }, _callee);
  289. }));
  290.  
  291. function syncIgLib() {
  292. return _syncIgLib.apply(this, arguments);
  293. }
  294.  
  295. return syncIgLib;
  296. }();
  297.  
  298. function getGames(page, notice) {
  299. if (notice) {
  300. Swal.fire({
  301. title: '正在同步第' + page + '页...',
  302. icon: 'info'
  303. });
  304. }
  305.  
  306. return TM_request({
  307. url: 'https://www.indiegala.com/library/showcase/' + page,
  308. method: 'GET',
  309. timeout: 30000,
  310. retry: 3
  311. }).then(function (response) {
  312. if (new URL(response.finalUrl).pathname === '/login') {
  313. if (notice) {
  314. Swal.fire({
  315. title: '请先登录(不可用)!',
  316. icon: 'error',
  317. showCancelButton: true,
  318. confirmButtonText: '登录(不可用)',
  319. cancelButtonText: '关闭'
  320. }).then(function (_ref3) {
  321. var value = _ref3.value;
  322.  
  323. if (value) {
  324. window.open('https://www.indiegala.com/login', '_blank');
  325. }
  326. });
  327. } else {
  328. $('body').overhang({
  329. type: 'error',
  330. message: 'IG登录(不可用)凭证已过期,请重新登录(不可用)<a href="https://www.indiegala.com/login" target="_blank">https://www.indiegala.com/login</a>',
  331. html: true,
  332. closeConfirm: true
  333. });
  334. }
  335.  
  336. return [0, []];
  337. }
  338.  
  339. if (response.status === 200) {
  340. if (response.responseText.includes('Profile locked')) {
  341. if (notice) {
  342. Swal.fire({
  343. title: '请先完成验证!',
  344. icon: 'error',
  345. html: '<a href="https://www.indiegala.com/library" target="_blank">前往验证</a>',
  346. showCancelButton: true,
  347. confirmButtonText: '老子完成验证了',
  348. cancelButtonText: '关闭'
  349. }).then(function (_ref4) {
  350. var value = _ref4.value;
  351.  
  352. if (value) {
  353. GM_setValue('IG-Verified', true);
  354. }
  355. });
  356. }
  357.  
  358. GM_setValue('IG-Verified', false);
  359. return [0, []];
  360. }
  361.  
  362. GM_setValue('IG-Verified', true);
  363. var html = $(response.responseText);
  364. var pages = 1;
  365.  
  366. if (page === 1) {
  367. var _html$find$attr, _html$find$attr$match;
  368.  
  369. var lastPageNum = parseInt((_html$find$attr = html.find('a.profile-private-page-library-pagination-item[href*="library/showcase"]:has(.fa-angle-double-right)').attr('href')) === null || _html$find$attr === void 0 ? void 0 : (_html$find$attr$match = _html$find$attr.match(/[\d]+/)) === null || _html$find$attr$match === void 0 ? void 0 : _html$find$attr$match[0]);
  370.  
  371. if (!isNaN(lastPageNum)) {
  372. pages = lastPageNum;
  373. }
  374. }
  375.  
  376. var _games2 = _toConsumableArray($.makeArray(html.find('a.library-showcase-title')).map(function (e) {
  377. var _$$attr2, _$$attr2$match, _$$attr2$match$;
  378.  
  379. return (_$$attr2 = $(e).attr('href')) === null || _$$attr2 === void 0 ? void 0 : (_$$attr2$match = _$$attr2.match(/https:\/\/.*?\.indiegala\.com\/(.*)/)) === null || _$$attr2$match === void 0 ? void 0 : (_$$attr2$match$ = _$$attr2$match[1]) === null || _$$attr2$match$ === void 0 ? void 0 : _$$attr2$match$.toLowerCase();
  380. })).filter(function (e) {
  381. return e;
  382. });
  383.  
  384. return [pages, _games2];
  385. } else {
  386. console.error(response);
  387.  
  388. if (notice) {
  389. Swal.fire({
  390. title: '获取游戏库数据失败!',
  391. text: response.status,
  392. icon: 'error'
  393. });
  394. }
  395. }
  396. })["catch"](function (error) {
  397. console.error(error);
  398.  
  399. if (notice) {
  400. Swal.fire({
  401. title: '获取游戏库数据失败!',
  402. icon: 'error'
  403. });
  404. }
  405.  
  406. return [0, []];
  407. });
  408. }
  409.  
  410. GM_registerMenuCommand('同步游戏库', function () {
  411. syncIgLib(true, true);
  412. });
  413. GM_addStyle('.ig-owned{color:#ffffff !important;background:#5c8a00 !important;}');
  414. GM_addStyle(GM_getResourceText('overhang'));
  415.  
  416. if (!GM_getValue('IG-Owned')) {
  417. Swal.fire({
  418. title: '首次使用IG游戏库检测请先同步!',
  419. icon: 'warning',
  420. showCancelButton: true,
  421. confirmButtonText: '同步',
  422. cancelButtonText: '关闭'
  423. }).then(function (_ref5) {
  424. var value = _ref5.value;
  425.  
  426. if (value) {
  427. syncIgLib(true, true);
  428. }
  429. });
  430. return;
  431. }
  432.  
  433. checkIgOwned(true); // syncIgLib(false, false)
  434. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址