Skip to content

Instantly share code, notes, and snippets.

  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nikolat/761858 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name replace star by profile icon
// @namespace http://www.hatena.ne.jp/Nikola/
// @description replace star by profile icon (for Google Chrome8)
// @include http://*.hatena.ne.jp/*
// @version 1.0.0
// ==/UserScript==
(function () {
var executeBrowserContext = function(funcOrString) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.charset = 'utf-8';
var t = document.createTextNode('(' + funcOrString.toString() + ')();');
s.appendChild(t);
document.body.appendChild(s);
};
executeBrowserContext(function() {
var COLOR = true;
if (this.Hatena && this.Hatena.Star){
Array.prototype.slice.call(document.getElementsByClassName('hatena-star-star')).forEach(function(img){
var color;
if (/^[a-zA-Z][-\w]{1,30}[a-zA-Z\d]$/.test(img.alt)) {
if (COLOR && (color = (/star-(\w+)\.gif/.exec(s.src)||[])[1]))
img.style.border = '2px solid ' + color;
img.src = Hatena.User.getProfileIcon(img.alt).src;
}
});
var pushStars = Hatena.Star.Entry.prototype.pushStars;
Hatena.Star.Entry.prototype.pushStars = function(stars, color){
stars = stars.map(function(star) {
var image = Hatena.User.getProfileIcon(star.name);
image.alt = star.name;
if (COLOR && color) image.style.outline = '2px solid ' + color;
star.img = image;
return star;
});
pushStars.call(this, stars, color);
};
var showName = Hatena.Star.Star.prototype.showName;
Hatena.Star.Star.prototype.showName = function(e){
this.screen_name = this.name;
showName.call(this,e);
};
}
});
})();
@nikolat
Copy link
Author

nikolat commented Jan 1, 2011

location.hrefに代入するタイプのスクリプト同士で喧嘩しないように

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment