Skip to content

Commit 59ad450

Browse files
authored
Add files via upload
1 parent 42b8738 commit 59ad450

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

frontend/js/favorites.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export function getFavorites(filterText) {
9191
const keyword = filterText.trim().toLowerCase();
9292
return state.favorites.filter(f =>
9393
f.baseQuery.toLowerCase().includes(keyword) ||
94-
f.query.toLowerCase().includes(keyword)
94+
f.query.toLowerCase().includes(keyword) ||
95+
(f.name && f.name.toLowerCase().includes(keyword))
9596
);
9697
}
9798

frontend/js/main.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,40 @@ async function _showTagPopover(anchor, entry, idx) {
568568
popover.appendChild(opt);
569569
});
570570

571+
// 分隔线 + 自定义标签输入
572+
const divider = document.createElement('div');
573+
divider.className = 'fav-tag-popover-divider';
574+
popover.appendChild(divider);
575+
576+
const customRow = document.createElement('div');
577+
customRow.className = 'fav-tag-custom-row';
578+
customRow.innerHTML = `
579+
<input type="text" class="fav-tag-custom-input" placeholder="新建分组…" maxlength="20">
580+
<button class="fav-tag-custom-add" title="添加">+</button>`;
581+
popover.appendChild(customRow);
582+
583+
const customInput = customRow.querySelector('.fav-tag-custom-input');
584+
const customAdd = customRow.querySelector('.fav-tag-custom-add');
585+
586+
const addCustomTag = () => {
587+
const name = customInput.value.trim();
588+
if (!name) return;
589+
// 添加自定义标签到当前收藏
590+
const newTags = [...currentTags, name];
591+
updateFavoriteTags(entry.baseQuery, newTags);
592+
const searchText = document.getElementById('favSearchInput')?.value || '';
593+
renderFavoritesList(searchText);
594+
popover.remove();
595+
document.removeEventListener('click', closeHandler);
596+
};
597+
customAdd.addEventListener('click', addCustomTag);
598+
customInput.addEventListener('keydown', (e) => {
599+
if (e.key === 'Enter') {
600+
e.preventDefault();
601+
addCustomTag();
602+
}
603+
});
604+
571605
// 点击外部关闭
572606
const closeHandler = (e) => {
573607
if (!popover.contains(e.target) && e.target !== anchor) {

frontend/js/ui.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ function getConfigObject() {
299299
proxyUsername: localStorage.getItem(STORAGE_KEYS.proxyUsername) || '',
300300
proxyPassword: localStorage.getItem(STORAGE_KEYS.proxyPassword) || '',
301301
userAgent: localStorage.getItem(STORAGE_KEYS.userAgent) || '',
302-
customHeaders: localStorage.getItem(STORAGE_KEYS.customHeaders) || '{}'
302+
customHeaders: localStorage.getItem(STORAGE_KEYS.customHeaders) || '{}',
303+
favorites: localStorage.getItem(STORAGE_KEYS.favorites) || '[]'
303304
}
304305
};
305306
}
@@ -389,6 +390,21 @@ function applyConfig(config, source) {
389390
localStorage.setItem(STORAGE_KEYS.dataRange, data.timeRange || 'default');
390391
}
391392

393+
// 恢复用户收藏(仅非系统规则,内置规则由 seedSystemRules 重建)
394+
if (data.favorites) {
395+
try {
396+
const imported = JSON.parse(data.favorites);
397+
const userFavs = imported.filter(f => !f.system);
398+
// 确保每条用户收藏有 tags 字段(兼容旧导出)
399+
userFavs.forEach(f => { if (!f.tags) f.tags = ['用户']; });
400+
const currentSystem = (() => {
401+
try { return JSON.parse(localStorage.getItem(STORAGE_KEYS.favorites) || '[]').filter(f => f.system); }
402+
catch { return []; }
403+
})();
404+
localStorage.setItem(STORAGE_KEYS.favorites, JSON.stringify([...userFavs, ...currentSystem]));
405+
} catch { /* 静默处理无效数据 */ }
406+
}
407+
392408
showToast(`配置从 ${source} 导入成功,页面将刷新`, 'success');
393409

394410
// 刷新页面以应用配置

0 commit comments

Comments
 (0)