zhi-hu

知知乎乎(收藏夹双列;隐藏视频回答;加宽;区分问题和视频)

目前为 2023-06-28 提交的版本。查看 最新版本

// ==UserScript==
// @name         zhi-hu
// @namespace    https://gf.qytechs.cn/zh-CN/scripts/438709-zhi-hu
// @version      0.0.14
// @description  知知乎乎(收藏夹双列;隐藏视频回答;加宽;区分问题和视频)
// @author       Song
// @match        *://www.zhihu.com/*
// @match        *://zhuanlan.zhihu.com/*
// @license MIT
// @grant        none
// ==/UserScript==
(function () {

    function addStyle() {
        let el = document.createElement('style');
        el.setAttribute('name', 'zhi_zhi_hu_hu');
        document.head.appendChild(el);
    }

    /**
     * 插入样式表
     */
    function insertCSS() {
        let styleSheet = document.styleSheets[document.styleSheets.length - 1];
        /*收藏栏的样式,变成双列*/
        styleSheet.insertRule('.Modal--large.FavlistsModal {width: 600px;}');
        styleSheet.insertRule('.Favlists-content .Favlists-item {width: 230px; float: left;}');
        styleSheet.insertRule(' .Favlists-content .Favlists-item:nth-child(even){margin-left: 60px;}');

        /*隐藏视频回答*/
        styleSheet.insertRule('.VideoAnswerPlayer, .VideoAnswerPlayer video, .VideoAnswerPlayer-video, .VideoAnswerPlayer-iframe {height: 2px;}');
        // styleSheet.insertRule('.ZVideoItem  {height: 2px;}');
        styleSheet.insertRule('.ContentItem.ZVideoItem  {height: 8px;}');
        styleSheet.insertRule('.ContentItem.EduSectionItem  {height: 8px;}');
        styleSheet.insertRule('.ZvideoItem .RichContent-cover{ height:8px; }');
        styleSheet.insertRule('.ZvideoItem .RichContent-cover-inner{height:4px; }');
        styleSheet.insertRule('.VideoAnswerPlayer video, nav.TopstoryTabs > a[aria-controls="Topstory-zvideo"]{height:4px; }');


        /*区分问题 和 视频*/
        let style = `font-weight: bold;font-size: 13px;padding: 1px 4px 0;border-radius: 2px;display: inline-block;vertical-align: top;margin: ${(location.pathname === '/search') ? '2' : '4'}px 4px 0 0;`
        let styles = [
            `.AnswerItem .ContentItem-title a:not(.zhihu_e_toQuestion)::before {content:'回答';color: #f68b83;background-color: #f68b8333;${style}}`,
            `.TopstoryQuestionAskItem .ContentItem-title a:not(.zhihu_e_toQuestion)::before {content:'回答';color: #ff5a4e;background-color: #ff5a4e33;${style}}`,
            `.ZVideoItem .ContentItem-title a::before, .ZvideoItem .ContentItem-title a::before {content:'视频';color: #00BCD4;background-color: #00BCD433;${style}}`,
            `.ArticleItem .ContentItem-title a::before {content:'文章';color: #2196F3;background-color: #2196F333;${style}}`
        ];
        styles.forEach(s => styleSheet.insertRule(s));

        /*视频*/
        styleSheet.insertRule('.ZVideoItem .RichContent{opacity: 0.5; color: #666  !important; font-style:italic !important;}');

        /*调整列表中专栏文章的样式*/
        styleSheet.insertRule('.ContentItem[itemprop=article]{opacity: 0.5; color: #666;font-style:italic;}');
        styleSheet.insertRule('.ContentItem[itemprop=article] .ContentItem-title{color: #666; }');


    }

    /**
     * 增宽
     * @param {number} maxWidth
     */
    function widening(maxWidth) {
        const ww = window.innerWidth - 30;
        if (ww < 1000) return;

        let w = ww > maxWidth ? maxWidth : ww;
        let styleSheet = document.styleSheets[document.styleSheets.length - 1];
        styleSheet.insertRule('.Topstory-container, .Question-main{min-width:' + w + 'px !important;}');
        styleSheet.insertRule('.Topstory-mainColumn, .Question-mainColumn{width:' + (w - 300) + 'px !important;}');
        // document.querySelector('.Topstory-container').style.minWidth = w + 'px';
        // document.querySelector('.Topstory-mainColumn').style.width = (w - 300) + 'px';
        // 专栏文章
        styleSheet.insertRule('.Post-Main .Post-RichTextContainer {min-width:' + w + 'px !important;}');
    }

    addStyle();
    widening(1200);
    insertCSS();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址