-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
103 lines (95 loc) · 3.59 KB
/
content.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
window.onload=function(){
// Decide if this is a private repo by looking for a Label with the text "Private"
function isPrivateRepo() {
var outlineLabels = document.querySelectorAll(
"span.Label.Label--outline.v-align-middle"
);
for (const label of outlineLabels) {
if (label.innerText == "Private") {
return true;
}
}
return false;
}
// Copy a formatted link to the GitHub issue
function addCopyButton() {
if (document.getElementById('extensionCopyButton')) return;
var element = document.createElement("input");
element.type = 'button';
element.value = 'Copy Formatted';
element.id = 'extensionCopyButton'
element.style.marginRight="20px";
element.onclick = function() {
var title = document.getElementsByClassName('js-issue-title')[0].innerText;
var href = window.location.href;
var id = href.substr(href.lastIndexOf('/') + 1);
var div = document.createElement('div');
div.appendChild(document.createTextNode(title));
var a = document.createElement('a');
var linkText = document.createTextNode('#' + id);
a.appendChild(linkText);
a.href = href;
div.appendChild(a);
document.body.appendChild(div);
const range = document.createRange();
range.selectNode(div);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
const successful = document.execCommand('copy');
document.body.removeChild(div);
};
document.getElementsByClassName('Header')[0].prepend(element);
}
// Add a button to copy link title and URL in MD format
function addCopyMarkdownButton() {
if (document.getElementById('extensionCopyButtonMarkdown')) return;
var element = document.createElement("input");
element.type = 'button';
element.value = 'Copy Markdown';
element.id = 'extensionCopyButtonMarkdown'
element.style.marginRight="20px";
element.onclick = function() {
var title = document.getElementsByClassName('js-issue-title')[0].innerText;
var href = window.location.href;
var id = href.substr(href.lastIndexOf('/') + 1);
var div = document.createElement('div');
div.appendChild(document.createTextNode(title + ' [#' + id + '](' + href + ')'));
document.body.appendChild(div);
const range = document.createRange();
range.selectNode(div);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
const successful = document.execCommand('copy');
document.body.removeChild(div);
};
document.getElementsByClassName('Header')[0].prepend(element);
}
if (isPrivateRepo()) {
// Set the background color of the header to dark red and a line down the margin
document.querySelectorAll("header")[0].style.backgroundColor = "darkRed";
var div = document.createElement('div');
div.style.width="10px";
div.style.backgroundColor="darkRed";
div.style.position = "fixed";
div.style.top = "0";
div.style.left = "0";
div.style.bottom = "0";
document.body.appendChild(div);
}
else {
// Set the background color of the header to dark blue and a line down the margin
document.querySelectorAll("header")[0].style.backgroundColor = "darkBlue";
var div = document.createElement('div');
div.style.width="10px";
div.style.backgroundColor="darkBlue";
div.style.position = "fixed";
div.style.top = "0";
div.style.left = "0";
div.style.bottom = "0";
document.body.appendChild(div);
}
addCopyButton();
addCopyMarkdownButton();
}