修复主题
This commit is contained in:
@@ -183,6 +183,14 @@ function animateCounter(element, target, duration = 1000) {
|
||||
|
||||
// 加载屏蔽规则统计信息
|
||||
async function loadShieldStats() {
|
||||
// 检查是否有有效的缓存数据
|
||||
const cachedStats = window.pageDataCache && window.pageDataCache.getCache('shield_stats');
|
||||
if (cachedStats) {
|
||||
console.log('使用缓存的屏蔽规则统计信息');
|
||||
updateShieldStatsUI(cachedStats);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取屏蔽规则统计信息
|
||||
const shieldResponse = await fetch('/api/shield');
|
||||
@@ -203,27 +211,18 @@ async function loadShieldStats() {
|
||||
const blacklists = await blacklistsResponse.json();
|
||||
const disabledBlacklistCount = blacklists.filter(blacklist => !blacklist.enabled).length;
|
||||
|
||||
// 组合统计数据
|
||||
const shieldStats = {
|
||||
...stats,
|
||||
disabledBlacklistCount
|
||||
};
|
||||
|
||||
// 更新统计信息
|
||||
const elements = [
|
||||
{ id: 'domain-rules-count', value: stats.domainRulesCount },
|
||||
{ id: 'domain-exceptions-count', value: stats.domainExceptionsCount },
|
||||
{ id: 'regex-rules-count', value: stats.regexRulesCount },
|
||||
{ id: 'regex-exceptions-count', value: stats.regexExceptionsCount },
|
||||
{ id: 'hosts-rules-count', value: stats.hostsRulesCount },
|
||||
{ id: 'blacklist-count', value: stats.blacklistCount }
|
||||
];
|
||||
updateShieldStatsUI(shieldStats);
|
||||
|
||||
elements.forEach(item => {
|
||||
const element = document.getElementById(item.id);
|
||||
if (element) {
|
||||
animateCounter(element, item.value || 0);
|
||||
}
|
||||
});
|
||||
|
||||
// 更新禁用黑名单数量
|
||||
const disabledBlacklistElement = document.getElementById('blacklist-disabled-count');
|
||||
if (disabledBlacklistElement) {
|
||||
animateCounter(disabledBlacklistElement, disabledBlacklistCount);
|
||||
// 存储数据到缓存
|
||||
if (window.pageDataCache) {
|
||||
window.pageDataCache.setCache('shield_stats', shieldStats);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载屏蔽规则统计信息失败:', error);
|
||||
@@ -231,8 +230,44 @@ async function loadShieldStats() {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新屏蔽规则统计信息UI
|
||||
function updateShieldStatsUI(stats) {
|
||||
if (!stats) return;
|
||||
|
||||
// 更新统计信息
|
||||
const elements = [
|
||||
{ id: 'domain-rules-count', value: stats.domainRulesCount },
|
||||
{ id: 'domain-exceptions-count', value: stats.domainExceptionsCount },
|
||||
{ id: 'regex-rules-count', value: stats.regexRulesCount },
|
||||
{ id: 'regex-exceptions-count', value: stats.regexExceptionsCount },
|
||||
{ id: 'hosts-rules-count', value: stats.hostsRulesCount },
|
||||
{ id: 'blacklist-count', value: stats.blacklistCount }
|
||||
];
|
||||
|
||||
elements.forEach(item => {
|
||||
const element = document.getElementById(item.id);
|
||||
if (element) {
|
||||
animateCounter(element, item.value || 0);
|
||||
}
|
||||
});
|
||||
|
||||
// 更新禁用黑名单数量
|
||||
const disabledBlacklistElement = document.getElementById('blacklist-disabled-count');
|
||||
if (disabledBlacklistElement) {
|
||||
animateCounter(disabledBlacklistElement, stats.disabledBlacklistCount || 0);
|
||||
}
|
||||
}
|
||||
|
||||
// 加载自定义规则
|
||||
async function loadLocalRules() {
|
||||
// 检查是否有有效的缓存数据
|
||||
const cachedRules = window.pageDataCache && window.pageDataCache.getCache('local_rules');
|
||||
if (cachedRules) {
|
||||
console.log('使用缓存的自定义规则');
|
||||
updateLocalRulesUI(cachedRules);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/shield/localrules');
|
||||
|
||||
@@ -243,41 +278,62 @@ async function loadLocalRules() {
|
||||
const data = await response.json();
|
||||
|
||||
// 更新自定义规则数量显示
|
||||
if (document.getElementById('local-rules-count')) {
|
||||
document.getElementById('local-rules-count').textContent = data.localRulesCount || 0;
|
||||
}
|
||||
updateLocalRulesUI(data);
|
||||
|
||||
// 设置当前规则类型
|
||||
currentRulesType = 'local';
|
||||
|
||||
// 合并所有自定义规则
|
||||
let rules = [];
|
||||
// 添加域名规则
|
||||
if (Array.isArray(data.domainRules)) {
|
||||
rules = rules.concat(data.domainRules);
|
||||
// 存储数据到缓存
|
||||
if (window.pageDataCache) {
|
||||
window.pageDataCache.setCache('local_rules', data);
|
||||
}
|
||||
// 添加域名排除规则
|
||||
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);
|
||||
} catch (error) {
|
||||
console.error('加载自定义规则失败:', error);
|
||||
showNotification('加载自定义规则失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// 更新自定义规则UI
|
||||
function updateLocalRulesUI(data) {
|
||||
if (!data) return;
|
||||
|
||||
// 更新自定义规则数量显示
|
||||
if (document.getElementById('local-rules-count')) {
|
||||
document.getElementById('local-rules-count').textContent = data.localRulesCount || 0;
|
||||
}
|
||||
|
||||
// 设置当前规则类型
|
||||
currentRulesType = 'local';
|
||||
|
||||
// 合并所有自定义规则
|
||||
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);
|
||||
}
|
||||
|
||||
// 加载远程规则
|
||||
async function loadRemoteRules() {
|
||||
// 检查是否有有效的缓存数据
|
||||
const cachedRules = window.pageDataCache && window.pageDataCache.getCache('remote_rules');
|
||||
if (cachedRules) {
|
||||
console.log('使用缓存的远程规则');
|
||||
updateRemoteRulesUI(cachedRules);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 设置当前规则类型
|
||||
currentRulesType = 'remote';
|
||||
@@ -290,36 +346,52 @@ async function loadRemoteRules() {
|
||||
const data = await response.json();
|
||||
|
||||
// 更新远程规则数量显示
|
||||
if (document.getElementById('remote-rules-count')) {
|
||||
document.getElementById('remote-rules-count').textContent = data.remoteRulesCount || 0;
|
||||
}
|
||||
updateRemoteRulesUI(data);
|
||||
|
||||
// 合并所有远程规则
|
||||
let rules = [];
|
||||
// 添加域名规则
|
||||
if (Array.isArray(data.domainRules)) {
|
||||
rules = rules.concat(data.domainRules);
|
||||
// 存储数据到缓存
|
||||
if (window.pageDataCache) {
|
||||
window.pageDataCache.setCache('remote_rules', data);
|
||||
}
|
||||
// 添加域名排除规则
|
||||
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);
|
||||
} catch (error) {
|
||||
console.error('加载远程规则失败:', error);
|
||||
showNotification('加载远程规则失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// 更新远程规则UI
|
||||
function updateRemoteRulesUI(data) {
|
||||
if (!data) return;
|
||||
|
||||
// 设置当前规则类型
|
||||
currentRulesType = 'remote';
|
||||
|
||||
// 更新远程规则数量显示
|
||||
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);
|
||||
}
|
||||
|
||||
// 更新规则表格
|
||||
function updateRulesTable(rules) {
|
||||
const tbody = document.getElementById('rules-table-body');
|
||||
@@ -600,6 +672,14 @@ async function handleAddRule() {
|
||||
|
||||
// 加载远程黑名单
|
||||
async function loadRemoteBlacklists() {
|
||||
// 检查是否有有效的缓存数据
|
||||
const cachedBlacklists = window.pageDataCache && window.pageDataCache.getCache('remote_blacklists');
|
||||
if (cachedBlacklists) {
|
||||
console.log('使用缓存的远程黑名单');
|
||||
updateBlacklistsTable(cachedBlacklists);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/shield/blacklists');
|
||||
|
||||
@@ -612,6 +692,11 @@ async function loadRemoteBlacklists() {
|
||||
// 确保blacklists是数组
|
||||
const blacklistArray = Array.isArray(blacklists) ? blacklists : [];
|
||||
updateBlacklistsTable(blacklistArray);
|
||||
|
||||
// 存储数据到缓存
|
||||
if (window.pageDataCache) {
|
||||
window.pageDataCache.setCache('remote_blacklists', blacklistArray);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载远程黑名单失败:', error);
|
||||
showNotification('加载远程黑名单失败', 'error');
|
||||
|
||||
Reference in New Issue
Block a user