User:Psl85/common.js

w.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.load('https://minecraft.gamepedia.com/index.php?title=User:KnightMiner/editSummaryPresets.js&action=raw&ctype=text/javascript'); }

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

} );

/** Testing stuff **/

// Force Preview and Edit-Summary - Start if (mw.config.get("wgAction") === "edit") $.when(mw.loader.using("user.options"), $.ready).then(function {		var $wpSave = $("#wpSave"),			$wpPreview = $("#wpPreview"),			saveVal = $wpSave.val,			classNames = "oo-ui-widget-enabled oo-ui-flaggedElement-progressive oo-ui-flaggedElement-primary";		if (!mw.user.options.get("forceeditsummary") || mw.user.options.get("previewonfirst"))			mw.loader.using("mediawiki.api", function  { new mw.Api.saveOptions({forceeditsummary: 1, previewonfirst: 0}); });		if (!$("#wikiPreview,#wikiDiff").is(":visible") && $wpSave.length && $wpPreview.length) {			$wpSave.prop("disabled", true)				.val("Save page (use preview first)")				.parent.removeClass(classNames).addClass("oo-ui-widget-disabled");			$wpPreview.one("click", function (e) { // re-enable $wpSave.prop("disabled", false) .val(saveVal) .parent.removeClass("oo-ui-widget-disabled").addClass(classNames); }).parent.addClass(classNames);		}	}); // Force Preview and Edit-Summary - End

