User:Theleekycauldron/DYK credit finder.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
importScript('User:Theleekycauldron/Query pages.js');
try {
	var api = new mw.Api();
} catch (SyntaxError) {}

function search(string) {
	var params = {
		action: 'query',
		list: 'search',
		srwhat: 'text',
		srnamespace: '3',
		srsearch: string,
		format: 'json'
	}
	return api.get( params ).done(function ( data ) {
		return data;
	} );
	
}
async function find_contrib_data(articles){
	//
	var contributors = {};
	let searchres;
	let query;
	for (let article of articles){
		contributors[article] = [];
		query = "insource:\"==DYK for <article>==\{\{ivmbox |image = Updated DYK query.svg\"".replace("<article>",article);
		searchres = await search(query);
		for (let res of searchres.query.search){
			if (!res.title.includes("/")){ // no hunting through archives
				contributors[article].push(res.title);
			}
		}
	}
	return contributors;	
}