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