+
-
-
-
-
-
-
-
-
-
-
-
diff --git a/popup.js b/popup.js
index 0b5726c..54a99ea 100644
--- a/popup.js
+++ b/popup.js
@@ -21,6 +21,11 @@ document.addEventListener('DOMContentLoaded', () => {
const goToRegister = document.getElementById('go-to-register');
const goToLogin = document.getElementById('go-to-login');
const logoutBtn = document.getElementById('logout-btn');
+ const archiveToggle = document.getElementById('archive-toggle');
+ const backToMain = document.getElementById('back-to-main');
+ const mainViewContent = document.getElementById('main-view-content');
+ const archiveViewContent = document.getElementById('archive-view-content');
+ const archiveList = document.getElementById('archive-list');
if (logoutBtn) {
logoutBtn.addEventListener('click', (e) => {
@@ -294,8 +299,9 @@ document.addEventListener('DOMContentLoaded', () => {
function renderRules() {
rulesList.innerHTML = '';
+ const activeRules = rules.filter(r => !r.archived);
- if (rules.length === 0) {
+ if (activeRules.length === 0) {
rulesList.innerHTML = `
-
`;
@@ -341,21 +349,75 @@ document.addEventListener('DOMContentLoaded', () => {
rulesList.appendChild(li);
});
+ attachRuleEvents();
+ }
+
+ function renderArchive() {
+ archiveList.innerHTML = '';
+ const archivedRules = rules.filter(r => r.archived);
+
+ if (archivedRules.length === 0) {
+ archiveList.innerHTML = '
暂无归档内容
';
+ return;
+ }
+
+ archivedRules.forEach(rule => {
+ const li = document.createElement('li');
+ li.className = 'rule-item';
+ li.innerHTML = `
+
+
${rule.clientName} ${rule.env.replace('_', ' ')}
+
帐号: ${rule.username}
+
+
+ `;
+ archiveList.appendChild(li);
+ });
+
+ document.querySelectorAll('.btn-restore').forEach(btn => {
+ btn.addEventListener('click', (e) => {
+ const id = e.currentTarget.getAttribute('data-id');
+ const index = rules.findIndex(r => r.id === id);
+ if (index !== -1) {
+ rules[index].archived = false;
+ saveRules();
+ renderArchive();
+ }
+ });
+ });
+
+ document.querySelectorAll('.btn-delete-perm').forEach(btn => {
+ btn.addEventListener('click', (e) => {
+ const id = e.currentTarget.getAttribute('data-id');
+ if (confirm('确定要彻底删除此配置吗?此操作不可撤销。')) {
+ rules = rules.filter(r => r.id !== id);
+ saveRules();
+ renderArchive();
+ }
+ });
+ });
+ }
+
+ function attachRuleEvents() {
document.querySelectorAll('.rule-info').forEach(infoArea => {
infoArea.addEventListener('click', (e) => {
const id = e.currentTarget.getAttribute('data-id');
const rule = rules.find(r => r.id === id);
- if (rule) {
- executePurgeAndLogin(rule, e.currentTarget);
- }
+ if (rule) executePurgeAndLogin(rule, e.currentTarget);
});
});
document.querySelectorAll('.btn-edit').forEach(btn => {
btn.addEventListener('click', (e) => {
e.stopPropagation();
- const id = e.currentTarget.getAttribute('data-id');
- toggleAddForm('edit', id);
+ toggleAddForm('edit', e.currentTarget.getAttribute('data-id'));
});
});
@@ -363,14 +425,31 @@ document.addEventListener('DOMContentLoaded', () => {
btn.addEventListener('click', (e) => {
e.stopPropagation();
const id = e.currentTarget.getAttribute('data-id');
- if (confirm('确定要删除此配置吗?')) {
- rules = rules.filter(r => r.id !== id);
+ const index = rules.findIndex(r => r.id === id);
+ if (index !== -1) {
+ rules[index].archived = true;
saveRules();
}
});
});
}
+ if (archiveToggle) {
+ archiveToggle.addEventListener('click', () => {
+ mainViewContent.classList.add('hidden');
+ archiveViewContent.classList.remove('hidden');
+ renderArchive();
+ });
+ }
+
+ if (backToMain) {
+ backToMain.addEventListener('click', () => {
+ archiveViewContent.classList.add('hidden');
+ mainViewContent.classList.remove('hidden');
+ renderRules();
+ });
+ }
+
// --- Drag and Drop functionality ---
function addDragEvents(item) {
item.addEventListener('dragstart', (e) => {