Expand Hatena::Star
by
noromanba
2014-12-11 [2014/12/11 03:55:50]
expand Hatena::Star handle colored stars
@@ -14,14 +14,32 @@
// TODO doubleness exec
Hatena.Star.EntryLoader.entries.forEach(function (entry) {
console.info('*ei:', ei++);
- entry.stars.some(function (star, idx) {
- console.info('*idx:', idx);
- if (star && star.count && star.showInnerStars) {
- star.showInnerStars();
- console.info('*expand:');
- return true; // rustic
- }
- });
+ var expander = entry.star_container.querySelector('span.hatena-star-inner-count');
+ if (expander && expander.textContent) {
+ entry.stars.some(function (star, idx) {
+ console.info('*idx:', idx);
+ if (star && star.count && star.showInnerStars) {
+ star.showInnerStars();
+ console.info('*expand:');
+ return true; // rustic
+ }
+ });
+ }
});
})(window.Hatena);
-console.timeEnd('*runtime'); //*runtime: 47ms -> *runtime: 57ms on http://d.hatena.ne.jp/amachang/
+console.timeEnd('*runtime');
+/*
+# Performance on http://d.hatena.ne.jp/amachang/
+## nonDOM *runtime: 47ms -> *runtime: 57ms
+## useDOM
+Hatena.Star.EntryLoader.entries[0].star_container.querySelector('SELECTOR')
+### selectors
++ .hatena-star-star-container > .hatena-star-inner-count
+ *runtime: 36ms -> *runtime: 2ms
++ span.hatena-star-star-container > span.hatena-star-inner-count
+ *runtime: 51ms -> *runtime: 3ms
++ span.hatena-star-inner-count
+ *runtime: 42ms -> *runtime: 2ms
++ .hatena-star-inner-count
+ *runtime: 39ms -> *runtime: 3ms
+*/
/*
* @title Expand Hatena::Star
* @description Expand Hateha::Star handle colored stars
* @include http://*
* @license MIT License http://nrm.mit-license.org/2012
* @require
*/
// http://os0x.g.hatena.ne.jp/os0x/20080502/1209724672
console.time('*runtime');
(function(Hatena) {
if (typeof Hatena === 'undefined') return;
var ei = 0;
// TODO doubleness exec
Hatena.Star.EntryLoader.entries.forEach(function (entry) {
console.info('*ei:', ei++);
var expander = entry.star_container.querySelector('span.hatena-star-inner-count');
if (expander && expander.textContent) {
entry.stars.some(function (star, idx) {
console.info('*idx:', idx);
if (star && star.count && star.showInnerStars) {
star.showInnerStars();
console.info('*expand:');
return true; // rustic
}
});
}
});
})(window.Hatena);
console.timeEnd('*runtime');
/*
# Performance on http://d.hatena.ne.jp/amachang/
## nonDOM *runtime: 47ms -> *runtime: 57ms
## useDOM
Hatena.Star.EntryLoader.entries[0].star_container.querySelector('SELECTOR')
### selectors
+ .hatena-star-star-container > .hatena-star-inner-count
*runtime: 36ms -> *runtime: 2ms
+ span.hatena-star-star-container > span.hatena-star-inner-count
*runtime: 51ms -> *runtime: 3ms
+ span.hatena-star-inner-count
*runtime: 42ms -> *runtime: 2ms
+ .hatena-star-inner-count
*runtime: 39ms -> *runtime: 3ms
*/
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。