CSDN|简书优化

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

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