Greasy Fork

来自缓存

Greasy Fork is available in English.

nodeseek关键词监控

nodeseek关键词监控着

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         nodeseek关键词监控
// @version      0.1
// @description  nodeseek关键词监控着
// @author       Damon
// @namespace   *://*.nodeseek.com/*
// @match       *://*.nodeseek.com/*
// @grant        none
// @license MIT
// ==/UserScript==



(async function() {
    'use strict';

    const telegramToken = '';
     
    const chatId = '';
    

    const sendTelegramMessage = async (text) => {
        const apiUrl = `https://api.telegram.org/bot${telegramToken}/sendMessage`;
        const response = await fetch(apiUrl, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                chat_id: chatId,
                text: text
            }),
        });
        return response.json();
    };


    const feishuApi = "";

    const sendFeishuMessage = async (text) => {
         fetch(feishuApi, {
              method: 'POST',
              headers: {
                  'Content-Type': 'application/json',
              },
              body: JSON.stringify({
                msg_type: "text",
                content: {
                  text: con,
                },
              }),
          });
    };


    const fetchWithTimeout = async (url, timeout) => {
        const controller = new AbortController();
        const timeoutId = setTimeout(() => controller.abort(), timeout);

        try {
            const response = await fetch(url, { signal: controller.signal });
            clearTimeout(timeoutId);
            return response;
        } catch (error) {
            clearTimeout(timeoutId);
            throw error;
        }
    };






    const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

    var k = 1;

    // 遍历每页
    for (let page = 1; page <= 1; page++) {
        k++;
        console.log(`Fetching page ${page}`);

        try {

        // 发送 Fetch 请求
        const response = await fetchWithTimeout('https://www.nodeseek.com/', 10000); // 10秒超时
        const html = await response.text();

        if (!response.ok) {
            throw new Error(`Fetch request failed with status: ${response.status}`);
        }

        // 解析 HTML
        const parser = new DOMParser();
        const doc = parser.parseFromString(html, 'text/html');

        // 处理每个 tbody
        const tbodies = doc.querySelectorAll('.post-title');
        tbodies.forEach(tbody => {
            const links = tbody.querySelectorAll('a');
            links.forEach(link => {
                if (link.textContent.includes("无忧")) {
                    if (!localStorage.getItem(link.href)) {
                        localStorage.setItem(link.href, true);

                        var msg = `-------------------------\n检测到【无忧】关键词\n-------------------------\n标题: ${link.textContent}\n链接: ${link.href}\n-------------------------`;
                        // 发送到 Telegram
                        sendTelegramMessage(msg);

                      console.log('New link found and saved:', link.href);
                      console.log(link.textContent);
                    } else {
                      console.log('Existing link:', link.href);
                    }
                }
            });
        });

        } catch (error) {
            // 处理超时或其他错误
            console.error(error);
            // 刷新当前页面
            location.reload();
        }

        // 每页请求后休眠15秒
        // if (page < 2) {
        //     await sleep(6000);
        // }
        // 每页请求后休眠15秒
        // if (page == 2) {
            await sleep(81000);
            page = 0;
        // }

        if (k == 10) {
          location.reload();
        }
    }
})();