Greasy Fork

Greasy Fork is available in English.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         自动化Faker新版微赞话题管理界面的Bin
// @namespace    https://mdhyy.cn/
// @version      1.0
// @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 = '1px 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 = "150px";
        }

        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) {
                    window.location.href = newUrl;
                }
            } else {
                console.log('zbid or topicId is missing in the URL');
            }
        }
    }

    // 等待DOM加载完毕后添加开关
    window.addEventListener('DOMContentLoaded', function() {

        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(); // 尝试自动跳转
    });
})();