--- userconf.lua

local downloads = require "downloads"
downloads.default_dir = os.getenv("HOME") .. "/tmp"
downloads.add_signal("download-location", function (uri, file)
    if not file or file == "" then
        file = (string.match(uri, "/([^/]+)$")
            or string.match(uri, "^%w+://(.+)")
            or string.gsub(uri, "/", "_")
            or "untitled")
    end
    return downloads.default_dir .. "/" .. file
end)


local settings = require "settings"
settings.window.scroll_step             = 40
settings.window.zoom_step               = 0.1
settings.window.search_engines.searx = "https://search.unbl.ink/search?q=%s"
settings.window.default_search_engine = "searx"

settings.webview.enable_smooth_scrolling = true
settings.webview.zoom_level  = 110
settings.webview.enable_webgl = true

local follow = require "follow"
follow.fontsize = "16px monospace"
follow.stylesheet = [===[
#luakit_select_overlay .hint_label {
    display:block;
    position:absolute;
    font-size: 14px;
    padding:3px;
    color:black;
    margin-top:10px;
    background-color:yellow;
    opacity:0.7;
}
]===]

local select = require "select"

select.label_maker = function ()
    local chars = charset("abcefghjklnoprstuvw")
    return trim(sort(reverse(chars)))
end

local modes = require "modes"

modes.add_binds("normal", {{
    "c",
    "Copy selected text.",
    function ()
        luakit.selection.clipboard = luakit.selection.primary
    end
}})

--- local unique_instance = require "unique_instance"
--- unique_instance.open_links_in_new_window = true


--local history require "history"

--history.db_path = "~/var/luakit-history.sqlite"

local add_cmds = modes.add_cmds
local actions = {
        adblock_update = {
                desc = "Update adblock from easylist official site",
                func = function (w)
                        local url = "https://easylist-downloads.adblockplus.org/easylist.txt"
                        local dir = os.getenv("HOME") .. "/.local/share/luakit/adblock"
                        downloads.add (url)
                        os.rename(downloads.default_dir .. "/easylist.txt", dir .. "/easylist.txt")
                end,
        }
}

add_cmds({{":adblock-update", actions.adblock_update },})
