PageSourceSearch

https://www.kikyus.net/serviceworker.js

js kikyus.net collected 2026-09-26 00:31:50 UTC 2,965 bytes, 119 lines download raw bytes

1//--------------------------------------------------MODE OFFLINE--------------------------------------------------------
2
3'use strict';
4
5// Our current cache and its contents.
6var CACHE = {
7	version: 'fa_pwa',
8	resources: [
9		'/?utm_source=pwa',
10	]
11};
12
13// Install the service worker, adding all cache entries
14this.addEventListener('install', function (event) {
15	const cssFile = new URL(location).searchParams.get('css');
16	event.waitUntil(
17		caches.open(CACHE.version).then(function (cache) {
18			//CACHE.resources.push('/'+cssFile);
19			return cache.addAll(CACHE.resources);
20		})
21	);
22});
23
24// Handle a fetch request. If not fetched from cache, attempt to add to cache.
25this.addEventListener('fetch', function (event) {
26	if(!event.request.url.indexOf('/ads.txt') > 0 || event.request.url.indexOf('/chatbox/') > 0) {
27		event.respondWith(
28			fetch(event.request).catch(function () {
29				return caches.match(event.request);
30			})
31		);
32	}
33});
34
35// Activate service worker
36this.addEventListener('activate', function (event) {
37	// Remove all caches that aren't whitelisted
38	var cacheWhitelist = [CACHE.version];
39	event.waitUntil(
40		caches.keys().then(function (keyList) {
41			return Promise.all(keyList.map(function (key) {
42				if (cacheWhitelist.indexOf(key) === -1) {
43					return caches.delete(key);
44				}
45			}));
46		})
47	);
48});
49
50//-------------------------------------------------PUSHS NOTIFICATIONS--------------------------------------------------
51this.addEventListener('push', function (event) {
52
53	if (!(this.Notification && this.Notification.permission === 'granted' && event.data)) {
54		return;
55	}
56
57	let data = event.data.json();
58
59	const title = data['title'];
60	const options = {
61		body: data['body'],
62		icon: data['icon'],
63		badge: data['badge'],
64		data: {
65			url: data['link']
66		},
67		renotify: true,
68	};
69
70	if (data['tag'] != undefined && data['tag'] != "") {
71		options.tag = data['tag'];
72	}
73
74	if (data['image'] != undefined && data['image'] != "") {
75		options.image = data['image'];
76	}
77
78	if (data['actions'] != undefined && data['actions'] != "") {
79		options.actions = data['actions'];
80	}
81
82	if (data['unread'] != undefined && data['unread']>0){
83		if (navigator.setAppBadge) {
84			navigator.setAppBadge(data['unread']);
85		}
86	}
87
88	const notificationPromise = this.registration.showNotification(title, options);
89	event.waitUntil(notificationPromise);
90});
91
92this.addEventListener('notificationclick', function (event) {
93
94	event.notification.close();
95
96	if (event.notification.data && event.notification.data.url) {
97
98		var click_url = event.notification.data.url;
99
100		event.waitUntil(clients.matchAll({
101			type: "window"
102		}).then(function (clientList) {
103			for (var i = 0; i < clientList.length; i++) {
104				var client = clientList[i];
105				if (client.url == click_url && 'focus' in client)
106					return client.focus();
107			}
108			if (clients.openWindow) {
109				return clients.openWindow(click_url);
110			}
111
112		}));
113	} else {
114		event.waitUntil(
115			clients.openWindow("/")
116		);
117	}
118});
119//EOF

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.