MediaWiki:Gadget-oneclick.js
Nota: Depois de publicar, deve limpar o cachê do seu navegador para ver as alterações.
- Firefox e Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Internet Explorer e Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
- Opera: Pressione Ctrl-F5.
//baseado em User:Awesome Aasim/oneclickdelete.js de en.wiki
//<nowiki>
if (mw.config.get("wgNamespaceNumber") >= 0 && mw.config.get("wgIsProbablyEditable")) {
var oneClick = {};
$(document).ready(function() {
oneClick.addReason = function(reason, tag) {
oneClick.reasons.push([tag, reason]);
//oneClick.tag[reason] = tag;
};
oneClick.addTag = function(reason) {
if (reason) {
console.log("Obtendo wikitexto…");
$.get(mw.config.get("wgScriptPath") + "/api.php", {
"action": "parse",
"prop": "wikitext",
"page": mw.config.get("wgPageName"),
"format": "json"
}).done(function(result) {
if (result.error) {
mw.notify($("<span class=\"error\">" + result.error.info + "</span>"));
} else if (result.parse.wikitext["*"].toLowerCase().substring(0, 100).includes("{{arquivada") || result.parse.wikitext["*"].toLowerCase().substring(0, 100).includes("{{arquivada")) {
mw.notify($("<span class=\"error\">" + "Pagina já marcada como arquivada." + "</span>"));
} else {
console.log("Obtendo token…");
$.get(mw.config.get("wgScriptPath") + "/api.php", {
"action": "query",
"meta": "tokens",
"type": "csrf",
"format": "json"
}).done(function(token) {
if (token.error) {
mw.notify($("<span class=\"error\">" + token.error.info + "</span>"));
} else {
console.log("Salvando…");
var newwikitext = result.parse.wikitext["*"];
$.post(mw.config.get("wgScriptPath") + '/api.php', {
"action": "edit",
"format": "json",
"title": mw.config.get("wgPageName"),
"appendtext": "\n{{" + reason + "}}",
"summary": "Adicionando {{" + reason + "}}",
"nocreate": "1",
"minor": "1",
"token": token.query.tokens.csrftoken
}).done(function(editresult) {
if (editresult.error) {
mw.notify($("<span class=\"error\">" + editresult.error.info + "</span>"));
} else {
location.href = "/wiki/" + mw.config.get("wgPageName");
}
}).fail(function(editresult) {
mw.notify("<span class=\"error\">" + editresult + "</span>");
});
}
}).fail(function(token) {
mw.notify($("<span class=\"error\">" + token + "</span>"));
});
}
}).fail(function(result) {
mw.notify($("<span class=\"error\">" + result + "</span>"));
});
}
};
oneClick.protect = function(reason, tag) {
console.log("Obtendo token…");
$.get(mw.config.get("wgScriptPath") + "/api.php", {
"action": "query",
"meta": "tokens",
"type": "csrf",
"format": "json"
}).done(function(token) {
if (token.error) {
mw.notify($("<span class=\"error\">" + token.error.info + "</span>"));
} else {
var temp = tag.substring(3, 6);
if (temp.toLowerCase() != "st:" && temp.toLowerCase() != "c1") {
$.post(mw.config.get("wgScriptPath") + '/api.php', {
"action": "protect",
"format": "json",
"title": mw.config.get("wgPageName"),
"expiry": "infinity",
"protections": "edit=sysop|move=sysop",
"reason": reason,
"token": token.query.tokens.csrftoken
}).done(function(editresult) {
if (editresult.error) {
mw.notify($("<span class=\"error\">" + editresult.error.info + "</span>"));
} else {
location.href = "/wiki/" + mw.config.get("wgPageName");
}
}).fail(function(editresult) {
mw.notify("<span class=\"error\">" + editresult + "</span>");
});
}
}
}).fail(function(token) {
mw.notify($("<span class=\"error\">" + token + "</span>"));
});
};
oneClick.select = $('<select name="deletiontemplate" style="width:20px; background: #fff; border:0;" id="qcsd-dropdown" class="mw-ui-input"/>');
oneClick.el = $('<div class="mw-indicator"><form id="qcsd"></form></div>');
$.get(mw.config.get("wgScriptPath") + "/api.php", {
"action": "parse",
"prop": "wikitext",
"format": "json",
"page": mw.config.get("wgPageName")
}).done(function(result) {
if (!result.error) {
// reasons begin
oneClick.reasons = [];
oneClick.addReason("[[WN:POP|Arquivo de notícia]]", "arquivada");
oneClick.select.append($('<option />').prop('disabled', true).prop('selected', true).text(""));
oneClick.select.append($('<option />').attr('value', '').text("Cancelar"));
oneClick.select.change(function(e) {
//debugger;
oneClick.select.prop("disabled", true);
if (mw.config.get("wgUserGroups").includes("sysop")) {
oneClick.protect($("#qcsd-dropdown option:selected").text(), $("#qcsd-dropdown").val());
} if (mw.config.get("wgUserGroups").includes("sysop")) {
oneClick.addTag($("#qcsd-dropdown").val());
}
});
oneClick.reasons.forEach(function(r) {
if (r[0] == "-") {
oneClick.select.append($('<option />').prop('disabled', true).text(r[1]));
} else {
oneClick.select.append($('<option />').attr('value', r[0]).text("\xA0\xA0" + r[1]));
}
});
if (mw.config.get("skin") == "vector-2022") {
oneClick.el.appendTo("#siteNotice");
} else { oneClick.el.appendTo("#siteNotice");
}
if (mw.config.get("skin") != "minerva") {
oneClick.el.css({"float": "right", "margin-right": "10px"});
}
oneClick.select.appendTo("#qcsd");
}
}).fail(function(result) {
});
});
}
//</nowiki>