/**
* Alt-Text Checker – Bookmarklet
* Prüft Bilder auf einer Webseite auf Barrierefreiheit (Alt-Text, WCAG 2.1).
* Läuft komplett lokal im Browser, keine Datenübertragung.
*
* Sicherheitshinweis: Attributwerte von der besuchten Seite (alt, title, IDs, …)
* gelten als nicht vertrauenswürdig. Sie werden daher ausschließlich über
* textContent / DOM-Knoten eingefügt, niemals über innerHTML mit String-Konkatenation.
*/
(function () {
'use strict';
const NS = 'atc'; // Namespace für CSS-Klassen
const STORAGE_PREFIX = 'alt-text-checker:excluded:';
const COLORS = {
success: { bg: 'lime', outline: '#000', text: '#000' },
error: { bg: '#EB0000', outline: '#fff', text: '#fff' },
warning: { bg: 'orange', outline: '#000', text: '#000' },
excluded:{ bg: '#e0e0e0', outline: '#666', text: '#333' },
info: { bg: 'yellow', outline: '#000', text: '#000' }
};
// Immer sichtbarer Text neben dem Icon – Icons allein sind für Screenreader
// nicht eindeutig (z.B. wird ✔ als "Häkchen" statt "OK" vorgelesen).
const BADGE_TEXT = {
success: 'OK',
error: 'FEHLER',
warning: 'WARNUNG',
excluded: 'AUSGESCHLOSSEN',
info: 'INFO'
};
const BASE_LABEL_STYLE = {
'font-family': 'sans-serif',
'font-size': 'small',
padding: '5px 8px',
outline: '2px dotted #000',
'outline-offset': '-3px',
border: '0',
cursor: 'default',
'z-index': '2147483647'
};
// ---------------------------------------------------------------------
// Speicherung der Ausschlüsse (pro Seiten-URL, dauerhaft im localStorage)
// ---------------------------------------------------------------------
function storageKey() {
return STORAGE_PREFIX + location.href;
}
function loadExclusions() {
try {
const raw = localStorage.getItem(storageKey());
return raw ? JSON.parse(raw) : [];
} catch (e) {
return [];
}
}
function saveExclusions(list) {
try {
localStorage.setItem(storageKey(), JSON.stringify(list));
} catch (e) {
// localStorage evtl. nicht verfügbar (z.B. privater Modus) – ignorieren
}
}
function imageIdentifier(img) {
// src ist die stabilste Kennung eines Bildes über mehrere Seitenaufrufe hinweg
if (img.tagName === 'IMG') return img.currentSrc || img.src || null;
// Nicht-
-Elemente mit role="img" (z.B. Inline-