update
This commit is contained in:
1 parent
61f505d439
commit
ba00741c11
17 files changed
+1646
-1168
No files matched your search
+54
-43
@@ -4,6 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<title>资讯推送Web端</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
|
||||
<!-- 引入 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>
|
||||
@@ -75,7 +76,13 @@
|
||||
<body>
|
||||
<div class="layui-container">
|
||||
<center><h1 class="layui-title" id="page-title">历史推送读取</h1><br>
|
||||
<button id="toggle-fetch-btn" class="layui-btn">切换读取源</button><br>
|
||||
<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>
|
||||
<h4>为保证网页运作性能,默认仅读取前20条记录,若您有需求可自行更改app.py</h4></center>
|
||||
<div id="markdown-content" class="layui-card-body"></div>
|
||||
</div>
|
||||
@@ -88,26 +95,38 @@
|
||||
<script>
|
||||
layui.use(['layer'], function(){
|
||||
var layer = layui.layer;
|
||||
var currentUrl = '/get-sec-news';
|
||||
|
||||
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'
|
||||
};
|
||||
|
||||
var titleMap = {
|
||||
'/get-sec-news': '安全新闻',
|
||||
'/get-tech-passage': '技术文章'
|
||||
'/get-tech-passage': '技术文章',
|
||||
'/get-baidu-news': '百度新闻',
|
||||
'/get-github-news': 'GitHub监控',
|
||||
'/get-wx-news': '微信文章监控'
|
||||
};
|
||||
|
||||
function updateTitle(url) {
|
||||
document.getElementById('page-title').innerText = titleMap[url] || '历史推送读取';
|
||||
}
|
||||
|
||||
document.getElementById('toggle-fetch-btn').addEventListener('click', function() {
|
||||
if (currentUrl === '/get-sec-news') {
|
||||
currentUrl = '/get-tech-passage';
|
||||
} else {
|
||||
currentUrl = '/get-sec-news';
|
||||
}
|
||||
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;
|
||||
|
||||
updateTitle(currentUrl);
|
||||
updateTitle(url);
|
||||
|
||||
fetch(currentUrl)
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.content) {
|
||||
@@ -122,45 +141,37 @@
|
||||
document.getElementById('markdown-content').innerHTML = '<p>无法加载历史推送文件!</p>';
|
||||
layer.msg('Failed to load markdown.', {icon: 5});
|
||||
});
|
||||
}
|
||||
|
||||
// Add event listeners to buttons
|
||||
Object.keys(buttonMap).forEach(key => {
|
||||
document.getElementById(key).addEventListener('click', function() {
|
||||
fetchContent(buttonMap[key], key);
|
||||
});
|
||||
});
|
||||
|
||||
// Initial fetch on page load
|
||||
updateTitle(currentUrl);
|
||||
var initialButtonId = 'sec-news-btn'; // Default button
|
||||
fetchContent(buttonMap[initialButtonId], initialButtonId);
|
||||
});
|
||||
|
||||
fetch(currentUrl)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.content) {
|
||||
const htmlContent = marked.parse(data.content);
|
||||
document.getElementById('markdown-content').innerHTML = htmlContent;
|
||||
} else {
|
||||
document.getElementById('markdown-content').innerHTML = '<p>加载历史推送文件时出错!(推送历史记录为空)</p>';
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取源文件失败:', error);
|
||||
document.getElementById('markdown-content').innerHTML = '<p>无法加载历史推送文件!</p>';
|
||||
layer.msg('Failed to load markdown.', {icon: 5});
|
||||
});
|
||||
// 显示或隐藏返回顶部按钮
|
||||
window.onscroll = function() {
|
||||
scrollFunction();
|
||||
};
|
||||
|
||||
// 显示或隐藏返回顶部按钮
|
||||
window.onscroll = function() {
|
||||
scrollFunction();
|
||||
};
|
||||
|
||||
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";
|
||||
}
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
// 返回顶部按钮点击事件
|
||||
document.getElementById("back-to-top").addEventListener("click", function() {
|
||||
document.body.scrollTop = 0;
|
||||
document.documentElement.scrollTop = 0;
|
||||
});
|
||||
// 返回顶部按钮点击事件
|
||||
document.getElementById("back-to-top").addEventListener("click", function() {
|
||||
document.body.scrollTop = 0;
|
||||
document.documentElement.scrollTop = 0;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in new issue
Block a user