⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hooks.lua.in

📁 一个很有名的浏览器
💻 IN
📖 第 1 页 / 共 2 页
字号:
	return url    endend------------------------------------------------------------------------  pre_format_html_hook------------------------------------------------------------------------ Plain strfind (no metacharacters).function sstrfind (s, pattern)    return strfind (s, pattern, 1, 1)endfunction highlight (url, html)  local ret=nil-- highlight patches  if strfind (url, "%.patch$") then	local tmp = tmpname ()	writeto (tmp) write (html) writeto()	html = pipe_read ("(code2html -l patch "..tmp.." - ) 2>/dev/null")	remove(tmp)	ret = 1  end-- Python  if strfind (url, "%.py$") then	local tmp = tmpname ()	writeto (tmp) write (html) writeto()	html = pipe_read ("(code2html -l python "..tmp.." - ) 2>/dev/null")	remove(tmp)	ret = 1  end-- Perl  if strfind (url, "%.pl$") then	local tmp = tmpname ()	writeto (tmp) write (html) writeto()	html = pipe_read ("(code2html -l perl "..tmp.." - ) 2>/dev/null")	remove(tmp)	ret = 1  end-- awk  if strfind (url, "%.awk$") then	local tmp = tmpname ()	writeto (tmp) write (html) writeto()	html = pipe_read ("(code2html -l awk "..tmp.." - ) 2>/dev/null")	remove(tmp)	ret = 1  end-- hightlight C code    if strfind (url, "%.[ch]$") then        local tmp = tmpname ()        writeto (tmp) write (html) writeto ()        html = pipe_read ("(code2html -l c "..tmp.." - ) 2>/dev/null")        remove (tmp)        ret = 1    end-- shell    if strfind (url, "%.sh$") then        local tmp = tmpname ()        writeto (tmp) write (html) writeto ()        html = pipe_read ("(code2html -l sh "..tmp.." - ) 2>/dev/null")        remove (tmp)        ret = 1    end    return ret, htmlendfunction pre_format_html_hook (url, html)    local ret = nil    -- Handle gzip'd files within reasonable size.    -- Note that this is not needed anymore since we have a support for this    -- in core ELinks. I still keep it here for a reference (as an example),    -- though. If you will add something similiar using pipe_read(), feel free    -- to remove this. --pasky--    if strfind (url, "%.gz$") and strlen (html) < 65536 then--        local tmp = tmpname ()--        writeto (tmp) write (html) writeto ()--        html = pipe_read ("(gzip -dc "..tmp.." || cat "..tmp..") 2>/dev/null")--        remove (tmp)--        ret = 1--    end    -- Highlight the source code    if highlight_enable then        ret, html = highlight(url, html)    end    -- Mangle ALT="" in IMG tags.    if mangle_blank_alt then	local n	html, n = gisub (html, '(<img.-) alt=""', '%1 alt="&nbsp;"')	ret = ret or (n > 0)    end    -- Fix unclosed INPUT tags.    if 1 then        local n	html, n = gisub (html, '(<input[^>]-[^=]")<', '%1><')	ret = ret or (n > 0)    end    -- Fix unclosed A tags.    if 1 then        local n	html, n = gisub (html, '(<a[^>]-[^=]")<', '%1><')	ret = ret or (n > 0)    end    -- These quick 'n dirty patterns don't maintain proper HTML.    -- linuxtoday.com    if sstrfind (url, "linuxtoday.com") then        if sstrfind (url, "news_story") then            html = gsub (html, '<TABLE CELLSPACING="0".-</TABLE>', '', 1)            html = gsub (html, '<TR BGCOLOR="#FFF.-</TR></TABLE>', '', 1)        else            html = gsub (html, 'WIDTH="120">\n<TR.+</TABLE></TD>', '>', 1)        end        html = gsub (html, '<A HREF="http://www.internet.com.-</A>', '')        html = gsub (html, "<IFRAME.-</IFRAME>", "")        -- emphasis in text is lost        return gsub (html, 'text="#002244"', 'text="#001133"', 1)    -- dictionary.com    elseif sstrfind (url, "dictionary.com/cgi-bin/dict.pl") then	local t = { t = "" }	local _, n = gsub (html, "resultItemStart %-%-%>(.-)%<%!%-%- resultItemEnd",			   function (x) %t.t = %t.t.."<tr><td>"..x.."</td></tr>" end)	if n == 0 then	    -- we've already mangled this page before	    return html	else	    return "<html><head><title>Dictionary.com lookup</title></head>"..		    "<body><table border=0 cellpadding=5>"..t.t.."</table>"..		    "</body></html>"	end    elseif sstrfind (url, "allmusic.com") then        return gsub(html, "javascript:z%('(.-)'%)", "/cg/amg.dll?p=amg&sql=%1")    end    return ret and htmlend------------------------------------------------------------------------  Miscellaneous functions, accessed with the Lua Console.------------------------------------------------------------------------ Reload this file (hooks.lua) from within Links.function reload ()    dofile (hooks_file)end-- Helper function.function catto (output)    local doc = current_document_formatted (79)    if doc then writeto (output) write (doc) writeto () endend-- Email the current document, using Mutt (http://www.mutt.org).-- This only works when called from lua_console_hook, below.function mutt ()    local tmp = tmpname ()    writeto (tmp) write (current_document ()) writeto ()    tinsert (tmp_files, tmp)    return "run", "mutt -a "..tmpend-- Table of expressions which are recognised by our lua_console_hook.console_hook_functions = {    reload	= "reload ()",    mutt	= mutt,}function lua_console_hook (expr)    local x = console_hook_functions[expr]    if type (x) == "function" then	return x ()    else	return "eval", x or expr    endend------------------------------------------------------------------------  quit_hook------------------------------------------------------------------------ We need to delete the temporary files that we create.if not tmp_files then    tmp_files = {}endfunction quit_hook ()    if bookmark_addon then	bm_save_bookmarks ()    end    if tmp_files and remove then        tmp_files.n = nil        for i,v in tmp_files do remove (v) end    endend------------------------------------------------------------------------  Examples of keybinding------------------------------------------------------------------------ Bind Ctrl-H to a "Home" page.--    bind_key ("main", "Ctrl-H",--	      function () return "goto_url", "http://www.google.com/" end)-- Bind Alt-p to print.--    bind_key ("main", "Alt-p", lpr)-- Bind Alt-m to toggle ALT="" mangling.    bind_key ("main", "Alt-m",	      function () mangle_blank_alt = not mangle_blank_alt end)------------------------------------------------------------------------  Bookmark addon----------------------------------------------------------------------if bookmark_addon then    dofile (elinks_home.."/bm.lua")    -- Add/change any bookmark options here.    -- Be careful not to load bookmarks if this script is being    -- reloaded while in ELinks, or we will lose unsaved changes.    if not bm_bookmarks or getn (bm_bookmarks) == 0 then	bm_load_bookmarks ()    end    -- My bookmark key bindings.--    bind_key ('main', 'a', bm_add_bookmark)--    bind_key ('main', 's', bm_view_bookmarks)--    bind_key ('main', 'Alt-e', bm_edit_bookmark)--    bind_key ('main', 'Alt-d', bm_delete_bookmark)--    bind_key ('main', 'Alt-k', bm_move_bookmark_up)--    bind_key ('main', 'Alt-j', bm_move_bookmark_down)end-- vim: shiftwidth=4 softtabstop=4

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -