-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentscript.js
28 lines (23 loc) · 952 Bytes
/
contentscript.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
var compareBtn = document.createElement('button');
compareBtn.className = 'btn btn-default';
compareBtn.innerHTML = '<i class="fa fa-stack-overflow with-text"></i> Compare';
compareBtn.onclick = function() {
var container = document.querySelector('#recent-deployments div table tbody tr:first-child td:nth-child(3) div');
if (container) {
var branch = container.innerText.replace(/^.*\((.*)\).*$/, '$1');
var commit = container.querySelector('a');
if (commit) {
var link = commit.href.replace(/commit/,'compare') + '...' + branch;
window.open(link, '_blank');
}
}
};
// check inside interval as vue may not have
// initiated yet at the time the extention content script is run
var intervalID = setInterval(function() {
var deployBtn = document.querySelector('#app > div > .section-header button.btn-primary');
if (deployBtn) {
clearInterval(intervalID);
deployBtn.insertAdjacentElement('beforebegin', compareBtn);
}
},100)