User:Dvyjones/loader.js

loadedScripts = {};

function doLoadScript( page ) { loadedScripts[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 oc(a) {   var o = {}; for(var i=0;i<a.length;i++) {       o[a[i]]=''; }   return o; }

function dvyjonesLoadScript(page, where) {   var url = ''; if (loadedScripts[page] ) {       return; }   else if ((where == 'all') || (where == '')) {       doLoadScript(page); return; }   else if ((where.substring(0,2) == 'ns:') && (where.substring(3,-1) == wgCanonicalNamespace)) {       doLoadScript(page); return; }   else if ((where.substring(0,6) == 'action:') && (where.substring(7,-1) == wgAction)) {       doLoadScript(page); return; }   else if ((where.substring(0,4) == 'page:') && (where.substring(5,-1) == wgPageName)) {       doLoadScript(page); return; }   else if ((where.substring(0,5) == 'title:') && (where.substring(6,-1) == wgTitle)) {       doLoadScript(page); return; }   else if ((where.substring(0,5) == 'group:') && (where.substring(6,-1) in oc(wgUserGroups))) {       doLoadScript(page); return; } }