2005-12-29 02:06:35 -05:00
|
|
|
/* These are examples for the ELinks SpiderMonkey scripting interface.
|
|
|
|
* Place choice parts in a file named "hooks.js" in your ELinks configuration
|
2023-01-26 06:41:46 -05:00
|
|
|
* directory (~/.config/elinks).
|
2005-12-29 02:06:35 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
elinks.keymaps.main["@"] = function () {
|
|
|
|
elinks.location = elinks.location + "/..";
|
|
|
|
};
|
|
|
|
|
|
|
|
elinks.preformat_html_hooks = new Array();
|
2006-01-27 22:23:17 -05:00
|
|
|
elinks.preformat_html = function (cached, vs) {
|
2005-12-29 02:06:35 -05:00
|
|
|
for (var i in elinks.preformat_html_hooks)
|
2006-01-27 22:23:17 -05:00
|
|
|
if (!elinks.preformat_html_hooks[i](cached, vs))
|
2005-12-29 02:06:35 -05:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
elinks.goto_url_hooks = new Array();
|
|
|
|
elinks.goto_url_hook = function (url) {
|
|
|
|
for (var i in elinks.goto_url_hooks){
|
|
|
|
url = elinks.goto_url_hooks[i](url);
|
2005-12-29 02:32:12 -05:00
|
|
|
if (false === url) return false;
|
2005-12-29 02:06:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
|
|
|
elinks.follow_url_hooks = new Array();
|
|
|
|
elinks.follow_url_hook = function (url) {
|
|
|
|
for (var i in elinks.follow_url_hooks) {
|
|
|
|
url = elinks.follow_url_hooks[i](url);
|
2005-12-29 02:32:12 -05:00
|
|
|
if (false === url) return false;
|
2005-12-29 02:06:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
2006-01-27 22:23:17 -05:00
|
|
|
function root_w00t(cached, vs) {
|
2005-12-29 02:06:35 -05:00
|
|
|
cached.content = cached.content.replace(/root/g, "w00t");
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
elinks.preformat_html_hooks.push(root_w00t);
|
|
|
|
|
2006-01-27 22:23:17 -05:00
|
|
|
function mangle_deb_bugnumbers(cached, vs) {
|
2005-12-29 02:06:35 -05:00
|
|
|
if (!cached.uri.match(/^[a-z0-9]+:\/\/[a-z0-9A-Z.-]+debian\.org/)
|
|
|
|
&& !cached.uri.match(/changelog\.Debian/))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
var num_re = /([0-9]+)/g;
|
|
|
|
var rewrite_closes_fn = function (str) {
|
|
|
|
return str.replace(num_re,
|
|
|
|
'<a href="http://bugs.debian.org/$1">$1</a>');
|
|
|
|
}
|
|
|
|
/* Debian Policy Manual 4.4 footnote 16 */
|
|
|
|
var closes_re = /closes:\s*(?:bug)?\#?\s?\d+(?:,\s*(?:bug)?\#?\s?\d+)*/gi;
|
|
|
|
|
2006-01-27 22:27:41 -05:00
|
|
|
var new_content = cached.content.replace(closes_re, rewrite_closes_fn);
|
2006-01-30 10:42:58 -05:00
|
|
|
if (cached.type == 'text/plain') {
|
2006-01-27 22:27:41 -05:00
|
|
|
cached.content = '<pre>' + new_content + '</pre>';
|
|
|
|
vs.plain = "0";
|
|
|
|
} else {
|
|
|
|
cached.content = new_content;
|
|
|
|
}
|
|
|
|
|
2005-12-29 02:06:35 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
elinks.preformat_html_hooks.push(mangle_deb_bugnumbers);
|
|
|
|
|
|
|
|
function block_pr0n(uri) {
|
|
|
|
if (uri.match(/pr0n/)) {
|
|
|
|
elinks.alert('No pr0n!');
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2006-10-20 17:04:52 -04:00
|
|
|
return uri;
|
2005-12-29 02:06:35 -05:00
|
|
|
}
|
|
|
|
elinks.follow_url_hooks.push(block_pr0n);
|
|
|
|
|
2006-06-23 00:00:02 -04:00
|
|
|
function reload() {
|
|
|
|
do_file(elinks.home + 'hooks.js');
|
|
|
|
}
|
|
|
|
|
2005-12-29 17:28:36 -05:00
|
|
|
do_file(elinks.home + 'smartprefixes_bookmarks.js');
|
|
|
|
do_file(elinks.home + 'smartprefixes_classic.js');
|