From 1ab47f58917693ef925023d1010c455f4b82e5b9 Mon Sep 17 00:00:00 2001 From: anekos Date: Thu, 5 Aug 2010 13:50:14 +0000 Subject: 複数URL時の補完に説明っぽいものをついか git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@38182 d0d07461-0603-4401-acd4-de1884942a52 --- twittperator.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'twittperator.js') diff --git a/twittperator.js b/twittperator.js index 5c94164..2fb7d7a 100755 --- a/twittperator.js +++ b/twittperator.js @@ -1326,26 +1326,33 @@ liberator.echo("[Twittperator] Your post " + '"' + t + '" (' + t.length + " characters) was sent.", true); }); } // }}} - function openLink(text) { // {{{ - // TODO 複数のリンクに対応 - let links = []; - text.replace(/https?:\/\/\S+/g, function(m) links.push(m)); - if (links.length <= 0) + function selectAndOpenLink(links) { // {{{ + if (!links || !links.length) return; - if (links.length == 1) - return liberator.open(links[0], liberator.NEW_TAB); + if (links.length === 1) + return liberator.open(links[0][0], liberator.NEW_TAB); commandline.input( "Select URL: ", function(arg) liberator.open(arg, liberator.NEW_TAB), { completer: function(context) { - context.completions = [[link, link] for ([, link] in Iterator(links))]; + context.completions = links; } } ); } // }}} + function openLink(text) { // {{{ + let m = text.match(/.*?(https?:\/\/[\S]+)/g); + if (!m) + return; + + let links = + m.map(function (s) s.match(/^(.*?)(https?:\/\/[\S]+)/).slice(1)) . + map(function (ss) (ss.reverse(), ss.map(String.trim))) + selectAndOpenLink(links); + } // }}} function ReTweet(id) { // {{{ let url = "http://api.twitter.com/1/statuses/retweet/" + id + ".json"; tw.post(url, null, function(text) { -- cgit v1.2.3