aboutsummaryrefslogtreecommitdiffstats
path: root/incuri.js
diff options
context:
space:
mode:
authorhogelog2008-10-03 17:11:47 +0000
committerhogelog2008-10-03 17:11:47 +0000
commitc9c02d857ac0b854a82cec06f5f25eea7a2f6f56 (patch)
treee831aff0a42db88df3a30966eac34e4291c68718 /incuri.js
parentf590a8bbee5c25f7996b263179f4effe88472121 (diff)
downloadvimperator-plugins-c9c02d857ac0b854a82cec06f5f25eea7a2f6f56.tar.bz2
URI中に含まれる番号をインクリメント/デクリメントしたURIを開くコマンド追加するincuri.js
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@20655 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'incuri.js')
-rw-r--r--incuri.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/incuri.js b/incuri.js
new file mode 100644
index 0000000..6999717
--- /dev/null
+++ b/incuri.js
@@ -0,0 +1,43 @@
+/**
+ * ==VimperatorPlugin==
+ * @name incuri.js
+ * @description increment number in URI
+ * @description-ja URIに含まれる数字をインクリメント
+ * @author hogelog
+ * @version 0.01
+ * ==/VimperatorPlugin==
+ *
+ * COMMANDS:
+ * :incuri -> Increment number in URI
+ * :decuri -> Decrement number in URI
+ *
+ */
+
+(function(){
+ var numreg = /^(.+[^\d])(\d+)([^\d]*)$/;
+ function numstr(num, len) {
+ var str = String(num);
+ while(str.length<len) {
+ str = "0" + str;
+ }
+ return str;
+ }
+ function makeinc(f) {
+ return function() {
+ let uri = window.content.location.href;
+ if(numreg.test(uri)) {
+ let num = RegExp.$2;
+ let nextnum = numstr(f(parseInt(num)), num.length);
+ let nexturi = RegExp.$1 + nextnum + RegExp.$3;
+ window.content.location.href = nexturi;
+ } else {
+ liberator.echoerr("Cannot find number in "+uri);
+ }
+ };
+ }
+ 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}));
+})();
+// vim: set sw=4 ts=4 et: