User:Fumple/vector.js

if(["Scribunto", "javascript", "css"].includes(mw.config.get("wgPageContentModel")) && ["view", "edit", "submit"].includes(mw.config.get("wgAction"))){ //Load editor (https://github.com/microsoft/monaco-editor/tree/main) $("head").append(''); $("body").append([       ' ',        '    var require = { paths: { vs: "https://microsoft.github.io/monaco-editor/node_modules/monaco-editor/min/vs" } };',        ' ',        ' ',        ' ',        ' '    ].join("\n")); var fplEditorCheck = setInterval(function {       if(($("#wpTextbox1").length != 0 || $("pre.mw-code").length != 0) && typeof monaco != "undefined"){            clearInterval(fplEditorCheck);            var editable = $("#wpTextbox1").length != 0;            if(!editable){                $("pre.mw-code").after(' ');                $("pre.mw-code").css("display", "none");                $("#vscodeeditor").css("height", "700px");            } else {                $("#wpTextbox1").after(' ');                $("#wpTextbox1").css("display", "none");                $("#wpTextbox1").attr("readonly",true);                $("#vscodeeditor").css("height", "700px");            }            new mw.Api.get({ "action": "query", "format": "json", "list": "gadgets", "gaprop": "id", "gaenabledonly": 1 }).then(function(data){ window.fplEditor = monaco.editor.create(document.getElementById('vscodeeditor'), {                   value: editable ? $("#wpTextbox1").val : $("pre.mw-code").text,                    language: {"Scribunto":"lua", "javascript":"javascript", "css":"css"}[mw.config.get("wgPageContentModel")],                    theme: data.query.gadgets.map(function(el){return el.id}).includes("darkmode") ? "vs-dark" : "vs",                    automaticLayout: true,                    readOnly: !editable                }); window.fplEditor.onDidChangeModelContent(function (e) {                   $("#wpTextbox1").val(window.fplEditor.getValue)                }); }).catch(function(ex){ alert("An error occurred, check the console for more details"); console.error(ex); $("#wpTextbox1").css("display", ""); $("#wpTextbox1").attr("readonly",null); $("pre.mw-code").css("display", ""); $("#vscodeeditor").remove; })       }    }, 100) }