Update server.js
Browse files
server.js
CHANGED
|
@@ -11,7 +11,7 @@ const PORT = process.env.PORT || 8080;
|
|
| 11 |
app.use(express.json());
|
| 12 |
app.use(express.urlencoded({ extended: true }));
|
| 13 |
|
| 14 |
-
// 中间件:处理HTML文件中的环境变量注入
|
| 15 |
app.use((req, res, next) => {
|
| 16 |
if (req.path.endsWith('.html') || req.path === '/' || req.path.endsWith('/')) {
|
| 17 |
const filePath = req.path === '/' || req.path.endsWith('/')
|
|
@@ -36,6 +36,64 @@ app.use((req, res, next) => {
|
|
| 36 |
`window.__ENV__.PASSWORD = "${passwordHash}"; // SHA-256 hash`
|
| 37 |
);
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
| 40 |
return res.send(content);
|
| 41 |
}
|
|
|
|
| 11 |
app.use(express.json());
|
| 12 |
app.use(express.urlencoded({ extended: true }));
|
| 13 |
|
| 14 |
+
// 中间件:处理HTML文件中的环境变量注入和强制设置脚本
|
| 15 |
app.use((req, res, next) => {
|
| 16 |
if (req.path.endsWith('.html') || req.path === '/' || req.path.endsWith('/')) {
|
| 17 |
const filePath = req.path === '/' || req.path.endsWith('/')
|
|
|
|
| 36 |
`window.__ENV__.PASSWORD = "${passwordHash}"; // SHA-256 hash`
|
| 37 |
);
|
| 38 |
|
| 39 |
+
// 注入强制设置脚本
|
| 40 |
+
const forcedSettingsScript = `
|
| 41 |
+
<script>
|
| 42 |
+
// 页面加载后立即执行
|
| 43 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 44 |
+
console.log('正在应用强制设置...');
|
| 45 |
+
|
| 46 |
+
// 选择所有API源
|
| 47 |
+
if (typeof API_SITES !== 'undefined') {
|
| 48 |
+
window.selectedAPIs = Object.keys(API_SITES).filter(key => key !== 'aggregated' && key !== 'custom');
|
| 49 |
+
localStorage.setItem('selectedAPIs', JSON.stringify(window.selectedAPIs));
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
// 默认关闭黄色内容过滤
|
| 53 |
+
localStorage.setItem('yellowFilterEnabled', 'false');
|
| 54 |
+
|
| 55 |
+
// 默认开启分片广告过滤
|
| 56 |
+
localStorage.setItem('adFilteringEnabled', 'true');
|
| 57 |
+
|
| 58 |
+
// 默认开启豆瓣热门推荐
|
| 59 |
+
localStorage.setItem('doubanEnabled', 'true');
|
| 60 |
+
|
| 61 |
+
// 如果页面上有相关元素,直接更新UI
|
| 62 |
+
setTimeout(function() {
|
| 63 |
+
// 更新黄色内容过滤开关
|
| 64 |
+
const yellowFilterToggle = document.getElementById('yellowFilterToggle');
|
| 65 |
+
if (yellowFilterToggle) {
|
| 66 |
+
yellowFilterToggle.checked = false;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
// 更新分片广告过滤开关
|
| 70 |
+
const adFilterToggle = document.getElementById('adFilterToggle');
|
| 71 |
+
if (adFilterToggle) {
|
| 72 |
+
adFilterToggle.checked = true;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
// 更新豆瓣热门开关
|
| 76 |
+
const doubanToggle = document.getElementById('doubanToggle');
|
| 77 |
+
if (doubanToggle) {
|
| 78 |
+
doubanToggle.checked = true;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// 尝试更新豆瓣区域可见性
|
| 82 |
+
if (typeof updateDoubanVisibility === 'function') {
|
| 83 |
+
updateDoubanVisibility();
|
| 84 |
+
} else if (window.updateDoubanVisibility) {
|
| 85 |
+
window.updateDoubanVisibility();
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
console.log('已应用强制设置');
|
| 89 |
+
}, 500);
|
| 90 |
+
});
|
| 91 |
+
</script>
|
| 92 |
+
`;
|
| 93 |
+
|
| 94 |
+
// 在</body>前插入脚本
|
| 95 |
+
content = content.replace('</body>', forcedSettingsScript + '</body>');
|
| 96 |
+
|
| 97 |
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
| 98 |
return res.send(content);
|
| 99 |
}
|