Greasy Fork is available in English.
把图片的最大宽度缩小50%
// ==UserScript==
// @name 虎扑楼中图片缩小
// @namespace http://tampermonkey.net/
// @version 0.7
// @description 把图片的最大宽度缩小50%
// @author Rod
// @match https://bbs.hupu.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
window.addEventListener('scroll', () => {
imgsmall()
})
function imgsmall() {
let arr = document.querySelectorAll("[class*=reply-list-content] img,.main-post-info img")
for (let item of arr) {
if (isVisible(item)) item.style.maxWidth = '50%'
}
}
function isVisible(elem) {
let coords = elem.getBoundingClientRect();
let windowHeight = document.documentElement.clientHeight;
// 顶部元素边缘可见或底部元素边缘可见
let topVisible = coords.top > -250 && coords.top < windowHeight;
let bottomVisible = coords.bottom < windowHeight + 250 && coords.bottom > 0;
return topVisible || bottomVisible;
}
})();