Jump to content

User:V111P/js/smartLinkingLoader.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.
/* smartLinkingLoader.js
 * v. 2014-07-07
 *
 * This script adds a toolbar button which, when pressed, loads smartLinking.js and calls window.smartLinking().
 *
 * Smart Linking home: http://en.wikipedia.org/wiki/User:V111P/js/Smart_Linking
 */
 
mw.libs.smartLinkingLoader = mw.libs.smartLinkingLoader || {};
mw.libs.smartLinkingLoader.version = 1000;

mw.libs.smartLinkingLoader.smartLinking = function () {
	"use strict";
	if (window.smartLinking) {
		window.smartLinking();
	}
	else {
		$.ajax({
			url: '//en.wikipedia.org/w/index.php?title=User:V111P/js/smartLinking.js'
					+ '&action=raw&ctype=text/javascript&smaxage=86400&maxage=604800',
			dataType: 'script',
			cache: true,
			success: function () {
				if (window.smartLinking)
					window.smartLinking();
				else
					setTimeout(function () {
						if (window.smartLinking)
							window.smartLinking();
					}, 500);
			}
		});
	}
};

mw.libs.smartLinkingLoader.addButton = function () {
	"use strict";
	var buttonId = 'smartLinkingButton';

	if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) == -1
		  || $('#' + buttonId).length > 0 )
		return;

	var addToolbarButtons_scriptUrl = '//en.wikipedia.org/w/index.php?title='
		+ 'User:V111P/js/addToolbarButtons.js&action=raw'
		+ '&ctype=text/javascript'; // [[User:V111P/js/addToolbarButtons.js]]
	var c = ( window.smartLinkingConfig || {} );
	var toolbarButtonProps = {
		id: buttonId,
		tooltip: (c.msgs && c.msgs.scriptName) || 'Smart Linking',
		section: 'main',
		group: 'insert',
		callback: mw.libs.smartLinkingLoader.smartLinking,
		iconUrl: '//upload.wikimedia.org/wikipedia/commons/9/96/Interpage_icon.png',
		iconUrlClassic: '//upload.wikimedia.org/wikipedia/commons/5/5a/Interpage_button.png'
	};

	if (mediaWiki.libs.addToolbarButtons)
		mediaWiki.libs.addToolbarButtons(toolbarButtonProps);
	else {
		var tbs = window.toolbarButtonsToAdd = window.toolbarButtonsToAdd || [];
		tbs.push(toolbarButtonProps);
		$.ajax({
			url: addToolbarButtons_scriptUrl,
			dataType: 'script',
			cache: true
		});
	}

};

if ((window.smartLinkingConfig || {}).addButton !== false)
	mediaWiki.libs.smartLinkingLoader.addButton();