xxhk.org

学习骇客

油猴脚本:微信读书 ⇒ 点击获图

2024 / 8 / 28

// ==UserScript== // @name Copy Image Link on Click // @namespace http://tampermonkey.net/ // @version 1.6 // @description Click on an image to copy its link, then automatically trigger Esc to display a message // @author xxhk // @match *://weread.qq.com/* // @grant GM_setClipboard // ==/UserScript== (function() { 'use strict'; // Custom messages const messages = [ '专注', // 这里添加你的自定义提示内容 '热爱', ]; // Function to copy text to clipboard function copyToClipboard(text) { GM_setClipboard(text, "text"); } // Function to show a temporary message function showTemporaryMessage() { const message = messages[Math.floor(Math.random() * messages.length)]; const msgDiv = document.createElement('div'); msgDiv.style.position = 'fixed'; msgDiv.style.top = '50%'; msgDiv.style.left = '50%'; msgDiv.style.transform = 'translate(-50%, -50%)'; msgDiv.style.backgroundColor = '#333'; msgDiv.style.color = '#fff'; msgDiv.style.padding = '10px'; msgDiv.style.borderRadius = '5px'; msgDiv.style.zIndex = '10000'; msgDiv.textContent = message; document.body.appendChild(msgDiv); setTimeout(() => { document.body.removeChild(msgDiv); }, 1000); } // Event listener for image click document.addEventListener('click', function(e) { if (e.target.tagName.toLowerCase() === 'img') { var imgSrc = e.target.src; copyToClipboard(imgSrc); // Trigger Esc key event const escEvent = new KeyboardEvent('keydown', { key: 'Escape', keyCode: 27, code: 'Escape', which: 27, bubbles: true, cancelable: true }); document.dispatchEvent(escEvent); } }); // Event listener for Esc key document.addEventListener('keydown', function(e) { if (e.key === 'Escape') { showTemporaryMessage(); } }); })();