Skip to content

Instantly share code, notes, and snippets.

@YuJianrong
Created February 17, 2012 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YuJianrong/1852152 to your computer and use it in GitHub Desktop.
Save YuJianrong/1852152 to your computer and use it in GitHub Desktop.
Add watchers count after the link of the git repository (https://github.com/user/repos/). Executed in the console of browser
var linksIterator=document.querySelectorAll("a[href^='http://github.com/'],a[href^='https://github.com']");
var links=[];
var callbackIndex = 0;
for (var i=0;i<linksIterator.length;++i) {
linksIterator[i].addEventListener("mouseover", (function(link) { return function(e) {
if ( link.watched ) return;
link.watched = true;
var url = /.*github\.com\/(.*?)\/(.*?)\/.*/.exec(link.href+"/");
if (url)
{
var name = url[1], repo=url[2];
var funcName = "callback"+callbackIndex;
callbackIndex++;
var theScript=document.createElement("script");
window[funcName]=(function(link, theScript){
return function( jsonObj) {
document.body.removeChild(theScript);
if ( jsonObj.meta.status !== 200 ) {
link.watched = false;
var textNode = document.createTextNode("(error["+jsonObj.meta.status+"]:"+jsonObj.data.message+")");
link.appendChild( textNode);
setTimeout(function(){
link.removeChild( textNode );
},3000);
} else {
link.appendChild(document.createTextNode("(watch:"+jsonObj.data.watchers+", forks:"+ jsonObj.data.forks +")"));
}
// window.xxx=jsonObj;
// console.log("url["+linkObj.href+ "] len:"+jsonObj.data.watchers);
}
} )(link, theScript);
theScript.src="https://api.github.com/repos/"+ name +"/"+repo+"?callback="+funcName;
document.body.appendChild(theScript);
}
};
})(linksIterator[i]), false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment