// ==UserScript== // @name 妖火图片加强(改) // @namespace http://yaohuo.me/ // @version 0.42 // @description 妖火图片加强!!! 改 烟花小神 的 // @require https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js // @match https://yaohuo.me/bbs-** // @match https://www.yaohuo.me/bbs-** // @icon https://www.google.com/s2/favicons?sz=64&domain=yaohuo.me // @author 夜猎 // @downloadURL none // ==/UserScript== (function() { 'use strict'; function offSet(curEle) { var totalLeft = null; var totalTop = null; var par = curEle.offsetParent; //首先把自己本身的相加 totalLeft += curEle.offsetLeft; totalTop += curEle.offsetTop; //现在开始一级一级往上查找,只要没有遇到body,我们就把父级参照物的边框和偏移相加 while (par){ if (navigator.userAgent.indexOf("MSIE 8.0") === -1){ //不是IE8我们才进行累加父级参照物的边框 totalTop += par.clientTop; totalLeft += par.clientLeft; } //把父级参照物的偏移相加 totalTop += par.offsetTop; totalLeft += par.offsetLeft; par = par.offsetParent; } return {left: totalLeft,top: totalTop}; //返回一个数组,方便我们使用哦。 } $(document).ready(function() { var defaultImgSize = 100; var maxPreviewSize = 9999; var imageContainer = document.createElement('div'); imageContainer.classList.add('imageContainer'); imageContainer.style.display = 'none'; imageContainer.style.backgroundColor = 'rgba(0, 0, 0, 0.5)'; imageContainer.style.borderRadius = '10px'; imageContainer.style.position = 'fixed'; imageContainer.style.top = '50%'; imageContainer.style.left = '50%'; imageContainer.style.transform = 'translate(-50%, -50%)'; imageContainer.style.zIndex = '9999'; imageContainer.style.padding = '20px'; document.body.appendChild(imageContainer); var imageElement = document.createElement('img'); imageElement.style.maxWidth = maxPreviewSize + 'px'; imageElement.style.maxHeight = maxPreviewSize + 'px'; imageContainer.appendChild(imageElement); var contentImages = document.querySelectorAll('.content img'); var recontentImages = document.querySelectorAll('.recontent img'); var thirdImages = [] for (let i = 0; i < contentImages.length; i++) { thirdImages.push(contentImages[i]) } for (let i = 0; i < recontentImages.length; i++) { thirdImages.push(recontentImages[i]) } for (let i = 0; i < thirdImages.length; i++) { var thirdImage = thirdImages[i]; thirdImage.style.maxHeight = '780px'; if (thirdImage.parentNode.tagName == 'A' && thirdImage.parentNode.href.indexOf('https://yaohuo.me/bbs/upload/') == 0) { thirdImage.parentNode.onclick = function() { return false; }; } thirdImage.onclick = function() { // 使用toggle函数根据当前样式来决定添加还是移除max-height属性 if (this.style.maxHeight) { this.style.maxHeight = null; // 移除max-height } else { this.style.maxHeight = '780px'; // 添加max-height let offTop = offSet(this).top; // 计算新的滚动位置,使图片位于视口偏下150px处 window.scrollTo({ top: offTop + 150, behavior: "smooth" }); //this.scrollIntoView({behavior: "smooth"}); } }; } }); })();