Skip to content

Instantly share code, notes, and snippets.

@kurain
Created May 13, 2010 12:33
Show Gist options
  • Save kurain/399777 to your computer and use it in GitHub Desktop.
Save kurain/399777 to your computer and use it in GitHub Desktop.
highlight your Hatena Star
// ==UserScript==
// @name highlightOwnStar
// @namespace kurain.net
// @include http://*
// @include https://*
// ==/UserScript==
(function(){
function main() {
GM_xmlhttpRequest({
method:"GET",
url:"http://b.hatena.ne.jp/my.name",
onload:highlight
});
}
function highlight (json) {
owner_id = eval("(" + json.responseText + ")").name
var randomColor = function() {
return 'rgb(' + (Math.random() > 0.5 ? 255 : 0) + ', ' + (Math.random() > 0.5 ? 255 : 0) + ', ' + (Math.random() > 0.5 ? 255 : 0) + ')';
};
var style = document.createElement('style');
document.body.appendChild(style);
var stars = document.querySelectorAll('span.hatena-star-star-container a');
var classes = [];
for( var i=0; i < stars.length; i++ ) {
if ( stars[i].href.indexOf( owner_id ) > 0 ) {
var ownStarClass = 'ownHatenaStar-' + i;
classes.push(ownStarClass);
stars[i].className = stars[i].className + ' ' + ownStarClass;
}
}
var apply = function() {
style.textContent = classes.map(function(selector) {
if (!selector) return '';
return '.' + selector + ' { background: ' + randomColor() + ' }';
}).join("\n");
};
setInterval(apply, 0);
}
window.addEventListener('load', main , false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment