Upload 2 files
Browse files- static/app.js +34 -3
- static/index.html +1 -1
static/app.js
CHANGED
|
@@ -128,6 +128,7 @@ function cacheDom() {
|
|
| 128 |
DOM.themeBtn = $("#theme-btn");
|
| 129 |
DOM.leftSidebar = $("#left-sidebar");
|
| 130 |
DOM.rightSidebar = $("#right-sidebar");
|
|
|
|
| 131 |
DOM.sidebarTitle = $("#sidebar-title");
|
| 132 |
DOM.sidebarContent = $("#sidebar-content");
|
| 133 |
DOM.resultCount = $("#result-count");
|
|
@@ -181,8 +182,14 @@ function syncRoute() {
|
|
| 181 |
STATE.source = route.source;
|
| 182 |
if (STATE.source) {
|
| 183 |
DOM.sidebarTitle.textContent = STATE.source;
|
|
|
|
| 184 |
} else {
|
| 185 |
DOM.sidebarTitle.textContent = "数据包";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
}
|
| 188 |
|
|
@@ -238,6 +245,10 @@ function showToast(message, duration = 2000) {
|
|
| 238 |
}, duration);
|
| 239 |
}
|
| 240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
function getHistory() {
|
| 242 |
try {
|
| 243 |
return JSON.parse(localStorage.getItem(HISTORY_KEY)) || [];
|
|
@@ -271,7 +282,7 @@ function addHistory(query) {
|
|
| 271 |
function renderHistoryDropdown() {
|
| 272 |
const items = getHistory();
|
| 273 |
if (!items.length) {
|
| 274 |
-
|
| 275 |
return;
|
| 276 |
}
|
| 277 |
DOM.searchHistoryDropdown.innerHTML = items.map((item) => `
|
|
@@ -279,7 +290,7 @@ function renderHistoryDropdown() {
|
|
| 279 |
<span class="history-text">${escapeHTML(item)}</span>
|
| 280 |
<button type="button" class="history-del" data-del="${escapeHTML(item)}" aria-label="删除历史">×</button>
|
| 281 |
</div>`).join("") + '<div class="history-footer"><button type="button" class="history-clear-all">清空历史</button></div>';
|
| 282 |
-
|
| 283 |
}
|
| 284 |
|
| 285 |
function applyTheme() {
|
|
@@ -292,6 +303,13 @@ function applyMobileMode() {
|
|
| 292 |
if (DOM.mobileToggleIcon) {
|
| 293 |
DOM.mobileToggleIcon.className = STATE.isMobile ? "ui-icon ui-icon-desktop" : "ui-icon ui-icon-phone";
|
| 294 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
if (STATE.isMobile) {
|
| 296 |
STATE.leftSidebarOpen = false;
|
| 297 |
STATE.rightSidebarOpen = false;
|
|
@@ -676,6 +694,12 @@ function attachEvents() {
|
|
| 676 |
if (STATE.isMobile && STATE.leftSidebarOpen) STATE.rightSidebarOpen = false;
|
| 677 |
updateSidebarVisibility();
|
| 678 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 679 |
DOM.settingsBtn.addEventListener("click", () => {
|
| 680 |
STATE.rightSidebarOpen = !STATE.rightSidebarOpen;
|
| 681 |
if (STATE.isMobile && STATE.rightSidebarOpen) STATE.leftSidebarOpen = false;
|
|
@@ -699,18 +723,25 @@ function attachEvents() {
|
|
| 699 |
STATE.isMobile = !STATE.isMobile;
|
| 700 |
applyMobileMode();
|
| 701 |
});
|
|
|
|
| 702 |
DOM.searchInput.addEventListener("focus", renderHistoryDropdown);
|
| 703 |
-
DOM.searchInput.addEventListener("blur", () => setTimeout(() => {
|
|
|
|
|
|
|
| 704 |
DOM.searchHistoryDropdown.addEventListener("click", (event) => {
|
| 705 |
const delBtn = event.target.closest(".history-del");
|
| 706 |
if (delBtn) {
|
| 707 |
event.stopPropagation();
|
| 708 |
removeHistory(delBtn.dataset.del);
|
|
|
|
|
|
|
| 709 |
return;
|
| 710 |
}
|
| 711 |
const clearBtn = event.target.closest(".history-clear-all");
|
| 712 |
if (clearBtn) {
|
| 713 |
clearHistory();
|
|
|
|
|
|
|
| 714 |
return;
|
| 715 |
}
|
| 716 |
const item = event.target.closest("[data-query]");
|
|
|
|
| 128 |
DOM.themeBtn = $("#theme-btn");
|
| 129 |
DOM.leftSidebar = $("#left-sidebar");
|
| 130 |
DOM.rightSidebar = $("#right-sidebar");
|
| 131 |
+
DOM.sidebarExpandBtn = $("#sidebar-expand-btn");
|
| 132 |
DOM.sidebarTitle = $("#sidebar-title");
|
| 133 |
DOM.sidebarContent = $("#sidebar-content");
|
| 134 |
DOM.resultCount = $("#result-count");
|
|
|
|
| 182 |
STATE.source = route.source;
|
| 183 |
if (STATE.source) {
|
| 184 |
DOM.sidebarTitle.textContent = STATE.source;
|
| 185 |
+
if (DOM.sidebarExpandBtn && !STATE.isMobile) DOM.sidebarExpandBtn.style.display = "";
|
| 186 |
} else {
|
| 187 |
DOM.sidebarTitle.textContent = "数据包";
|
| 188 |
+
if (DOM.sidebarExpandBtn) {
|
| 189 |
+
DOM.sidebarExpandBtn.style.display = "none";
|
| 190 |
+
DOM.leftSidebar.classList.remove("expanded-wide");
|
| 191 |
+
DOM.sidebarExpandBtn.textContent = "↔";
|
| 192 |
+
}
|
| 193 |
}
|
| 194 |
}
|
| 195 |
|
|
|
|
| 245 |
}, duration);
|
| 246 |
}
|
| 247 |
|
| 248 |
+
function setHistoryDropdownOpen(open) {
|
| 249 |
+
DOM.searchHistoryDropdown.style.display = open ? "" : "none";
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
function getHistory() {
|
| 253 |
try {
|
| 254 |
return JSON.parse(localStorage.getItem(HISTORY_KEY)) || [];
|
|
|
|
| 282 |
function renderHistoryDropdown() {
|
| 283 |
const items = getHistory();
|
| 284 |
if (!items.length) {
|
| 285 |
+
setHistoryDropdownOpen(false);
|
| 286 |
return;
|
| 287 |
}
|
| 288 |
DOM.searchHistoryDropdown.innerHTML = items.map((item) => `
|
|
|
|
| 290 |
<span class="history-text">${escapeHTML(item)}</span>
|
| 291 |
<button type="button" class="history-del" data-del="${escapeHTML(item)}" aria-label="删除历史">×</button>
|
| 292 |
</div>`).join("") + '<div class="history-footer"><button type="button" class="history-clear-all">清空历史</button></div>';
|
| 293 |
+
setHistoryDropdownOpen(true);
|
| 294 |
}
|
| 295 |
|
| 296 |
function applyTheme() {
|
|
|
|
| 303 |
if (DOM.mobileToggleIcon) {
|
| 304 |
DOM.mobileToggleIcon.className = STATE.isMobile ? "ui-icon ui-icon-desktop" : "ui-icon ui-icon-phone";
|
| 305 |
}
|
| 306 |
+
if (DOM.sidebarExpandBtn) {
|
| 307 |
+
DOM.sidebarExpandBtn.style.display = (!STATE.isMobile && STATE.source) ? "" : "none";
|
| 308 |
+
if (STATE.isMobile) {
|
| 309 |
+
DOM.leftSidebar.classList.remove("expanded-wide");
|
| 310 |
+
DOM.sidebarExpandBtn.textContent = "↔";
|
| 311 |
+
}
|
| 312 |
+
}
|
| 313 |
if (STATE.isMobile) {
|
| 314 |
STATE.leftSidebarOpen = false;
|
| 315 |
STATE.rightSidebarOpen = false;
|
|
|
|
| 694 |
if (STATE.isMobile && STATE.leftSidebarOpen) STATE.rightSidebarOpen = false;
|
| 695 |
updateSidebarVisibility();
|
| 696 |
});
|
| 697 |
+
if (DOM.sidebarExpandBtn) {
|
| 698 |
+
DOM.sidebarExpandBtn.addEventListener("click", () => {
|
| 699 |
+
DOM.leftSidebar.classList.toggle("expanded-wide");
|
| 700 |
+
DOM.sidebarExpandBtn.textContent = DOM.leftSidebar.classList.contains("expanded-wide") ? "→" : "↔";
|
| 701 |
+
});
|
| 702 |
+
}
|
| 703 |
DOM.settingsBtn.addEventListener("click", () => {
|
| 704 |
STATE.rightSidebarOpen = !STATE.rightSidebarOpen;
|
| 705 |
if (STATE.isMobile && STATE.rightSidebarOpen) STATE.leftSidebarOpen = false;
|
|
|
|
| 723 |
STATE.isMobile = !STATE.isMobile;
|
| 724 |
applyMobileMode();
|
| 725 |
});
|
| 726 |
+
let historyDropdownActive = false;
|
| 727 |
DOM.searchInput.addEventListener("focus", renderHistoryDropdown);
|
| 728 |
+
DOM.searchInput.addEventListener("blur", () => setTimeout(() => { if (!historyDropdownActive) setHistoryDropdownOpen(false); }, 120));
|
| 729 |
+
DOM.searchHistoryDropdown.addEventListener("mouseenter", () => { historyDropdownActive = true; });
|
| 730 |
+
DOM.searchHistoryDropdown.addEventListener("mouseleave", () => { historyDropdownActive = false; });
|
| 731 |
DOM.searchHistoryDropdown.addEventListener("click", (event) => {
|
| 732 |
const delBtn = event.target.closest(".history-del");
|
| 733 |
if (delBtn) {
|
| 734 |
event.stopPropagation();
|
| 735 |
removeHistory(delBtn.dataset.del);
|
| 736 |
+
historyDropdownActive = true;
|
| 737 |
+
DOM.searchInput.focus();
|
| 738 |
return;
|
| 739 |
}
|
| 740 |
const clearBtn = event.target.closest(".history-clear-all");
|
| 741 |
if (clearBtn) {
|
| 742 |
clearHistory();
|
| 743 |
+
historyDropdownActive = true;
|
| 744 |
+
DOM.searchInput.focus();
|
| 745 |
return;
|
| 746 |
}
|
| 747 |
const item = event.target.closest("[data-query]");
|
static/index.html
CHANGED
|
@@ -36,7 +36,7 @@
|
|
| 36 |
|
| 37 |
<div id="app-body" class="app-body">
|
| 38 |
<aside id="left-sidebar" class="sidebar left-sidebar">
|
| 39 |
-
<div class="sidebar-header"><span id="sidebar-title">数据包</span></div>
|
| 40 |
<div id="sidebar-content" class="sidebar-content"><div class="sidebar-loading">加载中...</div></div>
|
| 41 |
</aside>
|
| 42 |
|
|
|
|
| 36 |
|
| 37 |
<div id="app-body" class="app-body">
|
| 38 |
<aside id="left-sidebar" class="sidebar left-sidebar">
|
| 39 |
+
<div class="sidebar-header"><span id="sidebar-title">数据包</span><button id="sidebar-expand-btn" class="icon-btn-sm" title="展开/收起侧边栏" style="display:none">↔</button></div>
|
| 40 |
<div id="sidebar-content" class="sidebar-content"><div class="sidebar-loading">加载中...</div></div>
|
| 41 |
</aside>
|
| 42 |
|