博客网站的精简和宽屏处理

自定义精简

目前為 2023-12-22 提交的版本,檢視 最新版本

// ==UserScript==
// @name         博客网站的精简和宽屏处理
// @namespace    https://github.com/liehuoe/tampermonkey_script
// @version      0.1
// @author       ckl
// @description  自定义精简
// @license      MIT
// @match        https://*.zhihu.com/*
// @match        https://*.csdn.net/*
// @match        https://*.jianshu.com/*
// @match        https://*.juejin.cn/*
// @match        https://*.51cto.com/*
// @match        http://*.360doc.com/*
// @icon         data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB0PSIxNzAxNDAzMDEwODAzIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9Ijg1NTgiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMjU2IiBoZWlnaHQ9IjI1NiI+PHBhdGggZD0iTTMyIDY0TDk2IDB2MTAyNGwtNjQtNjRoOTI2LjQ3NmwtNjQgNjRWMGw2NCA2NEgzMnpNOTU4LjQ3NiAwdjEwMjRIMzJWMGg5MjYuNDc2eiIgcC1pZD0iODU1OSIgZmlsbD0iI2Q0MjM3YSI+PC9wYXRoPjxwYXRoIGQ9Ik0xNzguMjg2IDIxMC4yODZsNjQtNjR2MjkyLjU3MWwtNjQtNjRIODEyLjE5bC02NCA2NFYxNDYuMjg2bDY0IDY0SDE3OC4yODZ6IG02MzMuOTA0LTY0djI5Mi41NzFIMTc4LjI4NlYxNDYuMjg2SDgxMi4xOXpNMTc4LjI4NiA3NDYuNjY3bDY0LTY0djE5NS4wNDdsLTY0LTY0SDgxMi4xOWwtNjQgNjRWNjgyLjY2N2w2NCA2NEgxNzguMjg2eiBtNjMzLjkwNC02NHYxOTUuMDQ3SDE3OC4yODZWNjgyLjY2N0g4MTIuMTl6TTc4Ny44MSA1OTIuNzYyYzE3LjY3MyAwIDMyLTE0LjMyNyAzMi0zMiAwLTE3LjY3My0xNC4zMjctMzItMzItMzJIMjAyLjY2N2MtMTcuNjczIDAtMzIgMTQuMzI3LTMyIDMyIDAgMTcuNjczIDE0LjMyNyAzMiAzMiAzMkg3ODcuODF6IiBwLWlkPSI4NTYwIiBmaWxsPSIjZDQyMzdhIj48L3BhdGg+PC9zdmc+
// @grant        GM_addStyle
// @grant        unsafeWindow
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

let autoWidthDisabled = false;
function initAutoWidthDisabled() {
    const key = 'autoWidthDisabled';
    autoWidthDisabled = GM_getValue(key);
    let menuId = GM_registerMenuCommand(
        `${autoWidthDisabled ? '🔲' : '✅'}宽屏处理`,
        () => {
            GM_setValue('autoWidthDisabled', !autoWidthDisabled);
            GM_unregisterMenuCommand(menuId);
            initAutoWidthDisabled();
            location.reload();
        }
    )
}
initAutoWidthDisabled();

