CSDN|简书优化

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

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

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