Greasy Fork is available in English.

大别野[米游社频道]右侧成员栏显示频道用户数,标签位置显示频道创建时间

大别野[米游社频道]右侧成员栏显示频道用户数,标签位置显示频道创建时间。自用

// ==UserScript==
// @name         大别野[米游社频道]右侧成员栏显示频道用户数,标签位置显示频道创建时间
// @name:en   Display Dabieye [Mihoyo channel] members & channel creation time
// @namespace    http://tampermonkey.net/
// @version      0.4.2
// @description  大别野[米游社频道]右侧成员栏显示频道用户数,标签位置显示频道创建时间。自用
// @description:en   Dabieye [Mihoyo channel] right side member column shows the number of channel users, and the label position shows the channel creation time. Self-use
// @author       aspen138
// @match        https://dby.miyoushe.com/*
// @match        https://dby.miyoushe.com/chat/*
// @icon         https://dby.miyoushe.com/favicon.png
// @require      https://update.greasyfork.org/scripts/483208/1302155/ajaxHooker_myaijarvis.js
// @grant        GM_addStyle
// @run-at       document-start
// @license      MIT
// ==/UserScript==
 
 
 
// 定义一个全局对象,用来包装memberNum
var globals = {};
 
 
// Define the updateMemberText function
const updateMemberText = () => {
    console.log("触发updateMemberText");
 
    // Use setInterval to periodically check for the elements
    const intervalId = setInterval(() => {
        var elements = document.querySelectorAll('#__nuxt > div > div > div:nth-child(3) > div > h2');
        console.log(elements);
 
        // Only proceed if elements are found
        if (elements.length > 0) {
            elements.forEach(targetElement => {
                if (targetElement && targetElement.textContent.includes('')) {
                    targetElement.childNodes.forEach((child) => {
                        if (child.nodeType === Node.TEXT_NODE && child.textContent.includes('')) {
                            console.log("这个应该后出现 频道人数函数里", globals.memberNum);
                            child.textContent = globals.memberNum + '名频道成员';
                        }
                    });
                }
            });
 
            // Clear the interval once updates are made
            clearInterval(intervalId);
        }
    }, 100); // Check every 100ms or any other reasonable time interval
};
 
 
//"退出大别野"文字改为更容易理解的"退出此频道"
(function (){
  // Function to observe DOM changes
    const observeDOM = () => {
        // Options for the observer (which mutations to observe)
        const config = {
            childList: true,
            subtree: true
        };
 
        // Callback function to execute when mutations are observed
        const callback = function(mutationsList, observer) {
            for (let mutation of mutationsList) {
                if (mutation.type === 'childList') {
                    changeTextContent();
                }
            }
        };
 
        // Create an observer instance linked to the callback function
        const observer = new MutationObserver(callback);
 
        // Start observing the target node for configured mutations
        observer.observe(document.body, config);
    };
 
    // Function to change the text content
    const changeTextContent = () => {
        // Select the element based on its inner text
        let elements = Array.from(document.querySelectorAll('span'));
        let targetElement = elements.find(el => el.textContent.includes('退出大别野'));
 
        // If the element is found, change its text content
        if (targetElement) {
            targetElement.textContent = '退出此频道';
        }
    };
 
    // Wait for the DOM to be fully loaded
    document.addEventListener('DOMContentLoaded', observeDOM);
})();
 
 
(function() {
    'use strict';
 
    function timestampToTime(timestamp) {
        const milliseconds = timestamp * 1000;
        const date = new Date(milliseconds);
        const year = date.getFullYear();
        const month = addZero(date.getMonth() + 1);
        const day = addZero(date.getDate());
        const hour = addZero(date.getHours());
        const minute = addZero(date.getMinutes());
        const second = addZero(date.getSeconds());
 
        return `${ year }-${ month }-${ day } ${ hour }:${ minute }:${ second }`;
    }
 
    function addZero(num) {
        return num < 10 ? `0${ num }` : `${ num }`;
    }
 
    
 
    ajaxHooker.hook(request => {
        if (request.url.includes("https://bbs-api.miyoushe.com/vila/wapi/villa/v2/getVillaFull")
            // || request.url.includes("https://bbs-api.miyoushe.com/vila/wapi/home/list")
        ) {
            //console.log("成功劫持")
            //console.log(request)
            request.response = res => {
                //console.log('\n== ↓ ↓ ↓ ↓ ↓ == \n', res)
                var jsonString = res.responseText
                try {
                    var json = JSON.parse(jsonString);
                    globals.memberNum = json.data.villa_full_info.villa_info.member_num;
                    var createdAt = timestampToTime(Number(json.data.villa_full_info.villa_info.villa_created_at));
                    console.log("这个应该先出现    频道人数函数里",globals.memberNum)
                    //json.data.villa_full_info.villa_info.tags.push('人数:' + globals.memberNum);
                    setTimeout(updateMemberText(),10*1000);
                    json.data.villa_full_info.villa_info.tags.push('创建时间:' + createdAt);
                    res.responseText = JSON.stringify(json);
                } catch (e) {
                    console.error("Parsing error:", e);
                }
                // GM_addStyle(`
                // .memberNum {
                // 			position: absolute;
                // 			left: 0;
                // 			bottom: -25px;
                // 			color: #999;
                // 		}
                // `);
            }
        }
    });
    // Your code here...
})();