CSDN|简书优化

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

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

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