User:Thundercraft5/sw.js

// Add any test code here. // DO NOT SUBMIT TO JSRT! /* global self, Request */ /* jshint undef:true, esversion: 6 */ const map = { "test": "User:Thundercraft5/sw.js/module.js", };

self.addEventListener('fetch', event => { // ignore:line	let { request: { url }, request } = event;	url = new URL(url);	if (url.pathname.match(/^\/@(?!.*\/wiki\/).*(\.[mc]?js$)?/)) {		url = new URL(url);		let normalized = url.pathname.replace(/^\/@/g, "");		console.log(normalized);		if (map[normalized]) normalized = map[normalized];		url.searchParams.append("action", "raw");		url.searchParams.append("ctype", "text/javascript");		url.searchParams.set("title", normalized);		url.pathname = "/index.php";		event.respondWith(fetch(new Request(url, { ...request })) .then(response => ([ { ...response }, response.body, ]))			.then(([response, body]) => new Response(body, { ...response }))); 	} });

self.addEventListener('activate', event => {	console.log(event); });

self.addEventListener('install', event => {	console.log(event);	});