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"; } }

setUpSynchTable;

/****************************************************************************** * Shroom Youtube Popups                                                     * ******************************************************************************/

function shroomYoutubeController { var spans = document.getElementsByClassName("shroomYoutube");

if (spans.length == 0) { return; }

this.APIReady = false; this.APIContinue = function {}; onYouTubeIframeAPIReady = function { this.APIReady = true; this.APIContinue; }.bind(this); this.players = [];

var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

this.containerDiv = document.createElement("div"); this.containerDiv.className = "shroomYoutubeContainer"; var shadeDiv = document.createElement("div"); shadeDiv.className = "shroomYoutubeShade"; shadeDiv.onclick = this.hideContainer.bind(this); this.bgDiv = document.createElement("div"); this.bgDiv.className = "shroomYoutubeBg"; var throbber = document.createElement("div"); throbber.className = "shroomThrobber"; this.bgDiv.appendChild(throbber); var closeButton = document.createElement("div"); closeButton.className = "shroomYoutubeClose"; closeButton.onclick = this.hideContainer.bind(this); this.bgDiv.appendChild(closeButton); this.containerDiv.appendChild(shadeDiv); this.containerDiv.appendChild(this.bgDiv); document.body.appendChild(this.containerDiv);

for (var i = 0; i < spans.length; i++) { new shroomYoutubeInstance (this, spans[i]) } }

function shroomYoutubeInstance (parent, span) { this.parent = parent; this.span = span; this.link = this.span.getElementsByTagName("a")[0]; this.videoWrapper = document.createElement("div"); this.videoWrapper.class = "shroomYoutubeVideoWrapper"; parent.bgDiv.appendChild(this.videoWrapper); this.link.onclick = this.showWrapper.bind(this); }

