broken link fixer

This commit is contained in:
2026-08-16 22:36:36 +02:00
parent d88d5e1377
commit 7322d42d9a
4 changed files with 187 additions and 0 deletions
+59
View File
@@ -227,6 +227,65 @@ a:hover { text-decoration: underline; }
.original-source { color: #999; margin-top: 30px; }
/* ==== Link-Status (broken) ==== */
.post-content a.is-broken {
color: #a06020;
border-bottom: 1px dashed #c9853f;
}
.post-content a.is-broken:hover {
color: var(--accent);
text-decoration: none;
}
/* ==== Broken-Link-Dialog ==== */
.broken-link-dialog {
border: 0;
padding: 0;
border-radius: 8px;
box-shadow: 0 8px 30px rgba(0,0,0,.35);
max-width: 420px;
width: calc(100% - 40px);
color: #333;
}
.broken-link-dialog::backdrop {
background: rgba(0,0,0,.55);
}
.broken-link-dialog-inner {
padding: 24px;
}
.broken-link-title {
margin: 0 0 8px;
font-size: 1.05rem;
font-weight: bold;
}
.broken-link-url {
margin: 0 0 18px;
font-size: .85rem;
color: #777;
word-break: break-all;
}
.broken-link-actions {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
}
.broken-link-actions a {
color: var(--accent);
font-weight: 600;
}
.broken-link-actions a:hover { text-decoration: underline; }
.broken-link-actions button {
border: 1px solid #ccc;
background: #f5f5f5;
color: #333;
border-radius: 4px;
padding: 6px 14px;
cursor: pointer;
font-size: .9rem;
}
.broken-link-actions button:hover { background: #eaeaea; }
/* ==== Kommentare ==== */
.post-content h2:has(+ ol) {
font-size: 1.5em;
+65
View File
@@ -0,0 +1,65 @@
(function () {
var script = document.getElementById("link-status-data");
if (!script) return;
var data;
try { data = JSON.parse(script.textContent); } catch (e) { return; }
var broken = data.broken || {};
var replacement = data.replacement || {};
var dialog = document.getElementById("broken-link-dialog");
var urlEl = dialog ? document.getElementById("broken-link-url") : null;
var archiveEl = dialog ? document.getElementById("broken-link-archive") : null;
var closeBtn = dialog ? dialog.querySelector("[data-dialog-close]") : null;
function variants(href) {
var list = [href];
var www = href.replace(/^https?:\/\/www\./i, "https://");
if (www !== href) list.push(www);
var noScheme = href.replace(/^https?:\/\//i, "");
if (noScheme !== href) list.push(noScheme);
return list;
}
function lookup(href) {
var vs = variants(href);
for (var i = 0; i < vs.length; i++) {
if (Object.prototype.hasOwnProperty.call(broken, vs[i])) return { status: "broken", key: vs[i] };
if (Object.prototype.hasOwnProperty.call(replacement, vs[i])) return { status: "replacement", key: vs[i] };
}
return null;
}
var content = document.querySelector(".post-content");
if (!content) return;
var links = content.querySelectorAll("a[href^='http']");
Array.prototype.forEach.call(links, function (a) {
var href = a.getAttribute("href");
var hit = lookup(href);
if (!hit) return;
if (hit.status === "broken") {
a.classList.add("is-broken");
a.setAttribute("aria-label", (a.textContent || "Link") + " (die URL scheint nicht mehr verfügbar zu sein)");
a.addEventListener("click", function (ev) {
ev.preventDefault();
if (!dialog) return;
var target = a.getAttribute("href");
urlEl.textContent = target;
archiveEl.href = "https://web.archive.org/web/*/" + target;
dialog.showModal();
});
} else if (hit.status === "replacement") {
var rep = replacement[hit.key];
if (rep) a.setAttribute("href", rep);
}
});
if (dialog) {
dialog.addEventListener("click", function (ev) {
if (ev.target === dialog) dialog.close();
});
if (closeBtn) closeBtn.addEventListener("click", function () { dialog.close(); });
}
})();