From 038f995067b9beb88a31b0b814284f5cc4fdab1a Mon Sep 17 00:00:00 2001 From: drry Date: Fri, 3 Oct 2008 21:50:36 +0000 Subject: * URI の部分指定を追加しました。 * e.g. `http://example1.jp:80/path1?query1#fragment1` git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@20659 d0d07461-0603-4401-acd4-de1884942a52 --- incuri.js | 77 +++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 19 deletions(-) (limited to 'incuri.js') diff --git a/incuri.js b/incuri.js index 6999717..0253851 100644 --- a/incuri.js +++ b/incuri.js @@ -1,20 +1,30 @@ /** * ==VimperatorPlugin== * @name incuri.js - * @description increment number in URI + * @description increment the number in the URI * @description-ja URIに含まれる数字をインクリメント * @author hogelog - * @version 0.01 + * @version 0.02 * ==/VimperatorPlugin== * * COMMANDS: - * :incuri -> Increment number in URI - * :decuri -> Decrement number in URI + * :decdomain -> Increment the number in the domain name + * :decfragment -> Increment the number in the fragment ID + * :decpath -> Increment the number in the path name + * :decport -> Increment the number in the port number + * :decquery -> Increment the number in the query string + * :decuri -> Decrement the number in the URI + * :incdomain -> Increment the number in the domain name + * :incfragment -> Increment the number in the fragment ID + * :incpath -> Increment the number in the path name + * :incport -> Increment the number in the port number + * :incquery -> Increment the number in the query string + * :incuri -> Increment the number in the URI * */ -(function(){ - var numreg = /^(.+[^\d])(\d+)([^\d]*)$/; +(function() { + var numreg = /^(.*\D|)(\d+)(\D*)$/; function numstr(num, len) { var str = String(num); while(str.length 2 ? p == part ? newpart + : l[part] + : part) + .join(""); + } } else { - liberator.echoerr("Cannot find number in "+uri); + liberator.echoerr("Cannot find a number in the " + + p + " <" + part + ">"); } }; - } - liberator.commands.add(["incuri"], "Increment number in URI", - makeinc(function(x) {return x+1})); - liberator.commands.add(["decuri"], "Decrement number in URI", - makeinc(function(x) {return x-1})); + [ + ["uri", "href", "URI"], + ["path", "pathname", "path name"], + ["query", "search", "query string"], + ["fragment", "hash", "fragment ID"], + ["port", "port", "port number"], + ["domain", "hostname", "domain name"] + ].forEach(function(part) { + var [suffix, prop, name] = part; + [ + ["In", 1], ["De", -1] + ].forEach(function(direction) { + var [prefix, dir] = direction; + liberator.commands + .add([prefix.toLowerCase() + "c" + suffix], + prefix + "crement the number in the " + name + ".", + makeinc(function(x) x + dir, prop)); + }); + }); })(); -// vim: set sw=4 ts=4 et: +// vim: set sw=4 ts=4 sts=4 et: -- cgit v1.2.3