// ==UserScript== // @name 百度贴吧图片点击放大-优化版 // @namespace https://greasyfork.org/users/51104 // @version 1.8.3 // @description 直接在当前页面点击查看原图(包括签名档)。支持图片的多开、拖拽、垂直或水平滚动和缩放旋转。优化:先显示原尺寸图片,再加载高清图并保持大小不变,未放大的时候按照高度限制(可设置)等比例缩放图片大小,防止图片挤占过多空间。新增自动加载原图功能,可在设置中开启。 // @match *://tieba.baidu.com/p/* // @match *://tieba.baidu.com/f?* // @exclude *://tieba.baidu.com/f?*kw=* // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @author lliwhx (modified) // @license MIT // @copyright Copyright © 2016-2022 lliwhx // ==/UserScript== (function (win, doc) { 'use strict'; if(doc.title==='贴吧404')return; var iTarget, preferences, gallery, iMouse, debounce, docElement = doc.documentElement, docWidth = docElement.clientWidth - 5, docHeight = docElement.clientHeight - 5; // 自动加载原图开关标志 var autoLoadEnabled = false; // 添加过渡动画样式(移除所有边框,只保留阴影) GM_addStyle(` .BDE_Image,.d_content_img,.j_user_sign{cursor:zoom-in;} .btzi-gallery{position:fixed;top:0;left:0;z-index:19990801;} .btzi-img{ position:absolute; transform-origin:0 0; box-shadow:0 0 7px rgba(0,0,0,.4); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); will-change: transform; } .btzi-img:hover{z-index:20220801;box-shadow:0 0 7px rgb(0,0,0);} .btzi-img:active{box-shadow:0 0 7px rgba(0,0,0,.4);cursor:move;} .btzi-loading{z-index:20220802;} .btzi-img.animating {pointer-events: none;} .btzi-img.no-transition {transition: none !important;} /* 移除所有加载状态边框,保留阴影即可 */ `); // ==================== 自动加载原图相关函数 ==================== /** * 获取图片的高清原图 URL * @param {HTMLImageElement} img 原始图片元素 * @param {Function} callback 回调函数,参数为高清URL或null */ function fetchHighQualityUrl(img, callback) { if (img.dataset.highQualityUrl) { callback(img.dataset.highQualityUrl); return; } var tSrc = /https?:\/\/(\w+)\.baidu\.com\/.+\/(\w+\.[a-zA-Z]{3,4}([^_]*_?))/.exec(img.src); if (tSrc && tSrc[3]) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { try { var response = JSON.parse(this.responseText); var highQualityUrl = response?.data?.img?.original?.waterurl; if (highQualityUrl) { img.dataset.highQualityUrl = highQualityUrl; callback(highQualityUrl); } else { callback(null); } } catch(e) { callback(null); } } else if (this.readyState == 4) { callback(null); } }; var pic_id = /(\w+)/.exec(tSrc[2])[0]; var tid = /\d+/.exec(location.pathname)[0]; xhttp.open("GET", "https://tieba.baidu.com/photo/p?alt=jview&pic_id="+pic_id+"&tid="+tid, true); xhttp.send(); } else { var originalSrcMatch = img.src.match(/^(.*?)(?:_\d+x\d+)?\.(jpg|jpeg|png|gif|bmp|webp)(?:\?.*)?$/i); if (originalSrcMatch) { var baseUrl = originalSrcMatch[1] + '.' + originalSrcMatch[2]; img.dataset.highQualityUrl = baseUrl; callback(baseUrl); } else { callback(null); } } } /** * 自动加载单张图片的高清原图 * @param {HTMLImageElement} img 原始图片元素 */ function autoLoadImage(img) { if (img.getAttribute('data-original-auto-loaded') === 'true') return; if (!img.complete) { img.addEventListener('load', function onLoad() { img.removeEventListener('load', onLoad); autoLoadImage(img); }); return; } fetchHighQualityUrl(img, function(highQualityUrl) { if (highQualityUrl) { img.src = highQualityUrl; img.setAttribute('data-original-auto-loaded', 'true'); } else { img.setAttribute('data-original-auto-loaded', 'failed'); } }); } /** * 自动加载页面中所有符合条件的图片 */ function autoLoadAllImages() { if (!autoLoadEnabled) return; var images = document.querySelectorAll('.BDE_Image, .j_user_sign, .d_content_img'); images.forEach(function(img) { autoLoadImage(img); }); } // 创建 MutationObserver 监听动态添加的图片 var observer = new MutationObserver(function(mutations) { if (!autoLoadEnabled) return; mutations.forEach(function(mutation) { if (mutation.addedNodes.length) { mutation.addedNodes.forEach(function(node) { if (node.nodeName === 'IMG' && (node.classList.contains('BDE_Image') || node.classList.contains('j_user_sign') || node.classList.contains('d_content_img'))) { autoLoadImage(node); } else if (node.querySelectorAll) { var imgs = node.querySelectorAll('.BDE_Image, .j_user_sign, .d_content_img'); imgs.forEach(autoLoadImage); } }); } }); }); observer.observe(document.body, { childList: true, subtree: true }); // ==================== 打开图片函数(修复未加载完成时的错误) ==================== function open(e) { var t = e.target; if (!e.button && ['BDE_Image', 'j_user_sign', 'd_content_img'].includes(t.className) && t.parentNode.nodeName !== 'A') { iTarget = t; var i = doc.createElement('img'); i.className = 'btzi-img'; var rect = t.getBoundingClientRect(); var startX = rect.left; var startY = rect.top; var startWidth = rect.width; var startHeight = rect.height; i.style.backgroundColor = '#f0f0f0'; var loadingText = doc.createElement('div'); loadingText.className = 'btzi-loading'; loadingText.textContent = '加载中...'; loadingText.style.position = 'absolute'; loadingText.style.top = '50%'; loadingText.style.left = '50%'; loadingText.style.transform = 'translate(-50%, -50%)'; loadingText.style.color = '#666'; loadingText.style.fontSize = '14px'; loadingText.style.zIndex = '1'; i.src = t.src; // 获取图片的自然尺寸(如果尚未加载完成,则使用当前显示的尺寸,若为0则使用默认值100) var naturalWidth, naturalHeight; if (t.complete) { naturalWidth = t.naturalWidth; naturalHeight = t.naturalHeight; } else { naturalWidth = t.width || 100; naturalHeight = t.height || 100; } var w = naturalWidth, h = naturalHeight, s = (!+preferences.size) && (docWidth - w < 0 || docHeight - h < 0) ? Math.min((docWidth - 5) / w, (docHeight - 5) / h) : 1, x = docWidth - w * s - 5 > 0 ? (docWidth - w * s) / 2 : 5, y = docHeight - h * s - 5 > 0 ? (docHeight - h * s) / 2 : 5; i.iData = { width: w, height: h, x: x, y: y, scale: s, rotate: 0, isHighQuality: false, displayWidth: w * s, displayHeight: h * s }; transform(i, startX, startY, startWidth / w, 0); gallery.appendChild(i); i.appendChild(loadingText); i.classList.add('animating'); requestAnimationFrame(() => { transform(i, x, y, s, 0); setTimeout(() => { i.classList.remove('animating'); }, 300); }); var onImageLoaded = function() { loadingText.remove(); i.style.backgroundColor = ''; var actualWidth = i.naturalWidth; var actualHeight = i.naturalHeight; // 从当前样式解析实际位置(防止用户拖动后 iData 未更新) var currentTransform = i.style.transform; var translateMatch = /translate\((-?\d+)px,\s?(-?\d+)px\)/.exec(currentTransform); var currentX = translateMatch ? parseInt(translateMatch[1]) : i.iData.x; var currentY = translateMatch ? parseInt(translateMatch[2]) : i.iData.y; var currentScale = i.iData.scale; // 缩放已实时更新 var currentRotate = i.iData.rotate; // 如果实际尺寸与临时尺寸不一致,调整缩放保持显示尺寸不变 if (actualWidth !== w || actualHeight !== h) { var currentDisplayWidth = i.iData.displayWidth; var currentDisplayHeight = i.iData.displayHeight; var newScaleX = currentDisplayWidth / actualWidth; var newScaleY = currentDisplayHeight / actualHeight; var newScale = newScaleX; // 保持宽高比 i.iData.width = actualWidth; i.iData.height = actualHeight; i.iData.scale = newScale; i.iData.displayWidth = actualWidth * newScale; i.iData.displayHeight = actualHeight * newScale; i.classList.add('no-transition'); transform(i, currentX, currentY, newScale, currentRotate); requestAnimationFrame(() => { i.classList.remove('no-transition'); }); } if (!autoLoadEnabled) { var tSrc = /https?:\/\/(\w+)\.baidu\.com\/.+\/(\w+\.[a-zA-Z]{3,4}([^_]*_?))/.exec(t.src); if(tSrc && tSrc[3]){ loadHighQualityImage(i, tSrc[2], t); } else { var originalSrcMatch = t.src.match(/^(.*?)(?:_\d+x\d+)?\.(jpg|jpeg|png|gif|bmp|webp)(?:\?.*)?$/i); if (originalSrcMatch) { var baseUrl = originalSrcMatch[1] + '.' + originalSrcMatch[2]; loadHighQualityImageDirect(i, baseUrl, t); } else { i.classList.remove('loading'); } } } else { i.classList.remove('loading'); } i.removeEventListener('load', onImageLoaded); i.removeEventListener('error', onImageError); }; var onImageError = function() { loadingText.remove(); i.style.backgroundColor = ''; i.classList.remove('loading'); i.removeEventListener('load', onImageLoaded); i.removeEventListener('error', onImageError); }; if (i.complete) { onImageLoaded(); } else { i.addEventListener('load', onImageLoaded); i.addEventListener('error', onImageError); } } } // ==================== 以下为原有函数(保持原样) ==================== var tiebaTid = /\d+/.exec(location.pathname)[0]; function loadHighQualityImage(i, tSrc, originalImg) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { var loadingElement = i.querySelector('.btzi-loading'); if (this.status == 200) { try { var response = JSON.parse(this.responseText); var highQualityUrl = response?.data?.img?.original?.waterurl; if (highQualityUrl) { loadAndReplaceImage(i, highQualityUrl, originalImg, loadingElement); } else { if (loadingElement) loadingElement.remove(); i.style.backgroundColor = ''; i.classList.remove('loading'); } } catch(e) { console.error('解析高质量图片URL失败:', e); if (loadingElement) loadingElement.remove(); i.style.backgroundColor = ''; i.classList.remove('loading'); } } else { if (loadingElement) loadingElement.remove(); i.style.backgroundColor = ''; i.classList.remove('loading'); } } }; tSrc = /(\w+)/.exec(tSrc)[0]; xhttp.open("GET", "https://tieba.baidu.com/photo/p?alt=jview&pic_id="+tSrc+"&tid="+tiebaTid, true); xhttp.send(); } function loadHighQualityImageDirect(i, highQualityUrl, originalImg) { var loadingElement = i.querySelector('.btzi-loading'); loadAndReplaceImage(i, highQualityUrl, originalImg, loadingElement); } function loadAndReplaceImage(i, highQualityUrl, originalImg, loadingElement) { var highQualityImg = new Image(); i.classList.add('loading'); i.classList.remove('success-flash', 'error'); highQualityImg.onload = function() { var currentData = i.iData; var currentX = currentData.x; var currentY = currentData.y; var currentScale = currentData.scale; var currentRotate = currentData.rotate; var targetDisplayWidth = currentData.displayWidth; var targetDisplayHeight = currentData.displayHeight; var newScaleX = targetDisplayWidth / this.width; var newScaleY = targetDisplayHeight / this.height; var newScale = newScaleX; i.classList.add('no-transition'); i.iData = { width: this.width, height: this.height, x: currentX, y: currentY, scale: newScale, rotate: currentRotate, isHighQuality: true, displayWidth: targetDisplayWidth, displayHeight: targetDisplayHeight }; i.src = highQualityUrl; transform(i, currentX, currentY, newScale, currentRotate); if (loadingElement) loadingElement.remove(); i.style.backgroundColor = ''; i.classList.remove('loading'); highQualityImg.onload = null; highQualityImg.onerror = null; }; highQualityImg.onerror = function() { if (loadingElement) loadingElement.remove(); i.style.backgroundColor = ''; i.classList.remove('loading'); i.iData.isHighQuality = false; highQualityImg.onload = null; highQualityImg.onerror = null; }; highQualityImg.src = highQualityUrl; } // 鼠标按下图片函数 function down(e) { var t, data; if (!e.button) { t = e.target; data = t.iData; iTarget = t; t.classList.add('no-transition'); iMouse = { clientX: e.clientX, clientY: e.clientY, offsetX: data.x - e.clientX, offsetY: data.y - e.clientY }; t = null; data = null; e.preventDefault(); e.stopPropagation(); doc.addEventListener('mousemove', move); doc.addEventListener('mouseup', up); } } function move(e) { var t = iTarget, data = t.iData, x = e.clientX + iMouse.offsetX, y = e.clientY + iMouse.offsetY; e.stopPropagation(); transform(t, x, y, data.scale, data.rotate); t = null; x = null; y = null; data = null; } function up(e) { var t, data, translate; if (iMouse.clientX === e.clientX && iMouse.clientY === e.clientY) { iTarget = null; } else { t = iTarget; data = t.iData; translate = /translate\((-?\d+)px,\s?(-?\d+)px\)/.exec(t.getAttribute('style')); data.x = translate[1] | 0; data.y = translate[2] | 0; t.classList.remove('no-transition'); t = null; data = null; translate = null; } iMouse = null; doc.removeEventListener('mousemove', move); doc.removeEventListener('mouseup', up); } function close(e) { var t = e.target; switch (preferences.closeWindow) { case 'btzi_gallery': if (!iTarget) { t.iData = null; t.remove(); } break; case 'document': if (!iTarget || (t !== iTarget && t !== docElement)) { if(doc.body.classList.contains('btzi-enabled') || t.id === 'btzi_settings_save')break; gallery.style.display = 'none'; while (gallery.hasChildNodes()) { gallery.firstChild.iData = null; gallery.firstChild.remove(); } gallery.style.display = ''; } break; } t=null; iTarget = null; } function wheel(e) { var t = e.target, data = t.iData, x = data.x, y = data.y, s = data.scale, r = data.rotate, p = preferences, eKey = !e.altKey && !e.ctrlKey && !e.shiftKey, wKey = p.wheelKey, zKey = p.zoomKey, rKey = p.rotateKey, wDirection = p.wheelDirection, zDirection = p.zoomDirection, rDirection = p.rotateDirection, deltaXY = (e.deltaY || e.deltaX) > 0 ? 100 : -100, delta, tmp, z; e.preventDefault(); e.stopPropagation(); t.classList.add('no-transition'); if (wKey === 'type' && eKey || wKey !== 'type' && e[wKey]) { // 移动逻辑略 } if (zKey === 'type' && eKey || zKey !== 'type' && e[zKey]) { delta = deltaXY * zDirection > 0 ? 1.2 : 0.9; z = s * delta; if (z < 0.1) z = 0.1; tmp = z / s; data.x = e.clientX - (e.clientX - x) * tmp; data.y = e.clientY - (e.clientY - y) * tmp; data.scale = z; data.displayWidth = data.width * z; data.displayHeight = data.height * z; transform(t, data.x, data.y, z, r); return; } if (rKey === 'type' && eKey || rKey !== 'type' && e[rKey]) { tmp = data.width; data.width = data.height; data.height = tmp; delta = deltaXY * rDirection > 0 ? 90 : 270; z = (r + delta) % 360; tmp = 0.01745329 * delta; data.x = e.clientX - (e.clientX - x) * Math.cos(tmp) + (e.clientY - y) * Math.sin(tmp); data.y = e.clientY - (e.clientX - x) * Math.sin(tmp) - (e.clientY - y) * Math.cos(tmp); data.rotate = z; transform(t, data.x, data.y, s, z); return; } requestAnimationFrame(() => { t.classList.remove('no-transition'); }); } function transform(t, x, y, s, r) { t.style.transform = `translate(${x | 0}px, ${y | 0}px) scale(${s}) rotate(${r}deg)`; } function frame(w) { return doc.getElementById(w) || doc; } function resize() { clearTimeout(debounce); debounce = setTimeout(function () { docWidth = docElement.clientWidth - 5; docHeight = docElement.clientHeight - 5; }, 500); } var postlist = doc.getElementById('j_p_postlist'); var prevent = function (e) { var t = e.target; if (!e.button && t.className === 'BDE_Image' && t.parentNode.nodeName !== 'A') { e.stopPropagation(); } }; var callback = function () { gallery.style.display = 'none'; while (gallery.hasChildNodes()) { gallery.firstChild.iData = null; gallery.firstChild.remove(); } gallery.style.display = ''; }; var observerPage = new MutationObserver(callback); observerPage.observe(postlist, { childList: true }); GM_addStyle(` .BDE_Image,.d_content_img,.j_user_sign{cursor:zoom-in;} .btzi-gallery{position:fixed;top:0;left:0;z-index:19990801;} .btzi-img{position:absolute;transform-origin:0 0;box-shadow:0 0 7px rgba(0,0,0,.4);} .btzi-img:hover{z-index:20220801;box-shadow:0 0 7px rgb(0,0,0);} .btzi-img:active{box-shadow:0 0 7px rgba(0,0,0,.4);cursor:move;} .btzi-loading{z-index:20220802;} `); preferences = JSON.parse(GM_getValue('btzi-UserSettings', '{"open": "click","close": "click","closeWindow":"btzi_gallery","size":"0","wheelKey":"ctrlKey","wheelDirection": "-1","zoomKey":"type","zoomDirection": "-1","rotateKey":"shiftKey","rotateDirection": "1","autoLoadOriginal":"false"}')); autoLoadEnabled = preferences.autoLoadOriginal === 'true'; gallery = doc.createElement('div'); gallery.className = 'btzi-gallery'; gallery.id = 'btzi_gallery'; gallery.addEventListener('mousedown', down); gallery.addEventListener('wheel', wheel); doc.body.appendChild(gallery); postlist.addEventListener('click', prevent, true); postlist.addEventListener(preferences.open, open, true); frame(preferences.closeWindow).addEventListener(preferences.close, close); win.addEventListener('resize', resize); if (autoLoadEnabled) { if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', autoLoadAllImages); } else { autoLoadAllImages(); } } // 用户设置界面(略,与之前相同) var settings = function () { GM_addStyle('.btzi-enabled .btzi-modal,.btzi-enabled .btzi-container{display:flex;}.btzi-modal,.btzi-container{position:fixed;top:0;left:0;display:none;width:100%;height:100%;}.btzi-modal{z-index:20211231;background-color:rgba(0,0,0,.7);}.btzi-container{z-index:20220101;justify-content:center;align-items:center;text-align:left;}.btzi-content{width:335px;border-radius:6px;background-color:#fff;}.btzi-header,.btzi-body,.btzi-footer{padding:11px;}.btzi-header{border-bottom:1px solid #e6ecf0;}.btzi-title{padding:0;margin:0;font:400 20px sans-serif;color:#000;text-align:center;}.btzi-group{padding:0;margin:0;margin-bottom:15px;border:0;}.btzi-legend,.btzi-controls,.btzi-select,.btzi-button{font:14px sans-serif;color:#000;}.btzi-legend{padding:5px 0;margin:0;float:left;width:81px;text-align:right;}.btzi-controls{margin-left:93px;clear:none;}.btzi-select{box-sizing:border-box;padding:4px;margin:0;width:180px;height:30px;border:1px solid #e6ecf0;border-radius:3px;appearance:auto;}.btzi-select:focus{outline:#f0f auto;}.btzi-footer{text-align:center;border-top:1px solid #e6ecf0;}.btzi-button{padding:9px 18px;border:0;border-radius:75px;font-weight:700;color:#fff;background:#4ab3f4;cursor:pointer;transition:box-shadow .17s ease-in-out;}.btzi-button:hover,.btzi-button:active{background:#1da1f2;}.btzi-button:focus{box-shadow:0 0 0 2px #fff,0 0 0 4px #a4d9f9;}.btzi-button:active{box-shadow:0 0 0 2px #fff,0 0 0 4px #4ab3f4;}'); var html = '

