display lua hooks errors
[elinks.git] / contrib / smjs / hooks.js
blob7973640ac8fed225848edc06ed819172176f98b1
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).
4  */
6 elinks.keymaps.main["@"] = function () {
7         elinks.location = elinks.location + "/..";
8 };
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))
14                         return false;
16         return true;
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;
24         }
26         return url;
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;
34         }
36         return url;
39 function root_w00t(cached, vs) {
40         cached.content = cached.content.replace(/root/g, "w00t");
41         return true;
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/))
48                 return true;
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>');
54         }
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>';
61                 vs.plain = "0";
62         } else {
63                 cached.content = new_content;
64         }
67         return true;
69 elinks.preformat_html_hooks.push(mangle_deb_bugnumbers);
71 function block_pr0n(uri) {
72         if (uri.match(/pr0n/)) {
73                 elinks.alert('No pr0n!');
74                 return "";
75         }
77         return uri;
79 elinks.follow_url_hooks.push(block_pr0n);
81 function reload() {
82         do_file(elinks.home + 'hooks.js');
85 do_file(elinks.home + 'smartprefixes_bookmarks.js');
86 do_file(elinks.home + 'smartprefixes_classic.js');