Skip to content

Instantly share code, notes, and snippets.

@vrld
Created December 26, 2010 15:53
Show Gist options
  • Save vrld/755487 to your computer and use it in GitHub Desktop.
Save vrld/755487 to your computer and use it in GitHub Desktop.
Opera Speed Dial like thing for luakit
local chrome = require "chrome"
local capi = { luakit = luakit }
local page = "chrome://favs/"
local pattern = page.."?"
local cutycapt_bin = "/home/matthias/.bin/CutyCapt"
local html_template = [====[
<html>
<head>
<title>Speed Dial</title>
<style type="text/css">
{style}
</style>
</head>
<body>
{favs}
</body>
</html>
]====]
local html_style = [====[
body {
background: #afafaf;
text-align: center;
}
a.fav {
background: #e0e0e0;
display:inline-block;
width: 280;
border: 1px solid black;
border-radius: 5px;
padding-top: 10px;
margin:8px;
text-align: center;
text-decoration: none;
font-weight: bold;
color: black;
}
a.fav:hover {
background: #ffffff;
border-width:1px;
}
a.fav img {
border: 1px solid #909090;
}
]====]
local fav_template = [====[
<a class="fav" href={url}>
<img src="{thumb}" width="240" height="180" border="0" />
{title}
</a>
]====]
local function favs()
local favs = {}
local updated = {}
-- favs file format:
-- [url] [thumbnail] [refresh-thumbnail] [title]
-- example: http://luakit.org none no Luakit Browser
local f = io.open(capi.luakit.data_dir .. "/favs")
for line in f:lines() do
local url, thumb, refresh, title = line:match("(%S+)%s+(%S+)%s+(%S+)%s+(.+)")
if thumb == "none" or refresh == "yes" then
thumb = string.format("%s/thumb-%s.png", capi.luakit.data_dir, url:gsub("%W",""))
local cmd = string.format('%s --url="%s" --out="%s" --min-width=1024 --min-height=768 && mogrify -extent 1024x768 -size 240x180 -resize 240x180 %s', cutycapt_bin, url, thumb, thumb)
capi.luakit.spawn(string.format("zsh -c '%s'", cmd))
end
updated[#updated+1] = string.format("%s %s %s %s", url, thumb, refresh, title)
local subs = {
url = url,
thumb = "file://"..thumb,
title = title,
}
favs[#favs+1] = fav_template:gsub("{(%w+)}", subs)
end
f:close()
local f = io.open(capi.luakit.data_dir .. "/favs", "w")
f:write(table.concat(updated, "\n"))
f:close()
return table.concat(favs, "\n")
end
local function html()
local subs = {
style = html_style,
favs = favs(),
}
return html_template:gsub("{(%w+)}", subs)
end
local function show(view)
-- file:// is neccessary so that webkit shows the images :/
view:load_string(html(), "file://favs")
end
chrome.add(pattern, show)
@wardhan
Copy link

wardhan commented Aug 31, 2013

i am using up to date debian sid.
copied your code & update my username in userconf.lua
i have created local share favs folder.
installed imagemagick & cutycapt.
copied cutycapt from /usr/bin/ to .bin

my issues:
if i add a website as a bookmark, will it create a thumbnail ?
is my approach is correct ?
what is the right way to view speed dial ? i have tried :Speed Dial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment