mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-05-21 18:12:33 +02:00
+stylua
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
+68
-50
@@ -1,6 +1,6 @@
|
||||
Plugin = {
|
||||
name = "Scopes",
|
||||
description = [[
|
||||
name = "Scopes",
|
||||
description = [[
|
||||
Auto-forward requests and exclude them from history based on patterns.
|
||||
|
||||
**Config** (YAML):
|
||||
@@ -34,70 +34,88 @@ patterns:
|
||||
- "h:^$"
|
||||
```
|
||||
]],
|
||||
priority = 100,
|
||||
on_request = { sync = true },
|
||||
on_response = { sync = true },
|
||||
on_history_entry = { sync = true },
|
||||
priority = 100,
|
||||
on_request = { sync = true },
|
||||
on_response = { sync = true },
|
||||
on_history_entry = { sync = true },
|
||||
}
|
||||
|
||||
local blacklist = {}
|
||||
local whitelist = {}
|
||||
local blacklist_req = {}
|
||||
local whitelist_req = {}
|
||||
local blacklist = {}
|
||||
local whitelist = {}
|
||||
local blacklist_req = {}
|
||||
local whitelist_req = {}
|
||||
local blacklist_hist = {}
|
||||
local whitelist_hist = {}
|
||||
|
||||
function on_config()
|
||||
blacklist, whitelist = {}, {}
|
||||
blacklist_req, whitelist_req = {}, {}
|
||||
blacklist_hist, whitelist_hist = {}, {}
|
||||
local cfg = get_config()
|
||||
if not cfg or not cfg.patterns then return end
|
||||
for _, line in ipairs(cfg.patterns) do
|
||||
local trimmed = line:match("^%s*(.-)%s*$")
|
||||
if trimmed ~= "" and trimmed:sub(1, 1) ~= "#" then
|
||||
local scope = trimmed:match("^([rh]):")
|
||||
local rest = scope and trimmed:sub(3) or trimmed
|
||||
local is_bl = rest:sub(1, 1) == "!"
|
||||
local pattern = is_bl and rest:sub(2) or rest
|
||||
if scope == "r" then
|
||||
table.insert(is_bl and blacklist_req or whitelist_req, pattern)
|
||||
elseif scope == "h" then
|
||||
table.insert(is_bl and blacklist_hist or whitelist_hist, pattern)
|
||||
else
|
||||
table.insert(is_bl and blacklist or whitelist, pattern)
|
||||
end
|
||||
end
|
||||
end
|
||||
blacklist, whitelist = {}, {}
|
||||
blacklist_req, whitelist_req = {}, {}
|
||||
blacklist_hist, whitelist_hist = {}, {}
|
||||
local cfg = get_config()
|
||||
if not cfg or not cfg.patterns then
|
||||
return
|
||||
end
|
||||
for _, line in ipairs(cfg.patterns) do
|
||||
local trimmed = line:match("^%s*(.-)%s*$")
|
||||
if trimmed ~= "" and trimmed:sub(1, 1) ~= "#" then
|
||||
local scope = trimmed:match("^([rh]):")
|
||||
local rest = scope and trimmed:sub(3) or trimmed
|
||||
local is_bl = rest:sub(1, 1) == "!"
|
||||
local pattern = is_bl and rest:sub(2) or rest
|
||||
if scope == "r" then
|
||||
table.insert(is_bl and blacklist_req or whitelist_req, pattern)
|
||||
elseif scope == "h" then
|
||||
table.insert(is_bl and blacklist_hist or whitelist_hist, pattern)
|
||||
else
|
||||
table.insert(is_bl and blacklist or whitelist, pattern)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function check_skip(url, bl_extra, wl_extra)
|
||||
for _, p in ipairs(blacklist) do
|
||||
if url:match(p) then return true end
|
||||
end
|
||||
for _, p in ipairs(bl_extra) do
|
||||
if url:match(p) then return true end
|
||||
end
|
||||
local wl = {}
|
||||
for _, p in ipairs(whitelist) do wl[#wl + 1] = p end
|
||||
for _, p in ipairs(wl_extra) do wl[#wl + 1] = p end
|
||||
if #wl > 0 then
|
||||
for _, p in ipairs(wl) do
|
||||
if url:match(p) then return false end
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
for _, p in ipairs(blacklist) do
|
||||
if url:match(p) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
for _, p in ipairs(bl_extra) do
|
||||
if url:match(p) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
local wl = {}
|
||||
for _, p in ipairs(whitelist) do
|
||||
wl[#wl + 1] = p
|
||||
end
|
||||
for _, p in ipairs(wl_extra) do
|
||||
wl[#wl + 1] = p
|
||||
end
|
||||
if #wl > 0 then
|
||||
for _, p in ipairs(wl) do
|
||||
if url:match(p) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function on_request(req)
|
||||
if check_skip(req.url, blacklist_req, whitelist_req) then return "forward" end
|
||||
if check_skip(req.url, blacklist_req, whitelist_req) then
|
||||
return "forward"
|
||||
end
|
||||
end
|
||||
|
||||
function on_response(req)
|
||||
if check_skip(req.url, blacklist_req, whitelist_req) then return "forward" end
|
||||
if check_skip(req.url, blacklist_req, whitelist_req) then
|
||||
return "forward"
|
||||
end
|
||||
end
|
||||
|
||||
function on_history_entry(entry)
|
||||
if check_skip(entry.host .. entry.path, blacklist_hist, whitelist_hist) then return "skip" end
|
||||
if check_skip(entry.host .. entry.path, blacklist_hist, whitelist_hist) then
|
||||
return "skip"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user