您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds FloatingWindow
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/477480/1266847/FloatingWindow.js
// ==UserScript== // @name FloatingWindow // @version 1.1 // @grant GM_addStyle // @grant GM_getValue // @grant GM_setValue // @description Adds FloatingWindow // ==/UserScript== GM_addStyle(` .floatingWindowContainer { width:200px; position:fixed; opacity:0.5; z-index: 9999; } .floatingWindowTitleBar { background-color:#fff; font-weight:bold; text-align:center; cursor:pointer; } .floatingWindowContainer.active { opacity:1; z-index: 10000; } .floatingWindowBody{ flex-wrap:wrap; } `); class FloatingWindow { constructor(title,settings = {}) { this.settings = { position:settings?.position || {x:window.innerWidth*0.8,y:100}, open: settings.hasOwnProperty("open") ? settings.open : true, bodyDisplay:settings?.bodyDisplay || "block" } this.container = document.createElement("div"); this.container.className = "floatingWindowContainer"; this.container.id = title.replaceAll(/\W+/g,"_"); this.windowPosition = GM_getValue(`${this.container.id}_position`,this.settings.position); this.container.style.left = `${this.windowPosition.x}px`; this.container.style.top = `${this.windowPosition.y}px`; this.titleBar = document.createElement("div"); this.titleBar.className = "floatingWindowTitleBar"; this.titleBar.appendChild(document.createTextNode(title)); this.titleBar.addEventListener("click",()=>{this.toggleWindow();}) this.titleBar.addEventListener("dragstart",(e)=>{this.dragStartHandler(e);}) this.titleBar.addEventListener("drag",(e)=>{this.dragHandler(e);}) this.titleBar.addEventListener("dragend",(e)=>{this.dragEndHandler(e);}) document.body.addEventListener("dragenter",(e)=>{ if (this.pointerValues.positionOffset) { e.dataTransfer.dropEffect = "move"; } }) // this.titleBar.addEventListener("pointerdown",(e)=>{this.pointerDownHandler(e);}); // this.titleBar.addEventListener("pointermove",(e)=>{this.pointerMoveHandler(e);}); // this.titleBar.addEventListener("pointerleave",(e)=>{this.pointerMoveHandler(e);}); // this.titleBar.addEventListener("pointerout",(e)=>{this.pointerMoveHandler(e);}); // this.titleBar.addEventListener("pointerup",(e)=>{this.pointerUpHandler(e);}); this.titleBar.draggable = true; this.container.appendChild(this.titleBar); this.body = document.createElement("div"); this.body.className = "floatingWindowBody"; this.windowOpen = GM_getValue(`${this.container.id}_open`,this.settings.open); if (this.windowOpen) this.container.classList.add("active"); this.body.style.display = this.windowOpen ? this.settings.bodyDisplay : "none"; this.container.appendChild(this.body); document.body.appendChild(this.container); this.pointerValues = { newPosition:null, positionOffset:null }; } toggleWindow() { this.windowOpen = !this.windowOpen; this.container.classList.toggle("active"); GM_setValue(`${this.container.id}_open`,this.windowOpen); this.body.style.display = this.windowOpen ? this.settings.bodyDisplay : "none"; } dragStartHandler(e) { this.pointerValues.positionOffset = { x:e.clientX - this.windowPosition.x, y:e.clientY - this.windowPosition.y }; e.dataTransfer.effectAllowed = "move"; } dragHandler(e) { if (this.pointerValues.positionOffset) { this.pointerValues.newPosition = { x:e.clientX - this.pointerValues.positionOffset.x, y:e.clientY - this.pointerValues.positionOffset.y }; } } dragEndHandler(e) { e.preventDefault(); this.pointerValues.newPosition = { x:e.clientX - this.pointerValues.positionOffset.x, y:e.clientY - this.pointerValues.positionOffset.y }; this.container.style.left = `${this.pointerValues.newPosition.x}px`; this.container.style.top = `${this.pointerValues.newPosition.y}px`; this.windowPosition = this.pointerValues.newPosition; GM_setValue(`${this.container.id}_position`,this.windowPosition); this.pointerValues.dragging = false; this.pointerValues.positionOffset = this.pointerValues.newPosition = null; } }