User:Theleekycauldron/Scripts/PSHAW/dependencies/Hook.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 Hook { constructor(id,content,credits){ this.id      = id; this.content = content; this.articles = [] for (let m of this.content.matchAll(/[^']*?\[\[([^\]\|]+)[^']*|\[\[.*([^']+)]]/g)){ this.articles.push(m[1]) }		this.credits = credits }	morebits{ let t = this.content while (t.includes("\'\'\'")){ t = t.replace(/'''/,""); t = t.replace(/'''/,""); }		while (t.includes("\'\'")){ t = t.replace(/''/,""); t = t.replace(/''/,""); }		return ""+this.id+": "+t.slice }	give_credit(credit){ let res; console.log(credit) if (credit.make){ res = ` ~` } else { res = ` ~` }		var params = { action: 'edit', title: `User talk:${credit.user}`, summary: `Giving credit for ${credit.article}`+tag, section: 'new', sectiontitle: `DYK for ${credit.article}`, text: res, format: 'json' }		return api.postWithToken( 'csrf', params ); }	tag_talk(article,file){ let res; let today = new Date today = `${today.getUTCDate} ${["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][today.getUTCMonth]} ${today.getUTCFullYear}` res = `` get_section(`Talk:${article}`,0).then((talk) => {			console.log(talk)			let talktext = talk.wikitext + `\n${res}`			console.log(talktext)			var params = {				action: 'edit',				title: `Talk:${article}`,				summary: `Article appeared on DYK on ${today}, adding `+tag,				section: '0',				text: talktext,				format: 'json'			}			return api.postWithToken( 'csrf', params );		}) } } //