1 /* These are examples for the ELinks SpiderMonkey scripting interface.
2 * Place choice parts in a file named "hooks.js" in your ELinks configuration
3 * directory (~/.elinks).
6 elinks
.keymaps
.main
["@"] = function () {
7 elinks
.location
= elinks
.location
+ "/..";
10 elinks
.preformat_html_hooks
= new Array();
11 elinks
.preformat_html = function (cached
, vs
) {
12 for (var i
in elinks
.preformat_html_hooks
)
13 if (!elinks
.preformat_html_hooks
[i
](cached
, vs
))
19 elinks
.goto_url_hooks
= new Array();
20 elinks
.goto_url_hook = function (url
) {
21 for (var i
in elinks
.goto_url_hooks
){
22 url
= elinks
.goto_url_hooks
[i
](url
);
23 if (false === url
) return false;
29 elinks
.follow_url_hooks
= new Array();
30 elinks
.follow_url_hook = function (url
) {
31 for (var i
in elinks
.follow_url_hooks
) {
32 url
= elinks
.follow_url_hooks
[i
](url
);
33 if (false === url
) return false;
39 function root_w00t(cached
, vs
) {
40 cached
.content
= cached
.content
.replace(/root/g, "w00t");
43 elinks
.preformat_html_hooks
.push(root_w00t
);
45 function mangle_deb_bugnumbers(cached
, vs
) {
46 if (!cached
.uri
.match(/^[a-z0-9]+:\/\/[a-z0-9A-Z.-]+debian\.org/)
47 && !cached
.uri
.match(/changelog\.Debian/))
50 var num_re
= /([0-9]+)/g;
51 var rewrite_closes_fn = function (str
) {
52 return str
.replace(num_re
,
53 '<a href="http://bugs.debian.org/$1">$1</a>');
55 /* Debian Policy Manual 4.4 footnote 16 */
56 var closes_re
= /closes:\s*(?:bug)?\#?\s?\d+(?:,\s*(?:bug)?\#?\s?\d+)*/gi;
58 var new_content
= cached
.content
.replace(closes_re
, rewrite_closes_fn
);
59 if (cached
.type
== 'text/plain') {
60 cached
.content
= '<pre>' + new_content
+ '</pre>';
63 cached
.content
= new_content
;
69 elinks
.preformat_html_hooks
.push(mangle_deb_bugnumbers
);
71 function block_pr0n(uri
) {
72 if (uri
.match(/pr0n/)) {
73 elinks
.alert('No pr0n!');
79 elinks
.follow_url_hooks
.push(block_pr0n
);
82 do_file(elinks
.home
+ 'hooks.js');
85 do_file(elinks
.home
+ 'smartprefixes_bookmarks.js');
86 do_file(elinks
.home
+ 'smartprefixes_classic.js');