User:Gifted9/common.js

The most up-to-date image and information guide on Webkinz Classic items, events, and more!

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// javascript wiki browser: autowikibrowser but slightly uglier and in-browser, for when i'm not on my home computer
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript');

// add somewhat sensitive stuff to my user tools dropdown so it's more accessible to me and less accessible to everyone reading my userpage
// documentation at [[mw:ResourceLoader/Core modules]] and https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.util-method-addPortletLink

    // First wait for mediawiki.util to load, and the page to be ready.
    mw.loader.using('mediawiki.util', function() {

        // General usage pattern: mw.util.addPortletLink( portletId, href, text /* Optional: , id, tooltip, accesskey, nextnode */ );

        // personal common.js
        mw.util.addPortletLink(
            'p-personal',
            mw.util.getUrl('User:Gifted9/common.js'),
            'User:Gifted9/common.js');

        // all subpages of my userpage
        mw.util.addPortletLink(
            'p-personal',
            mw.util.getUrl('Special:PrefixIndex/User:Gifted9'),
            'Special:PrefixIndex/User:Gifted9');

/**
 * adds history and delete links to Special:WhatLinksHere 
 * @source: https://www.mediawiki.org/wiki/Snippets/Special:WhatLinksHere_history_link
 * @rev: 2
 */
$( '#mw-whatlinkshere-list li' ).each( function() {
	var url = mw.config.get( 'wgScript' ) + '?title=' + encodeURIComponent( $( 'a:first', this ).text() ) + '&action=';
	$( '.mw-whatlinkshere-tools a:last', this )
		.after( $( '<a>' ).attr( 'href', url + 'delete' ).text( 'delete' ) ).after( ' | ' )
		.after( $( '<a>' ).attr( 'href', url + 'history' ).text( 'hist' ) ).after( ' | ' )
});
    });

/*** Restorer ***/

// Easily restore an older version of a page
// Documentation at [[w:User:BrandonXLF/Restorer]]
// By [[w:User:BrandonXLF]]

$(function() {
	if (mw.config.get('wgAction') != 'history') return;

	window.restorerSummary = window.restorerSummary ||
		'Restored revision $ID by [[Special:Contributions/$USER|$USER]] ([[w:User:BrandonXLF/Restorer|Restorer]])';

	function restore(revid) {
		var api = new mw.Api();

		return api.get({
			action: 'query',
			revids: revid,
			prop: 'revisions',
			rvprop: 'user',
			format: 'json',
			formatversion: '2'
		}).then(function(res) {
			var user = res.query.pages[0].revisions[0].user;

			return api.postWithEditToken({
				action: 'edit',
				pageid: mw.config.get('wgArticleId'),
				undo: mw.config.get('wgCurRevisionId'),
				undoafter: revid,
				summary: window.restorerSummary.replace(/\$ID/g, revid).replace(/\$USER/g, user)
			});
		}).then(
			function() {
				mw.notify('Restored revision successfully.');
				location.reload();
			},
			function(_, data) {
				mw.notify(api.getErrorMessage(data), {type: 'error'});
			}
		);
	}

	function addLink(item) {
		var revid = item.getAttribute('data-mw-revid');
		if (revid == mw.config.get('wgCurRevisionId')) return;

		var links = item.querySelector('.comment + .mw-changeslist-links');
		if (!links) return;

		var parent = document.createElement('span'),
			el = document.createElement('a');

		el.addEventListener('click', function() {
			el.className = 'restorer-loading';

			restore(revid).always(function() {
				el.className = '';
			});
		});

		el.textContent = 'restore';
		parent.appendChild(el);
		links.appendChild(parent);
	}

	var parents = document.querySelectorAll('li[data-mw-revid]');

	for (var i = 0; i < parents.length; i++) {
		addLink(parents[i]);
	}

	mw.loader.addStyleTag(
		'@keyframes restorer-loading {' +
		'0%, 100% {content: " ⡁"} 16% {content: " ⡈"} 33% {content: " ⠔"} 50% {content: " ⠒"} 66% {content: " ⠢"} 83% {content: " ⢁"}}' +
		'.restorer-loading::after {white-space: pre; content: ""; animation: restorer-loading 0.5s infinite}'
	);
});