-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.js
More file actions
48 lines (38 loc) · 1.54 KB
/
button.js
File metadata and controls
48 lines (38 loc) · 1.54 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
const BEE_BUTTON_ID = 'flowup-bee-button';
const observer = new MutationObserver(onContainerChange);
observer.observe(document.querySelector('[role="main"]'), {
childList: true,
subtree: true
});
window.addEventListener('load', onContainerChange);
function onContainerChange() {
if (!/^\/[^\/]+\/[^\/]+\/pull\//.test(window.location.pathname) ||
document.querySelector(`#${BEE_BUTTON_ID}`) !== null) {
return;
}
const itemOnSite = document.getElementById("partial-discussion-header").lastElementChild.lastElementChild,
parent = itemOnSite.lastElementChild.parentElement,
next = itemOnSite.lastElementChild.nextSibling,
button = document.createElement("button"),
img = document.createElement('img'),
repository = itemOnSite.lastElementChild.title.match(/([A-Za-z0-9_-]*):/)[1],
branch = itemOnSite.lastElementChild.lastElementChild.innerHTML;
button.className = 'btn btn-sm';
button.style.marginLeft = '10px';
button.style.outline = 'none !important';
button.type = 'button';
button.id = BEE_BUTTON_ID;
button.addEventListener("click", openNewWindow);
img.src = chrome.extension.getURL("/bee.png");
img.style.width = '20px';
img.style.height = '20px';
img.style.verticalAlign = 'sub';
button.appendChild(img);
if (next) parent.insertBefore(button, next);
else parent.appendChild(button);
parent.firstElementChild.style.verticalAlign = 'sub';
function openNewWindow() {
const newWindow = window.open();
newWindow.location.href = 'https://bee.flowdock.eu/' + repository + '/' + branch;
}
}