PageSourceSearch

https://0hh.ru/sw2.js

js 0hh.ru collected 2026-10-09 04:34:49 UTC 3,447 bytes, 132 lines download raw bytes

1"use strict";
2
3var VERSION = 'v0.0.22';
4
5self.addEventListener('install', function(event) {
6	self.skipWaiting();
7	event.waitUntil(
8		caches.open(VERSION).then(function(cache) {
9			return cache.addAll([
10				'/manifest.json',
11				'/assets/push.css',
12				// '/assets/push.js'
13			]);
14		})
15	);
16});
17
18self.defaultLink='https://fo.ru';
19
20/*self.addEventListener('fetch', function(event) {
21	var request = event.request;
22
23	if (request.method !== 'GET') return;
24
25	event.respondWith(
26		caches.match(request).then(function(response) {
27			return response || fetch(request);
28		}).catch(function() {
29			return caches.match('/');
30		})
31	);
32});*/
33
34self.addEventListener('activate', function(event) {
35	if (self.clients && clients.claim) {
36		clients.claim();
37	}
38	event.waitUntil(
39		caches
40			.keys()
41			.then(function (keys) {
42				return Promise.all(
43					keys
44						.filter(function (key) {
45							return !key.startsWith(VERSION);
46						})
47						.map(function (key) {
48							return caches.delete(key);
49						})
50				);
51			})
52			.then(function() {
53				console.log('new service worker version registered', VERSION);
54			}).catch(function (error) {
55				console.error('error registering new service worker version', error);
56			})
57	);
58});
59
60self.addEventListener('push', function(event) {
61
62	var notificationData = {};
63
64	try {
65		notificationData = event.data.json();
66		self.defaultLink= notificationData.link;
67	} catch (e) {
68		notificationData = {
69			title: 'Default title',
70			body: 'Default message',
71			icon: '/logo_4u_bigger.png'
72		};
73	}
74
75	event.waitUntil(
76		self.registration.showNotification(notificationData.title, {
77			body: notificationData.body,
78			icon: notificationData.icon
79		})
80
81
82	);
83	//self.defaultLink= notificationData.link;
84});
85
86self.addEventListener('notificationclick', function(event) {
87
88	// close the notification
89	//event.notification.close();
90	self.clients.openWindow(self.defaultLink);
91
92	// see if the current is open and if it is focus it
93	// otherwise open new tab
94  event.waitUntil(
95
96    self.clients.matchAll().then(function(clientList) {
97
98      if (clientList.length > 0) {
99        return clientList[0].focus();
100      }
101
102      return self.clients.openWindow('/');
103    })
104  );
105});
106/* ------------- кеширование ------------------ */
107//importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js');
108importScripts('https://uploads.static.fo.vin/workbox-sw.js');
109
110const CACHE_NAME = 'workbox:cross-origin';
111
112// Cache all
113//const REGEXP_ALL = /.*\.(?:js|css|png|jpg|jpeg|svg|webp|gif|woff2|ttf)/;
114//const REGEXP_ALL = /^\/.*\.(?:js|css|png|jpg|jpeg|svg|webp|gif|woff2|ttf)/;
115//const REGEXP_ALL = /^(\/|https:\/\/fo.ru|http:\/\/localhost|https:\/\/editor.fo.ru).*\.(?:js|css|png|jpg|jpeg|svg|webp|gif|woff2|ttf)/;
116// const REGEXP_ALL = /^(?!https?:\/\/(?:xoney\.com|(?:[^\/]+\.)?staticflickr\.com|(?:[^\/]+\.)?unsplash\.com))(https?:\/\/[^\/]+\/)?.*\.(?:js|css|png|jpg|jpeg|svg|webp|gif|woff2|ttf)$/;
117const REGEXP_ALL = /^(?!https?:\/\/(?:xoney\.com|(?:[^\/]+\.)?yandex\.ru|(?:[^\/]+\.)?staticflickr\.com|(?:[^\/]+\.)?unsplash\.com|(?:[^\/]+\.)?insta\.news))(https?:\/\/[^\/]+\/)?.*\.(?:js|css|png|jpg|jpeg|svg|webp|gif|woff2|ttf)$/;
118
119// [OK] Stale While Revalidate
120workbox.routing.registerRoute(
121  REGEXP_ALL,
122  workbox.strategies.staleWhileRevalidate({
123    cacheName: `${CACHE_NAME}:stale-while-revalidate`,
124  }),
125);
126
127self.addEventListener('install', function() {
128  // For Develop Only
129  self.skipWaiting();
130});
131
132

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.