User:TheNozomi/global.js

window.UseCSS = { skin: '', init: function { if (window.location.href.indexOf('usesitecss=') == -1) return; var url = UseCSS.parseURL(window.location.href); if (url.query.usesitecss) { UseCSS.skin = (url.query.usewikicss || url.query.usesitecss); }		if (UseCSS.skin != '') { $(document.body).bind('click.usecss', UseCSS.clicEvent); $('form').bind('submit.usecss', UseCSS.submitEvent); }	},	parseURL: function(url) { var ret = {base:,qs:,query:{},hash:''}; var loc = url.indexOf('#'); if (loc != -1) { ret.hash = url.substr(loc+1); url = url.substr(0,loc); }		loc = url.indexOf('?'); if (loc != -1) { ret.qs = url.substr(loc+1); url = url.substr(0,loc); var paras = ret.qs.split('&'); for (var i = 0; i < paras.length; i++) { var p = paras[i].split('='); if (p.length == 2) { ret.query[p[0]] = p[1]; }			}		}		ret.base = url; return ret; },	getURL: function(url) { var nurl = url.base + '?'; for (var p in url.query) { nurl += p + '=' + url.query[p] + '&'; }		nurl = nurl.substr(0,nurl.length-1); if (url.hash != '') { nurl += '#'+ url.hash; }		return nurl; },	clicEvent: function(e) { if (e.target.tagName.toLowerCase != 'a') return; if (e.target.href.indexOf(window.wgServer) != 0) return; var url = UseCSS.parseURL(e.target.href); var thisloc = UseCSS.parseURL(window.location.href); if (url.base == thisloc.base && url.qs == thisloc.qs && url.hash != '') { return; }		if (url.query.usesitecss && url.query.usesitecss != UseCSS.skin) { url.query.usewikicss = UseCSS.skin; } else { url.query.usesitecss = UseCSS.skin; }		e.target.href = UseCSS.getURL(url); },	submitEvent: function(e) { if (this.action.indexOf(window.wgServer) != 0) return; if (this.method == 'post') { var url = UseCSS.parseURL(this.action); url.query.usesitecss = UseCSS.skin; this.action = UseCSS.getURL(url); } else { $(this).append(''); }	},	stop: function { $(document.body).unbind('click.usecss'); $('form').unbind('submit.usecss'); } }; $(UseCSS.init);

