-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.html
More file actions
252 lines (221 loc) · 10.2 KB
/
Copy pathoutput.html
File metadata and controls
252 lines (221 loc) · 10.2 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE html>
<html lang="sr">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; connect-src 'self'">
<title>ProTimer — Ekran</title>
<style>
*{box-sizing:border-box; user-select:none; margin:0;}
html,body{height:100%; overflow:hidden;
font-family:-apple-system, "Helvetica Neue", system-ui, sans-serif;}
body{background:#000; transition:background .15s;}
body.idle{cursor:none;}
body.flash::after{content:''; position:fixed; inset:0; background:var(--flashCol,#ff4540);
z-index:50; animation:zflash .4s steps(2,start) 6; pointer-events:none;}
@keyframes zflash{50%{opacity:0;}}
#stage{position:absolute; inset:0; display:flex; flex-direction:column;
align-items:center; justify-content:center;}
/* gornji tekst (labela / naziv koji korisnik ubaci) */
#text{font-weight:600; line-height:1.1; text-align:center; padding:0 5vw;
white-space:pre-wrap; word-break:break-word; display:none;}
/* glavni tajmer */
#timer{font-family:"SF Mono", ui-monospace, Menlo, monospace; font-weight:700;
font-variant-numeric:tabular-nums; line-height:.95; white-space:nowrap;}
/* donja poruka (alert) */
#msg{position:absolute; bottom:7vh; left:0; right:0; text-align:center;
font-size:6vh; font-weight:700; padding:0 5vw; line-height:1.15;
white-space:pre-wrap; display:none;}
#msg.flash{animation:pulse .8s steps(2,start) infinite;}
#timer.neg{animation:pulse 1s steps(2,start) infinite;}
@keyframes pulse{50%{opacity:.25;}}
/* tanka traka napretka (opciono) */
#prog{position:absolute; bottom:0; left:0; height:1vh; width:100%; display:none;}
/* NOW / NEXT traka */
#nownext{position:absolute; left:0; right:0; bottom:0; display:none; flex-direction:column;
font-family:-apple-system, system-ui, sans-serif;}
#nownext .nn{display:flex; justify-content:space-between; align-items:baseline; gap:3vw;
padding:1.3vh 3.5vw; border-top:1px solid rgba(255,255,255,.13);}
#nownext .nn .ttl{overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:600;}
#nownext .nn .tag{flex:0 0 auto; font-size:1.9vh; letter-spacing:.18em; opacity:.55; font-weight:700;}
#nownext .now .ttl{font-size:4vh;}
#nownext .next{opacity:.62;} #nownext .next .ttl{font-size:3vh;}
#blackout{position:absolute; inset:0; background:#000; z-index:80; display:none;}
/* providni (frameless) prozor — prevlačenje za pomeranje */
body.overlay #stage{ -webkit-app-region: drag; }
</style>
</head>
<body>
<div id="stage">
<div id="text"></div>
<div id="timer">--:--</div>
</div>
<div id="msg"></div>
<div id="nownext"></div>
<div id="prog"></div>
<div id="blackout"></div>
<script>
const IS_ELECTRON = !!window.pt;
const api = window.pt || null;
let S = null, prevRem = null, lastKey = '';
let isFS = false, fitMode = false, lastFitH = 0; // kompaktan prozor (prati tajmer)
if (IS_ELECTRON) api.onWinFs(v => { isFS = !!v; lastKey = ''; lastFitH = 0; });
const $ = id => document.getElementById(id);
function pad(n){ return String(n).padStart(2,'0'); }
function fmtSecs(s, neg){
const h=Math.floor(s/3600), m=Math.floor((s%3600)/60), x=s%60;
return (neg?'−':'') + (h>0 ? `${h}:${pad(m)}:${pad(x)}` : `${m}:${pad(x)}`);
}
function fmtMs(ms){ return ms>=0 ? fmtSecs(Math.ceil(ms/1000),false) : fmtSecs(Math.floor(-ms/1000),true); }
function applyState(s){
if (S && (s.mode!==S.mode || s.durationMs!==S.durationMs)) prevRem = null;
S = s;
}
// --- prijem stanja: Electron (IPC) ili browser/OBS (SSE) ---
if (IS_ELECTRON){
api.onState(applyState);
} else {
const connect = () => {
const es = new EventSource('/events');
es.onmessage = e => { try { applyState(JSON.parse(e.data)); } catch(_){} };
es.onerror = () => { es.close(); setTimeout(connect, 1000); };
};
connect();
}
function render(){
requestAnimationFrame(render);
const now = Date.now();
const d = new Date();
// dok ne stigne stanje — prikaži tačno vreme
if (!S){ paint(`${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`, '#ffffff', '#000000', false, '', '', false, null); return; }
const bg = S.transparent ? 'transparent' : (S.bgColor || '#000000');
document.body.classList.toggle('overlay', !!S.transparent);
let fg = S.fgColor || '#ffffff';
let text, neg = false, prog = null;
if (S.mode === 'clock'){
text = `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
} else if (S.mode === 'countup'){
const el = S.running ? S.elapsedMs + (now - S.startAt) : S.elapsedMs;
text = fmtSecs(Math.floor(el/1000), false);
} else {
let rem = S.running ? S.endAt - now : S.remMs;
if (!S.overtime && rem < 0) rem = 0;
if (S.useWarnColors){
if (rem <= S.redSec*1000) fg = S.warnRed || '#ff4540';
else if (rem <= S.yellowSec*1000) fg = S.warnYellow || '#ffc23a';
}
if (rem < 0){ fg = S.warnRed || '#ff4540'; neg = true; }
prog = S.durationMs > 0 ? Math.max(0, Math.min(1, rem / S.durationMs)) : 0;
text = fmtMs(rem);
if (S.running && S.flashZero && prevRem !== null && prevRem > 0 && rem <= 0) doFlash(fg);
if (S.running) prevRem = rem;
}
// kompaktan prozor: kad NIJE fullscreen i opcija je uključena → tajmer puni širinu, prozor prati visinu
// tajmer UVEK puni prozor; grid se realizuje veličinom/pozicijom samog PROZORA (main proces)
{ const st=$('stage'); if(st.style.left){ st.style.inset='0'; st.style.left=st.style.top=st.style.width=st.style.height=''; } }
// fit (kompaktan prozor) — samo ako NIJE grid i NIJE fullscreen
fitMode = IS_ELECTRON && !!S.fitWindow && !isFS && !S.gridOn;
paint(text, fg, bg, neg, S.text || '', S.message ? S.message.text : '',
S.message && S.message.flash, S.showProgress ? prog : null);
if (fitMode) requestFit();
renderNowNext(fg);
$('blackout').style.display = S.blackout ? 'block' : 'none';
}
// kompaktan prozor: traži od main-a da visina prozora bude tačno koliko i tajmer (+mali rub)
function requestFit(){
const tEl=$('timer'), txtEl=$('text');
if (tEl.style.display==='none') return;
let h = tEl.getBoundingClientRect().height;
if (txtEl.style.display!=='none') h += txtEl.getBoundingClientRect().height + h*0.06;
const want = Math.round(h * 1.34);
if (h > 4 && Math.abs(want - lastFitH) > 4){ lastFitH = want; api.fitWindow(want); }
}
function renderNowNext(fg){
const el = $('nownext');
const cues = S.cues || [];
if (!S.showNowNext || S.currentCue == null || S.currentCue < 0 || !cues.length){
el.style.display = 'none'; $('msg').style.bottom = '';
return;
}
const cur = cues[S.currentCue], nxt = cues[S.currentCue + 1];
const NOW = S.lang === 'en' ? 'NOW' : 'SADA', NEXT = S.lang === 'en' ? 'NEXT' : 'SLEDI';
let html = `<div class="nn now"><span class="ttl"></span><span class="tag">${NOW}</span></div>`;
if (nxt) html += `<div class="nn next"><span class="ttl"></span><span class="tag">${NEXT}</span></div>`;
el.innerHTML = html;
el.querySelector('.now .ttl').textContent = cur ? cur.name : '';
if (nxt) el.querySelector('.next .ttl').textContent = nxt.name;
el.style.color = fg;
el.style.bottom = S.showProgress ? '1vh' : '0';
el.style.display = 'flex';
$('msg').style.bottom = nxt ? '17vh' : '12vh';
}
function paint(timeText, fg, bg, neg, bigText, msgText, msgFlash, prog){
document.body.style.background = bg;
const tEl = $('timer'), txtEl = $('text'), st = $('stage');
// veličina referentne oblasti = #stage (ceo ekran, ili kockica grida)
const sw = st.clientWidth || innerWidth, sh = st.clientHeight || innerHeight;
const textOnly = S && S.textOnly && bigText;
// tekst (labela ili samostalno)
if (bigText){
txtEl.style.display = 'block';
txtEl.textContent = bigText;
txtEl.style.color = fg;
txtEl.style.fontSize = textOnly
? Math.min(sw*0.9/Math.max(6, bigText.length*0.55), sh*0.5) + 'px'
: Math.min(sh*0.12, sw*0.06) + 'px';
txtEl.style.marginBottom = textOnly ? '0' : (sh*0.02)+'px';
} else {
txtEl.style.display = 'none';
}
// tajmer
if (textOnly){
tEl.style.display = 'none';
} else {
tEl.style.display = 'block';
tEl.textContent = timeText;
tEl.style.color = fg;
tEl.className = neg ? 'neg' : '';
if (fitMode){
// puni širinu prozora; rezervisana dužina (stabilna) da se prozor ne trza po cifri
const refLen = Math.max(timeText.length, fmtMs(S.durationMs||0).length, 4);
tEl.style.fontSize = Math.max(14, sw*0.86/(refLen*0.6)) + 'px';
} else {
const key = timeText.length + '|' + Math.round(sw) + 'x' + Math.round(sh) + '|' + (bigText?1:0);
if (key !== lastKey){
lastKey = key;
const avail = bigText ? sh*0.6 : sh*0.7;
tEl.style.fontSize = Math.min(sw*0.92/(timeText.length*0.6), avail) + 'px';
}
}
}
// poruka
const mEl = $('msg');
if (msgText){ mEl.style.display='block'; mEl.textContent=msgText; mEl.style.color=fg; mEl.className = msgFlash?'flash':''; }
else mEl.style.display='none';
// traka napretka
const pEl = $('prog');
if (prog !== null){ pEl.style.display='block'; pEl.style.width=(prog*100)+'%'; pEl.style.background=fg; }
else pEl.style.display='none';
}
function doFlash(col){
document.body.style.setProperty('--flashCol', col);
document.body.classList.remove('flash'); void document.body.offsetWidth;
document.body.classList.add('flash');
}
document.body.addEventListener('animationend', e => {
if (e.target === document.body || e.animationName === 'zflash') document.body.classList.remove('flash');
});
// ---------- Electron-only: čist ekran, BEZ vidljivih kontrola (kontrola je u kontrolnom prozoru) ----------
// zadržano samo: sakrivanje kursora na mirovanje + nevidljive prečice (Esc / dupli klik za pun ekran)
if (IS_ELECTRON){
let idleT=null;
const wake = () => { document.body.classList.remove('idle'); clearTimeout(idleT);
idleT=setTimeout(()=>document.body.classList.add('idle'),2000); };
document.addEventListener('mousemove', wake); wake();
document.addEventListener('keydown', e => { if (e.key==='Escape') api.exitFullscreen(); });
document.addEventListener('dblclick', () => api.toggleFullscreen());
}
window.addEventListener('resize', () => { lastKey=''; });
requestAnimationFrame(render);
</script>
</body>
</html>