Last active
March 9, 2020 17:19
-
-
Save ondrajz/46d722403b52a899ed77398688c6b0cb to your computer and use it in GitHub Desktop.
UserScript: Github Links to Star Badges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Github Links to Star Badges | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Adds github stars badges after github links. | |
// @author TrueFurby | |
// @match https://awesome-go.com/ | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var gitLinks = $("a[href*='github.com']"); | |
console.log(gitLinks.length + ' git links'); | |
gitLinks.each(function(){ | |
var a = $(this); | |
var link = a.attr('href'); | |
var re = /github.com\/([^\/]+)\/([^\/]+)\/?/; | |
var matches = link.match(re); | |
if (!matches || matches.length<3) { | |
return; | |
} | |
var user = matches[1]||'stars'; | |
var repo = matches[2]||'badges'; | |
var shield = 'https://img.shields.io/github/stars/'+user+'/'+repo+'.svg'; | |
console.debug("git link:", { | |
'a': a, | |
'link': link, | |
'user': user, | |
'repo': repo, | |
'shield': shield, | |
}); | |
var b = document.createElement('img'); | |
b.style.margin = '0 0 0 5px'; | |
b.style.padding = '0'; | |
b.src = shield; | |
b.height = 20; | |
a.after(b); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment