Created
June 17, 2013 23:39
-
-
Save ebith/5801488 to your computer and use it in GitHub Desktop.
direct_bookmark.jsにツイッター連携付きのはてなブックマークを行うオプションを追加する(要はてブ拡張)
This file contains hidden or 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
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