Greasy Fork is available in English.

IG-Owned

indiegala 检测游戏是否已拥有

  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.4
  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 GM_cookie
  49. // @grant unsafeWindow
  50. // @grant window.open
  51. // @require https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js
  52. // @require https://cdn.jsdelivr.net/npm/jquery.easing@1.4.1/jquery.easing.min.js
  53. // @require https://cdn.jsdelivr.net/npm/regenerator-runtime@0.13.7/runtime.min.js
  54. // @require https://cdn.jsdelivr.net/npm/sweetalert2@9
  55. // @require https://cdn.jsdelivr.net/npm/promise-polyfill@8.1.3/dist/polyfill.min.js
  56. // @require https://greasyfork.org/scripts/418102-tm-request/code/TM_request.js?version=902218
  57. // @require https://greasyfork.org/scripts/426803-gistsync/code/gistSync.js?version=957824
  58. // @require https://cdn.jsdelivr.net/npm/overhang@1.0.8/dist/overhang.min.js
  59. // @resource overhang https://cdn.jsdelivr.net/npm/overhang@1.0.8/dist/overhang.min.css
  60. // @connect indiegala.com
  61. // @connect api.github.com
  62. // @run-at document-end
  63. // ==/UserScript==
  64.  
  65. /* global syncIgLib */
  66. (function () {
  67. if (/^https?:\/\/www\.indiegala\.com\/(library|showcase)/.test(window.location.href)) {
  68. var _GM_getValue;
  69.  
  70. var games = _toConsumableArray($.makeArray($('a.library-showcase-title,a.main-list-item-clicker')).map(function (e) {
  71. var _$$attr, _$$attr$match, _$$attr$match$;
  72.  
  73. 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();
  74. })).filter(function (e) {
  75. return e;
  76. });
  77.  
  78. var allGames = ((_GM_getValue = GM_getValue('IG-Owned')) === null || _GM_getValue === void 0 ? void 0 : _GM_getValue.games) || [];
  79. GM_setValue('IG-Owned', {
  80. time: new Date().getTime(),
  81. games: _toConsumableArray(new Set([].concat(_toConsumableArray(allGames), _toConsumableArray(games)))).filter(function (e) {
  82. return e;
  83. })
  84. });
  85. }
  86.  
  87. if (window.location.hostname.includes('.indiegala.com')) {
  88. if ($('i.fa-download:visible').length > 0) {
  89. var _GM_getValue2;
  90.  
  91. var _allGames = ((_GM_getValue2 = GM_getValue('IG-Owned')) === null || _GM_getValue2 === void 0 ? void 0 : _GM_getValue2.games) || [];
  92.  
  93. GM_setValue('IG-Owned', {
  94. time: new Date().getTime(),
  95. games: _toConsumableArray(new Set([].concat(_toConsumableArray(_allGames), [window.location.pathname.replace('/', '')]))).filter(function (e) {
  96. return e;
  97. })
  98. });
  99. }
  100. }
  101.  
  102. var loadTimes = 0;
  103. var observer = new MutationObserver(checkIgOwned);
  104. observer.observe(document.documentElement, {
  105. attributes: false,
  106. characterData: false,
  107. childList: true,
  108. subtree: true
  109. });
  110.  
  111. function checkIgOwned() {
  112. var _GM_getValue3;
  113.  
  114. var first = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  115. loadTimes++;
  116.  
  117. if (loadTimes > 1000) {
  118. observer.disconnect();
  119. return;
  120. }
  121.  
  122. var allGames = (((_GM_getValue3 = GM_getValue('IG-Owned')) === null || _GM_getValue3 === void 0 ? void 0 : _GM_getValue3.games) || []).filter(function (e) {
  123. return e;
  124. });
  125. var igLink = $('a[href*=".indiegala.com"]:not(".ig-checked")');
  126. if (igLink.length === 0) return;
  127. if (first === true) syncIgLib(false, false);
  128.  
  129. var _iterator = _createForOfIteratorHelper($.makeArray(igLink)),
  130. _step;
  131.  
  132. try {
  133. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  134. var el = _step.value;
  135. var $this = $(el).addClass('ig-checked');
  136. var href = $this.attr('href');
  137. console.log(new URL(href).hostname.split('.')[0].toLowerCase());
  138.  
  139. if (/^https?:\/\/.+?\.indiegala\.com/.test(href) && (allGames.includes(new URL(href).pathname.replace(/\//g, '').toLowerCase()) || allGames.includes(new URL(href).hostname.split('.')[0].toLowerCase()))) {
  140. var itemContDiv = $this.parents('.item-cont');
  141.  
  142. if (window.location.hostname === 'www.indiegala.com' && itemContDiv.length > 0) {
  143. itemContDiv.addClass('ig-owned');
  144. } else {
  145. $this.addClass('ig-owned');
  146. }
  147. }
  148. }
  149. } catch (err) {
  150. _iterator.e(err);
  151. } finally {
  152. _iterator.f();
  153. }
  154. }
  155.  
  156. unsafeWindow.syncIgLib = /*#__PURE__*/function () {
  157. var _syncIgLib = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
  158. var _GM_getValue4;
  159.  
  160. var notice,
  161. update,
  162. allGames,
  163. cookies,
  164. _yield$getGames,
  165. _yield$getGames2,
  166. pages,
  167. games,
  168. i,
  169. _yield$getGames3,
  170. _yield$getGames4,
  171. _games,
  172. _args = arguments;
  173.  
  174. return regeneratorRuntime.wrap(function _callee$(_context) {
  175. while (1) {
  176. switch (_context.prev = _context.next) {
  177. case 0:
  178. notice = _args.length > 0 && _args[0] !== undefined ? _args[0] : false;
  179. update = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
  180.  
  181. if (GM_getValue('IG-Verified')) {
  182. _context.next = 5;
  183. break;
  184. }
  185.  
  186. if (notice) {
  187. Swal.fire({
  188. title: '请先完成验证!',
  189. icon: 'error',
  190. html: '<a href="https://www.indiegala.com/library" target="_blank">前往验证</a>',
  191. showCancelButton: true,
  192. confirmButtonText: '老子完成验证了',
  193. cancelButtonText: '关闭'
  194. }).then(function (_ref) {
  195. var value = _ref.value;
  196.  
  197. if (value) {
  198. GM_setValue('IG-Verified', true);
  199. }
  200. });
  201. } else if (!GM_getValue('IG-Ignore')) {
  202. Swal.fire({
  203. title: '[IG-Owned]提醒',
  204. icon: 'error',
  205. html: '获取IG游戏库失败,请<a href="https://www.indiegala.com/library" target="_blank">前往验证</a>',
  206. showCancelButton: true,
  207. showDenyButton: true,
  208. confirmButtonText: '老子完成验证了',
  209. cancelButtonText: '关闭',
  210. denyButtonText: '不再提醒'
  211. }).then(function (_ref2) {
  212. var value = _ref2.value,
  213. isDenied = _ref2.isDenied;
  214.  
  215. if (isDenied) {
  216. GM_setValue('IG-Ignore', true);
  217. return;
  218. }
  219.  
  220. if (value) {
  221. GM_setValue('IG-Verified', true);
  222. }
  223. });
  224. }
  225.  
  226. return _context.abrupt("return", []);
  227.  
  228. case 5:
  229. allGames = ((_GM_getValue4 = GM_getValue('IG-Owned')) === null || _GM_getValue4 === void 0 ? void 0 : _GM_getValue4.games) || [];
  230. _context.next = 8;
  231. return getCookies();
  232.  
  233. case 8:
  234. cookies = _context.sent;
  235. _context.next = 11;
  236. return getGames(1, notice, cookies);
  237.  
  238. case 11:
  239. _yield$getGames = _context.sent;
  240. _yield$getGames2 = _slicedToArray(_yield$getGames, 2);
  241. pages = _yield$getGames2[0];
  242. games = _yield$getGames2[1];
  243.  
  244. if (!(pages === 0)) {
  245. _context.next = 17;
  246. break;
  247. }
  248.  
  249. return _context.abrupt("return");
  250.  
  251. case 17:
  252. allGames = [].concat(_toConsumableArray(allGames), _toConsumableArray(games));
  253.  
  254. if (!(pages > 1 && update)) {
  255. _context.next = 30;
  256. break;
  257. }
  258.  
  259. i = 2;
  260.  
  261. case 20:
  262. if (!(i <= pages)) {
  263. _context.next = 30;
  264. break;
  265. }
  266.  
  267. _context.next = 23;
  268. return getGames(i, notice, cookies);
  269.  
  270. case 23:
  271. _yield$getGames3 = _context.sent;
  272. _yield$getGames4 = _slicedToArray(_yield$getGames3, 2);
  273. _games = _yield$getGames4[1];
  274. allGames = [].concat(_toConsumableArray(allGames), _toConsumableArray(_games));
  275.  
  276. case 27:
  277. i++;
  278. _context.next = 20;
  279. break;
  280.  
  281. case 30:
  282. allGames = _toConsumableArray(new Set(allGames));
  283. GM_setValue('IG-Owned', {
  284. time: new Date().getTime(),
  285. games: allGames.filter(function (e) {
  286. return e;
  287. })
  288. });
  289.  
  290. if (notice) {
  291. Swal.fire({
  292. title: '同步完成!',
  293. icon: 'success'
  294. });
  295. }
  296.  
  297. return _context.abrupt("return", allGames);
  298.  
  299. case 34:
  300. case "end":
  301. return _context.stop();
  302. }
  303. }
  304. }, _callee);
  305. }));
  306.  
  307. function syncIgLib() {
  308. return _syncIgLib.apply(this, arguments);
  309. }
  310.  
  311. return syncIgLib;
  312. }();
  313.  
  314. function getGames(page, notice, cookies) {
  315. if (notice) {
  316. Swal.fire({
  317. title: '正在同步第' + page + '页...',
  318. icon: 'info'
  319. });
  320. }
  321.  
  322. return TM_request({
  323. url: 'https://www.indiegala.com/library/showcase/' + page,
  324. method: 'GET',
  325. timeout: 30000,
  326. retry: 3,
  327. headers: {
  328. cookie: cookies
  329. }
  330. }).then(function (response) {
  331. if (new URL(response.finalUrl).pathname === '/login') {
  332. if (notice) {
  333. Swal.fire({
  334. title: '请先登录!',
  335. icon: 'error',
  336. showCancelButton: true,
  337. confirmButtonText: '登录',
  338. cancelButtonText: '关闭'
  339. }).then(function (_ref3) {
  340. var value = _ref3.value;
  341.  
  342. if (value) {
  343. window.open('https://www.indiegala.com/login', '_blank');
  344. }
  345. });
  346. } else {
  347. $('body').overhang({
  348. type: 'error',
  349. message: 'IG登录凭证已过期,请重新登录<a href="https://www.indiegala.com/login" target="_blank">https://www.indiegala.com/login</a>',
  350. html: true,
  351. closeConfirm: true
  352. });
  353. }
  354.  
  355. return [0, []];
  356. }
  357.  
  358. if (response.status === 200) {
  359. if (response.responseText.includes('Profile locked')) {
  360. if (notice) {
  361. Swal.fire({
  362. title: '请先完成验证!',
  363. icon: 'error',
  364. html: '<a href="https://www.indiegala.com/library" target="_blank">前往验证</a>',
  365. showCancelButton: true,
  366. confirmButtonText: '老子完成验证了',
  367. cancelButtonText: '关闭'
  368. }).then(function (_ref4) {
  369. var value = _ref4.value;
  370.  
  371. if (value) {
  372. GM_setValue('IG-Verified', true);
  373. }
  374. });
  375. }
  376.  
  377. GM_setValue('IG-Verified', false);
  378. return [0, []];
  379. }
  380.  
  381. GM_setValue('IG-Verified', true);
  382. var html = $(response.responseText);
  383. var pages = 1;
  384.  
  385. if (page === 1) {
  386. var _html$find$attr, _html$find$attr$match;
  387.  
  388. 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]);
  389.  
  390. if (!isNaN(lastPageNum)) {
  391. pages = lastPageNum;
  392. }
  393. }
  394.  
  395. var _games2 = _toConsumableArray($.makeArray(html.find('a.library-showcase-title')).map(function (e) {
  396. var _$$attr2, _$$attr2$match, _$$attr2$match$;
  397.  
  398. 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();
  399. })).filter(function (e) {
  400. return e;
  401. });
  402.  
  403. return [pages, _games2];
  404. } else {
  405. console.error(response);
  406.  
  407. if (notice) {
  408. Swal.fire({
  409. title: '获取游戏库数据失败!',
  410. text: response.status,
  411. icon: 'error'
  412. });
  413. }
  414. }
  415. })["catch"](function (error) {
  416. console.error(error);
  417.  
  418. if (notice) {
  419. Swal.fire({
  420. title: '获取游戏库数据失败!',
  421. icon: 'error'
  422. });
  423. }
  424.  
  425. return [0, []];
  426. });
  427. }
  428.  
  429. function getCookies() {
  430. return new Promise(function (resolve, reject) {
  431. GM_cookie.list({
  432. url: 'https://www.indiegala.com/library/showcase/1'
  433. }, function (cookies, error) {
  434. if (!error) {
  435. resolve(cookies.map(function (c) {
  436. return "".concat(c.name, "=").concat(c.value);
  437. }).join(';'));
  438. } else {
  439. reject(error);
  440. }
  441. });
  442. });
  443. }
  444.  
  445. GM_registerMenuCommand('同步游戏库', function () {
  446. syncIgLib(true, true);
  447. });
  448. GM_addStyle('.ig-owned{color:#ffffff !important;background:#5c8a00 !important;}');
  449. GM_addStyle(GM_getResourceText('overhang'));
  450.  
  451. if (!GM_getValue('IG-Owned')) {
  452. Swal.fire({
  453. title: '首次使用IG游戏库检测请先同步!',
  454. icon: 'warning',
  455. showCancelButton: true,
  456. confirmButtonText: '同步',
  457. cancelButtonText: '关闭'
  458. }).then(function (_ref5) {
  459. var value = _ref5.value;
  460.  
  461. if (value) {
  462. syncIgLib(true, true);
  463. }
  464. });
  465. return;
  466. }
  467.  
  468. checkIgOwned(true); // syncIgLib(false, false)
  469. })();