Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
(() => {
	"use strict";

	const tânMùi = ( box ) => {
		const {
			mounted,
			tag,
			name = mw.config.get( "wgUserName" ) || "TDS Wiki",
			bg
		} = box.dataset;

		if ( mounted || !tag ) return;
		box.dataset.mounted = "1";

		const params = new URLSearchParams( { tag, name } );
		if ( bg ) params.set( "bg", bg );

		box.replaceChildren( Object.assign( document.createElement( "iframe" ), {
			src: `https://tools.tds.wiki/nametags/embed/?${ params }`,
			loading: "lazy",
			allowFullscreen: true,
			title: `Nametag preview: ${ tag }`
		} ) );
	};

	mw.hook( "wikipage.content" ).add( ( target ) => {
		if ( !target ) return;

		const nodes = Symbol.iterator in Object( target ) ? target : [ target ];
		for ( const node of nodes ) {
			if ( !node || typeof node.querySelectorAll !== "function" ) continue;
			if ( typeof node.matches === "function" && node.matches( ".nametag-embed" ) ) {
				tânMùi( node );
			}
			node.querySelectorAll( ".nametag-embed" ).forEach( tânMùi );
		}
	} );
})();