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 19:42, 30 December 2011 (start). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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 raw tab on js pages */

function endsWith(text) {
    for(var i = 0; i < text.length; i++) {
	if(this.charAt((this.length - 1) - i) != text.charAt((text.length - 1) - i)) {return false;}
    }
    return true;
}

function addrawtab () {
   if (wgPageName.endsWith('.js') == true) {
	this.rawLink = new wa_element('li');
	this.rawLink.ele_obj.id	= 'ca-raw';
 
	if ( mw.config.get ( 'skin' ) == 'vector' ) {
		this.rawLink.ele_obj.innerHTML	= '<span><a href="http://en.wikipedia.org/index.php?title='+ wgPageName +'&action=raw&ctype=text/javascript">Raw</a></span>';
		this.csdHelperLink.attach(document.getElementById('ca-talk'), 'after');
	} else {
		this.rawLink.ele_obj.innerHTML	= '<a href="http://en.wikipedia.org/index.php?title='+ wgPageName +'&action=raw&ctype=text/javascript">Raw</a>';
		this.rawLink.attach(document.getElementById('ca-move'), 'before');
		}
   }
}
addOnloadHook('addrawtab');