User:Cåm/global.js

/** __NOWYSIWYG__ * ============================================= * The majority of the scripts here are for * personal use as they modify parts of the * oasis skin violating Terms of Use. * ============================================= * @author Cåm */ (function ($, mw) { /*jshint forin:true, eqeqeq:true, quotmark:single, bitwise:true, strict:true, undef:true, unused:false, curly:true, undef:true, browser:true, trailing:true, jquery:true, indent:4 */ /*global mediaWiki, importArticles */	'use strict'; /* Run scripts below this line */

// import variables var monoBookText = 'Monobook', oasisText = 'Oasis', fdButtons = [];

// Fastdelete button names fdButtons[fdButtons.length] = { // RuneScape Wiki only 'summary': 'Successful RfD', 'label': 'RfD' };

fdButtons[fdButtons.length] = { 'summary': 'Housekeeping', 'label': 'Housekeeping' };

/**	 * Imports * See Help:Including additional JavaScript and CSS for help with importArticles * See imported pages for documentation * @todo Move AntiUnicruft & Tabkey to Greasemonkey (or equivalent) */	importArticles({		type: 'script',		articles: [			'u:dev:AjaxUndo/code.js',		// Add a undo link to page diffs and histories				'u:dev:AllPagesHideRedirect/code.js',	// Adds a hide redirect button to AllPages & PrefixIndex			'u:dev:AntiUnicruft/code.js',		// Removes invisible characters			'u:dev:FastDelete/code.js',		// Fast Delete buttons			'u:dev:SkinSwitchButton/code.js',	// Switch between Monobook & Oasis			'u:dev:UnsafeScripts/code.js',		// Allows import of scripts into .js pages			'u:kangaroopower:MediaWiki:Scope.js',	// FindReplace function for source editor			'u:runescape:User:Cåm/oldfilepages.js',	// Changes file pages back to original styling			'u:runescape:User:Joeytje50/tabkey.js',	// Allows use of tabkey for use in scripts			'u:wikimarks:Client.js'			// Customisable On The Wiki tab		]	});

/**	 * Special:Editcount link in profile masthead * Original by Matthew2602 * Fixed for Special:Contributions by Cåm */	function editcountMasthead { if ($('#UserProfileMasthead').length === 0) { return; }

if (mw.config.get('wgCanonicalNamespace') === 'Special') { var user = mw.config.get( 'wgTitle').split('/'); $('#UserProfileMasthead .tally em').html('' + $('#UserProfileMasthead .tally em').text + ''); } else { $('#UserProfileMasthead .tally em').html('' + $('#UserProfileMasthead .tally em').text + ''); }	}

/**	 * Unchecks redirect checkbox on file pages * Because redirects in file namespace do nothing */	function uncheckFileRedirects { if(mw.config.get('wgCanonicalSpecialPageName') === 'Movepage' && (/File/).test( mw.config.get('wgTitle'))) { $('#wpLeaveRedirect').removeAttr('checked'); }	}

/**	 * Prevent autoplay on youtube videos embedded into file pages * Original from w:Thread:522896 * Fixed for file pages by Cåm */

// For user page youtube autoplay // Normally embedded through templates and mediawiki pages var source;

function switchAutoplay {

if(!$('iframe[src*="youtube.com"]').length) { return; }

$('iframe[src*="youtube.com"]').each(function {			source = $(this).attr('src');			if (source.indexOf('autoplay=1') !== -1) {				$(this).attr('src', source.replace('autoplay=1', 'autoplay=0'));			}		}); }

// For file pages function removeAutoplay {

// abort if not on a file page if (!$('#file').length) { return; }		// abort if not a video // normal images use '#file > a > img' // videos use '#file > iframe > (youtube stuff)' if ($('#file > a').length) { return; }		var loading; // used in setInterval function iframeLoad { if ($('#file iframe[src*="youtube.com"]').length) { switchAutoplay; abortTimer; }		}		// aborts the timer function abortTimer { clearInterval(loading); }		// there is probably a better way of doing this // but as this actually works... loading = setInterval(iframeLoad, 50); // 0.05s

}

/**	 * Adds a link to headers allowing easier copy/paste linking */	function linkHeaders { var $header = $('.mw-headline'), $id = $.map($header, function (n, i) {			return n.id;		}), i;

for (i = 0; i < $id.length; i++) { $('#' + $id[i]).after('  '); }	}

$(function {		editcountMasthead;		uncheckFileRedirects;		removeAutoplay;		switchAutoplay;		linkHeaders;	});

/* Run scripts above this line */ }(jQuery, mediaWiki)); /* */