用户设置

打开图片
关闭图片
图片大小
滚动图片
缩放图片
旋转图片
自动加载原图
'; doc.body.insertAdjacentHTML('beforeend', html); var form = doc.getElementById('btzi_settings_form'); var p = preferences; for (var prop in p) { form[`btzi[${prop}]`].value = p[prop]; } var KeyIndex = {'btzi[wheelKey]':form['btzi[wheelKey]'].selectedIndex,'btzi[zoomKey]':form['btzi[zoomKey]'].selectedIndex,'btzi[rotateKey]':form['btzi[rotateKey]'].selectedIndex}; var change = function () { var prop,tmp; for (prop in KeyIndex) { if (this.selectedIndex === KeyIndex[prop]) { tmp = KeyIndex[this.name]; KeyIndex[prop] = tmp; form[prop].selectedIndex = tmp; break; } } KeyIndex[this.name] = this.selectedIndex; prop = null; tmp = null; }; form['btzi[wheelKey]'].addEventListener('change', change); form['btzi[zoomKey]'].addEventListener('change', change); form['btzi[rotateKey]'].addEventListener('change', change); doc.getElementById('btzi_settings_save').addEventListener('click', function () { var prop, prefer = p, opened = prefer.open, closed = prefer.close, closedWindow = prefer.closeWindow; for (prop in prefer) { prefer[prop] = form[`btzi[${prop}]`].value; } if (opened !== prefer.open) { postlist.removeEventListener(opened, open, true); postlist.addEventListener(prefer.open, open, true); } if (closed !== prefer.close || closedWindow !== prefer.closeWindow) { frame(closedWindow).removeEventListener(closed, close); frame(prefer.closeWindow).addEventListener(prefer.close, close); } GM_setValue('btzi-UserSettings', JSON.stringify(prefer)); doc.body.classList.remove('btzi-enabled'); autoLoadEnabled = prefer.autoLoadOriginal === 'true'; if (autoLoadEnabled) { autoLoadAllImages(); } prefer=null; }); settings = null; doc.body.classList.add('btzi-enabled'); }; if (!GM_getValue('btzi-UserSettings')) { settings(); } GM_registerMenuCommand('btzi-用户设置', function () { if (settings) { settings(); } else { doc.body.classList.add('btzi-enabled'); } }); // ==================== 高度限制功能(保持不变) ==================== function initDefaults() { if (GM_getValue('enabled') === undefined) GM_setValue('enabled', true); if (GM_getValue('maxHeight') === undefined) GM_setValue('maxHeight', 300); } function registerMenuCommands() { GM_registerMenuCommand('设置最大图片高度', function() { const current = GM_getValue('maxHeight', 100); const newHeight = prompt('请输入最大图片高度(像素):', current); if (newHeight !== null && !isNaN(newHeight) && parseInt(newHeight) > 0) { GM_setValue('maxHeight', parseInt(newHeight)); resizeImages(); } else if (newHeight !== null) alert('请输入有效的数字'); }); GM_registerMenuCommand('开关图片高度限制', function() { const current = GM_getValue('enabled', true); GM_setValue('enabled', !current); resizeImages(); }); } function resizeImages() { if (!GM_getValue('enabled', true)) { document.querySelectorAll('img.BDE_Image').forEach(img => { img.style.maxHeight = ''; img.style.width = ''; const replaceDiv = img.closest('.replace_div'); if (replaceDiv) { replaceDiv.style.height = ''; const tip = replaceDiv.querySelector('.replace_tip'); if (tip) tip.style.display = ''; } }); return; } const maxHeight = GM_getValue('maxHeight', 100); document.querySelectorAll('img.BDE_Image').forEach(img => { if (img.complete) applyResize(img, maxHeight); else img.addEventListener('load', function() { applyResize(img, maxHeight); }); }); } function applyResize(img, maxHeight) { const originalWidth = img.naturalWidth || parseInt(img.width); const originalHeight = img.naturalHeight || parseInt(img.height); const replaceDiv = img.closest('.replace_div'); if (originalHeight > maxHeight) { const scale = maxHeight / originalHeight; const newWidth = Math.round(originalWidth * scale); img.style.maxHeight = maxHeight + 'px'; img.style.width = newWidth + 'px'; img.style.height = 'auto'; if (replaceDiv) { replaceDiv.style.height = 'auto'; const tip = replaceDiv.querySelector('.replace_tip'); if (tip) tip.style.display = 'none'; } } else { img.style.maxHeight = ''; img.style.width = ''; img.style.height = ''; if (replaceDiv) { replaceDiv.style.height = ''; const tip = replaceDiv.querySelector('.replace_tip'); if (tip) tip.style.display = ''; } } } function observePageChanges() { const observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.addedNodes.length) resizeImages(); }); }); observer.observe(document.body, { childList: true, subtree: true }); } initDefaults(); registerMenuCommands(); window.addEventListener('load', resizeImages); observePageChanges(); resizeImages(); console.log('也许我走了,什么都不会剩下。但优化的加载体验会留下。'); })(window, document);