mw.loader.using('mediawiki.api', function {	if ($('.mw-rollback-link').length) return;	var conf = mw.config.get([ 'wgAction', 'wgCanonicalSpecialPageName', 'wgContentLanguage', 'wgPageName', 'wgUserLanguage', 'skin' ]),	i18n = {		en: {			rollback: "rollback",			description: "&quot;Rollback&quot; reverts edit(s) to this page of the last contributor in one click",			summary: "Reverted edits by $1 (talk | block) to last version by $2",			summaryShort: "Reverted edits by $1 (talk | block)",			editConflict: "Unable to rollback (edit conflict)",			contentFail: "Unable to rollback (failed to get page content)",			singleEditor: "Unable to rollback (no different editor found)",			revisionFail: "Unable to rollback (failed to get revisions)",			editFail: "Unable to rollback (failed to publish edit)",			success: "Rollback successful"		},		es: {			rollback: "rollback",			description: "&quot;Rollback&quot; reverts edit(s) to this page of the last contributor in one click",			summary: "Revertidos las ediciones de $1 (disc | bloquear) a la última edición de $2", summaryShort: "Revertidos las ediciones de $1 (disc | bloquear)", editConflict: "Unable to rollback (edit conflict)", contentFail: "Unable to rollback (failed to get page content)", singleEditor: "Unable to rollback (no different editor found)", revisionFail: "Unable to rollback (failed to get revisions)", editFail: "Unable to rollback (failed to publish edit)", success: "Rollback successful" }	};	i18n = i18n[conf.wgContentLanguage] || i18n[conf.wgContentLanguage.split('-')[0]] || i18n[conf.wgUserLanguage] || i18n[conf.wgUserLanguage.split('-')[0]] || i18n.en; if (conf.wgAction == "history" && $('#pagehistory li').length > 1) $('#pagehistory li:first .mw-history-undo a').before(' ' + i18n.rollback + ' | '); else if (conf.wgCanonicalSpecialPageName == "Contributions") { $('#mw-content-text ul').find('li').each(function {			if ($(this).find('.mw-uctop').length)				$(this).append(' [' + i18n.rollback + '] ');		}); }	else if (($.getUrlVar('diff') || $.getUrlVar('oldid')) && $('#differences-nextlink').length === 0) $('.mw-usertoollinks:last').after('   [' + i18n.rollback + '] '); else return; conf.API = new mw.Api; conf.token = mw.user.tokens.values.editToken; mw.util.addCSS('.mw-custom-rollback-link a { cursor: pointer; }'); $('.mw-custom-rollback-link a').click(function {		getRevisionIdAndContent($(this).data('id'),$(this).data('user').replace(/_/g, " "));		$(this).parent.remove;	}); function getRevisionIdAndContent(title,target) { conf.API.get({		action: 'query',		prop: 'revisions',		titles: title,		rvprop: 'user|ids',		rvlimit: 500,		cb: new Date.getTime		}) .done(function(d) {			if (!d.error) {				var revisions;				for (var i in d.query.pages) {					revisions = d.query.pages[i].revisions;				}				if (target != revisions[0].user) {					outputError(i18n.editConflict);					return;				}				var lastUser,				revId;				for (var i in revisions) {					if (revisions[i].user != target) {						lastUser = revisions[i].user;						revId = revisions[i].revid;						break;					}				}				if (lastUser) {					conf.API.get({ action: 'query', prop: 'revisions', rvprop: 'content', revids: revId, cb: new Date.getTime })					.done(function(d) { if (!d.error) { var content = ""; //can be no content on page for (var i in d.query.pages) { if (d.query.pages[i].revisions) content = d.query.pages[i].revisions[0]["*"]; }							performRollback(title,content,target,lastUser); }						else outputError(i18n.contentFail + ': ' + d.error.code); })					.fail(function { outputError(i18n.contentFail); });				}				else					outputError(i18n.singleEditor);			}			else				outputError(i18n.revisionFail + ': ' + d.error.code);		}) .fail(function {			outputError(i18n.revisionFail);		}); }	function performRollback(page,text,user,user2) { var summary = i18n.summary.replace(/\$1/g,user).replace(/\$2/g,user2); if (summary.length > 150) summary = i18n.summaryShort.replace('$1',user); conf.API.post({		action: 'edit',		title: page,		text: text,		summary: summary,		minor: true,		token: conf.token		}) .done(function(d) {			if (!d.error) {				new BannerNotification(i18n.success,'confirm').show;							}			else				outputError(i18n.editFail + ': ' + d.error.code);		}) .fail(function {			outputError(i18n.editFail);		}); }

function outputError(text) { switch (conf.skin) { case 'oasis': case 'wikia': new BannerNotification(text,'error').show; break; default: alert(text); break; }		} });

/* Resize image lightbox dynamically based on browser width */ $(function {   LightboxLoader.lightboxSettings.width = Math.round($(window).width * 0.85);    $(window).resize(function { LightboxLoader.lightboxSettings.width = Math.round($(window).width * 0.85); }); });

// Script imports var WHAMDelay = 100; importArticles({   type: 'script',    articles: [        'u:dev:PortableCSSPad/code.js',        'u:dev:WHAM/code.2.js',        'u:dev:AjaxRedirect/code.js',        'u:dev:FindAndReplace/code.js',        'u:dev:ListFiles/code.js',        'u:dev:Thread Inspection/code.js',        'u:dev:Nuke/code.js',        'u:dev:HoverEditCount.js',        'u:dev:UnhideUserMasthead/code.js',        'u:dev:MastheadGender/code.js',        'u:dev:DupImageList/code.js',        'u:dev:QuickDiff/code.js'    ] });