משתמש:Guycn2/getLoadedModuleNames.js

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
/*

This snippet allows you to quickly check which
ResourceLoader modules are currently loaded.

Just run the getLoadedModuleNames() function at your browser's
console, and a list of all loaded modules will be displayed.

A more useful feature is checking which modules are subsquently loaded AFTER
initial page load. As you interact with the page, more and more ResourceLoader
modules are loaded, and sometimes you may need to detect which specific
module(s) are used by a certain tool or feature.

For example, when you open the "Echo" notifications popup, about a dozen new
modules are being loaded, ones that were not initially loaded on page load.
You can use this snippet to get these newly-loaded module names. To do this:

1) Navigate to any wiki page (or reload the current one by pressing F5)
2) As soon as the page loads, run the getLoadedModuleNames() function
   at your browser's console.
3) Open the notifications popup by clicking either the "alerts"
   or the "notices" icons at the top of the page
4) Run the getLoadedModuleNames() function again at your browser's console
5) This time, you will only get the specific modules that were loaded
   _after_ your previous check, so you can infer that these modules are probably
   used by the Echo feature.
   (In this example, you'll see module names like ext.echo.logger and ext.echo.ui,
   from which you can also guess their relation to the Echo feature.)
   
   Written by: [[User:Guycn2]]

*/

window.getLoadedModuleNames = () => {
	
	'use strict';
	
	const modules = mw.loader.getModuleNames();
	
	let loadedModules = mw.config.get( 'loadedModules' );
	
	if ( loadedModules ) {
		
		mw.config.set( 'alreadyCheckedLoadedModuleNames', true );
		
		let newModules = [];
		
		modules.forEach( module => {
			if ( mw.loader.getState( module ) === 'ready' ) {
				newModules.push( module );
			}
		} );
		
		newModules = newModules.filter( module => !loadedModules.includes( module ) );
		
		console.log(
			`${ newModules.length } new modules were loaded after last check:`,
			newModules
		);
		
	}
	
	loadedModules = [];
	
	modules.forEach( module => {
		if ( mw.loader.getState( module ) === 'ready' ) {
			loadedModules.push( module );
		}
	} );
	
	mw.config.set( 'loadedModules', loadedModules );
	
	if ( mw.config.get( 'alreadyCheckedLoadedModuleNames' ) ) {
		return;
	}
	
	console.log(
		`There are ${ modules.length } modules available on this wiki. Of these, ${ loadedModules.length } are currently loaded:`,
		loadedModules
	);
	
};