/*
* @title はてブでメタブ表示(レイアウト汚くなる)
* @description my bookmarklet
* @include http://b.hatena.ne.jp/entry/*
* @license MIT License
* @require
*/
(function(){
/*
* CONSTANTS
*/
var DEBUG = true;
var HBBP_URL = "http://b.hatena.ne.jp/js/bookmark_blogparts.js";
//////////////////////////////
var p = function() {
if ( !DEBUG ) return;
console.log.apply(console, arguments);
};
var forEach = function(a,f){
for (var i=0,l=a.length;i<l;i++){
if(f(a[i]) === false) break;
}
};
//////////////////////////////
var targets = {};
var showBookmarkComment = function(uri){
var h = HBBlogParts;
var apiEndPoint = h.API_DOMAIN + '/entry/jsonlite/?';
var request = apiEndPoint + 'url=' + encodeURIComponent(uri) +
'&callback=HBBlogParts.CatchJsonMetab';
var scriptTag = Ten.Element('script',{ src: request, type: 'text/javascript'});
document.body.appendChild(scriptTag);
};
var insert = function(container, url){
var h = HBBlogParts;
forEach(targets[url] || [], function(target){
var parent = target.parentNode;
parent.insertBefore(container, target);
});
};
var catchJsonMetab = function(entry){
var h = HBBlogParts;
if ( !entry ){
p('No Bookmarks');
}else{
var container = new h.BookmarkContainer(entry);
if( h.isPermalinkPage() ) {
container.commentLimit = h.permalinkCommentLimit;
} else {
container.commentLimit = h.listPageCommentLimit;
}
var url = entry.url;
insert(container.toHTML(h.Design),url);
h.setStyles();
h.shownPermalinks[url] = 1;
}
h.catchCount++;
if( h.catchCount >= h.Entries.length ) h.showEmptyEntries();
};
var showBlogPart = function(n){
var h = HBBlogParts;
var elements = [n];
var uri = n.href;
(targets[uri] || (targets[uri] = [])).push(n);
showBookmarkComment(uri);
};
var main = function(){
var h = HBBlogParts;
h.debug = DEBUG;
h.CatchJsonMetab = catchJsonMetab;
var entries = [];
forEach(document.querySelectorAll('a.profile-icon'), showBlogPart);};
/*
* START
*/
if( typeof HBBlogParts == 'undefined' ){
var mainjs = document.createElement('script');
mainjs.src = HBBP_URL;
document.querySelector('head').appendChild(mainjs);}
(function(){
if(typeof HBBlogParts == 'undefined'){
setTimeout(arguments.callee,20);}else{main();}})();
})();