CSDN|简书优化

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

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

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