User:Psl85/hydra.js

mw.loader.localLoad = function( url ) { return mw.loader.load( '//minecraft.gamepedia.com/index.php?title=' + url + '&action=raw&ctype=text/javascript' ); };

/* Auto-refresh button on Special:RecentChanges */ function setCookie(c_name, value, expiredays) { var exdate = new Date; exdate.setDate(exdate.getDate + expiredays); document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString); } function getCookie(c_name) { if (document.cookie.length > 0) { c_start = document.cookie.indexOf(c_name + "="); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) c_end = document.cookie.length; return unescape(document.cookie.substring(c_start, c_end)); }	}	return ""; } var ajaxPages = new Array("Special:RecentChanges"); var ajaxRCOverride = false; var rcRefresh = 30000; function ajaxRC { appTo = $(".firstHeading"); appTo.append('   AUTO-REFRESH:   '); $("#autoRefreshToggle").click(function {		setCookie("ajaxRC", $("#autoRefreshToggle").is(":checked") ? "on" : "off")		loadRCData	}); $("#autoRefreshProgress").hide; if (getCookie("ajaxRC") == "on" || ajaxRCOverride) { $("#autoRefreshToggle").attr("checked", "checked"); setTimeout("loadRCData;", rcRefresh); } } function loadRCData { if (!$("#autoRefreshToggle").is(":checked")) return; $('#autoRefreshProgress').show $(article).load(location.href + " " + article + " > *", function (data) {		$(article + " .mw-collapsible").makeCollapsible;		$('#autoRefreshProgress').hide		if ($("#autoRefreshToggle").is(":checked")) setTimeout("loadRCData;", rcRefresh);	}); } $(function {	article = "#bodyContent";	for (x in ajaxPages) {		if (mw.config.get('wgPageName') == ajaxPages[x] && $("#autoRefreshToggle").length == 0) ajaxRC;	} });

function setUpSynchTable { var tables = document.getElementsByClassName("awardsSynchronisedTable"); for (var k = 0; k < tables.length; k++) { var rows = tables[k].rows; for (var i = 0; i < rows.length; i++) { var cells = rows[i].cells; for (var j = 0; j < cells.length; j++) { cells[j].style.verticalAlign = "top"; var synchDiv = document.createElement("DIV"); synchDiv.style.position = "relative"; synchDiv.className = "synchDiv"; var childs = cells[j].childNodes; while (childs.length > 0) { synchDiv.appendChild(childs[0]); }       cells[j].appendChild(synchDiv); }   }  }  if (tables.length > 0) { document.onscroll = synchTableOnScroll; } }

function synchTableOnScroll { var divs = document.getElementsByClassName("synchDiv"); for (var i = 0; i < divs.length; i++) { var parent = divs[i].parentNode; var parentRect = parent.getBoundingClientRect; var offset; if (window.innerHeight > divs[i].offsetHeight) { offset = Math.min(Math.max(-1 * parentRect.top, 0), parent.clientHeight - divs[i].offsetHeight); } else { offset = Math.min(Math.max(-1 * parentRect.top / (parent.clientHeight - window.innerHeight) * (parent.clientHeight - divs[i].offsetHeight), 0), parent.clientHeight - divs[i].offsetHeight); }   divs[i].style.top = offset + "px"; } }

/** Scripts **/

// User:KnightMiner/editSummaryPresets.js // Creates a dropdown menu on edit summaries with presets if (mw.config.get('wgAction') === 'edit' || mw.config.get('wgAction') === 'submit') { var customSummaries = [ 'Reply', 'Comment', 'Suggestion', 'Added info', 'Fixed typo', 'Fixed red link', 'Removing unsourced info', 'Please write in American English, not British', 'Overlinking', 'Add history in the history section', 'Do not edit other users comments', 'Reverted vandalism or test edit', 'Tagging page for deletion', 'Remove spam', 'Rewriting', 'Copyedit', 'Do that in the forums' ];	mw.loader.localLoad('User:KnightMiner/editSummaryPresets.js'); }

