DCSS Webtiles Extension Module Loader

Load the DWEM from other Webtiles sites as well.

当前为 2024-04-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name DCSS Webtiles Extension Module Loader
  3. // @description Load the DWEM from other Webtiles sites as well.
  4. // @version 1.1
  5. // @author refracta
  6. // @match http://webzook.net:8080/*
  7. // @match https://crawl.kelbi.org/*
  8. // @match http://crawl.akrasiac.org:8080/*
  9. // @match https://underhound.eu:8080/*
  10. // @match https://cbro.berotato.org:8443/*
  11. // @match http://lazy-life.ddo.jp:8080/*
  12. // @match https://crawl.xtahua.com/*
  13. // @match https://crawl.project357.org/*
  14. // @match http://joy1999.codns.com:8081/*
  15. // @grant none
  16. // @run-at document-start
  17. // @namespace https://greasyfork.org/users/467840
  18. // ==/UserScript==
  19.  
  20. (function () {
  21. 'use strict';
  22. const [head] = document.getElementsByTagName('head');
  23.  
  24. async function haltRequireJS() {
  25. let disableRJSInjection = true;
  26. for (const funcName of ['appendChild', 'insertBefore']) {
  27. head['_' + funcName] = head[funcName];
  28. head[funcName] = function (tag) {
  29. if (disableRJSInjection && (tag.getAttribute('data-requirecontext') !== null || tag.getAttribute('data-requiremodule') !== null)) {
  30. return tag;
  31. }
  32. return this['_' + funcName].apply(this, arguments);
  33. }
  34. }
  35.  
  36. const scripts = head.getElementsByTagName('script');
  37. const rjsScript = Array.from(scripts).find(s => s.src?.endsWith('require.js'));
  38. rjsScript?.remove();
  39.  
  40. const config = (() => {
  41. const dataMain = rjsScript.getAttribute('data-main');
  42. let mainScript = dataMain;
  43. const src = mainScript.split('/');
  44. mainScript = src.pop();
  45. const baseUrl = src.length ? src.join('/') + '/' : './';
  46. mainScript = mainScript.replace(/\.js$/, '');
  47. if (/^\/|:|\?|\.js$/.test(mainScript)) {
  48. mainScript = dataMain;
  49. }
  50. return {deps: [mainScript], baseUrl};
  51. })();
  52.  
  53. window.require = window.define = window.requirejs = undefined;
  54. const newRJSScript = document.createElement('script');
  55. newRJSScript.src = rjsScript.src;
  56. await new Promise(resolve => {
  57. newRJSScript.onload = newRJSScript.onreadystatechange = () => {
  58. if (!newRJSScript.readyState || /loaded|complete/.test(newRJSScript.readyState)) {
  59. newRJSScript.onload = newRJSScript.onreadystatechange = null;
  60. resolve();
  61. }
  62. };
  63. head.appendChild(newRJSScript);
  64. });
  65.  
  66. window.startMainScript = async () => {
  67. disableRJSInjection = false;
  68. require.config(config);
  69. };
  70. }
  71.  
  72. (async () => {
  73. await haltRequireJS();
  74. if (localStorage.DWEM_DEBUG === 'true') {
  75. await import(localStorage.DWEM_DEBUG_LOADER);
  76. } else {
  77. try {
  78. await import('https://refracta.github.io/dcss-webtiles-extension-module/loader/dwem-core-loader.js');
  79. } catch (e) {
  80. await import('https://cdn.jsdelivr.net/gh/refracta/dcss-webtiles-extension-module/loader/dwem-base-loader.js');
  81. }
  82. }
  83. })();
  84. })();