/** CSDN */
function csdn() {
    // 右上发布文章弹窗
    GM_addStyle('.csdn-toolbar-creative-mp{display:none !important}');
    // 右边工具栏
    GM_addStyle('.csdn-side-toolbar{display:none !important}');
}
/** CSDN 博客 */
function csdn_blog() {
    // 右上登录(不可用)提示
    GM_addStyle('#csdn-toolbar-profile-nologin{display:none !important}');
    // 左边侧栏
    GM_addStyle('.blog_container_aside{display:none !important}');
    GM_addStyle('#toolBarBox .left-toolbox{left:0 !important; width:100% !important}');
    // 下方"关注博主即可阅读全文"
    GM_addStyle('.hide-article-box{display:none !important}');
    GM_addStyle('#article_content{height:auto !important}');
    // 宽屏
    if (!autoWidthDisabled) {
        GM_addStyle('#mainBox{flex:1 !important; width:0 !important; margin-right:0 !important}');
        GM_addStyle('#mainBox > main{width:100% !important}');
    } else {
        GM_addStyle('#mainBox{width:auto !important;');
    }
    // 显示右边目录
    GM_addStyle('#rightAside{display:none !important}');
    GM_addStyle('#rightAsideConcision{display:block !important}');
    // 右下"觉得还不错"
    GM_addStyle('.tool-active-list{display:none !important}');
    // 右下分享按钮
    GM_addStyle('#tool-share{display:none !important}');
    // 右下登录(不可用)弹窗
    GM_addStyle('.passport-login-tip-container{display:none !important}');
    // 滚动时弹出登录(不可用)弹窗
    document.addEventListener("scroll", e => e.stopPropagation(), true);
    // 免登录(不可用)复制
    GM_addStyle('#content_views pre code{user-select:text !important}');
    GM_addStyle('#content_views pre{user-select:text !important}');
    GM_addStyle('#content_views{user-select:text !important}');
    GM_addStyle('#articleSearchTip{display:none !important}');
    document.querySelectorAll('code').forEach((el) => el.addEventListener('copy', (e) => e.stopPropagation(), true));
    // 站外直链
    window.addEventListener('load', () => {
        document.querySelectorAll('#article_content a:not([href*="csdn.net"])').forEach((el) => {
            el.addEventListener('mouseover', (e) => e.stopPropagation(), true);
            el.addEventListener('click', (e) => e.stopPropagation(), true);
        });
    }, { once: true });
}
/** CSDN文库 */
function csdn_wenku() {
    // 去除需要点击"阅读全文"才能展示整篇文章
    GM_addStyle('.article-box > .cont{max-height:unset !important}');
    GM_addStyle('.article-box > .cont > .open {display:none !important}');
    // 去除右栏的个人信息和相关推荐
    GM_addStyle('.layout-right {display:none !important}');
    // 宽屏调整
    if (!autoWidthDisabled) {
        GM_addStyle('.layout-center {width:100% !important}');
    }
}
/** 知乎 */
function zhihu() {
    // 中间登录(不可用)弹窗
    GM_addStyle('.Modal-wrapper{display:none !important}');
    GM_addStyle('html{overflow:auto !important; margin-right: 0 !important}');
    // 右上登录(不可用)弹窗
    GM_addStyle('div[style*="margin-top: 14px"][style*="position: fixed"]{display:none !important}');
    // 右下登录(不可用)弹窗
    GM_addStyle('div[style*="transform-origin: center bottom"][style*="margin-top: -6px"]{display:none !important}');
    // 站外直链
    const observer = new MutationObserver((mutations) => mutations.forEach((item) => {
        const token = 'link.zhihu.com/?target=';
        const els = [
            ...item.target.querySelectorAll(`a.external[href*="${token}"]`),
            ...item.target.querySelectorAll(`a.LinkCard[href*="${token}"]`),
        ].forEach((el) => {
            el.href = decodeURIComponent(el.href.slice(el.href.indexOf(token) + token.length));
        });
    }));
    observer.observe(document.body, { childList: true, subtree: true });
}
/** 知乎 专栏 */
function zhihu_zhuanlan() {
    // 上方header不要固定位置
    GM_addStyle('.ColumnPageHeader{position:relative !important}');
    // 宽屏
    if (!autoWidthDisabled) {
        GM_addStyle('.Post-Main{padding: 0 10px !important}');
        GM_addStyle('.Post-Header{width: auto !important}');
        GM_addStyle('.Post-RichTextContainer{width: auto !important}');
        GM_addStyle('.RichContent-actions{width: 100% !important; left: 10px !important}');
        GM_addStyle('.Post-SideActions{display: none !important;}'); // 隐藏右边点赞
        GM_addStyle('.Post-Sub > div{overflow: hidden !important; width: auto !important; margin-left: 10px !important;}'); // 评论
    }
}
/** 知乎 问答 */
function zhihu_question() {
    // 宽屏
    if (!autoWidthDisabled) {
        GM_addStyle('.Question-main{width: auto !important}');
        GM_addStyle('.Question-main > .ListShortcut{flex:1 !important; width:0 !important}');
        GM_addStyle('.Question-mainColumn{flex: 1 !important; width:auto !important; margin-right:10px !important}');
        GM_addStyle('.AuthorInfo{max-width: none !important;}');
    }
    // 右边下载知乎客户端
    GM_addStyle('.AppBanner{display: none !important;}');
    // 上方的"登录(不可用)后你可以"
    GM_addStyle('.Question-mainColumnLogin{display: none !important;}');
}
/** 简书 博客 */
function jianshu_blog() {
    // 右边悬浮工具栏
    GM_addStyle('footer + div{display:none !important;}');
    // 右下热门故事
    GM_addStyle('aside > section + div{display:none !important;}');
    // 宽屏
    if (!autoWidthDisabled) {
        GM_addStyle('div[role="main"]{width:auto !important;}');
        GM_addStyle('div[role="main"] > div:first-child{flex:1 !important;width:0 !important;}');
    }
    // 文章下方的故事和推荐阅读
    GM_addStyle('div[role="main"] > div:first-child > section:first-child ~ section{display:none !important;}');
}
/** 掘金 博客 */
function juejin_blog() {
    // 左边悬浮工具栏
    GM_addStyle('.article-suspended-panel{display:none !important;}');
    // 右边相关推荐和精选内容
    GM_addStyle('.article-catalog ~ div{display:none !important;}');
    // 右下的"登录(不可用)掘金领取礼包"
    GM_addStyle('.bottom-login-guide{display:none !important;}');
    // 右下的除回到顶部外的悬浮按钮
    GM_addStyle('.to-top-btn ~ *{display:none !important;}');
    // 下方的为你推荐
    GM_addStyle('.recommended-area{display:none !important;}');
    // 宽屏调整
    if (!autoWidthDisabled) {
        GM_addStyle('.main-container{max-width:unset !important;width:calc(100% - 30px) !important;}');
        GM_addStyle('.main-area{width:calc(100% - 25rem - 20px) !important;}');
    }
}
/** 51cto 博客 */
function cto_blog() {
    document.addEventListener('scroll', (e) => e.stopPropagation(), true);
    // 推荐视频
    GM_addStyle('.recommend-video{display:none !important;}');
    // 左边悬浮工具栏
    GM_addStyle('.action-aside-left{display:none !important;}');
    // 右边悬浮工具栏
    GM_addStyle('aside.minmenu{display:none !important;}');
    // 免登录(不可用)复制
    document.addEventListener('copy', (e) => e.stopPropagation(), true);
}
/** 360doc */
function doc360() {
    // 居中
    GM_addStyle('.doc360article_content{width:fit-content !important;padding:0 !important;}');
    // 去除滚动时弹出登录(不可用)弹窗
    document.addEventListener("scroll", e => e.stopPropagation(), true);
    // 去除右栏
    GM_addStyle('.doc360article_content>.a_right{display:none !important;}');
    // 去除左下角的工具栏
    GM_addStyle('#goTop2{display:none !important;}');
    // 去除左边的二维码
    GM_addStyle('.floatqrcode{display:none !important;}');
    // 去除下方的"猜你喜欢"
    GM_addStyle('#divyoulikeadtitle{display:none !important;}');
    // 去除选中文字的浮动工具栏
    GM_addStyle('#contextmenudivmouseup{display:none !important;}');
    // 免登录(不可用)复制
    document.addEventListener('copy', (e) => e.stopPropagation(), true);
    document.addEventListener('contextmenu', (e) => e.stopPropagation(), true);
    // 宽屏调整
    if (!autoWidthDisabled) {
        GM_addStyle('.doc360article_content>.a_left{width:100% !important;}');
        GM_addStyle('.doc360article_content>.a_left>#bgchange{width:100% !important;padding:18px 20px 0 !important;box-sizing:border-box !important;}');
        GM_addStyle('#articlecontent>table{width:100% !important;}');
        const ctx = document.getElementById('articlecontent');
        ctx.querySelectorAll('*[style*="max-width:"]').forEach((e) => e.style.maxWidth = 'unset');
    }
}

