User:Theleekycauldron/Scripts/PSHAW/protocols/creditor.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Theleekycauldron/Scripts/PSHAW/protocols/creditor. |
/*<nowiki>
Copyright (c) 2023 theleekycauldron
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
$.when(
mw.loader.using('ext.gadget.morebits'),
$.ready
).then(async function() {
console.log("ready!");
if (mw.config.get('wgPageName').includes("Template:Did_you_know/Queue/")) {
$(mw.util.addPortletLink(window.DYKH_portlet || 'p-cactions', '#', 'Give credits (PSHAW)', 'dyk-portlet', 'Credits')).click(give_credits);
}
});
give_credits = async function (e) {
prep = new Prep(mw.config.get('wgPageName'));
await prep.initialize();
e.preventDefault();
var Window = new Morebits.simpleWindow(700, 400);
Window.setTitle("The prep set's half-assed workbench (PSHAW)");
Window.addFooterLink("DYK promoter's rules", "Wikipedia:Did you know/Prep builder instructions");
var form = new Morebits.quickForm();
let result;
function show(){
result = form.render();
Window.setContent(result);
Window.display();
}
form.append({type: 'div', name: 'header1', label: "<b>User talk credits:</b>"})
form.append({type: 'button', name: 'usertalkselectall', label: "select all", event: () => selectAll(3,true), style: "float: right"})
form.append({type: 'button', name: 'usertalkdeselectall', label: "deselect all", event: () => selectAll(3,false), style: "float: right"})
form.append({type: 'checkbox', name: 'usertalklist', list: []})
function selectAll(c,s){
for (let box of form.root.childs[c].data.list){
box.checked = s;
}
show();
}
for (let hook of prep.hooks){
for (var i=0; i<hook.credits.length; i++){
let credit = hook.credits[i];
form.root.childs[3].data.list.push({type: 'checkbox', label: `[[User:${credit.user}|${credit.user}]], for ${credit.make?"making":"nominating"} [[${credit.article}]]`, value:JSON.stringify(hook)+i, checked: credit.user!="Editor"})
}
}
form.append({type: 'div', name: 'header2', label: "<b>Talk tags:</b>", style:"clear: both"})
form.append({type: 'button', name: 'talkselectall', label: "select all", event: () => selectAll(7,true), style: "float: right"})
form.append({type: 'button', name: 'talkdeselectall', label: "deselect all", event: () => selectAll(7,false), style: "float: right"})
form.append({type: 'checkbox', name: 'talktags', list: []})
for (var i=0; i<prep.hooks.length; i++){
for (var j=0; j<prep.hooks[i].articles.length; j++){
form.root.childs[7].data.list.push({type: 'checkbox', label: `[[${prep.hooks[i].articles[j]}]]`, value:`${i}.${j}`, checked: true})
}
}
form.append({type: 'button', name: 'submit', label: "submit!", event: () => evaluate(e,result), style: "clear: both"})
show();
evaluate = async function(e,result){
form.root.childs = [];
form.append({type: 'div', name: 'messagingusers', label: 'Messaging users... '})
form.append({type: 'div', name: 'taggingtalks', label: 'Tagging talk pages... '})
show();
for (let tag of result.usertalklist){
if (tag.checked){
value = tag.value
ind = value[value.length-1]
value = value.slice(0,value.length-1)
hook = Object.assign(new Hook(0,"",[]), JSON.parse(value));
hook.give_credit(hook.credits[ind]).done(function (data){
console.log(data);
})
}
}
form.root.childs[0].data.label += 'done! :)';
show();
for (let tag of result.talktags){
if (tag.checked){
a = tag.value.split(".")
hook = prep.hooks[a[0]]
hook.tag_talk(hook.articles[a[1]],a[0]==0?prep.file.name:"")
}
}
form.root.childs[1].data.label += 'done! :)';
show();
location.reload(true);
}
}
// </nowiki>