Daily News Fetcher - Moyu Ribao, Weiyu Jianbao & TopURL
// ==UserScript==
// @name Daily News Fetcher - Moyu Ribao, Weiyu Jianbao & TopURL
// @namespace https://bbs.tampermonkey.net.cn/
// @description 获取每日新闻并显示所有新闻和图片(结合摸鱼日报、新闻简报和TopURL API)
// @version 1.1.0
// @author shuaima
// @crontab * once * * *
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @grant GM_openInTab
// @grant GM_log
// @connect dayu.qqsuu.cn
// @connect news.topurl.cn
// ==/UserScript==
return new Promise((resolve, reject) => {
// Fetching Moyu Ribao API
GM_xmlhttpRequest({
method: "GET",
url: "https://dayu.qqsuu.cn/moyuribao/apis.php?type=json", // Moyu Ribao JSON data
onload: xhr => {
try {
let moyuData = JSON.parse(xhr.responseText);
GM_log(moyuData); // Debug log for Moyu Ribao data
// Fetching Weiyu Jianbao API
GM_xmlhttpRequest({
method: "GET",
url: "https://dayu.qqsuu.cn/weiyujianbao/apis.php?type=json", // Weiyu Jianbao JSON data
onload: xhr => {
try {
let weiyuData = JSON.parse(xhr.responseText);
GM_log(weiyuData); // Debug log for Weiyu Jianbao data
// Fetching TopURL API
GM_xmlhttpRequest({
method: "GET",
url: "http://news.topurl.cn/api", // TopURL JSON data
onload: xhr => {
try {
let topurlData = JSON.parse(xhr.responseText);
GM_log(topurlData); // Debug log for TopURL data
// Create content from Moyu Ribao
let moyuImageUrl = moyuData.data;
let moyuContent = '';
if (moyuImageUrl) {
moyuContent = `<div class="image-container">
<h2>摸鱼日报图片</h2>
<img src="${moyuImageUrl}" alt="摸鱼日报图片">
</div>`;
}
// Create content from Weiyu Jianbao
let weiyuImageUrl = weiyuData.data;
let weiyuContent = '';
if (weiyuImageUrl) {
weiyuContent = `<div class="image-container">
<h2>新闻简报图片</h2>
<img src="${weiyuImageUrl}" alt="新闻简报图片">
</div>`;
}
// Build news content from TopURL API
let newsContent = '';
if (topurlData && topurlData.data && topurlData.data.newsList && topurlData.data.newsList.length > 0) {
topurlData.data.newsList.forEach((newsItem, index) => {
newsContent += `
<div class="news-item">
<a href="${newsItem.url}" target="_blank">
<h2>${index + 1}. ${newsItem.title}</h2>
</a>
</div>
`;
});
} else {
newsContent = `<p>没有获取到新闻内容,请稍后再试。</p>`;
}
// Show a notification and display all content when clicked
GM_notification({
title: "每日新闻播报",
text: "点击查看全部新闻和图片",
onclick: function () {
// Combine the content into a single HTML page
let newsPageContent = `
<html>
<head>
<meta charset="UTF-8">
<title>每日新闻</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
color: #333;
}
h1 {
text-align: center;
padding: 20px;
background-color: #007bff;
color: white;
margin: 0;
font-size: 24px;
}
.container {
display: block;
padding: 20px;
max-width: 900px;
margin: 0 auto;
}
.image-container {
background-color: white;
border-radius: 10px;
padding: 15px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
margin-bottom: 10px;
}
.image-container img {
max-width: 100%;
height: auto;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.news-item {
background-color: white;
border-radius: 10px;
padding: 15px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
margin-bottom: 10px;
}
.news-item h2 {
font-size: 18px;
color: #000;
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: inherit;
}
a:hover h2 {
color: #0056b3;
}
footer {
text-align: center;
margin-top: 40px;
padding: 20px;
background-color: #333;
color: white;
font-size: 14px;
}
</style>
</head>
<body>
<h1>每日新闻</h1>
<div class="container">
${moyuContent}
${weiyuContent}
${newsContent}
</div>
<footer>感谢您的使用,新闻数据来自摸鱼日报、新闻简报和TopURL</footer>
</body>
</html>
`;
let blob = new Blob([newsPageContent], { type: "text/html; charset=utf-8" });
let url = URL.createObjectURL(blob);
GM_openInTab(url, { active: true }); // Open the page with all news and images
},
ondone() {
resolve();
}
});
} catch (error) {
GM_log(error); // Error handling for TopURL data
GM_notification("解析TopURL数据时发生错误");
reject(error);
}
},
onerror: xhr => {
GM_log(xhr); // Error handling for request failure
GM_notification("TopURL接口请求失败,请检查API是否可访问");
reject(new Error("接口请求失败"));
}
});
} catch (error) {
GM_log(error); // Error handling for Weiyu Jianbao data
GM_notification("解析新闻简报数据时发生错误");
reject(error);
}
},
onerror: xhr => {
GM_log(xhr); // Error handling for request failure
GM_notification("新闻简报接口请求失败,请检查API是否可访问");
reject(new Error("新闻简报接口请求失败"));
}
});
} catch (error) {
GM_log(error); // Error handling for Moyu Ribao data
GM_notification("解析摸鱼日报数据时发生错误");
reject(error);
}
},
onerror: xhr => {
GM_log(xhr); // Error handling for request failure
GM_notification("摸鱼日报接口请求失败,请检查API是否可访问");
reject(new Error("摸鱼日报接口请求失败"));
}
});
});