randomfox (randomfox) wrote,
randomfox
randomfox

K-Meleon Lua macros for Up Directory and Top Level

In toolbars.cfg:
GO{
.
.
.
	Up {
	luamacros(UpDir)|up
	Up.
	toolhot.bmp[16]
	toolcold.bmp[16]
	}
}
In menus.cfg:
up{
luamacros(UpDir, Go Up Directory)
luamacros(TopDir, Go to Top Level of site)
}
Lua code:
-- Lua macros for Up Directory

local function ParseURL()
    local _, url = GetDocInfo()

    local _, _, host, path = string.find(url, "^(%a+://[^/]+)(.*)$")
    if host then
	return host, path
    end
end

local function iterslash(s, i)
    local _, fend = string.find(s, "/", i + 1, true)
    if fend then
	return fend
    end
end

function UpDir()
    local host, path = ParseURL()
    if host == nil then
	return
    end

    local lastslash = 0
    for i in iterslash, string.gsub(path, "/%s*$", ""), 0 do
	lastslash = i
    end

    NavigateTo(host .. 
	(lastslash > 0 and string.sub(path, 1, lastslash) or "/"), OPEN)
end

function TopDir()
    local host, _ = ParseURL()
    if host then
	NavigateTo(host .. "/", OPEN)
    end
end


Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments