CSDN|简书优化

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

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

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