-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.html
More file actions
580 lines (540 loc) · 24 KB
/
Copy pathconfig.html
File metadata and controls
580 lines (540 loc) · 24 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Heat Cluster Overlay — Konfiguration</title>
<style>
:root {
--bg: #0f1115;
--panel: #181b22;
--panel-2: #1f232c;
--line: #2a2f3a;
--text: #e7eaf0;
--muted: #9aa3b2;
--accent: #ff7a3c;
--accent-2: #ff5a28;
}
* { box-sizing: border-box; }
body {
margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
display: grid; grid-template-columns: 380px 1fr; gap: 0;
}
@media (max-width: 860px) { body { grid-template-columns: 1fr; } }
.panel {
padding: 24px; border-right: 1px solid var(--line);
display: flex; flex-direction: column; gap: 18px;
min-height: 100vh; background: var(--panel);
}
h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
.sub { color: var(--muted); font-size: 12.5px; margin-top: -10px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 14px 14px 4px; margin: 0; }
legend { padding: 0 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }
.field { margin-bottom: 12px; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
input[type="text"], input[type="number"] {
width: 100%; padding: 9px 10px; border-radius: 8px;
border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
font: inherit; outline: none;
}
input:focus { border-color: var(--accent); }
.row { display: flex; gap: 10px; }
.row > .field { flex: 1; }
.check { display: flex; align-items: center; gap: 9px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.check label { margin: 0; color: var(--text); font-size: 13.5px; }
.urlbox {
display: flex; gap: 8px; align-items: stretch;
}
.urlbox input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
button {
border: none; border-radius: 8px; padding: 10px 14px; font: inherit; font-weight: 600;
cursor: pointer; background: linear-gradient(180deg, var(--accent), var(--accent-2));
color: #1a0d06; white-space: nowrap;
}
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); font-weight: 500; }
button:active { transform: translateY(1px); }
.zone-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.zone-row:last-of-type { border-bottom: 0; }
.zone-row .name { flex: 1; font-size: 13px; }
.zone-row .state { font-size: 11.5px; color: var(--muted); }
.zone-row button { padding: 6px 10px; font-size: 12px; }
.zone-row.editing { outline: 1px solid var(--accent); border-radius: 6px; }
/* Aktions-Modus: Zeile wird zur Spalte (Kopf · Action-Name · Schwellen) */
.zone-row.actions { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 0; }
.zone-head { display: flex; align-items: center; gap: 8px; }
.zone-thresholds { display: flex; gap: 8px; }
.zone-thresholds .tcol { flex: 1; }
.zone-thresholds .tcol label { display: block; font-size: 11px; color: var(--muted); margin: 0 0 3px; text-transform: none; letter-spacing: 0; }
#actionsHint { display: none; }
body.actions-mode #actionsHint { display: block; }
/* Vorschau */
.preview { padding: 24px; display: flex; flex-direction: column; gap: 12px; min-height: 100vh; }
.preview-head { display: flex; align-items: center; justify-content: space-between; }
.preview-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.stage {
width: 100%; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; border: 1px solid var(--line);
/* Karo-Muster macht Transparenz sichtbar */
background-color: #20242c;
background-image:
linear-gradient(45deg, #262b34 25%, transparent 25%),
linear-gradient(-45deg, #262b34 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, #262b34 75%),
linear-gradient(-45deg, transparent 75%, #262b34 75%);
background-size: 24px 24px;
background-position: 0 0, 0 12px, 12px -12px, -12px 0;
position: relative;
}
/* Schichten in der Stage (unten → oben): Referenzbild · Vorschau (Kreise) · Zonen-Umrisse */
.stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; z-index: 2; }
.editor-bg, .editor-layer { position: absolute; inset: 0; width: 100%; height: 100%; display: none; }
.editor-bg { object-fit: fill; z-index: 1; } /* Referenzbild: hinter der Vorschau */
.editor-layer { z-index: 3; pointer-events: none; } /* Zonen-Umrisse: über der Vorschau */
body.zones-mode .editor-layer, body.actions-mode .editor-layer { display: block; } /* im Zonen-/Aktions-Modus immer sichtbar */
body.editing .editor-layer { pointer-events: auto; cursor: crosshair; } /* nur beim Editieren klickbar */
.editor-toolbar { display: flex; gap: 8px; align-items: center; }
.editor-toolbar .note { flex: 1; }
.note { color: var(--muted); font-size: 12px; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-size: 12px; }
</style>
</head>
<body>
<form class="panel" id="form">
<div>
<h1>Heat Cluster Overlay</h1>
<div class="sub">Einstellungen → fertige OBS-Browser-Source-URL</div>
</div>
<fieldset>
<legend>Modus</legend>
<div class="field">
<label for="mode">Overlay-Modus</label>
<select id="mode">
<option value="cluster">Cluster (automatische Hotspots)</option>
<option value="zones">Zonen (feste Vierecke)</option>
<option value="actions">Aktions-Zonen (Streamer.Bot)</option>
</select>
<div class="hint">„Zonen" misst Klick-Anteile in selbst platzierten Bereichen.</div>
</div>
</fieldset>
<fieldset>
<legend>Quelle</legend>
<div class="field">
<label for="channel">Twitch-Channel-ID (numerisch)</label>
<input type="text" id="channel" inputmode="numeric" placeholder="z. B. 97032862">
<div class="hint">Leer lassen oder „Sim-Modus" aktivieren, um ohne Stream zu testen.</div>
</div>
<div class="field check">
<input type="checkbox" id="sim">
<label for="sim">Sim-Modus (Testklicks statt Live-Heat)</label>
</div>
<div class="field">
<label for="autoclicks">Auto-Klicks pro Sekunde (nur Sim)</label>
<input type="number" id="autoclicks" min="0" max="200" step="1" value="0">
<div class="hint">0 = nur echte Mausklicks ins Bild. ~30 ergibt eine lebhafte Demo.</div>
</div>
</fieldset>
<fieldset>
<legend>Cluster & Kreise</legend>
<div class="row">
<div class="field">
<label for="window">Zeitfenster (Sek.)</label>
<input type="number" id="window" min="1" max="120" step="1" value="12">
</div>
<div class="field">
<label for="threshold">Threshold (%)</label>
<input type="number" id="threshold" min="0" max="100" step="1" value="10">
</div>
</div>
<div class="row">
<div class="field">
<label for="maxCircles">Max. Kreise</label>
<input type="number" id="maxCircles" min="1" max="10" step="1" value="5">
</div>
<div class="field">
<label for="mergeRadius">Merge-Radius (% Breite)</label>
<input type="number" id="mergeRadius" min="1" max="50" step="1" value="8">
</div>
</div>
<div class="field check">
<input type="checkbox" id="grow" checked>
<label for="grow">Kreise wachsen mit Anteil (sonst feste Größe, nur %)</label>
</div>
</fieldset>
<fieldset id="zonesFs">
<legend>Zonen</legend>
<div class="hint" id="actionsHint" style="margin-bottom:10px">
Pro Zone: <strong>Action-Name</strong> (genau wie in Streamer.Bot) + Schwellen.
„enter" = Klicks im Fenster bis zur Auslösung, „rearm" = darunter wird die Zone
wieder scharf, „cooldown" = Sperrzeit (Sek.) nach dem Feuern.
</div>
<div id="zoneList"></div>
<button type="button" class="secondary" id="addZoneBtn">+ Zone hinzufügen</button>
<div class="hint" style="margin-top:8px">
„Editieren" → 4 Punkte in der Vorschau anklicken. Reihenfolge im Uhrzeigersinn empfohlen.
</div>
</fieldset>
<fieldset id="sbFs">
<legend>Streamer.Bot</legend>
<div class="field">
<label for="sb">WebSocket-URL</label>
<input type="text" id="sb" placeholder="ws://127.0.0.1:8080/">
</div>
<div class="field">
<label for="sbtoken">Auth-Token (optional)</label>
<input type="text" id="sbtoken" placeholder="leer = keine Authentifizierung">
</div>
<div class="hint">Token nur nötig, wenn der Streamer.Bot-WebSocket-Server Authentifizierung verlangt.</div>
</fieldset>
<fieldset>
<legend>OBS-URL</legend>
<div class="field check" style="margin-bottom:12px">
<input type="checkbox" id="status">
<label for="status" id="statusLabel">Status-Badge anzeigen (Verbindung/Modus)</label>
</div>
<div class="urlbox">
<input type="text" id="obsUrl" readonly>
<button type="button" id="copyBtn">Kopieren</button>
</div>
<div class="hint" style="margin-top:10px">
In OBS: <code>+</code> → <em>Browser</em> → diese URL einfügen, Breite/Höhe = Stream-Auflösung
(z. B. 1920×1080), „Hintergrund transparent" lassen.
</div>
<div class="field" style="margin-top:10px">
<button type="button" class="secondary" id="openBtn">Overlay in neuem Tab öffnen</button>
</div>
</fieldset>
</form>
<div class="preview">
<div class="preview-head">
<span class="preview-title">Live-Vorschau</span>
<span class="note">Karo = transparent. Klicke ins Bild, um Testklicks zu setzen.</span>
</div>
<div class="stage">
<iframe id="preview" title="Overlay-Vorschau"></iframe>
<img id="refImage" class="editor-bg" alt="">
<canvas id="editor" class="editor-layer"></canvas>
</div>
<div class="editor-toolbar" id="editorToolbar">
<span class="note" id="editorHint">Im Zonen-Modus „Editieren" wählen, dann 4 Punkte klicken.</span>
<button type="button" class="secondary" id="refBtn">Referenzbild laden</button>
<button type="button" class="secondary" id="refClearBtn" style="display:none">Referenzbild entfernen</button>
<input type="file" id="refInput" accept="image/*" style="display:none">
</div>
</div>
<script>
const STORE_KEY = 'heat-overlay-config';
const fields = ['channel', 'sim', 'autoclicks', 'window', 'threshold', 'maxCircles', 'mergeRadius', 'status', 'mode', 'grow', 'sb', 'sbtoken'];
const round4 = (v) => Math.round(v * 1e4) / 1e4;
let state = { zones: [] }; // zones: [{ points: [{x,y}, ...] }] (0..4 Punkte)
let editingIndex = null; // von Task 6 genutzt
let lastMode = null; // damit applyModeVisibility die Zonenliste nur bei echtem Moduswechsel neu baut
function encodeActions(zones) {
return zones.filter((z) => z.points.length === 4).map((z) =>
[z.enter ?? 20, z.rearm ?? 10, z.cooldown ?? 60, encodeURIComponent(z.action || '')].join('|')
).join(';');
}
function encodeZones(zones) {
return zones
.filter((z) => z.points.length === 4)
.map((z) => z.points.map((p) => round4(p.x) + ',' + round4(p.y)).join(','))
.join(';');
}
const el = (id) => document.getElementById(id);
function renderZoneList() {
const list = el('zoneList');
list.innerHTML = '';
state.zones.forEach((z, i) => {
const row = document.createElement('div');
row.className = 'zone-row' + (editingIndex === i ? ' editing' : '');
const name = document.createElement('span');
name.className = 'name';
name.textContent = 'Zone ' + (i + 1);
const st = document.createElement('span');
st.className = 'state';
st.textContent = z.points.length + '/4';
const edit = document.createElement('button');
edit.type = 'button';
edit.className = 'secondary';
edit.textContent = editingIndex === i ? 'Klicke 4 Punkte …' : 'Editieren';
edit.addEventListener('click', () => startEdit(i));
const del = document.createElement('button');
del.type = 'button';
del.className = 'secondary';
del.textContent = 'Löschen';
del.addEventListener('click', () => {
state.zones.splice(i, 1);
if (editingIndex === i) { editingIndex = null; document.body.classList.remove('editing'); }
else if (editingIndex !== null && i < editingIndex) editingIndex--;
renderZoneList();
update();
});
if (el('mode').value === 'actions') {
const z = state.zones[i];
if (z.action === undefined) { z.action = ''; z.enter = 20; z.rearm = 10; z.cooldown = 60; }
row.classList.add('actions');
const mk = (key) => {
const inp = document.createElement('input');
inp.type = key === 'action' ? 'text' : 'number';
if (key !== 'action') inp.min = '0';
inp.value = z[key];
inp.addEventListener('input', () => {
z[key] = key === 'action' ? inp.value : Number(inp.value);
update();
});
return inp;
};
// Zeile 1: Kopf (Name · Status · Editieren · Löschen)
const head = document.createElement('div');
head.className = 'zone-head';
head.append(name, st, edit, del);
// Zeile 2: Action-Name (volle Breite)
const actionInput = mk('action');
actionInput.placeholder = 'Action-Name (Streamer.Bot)';
// Zeile 3: enter · rearm · cooldown mit eigenen Labels
const thr = document.createElement('div');
thr.className = 'zone-thresholds';
[['enter', 'enter'], ['rearm', 'rearm'], ['cooldown', 'cooldown (s)']].forEach(([key, lbl]) => {
const col = document.createElement('div');
col.className = 'tcol';
const l = document.createElement('label');
l.textContent = lbl;
col.append(l, mk(key));
thr.appendChild(col);
});
row.append(head, actionInput, thr);
} else {
row.append(name, st, edit, del);
}
list.appendChild(row);
});
}
const editor = el('editor');
const ectx = editor.getContext('2d');
function startEdit(i) {
editingIndex = i;
state.zones[i].points = [];
document.body.classList.add('editing');
sizeEditor();
drawEditor();
renderZoneList();
}
function finishEdit() {
editingIndex = null;
document.body.classList.remove('editing');
renderZoneList();
update();
}
function sizeEditor() {
editor.width = editor.clientWidth;
editor.height = editor.clientHeight;
}
// Zeichnet ALLE Zonen-Umrisse: fertige dezent, die gerade editierte hervorgehoben (mit Eckpunkten).
function drawEditor() {
ectx.clearRect(0, 0, editor.width, editor.height);
state.zones.forEach((z, i) => {
const pts = z.points;
if (!pts.length) return;
const active = i === editingIndex;
ectx.lineWidth = active ? 2 : 1.5;
ectx.strokeStyle = active ? 'rgba(255,122,60,0.95)' : 'rgba(255,122,60,0.6)';
ectx.fillStyle = ectx.strokeStyle;
ectx.beginPath();
pts.forEach((p, k) => {
const x = p.x * editor.width, y = p.y * editor.height;
if (k === 0) ectx.moveTo(x, y); else ectx.lineTo(x, y);
});
if (pts.length === 4) ectx.closePath();
ectx.stroke();
if (active) {
for (const p of pts) {
ectx.beginPath();
ectx.arc(p.x * editor.width, p.y * editor.height, 5, 0, Math.PI * 2);
ectx.fill();
}
}
// Zonen-Label am Schwerpunkt (bzw. erstem Punkt), mit dunklem Umriss für Lesbarkeit.
let lx = 0, ly = 0;
for (const p of pts) { lx += p.x; ly += p.y; }
lx = (lx / pts.length) * editor.width;
ly = (ly / pts.length) * editor.height;
const label = 'Zone ' + (i + 1);
ectx.save();
ectx.font = '700 13px system-ui, -apple-system, Segoe UI, sans-serif';
ectx.textAlign = 'center';
ectx.textBaseline = 'middle';
ectx.lineWidth = 3;
ectx.strokeStyle = 'rgba(0,0,0,0.7)';
ectx.fillStyle = '#fff';
ectx.strokeText(label, lx, ly);
ectx.fillText(label, lx, ly);
ectx.restore();
});
}
editor.addEventListener('pointerdown', (e) => {
if (editingIndex === null) return;
const r = editor.getBoundingClientRect();
const x = (e.clientX - r.left) / r.width;
const y = (e.clientY - r.top) / r.height;
const pts = state.zones[editingIndex].points;
pts.push({ x: Math.min(1, Math.max(0, x)), y: Math.min(1, Math.max(0, y)) });
renderZoneList(); // Status n/4 aktualisieren
drawEditor();
if (pts.length === 4) finishEdit();
});
window.addEventListener('resize', () => { if (document.body.classList.contains('zones-mode') || document.body.classList.contains('actions-mode')) { sizeEditor(); drawEditor(); } });
function readForm() {
return {
channel: el('channel').value.trim(),
sim: el('sim').checked,
autoclicks: el('autoclicks').value,
window: el('window').value,
threshold: el('threshold').value,
maxCircles: el('maxCircles').value,
mergeRadius: el('mergeRadius').value,
status: el('status').checked,
mode: el('mode').value,
grow: el('grow').checked,
sb: el('sb').value.trim(),
sbtoken: el('sbtoken').value.trim(),
};
}
function writeForm(v) {
if (!v) return;
el('channel').value = v.channel || '';
el('sim').checked = !!v.sim;
el('autoclicks').value = v.autoclicks ?? 0;
el('window').value = v.window ?? 12;
el('threshold').value = v.threshold ?? 10;
el('maxCircles').value = v.maxCircles ?? 5;
el('mergeRadius').value = v.mergeRadius ?? 8;
el('status').checked = !!v.status;
el('mode').value = v.mode || 'cluster';
el('grow').checked = v.grow !== false; // Default: an
el('sb').value = v.sb || '';
el('sbtoken').value = v.sbtoken || '';
}
// Baut die Query-Parameter; `forStatus` erzwingt das Status-Badge in der Vorschau.
function buildParams(v, forceStatus) {
const p = new URLSearchParams();
if (v.channel) p.set('channel', v.channel);
if (v.sim) p.set('sim', '1');
if (Number(v.autoclicks) > 0) p.set('autoclicks', v.autoclicks);
p.set('window', v.window);
p.set('threshold', v.threshold);
p.set('maxCircles', v.maxCircles);
p.set('mergeRadius', v.mergeRadius);
if (forceStatus || v.status) p.set('status', '1');
if (v.grow === false) p.set('grow', '0');
if (v.mode === 'zones') {
p.set('mode', 'zones');
const z = encodeZones(state.zones);
if (z) p.set('zones', z);
}
if (v.mode === 'actions') {
const z = encodeZones(state.zones);
if (z) p.set('zones', z);
const a = encodeActions(state.zones);
if (a) p.set('actions', a);
if (v.sb) p.set('sb', v.sb);
if (v.sbtoken) p.set('sbtoken', v.sbtoken);
}
return p.toString();
}
function artifactBase(mode) {
return new URL(mode === 'actions' ? 'actions.html' : 'overlay.html', location.href).href;
}
function update() {
const v = readForm();
localStorage.setItem(STORE_KEY, JSON.stringify({ ...v, zones: state.zones }));
applyModeVisibility();
const base = artifactBase(v.mode);
const obsUrl = base + '?' + buildParams(v, false);
el('obsUrl').value = obsUrl;
// Vorschau: Status erzwingen; im Aktions-Modus dry-run, damit nichts gesendet wird.
let previewUrl = base + '?' + buildParams(v, true);
if (v.mode === 'actions') previewUrl += '&dryrun=1';
const iframe = el('preview');
if (iframe.src !== previewUrl) iframe.src = previewUrl;
}
// Events
fields.forEach((id) => {
el(id).addEventListener('input', update);
el(id).addEventListener('change', update);
});
el('addZoneBtn').addEventListener('click', () => {
state.zones.push({ points: [] });
renderZoneList();
update();
});
function applyModeVisibility() {
const mode = el('mode').value;
const zonesLike = mode === 'zones' || mode === 'actions';
el('zonesFs').style.display = zonesLike ? '' : 'none';
el('sbFs').style.display = mode === 'actions' ? '' : 'none';
el('editorToolbar').style.display = zonesLike ? 'flex' : 'none';
// Cluster/Kreis-Felder im Aktions-Modus ausblenden
const clusterFs = el('threshold').closest('fieldset');
clusterFs.style.display = mode === 'actions' ? 'none' : '';
document.body.classList.toggle('zones-mode', mode === 'zones');
document.body.classList.toggle('actions-mode', mode === 'actions');
applyRefVisibility();
// Liste nur bei echtem Moduswechsel neu bauen — sonst verliert ein Zonen-Input
// bei jedem Tastendruck den Fokus (update() läuft pro Eingabe). Strukturelle
// Änderungen (Add/Delete/Edit) rufen renderZoneList() ohnehin selbst auf.
if (mode !== lastMode) { lastMode = mode; renderZoneList(); }
if (zonesLike) { sizeEditor(); drawEditor(); }
}
// Referenzbild ist sichtbar, sobald eines geladen ist UND der Zonen-Modus aktiv ist —
// unabhängig davon, ob gerade editiert wird. Der „Entfernen"-Button erscheint mit ihm.
function applyRefVisibility() {
const img = el('refImage');
const has = !!img.getAttribute('src');
img.style.display = (has && (el('mode').value === 'zones' || el('mode').value === 'actions')) ? 'block' : 'none';
el('refClearBtn').style.display = has ? 'inline-block' : 'none';
}
el('copyBtn').addEventListener('click', async () => {
const url = el('obsUrl').value;
try {
await navigator.clipboard.writeText(url);
el('copyBtn').textContent = 'Kopiert ✓';
} catch (e) {
el('obsUrl').select();
document.execCommand && document.execCommand('copy');
el('copyBtn').textContent = 'Kopiert ✓';
}
setTimeout(() => (el('copyBtn').textContent = 'Kopieren'), 1400);
});
el('openBtn').addEventListener('click', () => window.open(el('obsUrl').value, '_blank'));
el('refBtn').addEventListener('click', () => el('refInput').click());
el('refInput').addEventListener('change', (e) => {
const file = e.target.files && e.target.files[0];
if (!file) return;
const img = el('refImage');
if (img.dataset.objurl) URL.revokeObjectURL(img.dataset.objurl); // altes Bild freigeben
const url = URL.createObjectURL(file);
img.dataset.objurl = url;
img.src = url;
el('refInput').value = ''; // erneutes Laden derselben Datei erlauben
applyRefVisibility();
});
el('refClearBtn').addEventListener('click', () => {
const img = el('refImage');
if (img.dataset.objurl) { URL.revokeObjectURL(img.dataset.objurl); delete img.dataset.objurl; }
img.removeAttribute('src');
applyRefVisibility();
});
// Init: gespeicherte Werte laden, dann Vorschau bauen.
try {
const saved = JSON.parse(localStorage.getItem(STORE_KEY));
if (saved) {
writeForm(saved);
if (Array.isArray(saved.zones)) state.zones = saved.zones;
}
} catch (e) { /* noop */ }
renderZoneList();
update();
</script>
</body>
</html>