// ==UserScript== // @name SBM Comments Viewer for chrome // @namespace http://zuzu-service.net/ // @description Show social bookmark's comments at the bottom of chrome. // @version 0.0.1 // @include http://* // @exclude http://reader.livedoor.com/reader/* // @exclude http://www.google.com/search?* // author: zuzu( http://d.hatena.ne.jp/zuzu_sion/ ) // original author: tyoro( http://tyoro.orz.ne.jp/ ) // original script : http://white.s151.xrea.com/wiki/index.php?script/SBMCommentsViewer // by http://white.s151.xrea.com/blog/ // ==/UserScript== /* Last Modified: 2007.11.01 Copyright (C) 2006-2007 shiro Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ var SBMCommentsViewer = function() { var forfilter = function(arr,callback) { var _arr = []; for(var i=0, len = arr.length; i < len; i++) { try { if (callback(arr[i],i)) _arr.push(arr[i]); } catch (e) { throw e; } } return _arr; }; // -------------------------------------------------------------- // Shortcut key // -------------------------------------------------------------- // C -- control // S -- shift // A -- alt var BIND_KEY = 'S-c'; // -------------------------------------------------------------- // max count (each sbm) // -------------------------------------------------------------- var MAX_GET_COUNT = 100; // -------------------------------------------------------------- // ignore user // -------------------------------------------------------------- var ignore_hatena = []; var ignore_delicious = []; var ignore_livedoor = []; var ignore_buzzurl = []; var ignore_pookmark = []; var ignore_ldr = []; // -------------------------------------------------------------- // mouse // -------------------------------------------------------------- // mouseover,click,dblclick etc var mouse_event_show = 'click'; // -------------------------------------------------------------- // CSS // -------------------------------------------------------------- var font_css = "font-size:100%; color:#333333;"; var button_font_css = "font-size:100%; color:#eeeeee;"; var back_css = [ "background-image:none;", "background-color:white; ", "opacity:0.90;" ].join(''); var comment_height = 250; var option_height = 80; // for comment area var comment_area_css = [ "left:20px; ", "right:0px; ", "bottom:0px; ", "text-align:left; ", "position:fixed; ", "z-index:100; ", "height:" + comment_height + "px; ", "margin:0px; ", "padding:0px;", back_css, font_css ].join(''); // for comment var comment_css = [ "position:relative; ", "bottom:0px; ", "border: 1px solid #999999; ", "overflow:auto; ", "margin:0px; ", "height:" + comment_height + "px; ", back_css, font_css ].join(''); // for count var count_css = [ "position:absolute; ", "text-align:right; ", "right:0px; ", "position:absolute; ", "border:1px solid #999999; ", "top:-" + (option_height-2) + "px; ", back_css, font_css, "opacity:0.2; " ].join(''); // for count(number) var number_css = "font-weight:bold;"; // for options var option_css = [ "left:0px; ", "right:0px; ", "position:absolute; ", "border:1px solid #999999; ", "marginargin:0px; ", "border-bottom:0; ", "line-height:110%; ", "height:" + option_height + "px; ", "top:-" + option_height + "px; ", back_css, font_css ].join(''); // for stress text of option var option_text_css = "font-weight:bold; text-decoration:underline;"; // for anchor var anchor_css = [ "font-size:100%;", "color:blue;", "text-decoration:none;", back_css ].join(''); // for mini mode var mini_css = [ "right:0px;", "bottom:0px; ", "text-align:right; ", "position:fixed; ", "overflow:auto; ", "z-index:100; ", back_css, font_css, // "padding-left:10px; ", // "padding-right:10px; ", "border-top: 1px solid #666666; ", "border-left: 1px solid #666666; " ].join(''); // for mini mode list area var mini_lt_css = [ "border-top: 0px; ", "border-left: 0px; ", "padding-left:0px; ", "padding-right:0px; " ].join(''); // for mini mode open area var mini_op_css = [ "background-color:red; ", "opacity:0.90;", button_font_css, "border-top: 1px solid #666666; ", "border-left: 1px solid #666666; " ].join(''); // for mini mode close area var mini_cl_css = [ "background-color:blue; ", "opacity:0.90;", button_font_css, "border-top: 1px solid #666666; ", "border-left: 1px solid #666666; " ].join(''); // for mini mode mini area var mini_mini_css = [ "right:0px;", "bottom:0px; ", "height:15px; ", "width:7px; ", "text-align:right; ", "position:fixed; ", "overflow:auto; ", "z-index:99; ", "background-color:red; ", "opacity:0.90;", button_font_css, "border-top: 1px solid #666666; ", "border-left: 1px solid #666666; " ].join(''); // tag cloud var tag_cloud_min_size = 15; var tag_cloud_max_size = 50; try{ if (self.location.href!=top.location.href || !document.body) return; }catch(e){ return; } var uri = top.location.href.replace(/#/g, '%23'); var w = contentWindow; var option = new Option(); var comment_area = new CommentArea(); var is_load = false; // -------------------------------------------------------------- // Comment Area // -------------------------------------------------------------- function CommentArea (show) { this.comments = []; this.comments_no_dup = false; var counts = []; CommentArea.prototype.setup = function () { if(this.id) return; this.id = 'SBMCommentsViewerArea'; this.div = document.createElement('div'); this.div.setAttribute('id', this.id); this.div.setAttribute('style', comment_area_css + 'display:none;'); this.div.addEventListener("dblclick", function(){comment_area.hide()}, false); document.body.appendChild(this.div); this.id_option = 'SBMoptionsViewerOptionArea'; this.option = document.createElement('div'); this.option.setAttribute('id', this.id_option); this.option.setAttribute('style', option_css); this.div.appendChild(this.option); this.id_panel = 'SBMCommentsViewerCommentArea'; this.comment = document.createElement('ol'); this.panel = document.createElement('div'); this.panel.setAttribute('style', comment_css); this.panel.setAttribute('id', this.id_panel); this.div.appendChild(this.panel); this.id_count = 'SBMCommentsViewerCountArea'; this.count = document.createElement('div'); this.count.setAttribute('id', this.id_count); this.count.setAttribute('style', count_css); this.count_opacity = this.count.style.opacity; this.count.addEventListener("mouseover", function(){ this.style.opacity = '1.0'; }, false); this.count.addEventListener("mouseout", function(){ this.style.opacity = comment_area.count_opacity; }, false); this.div.appendChild(this.count); this.id_mini = 'SBMCommentsViewerMini'; this.mini = document.createElement('div'); this.mini.setAttribute('id', this.id_mini); this.mini.setAttribute('style', mini_css + 'display:none'); document.body.appendChild(this.mini); this.id_miniop = 'SBMCommentsViewerMiniOpen'; this.miniop = document.createElement('span'); this.miniop.setAttribute('id', this.id_miniop); this.miniop.innerHTML = "<"; this.miniop.setAttribute('style', mini_op_css ); this.miniop.addEventListener(mouse_event_show, function(){comment_area.show()}, false); this.mini.appendChild(this.miniop); this.id_miniop = 'SBMCommentsViewerMiniList'; this.minilt = document.createElement('span'); this.minilt.setAttribute('id', this.id_minilt); this.minilt.setAttribute('style', mini_lt_css ); this.mini.appendChild(this.minilt); this.id_minicl = 'SBMCommentsViewerMiniClose'; this.minicl = document.createElement('span'); this.minicl.setAttribute('id', this.id_minicl); this.minicl.innerHTML = ">"; this.minicl.setAttribute('style', mini_cl_css ); this.minicl.addEventListener(mouse_event_show, function(){comment_area.minishow()}, false); this.mini.appendChild(this.minicl); this.id_minimini = 'SBMCommentsViewerMinimini'; this.minimini = document.createElement('div'); this.minimini.setAttribute('id', this.id_minimini); this.minimini.innerHTML = "<"; this.minimini.setAttribute('style', mini_mini_css + 'display:none'); this.minimini.addEventListener(mouse_event_show, function(){comment_area.minihide()}, false); document.body.appendChild(this.minimini); } CommentArea.prototype.show = function (reset) { this.setup(); loadSBM(); this.getOption(); if(reset) this.init(false); if(this.mini.style.display != 'none') this.mini.style.display = 'none'; if(this.div.style.display != 'block') this.div.style.display = 'block'; } CommentArea.prototype.hide = function () { if(this.mini.style.display != 'block') this.mini.style.display = 'block'; if(this.div.style.display != 'none') this.div.style.display = 'none'; } CommentArea.prototype.minishow = function (reset) { if(this.mini.style.display != 'none') this.mini.style.display = 'none'; if(this.minimini.style.display != 'block') this.minimini.style.display = 'block'; } CommentArea.prototype.minihide = function () { if(this.mini.style.display != 'block') this.mini.style.display = 'block'; if(this.minimini.style.display != 'none') this.minimini.style.display = 'none'; } CommentArea.prototype.toggle = function () { if(!this.div || this.div.style.display == 'none'){ this.show(); }else{ this.hide(); } } CommentArea.prototype.init = function (_type) { var types = []; for(var property in this.comments) { types.push(property); } if(option.show_type == "Comment"){ this.initComment(_type, types); }else{ this.initTagCloud(_type, types); } } CommentArea.prototype.initTagCloud = function (_type, types) { var tagcloud; if(!_type && this.tagcloud){ tagcloud = this.tagcloud; }else{ var tags = []; var min; var max; var cmts = this.getUniqueUser(_type, types); for(var i=0; icount){ min = count; } if(count !=0 && max b.href) ? 1 : -1;}); break; case "SBMDesc": cmts.sort(function(a,b){return (a.href > b.href) ? -1 : 1;}); break; case "DateAsc": cmts.sort(function(a,b){return a.date-b.date;}); break; case "DateDesc": cmts.sort(function(a,b){return b.date-a.date;}); break; case "UserAsc": cmts.sort(function(a,b){return (a.user > b.user) ? 1 : -1;}); break; case "UserDesc": cmts.sort(function(a,b){return (a.user > b.user) ? -1 : 1;}); break; } for(var a=0; a 0) { var type = types.shift(); for(var i=0; i1) ? "s" : " "; return '' + this.count + ' user' + s +'
'; } Count.prototype.getMiniHTML = function(){ return ':' + this.count + ' '; } return this; } // -------------------------------------------------------------- // Tag Cloud // -------------------------------------------------------------- function TagCloud(_tags, _min, _max){ this.tags = _tags; this.count_min = _min; this.count_max = _max; this.size_min = tag_cloud_min_size; this.size_max = tag_cloud_max_size; this.keys = []; for(var tag in this.tags){ this.keys.push(tag); } TagCloud.prototype.calc = function(count) { return (this.size_max - this.size_min) * (count - this.count_min) / (this.count_max - this.count_min) + this.size_min; } TagCloud.prototype.getHTML = function(){ var div = document.createElement('div'); var tags = this.tags; switch(option.tag_sort_type) { case "NumberAsc": this.keys.sort(function(a,b){return tags[a]-tags[b]}); break; case "NumberDesc": this.keys.sort(function(a,b){return tags[b]-tags[a]}); break; case "NameAsc": this.keys.sort(function(a,b){return (a > b) ? 1 : -1;}); break; case "NameDesc": this.keys.sort(function(a,b){return (a > b) ? -1 : 1;}); break; } for(var i=0; i * Version: 2.0.0 * LastModified: May 13 2002 * * This program is free software. You can redistribute it and/or modify * it without any warranty. This library calculates the MD5 based on RFC1321. * See RFC1321 for more information and algorism. */ var MD5_T = new Array(0x00000000, 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391); var MD5_round1 = new Array(new Array( 0, 7, 1), new Array( 1,12, 2), new Array( 2,17, 3), new Array( 3,22, 4), new Array( 4, 7, 5), new Array( 5,12, 6), new Array( 6,17, 7), new Array( 7,22, 8), new Array( 8, 7, 9), new Array( 9,12,10), new Array(10,17,11), new Array(11,22,12), new Array(12, 7,13), new Array(13,12,14), new Array(14,17,15), new Array(15,22,16)); var MD5_round2 = new Array(new Array( 1, 5,17), new Array( 6, 9,18), new Array(11,14,19), new Array( 0,20,20), new Array( 5, 5,21), new Array(10, 9,22), new Array(15,14,23), new Array( 4,20,24), new Array( 9, 5,25), new Array(14, 9,26), new Array( 3,14,27), new Array( 8,20,28), new Array(13, 5,29), new Array( 2, 9,30), new Array( 7,14,31), new Array(12,20,32)); var MD5_round3 = new Array(new Array( 5, 4,33), new Array( 8,11,34), new Array(11,16,35), new Array(14,23,36), new Array( 1, 4,37), new Array( 4,11,38), new Array( 7,16,39), new Array(10,23,40), new Array(13, 4,41), new Array( 0,11,42), new Array( 3,16,43), new Array( 6,23,44), new Array( 9, 4,45), new Array(12,11,46), new Array(15,16,47), new Array( 2,23,48)); var MD5_round4 = new Array(new Array( 0, 6,49), new Array( 7,10,50), new Array(14,15,51), new Array( 5,21,52), new Array(12, 6,53), new Array( 3,10,54), new Array(10,15,55), new Array( 1,21,56), new Array( 8, 6,57), new Array(15,10,58), new Array( 6,15,59), new Array(13,21,60), new Array( 4, 6,61), new Array(11,10,62), new Array( 2,15,63), new Array( 9,21,64)); function MD5_F(x,y,z){return (x&y)|(~x&z);} function MD5_G(x,y,z){return (x&z)|(y&~z);} function MD5_H(x,y,z){return x^y^z;} function MD5_I(x,y,z){return y^(x|~z);} var MD5_round=new Array(new Array(MD5_F, MD5_round1), new Array(MD5_G, MD5_round2), new Array(MD5_H, MD5_round3), new Array(MD5_I, MD5_round4)); function MD5_pack(n32){return String.fromCharCode(n32 & 0xff)+String.fromCharCode((n32>>>8)&0xff)+String.fromCharCode((n32>>>16)&0xff)+String.fromCharCode((n32>>>24)&0xff);} function MD5_unpack(s4){return s4.charCodeAt(0)|(s4.charCodeAt(1)<<8)|(s4.charCodeAt(2)<<16)|(s4.charCodeAt(3)<<24);} function MD5_number(n){while(n<0)n+=4294967296;while(n>4294967295)n-=4294967296;return n;} function MD5_apply_round(x,s,f,abcd,r){var a,b,c,d;var kk,ss,ii;var t,u;a=abcd[0];b=abcd[1];c=abcd[2];d=abcd[3];kk=r[0];ss=r[1];ii=r[2];u=f(s[b],s[c],s[d]);t=s[a]+u+x[kk]+MD5_T[ii];t=MD5_number(t);t=((t<>>(32-ss)));t+=s[b];s[a]=MD5_number(t);} function MD5_hash(data){var abcd,x,state,s;var len,index,padLen,f,r;var i,j,k;var tmp;state = new Array(0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476);len=data.length;index=len&0x3f;padLen=(index<56)?(56-index):(120-index);if(padLen>0){data+="\x80";for(i=0;i>4) & 0xf);out+="0123456789abcdef".charAt(c & 0xf);}return out;} // -------------------------------------------------------------- // Comment // // user | string | user name // image | string | url of icon // href | string | url // tags | list | // comment | string | // date | date | // sbm | string | hatena, delicious, livedoor, buzzurl, pookmark, ldr // -------------------------------------------------------------- function Comment (user, image, href, tags, comment, date, tag_base, sbm) { this.user = user; this.image = image; this.href = href; this.tags = tags; this.comment = comment; this.date = date; this.tag_base = tag_base; this.sbm = sbm; this.ignore = []; this.ignore["hatena"] = ignore_hatena; this.ignore["delicious"] = ignore_delicious; this.ignore["livedoor"] = ignore_livedoor; this.ignore["buzzurl"] = ignore_buzzurl; this.ignore["pookmark"] = ignore_pookmark; this.ignore["ldr"] = ignore_ldr; Comment.prototype.isNotIgnore = function(){ var res = true; for(var i=0; i ' + this.user +': '; if(option.show_tag) { for(var i=0; i' + this.tags[i] + ''; if(i+1"; } return this.HTML; } return this; } // -------------------------------------------------------------- // hatena (jsonp) // -------------------------------------------------------------- var hb_jsonp = "http://b.hatena.ne.jp/entry/json/"; var hb_favicon = "http://b.hatena.ne.jp/favicon.ico"; var hb_page = "http://b.hatena.ne.jp/entry/" + uri; var hb_add = "http://b.hatena.ne.jp/add?mode=confirm&url="+uri; function hbLoad() { w.hbCallback = function(json) { var comments = []; if(json){ comment_area.addCount(json.count, hb_favicon, hb_page , hb_add ); var comment = ""; var count = (json.bookmarks.length < MAX_GET_COUNT) ? json.bookmarks.length: MAX_GET_COUNT; for(var i=0; i/g,'>') : ''; comments.push(new Comment(user, image, href, tags, comment, date, tag_base, "livedoor")); } comment_area.addComments('livedoor', comments); comment_area.init('livedoor'); }else{ comment_area.addCount(0, livedoor_favicon, livedoor_page, livedoor_add); } } var json = document.createElement('script'); json.src = livedoor_jsonp + "?link=" + encodeURIComponent(uri.replace(/%23/g, '#')) + "&callback=livedoorCallback&all=1"; json.type = 'text/javascript'; json.charset = 'utf-8'; comment_area.div.appendChild(json); } // -------------------------------------------------------------- // buzzurl (jsonp) // -------------------------------------------------------------- var buzzurl = 'http://buzzurl.jp/user/'; var buzzurl_favicon = "http://labs.ecnavi.jp/buzzurl-help/add_icon_mini_01.gif"; var buzzurl_page = "http://buzzurl.jp/entry/" + uri; var buzzurl_html = 'http://buzzurl.jp/entry/'; var buzzurl_jsonp = "http://api.buzzurl.jp/api/posts/get/v1/json/"; var buzzurl_add = "http://buzzurl.jp/config/add/confirm?url="+uri; function bzLoad() { w.bzCallback = function(json) { var comments = []; if(json && json[0] && json[0].user_num){ comment_area.addCount(json[0].user_num, buzzurl_favicon, buzzurl_page, buzzurl_add); var count = (json[0].posts.length < MAX_GET_COUNT) ? json[0].posts.length : MAX_GET_COUNT; for(var i =0; i