Created
February 17, 2012 09:32
-
-
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
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
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