跳到正文

剪贴板

剪贴板 ge54v7hj

原文
剪贴板信息

剪贴板信息

收录
更新
代码
// ==UserScript==
// @name         Luogu Team Quick Access(made by fire_star_)
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  蓝色可右键拖拽圆球,右键可以打开团队快捷菜单
// @author       fire_star_
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const ball = document.createElement('div');
    ball.style.position = 'fixed';
    ball.style.width = '40px';
    ball.style.height = '40px';
    ball.style.backgroundColor = '#3498db';
    ball.style.borderRadius = '50%';
    ball.style.cursor = 'move';
    ball.style.zIndex = '9999';
    ball.style.right = '40px';
    ball.style.bottom = '40px';
    ball.style.boxShadow = '0 2px 10px rgba(0,0,0,0.2)';
    let isDragging = false;
    let offsetX, offsetY;
    ball.addEventListener('mousedown', (e) => {
        if (e.button === 0) {
            isDragging = true;
            offsetX = e.clientX - ball.getBoundingClientRect().left;
            offsetY = e.clientY - ball.getBoundingClientRect().top;
            ball.style.cursor = 'grabbing';
        }
    });
    document.addEventListener('mousemove', (e) => {
        if (isDragging) {
            ball.style.left = (e.clientX - offsetX) + 'px';
            ball.style.top = (e.clientY - offsetY) + 'px';
            ball.style.right = 'unset';
            ball.style.bottom = 'unset';
        }
    });

    document.addEventListener('mouseup', () => {
        isDragging = false;
        ball.style.cursor = 'move';
    });

    const menu = document.createElement('div');
    menu.style.position = 'absolute';
    menu.style.backgroundColor = 'white';
    menu.style.borderRadius = '4px';
    menu.style.boxShadow = '0 2px 10px rgba(0,0,0,0.1)';
    menu.style.padding = '8px 0';
    menu.style.minWidth = '120px';
    menu.style.display = 'none';
    menu.style.zIndex = '10000';

    const createMenuItem = (text, color, url) => {
        const item = document.createElement('div');
        item.textContent = text;
        item.style.padding = '8px 16px';
        item.style.cursor = 'pointer';
        item.style.color = color;
        item.addEventListener('click', () => {
            window.open(url, '_blank');
            menu.style.display = 'none';
        });
        item.addEventListener('mouseenter', () => {
            item.style.backgroundColor = '#f5f5f5';
        });
        item.addEventListener('mouseleave', () => {
            item.style.backgroundColor = 'transparent';
        });
        return item;
    };

    menu.appendChild(createMenuItem('示例一', '#3498db', 'https://www.luogu.com.cn/team/xxxxxx'));
    menu.appendChild(createMenuItem('示例二', '#e74c3c', 'https://www.luogu.com.cn/team/xxxxxx'));

    ball.addEventListener('contextmenu', (e) => {
        e.preventDefault();
        menu.style.display = 'block';
        menu.style.left = (e.clientX - 10) + 'px';
        menu.style.top = (e.clientY - 10) + 'px';
    });

    document.addEventListener('click', (e) => {
        if (!menu.contains(e.target) && e.target !== ball) {
            menu.style.display = 'none';
        }
    });

    document.body.appendChild(ball);
    document.body.appendChild(menu);
})();