Jump to content

User:Kangaroopower/rawtab.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Kangaroopower (talk | contribs) at 02:38, 15 February 2014 (some css fixes). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// Adds a portlet that saysraw to js and css pages which links to the raw text version of the page
/* Put: 
// [[User:Kangaroopower/scripts/rawtab.js]] 
importScript('User:Kangaroopower/scripts/rawtab.js');
in your skins's js page to use
*/

String.prototype.endsWith = function (txt) {
	if (txt.length > this.length || txt.length <= 0) return false; 
    return this.substring(this.length - txt.length, this.length) === txt;
}
 
$(document).ready(function() {
	var page = mw.config.get('wgPageName'),
		tab = '<li id="ca-raw"><span><a href="/w/index.php?title='+ page +'&action=raw&ctype=text/javascript">Raw</a></span></li>';
 
	if ((page.endsWith('.js') || page.endsWith('.css')) && mw.config.get('wgNamespaceNumber') !== -1) { 
		if (mw.config.get( 'skin' ) === 'vector') {	
			$('#ca-talk').after(tab);
		} else {
			$('#ca-move').before();
		}
	}
});