-
-
Save frohoff/9c3718259e5707610d3a3cfdd57f4afb 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/ | |
// @require http://code.jquery.com/jquery-latest.js | |
// @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