CSDN|简书优化

支持手机端和PC端,屏蔽广告,优化浏览体验,自动跳转简书拦截URL

当前为 2023-09-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name CSDN|简书优化
  3. // @icon https://www.csdn.net/favicon.ico
  4. // @namespace https://greasyfork.org/zh-CN/scripts/406136-csdn-简书优化
  5. // @supportURL https://greasyfork.org/zh-CN/scripts/406136-csdn-简书优化/feedback
  6. // @version 0.7.4
  7. // @description 支持手机端和PC端,屏蔽广告,优化浏览体验,自动跳转简书拦截URL
  8. // @author WhiteSevs
  9. // @match http*://*.csdn.net/*
  10. // @match http*://*.jianshu.com/*
  11. // @match http*://*.jianshu.io/*
  12. // @grant GM_registerMenuCommand
  13. // @grant GM_unregisterMenuCommand
  14. // @grant GM_getValue
  15. // @grant GM_setValue
  16. // @grant GM_deleteValue
  17. // @grant GM_listValues
  18. // @grant GM_info
  19. // @grant unsafeWindow
  20. // @run-at document-start
  21. // @require https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.4.1/jquery.min.js
  22. // @require https://greasyfork.org/scripts/449471-viewer/code/Viewer.js?version=1170654
  23. // @require https://greasyfork.org/scripts/455186-whitesevsutils/code/WhiteSevsUtils.js?version=1244325
  24. // ==/UserScript==
  25.  
  26. (function () {
  27. const utils = Utils.noConflict();
  28. const jQuery = $.noConflict(true);
  29. const log = new utils.Log(GM_info);
  30. log.config({
  31. logMaxCount: 20,
  32. autoClearConsole: true,
  33. });
  34. /**
  35. * 因为在有些页面上,比如:简书,当插入style元素到head中,该页面清除该元素
  36. */
  37. const GM_addStyle = utils.GM_addStyle;
  38. let GM_Menu = null;
  39. /**
  40. * 移除元素(未出现也可以等待出现)
  41. * @param {string} selectorText 元素选择器
  42. */
  43. const waitForElementToRemove = function (selectorText = "") {
  44. utils.waitNode(selectorText).then((dom) => {
  45. dom.forEach((item) => {
  46. item.remove();
  47. });
  48. });
  49. };
  50.  
  51. const Optimization = {
  52. jianshu: {
  53. /**
  54. * 判断是否是简书
  55. */
  56. locationMatch() {
  57. return Boolean(/jianshu.(com|io)/i.test(window.location.origin));
  58. },
  59. PC: {
  60. /**
  61. * 添加屏蔽CSS
  62. */
  63. addCSS() {
  64. GM_addStyle(`
  65. .download-app-guidance,
  66. .call-app-btn,
  67. .collapse-tips,
  68. .note-graceful-button,
  69. .app-open,
  70. .header-wrap,
  71. .recommend-wrap.recommend-ad,
  72. .call-app-Ad-bottom,
  73. #recommended-notes p.top-title span.more,
  74. #homepage .modal,
  75. button.index_call-app-btn,
  76. span.note__flow__download,
  77. .download-guide,
  78. #footer,
  79. .comment-open-app-btn-wrap,
  80. .nav.navbar-nav + div,
  81. .self-flow-ad,
  82. #free-reward-panel,
  83. div[id*='AdFive'],
  84. #index-aside-download-qrbox,
  85. .baidu-app-download-2eIkf_1,
  86. /* 底部的"小礼物走一走,来简书关注我"、赞赏支持和更多精彩内容,就在简书APP */
  87. div[role="main"] > div > section:first-child > div:nth-last-child(2){
  88. display:none !important;
  89. }
  90. body.reader-day-mode.normal-size {
  91. overflow: auto !important;
  92. }
  93. .collapse-free-content{
  94. height:auto !important;
  95. }
  96. .copyright{
  97. color:#000 !important;
  98. }
  99. #note-show .content .show-content-free .collapse-free-content:after{
  100. background-image:none !important;
  101. }
  102. footer > div > div{
  103. justify-content: center;
  104. }
  105. /* 修复底部最后编辑于:。。。在某些套壳浏览器上的错位问题 */
  106. #note-show .content .show-content-free .note-meta-time{
  107. margin-top: 0px !important;
  108. }
  109. `);
  110. },
  111. /**
  112. * 全文居中
  113. */
  114. articleCenter() {
  115. log.success("全文居中");
  116. GM_addStyle(`
  117. div[role=main] aside,
  118. div._3Pnjry{
  119. display: none !important;
  120. }
  121. div._gp-ck{
  122. width: 100% !important;
  123. }`);
  124. waitForElementToRemove("div[role=main] aside");
  125. waitForElementToRemove("div._3Pnjry");
  126. utils.waitNode("div._gp-ck").then((dom) => {
  127. dom.forEach((item) => {
  128. item.style["width"] = "100%";
  129. });
  130. });
  131. },
  132. /**
  133. * 去除剪贴板劫持
  134. */
  135. removeClipboardHijacking() {
  136. log.success("去除剪贴板劫持");
  137. const stopNativePropagation = (event) => {
  138. event.stopPropagation();
  139. };
  140. window.addEventListener("copy", stopNativePropagation, true);
  141. document.addEventListener("copy", stopNativePropagation, true);
  142. },
  143. /**
  144. * 自动展开全文
  145. */
  146. autoExpandFullText() {
  147. utils
  148. .waitNode(`div#homepage div[class*="dialog-"]`)
  149. .then((nodeList) => {
  150. nodeList[0].style["visibility"] = "hidden";
  151. utils.mutationObserver(nodeList[0], {
  152. callback: (mutations) => {
  153. if (mutations.length == 0) {
  154. return;
  155. }
  156. if (mutations[0].target.style["display"] != "none") {
  157. log.success("自动展开全文");
  158. document
  159. .querySelector(
  160. 'div#homepage div[class*="dialog-"] .cancel'
  161. )
  162. ?.click();
  163. }
  164. },
  165. config: {
  166. /* 子节点的变动(新增、删除或者更改) */
  167. childList: false,
  168. /* 属性的变动 */
  169. attributes: true,
  170. /* 节点内容或节点文本的变动 */
  171. characterData: true,
  172. /* 是否将观察器应用于该节点的所有后代节点 */
  173. subtree: true,
  174. },
  175. });
  176. });
  177. },
  178. /**
  179. * 去除简书拦截其它网址的url并自动跳转
  180. */
  181. jumpRedirect() {
  182. if (window.location.pathname === "/go-wild") {
  183. /* 禁止简书拦截跳转 */
  184. window.stop();
  185. let search = window.location.href.replace(
  186. window.location.origin + "/",
  187. ""
  188. );
  189. search = decodeURIComponent(search);
  190. let newURL = search
  191. .replace(/^go-wild\?ac=2&url=/gi, "")
  192. .replace(/^https:\/\/link.zhihu.com\/\?target\=/gi, "");
  193. window.location.href = newURL;
  194. }
  195. },
  196. /**
  197. * 屏蔽相关文章
  198. */
  199. shieldRelatedArticles() {
  200. log.success("屏蔽相关文章");
  201. GM_addStyle(`
  202. div[role="main"] > div > section:nth-child(2){
  203. display: none !important;
  204. }
  205. `)
  206. },
  207. /**
  208. * 屏蔽评论区
  209. */
  210. shieldUserComments() {
  211. log.success("屏蔽评论区");
  212. GM_addStyle(`
  213. div#note-page-comment{
  214. display: none !important;
  215. }
  216. `)
  217. },
  218. /**
  219. * 屏蔽推荐阅读
  220. */
  221. shieldRecommendedReading() {
  222. log.success("屏蔽推荐阅读");
  223. GM_addStyle(`
  224. div[role="main"] > div > section:last-child{
  225. display: none !important;
  226. }
  227. `)
  228. },
  229. run() {
  230. this.addCSS();
  231. this.removeClipboardHijacking();
  232. this.autoExpandFullText();
  233. if (GM_Menu.get("JianShuArticleCenter")) {
  234. this.articleCenter();
  235. }
  236. if (GM_Menu.get("JianShuShieldRelatedArticles")) {
  237. this.shieldRelatedArticles();
  238. }
  239. if (GM_Menu.get("JianShuShieldUserComments")) {
  240. this.shieldUserComments();
  241. }
  242. if (GM_Menu.get("JianShuShieldRecommendedReading")) {
  243. this.shieldRecommendedReading();
  244. }
  245. },
  246. },
  247. Mobile: {
  248. addCSS() {
  249. Optimization.jianshu.PC.addCSS();
  250. },
  251. /**
  252. * 手机-移除底部推荐阅读
  253. */
  254. removeFooterRecommendRead() {
  255. log.success("移除底部推荐阅读");
  256. GM_addStyle(`
  257. #recommended-notes{
  258. display: none !important;
  259. }`);
  260. },
  261. /**
  262. * 处理原型
  263. */
  264. handlePrototype() {
  265. log.success("处理原型添加script标签");
  266. let originalAppendChild = Node.prototype.appendChild;
  267. Node.prototype.appendChild = function (element) {
  268. /* 允许添加的元素localName */
  269. let allowElementLocalNameList = ["img"];
  270. /* 不允许script标签加载包括jianshu.io的js资源,会让简书跳到广告页面 */
  271. if (
  272. element.src &&
  273. !element.src.includes("jianshu.io") &&
  274. !allowElementLocalNameList.includes(element.localName)
  275. ) {
  276. log.success(["禁止添加的元素", element]);
  277. return null;
  278. } else {
  279. return originalAppendChild.call(this, element);
  280. }
  281. };
  282. },
  283. /**
  284. * 屏蔽评论区
  285. */
  286. shieldUserComments() {
  287. log.success("屏蔽评论区");
  288. GM_addStyle(`
  289. #comment-main{
  290. display: none !important;
  291. }
  292. `);
  293. },
  294. run() {
  295. this.handlePrototype();
  296. this.addCSS();
  297. Optimization.jianshu.PC.removeClipboardHijacking();
  298. Optimization.jianshu.PC.autoExpandFullText();
  299. if (GM_Menu.get("JianShuremoveFooterRecommendRead")) {
  300. this.removeFooterRecommendRead();
  301. }
  302. if (GM_Menu.get("JianShuShieldUserComments")) {
  303. this.shieldUserComments();
  304. }
  305. },
  306. },
  307. /**
  308. * 函数入口
  309. */
  310. run() {
  311. this.PC.jumpRedirect();
  312. if (utils.isPhone()) {
  313. log.success("简书-移动端");
  314. this.Mobile.run();
  315. } else {
  316. log.success("简书-桌面端");
  317. this.PC.run();
  318. }
  319. },
  320. },
  321. csdn: {
  322. /**
  323. * 判断是否是CSDN
  324. */
  325. locationMatch() {
  326. return Boolean(/csdn.net/i.test(window.location.origin));
  327. },
  328. PC: {
  329. addCSS() {
  330. GM_addStyle(`
  331. .ecommend-item-box.recommend-recommend-box,
  332. .login-mark,
  333. .opt-box.text-center,
  334. .leftPop,
  335. #csdn-shop-window,
  336. .toolbar-advert,
  337. .hide-article-box,
  338. .user-desc.user-desc-fix,
  339. .recommend-card-box,
  340. .more-article,
  341. .article-show-more,
  342. #csdn-toolbar-profile-nologin,
  343. .guide-rr-first,
  344. #recommend-item-box-tow,
  345. /* 发文章得原力分图片提示 */
  346. div.csdn-toolbar-creative-mp,
  347. /* 阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。 */
  348. #toolBarBox div.write-guide-buttom-box,
  349. /* 觉得还不错? 一键收藏 */
  350. ul.toolbox-list div.tool-active-list{
  351. display: none !important;
  352. }
  353. .comment-list-box{
  354. max-height: none !important;
  355. }
  356. .blog_container_aside,
  357. #nav{
  358. margin-left: -45px;
  359. }
  360. .recommend-right.align-items-stretch.clearfix,.dl_right_fixed{
  361. margin-left: 45px;
  362. }
  363. #content_views pre,
  364. #content_views pre code{
  365. user-select: text !important;
  366. }
  367. #article_content,
  368. .user-article.user-article-hide{
  369. height: auto !important;
  370. overflow: auto !important;
  371. }
  372. `);
  373. },
  374. /**
  375. * 去除剪贴板劫持
  376. */
  377. removeClipboardHijacking() {
  378. log.info("去除剪贴板劫持");
  379. jQuery(".article-copyright")?.remove();
  380. if (unsafeWindow.articleType) {
  381. unsafeWindow.articleType = 0;
  382. }
  383. if (
  384. unsafeWindow.csdn &&
  385. unsafeWindow.csdn.copyright &&
  386. unsafeWindow.csdn.copyright.textData
  387. ) {
  388. unsafeWindow.csdn.copyright.textData = "";
  389. }
  390. if (
  391. unsafeWindow.csdn &&
  392. unsafeWindow.csdn.copyright &&
  393. unsafeWindow.csdn.copyright.htmlData
  394. ) {
  395. unsafeWindow.csdn.copyright.htmlData = "";
  396. }
  397. },
  398. /**
  399. * 取消禁止复制
  400. */
  401. unBlockCopy() {
  402. log.info("取消禁止复制");
  403. jQuery(document).on("click", ".hljs-button", function (event) {
  404. utils.preventEvent(event);
  405. /* 复制按钮 */
  406. let btnNode = jQuery(this);
  407. /* 需要复制的文本 */
  408. let copyText = btnNode.parent().text();
  409. utils.setClip(copyText);
  410. btnNode.attr("data-title", "复制成功");
  411. });
  412. jQuery(document).on("mouseenter mouseleave", "pre", function () {
  413. this.querySelector(".hljs-button")?.setAttribute(
  414. "data-title",
  415. "复制"
  416. );
  417. });
  418. /* 取消Ctrl+C的禁止 */
  419. utils.waitNode("#content_views").then(() => {
  420. unsafeWindow.$("#content_views").unbind("copy");
  421. jQuery("#content_views")
  422. .off("copy")
  423. .on("copy", function (event) {
  424. utils.preventEvent(event);
  425. utils.setClip(unsafeWindow.getSelection().toString());
  426. return false;
  427. });
  428. });
  429. /* 删除所有复制按钮的原有的复制事件 */
  430. jQuery(".hljs-button").each((_, item) => {
  431. item.removeAttribute("onclick");
  432. });
  433. },
  434. /**
  435. * 点击代码块自动展开
  436. */
  437. clickPreCodeAutomatically() {
  438. if (!GM_Menu.get("autoExpandContent")) {
  439. return;
  440. }
  441. log.info("点击代码块自动展开");
  442. jQuery(document).on("click", "pre", function () {
  443. let clickNode = jQuery(this);
  444. clickNode.css("height", "auto");
  445. clickNode.find(".hide-preCode-box")?.remove();
  446. });
  447. },
  448. /**
  449. * 恢复评论到正确位置
  450. */
  451. restoreComments() {
  452. /* 第一条评论 */
  453. log.info("恢复评论到正确位置-第一条评论");
  454. utils.waitNode(".first-recommend-box").then((dom) => {
  455. jQuery(
  456. ".recommend-box.insert-baidu-box.recommend-box-style"
  457. ).prepend(jQuery(dom));
  458. });
  459. log.info("恢复评论到正确位置-第二条评论");
  460. /* 第二条评论 */
  461. utils.waitNode(".second-recommend-box").then((dom) => {
  462. jQuery(
  463. ".recommend-box.insert-baidu-box.recommend-box-style"
  464. ).prepend(jQuery(dom));
  465. });
  466. },
  467. /**
  468. * 标识CSDN下载的链接
  469. */
  470. identityCSDNDownload() {
  471. log.info("标识CSDN下载的链接");
  472. jQuery(
  473. ".recommend-item-box[data-url*='https://download.csdn.net/']"
  474. ).each((index, item) => {
  475. if (GM_Menu.get("removeCSDNDownloadPC")) {
  476. item.remove();
  477. } else {
  478. jQuery(item).find(".content-box").css("border", "2px solid red");
  479. }
  480. });
  481. },
  482. /**
  483. * 全文居中
  484. */
  485. articleCenter() {
  486. if (!GM_Menu.get("articleCenter")) {
  487. return;
  488. }
  489. log.info("全文居中");
  490. GM_addStyle(`
  491. aside.blog_container_aside{
  492. display:none !important;
  493. }
  494. #mainBox main{
  495. width: inherit !important;
  496. }
  497. `);
  498. GM_addStyle(`
  499. @media (min-width: 1320px) and (max-width:1380px) {
  500. .nodata .container {
  501. width:900px !important
  502. }
  503.  
  504. .nodata .container main {
  505. width: 900px
  506. }
  507. .nodata .container main #pcCommentBox pre >ol.hljs-ln {
  508. width: 490px !important
  509. }
  510. .nodata .container main .articleConDownSource {
  511. width: 500px
  512. }
  513. }
  514. @media screen and (max-width: 1320px) {
  515. .nodata .container {
  516. width:760px !important
  517. }
  518. .nodata .container main {
  519. width: 760px
  520. }
  521. .nodata .container main #pcCommentBox pre >ol.hljs-ln {
  522. width: 490px !important
  523. }
  524. .nodata .container main .toolbox-list .tool-reward {
  525. display: none
  526. }
  527. .nodata .container main .more-toolbox-new .toolbox-left .profile-box .profile-name {
  528. max-width: 128px
  529. }
  530. .nodata .container main .articleConDownSource {
  531. width: 420px
  532. }
  533. }
  534. @media screen and (min-width: 1380px) {
  535. .nodata .container {
  536. width:1010px !important
  537. }
  538. .nodata .container main {
  539. width: 1010px
  540. }
  541. .nodata .container main #pcCommentBox pre >ol.hljs-ln {
  542. width: 490px !important
  543. }
  544. .nodata .container main .articleConDownSource {
  545. width: 560px
  546. }
  547. }
  548. @media (min-width: 1550px) and (max-width:1700px) {
  549. .nodata .container {
  550. width:820px !important
  551. }
  552. .nodata .container main {
  553. width: 820px
  554. }
  555. .nodata .container main #pcCommentBox pre >ol.hljs-ln {
  556. width: 690px !important
  557. }
  558. .nodata .container main .articleConDownSource {
  559. width: 500px
  560. }
  561. }
  562. @media screen and (min-width: 1700px) {
  563. .nodata .container {
  564. width:1010px !important
  565. }
  566. .nodata .container main {
  567. width: 1010px
  568. }
  569. .nodata .container main #pcCommentBox pre >ol.hljs-ln {
  570. width: 690px !important
  571. }
  572. .nodata .container main .articleConDownSource {
  573. width: 560px
  574. }
  575. }
  576. `);
  577. },
  578. /**
  579. * 添加前往评论的按钮,在返回顶部的下面
  580. */
  581. addGotoRecommandButton() {
  582. log.info("添加前往评论的按钮,在返回顶部的上面");
  583. let gotoRecommandNode = jQuery(`
  584. <a class="option-box" data-type="gorecommand">
  585. <span class="show-txt" style="display:flex;opacity:100;">前往<br>评论</span>
  586. </a>
  587. `);
  588. jQuery(gotoRecommandNode).on("click", function () {
  589. log.info("滚动到评论");
  590. jQuery("html, body").animate(
  591. {
  592. scrollTop:
  593. jQuery("#toolBarBox").offset().top -
  594. jQuery("#csdn-toolbar").height() -
  595. 8,
  596. },
  597. 1000
  598. );
  599. });
  600. utils.waitNode(".csdn-side-toolbar").then(() => {
  601. jQuery(".csdn-side-toolbar a").eq("-2").after(gotoRecommandNode);
  602. });
  603. },
  604. /**
  605. * 屏蔽登录弹窗
  606. */
  607. shieldLoginDialog() {
  608. if (GM_Menu.get("shieldLoginDialog")) {
  609. log.info("屏蔽登录弹窗");
  610. window.GM_CSS_GM_shieldLoginDialog = [
  611. GM_addStyle(
  612. `.passport-login-container{display: none !important;}`
  613. ),
  614. ];
  615. }
  616. },
  617. /**
  618. * 自动展开内容块
  619. */
  620. autoExpandContent() {
  621. if (!GM_Menu.get("autoExpandContent")) {
  622. return;
  623. }
  624. log.info("自动展开内容块");
  625. GM_addStyle(`
  626. pre.set-code-hide{
  627. height: auto !important;
  628. }
  629. pre.set-code-hide .hide-preCode-box{
  630. display: none !important;
  631. }
  632. `);
  633. },
  634. /**
  635. * 屏蔽右侧悬浮按钮
  636. */
  637. csdnShieldfloatingButton() {
  638. if (!GM_Menu.get("csdnShieldfloatingButton")) {
  639. return;
  640. }
  641. log.info("屏蔽右侧悬浮按钮");
  642. GM_addStyle(`
  643. div.csdn-side-toolbar{
  644. display: none !important;
  645. }
  646. `);
  647. },
  648. /**
  649. * 屏蔽底部推荐文章
  650. */
  651. csdnShieldBottomRecommendArticle() {
  652. if (!GM_Menu.get("csdnShieldBottomRecommendArticle")) {
  653. return;
  654. }
  655. log.info("屏蔽底部推荐文章");
  656. GM_addStyle(`
  657. main > div.recommend-box {
  658. display: none !important;
  659. }
  660. `);
  661. },
  662. /**
  663. * 屏蔽底部悬浮工具栏
  664. */
  665. csdnShieldBottomFloatingToolbar() {
  666. if (!GM_Menu.get("csdnShieldBottomFloatingToolbar")) {
  667. return;
  668. }
  669. log.info("屏蔽底部悬浮工具栏");
  670. GM_addStyle(`
  671. #toolBarBox {
  672. display: none !important;
  673. }
  674. `);
  675. },
  676. /**
  677. * 显示/隐藏目录
  678. */
  679. showOrHideDirectory() {
  680. if (GM_Menu.get("showOrHideDirectory")) {
  681. log.info("显示目录");
  682. GM_addStyle(`
  683. aside.blog_container_aside{
  684. display: none !important;
  685. }
  686. `);
  687. } else {
  688. log.info("隐藏目录");
  689. GM_addStyle(`
  690. aside.blog_container_aside{
  691. display: block !important;
  692. }
  693. `);
  694. }
  695. },
  696. /**
  697. * 显示/隐藏侧边栏
  698. */
  699. showOrHideSidebar() {
  700. if (GM_Menu.get("showOrHideSidebar")) {
  701. log.info("显示侧边栏");
  702. GM_addStyle(`
  703. #rightAsideConcision{
  704. display: none !important;
  705. }
  706. `);
  707. } else {
  708. log.info("隐藏侧边栏");
  709. GM_addStyle(`
  710. #rightAsideConcision{
  711. display: block !important;
  712. }
  713. `);
  714. }
  715. },
  716. /**
  717. * 去除CSDN拦截其它网址的url并自动跳转
  718. */
  719. jumpRedirect() {
  720. /* https://link.csdn.net/?target=https%3A%2F%2Fjaist.dl.sourceforge.net%2Fproject%2Fportecle%2Fv1.11%2Fportecle-1.11.zip */
  721. if (
  722. window.location.hostname === "link.csdn.net" &&
  723. window.location.search.startsWith("?target")
  724. ) {
  725. /* 禁止CSDN拦截跳转 */
  726. window.stop();
  727. let search = window.location.search.replace(/^\?target=/gi, "");
  728. search = decodeURIComponent(search);
  729. let newURL = search;
  730. log.success(`跳转链接 ${newURL}`);
  731. window.location.href = newURL;
  732. }
  733. },
  734. run() {
  735. this.addCSS();
  736. this.articleCenter();
  737. this.shieldLoginDialog();
  738. this.autoExpandContent();
  739. this.csdnShieldfloatingButton();
  740. this.csdnShieldBottomRecommendArticle();
  741. this.csdnShieldBottomFloatingToolbar();
  742. this.showOrHideDirectory();
  743. this.showOrHideSidebar();
  744. let that = this;
  745. jQuery(document).ready(function () {
  746. that.removeClipboardHijacking();
  747. that.unBlockCopy();
  748. that.identityCSDNDownload();
  749. that.clickPreCodeAutomatically();
  750. that.restoreComments();
  751. that.addGotoRecommandButton();
  752. });
  753. },
  754. },
  755. Mobile: {
  756. addCSS() {
  757. GM_addStyle(`
  758. #mainBox{
  759. width: auto;
  760. }
  761. .user-desc.user-desc-fix{
  762. height: auto !important;
  763. overflow: auto !important;
  764. }
  765. #operate,.feed-Sign-span,
  766. .view_comment_box,
  767. .weixin-shadowbox.wap-shadowbox,
  768. .feed-Sign-span,
  769. .user-desc.user-desc-fix,
  770. .comment_read_more_box,
  771. #content_views pre.set-code-hide .hide-preCode-box,
  772. .passport-login-container,
  773. .hljs-button[data-title='登录后复制'],
  774. .article-show-more,
  775. #treeSkill,
  776. div.btn_open_app_prompt_div,
  777. div.readall_box,
  778. div.aside-header-fixed,
  779. div.feed-Sign-weixin,
  780. div.ios-shadowbox{
  781. display:none !important;
  782. }
  783. .component-box .praise {
  784. background: #ff5722;
  785. border-radius: 5px;
  786. padding: 0px 8px;
  787. height: auto;
  788. }
  789. .component-box .praise,.component-box .share {
  790. color: #fff;
  791. }
  792. .component-box a {
  793. display: inline-block;
  794. font-size:xx-small;
  795. }
  796. .component-box {
  797. display: inline;
  798. margin: 0;
  799. position: relative;
  800. white-space:nowrap;
  801. }
  802. .csdn-edu-title{
  803. background: #4d6de1;
  804. border-radius: 5px;
  805. padding: 0px 8px;
  806. height: auto;
  807. color: #fff !important;
  808. }
  809. #comment{
  810. max-height: none !important;
  811. }
  812. #content_views pre,
  813. #content_views pre code{
  814. webkit-touch-callout: text !important;
  815. -webkit-user-select: text !important;
  816. -khtml-user-select: text !important;
  817. -moz-user-select: text !important;
  818. -ms-user-select: text !important;
  819. user-select: text !important;
  820. }
  821. #content_views pre.set-code-hide,
  822. .article_content{
  823. height: 100% !important;
  824. overflow: auto !important;
  825. }`);
  826. GM_addStyle(`
  827. .GM-csdn-dl{
  828. padding: .24rem .32rem;
  829. width: 100%;
  830. justify-content: space-between;
  831. -webkit-box-pack: justify;
  832. border-bottom: 1px solid #F5F6F7!important;
  833. }
  834. .GM-csdn-title{
  835. font-size: .3rem;
  836. color: #222226;
  837. letter-spacing: 0;
  838. line-height: .44rem;
  839. font-weight: 600;
  840. //max-height: .88rem;
  841. word-break: break-all;
  842. overflow: hidden;
  843. display: -webkit-box;
  844. -webkit-box-orient: vertical;
  845. -webkit-line-clamp: 2
  846. }
  847. .GM-csdn-title a{
  848. word-break: break-all;
  849. color: #222226;
  850. font-weight: 600;
  851. }
  852. .GM-csdn-title em,.GM-csdn-content em{
  853. font-style: normal;
  854. color: #fc5531
  855. }
  856. .GM-csdn-content{
  857. //max-width: 5.58rem;
  858. overflow: hidden;
  859. text-overflow: ellipsis;
  860. display: -webkit-box;
  861. -webkit-line-clamp: 1;
  862. -webkit-box-orient: vertical;
  863. color: #555666;
  864. font-size: .24rem;
  865. line-height: .34rem;
  866. max-height: .34rem;
  867. word-break: break-all;
  868. -webkit-box-flex: 1;
  869. -ms-flex: 1;
  870. flex: 1;
  871. margin-top: .16rem;
  872. }
  873. .GM-csdn-img img{
  874. width: 2.18rem;
  875. height: 1.58rem;
  876. //margin-left: .16rem
  877. }
  878. .GM-csdn-Redirect{
  879. color: #fff;
  880. background-color: #f90707;
  881. font-family: sans-serif;
  882. margin: auto 2px;
  883. border: 1px solid #ccc;
  884. border-radius: 4px;
  885. padding: 0px 3px;
  886. font-size: xx-small;
  887. display: inline;
  888. white-space: nowrap;
  889. }`);
  890. },
  891. /**
  892. * 重构底部推荐
  893. */
  894. refactoringRecommendation() {
  895. log.info("重构底部推荐");
  896. function refactoring() {
  897. /* 反复执行的重构函数 */
  898. jQuery(".container-fluid").each((index, item) => {
  899. item = jQuery(item);
  900. var url = ""; /* 链接 */
  901. var title = ""; /* 标题 */
  902. var content = ""; /* 内容 */
  903. var img = ""; /* 图片 */
  904. var isCSDNDownload = false; /* 判断是否是CSDN资源下载 */
  905. var isCSDNEduDownload = false; /* 判断是否是CSDN-学院资源下载 */
  906. if (item.attr("data-url")) {
  907. /* 存在真正的URL */
  908. url = item.attr("data-url");
  909. title = item.find(".recommend_title div.left").html();
  910. content = item.find(".text").html();
  911. if (item.find(".recommend-img").length) {
  912. /* 如果有图片就加进去 */
  913. item.find(".recommend-img").each((_index_, _item_) => {
  914. img += jQuery(_item_).html();
  915. });
  916. }
  917. } else {
  918. log.info("节点上无data-url");
  919. url = item.find("a[data-type]").attr("href");
  920. title = item.find(".recommend_title div.left").html();
  921. content = item.find(".text").html();
  922. }
  923. if (GM_Menu.get("showDirect")) {
  924. /* 开启就添加 */
  925. title += `<div class="GM-csdn-Redirect">Redirect</div>`;
  926. }
  927. var _URL_ = new URL(url);
  928. if (
  929. _URL_.host === "download.csdn.net" ||
  930. (_URL_.host === "www.iteye.com" &&
  931. _URL_.pathname.match(/^\/resource/gi))
  932. ) {
  933. /* 该链接为csdn资源下载 */
  934. log.info("该链接为csdn资源下载");
  935. isCSDNDownload = true;
  936. title += `<div class="component-box"><a class="praise" href="javascript:;">CSDN下载</a></div>`;
  937. } else if (_URL_.origin.match(/edu.csdn.net/gi)) {
  938. /* 该链接为csdn学院下载 */
  939. isCSDNEduDownload = true;
  940. log.info("该链接为csdn学院下载");
  941. title += `<div class="component-box"><a class="csdn-edu-title" href="javascript:;">CSDN学院</a></div>`;
  942. }
  943. item.attr("class", "GM-csdn-dl");
  944. item.attr("data-url", url);
  945. item.html(
  946. `<div class="GM-csdn-title"><div class="left">${title}</div></div><div class="GM-csdn-content">${content}</div><div class="GM-csdn-img">${img}</div>`
  947. );
  948. if (
  949. (isCSDNDownload || isCSDNEduDownload) &&
  950. GM_Menu.get("removeCSDNDownloadMobile")
  951. ) {
  952. item.remove();
  953. }
  954. /* jQuery("#recommend")
  955. .find(".recommend_list")
  956. .before(jQuery("#first_recommend_list").find("dl").parent().html()); */
  957. });
  958. }
  959. utils.waitNode("#recommend").then((nodeList) => {
  960. utils.mutationObserver(nodeList[0], {
  961. callback: () => {
  962. setTimeout(() => {
  963. refactoring();
  964. }, 300);
  965. },
  966. config: { childList: true, subtree: true, attributes: true },
  967. });
  968. });
  969.  
  970. this.recommendClickEvent();
  971. },
  972. /**
  973. * 设置底部推荐点击跳转事件
  974. */
  975. recommendClickEvent() {
  976. log.info("设置底部推荐点击跳转事件");
  977. jQuery(document).on("click", ".GM-csdn-dl", function () {
  978. let url = jQuery(this).attr("data-url");
  979. if (GM_Menu.get("openNewTab")) {
  980. window.open(url, "_blank");
  981. } else {
  982. window.location.href = url;
  983. }
  984. });
  985. },
  986. /**
  987. * 去除广告
  988. */
  989. removeAds() {
  990. log.info("去除广告");
  991. /* 登录窗口 */
  992. waitForElementToRemove(".passport-login-container");
  993. /* 打开APP */
  994. waitForElementToRemove(
  995. ".btn_open_app_prompt_box.detail-open-removed"
  996. );
  997. /* 广告 */
  998. waitForElementToRemove(".add-firstAd");
  999. /* 打开CSDN APP 小程序看全文 */
  1000. waitForElementToRemove("div.feed-Sign-weixin");
  1001. /* ios版本提示 */
  1002. waitForElementToRemove("div.ios-shadowbox");
  1003. },
  1004. run() {
  1005. this.addCSS();
  1006. let that = this;
  1007. jQuery(document).ready(function () {
  1008. that.removeAds();
  1009. that.refactoringRecommendation();
  1010. });
  1011. },
  1012. },
  1013. /**
  1014. * 函数入口
  1015. */
  1016. run() {
  1017. Optimization.csdn.PC.jumpRedirect();
  1018. if (utils.isPhone()) {
  1019. log.success("移动端模式");
  1020. this.Mobile.run();
  1021. } else {
  1022. log.success("桌面端模式");
  1023. this.PC.run();
  1024. }
  1025. },
  1026. },
  1027. huaWeiCSDN: {
  1028. /**
  1029. * 判断是否是CSDN
  1030. */
  1031. locationMatch() {
  1032. return Boolean(/huaweicloud.csdn.net/i.test(window.location.origin));
  1033. },
  1034. PC: {
  1035. addCSS() {
  1036. GM_addStyle(`
  1037. /* 底部免费抽xxx奖品广告 */
  1038. div.siderbar-box,
  1039. /* 华为开发者联盟加入社区 */
  1040. div.user-desc.user-desc-fix,
  1041. /* 点击阅读全文 */
  1042. div.article-show-more{
  1043. display: none !important;
  1044. }
  1045.  
  1046. /* 自动展开全文 */
  1047. .main-content .user-article{
  1048. height: auto !important;
  1049. overflow: auto !important;
  1050. }
  1051. `);
  1052. },
  1053. run() {
  1054. this.addCSS();
  1055. this.huaweiCSDNShieldCloudDeveloperTaskChallengeEvent();
  1056. this.huaweiCSDNShieldLeftFloatingButton();
  1057. this.huaweiCSDNBlockRightColumn();
  1058. this.huaweiCSDNBlockRecommendedContentAtTheBottom();
  1059. this.huaweiCSDNShieldTheBottomForMoreRecommendations();
  1060. },
  1061. /**
  1062. * 屏蔽云开发者任务挑战活动
  1063. */
  1064. huaweiCSDNShieldCloudDeveloperTaskChallengeEvent() {
  1065. let GM_cookie = new utils.GM_Cookie();
  1066. GM_cookie.set({ name: "show_join_group_index", value: 1 });
  1067. log.success("屏蔽云开发者任务挑战活动");
  1068. },
  1069. /**
  1070. * 屏蔽左侧悬浮按钮
  1071. */
  1072. huaweiCSDNShieldLeftFloatingButton() {
  1073. if (!GM_Menu.get("huaweiCSDNShieldLeftFloatingButton")) {
  1074. return;
  1075. }
  1076. log.success(
  1077. "屏蔽左侧悬浮按钮,包括当前阅读量、点赞按钮、评论按钮、分享按钮"
  1078. );
  1079. GM_addStyle(`
  1080. div.toolbar-wrapper.article-interact-bar{
  1081. display: none !important;
  1082. }`);
  1083. },
  1084. /**
  1085. * 屏蔽右侧栏
  1086. */
  1087. huaweiCSDNBlockRightColumn() {
  1088. if (!GM_Menu.get("huaweiCSDNBlockRightColumn")) {
  1089. return;
  1090. }
  1091. log.success("屏蔽右侧栏,包括相关产品-活动日历-运营活动-热门标签");
  1092. GM_addStyle(`
  1093. div.page-home-right.dp-aside-right{
  1094. display: none !important;
  1095. }
  1096. `);
  1097. },
  1098. /**
  1099. * 屏蔽底部推荐内容
  1100. */
  1101. huaweiCSDNBlockRecommendedContentAtTheBottom() {
  1102. if (!GM_Menu.get("huaweiCSDNBlockRecommendedContentAtTheBottom")) {
  1103. return;
  1104. }
  1105. log.success("屏蔽底部推荐内容");
  1106. GM_addStyle(`
  1107. div.recommend-card-box{
  1108. display: none !important;
  1109. }`);
  1110. },
  1111. /**
  1112. * 屏蔽底部更多推荐
  1113. */
  1114. huaweiCSDNShieldTheBottomForMoreRecommendations() {
  1115. if (!GM_Menu.get("huaweiCSDNShieldTheBottomForMoreRecommendations")) {
  1116. return;
  1117. }
  1118. log.success("屏蔽底部更多推荐");
  1119. GM_addStyle(`
  1120. div.more-article{
  1121. display: none !important;
  1122. }`);
  1123. },
  1124. },
  1125. },
  1126. };
  1127. if (Optimization.huaWeiCSDN.locationMatch()) {
  1128. GM_Menu = new utils.GM_Menu(
  1129. {
  1130. huaweiCSDNShieldCloudDeveloperTaskChallengeEvent: {
  1131. text: "电脑-屏蔽云开发者任务挑战活动",
  1132. enable: true,
  1133. showText: (_text_, _enable_) => {
  1134. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1135. },
  1136. callback: () => {
  1137. window.location.reload();
  1138. },
  1139. },
  1140. huaweiCSDNShieldLeftFloatingButton: {
  1141. text: "电脑-屏蔽左侧悬浮按钮",
  1142. enable: false,
  1143. title: "包括当前阅读量、点赞按钮、评论按钮、分享按钮",
  1144. showText: (_text_, _enable_) => {
  1145. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1146. },
  1147. callback: () => {
  1148. window.location.reload();
  1149. },
  1150. },
  1151. huaweiCSDNBlockRightColumn: {
  1152. text: "电脑-屏蔽右侧",
  1153. enable: false,
  1154. title: "包括相关产品-活动日历-运营活动-热门标签",
  1155. showText: (_text_, _enable_) => {
  1156. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1157. },
  1158. callback: () => {
  1159. window.location.reload();
  1160. },
  1161. },
  1162. huaweiCSDNBlockRecommendedContentAtTheBottom: {
  1163. text: "电脑-屏蔽底部推荐内容",
  1164. enable: false,
  1165. showText: (_text_, _enable_) => {
  1166. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1167. },
  1168. callback: () => {
  1169. window.location.reload();
  1170. },
  1171. },
  1172. huaweiCSDNShieldTheBottomForMoreRecommendations: {
  1173. text: "电脑-屏蔽底部更多推荐",
  1174. enable: false,
  1175. showText: (_text_, _enable_) => {
  1176. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1177. },
  1178. callback: () => {
  1179. window.location.reload();
  1180. },
  1181. },
  1182. },
  1183. false,
  1184. GM_getValue,
  1185. GM_setValue,
  1186. GM_registerMenuCommand,
  1187. GM_unregisterMenuCommand
  1188. );
  1189. Optimization.huaWeiCSDN.PC.run();
  1190. } else if (Optimization.csdn.locationMatch()) {
  1191. if (utils.isPhone()) {
  1192. GM_Menu = new utils.GM_Menu(
  1193. {
  1194. showDirect: {
  1195. text: "手机-标识处理过的底部推荐文章",
  1196. enable: true,
  1197. showText: (_text_, _enable_) => {
  1198. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1199. },
  1200. callback: () => {
  1201. window.location.reload();
  1202. },
  1203. },
  1204. openNewTab: {
  1205. text: "手机-底部推荐文章新标签页打开",
  1206. enable: true,
  1207. showText: (_text_, _enable_) => {
  1208. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1209. },
  1210. callback: () => {
  1211. window.location.reload();
  1212. },
  1213. },
  1214. removeCSDNDownloadMobile: {
  1215. text: "手机-移除文章底部的CSDN下载",
  1216. enable: false,
  1217. showText: (_text_, _enable_) => {
  1218. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1219. },
  1220. callback: () => {
  1221. window.location.reload();
  1222. },
  1223. },
  1224. },
  1225. false,
  1226. GM_getValue,
  1227. GM_setValue,
  1228. GM_registerMenuCommand,
  1229. GM_unregisterMenuCommand
  1230. );
  1231. } else {
  1232. GM_Menu = new utils.GM_Menu(
  1233. {
  1234. removeCSDNDownloadPC: {
  1235. text: "电脑-屏蔽底部推荐文章的CSDN下载",
  1236. enable: false,
  1237. showText: (_text_, _enable_) => {
  1238. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1239. },
  1240. callback: () => {
  1241. window.location.reload();
  1242. },
  1243. },
  1244. shieldLoginDialog: {
  1245. text: "电脑-屏蔽登录弹窗",
  1246. enable: true,
  1247. showText: (_text_, _enable_) => {
  1248. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1249. },
  1250. callback: (_key_, _enable_) => {
  1251. if (!_enable_) {
  1252. window.GM_CSS_GM_shieldLoginDialog?.forEach((item) => {
  1253. item.remove();
  1254. });
  1255. } else {
  1256. if (typeof window.GM_CSS_GM_shieldLoginDialog !== "undefined") {
  1257. window.GM_CSS_GM_shieldLoginDialog = [
  1258. ...window.GM_CSS_GM_shieldLoginDialog,
  1259. GM_addStyle(
  1260. `.passport-login-container{display: none !important;}`
  1261. ),
  1262. ];
  1263. } else {
  1264. window.GM_CSS_GM_shieldLoginDialog = [
  1265. GM_addStyle(
  1266. `.passport-login-container{display: none !important;}`
  1267. ),
  1268. ];
  1269. }
  1270. }
  1271. },
  1272. },
  1273. csdnShieldfloatingButton: {
  1274. text: "电脑-屏蔽右侧悬浮按钮",
  1275. enable: false,
  1276. showText: (_text_, _enable_) => {
  1277. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1278. },
  1279. callback: () => {
  1280. window.location.reload();
  1281. },
  1282. },
  1283. csdnShieldBottomRecommendArticle: {
  1284. text: "电脑-屏蔽底部推荐文章",
  1285. enable: false,
  1286. showText: (_text_, _enable_) => {
  1287. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1288. },
  1289. callback: () => {
  1290. window.location.reload();
  1291. },
  1292. },
  1293. csdnShieldBottomFloatingToolbar: {
  1294. text: "电脑-屏蔽底部悬浮工具栏",
  1295. enable: false,
  1296. showText: (_text_, _enable_) => {
  1297. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1298. },
  1299. callback: () => {
  1300. window.location.reload();
  1301. },
  1302. },
  1303. articleCenter: {
  1304. text: "电脑-全文居中",
  1305. enable: true,
  1306. showText: (_text_, _enable_) => {
  1307. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1308. },
  1309. callback: () => {
  1310. window.location.reload();
  1311. },
  1312. },
  1313. autoExpandContent: {
  1314. text: "电脑-自动展开内容块",
  1315. enable: false,
  1316. showText: (_text_, _enable_) => {
  1317. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1318. },
  1319. callback: () => {
  1320. window.location.reload();
  1321. },
  1322. },
  1323. showOrHideDirectory: {
  1324. text: "电脑-显示目录",
  1325. enable: false,
  1326. showText: (_text_, _enable_) => {
  1327. return _enable_ ? `⚙ 电脑-隐藏目录` : `⚙ ${_text_}`;
  1328. },
  1329. callback: (_key_, _enable_) => {
  1330. window.location.reload();
  1331. },
  1332. },
  1333. showOrHideSidebar: {
  1334. text: "电脑-显示侧边栏",
  1335. enable: false,
  1336. showText: (_text_, _enable_) => {
  1337. return _enable_ ? `⚙ 电脑-隐藏侧边栏` : `⚙ ${_text_}`;
  1338. },
  1339. callback: (_key_, _enable_) => {
  1340. window.location.reload();
  1341. },
  1342. },
  1343. },
  1344. false,
  1345. GM_getValue,
  1346. GM_setValue,
  1347. GM_registerMenuCommand,
  1348. GM_unregisterMenuCommand
  1349. );
  1350. }
  1351. GM_Menu.add({
  1352. gotoCSDNCKnow: {
  1353. text: "⚙ 前往C知道",
  1354. callback() {
  1355. window.open("https://so.csdn.net/so/ai?", "_blank");
  1356. },
  1357. },
  1358. });
  1359. Optimization.csdn.run();
  1360. } else if (Optimization.jianshu.locationMatch()) {
  1361. if (utils.isPhone()) {
  1362. GM_Menu = new utils.GM_Menu(
  1363. {
  1364. JianShuremoveFooterRecommendRead: {
  1365. text: "手机-移除底部推荐阅读",
  1366. enable: false,
  1367. showText: (_text_, _enable_) => {
  1368. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1369. },
  1370. callback: () => {
  1371. window.location.reload();
  1372. },
  1373. },
  1374. JianShuShieldUserComments: {
  1375. text: "手机-屏蔽评论区",
  1376. showText: (_text_, _enable_) => {
  1377. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1378. },
  1379. callback: () => {
  1380. window.location.reload();
  1381. },
  1382. },
  1383. },
  1384. false,
  1385. GM_getValue,
  1386. GM_setValue,
  1387. GM_registerMenuCommand,
  1388. GM_unregisterMenuCommand
  1389. );
  1390. } else {
  1391. GM_Menu = new utils.GM_Menu(
  1392. {
  1393. JianShuArticleCenter: {
  1394. text: "电脑-全文居中",
  1395. enable: true,
  1396. showText: (_text_, _enable_) => {
  1397. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1398. },
  1399. callback: () => {
  1400. window.location.reload();
  1401. },
  1402. },
  1403. JianShuShieldRelatedArticles: {
  1404. text: "电脑-屏蔽相关文章",
  1405. enable: false,
  1406. showText: (_text_, _enable_) => {
  1407. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1408. },
  1409. callback: () => {
  1410. window.location.reload();
  1411. },
  1412. },
  1413. JianShuShieldUserComments: {
  1414. text: "电脑-屏蔽评论区",
  1415. enable: false,
  1416. showText: (_text_, _enable_) => {
  1417. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1418. },
  1419. callback: () => {
  1420. window.location.reload();
  1421. },
  1422. },
  1423. JianShuShieldRecommendedReading: {
  1424. text: "电脑-屏蔽推荐阅读",
  1425. enable: false,
  1426. showText: (_text_, _enable_) => {
  1427. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1428. },
  1429. callback: () => {
  1430. window.location.reload();
  1431. },
  1432. },
  1433. },
  1434. false,
  1435. GM_getValue,
  1436. GM_setValue,
  1437. GM_registerMenuCommand,
  1438. GM_unregisterMenuCommand
  1439. );
  1440. }
  1441.  
  1442. Optimization.jianshu.run();
  1443. }
  1444. })();