diff options
author | drry | 2008-09-05 17:01:02 +0000 |
---|---|---|
committer | drry | 2008-09-05 17:01:02 +0000 |
commit | 02c90b4c7d9cb363fbc4dc2c57d14eefa121c905 (patch) | |
tree | 732135a8e55144220e1a2009d97e66830c768356 /relative_move.js | |
parent | ded669d5a613eedc46c2e1db94f6179eb1cf071a (diff) | |
download | vimperator-plugins-02c90b4c7d9cb363fbc4dc2c57d14eefa121c905.tar.bz2 |
* fixed a missing `var` for the `_r`.
* et cetera.
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@18906 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'relative_move.js')
-rw-r--r-- | relative_move.js | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/relative_move.js b/relative_move.js index c36abc4..9bb937c 100644 --- a/relative_move.js +++ b/relative_move.js @@ -18,16 +18,17 @@ (function (){ function trim_query(url){ - var res = (_r = url.match(/^(.*)\?/)) ? _r[1] : url; - res = (_r = res.match(/^(http.*)http/)) ? _r[1] : res; - res = (_r = url.match(/^(.*)#/)) ? _r[1] : res; + var _r; + var res = (_r = url.match(/^.*(?=\?)/)) ? _r[0] : url; + res = (_r = res.match(/^https?:\/\/.*(?=https?:\/\/)/)) ? _r[0] : res; + res = (_r = url.match(/^.*(?=#)/)) ? _r[0] : res; return res; } function open_path(path, tab){ var win = window.content.window; var loc = win.location; - var splited_path = path.split("/"); + var splited_path = path.split(/\/+/); var up = 0; if(!tab){ @@ -48,33 +49,33 @@ break; } + var url, base; switch(up){ case -2: // "/hoge" - var base = loc.protocol + "//" + loc.hostname; - var url = base + path; + base = loc.protocol + "//" + loc.hostname; + url = base + path; break; case -1: // "./hoge" - var _r = null; - var base = trim_query(loc.href); + base = trim_query(loc.href); path = path.substring(2); if(base[base.length-1] == "/") - var url = base + path; + url = base + path; else - var url = base + "/" + path; + url = base + "/" + path; break; case 0: // "hoge" - var url = loc.href + path; + url = loc.href + path; break; default: // "../../hoge" - var base = trim_query(loc.href); - var c = 0; + base = trim_query(loc.href); + let c = 0; while(c < up){ if(c > 0) base = base.substr(0, base.length-1); - base = base.match(/^(.*\/)[^\/]*$/)[1]; + [base] = base.match(/^.*\/(?=[^\/]*$)/); path = path.substring(3); c++; } - var url = base + path; + url = base + path; break; } liberator.open(url, tab); @@ -83,9 +84,7 @@ liberator.commands.addUserCommand( ["ro[pen]"], "Open relative URL in the current tab", - function(path){ - open_path(path); - } + open_path ); liberator.commands.addUserCommand( |