User:Theleekycauldron/Scripts/PSHAW/dependencies/Prep.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. class Prep { constructor(title){ this.title = title.replaceAll("_"," "); //MediaWiki stuff }	async initialize{ await get_pages(this.title,"user|content",null,"older").then((res) => {			this.page   = res			this.content = this.page[0].revisions[0].slots.main.content;			this.loadHooks;			this.loadFiles;		}) }	loadHooks{ let splittext = this.content.split("\n"); let ip = [splittext.indexOf("")+2,splittext.indexOf(""),splittext.indexOf("-->")+1,splittext.indexOf(" ")]; //important split points let hooktext = splittext.slice(ip[0],ip[1]); let creditstext = splittext.slice(ip[2],ip[3]); this.hooks = [] for (var h=0; h 0){ for (let c in creditstext){ let credit = new Credit(creditstext[c]); if (hook.articles.includes(credit.article)){ hook.credits.push(credit) if (!credit.make){ credit.subpage = hook.credits[0].subpage }					}				}			} else { hook.credits.push(new Credit("* ")) if (h==hooktext.length-1){ hook.credits.push(new Credit("* ")) }			}		}	}	loadFiles{ let filetext = this.content.match(/\{\{main page image\/DYK.*?}}/g); this.file = new File(filetext[0]) }	morebits{ let res = [] for (let i=0; i hook.articles.length == 0) }	addHook(hook,slot,file){ if (slot == 0){ this.file = file }		this.hooks[slot] = hook }	assemble{ let res = [] res.push(`${this.title.includes("Queue")?"":""}

Hooks
`)		res.push(this.file.mpi+"")		for (let hook of this.hooks){			res.push("* "+hook.content)		}		res.push(` class=dyk-footer noprint|style=margin-top: 0.5em; text-align: right;
 * Archive
 * Start a new article
 * Nominate an article

Credits
This space is to credit the creators/nominators of the items in this template that in fact appear on the Main Page. If you replace or remove an item before it appears on the Main Page, please revert the promotion of the hook so its template appears again at Template talk:Did you know and add a note to the nomination's template explaining why you removed it. `)		for (let hook of this.hooks){			for (let credit of hook.credits){				res.push(credit.content)			}		}		res.push(` `)		this.content = res.join("\n")		return this.content	}	save(summary){		var params = {				action: 'edit',				title: this.title,				summary: summary+tag,				text: this.content,				format: 'json'			}		return api.postWithToken( 'csrf', params );	} } //