优化移动端知乎网页

自动展开,去除app下载,去除打开app

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         优化移动端知乎网页
// @version      1.5
// @description  自动展开,去除app下载,去除打开app
// @author       Zruiry
// @match        https://www.zhihu.com/question/*
// @grant        none
// @namespace    Zruiry
// ==/UserScript==

(function() {

    // 知乎消除
    const ele = [
        // 头部下载app
        '.MobileAppHeader-downloadLink',
        // 底部悬浮的打开app
        '.OpenInAppButton',
        // 打开app查看更多评论
        '.CommentsForOia .Button',
        // 评论下方广告
        '.MBannerAd',
        // 相关推荐
        '.RelatedReadings',
        // 热门推荐
        '.HotQuestions'
    ];
    for (let e of ele) {
        document.querySelector('style').innerHTML += e + `{display: none !important;}`;
    }

    // 优化头部
    document.getElementsByClassName('MobileAppHeader-authLink')[0].innerText = '登录';
    document.getElementsByClassName('MobileAppHeader-searchBoxWithUnlogin')[0].style.width = 'calc(100vw - 170px)'

    try {
        // 消除遮屏弹窗
        var obj = document.querySelector('.ModalWrap').children[0];
        obj.children[0].setAttribute('class', '');
        obj.children[1].setAttribute('class', 'ModalExp-content');
        obj.setAttribute('data-stop-scroll-propagation', false);
    } catch (e) {
        console.log(e);
    }

    try {
        // 自动展开
        var open = document.querySelector('.RichContent');
        open.setAttribute('class', 'RichContent RichContent--unescapable');
        open.removeChild(open.childNodes[1]);
        document.querySelector('.RichContent-inner').setAttribute('style', 'max-height: auto !important;');
        document.querySelector('.ContentItem-actions').setAttribute('class', 'ContentItem-actions RichContent-actions');
    } catch (e) {
        console.log(e);
    }

    try {
        // 开启页面滚动
        document.querySelector('body').setAttribute('class', 'Body--Mobile Body--Android');
        document.querySelector('body').setAttribute('style', 'overflow: auto');
    } catch (e) {
        console.log(e);
    }

})();