User:Paradox-/global.js

// Import //importArticle({ type: "script", article: "u:ucp:User:Paradox-/ace.js" })

// Header Nav //--- Replace "Explore" with "Recent Changes" var r = $("nav .wds-tabs > li").last if ($("> div > a > span", r).text == "Discuss") { //--- Move Discuss to the right r.css({ "position": "absolute", "right": "1%" }) r = r.prev } $(".wds-dropdown", r).remove $(r).append(" Recent Changes  ")

//--- Page Count link to Special:AllPages $(".wds-community-header__counter").wrap("")

//--- Remove "New Page", "Recent Changes" & "Admin Dashboard" $(".wds-community-header__wiki-buttons > .wds-is-secondary").remove

// Edit Dropdown //--- Add "Purge" & "Info" //$(".page-header__contribution-buttons ul.wds-list.wds-is-linked li:nth-child(2)").after("Purge") $(".page-header__contribution-buttons ul.wds-list.wds-is-linked li:nth-child(2)").after("Purge") $("#purge").on("click", function { new mw.Api.post({ action: "purge", pageids: mw.config.get("wgArticleId") }).done(function { location.reload }) }) $(".page-header__contribution-buttons ul.wds-list.wds-is-linked li:nth-child(3)").after("Info</a></li>")

//--- Remove "VisualEditor" & "Talk" $("#ca-ve-edit, #ca-talk").parent.remove

// Remove unrelated footer $("#mixed-content-footer").remove

// Global Nav //--- Move user profile to Header Nav -- & User profile image link to profile $(".wds-global-navigation__user-menu").insertAfter(".wds-community-header__sitename").contents.wrap("</a>").css("cursor", "pointer")

//--- Move notifications to Header Nav $(".wds-global-navigation__notifications-dropdown").prependTo(".wds-community-header__wiki-buttons")