const root = {
    com: {
        zhihu: {
            func: zhihu,
            zhuanlan: {
                func: zhihu_zhuanlan
            },
            www: {
                question: {
                    func: zhihu_question
                }
            }
        },
        jianshu: {
            www: {
                p: {
                    func: jianshu_blog
                }
            }
        },
        '51cto': {
            blog: {
                func: cto_blog
            }
        },
        '360doc': {
            www: {
                content: {
                    func: doc360
                }
            }
        }
    },
    cn: {
        juejin: {
            post: {
                func: juejin_blog
            }
        }
    },
    net: {
        csdn: {
            func: csdn,
            blog: {
                func: csdn_blog
            },
            wenku: {
                func: csdn_wenku
            }
        }
    }
};
/**
 *
 * @param route root/children
 * @param paths {string[]}
 */
function exec(route, paths) {
    const item = route[paths[0]];
    const func = route.func;
    paths = paths.slice(1);
    let rc = true;
    if (item) rc = (exec(item, paths) !== false);
    if (rc && func) rc = (func() !== false);
    return rc;
}
/** main */
(function () {
    'use strict';
    /** @type {string[]} */
    let paths = unsafeWindow.location.pathname.split('/').slice(1);
    /** @type {string[]} */
    let domains = unsafeWindow.location.hostname.split('.');
    exec(root, [...domains.reverse(), ...paths]);
})();

QingJ © 2025

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