mirror of
https://github.com/rkd77/elinks.git
synced 2025-09-21 19:46:23 -04:00
Factor smartprefixes_common.js and smartprefixes_bookmarks.js out of
hooks.js and add smartprefixes_classic.js.
This commit is contained in:
committed by
Miciah Dashiel Butler Masters
parent
7f1711471f
commit
ff2f2e2df1
@@ -61,26 +61,6 @@ function mangle_deb_bugnumbers(cached) {
|
||||
}
|
||||
elinks.preformat_html_hooks.push(mangle_deb_bugnumbers);
|
||||
|
||||
function rewrite_uri(uri) {
|
||||
if (!elinks.bookmarks.smartprefixes) return true;
|
||||
|
||||
var parts = uri.split(" ");
|
||||
var prefix = parts[0];
|
||||
|
||||
if (!elinks.bookmarks.smartprefixes.children[prefix]) return true;
|
||||
|
||||
var rule = elinks.bookmarks.smartprefixes.children[prefix].url;
|
||||
var rest = parts.slice(1).join(" ");
|
||||
|
||||
if (rule.match(/^javascript:/))
|
||||
return eval(rule
|
||||
.replace(/^javascript:/, "")
|
||||
.replace(/%s/, rest));
|
||||
|
||||
return rule.replace(/%s/, escape(rest));
|
||||
}
|
||||
elinks.goto_url_hooks.push(rewrite_uri);
|
||||
|
||||
function block_pr0n(uri) {
|
||||
if (uri.match(/pr0n/)) {
|
||||
elinks.alert('No pr0n!');
|
||||
@@ -91,92 +71,5 @@ function block_pr0n(uri) {
|
||||
}
|
||||
elinks.follow_url_hooks.push(block_pr0n);
|
||||
|
||||
|
||||
/* The following functions are for use as smartprefixes. Create a top-level
|
||||
* folder titled "smartprefixes". In it, add a bookmark for each smartprefix,
|
||||
* putting the keyword in the title and either a normal URI or some JavaScript
|
||||
* code prefixed with "javascript:" as the URI. When you enter the keyword
|
||||
* in the Go to URL box, ELinks will take the URI of the corresponding bookmark,
|
||||
* replace any occurrence of "%s" with the rest of the text entered in the Go to
|
||||
* URL box, evaluate the code if the URI starts with "javascript:", and go to
|
||||
* the resulting URI.
|
||||
*/
|
||||
|
||||
/* Helper function for debian_contents and debian_file. */
|
||||
function debian_package (url, t)
|
||||
{
|
||||
url = url.replace(/(\w+):(\w+)/g,
|
||||
function (all, key, val) { t[key] = val; return ""; })
|
||||
|
||||
return 'http://packages.debian.org/cgi-bin/search_contents.pl?word='
|
||||
+ escape(url.replace(/\s*(\S+)\s*/, '$1'))
|
||||
+ '&searchmode=' + (t.searchmode || 'searchfilesanddirs')
|
||||
+ '&case=' + (t["case"] || 'insensitive')
|
||||
+ '&version=' + (t.version || 'stable')
|
||||
+ '&arch=' + (t.arch || 'i386')
|
||||
}
|
||||
|
||||
/* javascript:debian_contents("%s"); */
|
||||
function debian_contents (url)
|
||||
{
|
||||
return debian_package (url, { searchmode: "filelist" })
|
||||
}
|
||||
|
||||
/* javascript:debian_file("%s"); */
|
||||
function debian_file (url)
|
||||
{
|
||||
return debian_package (url, { searchmode: "searchfilesanddirs" })
|
||||
}
|
||||
|
||||
/* javascript:cvsweb("http://cvsweb.elinks.cz/cvsweb.cgi/", "elinks", "%s"); */
|
||||
function cvsweb (base, project, url)
|
||||
{
|
||||
/* <file>:<revision>[-><revision>] */
|
||||
url = url.replace(/^(.*):(.*?)(?:->(.*))?$/, "$1 $2 $3");
|
||||
|
||||
var parts = url.split(" ");
|
||||
if (parts[3]) {
|
||||
elinks.alert('this smartprefix takes only one to three arguments');
|
||||
return "";
|
||||
}
|
||||
|
||||
var file = parts[0], oldrev = parts[1], newrev = parts[2];
|
||||
if (!file) {
|
||||
elinks.alert('no file given');
|
||||
return "";
|
||||
}
|
||||
|
||||
if (newrev)
|
||||
return base + project + "/" + file + ".diff"
|
||||
+ "?r1=" + oldrev + "&r2=" + newrev + "&f=u";
|
||||
|
||||
if (oldrev)
|
||||
return base + "~checkout~/" + project + "/" + file
|
||||
+ (oldrev != "latest" && "?rev=" + oldrev || "");
|
||||
|
||||
return base + project + "/" + file
|
||||
}
|
||||
|
||||
/* javascript:gmane("%s") */
|
||||
function gmane (url)
|
||||
{
|
||||
var v = url.split(' ');
|
||||
var group = v[0], words = v.slice(1).join(' ');
|
||||
|
||||
if (!words) return "";
|
||||
|
||||
return "http://search.gmane.org/search.php?query=" + words
|
||||
+ "&group=" + group;
|
||||
}
|
||||
|
||||
/* javascript:bugzilla('http://bugzilla.elinks.cz/', "%s"); */
|
||||
function bugzilla (base_url, arguments)
|
||||
{
|
||||
if (!arguments || arguments == '') return base_url;
|
||||
|
||||
if (arguments.match(/^[\d]+$/))
|
||||
return base_url + 'show_bug.cgi?id=' + arguments;
|
||||
|
||||
return base_url + 'buglist.cgi?short_desc_type=allwordssubstr'
|
||||
+ '&short_desc=' + escape(arguments);
|
||||
}
|
||||
do_file(elinks.home + 'smartprefixes_bookmarks.js');
|
||||
do_file(elinks.home + 'smartprefixes_classic.js');
|
||||
|
Reference in New Issue
Block a user