|
|
本帖最后由 Makima 于 2025-10-5 10:44 编辑
双击右键勋章(GIF图片
会自动复制 插入图片的链接
适用于勋章放大镜

- // ==UserScript==
- // @name 双击右键复制gif
- // @version 0.1
- // @author MKM
- // @match https://www.gamemale.com/*
- // @grant GM_setClipboard
- // ==/UserScript==
- (function() {
- 'use strict';
- let lastRightClickTime = 0;
- let lastRightClickTarget = null;
- document.addEventListener('contextmenu', function(event) {
- const target = event.target;
- if (target.tagName === 'IMG' && isGifImage(target)) {
- const currentTime = Date.now();
- if (currentTime - lastRightClickTime < 500 && lastRightClickTarget === target) {
- event.preventDefault();
- event.stopPropagation();
- const formattedText = `[img]${target.src}[/img]`;
- GM_setClipboard(formattedText, 'text');
- showNotification('✅已复制', event.clientX, event.clientY);
- }
- lastRightClickTime = currentTime;
- lastRightClickTarget = target;
- } else {
- lastRightClickTarget = null;
- }
- }, true);
- function isGifImage(imgElement) {
- if (!imgElement.src) return false;
- const src = imgElement.src.toLowerCase();
- if (src.endsWith('.gif') || src.includes('.gif?')) {
- return true;
- }
- if (imgElement.srcset && imgElement.srcset.toLowerCase().includes('.gif')) {
- return true;
- }
- try {
- const url = new URL(src, window.location.href);
- return url.pathname.toLowerCase().endsWith('.gif');
- } catch {
- return false;
- }
- }
- function showNotification(message, x, y) {
- const notification = document.createElement('div');
- notification.style.cssText = `
- position: fixed;
- left: ${x + 10}px;
- top: ${y + 10}px;
- background: #4CAF50;
- color: white;
- padding: 8px 12px;
- border-radius: 4px;
- z-index: 100000;
- font-family: Arial, sans-serif;
- font-size: 12px;
- font-weight: bold;
- box-shadow: 0 2px 8px rgba(0,0,0,0.3);
- transition: all 0.3s ease;
- pointer-events: none;
- `;
- notification.textContent = message;
- document.body.appendChild(notification);
- setTimeout(() => {
- notification.style.opacity = '0';
- notification.style.transform = 'translateY(-10px)';
- setTimeout(() => notification.remove(), 300);
- }, 1000);
- }
- })();
复制代码
|
|