- Fix manifest.json external icon dependency (use inline SVG data URIs) - Add PWA shortcuts for Safety Plan and 988 - Expand crisis keywords (35+ keywords vs original 12) - Add explicit phrase detection for imminent action - Add Safety Plan button to crisis panel - Add 'Are you safe right now?' to crisis panel text - Support URL param (?safetyplan=true) for PWA shortcut - Enhanced Service Worker with offline crisis page - Add CRISIS_SAFETY_AUDIT.md comprehensive report Addresses gaps identified in post-PR#9 safety audit: - Self-harm keywords (cutting, self-harm, etc.) - Passive suicidal ideation detection - Offline crisis resource page - Crisis panel quick-access improvements
119 lines
3.9 KiB
JavaScript
119 lines
3.9 KiB
JavaScript
const CACHE_NAME = 'the-door-v2';
|
|
const ASSETS = [
|
|
'/',
|
|
'/index.html',
|
|
'/about',
|
|
'/manifest.json'
|
|
];
|
|
|
|
// Crisis resources to show when everything fails
|
|
const CRISIS_OFFLINE_RESPONSE = `<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>You're Not Alone | The Door</title>
|
|
<style>
|
|
body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:#0d1117;color:#e6edf3;max-width:600px;margin:0 auto;padding:20px;line-height:1.6}
|
|
h1{color:#ff6b6b;font-size:1.5rem;margin-bottom:1rem}
|
|
.crisis-box{background:#1c1210;border:2px solid #c9362c;border-radius:12px;padding:20px;margin:20px 0;text-align:center}
|
|
.crisis-box a{display:inline-block;background:#c9362c;color:#fff;text-decoration:none;padding:16px 32px;border-radius:8px;font-weight:700;font-size:1.2rem;margin:10px 0}
|
|
.hope{color:#8b949e;font-style:italic;margin-top:30px;padding-top:20px;border-top:1px solid #30363d}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>You are not alone.</h1>
|
|
<p>Your connection is down, but help is still available.</p>
|
|
<div class="crisis-box">
|
|
<p><strong>Call or text 988</strong><br>Suicide & Crisis Lifeline<br>Free, 24/7, Confidential</p>
|
|
<a href="tel:988">Call 988 Now</a>
|
|
<p style="margin-top:15px"><strong>Or text HOME to 741741</strong><br>Crisis Text Line</p>
|
|
</div>
|
|
<p><strong>When you're ready:</strong></p>
|
|
<ul>
|
|
<li>Take five deep breaths</li>
|
|
<li>Drink some water</li>
|
|
<li>Step outside if you can</li>
|
|
<li>Text or call someone you trust</li>
|
|
</ul>
|
|
<p class="hope">
|
|
"The Lord is close to the brokenhearted and saves those who are crushed in spirit." — Psalm 34:18
|
|
</p>
|
|
<p style="font-size:0.85rem;color:#6e7681;margin-top:30px">
|
|
This page was created by The Door — a crisis intervention project.<br>
|
|
Connection will restore automatically. You don't have to go through this alone.
|
|
</p>
|
|
</body>
|
|
</html>`;
|
|
|
|
// Install event - cache core assets
|
|
self.addEventListener('install', (event) => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME).then((cache) => {
|
|
return cache.addAll(ASSETS);
|
|
})
|
|
);
|
|
self.skipWaiting();
|
|
});
|
|
|
|
// Activate event - cleanup old caches
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((keys) => {
|
|
return Promise.all(
|
|
keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key))
|
|
);
|
|
})
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
// Fetch event - network first, fallback to cache for static,
|
|
// but for the crisis front door, we want to ensure the shell is ALWAYS available.
|
|
self.addEventListener('fetch', (event) => {
|
|
const url = new URL(event.request.url);
|
|
|
|
// Skip API calls - they should always go to network
|
|
if (url.pathname.startsWith('/api/')) {
|
|
return;
|
|
}
|
|
|
|
// Skip non-GET requests
|
|
if (event.request.method !== 'GET') {
|
|
return;
|
|
}
|
|
|
|
event.respondWith(
|
|
fetch(event.request)
|
|
.then((response) => {
|
|
// If we got a valid response, cache it for next time
|
|
if (response.ok && ASSETS.includes(url.pathname)) {
|
|
const copy = response.clone();
|
|
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, copy));
|
|
}
|
|
return response;
|
|
})
|
|
.catch(() => {
|
|
// If network fails, try cache
|
|
return caches.match(event.request).then((cached) => {
|
|
if (cached) return cached;
|
|
|
|
// If it's a navigation request and we're offline, show offline crisis page
|
|
if (event.request.mode === 'navigate') {
|
|
return new Response(CRISIS_OFFLINE_RESPONSE, {
|
|
status: 200,
|
|
headers: new Headers({ 'Content-Type': 'text/html' })
|
|
});
|
|
}
|
|
|
|
// For other requests, return a simple offline message
|
|
return new Response('Offline. Call 988 for immediate help.', {
|
|
status: 503,
|
|
statusText: 'Service Unavailable',
|
|
headers: new Headers({ 'Content-Type': 'text/plain' })
|
|
});
|
|
});
|
|
})
|
|
);
|
|
});
|