-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
74 lines (58 loc) · 1.99 KB
/
app.js
File metadata and controls
74 lines (58 loc) · 1.99 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
(function(){
function run(ctx) {
ctx = ctx || document;
if ('/issues' !== location.pathname) {
return;
}
if (location.href.indexOf('gitdo%3A') === -1) {
return;
}
const requested = get(location.href.replace('gitdo%3A', 'review-requested%3A')).then(findEntries);
const assignee = get(location.href.replace('gitdo%3A', 'assignee%3A')).then(findEntries);
Promise.all([requested, assignee])
.then(combineEntries)
.then(drawEntries);
}
function drawEntries(entries) {
const ul = drawUl();
const selected = document.querySelector('.states a.selected');
if (selected) {
selected.childNodes[2].data = " " + entries.length + " Open";
}
entries.forEach(entry => ul.appendChild(entry));
}
function combineEntries(sources) {
return sources
.reduce((all, source) => all.concat(source), [])
.reduce((carry, entry) => carry.filter(fltr => fltr.id == entry.id).length ? carry : carry.concat(entry), []);
}
function findEntries(html) {
var div = document.createElement('div');
div.innerHTML = html;
return Array.prototype.slice.call(div.querySelectorAll('.js-issue-row'));
}
function drawUl() {
let blankslate = document.querySelector('.blankslate');
let ul = document.createElement('ul');
ul.className = "border-right border-bottom border-left js-navigation-container js-active-navigation-container";
blankslate.parentNode.insertBefore(ul, blankslate);
blankslate.parentNode.removeChild(blankslate);
return ul;
}
function get(URL) {
return fetch(URL).then(function(response) {
return response.text();
});
};
run();
window.addEventListener('load', function () {
setTimeout(function () {
document.addEventListener("DOMSubtreeModified", function(e){
if (e.target.tagName.toLowerCase() === 'div' && e.target.hasAttribute('data-pjax') === true) {
run(e.target);
return;
}
});
}, 1000);
}, false);
}());