-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
content.js
33 lines (26 loc) · 1.41 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
buttonNav = document.getElementsByClassName("Box-sc-g0xbh4-0 bWpuBf");
if (buttonNav[0] != null) {
// Options
chrome.storage.sync.get(["backgroundColor", "textColor", "buttonTitle", "openInNewPage", "adaptToTheme"], function (obj) {
// If obj and obj.x defined => obj.x, else => "xxx"
let backgroundColor = obj && obj.backgroundColor ? obj.backgroundColor : "#fafbfc";
let textColor = obj && obj.textColor ? obj.textColor : "#24292e";
let buttonTitle = obj && obj.buttonTitle ? obj.buttonTitle : "View on Github1s";
let openInNewPage = obj && obj.openInNewPage ? obj.openInNewPage : false;
let adaptToTheme = obj && typeof obj.adaptToTheme === 'boolean' ? obj.adaptToTheme : true;
// Create the Github1s button
var btn = document.createElement("a");
btn.innerHTML = buttonTitle;
btn.classList = "btn ml-1 d-none d-md-block";
btn.href = window.location.href.replace("https://github.com/", "https://github1s.com/");
if (openInNewPage) btn.target = "_blank";
if (!backgroundColor.startsWith("#")) backgroundColor = `#${backgroundColor}`;
if (!textColor.startsWith("#")) textColor = `#${textColor}`;
if(!adaptToTheme) {
btn.style.backgroundColor = backgroundColor;
btn.style.color = textColor;
}
// Add the button
buttonNav[0].appendChild(btn);
});
}