1 // Vimperator plugin: Relative Move
5 // If you stay "http://example.com/aaa/bbb/ccc"
8 // move to http://example.com/aaa/bbb/cccddd
10 // move to http://example.com/aaa/bbb/ccc/ddd
12 // move to http://example.com/aaa/bbb/ddd
14 // move to http://example.com/aaa/ddd
16 // move to http://example.com/ddd
20 function trim_query(url){
22 var res = (_r = url.match(/^.*(?=\?)/)) ? _r[0] : url;
23 res = (_r = res.match(/^https?:\/\/.*(?=https?:\/\/)/)) ? _r[0] : res;
24 res = (_r = url.match(/^.*(?=#)/)) ? _r[0] : res;
28 function open_path(path, tab){
29 var win = window.content.window;
30 var loc = win.location;
31 var splited_path = path.toString().split(/\/+/);
35 tab = liberator.CURRENT_TAB;
38 switch(splited_path[0]){
43 while(splited_path[up] == "..") up++;
55 base = loc.protocol + "//" + loc.hostname;
59 base = trim_query(loc.href);
60 path = path.toString().substring(2);
61 if(base[base.length-1] == "/")
64 url = base + "/" + path;
67 url = loc.href + path;
69 default: // "../../hoge"
70 base = trim_query(loc.href);
73 if(c > 0) base = base.substr(0, base.length-1);
74 [base] = base.match(/^.*\/(?=[^\/]*$)/);
75 path = path.toString().substring(3);
81 liberator.open(url, tab);
84 commands.addUserCommand(
86 "Open relative URL in the current tab",
90 commands.addUserCommand(
92 "Open relative URL in a new tab",
94 open_path(path, liberator.NEW_TAB);