Sneak Peek Help
Table of contents
What is Sneak Peek?
Sneak Peek is an extension for Mozilla Firefox that allows you to preview information from link
targets by hovering over hyperlinks on a webpage. Unlike other preview extensions (Cooliris etc.) the Sneak
Peek extension does not show preview on all links, and it does not show a preview of the entire link target page. Instead
the extension uses little snippets of code, so-called Sneak Peek Scripts, that define for which pages you want
to see a preview, and precisely which part of the link target you want to preview. The extension was built
to generalize an old Greasemonkey script I had written, that allowed you to hover over links in the
Joel on Software message boards, and see the first post in
the thread in a preview box. After getting used to having the functionality on that message board I started
missing it on other message boards I use so I created this extension so I could easily create previews for
any message board. Although the extension was mainly made to preview posts in message boards it can be used
for any case where you want to preview only a specific part of a link target, I use it for example to preview
comments on my blog page by hovering over the comments link.
Sneak Peek Scripts Explained
A Sneak Peek script is a simple textfile that defines which links on which sites should have preview functionality
and what the preview should consists of. The first line of the textfile must be @@SneakPeek, and the
following lines consist of name : value pairs that define what the script is for. The properties
are explained below.
-
Name: This is simply the name of the script and can be anything. The script is required to have a name.
-
Author: This is the author of the script and the value can be left empty.
-
URL: This is the url for the author of the script and the value can be left empty.
-
Site Pattern: This is a regular expression pattern that defines on which
sites this script should be run. This pattern will be compared against every url loaded
in the browser, and if it matches a loaded url then the extension will set up previews
on the correct links in the page.
-
Link Pattern: This is a regular expression pattern that defines
which links should show previews when hovered over. Note that these are only links on
pages that match the Site Pattern part of the script. This is always
compared against the full url of a link, for example if in the source of a page a link is
written as <a href="./foo.html"> and the current domain is http://bar.com, then the link
that the pattern will be compared against is the full http://bar.com/foo.html, NOT just ./foo.html.
-
Peek Pattern: This is a regular expression pattern that defines which part
of the link target page should be shown as a preview. When the mouse is hovering over a link
that matches the Link Pattern then the extension will fetch the source
of the page that the link links to and match the source of that page to this regular expression.
The match will then be displayed as a preview beneath the link that is being hovered over.
Example script: Joel on Software discussion forums
@@SneakPeek
name : Joel on software discussion forums
author : Einar Egilsson
url : http://tech.einaregilsson.com
sitePattern : ^http://discuss\.joelonsoftware\.com.*
linkPattern : ^http://discuss.joelonsoftware.com/default\.asp\?\w+\.\d+\.\d+\.\d+$
peekPattern : <div class="discussBody">[^]*?</div>
The script above is for the Joel on Software discussion forums. It will be run on any page under the domain
http://discuss.joelonsoftware.com, and it will create a preview for all links that link to default.asp and have
a querystring that is a word followed by three number seperated by dots, e.g. joel.234.456.765. When those links
are hovered over the extension will fetch the source of the link target, cut from that source a <div> element
with the class discussBody and display the contents of that <div> as a preview beneath the link.
Where can I get Sneak Peek scripts?
Anyone can publish their scripts anywhere but I will try to maintain a collection of my scripts and
submissions by others at http://tech.einaregilsson.com/projects/sneak-peek/
How do I install Sneak Peek scripts?
When you open a file in the browser where the first line is @@SneakPeek then the extension will tell you
that this looks like a SneakPeek script and ask you whether you want to install the script or not.
Regular expressions tips and tricks
If you do not know regular expression I suggest you look at http://regular-expressions.info.
If you do know them, here are some useful tips when creating the site, link and peek patterns:
- I usually start the site and link patterns with ^, meaning that the match has to be made at the beginning of the url in the address bar.
- To avoid greedy matches for the peek pattern, use *? instead of just *.
- The dot (.) in JavaScript regular expressions does not match newlines and there is no DOTALL option like there is in many other languages.
The best solution I've found is to use something like [^]*? to match ANYTHING non greedily. For example <div class="post">[^]*?<div> would
match a div with the class post and continue the match until the FIRST <div> that is after the opening div.
Contact and Support
You can leave comments at http://tech.einaregilsson.com/projects/sneak-peek/
or email me at sneakpeek@einaregilsson.com