Greasy Fork

来自缓存

Greasy Fork is available in English.

虎扑图片缩小

虎扑帖子图片缩小

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴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;
      }
    }
  }
})();