User:Inductiveload/Add toolbar buttons.js

// ================================================================== // Jump to file.js // // Adds a link to the file at Commons from a Page: namespace page. // ================================================================== function jumpToFile { //regex to get the filename var r = new RegExp( "Page:(.*)/(\\d+)" ); var match = r.exec(wgPageName); if (match) { if (!document.getElementById) { return; }           x = document.getElementById('ca-index'); if (!x) { return; }           var commonsUrl = "http://commons.wikimedia.org/wiki/File:" + match[1] x = x.parentNode liTag = document.createElement('LI'); liTag.id = 'jumptofile'; aTag = document.createElement('A'); aTag.accessKey = "a"; aTag.href     = commonsUrl; aTag.target   = 'target="_newtab"' spanTag = document.createElement('SPAN'); imgTag = document.createElement('IMG'); imgTag.alt   = "File"; imgTag.height = 16; imgTag.width = 16; imgTag.src   = 'http://upload.wikimedia.org/wikipedia/commons/5/56/Book_go.png' spanTag.appendChild(imgTag); aTag.appendChild(spanTag); liTag.appendChild(aTag); x.appendChild(liTag); }       else { return } } //only show in the page namespace if ( wgNamespaceNumber == 104 ) { addOnloadHook(jumpToFile); }