MediaWiki:Common.js/User:Fumple/PatrolTool.js

function error(data){ $("#funpl-patroltool").css("display", "none"); $("#funpl-patroltool-error").css("display", ""); $("#funpl-patroltool-error-text").text(data); console.error(data); }

var namespaceselect = null;

new mw.Api.get({   "action": "query",    "format": "json",    "meta": "userinfo",    "uiprop": "rights" }).done((data) => {    console.log(data);    if (data.query.userinfo.rights.includes("patrolmarks") && data.query.userinfo.rights.includes("patrol")) {        loadFilters;    }    else if (data.query.userinfo.id != 0) {        $("#funpl-patroltool").css("display", "none");        $("#funpl-patroltool-error").css("display", "");        $("#funpl-patroltool-error-text").html("You can't use this tool as you don't have the correct rights");    }    else {        $("#funpl-patroltool").css("display", "none");        $("#funpl-patroltool-error").css("display", "");        $("#funpl-patroltool-error-text").html("You can't use this tool as you don't have the correct rights You're also logged out, maybe you want to log in"); } }).catch(error); //$("#funpl-patroltool-loading").remove

async function loadFilters{ await mw.loader.load("oojs-ui-widgets"); $("#funpl-patroltool-header").text("Loading namespaces..."); new mw.Api.get({       "action": "query",        "format": "json",        "meta": "siteinfo",        "siprop": "namespaces"    }).done((data) => {        console.log("namespaces", data);        namespaceselect = new OO.ui.MenuTagMultiselectWidget({ "options":[{ "data":"*", "label":"All namespaces" }]       })        var layout = new OO.ui.FieldLayout(namespaceselect, { "align": 'top', "label": 'Select namespaces', "id":"funpl-patroltool-nss" })       for(var nsid in data.query.namespaces){            namespaceselect.addOptions([{ "data":nsid, "label":data.query.namespaces[nsid]["*"] != "" ? data.query.namespaces[nsid]["*"] : "(Main)" }])       }        $("#funpl-patroltool-header").text("Select filters");        $("#funpl-patroltool-loading").remove;        $("#funpl-patroltool").append(layout.$element)    }).catch(error); }