Greasy Fork

Greasy Fork is available in English.

虎扑图片缩小

虎扑帖子图片缩小

当前为 2023-06-30 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        虎扑图片缩小
// @description    虎扑帖子图片缩小
// @namespace   Violentmonkey Scripts
// @match       *://bbs.hupu.com/*
// @version     1.0
// @author      Jason
// @license      GPL-3.0 License
// @compatible  Chrome
// ==/UserScript==

(function () {
  'use strict';
  process();
  window.addEventListener('scroll', () => {
    process();
  })
  function process() {
    //页面向下滚动时,标题不要固定在页面顶端
    let title = document.querySelector('.post-fix-title');
    if(title != null) {
      title.style.position = 'absolute';
      title = title.parentNode.parentNode;
      title.style.position = 'absolute';
    }
    //楼中图片
    let threadImgs = document.querySelectorAll(".thread-content-detail img");
    for(let i = 0; i < threadImgs.length; ++i) {
      let threadImg = threadImgs[i];
      let computedStyle = window.getComputedStyle(threadImg);
      let width = parseFloat(computedStyle.width.replace('px', ''));
      let height = parseFloat(computedStyle.height.replace('px', ''));
      //图片宽高比
      let rate = height / width;

      let smallWidth = '50%';
      let smallHeight = '50%';
      //如果图片近似于正方形,就当它是表情包,表情包宽度缩小到50px,高度也按比例缩小;否则就当它是普通图片,宽度和高度缩小50%
      if(rate <= 1.2 && rate >= 0.7) {
        smallWidth = 50;
        smallHeight = smallWidth * rate;
        threadImg.style.width = smallWidth + 'px';
        threadImg.style.height = smallHeight + 'px';
      } else {
        threadImg.style.width = smallWidth;
        threadImg.style.height = smallHeight;
      }
    }
  }
})();