CC98查询粉丝的变动

to find out how my fans change

目前為 2024-09-13 提交的版本,檢視 最新版本

// ==UserScript==
// @name         CC98查询粉丝的变动
// @namespace    http://tampermonkey.net/
// @version      v1.8
// @description  to find out how my fans change
// @author       Lay
// @match        https://www.cc98.org/usercenter/myfans/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @license      AGPL -3.0 
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';
    let currentPage = 1;
    let totalPages = 1; // 初始化总页数为1

    // 获取总页数
    function getTotalPages() {
        const pageCountElement = document.querySelector('#userCenterPageCount ul');
        if (pageCountElement) {
            const pageItems = pageCountElement.querySelectorAll('li');
            totalPages = pageItems.length; // 更新总页数
        }
    }

    function fetchFans(page) {
        const url = `https://www.cc98.org/usercenter/myfans/${page}`;
        
        GM_xmlhttpRequest({
            method: "GET",
            url: url,
            onload: function(response) {
                const parser = new DOMParser();
                const doc = parser.parseFromString(response.responseText, 'text/html');
                const fansElements = document.querySelectorAll('.user-center-myfans-exact .user-center-myfollowings-user');

                const currentFans = new Set();
                fansElements.forEach(element => {
                    const userIdElement = element.querySelector('.user-center-myfollowings-user-id a');
                    if (userIdElement) {
                        currentFans.add(userIdElement.textContent.trim());
                    }
                });

                console.log('当前粉丝:', [...currentFans].join(', '));

                const previousFans = new Set(JSON.parse(localStorage.getItem('fansList') || '[]'));
                checkForChanges(currentFans, previousFans);

                // 更新存储的粉丝列表
                localStorage.setItem('fansList', JSON.stringify([...currentFans]));

                // 翻页
                if (currentPage < totalPages) {
                    currentPage++;
                    fetchFans(currentPage);
                }
            }
        });
    }

    function checkForChanges(currentFans, previousFans) {
        const addedFans = [...currentFans].filter(fan => !previousFans.has(fan));
        const removedFans = [...previousFans].filter(fan => !currentFans.has(fan));

        if (addedFans.length > 0) {
            alert('新增加的粉丝: \n' + addedFans.join(', \n'));
        }

        if (removedFans.length > 0) {
            alert('减少的粉丝: \n' + removedFans.join(', \n'));
        }
    }

    // 页面加载时获取总页数并检查粉丝变化
    getTotalPages();
    fetchFans(currentPage);

    // 每隔5分钟检查一次(300000毫秒)
    setInterval(fetchFans, 300000);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址