// User:Majr/Prism.js // Adds JavaScript, CSS and Lua syntax highlighting, see file for license // Requires a theme from http://prismjs.com to be added to usercss mw.loader.localLoad( 'User:Majr/Prism.js' );

// User:Majr/inputCounter.js // Adds a character counter to input fields mw.loader.localLoad( 'User:Majr/inputCounter.js' );

// User:Majr/codeLinks.js mw.loader.localLoad( 'User:Majr/codeLinks.js' );

// User:Majr/renderConsoleOutput.js // Allows the output wikitext of the lua console to be rendered if ( $( '#mw-scribunto-console' ).length ) { mw.loader.localLoad( 'User:Majr/renderConsoleOutput.js' ); }

/** General fixes **/

$( function { 'use strict';

// Replaces the Special:Achievements tab with the Special:MyPage/Sandbox tab $('#pt-achievements a').attr({ href: '/User:' + mw.config.get( 'wgUserName' ) + '/Sandbox' }).text('Sandbox');

// Makes one of the user links my profile, and the other the userwiki $('.netbar-box.right li.user a').attr({ href: '/UserProfile:' + mw.config.get( 'wgUserName' ) }).text( 'Profile' );

// Add a subpages link to pages if ( mw.config.get( 'wgArticleId' ) != 0 ) { mw.util.addPortletLink (		'p-tb',		'/Special:PrefixIndex/' + mw.config.get( 'wgRelevantPageName' ) + '/',		'Subpages',		't-subpages',		'Subpages of the article'	); }

/* Add link to browse the source code */ {	mw.util.addPortletLink (		'p-tb',		'/index.php?title=' + mw.config.get( 'wgRelevantPageName' ) + '&action=raw',		'View Source',		't-viewsource',		'View the wikitext of the current page'	); } /** Mostly direct code from User:Majr/hydra.js **/

// Modify the editing toolbar if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) > -1 ) { mw.loader.using( 'ext.wikiEditor.toolbar', function {

// Modify the text added by the signature button. var $button = $( '#wikiEditor-section-main > .group-insert > a[rel="signature"]' ); if ( $button.length ) { var action = $button.data( 'action' ); action.options.pre = ' ' + ' '; $button.data( 'action', action ); }

// Add an option to insert ' } }				}			}		// Add an option to insert template braces } ).wikiEditor( 'addToToolbar', { section: 'advanced', group: 'insert', tools: { sign: { label: 'Template', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/4/43/Button-template.png', action: { type: 'replace', options: { pre: '' } }				}			}		// Add characters to the symbols insert page } ).on( 'wikiEditor-toolbar-buildSection-characters', function (event, section) { section.pages.symbols.characters.push( '¦', '²{', '}²' ); } );	} ); }

// Add 0th section edit button to first infobox which is in the 0th section var $firstInfobox = $( '.notaninfobox' ).first; if ( !$firstInfobox.prevAll( 'h1, h2, h3, h4, h5, h6' ).length ) { $firstInfobox.children( '.infobox-title' ).css( 'padding-left', 50 ).prepend(		$( ' ' ).addClass( 'mw-editsection' ).css( { float: 'right', lineHeight: 'inherit' } ).append( '[',			$( '' ).prop( 'href', '/' + mw.config.get( 'wgPageName' ) + '?action=edit&section=0' ).text( 'edit' ), ']'		)	); }

} );

