CSDN|简书优化

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

当前为 2023-05-17 提交的版本,查看 最新版本

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