Let op! Nadat u de veranderingen heeft opgeslagen, moet u de cache van uw browser nog legen om ze daadwerkelijk te zien.

Mozilla (incl. Firefox) Ctrl+Shift+R
Internet Explorer Ctrl+F5
Opera F5
Safari Cmd+R
Konqueror F5
//script to update subpages of Sjabloon:Wikipedia artikel/Petscan
//To start the YOLO autoclicker somewhere other than at the beginning, click the update link for the page where you want it to start before clicking YOLO
//To stop YOLO after it begins, kill -9 -1
/*jshint esversion:8*/
//<nowiki>
//if ( mw.config.get('wgAction') == 'view' && mw.config.get('wgTitle') == 'Wikipedia artikel/Petscan' && mw.util.getParamValue('skipwalu') != '1' ) { mw.loader.load('/w/index.php?title=User:Alexis_Jazz/WALU.js&action=raw&ctype=text/javascript'); }
mw.loader.addStyleTag('.petscanupdate{padding-left:1em;padding-right:1em;}.WALUbusy{background-color:#ddd;display:inline-block;min-height:5em}.WALUsuccess{background-color:rgba(200,255,200,0.5)}.WALUfail{background-color:rgba(255,200,200,0.5)}');
mw.loader.addStyleTag(`
@keyframes example {
  0%   {font-size:1em;}
  50%  {font-size:2em;}
  100% {font-size:1em;}
}`);
mw.loader.addStyleTag('.WALUbusy .petscanupdate{background-color:orange !important;display:inline-block;animation-name: example;animation-duration: 1s !important;animation-iteration-count:infinite !important}');
window.WALU = {}; //Wikipedia Article Link Updater
var WALU = window.WALU;
WALU.api = new mw.Api();
mw.loader.using(['mediawiki.ForeignApi','mediawiki.Uri'], function(){
	WALU.wdapi = new mw.ForeignApi('https://www.wikidata.org/w/api.php');
});
WALU.YOLO = function(num,int3){
	if ( $('.WALUsuccess')[0] ) {
		for(int3=0;int3<$('.petscanupdate').length;int3++){
			if($('.petscanupdate')[int3].classList.contains('petscanupdatedone')){
				num=(int3+1);
				break;
			}
		}
	} else {
		num=0;
	}
	WALU.clickAll = setInterval(function() {
		if ( $('.petscanupdate')[num] ) {
			$('.petscanupdate')[num].click();
			num++;
		} else {
			clearInterval(WALU.clickAll);
		}
	},2500);
};
WALU.YOLOel = document.createElement('a');
WALU.YOLOel.innerText = 'YOLO';
WALU.YOLOel.id = 'YOLOel';
WALU.YOLOel.style['font-style'] = 'bold';
WALU.YOLOel.style['font-size'] = '10em';
if ( mw.config.get('wgTitle').match(/^Wikipedia artikel\/Petscan/) ) {
	$('#bodyContent').prepend(WALU.YOLOel);
	$('#YOLOel').on('click',WALU.YOLO);
}
async function petscan(url,pageTitle,el,petscanfetch,petscanjson,wikitext,int,color,entries,newentry,countEl,isDomain,title,qids,wikicode){
	el.parentElement.classList.add('WALUbusy');
	petscanfetch = await fetch(url);
	petscanjson = await petscanfetch.json();
	entries=petscanjson['*']['0'].a['*'];
	wikitext="{{#switch:{{{1|}}}";
	isDomain=0;
	wikicode=pageTitle.replace(/.*ikipedia.artikel\/([a-z]*).*/,'$1');
	if ( url.match(/P856/) ) {
		isDomain=1;
		qids=[];
		WALU.entriesprocessed=0;
		WALU[pageTitle]='';
	}
	for(int=0;int<entries.length;int++){
		title=entries[int].title.replace(/_/g,' ');
		if ( isDomain ) {
			qids.push(entries[int].q);
		} else {
			newentry=entries[int].title.replace(/_/g,' ').replace(/([^\(]*)( \(.*)/,'|{{subst:lc:$1}}=$1$2').replace(/^([^\|].*)/,'|{{subst:lc:$1}}=$1');
			wikitext += "\n"+newentry;
		}
	}
	if ( isDomain ) {
		WALU.getDomainsWd(qids,wikicode,pageTitle,entries,el);
	} else {
		wikitext += "\n}}";
		WALU.editPage(pageTitle,wikitext,'update content from petscan using script',el,entries);
	}
}
WALU.getDomainsWd = function(qids,wikicode,pageTitle,entries,el,newentry,int2,int,qids_limited) {
	qids_limited=[];
	for(int=0;int<10;int++){	//get max 10 wikidata items per request. Sure, the limit is 50 (without apihighlimits), but that results in truncated output sometimes and processing the json takes forever
		if ( qids.length > 0 ) {
			qids_limited.push(qids.pop());
		}
	}
	WALU.wdapi.post({action:'wbgetentities',ids:qids_limited,format:'json',props:['claims','sitelinks']}).then(function(data,int2,uriobj,testval){
		for(int2=0;int2<Object.keys(data.entities).length;int2++){
			testval=0;
			try{testval=data.entities[Object.keys(data.entities)[int2]].claims.P856[0].mainsnak.datavalue.value;} catch (e) {}
			if ( testval ) {
				uriobj = new mw.Uri(data.entities[Object.keys(data.entities)[int2]].claims.P856[0].mainsnak.datavalue.value+'/');
				if ( data.entities[Object.keys(data.entities)[int2]].sitelinks[wikicode] ) {
					newentry='|'+uriobj.host.replace(/^www\./,'').toLowerCase()+'='+data.entities[Object.keys(data.entities)[int2]].sitelinks[wikicode].title;
					WALU[pageTitle] += "\n"+newentry;
				}
			}
		}
		if ( qids.length > 0 ) {
			WALU.getDomainsWd(qids,wikicode,pageTitle,entries,el);
		} else {
			WALU.editPage(pageTitle,"{{#switch:{{{1|}}}"+WALU[pageTitle]+"\n}}",'update content from petscan using script',el,entries);
		}
	});
};
WALU.editPage = function(pageTitle,wikitext,editsummary,el,entries) {
	WALU.api.postWithEditToken( {action: 'edit', title:pageTitle, text: wikitext, assert:'user',watchlist:'nochange',summary:editsummary} ).then( function ( data,int ) {
		el.parentElement.classList.remove('WALUbusy');
		el.parentElement.classList.add('WALUsuccess');
		el.parentElement.querySelectorAll('.petscanupdate')[0].classList.add('petscanupdatedone');
		if ( entries.length > 3000 ) {
			color='#f00';
		} else if ( entries.length > 2000 ) {
			color='#fb0';
		} else if ( entries.length > 500 ) {
			color='#3c3';
		} else {
			color='inherit';
		}
		countEl = document.createElement('span');
		countEl.innerHTML = ' <span style="color:'+color+'">'+entries.length+'</span> entries';
		el.append(countEl);
	}, function ( data, int ) { el.parentElement.classList.add('WALUfail');});
};
$('.petscanlink').append('<a class="petscanupdate">update</a>');
$('.petscanupdate').on('click',function(pageTitle,scanLink){
	pageTitle=decodeURIComponent(this.parentElement.querySelectorAll('.petscanlink_pagetitle a')[0].href.replace(/.*\/wiki\//,'').replace(/.*title=([^\&]*).*/,'$1'));
	scanLink=this.parentElement.querySelectorAll('.petscanupdatelink a')[0].href;
	petscan(scanLink,pageTitle,this.parentElement);	
});
//</nowiki>