1 /* Modern, bookmark-based smartprefixes */
3 var loaded_smartprefixes_common_code;
4 if (!loaded_smartprefixes_common_code) {
5 do_file(elinks.home + "smartprefixes_common.js");
6 loaded_smartprefixes_common_code = 1;
9 /* Create a top-level folder titled "smartprefixes". In it, add a bookmark
10 * for each smartprefix, putting the keyword in the title and either a normal
11 * URI or some JavaScript code prefixed with "javascript:" as the URI. When you
12 * enter the keyword in the Go to URL box, ELinks will take the URI
13 * of the corresponding bookmark, replace any occurrence of "%s" with the rest
14 * of the text entered in the Go to URL box, evaluate the code if the URI
15 * starts with "javascript:", and go to the resulting URI.
17 function rewrite_uri(uri) {
18 if (!elinks.bookmarks.smartprefixes) return uri;
20 var parts = uri.split(" ");
21 var prefix = parts[0];
23 if (!elinks.bookmarks.smartprefixes.children[prefix]) return uri;
25 var rule = elinks.bookmarks.smartprefixes.children[prefix].url;
26 var rest = parts.slice(1).join(" ");
28 if (rule.match(/^javascript:/))
30 .replace(/^javascript:/, "")
31 .replace(/%s/, rest));
33 return rule.replace(/%s/, escape(rest));
35 elinks.goto_url_hooks.push(rewrite_uri);