-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
37 lines (29 loc) · 1017 Bytes
/
content.js
File metadata and controls
37 lines (29 loc) · 1017 Bytes
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
function isGithubRepo(link){
//Verify it looks like a repo & the link has outerText
const regex = /github\.com\/[^/]*\/[^/]*\/{0,1}$/gm;
return (regex.test(link.href) && link.outerText)
}
function addShield(link){
var url = link.pathname.split('/')
var user = url[1]
var project = url[2]
/* if (!(user && project)){
console.log('href:${} ')
} */
var shield = ` <img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/${user}/${project}?style=flat-square">`
link.insertAdjacentHTML('afterend',shield)
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function getGithubCommits(){
//find hyperlinks to github repos, expecting the format github.com/[user]/[repo]/
links = document.querySelectorAll('a[href^="https://github.com/"]')
for (link of links){
if (isGithubRepo(link)){
addShield(link);
await sleep(300);
}
}
}
getGithubCommits();