mirror of
https://github.com/eternity4719/HowToLiveBetter.git
synced 2026-11-20 08:40:44 +08:00
fix(index): 避免 writeUrl 保留无效 hash 导致刷新丢失检索词,并防止弹窗时快捷键抢焦点
1. writeUrl() 中仅在当前筛选下目标卡片可见时保留 location.hash,并在 replaceState 中传递 history.state 保留历史定位状态,避免 F5 刷新时因 hash 与新筛选条件冲突导致检索词被误重置。2. 全局 keydown 监听在长文弹窗或赞赏弹窗打开时跳过快捷键,避免 / 键窃取焦点破坏模态弹窗体验。
This commit is contained in:
+5
-1
@@ -1157,7 +1157,10 @@ function writeUrl(){
|
||||
for (const d of DIMS) if (state[d].size) p.set(d, [...state[d]].join(','));
|
||||
if (state.dispute) p.set('dispute','1'); if (state.todo) p.set('todo','1');
|
||||
if (PERF.on) p.set('perf','1');
|
||||
const qs = p.toString(); history.replaceState(null, '', (qs ? '?'+qs : location.pathname) + location.hash);
|
||||
const qs = p.toString();
|
||||
const hash = location.hash;
|
||||
const validHash = hash && document.getElementById(hash.slice(1))?.offsetParent ? hash : '';
|
||||
history.replaceState(history.state, '', (qs ? '?'+qs : location.pathname) + validHash);
|
||||
}
|
||||
function syncControls(){
|
||||
document.getElementById('q').value = state.q;
|
||||
@@ -1278,6 +1281,7 @@ function wire(){
|
||||
document.getElementById('reset').addEventListener('click', reset);
|
||||
document.getElementById('reset2').addEventListener('click', reset);
|
||||
document.addEventListener('keydown', e => {
|
||||
if (!DM.mask.hidden || !TIP.hidden) return;
|
||||
if (e.key === '/' && !/INPUT|TEXTAREA/.test(document.activeElement.tagName)) { e.preventDefault(); document.getElementById('q').focus(); }
|
||||
if (e.key === 'Escape') { if (document.activeElement.id === 'q') document.activeElement.blur(); setMenu(false); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user