Greasy Fork

Greasy Fork is available in English.

抖店后台操作增强脚本

为抖店后台添加一些有用的功能,包括获取Cookie、复制目标信息和隐藏商家助手等选项。单击按钮打开功能菜单,点击菜单以外区域可关闭菜单。

当前为 2024-07-28 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         抖店后台操作增强脚本
// @namespace    vip4pt
// @version      1.11
// @description  为抖店后台添加一些有用的功能,包括获取Cookie、复制目标信息和隐藏商家助手等选项。单击按钮打开功能菜单,点击菜单以外区域可关闭菜单。
// @author       vip4pt
// @match        https://fxg.jinritemai.com/ffa/*
// @match        https://im.jinritemai.com/*
// @match        https://buyin.jinritemai.com/dashboard/*
// @match        https://haohuo.jinritemai.com/*
// @grant        GM_setClipboard
// @license      zh-cn
// ==/UserScript==

(function() {
    'use strict';

    var menuVisible = false;
    var assistantHidden = false;

    // 创建按钮容器
    var buttonContainer = document.createElement('div');
    buttonContainer.style.position = 'fixed';
    buttonContainer.style.left = '10px';
    buttonContainer.style.bottom = '60px';
    buttonContainer.style.zIndex = '9999';

    // 创建菜单按钮
    var menuButton = document.createElement('button');
    menuButton.innerHTML = '打开菜单';
    menuButton.style.display = 'block';
    menuButton.style.marginBottom = '10px';
    buttonContainer.appendChild(menuButton);

    // 创建菜单内容
    var menuContent = document.createElement('div');
    menuContent.style.display = 'none';
    menuContent.style.backgroundColor = 'white';
    menuContent.style.border = '1px solid black';
    menuContent.style.padding = '10px';
    buttonContainer.appendChild(menuContent);

    // 创建获取Cookie按钮
    var cookieButton = document.createElement('button');
    cookieButton.innerHTML = '获取Cookie';
    cookieButton.style.display = 'block';
    cookieButton.style.marginBottom = '5px';
    menuContent.appendChild(cookieButton);

    // 创建获取目标信息按钮
    var targetInfoButton = document.createElement('button');
    targetInfoButton.innerHTML = '获取目标信息';
    targetInfoButton.style.display = 'block';
    targetInfoButton.style.marginBottom = '5px';
    menuContent.appendChild(targetInfoButton);

    // 创建选择框
    var toggleDivButton = document.createElement('input');
    toggleDivButton.type = 'checkbox';
    toggleDivButton.style.marginRight = '5px';
    var toggleDivLabel = document.createElement('label');
    toggleDivLabel.innerHTML = '隐藏商家助手';
    toggleDivLabel.appendChild(toggleDivButton);
    menuContent.appendChild(toggleDivLabel);

    // 恢复上次保存的选择框状态
    var savedState = localStorage.getItem('hideAssistant');
    if (savedState === 'hidden') {
        toggleDivButton.checked = true;
        assistantHidden = true;
    }

    // 菜单按钮点击事件处理程序
    menuButton.addEventListener('click', function() {
        toggleMenu();
    });

    // 获取Cookie按钮点击事件处理程序
    cookieButton.addEventListener('click', function() {
        var cookie = document.cookie;
        console.log('Cookie:', cookie);
        GM_setClipboard(cookie);
        showNotification('Cookie已复制到剪贴板');
    });

    // 获取目标信息按钮点击事件处理程序
    targetInfoButton.addEventListener('click', function() {
        var targetElements = document.evaluate("//div[contains(text(), 'ID:')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
        var targetInfoArray = [];
        for (var i = 0; i < targetElements.snapshotLength; i++) {
            var targetElement = targetElements.snapshotItem(i);
            var targetInfo = targetElement.textContent;
            targetInfoArray.push(targetInfo);
        }
        if (targetInfoArray.length > 0) {
            console.log('目标信息:', targetInfoArray);
            GM_setClipboard(targetInfoArray.join('\n'));
            showNotification('目标信息已复制到剪贴板');
        } else {
            console.log('未找到目标信息');
        }
    });


    // 选择框点击事件处理程序
    toggleDivButton.addEventListener('change', function() {
        assistantHidden = toggleDivButton.checked;
        saveAssistantState();
        toggleAssistant();
    });

    // 点击页面其他区域收起菜单
    document.addEventListener('click', function(event) {
        if (menuVisible && !buttonContainer.contains(event.target)) {
            toggleMenu();
        }
    });

    // 初始化MutationObserver,监控页面变化
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (assistantHidden) {
                hideAssistant();
            }
        });
    });

    // 监控整个文档的变化
    observer.observe(document, { childList: true, subtree: true });

    // 切换菜单的显示状态
    function toggleMenu() {
        menuVisible = !menuVisible;
        if (menuVisible) {
            menuButton.innerHTML = '关闭菜单';
            menuContent.style.display = 'block';
        } else {
            menuButton.innerHTML = '打开菜单';
            menuContent.style.display = 'none';
        }
    }

    // 保存商家助手状态到本地存储
    function saveAssistantState() {
        localStorage.setItem('hideAssistant', assistantHidden ? 'hidden' : 'visible');
    }

    // 隐藏元素
    function hideAssistant() {
        var targetClass = 'index_DragController__';
        var elements = document.querySelectorAll('body > div[class*="' + targetClass + '"]');
        elements.forEach(function(element) {
            element.style.display = 'none';
        });
    }

    // 显示元素
    function showAssistant() {
        var targetClass = 'index_DragController__';
        var elements = document.querySelectorAll('body > div[class*="' + targetClass + '"]');
        elements.forEach(function(element) {
            element.style.display = '';
        });
    }

    // 切换商家助手的显示/隐藏状态
    function toggleAssistant() {
        if (assistantHidden) {
            hideAssistant();
        } else {
            showAssistant();
        }
    }

    // 创建提示框
    function showNotification(message) {
        var alertBox = document.createElement('div');
        alertBox.innerHTML = message;
        alertBox.style.position = 'fixed';
        alertBox.style.left = '50%';
        alertBox.style.bottom = '10px';
        alertBox.style.transform = 'translateX(-50%)';
        alertBox.style.padding = '10px';
        alertBox.style.backgroundColor = 'white';
        alertBox.style.border = '1px solid black';
        alertBox.style.zIndex = '9999';
        document.body.appendChild(alertBox);
        setTimeout(function() {
            document.body.removeChild(alertBox);
        }, 3000);
    }

    // 将容器添加到页面
    document.body.appendChild(buttonContainer);
})();