/* Blockinfo */ /*jshint undef:true */ /*global jQuery, mw */ (function{ 'use strict';

var api = new mw.Api;

function el(tag, child, attr, events) { var key, node = document.createElement(tag); if (child) { if (typeof child !== 'object') child = [child]; for (var i = 0; i < child.length; ++i) { var ch = child[i]; if ((ch === void(null)) || (ch === null)) continue; else if (typeof ch !== 'object') ch = document.createTextNode(String(ch)); node.appendChild(ch); }	}	if (attr) for (key in attr) { node.setAttribute(key, String(attr[key])); }	if (events) for (key in events) { node.addEventListener(key, events[key], false); }	return node; }

function fmtDate(date) { // XXX: uses browser's time zone instead of preferences date = new Date(date);

switch (mw.user.options.get('date')) { case 'dmy'    : return date.toLocaleTimeString + ', ' + date.getDate + ' ' + mw.language.months.genitive[date.getMonth] + ' ' + date.getFullYear; case 'mdy'    : return date.toLocaleTimeString + ', ' + mw.language.months.genitive[date.getMonth] + ' ' + date.getFullYear + ', ' + date.getDate; case 'ymd'    : return date.toLocaleTimeString + ', ' + date.getFullYear + ' ' + mw.language.months.genitive[date.getMonth] + ' ' + date.getDate; case 'default' : return date.toLocaleString; case 'ISO 8601': return date.toISOString; } }

var wd2iw = { 'metawiki': 'm' };

function buildList(user, callback) { var isAnon = mw.util.isIPv4Address(user) || mw.util.isIPv6Address(user);

var rq = api.get({		action: 'query',		list: 'blocks' + (isAnon ? '|globalblocks' : '|globalallusers'),		// blocks		bkip: isAnon ? user : void(window.warranty),		bkusers: isAnon ? void(window.warranty) : user,		bkprop: 'id|user|range|timestamp|expiry|by|reason|flags',		bkdir: 'older',		// globalblocks		bgip: isAnon ? user : void(window.warranty),		bgprop: isAnon ? 'id|address|range|timestamp|expiry|by|reason' : void(window.warranty),		bgdir: isAnon ? 'older' : void(window.warranty),		// globalallusers		agufrom: !isAnon ? user : void(window.warranty),		aguto: !isAnon ? user : void(window.warranty),		agulimit: !isAnon ? 1 : void(window.warranty),		aguprop: !isAnon ? 'lockinfo' : void(window.warranty)	}); rq.then(function (result) {		var list = el('ul'), item, i;

if (result.query.globalallusers && result.query.globalallusers[0] && ('locked' in result.query.globalallusers[0])) { list.appendChild(el('li', [ "This account is globally locked", " (", el('a', "globalauth log", { href: mw.util.getUrl('m:Special:Log/globalauth', { page: 'User:' + user + '@global' }) }), ")." ]));		}		for (i = 0; i < result.query.blocks.length; ++i) { item = result.query.blocks[i]; list.appendChild(el('li', [ fmtDate(item.timestamp), ': ', el('a', item.by, { href: mw.util.getUrl('User:' + item.by) }), " blocked ", el('b', item.user), " (", el('a', 'block log', { href: mw.util.getUrl('Special:Log/block', { page: 'User:' + item.user }) }), "),", ' expiring ', el('b', item.expiry === 'infinity' ? 'never' : fmtDate(item.expiry)), item.reason && " (", item.reason, item.reason && ")", ]));		}		if (result.query.globalblocks) for (i = 0; i < result.query.globalblocks.length; ++i) { item = result.query.globalblocks[i]; list.appendChild(el('li', [ fmtDate(item.timestamp), ': ', el('a', item.by, { href: mw.util.getUrl(wd2iw[item.bywiki] + ':User:' + item.by) }), " at ", el('code', item.bywiki), " globally blocked ", el('b', item.address), " (", el('a', "gblblock log", { href: mw.util.getUrl(wd2iw[item.bywiki] + ':Special:Log/gblblock', { page: 'User:' + item.address }) }), "),", " expiring ", el('b', item.expiry === 'infinity' ? "never" : fmtDate(item.expiry)), item.reason && " (", item.reason, item.reason && ")", ]));		}		callback(list); });	return rq; }

function makeBox(user, relTo) { if (!user) return; relTo = relTo || document.getElementById('mw-content-text');

var afterList, box = el('div', [		el('p', [el('strong', user), ' is currently blocked.']),		afterList = el('small', [ el('a', "block log"      , { href: mw.util.getUrl('Special:Log/block', { page: 'User:' + user }) }) ])	], {		'class': 'mw-warning-with-logexcerpt'	});

relTo.rq = buildList(user, function (list) {		relTo.rq = null;		if (!list.hasChildNodes)			return;

box.insertBefore(list, afterList); relTo.parentNode.insertBefore(box, relTo); });

return box; }

var user;

var wgNamespaceNumber = mw.config.get('wgNamespaceNumber'); var wgNamespaceIds = mw.config.get('wgNamespaceIds'); var wgTitle = mw.config.get('wgTitle');

if ((wgNamespaceNumber & ~1) === wgNamespaceIds.user) { makeBox(wgTitle.replace(/\/.*$/, '')); } else if ((mw.config.get('wgCanonicalSpecialPageName') === 'Contributions') || (mw.config.get('wgCanonicalSpecialPageName') === 'DeletedContributions')) { makeBox(wgTitle.indexOf('/') !== -1 ? wgTitle.replace(/^.*?\//, '') : mw.util.getParamValue('target')); } else if (mw.config.get('wgCanonicalSpecialPageName') === 'Log') { user = mw.util.getParamValue('user'); if (/^[^\/]+\/(block|delete)$/.test(wgTitle)) return; if (wgTitle.indexOf('/') !== -1) user = wgTitle.replace(/^.*\//, ''); makeBox(user); } else if (mw.config.get('wgCanonicalSpecialPageName') === 'Block') { var ipinput = document.getElementById('mw-bi-target'); var relTo = ipinput.form.getElementsByTagName('legend')[0].nextSibling; var warnnode = null;

var refresh = function { if (relTo.rq) relTo.rq.abort;

if (warnnode && warnnode.parentNode) { warnnode.parentNode.removeChild(warnnode); warnnode = null; }

if (!ipinput.value) return;

warnnode = makeBox(ipinput.value, relTo); };

var tmout; ipinput.addEventListener('input', function {		clearTimeout(tmout);		tmout = setTimeout(refresh, 500);	}, false); ipinput.addEventListener('change', function {		refresh;	}, false); refresh; return; }

});

/* Add revert links to easily revert to a previous revision */ $( document ).ready( function { 	if (mw.util.getParamValue('action') === 'history') {		var chemin = '//en.wiktionary.org/w/index.php?action=edit&retablir';		var pagehistory = document.getElementById('pagehistory');        pagehistory = pagehistory && pagehistory.getElementsByTagName('li');		for (var x = 0; x < pagehistory.length - 1; x++) {			var atags = pagehistory[x].getElementsByTagName('a');			if (x === 0) {				var user2 = atags[2].innerHTML;			} else {				var user = atags[3].innerHTML,					oldid = atags[2].href.match('&oldid=([0-9]+)')[1],					revertLink = document.createElement( "a" );				revertLink.href = chemin+'&oldid='+oldid+'&user='+user+'&user2='+user2;				revertLink.appendChild( document.createTextNode( "Revert" ) );				pagehistory[x].appendChild( document.createTextNode( " \u2014 (" ) ); pagehistory[x].appendChild( revertLink ); pagehistory[x].appendChild( document.createTextNode( ")" ) );			}			}	} else if (location.href.match(/&retablir&/)) {		var message = prompt ('Which edit summary do you want to leave while reverting?', 'Reverted edits by '+mw.util.getParamValue('user2')+);		if (message) {			document.getElementById('wpSummary').value = message + '; Reverted to version '+mw.util.getParamValue('oldid')+' by '+mw.util.getParamValue('user')+;		} else {			document.getElementById('wpSummary').value = 'Reverted to version '+mw.util.getParamValue('oldid')+' by '+mw.util.getParamValue('user')+'';		}		if (message != null) document.getElementById('editform').submit;	} }); /** Testing stuff **/