-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathblack_screen.html
More file actions
159 lines (144 loc) · 6.87 KB
/
black_screen.html
File metadata and controls
159 lines (144 loc) · 6.87 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Black Screen • Time & Battery</title>
<style>
:root{
--bg:#000000;
--hud:#2e2e2e; /* dark grey text */
--hud-dim:#555555;
--ring:#1a1a1a; /* subtle borders if needed */
}
html,body{ margin:0; height:100%; background:var(--bg); color:#d0d0d0; font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans"; }
/* BLACKOUT MODE */
body.blackout{ background:#000; cursor:none; }
body.blackout .hud{ display:none; }
/* HUD ELEMENTS */
.hud{ position:fixed; z-index:2; font-size:12px; line-height:1.3; color:var(--hud); user-select:none; }
/* Bottom-right: time & battery */
#status{
right:10px; bottom:10px; text-align:right; opacity:.9;
}
#clock{ font-variant-numeric: tabular-nums; }
#battery{ margin-top:4px; color:var(--hud-dim); }
/* Top-right: controls/help/settings */
#controls{
top:10px; right:10px; text-align:right; max-width:min(42ch, 70vw);
background:transparent; padding:8px 10px; border-radius:8px;
}
#controls .title{ font-weight:700; color:var(--hud); margin-bottom:4px; opacity:.9; }
#controls .row{ color:var(--hud-dim); }
#controls kbd{ padding:2px 6px; border-radius:6px; border:1px solid var(--ring); background:#0d0d0d; color:#8a8a8a; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }
#controls button{ margin-left:8px; padding:2px 6px; border-radius:6px; border:1px solid var(--ring); background:#0f0f0f; color:#8c8c8c; cursor:pointer; }
#controls button:hover{ filter:brightness(1.1); }
#controls .hint{ margin-top:6px; font-size:11px; color:#4b4b4b; }
/* accessibility: allow clicking blank screen to exit */
#exitLayer{ position:fixed; inset:0; display:none; background:transparent; border:none; }
body.blackout #exitLayer{ display:block; }
</style>
</head>
<body>
<!-- TOP-RIGHT: keybinds & help -->
<div id="controls" class="hud" aria-live="polite">
<div class="title">Controls</div>
<div class="row">Enter black mode: <kbd id="enterKeyLabel">Right Arrow</kbd><button id="rebindEnter" title="Click, then press any key">Change</button></div>
<div class="row">Exit black mode: <kbd id="exitKeyLabel">Up Arrow</kbd><button id="rebindExit" title="Click, then press any key">Change</button></div>
<div class="hint">Tip: <kbd>Esc</kbd> or click exits if you get stuck.</div>
</div>
<!-- BOTTOM-RIGHT: clock & battery -->
<div id="status" class="hud">
<div id="clock" aria-label="Current time">--:-- --</div>
<div id="battery" aria-label="Battery status">Battery: --% • --</div>
</div>
<!-- clickable layer to exit blackout (failsafe) -->
<button id="exitLayer" aria-label="Exit black mode"></button>
<script>
(function(){
const pad = n => n.toString().padStart(2,'0');
const clockEl = document.getElementById('clock');
function updateClock(){
const d = new Date();
let h = d.getHours();
const m = d.getMinutes();
const ampm = h >= 12 ? 'pm' : 'am';
h = h % 12; if (h === 0) h = 12;
clockEl.textContent = `${h}:${pad(m)} ${ampm}`;
}
updateClock();
setInterval(updateClock, 1000 * 15);
// Battery API
const batteryEl = document.getElementById('battery');
function fmtBattery(b){
const pct = Math.round(b.level * 100);
const state = b.charging ? 'charging' : 'not charging';
batteryEl.textContent = `Battery: ${pct}% • ${state}`;
}
if ('getBattery' in navigator) {
navigator.getBattery().then(b => {
fmtBattery(b);
b.addEventListener('levelchange', () => fmtBattery(b));
b.addEventListener('chargingchange', () => fmtBattery(b));
}).catch(()=>{ batteryEl.textContent = 'Battery: unavailable'; });
} else {
batteryEl.textContent = 'Battery: unavailable';
}
// Keybinds
const STORAGE_KEY = 'blackscreen_keybinds_v1';
const defaults = { enter:'ArrowRight', exit:'ArrowUp' };
const loadKeys = () => { try { return Object.assign({}, defaults, JSON.parse(localStorage.getItem(STORAGE_KEY)||'{}')); } catch { return {...defaults}; } };
const saveKeys = (k) => { localStorage.setItem(STORAGE_KEY, JSON.stringify(k)); };
let keys = loadKeys();
const enterLbl = document.getElementById('enterKeyLabel');
const exitLbl = document.getElementById('exitKeyLabel');
function refreshLabels(){
enterLbl.textContent = labelFor(keys.enter);
exitLbl.textContent = labelFor(keys.exit);
}
function labelFor(code){
const map = { ArrowRight:'Right Arrow', ArrowUp:'Up Arrow', ArrowLeft:'Left Arrow', ArrowDown:'Down Arrow', Space:'Space', Escape:'Esc'};
return map[code] || code;
}
refreshLabels();
let capture = null; // 'enter' | 'exit' | null
function beginCapture(which){
capture = which;
const btn = which==='enter' ? rebindEnter : rebindExit;
const prev = which==='enter' ? keys.enter : keys.exit;
btn.textContent = 'Press any key…';
btn.disabled = true;
const stop = ()=>{ capture=null; btn.textContent='Change'; btn.disabled=false; };
const ondown = (e)=>{
if(!capture) return;
e.preventDefault();
const code = e.code;
// Disallow modifier-only keys
if (code==='ShiftLeft'||code==='ShiftRight'||code==='ControlLeft'||code==='ControlRight'||code==='AltLeft'||code==='AltRight') return;
if (capture==='enter') keys.enter = code; else keys.exit = code;
saveKeys(keys); refreshLabels(); stop();
window.removeEventListener('keydown', ondown, true);
};
window.addEventListener('keydown', ondown, true);
}
const rebindEnter = document.getElementById('rebindEnter');
const rebindExit = document.getElementById('rebindExit');
rebindEnter.addEventListener('click', ()=> beginCapture('enter'));
rebindExit.addEventListener('click', ()=> beginCapture('exit'));
// Black mode toggling
const exitLayer = document.getElementById('exitLayer');
function enterBlack(){ document.body.classList.add('blackout'); }
function exitBlack(){ document.body.classList.remove('blackout'); }
window.addEventListener('keydown', (e)=>{
if (capture) return; // when rebinding, ignore
if (document.body.classList.contains('blackout')){
if (e.code === keys.exit || e.code === 'Escape') { e.preventDefault(); exitBlack(); }
} else {
if (e.code === keys.enter) { e.preventDefault(); enterBlack(); }
}
}, {passive:false});
exitLayer.addEventListener('click', exitBlack);
})();
</script>
</body>
</html>