Skip to content

Commit 675dcf9

Browse files
committed
Initial commit
0 parents  commit 675dcf9

File tree

6 files changed

+67
-0
lines changed

6 files changed

+67
-0
lines changed

images/icon-128.png

5.86 KB
Loading

images/icon-16.png

2.17 KB
Loading

images/icon-32.png

2.77 KB
Loading

images/icon-48.png

3.36 KB
Loading

manifest.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"manifest_version": 3,
3+
"name": "GitDumb",
4+
"version": "1.0",
5+
"description": "Adds a download button to Github repositories.",
6+
7+
"icons": {
8+
"16": "images/icon-16.png",
9+
"32": "images/icon-32.png",
10+
"48": "images/icon-48.png",
11+
"128": "images/icon-128.png"
12+
},
13+
"content_scripts": [
14+
{
15+
"js": ["scripts/content.js"],
16+
"matches": [
17+
"https://github.com/*"
18+
]
19+
}
20+
]
21+
}

scripts/content.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
let url = window.location.href;
2+
if (!url.endsWith('/')) {
3+
url += '/';
4+
}
5+
const urlRoot = url.split('/').slice(0, 5).join('/');
6+
console.log(urlRoot)
7+
8+
if(url === urlRoot || url === urlRoot + '/') {
9+
console.log("Searching for latest release tag")
10+
const latest = document.querySelector('[title="Label: Latest"]');
11+
if(latest) {
12+
const sidebar = document.querySelector('.Layout-sidebar');
13+
const firstChild = sidebar.firstElementChild;
14+
const firstChildFirstChild = firstChild.firstElementChild;
15+
const firstChildFirstChildsFirstChild = firstChildFirstChild.firstElementChild;
16+
const firstChildFirstChildsFirstChildsFirstChild = firstChildFirstChildsFirstChild.firstElementChild;
17+
const button = document.createElement('a');
18+
button.classList.add('gd_downloadbutton');
19+
button.href = urlRoot + '/releases/latest';
20+
button.textContent = 'Download';
21+
firstChildFirstChildsFirstChildsFirstChild.insertAdjacentElement('afterbegin', button)
22+
const style = document.createElement('style');
23+
style.textContent = `
24+
.gd_downloadbutton {
25+
display: inline-block;
26+
background-color: #007bff;
27+
color: white;
28+
padding: 10px 20px;
29+
border-radius: 5px;
30+
text-decoration: none;
31+
font-weight: bold;
32+
width: 100%;
33+
text-align: center;
34+
margin-bottom: 15px;
35+
}
36+
.gd_downloadbutton:hover {
37+
background-color: #0069d9;
38+
cursor: pointer;
39+
color: black;
40+
}
41+
`;
42+
document.head.appendChild(style);
43+
} else {
44+
console.log("No latest release found")
45+
}
46+
}

0 commit comments

Comments
 (0)