// ==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 = `

摸鱼日报图片

摸鱼日报图片
`; } // Create content from Weiyu Jianbao let weiyuImageUrl = weiyuData.data; let weiyuContent = ''; if (weiyuImageUrl) { weiyuContent = `

新闻简报图片

新闻简报图片
`; } // 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 += `

${index + 1}. ${newsItem.title}

`; }); } else { newsContent = `

没有获取到新闻内容,请稍后再试。

`; } // 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 = ` 每日新闻

每日新闻

${moyuContent} ${weiyuContent} ${newsContent}
`; 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("摸鱼日报接口请求失败")); } }); });