User:Theleekycauldron/Scripts/PSHAW/dependencies/Nomination.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 Nomination { constructor(title){ this.title = title.replaceAll("_"," "); //MediaWiki stuff get_pages(this.title,"user|content",null,"older").then((res) => {			this.page   = res			this.content = this.page[0].revisions[0].slots.main.content;			this.isHatted = this.content.includes("No further edits should be made to this page.")			this.isApproved = this.content.includes("") || this.content.includes("") || this.content.match(/\|.*?status.*?=.*?y/g) != undefined			this.alphanumericals="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";			this.loadHooks;			this.loadFiles;		}); }

hasBeenEditedByUser{ for (let revision of this.page[0].revisions){ if (revision.user==mw.config.get('wgUserName')){ return true }		}		return false }	hat(type,prep="",topmessage=""){ var splittext = this.content.split("\n"); splittext[0] = "{{subst:DYKsubpage"; splittext[2] = "|passed="+type; console.log(topmessage) if (topmessage != ""){ splittext.splice(4,0,topmessage); }		this.content = splittext.join("\n"); return this.content }	loadHooks{ this.hooks = [] console.log(this.content) let credits = this.content.match(/\* \{\{DYK(make|nom).*?\}\}/g); if (credits == null){ credits = ["* "] }		let hooktext = this.content.match(/('''ALT.+?)?(\.\.\..*?)(?:|\?)/g); console.log(hooktext) let u=0; for (let hook of hooktext){ hook = hook.split("..."); if (hook[0].includes("ALT")){ let i;				for (i=hook[0].indexOf("ALT")+3; this.alphanumericals.includes(hook[0].charAt(i)); i++){} hook[0] = hook[0].substring(hook[0].indexOf("ALT"),i); } else { hook[0] = "U"+u; u++; }			hook = new Hook(hook[0],"..."+hook[1],[]) for (let c=0; c<credits.length; c++){ hook.credits.push(new Credit(credits[c])); }			this.hooks.push(hook); }	}	loadFiles{ this.files = [] let filetext = this.content.match(/\{\{main page image\/DYK.*?}}/g); if (filetext != null){ for (let file of filetext){ this.files.push(new File(file)); }		}	}	morebits{ let res = [] for (let hook of this.hooks){ res.push({type: 'option', label: hook.morebits, value: JSON.stringify(hook)}) }		return res }	save(summary){ let params = { action: 'edit', title: this.title, summary: summary+tag, text: this.content, format: 'json' }		return api.postWithToken( 'csrf', params ); } } //