async function fixJSForCodeSite( js ) {

		const moduleRE = /(import.*?)('|")(.*?)('|")/g;

		// convert https://threejs.org/build/three.module.js -> https://cdn.jsdelivr.net/npm/three@<version>
		// convert https://threejs.org/examples/jsm/.?? -> https://cdn.jsdelivr.net/npm/three@<version>/examples/jsm/.??

		if ( ! version ) {

			try {

				const res = await fetch( 'https://raw.githubusercontent.com/mrdoob/three.js/master/package.json' );
				const json = await res.json();
				version = json.version;

			} catch ( e ) {

				console.error( e );

			}

		}

		function addVersion( href ) {

			if ( href.startsWith( window.location.origin ) ) {

				if ( href.includes( '/build/three.module.js' ) ) {

					return `https://cdn.jsdelivr.net/npm/three@${version}`;

				} else if ( href.includes( '/examples/jsm/' ) ) {

					const url = new URL( href );
					return `https://cdn.jsdelivr.net/npm/three@${version}${url.pathname}${url.search}${url.hash}`;

				}

			}

			return href;

		}

		function addVersionToURL( match, start, q1, url, q2 ) {

			return start + q1 + addVersion( url ) + q2;

		}

		if ( version !== undefined ) {

			js = js.replace( moduleRE, addVersionToURL );

		}

		return js;

	}
Change JavaScript before uploading code to JSFiddle/Codepen

@param {string} js JavaScript source
@returns {string} The JavaScript source with any fixes applied.