User:Andrewds1021/global.js

/* check for Internet Explorer if found: load CSS corrections

if (["MSIE", "Trident/7."].some(function (arg) { return (navigator.userAgent.indexOf(arg) >= 0); })) {   importArticles({        type: "style",        article: "u:w:User:Andrewds1021/IE11.css"    }); }

/* check for "Edit with form" in edit button dropdown if found: check main button for either classic editor or VisualEditor if found: move main button action to top of dropdown move form edit to main button

$(function {    var list_link = document.getElementById("ca-formedit");    if (!list_link) {        return;    }    var list_line = list_link.parentElement;    var list = list_line.parentElement;    var edit_link = list.parentElement.parentElement.previousElementSibling;    var ll_temp = "";    switch (edit_link.id) {        case "ca-viewsource":            ll_temp = list_link.innerHTML;            list_link.innerHTML = edit_link.lastElementChild.innerHTML;            edit_link.lastElementChild.innerHTML = ll_temp;            break;        case "ca-edit":            list_link.accessKey = edit_link.accessKey;            edit_link.removeAttribute("accesskey");            list_link.innerHTML = "Classic editor";            break;        case "ca-ve-edit":            list_link.accessKey = edit_link.accessKey;            edit_link.removeAttribute("accesskey");            list_link.innerHTML = "VisualEditor"; break; default: return; }   ll_temp = list_link.id; list_link.id = edit_link.id; edit_link.id = ll_temp; ll_temp = list_link.getAttribute("data-tracking"); list_link.setAttribute("data-tracking", edit_link.getAttribute("data-tracking")+"-dropdown"); edit_link.setAttribute("data-tracking", ll_temp.replace("-dropdown", "")); ll_temp = list_link.getAttribute("href"); list_link.setAttribute("href", edit_link.getAttribute("href")); edit_link.setAttribute("href", ll_temp); list.insertBefore(list_line, list.firstElementChild); });

/* check for "Create" in main edit button if found: check for both source editor and VisualEditor if found: add "Create with form" as 2nd in dropdown else: add "Create with form" to top of dropdown

$(function {    var ce_link = document.getElementById("ca-edit");    var ve_link = document.getElementById("ca-ve-edit");    if ((!ce_link && !ve_link) || ($(".page-header__contribution-buttons .wds-button-group > a[href*='flow=create-page-create-button']").length <= 0)) {        return;    }    var list = $(".page-header__contribution-buttons ul")[0];    var list_item = document.createElement("li");    var list_link = document.createElement("a");    var link_text = document.createTextNode("Create with form");    list_link.id = "ca-form-create";    list_link.setAttribute("data-tracking", "ca-form-create-dropdown");    list_link.setAttribute("href", "/wiki/Special:FormStart?tfl_formstart_pagename="+encodeURIComponent(location.pathname.substr(6)));    list_link.appendChild(link_text);    list_item.appendChild(list_link);    if (ce_link && ve_link) {        list.insertBefore(list_item, list.children[1]); } else { list.insertBefore(list_item, list.firstElementChild); } });

/* check that page is "Special:FormStart" if true: check for URL query parameter "tfl_formstart_pagename" if found: place value in field for "page_name"

$(function {    if (!document.body.classList.contains("mw-special-FormStart")) { // will not work in older browsers        return;    }    var params = location.search.substr(1).split(/[&=]/);    var param_idx = params.indexOf("tfl_formstart_pagename");    var field = $("form input[name='page_name']")[0];    if (!field || (param_idx == -1) || (param_idx == (params.length-1))) {        return;    }    field.value = decodeURIComponent(params[param_idx+1]); });