User:Fumple/vector.js: Difference between revisions
From Inkipedia, the Splatoon wiki
(Editable var) |
(Update darkmode gadget name) |
||
Line 34: | Line 34: | ||
value: editable ? $("#wpTextbox1").val() : $("pre.mw-code").text(), | value: editable ? $("#wpTextbox1").val() : $("pre.mw-code").text(), | ||
language: {"Scribunto":"lua", "javascript":"javascript", "css":"css"}[mw.config.get("wgPageContentModel")], | language: {"Scribunto":"lua", "javascript":"javascript", "css":"css"}[mw.config.get("wgPageContentModel")], | ||
theme: data.query.gadgets.map(function(el){return el.id}).includes(" | theme: data.query.gadgets.map(function(el){return el.id}).includes("dark-vector") ? "vs-dark" : "vs", | ||
automaticLayout: true, | automaticLayout: true, | ||
readOnly: !editable | readOnly: !editable |
Latest revision as of 19:21, 10 October 2023
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('<link rel="stylesheet" data-name="vs/editor/editor.main" href="https://microsoft.github.io/monaco-editor/node_modules/monaco-editor/min/vs/editor/editor.main.css" />'); $("body").append([ '<script>', ' var require = { paths: { vs: "https://microsoft.github.io/monaco-editor/node_modules/monaco-editor/min/vs" } };', '</script>', '<script src="https://microsoft.github.io/monaco-editor/node_modules/monaco-editor/min/vs/loader.js"></script>', '<script src="https://microsoft.github.io/monaco-editor/node_modules/monaco-editor/min/vs/editor/editor.main.nls.js"></script>', '<script src="https://microsoft.github.io/monaco-editor/node_modules/monaco-editor/min/vs/editor/editor.main.js"></script>' ].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('<div id="vscodeeditor"></div>'); $("pre.mw-code").css("display", "none"); $("#vscodeeditor").css("height", "700px"); } else { $("#wpTextbox1").after('<div id="vscodeeditor"></div>'); $("#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("dark-vector") ? "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) }