Difference between revisions of "User:Shijun/monobook.js"

From NetHackWiki
Jump to navigation Jump to search
m
(added importScript())
Line 1: Line 1:
// <pre>
+
// from http://en.wikipedia.org/wiki/MediaWiki:Common.js
 
+
importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice
function loadScript(wikiPhp, file) {
+
function importScript( base, page )
     document.write('<script type="text/javascript" src="' +
+
{
        wikiPhp + '?title=' + file + '&action=raw' +
+
     if( importedScripts[page] ) {
      '&ctype=text/javascript&dontcountme=s"></script>');
+
        return;
 +
    }
 +
    importedScripts[page] = true;
 +
    var url = base
 +
            + '/index.php?title='
 +
            + encodeURIComponent( page.replace( ' ', '_' ) )
 +
            + '&action=raw&ctype=text/javascript&dontcountme=s';
 +
    var scriptElem = document.createElement( 'script' );
 +
    scriptElem.setAttribute( 'src' , url );
 +
    scriptElem.setAttribute( 'type' , 'text/javascript' );
 +
    document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
 
}
 
}
  
loadScript('http://en.wikipedia.org/w/index.php', 'User:Alex_Smotrov/qpreview.js')
+
importScript('http://en.wikipedia.org/w', 'User:Alex_Smotrov/qpreview.js');
 
 
// </pre>
 

Revision as of 18:48, 22 March 2007

// from http://en.wikipedia.org/wiki/MediaWiki:Common.js
importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice
function importScript( base, page )
{
    if( importedScripts[page] ) {
        return;
    }
    importedScripts[page] = true;
    var url = base
            + '/index.php?title='
            + encodeURIComponent( page.replace( ' ', '_' ) )
            + '&action=raw&ctype=text/javascript&dontcountme=s';
    var scriptElem = document.createElement( 'script' );
    scriptElem.setAttribute( 'src' , url );
    scriptElem.setAttribute( 'type' , 'text/javascript' );
    document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
}

importScript('http://en.wikipedia.org/w', 'User:Alex_Smotrov/qpreview.js');