NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name liblib.art快捷粘贴 // @namespace http://tampermonkey.net/ // @version 2025-04-27 // @description liblib.art快捷粘贴 // @author van // @license AGPL-3.0-or-later // @grant none // @include *://*.liblib.art/* // ==/UserScript== (function() { 'use strict'; let inited = false let intervalIdx = undefined let init = function(){ if(inited)return; var currentInput // 监听全局粘贴事件 document.addEventListener('paste', async (event) => { const fileInput = currentInput; // 1. 获取剪贴板数据 const clipboardItems = event.clipboardData?.items || []; // 2. 查找图片数据 for (const item of clipboardItems) { if (item.type.startsWith('image/')) { if(!fileInput){ alert("鼠标请放在控件上,再粘贴") return } // 3. 获取图片Blob对象 const blob = item.getAsFile(); // 4. 创建DataTransfer对象并填充 const dataTransfer = new DataTransfer(); dataTransfer.items.add(blob); // 5. 赋值给文件输入框 fileInput.files = dataTransfer.files; // 6. 触发change事件(如果需要) fileInput.dispatchEvent(new Event('change')); // 7. 预览图片(可选) const previewUrl = URL.createObjectURL(blob); console.log('图片预览URL:', previewUrl); break; } } }); // 检查元素及其所有父级元素的display属性 function isElementHidden(element) { if (!element) return true; // 检查当前元素是否隐藏 if (element.style.display === 'none') { return true; } // 获取计算样式 const computedStyle = window.getComputedStyle(element); if (computedStyle.display === 'none') { return true; } // 递归检查父级元素 if (element.parentElement) { return isElementHidden(element.parentElement); } return false; } document.addEventListener('mousemove', (e) => { // 获取所有符合条件的input元素 const fileInputs = document.querySelectorAll( 'input[type="file"][accept*="jpeg"]' ); // 遍历并检查每个元素 fileInputs.forEach(input => { if (!isElementHidden(input)) { const rect = input.getBoundingClientRect(); const isHovering = ( e.clientX >= rect.left && e.clientX <= rect.right && e.clientY >= rect.top && e.clientY <= rect.bottom ); if(isHovering){ input.parentElement.style.border = '4px solid #27ae60'; currentInput = input }else{ input.parentElement.style.border = '0px solid #27ae60'; if(input == currentInput){ currentInput = undefined } } } }); }); inited = true; if(intervalIdx){ clearInterval(intervalIdx) intervalIdx = undefined } } window.onload = function() { init() } intervalIdx = setInterval(init, 1000) })();