Last active
October 13, 2015 22:08
-
-
Save saitamanodoruji/4263416 to your computer and use it in GitHub Desktop.
はてブのコメントを簡単に Quote する Tombloo パッチ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://b.hatena.ne.jp/entry/{url} で動作する. | |
// 範囲選択せずにコメント上でコンテクストメニューを開けば全文 Quote. | |
// 範囲選択するとそこだけ Quote. | |
// 本文の先頭にはてな ID が入り permalink にアンカーされる. | |
// タグ, 日付は省略. | |
Tombloo.Service.extractors.register( | |
{ | |
name: 'Quote - Hatena Bookmark', | |
RE: /^http:\/\/b\.hatena\.ne\.jp\/entry\//, | |
check: function(ctx){ | |
if (!this.RE.test(ctx.href)) | |
return false; | |
if (ctx.selection) { | |
var sel = ctx.window.getSelection().anchorNode; | |
if ($x('./ancestor-or-self::li[starts-with(@id, "bookmark-user-")]', sel)) | |
return true; | |
} | |
var ctx_li = $x('./ancestor-or-self::li[starts-with(@id, "bookmark-user-")]', ctx.target); | |
if (ctx_li) | |
var comment = $x('.//span[contains(concat(" ", @class, " "), " comment ")]', ctx_li); | |
if (comment && comment.textContent) | |
return true; | |
return false; | |
}, | |
extract: function(ctx){ | |
var sel, li, doc, username, comment, permalink; | |
if (ctx.selection) { | |
sel = ctx.window.getSelection().anchorNode; | |
li = $x('./ancestor-or-self::li[starts-with(@id, "bookmark-user-")]', sel); | |
comment = ctx.window.getSelection(); | |
} else { | |
li = $x('./ancestor-or-self::li[starts-with(@id, "bookmark-user-")]', ctx.target); | |
comment = $x('.//span[contains(concat(" ", @class, " "), " comment ")]', li).textContent; | |
} | |
doc = li.ownerDocument; | |
permalink = $x('.//a[contains(concat(" ", @class, " "), " username ")]', li).href; | |
username = li.id.replace(/bookmark-user-([A-Za-z0-9_-]{3,15})/, '$1'); | |
return { | |
type: 'quote', | |
item : doc.title, | |
body: '<a href="' + permalink + '">' + username + '</a> ' + comment, | |
itemUrl: doc.location.href, | |
}; | |
}, | |
}, | |
'Link', | |
false | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment