Greasy Fork

Greasy Fork is available in English.

【微赞直播】自动化Faker新版微赞话题管理界面的Bin

在打开微赞后台时,可以在【话题列表页】或【新版话题管理页】自己指定,是否自动打开旧版本管理界面。进入首页后自动打开【视频直播列表】

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         【微赞直播】自动化Faker新版微赞话题管理界面的Bin
// @namespace    https://mdhyy.cn/
// @version      1.2
// @description  在打开微赞后台时,可以在【话题列表页】或【新版话题管理页】自己指定,是否自动打开旧版本管理界面。进入首页后自动打开【视频直播列表】
// @author       明灯花月夜
// @match        https://live.vzan.com/*
// @run-at       document-start
// @grant        none
// @license MIT
// ==/UserScript==



(function() {
    'use strict';

    // 创建开关和文本
    function createToggle() {

        const currentUrl = window.location.href;
        const isCorrectPage = currentUrl.includes('https://live.vzan.com/admin/index.html?zbid=') && currentUrl.includes('TopicManage/TopicSetHome');


        const toggleDiv = document.createElement('div');
        toggleDiv.style.position = 'fixed';
        if (isCorrectPage) {
            toggleDiv.style.top = '80px';
            toggleDiv.style.right = '10px';
        }else{
            toggleDiv.style.top = '10px';
            toggleDiv.style.left = '10px';
        }

        toggleDiv.style.zIndex = '99999999';
        toggleDiv.style.backgroundColor = '#fff';
        toggleDiv.style.border = '3px solid #ccc';
        toggleDiv.style.padding = '10px';
        toggleDiv.style.boxShadow = '0 2px 5px rgba(0,0,0,0.2)';

        const toggleLabel = document.createElement('label');
        toggleLabel.textContent = '自动跳转到旧版话题管理: ';
        const toggleCheckbox = document.createElement('input');
        toggleCheckbox.type = 'checkbox';
        // 从localStorage获取开关状态
        toggleCheckbox.checked = localStorage.getItem('autoRedirectEnabled') === 'true';
        //toggleCheckbox.checked = true; // 默认为选中状态
        toggleLabel.appendChild(toggleCheckbox);

        toggleDiv.appendChild(toggleLabel);
        document.body.appendChild(toggleDiv);

        // 监听开关状态变化
        toggleCheckbox.addEventListener('change', function() {
            localStorage.setItem('autoRedirectEnabled', toggleCheckbox.checked);
        });

        // Make the toggle draggable
        makeDraggable(toggleDiv);
    }





    // Function to make an element draggable
    function makeDraggable(element) {
        let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
        if (document.getElementById(element.id + "header")) {
            document.getElementById(element.id + "header").onmousedown = dragMouseDown;
        } else {
            element.onmousedown = dragMouseDown;
        }

        function dragMouseDown(e) {
            e = e || window.event;
            e.preventDefault();
            pos3 = e.clientX;
            pos4 = e.clientY;
            document.onmouseup = closeDragElement;
            document.onmousemove = elementDrag;
        }

        function elementDrag(e) {
            e = e || window.event;
            e.preventDefault();
            pos1 = pos3 - e.clientX;
            pos2 = pos4 - e.clientY;
            pos3 = e.clientX;
            pos4 = e.clientY;
            element.style.top = (element.offsetTop - pos2) + "px";
            element.style.left = (element.offsetLeft - pos1) + "px";
            element.style.width = element.style.width;
        }

        function closeDragElement() {
            document.onmouseup = null;
            document.onmousemove = null;
        }
    }



    // 跳转函数
    function redirectToNewUrl() {
        const currentUrl = window.location.href;
        const isCorrectPage = currentUrl.includes('https://live.vzan.com/admin/index.html?zbid=') && currentUrl.includes('TopicManage/TopicSetHome');

        if (isCorrectPage) {
            const queryParams = new URLSearchParams(window.location.search);
            const zbid = queryParams.get('zbid');
            const hash = window.location.hash;
            const topicIdMatch = hash.match(/topicId=([0-9]+)/);
            const topicId = topicIdMatch ? topicIdMatch[1] : null;

            if (zbid && topicId) {
                const newUrl = `https://live.vzan.com/nlive/navmenu?zid=${zbid}&tid=${topicId}&backurl=TopicEditV2`;

                // 如果开关为开启状态,则跳转
                if (document.querySelector('input[type="checkbox"]').checked) {

                    showModal('正在跳转到旧版管理界面...');

                    window.location.href = newUrl;
                    // 设置延时来点击包含 '账号登录' 的 span 元素

                }
            } else {
                console.log('zbid or topicId is missing in the URL');
            }
        }
    }




    // 等待DOM加载完毕后添加开关
    window.addEventListener('load', function() {
        //监听函数START
        const currentUrl = window.location.href;
        const isCorrectPage = currentUrl.includes('https://live.vzan.com/admin/index.html?zbid=') && currentUrl.includes('TopicManage/TopicSetHome');
        const isCorrectPage2 = currentUrl.includes('https://live.vzan.com/admin/index.html?zbid=') && currentUrl.includes('#/Live/Topic');

        if (isCorrectPage||isCorrectPage2) {
            createToggle();
        }
        redirectToNewUrl(); // 尝试自动跳转



        // 检查是否为登录页面
        if (currentUrl.includes('/login')||currentUrl.includes('workbench')) {
            // 设置登录状态为0并保存到localStorage
            localStorage.setItem('isLoggedOut', '0');

            // 调用函数以显示弹窗,例如:
            showModal('状态重置,下次打开【直播管理】界面,会自动跳转到【视频直播列表】');

        }

        // 从localStorage获取登录状态
        var isLoggedOut = localStorage.getItem('isLoggedOut');
        if (isLoggedOut === '0') {

            // 检查是否需要跳转
            if (currentUrl.includes('industry-center/agent-promotion/liveTopic')) {

                showCountdown();
                // 设置延时来跳转到列表
                setTimeout(function() {


                    // 提取zbid参数
                    const queryParams = new URLSearchParams(window.location.search);
                    const zbid = queryParams.get('zbid');


                    var storedZbid = zbid;
                    // 构建跳转URL
                    var redirectUrl = 'https://live.vzan.com/admin/index.html?zbid=' + storedZbid + '#/Live/Topic';
                    // 跳转到新地址
                    window.location.href = redirectUrl;
                    // 重置登录状态
                    localStorage.setItem('isLoggedOut', '1');




                }, 4000); // 延迟2秒后执行点击

            }// 检查是否需要跳转
        }//判断 是否为0


        //网页加载完毕 监听函数END
    });









    function showCountdown() {
        // 创建一个div元素用于显示倒计时
        var countdownDiv = document.createElement('div');
        countdownDiv.style.position = 'fixed';
        countdownDiv.style.top = '0';
        countdownDiv.style.left = '50%';
        countdownDiv.style.transform = 'translate(-50%, 0)';
        countdownDiv.style.width = '100%';
        countdownDiv.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
        countdownDiv.style.color = '#fff';
        countdownDiv.style.textAlign = 'center';
        countdownDiv.style.padding = '10px 0';
        countdownDiv.style.zIndex = '9999';
        countdownDiv.style.fontSize = '24px';
        countdownDiv.style.fontFamily = 'Arial, sans-serif';
        document.body.appendChild(countdownDiv);

        // 设置倒计时时间为4秒
        var countdown = 4;

        // 更新倒计时的函数
        var updateCountdown = function() {
            countdownDiv.textContent = '801微赞助手:倒计时: ' + countdown + ' 秒后,跳转直播列表界面。';
            countdown -= 1;

            if (countdown < 0) {
                // 倒计时结束,移除倒计时提示
                clearInterval(intervalId);
                document.body.removeChild(countdownDiv);
            }
        };

        // 每秒更新一次倒计时
        var intervalId = setInterval(updateCountdown, 1000);

        // 立即开始倒计时
        updateCountdown();
    }




























    function showModal(message) {
        // 创建一个div元素用于显示弹窗
        var modalDiv = document.createElement('div');
        modalDiv.style.position = 'fixed';
        modalDiv.style.top = '0';
        modalDiv.style.left = '50%';
        modalDiv.style.transform = 'translateX(-50%)';
        modalDiv.style.width = '100%';
        modalDiv.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
        modalDiv.style.color = '#fff';
        modalDiv.style.textAlign = 'center';
        modalDiv.style.padding = '10px 0';
        modalDiv.style.zIndex = '9999';
        modalDiv.style.fontSize = '24px';
        modalDiv.style.fontFamily = 'Arial, sans-serif';
        modalDiv.textContent = "801微赞助手:"+message;
        document.body.appendChild(modalDiv);

        // 设置延迟时间为3秒
        var delay = 3000;

        // 延迟后关闭弹窗的函数
        var closeModal = function() {
            document.body.removeChild(modalDiv);
        };

        // 设置延迟关闭弹窗
        setTimeout(closeModal, delay);
    }





})();