CC98查询粉丝的变动

to find out how my fans change

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

// ==UserScript==
// @name         CC98查询粉丝的变动
// @namespace    http://tampermonkey.net/
// @version      v2.1
// @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;

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

    // 读取当前页的粉丝
    function fetchFans(page, currentFans) {
        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 = doc.querySelectorAll('.user-center-myfans-exact .user-center-myfollowings-user');

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

                // 翻页
                if (page < totalPages) {
                    fetchFans(page + 1, currentFans);
                } else {
                    // 所有页面读取完毕,进行对比
                    compareFans(currentFans);
                }
            }
        });
    }

    function compareFans(currentFans) {
        const previousFans = new Set(JSON.parse(localStorage.getItem('fansList') || '[]'));

        // 对比粉丝
        const addedFans = [...currentFans].filter(fan => !previousFans.has(fan));
        const removedFans = [...previousFans].filter(fan => !currentFans.has(fan));

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

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

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

    // 页面加载时获取总页数并开始读取粉丝
    getTotalPages();
    fetchFans(currentPage, new Set());
})();

QingJ © 2025

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