// ==UserScript== // @name CSDN|简书优化 // @namespace http://tampermonkey.net/ // @version 0.5.0 // @description 支持手机端和PC端 // @author MT-戒酒的李白染 // @include http*://www.csdn.net/* // @include http*://bbs.csdn.net/* // @include http*://www.jianshu.com/* // @include http*://*blog.csdn.net/* // @include http*://download.csdn.net/* // @include http*://huaweicloud.csdn.net/* // @grant GM_addStyle // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM_listValues // @grant unsafeWindow // @run-at document-start // @require https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.4.1/jquery.min.js // @require https://greasyfork.org/scripts/449471-viewer/code/Viewer.js?version=1081056 // @require https://greasyfork.org/scripts/455186-whitesevsutils/code/WhiteSevsUtils.js?version=1137273 // @downloadURL none // ==/UserScript== (function () { "use strict"; function waitForElementToRemove(_query_ = "") { /* 移除元素(未出现也可以等待出现) */ Utils.waitForDOM(_query_).then((dom) => { dom.forEach((item) => { $(item).remove(); }); }); } function JianShu() { /* 简书 */ function isJianShu() { /* 判断是否是 简书 */ return Boolean(/jianshu.com/i.test(window.location.origin)); } function PC() { console.log("简书"); const css = ` .download-app-guidance, .call-app-btn, .collapse-tips, .note-graceful-button, .app-open, .header-wrap, .recommend-wrap.recommend-ad, .call-app-Ad-bottom, #recommended-notes p.top-title span.more, #homepage .modal, button.index_call-app-btn, span.note__flow__download, .download-guide, #footer, .comment-open-app-btn-wrap, .nav.navbar-nav + div{ display:none !important; } body.reader-day-mode.normal-size { overflow: auto !important; } .collapse-free-content{ height:auto !important; } .copyright{ color:#000 !important; } #note-show .content .show-content-free .collapse-free-content:after{ background-image:none !important; } `; GM_addStyle(css); Utils.waitForDOM('div#homepage div[class*="dialog-"]').then((dom) => { if (dom.length) { dom[0].style["visibility"] = "hidden"; } }); Utils.mutationObserver('div#homepage div[class*="dialog-"]', { fn: (mutations) => { if (mutations.length == 0) { return; } if (mutations[0].target.style["display"] != "none") { document .querySelector('div#homepage div[class*="dialog-"] .cancel') ?.click(); } }, config: { /* 子节点的变动(新增、删除或者更改) */ childList: false, /* 属性的变动 */ attributes: true, /* 节点内容或节点文本的变动 */ characterData: true, /* 是否将观察器应用于该节点的所有后代节点 */ subtree: true, }, }); } if (isJianShu()) { PC(); } } function CSDN() { /* csdn-移动端 */ function isCSDN() { /* 判断是否是 CSDN */ return Boolean(/csdn.net/i.test(window.location.origin)); } function Mobile() { /* 移动端 */ console.log("CSDN-移动端"); const css = ` #mainBox{ width: auto; } .user-desc.user-desc-fix{ height: auto !important; overflow: auto !important; } #operate,.feed-Sign-span, .view_comment_box, .weixin-shadowbox.wap-shadowbox, .feed-Sign-span, .user-desc.user-desc-fix, .comment_read_more_box, #content_views pre.set-code-hide .hide-preCode-box, .passport-login-container, .hljs-button[data-title='登录后复制'], .article-show-more, #treeSkill, div.btn_open_app_prompt_div, div.readall_box, div.aside-header-fixed{ display:none !important; } .GM-csdn-dl{ padding: .24rem .32rem; width: 100%; justify-content: space-between; -webkit-box-pack: justify; border-bottom: 1px solid #F5F6F7!important; } .GM-csdn-title{ font-size: .3rem; color: #222226; letter-spacing: 0; line-height: .44rem; font-weight: 600; //max-height: .88rem; word-break: break-all; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2 } .GM-csdn-title a{ word-break: break-all; color: #222226; font-weight: 600; } .GM-csdn-title em,.GM-csdn-content em{ font-style: normal; color: #fc5531 } .GM-csdn-content{ //max-width: 5.58rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; color: #555666; font-size: .24rem; line-height: .34rem; max-height: .34rem; word-break: break-all; -webkit-box-flex: 1; -ms-flex: 1; flex: 1; margin-top: .16rem; } .GM-csdn-img img{ width: 2.18rem; height: 1.58rem; //margin-left: .16rem } .GM-csdn-Redirect{ color: #fff; background-color: #f90707; font-family: sans-serif; margin: auto 2px; border: 1px solid #ccc; border-radius: 4px; padding: 0px 3px; font-size: xx-small; display: inline; white-space: nowrap; } .component-box .praise { background: #ff5722; border-radius: 5px; padding: 0px 8px; height: auto; } .component-box .praise,.component-box .share { color: #fff; } .component-box a { display: inline-block; font-size:xx-small; } .component-box { display: inline; margin: 0; position: relative; white-space:nowrap; } .csdn-edu-title{ background: #4d6de1; border-radius: 5px; padding: 0px 8px; height: auto; color: #fff !important; } #comment{ max-height: none !important; } #content_views pre, #content_views pre code{ webkit-touch-callout: text !important; -webkit-user-select: text !important; -khtml-user-select: text !important; -moz-user-select: text !important; -ms-user-select: text !important; user-select: text !important; } #content_views pre.set-code-hide, .article_content{ height: 100% !important; overflow: auto !important; } `; GM_addStyle(css); function refactoringRecommendation() { /* 重构底部推荐 */ function refactoring() { /* 反复执行的重构函数 */ $(".container-fluid").each((index, item) => { item = $(item); var url = ""; /* 链接 */ var title = ""; /* 标题 */ var content = ""; /* 内容 */ var img = ""; /* 图片 */ var isCSDNDownload = false; /* 判断是否是CSDN资源下载 */ var isCSDNEduDownload = false; /* 判断是否是CSDN-学院资源下载 */ if (item.attr("data-url")) { /* 存在真正的URL */ url = item.attr("data-url"); title = item.find(".recommend_title div.left").html(); content = item.find(".text").html(); if (item.find(".recommend-img").length) { /* 如果有图片就加进去 */ item.find(".recommend-img").each((_index_, _item_) => { img += $(_item_).html(); }); } } else { console.log("节点上无data-url"); url = item.find("a[data-type]").attr("href"); title = item.find(".recommend_title div.left").html(); content = item.find(".text").html(); } if (GM_Menu.getEnable("showDirect")) { /* 开启就添加 */ title += `