Created
December 6, 2011 08:22
-
-
Save laiso/1437347 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
### | |
* @title Google 検索の結果にtwitter上で何個言及されているかを表示するブックマークレット | |
* @description http://d.hatena.ne.jp/laiso/20111204/p1 | |
* @include http://*.google.*\/search | |
* @licence MIT | |
* @require jQuery | |
### | |
_STYLE = """ | |
padding: 0 0.5em; | |
margin: 0 0.5em; | |
color: #30566D; | |
text-shadow: 0 1px 0 white; | |
background-color: #C0DEED; | |
font-weight: bold; | |
text-decoration-line: none; | |
""" | |
addCounter = (a) -> | |
jQuery.getJSON 'http://urls.api.twitter.com/1/urls/count.json?url='+encodeURIComponent(a.href)+'&callback=?' | |
,null | |
, (data, textStatus, jqXHR) => | |
counter = document.createElement 'A' | |
counter.setAttribute('style', _STYLE) | |
counter.href = 'https://twitter.com/#!/search/realtime/' + encodeURIComponent a.href | |
counter.innerText = data['count'] | |
point = document.createRange() | |
point.selectNode(a) | |
point.collapse false | |
point.insertNode counter | |
point.detach() | |
links = document.querySelectorAll 'a.l' | |
for all, a of links | |
if typeof a == 'object' | |
addCounter a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment