Analytics: Banner-Skript Review-Fixes (R8/R9, Tab-Widerruf)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5930f052d7
commit
da8bba2a1c
6 files changed
+239
-152
No files matched your search
Vendored
+18
-28
@@ -16,9 +16,12 @@ function vpClass(width) {
|
||||
|
||||
function cleanPath(href) {
|
||||
let p = '/';
|
||||
try {
|
||||
p = new URL(String(href == null ? '' : href), 'http://x.invalid/').pathname || '/';
|
||||
} catch (e) { /* bleibt '/' */ }
|
||||
const h = String(href == null ? '' : href);
|
||||
if (h.charAt(0) === '/') {
|
||||
p = h.replace(/[?#].*$/, '') || '/'; // wie location.pathname, auch '//foo'
|
||||
} else {
|
||||
try { p = new URL(h, 'http://x.invalid/').pathname || '/'; } catch (e) { /* bleibt '/' */ }
|
||||
}
|
||||
try { p = decodeURIComponent(p); } catch (e) { /* kaputtes Encoding: roh lassen */ }
|
||||
if (p.charAt(0) !== '/') p = '/' + p;
|
||||
return p.slice(0, 300);
|
||||
@@ -37,32 +40,19 @@ function refHost(referrer, ownHost) {
|
||||
} catch (e) { return ''; }
|
||||
}
|
||||
|
||||
// Erzeugt wirkende Namen (css-1a2b3c, ember12345, 9f8e7d6c5b4a ...) erkennen.
|
||||
function looksGenerated(s) {
|
||||
if (/\d{4,}/.test(s)) return true;
|
||||
const mixed = (t, min) => t.length >= min && /\d/.test(t) && /[a-z]/i.test(t);
|
||||
if (mixed(s, 10) && !/[-_]/.test(s)) return true;
|
||||
if (/^[a-f0-9]{8,}$/i.test(s) && /\d/.test(s)) return true;
|
||||
return s.split(/[-_]/).some((p) => mixed(p, 6));
|
||||
}
|
||||
|
||||
const safeName = (s) => String(s).replace(/[^\w-]/g, '');
|
||||
|
||||
// Nur Tag-Namen mit :nth-of-type, keine IDs/Klassen (koennten personenbezogene Texte enthalten).
|
||||
function cssPath(el) {
|
||||
const parts = [];
|
||||
let n = el;
|
||||
while (n && n.tagName && parts.length < 5) {
|
||||
const tag = String(n.tagName).toLowerCase();
|
||||
let seg = tag;
|
||||
const id = n.id ? safeName(n.id) : '';
|
||||
if (id && !looksGenerated(id)) {
|
||||
parts.unshift(seg + '#' + id);
|
||||
break;
|
||||
while (n && n.tagName && parts.length < 6) {
|
||||
const tag = String(n.tagName).toLowerCase().replace(/[^a-z0-9-]/g, '');
|
||||
if (!tag) break;
|
||||
let idx = 1;
|
||||
for (let s = n.previousElementSibling; s; s = s.previousElementSibling) {
|
||||
if (String(s.tagName).toLowerCase() === String(n.tagName).toLowerCase()) idx++;
|
||||
}
|
||||
const raw = n.getAttribute ? n.getAttribute('class') : '';
|
||||
const cls = String(raw || '').split(/\s+/).map(safeName).filter((c) => c && !looksGenerated(c)).slice(0, 2);
|
||||
if (cls.length) seg += '.' + cls.join('.');
|
||||
parts.unshift(seg);
|
||||
parts.unshift(tag + ':nth-of-type(' + idx + ')');
|
||||
if (tag === 'body' || tag === 'html') break;
|
||||
n = n.parentNode;
|
||||
}
|
||||
let out = parts.join(' > ');
|
||||
@@ -140,7 +130,7 @@ function main() {
|
||||
const bar = document.createElement('div');
|
||||
bar.className = 'bar';
|
||||
const msg = document.createElement('span');
|
||||
msg.innerHTML = escapeHtml('Heatmap wird geladen ...');
|
||||
msg.textContent = 'Heatmap wird geladen ...';
|
||||
const close = document.createElement('button');
|
||||
close.setAttribute('type', 'button');
|
||||
close.textContent = 'Schließen';
|
||||
@@ -212,11 +202,11 @@ function main() {
|
||||
.then(function (r) { if (!r.ok) throw new Error('heat'); return r.json(); })
|
||||
.then(function (j) {
|
||||
points = (j && Array.isArray(j.points) ? j.points : []).filter(function (p) { return p && p.x >= 0 && p.x <= 1 && p.y >= 0 && p.y <= 1; });
|
||||
msg.innerHTML = escapeHtml('Heatmap – ' + points.length + ' Klicks (letzte 30 Tage)');
|
||||
msg.textContent = 'Heatmap – ' + points.length + ' Klicks (letzte 30 Tage)';
|
||||
draw();
|
||||
timer = setInterval(redrawIfChanged, 1000);
|
||||
})
|
||||
.catch(function () { msg.innerHTML = escapeHtml('Heatmap-Link abgelaufen oder ungültig'); });
|
||||
.catch(function () { msg.textContent = 'Heatmap-Link abgelaufen oder ungültig'; });
|
||||
}
|
||||
|
||||
try { main(); } catch (e) { /* nie die Seite stoeren */ }
|
||||
|
||||
Reference in new issue
Block a user