// ==UserScript== // @name WebDroid // @namespace https://bbs.tampermonkey.net.cn/ // @version 1.1.0 // @description 一个侧边手机模拟容器 // @author 黎墨秋 // @match *://*/* // @grant GM_addStyle // ==/UserScript== (function() { 'use strict'; /** * 【环境守卫】 * 判定当前脚本运行的环境。 * 如果 window.self !== window.top,说明脚本正运行在一个 iframe 内部。 */ if (window.self !== window.top) { return; // 直接退出,不在任何 iframe 或广告弹窗内运行 } // ================= 配置区 ================= const CONFIG = { url: "https://webdroid.vosphere.cn", // 替换为你的链接 width: 380, ballColor: "#333333", }; // 1. 注入样式 GM_addStyle(` #webdroid-ball { position: fixed; right: 10px; top: 50%; width: 45px; height: 45px; background: ${CONFIG.ballColor}; color: white; border-radius: 50%; cursor: move; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 15px rgba(0,0,0,0.3); z-index: 2147483647; transition: transform 0.2s; font-family: sans-serif; font-size: 10px; font-weight: bold; user-select: none; border: 2px solid rgba(255,255,255,0.2); } #webdroid-container { position: fixed; top: 0; right: -${CONFIG.width + 20}px; width: ${CONFIG.width}px; height: 100vh; background: #fff; box-shadow: -10px 0 30px rgba(0,0,0,0.2); z-index: 2147483646; transition: right 0.4s cubic-bezier(0.075, 0.82, 0.165, 1); display: flex; flex-direction: column; border-left: 1px solid #ddd; } #webdroid-container.open { right: 0; } .droid-status-bar { height: 30px; background: #f1f1f1; display: flex; align-items: center; justify-content: center; flex-shrink: 0; } .droid-status-bar::after { content: ""; width: 50px; height: 5px; background: #bbb; border-radius: 10px; } #webdroid-iframe { flex: 1; border: none; width: 100%; height: 100%; } `); // 2. 创建元素 const ball = document.createElement('div'); ball.id = 'webdroid-ball'; ball.innerHTML = 'Droid'; document.body.appendChild(ball); const container = document.createElement('div'); container.id = 'webdroid-container'; container.innerHTML = `
`; document.body.appendChild(container); // 3. 逻辑控制 let isOpen = false; let isDragging = false; ball.addEventListener('click', () => { if (isDragging) return; isOpen = !isOpen; if (isOpen) { container.classList.add('open'); ball.style.right = `${CONFIG.width + 10}px`; ball.innerHTML = 'CLOSE'; ball.style.background = '#ff4444'; } else { container.classList.remove('open'); ball.style.right = '10px'; ball.innerHTML = 'Droid'; ball.style.background = CONFIG.ballColor; } }); // 4. 垂直拖拽逻辑 ball.onmousedown = function(e) { let startY = e.clientY - ball.offsetTop; isDragging = false; document.onmousemove = function(ev) { isDragging = true; let y = ev.clientY - startY; if (y < 0) y = 0; if (y > window.innerHeight - 50) y = window.innerHeight - 50; ball.style.top = y + 'px'; }; document.onmouseup = function() { document.onmousemove = null; document.onmouseup = null; setTimeout(() => { isDragging = false; }, 100); }; }; })();