增加了API断电

This commit is contained in:
Alex Yang
2025-11-28 00:42:11 +08:00
parent b1c63f6713
commit 45ed4d0d6b
5 changed files with 206 additions and 87 deletions

View File

@@ -53,7 +53,7 @@ async function loadShieldStats() {
async function loadLocalRules() {
showLoading('加载本地规则...');
try {
const response = await fetch('/api/shield?all=true');
const response = await fetch('/api/shield/localrules');
if (!response.ok) {
throw new Error(`加载失败: ${response.status}`);
@@ -61,6 +61,11 @@ async function loadLocalRules() {
const data = await response.json();
// 更新本地规则数量显示
if (document.getElementById('local-rules-count')) {
document.getElementById('local-rules-count').textContent = data.localRulesCount || 0;
}
// 合并所有本地规则
let rules = [];
// 添加域名规则
@@ -89,6 +94,51 @@ async function loadLocalRules() {
}
}
// 加载远程规则
async function loadRemoteRules() {
showLoading('加载远程规则...');
try {
const response = await fetch('/api/shield/remoterules');
if (!response.ok) {
throw new Error(`加载失败: ${response.status}`);
}
const data = await response.json();
// 更新远程规则数量显示
if (document.getElementById('remote-rules-count')) {
document.getElementById('remote-rules-count').textContent = data.remoteRulesCount || 0;
}
// 合并所有远程规则
let rules = [];
// 添加域名规则
if (Array.isArray(data.domainRules)) {
rules = rules.concat(data.domainRules);
}
// 添加域名排除规则
if (Array.isArray(data.domainExceptions)) {
rules = rules.concat(data.domainExceptions);
}
// 添加正则规则
if (Array.isArray(data.regexRules)) {
rules = rules.concat(data.regexRules);
}
// 添加正则排除规则
if (Array.isArray(data.regexExceptions)) {
rules = rules.concat(data.regexExceptions);
}
updateRulesTable(rules);
hideLoading();
} catch (error) {
console.error('加载远程规则失败:', error);
showErrorMessage('加载远程规则失败');
hideLoading();
}
}
// 更新规则表格
function updateRulesTable(rules) {
const tbody = document.getElementById('rules-table-body');
@@ -416,6 +466,15 @@ function setupShieldEventListeners() {
// 远程黑名单管理事件
document.getElementById('save-blacklist-btn').addEventListener('click', handleAddBlacklist);
// 添加切换查看本地规则和远程规则的事件监听
if (document.getElementById('view-local-rules-btn')) {
document.getElementById('view-local-rules-btn').addEventListener('click', loadLocalRules);
}
if (document.getElementById('view-remote-rules-btn')) {
document.getElementById('view-remote-rules-btn').addEventListener('click', loadRemoteRules);
}
}
// 显示成功消息