Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save noromanba/2795925 to your computer and use it in GitHub Desktop.
Save noromanba/2795925 to your computer and use it in GitHub Desktop.
Expand Hatena Star with visualize avatar, id and quote when quadruple click for UserScript
// ==UserScript==
// @name Fancy Expand Hatena Star
// @namespace https://www.hatena.ne.jp/noromanba/
// @description Expand Hatena::Star with avatar, id and quote when quadruple-click for UserScript
// @include http://*
// @include https://*.hatena.tld/*
// @version 2012.11.20.0
// @homepage https://gist.github.com/2795925
// @downloadURL https://raw.github.com/gist/2795925/fancy-expand-hatena-star.user.js
// @installURL https://raw.github.com/gist/2795925/fancy-expand-hatena-star.user.js
// @license Unknown (as-is)
// @contributor hotchpotch https://gist.github.com/43275
// @author noromanba (https://www.hatena.ne.jp/noromanba/)
// @icon https://upload.wikimedia.org/wikipedia/commons/a/a1/Detective_barnstar.png
// @icon64 https://upload.wikimedia.org/wikipedia/commons/a/a1/Detective_barnstar.png
// ==/UserScript==
// Icon (Public Domain by ChrisO)
// https://commons.wikimedia.org/wiki/File:Detective_barnstar.png
// c.f. http://d.hatena.ne.jp/secondlife/20090105/1231156424
(function () {
var executeBrowserContext = function (funcOrString) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.charset = 'utf-8';
s.appendChild(document.createTextNode('(' + funcOrString.toString() + ')();'));
(document.head || document.body).appendChild(s);
};
var fancyExpand = function () {
if (!window.Hatena || !window.Hatena.Star) return;
var CLICK_THRESHOLD = 4,
CLICK_TIMEOUT = 1000,
ALL_STAR_EXPAND_TIMEOUT = 1000;
var clickCount = 0;
document.body.addEventListener('mousedown', function () {
setTimeout(function () {
clickCount = 0;
}, CLICK_TIMEOUT);
clickCount += 1;
if (clickCount >= CLICK_THRESHOLD)
expandAll();
}, false);
function expandAll() {
// c.f. http://ptech.g.hatena.ne.jp/noromanba/20120423/1335205764
Hatena.Star.EntryLoader.entries.forEach(function (entry) {
var expander = entry.star_container.querySelector('span.hatena-star-inner-count');
if (expander && expander.textContent) {
entry.stars.some(function (star) {
if (star && star.count && star.showInnerStars) {
star.showInnerStars(); // async
return true;
}
});
}
});
// must be live-Node?
var innerStars = Ten.DOM.getElementsByTagAndClassName('span', 'hatena-star-inner-count');
if (innerStars.length) {
setTimeout(expand, ALL_STAR_EXPAND_TIMEOUT);
} else {
expand();
}
}
function expand() {
var currentStar;
var showName = function (name, quote, pos, src) {
var container = new Ten.Element('div', {
style: {
display: 'inline',
fontSize: '90%',
padding: '1px',
margin: '0px 0px 0px 1px',
color: '#000',
backgroundColor: '#FFF'
}
});
container.className = 'fancy-star-container';
container.appendChild(Hatena.Star.User.getProfileIcon(name, src));
var nameplate = document.createElement('span');
nameplate.textContent = name;
container.appendChild(nameplate);
if (quote) {
var speech = document.createElement('blockquote');
Ten.Style.applyStyle(speech, {
display: 'inline',
fontSize: '90%',
padding: '0px',
margin: '0px',
color: '#000',
backgroundColor: '#DDD'
});
speech.textContent = '" ' + quote.replace(/<br\s?\/>/g, '↵') + ' "';
container.appendChild(speech);
}
Ten.DOM.replaceNode(container, currentStar);
Ten.DOM.unshiftChild(container, currentStar);
}; // /showName()
var origShowName = Hatena.Star.NameScreen.prototype.showName;
Hatena.Star.NameScreen.prototype.showName = showName;
// must be live-Node?
var stars = Ten.DOM.getElementsByTagAndClassName('img', 'hatena-star-star');
Array.prototype.forEach.call(stars, function (star) {
if (star.parentNode.className === 'fancy-star-container') return;
currentStar = star;
var mouseoverEvent = document.createEvent('MouseEvents');
mouseoverEvent.initMouseEvent('mouseover',
true, true, window, 1, 1, 1, 1, 1, false, false, false, false, true, star);
star.dispatchEvent(mouseoverEvent);
var mouseoutEvent = document.createEvent('MouseEvents');
mouseoutEvent.initEvent('mouseout', true, true);
star.dispatchEvent(mouseoutEvent);
});
Hatena.Star.NameScreen.prototype.showName = origShowName;
} // /expand()
}; // /fancyExpand()
executeBrowserContext(fancyExpand);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment