贴吧禁止折叠长图

贴吧会自动折叠长图不喜欢,是个坏功能,不要

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         贴吧禁止折叠长图
// @namespace    You Boy
// @version      0.4
// @description  贴吧会自动折叠长图不喜欢,是个坏功能,不要
// @author       You Boy
// @match        *://tieba.baidu.com/p/*
// @icon         https://tb3.bdstatic.com/public/icon/favicon-v2.ico
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 遍历删除replace_div
    function removeReplaceDiv(){
        const replaceDivArray = document.querySelectorAll("div.replace_div");
        try{
            for(const item of replaceDivArray){
                item.classList.remove('replace_div');
                item.querySelector('div.replace_tip').remove();
            }
        }catch(err){
            console.group('贴吧禁止折叠长图 Error Info:删除replace_div');
            console.error(err);
            console.groupEnd();
        }
    }

    // 删除图片高度,使之高度自适应
    function removeBDEHeight(){
        const bdImageArray = document.querySelectorAll("img.BDE_Image");
        try{
            for(const item of bdImageArray){
                item.removeAttribute('height');
            }
        }catch(err){
            console.group('贴吧禁止折叠长图 Error Info:删除BDE_Image高度');
            console.error(err);
            console.groupEnd();
        }
    }

    // 处理事件
    const handleEvents = function(){
        removeReplaceDiv();
        removeBDEHeight();
    }

    // 增加绑定事件,使之可以监听pushState和replaceState
    const bindStateListener = function(stateName) {
        const historyState = history[stateName];
        return function() {
            const newState = historyState.apply(this, arguments);
            const e = new Event(stateName);
            e.arguments = arguments;
            window.dispatchEvent(e);
            return newState;
        };
    };
    history.pushState = bindStateListener('pushState');
    history.replaceState = bindStateListener('replaceState');

    // 延迟函数
    const delay = function(fun,time){
        const delayTime = time || 1000;
        setTimeout(fun,delayTime);
        // 原来基础上多加个2秒,再次执行一次,网速慢导致有部分漏网之鱼
        setTimeout(fun,delayTime + 2e3);
        // 还。。还想来?
        setTimeout(fun,delayTime + 4e3);
    }

    window.addEventListener('load', function() {
        handleEvents();
    });
    window.addEventListener('popstate', function() {
        delay(handleEvents);
    });
    window.addEventListener('replaceState', function() {
        delay(handleEvents);
    });
    window.addEventListener('pushState', function() {
        delay(handleEvents);
    });
})();