From abc5b8b57fd2ae6cb04596a60ea4ba1c5936760b Mon Sep 17 00:00:00 2001 From: tyru Date: Sun, 22 Apr 2012 15:20:39 +0900 Subject: direct_bookmark.js - add --url option to :sbm --- direct_bookmark.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/direct_bookmark.js b/direct_bookmark.js index 5d15112..d796dbc 100644 --- a/direct_bookmark.js +++ b/direct_bookmark.js @@ -67,6 +67,8 @@ for Migemo search: require XUL/Migemo Extension Arguments -s,-service: default:"hdl" Specify target SBM services to post + -u,--url: default:Current buffer URL + Specify target SBM services to post ||< === :bentry === >|| @@ -655,6 +657,19 @@ for Migemo search: require XUL/Migemo Extension first.call([]); } + function getTitleByURL(url) { + if (url === liberator.modules.buffer.URL) + return liberator.modules.buffer.title; + + let xhr = new XMLHttpRequest(); + xhr.open("GET", url, false); + xhr.send(null); + + let html = parseHTML(xhr.responseText); + let title = getFirstElementByXPath("title", html); + + return title ? title.innerText : ''; + } liberator.modules.commands.addUserCommand(['btags'],"Update Social Bookmark Tags", function(arg){setTimeout(function(){getTagsAsync().call([])},0)}, {}, true); liberator.modules.commands.addUserCommand(['bentry'],"Goto Bookmark Entry Page", @@ -705,8 +720,10 @@ for Migemo search: require XUL/Migemo Extension liberator.modules.commands.addUserCommand(['sbm'],"Post to Social Bookmark", function(arg){ var targetServices = useServicesByPost; + var url = liberator.modules.buffer.URL; if (arg["-s"]) targetServices = arg["-s"]; + if (arg["-u"]) url = arg["-u"]; comment = arg.literalArg; var tags = []; @@ -726,15 +743,12 @@ for Migemo search: require XUL/Migemo Extension tags.forEach(function (t) __context__.tags.add(t)); - var url = liberator.modules.buffer.URL; - var title = liberator.modules.buffer.title; - 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,title, + isNormalize ? getNormalizedPermalink(url) : url,getTitleByURL(url), comment,tags )); if(echoType == "multiline") { @@ -791,6 +805,10 @@ for Migemo search: require XUL/Migemo Extension set(context, tags); }; + /* + * XXX: Should recognize --url option? + * TODO: Complete --url argument like :open + */ if (buffer.URL == lastURL){ if (done) { onComplete(lastUserTags); @@ -818,6 +836,7 @@ for Migemo search: require XUL/Migemo Extension }, options: [ [['-s','-service'], liberator.modules.commands.OPTION_STRING], + [['-u','--url'], liberator.modules.commands.OPTION_STRING], ] }, true -- cgit v1.2.3 From 26272624b6fb29fb9456bcae435b84ed32f8fdcc Mon Sep 17 00:00:00 2001 From: tyru Date: Sun, 22 Apr 2012 16:11:49 +0900 Subject: direct_bookmark.js - fix xpath --- direct_bookmark.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/direct_bookmark.js b/direct_bookmark.js index d796dbc..e7d0a00 100644 --- a/direct_bookmark.js +++ b/direct_bookmark.js @@ -666,9 +666,9 @@ for Migemo search: require XUL/Migemo Extension xhr.send(null); let html = parseHTML(xhr.responseText); - let title = getFirstElementByXPath("title", html); + let title = getFirstElementByXPath("//title/text()", html); - return title ? title.innerText : ''; + return title.nodeValue; } liberator.modules.commands.addUserCommand(['btags'],"Update Social Bookmark Tags", function(arg){setTimeout(function(){getTagsAsync().call([])},0)}, {}, true); -- cgit v1.2.3 From c6d2f727926988293e4ad3434fcc0598fc002f07 Mon Sep 17 00:00:00 2001 From: tyru Date: Sun, 22 Apr 2012 16:12:45 +0900 Subject: direct_bookmark.js - add TODO --- direct_bookmark.js | 1 + 1 file changed, 1 insertion(+) diff --git a/direct_bookmark.js b/direct_bookmark.js index e7d0a00..55423d3 100644 --- a/direct_bookmark.js +++ b/direct_bookmark.js @@ -668,6 +668,7 @@ for Migemo search: require XUL/Migemo Extension let html = parseHTML(xhr.responseText); let title = getFirstElementByXPath("//title/text()", html); + // FIXME: encoding (see charset and must I convert...?) return title.nodeValue; } liberator.modules.commands.addUserCommand(['btags'],"Update Social Bookmark Tags", -- cgit v1.2.3 From be20b38ba3abe465f569d24d72d101a1013a38c8 Mon Sep 17 00:00:00 2001 From: anekos Date: Mon, 25 Jun 2012 17:16:32 +0900 Subject: Recognize --url option. --- direct_bookmark.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/direct_bookmark.js b/direct_bookmark.js index 55423d3..fbb9349 100644 --- a/direct_bookmark.js +++ b/direct_bookmark.js @@ -796,6 +796,8 @@ for Migemo search: require XUL/Migemo Extension if (m.test(tag) && match_result[1].indexOf('[' + tag + ']') < 0) ]; } + let url = arg["-u"] || buffer.URL; + context.fork('UserTags', 0, context, function(context){ context.title = ['User Tags', 'User Tags']; @@ -807,20 +809,19 @@ for Migemo search: require XUL/Migemo Extension }; /* - * XXX: Should recognize --url option? * TODO: Complete --url argument like :open */ - if (buffer.URL == lastURL){ + if (url == lastURL){ if (done) { onComplete(lastUserTags); } else { context.incomplete = true; } } else { - lastURL = buffer.URL; + lastURL = url; context.incomplete = true; done = false; - getUserTags(buffer.URL, function (tags) onComplete(tags)); + getUserTags(url, function (tags) onComplete(tags)); } }); -- cgit v1.2.3 From b54e38d5d0802545aa346f14da9a8885eed85288 Mon Sep 17 00:00:00 2001 From: anekos Date: Mon, 2 Jul 2012 03:32:55 +0900 Subject: Add :sbmother command instead of -url option. --- direct_bookmark.js | 154 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 86 insertions(+), 68 deletions(-) diff --git a/direct_bookmark.js b/direct_bookmark.js index fbb9349..fe14501 100644 --- a/direct_bookmark.js +++ b/direct_bookmark.js @@ -718,13 +718,14 @@ for Migemo search: require XUL/Migemo Extension }).join('
'); liberator.echo(html, true); }, {}, true); - liberator.modules.commands.addUserCommand(['sbm'],"Post to Social Bookmark", - function(arg){ + // Add :sbm, :sbmo {{{ + { + let action = function(arg){ var targetServices = useServicesByPost; var url = liberator.modules.buffer.URL; if (arg["-s"]) targetServices = arg["-s"]; - if (arg["-u"]) url = arg["-u"]; + if (arg[0]) url = arg[0]; comment = arg.literalArg; var tags = []; @@ -768,80 +769,97 @@ for Migemo search: require XUL/Migemo Extension } d.error(function(e){liberator.echoerr("direct_bookmark.js: Exception throwed! " + e);liberator.log(e);}); setTimeout(function(){first.call();},0); - },{ - literal: 0, - completer: let (lastURL, lastUserTags, onComplete, done = true) function(context, arg){ - function matchPosition (e){ - let m = liberator.globalVariables.direct_sbm_tag_match || 'prefix'; - switch (m) { - case 'infix': return e; - case 'suffix': return e + "$"; - } - return "^" + e; + }; + + let completer = let (lastURL, lastUserTags, onComplete, done = true) function(context, arg){ + function matchPosition (e){ + let m = liberator.globalVariables.direct_sbm_tag_match || 'prefix'; + switch (m) { + case 'infix': return e; + case 'suffix': return e + "$"; } + return "^" + e; + } - function set (context, tags) { - let filter = context.filter; - var match_result = filter.match(/((?:\[[^\]]*\])*)\[?(.*)/); //[all, commited, now inputting] - var expr = XMigemoCore && isUseMigemo ? "(" + XMigemoCore.getRegExp(match_result[2]) + ")" - : match_result[2]; - var m = new RegExp(matchPosition(expr),'i'); + function set (context, tags) { + let filter = context.filter; + var match_result = filter.match(/((?:\[[^\]]*\])*)\[?(.*)/); //[all, commited, now inputting] + var expr = XMigemoCore && isUseMigemo ? "(" + XMigemoCore.getRegExp(match_result[2]) + ")" + : match_result[2]; + var m = new RegExp(matchPosition(expr),'i'); - context.advance( match_result[1].length ); + context.advance( match_result[1].length ); - context.incomplete = false; - context.completions = - [ ["[" + tag + "]","Tag"] - for each (tag in tags) - if (m.test(tag) && match_result[1].indexOf('[' + tag + ']') < 0) ]; - } + context.incomplete = false; + context.completions = + [ ["[" + tag + "]","Tag"] + for each (tag in tags) + if (m.test(tag) && match_result[1].indexOf('[' + tag + ']') < 0) ]; + } - let url = arg["-u"] || buffer.URL; - - context.fork('UserTags', 0, context, function(context){ - context.title = ['User Tags', 'User Tags']; - - onComplete = function(tags){ - done = true; - lastUserTags = tags; - context.incomplete = false; - set(context, tags); - }; - - /* - * TODO: Complete --url argument like :open - */ - if (url == lastURL){ - if (done) { - onComplete(lastUserTags); - } else { - context.incomplete = true; - } + let url = arg[0] || buffer.URL; + liberator.log(url); + + context.fork('UserTags', 0, context, function(context){ + context.title = ['User Tags', 'User Tags']; + + onComplete = function(tags){ + done = true; + lastUserTags = tags; + context.incomplete = false; + set(context, tags); + }; + + /* + * TODO: Complete --url argument like :open + */ + if (url == lastURL){ + if (done) { + onComplete(lastUserTags); } else { - lastURL = url; context.incomplete = true; - done = false; - getUserTags(url, function (tags) onComplete(tags)); } - }); + } else { + lastURL = url; + context.incomplete = true; + done = false; + getUserTags(url, function (tags) onComplete(tags)); + } + }); - context.fork('MyTags', 0, context, function(context, arg){ - context.title = ['My Tag','Description']; + context.fork('MyTags', 0, context, function(context, arg){ + context.title = ['My Tag','Description']; - if(__context__.tags.isEmpty){ - context.incomplete = true; - getTagsAsync(set.bind(null, context)).call([]); - } else { - set(context, __context__.tags); - } - }); - }, - options: [ - [['-s','-service'], liberator.modules.commands.OPTION_STRING], - [['-u','--url'], liberator.modules.commands.OPTION_STRING], - ] - }, - true - ); + if(__context__.tags.isEmpty){ + context.incomplete = true; + getTagsAsync(set.bind(null, context)).call([]); + } else { + set(context, __context__.tags); + } + }); + }; + + let options = [ [['-s','-service'], liberator.modules.commands.OPTION_STRING] ]; + + let urlCompleter = function(context, args){ + if (args.length <= 1) { + return completion.url(context, 'hsl'); + } else { + return completer(context, args); + } + }; + + liberator.modules.commands.addUserCommand(['sbm'],"Post to Social Bookmark (Current Buffer)", + action, + {literal: 0, completer: completer, options: options}, + true + ); + + liberator.modules.commands.addUserCommand(['sbmo[ther]'],"Post to Social Bookmark", + action, + {literal: 1, completer: urlCompleter, options: options}, + true + ); + } // }}} })(); // vim:sw=4 ts=4 et: -- cgit v1.2.3 From e55a10145b1cff318f7fd7b84567e62c905d9e9d Mon Sep 17 00:00:00 2001 From: anekos Date: Mon, 2 Jul 2012 13:11:36 +0900 Subject: arg[0] is not empty... --- direct_bookmark.js | 86 ++++++++++++++++++++++++++++-------------------------- 1 file 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 ); -- cgit v1.2.3 From 92c05a3d71b74a20f8fb080595e3121533a75d6a Mon Sep 17 00:00:00 2001 From: tyru Date: Fri, 27 Jul 2012 00:28:22 +0900 Subject: remove old description and comment --- direct_bookmark.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/direct_bookmark.js b/direct_bookmark.js index c3a3d27..c696498 100644 --- a/direct_bookmark.js +++ b/direct_bookmark.js @@ -67,8 +67,6 @@ for Migemo search: require XUL/Migemo Extension Arguments -s,-service: default:"hdl" Specify target SBM services to post - -u,--url: default:Current buffer URL - Specify target SBM services to post ||< === :bentry === >|| @@ -812,9 +810,6 @@ for Migemo search: require XUL/Migemo Extension set(context, tags); }; - /* - * TODO: Complete --url argument like :open - */ if (url == lastURL){ if (done) { onComplete(lastUserTags); -- cgit v1.2.3