1
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Example recipes</title><meta name="generator" content="DocBook XSL Stylesheets V1.68.1"><link rel="start" href="index.html" title="The ELinks Manual"><link rel="up" href="ch14.html" title="Chapter 14. Scripting ELinks with Lua"><link rel="prev" href="ch14s03.html" title="Using ELinks with Lua"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Example recipes</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch14s03.html">Prev</a> </td><th width="60%" align="center">Chapter 14. Scripting ELinks with Lua</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2522664"></a>Example recipes</h2></div></div></div><p>This chapter contains some example scripts that you can use. All of them come
1
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Example recipes</title><meta name="generator" content="DocBook XSL Stylesheets V1.68.1"><link rel="start" href="index.html" title="The ELinks Manual"><link rel="up" href="ch14.html" title="Chapter 14. Scripting ELinks with Lua"><link rel="prev" href="ch14s03.html" title="Using ELinks with Lua"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Example recipes</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch14s03.html">Prev</a> </td><th width="60%" align="center">Chapter 14. Scripting ELinks with Lua</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2523202"></a>Example recipes</h2></div></div></div><p>This chapter contains some example scripts that you can use. All of them come
2
2
from <code class="literal">contrib/lua/hooks.lua</code>. I really recommend you to see it directly
3
3
instead of copying code out of this document. Also, not everything in there is
4
4
covered here.</p><p>If you would like to contribute scripts, that would be great! Please send
5
them to me at <a href="mailto:tjaden@@users.sourceforge.net" target="_top">tjaden@@users.sourceforge.net</a>. Cliff and I plan to
5
them to me at <a href="mailto:tjaden@users.sourceforge.net" target="_top">tjaden@users.sourceforge.net</a>. Cliff and I plan to
6
6
start a script repository, provided we get some contributions. As for script
7
7
ideas, you'll just have to be a little creative :-)</p><p>Also take a look at the <code class="literal">contrib/lua/</code> directory in the ELinks distribution.
8
8
Note that Peter and Cliff don't maintain the Lua support intensively anymore,
9
thus it would be probably nice to Cc me (<a href="mailto:pasky@@ucw.cz" target="_top">pasky@@ucw.cz</a>) if you want
9
thus it would be probably nice to Cc me (<a href="mailto:pasky@ucw.cz" target="_top">pasky@ucw.cz</a>) if you want
10
10
to contribute some patch, so that I would be able to add it to the ELinks
11
distribution.</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2522726"></a>Go to URL on steroids</h3></div></div></div><p>There are some web sites that I visit often. Bookmarks are okay, but they are
11
distribution.</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523264"></a>Go to URL on steroids</h3></div></div></div><p>There are some web sites that I visit often. Bookmarks are okay, but they are
12
12
separate from the "Go to URL" dialog box, so I keep forgetting to use them.
13
13
Also, when I visit a search engine home page, all I really want to do is enter
14
14
a search term.</p><p>The following script allows me to type certain strings into the "Go to URL"
73
73
end</pre><p>(Note that this was noticably enhanced and rewritten in the ELinks standart
74
hooks.)</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2522802"></a>Expanding ~ (tilde)</h3></div></div></div><p>By adding an extra snippet of code to the previous example, we can make ELinks
74
hooks.)</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523340"></a>Expanding ~ (tilde)</h3></div></div></div><p>By adding an extra snippet of code to the previous example, we can make ELinks
75
75
expand pathnames such as <code class="literal">~/foo/bar</code>
76
76
and <code class="literal">~user/zappo</code>, like in the shell
77
77
and other Unix programs.</p><pre class="screen">-- Home directory: If you do not enable system functions, you will need
95
.</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2522853"></a>Filtering crap</h3></div></div></div><p>Many web pages nowadays have columns to the left and right of the text, which
95
.</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523391"></a>Filtering crap</h3></div></div></div><p>Many web pages nowadays have columns to the left and right of the text, which
96
96
are utterly useless. If you happen to be viewing the page in a 80x25 screen,
97
97
the text you want to read ends up crammed into a tiny space in the centre. We
98
use ELinks Lua support to manipulate the HTML before it reaches the parser.</p><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2522868"></a>linuxtoday.com</h4></div></div></div><p>Note: This recipe is out of date.</p><p>Linux Today has two problems when viewed in ELinks: the useless columns on the
98
use ELinks Lua support to manipulate the HTML before it reaches the parser.</p><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2523406"></a>linuxtoday.com</h4></div></div></div><p>Note: This recipe is out of date.</p><p>Linux Today has two problems when viewed in ELinks: the useless columns on the
99
99
left and the right and all the text appears in cyan. Here is a quick recipe
100
100
to fix that:</p><pre class="screen">-- Plain strfind (no metacharacters)
101
101
function sstrfind (s, pattern)
122
end</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2522922"></a>linuxgames.com</h4></div></div></div><p>Here is a simpler example, for <a href="http://www.linuxgames.com/" target="_top">http://www.linuxgames.com/</a>.</p><pre class="screen">function pre_format_html_hook (url, html)
122
end</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2523461"></a>linuxgames.com</h4></div></div></div><p>Here is a simpler example, for <a href="http://www.linuxgames.com/" target="_top">http://www.linuxgames.com/</a>.</p><pre class="screen">function pre_format_html_hook (url, html)
127
127
return gsub (html, "<CENTER>.-</center>", "", 1)
130
.</pre></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2522953"></a>Reading gzipped files</h3></div></div></div><p>Note: ELinks already supports gzipped files natively.</p><p>Sometimes documents come gzipped in order to save space, but then you need to
130
.</pre></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523492"></a>Reading gzipped files</h3></div></div></div><p>Note: ELinks already supports gzipped files natively.</p><p>Sometimes documents come gzipped in order to save space, but then you need to
131
131
uncompress them to read them with ELinks. Here is a recipe to handle gzipped
132
132
files on a Unix system.</p><pre class="screen">-- This script requires system functions.
148
.</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2522995"></a>Printing</h3></div></div></div><p>Printing a web page with ELinks usually involves quite a few steps: Save the
148
.</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523534"></a>Printing</h3></div></div></div><p>Printing a web page with ELinks usually involves quite a few steps: Save the
149
149
current document onto disk. Run it through ELinks on the command-line (so it
150
150
fits into 80 columns) to generate a plain text version. Remove the 80th
151
151
column from the text version, as it will make printers wrap down to the next
170
170
-- Send the current document to `enscript'.
171
171
function enscript ()
172
172
catto ("|enscript -fCourier8")
173
end</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523074"></a>Deferring to Netscape</h3></div></div></div><p>If you come across a brain-dead web page that is totally unreadable with
173
end</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523612"></a>Deferring to Netscape</h3></div></div></div><p>If you come across a brain-dead web page that is totally unreadable with
174
174
ELinks, you'd probably want to open it with a graphical browser. The
175
175
following function opens the current document in Netscape.</p><pre class="screen">-- This function requires `execute', a system function.
183
183
local new = netscape_new_window and ",new_window" or ""
184
184
execute ("( netscape -remote 'openURL("..current_url ()..new..")'"
185
185
.." || netscape '"..current_url ().."' ) 2>/dev/null &")
186
end</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523107"></a>Alternative bookmark system</h3></div></div></div><p>Many people would like to have a bookmark system with categories (note that
186
end</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523645"></a>Alternative bookmark system</h3></div></div></div><p>Many people would like to have a bookmark system with categories (note that
187
187
ELinks already supports that, marketing name Hiearchical bookmarks), and also
188
188
to be able to view them and search for them in an HTML page. I have written
189
189
an alternative bookmark system (for ELinks), which some people may like better
190
than the standard bookmark system.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523130"></a>More ideas</h3></div></div></div><div class="itemizedlist"><ul type="disc"><li>
190
than the standard bookmark system.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523666"></a>More ideas</h3></div></div></div><div class="itemizedlist"><ul type="disc"><li>
191
191
The Lua interface needs to be redesigned to provide more flexible, coherent
192
192
and usable interface to the scripts.