generals.io+

A simple script that helps you to make generals.io better

目前为 2022-03-06 提交的版本。查看 最新版本

  1. /* eslint-disable no-multi-spaces */
  2.  
  3. // ==UserScript==
  4. // @name generals.io+
  5. // @name:zh-CN generals.io+
  6. // @name:en generals.io+
  7. // @namespace generals.io_plus
  8. // @version 0.4.1
  9. // @description A simple script that helps you to make generals.io better
  10. // @description:zh-CN 一个简单的generals.io增强脚本
  11. // @description:en A simple script that helps you to make generals.io better
  12. // @author PY-DNG
  13. // @license MIT
  14. // @match https://generals.io/*
  15. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMAAAADACAYAAABS3GwHAAAvmElEQVR42u2dd3hc1Znwf+fOSLKq1WWry7bchCuuGGMZE4wpG3YpCbsJKZu2WZIQUnYT8mGZ5EuDfAQI2SUhIWU3EBISMAQCcWwZ9yrbuBdJVu+9jjT3fH+cGWuarDajuZLv73nmeeCOdefcc897znve8xaByeh47TU4ehQsFgtSRgJJQCowDcgGMoAUxyceiAYigTDHxwpojrvZHZ9eoAfoAtqAJqAOqAXKHZ9Kx6cR6HD8HRQUBLtHJiQi2A2YEBQUgBACKaOBTGA2MB812GOBLGA6aqCHA6EMDG5/oQN9KOFoAmqAMqAZJSBnHJ9yhGhHSt0UiqExBcAX7gM+G1gOrALygJmogW4NdjM96EcJRglwEtgLHHH8fzsgTYHwxhQAJ2rQa0iZDCwG8oG1QC5qwFuC3cQRYketDheA94BC4ARqtbCbwqC4dgVgYABEoGb2m4AlqME/A6XKTCZ6UKvBUeA4sBO1UnShafDYY8FuX1C49gRAzfQWpMwE1gP3AKtRuvy10h8SaEGpSX8GdgCXuQZXhmvjhQ+81HDUDP8AcAdq8zrRVBt/Y0dtprcCrwBFQPe1sipMbgFQA19DqTT/hNLrVwFxwW6aQWkB9gPbUAJxCZjU1qTJKQADVpyFwMeAD6KsOf42TU5WJEoleg34JXCKSSoIk0sABmb8ecBHgX9GHUiZjJ4y4GXgt8BpJpkgTA4BUC/ECixDDfw7UQdWJv6j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HaCEBFAHrAQWIZK3pWDWi0mE90oL9udwBHgOHAKdYo7oU2ZY+HaFQBP1MqgIWUysAhV+fJGYDYQz8RTleyoWf48KtBoB3ACqGMCuSoEGlMAfKEGh0BFpWUBy4FVqJViFkog/FNdx3/0A00oh7STwB6Uvb4EKdsRYlJaccaKKQDDwV0gMlGrQpLjMxtlYk1FCUY4ynPV3yZXHeV70wU0opIJXAbOAg2Oz1mU3b6DSW698RemAIyFAbUpCkhECcE0lEBkoJJ+paAEIxrlxToFFdNgYUCtsjs+vUAP0Inyq29EqSy1qFjpMlSB6CrUgO9E1+1ERcHXvx7s3piQ/H+yD9zkcFrfEwAAAABJRU5ErkJggg==
  16. // @grant GM_registerMenuCommand
  17. // @grant GM_unregisterMenuCommand
  18. // @grant GM_getValue
  19. // @grant GM_setValue
  20. // @grant unsafeWindow
  21. // @require https://cdn.jsdelivr.net/gh/MohammadYounes/AlertifyJS@3151fa0d65909936afcbb2f1665ed4f20767bee5/build/alertify.min.js
  22. // @resource alertify-css https://cdn.jsdelivr.net/gh/MohammadYounes/AlertifyJS@3151fa0d65909936afcbb2f1665ed4f20767bee5/build/css/alertify.min.css
  23. // @resource alertify-theme https://cdn.jsdelivr.net/gh/MohammadYounes/AlertifyJS@3151fa0d65909936afcbb2f1665ed4f20767bee5/build/css/themes/default.min.css
  24. // ==/UserScript==
  25.  
  26. (function __MAIN__() {
  27. 'use strict';
  28.  
  29. // Polyfills
  30. const script_name = 'generals.io+';
  31. const script_version = '0.4.1';
  32. const NMonkey_Info = {
  33. GM_info: {
  34. script: {
  35. name: script_name,
  36. author: 'PY-DNG',
  37. version: script_version
  38. }
  39. },
  40. requires: [
  41. {
  42. src: 'https://cdn.jsdelivr.net/gh/MohammadYounes/AlertifyJS@3151fa0d65909936afcbb2f1665ed4f20767bee5/build/alertify.min.js',
  43. loaded: () => (typeof(alertify) === 'object'),
  44. execmode: 'function'
  45. }
  46. ],
  47. resources: [
  48. {
  49. src: 'https://cdn.jsdelivr.net/gh/MohammadYounes/AlertifyJS@3151fa0d65909936afcbb2f1665ed4f20767bee5/build/css/alertify.min.css',
  50. name: 'alertify-css'
  51. },
  52. {
  53. src: 'https://cdn.jsdelivr.net/gh/MohammadYounes/AlertifyJS@3151fa0d65909936afcbb2f1665ed4f20767bee5/build/css/themes/default.min.css',
  54. name: 'alertify-theme'
  55. }
  56. ],
  57. mainFunc: __MAIN__
  58. };
  59. const NMonkey_Ready = NMonkey(NMonkey_Info);
  60. if (!NMonkey_Ready) {return false;}
  61. polyfill_replaceAll();
  62.  
  63. // Constances
  64. const CONST = {
  65. Number: {
  66. Interval: 500
  67. },
  68. Storage: {
  69. Key: {
  70. CustomColor: 'User-Preferred-Color'
  71. }
  72. },
  73. Colors: ['red', 'green', 'lightblue', 'purple', 'teal', 'blue', 'orange', 'maroon', 'yellow', 'pink', 'brown', 'lightgreen', 'purple-blue', 'white'],
  74. Color: {},
  75. Css: {
  76. alertify: '.ajs-content>p {color: black;}',
  77. CustomColor: '.{MC} {background-color: {UCV} !important;} .{UC} {background-color: {MCV} !important;}'
  78. },
  79. Text: {
  80. 'zh-CN': {
  81. CustomColor: '自定义颜色',
  82. EnterColor: '请输入你想要的颜色的英文名称,</br>可用的颜色为{AC},</br>留空即使用服务器提供的颜色:',
  83. ColorTitle: '自定义颜色',
  84. DefaultColor: '',
  85. InvalidColor: '颜色 "{C}" 不受支持!'
  86. },
  87. 'en': {
  88. CustomColor: 'Custom Preferred Color',
  89. EnterColor: 'Enter your preferred color name,</br>Available colors are {AC},</br>Leave it blank if you don\'t want to custom your color: ',
  90. ColorTitle: 'Custom Preferred Color',
  91. DefaultColor: '',
  92. InvalidColor: 'Color "{C}" is not supported!'
  93. },
  94. 'default': {
  95. CustomColor: 'Custom Preferred Color',
  96. EnterColor: 'Enter your preferred color name,</br>Available colors are {AC},</br>Leave it blank if you don\'t want to custom your color: ',
  97. ColorTitle: 'Custom Preferred Color',
  98. DefaultColor: '',
  99. InvalidColor: 'Color "{C}" is not supported!'
  100. }
  101. }
  102. }
  103. for (const color of CONST.Colors) {
  104. CONST.Color[color] = getColorValue(color);
  105. }
  106.  
  107. // Init language
  108. let i18n = navigator.language;
  109. if (!Object.keys(CONST.Text).includes(i18n)) {i18n = 'default';}
  110.  
  111. // Arguments: level=LogLevel.Info, logContent, asObject=false
  112. // Needs one call "DoLog();" to get it initialized before using it!
  113. function DoLog() {
  114. // Get window
  115. const win = (typeof(unsafeWindow) === 'object' && unsafeWindow !== null) ? unsafeWindow : window ;
  116.  
  117. // Global log levels set
  118. win.LogLevel = {
  119. None: 0,
  120. Error: 1,
  121. Success: 2,
  122. Warning: 3,
  123. Info: 4,
  124. }
  125. win.LogLevelMap = {};
  126. win.LogLevelMap[LogLevel.None] = {prefix: '' , color: 'color:#ffffff'}
  127. win.LogLevelMap[LogLevel.Error] = {prefix: '[Error]' , color: 'color:#ff0000'}
  128. win.LogLevelMap[LogLevel.Success] = {prefix: '[Success]' , color: 'color:#00aa00'}
  129. win.LogLevelMap[LogLevel.Warning] = {prefix: '[Warning]' , color: 'color:#ffa500'}
  130. win.LogLevelMap[LogLevel.Info] = {prefix: '[Info]' , color: 'color:#888888'}
  131. win.LogLevelMap[LogLevel.Elements] = {prefix: '[Elements]', color: 'color:#000000'}
  132.  
  133. // Current log level
  134. DoLog.logLevel = win.isPY_DNG ? LogLevel.Info : LogLevel.Warning; // Info Warning Success Error
  135.  
  136. // Log counter
  137. DoLog.logCount === undefined && (DoLog.logCount = 0);
  138. if (++DoLog.logCount > 512) {
  139. console.clear();
  140. DoLog.logCount = 0;
  141. }
  142.  
  143. // Get args
  144. let level, logContent, asObject;
  145. switch (arguments.length) {
  146. case 1:
  147. level = LogLevel.Info;
  148. logContent = arguments[0];
  149. asObject = false;
  150. break;
  151. case 2:
  152. level = arguments[0];
  153. logContent = arguments[1];
  154. asObject = false;
  155. break;
  156. case 3:
  157. level = arguments[0];
  158. logContent = arguments[1];
  159. asObject = arguments[2];
  160. break;
  161. default:
  162. level = LogLevel.Info;
  163. logContent = 'DoLog initialized.';
  164. asObject = false;
  165. break;
  166. }
  167.  
  168. // Log when log level permits
  169. if (level <= DoLog.logLevel) {
  170. let msg = '%c' + LogLevelMap[level].prefix;
  171. let subst = LogLevelMap[level].color;
  172.  
  173. if (asObject) {
  174. msg += ' %o';
  175. } else {
  176. switch(typeof(logContent)) {
  177. case 'string': msg += ' %s'; break;
  178. case 'number': msg += ' %d'; break;
  179. case 'object': msg += ' %o'; break;
  180. }
  181. }
  182.  
  183. console.log(msg, subst, logContent);
  184. }
  185. }
  186. DoLog();
  187.  
  188. let EB;
  189. main();
  190. function main() {
  191. // Common actions
  192. loadinResourceCSS();
  193. myCss();
  194.  
  195. // Event-based actions
  196. EB = new EventBroadcast();
  197. initEvents();
  198. EB.start();
  199.  
  200. // Clear advertisements
  201. EB.addEventListener('nogame', clearAds);
  202.  
  203. // Gaming improvements
  204. EB.addEventListener('gamestart', mapEnhance);
  205.  
  206. // Custom your preferred color
  207. const cfuncs = colorCustom();
  208. EB.addEventListener('gamestart', cfuncs.apply);
  209. EB.addEventListener('gameover', cfuncs.remove);
  210. EB.addEventListener('colorpanel', cfuncs.enable)
  211.  
  212. function initEvents() {
  213. // Game status events
  214. EB.setEventTrigger('game', gaming);
  215. EB.setEventTrigger('nogame', () => (!gaming()));
  216.  
  217. // Game status change events
  218. let game_on = gaming();
  219. EB.setEventTrigger('gamestart', function() {
  220. if (!game_on && gaming()) {
  221. game_on = gaming();
  222. return true;
  223. }
  224. return false;
  225. });
  226. EB.setEventTrigger('gameover', function() {
  227. if (game_on && !gaming()) {
  228. game_on = gaming();
  229. return true;
  230. }
  231. return false;
  232. });
  233.  
  234. // Color-select panel displayed
  235. const display = () => ($('center>div>.supporter-circle') ? true : false);
  236. let display_on = display();
  237. EB.setEventTrigger('colorpanel', function() {
  238. const returnValue = (!display_on && display()) ? true : false;
  239. display_on = display();
  240. return returnValue;
  241. });
  242. }
  243. }
  244.  
  245. function myCss() {
  246. addStyle(CONST.Css.alertify);
  247. }
  248.  
  249. function clearAds() {
  250. const adsSelectors = ['#main-menu-upsell-banner', '#custom-queue-ad', '#custom-queue-ad-skyscraper', '#custom-queue-ad-top', 'center>div.tips-banner+div', '#replay-ad-container'];
  251. $('#custom-queue-content') && ($('#custom-queue-content').style.marginLeft = '0px');
  252. for (const ad of adsSelectors) {
  253. $R(ad);
  254. }
  255. }
  256.  
  257. function mapEnhance() {
  258. const elmMap = $('#gameMap');
  259. const capital = $('.general');
  260.  
  261. markForever();
  262.  
  263. // Once a grid had been visible, keep its type visible forever
  264. function markForever() {
  265. // Data
  266. const grids = elmMap.querySelectorAll('td');
  267. const fields = [];
  268. const mounts = [];
  269. const cities = [];
  270. const capitals = [];
  271.  
  272. // Launch
  273. const interval = setInterval(mark, CONST.Number.Interval*3);
  274. EB.addEventListener('gameover', () => (clearInterval(interval)));
  275. mark();
  276.  
  277. function mark() {
  278. if (!$('#gameMap')) {
  279. clearInterval(interval);
  280. mapEnhance();
  281. return false;
  282. }
  283. for (const grid of grids) {
  284. const classes = grid.className.split(' ');
  285.  
  286. if (classes.includes('city') && !cities.includes(grid)) {
  287. cities.push(grid);
  288. keepBgImage(grid);
  289. DoLog(LogLevel.Success, 'Marked a city.');
  290. } else if (classes.includes('general') && !capitals.includes(grid)) {
  291. capitals.push(grid);
  292. keepBgImage(grid);
  293. DoLog(LogLevel.Success, 'Marked a capital.');
  294. } else if (classes.includes('mountain') && !mounts.includes(grid)) {
  295. mounts.push(grid);
  296. keepBgImage(grid);
  297. DoLog(LogLevel.Success, 'Marked a Mountain.');
  298. } else if (!classes.includes('obstacle') && !fields.includes(grid)) {
  299. fields.push(grid);
  300. }
  301. }
  302.  
  303. for (const visible_grid of mounts.concat(cities).concat(capitals)) {
  304. markVisible(visible_grid);
  305. }
  306. }
  307.  
  308. function keepBgImage(grid) {
  309. const computedStyle = getComputedStyle(grid);
  310. grid.style.backgroundImage = computedStyle.backgroundImage;
  311. grid.style.backgroundRepeat = computedStyle.backgroundRepeat;
  312. grid.style.backgroundPosition = computedStyle.backgroundPosition;
  313. }
  314. function markVisible(grid) {
  315. grid.classList.remove('fog');
  316. }
  317. }
  318. }
  319.  
  320. // Custom preferred Color without premium account
  321. function colorCustom() {
  322. GM_registerMenuCommand(CONST.Text[i18n].CustomColor, custom);
  323. const cssid = 'User-Preferred-Color';
  324.  
  325. function custom() {
  326. const box = alertify.prompt(CONST.Text[i18n].ColorTitle, CONST.Text[i18n].EnterColor.replace('{AC}', CONST.Colors.join(', ')), CONST.Text[i18n].DefaultColor, colorGot, cancel);
  327.  
  328. function colorGot(e, color) {
  329. if (!CONST.Colors.includes(color)) {
  330. alertify.alert(CONST.Text[i18n].InvalidColor);
  331. }
  332. GM_setValue(CONST.Storage.Key.CustomColor, color);
  333. apply();
  334. }
  335.  
  336. function cancel() {}
  337. }
  338.  
  339. function apply() {
  340. // Get color provided by server
  341. const elmMap = $('#gameMap');
  342. const capital = $('.general');
  343. const myColor = getColor(capital);
  344. const myValue = getColorValue(myColor);
  345. const color = GM_getValue(CONST.Storage.Key.CustomColor, '');
  346. color && loadColor(color);
  347.  
  348. // Apply user preferred color
  349. function loadColor(color) {
  350. const userColor = color;
  351. const userValue = getColorValue(userColor);
  352. addStyle(CONST.Css.CustomColor.replace('{MC}', myColor).replace('{MCV}', myValue).replace('{UC}', userColor).replace('{UCV}', userValue), cssid);
  353. }
  354. }
  355.  
  356. function remove() {
  357. $R('#'+cssid);
  358. }
  359.  
  360. function enable() {
  361. const div = $('center>div>.supporter-circle').parentElement;
  362. div.style.pointerEvents = 'auto';
  363. let selected;
  364. for (const span of div.children) {
  365. // Transmition effect
  366. span.style.transitionDuration = '0.3s';
  367.  
  368. // Display current preferred color
  369. const color = span.style.boxShadow.match(/rgb\(\d+, \d+, \d+\)/)[0];
  370. if (isSameColor(color, getColorValue(GM_getValue(CONST.Storage.Key.CustomColor)))) {
  371. span.style.boxShadow = span.style.boxShadow.replace('0px 0px 0px 15px inset', '0px 0px 0px 3px inset');
  372. selected = span;
  373. } else {
  374. span.style.boxShadow = span.style.boxShadow.replace('0px 0px 0px 3px inset', '0px 0px 0px 15px inset');
  375. }
  376.  
  377. // Save when clicked
  378. span.addEventListener('click', circleClick);
  379. }
  380.  
  381. function circleClick(e) {
  382. const span = e.target;
  383. const color = span.style.boxShadow.match(/rgb\(\d+, \d+, \d+\)/)[0];
  384. GM_setValue(CONST.Storage.Key.CustomColor, getColorName(color));
  385.  
  386. // Display
  387. span.style.boxShadow = span.style.boxShadow.replace('0px 0px 0px 15px inset', '0px 0px 0px 3px inset');
  388. selected.style.boxShadow = selected.style.boxShadow.replace('0px 0px 0px 3px inset', '0px 0px 0px 15px inset');
  389. selected = span;
  390. }
  391. }
  392.  
  393. return {
  394. custom: custom,
  395. apply: apply,
  396. remove: remove,
  397. enable: enable
  398. }
  399. }
  400.  
  401. // Whether gameboard exists
  402. function gaming() {
  403. const API = getAPI();
  404. return $('#gameMap .general') && (!API || API[0] !== 'replays') ? true : false;
  405. }
  406.  
  407. // Get the color of a grid
  408. function getColor(grid) {
  409. for (const cls of grid.classList) {
  410. if (CONST.Colors.includes(cls)) {
  411. return cls;
  412. }
  413. }
  414. }
  415.  
  416. // Get the value of color name
  417. function getColorValue(color) {
  418. const elm = document.createElement('td');
  419. elm.classList.add(color);
  420. document.body.appendChild(elm);
  421. const value = getComputedStyle(elm).backgroundColor;
  422. document.body.removeChild(elm);
  423. return value;
  424. }
  425.  
  426. // Get the name of color value
  427. function getColorName(color) {
  428. for (const [name, value] of Object.entries(CONST.Color)) {
  429. if (isSameColor(color, value)) {
  430. return name;
  431. }
  432. }
  433. }
  434.  
  435. // Whether two given color is the same
  436. function isSameColor(c1, c2) {
  437. const rgb = /^rgb/;
  438. c1 = c1.trim().toLowerCase();
  439. c2 = c2.trim().toLowerCase();
  440. !rgb.test(c1) && (c1 = CONST.Color[c1]);
  441. !rgb.test(c2) && (c2 = CONST.Color[c2]);
  442. c1 = c1.replaceAll(', ', ',').replaceAll(' ', ',');
  443. c2 = c2.replaceAll(', ', ',').replaceAll(' ', ',');
  444. return c1 === c2;
  445. }
  446.  
  447. // Basic functions
  448. function $(e) {return document.querySelector(e);}
  449. function $R(e) {const el = $(e); return el && el.parentElement.removeChild(el);}
  450.  
  451. function loadinResourceCSS() {
  452. for (const res of NMonkey_Info.resources) {
  453. const css = GM_getResourceText(res.name);
  454. css && addStyle(css);
  455. }
  456. }
  457.  
  458. function EventBroadcast() {
  459. const EB = this;
  460. const _EB = {};
  461.  
  462. // Init
  463. _EB.event = {};
  464. _EB.time = 500;
  465. _EB.interval = null;
  466. _EB.listeners = {};
  467. defineProxy(EB, _EB, 'event', false);
  468. defineProxy(EB, _EB, 'time', true);
  469. defineProxy(EB, _EB, 'interval', false);
  470.  
  471. // Start listen-interval
  472. setTimeout(EB.start, 0);
  473.  
  474. // Add an event trigger
  475. EB.setEventTrigger = function(eventName, trigger) {
  476. EB.initEvent(eventName);
  477. _EB.event[eventName].trigger = trigger;
  478. }
  479.  
  480. // Add an event listener
  481. EB.addEventListener = function(eventName, eventFunc, once=false) {
  482. const id = makeid();
  483. const listenerObj = {
  484. eventName: eventName,
  485. eventFunc: eventFunc,
  486. once: once
  487. }
  488.  
  489. // Add to event.listeners
  490. EB.initEvent(eventName);
  491. _EB.event[eventName].listeners[id] = listenerObj;
  492.  
  493. // Add to _EB.listeners
  494. _EB.listeners[id] = listenerObj;
  495. }
  496.  
  497. // Remove an event listener
  498. EB.removeEventListener = function(id) {
  499. if (_EB.listeners[id]) {
  500. const listenerObj = _EB.listeners[id];
  501.  
  502. // Remove from event.listeners
  503. delete _EB.event[listenerObj.eventName].listeners[id];
  504.  
  505. // Remove from _EB.listeners
  506. delete _EB.listeners[id];
  507. }
  508. }
  509.  
  510. // Init an event obj
  511. EB.initEvent = function(eventName=null) {
  512. const event = _EB.event[eventName] || {trigger: null, listeners: {}};
  513. !_EB.event[eventName] && Object.defineProperty(event.listeners, 'length', {
  514. configurable: false,
  515. enumerable: false,
  516. get: function() {return Object.keys(event.listeners).length;}
  517. });
  518. eventName && !_EB.event[eventName] && (_EB.event[eventName] = event);
  519. return event;
  520. }
  521.  
  522. // Get all listeners of an event or all events
  523. EB.getEventListeners = function(eventName) {
  524. const event = _EB.event[eventName] || EB.initEvent();
  525. return event.listeners;
  526. }
  527.  
  528. // Remove all event listeners
  529. EB.removeAllListeners = function(eventName=null) {
  530. if (eventName) {
  531. const event = _EB.event[eventName] || EB.initEvent();
  532. for (const [id, listenerObj] of Object.entries(event.listeners)) {
  533. EB.removeEventListener(id);
  534. }
  535. } else {
  536. for (const [id, listenerObj] of Object.entries(_EB.listeners)) {
  537. EB.removeEventListener(id);
  538. }
  539. }
  540. }
  541.  
  542. // Start listening
  543. EB.start = function() {
  544. _EB.interval = setInterval(EB.listen, _EB.time);
  545. }
  546.  
  547. // Stop listening
  548. EB.stop = function() {
  549. clearInterval(_EB.interval);
  550. _EB.interval = null;
  551. }
  552.  
  553. EB.listen = function() {
  554. for (const [eventName, event] of Object.entries(_EB.event)) {
  555. if (event.trigger()) {
  556. DoLog('Dispatching {} event'.replace('{}', eventName));
  557. for (const [id, listenerObj] of Object.entries(event.listeners)) {
  558. listenerObj.eventFunc();
  559. listenerObj.once && EB.removeEventListener(id);
  560. }
  561. }
  562. }
  563. }
  564.  
  565. const makeid = (function() {
  566. let cur = 0;
  567. return function() {
  568. return ++cur;
  569. }
  570. }) ();
  571.  
  572. function defineProxy(outerObj, innerObj, propName, writable) {
  573. Object.defineProperty(outerObj, propName, {
  574. configurable: false,
  575. enumerable: true,
  576. get: function() {
  577. return innerObj[propName];
  578. },
  579. set: function(newValue) {
  580. writable && (innerObj[propName] = newValue);
  581. }
  582. })
  583. }
  584. }
  585.  
  586. // Just stopPropagation and preventDefault
  587. function destroyEvent(e) {
  588. if (!e) {return false;};
  589. if (!e instanceof Event) {return false;};
  590. e.stopPropagation();
  591. e.preventDefault();
  592. }
  593.  
  594. // GM_XHR HOOK: The number of running GM_XHRs in a time must under maxXHR
  595. // Returns the abort function to stop the request anyway(no matter it's still waiting, or requesting)
  596. // (If the request is invalid, such as url === '', will return false and will NOT make this request)
  597. // If the abort function called on a request that is not running(still waiting or finished), there will be NO onabort event
  598. // Requires: function delItem(){...} & function uniqueIDMaker(){...}
  599. function GMXHRHook(maxXHR=5) {
  600. const GM_XHR = GM_xmlhttpRequest;
  601. const getID = uniqueIDMaker();
  602. let todoList = [], ongoingList = [];
  603. GM_xmlhttpRequest = safeGMxhr;
  604.  
  605. function safeGMxhr() {
  606. // Get an id for this request, arrange a request object for it.
  607. const id = getID();
  608. const request = {id: id, args: arguments, aborter: null};
  609.  
  610. // Deal onload function first
  611. dealEndingEvents(request);
  612.  
  613. /* DO NOT DO THIS! KEEP ITS ORIGINAL PROPERTIES!
  614. // Stop invalid requests
  615. if (!validCheck(request)) {
  616. return false;
  617. }
  618. */
  619.  
  620. // Judge if we could start the request now or later?
  621. todoList.push(request);
  622. checkXHR();
  623. return makeAbortFunc(id);
  624.  
  625. // Decrease activeXHRCount while GM_XHR onload;
  626. function dealEndingEvents(request) {
  627. const e = request.args[0];
  628.  
  629. // onload event
  630. const oriOnload = e.onload;
  631. e.onload = function() {
  632. reqFinish(request.id);
  633. checkXHR();
  634. oriOnload ? oriOnload.apply(null, arguments) : function() {};
  635. }
  636.  
  637. // onerror event
  638. const oriOnerror = e.onerror;
  639. e.onerror = function() {
  640. reqFinish(request.id);
  641. checkXHR();
  642. oriOnerror ? oriOnerror.apply(null, arguments) : function() {};
  643. }
  644.  
  645. // ontimeout event
  646. const oriOntimeout = e.ontimeout;
  647. e.ontimeout = function() {
  648. reqFinish(request.id);
  649. checkXHR();
  650. oriOntimeout ? oriOntimeout.apply(null, arguments) : function() {};
  651. }
  652.  
  653. // onabort event
  654. const oriOnabort = e.onabort;
  655. e.onabort = function() {
  656. reqFinish(request.id);
  657. checkXHR();
  658. oriOnabort ? oriOnabort.apply(null, arguments) : function() {};
  659. }
  660. }
  661.  
  662. // Check if the request is invalid
  663. function validCheck(request) {
  664. const e = request.args[0];
  665.  
  666. if (!e.url) {
  667. return false;
  668. }
  669.  
  670. return true;
  671. }
  672.  
  673. // Call a XHR from todoList and push the request object to ongoingList if called
  674. function checkXHR() {
  675. if (ongoingList.length >= maxXHR) {return false;};
  676. if (todoList.length === 0) {return false;};
  677. const req = todoList.shift();
  678. const reqArgs = req.args;
  679. const aborter = GM_XHR.apply(null, reqArgs);
  680. req.aborter = aborter;
  681. ongoingList.push(req);
  682. return req;
  683. }
  684.  
  685. // Make a function that aborts a certain request
  686. function makeAbortFunc(id) {
  687. return function() {
  688. let i;
  689.  
  690. // Check if the request haven't been called
  691. for (i = 0; i < todoList.length; i++) {
  692. const req = todoList[i];
  693. if (req.id === id) {
  694. // found this request: haven't been called
  695. delItem(todoList, i);
  696. return true;
  697. }
  698. }
  699.  
  700. // Check if the request is running now
  701. for (i = 0; i < ongoingList.length; i++) {
  702. const req = todoList[i];
  703. if (req.id === id) {
  704. // found this request: running now
  705. req.aborter();
  706. reqFinish(id);
  707. checkXHR();
  708. }
  709. }
  710.  
  711. // Oh no, this request is already finished...
  712. return false;
  713. }
  714. }
  715.  
  716. // Remove a certain request from ongoingList
  717. function reqFinish(id) {
  718. let i;
  719. for (i = 0; i < ongoingList.length; i++) {
  720. const req = ongoingList[i];
  721. if (req.id === id) {
  722. ongoingList = delItem(ongoingList, i);
  723. return true;
  724. }
  725. }
  726. return false;
  727. }
  728. }
  729. }
  730.  
  731. // Get a url argument from lacation.href
  732. // also recieve a function to deal the matched string
  733. // returns defaultValue if name not found
  734. // Args: name, dealFunc=(function(a) {return a;}), defaultValue=null
  735. function getUrlArgv(details) {
  736. typeof(details) === 'string' && (details = {name: details});
  737. typeof(details) === 'undefined' && (details = {});
  738. if (!details.name) {return null;};
  739.  
  740. const url = details.url ? details.url : location.href;
  741. const name = details.name ? details.name : '';
  742. const dealFunc = details.dealFunc ? details.dealFunc : ((a)=>{return a;});
  743. const defaultValue = details.defaultValue ? details.defaultValue : null;
  744. const matcher = new RegExp(name + '=([^&]+)');
  745. const result = url.match(matcher);
  746. const argv = result ? dealFunc(result[1]) : defaultValue;
  747.  
  748. return argv;
  749. }
  750.  
  751. // Append a style text to document(<head>) with a <style> element
  752. function addStyle(css, id) {
  753. const style = document.createElement("style");
  754. id && (style.id = id);
  755. style.textContent = css;
  756. for (const elm of document.querySelectorAll('#'+id)) {
  757. elm.parentElement && elm.parentElement.removeChild(elm);
  758. }
  759. document.head.appendChild(style);
  760. }
  761.  
  762. // File download function
  763. // details looks like the detail of GM_xmlhttpRequest
  764. // onload function will be called after file saved to disk
  765. function downloadFile(details) {
  766. if (!details.url || !details.name) {return false;};
  767.  
  768. // Configure request object
  769. const requestObj = {
  770. url: details.url,
  771. responseType: 'blob',
  772. onload: function(e) {
  773. // Save file
  774. saveFile(URL.createObjectURL(e.response), details.name);
  775.  
  776. // onload callback
  777. details.onload ? details.onload(e) : function() {};
  778. }
  779. }
  780. if (details.onloadstart ) {requestObj.onloadstart = details.onloadstart;};
  781. if (details.onprogress ) {requestObj.onprogress = details.onprogress;};
  782. if (details.onerror ) {requestObj.onerror = details.onerror;};
  783. if (details.onabort ) {requestObj.onabort = details.onabort;};
  784. if (details.onreadystatechange) {requestObj.onreadystatechange = details.onreadystatechange;};
  785. if (details.ontimeout ) {requestObj.ontimeout = details.ontimeout;};
  786.  
  787. // Send request
  788. GM_xmlhttpRequest(requestObj);
  789. }
  790.  
  791. // get '/' splited API array from a url
  792. function getAPI(url=location.href) {
  793. return url.replace(/https?:\/\/(.*?\.){1,2}.*?\//, '').replace(/\?.*/, '').match(/[^\/]+?(?=(\/|$))/g);
  794. }
  795.  
  796. // get host part from a url(includes '^https://', '/$')
  797. function getHost(url=location.href) {
  798. const match = location.href.match(/https?:\/\/[^\/]+\//);
  799. return match ? match[0] : match;
  800. }
  801.  
  802. function AsyncManager() {
  803. const AM = this;
  804.  
  805. // Ongoing xhr count
  806. this.taskCount = 0;
  807.  
  808. // Whether generate finish events
  809. let finishEvent = false;
  810. Object.defineProperty(this, 'finishEvent', {
  811. configurable: true,
  812. enumerable: true,
  813. get: () => (finishEvent),
  814. set: (b) => {
  815. finishEvent = b;
  816. b && AM.taskCount === 0 && AM.onfinish && AM.onfinish();
  817. }
  818. });
  819.  
  820. // Add one task
  821. this.add = () => (++AM.taskCount);
  822.  
  823. // Finish one task
  824. this.finish = () => ((--AM.taskCount === 0 && AM.finishEvent && AM.onfinish && AM.onfinish(), AM.taskCount));
  825. }
  826.  
  827. // NMonkey By PY-DNG, 2021.07.18 - 2022.02.18, License GPL-3
  828. // NMonkey: Provides GM_Polyfills and make your userscript compatible with non-script-manager environment
  829. // Description:
  830. /*
  831. Simulates a script-manager environment("NMonkey Environment") for non-script-manager browser, load @require & @resource, provides some GM_functions(listed below), and also compatible with script-manager environment.
  832. Provides GM_setValue, GM_getValue, GM_deleteValue, GM_listValues, GM_xmlhttpRequest, GM_openInTab, GM_setClipboard, GM_getResourceText, GM_getResourceURL, GM_addStyle, GM_addElement, GM_log, unsafeWindow(object), GM_info(object)
  833. Also provides an object called GM_POLYFILLED which has the following properties that shows you which GM_functions are actually polyfilled.
  834. Returns true if polyfilled is environment is ready, false for not. Don't worry, just follow the usage below.
  835. */
  836. // Note: DO NOT DEFINE GM-FUNCTION-NAMES IN YOUR CODE. DO NOT DEFINE GM_POLYFILLED AS WELL.
  837. // Note: NMonkey is an advanced version of GM_PolyFill (and BypassXB), it includes more functions than GM_PolyFill, and provides better stability and compatibility. Do NOT use NMonkey and GM_PolyFill (and BypassXB) together in one script.
  838. // Usage:
  839. /*
  840. // ==UserScript==
  841. // @name xxx
  842. // @namespace xxx
  843. // @version 1.0
  844. // ...
  845. // @require https://.../xxx.js
  846. // @require ...
  847. // ...
  848. // @resource https://.../xxx
  849. // @resource ...
  850. // ...
  851. // ==/UserScript==
  852.  
  853. // Use a closure to wrap your code. Make sure you have it a name.
  854. (function YOUR_MAIN_FUNCTION() {
  855. 'use strict';
  856. // Strict mode is optional. You can use strict mode or not as you want.
  857. // Polyfill first. Do NOT do anything before Polyfill.
  858. var NMonkey_Ready = NMonkey({
  859. mainFunc: YOUR_MAIN_FUNCTION,
  860. name: "script-storage-key, aims to separate different scripts' storage area. Use your script's @namespace value if you don't how to fill this field.",
  861. requires: [
  862. {
  863. src: "https://.../xxx.js",
  864. loaded: function() {return boolean_value_shows_whether_this_js_has_already_loaded;}
  865. execmode: "'eval' for eval code in current scope or 'function' for Function(code)() in global scope or 'script' for inserting a <script> element to document.head"
  866. },
  867. ...
  868. ],
  869. resources: [
  870. {
  871. src: "https://.../xxx"
  872. name: "@resource name. Will try to get it from @resource using this name before fetch it from src",
  873. },
  874. ...
  875. ],
  876. GM_info: {
  877. // You can get GM_info object, if you provide this argument(and there is no GM_info provided by the script-manager).
  878. // You can provide any object here, what you provide will be what you get.
  879. // Additionally, two property of NMonkey itself will be attached to GM_info if polyfilled:
  880. // {
  881. // scriptHandler: "NMonkey"
  882. // version: "NMonkey's version, it should look like '0.1'"
  883. // }
  884. // The following is just an example.
  885. script: {
  886. name: 'my first userscript for non-scriptmanager browsers!',
  887. description: 'this script works well both in my PC and my mobile!',
  888. version: '1.0',
  889. released: true,
  890. version_num: 1,
  891. authors: ['Johnson', 'Leecy', 'War Mars']
  892. update_history: {
  893. '0.9': 'First beta version',
  894. '1.0': 'Finally released!'
  895. }
  896. }
  897. surprise: 'if you check GM_info.surprise and you will read this!'
  898. // And property "scriptHandler" & "version" will be attached here
  899. }
  900. });
  901. if (!NMonkey_Ready) {
  902. // Stop executing of polyfilled environment not ready.
  903. // Don't worry, during polyfill progress YOUR_MAIN_FUNCTION will be called twice, and on the second call the polyfilled environment will be ready.
  904. return;
  905. }
  906.  
  907. // Your code here...
  908. // Make sure your code is written after NMonkey be called
  909. if
  910. // ...
  911.  
  912. // Just place NMonkey function code here
  913. function NMonkey(details) {
  914. ...
  915. }
  916. }) ();
  917.  
  918. // Oh you want to write something here? Fine. But code you write here cannot get into the simulated script-manager-environment.
  919. */
  920. function NMonkey(details) {
  921. // Init DoLog
  922. DoLog();
  923.  
  924. // Get argument
  925. const mainFunc = details.mainFunc;
  926. const name = details.name || 'default';
  927. const requires = details.requires || [];
  928. const resources = details.resources || [];
  929. details.GM_info = details.GM_info || {};
  930. details.GM_info.scriptHandler = 'NMonkey';
  931. details.GM_info.version = '1.0';
  932.  
  933. // Run in variable-name-polifilled environment
  934. if (InNPEnvironment()) {
  935. // Already in polifilled environment === polyfill has alredy done, just return
  936. return true;
  937. }
  938.  
  939. // Not in polifilled environment, then polyfill functions and create & move into the environment
  940. // Bypass xbrowser's useless GM_functions
  941. bypassXB();
  942.  
  943. // Start polyfill
  944. const GM_POLYFILL_KEY_STORAGE = 'GM_STORAGE_POLYFILL';
  945. let GM_POLYFILL_storage;
  946. const Supports = {
  947. GetStorage: function() {
  948. let gstorage = localStorage.getItem(GM_POLYFILL_KEY_STORAGE);
  949. gstorage = gstorage ? JSON.parse(gstorage) : {};
  950. let storage = gstorage[name] ? gstorage[name] : {};
  951. return storage;
  952. },
  953.  
  954. SaveStorage: function() {
  955. let gstorage = localStorage.getItem(GM_POLYFILL_KEY_STORAGE);
  956. gstorage = gstorage ? JSON.parse(gstorage) : {};
  957. gstorage[name] = GM_POLYFILL_storage;
  958. localStorage.setItem(GM_POLYFILL_KEY_STORAGE, JSON.stringify(gstorage));
  959. },
  960. };
  961. const Provides = {
  962. // GM_setValue
  963. GM_setValue: function(name, value) {
  964. GM_POLYFILL_storage = Supports.GetStorage();
  965. name = String(name);
  966. GM_POLYFILL_storage[name] = value;
  967. Supports.SaveStorage();
  968. },
  969.  
  970. // GM_getValue
  971. GM_getValue: function(name, defaultValue) {
  972. GM_POLYFILL_storage = Supports.GetStorage();
  973. name = String(name);
  974. if (GM_POLYFILL_storage.hasOwnProperty(name)) {
  975. return GM_POLYFILL_storage[name];
  976. } else {
  977. return defaultValue;
  978. }
  979. },
  980.  
  981. // GM_deleteValue
  982. GM_deleteValue: function(name) {
  983. GM_POLYFILL_storage = Supports.GetStorage();
  984. name = String(name);
  985. if (GM_POLYFILL_storage.hasOwnProperty(name)) {
  986. delete GM_POLYFILL_storage[name];
  987. Supports.SaveStorage();
  988. }
  989. },
  990.  
  991. // GM_listValues
  992. GM_listValues: function() {
  993. GM_POLYFILL_storage = Supports.GetStorage();
  994. return Object.keys(GM_POLYFILL_storage);
  995. },
  996.  
  997. // unsafeWindow
  998. unsafeWindow: window,
  999.  
  1000. // GM_xmlhttpRequest
  1001. // not supported properties of details: synchronous binary nocache revalidate context fetch
  1002. // not supported properties of response(onload arguments[0]): finalUrl
  1003. // ---!IMPORTANT!--- DOES NOT SUPPORT CROSS-ORIGIN REQUESTS!!!!! ---!IMPORTANT!---
  1004. // details.synchronous is not supported as Tampermonkey
  1005. GM_xmlhttpRequest: function(details) {
  1006. const xhr = new XMLHttpRequest();
  1007.  
  1008. // open request
  1009. const openArgs = [details.method, details.url, true];
  1010. if (details.user && details.password) {
  1011. openArgs.push(details.user);
  1012. openArgs.push(details.password);
  1013. }
  1014. xhr.open.apply(xhr, openArgs);
  1015.  
  1016. // set headers
  1017. if (details.headers) {
  1018. for (const key of Object.keys(details.headers)) {
  1019. xhr.setRequestHeader(key, details.headers[key]);
  1020. }
  1021. }
  1022. details.cookie ? xhr.setRequestHeader('cookie', details.cookie) : function () {};
  1023. details.anonymous ? xhr.setRequestHeader('cookie', '') : function () {};
  1024.  
  1025. // properties
  1026. xhr.timeout = details.timeout;
  1027. xhr.responseType = details.responseType;
  1028. details.overrideMimeType ? xhr.overrideMimeType(details.overrideMimeType) : function () {};
  1029.  
  1030. // events
  1031. xhr.onabort = details.onabort;
  1032. xhr.onerror = details.onerror;
  1033. xhr.onloadstart = details.onloadstart;
  1034. xhr.onprogress = details.onprogress;
  1035. xhr.onreadystatechange = details.onreadystatechange;
  1036. xhr.ontimeout = details.ontimeout;
  1037. xhr.onload = function (e) {
  1038. const response = {
  1039. readyState: xhr.readyState,
  1040. status: xhr.status,
  1041. statusText: xhr.statusText,
  1042. responseHeaders: xhr.getAllResponseHeaders(),
  1043. response: xhr.response
  1044. };
  1045. (details.responseType === '' || details.responseType === 'text') ? (response.responseText = xhr.responseText) : function () {};
  1046. (details.responseType === '' || details.responseType === 'document') ? (response.responseXML = xhr.responseXML) : function () {};
  1047. details.onload(response);
  1048. }
  1049.  
  1050. // send request
  1051. details.data ? xhr.send(details.data) : xhr.send();
  1052.  
  1053. return {
  1054. abort: xhr.abort
  1055. };
  1056. },
  1057.  
  1058. // NOTE: options(arg2) is NOT SUPPORTED! if provided, then will just be skipped.
  1059. GM_openInTab: function(url) {
  1060. window.open(url);
  1061. },
  1062.  
  1063. // NOTE: needs to be called in an event handler function, and info(arg2) is NOT SUPPORTED!
  1064. GM_setClipboard: function(text) {
  1065. // Create a new textarea for copying
  1066. const newInput = document.createElement('textarea');
  1067. document.body.appendChild(newInput);
  1068. newInput.value = text;
  1069. newInput.select();
  1070. document.execCommand('copy');
  1071. document.body.removeChild(newInput);
  1072. },
  1073.  
  1074. GM_getResourceText: function(name) {
  1075. const _get = typeof(GM_getResourceText) === 'function' ? GM_getResourceText : () => (null);
  1076. let text = _get(name);
  1077. if (text) {return text;}
  1078. for (const resource of resources) {
  1079. if (resource.name === name) {
  1080. return resource.content ? resource.content : null;
  1081. }
  1082. }
  1083. return null;
  1084. },
  1085.  
  1086. GM_getResourceURL: function(name) {
  1087. const _get = typeof(GM_getResourceURL) === 'function' ? GM_getResourceURL : () => (null);
  1088. let url = _get(name);
  1089. if (url) {return url;}
  1090. for (const resource of resources) {
  1091. if (resource.name === name) {
  1092. return resource.src ? btoa(resource.src) : null;
  1093. }
  1094. }
  1095. return null;
  1096. },
  1097.  
  1098. GM_addStyle: function(css) {
  1099. const style = document.createElement('style');
  1100. style.innerHTML = css;
  1101. document.head.appendChild(style)
  1102. },
  1103.  
  1104. GM_addElement: function() {
  1105. let parent_node, tag_name, attributes;
  1106. const head_elements = ['title', 'base', 'link', 'style', 'meta', 'script', 'noscript'/*, 'template'*/];
  1107. if (arguments.length === 2) {
  1108. tag_name = arguments[0];
  1109. attributes = arguments[1];
  1110. parent_node = head_elements.includes(tag_name.toLowerCase()) ? document.head : document.body;
  1111. } else if (arguments.length === 3) {
  1112. parent_node = arguments[0];
  1113. tag_name = arguments[1];
  1114. attributes = arguments[2];
  1115. }
  1116. const element = document.createElement(tag_name);
  1117. for (const [prop, value] of Object.entries(attributes)) {
  1118. element[prop] = value;
  1119. }
  1120. parent_node.appendChild(element);
  1121. },
  1122.  
  1123. GM_log: function() {
  1124. const args = []
  1125. for (let i = 0; i < arguments.length; i++) {
  1126. args[i] = arguments[i];
  1127. }
  1128. console.log.apply(null, args);
  1129. },
  1130.  
  1131. GM_info: details.GM_info,
  1132.  
  1133. GM: {info: details.GM_info}
  1134. };
  1135. const _GM_POLYFILLED = Provides.GM_POLYFILLED = {};
  1136. for (const pname of Object.keys(Provides)) {
  1137. _GM_POLYFILLED[pname] = true;
  1138. }
  1139.  
  1140. // Create & move into polifilled environment
  1141. ExecInNPEnv();
  1142.  
  1143. return false;
  1144.  
  1145. // Bypass xbrowser's useless GM_functions
  1146. function bypassXB() {
  1147. if (typeof(mbrowser) === 'object' || (typeof(GM_info) === 'object' && GM_info.scriptHandler === 'XMonkey')) {
  1148. // Useless functions in XMonkey 1.0
  1149. const GM_funcs = [
  1150. 'unsafeWindow',
  1151. 'GM_getValue',
  1152. 'GM_setValue',
  1153. 'GM_listValues',
  1154. 'GM_deleteValue',
  1155. 'GM_xmlhttpRequest'
  1156. ];
  1157. for (const GM_func of GM_funcs) {
  1158. window[GM_func] = undefined;
  1159. eval('typeof({F}) === "function" && ({F} = undefined);'.replaceAll('{F}', GM_func));
  1160. }
  1161. // Delete dirty data saved by these stupid functions before
  1162. for (let i = 0; i < localStorage.length; i++) {
  1163. const key = localStorage.key(i);
  1164. const value = localStorage.getItem(key);
  1165. value === '[object Object]' && localStorage.removeItem(key);
  1166. }
  1167. }
  1168. }
  1169.  
  1170. // Check if already in name-predefined environment
  1171. // I think there won't be anyone else wants to use this fxxking variable name...
  1172. function InNPEnvironment() {
  1173. return (typeof(GM_POLYFILLED) === 'object' && GM_POLYFILLED !== null) ? true : false;
  1174. }
  1175.  
  1176. function ExecInNPEnv() {
  1177. const NG = new NameGenerator();
  1178.  
  1179. // Init names
  1180. const tnames = ['context', 'fapply', 'CDATA', 'uneval', 'define', 'module', 'exports', 'window', 'globalThis', 'console', 'cloneInto', 'exportFunction', 'createObjectIn', 'GM', 'GM_info'];
  1181. const pnames = Object.keys(Provides);
  1182. const fnames = tnames.slice();
  1183. const argvlist = [];
  1184. const argvs = [];
  1185.  
  1186. // Add provides
  1187. for (const pname of pnames) {
  1188. !fnames.includes(pname) && fnames.push(pname);
  1189. }
  1190.  
  1191. // Add grants
  1192. if (typeof(GM_info) === 'object' && GM_info.script && GM_info.script.grant) {
  1193. for (const gname of GM_info.script.grant) {
  1194. !fnames.includes(gname) && fnames.push(gname);
  1195. }
  1196. }
  1197.  
  1198. // Make name code
  1199. for (let i = 0; i < fnames.length; i++) {
  1200. const fname = fnames[i];
  1201. const exist = eval('typeof ' + fname) !== 'undefined' ? true : false;
  1202. argvlist[i] = exist ? fname : (Provides.hasOwnProperty(fname) ? 'Provides.'+fname : '');
  1203. argvs[i] = exist ? eval(fname) : (Provides.hasOwnProperty(fname) ? Provides[name] : undefined);
  1204. pnames.includes(fname) && (_GM_POLYFILLED[fname] = !exist);
  1205. }
  1206.  
  1207. // Load all @require and @resource
  1208. loadRequires(requires, resources, function(requires, resources) {
  1209. // Join requirecode
  1210. let requirecode = '';
  1211. for (const require of requires) {
  1212. const mode = require.execmode ? require.execmode : 'eval';
  1213. const content = require.content;
  1214. if (!content) {continue;}
  1215. switch(mode) {
  1216. case 'eval':
  1217. requirecode += content + '\n';
  1218. break;
  1219. case 'function': {
  1220. const func = Function.apply(null, fnames.concat(content));
  1221. func.apply(null, argvs);
  1222. break;
  1223. }
  1224. case 'script': {
  1225. const s = document.createElement('script');
  1226. s.innerHTML = content;
  1227. document.head.appendChild(s);
  1228. break;
  1229. }
  1230. }
  1231.  
  1232. }
  1233.  
  1234. // Make final code & eval
  1235. const varnames = ['NG', 'tnames', 'pnames', 'fnames', 'argvist', 'argvs', 'code', 'finalcode', 'wrapper', 'ExecInNPEnv', 'GM_POLYFILL_KEY_STORAGE', 'GM_POLYFILL_storage', 'InNPEnvironment', 'NameGenerator', 'LocalCDN', 'loadRequires', 'requestText', 'Provides', 'Supports', 'bypassXB', 'details', 'mainFunc', 'name', 'requires', 'resources', '_GM_POLYFILLED', 'NMonkey', 'polyfill_status'];
  1236. const code = requirecode + 'let ' + varnames.join(', ') + ';\n(' + mainFunc.toString() + ') ();';
  1237. const wrapper = Function.apply(null, fnames.concat(code));
  1238. const finalcode = '(' + wrapper.toString() + ').apply(this, [' + argvlist.join(', ') + ']);';
  1239. eval(finalcode);
  1240. });
  1241.  
  1242. function NameGenerator() {
  1243. const NG = this;
  1244. const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1245. let index = [0];
  1246.  
  1247. NG.generate = function() {
  1248. const chars = [];
  1249. indexIncrease();
  1250. for (let i = 0; i < index.length; i++) {
  1251. chars[i] = letters.charAt(index[i]);
  1252. }
  1253. return chars.join('');
  1254. }
  1255.  
  1256. NG.randtext = function(len=32) {
  1257. const chars = [];
  1258. for (let i = 0; i < len; i++) {
  1259. chars[i] = letters[randint(0, letter.length-1)];
  1260. }
  1261. return chars.join('');
  1262. }
  1263.  
  1264. function indexIncrease(i=0) {
  1265. index[i] === undefined && (index[i] = -1);
  1266. ++index[i] >= letters.length && (index[i] = 0, indexIncrease(i+1));
  1267. }
  1268.  
  1269. function randint(min, max) {
  1270. return Math.floor(Math.random() * (max - min + 1)) + min;
  1271. }
  1272. }
  1273. }
  1274.  
  1275. // Load all @require and @resource for non-GM/TM environments (such as Alook javascript extension)
  1276. // Requirements: function AsyncManager(){...}, function LocalCDN(){...}
  1277. function loadRequires(requires, resoures, callback, args=[]) {
  1278. // LocalCDN
  1279. const LCDN = new LocalCDN();
  1280.  
  1281. // AsyncManager
  1282. const AM = new AsyncManager();
  1283. AM.onfinish = function() {
  1284. callback.apply(null, [requires, resoures].concat(args));
  1285. }
  1286.  
  1287. // Load js
  1288. for (const js of requires) {
  1289. !js.loaded() && loadinJs(js);
  1290. }
  1291.  
  1292. // Load resource
  1293. for (const resource of resoures) {
  1294. loadinResource(resource);
  1295. }
  1296.  
  1297. AM.finishEvent = true;
  1298.  
  1299. function loadinJs(js) {
  1300. AM.add();
  1301. LCDN.get(js.src, function(content) {
  1302. js.content = content;
  1303. AM.finish();
  1304. });
  1305. }
  1306.  
  1307. function loadinResource(resource) {
  1308. let content;
  1309. if (typeof(GM_getResourceText) === 'function' && (content = GM_getResourceText(resource.name))) {
  1310. resource.content = content;
  1311. } else {
  1312. AM.add();
  1313. LCDN.get(resource.src, function(content) {
  1314. resource.content = content;
  1315. AM.finish();
  1316. });
  1317. }
  1318. }
  1319. }
  1320.  
  1321. // Loads web resources and saves them to GM-storage
  1322. // Tries to load web resources from GM-storage in subsequent calls
  1323. // Updates resources every $(this.expire) hours, or use $(this.refresh) function to update all resources instantly
  1324. // Dependencies: GM_getValue(), GM_setValue(), requestText(), AsyncManager(), KEY_LOCALCDN
  1325. function LocalCDN() {
  1326. const LC = this;
  1327. const GM_getValue = Provides.GM_getValue, GM_setValue = Provides.GM_setValue;
  1328.  
  1329. const KEY_LOCALCDN = 'LOCAL-CDN';
  1330. const KEY_LOCALCDN_VERSION = 'version';
  1331. const VALUE_LOCALCDN_VERSION = '0.2';
  1332.  
  1333. // Default expire time (by hour)
  1334. LC.expire = 72;
  1335.  
  1336. // Try to get resource content from loaclCDN first, if failed/timeout, request from web && save to LocalCDN
  1337. // Accepts callback only
  1338. // Returns true if got from LocalCDN, false if got from web
  1339. LC.get = function(url, callback, args=[]) {
  1340. const CDN = GM_getValue(KEY_LOCALCDN, {});
  1341. const resource = CDN[url];
  1342. const time = (new Date()).getTime();
  1343.  
  1344. if (resource && !expired(time, resource.time)) {
  1345. callback.apply(null, [resource.content].concat(args));
  1346. return true;
  1347. } else {
  1348. LC.request(url, function(content) {
  1349. callback.apply(null, [content].concat(args));
  1350. });
  1351. return false;
  1352. }
  1353. }
  1354.  
  1355. // Generate resource obj and set to CDN[url]
  1356. // Returns resource obj
  1357. LC.set = function(url, content) {
  1358. const CDN = GM_getValue(KEY_LOCALCDN, {});
  1359. const time = (new Date()).getTime();
  1360. const resource = {
  1361. url: url,
  1362. time: time,
  1363. content: content
  1364. }
  1365. CDN[url] = resource;
  1366. GM_setValue(KEY_LOCALCDN, CDN);
  1367. return resource;
  1368. }
  1369.  
  1370. // Delete one resource from LocalCDN
  1371. LC.delete = function(url) {
  1372. const CDN = GM_getValue(KEY_LOCALCDN, {});
  1373. if (!CDN[url]) {
  1374. return false;
  1375. } else {
  1376. delete CDN[url];
  1377. GM_setValue(KEY_LOCALCDN, CDN);
  1378. return true;
  1379. }
  1380. }
  1381.  
  1382. // Delete all resources in LocalCDN
  1383. LC.clear = function() {
  1384. GM_setValue(KEY_LOCALCDN, {});
  1385. upgradeConfig();
  1386. }
  1387.  
  1388. // List all resource saved in LocalCDN
  1389. LC.list = function() {
  1390. const CDN = GM_getValue(KEY_LOCALCDN, {});
  1391. const urls = LC.listurls();
  1392. const resources = [];
  1393.  
  1394. for (const url of urls) {
  1395. resources.push(CDN[url]);
  1396. }
  1397.  
  1398. return resources;
  1399. }
  1400.  
  1401. // List all resource's url saved in LocalCDN
  1402. LC.listurls = function() {
  1403. const CDN = GM_getValue(KEY_LOCALCDN, {});
  1404. const keys = Object.keys(CDN);
  1405. const urls = [];
  1406.  
  1407. for (const key of keys) {
  1408. if (key === KEY_LOCALCDN_VERSION) {continue;}
  1409. urls.push(key);
  1410. }
  1411.  
  1412. return urls;
  1413. }
  1414.  
  1415. // Request content from web and save it to CDN[url]
  1416. // Accepts callback only
  1417. LC.request = function(url, callback, args=[]) {
  1418. const CDN = GM_getValue(KEY_LOCALCDN, {});
  1419. requestText(url, function(content) {
  1420. LC.set(url, content);
  1421. callback.apply(null, [content].concat(args));
  1422. });
  1423. }
  1424.  
  1425. // Re-request all resources in CDN instantly, ignoring LC.expire
  1426. LC.refresh = function(callback, args=[]) {
  1427. const urls = LC.listurls();
  1428.  
  1429. const AM = new AsyncManager();
  1430. AM.onfinish = function() {
  1431. callback.apply(null, [].concat(args))
  1432. };
  1433.  
  1434. for (const url of urls) {
  1435. AM.add();
  1436. LC.request(url, function() {
  1437. AM.finish();
  1438. });
  1439. }
  1440.  
  1441. AM.finishEvent = true;
  1442. }
  1443.  
  1444. function upgradeConfig() {
  1445. const CDN = GM_getValue(KEY_LOCALCDN, {});
  1446. switch(CDN[KEY_LOCALCDN_VERSION]) {
  1447. case undefined:
  1448. init();
  1449. break;
  1450. case '0.1':
  1451. v01_To_v02();
  1452. logUpgrade();
  1453. break;
  1454. case VALUE_LOCALCDN_VERSION:
  1455. DoLog('LocalCDN is in latest version.');
  1456. break;
  1457. default:
  1458. DoLog(LogLevel.Error, 'LocalCDN.upgradeConfig: Invalid config version({V}) for LocalCDN. '.replace('{V}', CDN[KEY_LOCALCDN_VERSION]));
  1459. }
  1460. CDN[KEY_LOCALCDN_VERSION] = VALUE_LOCALCDN_VERSION;
  1461. GM_setValue(KEY_LOCALCDN, CDN);
  1462.  
  1463. function logUpgrade() {
  1464. DoLog(LogLevel.Success, 'LocalCDN successfully upgraded From v{V1} to v{V2}. '.replaceAll('{V1}', CDN[KEY_LOCALCDN_VERSION]).replaceAll('{V2}', VALUE_LOCALCDN_VERSION));
  1465. }
  1466.  
  1467. function init() {
  1468. // Nothing to do here
  1469. }
  1470.  
  1471. function v01_To_v02() {
  1472. const urls = LC.listurls();
  1473. for (const url of urls) {
  1474. if (url === KEY_LOCALCDN_VERSION) {continue;}
  1475. CDN[url] = {
  1476. url: url,
  1477. time: 0,
  1478. content: CDN[url]
  1479. };
  1480. }
  1481. }
  1482. }
  1483.  
  1484. function clearExpired() {
  1485. const resources = LC.list();
  1486. const time = (new Date()).getTime();
  1487.  
  1488. for (const resource of resources) {
  1489. expired(resource.time, time) && LC.delete(resource.url);
  1490. }
  1491. }
  1492.  
  1493. function expired(t1, t2) {
  1494. return (t2 - t1) > (LC.expire * 60 * 60 * 1000);
  1495. }
  1496.  
  1497. upgradeConfig();
  1498. clearExpired();
  1499. }
  1500.  
  1501. function requestText(url, callback, args=[]) {
  1502. Provides.GM_xmlhttpRequest({
  1503. method: 'GET',
  1504. url: url,
  1505. responseType: 'text',
  1506. onload: function(response) {
  1507. const text = response.responseText;
  1508. const argvs = [text].concat(args);
  1509. callback.apply(null, argvs);
  1510. }
  1511. })
  1512. }
  1513.  
  1514. function AsyncManager() {
  1515. const AM = this;
  1516.  
  1517. // Ongoing xhr count
  1518. this.taskCount = 0;
  1519.  
  1520. // Whether generate finish events
  1521. let finishEvent = false;
  1522. Object.defineProperty(this, 'finishEvent', {
  1523. configurable: true,
  1524. enumerable: true,
  1525. get: () => (finishEvent),
  1526. set: (b) => {
  1527. finishEvent = b;
  1528. b && AM.taskCount === 0 && AM.onfinish && AM.onfinish();
  1529. }
  1530. });
  1531.  
  1532. // Add one task
  1533. this.add = () => (++AM.taskCount);
  1534.  
  1535. // Finish one task
  1536. this.finish = () => ((--AM.taskCount === 0 && AM.finishEvent && AM.onfinish && AM.onfinish(), AM.taskCount));
  1537. }
  1538.  
  1539. // Arguments: level=LogLevel.Info, logContent, asObject=false
  1540. // Needs one call "DoLog();" to get it initialized before using it!
  1541. function DoLog() {
  1542. const win = typeof(unsafeWindow) !== 'undefined' ? unsafeWindow : window;
  1543.  
  1544. // Global log levels set
  1545. win.LogLevel = {
  1546. None: 0,
  1547. Error: 1,
  1548. Success: 2,
  1549. Warning: 3,
  1550. Info: 4,
  1551. }
  1552. win.LogLevelMap = {};
  1553. win.LogLevelMap[LogLevel.None] = {prefix: '' , color: 'color:#ffffff'}
  1554. win.LogLevelMap[LogLevel.Error] = {prefix: '[Error]' , color: 'color:#ff0000'}
  1555. win.LogLevelMap[LogLevel.Success] = {prefix: '[Success]' , color: 'color:#00aa00'}
  1556. win.LogLevelMap[LogLevel.Warning] = {prefix: '[Warning]' , color: 'color:#ffa500'}
  1557. win.LogLevelMap[LogLevel.Info] = {prefix: '[Info]' , color: 'color:#888888'}
  1558. win.LogLevelMap[LogLevel.Elements] = {prefix: '[Elements]', color: 'color:#000000'}
  1559.  
  1560. // Current log level
  1561. DoLog.logLevel = win.isPY_DNG ? LogLevel.Info : LogLevel.Warning; // Info Warning Success Error
  1562.  
  1563. // Log counter
  1564. DoLog.logCount === undefined && (DoLog.logCount = 0);
  1565. if (++DoLog.logCount > 512) {
  1566. console.clear();
  1567. DoLog.logCount = 0;
  1568. }
  1569.  
  1570. // Get args
  1571. let level, logContent, asObject;
  1572. switch (arguments.length) {
  1573. case 1:
  1574. level = LogLevel.Info;
  1575. logContent = arguments[0];
  1576. asObject = false;
  1577. break;
  1578. case 2:
  1579. level = arguments[0];
  1580. logContent = arguments[1];
  1581. asObject = false;
  1582. break;
  1583. case 3:
  1584. level = arguments[0];
  1585. logContent = arguments[1];
  1586. asObject = arguments[2];
  1587. break;
  1588. default:
  1589. level = LogLevel.Info;
  1590. logContent = 'DoLog initialized.';
  1591. asObject = false;
  1592. break;
  1593. }
  1594.  
  1595. // Log when log level permits
  1596. if (level <= DoLog.logLevel) {
  1597. let msg = '%c' + LogLevelMap[level].prefix;
  1598. let subst = LogLevelMap[level].color;
  1599.  
  1600. if (asObject) {
  1601. msg += ' %o';
  1602. } else {
  1603. switch(typeof(logContent)) {
  1604. case 'string': msg += ' %s'; break;
  1605. case 'number': msg += ' %d'; break;
  1606. case 'object': msg += ' %o'; break;
  1607. }
  1608. }
  1609.  
  1610. console.log(msg, subst, logContent);
  1611. }
  1612. }
  1613. }
  1614.  
  1615. // Polyfill String.prototype.replaceAll
  1616. // replaceValue does NOT support regexp match groups($1, $2, etc.)
  1617. function polyfill_replaceAll() {
  1618. String.prototype.replaceAll = String.prototype.replaceAll ? String.prototype.replaceAll : PF_replaceAll;
  1619.  
  1620. function PF_replaceAll(searchValue, replaceValue) {
  1621. const str = String(this);
  1622.  
  1623. if (searchValue instanceof RegExp) {
  1624. const global = RegExp(searchValue, 'g');
  1625. if (/\$/.test(replaceValue)) {console.error('Error: Polyfilled String.protopype.replaceAll does support regexp groups');};
  1626. return str.replace(global, replaceValue);
  1627. } else {
  1628. return str.split(searchValue).join(replaceValue);
  1629. }
  1630. }
  1631. }
  1632.  
  1633. function randint(min, max) {
  1634. return Math.floor(Math.random() * (max - min + 1)) + min;
  1635. }
  1636.  
  1637. // Del a item from an array using its index. Returns the array but can NOT modify the original array directly!!
  1638. function delItem(arr, delIndex) {
  1639. arr = arr.slice(0, delIndex).concat(arr.slice(delIndex+1));
  1640. return arr;
  1641. }
  1642. })();