// ==UserScript== // @name Nuist南信大公告更新检测 // @namespace https://bulletin.nuist.edu.cn/ // @version 2.5 // @description 每日检查 NUIST 公告页的变更,并返回前 10 个非置顶标题,并手动执行和通知变更 // @author QianYu // @crontab * 1-23 once * * // @grant GM.setValue // @grant GM.getValue // @grant GM.registerMenuCommand // @grant GM_xmlhttpRequest // @grant GM_notification // @connect bulletin.nuist.edu.cn // ==/UserScript== (function() { 'use strict'; async function checkForChanges() { GM_xmlhttpRequest({ method: 'GET', url: 'https://bulletin.nuist.edu.cn/791/list.htm', onload: async function(response) { const pageContent = response.responseText; const parser = new DOMParser(); const doc = parser.parseFromString(pageContent, 'text/html'); const currentZdtbTitles = []; const zdtbItems = doc.querySelectorAll('.zdtb a'); zdtbItems.forEach(item => { const title = item.textContent.trim(); currentZdtbTitles.push(title); }); const previousZdtbTitles = await GM.getValue('zdtbTitles', []); let changeDetected = false; if (JSON.stringify(currentZdtbTitles) !== JSON.stringify(previousZdtbTitles)) { changeDetected = true; console.log('置顶标题发生变化!'); } else { console.log('置顶标题无变化。'); } const newsTitles = []; const newsUrls = []; const newsItems = doc.querySelectorAll('.news_list.clearfix .news'); let nonStickyCount = 0; newsItems.forEach((item, index) => { if (!item.querySelector('.zdtb img') && nonStickyCount < 10) { const titleElement = item.querySelector('.news_title .btt a'); const title = titleElement.textContent.trim(); const url = titleElement.href; newsTitles.push(`${nonStickyCount + 1}. ${title}`); newsUrls.push(url); nonStickyCount++; } }); console.log('前10个非置顶公告标题:', newsTitles); if (newsTitles.length > 0) { const newsContent = newsTitles.map((title, index) => `${title} - ${newsUrls[index]}`).join('\n'); GM_notification({ title: changeDetected ? 'NUIST Bulletin Update <有变化>' : 'NUIST Bulletin Update', text: `前10个非置顶公告标题:\n${newsTitles.join('\n')}`, timeout: 0, image: 'https://www.nuist.edu.cn/_upload/tpl/00/43/67/template67/images/logo.png', onclick: () => { window.open(newsUrls[0], '_blank'); } }); console.log('通知已发送'); } else { console.log('没有新的非置顶公告'); } await GM.setValue('zdtbTitles', currentZdtbTitles); } }); } checkForChanges(); GM.registerMenuCommand('手动检查公告变化', checkForChanges); })();