User:Theleekycauldron/Scripts/PSHAW/protocols/creditor.js

/* 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: "User talk credits:"}) 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 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 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); } } //