This commit is contained in:
Omar Najjar 2025-03-17 22:07:41 +11:00
parent fd2411909a
commit 8761f20261
5 changed files with 118 additions and 1 deletions

BIN
fry.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -3,7 +3,9 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Browser Notepad</title> <title>noted.</title>
<link rel="icon" href="https://radical.omar-c29.workers.dev/memes/fry.png" type="image/png">
<link rel="manifest" href="manifest.json">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet">
@ -228,6 +230,19 @@
notepad.addEventListener('click', (e) => { notepad.addEventListener('click', (e) => {
e.stopPropagation(); e.stopPropagation();
}); });
// Register service worker for PWA functionality
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('service-worker.js')
.then(registration => {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
})
.catch(err => {
console.log('ServiceWorker registration failed: ', err);
});
});
}
</script> </script>
</body> </body>
</html> </html>

24
manifest.json Normal file
View file

@ -0,0 +1,24 @@
{
"name": "Browser Notepad",
"short_name": "Notepad",
"description": "A simple browser-based notepad application",
"start_url": "./index.html",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#f1f1f1",
"orientation": "portrait-primary",
"icons": [
{
"src": "https://radical.omar-c29.workers.dev/memes/fry.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "https://radical.omar-c29.workers.dev/memes/fry.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
}
]
}

BIN
noted.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 836 KiB

78
service-worker.js Normal file
View file

@ -0,0 +1,78 @@
const CACHE_NAME = 'browser-notepad-v1';
const urlsToCache = [
'./',
'./index.html',
'./manifest.json',
'https://radical.omar-c29.workers.dev/memes/fry.png',
'https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap',
'https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap',
'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap',
'https://fonts.googleapis.com/css2?family=Courier+Prime&display=swap'
];
// Install event - cache assets
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
});
// Activate event - clean up old caches
self.addEventListener('activate', event => {
const cacheWhitelist = [CACHE_NAME];
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheWhitelist.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
})
);
})
);
});
// Fetch event - serve cached content when offline
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
// Cache hit - return response
if (response) {
return response;
}
// Clone the request
const fetchRequest = event.request.clone();
return fetch(fetchRequest).then(
response => {
// Check if we received a valid response
if(!response || response.status !== 200 || response.type !== 'basic') {
return response;
}
// Clone the response
const responseToCache = response.clone();
caches.open(CACHE_NAME)
.then(cache => {
cache.put(event.request, responseToCache);
});
return response;
}
).catch(() => {
// If fetch fails (offline), try to return the cached HTML
if (event.request.mode === 'navigate') {
return caches.match('./index.html');
}
});
})
);
});