diff --git a/CHANGELOG.md b/CHANGELOG.md index db94279..caa992a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 更新日志 +## 0.0.3 + +- 网页书源管理批量操作新增「选中全部 N 个」:按当前搜索与状态筛选跨页全选,再批量检查、启停、删除。 + ## 0.0.2 - 设备上新增「从文件导入」:浏览选择 .json / .jsonl / .txt 书源文件直接导入;导入提示里显示因需要 JS/WebView 被禁用的个数。 diff --git a/moonsource-legadorule.koplugin/moonsource_legadorule/l10n/web/en.lua b/moonsource-legadorule.koplugin/moonsource_legadorule/l10n/web/en.lua index b81fb30..3663657 100644 --- a/moonsource-legadorule.koplugin/moonsource_legadorule/l10n/web/en.lua +++ b/moonsource-legadorule.koplugin/moonsource_legadorule/l10n/web/en.lua @@ -43,6 +43,7 @@ return { ["还没有书源,点右上角「添加书源」"] = "No sources yet. Click “Add sources”.", ["显示更多(还有 %1 个)"] = "Show more (%1 left)", ["已选 %1 项"] = "%1 selected", + ["选中全部 %1 个"] = "Select all %1", ["删除书源?"] = "Delete sources?", ["将删除 %1 个书源。"] = "%1 sources will be deleted.", ["已删除"] = "Deleted", diff --git a/moonsource-legadorule.koplugin/moonsource_legadorule/l10n/web/zh_TW.lua b/moonsource-legadorule.koplugin/moonsource_legadorule/l10n/web/zh_TW.lua index 234522f..db7cc4e 100644 --- a/moonsource-legadorule.koplugin/moonsource_legadorule/l10n/web/zh_TW.lua +++ b/moonsource-legadorule.koplugin/moonsource_legadorule/l10n/web/zh_TW.lua @@ -43,6 +43,7 @@ return { ["还没有书源,点右上角「添加书源」"] = "還沒有書源,点右上角「添加書源」", ["显示更多(还有 %1 个)"] = "顯示更多(還有 %1 個)", ["已选 %1 项"] = "已選 %1 項", + ["选中全部 %1 个"] = "選中全部 %1 個", ["删除书源?"] = "刪除書源?", ["将删除 %1 个书源。"] = "將刪除 %1 個書源。", ["已删除"] = "已刪除", diff --git a/moonsource-legadorule.koplugin/moonsource_legadorule/remote.lua b/moonsource-legadorule.koplugin/moonsource_legadorule/remote.lua index 5755c75..58f2b53 100644 --- a/moonsource-legadorule.koplugin/moonsource_legadorule/remote.lua +++ b/moonsource-legadorule.koplugin/moonsource_legadorule/remote.lua @@ -29,11 +29,14 @@ local function summary(s) reason = s.reason, ms = s.ms, checked = s.checked } end +local function statusOf(params) + return params.status == "on" and "on" or params.status == "off" and "off" or nil +end + local function listing(params) local page = math.max(1, math.floor(tonumber(params.page) or 1)) local size = math.min(200, math.max(1, math.floor(tonumber(params.size) or 50))) - local status = params.status == "on" and "on" or params.status == "off" and "off" or nil - local list, total = Sources.page(params.q and tostring(params.q) or nil, status, page, size) + local list, total = Sources.page(params.q and tostring(params.q) or nil, statusOf(params), page, size) local sources = {} for _idx, s in ipairs(list) do sources[#sources + 1] = summary(s) end return { sources = sources, total = total, counts = Sources.counts() } @@ -161,6 +164,8 @@ function Remote.handle(method, action, params, cb) require("utils.awake").poke() if method == "GET" and action == "list" then cb(200, listing(params)) + elseif method == "GET" and action == "keys" then + cb(200, { keys = Sources.keys(params.q and tostring(params.q) or nil, statusOf(params)) }) elseif method == "POST" and action == "import" then -- 原始文件体落在临时文件里(路径在 params.temp);粘贴的文本由网页同样当文件体发来 local path = params.temp diff --git a/moonsource-legadorule.koplugin/moonsource_legadorule/sources.lua b/moonsource-legadorule.koplugin/moonsource_legadorule/sources.lua index a7d6044..d7cc393 100644 --- a/moonsource-legadorule.koplugin/moonsource_legadorule/sources.lua +++ b/moonsource-legadorule.koplugin/moonsource_legadorule/sources.lua @@ -109,14 +109,11 @@ function Sources.all() return entries(" ORDER BY seq ASC") end ---- 分页查询:q 匹配名称或地址(不分大小写),status 为 "on" / "off" / nil。返回当页书源与符合条件的总数。 ---@param q string|nil ---@param status string|nil ----@param page integer 从 1 起 ----@param size integer ----@return table[] list ----@return integer total -function Sources.page(q, status, page, size) +---@return string cond +---@return table args +local function filter(q, status) local where, args = {}, {} if q and q ~= "" then local like = "%" .. q:gsub("[\\%%_]", "\\%0") .. "%" @@ -126,13 +123,36 @@ function Sources.page(q, status, page, size) end if status == "on" then where[#where + 1] = "enabled=1" elseif status == "off" then where[#where + 1] = "enabled=0" end - local cond = #where > 0 and (" WHERE " .. table.concat(where, " AND ")) or "" + return #where > 0 and (" WHERE " .. table.concat(where, " AND ")) or "", args +end + +--- 分页查询:q 匹配名称或地址(不分大小写),status 为 "on" / "off" / nil。返回当页书源与符合条件的总数。 +---@param q string|nil +---@param status string|nil +---@param page integer 从 1 起 +---@param size integer +---@return table[] list +---@return integer total +function Sources.page(q, status, page, size) + local cond, args = filter(q, status) local total = tonumber(DB.rowexec("SELECT COUNT(*) FROM legadorule_sources" .. cond .. ";", unpack(args))) or 0 args[#args + 1] = size args[#args + 1] = (page - 1) * size return entries(cond .. " ORDER BY seq ASC LIMIT ? OFFSET ?", unpack(args)), total end +--- 符合条件的全部书源 key(跨页全选)。 +---@param q string|nil +---@param status string|nil +---@return string[] +function Sources.keys(q, status) + local cond, args = filter(q, status) + local result, n = DB.query("SELECT key FROM legadorule_sources" .. cond .. " ORDER BY seq ASC;", unpack(args)) + local out = {} + for i = 1, n or 0 do out[i] = result[1][i] end + return out +end + ---@return { all: integer, on: integer, off: integer } function Sources.counts() local all = tonumber(DB.rowexec("SELECT COUNT(*) FROM legadorule_sources;")) or 0 diff --git a/moonsource-legadorule.koplugin/moonsource_legadorule/web/legado_sources.html b/moonsource-legadorule.koplugin/moonsource_legadorule/web/legado_sources.html index c7492bc..f49c0d4 100644 --- a/moonsource-legadorule.koplugin/moonsource_legadorule/web/legado_sources.html +++ b/moonsource-legadorule.koplugin/moonsource_legadorule/web/legado_sources.html @@ -33,6 +33,7 @@