v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

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

From Dwarf Fortress Wiki
Jump to navigation Jump to search
(i like knowing the server time, i feel naked without it)
 
(o rite, i forgot that import script was a common.js thing)
Line 1: Line 1:
 +
/** Import module *************************************************************
 +
*
 +
*  Description: Includes a raw wiki page as javascript or CSS,
 +
*              used for including user made modules.
 +
*  Maintainers: wikipedia:User:AzaToth
 +
*/
 +
importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice
 +
function importScript( page ) {
 +
    if( importedScripts[page] ) {
 +
        return;
 +
    }
 +
    importedScripts[page] = true;
 +
    var url = wgScriptPath
 +
            + '/index.php?title='
 +
            + encodeURIComponent( page.replace( / /g, '_' ) )
 +
            + '&action=raw&ctype=text/javascript';
 +
    var scriptElem = document.createElement( 'script' );
 +
    scriptElem.setAttribute( 'src' , url );
 +
    scriptElem.setAttribute( 'type' , 'text/javascript' );
 +
    document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
 +
}
 +
 +
function importStylesheet( page ) {
 +
    var sheet = '@import "'
 +
              + wgScriptPath
 +
              + '/index.php?title='
 +
              + encodeURIComponent( page.replace( / /g, '_' ) )
 +
              + '&action=raw&ctype=text/css";'
 +
    var styleElem = document.createElement( 'style' );
 +
    styleElem.setAttribute( 'type' , 'text/css' );
 +
    styleElem.appendChild( document.createTextNode( sheet ) );
 +
    document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
 +
}
 +
 +
 
importScript('User:Emi/Scripts/Clock.js');
 
importScript('User:Emi/Scripts/Clock.js');

Revision as of 20:37, 11 March 2010

/** Import module *************************************************************
 *
 *  Description: Includes a raw wiki page as javascript or CSS, 
 *               used for including user made modules.
 *  Maintainers: wikipedia:User:AzaToth
 */
importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice
function importScript( page ) {
    if( importedScripts[page] ) {
        return;
    }
    importedScripts[page] = true;
    var url = wgScriptPath
            + '/index.php?title='
            + encodeURIComponent( page.replace( / /g, '_' ) )
            + '&action=raw&ctype=text/javascript';
    var scriptElem = document.createElement( 'script' );
    scriptElem.setAttribute( 'src' , url );
    scriptElem.setAttribute( 'type' , 'text/javascript' );
    document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
}

function importStylesheet( page ) {
    var sheet = '@import "'
              + wgScriptPath
              + '/index.php?title='
              + encodeURIComponent( page.replace( / /g, '_' ) )
              + '&action=raw&ctype=text/css";'
    var styleElem = document.createElement( 'style' );
    styleElem.setAttribute( 'type' , 'text/css' );
    styleElem.appendChild( document.createTextNode( sheet ) );
    document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
}


importScript('User:Emi/Scripts/Clock.js');