setTimeout(function { //--- Move searchbar to Header Nav  $(".wds-global-navigation__search-container").insertAfter(".wds-community-header__sitename")  //--- Remove searchbar placeholder text  $(".wds-global-navigation__search-input").removeAttr("placeholder")  //--- Remove searchbar search scope  $(".wds-global-navigation__search-scope").remove }, 100)

// Dark Theme if (mw.config.get("wgSiteName") == "UCP Wiki") { $("body").css("background", "#282828") $(".WikiaPageContentWrapper").css("background", "#000000") $("head").append(" #userProfileApp{background:#000000;} ") }

// Ace if (mw.config.get("wgAction") == "edit" || mw.config.get("wgAction") == "submit") { //--- Edit Buttons $("#wpSave").attr("value", "Save") $("#wpPreview").attr("value", "Preview") $("#wpDiff").attr("value", "Changes") //--- Don't use ace for File or Category pages, or pages with less than 10 lines if (mw.config.get("wgNamespaceNumber") == 6 || mw.config.get("wgNamespaceNumber") == 14 || $("#wpTextbox1").text.split(/\n/).length <= 10) { //--- Styles without Ace $("head").append(" #WikiaRailWrapper,.ve-oasis-header__title,.wikiEditor-ui-top{display:none;}.ve-oasis-header{padding:5px 0;}#wpTextbox1{width:100%;height:300px;color:#E6E6E6;background:#002B36;border:1px solid #A2A9B1;font-family:'Monaco','Menlo','Ubuntu Mono','Consolas','source-code-pro',monospace;font-size:13px;line-height:1.5em;white-space:pre-wrap;}#wpSummary{color:#E6E6E6;background-color:#002B36;border:1px solid #A2A9B1;}#wpSave,#wpPreview,#wpDiff{width:135px;}.templatesUsed{margin-top:0.8em;} ") $("#wpTextbox1").focus } else { //--- Styles with Ace $("head").append(" #WikiaRailWrapper,#wpTextbox1,.ve-oasis-header__title,.wikiEditor-ui-top{display:none !important;}.ve-oasis-header{padding:5px 0;}#editor{width:100%;height:660px;font-size:13px;line-height:1.5em;display:none;}#wpSummary{color:#E6E6E6;background-color:#002B36;border:1px solid #A2A9B1;}#wpSave,#wpPreview,#wpDiff{width:135px;}.templatesUsed{margin-top:0.8em;} ") //--- Wait for #wpTextbox1 to exist var interval = setInterval(function {     if ($("#wpTextbox1").length) {        clearInterval(interval)        //--- Create div#editor for ace        $("#wpTextbox1").after("<div id=\"editor\"> <div id=\"statusbar\"> ")        $("#editor").text($("#wpTextbox1").text)        //--- 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 = mode == "css" ? 4 : 2        if (mode == "wikitext") {          mode = "mediawiki"        }        else if (mode == "Scribunto") {          mode = "lua"        }        //--- 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,            tabSize: tab,            printMargin: false,            wrap: true,            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) })           }          })          //--- Load status bar /*         $.getScript("https://pagecdn.io/lib/ace/1.4.12/ext-statusbar.min.js", function {            var StatusBar = ace.require("ace/ext/statusbar").StatusBar            new StatusBar(editor, $("#statusbar")[0])          }) */         //--- Clone ace content to default textarea on save/preview/diff $("#wpSave, #wpPreview, #wpDiff").on("click", function {           $("#wpTextbox1").text(editor.getValue)          }) $("#editor").show editor.focus window.scrollTo(0, 75) })     }    }, 50)  } }

// Lua/CSS/JS Highlight // https://github.com/richleland/pygments-css/blob/master/vim.css // http://minifycode.com/css-minifier/ // https://www.unminify2.com/ if ($(".mw-highlight").length) { if (mw.config.get("wgPageContentModel") == "Scribunto") { $("head").append(" .mw-highlight .kd, .mw-highlight .kr, .mw-highlight .o, .mw-highlight .ow{color:#859900;font-weight:normal}.mw-highlight .nb{color:#268BD2}.mw-highlight .c1, .mw-highlight .cm{color:#657B83}.mw-highlight .s, .mw-highlight .s1, .mw-highlight .s2{color:#2AA198}.mw-highlight .se{color:#A17D2A;font-weight:normal}.mw-highlight .nc, .mw-highlight .nf{color:inherit;font-weight:normal}.mw-highlight .mi{color:#D33682}.mw-highlight .kc{color:#B58900;font-weight:normal} ") } else if (mw.config.get("wgPageContentModel") == "css") { $("head").append(" .mw-highlight .nd, .mw-highlight .nf, .mw-highlight .s1, .mw-highlight .s2, .mw-highlight .sx{color:#2AA198}.mw-highlight .mh, .mw-highlight .mi, .mw-highlight .mf, .mw-highlight .cp{color:#D33682}.mw-highlight .c{color:#657B83}.mw-highlight .nc, .mw-highlight .nn, .mw-highlight .nb{color:#268BD2;font-weight:normal}.mw-highlight .nt{color:#E6E6E6;font-weight:normal}.mw-highlight .o{color:#E6E6E6}.mw-highlight .k{color:#859900;font-weight:normal}.mw-highlight .kt{color:#859900}.mw-highlight .kc{color:#93A1A1;font-weight:normal} ") } else if (mw.config.get("wgPageContentModel") == "javascript") { $("head").append(" .mw-highlight .k, .mw-highlight .o, .mw-highlight .sr{color:#859900;font-weight:normal}.mw-highlight .kc{color:#B58900;font-weight:normal}.mw-highlight .kd, .mw-highlight .nb{color:#268BD2}.mw-highlight .c1, .mw-highlight .cm{color:#657B83}.mw-highlight .s2{color:#2AA198}.mw-highlight .mi, .mw-highlight .mf{color:#D33682} ") } $("head").append(" #WikiaRailWrapper{display:none !important}.mw-highlight pre{counter-reset:line;color:#93A1A1;background:#002B36 !important;font-family:'Monaco','Menlo','Ubuntu Mono','Consolas','source-code-pro',monospace;font-size:13px;line-height:1.5em;white-space:pre-wrap;padding:0 0 0 87px;border:0}.mw-highlight .line:before{content:counter(line);counter-increment:line;position:relative;display:inline-block;color:#D0EDF7;width:42px;text-align:right;margin-left:-87px;margin-right:3.5px;padding-right:13px}.mw-highlight .linebg{position:absolute;background:#01313F;width:55px;margin-left:-87px}.mw-highlight .indent{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWNg0Db1ZVCxc/sPAAd4AlUHlLenAAAAAElFTkSuQmCC) right repeat-y} ") $(".mw-highlight pre").html("<span class=\"line\"> " + $(".mw-highlight pre").html.replace(/^( +)/gm, function(m) { return m.replace(/ (?=  )/g, "<span class=\"indent\">  ") }).replace(/\n/g, "\n<span class=\"line\"> ")) $(".mw-highlight pre").prepend("<div class=\"linebg\" style=\"height:" + $(".mw-highlight pre").css("height") + "\"> ") }

// Tags Report if (mw.config.get("wgPageName") == "Special:TagsReport") { //--- Temporary page style fix /* $(".tags-report .tags-report__input").css("background", "none") $(".wds-dropdown__content").css("color", "#000000") $("#bodyContent").css("font-size", "14px") */ //--- Load All button if ($(".wikia-paginator").length) { $(".tags-report__input").append('<input class="wds-button" id="button-loadall" type="button" value="Load All" style="margin-left:20px">') $("#button-loadall").on("click", function {     history.replaceState(null, "", "Special%3ATagsReport" + (location.search && location.search + "&" || "?") + "limit=" + $(".wikia-paginator li:eq(-2) a").attr("data-page") * (new URLSearchParams(location.search).get("limit") || 25))      location.reload    }) } //--- Main else { function viewbutton(e) { $(".viewbutton").prop("disabled", false) $("#button-" + e.data.id).prop("disabled", true) if (e.data.id == "tags") { $("#table-default").hide $("#table-tags").show }     else { $("#table-tags").hide $("#table-default").show if (e.data.id == "unique") { $("#table-default").css("width", "800px") $(".viewtoggle").hide $(".viewtoggle-o").show }       else { $("#table-default").css("width", "100%") $(".viewtoggle-o").hide $(".viewtoggle").show }       $(".viewpage").each(function {          $(this).attr("rowspan", $(this).attr("data-" + e.data.id))        }) }   }    $(".tags-report__input").append('<input class="wds-button viewbutton" id="button-default" type="button" value="Default" style="margin-left:20px">') $(".tags-report__input").append('<input class="wds-button viewbutton" id="button-unique" type="button" value="Unique Tags" style="margin-left:10px">') $(".tags-report__input").append('<input class="wds-button viewbutton" id="button-tags" type="button" value="Sort By Tags" style="margin-left:10px">') $(".tags-report table").addClass("viewtable").attr("id", "table-default") $("#button-default:enabled").on("click", { id: "default" }, viewbutton) $("#button-default").prop("disabled", true) // Unique Tags $("#button-unique:enabled").on("click", function {     var pages = []      var page = $("#table-default tbody tr:eq(0)")      var text      var tag      var paged = 1      var pageu = 1      var x = true      $("#table-default tbody tr").each(function { tag = [ $.trim($("td:eq(1)", this).text), $.trim($("td:eq(2)", this).text) ] if (text == $("td:eq(0)", this).text) { $("td:eq(0)", this).hide paged++ $.each(pages.reverse, function(i, t) {           if (t[0] == tag[0] && t[1] == tag[1]) {              x = false              return false            }          }) if (x) { $("td:eq(3), td:eq(4)", this).addClass("viewtoggle") pages.push(tag) pageu++ }         else { $(this).addClass("viewtoggle") }         x = true }       else { $("td:eq(0)", page).addClass("viewpage").attr({ "data-default": paged, "data-unique": pageu }).css("vertical-align", "top") $("td:eq(0) a", page).wrap("<div style=\"position:sticky;top:50%\"> ") //.parent.append("<span class=\"viewtoggle-o\"> (" + pageu + ") ") $("td:eq(3), td:eq(4)", page).addClass("viewtoggle") pages = [ tag ] page = $(this) text = $("td:eq(0)", page).text paged = 1 pageu = 1 }     })      $("td:eq(0)", page).addClass("viewpage").attr({ "data-default": paged, "data-unique": pageu }).css("vertical-align", "top")      $("td:eq(0) a", page).wrap("<div style=\"position:sticky;top:50%\"> ")      $("td:eq(3), td:eq(4)", page).addClass("viewtoggle")      $("th:eq(3), th:eq(4)", "#table-default thead").addClass("viewtoggle")      //--- Toggle tables      $("#button-unique:enabled").off("click").on("click", { id: "unique" }, viewbutton)      viewbutton({ data: { id: "unique" } })    }) // Sort by Tags $("#button-tags:enabled").on("click", function {     var tags = {}      var page      var tag      $("#table-default tbody tr").each(function { page = $.trim($("td:eq(0) a", this).parent.html) tag = $.trim($("td:eq(2)", this).text) if (!tags[tag]) { tags[tag] = [ page ] }       else if (!tags[tag].includes(page)) { tags[tag].push(page) }     })      //--- Create table      var table = $(" ").addClass("viewtable").attr("id", "table-tags").width(800).hide.append("  Tag  Pages  ")      $.each(tags, function(tag, pages) { table.append(" <td style=\"vertical-align:top\"><div style=\"position:sticky;top:50%\">" + tag + " (" + pages.length + ")  " + pages.join(" ") + "  ") })     $(".tags-report").append(table)      //--- Toggle tables      $("#button-tags:enabled").off("click").on("click", { id: "tags" }, viewbutton)      viewbutton({ data: { id: "tags" } })    }) } }