-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitbucket-pr-count.js
37 lines (36 loc) · 1.37 KB
/
bitbucket-pr-count.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
// ==UserScript==
// @name Bitbucket PR Count
// @version 1.0
// @description Show number of pull requests for each repository
// @match https://{server}/projects/****
// ==/UserScript==
function addCounts() {
'use strict';
const repos = document.getElementsByClassName('repository-name');
if (!repos.length) {
setTimeout(addCounts, 100);
return;
}
for (let i = 0; i < repos.length; i++) {
const repo = repos[i];
const url = repo.getElementsByTagName('a')[0].href;
fetch(url)
.then((response) => response.text())
.then(responseText => {
const page = document.createElement('div');
page.innerHTML = responseText;
const sidebarContainer = page.getElementsByClassName('aui-sidebar-group')[1];
const prCountContainer = sidebarContainer.querySelectorAll('aui-badge');
if (prCountContainer.length > 0) {
const prCount = prCountContainer[0].innerHTML;
const badge = document.createElement('span');
badge.setAttribute('class', 'aui-badge');
badge.setAttribute('style', 'margin-left: 10px; text-align: text-bottom');
badge.innerHTML = prCount;
repo.appendChild(badge);
}
})
.catch((err) => console.error(err));
}
}
addCounts();