Skip to content

Instantly share code, notes, and snippets.

@ebith
Created June 17, 2013 23:39
Show Gist options
  • Save ebith/5801488 to your computer and use it in GitHub Desktop.
Save ebith/5801488 to your computer and use it in GitHub Desktop.
direct_bookmark.jsにツイッター連携付きのはてなブックマークを行うオプションを追加する(要はてブ拡張)
liberator.registerObserver(
'enter',
function () {
commands.get('sbm').options.push([['-t', '-twitter'], liberator.modules.commands.OPTION_NOARG]);
libly.$U.around(
commands.get('sbm'),
'action',
function (next, [args]) {
if (args['-t']) {
if (!window.hBookmark.User.user) {
liberator.echoerr('Hatena Bookmark: failed, need login');
return
}
let postBody = [
['url', buffer.URL],
['comment', args.literalArg],
['post_twitter', args['-t']],
['rks', window.hBookmark.User.user.rks]
].map(function(p) p[0] + '=' + encodeURIComponent(p[1])).join('&');
let req = new libly.Request(
'http://b.hatena.ne.jp/' + window.hBookmark.User.user._name + '/add.edit.json',
{'Content-Type': 'application/x-www-form-urlencoded'},
{'postBody': postBody}
)
req.addEventListener("success", function(res){
liberator.echo('Hatena Bookmark: post completed');
});
req.addEventListener("failure", function(res){
liberator.echoerr('Hatena Bookmark: failed');
});
req.post();
}
else next();
},
true
);
}
);
// vim: ts=2 sw=2 et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment