Jump to content

MediaWiki:Live EriCSSon.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Magnus Manske (talk | contribs) at 12:25, 16 July 2012. 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.
if ( typeof ( $ ) === 'undefined' ) $ = $j ;

var live_ericsson = {
	init : function () {
//		if ( mw.config.get('wgNamespaceNumber') != 0 ) return ;
//		if ( mw.config.get('wgAction') != 'view' ) return ;
		var self = this ;
		var portletLink = mw.util.addPortletLink( 'p-tb', '#', 'Live EriCSSon','t-live-ericsson');
		$(portletLink).click ( function () {
			self.options() ;
			return false ;
		} ) ;
		self.run() ;
	} ,
	
	run : function () {
		var self = this ;
		var use_css = self.getURLParameter ( 'useCSS' ) ;
		if ( undefined === use_css ) return ;
		if ( null == use_css ) return ;
//		var url = wgServer + wgScriptPath + '/index.php?action=raw&title=' + use_css ;
		//http://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Main%20Page&rvprop=content
		var api = new mw.Api();
		api.get( {
			action: 'query',
			prop: 'revisions' ,
			titles: use_css ,
			rvprop: 'content'
		}, {
			ok: function () {
				var a = arguments[0] ;
				if ( undefined === a || undefined === a.query ) return ;
				var pages = a.query.pages ;
				if ( undefined === pages ) return ;
				$.each ( pages , function ( page , data ) {
					var css = data.revisions[0]['*'] ;
					mw.util.addCSS ( css ) ;
				} ) ;
			}
		} );		
		
	} ,
	
	options : function () {
	} ,
	
	getURLParameter : function(name) {
		return decodeURI(
			(RegExp('\\b' + name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
		);
	} ,

	the_end : ''
} ;

$( function () { live_ericsson.init () } ) ;