-
Notifications
You must be signed in to change notification settings - Fork 5
/
gitlab-scoped-labels.js
143 lines (141 loc) · 8.48 KB
/
gitlab-scoped-labels.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// ==UserScript==
// @name GitLab scoped labels (view only)
// @version 13
// @grant none
// @include https://git.octocat.lab/*
// @license GPL-3.0 License; https://www.gnu.org/licenses/gpl-3.0.txt
// ==/UserScript==
if(window.location.pathname.match(/.*\/boards/)) { // boards
const callback = function(mutations, observer) {
for(const mutation of mutations) {
for(const addedElement of mutation.addedNodes) {
const labels = document.querySelectorAll("span.gl-label");
for(const label of labels) {
if(label.innerText.includes("::")) {
label.classList.add("gl-label-scoped")
label.innerHTML = label.innerText.replace(/([^:]*)::([^:]*)/, "<a href='#' class='gl-link gl-label-link'><span class='gl-label-text'>$1</span> <span class='gl-label-text-scoped'>$2</span></a>");
} else if(label.parentNode.classList.contains("board-title-text")) {
label.classList.add("gl-label-scoped")
}
}
}
}
}
const observer = new MutationObserver(callback)
observer.observe(document, { childList: true, subtree: true })
} else if(window.location.pathname.match(/.*\/issues\/?$/)) { // issues list
const callback = function(mutations, observer) {
for(const mutation of mutations) {
for(const addedElement of mutation.addedNodes) {
if(addedElement.classList.contains("issue")) {
const labels = addedElement.querySelectorAll("span.gl-label");
for(const label of labels) {
if(label.firstChild.firstChild.innerText.includes("::")) {
label.classList.add("gl-label-scoped")
label.setAttribute("style", label.getAttribute("style") + label.firstChild.innerHTML.replace(/<.*style="background-color: (#\w*)">.*/, "--label-background-color: $1; --label-inset-border: inset 0 0 0 1px $1;"))
label.firstChild.innerHTML = label.firstChild.innerHTML.replace(/<(.*)>([^:]*)::([^:]*)<\/span>/, "<$1>$2</span> <span class='gl-label-text-scoped'>$3</span>")
}
}
}
}
}
}
const observer = new MutationObserver(callback)
observer.observe(document, { childList: true, subtree: true })
} else if(window.location.pathname.match(/.*\/issues\/.*/)) { // issue details
const callback = function(mutations, observer) {
for(const mutation of mutations) {
if(mutation.target.classList.contains("issuable-show-labels")) {
for(const label of mutation.addedNodes) {
if(label.innerText.includes("::")) {
label.classList.add("gl-label-scoped")
label.setAttribute("style", label.getAttribute("style") + label.firstChild.innerHTML.replace(/<.*style="background-color: (#\w*)">.*/, "--label-background-color: $1; --label-inset-border: inset 0 0 0 1px $1;"))
label.firstChild.innerHTML = label.firstChild.innerHTML.replace(/(.*)([^:]*)::([^:]*)(.*)/, "$1 $2</span> <span class='gl-label-text-scoped'>$3</span>$4")
}
}
} else if(mutation.target.classList.contains("notes")) {
for(const timeline of mutation.addedNodes) {
const labels = timeline.querySelectorAll("span.gl-label")
for(const label of labels) {
if(label.innerText.includes("::")) {
label.classList.add("gl-label-scoped")
label.firstChild.innerHTML.replace(/<.* style="background-color: (#\w*)".*/, "--label-background-color: $1; --label-inset-border: inset 0 0 0 1px $1;")
label.setAttribute("style", label.getAttribute("style") + label.firstChild.innerHTML.replace(/<.* style="background-color: (#\w*)".*/, "--label-background-color: $1; --label-inset-border: inset 0 0 0 1px $1;"))
label.firstChild.innerHTML = label.firstChild.innerHTML.replace(/<(.*)>([^:]*)::([^:]*)<\/span>/, "<$1>$2</span> <span class='gl-label-text-scoped'>$3</span>")
}
}
}
}
}
}
const observer = new MutationObserver(callback)
observer.observe(document, { childList: true, subtree: true })
} else if(window.location.pathname.match(/.*\/labels/)) { // labels
const labels = document.querySelectorAll("span.gl-label");
for(const label of labels) {
if(label.innerText.includes("::")) {
label.classList.add("gl-label-scoped")
const color = label.innerHTML.replace(/<.*style="background-color: (#\w*)".*/, "$1")
label.setAttribute("style", label.getAttribute("style") + "--label-background-color: " + color + "; --label-inset-border: inset 0 0 0 2px " + color + "; color " + color + ";")
label.innerHTML = label.innerText.replace(/([^:]*)::([^:]*)/, "<span style='background-color: " + color + "' class='gl-label-text gl-label-text-light'>$1</span> <span class='gl-label-text-scoped'>$2</span>");
}
}
} else if(window.location.pathname.match(/.*\/merge_requests$/)) { // merge request list
const labels = document.querySelectorAll("span.gl-label");
for(const label of labels) {
if(label.innerText.includes("::")) {
label.classList.add("gl-label-scoped")
const color = label.innerHTML.replace(/<.*style="background-color: (#\w*)".*/, "$1")
label.setAttribute("style", label.getAttribute("style") + "--label-background-color: " + color + "; --label-inset-border: inset 0 0 0 2px " + color + "; color " + color + ";")
label.innerHTML = label.innerText.replace(/([^:]*)::([^:]*)/, "<span style='background-color: " + color + "' class='gl-label-text gl-label-text-light'>$1</span> <span class='gl-label-text-scoped'>$2</span>");
}
}
} else if(window.location.pathname.match(/.*\/merge_requests\/.*/)) { // merge request
const callback = function(mutations, observer) {
for(const mutation of mutations) {
if(mutation.target.classList.contains("issuable-show-labels")) {
for(const label of mutation.addedNodes) {
if(label.innerText.includes("::")) {
label.classList.add("gl-label-scoped")
label.setAttribute("style", label.getAttribute("style") + label.firstChild.innerHTML.replace(/<.*style="background-color: (#\w*)">.*/, "--label-background-color: $1; --label-inset-border: inset 0 0 0 1px $1;"))
label.firstChild.innerHTML = label.firstChild.innerHTML.replace(/(.*)([^:]*)::([^:]*)(.*)/, "$1 $2</span> <span class='gl-label-text-scoped'>$3</span>$4")
}
}
} else if(mutation.target.classList.contains("notes")) {
for(const timeline of mutation.addedNodes) {
const labels = timeline.querySelectorAll("span.gl-label")
for(const label of labels) {
if(label.innerText.includes("::")) {
label.classList.add("gl-label-scoped")
label.firstChild.innerHTML.replace(/<.* style="background-color: (#\w*)".*/, "--label-background-color: $1; --label-inset-border: inset 0 0 0 1px $1;")
label.setAttribute("style", label.getAttribute("style") + label.firstChild.innerHTML.replace(/<.* style="background-color: (#\w*)".*/, "--label-background-color: $1; --label-inset-border: inset 0 0 0 1px $1;"))
label.firstChild.innerHTML = label.firstChild.innerHTML.replace(/<(.*)>([^:]*)::([^:]*)<\/span>/, "<$1>$2</span> <span class='gl-label-text-scoped'>$3</span>")
}
}
}
}
}
}
const observer = new MutationObserver(callback)
observer.observe(document, { childList: true, subtree: true })
} else if(window.location.pathname.match(/.*\/milestones\/.*/)) { // milestones
const callback = function(mutations, observer) {
for(const mutation of mutations) {
if(mutation.target.classList.contains("tab-pane")) {
for(const addedElement of mutation.addedNodes) {
const labels = addedElement.querySelectorAll("span.gl-label");
for(const label of labels) {
if(label.innerText.includes("::")) {
label.classList.add("gl-label-scoped")
label.firstChild.innerHTML.replace(/<.* style="background-color: (#\w*)".*/, "--label-background-color: $1; --label-inset-border: inset 0 0 0 1px $1;")
label.setAttribute("style", label.getAttribute("style") + label.firstChild.innerHTML.replace(/<.* style="background-color: (#\w*)".*/, "--label-background-color: $1; --label-inset-border: inset 0 0 0 1px $1;"))
label.firstChild.innerHTML = label.firstChild.innerHTML.replace(/<(.*)>([^:]*)::([^:]*)<\/span>/, "<$1>$2</span> <span class='gl-label-text-scoped'>$3</span>")
}
}
}
}
}
}
const observer = new MutationObserver(callback)
observer.observe(document, { childList: true, subtree: true })
}