aboutsummaryrefslogtreecommitdiffstats
path: root/incuri.js
diff options
context:
space:
mode:
authordrry2008-10-03 21:50:36 +0000
committerdrry2008-10-03 21:50:36 +0000
commit038f995067b9beb88a31b0b814284f5cc4fdab1a (patch)
tree432892fab7570ecb9ba551a03f4abbd51efdd015 /incuri.js
parentc9c02d857ac0b854a82cec06f5f25eea7a2f6f56 (diff)
downloadvimperator-plugins-038f995067b9beb88a31b0b814284f5cc4fdab1a.tar.bz2
* 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
Diffstat (limited to 'incuri.js')
-rw-r--r--incuri.js77
1 files changed, 58 insertions, 19 deletions
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<len) {
@@ -22,22 +32,51 @@
}
return str;
}
- function makeinc(f) {
- return function() {
- let uri = window.content.location.href;
- if(numreg.test(uri)) {
+ function makeinc(f, p)
+ function(arg) {
+ var l = window.content.location;
+ var part = l[p];
+ if(p == "port" && part == "") {
+ part = "80";
+ }
+ if(numreg.test(part)) {
let num = RegExp.$2;
let nextnum = numstr(f(parseInt(num)), num.length);
- let nexturi = RegExp.$1 + nextnum + RegExp.$3;
- window.content.location.href = nexturi;
+ let newpart = RegExp.$1 + nextnum + RegExp.$3;
+ if(p == "href") {
+ window.content.location.href = newpart;
+ } else {
+ window.content.location.href = [
+ "protocol", "//", "hostname", ":", "port", "pathname",
+ "search", "hash"
+ ].map(function(part) part.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: