diff --git a/README.md b/README.md index ae8f8a7..b1e3b50 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ Plugins list * user agent switcher (allow Luakit to fake it's an other browser) * yank selection (simply yanks selection like yanking title or URI) -Installing -========== +Adding Plugin Functionality +=========================== * In your GitHub application or any other graphical GIT client you may use you should clone this repository into your local luakit config directory, which may be like "/home/username/.config/luakit/". By default, it will be named "luakit-plugins", so clone instead into "/home/username/.config/luakit/plugins" to let Lua find modules correctly. @@ -33,6 +33,12 @@ plugins.policy = "automatic" ``` This will enable plugins module to load everything ignoring other implicit selections; to change this behaviour, set this value to "manual". +The ```remotemanager``` branch will allow you to automatically download and update plugins from git repos by adding them to the ```repos_to_watch``` table. For example... + +```repos_to_watch = { + "https://github.com/5paceManSpiff/luakit-adblock.git", +}``` + Development guidelines ====================== diff --git a/adblock/chrome.lua b/adblock/chrome.lua deleted file mode 100644 index a75632b..0000000 --- a/adblock/chrome.lua +++ /dev/null @@ -1,204 +0,0 @@ -local adblock = require("plugins.adblock") -local lousy = lousy -local util = lousy.util -local add_binds, add_cmds = add_binds, add_cmds -local chrome = chrome -local type = type -local tostring = tostring -local tonumber = tonumber -local pairs = pairs -local ipairs = ipairs -local string = string -local table = table -local window = window - - -module("plugins.adblock.chrome") - --- Templates -header_template = [==[

AdBlock module: {state}


AdBlock is in {mode} mode.{rules}

]==] -rules_template = [==[ {black} rules blacklisting, {white} rules whitelisting, {ignored} rules ignored.]==] -block_template = [==[

{opt}

]==] -list_template_enabled = [==[
  • {title}: (b{black}/w{white}/i{ignored}), {name} {id}
  • ]==] -list_template_disabled = [==[
  • {title}: {name} {id}
  • ]==] - -html_template = [==[ - - - {title} - - - -{header} -{opts} - - -]==] - --- Template subs -html_page_title = "AdBlock filters" - -html_style = [===[ - body { - font-family: monospace; - margin: 25px; - line-height: 1.5em; - font-size: 12pt; - } - div.tag { - width: 100%; - padding: 0px; - margin: 0 0 25px 0; - clear: both; - } - span.id { - font-size: small; - color: #333333; - float: right; - } - .tag ul { - padding: 0; - margin: 0; - list-style-type: none; - } - .tag h1 { - font-size: 12pt; - font-weight: bold; - font-style: normal; - font-variant: small-caps; - padding: 0 0 5px 0; - margin: 0; - color: #CC3333; - border-bottom: 1px solid #aaa; - } - .tag a:link { - color: #0077bb; - text-decoration: none; - } - .tag a:hover { - color: #0077bb; - text-decoration: underline; - } -]===] - - --- Functions --- Refresh open filters views (if any) -function refresh_views() - for _, w in pairs(window.bywidget) do - for _, v in ipairs(w.tabs.children) do - if string.match(v.uri, "^luakit://adblock/?") then - v:reload() - end - end - end -end - --- Enable adblock to refresh this chrome view. -adblock.refresh_views = refresh_views - --- URI of the chrome page -chrome_page = "luakit://adblock/" - ---- Shows the chrome page in the given view. -chrome.add("adblock", function (view, meta) - local uri = chrome_page - -- Get a list of all the unique tags in all the lists and build a - -- relation between a given tag and a list of subscriptions with that tag. - local opts = {} - local id = 0 - for _, list in pairs(adblock.subscriptions) do - id = id + 1 - list['id'] = id - for _, opt in ipairs(list.opts) do - if not opts[opt] then opts[opt] = {} end - opts[opt][list.title] = list - end - end - - -- For each opt build a block - local lines = {} - for _, opt in ipairs(util.table.keys(opts)) do - local links = {} - for _, title in ipairs(util.table.keys(opts[opt])) do - local list = opts[opt][title] - local link_subs = { - uri = list.uri, - id = list.id, - name = util.escape(list.uri), - title = list.title, - white = list.white, - black = list.black, - ignored = list.ignored - } - local list_template = list_template_disabled - -- Show rules count only when enabled this list and have read its rules - if util.table.hasitem(list.opts, "Enabled") and list.white and list.black and list.ignored then - -- For totals count items only once (protection from multi-tagging by several opts confusion) - list_template = list_template_enabled - end - local link = string.gsub(list_template, "{(%w+)}", link_subs) - table.insert(links, link) - end - - local block_subs = { - opt = opt, - links = table.concat(links, "\n") - } - local block = string.gsub(block_template, "{(%w+)}", block_subs) - table.insert(lines, block) - end - - local rulescount = { black = 0, white = 0, ignored = 0 } - for _, list in pairs(adblock.rules) do - if list.black and list.white and list.ignored then - rulescount.black, rulescount.white, rulescount.ignored = rulescount.black + list.black, rulescount.white + list.white, rulescount.ignored + list.ignored - end - end - -- Display rules count only if have them been count - local html_rules = "" - if rulescount.black + rulescount.white + rulescount.ignored > 0 then - html_rules = string.gsub(rules_template, "{(%w+)}", rulescount) - end - -- Fill the header - local header_subs = { - state = adblock.state(), - mode = adblock.mode(), - rules = html_rules, - } - local html_page_header = string.gsub(header_template, "{(%w+)}", header_subs) - - local html_subs = { - opts = table.concat(lines, "\n\n"), - title = html_page_title, - header = html_page_header, - style = html_style, - } - - local html = string.gsub(html_template, "{(%w+)}", html_subs) - view:load_string(html, tostring(uri)) -end) - --- Add chrome binds. -local key, buf = lousy.bind.key, lousy.bind.buf -add_binds("normal", { - buf("^ga$", function (w) - w:navigate(chrome_page) - end), - - buf("^gA$", function (w, b, m) - for i=1, m.count do - w:new_tab(chrome_page) - end - end, {count=1}), -}) - --- Add chrome commands. -local cmd = lousy.bind.cmd -add_cmds({ - cmd("adblock", function (w) - w:navigate("luakit://adblock/") - end), -}) diff --git a/adblock/companions b/adblock/companions deleted file mode 100644 index bb868be..0000000 --- a/adblock/companions +++ /dev/null @@ -1 +0,0 @@ -chrome diff --git a/adblock/init.lua b/adblock/init.lua deleted file mode 100644 index f446366..0000000 --- a/adblock/init.lua +++ /dev/null @@ -1,549 +0,0 @@ ------------------------------------------------------------------------- --- Simple URI-based content filter v0.3.1a -- --- (C) 2010 Chris van Dijk (quigybo) -- --- (C) 2010 Mason Larobina (mason-l) -- --- © 2012 Plaque FCC -- --- © 2010 adblock chromepage from bookmarks.lua by Henning Hasemann & -- --- Mason Larobina taken by Plaque FCC. -- --- -- --- Download an Adblock Plus compatible filter lists to luakit data -- --- dir into "/adblock/" directory for multiple lists support or into -- --- data dir root to use single file. EasyList is the most popular -- --- Adblock Plus filter list: http://easylist.adblockplus.org/ -- --- Filterlists need to be updated regularly (~weekly), use cron! -- ------------------------------------------------------------------------- - -local info = info -local pairs = pairs -local ipairs = ipairs -local assert = assert -local unpack = unpack -local type = type -local io = io -local os = os -local string = string -local table = table -local tostring = tostring -local tonumber = tonumber -local webview = webview -local lousy = require("lousy") -local util = lousy.util -local chrome = require("chrome") -local capi = { luakit = luakit } -local add_binds, add_cmds = add_binds, add_cmds -local lfs = require("lfs") -local window = window -local plugins = plugins - -module("plugins.adblock") - ---- Module global variables -local enabled = true --- Adblock Plus compatible filter lists -local adblock_dir = capi.luakit.data_dir .. "/adblock/" - -local filterfiles = {} -local simple_mode = true -local subscriptions_file = adblock_dir .. "/subscriptions" -subscriptions = {} - - - --- String patterns to filter URI's with -rules = {} - --- Functions to filter URI's by --- Return true or false to allow or block respectively, nil to continue matching -local filterfuncs = {} - --- Fitting for adblock.chrome.refresh_views() -refresh_views = function() - -- Dummy. -end - --- Enable or disable filtering -enable = function () - enabled = true - refresh_views() -end -disable = function () - enabled = false - refresh_views() -end - --- Report AdBlock state: «Enabled» or «Disabled» -state = function() - if enabled then - return "Enabled" - else - return "Disabled" - end -end - -mode = function() - if simple_mode then - return "simple" - else - return "normal" - end -end - --- Detect files to read rules from -function detect_files() - local curdir = lfs.currentdir() - -- Try to find subscriptions directory: - if not lfs.chdir(adblock_dir) then - lfs.mkdir(adblock_dir) - else - simple_mode = false - -- Look for filters lists: - lfs.chdir(curdir) - for filename in lfs.dir(adblock_dir) do - if string.find(filename, ".txt$") then - info("adblock: Found adblock list: " .. filename) - table.insert(filterfiles, filename) - end - end - end - - if table.maxn(filterfiles) < 1 then - simple_mode = true - filterfiles = { "/easylist.txt" } - end - - if not simple_mode then - info( "adblock: Found " .. table.maxn(filterfiles) .. " rules lists.\n" ) - end - - return -end - -local function get_abp_opts(s) - local opts = {} - local pos = string.find(s, "%$") - if pos then - local op = string.sub(s, pos+1) - s = string.sub(s, 1, pos-1) - for key in string.gmatch(op, "[^,]+") do - local val - local pos = string.find(key, "=") - if pos then - val = string.sub(key, pos+1) - key = string.sub(key, 1, pos-1) - end - - local negative = false - if string.sub(key, 1, 1) == "~" then - negative = true - key = string.sub(key, 2) - end - - if key == "domain" and val then - local domains = {} - for v in string.gmatch(val, "[^|]+") do - table.insert(domains, v) - end - if #domains > 0 then opts["domain"] = domains end - elseif key == "third-party" then - opts["third-party"] = not negative - else - opts["unknown"] = true - end - end - end - return s, opts -end - --- Convert Adblock Plus filter description to lua string pattern --- See http://adblockplus.org/en/filters for more information -abp_to_pattern = function (s) - -- Strip filter options - local opts - s, opts = get_abp_opts(s) - if opts and opts.unknown == true then return nil end -- Skip rules with unknown options - - if string.len(s) > 0 then - -- Protect magic characters (^$()%.[]*+-?) not used by ABP (^$()[]*) - s = string.gsub(s, "([%%%.%+%-%?])", "%%%1") - - -- Wildcards are globbing - s = string.gsub(s, "%*", "%.%*") - - -- Caret is separator (anything but a letter, a digit, or one of the following: - . %) - s = string.gsub(s, "%^", "[^%%w%%-%%.%%%%]") - - -- Double pipe is domain anchor (beginning only) - -- Unfortunately "||example.com" will also match "wexample.com" (lua doesn't do grouping) - s = string.gsub(s, "^||", "^https?://[^/]*%%.?") - - -- Pipe is anchor - s = string.gsub(s, "^|", "%^") - s = string.gsub(s, "|$", "%$") - - -- Convert to lowercase ($match-case option is not honoured) - s = string.lower(s) - end - - return s, opts -end - -add_unique_cached = function (pattern, opts, tab, cache_tab) - if cache_tab[pattern] then - return false - else - cache_tab[pattern], tab[pattern] = true, opts - return true - end -end - --- Parses an Adblock Plus compatible filter list -parse_abpfilterlist = function (filename, cache) - if os.exists(filename) then - info("adblock: loading filterlist %s", filename) - else - info("adblock: error loading filter list (%s: No such file or directory)", filename) - end - local pat, opts - local white, black, wlen, blen, icnt = {}, {}, 0, 0, 0 - for line in io.lines(filename) do - -- Ignore comments, header and blank lines - if line:match("^[![]") or line:match("^$") then - -- dammitwhydoesntluahaveacontinuestatement - - -- Ignore element hiding - elseif line:match("#") then - - -- Check for exceptions (whitelist) - elseif line:match("^@@") then - pat, opts = abp_to_pattern(string.sub(line, 3)) - if pat and pat ~= "^http://" then - if add_unique_cached(pat, opts, white, cache.white) then - wlen = wlen + 1 - else - icnt = icnt + 1 - end - -- table.insert(white, pat) - else - icnt = icnt + 1 - end - - -- Add everything else to blacklist - else - pat, opts = abp_to_pattern(line) - if pat and pat ~= "^http:" and pat ~= ".*" then - if add_unique_cached(pat, opts, black, cache.black) then - blen = blen + 1 - else - icnt = icnt + 1 - end - -- table.insert(black, pat) - else - icnt = icnt + 1 - end - end - end - - return white, black, wlen, blen, icnt -end - --- Load filter list files -load = function (reload, single_list) - if reload then subscriptions, filterfiles = {}, {} end - detect_files() - if not simple_mode and not single_list then - read_subscriptions() - local files_list = {} - for _, filename in ipairs(filterfiles) do - local list = subscriptions[filename] - if list and util.table.hasitem(list.opts, "Enabled") then - table.insert(files_list, filename) - else - add_list("", filename, "Disabled", true, false) - end - end - filterfiles = files_list - -- Yes we may have changed subscriptions and even fixed something with them. - write_subscriptions() - end - - -- [re-]loading: - if reload then rules = {} end - local filters_dir = adblock_dir - if simple_mode then - filters_dir = capi.luakit.data_dir - end - local filterfiles_loading = {} - if single_list and not reload then - filterfiles_loading = { single_list } - else - filterfiles_loading = filterfiles - end - local rules_cache = { - black = {}, - white = {} - } -- This cache should let us avoid unnecessary filters duplication. - - for _, filename in ipairs(filterfiles_loading) do - local white, black, wlen, blen, icnt = parse_abpfilterlist(filters_dir .. filename, rules_cache) - local list = {} - if not simple_mode then - list = subscriptions[filename] - else - local list_found = rules[filename] - if list_found then - list = list_found - end - end - if not util.table.hasitem(rules, list) then - rules[filename] = list - end - list.title, list.white, list.black, list.ignored = filename, wlen or 0, blen or 0, icnt or 0 - list.whitelist, list.blacklist = white or {}, black or {} - end - - rules_cache.white, rules_cache.black = nil, nil - rules_cache = nil - refresh_views() -end - -local function domain_match(domain, opts) - local res = false - local cnt = 0 - local dlist = opts["domain"] - if dlist then - for _, s in pairs(dlist) do - if string.len(s) > 0 then - if string.sub(s, 1, 1) == "~" then - if domain == string.sub(s, 2) then return false end - else - cnt = cnt + 1 - if not res and domain == s then res = true end - end - end - end - end - return cnt == 0 or res -end - -local function third_party_match(page_domain, domain2, opts) - local thp = opts["third-party"] - if thp ~= nul then - if thp == true then return domain1 ~= domain2 end - return domain1 == domain2 - end - return true -end - -local function domain_from_uri(uri) - local domain = (uri and string.match(string.lower(uri), "^%a+://([^/]*)/?")) - -- Strip leading www. www2. etc - domain = string.match(domain or "", "^www%d?%.(.+)") or domain - return domain or "" -end - --- Tests URI against user-defined filter functions, then whitelist, then blacklist -match = function (uri, signame, page_uri) - -- Matching is not case sensitive - uri = string.lower(uri) - - signame = signame or "" - - local page_domain, uri_domain - if signame ~= "navigation-request" then - page_domain = domain_from_uri(page_uri) - uri_domain = domain_from_uri(uri) - else - page_domain = domain_from_uri(uri) - uri_domain = page_uri - end - - -- Test uri against filterfuncs - for _, func in ipairs(filterfuncs) do - local ret = func(uri) - if ret ~= nil then - info("adblock: filter function %s returned %s to uri %s", tostring(func), tostring(ret), uri) - return ret - end - end - - -- Test against each list's whitelist rules first - for _, list in pairs(rules) do - -- Check for a match to whitelist - for pattern, opts in pairs(list.whitelist or {}) do - if third_party_match(page_domain, uri_domain, opts) then - if domain_match(page_domain, opts) and string.match(uri, pattern) then - info("adblock: allowing %q as pattern %q matched to uri %s", signame, pattern, uri) - return true - end - end - end - end - - -- Test against each list's blacklist rules - for _, list in pairs(rules) do - -- Check for a match to blacklist - for pattern, opts in pairs(list.blacklist or {}) do - if third_party_match(page_domain, uri_domain, opts) then - if domain_match(page_domain, opts) and string.match(uri, pattern) then - info("adblock: blocking %q as pattern %q matched to uri %s", signame, pattern, uri) - return false - end - end - end - end -end - --- Direct requests to match function -filter = function (v, uri, signame) - if enabled then return match(uri, signame or "", v.uri) end -end - -function table.itemid(t, item) - local pos = 0 - for id, v in pairs(t) do - pos = pos + 1 - if v == item then - return pos - end - end -end - --- Connect signals to all webview widgets on creation -webview.init_funcs.adblock_signals = function (view, w) - --view:add_signal("navigation-request", function (v, uri) return filter(v, uri, "navigation-request") end) - view:add_signal("resource-request-starting", function (v, uri) return filter(v, uri, "resource-request-starting") end) -end - --- Remove options and add new ones to list --- @param list_index Index of the list to modify --- @param opt_ex Options to exclude --- @param opt_inc Options to include -function list_opts_modify(list_index, opt_ex, opt_inc) - assert( simple_mode == false, "adblock list management: not supported in simple mode" ) - assert(type(list_index) == "number", "list options modify: invalid list index") - assert(list_index > 0, "list options modify: index has to be > 0") - if not opt_ex then opt_ex = {} end - if not opt_inc then opt_inc = {} end - - if type(opt_ex) == "string" then opt_ex = util.string.split(opt_ex) end - if type(opt_inc) == "string" then opt_inc = util.string.split(opt_inc) end - - local list = util.table.values(subscriptions)[list_index] - local opts = opt_inc - for _, opt in ipairs(list.opts) do - if not util.table.hasitem(opt_ex, opt) then - table.insert(opts, opt) - end - end - - -- Manage list's rules - local listIDfound = table.itemid(rules, list) - if util.table.hasitem(opt_inc, "Enabled") then - if not listIDfound then - load(false, list.title) - end - elseif util.table.hasitem(opt_inc, "Disabled") then - rules[list.title] = nil - end - - list.opts = opts - write_subscriptions() - refresh_views() -end - ---- Add a list to the in-memory lists table -function add_list(uri, title, opts, replace, save_lists) - assert( (title ~= nil) and (title ~= ""), "adblock list add: no title given") - if not opts then opts = {} end - - -- Create tags table from string - if type(opts) == "string" then opts = util.string.split(opts) end - if table.maxn(opts) == 0 then table.insert(opts, "Disabled") end - if not replace and ( subscriptions[title] or subscriptions[uri] ) then - local list = subscriptions[title] or subscriptions[uri] - -- Merge tags - for _, opts in ipairs(opts) do - if not util.table.hasitem(list, opts) then table.insert(list, opts) end - end - else - -- Insert new adblock list - local list = { uri = uri, title = title, opts = opts } - if not (uri == "" or uri == nil) then - subscriptions[uri] = list - end - if not (title == "" or title == nil) then - subscriptions[title] = list - end - end - - -- Save by default - if save_lists ~= false then write_subscriptions() end -end - ---- Save the in-memory subscriptions to flatfile. --- @param file The destination file or the default location if nil. -function write_subscriptions(file) - if not file then file = subscriptions_file end - - local lines = {} - local added = {} - for _, list in pairs(subscriptions) do - if not util.table.hasitem(added, list) then - local subs = { uri = list.uri, title = list.title, opts = table.concat(list.opts or {}, " "), } - local line = string.gsub("{title}\t{uri}\t{opts}", "{(%w+)}", subs) - table.insert(added, list) - table.insert(lines, line) - end - end - - -- Write table to disk - local fh = io.open(file, "w") - fh:write(table.concat(lines, "\n")) - io.close(fh) -end - ---- Load subscriptions from a flatfile to memory. --- @param file The subscriptions file or the default subscriptions location if nil. --- @param clear_first Should the subscriptions in memory be dumped before loading. -function read_subscriptions(file, clear_first) - if clear_first then clear() end - - -- Find a subscriptions file - if not file then file = subscriptions_file end - if not os.exists(file) then return end - - -- Read lines into subscriptions data table - for line in io.lines(file or subscriptions_file) do - local title, uri, opts = unpack(util.string.split(line, "\t")) - if title ~= "" then add_list(uri, title, opts, false, false) end - end -end - - --- Add commands. -local cmd = lousy.bind.cmd -add_cmds({ - cmd({"adblock-reload", "abr"}, function (w) - info("adblock: Reloading filters.") - load(true) - info("adblock: Reloading filters complete.") - end), - - cmd({"adblock-list-enable", "able"}, function (w, a) - list_opts_modify(tonumber(a), "Disabled", "Enabled") - end), - - cmd({"adblock-list-disable", "abld"}, function (w, a) - list_opts_modify(tonumber(a), "Enabled", "Disabled") - end), - cmd({"adblock-enable", "abe"}, function (w) - enable() - end), - - cmd({"adblock-disable", "abd"}, function (w) - disable() - end), -}) - --- Initialise module -load() diff --git a/init.lua b/init.lua index 6462f6f..735c7c8 100644 --- a/init.lua +++ b/init.lua @@ -21,9 +21,12 @@ module("plugins") plugins_dir = capi.luakit.config_dir .. "/plugins/" rcfile = plugins_dir .. "rc.lua" +remotefile = plugins_dir .. "remote.lua" plugins_to_load = {} policy = "manual" -- To prevent automatic load on old rc.lua configs. +local remote = dofile(remotefile) + -- Get current list of usable plugins. -- Method: listing all "/(*)/init.lua" catalogues and returning -- a table of their names as we use in rc.lua for manual selection. @@ -99,6 +102,12 @@ plugins.policy = "automatic" -- Choose "manual" to enable selection below. -- everything ignoring manual selection. plugins.plugins_to_load = { {plugins} +} + +plugins.remote_policy = "automatic" -- Choose "manual" to enable manual updates. + +plugins.repos_to_watch = { + } ]=] @@ -135,6 +144,12 @@ load_plugins = function() -- Read rcfile with plugins list: local rc = dofile (rcfile) + -- Checks for remote repos to download/update + remote.manage(repos_to_watch, remote_policy, valid_plugins, plugins_dir) + + -- Updates valid_plugins after downloading/updating + valid_plugins = plugins_list (plugins_dir) + -- TODO: Refactor this ugly code into something efficient. if policy ~= nil and policy == "automatic" then plugins_to_load = {} @@ -142,7 +157,7 @@ load_plugins = function() table.insert(plugins_to_load, plugin_id) end end - + -- Import plugins: for _, plugin_id in pairs(plugins_to_load) do if valid_plugins[plugin_id] then @@ -153,7 +168,7 @@ load_plugins = function() print ("Ignore plugin '" .. plugin_id .. "'.") end end - + print ("Initializing plugins: done.") end diff --git a/oldschoolkeys/init.lua b/oldschoolkeys/init.lua deleted file mode 100644 index f6e1fa0..0000000 --- a/oldschoolkeys/init.lua +++ /dev/null @@ -1,27 +0,0 @@ ------------------------------------------------------------------------- --- Add some convenient keybindings back. -- ------------------------------------------------------------------------- - -local pairs = pairs -local lousy = require("lousy") -local key, buf, but = lousy.bind.key, lousy.bind.buf, lousy.bind.but -local add_binds, add_cmds = add_binds, add_cmds - -module("oldschoolkeys") - -local userbindings = { - -- Normal mode: - normal = { - key({}, "b", function (w, m) w:back(m.count) end, {count=1}), - key({"Mod1"}, "Page_Up", function (w, m) w.tabs:reorder(w.view, w.tabs:current() - m.count) end, {count=1}), - key({"Mod1"}, "Page_Down", function (w, m) w.tabs:reorder(w.view, (w.tabs:current() + m.count) % w.tabs:count()) end, {count=1}), - }, -} - -function load() - for modename, modebinds in pairs(userbindings) do - add_binds(modename, modebinds) - end -end - -load() diff --git a/remote.lua b/remote.lua new file mode 100644 index 0000000..31d41db --- /dev/null +++ b/remote.lua @@ -0,0 +1,75 @@ +remote = {} + +remote.manage = function(repos_to_watch, remote_policy, valid_plugins, plugins_dir) + local repos_short = remote.shrink(repos_to_watch) + + local status = remote.get_status(repos_short, valid_plugins) + + for repo, data in pairs(status) do + if data.state == "new" then + print("Downloading " .. repo) + remote.download(data.path, repo, plugins_dir) + elseif remote_policy ~= nil and remote_policy == "automatic" then + remote.update(repo, plugins_dir) + end + end +end + +remote.download = function(path, repo, plugins_dir) + local command = "git clone " .. path .. " " .. plugins_dir .. repo .. "/" + if os.execute(command) == nil then + print("Error downloading from path") + end +end + +remote.update = function(repo, plugins_dir) + print("Pulling changes from " .. repo) + local command = "cd " .. plugins_dir .. repo .. "; git pull;" + os.execute(command) +end + +remote.get_status = function(repos_short, valid_plugins) + local status = {} + for repo_short, repo in pairs(repos_short) do + local present = false + for valid in pairs(valid_plugins) do + if repo_short == valid then + present = true + end + end + + status[repo_short] = {path = repo} + + if present == true then + status[repo_short].state = "old" + else + status[repo_short].state = "new" + end + end + + return status +end + +remote.shrink = function(repos_to_watch) + local repos_short = {} + for _, repo in pairs(repos_to_watch) do + local repo_short = "" + for c in repo:gmatch(".") do + if c == "/" then + repo_short = "" + else + repo_short = repo_short .. c + end + end + + if repo_short:find(".git") ~= nil then + repo_short = repo_short:sub(0, -5) + end + + repos_short[repo_short] = repo + end + + return repos_short +end + +return remote diff --git a/tabmenu/init.lua b/tabmenu/init.lua deleted file mode 100644 index 698d643..0000000 --- a/tabmenu/init.lua +++ /dev/null @@ -1,86 +0,0 @@ ----------------------------------------------------------------- --- Switch tabs using a menu widget -- --- © 2012 Alexander Clare -- ----------------------------------------------------------------- - -local ipairs = ipairs -local table = table - -local lousy = require "lousy" -local add_binds, add_cmds = add_binds, add_cmds -local new_mode, menu_binds = new_mode, menu_binds - -module("plugins.tabmenu") - -hide_box = false - -local cmd = lousy.bind.cmd -add_cmds({ - cmd("tabmenu", function (w) w:set_mode("tabmenu") end), -}) - -local escape = lousy.util.escape -new_mode("tabmenu", { - enter = function (w) - hide_box = not w.sbar.ebox.visible - local rows = {} - for _, view in ipairs(w.tabs.children) do - table.insert(rows, {escape(view.uri), escape(view.title), v = view }) - end - w.menu:build(rows) - local cur = w.tabs:current() - local ind = 0 - repeat w.menu:move_down(); ind = ind + 1 until ind == cur - w.sbar.ebox:show() - w:notify("Use j/k to move, d close, Return switch.", false) - end, - - leave = function (w) - if hide_box == true then - w.sbar.ebox:hide() - end - w.menu:hide() - end, -}) - -local key = lousy.bind.key -add_binds("tabmenu", lousy.util.table.join({ - -- Close tab - key({}, "d", function (w) - local row = w.menu:get() - if row and row.v then - local cur = w.view - w:close_tab(w.tabs[w.tabs:indexof(row.v)]) - if cur ~= row.v then - w.menu:del() - else - w:set_mode() - end - end - end), - - -- Switch to tab - key({}, "Return", function (w) - local row = w.menu:get() - if row and row.v then - local cur = w.view - if cur ~= row.v then - w.tabs:switch((w.tabs:indexof(row.v))) - else - w:set_mode() - end - end - end), - - -- Exit menu - key({}, "`", function (w) w:set_mode() end), - -}, menu_binds)) - --- Add key binds. -local buf = lousy.bind.buf -add_binds("normal", { - key({}, "m", function (w) - w:set_mode("tabmenu") - end), -}) diff --git a/tools/adblock-update.sh b/tools/adblock-update.sh deleted file mode 100755 index 7bbff11..0000000 --- a/tools/adblock-update.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -# -# Usage: adblock-update.sh [-h] [URL] -# This script can be used to download/update filterlists for the luakit adblock-module -# It will only update the file if the server-side version is newer. -# -# URL URL of the filterlist to download, leave empty to download Easylist -# -h, --help Display this help-message and exit - -# help message -function usage () -{ -cat << EOF -Usage: $0 [-h] [URL] -This script can be used to download/update filterlists for the luakit adblock-module. -It will only update the file if the server-side version is newer. - - URL URL of the filterlist to download, leave empty to download Easylist - -h, --help Display this help message and exit -EOF -} - -# check for $XDG_DATA_HOME or fallback -[[ -z "$XDG_DATA_HOME" ]] && DATADIR="$HOME/.local/share" || DATADIR="$XDG_DATA_HOME" - - -# use URL if given else default to easylist.txt -if (( $# == 1 )) || (( $# == 0 )); then - [[ ! -z $1 ]] && [[ $1 == "-h" ]] || [[ $1 == "--help" ]] && usage && exit 0 # check for -hflag - listurl="${1:-"https://easylist-downloads.adblockplus.org/easylist.txt"}" - listname="$(basename ${listurl})" -elif (( $# > 1 ));then - usage - exit 11 -fi - -# look for adblock directory || create -[[ -d "$DATADIR/luakit/adblock/" ]] || mkdir "$DATADIR/luakit/adblock/" && cd "$DATADIR/luakit/adblock/" - -# backup the old list -[[ -f ${listname} ]] && cp -p ${listname} ${listname}.b - -# try to download the file -wget -N --connect-timeout=10 --tries=20 --retry-connrefused --waitretry=5 ${listurl} - -# if download failed move old file back in place -if (( $? != 0 )); then - [[ -f ${listname}.b ]] && cp -p ${listname}.b ${listname} && rm ${listname}.b - echo "Error: List Download Failed!" - exit 11 -else - [[ -f ${listname}.b ]] && rm ${listname}.b # if all went well remove backup - echo "All went well. :)" - exit 0 -fi diff --git a/uaswitch/init.lua b/uaswitch/init.lua deleted file mode 100644 index bab70b6..0000000 --- a/uaswitch/init.lua +++ /dev/null @@ -1,86 +0,0 @@ ------------------------------------------------------------- --- Simple User Agent string changer v0.1.0 -- --- © 2012 Plaque FCC -- ------------------------------------------------------------- - -local globals = globals -local string = string -local type = type -local dofile = dofile -local assert = assert -local error = error -local pairs = pairs -local ipairs = ipairs -local io = io -local capi = { luakit = luakit } -local lousy = require ("lousy") -local util = lousy.util -local add_binds, add_cmds = add_binds, add_cmds -local lfs = require ("lfs") -local plugins = require ("plugins") -local window = window - -module("plugins.uaswitch") - -ua_alias_default = "default" - -ua_strings_file = plugins.plugins_dir .. "uaswitch/ua_strings.lua" - -ua_strings = {} - --- Refresh open filters views (if any) -function update_views() - for _, w in pairs(window.bywidget) do - for _, v in ipairs(w.tabs.children) do - v.user_agent = globals.useragent - end - end -end - -function load_ua_strings() - ua_strings = { - original = string.rep(globals.useragent, 1), - fakes = {} - } - dofile(ua_strings_file) -end - -function switch_to(alias) - if (not alias) then - alias = ua_alias_default - end - assert(type(alias) == "string", "user agent switch: invalid user agent alias") - local useragent = nil - io.stdout:write("uaswitcher: Requested change to '" .. alias .."'.\n") - if (alias == ua_alias_default) then - useragent = ua_strings.original - else - useragent = ua_strings.fakes[alias] - end - - if (useragent) then - io.stdout:write("uaswitcher: Change to '" .. useragent .."'.\n") - globals.useragent = string.rep(useragent, 1) - update_views() - return - else - error("uaswitcher: unknown alias '" .. alias .. "'") - end -end - -function load() - load_ua_strings() - -- switch_to(ua_alias_default) - switch_to("inferfox") -- And let them choke! ;'D -end - --- Add commands. -local cmd = lousy.bind.cmd -add_cmds({ - cmd({"user-agent", "ua"}, function (w, a) - switch_to(a) - end), -}) - --- Initialise module -load() diff --git a/uaswitch/ua_strings.lua b/uaswitch/ua_strings.lua deleted file mode 100644 index ce302e4..0000000 --- a/uaswitch/ua_strings.lua +++ /dev/null @@ -1,11 +0,0 @@ -plugins.uaswitch.ua_strings.fakes = { - - ["inferfox"] = "Mozilla/6.0 (compatible; AppleWebKit/latest; like Gecko/20120405; };-> infernal_edition:goto-hell) Firefox/666", - ["firefox_15"] = "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120427 Firefox/15.0a1", - ["firefox_14"] = "Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20120405 Firefox/14.0a1", - ["firefox_13"] = "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120403211507 Firefox/12.0", - ["firefox_11"] = "Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko Firefox/11.0", - ["ie10"] = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)", - ["camino"] = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.6; en; rv:1.9.2.14pre) Gecko/20101212 Camino/2.1a1pre (like Firefox/3.6.14pre)", - ["safari"] = "Mozilla/5.0 (Macintosh; PPC Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10", -} diff --git a/yanksel/init.lua b/yanksel/init.lua deleted file mode 100644 index 40cae05..0000000 --- a/yanksel/init.lua +++ /dev/null @@ -1,22 +0,0 @@ ------------------------------------------------------------------------- --- Add yanking selection keybinding (as seen on Wiki ;). -- ------------------------------------------------------------------------- - -local error = error -local luakit = luakit -local lousy = require("lousy") -local key, buf, but = lousy.bind.key, lousy.bind.buf -local add_binds, add_cmds = add_binds, add_cmds - -module("plugins.yanksel") - -add_binds("normal", { - buf("^ys$", - function (w) - local text = luakit.selection.primary - if not text then w:error("Empty selection.") return end - luakit.selection.clipboard = text - w:notify("Yanked selection: " .. text) - luakit.selection.primary = "" - end), -})