-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcontent.js
More file actions
56 lines (45 loc) · 1.19 KB
/
content.js
File metadata and controls
56 lines (45 loc) · 1.19 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
function replaceBug(element) {
// Prevent recursion
if (element.classList?.contains(".bugzilla")) {
return;
}
for (let child of element.childNodes) {
replaceBug(child);
}
if (element.nodeName != "#text") {
return;
}
let text = element.textContent;
let match = /(.*)?([Bb]ug\s+#?(\d{3,}))(.*)?/s.exec(text);
if (match) {
let span = document.createElement("span");
if (match[1]) {
span.append(match[1])
}
let a = document.createElement("a");
a.href = "https://bugzilla.mozilla.org/show_bug.cgi?id=" + match[3];
a.target = "_blank";
a.classList.add(".bugzilla");
a.textContent = match[2];
// Make link clickable inside another link.
a.addEventListener("click", (event) => {
event.stopPropagation();
});
span.append(a);
if (match[4]) {
span.append(match[4]);
}
element.replaceWith(span);
}
}
{
function update() {
let containers = document.querySelectorAll("[class*='prc-Text-Text-']");
for (let container of containers) {
replaceBug(container);
}
}
let observer = new MutationObserver(update);
observer.observe(document.body, { childList: true, subtree: true });
update();
}