CSDN|简书优化

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

当前为 2023-07-01 提交的版本,查看 最新版本

  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.6.9
  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=1213664
  24. // ==/UserScript==
  25.  
  26. (function () {
  27. const jQuery = $.noConflict(true);
  28. const log = new Utils.Log(GM_info);
  29. log.config({
  30. logMaxCount: 20,
  31. autoClearConsole: true,
  32. });
  33. /**
  34. * 因为在有些页面上,比如:简书,当插入style元素到head中,该页面清除该元素
  35. */
  36. const GM_addStyle = Utils.GM_addStyle;
  37. let GM_Menu = null;
  38. /**
  39. * 移除元素(未出现也可以等待出现)
  40. * @param {string} selectorText 元素选择器
  41. */
  42. const waitForElementToRemove = function (selectorText = "") {
  43. Utils.waitNode(selectorText).then((dom) => {
  44. dom.forEach((item) => {
  45. item.remove();
  46. });
  47. });
  48. };
  49.  
  50. const Optimization = {
  51. jianshu: {
  52. /**
  53. * 判断是否是简书
  54. */
  55. locationMatch() {
  56. return Boolean(/jianshu.(com|io)/i.test(window.location.origin));
  57. },
  58. PC: {
  59. /**
  60. * 添加屏蔽CSS
  61. */
  62. addCSS() {
  63. GM_addStyle(`
  64. .download-app-guidance,
  65. .call-app-btn,
  66. .collapse-tips,
  67. .note-graceful-button,
  68. .app-open,
  69. .header-wrap,
  70. .recommend-wrap.recommend-ad,
  71. .call-app-Ad-bottom,
  72. #recommended-notes p.top-title span.more,
  73. #homepage .modal,
  74. button.index_call-app-btn,
  75. span.note__flow__download,
  76. .download-guide,
  77. #footer,
  78. .comment-open-app-btn-wrap,
  79. .nav.navbar-nav + div,
  80. .self-flow-ad,
  81. #free-reward-panel,
  82. div[id*='AdFive'],
  83. #index-aside-download-qrbox{
  84. display:none !important;
  85. }
  86. body.reader-day-mode.normal-size {
  87. overflow: auto !important;
  88. }
  89. .collapse-free-content{
  90. height:auto !important;
  91. }
  92. .copyright{
  93. color:#000 !important;
  94. }
  95. #note-show .content .show-content-free .collapse-free-content:after{
  96. background-image:none !important;
  97. }
  98. footer > div > div{
  99. justify-content: center;
  100. }`);
  101. },
  102. /**
  103. * 全文居中
  104. */
  105. articleCenter() {
  106. GM_addStyle(`
  107. div[role=main] aside,
  108. div._3Pnjry{
  109. display: none !important;
  110. }
  111. div._gp-ck{
  112. width: 100% !important;
  113. }`);
  114. waitForElementToRemove("div[role=main] aside");
  115. waitForElementToRemove("div._3Pnjry");
  116. Utils.waitNode("div._gp-ck").then((dom) => {
  117. dom.forEach((item) => {
  118. item.style["width"] = "100%";
  119. });
  120. });
  121. },
  122. /**
  123. * 去除剪贴板劫持
  124. */
  125. removeClipboardHijacking() {
  126. const stopNativePropagation = (event) => {
  127. event.stopPropagation();
  128. };
  129. window.addEventListener("copy", stopNativePropagation, true);
  130. document.addEventListener("copy", stopNativePropagation, true);
  131. },
  132. /**
  133. * 自动展开全文
  134. */
  135. autoExpandFullText() {
  136. Utils.waitNode(`div#homepage div[class*="dialog-"]`).then(
  137. (nodeList) => {
  138. nodeList[0].style["visibility"] = "hidden";
  139. Utils.mutationObserver(nodeList[0], {
  140. callback: (mutations) => {
  141. if (mutations.length == 0) {
  142. return;
  143. }
  144. if (mutations[0].target.style["display"] != "none") {
  145. document
  146. .querySelector(
  147. 'div#homepage div[class*="dialog-"] .cancel'
  148. )
  149. ?.click();
  150. }
  151. },
  152. config: {
  153. /* 子节点的变动(新增、删除或者更改) */
  154. childList: false,
  155. /* 属性的变动 */
  156. attributes: true,
  157. /* 节点内容或节点文本的变动 */
  158. characterData: true,
  159. /* 是否将观察器应用于该节点的所有后代节点 */
  160. subtree: true,
  161. },
  162. });
  163. }
  164. );
  165. },
  166. /**
  167. * 去除简书拦截其它网址的url并自动跳转
  168. */
  169. jumpRedirect() {
  170. if (window.location.pathname === "/go-wild") {
  171. /* 禁止简书拦截跳转 */
  172. window.stop();
  173. let search = window.location.href.replace(
  174. window.location.origin + "/",
  175. ""
  176. );
  177. search = decodeURIComponent(search);
  178. let newURL = search
  179. .replace(/^go-wild\?ac=2&url=/gi, "")
  180. .replace(/^https:\/\/link.zhihu.com\/\?target\=/gi, "");
  181. window.location.href = newURL;
  182. }
  183. },
  184. run() {
  185. this.addCSS();
  186. this.removeClipboardHijacking();
  187. this.autoExpandFullText();
  188. if (GM_Menu.get("JianShuArticleCenter")) {
  189. this.articleCenter();
  190. }
  191. },
  192. },
  193. Mobile: {
  194. addCSS() {
  195. Optimization.jianshu.PC.addCSS();
  196. },
  197. /**
  198. * 手机-移除底部推荐阅读
  199. */
  200. removeFooterRecommendRead() {
  201. GM_addStyle(`
  202. #recommended-notes{
  203. display: none !important;
  204. }`);
  205. },
  206. run() {
  207. this.addCSS();
  208. Optimization.jianshu.PC.removeClipboardHijacking();
  209. Optimization.jianshu.PC.autoExpandFullText();
  210. if (GM_Menu.get("JianShuremoveFooterRecommendRead")) {
  211. this.removeFooterRecommendRead();
  212. }
  213. },
  214. },
  215. /**
  216. * 函数入口
  217. */
  218. run() {
  219. this.PC.jumpRedirect();
  220. if (Utils.isPhone()) {
  221. log.success("简书-移动端");
  222. this.Mobile.run();
  223. } else {
  224. log.success("简书-桌面端");
  225. this.PC.run();
  226. }
  227. },
  228. },
  229. csdn: {
  230. /**
  231. * 判断是否是CSDN
  232. */
  233. locationMatch() {
  234. return Boolean(/csdn.net/i.test(window.location.origin));
  235. },
  236. PC: {
  237. addCSS() {
  238. GM_addStyle(`
  239. .ecommend-item-box.recommend-recommend-box,
  240. .login-mark,
  241. .opt-box.text-center,
  242. .leftPop,
  243. #csdn-shop-window,
  244. .toolbar-advert,
  245. .hide-article-box,
  246. .user-desc.user-desc-fix,
  247. .recommend-card-box,
  248. .more-article,
  249. .article-show-more,
  250. #csdn-toolbar-profile-nologin,
  251. .guide-rr-first,
  252. #recommend-item-box-tow{
  253. display: none !important;
  254. }
  255. .comment-list-box{
  256. max-height: none !important;
  257. }
  258. .blog_container_aside,
  259. #nav{
  260. margin-left: -45px;
  261. }
  262. .recommend-right.align-items-stretch.clearfix,.dl_right_fixed{
  263. margin-left: 45px;
  264. }
  265. #content_views pre,
  266. #content_views pre code{
  267. user-select: text !important;
  268. }
  269. #article_content,
  270. .user-article.user-article-hide{
  271. height: auto !important;
  272. overflow: auto !important;
  273. }
  274. `);
  275. },
  276. /**
  277. * 去除剪贴板劫持
  278. */
  279. removeClipboardHijacking() {
  280. log.info("去除剪贴板劫持");
  281. jQuery(".article-copyright")?.remove();
  282. if (unsafeWindow.articleType) {
  283. unsafeWindow.articleType = 0;
  284. }
  285. if (
  286. unsafeWindow.csdn &&
  287. unsafeWindow.csdn.copyright &&
  288. unsafeWindow.csdn.copyright.textData
  289. ) {
  290. unsafeWindow.csdn.copyright.textData = "";
  291. }
  292. if (
  293. unsafeWindow.csdn &&
  294. unsafeWindow.csdn.copyright &&
  295. unsafeWindow.csdn.copyright.htmlData
  296. ) {
  297. unsafeWindow.csdn.copyright.htmlData = "";
  298. }
  299. },
  300. /**
  301. * 取消禁止复制
  302. */
  303. unBlockCopy() {
  304. log.info("取消禁止复制");
  305. jQuery(document).on("click", ".hljs-button.signin", function () {
  306. /* 复制按钮 */
  307. let btnNode = jQuery(this);
  308. /* 需要复制的文本 */
  309. let copyText = btnNode.parent().text();
  310. Utils.setClip(copyText);
  311. btnNode.attr("data-title", "复制成功");
  312. });
  313. jQuery(document).on("mouseenter mouseleave", "pre", function () {
  314. this.querySelector(".hljs-button.signin")?.setAttribute(
  315. "data-title",
  316. "复制"
  317. );
  318. });
  319. /* 取消Ctrl+C的禁止 */
  320. Utils.waitNode("#content_views").then(() => {
  321. unsafeWindow.$("#content_views").unbind("copy");
  322. jQuery("#content_views")
  323. .off("copy")
  324. .on("copy", function (event) {
  325. event?.preventDefault();
  326. event?.stopPropagation();
  327. Utils.setClip(unsafeWindow.getSelection().toString());
  328. return false;
  329. });
  330. });
  331. },
  332. /**
  333. * 点击代码块自动展开
  334. */
  335. clickPreCodeAutomatically() {
  336. if (!GM_Menu.get("autoExpandContent")) {
  337. return;
  338. }
  339. log.info("点击代码块自动展开");
  340. jQuery(document).on("click", "pre", function () {
  341. let clickNode = jQuery(this);
  342. clickNode.css("height", "auto");
  343. clickNode.find(".hide-preCode-box")?.remove();
  344. });
  345. },
  346. /**
  347. * 恢复评论到正确位置
  348. */
  349. restoreComments() {
  350. /* 第一条评论 */
  351. log.info("恢复评论到正确位置-第一条评论");
  352. Utils.waitNode(".first-recommend-box").then((dom) => {
  353. jQuery(".recommend-box.insert-baidu-box.recommend-box-style").prepend(
  354. jQuery(dom)
  355. );
  356. });
  357. log.info("恢复评论到正确位置-第二条评论");
  358. /* 第二条评论 */
  359. Utils.waitNode(".second-recommend-box").then((dom) => {
  360. jQuery(".recommend-box.insert-baidu-box.recommend-box-style").prepend(
  361. jQuery(dom)
  362. );
  363. });
  364. },
  365. /**
  366. * 标识CSDN下载的链接
  367. */
  368. identityCSDNDownload() {
  369. log.info("标识CSDN下载的链接");
  370. jQuery(".recommend-item-box[data-url*='https://download.csdn.net/']").each(
  371. (index, item) => {
  372. if (GM_Menu.get("removeCSDNDownloadPC")) {
  373. item.remove();
  374. } else {
  375. jQuery(item).find(".content-box").css("border", "2px solid red");
  376. }
  377. }
  378. );
  379. },
  380. /**
  381. * 全文居中
  382. */
  383. articleCenter() {
  384. if (!GM_Menu.get("articleCenter")) {
  385. return;
  386. }
  387. log.info("全文居中");
  388. GM_addStyle(`
  389. aside.blog_container_aside{
  390. display:none !important;
  391. }
  392. #mainBox main{
  393. width: inherit !important;
  394. }
  395. `);
  396. GM_addStyle(`
  397. @media (min-width: 1320px) and (max-width:1380px) {
  398. .nodata .container {
  399. width:900px !important
  400. }
  401.  
  402. .nodata .container main {
  403. width: 900px
  404. }
  405. .nodata .container main #pcCommentBox pre >ol.hljs-ln {
  406. width: 490px !important
  407. }
  408. .nodata .container main .articleConDownSource {
  409. width: 500px
  410. }
  411. }
  412. @media screen and (max-width: 1320px) {
  413. .nodata .container {
  414. width:760px !important
  415. }
  416. .nodata .container main {
  417. width: 760px
  418. }
  419. .nodata .container main #pcCommentBox pre >ol.hljs-ln {
  420. width: 490px !important
  421. }
  422. .nodata .container main .toolbox-list .tool-reward {
  423. display: none
  424. }
  425. .nodata .container main .more-toolbox-new .toolbox-left .profile-box .profile-name {
  426. max-width: 128px
  427. }
  428. .nodata .container main .articleConDownSource {
  429. width: 420px
  430. }
  431. }
  432. @media screen and (min-width: 1380px) {
  433. .nodata .container {
  434. width:1010px !important
  435. }
  436. .nodata .container main {
  437. width: 1010px
  438. }
  439. .nodata .container main #pcCommentBox pre >ol.hljs-ln {
  440. width: 490px !important
  441. }
  442. .nodata .container main .articleConDownSource {
  443. width: 560px
  444. }
  445. }
  446. @media (min-width: 1550px) and (max-width:1700px) {
  447. .nodata .container {
  448. width:820px !important
  449. }
  450. .nodata .container main {
  451. width: 820px
  452. }
  453. .nodata .container main #pcCommentBox pre >ol.hljs-ln {
  454. width: 690px !important
  455. }
  456. .nodata .container main .articleConDownSource {
  457. width: 500px
  458. }
  459. }
  460. @media screen and (min-width: 1700px) {
  461. .nodata .container {
  462. width:1010px !important
  463. }
  464. .nodata .container main {
  465. width: 1010px
  466. }
  467. .nodata .container main #pcCommentBox pre >ol.hljs-ln {
  468. width: 690px !important
  469. }
  470. .nodata .container main .articleConDownSource {
  471. width: 560px
  472. }
  473. }
  474. `);
  475. },
  476. /**
  477. * 添加前往评论的按钮,在返回顶部的下面
  478. */
  479. addGotoRecommandButton() {
  480. log.info("添加前往评论的按钮,在返回顶部的上面");
  481. let gotoRecommandNode = jQuery(`
  482. <a class="option-box" data-type="gorecommand">
  483. <span class="show-txt" style="display:flex;opacity:100;">前往<br>评论</span>
  484. </a>
  485. `);
  486. jQuery(gotoRecommandNode).on("click", function () {
  487. log.info("滚动到评论");
  488. jQuery("html, body").animate(
  489. {
  490. scrollTop:
  491. jQuery("#toolBarBox").offset().top -
  492. jQuery("#csdn-toolbar").height() -
  493. 8,
  494. },
  495. 1000
  496. );
  497. });
  498. Utils.waitNode(".csdn-side-toolbar").then(() => {
  499. jQuery(".csdn-side-toolbar a").eq("-2").after(gotoRecommandNode);
  500. });
  501. },
  502. /**
  503. * 屏蔽登录弹窗
  504. */
  505. shieldLoginDialog() {
  506. if (GM_Menu.get("shieldLoginDialog")) {
  507. log.info("屏蔽登录弹窗");
  508. window.GM_CSS_GM_shieldLoginDialog = [
  509. GM_addStyle(
  510. `.passport-login-container{display: none !important;}`
  511. ),
  512. ];
  513. }
  514. },
  515. /**
  516. * 自动展开内容块
  517. */
  518. autoExpandContent() {
  519. if (!GM_Menu.get("autoExpandContent")) {
  520. return;
  521. }
  522. log.info("自动展开内容块");
  523. GM_addStyle(`
  524. pre.set-code-hide{
  525. height: auto !important;
  526. }
  527. pre.set-code-hide .hide-preCode-box{
  528. display: none !important;
  529. }
  530. `);
  531. },
  532. /**
  533. * 显示/隐藏目录
  534. */
  535. showOrHideDirectory() {
  536. if (GM_Menu.get("showOrHideDirectory")) {
  537. log.info("显示目录");
  538. GM_addStyle(`
  539. aside.blog_container_aside{
  540. display: none !important;
  541. }
  542. `);
  543. } else {
  544. log.info("隐藏目录");
  545. GM_addStyle(`
  546. aside.blog_container_aside{
  547. display: block !important;
  548. }
  549. `);
  550. }
  551. },
  552. /**
  553. * 显示/隐藏侧边栏
  554. */
  555. showOrHideSidebar() {
  556. if (GM_Menu.get("showOrHideSidebar")) {
  557. log.info("显示侧边栏");
  558. GM_addStyle(`
  559. #rightAsideConcision{
  560. display: none !important;
  561. }
  562. `);
  563. } else {
  564. log.info("隐藏侧边栏");
  565. GM_addStyle(`
  566. #rightAsideConcision{
  567. display: block !important;
  568. }
  569. `);
  570. }
  571. },
  572. /**
  573. * 去除CSDN拦截其它网址的url并自动跳转
  574. */
  575. jumpRedirect() {
  576. /* https://link.csdn.net/?target=https%3A%2F%2Fjaist.dl.sourceforge.net%2Fproject%2Fportecle%2Fv1.11%2Fportecle-1.11.zip */
  577. if (
  578. window.location.hostname === "link.csdn.net" &&
  579. window.location.search.startsWith("?target")
  580. ) {
  581. /* 禁止CSDN拦截跳转 */
  582. window.stop();
  583. let search = window.location.search.replace(/^\?target=/gi, "");
  584. search = decodeURIComponent(search);
  585. let newURL = search;
  586. log.success(`跳转链接 ${newURL}`);
  587. window.location.href = newURL;
  588. }
  589. },
  590. run() {
  591. this.addCSS();
  592. this.articleCenter();
  593. this.shieldLoginDialog();
  594. this.autoExpandContent();
  595. this.showOrHideDirectory();
  596. this.showOrHideSidebar();
  597. let that = this;
  598. jQuery(document).ready(function () {
  599. that.removeClipboardHijacking();
  600. that.unBlockCopy();
  601. that.identityCSDNDownload();
  602. that.clickPreCodeAutomatically();
  603. that.restoreComments();
  604. that.addGotoRecommandButton();
  605. });
  606. },
  607. },
  608. Mobile: {
  609. addCSS() {
  610. GM_addStyle(`
  611. #mainBox{
  612. width: auto;
  613. }
  614. .user-desc.user-desc-fix{
  615. height: auto !important;
  616. overflow: auto !important;
  617. }
  618. #operate,.feed-Sign-span,
  619. .view_comment_box,
  620. .weixin-shadowbox.wap-shadowbox,
  621. .feed-Sign-span,
  622. .user-desc.user-desc-fix,
  623. .comment_read_more_box,
  624. #content_views pre.set-code-hide .hide-preCode-box,
  625. .passport-login-container,
  626. .hljs-button[data-title='登录后复制'],
  627. .article-show-more,
  628. #treeSkill,
  629. div.btn_open_app_prompt_div,
  630. div.readall_box,
  631. div.aside-header-fixed,
  632. div.feed-Sign-weixin,
  633. div.ios-shadowbox{
  634. display:none !important;
  635. }
  636. .component-box .praise {
  637. background: #ff5722;
  638. border-radius: 5px;
  639. padding: 0px 8px;
  640. height: auto;
  641. }
  642. .component-box .praise,.component-box .share {
  643. color: #fff;
  644. }
  645. .component-box a {
  646. display: inline-block;
  647. font-size:xx-small;
  648. }
  649. .component-box {
  650. display: inline;
  651. margin: 0;
  652. position: relative;
  653. white-space:nowrap;
  654. }
  655. .csdn-edu-title{
  656. background: #4d6de1;
  657. border-radius: 5px;
  658. padding: 0px 8px;
  659. height: auto;
  660. color: #fff !important;
  661. }
  662. #comment{
  663. max-height: none !important;
  664. }
  665. #content_views pre,
  666. #content_views pre code{
  667. webkit-touch-callout: text !important;
  668. -webkit-user-select: text !important;
  669. -khtml-user-select: text !important;
  670. -moz-user-select: text !important;
  671. -ms-user-select: text !important;
  672. user-select: text !important;
  673. }
  674. #content_views pre.set-code-hide,
  675. .article_content{
  676. height: 100% !important;
  677. overflow: auto !important;
  678. }`);
  679. GM_addStyle(`
  680. .GM-csdn-dl{
  681. padding: .24rem .32rem;
  682. width: 100%;
  683. justify-content: space-between;
  684. -webkit-box-pack: justify;
  685. border-bottom: 1px solid #F5F6F7!important;
  686. }
  687. .GM-csdn-title{
  688. font-size: .3rem;
  689. color: #222226;
  690. letter-spacing: 0;
  691. line-height: .44rem;
  692. font-weight: 600;
  693. //max-height: .88rem;
  694. word-break: break-all;
  695. overflow: hidden;
  696. display: -webkit-box;
  697. -webkit-box-orient: vertical;
  698. -webkit-line-clamp: 2
  699. }
  700. .GM-csdn-title a{
  701. word-break: break-all;
  702. color: #222226;
  703. font-weight: 600;
  704. }
  705. .GM-csdn-title em,.GM-csdn-content em{
  706. font-style: normal;
  707. color: #fc5531
  708. }
  709. .GM-csdn-content{
  710. //max-width: 5.58rem;
  711. overflow: hidden;
  712. text-overflow: ellipsis;
  713. display: -webkit-box;
  714. -webkit-line-clamp: 1;
  715. -webkit-box-orient: vertical;
  716. color: #555666;
  717. font-size: .24rem;
  718. line-height: .34rem;
  719. max-height: .34rem;
  720. word-break: break-all;
  721. -webkit-box-flex: 1;
  722. -ms-flex: 1;
  723. flex: 1;
  724. margin-top: .16rem;
  725. }
  726. .GM-csdn-img img{
  727. width: 2.18rem;
  728. height: 1.58rem;
  729. //margin-left: .16rem
  730. }
  731. .GM-csdn-Redirect{
  732. color: #fff;
  733. background-color: #f90707;
  734. font-family: sans-serif;
  735. margin: auto 2px;
  736. border: 1px solid #ccc;
  737. border-radius: 4px;
  738. padding: 0px 3px;
  739. font-size: xx-small;
  740. display: inline;
  741. white-space: nowrap;
  742. }`);
  743. },
  744. /**
  745. * 重构底部推荐
  746. */
  747. refactoringRecommendation() {
  748. log.info("重构底部推荐");
  749. function refactoring() {
  750. /* 反复执行的重构函数 */
  751. jQuery(".container-fluid").each((index, item) => {
  752. item = jQuery(item);
  753. var url = ""; /* 链接 */
  754. var title = ""; /* 标题 */
  755. var content = ""; /* 内容 */
  756. var img = ""; /* 图片 */
  757. var isCSDNDownload = false; /* 判断是否是CSDN资源下载 */
  758. var isCSDNEduDownload = false; /* 判断是否是CSDN-学院资源下载 */
  759. if (item.attr("data-url")) {
  760. /* 存在真正的URL */
  761. url = item.attr("data-url");
  762. title = item.find(".recommend_title div.left").html();
  763. content = item.find(".text").html();
  764. if (item.find(".recommend-img").length) {
  765. /* 如果有图片就加进去 */
  766. item.find(".recommend-img").each((_index_, _item_) => {
  767. img += jQuery(_item_).html();
  768. });
  769. }
  770. } else {
  771. log.info("节点上无data-url");
  772. url = item.find("a[data-type]").attr("href");
  773. title = item.find(".recommend_title div.left").html();
  774. content = item.find(".text").html();
  775. }
  776. if (GM_Menu.get("showDirect")) {
  777. /* 开启就添加 */
  778. title += `<div class="GM-csdn-Redirect">Redirect</div>`;
  779. }
  780. var _URL_ = new URL(url);
  781. if (
  782. _URL_.host === "download.csdn.net" ||
  783. (_URL_.host === "www.iteye.com" &&
  784. _URL_.pathname.match(/^\/resource/gi))
  785. ) {
  786. /* 该链接为csdn资源下载 */
  787. log.info("该链接为csdn资源下载");
  788. isCSDNDownload = true;
  789. title += `<div class="component-box"><a class="praise" href="javascript:;">CSDN下载</a></div>`;
  790. } else if (_URL_.origin.match(/edu.csdn.net/gi)) {
  791. /* 该链接为csdn学院下载 */
  792. isCSDNEduDownload = true;
  793. log.info("该链接为csdn学院下载");
  794. title += `<div class="component-box"><a class="csdn-edu-title" href="javascript:;">CSDN学院</a></div>`;
  795. }
  796. item.attr("class", "GM-csdn-dl");
  797. item.attr("data-url", url);
  798. item.html(
  799. `<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>`
  800. );
  801. if (
  802. (isCSDNDownload || isCSDNEduDownload) &&
  803. GM_Menu.get("removeCSDNDownloadMobile")
  804. ) {
  805. item.remove();
  806. }
  807. /* jQuery("#recommend")
  808. .find(".recommend_list")
  809. .before(jQuery("#first_recommend_list").find("dl").parent().html()); */
  810. });
  811. }
  812. Utils.waitNode("#recommend").then((nodeList) => {
  813. Utils.mutationObserver(nodeList[0], {
  814. callback: () => {
  815. setTimeout(() => {
  816. refactoring();
  817. }, 300);
  818. },
  819. config: { childList: true, subtree: true, attributes: true },
  820. });
  821. });
  822.  
  823. this.recommendClickEvent();
  824. },
  825. /**
  826. * 设置底部推荐点击跳转事件
  827. */
  828. recommendClickEvent() {
  829. log.info("设置底部推荐点击跳转事件");
  830. jQuery(document).on("click", ".GM-csdn-dl", function () {
  831. let url = jQuery(this).attr("data-url");
  832. if (GM_Menu.get("openNewTab")) {
  833. window.open(url, "_blank");
  834. } else {
  835. window.location.href = url;
  836. }
  837. });
  838. },
  839. /**
  840. * 去除广告
  841. */
  842. removeAds() {
  843. log.info("去除广告");
  844. /* 登录窗口 */
  845. waitForElementToRemove(".passport-login-container");
  846. /* 打开APP */
  847. waitForElementToRemove(
  848. ".btn_open_app_prompt_box.detail-open-removed"
  849. );
  850. /* 广告 */
  851. waitForElementToRemove(".add-firstAd");
  852. /* 打开CSDN APP 小程序看全文 */
  853. waitForElementToRemove("div.feed-Sign-weixin");
  854. /* ios版本提示 */
  855. waitForElementToRemove("div.ios-shadowbox");
  856. },
  857. run() {
  858. this.addCSS();
  859. let that = this;
  860. jQuery(document).ready(function () {
  861. that.removeAds();
  862. that.refactoringRecommendation();
  863. });
  864. },
  865. },
  866. /**
  867. * 函数入口
  868. */
  869. run() {
  870. Optimization.csdn.PC.jumpRedirect();
  871. if (Utils.isPhone()) {
  872. log.success("移动端模式");
  873. this.Mobile.run();
  874. } else {
  875. log.success("桌面端模式");
  876. this.PC.run();
  877. }
  878. },
  879. },
  880. };
  881.  
  882. if (Optimization.csdn.locationMatch()) {
  883. if (Utils.isPhone()) {
  884. GM_Menu = new Utils.GM_Menu(
  885. {
  886. showDirect: {
  887. text: "手机-标识处理过的底部推荐文章",
  888. enable: true,
  889. showText: (_text_, _enable_) => {
  890. return (_enable_ ? "✅" : "❌") + " " + _text_;
  891. },
  892. callback: () => {
  893. window.location.reload();
  894. },
  895. },
  896. openNewTab: {
  897. text: "手机-底部推荐文章新标签页打开",
  898. enable: true,
  899. showText: (_text_, _enable_) => {
  900. return (_enable_ ? "✅" : "❌") + " " + _text_;
  901. },
  902. callback: () => {
  903. window.location.reload();
  904. },
  905. },
  906. removeCSDNDownloadMobile: {
  907. text: "手机-移除文章底部的CSDN下载",
  908. enable: false,
  909. showText: (_text_, _enable_) => {
  910. return (_enable_ ? "✅" : "❌") + " " + _text_;
  911. },
  912. callback: () => {
  913. window.location.reload();
  914. },
  915. },
  916. },
  917. false,
  918. GM_getValue,
  919. GM_setValue,
  920. GM_registerMenuCommand,
  921. GM_unregisterMenuCommand
  922. );
  923. } else {
  924. GM_Menu = new Utils.GM_Menu(
  925. {
  926. removeCSDNDownloadPC: {
  927. text: "电脑-移除文章底部的CSDN下载",
  928. enable: false,
  929. showText: (_text_, _enable_) => {
  930. return (_enable_ ? "✅" : "❌") + " " + _text_;
  931. },
  932. callback: () => {
  933. window.location.reload();
  934. },
  935. },
  936. articleCenter: {
  937. text: "电脑-全文居中",
  938. enable: true,
  939. showText: (_text_, _enable_) => {
  940. return (_enable_ ? "✅" : "❌") + " " + _text_;
  941. },
  942. callback: () => {
  943. window.location.reload();
  944. },
  945. },
  946. shieldLoginDialog: {
  947. text: "电脑-屏蔽登录弹窗",
  948. enable: true,
  949. showText: (_text_, _enable_) => {
  950. return (_enable_ ? "✅" : "❌") + " " + _text_;
  951. },
  952. callback: (_key_, _enable_) => {
  953. if (!_enable_) {
  954. window.GM_CSS_GM_shieldLoginDialog.forEach((item) => {
  955. item.remove();
  956. });
  957. } else {
  958. if (typeof window.GM_CSS_GM_shieldLoginDialog !== "undefined") {
  959. window.GM_CSS_GM_shieldLoginDialog = [
  960. ...window.GM_CSS_GM_shieldLoginDialog,
  961. GM_addStyle(
  962. `.passport-login-container{display: none !important;}`
  963. ),
  964. ];
  965. } else {
  966. window.GM_CSS_GM_shieldLoginDialog = [
  967. GM_addStyle(
  968. `.passport-login-container{display: none !important;}`
  969. ),
  970. ];
  971. }
  972. }
  973. },
  974. },
  975. autoExpandContent: {
  976. text: "电脑-自动展开内容块",
  977. enable: false,
  978. showText: (_text_, _enable_) => {
  979. return (_enable_ ? "✅" : "❌") + " " + _text_;
  980. },
  981. callback: () => {
  982. window.location.reload();
  983. },
  984. },
  985. showOrHideDirectory: {
  986. text: "电脑-显示目录",
  987. enable: false,
  988. showText: (_text_, _enable_) => {
  989. return _enable_ ? `⚙ 电脑-隐藏目录` : `⚙ ${_text_}`;
  990. },
  991. callback: (_key_, _enable_) => {
  992. window.location.reload();
  993. },
  994. },
  995. showOrHideSidebar: {
  996. text: "电脑-显示侧边栏",
  997. enable: false,
  998. showText: (_text_, _enable_) => {
  999. return _enable_ ? `⚙ 电脑-隐藏侧边栏` : `⚙ ${_text_}`;
  1000. },
  1001. callback: (_key_, _enable_) => {
  1002. window.location.reload();
  1003. },
  1004. },
  1005. },
  1006. false,
  1007. GM_getValue,
  1008. GM_setValue,
  1009. GM_registerMenuCommand,
  1010. GM_unregisterMenuCommand
  1011. );
  1012. }
  1013. Optimization.csdn.run();
  1014. } else if (Optimization.jianshu.locationMatch()) {
  1015. if (Utils.isPhone()) {
  1016. GM_Menu = new Utils.GM_Menu(
  1017. {
  1018. JianShuremoveFooterRecommendRead: {
  1019. text: "手机-移除底部推荐阅读",
  1020. enable: false,
  1021. showText: (_text_, _enable_) => {
  1022. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1023. },
  1024. callback: () => {
  1025. window.location.reload();
  1026. },
  1027. },
  1028. },
  1029. false,
  1030. GM_getValue,
  1031. GM_setValue,
  1032. GM_registerMenuCommand,
  1033. GM_unregisterMenuCommand
  1034. );
  1035. } else {
  1036. GM_Menu = new Utils.GM_Menu(
  1037. {
  1038. JianShuArticleCenter: {
  1039. text: "电脑-全文居中",
  1040. enable: true,
  1041. showText: (_text_, _enable_) => {
  1042. return (_enable_ ? "✅" : "❌") + " " + _text_;
  1043. },
  1044. callback: () => {
  1045. window.location.reload();
  1046. },
  1047. },
  1048. },
  1049. false,
  1050. GM_getValue,
  1051. GM_setValue,
  1052. GM_registerMenuCommand,
  1053. GM_unregisterMenuCommand
  1054. );
  1055. }
  1056.  
  1057. Optimization.jianshu.run();
  1058. }
  1059. })();