init geek calc
Some checks failed
Deploy to GitHub Pages / build-and-deploy (push) Has been cancelled

This commit is contained in:
2025-10-04 10:53:41 +08:00
commit 54f427ea21
45 changed files with 4878 additions and 0 deletions

57
service-worker.js Normal file
View File

@@ -0,0 +1,57 @@
// Service Worker for Geek Calculator - enables offline functionality
const CACHE_NAME = 'geek-calculator-v1';
const urlsToCache = [
'/',
'/index.html',
'/styles.css',
'/app.js',
'/calculator.js',
'/rpn-calculator.js',
'/ui.js',
'/state.js',
'/utils.js',
'/manifest.webmanifest'
];
// Install event - cache resources
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
});
// Fetch event - serve from cache or network
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
// Return cached version if available, otherwise fetch from network
if (response) {
return response;
}
return fetch(event.request);
}
)
);
});
// Activate event - clean up old caches
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheName !== CACHE_NAME) {
console.log('Deleting old cache:', cacheName);
return caches.delete(cacheName);
}
})
);
})
);
});