Jump to content

User:MusikAnimal/dablinkwarn.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MusikAnimal (talk | contribs) at 19:29, 6 August 2021. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
( function ( mw, $ ) {
	var $wpTextbox1 = $( '#wpTextbox1' ),
		api = new mw.Api();

	$wpTextbox1.on( 'keyup', function (e) {
		if (e.which === 221) {
			var matches = $wpTextbox1.val().match(/\[\[(.*?)\]\]$/);
			if (matches && matches.length) {
				api.get({
					action: 'query',
					titles: matches[1],
					prop: 'pageprops',
					ppprop: 'disambiguation',
					formatversion: 2
				}).then(function (resp) {
					if (resp[0].pageprops.disambiguation) {
						mw.notify('You linked to the page "' + matches[1] + '" which is probably not what you wanted to link to.');
					}
				});
			}
		}
	} );
} )( mediaWiki, jQuery );