Created
August 10, 2012 14:07
-
-
Save ebith/3314438 to your computer and use it in GitHub Desktop.
Twitterにポストするかどうか選べるようにするパッチ(はてなブックマーク拡張も必要)
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
diff --git a/direct_bookmark.js b/direct_bookmark.js | |
index 46d5a79..13768c6 100644 | |
--- a/direct_bookmark.js | |
+++ b/direct_bookmark.js | |
@@ -337,26 +337,21 @@ for Migemo search: require XUL/Migemo Extension | |
account:['https://www.hatena.ne.jp', 'https://www.hatena.ne.jp', null], | |
loginPrompt:{ user:'', password:'', description:'Enter username and password.' }, | |
entryPage:'http://b.hatena.ne.jp/entry/%URL::HATENA%', | |
- poster:function(user,password,url,title,comment,tags){ | |
+ poster:function(user,password,url,title,comment,tags,postTwitter){ | |
var tagString = tags.length > 0 ? '[' + tags.join('][') + ']' : ""; | |
- var request = | |
- <entry xmlns="http://purl.org/atom/ns#"> | |
- <title>dummy</title> | |
- <link rel="related" type="text/html" href={url}/> | |
- <summary type="text/plain">{tagString + comment}</summary> | |
- </entry>; | |
- var wsse = new WSSEUtils(user,password); | |
- | |
+ if (!window.hBookmark.User.user) liberator.echo('Hatena Bookmark: failed, need login'); | |
+ var params = [ | |
+ ['url', url], ['comment', tagString + comment], ['post_twitter', postTwitter], ['rks', window.hBookmark.User.user.rks] | |
+ ].map(function(p) p[0] + '=' + encodeURIComponent(p[1])).join('&'); | |
return Deferred.http({ | |
method: "post", | |
- url: "http://b.hatena.ne.jp/atom/post", | |
- data: request.toString(), | |
+ url: "http://b.hatena.ne.jp/" + user + "/add.edit.json", | |
+ data: params, | |
headers: { | |
- "X-WSSE": wsse.getWSSEHeader(), | |
- "Content-Type": "application/atom+xml", | |
+ "Content-Type": "application/x-www-form-urlencoded", | |
}, | |
}).next(function(xhr){ | |
- if(xhr.status != 201) throw "Hatena Bookmark: failed"; | |
+ if(xhr.status != 200) throw "Hatena Bookmark: failed"; | |
}); | |
}, | |
tags:function(user,password){ | |
@@ -712,6 +707,7 @@ for Migemo search: require XUL/Migemo Extension | |
var url = liberator.modules.buffer.URL; | |
if (arg["-s"]) targetServices = arg["-s"]; | |
+ var postTwitter = arg["-t"] ? postTwitter = 1 : postTwitter = 0; | |
if (arg[0] && withUrl) url = arg[0]; | |
var comment = arg.literalArg; | |
@@ -738,7 +734,7 @@ for Migemo search: require XUL/Migemo Extension | |
d = d.next(function() currentService.poster( | |
user,password, | |
isNormalize ? getNormalizedPermalink(url) : url,getTitleByURL(url), | |
- comment,tags | |
+ comment,tags,postTwitter | |
)); | |
if(echoType == "multiline") { | |
d = d.next(function(){ | |
@@ -824,7 +820,7 @@ for Migemo search: require XUL/Migemo Extension | |
}); | |
}; | |
- let options = [ [['-s','-service'], liberator.modules.commands.OPTION_STRING] ]; | |
+ let options = [ [['-s','-service'], liberator.modules.commands.OPTION_STRING], [['-t', '-twitter'], liberator.modules.commands.OPTION_NOARG] ]; | |
let urlCompleter = function(context, args){ | |
if (args.length <= 1) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment