// ==UserScript== // @name Pinterest Ultra Assistant V7.0 (Ultimate User Experience) // @namespace http://tampermonkey.net/ // @version 7.0 // @description Adds a prominent Close button, ESC key support, and Fit-to-Screen view. Optimized for speed and comfort. // @author Pi Xiao // @match https://*.pinterest.com/* // @grant GM_openInTab // @grant GM_setClipboard // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; const BRIDGE_PAGE = "https://meishubiji.cn/ai-processing-center/"; // --- 1. 获取原图地址 --- const getOriginalUrl = (url) => url.replace(/\/(236x|474x|564x|736x|1200x)\//, '/originals/').replace(/\.webp$/, '.jpg'); // --- 2. 彻底关闭弹窗逻辑 --- function destroyOverlay() { const overlay = document.getElementById('px-ultimate-overlay'); if (overlay) { overlay.remove(); document.body.style.overflow = 'auto'; // 恢复页面滚动 // 移除键盘监听 document.removeEventListener('keydown', handleEsc); } } // 处理 ESC 键退出 function handleEsc(e) { if (e.key === "Escape") destroyOverlay(); } // --- 3. 2x HD 预览逻辑 --- async function processAndShow(imgUrl) { const originalUrl = getOriginalUrl(imgUrl); document.body.style.overflow = 'hidden'; // 禁止背景滚动 // 创建全屏遮罩 const overlay = document.createElement('div'); overlay.id = "px-ultimate-overlay"; overlay.style = ` position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.98); z-index: 2147483647; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; `; // 点击黑色背景区域也能关闭 overlay.onclick = (e) => { if (e.target === overlay) destroyOverlay(); }; overlay.innerHTML = `
ENHANCING VIEW...
Click image to toggle 2x Details | Press ESC to Close
`; overlay.appendChild(viewPort); overlay.appendChild(actionBar); document.getElementById('px-final-cta').onclick = () => window.open(`${BRIDGE_PAGE}?url=${encodeURIComponent(originalUrl)}`, '_blank'); }; img.onerror = () => { window.open(originalUrl, '_blank'); destroyOverlay(); }; } // --- 4. 轻量化注入逻辑 (保持稳定) --- function inject() { const images = document.querySelectorAll('img[src*="pinimg.com"]:not(.px-done)'); images.forEach(img => { if (img.width < 150) return; img.classList.add('px-done'); const container = img.closest('[data-test-id="pin-visual-wrapper"]') || img.closest('[data-test-id="visual-content-container"]') || img.parentElement; if (container) { const bar = document.createElement('div'); bar.className = 'px-helper-bar'; bar.style = "position:absolute; top:12px; left:12px; z-index:1000; display:flex; gap:6px; opacity:0; transition:0.3s; pointer-events:auto;"; const btnS = 'color:white; border:none; border-radius:4px; cursor:pointer; padding:5px 10px; font-weight:bold; font-size:10px; box-shadow:0 2px 8px rgba(0,0,0,0.5); white-space:nowrap;'; const b1 = document.createElement('button'); b1.innerHTML = '🪄 2x HD'; b1.style = btnS + 'background:#00BFFF;'; b1.onclick = (e) => { e.preventDefault(); e.stopPropagation(); processAndShow(img.src); }; const b2 = document.createElement('button'); b2.innerHTML = '🖼️ Originals'; b2.style = btnS + 'background:#E60023;'; b2.onclick = (e) => { e.preventDefault(); e.stopPropagation(); window.open(img.src.replace(/\/(236x|474x|564x|736x)\//, '/originals/'), '_blank'); }; bar.append(b1, b2); container.appendChild(bar); container.addEventListener('mouseenter', () => { if (window.getComputedStyle(container).position === 'static') container.style.position = 'relative'; bar.style.opacity = "1"; }); container.addEventListener('mouseleave', () => bar.style.opacity = "0"); } }); } setInterval(inject, 2500); const obs = new MutationObserver(inject); obs.observe(document.body, { childList: true, subtree: true }); })();