From 070f7d5262cc11325f304936ff2de1b3525a931a Mon Sep 17 00:00:00 2001 From: bhsd <2545473905@qq.com> Date: Sat, 13 Jan 2024 22:47:34 +0800 Subject: [PATCH] fix(libCachedCode): ES module --- .../MediaWiki:Gadget-wikieditor-highlight.js | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/gadgets/wikieditor-highlight/MediaWiki:Gadget-wikieditor-highlight.js b/src/gadgets/wikieditor-highlight/MediaWiki:Gadget-wikieditor-highlight.js index 06f52bf3..6d814c04 100644 --- a/src/gadgets/wikieditor-highlight/MediaWiki:Gadget-wikieditor-highlight.js +++ b/src/gadgets/wikieditor-highlight/MediaWiki:Gadget-wikieditor-highlight.js @@ -11,18 +11,24 @@ const $textarea = $("#wpTextbox1"); const isAdvanced = ["loading", "loaded", "executing", "ready"].includes(mw.loader.getState("ext.wikiEditor")); const lang = mw.config.get("wgNamespaceNumber") === 274 ? "html" : "mediawiki"; - const init = async () => { - await import("https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.2/mw/dist/base.min.js"); - cm = await CodeMirror.fromTextArea($textarea[0], lang); - cm.defaultLint(true); - cm.prefer([ - "highlightSpecialChars", - "highlightActiveLine", - "highlightWhitespace", - "bracketMatching", - "closeBrackets", - ]); - }; + const init = () => new Promise((resolve) => { + const script = document.createElement("script"); + script.addEventListener("load", async () => { + cm = await CodeMirror.fromTextArea($textarea[0], lang); + cm.defaultLint(true); + cm.prefer([ + "highlightSpecialChars", + "highlightActiveLine", + "highlightWhitespace", + "bracketMatching", + "closeBrackets", + ]); + resolve(); + }); + script.type = "module"; + script.src = "https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.2/mw/dist/base.min.js"; + document.head.appendChild(script); + }); if (!isAdvanced) { init(); return;