CC98查询粉丝的变动

自动获取所有粉丝名字

当前为 2024-12-29 提交的版本,查看 最新版本

// ==UserScript==
// @name         CC98查询粉丝的变动
// @namespace    http://tampermonkey.net/
// @version      3.1
// @description  自动获取所有粉丝名字
// @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 allFans = [];

    // 创建弹窗元素
    function createPopup() {
        let popup = document.createElement('div');
        popup.id = 'fansPopup';
        popup.style.position = 'fixed';
        popup.style.top = '50%';
        popup.style.left = '50%';
        popup.style.transform = 'translate(-50%, -50%)';
        popup.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
        popup.style.color = '#fff';
        popup.style.padding = '20px';
        popup.style.borderRadius = '10px';
        popup.style.zIndex = '9999';
        popup.style.maxWidth = '80%';
        popup.style.maxHeight = '70%';
        popup.style.overflow = 'auto';
        popup.style.fontSize = '16px';
        popup.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.5)';
        popup.style.display = 'none';  // 初始隐藏
        document.body.appendChild(popup);
        return popup;
    }

    // 打开弹窗并显示内容
    function openPopup(content) {
        let popup = document.getElementById('fansPopup');
        popup.innerHTML = content;
        popup.style.display = 'block';
    }

    // 关闭弹窗
    function closePopup() {
        let popup = document.getElementById('fansPopup');
        popup.style.display = 'none';
    }

    // 获取当前页粉丝数据的方法
    function getFansFromCurrentPage() {
        let fanElements = document.querySelectorAll('.user-center-myfollowings-user');
        let fans = Array.from(fanElements).map(el => {
            let name = el.querySelector('.user-center-myfollowings-user-id a').textContent.trim();
            let followers = el.querySelector('.user-center-myfollowings-user-fans').textContent.trim();
            return { name, followers };
        });
        return fans;
    }

    // 获取所有页码链接的方法
    function getAllPageLinks() {
        let pageElements = document.querySelectorAll('#userCenterPageCount a');
        let links = Array.from(pageElements).map(el => el.href);
        return links;
    }

    // 模拟逐页抓取数据
    async function scrapeAllFans() {
        let pageLinks = getAllPageLinks(); // 获取所有页码的链接
        let previousFansCount = allFans.length;

        for (let i = 0; i < pageLinks.length; i++) {
            console.log(`正在抓取第 ${i + 1} 页...`);
            window.location.href = pageLinks[i];

            // 等待页面加载完成(调整时间根据实际情况)
            await new Promise(resolve => setTimeout(resolve, 2000));

            // 抓取当前页的粉丝数据
            let fans = getFansFromCurrentPage();
            allFans.push(...fans);

            console.log(`第 ${i + 1} 页粉丝获取完成:`, fans);
        }

        console.log('所有粉丝数据已获取:', allFans);

        // 获取变化的粉丝
        let newFans = allFans.slice(previousFansCount);
        let removedFans = []; // 如果有移除粉丝的逻辑,可以添加

        // 显示变化
        let changeContent = `<strong>粉丝变化:</strong><br><br>新增粉丝:<br>${newFans.map(fan => fan.name).join("<br>")}`;
        openPopup(changeContent);
    }

    // 页面加载完成后开始抓取
    window.onload = () => {
        createPopup(); // 创建弹窗
        scrapeAllFans();
    };
})();

QingJ © 2025

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