Upload 2 files
Browse files- static/app.js +22 -0
- static/index.html +7 -0
static/app.js
CHANGED
|
@@ -15,6 +15,7 @@ const STATE = {
|
|
| 15 |
maxSize: null,
|
| 16 |
exact: false,
|
| 17 |
fulltext: false,
|
|
|
|
| 18 |
fulltextManifest: null,
|
| 19 |
fulltextLoaded: {},
|
| 20 |
historyEnabled: true,
|
|
@@ -163,6 +164,7 @@ function cacheDom() {
|
|
| 163 |
DOM.previewPanel = $("#preview-panel");
|
| 164 |
DOM.closeFiltersBtn = $("#close-filters-btn");
|
| 165 |
DOM.fulltextToggle = $("#fulltext-toggle");
|
|
|
|
| 166 |
DOM.historyToggle = $("#history-toggle");
|
| 167 |
DOM.exactToggle = $("#exact-search-toggle");
|
| 168 |
DOM.filterSourceList = $("#filter-source-list");
|
|
@@ -350,6 +352,7 @@ function syncUrl(replace = true) {
|
|
| 350 |
if (DOM.sortSelect.value !== "relevance") params.set("sort", DOM.sortSelect.value);
|
| 351 |
if (STATE.exact) params.set("exact", "1");
|
| 352 |
if (STATE.fulltext) params.set("fulltext", "1");
|
|
|
|
| 353 |
if (!STATE.historyEnabled) params.set("history", "0");
|
| 354 |
const basePath = STATE.source ? `/${encodeURIComponent(STATE.source)}` : "/";
|
| 355 |
const nextUrl = params.toString() ? `${basePath}?${params.toString()}` : basePath;
|
|
@@ -366,11 +369,13 @@ function loadUrlState() {
|
|
| 366 |
STATE.maxSize = params.get("max_size") ? parseInt(params.get("max_size"), 10) : null;
|
| 367 |
STATE.exact = params.get("exact") === "1";
|
| 368 |
STATE.fulltext = params.get("fulltext") === "1";
|
|
|
|
| 369 |
STATE.historyEnabled = params.get("history") !== "0";
|
| 370 |
const sort = params.get("sort") || "relevance";
|
| 371 |
DOM.searchInput.value = STATE.query;
|
| 372 |
DOM.exactToggle.checked = STATE.exact;
|
| 373 |
DOM.fulltextToggle.checked = STATE.fulltext;
|
|
|
|
| 374 |
DOM.historyToggle.checked = STATE.historyEnabled;
|
| 375 |
DOM.sortSelect.value = sort;
|
| 376 |
if (STATE.minSize !== null) DOM.filterMinSize.value = STATE.minSize;
|
|
@@ -479,6 +484,7 @@ async function pathSearch() {
|
|
| 479 |
page_size: STATE.page * STATE.pageSize,
|
| 480 |
sort: DOM.sortSelect.value,
|
| 481 |
exact: STATE.exact,
|
|
|
|
| 482 |
};
|
| 483 |
const data = await API.search(body, STATE.source);
|
| 484 |
STATE.total = data.total || 0;
|
|
@@ -831,12 +837,23 @@ function attachEvents() {
|
|
| 831 |
});
|
| 832 |
DOM.fulltextToggle.addEventListener("change", async () => {
|
| 833 |
STATE.fulltext = DOM.fulltextToggle.checked;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 834 |
DOM.searchInput.placeholder = STATE.fulltext ? "全文搜索 TXT 正文..." : "搜索 TXT 文件或路径...";
|
| 835 |
STATE.page = 1;
|
| 836 |
if (STATE.fulltext) await ensureFulltextLoaded();
|
| 837 |
syncUrl();
|
| 838 |
doSearch();
|
| 839 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 840 |
DOM.clearFiltersBtn.addEventListener("click", clearFilters);
|
| 841 |
DOM.emptyRandomBtn.addEventListener("click", randomDoc);
|
| 842 |
if (DOM.randomBookBtn) DOM.randomBookBtn.addEventListener("click", randomDoc);
|
|
@@ -1021,6 +1038,11 @@ async function init() {
|
|
| 1021 |
await renderFolderTree();
|
| 1022 |
updateFilterVisibility();
|
| 1023 |
attachEvents();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1024 |
updateSidebarVisibility();
|
| 1025 |
syncUrl();
|
| 1026 |
doSearch();
|
|
|
|
| 15 |
maxSize: null,
|
| 16 |
exact: false,
|
| 17 |
fulltext: false,
|
| 18 |
+
searchPaths: true,
|
| 19 |
fulltextManifest: null,
|
| 20 |
fulltextLoaded: {},
|
| 21 |
historyEnabled: true,
|
|
|
|
| 164 |
DOM.previewPanel = $("#preview-panel");
|
| 165 |
DOM.closeFiltersBtn = $("#close-filters-btn");
|
| 166 |
DOM.fulltextToggle = $("#fulltext-toggle");
|
| 167 |
+
DOM.searchPathsToggle = $("#search-paths-toggle");
|
| 168 |
DOM.historyToggle = $("#history-toggle");
|
| 169 |
DOM.exactToggle = $("#exact-search-toggle");
|
| 170 |
DOM.filterSourceList = $("#filter-source-list");
|
|
|
|
| 352 |
if (DOM.sortSelect.value !== "relevance") params.set("sort", DOM.sortSelect.value);
|
| 353 |
if (STATE.exact) params.set("exact", "1");
|
| 354 |
if (STATE.fulltext) params.set("fulltext", "1");
|
| 355 |
+
if (!STATE.searchPaths) params.set("search_paths", "0");
|
| 356 |
if (!STATE.historyEnabled) params.set("history", "0");
|
| 357 |
const basePath = STATE.source ? `/${encodeURIComponent(STATE.source)}` : "/";
|
| 358 |
const nextUrl = params.toString() ? `${basePath}?${params.toString()}` : basePath;
|
|
|
|
| 369 |
STATE.maxSize = params.get("max_size") ? parseInt(params.get("max_size"), 10) : null;
|
| 370 |
STATE.exact = params.get("exact") === "1";
|
| 371 |
STATE.fulltext = params.get("fulltext") === "1";
|
| 372 |
+
STATE.searchPaths = params.get("search_paths") !== "0";
|
| 373 |
STATE.historyEnabled = params.get("history") !== "0";
|
| 374 |
const sort = params.get("sort") || "relevance";
|
| 375 |
DOM.searchInput.value = STATE.query;
|
| 376 |
DOM.exactToggle.checked = STATE.exact;
|
| 377 |
DOM.fulltextToggle.checked = STATE.fulltext;
|
| 378 |
+
DOM.searchPathsToggle.checked = STATE.searchPaths;
|
| 379 |
DOM.historyToggle.checked = STATE.historyEnabled;
|
| 380 |
DOM.sortSelect.value = sort;
|
| 381 |
if (STATE.minSize !== null) DOM.filterMinSize.value = STATE.minSize;
|
|
|
|
| 484 |
page_size: STATE.page * STATE.pageSize,
|
| 485 |
sort: DOM.sortSelect.value,
|
| 486 |
exact: STATE.exact,
|
| 487 |
+
search_paths: STATE.searchPaths,
|
| 488 |
};
|
| 489 |
const data = await API.search(body, STATE.source);
|
| 490 |
STATE.total = data.total || 0;
|
|
|
|
| 837 |
});
|
| 838 |
DOM.fulltextToggle.addEventListener("change", async () => {
|
| 839 |
STATE.fulltext = DOM.fulltextToggle.checked;
|
| 840 |
+
if (DOM.searchPathsToggle) {
|
| 841 |
+
DOM.searchPathsToggle.disabled = STATE.fulltext;
|
| 842 |
+
if (STATE.fulltext) DOM.searchPathsToggle.closest(".toggle-row").style.opacity = "0.5";
|
| 843 |
+
else DOM.searchPathsToggle.closest(".toggle-row").style.opacity = "";
|
| 844 |
+
}
|
| 845 |
DOM.searchInput.placeholder = STATE.fulltext ? "全文搜索 TXT 正文..." : "搜索 TXT 文件或路径...";
|
| 846 |
STATE.page = 1;
|
| 847 |
if (STATE.fulltext) await ensureFulltextLoaded();
|
| 848 |
syncUrl();
|
| 849 |
doSearch();
|
| 850 |
});
|
| 851 |
+
DOM.searchPathsToggle.addEventListener("change", () => {
|
| 852 |
+
STATE.searchPaths = DOM.searchPathsToggle.checked;
|
| 853 |
+
STATE.page = 1;
|
| 854 |
+
syncUrl();
|
| 855 |
+
doSearch();
|
| 856 |
+
});
|
| 857 |
DOM.clearFiltersBtn.addEventListener("click", clearFilters);
|
| 858 |
DOM.emptyRandomBtn.addEventListener("click", randomDoc);
|
| 859 |
if (DOM.randomBookBtn) DOM.randomBookBtn.addEventListener("click", randomDoc);
|
|
|
|
| 1038 |
await renderFolderTree();
|
| 1039 |
updateFilterVisibility();
|
| 1040 |
attachEvents();
|
| 1041 |
+
if (DOM.searchPathsToggle) {
|
| 1042 |
+
DOM.searchPathsToggle.checked = STATE.searchPaths;
|
| 1043 |
+
DOM.searchPathsToggle.disabled = STATE.fulltext;
|
| 1044 |
+
DOM.searchPathsToggle.closest(".toggle-row").style.opacity = STATE.fulltext ? "0.5" : "";
|
| 1045 |
+
}
|
| 1046 |
updateSidebarVisibility();
|
| 1047 |
syncUrl();
|
| 1048 |
doSearch();
|
static/index.html
CHANGED
|
@@ -92,6 +92,13 @@
|
|
| 92 |
<span class="toggle-switch"></span>
|
| 93 |
</label>
|
| 94 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
<div class="filter-section">
|
| 96 |
<label class="toggle-row">
|
| 97 |
<span class="toggle-label">记录搜索历史</span>
|
|
|
|
| 92 |
<span class="toggle-switch"></span>
|
| 93 |
</label>
|
| 94 |
</div>
|
| 95 |
+
<div class="filter-section">
|
| 96 |
+
<label class="toggle-row">
|
| 97 |
+
<span class="toggle-label">搜索文件夹名</span>
|
| 98 |
+
<input type="checkbox" id="search-paths-toggle" checked>
|
| 99 |
+
<span class="toggle-switch"></span>
|
| 100 |
+
</label>
|
| 101 |
+
</div>
|
| 102 |
<div class="filter-section">
|
| 103 |
<label class="toggle-row">
|
| 104 |
<span class="toggle-label">记录搜索历史</span>
|