-
Notifications
You must be signed in to change notification settings - Fork 0
/
GitHub expand rich diffs.js
73 lines (63 loc) · 2.03 KB
/
GitHub expand rich diffs.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
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
// ==UserScript==
// @name GitHub expand rich diffs
// @namespace urn://https://www.georgegillams.co.uk/api/greasemonkey/github_expand_rich_diffs
// @include *github.com*
// @include *github.skyscannertools.net*
// @exclude none
// @version 7.0.0
// @description:en Creates a button which can expand all rich diffs in a PR.
// @grant none
// @description Creates a button which can expand all rich diffs in a PR.
// ==/UserScript==
function expandAllRichDiffs() {
const toClick = document.querySelectorAll(
`[aria-label="Display the rich diff"]`,
);
for (let i = toClick.length - 1; i >= 0; i -= 1) {
toClick[i].click();
}
}
function makeGHButton() {
const filesElement = document.getElementsByClassName('repository-content')[0];
if (!filesElement) {
return;
}
const buttonElement = document.createElement('button');
buttonElement.innerText = `Expand all rich diffs`;
buttonElement.style.backgroundColor = '#00A698';
buttonElement.style.border = 'none';
buttonElement.style.fontSize = '1.2rem';
buttonElement.style.fontWeight = 'bold';
buttonElement.style.padding = '0.375rem 1.5rem';
buttonElement.style.borderRadius = '0.5rem';
buttonElement.style.color = 'white';
buttonElement.id = 'expand_all_rich_diffs';
buttonElement.onclick = expandAllRichDiffs;
const newElement = document.createElement('div');
newElement.style.width = '100%';
newElement.style.display = 'flex';
newElement.style.justifyContent = 'center';
newElement.appendChild(buttonElement);
filesElement.appendChild(document.createElement('br'));
filesElement.appendChild(newElement);
}
function makeLinks() {
const docLoc = document.location.href;
if (!docLoc.includes('pull') || !docLoc.includes('files')) {
return;
}
const addedLink = document.getElementById('expand_all_rich_diffs');
if (addedLink) {
return;
}
makeGHButton();
}
function worker() {
try {
makeLinks();
} catch (e) {
// eslint-disable-next-line no-console
console.log(e);
}
}
setInterval(worker, 2000);