Jump to content

User:Kangaroopower/rawtab.js

From Wikipedia, the free encyclopedia
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 says raw 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'),
		end;

	if ((page.endsWith('.js') || page.endsWith('.css')) && mw.config.get('wgNamespaceNumber') !== -1) { 
		end = page.endsWith('.js') ? 'javascript' : 'css';
		mw.util.addPortletLink( 'p-namespaces', '/w/index.php?title='+ page +'&action=raw&ctype=text/'+ end, 'Raw');
	}
});