diff options
author | anekos | 2012-07-02 13:11:36 +0900 |
---|---|---|
committer | anekos | 2012-07-02 13:11:36 +0900 |
commit | e55a10145b1cff318f7fd7b84567e62c905d9e9d (patch) | |
tree | 23ab3c93d62bad2b07038dde30e5b5219f8c5d2a | |
parent | b54e38d5d0802545aa346f14da9a8885eed85288 (diff) | |
download | vimperator-plugins-e55a10145b1cff318f7fd7b84567e62c905d9e9d.tar.bz2 |
arg[0] is not empty...
-rw-r--r-- | direct_bookmark.js | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/direct_bookmark.js b/direct_bookmark.js index fe14501..c3a3d27 100644 --- a/direct_bookmark.js +++ b/direct_bookmark.js @@ -720,55 +720,57 @@ for Migemo search: require XUL/Migemo Extension }, {}, true);
// Add :sbm, :sbmo {{{
{
- let action = function(arg){
- var targetServices = useServicesByPost;
- var url = liberator.modules.buffer.URL;
+ let makeAction = function(withUrl) {
+ return function(arg){
+ var targetServices = useServicesByPost;
+ var url = liberator.modules.buffer.URL;
- if (arg["-s"]) targetServices = arg["-s"];
- if (arg[0]) url = arg[0];
- comment = arg.literalArg;
+ if (arg["-s"]) targetServices = arg["-s"];
+ if (arg[0] && withUrl) url = arg[0];
+ comment = arg.literalArg;
- var tags = [];
- var re = /\[([^\]]+)\]([^\[].*)?/g;
+ var tags = [];
+ var re = /\[([^\]]+)\]([^\[].*)?/g;
- var d = new Deferred();
- var first = d;
+ var d = new Deferred();
+ var first = d;
- if(/^\[[^\]]+\]/.test(comment)){
- var tag, text;
- while((tag = re.exec(comment))){
- [, tag, text] = tag;
- tags.push(tag);
+ if(/^\[[^\]]+\]/.test(comment)){
+ var tag, text;
+ while((tag = re.exec(comment))){
+ [, tag, text] = tag;
+ tags.push(tag);
+ }
+ comment = text || '';
}
- comment = text || '';
- }
- tags.forEach(function (t) __context__.tags.add(t));
-
- targetServices.split(/\s*/).forEach(function(service){
- var user, password, currentService = services[service] || null;
- [user,password] = currentService.account ? getUserAccount.apply(currentService,currentService.account) : ["", ""];
- d = d.next(function() currentService.poster(
- user,password,
- isNormalize ? getNormalizedPermalink(url) : url,getTitleByURL(url),
- comment,tags
- ));
- if(echoType == "multiline") {
+ tags.forEach(function (t) __context__.tags.add(t));
+
+ targetServices.split(/\s*/).forEach(function(service){
+ var user, password, currentService = services[service] || null;
+ [user,password] = currentService.account ? getUserAccount.apply(currentService,currentService.account) : ["", ""];
+ d = d.next(function() currentService.poster(
+ user,password,
+ isNormalize ? getNormalizedPermalink(url) : url,getTitleByURL(url),
+ comment,tags
+ ));
+ if(echoType == "multiline") {
+ d = d.next(function(){
+ liberator.echo("[" + services[service].description + "] post completed.");
+ });
+ }
+ d = d.error(function() {
+ liberator.echoerr(services[service].description + ": failed");
+ });
+ });
+ if(echoType == "simple") {
d = d.next(function(){
- liberator.echo("[" + services[service].description + "] post completed.");
+ liberator.echo("post completed.");
});
}
- d = d.error(function() {
- liberator.echoerr(services[service].description + ": failed");
- });
- });
- if(echoType == "simple") {
- d = d.next(function(){
- liberator.echo("post completed.");
- });
- }
- d.error(function(e){liberator.echoerr("direct_bookmark.js: Exception throwed! " + e);liberator.log(e);});
- setTimeout(function(){first.call();},0);
+ d.error(function(e){liberator.echoerr("direct_bookmark.js: Exception throwed! " + e);liberator.log(e);});
+ setTimeout(function(){first.call();},0);
+ };
};
let completer = let (lastURL, lastUserTags, onComplete, done = true) function(context, arg){
@@ -850,13 +852,13 @@ for Migemo search: require XUL/Migemo Extension };
liberator.modules.commands.addUserCommand(['sbm'],"Post to Social Bookmark (Current Buffer)",
- action,
+ makeAction(false),
{literal: 0, completer: completer, options: options},
true
);
liberator.modules.commands.addUserCommand(['sbmo[ther]'],"Post to Social Bookmark",
- action,
+ makeAction(true),
{literal: 1, completer: urlCompleter, options: options},
true
);
|