Tomblooで自動タグ付加
タグ付けとか面倒なわりにLivedoor Clipではタグからしか検索できないみたいで。他の人が付けたタグを見て自動でタグ付ける。
addAround(LivedoorClip, 'post', function(proceed, args){ var ps = args[0]; var url = "http://api.clip.livedoor.com/json/comments?" + queryString({ link: ps.itemUrl, all : 1 }); return loadJSONDoc(url).addCallback(function(res){ if(!res.isSuccess) return proceed(args); res.Comments.getTags = function(len, threshold){ var tags = { add: function(tag){ if(tag in tags) tags[tag]++; else tags[tag] = 1; }, toArray: function(){ var a = [{ name : x, count : this[x], toString: function(){ return this.count.toString() } } for(x in this) if(typeof this[x] == "number")]; a.sort(); a.reverse(); return a; } }; for each(let x in this) if(x.tags){ for each(let tag in x.tags) tags.add(tag) } var r = tags.toArray(); if(len) r.length = len; if(threshold) r = [tag for each(tag in r) if(tag.count >= threshold)]; return [tag.name for each(tag in r)]; }; ps.tags = res.Comments.getTags(3, 2); return proceed(args); }); });