User:Fumple/common.js

//https://gist.github.com/lucasdavila/4331999 var objectjoin = function (object, glue, separator) { if (glue == undefined) glue = '=';

if (separator == undefined) separator = ',';

return $.map(Object.getOwnPropertyNames(object), function (k) { return [k, object[k]].join(glue) }).join(separator); } function mwParse(parsetext) { return new Promise(function (k, no) {       new mw.Api.get({ action: 'parse', text: parsetext, title: mw.config.values.wgPageName, }).done(function (data) { const wikitext = data.parse.text['*']; if (wikitext) { k(wikitext); } else { k("") }       });    }); } $("#i-editadminlist").append("  "); $("#i-editadminlist").children.each(function {    if ($(this)[0].tagName == "table") {        console.log($($(this)[0].children[0]).children.length);    } })

var i_admin_addnew = function{ alert("NOTE: Everything you type here will be processed as wikitext") var u = {}; u["name"] = prompt("Type in the username of the new admin"); if (u["name"] == null || u["name"] == "") { alert("Prompt cancelled or left empty! Admin addition cancelled!"); return; }   u["flag"] = prompt("Type in the new admin's flag code (cancel to leave unknown)"); u["contact"] = prompt("Type in the new admin's contact info (cancel to leave blank)"); u["sig"] = prompt("Type in the users signature prototype (cancel to leave blank)"); u["timezone"] = prompt("Type in the users time zone (cancel to leave blank)"); u["special"] = prompt("What does the user specialize in? (cancel to leave blank)"); u["status"] = prompt("What is the user status? (https://splatoonwiki.org/wiki/Template:Style) Type in the style parameter (for type fullyactive)"); if (u["status"] == null || u["status"] == "") { u["status"] = prompt("Please fill this out, if you want to cancel the admin creation cancel again\nWhat is the user status? (https://splatoonwiki.org/wiki/Template:Style) Type in the style parameter (for type fullyactive)"); if (u["status"] == null || u["status"] == "") { alert("Prompt cancelled or left empty! Admin addition cancelled!"); return; }   }    u["bcrat"] = confirm("Is this user a Bureaucrat?"); u["admin"] = confirm("Is this user a Administrator?"); u["knight"] = confirm("Is this user a Knight?"); u["interface"] = confirm("Is this user a Interface Administrator?"); if (!u["bcrat"] && !u["admin"] && !u["knight"] && !u["interface"]) { alert("No role picked! Admin addition cancelled!"); return; }   var sure = confirm("That's it!\nAre you sure you want to add this person?\n" + objectjoin(u, ' = ', '\n')); if (!sure) { alert("Admin addition cancelled!"); return; }   else { /*       var progress = $("#progress"); alert("Starting addition... Please wait!") if (u["flag"] == null || u["flag"] == "") { u["flag"] = "?" }       progress.html("(1/8) Getting username"); var u_n = await mwParse(" " + u["flag"] + " "); progress.html("(2/8) Getting signature"); var u_sig = await mwParse(u["sig"]); progress.html("(3/8) Getting contact info"); var u_c = await mwParse(u["contact"]) progress.html("(4/8) Getting timezone"); var u_tz = await mwParse(u["timezone"]); progress.html("(5/8) Getting special"); var u_sp = await mwParse(u["special"]) progress.html("(6/8) Getting status"); var u_st = await mwParse(""); progress.html("(7/8) Checking permissions"); if (u["bcrat"]) { var u_1 = "Yes" }       else { var u_1 = "No" }       if (u["admin"]) { var u_2 = "Yes" }       else { var u_2 = "No" }       if (u["knight"]) { var u_3 = "Yes" }       else { var u_3 = "No" }       if (u["interface"]) { var u_4 = "Yes" }       else { var u_4 = "No" }       progress.html("(8/8) Generating and adding final text"); var f = " " + u_n + "  " + u_sig + "  " + u_c + "  " + u_tz + "  " + u_1 + "  " + u_2 + "  " + u_3 + "  " + u_4 + "  " + u_sp + "  " + u_st + "  "; $($("#i-editadminlist")[0].children[0].children[0]).append(f) progress.html("Done");*/ var parsing = [" " + u["flag"] + " ", u["sig"], u["contact"], u["timezone"], u["special"], ""]; var pt = parsing.join(" I-ADMINLIST-SEPERATOR "); mwParse(pt).then(function(wt){           console.log(wt.split(" I-ADMINLIST-SEPERATOR "));console.log(parsing.length)        }); alert("Done") } } $(".i-admin-addnew").click(i_admin_addnew);