-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfallback.min.js
More file actions
81 lines (81 loc) · 3.08 KB
/
fallback.min.js
File metadata and controls
81 lines (81 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(()=>{if(window.Fallback)return;let e=document.createElement("style");e.textContent=`
.fb-overlay {
position: fixed;
inset: 0;
background: rgba(0,0,0,.4);
backdrop-filter: blur(6px);
display: flex;
align-items: center;
justify-content: center;
z-index: 999999;
font-family: system-ui,-apple-system,BlinkMacSystemFont;
}
.fb-card {
background: white;
width: 340px;
border-radius: 18px;
padding: 20px;
box-shadow: 0 30px 60px rgba(0,0,0,.25);
}
.fb-title {
font-weight: 600;
font-size: 16px;
margin-bottom: 6px;
}
.fb-text {
font-size: 14px;
color: #555;
line-height: 1.5;
}
.fb-actions {
margin-top: 16px;
display: flex;
justify-content: flex-end;
gap: 12px;
}
.fb-btn {
background: #007aff;
color: white;
border: none;
border-radius: 10px;
padding: 6px 14px;
font-size: 14px;
cursor: pointer;
}
.fb-btn.secondary {
background: transparent;
color: #007aff;
}
.fb-banner {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: rgba(255,255,255,.85);
backdrop-filter: blur(10px);
border-radius: 14px;
padding: 8px 14px;
font-size: 13px;
color: #444;
box-shadow: 0 8px 20px rgba(0,0,0,.12);
z-index: 999999;
}
.fb-img-fallback {
display: flex;
align-items: center;
justify-content: center;
background: #f2f2f2;
color: #777;
font-size: 12px;
border-radius: 12px;
}
`,document.head.appendChild(e);let t=!1,n;function a(e,n){if(t)return;t=!0;let a=document.createElement("div");a.className="fb-overlay",a.innerHTML=`
<div class="fb-card" role="dialog" aria-modal="true">
<div class="fb-title">${e}</div>
<div class="fb-text">${n}</div>
<div class="fb-actions">
<button class="fb-btn secondary">Close</button>
<button class="fb-btn">Reload</button>
</div>
</div>
`;let r=()=>{t=!1,a.remove()};a.querySelector(".secondary").onclick=r,a.querySelector(".fb-btn:not(.secondary)").onclick=()=>location.reload(),a.addEventListener("click",e=>{e.target===a&&r()}),document.addEventListener("keydown",e=>"Escape"===e.key&&r(),{once:!0}),document.body.appendChild(a)}function r(){n||((n=document.createElement("div")).className="fb-banner",n.textContent="Offline mode",document.body.appendChild(n))}function o(){n?.remove(),n=null}window.onerror=()=>a("Unexpected error","This page encountered an error. Reloading may help."),window.addEventListener("unhandledrejection",()=>a("Background error","A background task failed. Reloading may help.")),document.addEventListener("error",e=>{let t=e.target;if("IMG"===t.tagName){let n=document.createElement("div");n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center",n.style.width=(t.width||240)+"px",n.style.height=(t.height||160)+"px",n.className="fb-img-fallback",n.textContent="Image unavailable",t.replaceWith(n)}},!0),window.addEventListener("offline",r),window.addEventListener("online",o),navigator.onLine||r(),window.Fallback={version:"0.2.0"}})();