// ==UserScript== // @name Show Hatena Bookmark Comments // @namespace http://www.ne.jp/asahi/nanto/moon/ // @description Show Hatena Bookmark's comments at the bottom of your browser. // @include http://* // ==/UserScript== /* Original Script: Hatena Bookmark Comments Viewer * * * Original Author: worris */ default xml namespace = "http://www.w3.org/1999/xhtml"; if (document.body && location.href == top.location.href) { GM_xmlhttpRequest({ method: "GET", url: "http://b.hatena.ne.jp/entry/json/" + location.href.replace(/#/g, "%23"), onload: showHBComments }); } function showHBComments(details) { document.getElementsByTagName("head")[0].appendChild(xml2dom(style)); var entry = eval(details.responseText); var container =
?B: { entry ? entry.count : 0 }
; if (!entry) { container.@class = "hb-no-entry"; document.body.appendChild(xml2dom(container)); return; } var comments =
; for each (var bm in entry.bookmarks) { if (!bm.comment) continue; comments.* += <>
{ bm.user }
{ bm.comment }
; } var commentRate = comments.dt.length() / entry.bookmarks.length; var panel =
0.5) ? 1 : 0) + ",1 " + (80 + 70 * Math.cos(2 * Math.PI * (commentRate - 0.25))) + "," + (80 + 70 * Math.sin(2 * Math.PI * (commentRate - 0.25))) + " z" }/> コメント率: { Math.round(100 * commentRate) }%
; if (comments.*.length()) panel.* += comments; container.* += panel; document.body.appendChild(xml2dom(container)); } var style = ; function xml2dom(xml) { if (typeof xml != "xml") return document.createTextNode(xml); var isSingleElement = (xml.length() == 1 && xml.nodeKind() == "element"); if (!isSingleElement) xml = .appendChild(xml); var xmlString = xml.toXMLString(); var doc = new DOMParser().parseFromString(xmlString, "application/xml"); var root = document.importNode(doc.documentElement, true); if (isSingleElement) return root; var range = document.createRange(); range.selectNodeContents(root); return range.cloneContents(); }