Jump to content

User:Lupin/popups.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.
var popScript     = '//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=MediaWiki:Gadget-popups.js';
var popStyleSheet = '//en.wikipedia.org/w/index.php?action=raw&ctype=text/css&title=MediaWiki:Gadget-navpop.css';
if ( window.localCSS ) { popStyleSheet = 'http://localhost:8080/js/navpop.css'; }

function popups_importScriptURI(url) {
	var s = document.createElement('script');
	s.setAttribute('src',url);
	s.setAttribute('type','text/javascript');
	document.getElementsByTagName('head')[0].appendChild(s);
	return s;
}

function popups_importStylesheetURI(url) {
	return document.createStyleSheet ? document.createStyleSheet(url) : popups_appendCSS('@import "' + url + '";');
}

function popups_appendCSS(text) {
	var s = document.createElement('style');
	s.type = 'text/css';
	s.rel = 'stylesheet';
	if (s.styleSheet) s.styleSheet.cssText = text //IE
	else s.appendChild(document.createTextNode(text + '')) //Safari sometimes borks on null
	document.getElementsByTagName('head')[0].appendChild(s);
	return s;
}

popups_importStylesheetURI(popStyleSheet);
popups_importScriptURI(popScript);

if ( typeof mw !== 'undefined' ) {
mw.loader.using( [ 'mediawiki.storage' ], function() {
	var k = 'User:Lupin/popups.js',
		t = 'Information: You are importing User:Lupin/popups.js' +
			' into your User:USERNAME/common.js or User:USERNAME/<skin>.js!\n' +
			'This script is unmaintained. Please remove this inclusion and enable the Navigation popups Gadget in the preferences of your account instead.',
		x = mw.storage.get( k );

	if ( !x ) {
		mw.storage.set( k, 1 );
		alert( t );
	} else {
		x++;
		mw.storage.set( k, x );
		if ( x % 25 === 0 ) {
			mw.notify( t );
		}
	}
});
}