Greasy Fork 还支持 简体中文。

CSDN|简书优化

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

目前為 2023-04-25 提交的版本,檢視 最新版本

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