-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathoverlay.js
More file actions
80 lines (69 loc) · 2.55 KB
/
Copy pathoverlay.js
File metadata and controls
80 lines (69 loc) · 2.55 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
/**
* overlay.js — numbers [data-cf-change] blocks and builds a floating
* "Changes (N)" chip that lets you jump to each edited region.
*
* Usage:
* Drop this script before </body> on any page that uses overlay.css.
* Claude marks an edited region with:
* <span data-cf-change="ch-your-slug">…edited content…</span>
* The slug becomes the jump label in the chip (hyphens → spaces, first
* char uppercased). Keep slugs short and kebab-case:
* ch-section-rewritten, ch-table-clarified
*
* No dependencies. Works alongside make-pages-interactive's own feedback
* styles without touching them.
*
* License: MIT (same as the make-pages-interactive repository).
*/
(function () {
"use strict";
function build() {
var changes = Array.from(document.querySelectorAll("[data-cf-change]"));
if (!changes.length) return;
// Number each block and ensure it has a stable id for deep-linking.
changes.forEach(function (el, i) {
el.setAttribute("data-cf-num", String(i + 1));
if (!el.id) el.id = el.getAttribute("data-cf-change");
});
// Build the floating chip.
var chip = document.createElement("div");
chip.id = "changes-chip";
var hdr = document.createElement("div");
hdr.id = "changes-chip-header";
hdr.textContent = "Changes (" + changes.length + ")";
hdr.addEventListener("click", function () {
chip.classList.toggle("open");
});
var list = document.createElement("div");
list.id = "changes-chip-list";
changes.forEach(function (el, i) {
var slug = el.getAttribute("data-cf-change") || "";
var title = slug.replace(/^ch-/, "").replace(/-/g, " ");
title = title.charAt(0).toUpperCase() + title.slice(1);
var a = document.createElement("a");
a.href = "#" + slug;
a.innerHTML = '<span class="num">' + (i + 1) + "</span>" + title;
a.addEventListener("click", function (e) {
e.preventDefault();
el.scrollIntoView({ behavior: "smooth", block: "center" });
// Brief highlight flash.
var orig = el.style.background;
el.style.transition = "background .2s";
el.style.background = "rgba(255,211,61,.35)";
setTimeout(function () {
el.style.background = orig;
}, 800);
chip.classList.remove("open");
});
list.appendChild(a);
});
chip.appendChild(hdr);
chip.appendChild(list);
document.body.appendChild(chip);
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", build);
} else {
build();
}
}());