v1.0.6: 导入网址文件增加追加/覆盖处理方式选择(默认追加)
This commit is contained in:
+11
-4
@@ -174,10 +174,12 @@ async function readFileSmart(file) {
|
||||
return text;
|
||||
}
|
||||
|
||||
function importUrlsText(text) {
|
||||
function importUrlsText(text, mode) {
|
||||
const ta = $("taskForm").elements["urls"];
|
||||
const clean = (s) => s.split(" #")[0].trim(); // 去掉行内注释 (URL 不含空格, 安全)
|
||||
const existing = new Set(ta.value.split(/\r?\n/).map(clean).filter(Boolean));
|
||||
const existing = new Set(
|
||||
mode === "overwrite" ? [] : ta.value.split(/\r?\n/).map(clean).filter(Boolean)
|
||||
);
|
||||
const fresh = text.split(/\r?\n/).map(clean).filter(Boolean);
|
||||
let added = 0;
|
||||
for (const line of fresh) {
|
||||
@@ -198,9 +200,14 @@ $("urlFileInput").onchange = async (e) => {
|
||||
}
|
||||
try {
|
||||
const text = await readFileSmart(file);
|
||||
const r = importUrlsText(text);
|
||||
const mode = $("importMode").value;
|
||||
const r = importUrlsText(text, mode);
|
||||
formDirty = true;
|
||||
toast(`已导入 ${file.name}:共 ${r.total} 行,新增 ${r.added} 条网址`);
|
||||
if (mode === "overwrite") {
|
||||
toast(`已导入 ${file.name}:共 ${r.total} 行(覆盖原列表,新增 ${r.added} 条)`);
|
||||
} else {
|
||||
toast(`已导入 ${file.name}:共 ${r.total} 行,新增 ${r.added} 条网址(追加)`);
|
||||
}
|
||||
} catch (err) {
|
||||
toast("文件读取失败: " + err.message, true);
|
||||
}
|
||||
|
||||
+5
-1
@@ -77,7 +77,11 @@
|
||||
<label>网址列表(每行一个,# 开头为注释)</label>
|
||||
<div class="row2" style="align-items:center">
|
||||
<button type="button" class="btn sm" id="btnImportUrls">📂 导入网址文件(.txt)</button>
|
||||
<span class="card-line">支持 UTF-8 / GBK 编码,自动去重追加</span>
|
||||
<select id="importMode" title="对已有网址的处理方式">
|
||||
<option value="append" selected>追加(保留已有)</option>
|
||||
<option value="overwrite">覆盖(清空已有)</option>
|
||||
</select>
|
||||
<span class="card-line">支持 UTF-8 / GBK,自动去重</span>
|
||||
<input type="file" id="urlFileInput" accept=".txt,.csv,.urls,text/plain" hidden>
|
||||
</div>
|
||||
<textarea name="urls" rows="5" placeholder="https://www.example.com/ https://www.example.com/page2"></textarea>
|
||||
|
||||
Reference in New Issue
Block a user