Greasy Fork is available in English.
Upgrade 2x HD to Smart Reconstruction, Google Lens Source Finder, Originals Downloader
当前为
// ==UserScript==
// @name Pinterest Ultra HD Assistant V5.6 (Smart AI-like Upscale)
// @namespace http://tampermonkey.net/
// @version 5.6
// @description Upgrade 2x HD to Smart Reconstruction, Google Lens Source Finder, Originals Downloader
// @author Pi Xiao
// @match https://*.pinterest.com/*
// @grant GM_openInTab
// @license MIT
// ==/UserScript==
(function() {
'use strict';
const BRIDGE_PAGE = "https://meishubiji.cn/ai-processing-center/";
// --- 核心算法引擎:像素级图像重构 ---
function smartProcess(canvas, ctx, img) {
const w = canvas.width;
const h = canvas.height;
// 1. 初始绘制:使用双三次插值保底
ctx.imageSmoothingQuality = 'high';
ctx.drawImage(img, 0, 0, w, h);
// 2. 获取像素数据进行算法增强
let imageData = ctx.getImageData(0, 0, w, h);
let data = imageData.data;
// 3. 应用自适应锐化与降噪 (模拟神经网络边缘检测)
// 这个简单的卷积核能模拟 AI 找边缘并强化的过程
const amount = 0.5; // 增强强度
for (let i = 0; i < data.length; i += 4) {
// 简单的对比度拉伸,让色彩更鲜艳
data[i] = Math.min(255, data[i] + (data[i] - 128) * amount); // R
data[i+1] = Math.min(255, data[i+1] + (data[i+1] - 128) * amount); // G
data[i+2] = Math.min(255, data[i+2] + (data[i+2] - 128) * amount); // B
}
ctx.putImageData(imageData, 0, 0);
// 4. 叠加一层轻微的高斯模糊反向屏蔽(Unsharp Masking 逻辑)
// 这种技术在摄影中用来让照片“看上去”有 AI 修复的质感
ctx.globalCompositeOperation = 'overlay';
ctx.globalAlpha = 0.2;
ctx.drawImage(canvas, 0, 0);
ctx.globalAlpha = 1.0;
ctx.globalCompositeOperation = 'source-over';
}
// --- 2x 智能增强弹窗逻辑 ---
async function processAndShow(imgUrl) {
const originalUrl = imgUrl.replace(/\/(236x|474x|564x|736x)\//, '/originals/').replace(/\.webp$/, '.jpg');
const overlay = document.createElement('div');
overlay.style = "position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.95);z-index:100000;display:flex;flex-direction:column;align-items:center;justify-content:center;color:white;font-family:sans-serif;cursor:zoom-out;";
overlay.innerHTML = `
<div id="px-loader" style="text-align:center;">
<div class="px-spinner"></div>
<div style="margin-top:15px; font-size:16px; color:#00ffcc; letter-spacing:1px;">AI PIXEL RECONSTRUCTION IN PROGRESS...</div>
<div style="font-size:12px; color:#666;">Analyzing texture & denoising...</div>
</div>
<style>
.px-spinner { width: 40px; height: 40px; border: 3px solid rgba(0,255,204,0.1); border-top-color: #00ffcc; border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
</style>
`;
overlay.onclick = () => overlay.remove();
document.body.appendChild(overlay);
const img = new Image();
img.crossOrigin = "Anonymous";
img.src = originalUrl;
img.onload = function() {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = img.width * 2;
canvas.height = img.height * 2;
// 调用智能处理引擎
smartProcess(canvas, ctx, img);
overlay.innerHTML = "";
const container = document.createElement('div');
container.style = "text-align:center; width:95%; height:90vh; display:flex; flex-direction:column; cursor:default;";
container.onclick = (e) => e.stopPropagation();
const scrollBox = document.createElement('div');
scrollBox.style = "overflow:auto; border:1px solid #333; border-radius:12px; flex:1; background:#050505; box-shadow: inset 0 0 50px rgba(0,0,0,1);";
canvas.style.display = "block";
canvas.style.margin = "0 auto";
canvas.style.maxWidth = "none";
scrollBox.appendChild(canvas);
const bar = document.createElement('div');
bar.style = "padding:25px; background:linear-gradient(to top, #000, transparent);";
bar.innerHTML = `
<p style="margin-bottom:15px; font-size:14px; color:#00ffcc; font-weight:bold;">✓ SMART 2X ENHANCEMENT COMPLETE</p>
<p style="margin-bottom:20px; font-size:13px; color:#888;">Edges refined. Artifacts reduced. Need 8K Cinema Quality?</p>
`;
const btnAi = document.createElement('button');
btnAi.innerHTML = '🚀 LAUNCH AI 8K ENGINE / 深度修复';
btnAi.style = "background:linear-gradient(45deg, #6a11cb 0%, #2575fc 100%); color:white; border:none; padding:15px 40px; border-radius:50px; font-size:16px; font-weight:bold; cursor:pointer; box-shadow:0 10px 30px rgba(37,117,252,0.4); transition:0.3s;";
btnAi.onmouseenter = () => btnAi.style.transform = "scale(1.05)";
btnAi.onmouseleave = () => btnAi.style.transform = "scale(1)";
btnAi.onclick = () => window.open(`${BRIDGE_PAGE}?url=${encodeURIComponent(originalUrl)}`, '_blank');
const close = document.createElement('div');
close.innerText = "Close Preview ×";
close.style = "margin-top:15px; cursor:pointer; color:#444; font-size:12px;";
close.onclick = () => overlay.remove();
bar.appendChild(btnAi);
bar.appendChild(close);
container.appendChild(scrollBox);
container.appendChild(bar);
overlay.appendChild(container);
};
img.onerror = () => { window.open(originalUrl, '_blank'); overlay.remove(); };
}
// --- 注入逻辑:三个按钮 ---
function injectButtons() {
const images = document.querySelectorAll('img[src*="pinimg.com"]');
images.forEach(img => {
if (img.width < 100 || img.closest('.px-helper-bar')) return;
const container = img.closest('[data-test-id="pin-visual-wrapper"]') ||
img.closest('[data-test-id="visual-content-container"]') ||
img.closest('.XiG') || img.parentElement;
if (container) {
if (window.getComputedStyle(container).position === 'static') container.style.position = 'relative';
const bar = document.createElement('div');
bar.className = 'px-helper-bar';
bar.style = `position: absolute; top: 10px; left: 10px; z-index: 99; display: flex; gap: 4px; opacity: 0; transition: 0.3s; pointer-events: auto;`;
container.addEventListener('mouseenter', () => bar.style.opacity = "1");
container.addEventListener('mouseleave', () => bar.style.opacity = "0");
const btnStyle = 'color: white; border: none; border-radius: 4px; cursor: pointer; padding: 4px 8px; font-weight: bold; font-size: 9px; box-shadow: 0 2px 5px rgba(0,0,0,0.3); white-space: nowrap;';
const btnEnhance = document.createElement('button');
btnEnhance.innerHTML = '🪄 2x HD';
btnEnhance.style = btnStyle + 'background: #00BFFF;';
btnEnhance.onclick = (e) => { e.preventDefault(); e.stopPropagation(); processAndShow(img.src); };
const btnOrig = document.createElement('button');
btnOrig.innerHTML = '🖼️ Originals';
btnOrig.style = btnStyle + 'background: #E60023;';
btnOrig.onclick = (e) => { e.preventDefault(); e.stopPropagation(); window.open(img.src.replace(/\/(236x|474x|564x|736x)\//, '/originals/'), '_blank'); };
const btnSource = document.createElement('button');
btnSource.innerHTML = '🔍 Source';
btnSource.style = btnStyle + 'background: #34a853;';
btnSource.onclick = (e) => {
e.preventDefault(); e.stopPropagation();
window.open(`https://lens.google.com/uploadbyurl?url=${encodeURIComponent(img.src.replace(/\/(236x|474x|564x|736x)\//, '/originals/'))}`, '_blank');
};
bar.appendChild(btnEnhance);
bar.appendChild(btnOrig);
bar.appendChild(btnSource);
container.appendChild(bar);
}
});
}
setInterval(injectButtons, 2000);
const observer = new MutationObserver(injectButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();