Documentation may be created at User:Psl85/common.js/doc.
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.
mw.loader.load( '//minecraft.gamepedia.com/index.php?title=User:Majr/goToTop.js&action=raw&ctype=text/javascript' );
/* 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(
'<a href="//commons.wikimedia.org/wiki/File:Blocked_user.svg" class="mw-indicator" id="gadget-blockindicator" title="' + title + '">' +
'<img src="//upload.wikimedia.org/wikipedia/commons/4/4f/Blocked_user.svg" height="20">' +
'</a>'
);
}
} );
} );
}
mw.loader.load( '//commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&action=raw&ctype=text/javascript' );
/* Auto-sign posts */
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=user:perhelion/signing.js&action=raw&ctype=text/javascript' );
/* PopUps - article previews and quick links while hower overlins rather than the default "tooltip" */
window.popupStructure = 'menus';
window.popupRevertSummaryPrompt = true;
window.popupMinorReverts = true;
mw.loader.load('//meta.wikimedia.org/w/index.php?title=Mediawiki:Gadget-popups.js&action=raw&ctype=text/javascript');
/* Past Blocks */
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');
/* 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' );
/* Wiki+ */
mw.loader.load('https://wikiplus-app.smartgslb.com/Main.js');
/* 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 = $( '<p>' );
if ( url ) {
$( '<span>' )
.text( url + ' at line ' + line + ': ' )
.appendTo( $msg );
}
$( '<span>' )
.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;
} );
/* Add a floating JavaScript alert when my talk page gets edited */
( function( $, mw ) {
$alert = '<div id="mw-echo-sliding-alert">';
$alert += '<div id="mw-echo-close-box"><img style="display: block;" src="//upload.wikimedia.org/wikipedia/commons/3/36/CloseWindow.svg"/></div>';
$alert += '<div id="mw-echo-alert-text">you have<a href="#" id="mw-echo-talk-link">new unread messages</a> on your discussion page. (<a href="#" id="mw-echo-talk-diff-link">diff</a>)</div>';
$alert += '</div>';
$(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 );
//Category: Wikipedia scripts
$( function() {
mw.loader.using( [ "mediawiki.util", "mediawiki.api.edit" ] ).then( function () {
var link = mw.util.addPortletLink(
"p-cactions",
"#",
"Undo last edit",
"ca-undo",
"Using the API, undo the last edit made to this page."
);
link.addEventListener( "click", function () {
var api = new mw.Api();
api.get( {
prop: 'revisions',
rvprop: 'content',
rvlimit: 2,
titles: mw.config.get( "wgPageName" )
} ).done( function ( data ) {
if ( !data.query || !data.query.pages ) return;
var pageid = Object.getOwnPropertyNames( data.query.pages )[0],
text = data.query.pages[pageid].revisions[1]["*"];
api.postWithToken( "csrf", {
action: "edit",
title: mw.config.get( "wgPageName" ),
summary: "Undoing last edit ([[User:Enterprisey/undo-last-edit.js|undo-last-edit]])",
minor: "yes",
text: text
} ).done ( function ( data ) {
if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {
mw.notify( "Undid last edit successfully! Reloading..." );
document.location.reload( true );
}
} );
} );
} );
} );
} );
/**
* Ajax Undo links
*
* Adds an Ajax undo link next to the normal undo link on page histories
* and on diff pages
*/
jQuery(document).ready( function ( $ ) {
"use strict";
function createUndoLink( diffUndoUrl ) {
var $ajaxUndoLink = $( '<a />' ).text( 'AJAX Undo' ).attr( 'href', '#' ).click( function () {
var $ajaxUndoLinkob = $( this ),
undoIdRegex = /&undo=([^&]*)/,
undoId = undoIdRegex.exec( diffUndoUrl )[1],
editToken,
etUrl = wgServer + wgScriptPath + '/api.php?action=query&prop=info|revisions&intoken=edit&titles=' + encodeURIComponent( wgPageName ) + '&format=json';
$ajaxUndoLinkob.html( ' <img src="http://images2.wikia.nocookie.net/dev/images/8/82/Facebook_throbber.gif" style="vertical-align: baseline;" border="0" alt="Undoing..." />' );
$.getJSON( etUrl, function ( data ) {
editToken = data.query.pages[wgArticleId].edittoken;
$.ajax( {
url: wgScriptPath + '/api.php?',
data: 'action=edit&format=json&title=' + encodeURIComponent( wgPageName ) + '&undo=' + encodeURIComponent( undoId ) + '&minor=yes&token=' + encodeURIComponent( editToken ),
dataType: 'json',
type: 'POST',
success: function ( data ) {
if ( data.edit && data.edit.result === 'Success' ) {
$ajaxUndoLinkob.text( '(undone)' );
} else if ( data.error && data.error.code === 'undofailure' ) {
$ajaxUndoLinkob.text( '(error)' );
alert( data.error.info );
} else {
$ajaxUndoLinkob.text( '(error)' );
alert( 'Error: Unknown result from API.' );
}
},
error: function () {
$ajaxUndoLinkob.text( '(error)' );
}
} );
} );
} );
return $ajaxUndoLink;
}
if ( $( '.mw-history-undo > a' ).length && wgAction === 'history' ) {
$( '.mw-history-undo > a' ).each( function () {
var diffUndoUrl = $( this ).attr( 'href' ),
$ajaxUndoLink = createUndoLink( diffUndoUrl );
$( this ).parent().after( ' | ', $ajaxUndoLink );
} );
} else if ( $( 'table.diff' ).length && typeof $.getUrlVar( 'diff' ) !== 'undefined' ) {
var $diffUndoLink = $( 'table.diff' ).find( '.diff-ntitle > #mw-diff-ntitle1 a:last' ),
diffUndoUrl = $diffUndoLink.attr( 'href' ),
$ajaxDiffUndoLink = createUndoLink( diffUndoUrl );
$diffUndoLink.parent().append( ' (', $ajaxDiffUndoLink, ')' );
}
} );
$( '#ca-user a' ).text( 'User' );
$( '#ca-history a' ).text( 'Page history' );
$( '#ca-move a' ).text( 'Rename' );
$( '#pt-preferences a' ).text( '⚙' );
$( '#ca-emailuser a' ).text( '📧' );
$( '#pt-logout a' ).text( 'Sign Out' );
$( '#pt-mytalk a' ).text( 'Discussion' );
$( '#ca-edit a' ).text( 'edit' );
/* 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);
// JavaScript code
$(function() {
var blockedDiv = $(".blocked");
if (blockedDiv.length > 0) {
var usernameSpan;
var username;
var targetBlock = $(".userinfo");
if ($("#mw-mf-viewport").length > 0) { // Detect mobile mode
usernameSpan = $("#section_0");
username = usernameSpan.html().match(/UserProfile:(.*)/)[1];
} else {
usernameSpan = $("h1 .mw-headline");
username = usernameSpan.attr("id");
}
$('<div class="blocked-no-stamp">').append(
$('<span>')
.append("This user is currently blocked! ")
.append($("<a>")
.attr("href", "https://minecraft.gamepedia.com/index.php?title=Special:Log/block&page=User%3A" + username)
.attr("title", "Block log")
.text("Check the block log")
).append(" • ")
.append($("<a>")
.attr("href", "https://minecraft.gamepedia.com/Special:GlobalBlockList?wpTarget=" + username)
.attr("title", "Global block log")
.text("List global blocks")
).append("")
).appendTo(targetBlock);
}
});
/* Open links outside Minecraft Wiki (external web links) in a new tab */
$( document ).on( 'click', 'a[href]', function( e ) {
if ( !this.href.match( mw.config.get( 'wgServer' ) ) )
this.target = '_BLANK';
});