// ==UserScript== // @name H2P: CSDN 界面优化 // @namespace http://tampermonkey.net/ // @version 0.0.3 // @icon https://csdnimg.cn/cdn/content-toolbar/csdn-logo.png?v=20200416.1 // @description CSDN 界面优化 // @author H2P // @compatible chrome // @match *://so.csdn.net/so/search/s.do?* // @match *://blog.csdn.net/* // @note 2020.07.20-V0.0.01 搜索界面和博客界面元素隐藏 // @note 2020.07.20-V0.0.02 点赞栏位置固定 // @note 2020.07.20-V0.0.03 搜索、分类专栏位置调整 // @downloadURL none // ==/UserScript== (function() { 'use strict'; const $H2P = function (xpath, one = true) { if (one) { return document.querySelector(xpath); } else { return Array.from(document.querySelectorAll(xpath)); } } const isCSDNSearch = window.location.href.includes('/so.csdn.net/so/search/'); const isCSDNBlog = window.location.href.includes('/blog.csdn.net/'); console.log(`isCSDNBlog: ${isCSDNBlog}`); let eleStyle = document.createElement('style'); if (isCSDNSearch) { // 右侧边栏 eleStyle.innerHTML += ` .con-r { display: none!important; } .con-l { width: 100%; } .con-l .con-l-right { width: calc(100% - 104px); } `; } else if (isCSDNBlog) { // 导航栏、主体 eleStyle.innerHTML += ` .csdn-toolbar { position: fixed!important; z-index: 9999; top: 0!important; } .main_father { margin-top: 44px!important; } .main_father main { margin-bottom: 10px!important; } `; // 右侧推荐、最新评论、热门文章 eleStyle.innerHTML += ` .recommend-right_aside, #asideNewComments, #asideHotArticle { display: none!important; } .more-toolbox .left-toolbox { position: relative!important; } aside.blog_container_aside { position: fixed!important; top: auto!important; bottom: auto!important; } `; // 分类专栏 eleStyle.innerHTML += ` #asideCategory > .aside-content { max-height: fit-content!important; overflow-y: scroll!important; } #asideCategory > .aside-content + p.text-center { display: none!important; } `; // 举报 eleStyle.innerHTML += ` .csdn-side-toolbar { display: none!important; } `; // 主体下方推荐、评论 eleStyle.innerHTML += ` .first-recommend-box, .second-recommend-box, .comment-box, .recommend-item-box.recommend-recommend-box, .recommend-other-item-box { display: none!important; } `; // 皮肤主题、底部 eleStyle.innerHTML += ` .template-box, .bottom-pub-footer { display: none!important; } `; } document.head.appendChild(eleStyle); // 调换分类专栏位置 let ele = document.createElement('aside'); ele.id = 'h2p-aside-right'; ele.classList.add('blog_container_aside'); let invl = setInterval(() => { if ($H2P('div#rightAside')) { $H2P('div#rightAside').appendChild(ele); window.clearInterval(invl); invl = setInterval(() => { if ($H2P('div#asideSearchArticle') && $H2P('div#asideCategory')) { $H2P('aside#h2p-aside-right').appendChild($H2P('div#asideSearchArticle')); $H2P('aside#h2p-aside-right').appendChild($H2P('div#asideCategory')); window.clearInterval(invl); } }, 100); } }, 100); })();