CC98查询粉丝的变动

自动获取所有粉丝名字

目前為 2024-12-29 提交的版本,檢視 最新版本

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

    // 获取当前用户名
    function getUsername() {
        const usernameElement = document.querySelector('.topBarUserName');
        return usernameElement ? usernameElement.textContent.trim() : '';
    }

    // 创建并插入按钮
    function createButtons() {
        const detectButton = document.createElement('button');
        detectButton.textContent = '开始检测粉丝变动';
        detectButton.style.position = 'fixed';
        detectButton.style.top = '10px';
        detectButton.style.left = '10px';
        detectButton.style.zIndex = 1000;
        detectButton.style.padding = '10px';
        detectButton.style.fontSize = '16px';
        detectButton.style.cursor = 'pointer';
        detectButton.addEventListener('click', () => {
            console.log("按钮点击,开始检测粉丝变动...");
            scrapeAllFans();
        });
        document.body.appendChild(detectButton);

        // 创建清空历史记录按钮
        const clearHistoryButton = document.createElement('button');
        clearHistoryButton.textContent = '清空历史记录';
        clearHistoryButton.style.position = 'fixed';
        clearHistoryButton.style.top = '10px';
        clearHistoryButton.style.left = '180px';
        clearHistoryButton.style.zIndex = 1000;
        clearHistoryButton.style.padding = '10px';
        clearHistoryButton.style.fontSize = '16px';
        clearHistoryButton.style.cursor = 'pointer';
        clearHistoryButton.addEventListener('click', () => {
            console.log("清空历史记录...");
            clearHistory();
        });
        document.body.appendChild(clearHistoryButton);

        // 创建历史记录显示区域
        const historyContainer = document.createElement('div');
        historyContainer.id = 'historyContainer';
        historyContainer.style.position = 'fixed';
        historyContainer.style.top = '50px';
        historyContainer.style.left = '10px';
        historyContainer.style.zIndex = 1000;
        historyContainer.style.width = '300px';
        historyContainer.style.height = '500px';
        historyContainer.style.overflowY = 'auto';
        historyContainer.style.border = '1px solid #ccc';
        historyContainer.style.backgroundColor = 'white';
        historyContainer.style.padding = '10px';
        historyContainer.style.fontSize = '14px';
        historyContainer.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
        document.body.appendChild(historyContainer);

        // 在页面加载后显示历史记录
        loadHistory();
    }

    // 从localStorage中读取历史记录
    function getStoredHistoryData() {
        const username = getUsername();
        console.log(`尝试从localStorage获取历史记录,用户名: ${username}`);
        const historyData = localStorage.getItem(`${username}_historyData`);
        console.log(`从localStorage读取到的历史数据: ${historyData}`);
        return JSON.parse(historyData || "[]");
    }

    // 显示历史记录
    function loadHistory() {
        let historyContainer = document.getElementById('historyContainer');
        let history = getStoredHistoryData();
        console.log('加载的历史记录:', history);  // 打印读取到的历史记录,确认是否为空数组

        if (history.length === 0) {
            historyContainer.innerHTML = '暂无历史记录';
        } else {
            // 显示历史记录
            history.forEach(record => {
                historyContainer.innerHTML += `<div>${record}</div>`;
            });
        }
    }

    // 存储历史记录到localStorage
    function storeHistoryData(record) {
        const username = getUsername();
        let history = getStoredHistoryData();
        history.unshift(record);  // 将新的记录添加到数组的最前面
        console.log('准备存储的历史记录:', history);  // 打印准备存储的数据,确认是否正确
        localStorage.setItem(`${username}_historyData`, JSON.stringify(history));
    }

    // 清空历史记录
    function clearHistory() {
        const username = getUsername();
        localStorage.removeItem(`${username}_historyData`);

        // 清空页面上显示的历史记录
        let historyContainer = document.getElementById('historyContainer');
        historyContainer.innerHTML = '暂无历史记录';
    }

    // 页面加载后创建按钮并加载历史记录
    window.addEventListener('load', () => {
        createButtons();
        loadHistory();  // 在页面加载时显示历史记录
    });

})();

QingJ © 2025

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