forked from tedbow/drupal-gitlab-chrome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitlab.js
52 lines (48 loc) · 1.69 KB
/
gitlab.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
(async () => {
let src = chrome.runtime.getURL("common.js");
const { utils } = await import(src);
function waitForElm(selector) {
return new Promise((resolve) => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver((mutations) => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
});
}
waitForElm(".js-discussion-container").then(() => {
const allLinks = document.querySelectorAll(".note-text a");
for (const anchorElement of allLinks) {
const hrefAtt = anchorElement.getAttribute("href");
const anchorText = anchorElement.innerHTML;
const issueId = utils.getIssueIdFromUrl(hrefAtt);
// Replace only if Drupal issue links.
if (
hrefAtt.includes("https://www.drupal.org/project/") &&
!isNaN(issueId) &&
hrefAtt === anchorText
) {
fetch(`https://www.drupal.org/api-d7/node/` + issueId + `.json`)
.then((response) => response.json())
.then((data) => {
if (Object.keys(data).length !== 0) {
const issueStatus = utils.getStatusForId(data.field_issue_status);
anchorElement.text = "#" + issueId + ": " + data.title;
anchorElement.setAttribute("title", "Status: " + issueStatus);
anchorElement.classList.add(
"project-issue-status-" + data.field_issue_status
);
}
});
}
}
});
})();