MediaWiki:AddCoordinates.js

Uit Wikipedia, de vrije encyclopedie

Opmerking: nadat u de wijzigingen hebt gepubliceerd is het wellicht nodig uw browsercache te legen.

  • Firefox / Safari: houd Shift ingedrukt terwijl u op Vernieuwen klikt of druk op Ctrl-F5 of Ctrl-R (⌘-Shift-R op een Mac)
  • Google Chrome: druk op Ctrl-Shift-R (⌘-Shift-R op een Mac)
  • Internet Explorer / Edge: houd Ctrl ingedrukt terwijl u op Vernieuwen klikt of druk op Ctrl-F5
  • Opera: druk op Ctrl-F5.
/**
 * Script to add coordinates
 * coordinates: A location template to add
**/
 
var AddCoordinates = {
	run : function() {
		var coordinates = mw.util.getParamValue('coordinates');
		if (coordinates==='') return; 
 
		var wptext = document.getElementById('wpTextbox1');
		if (!wptext) return;
 
		// Attempt to replace "no coordinate" tempalte
		var newtext = wptext.value.replace(/\{\{[Gg]een coördinaten\}\}/g, coordinates);
		// If not found, append to the end
		if (wptext.value===newtext){
			wptext.value = wptext.value + coordinates;
		// If found, replace text with the replaced version
		} else {
			wptext.value = newtext;
		}
		// Set the edit summary automatically
		var wpsummary = document.getElementById('wpSummary');
		if (wpsummary) {
			wpsummary.value = 'Coördinaten zijn toegevoegd met behulp van [[MediaWiki:AddCoordinates.js|AddCoordinates.js]]';
		}
		// Click the "Show changes" button (make sure not to load this script again on the target page, to avoid an infinite loop!)
		$('#wpDiff').click();
	}
};
 
if (mw.config.get('wgAction') === 'edit') {
	$( AddCoordinates.run );
}