0

【青龙脚本】不知道论坛有人回复?监控论坛新消息通知脚本

发表于:5 天前 攻略分享 42
本帖最后由 念。 于 2024-10-15 10:46 编辑

1、首先安装青龙面板(飞牛商店自带,不再赘述)

2、进入青龙面板Web页面,跟随图示操作


3、请检查是否安装过axios和cheerio依赖。检查方式如下图


4、依赖安装完成后,编辑上述添加的js脚本文件,并粘贴复制以下代码

  1. const axios = require("axios");
  2. const cheerio = require("cheerio");

  3. // 填写对应的 Cookie 值
  4. const cookies = {
  5.     'pvRK_2132_saltkey': '*****',
  6.     'pvRK_2132_auth': '*******',
  7. };
  8. const cookieHeader = Object.entries(cookies)
  9.     .map(([key, value]) => `${key}=${value}`)
  10.     .join("; ");

  11. async function checkForNewReminders() {
  12.     try {
  13.         const response = await axios.get(
  14.             "https://club.fnnas.com/home.php?mod=space&do=notice",
  15.             { headers: { Cookie: cookieHeader } }
  16.         );

  17.         const $ = cheerio.load(response.data);

  18.         // 检查是否有新提醒,通过检测 dd.ntc_body 的 style
  19.         let hasNewReminders = false;
  20.         $('.nts .cl .ntc_body').each((index, element) => {
  21.             const styleAttr = $(element).attr('style');
  22.             if (styleAttr && styleAttr.includes('color:#000;font-weight:bold;')) {
  23.                 hasNewReminders = true;
  24.                 return false; // 结束循环
  25.             }
  26.         });

  27.         if (hasNewReminders) {
  28.             console.log("有新提醒!");

  29.             // 提取前五条信息
  30.             const notifications = [];
  31.             $('.nts .cl').slice(0, 5).each((index, element) => {
  32.                 const time = $(element).find('dt .xg1 span').first().text().trim();
  33.                 const timeStyled = `<span style="color: red;">${time}</span>`;
  34.                 const content = $(element).find('.ntc_body').text().trim();

  35.                 notifications.push(`${timeStyled}:${content}`);
  36.             });

  37.             if (notifications.length > 0) {
  38.                 console.log("前五条通知信息:");
  39.                 notifications.forEach((notification, index) => {
  40.                     console.log(`${index + 1}: ${notification}`);
  41.                 });

  42.                 var notify = require("./sendNotify");
  43.                 await notify.sendNotify('飞牛论坛新提醒', notifications.join("\n"));
  44.             }
  45.         } else {
  46.             console.log("没有新提醒");
  47.         }
  48.     } catch (error) {
  49.         console.error("获取通知信息失败:", error);
  50.     }
  51. }

  52. // 调用方法
  53. checkForNewReminders();
复制代码


5、获取脚本中的'pvRK_2132_saltkey': '*****','pvRK_2132_auth': '********'
     去飞牛社区首页页面获取cookie,F12打开开发者模式,然后找到Network(网络)点击misc.php找到 浏览器不一样显示可能有点差异,如未找到请在控制台打开状态下刷新页面。


6、获取到后,编辑脚本文件,并替换对应的值。
7、进入定时任务页面添加新的定时任务


8、添加完成后,手动运行一下进行测试。
9、测试图


结语:此举仅仅是为了更方便的去获取论坛的回复和提醒。建议大家不要设置较短间隔,以免对论坛服务器造成太大压力。



收藏
送赞
分享

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

发表回复