User:Paradoxzyx/ace.js

// Ace var params = new URLSearchParams(location.search) //--- Replace "Edit" button with ?action=submit if ($("#ca-edit").length) { //--- Retain "oldid" URL parameter for editing old page revisions (Except when viewing diff) var id = params.get("oldid") id = id && !params.get("diff") ? "&oldid=" + id : "" //--- wds-button class, for if the edit source button is the main edit button or in the dropdown var wds = $("#ca-edit").hasClass("wds-button") ? " class=\"wds-button\"" : "" $("#ca-edit").wrap("").contents.unwrap } else if ($("body").hasClass("mw-special-Whatlinkshere")) { $(".mw-whatlinkshere-tools a").each(function {   if ($(this).is(":last-child")) {      $(this).attr("href", $(this).attr("href").replace("?action=edit", "?action=submit"))    }  }) }

if (mw.config.get("wgAction") == "submit" || (mw.config.get("wgAction") == "edit" && params.get("undo") && params.get("undoafter"))) { //--- Edit Page Styles $("head").append(" #wpTextbox1,#WikiaRailWrapper{display:none !important;}#wpSummary{color:#E6E6E6;background-color:#002B36;border:1px solid #A2A9B1;}.mw-editform #wpSummaryLabel,.templatesUsed{margin-top:0.8em;} ") //--- Ace //--- Create div#editor for ace $("#wpTextbox1").after(" ") $("#editor").text($("#wpTextbox1").text) //--- Edit Buttons $("#wpSave, #wpPreview, #wpDiff").css("width", "135px") $("#wpSave").attr("value", "Save") $("#wpPreview").attr("value", "Preview") $("#wpDiff").attr("value", "Changes") //--- Set mode (mediawiki/lua/javascript/css) -- If it errors, ace will default to text //--- Set tab (4 for CSS, 2 for everything else) var mode = mw.config.get("wgPageContentModel") var tab = 2 if (mode == "wikitext") { mode = "mediawiki" } else if (mode == "Scribunto") { mode = "lua" } else if (mode == "css") { tab = 4 } //--- Load ace $.getScript("https://pagecdn.io/lib/ace/1.4.12/ace.min.js", function {   ace.config.set("basePath", "https://pagecdn.io/lib/ace/1.4.12")    var editor = ace.edit("editor")    //--- Ace options    editor.setOptions({ theme: "ace/theme/solarized_dark", mode: "ace/mode/" + mode, printMargin: false, tabSize: tab, wrap: true, //--- More subjective options //useWorker: false, scrollPastEnd: 0.05 })   //--- CTRL+F opens search & replace by default (CTRL+H)    editor.commands.addCommand({ name: "replaceF", bindKey: { win: "Ctrl-F" }, readOnly: true, exec: function(editor) { ace.config.loadModule("ace/ext/searchbox", function(e) {         e.Search(editor, true)          //--- Prevent pressing CTRL+F from swapping to the search box while the search & replace box is open          var kb = editor.searchBox.$searchBarKb          var command = kb.commandKeyBinding["ctrl-h"]          command.bindKey += "|Ctrl-F"          kb.addCommand(command)        }) }   })    //--- Clone ace content to default textarea on save/preview/diff    $("#wpSave, #wpPreview, #wpDiff").click(function { $("#wpTextbox1").text(editor.getValue) })   $("#editor").show    window.scrollTo(0, 170)  }) }