知乎排版优化

知乎排版优化!

目前為 2018-02-01 提交的版本,檢視 最新版本

// ==UserScript==
// @name         知乎排版优化
// @namespace    https://www.zhihu.com/
// @version      1.8
// @description  知乎排版优化!
// @author       chenglinz <[email protected]>
// @match        https://www.zhihu.com/question/*
// @match        https://www.zhihu.com/people/*
// @match        https://www.zhihu.com/topic/*
// @match        https://www.zhihu.com/search?*
// @match        https://www.zhihu.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var path = location.pathname.slice(0);
    (function (){
        if (path == '/') {
            var re = document.querySelector('.GlobalSideBar');
            re.remove();
            var inner = document.querySelector('.Topstory-mainColumn');
            inner.style.marginLeft = '150px';
            inner.style.marginRight = '150px';
        }
    })();
    (function (){
        if (path.match(/\/question\/\d+/g)) {
            var re = document.querySelector('.Question-sideColumn');
            re.remove();
            var inner = document.querySelector('.Question-mainColumn');
            inner.style.marginLeft = '155px';
        }
    })();
    (function (){
        if (path.match(/\/topic\/.*/g)) {
            var re = document.querySelector('.ContentLayout-sideColumn');
            re.remove();
            var inner = document.querySelector('.ContentLayout-mainColumn');
            inner.style.marginLeft = '150px';
            inner.style.marginRight = '150px';
        }
    })();
    (function (){
        if (path.match(/\/people\/.*/g)) {
            var right = document.querySelector('.Profile-sideColumn');
            right.style.visibility = "hidden";
            var inner = document.querySelector('.Profile-mainColumn');
            inner.style.marginLeft = '155px';
        }
    })();
    // 只应用到主页,问题页,话题页,搜索页
    if (path.match(/\/search?.*/g)) {
        var re = document.querySelector('.zu-main-sidebar');
        re.style.visibility = "hidden";
        var inner = document.querySelector('.zu-main-content-inner');
        inner.style.marginLeft = '150px';
        inner.style.marginRight = '150px';
        var backtotop = document.querySelector('.zh-backtotop');
        backtotop.style.marginLeft = '350px';
    }
    (function(){
        // 导航不随页面滚动固定,再次按h取消
        let header = document.getElementsByTagName('header')[0];
        window.onscroll = function() {
            header.className = "Sticky AppHeader";
            let sticky = document.querySelector('.Sticky--holder');
            if (sticky) {
                sticky.style.position = "absolute";
                sticky.style.height = 0;
            }
        };
    })();
})();