$(function {

/* mw.loader.localLoad = function(url) { return mw.loader.load('/index.php?title='+url+'.js&action=raw&ctype=text/javascript') }; mw.loader.interLoad = function(url, wiki) { return mw.loader.load('//'+wiki+'.gamepedia.com/index.php?title='+url+'.js&action=raw&ctype=text/javascript') }; mw.loader.localLoad('User:ITechieGamer/test');

mw.loader.load('//help.gamepedia.com/index.php?title=User:ITechieGamer/interwiki.js&action=raw&ctype=text/javascript');

});

mw.loader.load( '//minecraft.gamepedia.com/index.php?title=User:Majr/goToTop.js&action=raw&ctype=text/javascript' );

/* Welcome script from User:ITechieGamer */

$(document).ready(function { // Add a new portal before the social profiles in the toolbox  var $welcomeGroup = $(' ').append($('Welcoming users ')),      $welcomeBody = $(' '),      $goodWelcomeLink = $('Good welcome'),      $badWelcomeLink = $('Bad welcome'),      $newUserLink = $('New users');  $($welcomeGroup.append($welcomeBody.html($('').append($('').html($goodWelcomeLink)).append($('').html($badWelcomeLink)).append($('').html($newUserLink))))).insertBefore('#p-socialProfiles');

$('#t-goodwelcome').click( function {   // Notify the user for the username    var username = prompt('Who would you like to good welcome?');    if(username == '' || username == null) return;

// Welcome the user window.open('/index.php?action=edit&section=new&title=User_talk:'+username+'&preload=User:ITechieGamer/welcome/good&preloadtitle=Welcome%21&preloadparams%5b%5d='+username+'&preloadparams%5b%5d=%7e', '_blank'); });

$('#t-badwelcome').click( function {   // Notify the user for the username    var username = prompt('Who would you like to bad welcome?');    if(username == '' || username == null) return;

// Welcome the user window.open('/index.php?action=edit&section=new&title=User_talk:'+username+'&preload=User:ITechieGamer/welcome/bad&preloadtitle=Welcome&preloadparams%5b%5d=%7e', '_blank'); }); });

/* Add image at the top right corner to blocked users' userpages */

if ( mw.config.get( 'wgRelevantUserName' ) ) { $( function {		'use strict';		var title = 'This username/IP number is blocked';		( new mw.Api ).get( { action: 'query', format: 'json', list: 'blocks', formatversion: 2, bkusers: mw.config.get( 'wgRelevantUserName' ) } ).done( function( data ) { if ( data.query.blocks.length ) { $( '.mw-indicators' ).prepend(					'' +						'<img src="//upload.wikimedia.org/wikipedia/commons/4/4f/Blocked_user.svg" height="20">' +					'</a>'				); }		} );	} ); }

// Scripts, some imported from Wiki Pedia, and modified to use on this wiki //

//

/* HotCat - fast addition of categories */

mw.loader.load( '//commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&action=raw&ctype=text/javascript' );

/* PopUps - article previews and quick links while hower overlins rather than the default "tooltip" */ mw.loader.load('//meta.wikimedia.org/w/index.php?title=Mediawiki:Gadget-popups.js&action=raw&ctype=text/javascript');

mw.loader.load('//terraria.gamepedia.com/index.php?title=MediaWiki:Gadget-PastBlocks.js&action=raw&ctype=text/javascript');

/* IP info */ mw.loader.load('//terraria.gamepedia.com/index.php?title=MediaWiki:Gadget-ipInfo.js&action=raw&ctype=text/javascript');

/* [edit] link for the top section */ mw.loader.load('//en.wikipedia.org/w/index.php?title=Mediawiki:Gadget-edittop.js&action=raw&ctype=text/javascript');

/* More Watchlist tools */

mw.loader.load( '//minecraft.gamepedia.com/index.php?title=User:Psl85/smartwatchlist.js&action=raw&ctype=text/javascript' );

/* RC options */ mw.loader.load( '//minecraft.gamepedia.com/index.php?title=User:Psl85/rc.js&action=raw&ctype=text/javascript' );

/* Dropdown menus for page tools and options */ mw.loader.load( '//minecraft.gamepedia.com/index.php?title=User:Psl85/dropdownmenu.js&action=raw&ctype=text/javascript' );

/* Note if there is error with javascript on a page */ // This only shows alerts for things after this handler is installed of course. // Because this is a gadget, error reporting can thus be inconsistent. var originalErrorHandler = window.onerror || null; // Column and error args are optional window.onerror = function ( message, url, line, colomn, error ) { var $msg = $( ' ' ); if ( url ) { $( ' ' )			.text( url + ' at line ' + line + ': ' ) .appendTo( $msg ); }	$( ' ' )		.text( message ) .appendTo( $msg );

mw.notify( $msg, {		autoHide: true,		autoHideSeconds: 10,		tag: null,		title: 'An error occured:',		type: 'error'	} ); if (originalErrorHandler) { return originalErrorHandler.apply(this, arguments); } }; // unbind on leaving the page $( window ) .on( 'unload', function {		window.onerror = originalErrorHandler;	} );

/* "Padlocks" on locked pages */ $( function {	'use strict';	var restrictions = mw.config.get( 'wgRestrictionEdit' );	if ( restrictions ) {		if ( restrictions.indexOf( 'sysop' ) !== -1 ) {			$( '.mw-indicators' ).prepend( '<img title="This page is fully protected so only administrators can edit it." id="gadget-protectionindicators-' + restrictions[ 0 ] + '" src="//upload.wikimedia.org/wikipedia/commons/5/59/Padlock.svg" height="20" />' );		} else if ( restrictions.indexOf( 'autoconfirmed' ) !== -1 ) {			$( '.mw-indicators' ).prepend( '<img title="This page is semi-protected so only logged-in users can edit it." id="gadget-protectionindicators-' + restrictions[ 0 ] + '" src="//upload.wikimedia.org/wikipedia/commons/f/fc/Padlock-silver.svg" height="20" />' );		} else if ( restrictions.indexOf( 'director' ) !== -1 ) {			$( 'mw-indicators' ).prepend( '<img title="This page is director-protected so only directors can edit it." id="gadget-protectionindicators-' + restrictions[ 0 ] + '" src="//upload.wikimedia.org/wikipedia/commons/4/4f/Padlock-purple.svg" height="20" />' );		}		}	} );

/* Add a floating JavaScript alert when my talk page gets edited */ ( function( $, mw ) { $alert = ' '; $alert += ' <img style="display: block;" src="//upload.wikimedia.org/wikipedia/commons/3/36/CloseWindow.svg"/> '; $alert += ' you havenew unread messages</a> on your discussion page. (diff</a>) '; $alert += ' '; $(document).ready(function { var newMsgRevisionId = mw.config.get( 'wgUserNewMsgRevisionId' ); if ( newMsgRevisionId ) { var userName = mw.config.get( 'wgUserName' ); var talkLink = '/User_talk:' + userName + '?redirect=no'; var diffLink = '/index.php?title=User_talk:' + userName + '&oldid=' + newMsgRevisionId + '&diff=cur'; $( 'body' ).append( $alert ); $( '#mw-echo-close-box' ).click( function( e ) {			$( '#mw-echo-sliding-alert' ).hide;			e.preventDefault;		} ); $( 'a#mw-echo-talk-link' ).attr( 'href', talkLink ); $( 'a#mw-echo-talk-diff-link' ).attr( 'href', diffLink ); mw.config.set( 'echoNewMsgAlertDisplayed', true ); } } ); } )( jQuery, mediaWiki ); //

$( '#ca-user a' ).text( 'User' ); $( '#ca-history a' ).text( 'Page history' ); $( '#ca-move a' ).text( 'Rename' ); $( '#pt-preferences a' ).text( 'Options' ); $( '#pt-logout a' ).text( 'Sign Out' ); $( '#pt-mytalk a' ).text( 'Discussion' );

/* Hide junk (example: ads, social features, and other things that i do not like) */ $('#p-sitePromos').remove; $('#p-socialProfiles').remove; $('#p-sharing').remove; $('.t-netbar-curseInfo').remove; $('#socialContainer').remove; $('#feedlinks').remove; $('.atfmrec').remove; $('.show-ads').remove; $('#siteNotice').remove; $('.curse-stripe').remove;

setTimeout(function{   $('.show-ads').remove;    //$('iframe').remove; },500);