-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitlab-history-button.user.js
More file actions
64 lines (60 loc) · 1.83 KB
/
gitlab-history-button.user.js
File metadata and controls
64 lines (60 loc) · 1.83 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
// ==UserScript==
// @name GitLab History Button
// @namespace https://gitlab.com
// @version 0.3
// @description Show history button on project page
// @author CSY54
// @include https://gitlab.*
// @icon https://gitlab.com/assets/favicon-72a2cad5025aa931d6ea56c3201d1f18e68a8cd39788c7c80d5b2b82aa5143ef.png
// @grant none
// @updateURL https://github.com/CSY54/tampermonkey-userscripts/raw/master/gitlab-history-button.user.js
// @downloadURL https://github.com/CSY54/tampermonkey-userscripts/raw/master/gitlab-history-button.user.js
// ==/UserScript==
;(async () => {
const repoName = document.querySelector('.home-panel-title')
if (!repoName) {
return
}
async function until(cb) {
const RETRY_LIMIT = 60
let retryCount = 0
return new Promise((res, rej) => {
const id = setInterval(() => {
if (cb()) {
clearInterval(id)
res()
}
retryCount++
if (retryCount > RETRY_LIMIT) {
clearInterval(id)
rej()
}
}, 1000)
})
}
until(() => {
try {
return (
document.querySelector('.tree-ref-holder button').textContent.trim() !==
''
)
} catch {
return false
}
})
.then(() => {
const path = window.location.pathname
const currentBranch = document
.querySelector('.tree-ref-holder button')
.textContent.trim()
const historyPath = new URL(
`${path}/-/commits/${currentBranch}/`,
window.location.href,
).pathname
const button = `<a href="${historyPath}" class="btn btn-default btn-md gl-button"><span class="gl-button-text">History</span></a>`
document
.querySelector('.tree-controls > div')
.children[1].insertAdjacentHTML('beforebegin', button)
})
.catch(() => {})
})()