User:Theleekycauldron/Scripts/PSHAW/protocols/hook puller.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. pagename = mw.config.get('wgPageName')

$.when(	mw.loader.using('ext.gadget.morebits'),	$.ready ).then(async function {	console.log("hook puller ready!");	if (pagename == "Template:Did_you_know" || pagename.includes("Template:Did_you_know/Queue/") || pagename.includes("Template:Did_you_know/Preparation_area")) {		$(mw.util.addPortletLink(window.DYKH_portlet || 'p-cactions', '#', 'Pull (PSHAW)', 'dyk-portlet', 'Pull hook')).click(pull);	} });

pull = async function (e) { prep = new Prep(pagename); await prep.initialize; var Window = new Morebits.simpleWindow(900, 500); 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; // render let result; function show{ result = form.render; Window.setContent(result); Window.display; }	// load up the prep/queue console.log("howdy :)");	console.log(form);	form.append({type: 'div',  name: 'prep',         label: "Hook to pull:"});	form.append({type: 'radio', name: 'hooksinprep',  label: 'Hooks:', list: []});	form.root.childs[1].data.list = prep.morebits;	show;	evaluate = async function (e, result){		console.log(result)		let slotnum = result.hooksinprep.value;		if (slotnum == ""){			alert("Which hook is being pulled?");			return;		}		let pulledhook = JSON.parse(result.nomhooks.value);		if (pulledhook == ""){			alert("You can't pull nothing! You're not a magician...");			return;		}

let imgfile; if (result.images==undefined){ imgfile=""; } else { imgfile=result.images.value; }		console.log(imgfile) if (imgfile==""){ //scrub (pictured) from hook if no image hook.content = hook.content.replace(/[^']\(.*?\)/,""); }		if (slotnum == 0 && imgfile == ""){ alert("You can't put this in the lead slot unless you've got an image to go along with it!"); return; }		form.root.childs = []; form.append({type: 'div', name: 'Promoting hook', label: 'Promoting hook to '+prep.title+'... '}) form.append({type: 'div', name: 'Closing nomination', label: 'Closing '+nomination.title+'... '}) show; prep.addHook(hook,slotnum,new File(imgfile)); prep.assemble nomination.hat("yes",prep.title); await nomination.save("To " + prep.title + "").done(function(data){			console.log(data)			form.root.childs[1].data.label += 'done! :)'; show; location.reload(true); });		await prep.save("Promoting " + nomination.title + "").done(function(data){ form.root.childs[0].data.label += 'done! :)';			console.log(form.root.childs[0]);			show;		}); } }

//