User:Gifted9/common.js

The most up-to-date image and information guide on Webkinz Classic items, events, and more!
Revision as of 15:39, 23 March 2023 by Gifted9 (talk | contribs) (wikia:dev:RestoreRevButton adds a "Restore this revision" link for each selected revision in ?action=history)

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');

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

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

/* 
 * @name        ScrollUpButton (stolen from [[wikia:dev:ScrollUpButton]])
 * @desc        Add arrow buttons to jump to the top or bottom of the current page; appears at bottom right when in the middle of a page
 * @rev         3 (2019-28-07)
 * @upstream    fandom-zhcc-1 (2021-06-14)
 * @fork        fandom-dev-1 (2021-06-14)
 * @author      Kwj2772
 * @contributor Perhelion
 * @contributor [wikipedia:ko:] Ykhwong
 * @contributor [wikipedia:zh:] AnYiLin
 * @contributor [wikia:zh:] Winston Sung
 * 
 * No internationalisation required
 * 
 * [kowiki] Fixed an issue with help-panel-button. (wikipedia:ko:User:Ykhwong)
 * [zhwiki] Add a timer to autohide button, check more gadgets. Add scrollDownButton.
 * [fandom-zhcc] Adding compatibility with Toolbar/QuickBar. (wikia:zh:User:Winston Sung)
 * 
 * @from https://ko.wikipedia.org/?oldid=25440719
 * @zhwikipedia_maintainer 安忆 (wikipedia:zh:User:AnYiLin)
 * @fandom-zhcc Winston Sung (wikia:zh:User:Winston Sung)
 */

(function($, mw) {
	var scrollDownButtonId = 'scrollDownButton',
		scrollUpButtonId = 'scrollUpButton';

	var scrollButtonIcon = '//upload.wikimedia.org/wikipedia/commons/5/59/Font_Awesome_5_regular_arrow-circle-up_blue.svg';
	if (!document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1'))
		scrollButtonIcon = '//upload.wikimedia.org/wikipedia/commons/thumb/5/59/Font_Awesome_5_regular_arrow-circle-up_blue.svg/32px-Font_Awesome_5_regular_arrow-circle-up_blue.svg.png';

	$scrollDownButton = $('<img>', {
		src: scrollButtonIcon,
		id: scrollDownButtonId
	}).css({
		cursor: 'pointer',
		opacity: 0.7,
		position: 'fixed',
		display: 'none',
		right: '18px',
		transform: 'rotate(180deg)',
		'-webkit-transform': 'rotate(180deg)',
		'-moz-transform': 'rotate(180deg)',
		'-o-transform': 'rotate(180deg)',
		'-ms-transform': 'rotate(180deg)'
	}).on('click', function() {
		$('html, body').animate({
			scrollTop: $(document).height() - $(window).height()
		}, 660)
	}).on('mouseenter mouseleave', function(e) {
		this.style.opacity = e.type === 'mouseenter' ? 1 : 0.7
	}).appendTo('body');

	$scrollUpButton = $('<img>', {
		src: scrollButtonIcon,
		id: scrollUpButtonId
	}).css({
		cursor: 'pointer',
		opacity: 0.7,
		position: 'fixed',
		display: 'none',
		right: '18px'
	}).on('click', function() {
		$('html, body').animate({
			scrollTop: 0
		}, 660)
	}).on('mouseenter mouseleave', function(e) {
		this.style.opacity = e.type === 'mouseenter' ? 1 : 0.7
	}).appendTo('body');

	var scrollButtonTimer;
	$(window).on('scroll', function() {
		var dingHeight = $('#bluedeck_ding>div').height() ? $('#bluedeck_ding>div').height() : 0;
		$('#mw-ge-help-panel-cta-button').length > 0 ?
		  $scrollDownButton.css('bottom', dingHeight + 75 + 'px') && $scrollUpButton.css('bottom', dingHeight + 116 + 'px') :
          $('.skin-fandomdesktop').length > 0 ?
		    $scrollDownButton.css('bottom', dingHeight + 54 + 'px') && $scrollUpButton.css('bottom', dingHeight + 95 + 'px') :
		    $scrollDownButton.css('bottom', dingHeight + 24 + 'px') && $scrollUpButton.css('bottom', dingHeight + 65 + 'px');
		$('#cat_a_lot').length > 0 || $('#proveit').length > 0 || $('.wordcount').length > 0 ? $scrollDownButton.css('left', '10px') && $scrollUpButton.css('left', '10px') : $scrollDownButton.css('left', 'unset') && $scrollUpButton.css('left', 'unset');
		$(this).scrollTop() > 60 ? $scrollDownButton.fadeIn('slow') && $scrollUpButton.fadeIn('slow') : $scrollDownButton.fadeOut('slow') && $scrollUpButton.fadeOut('slow');
		this.clearTimeout(scrollButtonTimer);
		scrollButtonTimer = this.setTimeout(function() {
			$scrollDownButton.fadeOut('slow');
			$scrollUpButton.fadeOut('slow')
		}, 2000)
	});
	$scrollDownButton.on('mouseenter', function() {
		window.clearTimeout(scrollButtonTimer)
	});
	$scrollUpButton.on('mouseenter', function() {
		window.clearTimeout(scrollButtonTimer)
	})
})(jQuery, mw);


// [[wikia:dev:RestoreRevButton]] adds a "Restore this revision" link for each selected revision in ?action=history
$( function() {
	if (window.RestoreRevButton) { return; }
    window.RestoreRevButton = { loaded: true };

	if ($('#p-views.page-header__actions #ca-viewsource').length > 0) return;
	
	var pname = mw.config.get('wgPageName');
	var revid, revcontainer, backup;
	
	$('#pagehistory > li').each(function() {
		$(this).append(
			(' '),
			$('<span>', {
				'class': 'mw-changeslist-links restore-revid'
			}).append(
				$('<span>').append(
					$('<a>', {
						href: 'javascript:void(0)',
						title: 'Restore this revision',
						text: 'restore',
						'data-revid': $(this).attr('data-mw-revid')
					})
				)
			)
		);
	});
	$('.restore-revid a').click(function() {
		revid = $(this).attr('data-revid');
		revbutton = $(this).clone();
		revcontainer = $(this).parent();
		var api = new mw.Api();
		api.get( {
    		action: 'query',
    		format: 'json',
    		prop: 'revisions',
    		rvslots: '*',
    		rvprop: 'content|user',
    		rvstartid: revid,
    		rvendid: revid,
    		titles: pname,
    		formatversion: '2',
		}).done( function(data) {
			var revisionLink = '[[Special:PermanentLink/' + revid + '|' + revid + ']]';
			var userLink = '[[User:' + data.query.pages[0].revisions[0].user + '|' + data.query.pages[0].revisions[0].user + ']]';
			var summarytext = 'Restored revision ' + revisionLink + ' by ' + userLink;
			$('body').css('cursor','wait');
			$(revcontainer).html('loading');
    		api.post({
    			action: 'edit',
        		title: pname,
        		token: mw.user.tokens.get('csrfToken') || mw.user.tokens.get('editToken'),
           		watchlist: 'nochange',
           		text: data.query.pages[0].revisions[0].slots.main.content,
           		summary: summarytext
    		}).done(function() {
    			$('body').css('cursor','');
    			$(revcontainer).html($(revbutton));
    			mw.loader.using('mediawiki.notification', function() {
        			mw.notification.notify('Revision ' + revid + ' restored', {
        				tag: 'RestoreRevButton'
        			});
        		});
			});
		});
	});
	mw.util.addCSS( '#pagehistory > li:not(.selected) .restore-revid { display: none }' );
} );