shroomYoutubeInstance.prototype.showWrapper = function (e) { if (e.button == 0 &&     !e.ctrlKey &&      !e.altKey &&      !e.shiftKey) { if (!this.parent.APIReady) { this.parent.containerDiv.className="shroomYoutubeContainer visible"; this.parent.APIContinue = this.span.onclick; //should invoke this function again... return false; } else if (this.videoWrapper.firstChild == null) { this.videoWrapper.appendChild(document.createElement("div")); var player = new YT.Player(this.videoWrapper.firstChild, {       width: '420',        height: '315',        videoId: this.span.dataset.video,        events: {          'onReady': this.onPlayerReady.bind(this),          'onStateChange': this.onPlayerStateChange.bind(this)        }      }); this.parent.addPlayer(player); }   var visibles = this.parent.containerDiv.getElementsByClassName("visible"); while (visibles.length > 0) { visibles[0].className="shroomYoutubeVideoWrapper"; }   this.parent.containerDiv.className="shroomYoutubeContainer visible"; this.videoWrapper.className="shroomYoutubeVideoWrapper visible"; return false; } else { return true; } }

shroomYoutubeInstance.prototype.onPlayerStateChange = function (e) { switch (e.data) { case -1: case 0: case 5: this.span.className = "shroomYoutube stopState"; break; case 1: this.parent.pauseOthers(e); case 3: this.span.className = "shroomYoutube playState"; break; case 2: this.span.className = "shroomYoutube pauseState"; break; } }

shroomYoutubeInstance.prototype.onPlayerReady = function (e) { e.target.playVideo; }

shroomYoutubeController.prototype.pauseOthers = function(e) { for (var i = 0; i < this.players.length; i++) { if (this.players[i] != e.target) { this.players[i].pauseVideo; } } }

shroomYoutubeController.prototype.hideContainer = function { this.containerDiv.className="shroomYoutubeContainer"; }

shroomYoutubeController.prototype.addPlayer = function (player) { this.players.push(player); }

new shroomYoutubeController ;

/** pollspinner ***************************************************************** * * description: this shows every awards poll to a user on the main page * maintainers: 2257 */

function pollspinner_boxSetup(nextPoll) {

var spinner = document.getElementsByClassName("pollspinner")[0]; spinner.className = "pollspinner animated throbbing";

var pollSubstitute = nextPoll.getElementsByClassName("pollspinner_poll")[0]; pollSubstitute.id = "PDI_container" + pollSubstitute.dataset.pollid;

while (pollSubstitute.childNodes.length > 0) { pollSubstitute.removeChild(pollSubstitute.childNodes[0]); }

this['pd_callback_' + pollSubstitute.dataset.pollid] = pollspinner_callback.bind(null, nextPoll);

var pdscript = document.createElement("script"); pdscript.addEventListener("error", pollspinner_reportLoadingError.bind(null, nextPoll)); pdscript.type = "text/javascript"; pdscript.language = "javascript"; pdscript.src = "https://s3.polldaddy.com/p/" + pollSubstitute.dataset.pollid + ".js"; pollSubstitute.appendChild(pdscript); }

function pollspinner_reportLoadingError(nextPoll) {

var pollSubstitute = nextPoll.getElementsByClassName("pollspinner_poll")[0]; var errorMessage = document.createTextNode("It looks like the poll failed to load. This could be the result of a network error, or your browser might have denied the request. Please make sure that scripts from the domain s3.polldaddy.com are allowed, then click the button below to try again."); pollSubstitute.appendChild(errorMessage);

var reload = document.createElement("div"); reload.className = "pollspinner_begin"; reload.appendChild(document.createTextNode("Reload")); reload.addEventListener("click", pollspinner_boxSetup.bind(null, nextPoll)); pollSubstitute.appendChild(reload);

pollspinner_activate(nextPoll);

}

function pollspinner_getNext_random(unansweredPolls) {

return Math.floor(Math.random * unansweredPolls.length); }

function pollspinner_getNext_sequential(unansweredPolls) {

return 0;

}

function pollspinner_appendSpecialButtons(nextPoll) {

var spinner = document.getElementsByClassName("pollspinner")[0]; var votebuttonOuter = nextPoll.getElementsByClassName("pds-votebutton-outer")[0]; var skip = document.createElement("a"); skip.className = "pds-vote-button pollspinner_skip"; skip.appendChild(document.createTextNode("Skip")); skip.addEventListener("click", pollspinner_skip.bind(null, spinner)); votebuttonOuter.insertBefore(skip, votebuttonOuter.getElementsByClassName("pds-vote-button")[0].nextSibling);

}

function pollspinner_resize {

var spinner = document.getElementsByClassName("pollspinner")[0]; var element = spinner.querySelectorAll("[data-status='active']")[0]; spinner.style.height = element.offsetHeight + "px";

}

function pollspinner_activate(element) {

var spinner = document.getElementsByClassName("pollspinner")[0]; var activeBoxes = spinner.querySelectorAll("[data-status='active']"); for (var i = 0; i < activeBoxes.length; i++) { activeBoxes[i].dataset.status = "unanswered"; }   var visibleBoxes = spinner.getElementsByClassName("pollspinnerbox visible"); while (visibleBoxes.length > 0) { visibleBoxes[0].removeEventListener("resize", pollspinner_resize); visibleBoxes[0].className = visibleBoxes[0].className.replace(/ *visible */g, " ") + " hidden"; }

element.dataset.status = "active"; pollspinner_resize; element.className = element.className.replace(/ *hidden */g, " ") + " visible";

}

function pollspinner_getNext { var spinner = document.getElementsByClassName("pollspinner")[0];

var unansweredPolls = spinner.querySelectorAll("[data-status='unanswered']"); var skippedPolls = spinner.querySelectorAll("[data-status='skipped']"); if (unansweredPolls.length > 0) { var nextPoll;

switch (spinner.dataset.order) { case "sequential": nextPoll = pollspinner_getNext_sequential(unansweredPolls); break; case "random": default: nextPoll = pollspinner_getNext_random(unansweredPolls); break; }

if (unansweredPolls[nextPoll].dataset.loaded) { pollspinner_activate(unansweredPolls[nextPoll]); } else { pollspinner_boxSetup(unansweredPolls[nextPoll]); }   } else if (skippedPolls.length > 0) { for (var i = 0; i < skippedPolls.length; i++) { skippedPolls[i].dataset.status = "unanswered"; }

pollspinner_getNext; } else {

var end = spinner.getElementsByClassName("pollspinnerbox end"); if (mw.config.get("wgUserName") == null) { end[0].innerHTML = "The power of the Votes is restored to the poll... and it's all thanks to you! Thank you!"; } else { end[0].innerHTML = mw.config.get("wgUserName") + "! The power of the Votes is restored to the poll... and it's all thanks to you! Thank you, " + mw.config.get("wgUserName") + "!"; }       pollspinner_activate(end[0]); } }

function pollspinner_callback( thisPoll, json ) { var obj = jQuery.parseJSON( json ); if ( obj.result == 'registered' || obj.result == 'already-registered' ) { var spinner = document.getElementsByClassName("pollspinner")[0];

var active = document.querySelectorAll("[data-status='active']")[0]; active.dataset.status = "answered"; var pdsBoxTop = active.getElementsByClassName("pds-box-top")[0]; var throbber = document.createElement("div"); throbber.className = "throbber"; throbber.appendChild(document.createTextNode("Loading next poll...")); pdsBoxTop.appendChild(throbber);

pollspinner_getNext; } else if (obj.result == 'view-results') { pollspinner_resize; } else if (obj.result == 'load') { var spinner = document.getElementsByClassName("pollspinner")[0]; spinner.className = "pollspinner animated";

var pdsBoxTop = thisPoll.getElementsByClassName("pds-box-top")[0]; var throbber = document.createElement("div"); throbber.className = "throbber"; throbber.appendChild(document.createTextNode("Loading next poll...")); pdsBoxTop.appendChild(throbber);

thisPoll.dataset.loaded = true; pollspinner_appendSpecialButtons(thisPoll); pollspinner_activate(thisPoll); } }

function pollspinner_skip (spinner) {

var activePoll = spinner.querySelectorAll("[data-status='active']"); if (activePoll.length > 0) { activePoll[0].dataset.status = "skipped"; pollspinner_getNext; } }

function pollspinner_begin (intro){

this.className += " clicked"; intro.dataset.status = "answered"; pollspinner_getNext;

}

function pollspinner_setup { var spinner = document.getElementsByClassName("pollspinner")[0]; if (spinner != null) { var preload = new Image; preload.src = "https://wiki.userpedia.net/images/8/82/Pollthrobber.png"; spinner.className = "pollspinner animated"; var pollSpinnerBoxes = spinner.getElementsByClassName("pollspinnerbox"); for (var i = 0; i < pollSpinnerBoxes.length; i++) { pollSpinnerBoxes[i].dataset.status = "unanswered"; }

var end = document.createElement("div"); end.className = "pollspinnerbox end"; end.dataset.status = "end"; spinner.appendChild(end); var intro = spinner.getElementsByClassName("pollspinnerbox intro")[0]; if (intro != null) { var begin = intro.getElementsByClassName("pollspinner_begin")[0]; begin.addEventListener("click", pollspinner_begin.bind(begin, intro)); pollspinner_activate(intro); } else { pollspinner_getNext; }

} }

pollspinner_setup;

/** 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 = [ 'Revert consecutive edits by {user} ([' + '[User talk:{user}|talk]])', {	label: 'Style guide', namespaces: [0], values: [ '[' + '[MCW:STYLE#Writing|Unsourced]], please provide a [' + '[Help:Official sources|valid source]]', '[' + '[MCW:STYLE#Writing|Tutorial information in non-tutorial article]]', '[' + '[MCW:STYLE#Writing|Mod info in vanilla article]]', '[' + '[MCW:UPTODATE|Outdated information]]', '[' + '[MCW:UPTODATE|History information outside of history section]]', '[' + '[MCW:FUTURE|Content not in a development version]]', '[' + '[MCW:STYLE#Grammar|This wiki uses US English]]', '[' + '[MCW:STYLE#Capitalization|Improper capitalization]]', '[' + '[MCW:IMAGES|Improper image]]', '[' + '[MCW:STYLE#Linking|Overlinking]]', '[' + '[MCW:FEATURES#Trivia|Comparative trivia]]', '[' + '[MCW:FEATURES#Trivia|Bugs are not trivia]]' ]		},		{  label: 'Wiki rules', values: [ '[' + '[MCW:RULES#1|Rule #1]]: Violates Minecraft ToU/brand guidelines', '[' + '[MCW:RULES#2|Rule #2]]: Spam', '[' + '[MCW:RULES#2|Rule #2]]: Vandalism', '[' + '[MCW:RULES#3|Rule #3]]: Harassment/insult/ad hominem', '[' + '[MCW:RULES#4|Rule #4]]: False info/hoax', '[' + '[MCW:RULES#4|Rule #4]]: Speculation', '[' + '[MCW:RULES#5|Rule #5]]: Advertising', '[' + '[MCW:RULES#6|Rule #6]]: Fan community', '[' + '[MCW:RULES#7|Rule #7]]: Plagiarism', '[' + '[MCW:RULES#8|Rule #8]]: [' + '[MCW:Wiki Rules/Video policy|Video policy]]' ]		},		{	label: 'Talk page guidelines', namespaces: [ 4, 'talk' ], values: [ '[' + '[MCW:TALK#General|Improper talk page usage]]', '[' + "[MCW:TALK#General|Don't edit other user's comments]]", '[' + "[MCW:TALK#General|Don't edit archives]]" ]		},		{	label: 'Talk page guidelines', namespaces: [ 'main' ], values: [ '[' + '[MCW:Projects/Rewrite for Style|Rewrite for Style]]', '[' + '[MCW:Projects/Rewrite for Style|Minor rewrite]]', '[' + '[MCW:Projects/Categorization|Categorize]]', '[' + '[MCW:Projects/Categorization|Change category]]', ]		},		{	label: 'Forums', values: [ '[' + '[forum:minecraft-discussion|Go to the forums]]', '[' + '[forum:minecraft-discussion/suggestions|Go to the suggestion forums]]', '[' + '[forum:mapping-and-modding/minecraft-mods|Go to the mod forums]]', '[' + '[forum:support|Go to the support forums]]' ]		}	];	mw.loader.localLoad('User:KnightMiner/editSummaryPresets.js'); }

// User:Majr/docTabs.js // Adds Doc + Doc discussion tabs to template and module pages and // changes Template/Module + Discussion tabs to always link to the original template/module + discussion page if ( 	$.inArray( mw.config.get( 'wgNamespaceNumber' ), [ 10, 11, 828, 829 ] ) > -1 ||	$.inArray( mw.config.get( 'wgNamespaceNumber' ), [ 2, 3 ] ) > -1 &&	mw.config.get( 'wgTitle' ).replace( /\/doc$/, '' ).search( /\.(js|css)$/ ) > -1 ) { mw.loader.localLoad( 'User:Majr/docTabs.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'	); }

/** 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' ), ']'		)	); }

} );

/** Testing stuff **/