User:Evad37/ScriptModules.js

Window.exportScriptModule = function(name, exported) { Window.exportScriptModule[name] = exported; }; Window.importScriptModule = function(module) { return mw.loader.using('mediawiki.util').then(function {		var modules = Array.isArray(module) ? module : [module];		var exports = modules.map(function(name) { var alreadyLoaded = ( Window.exportScriptModule[name] !== undefined ); return $.when(				alreadyLoaded ||				$.getScript( // When done for real, url would have `title=MediaWiki:Module/` 'https://en.wikipedia.org/w/index.php?title=User:Evad37/Module/' + mw.util.wikiUrlencode(name) + '.js&action=raw&ctype=text/javascript' )			)			.then(				function {					if ( Window.exportScriptModule[name] === undefined ) {						throw new Error('Script module "' + name + '" did not export anything!');					}					return Window.exportScriptModule[name];				},				function {					throw new Error('Failed to load script module "' + name + '"');				}			); });		return $.when.apply(null, exports).promise;	}); };