PyBot/web/templates/index.html

222 lines
8.4 KiB
HTML
Raw Normal View History

2024-12-10 16:24:41 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>资讯推送Web端</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2025-01-15 11:02:39 +08:00
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
2024-12-10 16:24:41 +08:00
<!-- 引入 Layui 的 CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui-src/dist/css/layui.css">
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 10px; /* 减少边距 */
2024-12-10 16:24:41 +08:00
}
h1 {
color: #333;
font-size: 1.5em; /* 适当减小标题字体 */
2024-12-10 16:24:41 +08:00
}
#markdown-content {
white-space: pre-wrap;
font-size: 0.9em; /* 减小内容字体 */
2024-12-10 16:24:41 +08:00
}
/* 返回顶部按钮样式 */
#back-to-top {
display: none;
position: fixed;
bottom: 10px; /* 调整位置 */
right: 10px; /* 调整位置 */
2024-12-10 16:24:41 +08:00
z-index: 99;
font-size: 16px; /* 减小字体 */
2024-12-10 16:24:41 +08:00
border: none;
outline: none;
background-color: #555;
color: white;
cursor: pointer;
padding: 10px; /* 减小内边距 */
2024-12-10 16:24:41 +08:00
border-radius: 4px;
}
#back-to-top:hover {
background-color: #777;
}
2025-01-14 18:16:59 +08:00
#markdown-content a {
color: blue;
text-decoration: none; /* 可选:去掉下划线 */
}
#markdown-content a:hover {
text-decoration: underline; /* 可选:鼠标悬停时显示下划线 */
}
/* 移动端样式调整 */
@media only screen and (max-width: 600px) {
body {
margin: 5px;
}
h1 {
font-size: 1.2em;
}
#markdown-content {
font-size: 0.8em;
}
#back-to-top {
font-size: 14px;
padding: 8px;
}
2025-01-14 18:16:59 +08:00
#markdown-content a {
color: blue;
text-decoration: none; /* 可选:去掉下划线 */
}
#markdown-content a:hover {
text-decoration: underline; /* 可选:鼠标悬停时显示下划线 */
}
2025-01-16 10:40:06 +08:00
/* 按钮样式调整 */
#button-container {
flex-direction: column; /* 换行显示按钮 */
align-items: center; /* 按钮居中对齐 */
}
#button-container .layui-btn {
margin: 5px 0; /* 增加按钮间距 */
width: 90%; /* 调整按钮宽度 */
max-width: 300px; /* 设置最大宽度 */
}
}
2024-12-10 16:24:41 +08:00
</style>
</head>
<body>
<div class="layui-container">
<center><h1 class="layui-title" id="page-title">历史推送读取</h1><br>
2025-01-16 10:40:06 +08:00
<!-- 折叠面板 -->
<div class="layui-collapse" lay-filter="test">
<div class="layui-colla-item">
<h2 class="layui-colla-title">选择监控源新闻类型</h2>
<div class="layui-colla-content">
<div id="button-container" class="layui-btn-group">
<button id="sec-news-btn" class="layui-btn">安全新闻</button>
<button id="tech-passage-btn" class="layui-btn">技术文章</button>
<button id="baidu-news-btn" class="layui-btn">百度新闻</button>
<button id="github-news-btn" class="layui-btn">GitHub新闻</button>
<button id="wx-news-btn" class="layui-btn">微信新闻</button>
</div>
</div>
</div>
2025-01-15 11:02:39 +08:00
</div>
2025-01-14 18:16:59 +08:00
<h4>为保证网页运作性能默认仅读取前20条记录若您有需求可自行更改app.py</h4></center>
2024-12-10 16:24:41 +08:00
<div id="markdown-content" class="layui-card-body"></div>
</div>
<!-- 返回顶部按钮 -->
<button id="back-to-top" title="Go to top">Top</button>
<!-- 引入 Layui 的 JS -->
<script src="https://cdn.jsdelivr.net/npm/layui-src/dist/layui.js"></script>
<script>
2025-01-16 10:40:06 +08:00
layui.use(['layer', 'element'], function(){
2024-12-10 16:24:41 +08:00
var layer = layui.layer;
2025-01-16 10:40:06 +08:00
var element = layui.element;
2025-01-15 11:02:39 +08:00
var buttonMap = {
'sec-news-btn': '/get-sec-news',
'tech-passage-btn': '/get-tech-passage',
'baidu-news-btn': '/get-baidu-news',
'github-news-btn': '/get-github-news',
'wx-news-btn': '/get-wx-news'
};
2024-12-10 16:24:41 +08:00
var titleMap = {
'/get-sec-news': '安全新闻',
2025-01-15 11:02:39 +08:00
'/get-tech-passage': '技术文章',
'/get-baidu-news': '百度新闻',
'/get-github-news': 'GitHub监控',
'/get-wx-news': '微信文章监控'
2024-12-10 16:24:41 +08:00
};
function updateTitle(url) {
document.getElementById('page-title').innerText = titleMap[url] || '历史推送读取';
}
2025-01-15 11:02:39 +08:00
function fetchContent(url, buttonId) {
// Disable all buttons
Object.keys(buttonMap).forEach(key => {
document.getElementById(key).disabled = false;
});
// Enable the clicked button
document.getElementById(buttonId).disabled = true;
2024-12-10 16:24:41 +08:00
2025-01-15 11:02:39 +08:00
updateTitle(url);
2024-12-10 16:24:41 +08:00
2025-01-15 11:02:39 +08:00
fetch(url)
2024-12-10 16:24:41 +08:00
.then(response => response.json())
.then(data => {
if (data.content) {
const htmlContent = marked.parse(data.content);
document.getElementById('markdown-content').innerHTML = htmlContent;
2025-01-16 10:40:06 +08:00
// 添加这一行代码
addTargetBlankToLinks();
2024-12-10 16:24:41 +08:00
} else {
2024-12-25 18:40:20 +08:00
document.getElementById('markdown-content').innerHTML = '<p>加载历史推送文件时出错!(推送历史记录为空)</p>';
2024-12-10 16:24:41 +08:00
}
})
.catch(error => {
console.error('获取源文件失败:', error);
document.getElementById('markdown-content').innerHTML = '<p>无法加载历史推送文件!</p>';
2025-01-16 10:40:06 +08:00
layer.msg('加载资源失败', {icon: 5});
2024-12-10 16:24:41 +08:00
});
2025-01-15 11:02:39 +08:00
}
// Add event listeners to buttons
Object.keys(buttonMap).forEach(key => {
document.getElementById(key).addEventListener('click', function() {
fetchContent(buttonMap[key], key);
2025-01-16 10:40:06 +08:00
// Check if the device is mobile
if (isMobileDevice()) {
// Collapse the panel
element.collapse('hide', 'test', 0);
}
2025-01-15 11:02:39 +08:00
});
2024-12-10 16:24:41 +08:00
});
// Initial fetch on page load
2025-01-15 11:02:39 +08:00
var initialButtonId = 'sec-news-btn'; // Default button
fetchContent(buttonMap[initialButtonId], initialButtonId);
});
2024-12-10 16:24:41 +08:00
2025-01-15 11:02:39 +08:00
// 显示或隐藏返回顶部按钮
window.onscroll = function() {
scrollFunction();
};
2024-12-10 16:24:41 +08:00
2025-01-15 11:02:39 +08:00
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("back-to-top").style.display = "block";
} else {
document.getElementById("back-to-top").style.display = "none";
2024-12-10 16:24:41 +08:00
}
2025-01-15 11:02:39 +08:00
}
2024-12-10 16:24:41 +08:00
2025-01-15 11:02:39 +08:00
// 返回顶部按钮点击事件
document.getElementById("back-to-top").addEventListener("click", function() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
2024-12-10 16:24:41 +08:00
});
2025-01-16 10:40:06 +08:00
// 检测是否为移动设备
function isMobileDevice() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
function addTargetBlankToLinks() {
var links = document.querySelectorAll('#markdown-content a');
links.forEach(function(link) {
link.setAttribute('target', '_blank');
});
}
// 在页面加载完成后调用该函数
window.onload = function() {
addTargetBlankToLinks();
};
2024-12-10 16:24:41 +08:00
</script>
</body>
</html>