CSDN优化

支持PC和手机端、屏蔽广告、优化浏览体验、重定向拦截的Url、自动展开全文、自动展开代码块、全文居中、允许复制内容、去除复制内容的小尾巴、自定义屏蔽元素等

当前为 2024-07-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name CSDN优化
  3. // @namespace https://github.com/WhiteSevs/TamperMonkeyScript
  4. // @version 2024.7.7
  5. // @author WhiteSevs
  6. // @description 支持PC和手机端、屏蔽广告、优化浏览体验、重定向拦截的Url、自动展开全文、自动展开代码块、全文居中、允许复制内容、去除复制内容的小尾巴、自定义屏蔽元素等
  7. // @license GPL-3.0-only
  8. // @icon https://www.csdn.net/favicon.ico
  9. // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues
  10. // @match *://*.csdn.net/*
  11. // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js
  12. // @require https://update.greasyfork.org/scripts/456485/1405857/pops.js
  13. // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js
  14. // @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.9/dist/index.umd.js
  15. // @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js
  16. // @grant GM_addStyle
  17. // @grant GM_cookie
  18. // @grant GM_deleteValue
  19. // @grant GM_getValue
  20. // @grant GM_info
  21. // @grant GM_registerMenuCommand
  22. // @grant GM_setValue
  23. // @grant GM_unregisterMenuCommand
  24. // @grant GM_xmlhttpRequest
  25. // @grant unsafeWindow
  26. // @run-at document-start
  27. // ==/UserScript==
  28.  
  29. (function (Qmsg, DOMUtils, Utils) {
  30. 'use strict';
  31.  
  32. var _a;
  33. var _GM_deleteValue = /* @__PURE__ */ (() => typeof GM_deleteValue != "undefined" ? GM_deleteValue : void 0)();
  34. var _GM_getValue = /* @__PURE__ */ (() => typeof GM_getValue != "undefined" ? GM_getValue : void 0)();
  35. var _GM_info = /* @__PURE__ */ (() => typeof GM_info != "undefined" ? GM_info : void 0)();
  36. var _GM_registerMenuCommand = /* @__PURE__ */ (() => typeof GM_registerMenuCommand != "undefined" ? GM_registerMenuCommand : void 0)();
  37. var _GM_setValue = /* @__PURE__ */ (() => typeof GM_setValue != "undefined" ? GM_setValue : void 0)();
  38. var _GM_unregisterMenuCommand = /* @__PURE__ */ (() => typeof GM_unregisterMenuCommand != "undefined" ? GM_unregisterMenuCommand : void 0)();
  39. var _GM_xmlhttpRequest = /* @__PURE__ */ (() => typeof GM_xmlhttpRequest != "undefined" ? GM_xmlhttpRequest : void 0)();
  40. var _unsafeWindow = /* @__PURE__ */ (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)();
  41. var _monkeyWindow = /* @__PURE__ */ (() => window)();
  42. const _SCRIPT_NAME_ = "CSDN优化";
  43. const utils = Utils.noConflict();
  44. const domutils = DOMUtils.noConflict();
  45. const pops = _monkeyWindow.pops || _unsafeWindow.pops;
  46. const log = new utils.Log(
  47. _GM_info,
  48. _unsafeWindow.console || _monkeyWindow.console
  49. );
  50. const SCRIPT_NAME = ((_a = _GM_info == null ? void 0 : _GM_info.script) == null ? void 0 : _a.name) || _SCRIPT_NAME_;
  51. const DEBUG = false;
  52. log.config({
  53. debug: DEBUG,
  54. logMaxCount: 1e3,
  55. autoClearConsole: true,
  56. tag: true
  57. });
  58. Qmsg.config(
  59. Object.defineProperties(
  60. {
  61. html: true,
  62. autoClose: true,
  63. showClose: false
  64. },
  65. {
  66. position: {
  67. get() {
  68. return PopsPanel.getValue("qmsg-config-position", "bottom");
  69. }
  70. },
  71. maxNums: {
  72. get() {
  73. return PopsPanel.getValue("qmsg-config-maxnums", 5);
  74. }
  75. },
  76. showReverse: {
  77. get() {
  78. return PopsPanel.getValue("qmsg-config-showreverse", true);
  79. }
  80. },
  81. zIndex: {
  82. get() {
  83. let maxZIndex = Utils.getMaxZIndex();
  84. let popsMaxZIndex = pops.config.Utils.getPopsMaxZIndex(maxZIndex).zIndex;
  85. return Utils.getMaxValue(maxZIndex, popsMaxZIndex) + 100;
  86. }
  87. }
  88. }
  89. )
  90. );
  91. const GM_Menu = new utils.GM_Menu({
  92. GM_getValue: _GM_getValue,
  93. GM_setValue: _GM_setValue,
  94. GM_registerMenuCommand: _GM_registerMenuCommand,
  95. GM_unregisterMenuCommand: _GM_unregisterMenuCommand
  96. });
  97. const httpx = new utils.Httpx(_GM_xmlhttpRequest);
  98. httpx.interceptors.response.use(void 0, (data) => {
  99. log.error(["拦截器-请求错误", data]);
  100. if (data.type === "onabort") {
  101. Qmsg.warning("请求取消");
  102. } else if (data.type === "onerror") {
  103. Qmsg.error("请求异常");
  104. } else if (data.type === "ontimeout") {
  105. Qmsg.error("请求超时");
  106. } else {
  107. Qmsg.error("其它错误");
  108. }
  109. return data;
  110. });
  111. httpx.config({
  112. logDetails: DEBUG
  113. });
  114. ({
  115. Object: {
  116. defineProperty: _unsafeWindow.Object.defineProperty
  117. },
  118. Function: {
  119. apply: _unsafeWindow.Function.prototype.apply,
  120. call: _unsafeWindow.Function.prototype.call
  121. },
  122. Element: {
  123. appendChild: _unsafeWindow.Element.prototype.appendChild
  124. },
  125. setTimeout: _unsafeWindow.setTimeout
  126. });
  127. const addStyle = utils.addStyle;
  128. const KEY = "GM_Panel";
  129. const ATTRIBUTE_KEY = "data-key";
  130. const ATTRIBUTE_DEFAULT_VALUE = "data-default-value";
  131. const CSDNRouter = {
  132. /**
  133. * 判断是否是华为云联盟
  134. * + huaweicloud.csdn.net
  135. */
  136. isHuaWeiCloudBlog() {
  137. return Boolean(/huaweicloud.csdn.net/i.test(window.location.origin));
  138. },
  139. /**
  140. * 判断是否是博客
  141. * + blog.csdn.net
  142. */
  143. isBlog() {
  144. return Boolean(/blog.csdn.net/i.test(window.location.origin));
  145. },
  146. /**
  147. * 判断是否是文库
  148. * + wenku.csdn.net
  149. */
  150. isWenKu() {
  151. return Boolean(/wenku.csdn.net/i.test(window.location.origin));
  152. },
  153. /**
  154. * 判断是否是链接
  155. * + link.csdn.net
  156. */
  157. isLink() {
  158. return window.location.hostname === "link.csdn.net";
  159. },
  160. /**
  161. * 判断是否是搜索
  162. * + so.csdn.net
  163. */
  164. isSo() {
  165. return window.location.hostname === "so.csdn.net";
  166. },
  167. /**
  168. * 判断是否是C知道
  169. * + so.csdn.net/know
  170. * + /chat
  171. * + /so/ai
  172. */
  173. isSoCKnow() {
  174. return this.isSo() && (window.location.pathname.startsWith("/chat") || window.location.pathname.startsWith("/so/ai"));
  175. },
  176. /**
  177. * 判断是否是资源页面
  178. * + download.csdn.net
  179. */
  180. isDownload() {
  181. return window.location.hostname === "download.csdn.net";
  182. }
  183. };
  184. const UISlider = function(text, key, defaultValue, min, max, changeCallBack, getToolTipContent, description) {
  185. let result = {
  186. text,
  187. type: "slider",
  188. description,
  189. attributes: {},
  190. getValue() {
  191. return PopsPanel.getValue(key, defaultValue);
  192. },
  193. getToolTipContent(value) {
  194. if (typeof getToolTipContent === "function") {
  195. return getToolTipContent(value);
  196. } else {
  197. return `${value}`;
  198. }
  199. },
  200. callback(event, value) {
  201. if (typeof changeCallBack === "function") {
  202. if (changeCallBack(event, value)) {
  203. return;
  204. }
  205. }
  206. PopsPanel.setValue(key, value);
  207. },
  208. min,
  209. max
  210. };
  211. if (result.attributes) {
  212. result.attributes[ATTRIBUTE_KEY] = key;
  213. result.attributes[ATTRIBUTE_DEFAULT_VALUE] = defaultValue;
  214. }
  215. return result;
  216. };
  217. const UISwitch = function(text, key, defaultValue, clickCallBack, description) {
  218. let result = {
  219. text,
  220. type: "switch",
  221. description,
  222. attributes: {},
  223. getValue() {
  224. return Boolean(PopsPanel.getValue(key, defaultValue));
  225. },
  226. callback(event, value) {
  227. log.success(`${value ? "开启" : "关闭"} ${text}`);
  228. if (typeof clickCallBack === "function") {
  229. if (clickCallBack(event, value)) {
  230. return;
  231. }
  232. }
  233. PopsPanel.setValue(key, Boolean(value));
  234. },
  235. afterAddToUListCallBack: void 0
  236. };
  237. if (result.attributes) {
  238. result.attributes[ATTRIBUTE_KEY] = key;
  239. result.attributes[ATTRIBUTE_DEFAULT_VALUE] = Boolean(defaultValue);
  240. }
  241. return result;
  242. };
  243. const SettingUIBlog = {
  244. id: "panel-blog",
  245. title: "博客",
  246. isDefault() {
  247. return CSDNRouter.isBlog();
  248. },
  249. forms: [
  250. {
  251. text: "",
  252. type: "forms",
  253. forms: [
  254. {
  255. text: "全局屏蔽",
  256. type: "deepMenu",
  257. forms: [
  258. {
  259. text: "",
  260. type: "forms",
  261. forms: [
  262. UISwitch(
  263. "【屏蔽】登录弹窗",
  264. "csdn-blog-shieldLoginDialog",
  265. true
  266. ),
  267. UISwitch(
  268. "【屏蔽】左侧博客信息",
  269. "csdn-blog-shieldLeftBlogContainerAside",
  270. false
  271. ),
  272. UISwitch(
  273. "【屏蔽】右侧目录信息",
  274. "csdn-blog-shieldRightDirectoryInformation",
  275. false
  276. ),
  277. UISwitch(
  278. "【屏蔽】顶部工具栏",
  279. "csdn-blog-shieldTopToolbar",
  280. false
  281. ),
  282. UISwitch(
  283. "【屏蔽】底部的悬浮工具栏",
  284. "csdn-blog-shieldBottomFloatingToolbar",
  285. false
  286. )
  287. ]
  288. }
  289. ]
  290. },
  291. {
  292. text: "右侧悬浮工具栏",
  293. type: "deepMenu",
  294. forms: [
  295. {
  296. text: "功能",
  297. type: "forms",
  298. forms: [
  299. UISwitch(
  300. "启用",
  301. "csdn-blog-rightToolbarEnable",
  302. true,
  303. void 0,
  304. "创作中心,隐藏/显示侧栏,新手引导,客服、举报..."
  305. ),
  306. UISwitch(
  307. "【添加按钮】前往评论",
  308. "csdn-blog-addGotoRecommandButton",
  309. true,
  310. void 0,
  311. "在悬浮工具栏最后面添加"
  312. ),
  313. UISlider(
  314. "right偏移",
  315. "csdn-blog-rightToolbarRightOffset",
  316. 90,
  317. 0,
  318. document.documentElement.clientWidth,
  319. (event, value) => {
  320. let csdnSideToolbar = document.querySelector(
  321. ".csdn-side-toolbar"
  322. );
  323. domutils.css(csdnSideToolbar, {
  324. right: value + "px"
  325. });
  326. },
  327. (value) => {
  328. return `当前:${value}px,默认:90px`;
  329. }
  330. ),
  331. UISlider(
  332. "top偏移",
  333. "csdn-blog-rightToolbarTopOffset",
  334. 140,
  335. 0,
  336. document.documentElement.clientHeight,
  337. (event, value) => {
  338. let csdnSideToolbar = document.querySelector(
  339. ".csdn-side-toolbar"
  340. );
  341. domutils.css(csdnSideToolbar, {
  342. top: value + "px"
  343. });
  344. },
  345. (value) => {
  346. return `当前:${value}px,默认:90px`;
  347. }
  348. )
  349. ]
  350. },
  351. {
  352. text: "屏蔽",
  353. type: "forms",
  354. forms: [
  355. UISwitch(
  356. "【屏蔽】创作中心",
  357. "csdn-blog-rightToolbarCreativeCenter",
  358. false
  359. ),
  360. UISwitch(
  361. "【屏蔽】显示/隐藏侧栏",
  362. "csdn-blog-rightToolbarShowOrSidebar",
  363. false
  364. ),
  365. UISwitch(
  366. "【屏蔽】新手引导",
  367. "csdn-blog-rightToolbarBeginnerGuidance",
  368. false
  369. ),
  370. UISwitch(
  371. "【屏蔽】客服",
  372. "csdn-blog-rightToolbarCustomerService",
  373. false
  374. ),
  375. UISwitch("【屏蔽】举报", "csdn-blog-rightToolbarReport", false),
  376. UISwitch(
  377. "【屏蔽】返回顶部",
  378. "csdn-blog-rightToolbarBackToTop",
  379. false
  380. )
  381. ]
  382. }
  383. ]
  384. },
  385. {
  386. text: "内容",
  387. type: "deepMenu",
  388. forms: [
  389. {
  390. text: "功能",
  391. type: "forms",
  392. forms: [
  393. UISwitch(
  394. "点击代码块自动展开",
  395. "csdn-blog-clickPreCodeAutomatically",
  396. true,
  397. void 0,
  398. "当鼠标点击代码块区域时,将自动展开内容"
  399. ),
  400. UISwitch(
  401. "自动展开代码块",
  402. "csdn-blog-autoExpandCodeContent",
  403. true,
  404. void 0,
  405. "懒人操作,免手动点击展开"
  406. ),
  407. UISwitch(
  408. "自动展开内容",
  409. "csdn-blog-autoExpandContent",
  410. true,
  411. void 0,
  412. "懒人操作,免手动点击展开"
  413. ),
  414. UISwitch(
  415. "全文居中",
  416. "csdn-blog-articleCenter",
  417. true,
  418. function(event, enable) {
  419. if (enable) {
  420. alert(
  421. "为了更好的呈现效果,请开启功能:【屏蔽】左侧博客信息、【屏蔽】右侧目录信息"
  422. );
  423. }
  424. },
  425. "自动屏蔽左侧和右侧的信息,且将文章居中"
  426. ),
  427. UISwitch(
  428. "允许选择内容",
  429. "csdn-blog-allowSelectContent",
  430. true,
  431. void 0
  432. )
  433. ]
  434. },
  435. {
  436. text: "屏蔽",
  437. type: "forms",
  438. forms: [
  439. UISwitch(
  440. "【屏蔽】底部xx技能树",
  441. "csdn-blog-shieldBottomSkillTree",
  442. false
  443. ),
  444. UISwitch(
  445. "【屏蔽】选中文字悬浮栏",
  446. "csdn-blog-shieldArticleSearchTip",
  447. false,
  448. void 0,
  449. "选中文字弹出的,例如:搜索、评论、笔记"
  450. )
  451. ]
  452. }
  453. ]
  454. },
  455. {
  456. text: "评论区",
  457. type: "deepMenu",
  458. forms: [
  459. {
  460. text: "",
  461. type: "forms",
  462. forms: [
  463. UISwitch(
  464. "启用",
  465. "csdn-blog-blockComment",
  466. true,
  467. void 0,
  468. "关闭是屏蔽评论区"
  469. ),
  470. UISwitch("优化评论区的位置", "csdn-blog-restoreComments", true)
  471. ]
  472. }
  473. ]
  474. },
  475. {
  476. text: "底部文章",
  477. type: "deepMenu",
  478. forms: [
  479. {
  480. text: "",
  481. type: "forms",
  482. forms: [
  483. UISwitch(
  484. "启用",
  485. "csdn-blog-bottomRecommendArticleEnable",
  486. true,
  487. void 0,
  488. "关闭是屏蔽底部文章"
  489. ),
  490. UISwitch(
  491. "标识CSDN下载",
  492. "csdn-blog-identityCSDNDownload",
  493. true,
  494. void 0,
  495. "使用红框标识"
  496. ),
  497. UISwitch(
  498. "移除资源下载的文章",
  499. "csdn-blog-removeResourceDownloadArticle",
  500. false,
  501. void 0,
  502. "移除download.csdn.net、www.iteye.com、edu.csdn.net的文章链接"
  503. )
  504. ]
  505. }
  506. ]
  507. },
  508. {
  509. text: "劫持/拦截",
  510. type: "deepMenu",
  511. forms: [
  512. {
  513. text: "",
  514. type: "forms",
  515. forms: [
  516. UISwitch(
  517. "拦截-复制的小尾巴",
  518. "csdn-blog-removeClipboardHijacking",
  519. true
  520. ),
  521. UISwitch(
  522. "劫持-禁止复制",
  523. "csdn-blog-unBlockCopy",
  524. true,
  525. void 0,
  526. "允许点击复制按钮进行复制"
  527. )
  528. ]
  529. }
  530. ]
  531. }
  532. ]
  533. }
  534. ]
  535. };
  536. const SettingUILink = {
  537. id: "panel-link",
  538. title: "链接",
  539. isDefault() {
  540. return CSDNRouter.isLink();
  541. },
  542. forms: [
  543. {
  544. text: "功能",
  545. type: "forms",
  546. forms: [
  547. UISwitch(
  548. "重定向链接",
  549. "csdn-link-jumpRedirect",
  550. true,
  551. void 0,
  552. "自动跳转至被拦截的Url链接"
  553. )
  554. ]
  555. }
  556. ]
  557. };
  558. const SettingUIHuaWeiCloud = {
  559. id: "panel-hua-wei-cloud",
  560. title: "华为云开发者联盟",
  561. isDefault() {
  562. return CSDNRouter.isHuaWeiCloudBlog();
  563. },
  564. forms: [
  565. {
  566. text: "功能",
  567. type: "forms",
  568. forms: [
  569. UISwitch(
  570. "自动展开全文",
  571. "csdn-hua-wei-cloud-autoExpandContent",
  572. true
  573. )
  574. ]
  575. },
  576. {
  577. text: "屏蔽",
  578. type: "forms",
  579. forms: [
  580. UISwitch(
  581. "【屏蔽】云开发者任务挑战活动",
  582. "csdn-hua-wei-cloud-shieldCloudDeveloperTaskChallengeEvent",
  583. true
  584. ),
  585. UISwitch(
  586. "【屏蔽】左侧悬浮按钮",
  587. "csdn-hua-wei-cloud-shieldLeftFloatingButton",
  588. false,
  589. function(event, enable) {
  590. if (enable) {
  591. alert(
  592. "开启后将屏蔽【当前阅读量】、【点赞按钮】、【评论按钮】、【分享按钮】"
  593. );
  594. }
  595. }
  596. ),
  597. UISwitch(
  598. "【屏蔽】右侧栏",
  599. "csdn-hua-wei-cloud-blockRightColumn",
  600. false,
  601. function(event, enable) {
  602. if (enable) {
  603. alert(
  604. "开启后将屏蔽【相关产品】-【活动日历】-【运营活动】-【热门标签】"
  605. );
  606. }
  607. }
  608. ),
  609. UISwitch(
  610. "【屏蔽】底部推荐内容",
  611. "csdn-hua-wei-cloud-blockRecommendedContentAtTheBottom",
  612. false
  613. ),
  614. UISwitch(
  615. "【屏蔽】底部更多推荐",
  616. "csdn-hua-wei-cloud-shieldTheBottomForMoreRecommendations",
  617. false
  618. )
  619. ]
  620. }
  621. ]
  622. };
  623. const SettingUIWenKu = {
  624. id: "panel-wenku",
  625. title: "资源",
  626. isDefault() {
  627. return CSDNRouter.isLink();
  628. },
  629. forms: [
  630. {
  631. text: "屏蔽",
  632. type: "forms",
  633. forms: [
  634. UISwitch(
  635. "【屏蔽】资源推荐",
  636. "csdn-wenku-shieldResourceRecommend",
  637. false
  638. ),
  639. UISwitch(
  640. "【屏蔽】右侧用户信息",
  641. "csdn-wenku-shieldRightUserInfo",
  642. false
  643. ),
  644. UISwitch(
  645. "【屏蔽】右侧悬浮工具栏",
  646. "csdn-wenku-shieldRightToolBar",
  647. false
  648. )
  649. ]
  650. }
  651. ]
  652. };
  653. const SettingUISo = {
  654. id: "panel-so",
  655. title: "搜索",
  656. isDefault() {
  657. return CSDNRouter.isSo();
  658. },
  659. forms: [
  660. {
  661. text: "C知道-功能",
  662. type: "forms",
  663. forms: [
  664. UISwitch(
  665. "去除水印",
  666. "csdn-so-cknow-removeMaskCover",
  667. true
  668. )
  669. ]
  670. }
  671. ]
  672. };
  673. const MSettingUIBlog = {
  674. id: "m-panel-blog",
  675. title: "博客",
  676. isDefault() {
  677. return CSDNRouter.isBlog();
  678. },
  679. forms: [
  680. {
  681. text: "",
  682. type: "forms",
  683. forms: [
  684. {
  685. text: "全局屏蔽",
  686. type: "deepMenu",
  687. forms: [
  688. {
  689. text: "",
  690. type: "forms",
  691. forms: [
  692. UISwitch(
  693. "【屏蔽】广告",
  694. "m-csdn-blog-removeAds",
  695. true,
  696. void 0,
  697. "包括:登录弹窗、打开APP、ios版本提示等"
  698. ),
  699. UISwitch(
  700. "【屏蔽】顶部Toolbar",
  701. "m-csdn-blog-shieldTopToolbar",
  702. false
  703. )
  704. ]
  705. }
  706. ]
  707. },
  708. {
  709. text: "内容",
  710. type: "deepMenu",
  711. forms: [
  712. {
  713. text: "",
  714. type: "forms",
  715. forms: [
  716. UISwitch(
  717. "允许选中文字",
  718. "m-csdn-blog-allowSelectText",
  719. true,
  720. void 0,
  721. "设置user-select: text;"
  722. ),
  723. UISwitch(
  724. "自动展开",
  725. "m-csdn-blog-autoExpandContent",
  726. true,
  727. void 0,
  728. "包括内容、代码块"
  729. ),
  730. UISwitch(
  731. "不限制代码块的最大高度",
  732. "m-csdn-blog-notLimitCodePreMaxHeight",
  733. false,
  734. void 0,
  735. "让代码块的高度直接被撑开"
  736. )
  737. ]
  738. }
  739. ]
  740. },
  741. {
  742. text: "评论",
  743. type: "deepMenu",
  744. forms: [
  745. {
  746. text: "",
  747. type: "forms",
  748. forms: [
  749. UISwitch(
  750. "启用",
  751. "m-csdn-blog-comment-enable",
  752. true,
  753. void 0,
  754. "关闭是屏蔽评论区"
  755. ),
  756. UISwitch(
  757. "不限制评论区的最大高度",
  758. "m-csdn-blog-notLimitCommentMaxHeight",
  759. true,
  760. void 0,
  761. "让评论区高度直接被撑开"
  762. )
  763. ]
  764. }
  765. ]
  766. },
  767. {
  768. text: "底部文章",
  769. type: "deepMenu",
  770. forms: [
  771. {
  772. text: "",
  773. type: "forms",
  774. forms: [
  775. UISwitch(
  776. "启用",
  777. "m-csdn-blog-bottomArticleEnable",
  778. true,
  779. void 0,
  780. "关闭是屏蔽底部文章"
  781. ),
  782. UISwitch(
  783. "移除资源下载",
  784. "m-csdn-blog-removeResourceArticle",
  785. false,
  786. void 0,
  787. "移除download.csdn.net、www.iteye.com、edu.csdn.net的文章链接"
  788. ),
  789. UISwitch(
  790. "重构",
  791. "m-csdn-blog-refactoringRecommendation",
  792. true,
  793. void 0,
  794. "文章的样式统一"
  795. ),
  796. UISwitch(
  797. "新标签页打开",
  798. "m-csdn-blog-openNewTab",
  799. true,
  800. void 0,
  801. "新标签页打开文章"
  802. )
  803. ]
  804. }
  805. ]
  806. },
  807. {
  808. text: "劫持/拦截",
  809. type: "deepMenu",
  810. forms: [
  811. {
  812. text: "",
  813. type: "forms",
  814. forms: [
  815. UISwitch(
  816. "劫持-禁止复制",
  817. "m-csdn-blog-unBlockCopy",
  818. true,
  819. void 0,
  820. "允许点击复制按钮进行复制"
  821. )
  822. ]
  823. }
  824. ]
  825. }
  826. ]
  827. }
  828. ]
  829. };
  830. const MSettingUILink = {
  831. id: "m-panel-link",
  832. title: "链接",
  833. isDefault() {
  834. return CSDNRouter.isLink();
  835. },
  836. forms: [
  837. {
  838. text: "功能",
  839. type: "forms",
  840. forms: [
  841. UISwitch(
  842. "重定向链接",
  843. "m-csdn-link-jumpRedirect",
  844. true,
  845. void 0,
  846. "自动跳转至被拦截的Url链接"
  847. )
  848. ]
  849. }
  850. ]
  851. };
  852. const MSettingUISo = {
  853. id: "panel-so",
  854. title: "搜索",
  855. isDefault() {
  856. return CSDNRouter.isSo();
  857. },
  858. forms: [
  859. {
  860. text: "C知道-功能",
  861. type: "forms",
  862. forms: [
  863. UISwitch(
  864. "去除水印",
  865. "m-csdn-so-cknow-removeMaskCover",
  866. true
  867. )
  868. ]
  869. }
  870. ]
  871. };
  872. const MSettingUIWenKu = {
  873. id: "m-panel-wenku",
  874. title: "文库",
  875. isDefault() {
  876. return CSDNRouter.isWenKu();
  877. },
  878. forms: [
  879. {
  880. text: "屏蔽",
  881. type: "forms",
  882. forms: [
  883. UISwitch(
  884. "【屏蔽】底部工具栏",
  885. "m-csdn-wenku-shieldBottomToolbar",
  886. false
  887. )
  888. ]
  889. }
  890. ]
  891. };
  892. const MSettingUIHuaWeiCloud = {
  893. id: "m-panel-hua-wei-cloud",
  894. title: "华为云开发者联盟",
  895. isDefault() {
  896. return CSDNRouter.isHuaWeiCloudBlog();
  897. },
  898. forms: [
  899. {
  900. text: "功能",
  901. type: "forms",
  902. forms: [
  903. UISwitch(
  904. "自动展开全文",
  905. "m-csdn-hua-wei-cloud-autoExpandContent",
  906. true
  907. )
  908. ]
  909. }
  910. ]
  911. };
  912. const MSettingUIDownload = {
  913. id: "m-panel-download",
  914. title: "资源",
  915. isDefault() {
  916. return CSDNRouter.isDownload();
  917. },
  918. forms: [
  919. {
  920. text: "功能",
  921. type: "forms",
  922. forms: [
  923. UISwitch(
  924. "自动展开资源介绍",
  925. "m-csdn-download-automaticallyExpandResourceIntroduction",
  926. true,
  927. void 0,
  928. "屏蔽资源介绍【展开全部】按钮并展开资源介绍"
  929. )
  930. ]
  931. },
  932. {
  933. text: "屏蔽",
  934. type: "forms",
  935. forms: [
  936. UISwitch(
  937. "【屏蔽】广告",
  938. "m-csdn-download-removeAds",
  939. true,
  940. void 0,
  941. "包括:登录弹窗、会员降价等"
  942. )
  943. ]
  944. }
  945. ]
  946. };
  947. const UISelect = function(text, key, defaultValue, data, callback, description) {
  948. let selectData = [];
  949. if (typeof data === "function") {
  950. selectData = data();
  951. } else {
  952. selectData = data;
  953. }
  954. let result = {
  955. text,
  956. type: "select",
  957. description,
  958. attributes: {},
  959. getValue() {
  960. return PopsPanel.getValue(key, defaultValue);
  961. },
  962. callback(event, isSelectedValue, isSelectedText) {
  963. PopsPanel.setValue(key, isSelectedValue);
  964. if (typeof callback === "function") {
  965. callback(event, isSelectedValue, isSelectedText);
  966. }
  967. },
  968. data: selectData
  969. };
  970. if (result.attributes) {
  971. result.attributes[ATTRIBUTE_KEY] = key;
  972. result.attributes[ATTRIBUTE_DEFAULT_VALUE] = defaultValue;
  973. }
  974. return result;
  975. };
  976. const SettingUICommon = {
  977. id: "component-common",
  978. title: "通用",
  979. forms: [
  980. {
  981. text: "Toast配置",
  982. type: "forms",
  983. forms: [
  984. UISelect(
  985. "Toast位置",
  986. "qmsg-config-position",
  987. "bottom",
  988. [
  989. {
  990. value: "topleft",
  991. text: "左上角"
  992. },
  993. {
  994. value: "top",
  995. text: "顶部"
  996. },
  997. {
  998. value: "topright",
  999. text: "右上角"
  1000. },
  1001. {
  1002. value: "left",
  1003. text: "左边"
  1004. },
  1005. {
  1006. value: "center",
  1007. text: "中间"
  1008. },
  1009. {
  1010. value: "right",
  1011. text: "右边"
  1012. },
  1013. {
  1014. value: "bottomleft",
  1015. text: "左下角"
  1016. },
  1017. {
  1018. value: "bottom",
  1019. text: "底部"
  1020. },
  1021. {
  1022. value: "bottomright",
  1023. text: "右下角"
  1024. }
  1025. ],
  1026. (event, isSelectValue, isSelectText) => {
  1027. log.info("设置当前Qmsg弹出位置" + isSelectText);
  1028. },
  1029. "Toast显示在页面九宫格的位置"
  1030. ),
  1031. UISelect(
  1032. "最多显示的数量",
  1033. "qmsg-config-maxnums",
  1034. 3,
  1035. [
  1036. {
  1037. value: 1,
  1038. text: "1"
  1039. },
  1040. {
  1041. value: 2,
  1042. text: "2"
  1043. },
  1044. {
  1045. value: 3,
  1046. text: "3"
  1047. },
  1048. {
  1049. value: 4,
  1050. text: "4"
  1051. },
  1052. {
  1053. value: 5,
  1054. text: "5"
  1055. }
  1056. ],
  1057. void 0,
  1058. "限制Toast显示的数量"
  1059. ),
  1060. UISwitch(
  1061. "逆序弹出",
  1062. "qmsg-config-showreverse",
  1063. false,
  1064. void 0,
  1065. "修改Toast弹出的顺序"
  1066. )
  1067. ]
  1068. }
  1069. // {
  1070. // text: "Cookie配置",
  1071. // type: "forms",
  1072. // forms: [
  1073. // UISwitch(
  1074. // "启用",
  1075. // "httpx-use-cookie-enable",
  1076. // false,
  1077. // void 0,
  1078. // "启用后,将根据下面的配置进行添加cookie"
  1079. // ),
  1080. // UISwitch(
  1081. // "使用document.cookie",
  1082. // "httpx-use-document-cookie",
  1083. // false,
  1084. // void 0,
  1085. // "自动根据请求的域名来设置对应的cookie"
  1086. // ),
  1087. // UITextArea(
  1088. // "tieba.baidu.com",
  1089. // "httpx-cookie-tieba.baidu.com",
  1090. // "",
  1091. // void 0,
  1092. // void 0,
  1093. // "Cookie格式:xxx=xxxx;xxx=xxxx"
  1094. // ),
  1095. // ],
  1096. // },
  1097. ]
  1098. };
  1099. const MSettingUICommon = {
  1100. id: "component-common",
  1101. title: "通用",
  1102. forms: [
  1103. {
  1104. text: "Toast配置",
  1105. type: "forms",
  1106. forms: [
  1107. UISelect(
  1108. "Toast位置",
  1109. "qmsg-config-position",
  1110. "bottom",
  1111. [
  1112. {
  1113. value: "topleft",
  1114. text: "左上角"
  1115. },
  1116. {
  1117. value: "top",
  1118. text: "顶部"
  1119. },
  1120. {
  1121. value: "topright",
  1122. text: "右上角"
  1123. },
  1124. {
  1125. value: "left",
  1126. text: "左边"
  1127. },
  1128. {
  1129. value: "center",
  1130. text: "中间"
  1131. },
  1132. {
  1133. value: "right",
  1134. text: "右边"
  1135. },
  1136. {
  1137. value: "bottomleft",
  1138. text: "左下角"
  1139. },
  1140. {
  1141. value: "bottom",
  1142. text: "底部"
  1143. },
  1144. {
  1145. value: "bottomright",
  1146. text: "右下角"
  1147. }
  1148. ],
  1149. (event, isSelectValue, isSelectText) => {
  1150. log.info("设置当前Qmsg弹出位置" + isSelectText);
  1151. },
  1152. "Toast显示在页面九宫格的位置"
  1153. ),
  1154. UISelect(
  1155. "最多显示的数量",
  1156. "qmsg-config-maxnums",
  1157. 3,
  1158. [
  1159. {
  1160. value: 1,
  1161. text: "1"
  1162. },
  1163. {
  1164. value: 2,
  1165. text: "2"
  1166. },
  1167. {
  1168. value: 3,
  1169. text: "3"
  1170. },
  1171. {
  1172. value: 4,
  1173. text: "4"
  1174. },
  1175. {
  1176. value: 5,
  1177. text: "5"
  1178. }
  1179. ],
  1180. void 0,
  1181. "限制Toast显示的数量"
  1182. ),
  1183. UISwitch(
  1184. "逆序弹出",
  1185. "qmsg-config-showreverse",
  1186. false,
  1187. void 0,
  1188. "修改Toast弹出的顺序"
  1189. )
  1190. ]
  1191. }
  1192. // {
  1193. // text: "Cookie配置",
  1194. // type: "forms",
  1195. // forms: [
  1196. // UISwitch(
  1197. // "启用",
  1198. // "httpx-use-cookie-enable",
  1199. // false,
  1200. // void 0,
  1201. // "启用后,将根据下面的配置进行添加cookie"
  1202. // ),
  1203. // UISwitch(
  1204. // "使用document.cookie",
  1205. // "httpx-use-document-cookie",
  1206. // false,
  1207. // void 0,
  1208. // "自动根据请求的域名来设置对应的cookie"
  1209. // ),
  1210. // UITextArea(
  1211. // "tieba.baidu.com",
  1212. // "httpx-cookie-tieba.baidu.com",
  1213. // "",
  1214. // void 0,
  1215. // void 0,
  1216. // "Cookie格式:xxx=xxxx;xxx=xxxx"
  1217. // ),
  1218. // ],
  1219. // },
  1220. ]
  1221. };
  1222. const __PopsPanel__ = {
  1223. data: null,
  1224. oneSuccessExecMenu: null,
  1225. onceExec: null,
  1226. listenData: null
  1227. };
  1228. const PopsPanel = {
  1229. /** 数据 */
  1230. $data: {
  1231. /**
  1232. * 菜单项的默认值
  1233. */
  1234. get data() {
  1235. if (__PopsPanel__.data == null) {
  1236. __PopsPanel__.data = new utils.Dictionary();
  1237. }
  1238. return __PopsPanel__.data;
  1239. },
  1240. /**
  1241. * 成功只执行了一次的项
  1242. */
  1243. get oneSuccessExecMenu() {
  1244. if (__PopsPanel__.oneSuccessExecMenu == null) {
  1245. __PopsPanel__.oneSuccessExecMenu = new utils.Dictionary();
  1246. }
  1247. return __PopsPanel__.oneSuccessExecMenu;
  1248. },
  1249. /**
  1250. * 成功只执行了一次的项
  1251. */
  1252. get onceExec() {
  1253. if (__PopsPanel__.onceExec == null) {
  1254. __PopsPanel__.onceExec = new utils.Dictionary();
  1255. }
  1256. return __PopsPanel__.onceExec;
  1257. },
  1258. /** 脚本名,一般用在设置的标题上 */
  1259. get scriptName() {
  1260. return SCRIPT_NAME;
  1261. },
  1262. /** 菜单项的总值在本地数据配置的键名 */
  1263. key: KEY,
  1264. /** 菜单项在attributes上配置的菜单键 */
  1265. attributeKeyName: ATTRIBUTE_KEY,
  1266. /** 菜单项在attributes上配置的菜单默认值 */
  1267. attributeDefaultValueName: ATTRIBUTE_DEFAULT_VALUE
  1268. },
  1269. /** 监听器 */
  1270. $listener: {
  1271. /**
  1272. * 值改变的监听器
  1273. */
  1274. get listenData() {
  1275. if (__PopsPanel__.listenData == null) {
  1276. __PopsPanel__.listenData = new utils.Dictionary();
  1277. }
  1278. return __PopsPanel__.listenData;
  1279. }
  1280. },
  1281. init() {
  1282. this.initPanelDefaultValue();
  1283. this.initExtensionsMenu();
  1284. },
  1285. initExtensionsMenu() {
  1286. if (_unsafeWindow.top !== _unsafeWindow.self) {
  1287. return;
  1288. }
  1289. GM_Menu.add([
  1290. {
  1291. key: "show_pops_panel_setting",
  1292. text: "⚙ PC端设置",
  1293. autoReload: false,
  1294. isStoreValue: false,
  1295. showText(text) {
  1296. return text;
  1297. },
  1298. callback: () => {
  1299. this.showPanel();
  1300. }
  1301. },
  1302. {
  1303. key: "m_show_pops_panel_setting",
  1304. text: "⚙ 移动端端设置",
  1305. autoReload: false,
  1306. isStoreValue: false,
  1307. showText(text) {
  1308. return text;
  1309. },
  1310. callback: () => {
  1311. this.showMPanel();
  1312. }
  1313. },
  1314. {
  1315. key: "gotoCSDNCKnow",
  1316. text: "⚙ 前往C知道",
  1317. isStoreValue: false,
  1318. autoReload: false,
  1319. showText(text) {
  1320. return text;
  1321. },
  1322. callback() {
  1323. window.open("https://so.csdn.net/chat", "_blank");
  1324. }
  1325. }
  1326. ]);
  1327. },
  1328. /** 初始化本地设置默认的值 */
  1329. initPanelDefaultValue() {
  1330. let that = this;
  1331. function initDefaultValue(config) {
  1332. if (!config["attributes"]) {
  1333. return;
  1334. }
  1335. let key = config.attributes[ATTRIBUTE_KEY];
  1336. let defaultValue = config["attributes"][ATTRIBUTE_DEFAULT_VALUE];
  1337. if (key == null) {
  1338. log.warn(["请先配置键", config]);
  1339. return;
  1340. }
  1341. if (that.$data.data.has(key)) {
  1342. log.warn("请检查该key(已存在): " + key);
  1343. }
  1344. that.$data.data.set(key, defaultValue);
  1345. }
  1346. function loopInitDefaultValue(configList) {
  1347. for (let index = 0; index < configList.length; index++) {
  1348. let configItem = configList[index];
  1349. initDefaultValue(configItem);
  1350. let childForms = configItem.forms;
  1351. if (childForms && Array.isArray(childForms)) {
  1352. loopInitDefaultValue(childForms);
  1353. }
  1354. }
  1355. }
  1356. let contentConfigList = this.getPanelContentConfig().concat(
  1357. this.getMPanelContentConfig()
  1358. );
  1359. for (let index = 0; index < contentConfigList.length; index++) {
  1360. let leftContentConfigItem = contentConfigList[index];
  1361. if (!leftContentConfigItem.forms) {
  1362. continue;
  1363. }
  1364. let rightContentConfigList = leftContentConfigItem.forms;
  1365. if (rightContentConfigList && Array.isArray(rightContentConfigList)) {
  1366. loopInitDefaultValue(rightContentConfigList);
  1367. }
  1368. }
  1369. },
  1370. /**
  1371. * 设置值
  1372. * @param key 键
  1373. * @param value 值
  1374. */
  1375. setValue(key, value) {
  1376. let locaData = _GM_getValue(KEY, {});
  1377. let oldValue = locaData[key];
  1378. locaData[key] = value;
  1379. _GM_setValue(KEY, locaData);
  1380. if (this.$listener.listenData.has(key)) {
  1381. this.$listener.listenData.get(key).callback(key, oldValue, value);
  1382. }
  1383. },
  1384. /**
  1385. * 判断该键是否存在
  1386. * @param key 键
  1387. */
  1388. hasKey(key) {
  1389. let locaData = _GM_getValue(KEY, {});
  1390. return key in locaData;
  1391. },
  1392. /**
  1393. * 获取值
  1394. * @param key 键
  1395. * @param defaultValue 默认值
  1396. */
  1397. getValue(key, defaultValue) {
  1398. let locaData = _GM_getValue(KEY, {});
  1399. let localValue = locaData[key];
  1400. if (localValue == null) {
  1401. if (this.$data.data.has(key)) {
  1402. return this.$data.data.get(key);
  1403. }
  1404. return defaultValue;
  1405. }
  1406. return localValue;
  1407. },
  1408. /**
  1409. * 删除值
  1410. * @param key 键
  1411. */
  1412. deleteValue(key) {
  1413. let locaData = _GM_getValue(KEY, {});
  1414. let oldValue = locaData[key];
  1415. Reflect.deleteProperty(locaData, key);
  1416. _GM_setValue(KEY, locaData);
  1417. if (this.$listener.listenData.has(key)) {
  1418. this.$listener.listenData.get(key).callback(key, oldValue, void 0);
  1419. }
  1420. },
  1421. /**
  1422. * 监听调用setValue、deleteValue
  1423. * @param key 需要监听的键
  1424. * @param callback
  1425. */
  1426. addValueChangeListener(key, callback) {
  1427. let listenerId = Math.random();
  1428. this.$listener.listenData.set(key, {
  1429. id: listenerId,
  1430. key,
  1431. callback
  1432. });
  1433. return listenerId;
  1434. },
  1435. /**
  1436. * 移除监听
  1437. * @param listenerId 监听的id
  1438. */
  1439. removeValueChangeListener(listenerId) {
  1440. let deleteKey = null;
  1441. for (const [key, value] of this.$listener.listenData.entries()) {
  1442. if (value.id === listenerId) {
  1443. deleteKey = key;
  1444. break;
  1445. }
  1446. }
  1447. if (typeof deleteKey === "string") {
  1448. this.$listener.listenData.delete(deleteKey);
  1449. } else {
  1450. console.warn("没有找到对应的监听器");
  1451. }
  1452. },
  1453. /**
  1454. * 自动判断菜单是否启用,然后执行回调
  1455. * @param key
  1456. * @param callback 回调
  1457. */
  1458. execMenu(key, callback) {
  1459. if (typeof key !== "string") {
  1460. throw new TypeError("key 必须是字符串");
  1461. }
  1462. if (!this.$data.data.has(key)) {
  1463. log.warn(`${key} 键不存在`);
  1464. return;
  1465. }
  1466. let value = PopsPanel.getValue(key);
  1467. if (value) {
  1468. callback(value);
  1469. }
  1470. },
  1471. /**
  1472. * 自动判断菜单是否启用,然后执行回调,只会执行一次
  1473. * @param key
  1474. * @param callback 回调
  1475. */
  1476. execMenuOnce(key, callback) {
  1477. if (typeof key !== "string") {
  1478. throw new TypeError("key 必须是字符串");
  1479. }
  1480. if (!this.$data.data.has(key)) {
  1481. log.warn(`${key} 键不存在`);
  1482. return;
  1483. }
  1484. let value = PopsPanel.getValue(key);
  1485. if (value) {
  1486. if (this.$data.oneSuccessExecMenu.has(key)) {
  1487. return;
  1488. }
  1489. callback(value);
  1490. this.$data.oneSuccessExecMenu.set(key, 1);
  1491. }
  1492. },
  1493. /**
  1494. * 根据key执行一次
  1495. * @param key
  1496. */
  1497. onceExec(key, callback) {
  1498. if (typeof key !== "string") {
  1499. throw new TypeError("key 必须是字符串");
  1500. }
  1501. if (this.$data.onceExec.has(key)) {
  1502. return;
  1503. }
  1504. callback();
  1505. this.$data.onceExec.set(key, 1);
  1506. },
  1507. /**
  1508. * 显示设置面板
  1509. */
  1510. showPanel() {
  1511. pops.panel({
  1512. title: {
  1513. text: `${SCRIPT_NAME}-PC端设置`,
  1514. position: "center",
  1515. html: false,
  1516. style: ""
  1517. },
  1518. content: this.getPanelContentConfig(),
  1519. mask: {
  1520. enable: true,
  1521. clickEvent: {
  1522. toClose: true,
  1523. toHide: false
  1524. }
  1525. },
  1526. isMobile: this.isMobile(),
  1527. width: this.getWidth(),
  1528. height: this.getHeight(),
  1529. drag: true,
  1530. only: true
  1531. });
  1532. },
  1533. /**
  1534. * 显示设置面板
  1535. */
  1536. showMPanel() {
  1537. pops.panel({
  1538. title: {
  1539. text: `${SCRIPT_NAME}-移动端设置`,
  1540. position: "center",
  1541. html: false,
  1542. style: ""
  1543. },
  1544. content: this.getMPanelContentConfig(),
  1545. mask: {
  1546. enable: true,
  1547. clickEvent: {
  1548. toClose: true,
  1549. toHide: false
  1550. }
  1551. },
  1552. isMobile: this.isMobile(),
  1553. width: this.getWidth(),
  1554. height: this.getHeight(),
  1555. drag: true,
  1556. only: true
  1557. });
  1558. },
  1559. isMobile() {
  1560. return window.outerWidth < 550;
  1561. },
  1562. /**
  1563. * 获取设置面板的宽度
  1564. */
  1565. getWidth() {
  1566. if (window.outerWidth < 800) {
  1567. return "92dvw";
  1568. } else {
  1569. return "800px";
  1570. }
  1571. },
  1572. /**
  1573. * 获取设置面板的高度
  1574. */
  1575. getHeight() {
  1576. if (window.outerHeight > 450) {
  1577. return "80dvh";
  1578. } else {
  1579. return "450px";
  1580. }
  1581. },
  1582. /**
  1583. * 获取配置内容
  1584. */
  1585. getPanelContentConfig() {
  1586. let configList = [
  1587. SettingUICommon,
  1588. SettingUIBlog,
  1589. SettingUILink,
  1590. SettingUIHuaWeiCloud,
  1591. SettingUIWenKu,
  1592. SettingUISo
  1593. ];
  1594. return configList;
  1595. },
  1596. /**
  1597. * 获取配置内容
  1598. */
  1599. getMPanelContentConfig() {
  1600. let configList = [
  1601. MSettingUICommon,
  1602. MSettingUIBlog,
  1603. MSettingUILink,
  1604. MSettingUIHuaWeiCloud,
  1605. MSettingUIWenKu,
  1606. MSettingUISo,
  1607. MSettingUIDownload
  1608. ];
  1609. return configList;
  1610. }
  1611. };
  1612. const ShieldCSS$4 = "/* 底部免费抽xxx奖品广告 */\r\ndiv.siderbar-box,\r\n/* 华为开发者联盟加入社区 */\r\ndiv.user-desc.user-desc-fix {\r\n display: none !important;\r\n}\r\n";
  1613. const CSDNUtils = {
  1614. /**
  1615. * 移除元素(未出现也可以等待出现)
  1616. * @param selectorText 元素选择器
  1617. */
  1618. waitForElementToRemove(selectorText = "") {
  1619. utils.waitNodeList(selectorText).then((nodeList) => {
  1620. nodeList.forEach((item) => item.remove());
  1621. });
  1622. },
  1623. /**
  1624. * 添加屏蔽CSS
  1625. * @param args
  1626. * @example
  1627. * addBlockCSS("")
  1628. * addBlockCSS("","")
  1629. * addBlockCSS(["",""])
  1630. */
  1631. addBlockCSS(...args) {
  1632. let selectorList = [];
  1633. if (args.length === 0) {
  1634. return;
  1635. }
  1636. if (args.length === 1 && typeof args[0] === "string" && args[0].trim() === "") {
  1637. return;
  1638. }
  1639. args.forEach((selector) => {
  1640. if (Array.isArray(selector)) {
  1641. selectorList = selectorList.concat(selector);
  1642. } else {
  1643. selectorList.push(selector);
  1644. }
  1645. });
  1646. addStyle(`${selectorList.join(",\n")}{display: none !important;}`);
  1647. }
  1648. };
  1649. const CSDNHuaWeiCloud = {
  1650. init() {
  1651. addStyle(ShieldCSS$4);
  1652. PopsPanel.execMenu(
  1653. "csdn-hua-wei-cloud-shieldCloudDeveloperTaskChallengeEvent",
  1654. () => {
  1655. this.shieldCloudDeveloperTaskChallengeEvent();
  1656. }
  1657. );
  1658. PopsPanel.execMenu("csdn-hua-wei-cloud-autoExpandContent", () => {
  1659. this.autoExpandContent();
  1660. });
  1661. PopsPanel.execMenu("csdn-hua-wei-cloud-shieldLeftFloatingButton", () => {
  1662. this.shieldLeftFloatingButton();
  1663. });
  1664. PopsPanel.execMenu("csdn-hua-wei-cloud-blockRightColumn", () => {
  1665. this.blockRightColumn();
  1666. });
  1667. PopsPanel.execMenu(
  1668. "csdn-hua-wei-cloud-blockRecommendedContentAtTheBottom",
  1669. () => {
  1670. this.blockRecommendedContentAtTheBottom();
  1671. }
  1672. );
  1673. PopsPanel.execMenu(
  1674. "csdn-hua-wei-cloud-shieldTheBottomForMoreRecommendations",
  1675. () => {
  1676. this.shieldTheBottomForMoreRecommendations();
  1677. }
  1678. );
  1679. },
  1680. /**
  1681. * 自动展开内容
  1682. */
  1683. autoExpandContent() {
  1684. log.info("自动展开全文");
  1685. CSDNUtils.addBlockCSS("div.article-show-more");
  1686. addStyle(`
  1687. /* 自动展开全文 */
  1688. .main-content .user-article{
  1689. height: auto !important;
  1690. overflow: auto !important;
  1691. }
  1692. `);
  1693. },
  1694. /**
  1695. * 屏蔽云开发者任务挑战活动
  1696. */
  1697. shieldCloudDeveloperTaskChallengeEvent() {
  1698. let GM_cookie = new utils.GM_Cookie();
  1699. GM_cookie.set({ name: "show_join_group_index", value: 1 });
  1700. log.info("设置Cookie 屏蔽云开发者任务挑战活动");
  1701. },
  1702. /**
  1703. * 屏蔽左侧悬浮按钮
  1704. */
  1705. shieldLeftFloatingButton() {
  1706. log.info("屏蔽左侧悬浮按钮,包括当前阅读量、点赞按钮、评论按钮、分享按钮");
  1707. CSDNUtils.addBlockCSS("div.toolbar-wrapper.article-interact-bar");
  1708. },
  1709. /**
  1710. * 屏蔽右侧栏
  1711. */
  1712. blockRightColumn() {
  1713. log.info("屏蔽右侧栏,包括相关产品-活动日历-运营活动-热门标签");
  1714. CSDNUtils.addBlockCSS("div.page-home-right.dp-aside-right");
  1715. },
  1716. /**
  1717. * 屏蔽底部推荐内容
  1718. */
  1719. blockRecommendedContentAtTheBottom() {
  1720. log.info("屏蔽底部推荐内容");
  1721. CSDNUtils.addBlockCSS("div.recommend-card-box");
  1722. },
  1723. /**
  1724. * 屏蔽底部更多推荐
  1725. */
  1726. shieldTheBottomForMoreRecommendations() {
  1727. log.info("屏蔽底部更多推荐");
  1728. CSDNUtils.addBlockCSS("div.more-article");
  1729. }
  1730. };
  1731. const BlogShieldCSS = ".ecommend-item-box.recommend-recommend-box,\r\n.login-mark,\r\n.opt-box.text-center,\r\n.leftPop,\r\n#csdn-shop-window,\r\n.toolbar-advert,\r\n.hide-article-box,\r\n.user-desc.user-desc-fix,\r\n.recommend-card-box,\r\n.more-article,\r\n.article-show-more,\r\n#csdn-toolbar-profile-nologin,\r\n.guide-rr-first,\r\n#recommend-item-box-tow,\r\n/* 发文章得原力分图片提示 */\r\ndiv.csdn-toolbar-creative-mp,\r\n/* 阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。 */\r\n#toolBarBox div.write-guide-buttom-box,\r\n/* 觉得还不错? 一键收藏 */\r\nul.toolbox-list div.tool-active-list,\r\n/* 右边按钮组的最上面的创作话题 */\r\ndiv.csdn-side-toolbar .activity-swiper-box,\r\n.sidetool-writeguide-box .tip-box,\r\n/* 右下角的登录提示 */\r\n.passport-login-tip-container {\r\n display: none !important;\r\n}\r\n\r\n\r\n";
  1732. const BlogCSS = "/*.blog_container_aside,\r\n#nav {\r\n margin-left: -45px;\r\n}\r\n.recommend-right.align-items-stretch.clearfix,\r\n.dl_right_fixed {\r\n margin-left: 45px;\r\n}*/\r\n";
  1733. const BlogArticleCenterCSS = '#mainBox main {\r\n width: inherit !important;\r\n}\r\n/* 当文章向下滚动时,触发左侧信息悬浮 */\r\naside.blog_container_aside[style*="position: fixed;"] {\r\n display: none !important;\r\n}\r\n\r\n@media (min-width: 1320px) and (max-width: 1380px) {\r\n .nodata .container {\r\n width: 900px !important;\r\n }\r\n\r\n .nodata .container main {\r\n width: 900px;\r\n }\r\n\r\n .nodata .container main #pcCommentBox pre > ol.hljs-ln {\r\n width: 490px !important;\r\n }\r\n\r\n .nodata .container main .articleConDownSource {\r\n width: 500px;\r\n }\r\n}\r\n\r\n@media screen and (max-width: 1320px) {\r\n .nodata .container {\r\n width: 760px !important;\r\n }\r\n\r\n .nodata .container main {\r\n width: 760px;\r\n }\r\n\r\n .nodata .container main #pcCommentBox pre > ol.hljs-ln {\r\n width: 490px !important;\r\n }\r\n\r\n .nodata .container main .toolbox-list .tool-reward {\r\n display: none;\r\n }\r\n\r\n .nodata\r\n .container\r\n main\r\n .more-toolbox-new\r\n .toolbox-left\r\n .profile-box\r\n .profile-name {\r\n max-width: 128px;\r\n }\r\n\r\n .nodata .container main .articleConDownSource {\r\n width: 420px;\r\n }\r\n}\r\n\r\n@media screen and (min-width: 1380px) {\r\n .nodata .container {\r\n width: 1010px !important;\r\n }\r\n\r\n .nodata .container main {\r\n width: 1010px;\r\n }\r\n\r\n .nodata .container main #pcCommentBox pre > ol.hljs-ln {\r\n width: 490px !important;\r\n }\r\n\r\n .nodata .container main .articleConDownSource {\r\n width: 560px;\r\n }\r\n}\r\n\r\n@media (min-width: 1550px) and (max-width: 1700px) {\r\n .nodata .container {\r\n width: 820px !important;\r\n }\r\n\r\n .nodata .container main {\r\n width: 820px;\r\n }\r\n\r\n .nodata .container main #pcCommentBox pre > ol.hljs-ln {\r\n width: 690px !important;\r\n }\r\n\r\n .nodata .container main .articleConDownSource {\r\n width: 500px;\r\n }\r\n}\r\n\r\n@media screen and (min-width: 1700px) {\r\n .nodata .container {\r\n width: 1010px !important;\r\n }\r\n\r\n .nodata .container main {\r\n width: 1010px;\r\n }\r\n\r\n .nodata .container main #pcCommentBox pre > ol.hljs-ln {\r\n width: 690px !important;\r\n }\r\n\r\n .nodata .container main .articleConDownSource {\r\n width: 560px;\r\n }\r\n}\r\n';
  1734. const CSDNBlogRightToolBar = {
  1735. init() {
  1736. if (!PopsPanel.getValue("csdn-blog-rightToolbarEnable")) {
  1737. this.shieldRightToolbar();
  1738. }
  1739. PopsPanel.execMenuOnce("csdn-blog-rightToolbarCreativeCenter", () => {
  1740. this.shieldCreativeCenter();
  1741. });
  1742. PopsPanel.execMenuOnce("csdn-blog-rightToolbarShowOrSidebar", () => {
  1743. this.shieldShowOrSidebar();
  1744. });
  1745. PopsPanel.execMenuOnce("csdn-blog-rightToolbarBeginnerGuidance", () => {
  1746. this.shieldBeginnerGuidance();
  1747. });
  1748. PopsPanel.execMenuOnce("csdn-blog-rightToolbarCustomerService", () => {
  1749. this.shieldCustomerService();
  1750. });
  1751. PopsPanel.execMenuOnce("csdn-blog-rightToolbarReport", () => {
  1752. this.shieldReport();
  1753. });
  1754. PopsPanel.execMenuOnce("csdn-blog-rightToolbarBackToTop", () => {
  1755. this.shieldBackToTop();
  1756. });
  1757. this.initRightToolbarOffset();
  1758. domutils.ready(() => {
  1759. PopsPanel.execMenu("csdn-blog-addGotoRecommandButton", () => {
  1760. this.addGotoRecommandButton();
  1761. });
  1762. });
  1763. },
  1764. /**
  1765. * 屏蔽右侧工具栏
  1766. */
  1767. shieldRightToolbar() {
  1768. log.info("屏蔽右侧工具栏");
  1769. CSDNUtils.addBlockCSS(`div.csdn-side-toolbar`);
  1770. },
  1771. /**
  1772. * 【添加】前往评论按钮,在返回顶部的下面
  1773. */
  1774. addGotoRecommandButton() {
  1775. log.info("【添加】前往评论按钮,在返回顶部的上面");
  1776. let gotoRecommandNode = document.createElement("a");
  1777. gotoRecommandNode.className = "option-box";
  1778. gotoRecommandNode.setAttribute("data-type", "gorecommand");
  1779. gotoRecommandNode.innerHTML = `<span class="show-txt" style="display:flex;opacity:100;">前往<br>评论</span>`;
  1780. gotoRecommandNode.addEventListener("click", function() {
  1781. let toolbarBoxElement = document.querySelector(
  1782. "#toolBarBox"
  1783. );
  1784. if (!toolbarBoxElement.getClientRects().length) {
  1785. log.error("评论区处于隐藏状态");
  1786. return;
  1787. }
  1788. log.info("滚动到评论");
  1789. let toolbarBoxOffsetTop = toolbarBoxElement.getBoundingClientRect().top + window.scrollY;
  1790. let csdnToolBarElement = document.querySelector(
  1791. "#csdn-toolbar"
  1792. );
  1793. let csdnToolBarStyles = window.getComputedStyle(csdnToolBarElement);
  1794. let csdnToolBarHeight = csdnToolBarElement.clientHeight - parseFloat(csdnToolBarStyles.paddingTop) - parseFloat(csdnToolBarStyles.paddingBottom);
  1795. window.scrollTo({
  1796. top: toolbarBoxOffsetTop - csdnToolBarHeight - 8,
  1797. left: 0,
  1798. behavior: "smooth"
  1799. });
  1800. });
  1801. utils.waitNode(".csdn-side-toolbar").then(() => {
  1802. let targetElement = document.querySelector(
  1803. ".csdn-side-toolbar a:nth-last-child(2)"
  1804. );
  1805. targetElement.parentElement.insertBefore(
  1806. gotoRecommandNode,
  1807. targetElement.nextSibling
  1808. );
  1809. });
  1810. },
  1811. /**
  1812. * 初始化右侧工具栏的偏移(top、right)
  1813. */
  1814. initRightToolbarOffset() {
  1815. log.info("初始化右侧工具栏的偏移(top、right)");
  1816. addStyle(`
  1817. .csdn-side-toolbar{
  1818. left: unset !important;
  1819. }
  1820. `);
  1821. utils.waitNode(".csdn-side-toolbar").then(($sideToolbar) => {
  1822. domutils.css($sideToolbar, {
  1823. top: parseInt(PopsPanel.getValue("csdn-blog-rightToolbarTopOffset")) + "px",
  1824. right: parseInt(PopsPanel.getValue("csdn-blog-rightToolbarRightOffset")) + "px"
  1825. });
  1826. });
  1827. },
  1828. /**
  1829. * 【屏蔽】创作中心
  1830. */
  1831. shieldCreativeCenter() {
  1832. log.info("【屏蔽】创作中心");
  1833. CSDNUtils.addBlockCSS(".csdn-side-toolbar .sidetool-writeguide-box");
  1834. },
  1835. /**
  1836. * 【屏蔽】显示/隐藏侧栏
  1837. */
  1838. shieldShowOrSidebar() {
  1839. log.info("【屏蔽】显示/隐藏侧栏");
  1840. CSDNUtils.addBlockCSS(".csdn-side-toolbar a.sidecolumn");
  1841. },
  1842. /**
  1843. * 【屏蔽】新手引导
  1844. */
  1845. shieldBeginnerGuidance() {
  1846. log.info("【屏蔽】新手引导");
  1847. CSDNUtils.addBlockCSS('.csdn-side-toolbar a.option-box[data-type="guide"]');
  1848. },
  1849. /**
  1850. * 【屏蔽】客服
  1851. */
  1852. shieldCustomerService() {
  1853. log.info("【屏蔽】客服");
  1854. CSDNUtils.addBlockCSS('.csdn-side-toolbar a.option-box[data-type="cs"]');
  1855. },
  1856. /**
  1857. * 【屏蔽】举报
  1858. */
  1859. shieldReport() {
  1860. log.info("【屏蔽】举报");
  1861. CSDNUtils.addBlockCSS(
  1862. '.csdn-side-toolbar a.option-box[data-type="report"]'
  1863. );
  1864. },
  1865. /**
  1866. * 【屏蔽】返回顶部
  1867. */
  1868. shieldBackToTop() {
  1869. log.info("【屏蔽】返回顶部");
  1870. CSDNUtils.addBlockCSS('.csdn-side-toolbar a.option-box[data-type="gotop"]');
  1871. }
  1872. };
  1873. const CSDNBlog = {
  1874. init() {
  1875. this.addCSS();
  1876. CSDNBlogRightToolBar.init();
  1877. PopsPanel.execMenu("csdn-blog-articleCenter", () => {
  1878. this.articleCenter();
  1879. });
  1880. PopsPanel.execMenu("csdn-blog-shieldLoginDialog", () => {
  1881. this.shieldLoginDialog();
  1882. });
  1883. PopsPanel.execMenu("csdn-blog-autoExpandContent", () => {
  1884. this.autoExpandContent();
  1885. });
  1886. PopsPanel.execMenu("csdn-blog-autoExpandCodeContent", () => {
  1887. this.autoExpandCodeContent();
  1888. });
  1889. if (!PopsPanel.getValue("csdn-blog-comment-enable")) {
  1890. this.blockComment();
  1891. }
  1892. if (!PopsPanel.getValue("csdn-blog-bottomRecommendArticleEnable")) {
  1893. this.shieldBottomRecommendArticle();
  1894. }
  1895. PopsPanel.execMenu("csdn-blog-shieldBottomSkillTree", () => {
  1896. this.shieldBottomSkillTree();
  1897. });
  1898. PopsPanel.execMenu("csdn-blog-shieldBottomFloatingToolbar", () => {
  1899. this.shieldBottomFloatingToolbar();
  1900. });
  1901. PopsPanel.execMenu("csdn-blog-shieldLeftBlogContainerAside", () => {
  1902. this.shieldLeftBlogContainerAside();
  1903. });
  1904. PopsPanel.execMenu("csdn-blog-shieldRightDirectoryInformation", () => {
  1905. this.shieldRightDirectoryInformation();
  1906. });
  1907. PopsPanel.execMenu("csdn-blog-shieldTopToolbar", () => {
  1908. this.shieldTopToolbar();
  1909. });
  1910. PopsPanel.execMenu("csdn-blog-shieldArticleSearchTip", () => {
  1911. this.shieldArticleSearchTip();
  1912. });
  1913. PopsPanel.execMenu("csdn-blog-allowSelectContent", () => {
  1914. this.allowSelectContent();
  1915. });
  1916. domutils.ready(() => {
  1917. PopsPanel.execMenu("csdn-blog-removeClipboardHijacking", () => {
  1918. this.removeClipboardHijacking();
  1919. });
  1920. PopsPanel.execMenuOnce("csdn-blog-unBlockCopy", () => {
  1921. this.unBlockCopy();
  1922. });
  1923. PopsPanel.execMenu("csdn-blog-identityCSDNDownload", () => {
  1924. this.identityCSDNDownload();
  1925. });
  1926. PopsPanel.execMenuOnce("csdn-blog-clickPreCodeAutomatically", () => {
  1927. this.clickPreCodeAutomatically();
  1928. });
  1929. PopsPanel.execMenu("csdn-blog-restoreComments", () => {
  1930. this.restoreComments();
  1931. });
  1932. });
  1933. },
  1934. /**
  1935. * 添加屏蔽CSS和功能CSS
  1936. */
  1937. addCSS() {
  1938. log.info("添加屏蔽CSS和功能CSS");
  1939. addStyle(BlogShieldCSS);
  1940. addStyle(BlogCSS);
  1941. },
  1942. /**
  1943. * 去除剪贴板劫持
  1944. */
  1945. removeClipboardHijacking() {
  1946. var _a2;
  1947. log.info("去除剪贴板劫持");
  1948. (_a2 = document.querySelector(".article-copyright")) == null ? void 0 : _a2.remove();
  1949. if (_unsafeWindow.articleType) {
  1950. _unsafeWindow.articleType = 0;
  1951. }
  1952. if (_unsafeWindow.csdn && _unsafeWindow.csdn.copyright && _unsafeWindow.csdn.copyright.textData) {
  1953. _unsafeWindow.csdn.copyright.textData = "";
  1954. }
  1955. if (_unsafeWindow.csdn && _unsafeWindow.csdn.copyright && _unsafeWindow.csdn.copyright.htmlData) {
  1956. _unsafeWindow.csdn.copyright.htmlData = "";
  1957. }
  1958. },
  1959. /**
  1960. * 取消禁止复制
  1961. */
  1962. unBlockCopy() {
  1963. log.info("取消禁止复制");
  1964. domutils.on(
  1965. document,
  1966. "click",
  1967. function(event) {
  1968. let $click = event.target;
  1969. let $parent = $click.parentElement;
  1970. if (!$click.classList.contains("hljs-button")) {
  1971. return;
  1972. }
  1973. utils.preventEvent(event);
  1974. let copyText = ($parent.innerText || $parent.textContent || "").toString();
  1975. log.info(
  1976. "点击复制按钮复制内容:" + (copyText.length > 8 ? copyText.substring(0, 8) + "..." : copyText)
  1977. );
  1978. utils.setClip(copyText);
  1979. $click.setAttribute("data-title", "复制成功");
  1980. },
  1981. {
  1982. capture: true
  1983. }
  1984. );
  1985. let changeDataTitle = new utils.LockFunction(function(event) {
  1986. let $mouse = event.target;
  1987. if ($mouse.localName !== "pre") {
  1988. return;
  1989. }
  1990. let $hljsBtn = $mouse.querySelector(".hljs-button");
  1991. if ($hljsBtn) {
  1992. $hljsBtn.setAttribute("data-title", "复制");
  1993. }
  1994. });
  1995. domutils.on(
  1996. document,
  1997. ["mouseenter", "mouseleave"],
  1998. function(event) {
  1999. changeDataTitle.run(event);
  2000. },
  2001. {
  2002. capture: true
  2003. }
  2004. );
  2005. utils.waitNode("#content_views").then(($content_views) => {
  2006. var _a2;
  2007. if (_unsafeWindow.$) {
  2008. (_a2 = _unsafeWindow.$("#content_views")) == null ? void 0 : _a2.unbind("copy");
  2009. }
  2010. domutils.on(
  2011. $content_views,
  2012. "copy",
  2013. function(event) {
  2014. utils.preventEvent(event);
  2015. let selectText = _unsafeWindow.getSelection();
  2016. let copyText = selectText == null ? void 0 : selectText.toString();
  2017. log.info(
  2018. "Ctrl+C复制内容:" + (copyText.length > 8 ? copyText.substring(0, 8) + "..." : copyText)
  2019. );
  2020. utils.setClip(copyText);
  2021. return false;
  2022. },
  2023. {
  2024. capture: true
  2025. }
  2026. );
  2027. });
  2028. utils.waitNode(".hljs-button").then(() => {
  2029. setTimeout(() => {
  2030. document.querySelectorAll(".hljs-button").forEach((element) => {
  2031. element.removeAttribute("onclick");
  2032. element.removeAttribute("data-report-click");
  2033. element.setAttribute("data-title", "复制");
  2034. });
  2035. }, 250);
  2036. });
  2037. },
  2038. /**
  2039. * 点击代码块自动展开
  2040. */
  2041. clickPreCodeAutomatically() {
  2042. log.info("点击代码块自动展开");
  2043. document.addEventListener("click", function(event) {
  2044. var _a2;
  2045. let $click = event.target;
  2046. if ($click.localName !== "pre") {
  2047. return;
  2048. }
  2049. $click.style.setProperty("height", "auto");
  2050. (_a2 = $click.querySelector(".hide-preCode-box")) == null ? void 0 : _a2.remove();
  2051. });
  2052. },
  2053. /**
  2054. * 恢复评论到正确位置
  2055. */
  2056. restoreComments() {
  2057. log.info("恢复评论到正确位置-第一条评论");
  2058. utils.waitNode(".first-recommend-box").then(($firstRecommendBox) => {
  2059. let recommendBoxElement = document.querySelector(
  2060. ".recommend-box.insert-baidu-box.recommend-box-style"
  2061. );
  2062. recommendBoxElement.insertBefore(
  2063. $firstRecommendBox,
  2064. recommendBoxElement.firstChild
  2065. );
  2066. });
  2067. log.info("恢复评论到正确位置-第二条评论");
  2068. utils.waitNode(".second-recommend-box").then(($secondRecommendBox) => {
  2069. let recommendBoxElement = document.querySelector(
  2070. ".recommend-box.insert-baidu-box.recommend-box-style"
  2071. );
  2072. recommendBoxElement.insertBefore(
  2073. $secondRecommendBox,
  2074. recommendBoxElement.firstChild
  2075. );
  2076. });
  2077. },
  2078. /**
  2079. * 标识CSDN下载的链接
  2080. */
  2081. identityCSDNDownload() {
  2082. log.info("标识CSDN下载的链接");
  2083. document.querySelectorAll(
  2084. ".recommend-item-box[data-url*='https://download.csdn.net/']"
  2085. ).forEach((item) => {
  2086. if (PopsPanel.getValue("csdn-blog-removeResourceDownloadArticle")) {
  2087. item.remove();
  2088. } else {
  2089. item.querySelector(".content-box").style.setProperty("border", "2px solid red");
  2090. }
  2091. });
  2092. },
  2093. /**
  2094. * 全文居中
  2095. */
  2096. articleCenter() {
  2097. log.info("全文居中");
  2098. addStyle(BlogArticleCenterCSS);
  2099. },
  2100. /**
  2101. * 屏蔽登录弹窗
  2102. */
  2103. shieldLoginDialog() {
  2104. log.info("屏蔽登录弹窗");
  2105. CSDNUtils.addBlockCSS(`.passport-login-container`);
  2106. },
  2107. /**
  2108. * 自动展开代码块
  2109. */
  2110. autoExpandCodeContent() {
  2111. log.info("自动展开代码块");
  2112. CSDNUtils.addBlockCSS("pre.set-code-hide .hide-preCode-box");
  2113. addStyle(`
  2114. pre.set-code-hide{
  2115. height: auto !important;
  2116. }
  2117. /* 自动展开代码块 */
  2118. .comment-list-box,
  2119. main div.blog-content-box pre {
  2120. max-height: none !important;
  2121. }
  2122. `);
  2123. },
  2124. /**
  2125. * 自动展开全文
  2126. */
  2127. autoExpandContent() {
  2128. log.info("自动展开全文");
  2129. addStyle(`
  2130. /* 自动展开全文 */
  2131. #article_content,
  2132. .user-article.user-article-hide {
  2133. height: auto !important;
  2134. overflow: auto !important;
  2135. }
  2136. `);
  2137. },
  2138. /**
  2139. * 屏蔽评论区
  2140. */
  2141. blockComment() {
  2142. log.info("屏蔽评论区");
  2143. CSDNUtils.addBlockCSS(`#pcCommentBox`);
  2144. },
  2145. /**
  2146. * 屏蔽底部推荐文章
  2147. */
  2148. shieldBottomRecommendArticle() {
  2149. log.info("屏蔽底部推荐文章");
  2150. CSDNUtils.addBlockCSS(`main > div.recommend-box`);
  2151. },
  2152. /**
  2153. * 屏蔽底部xx技能树
  2154. */
  2155. shieldBottomSkillTree() {
  2156. log.info("屏蔽底部xx技能树");
  2157. CSDNUtils.addBlockCSS(`#treeSkill`);
  2158. },
  2159. /**
  2160. * 屏蔽底部悬浮工具栏
  2161. */
  2162. shieldBottomFloatingToolbar() {
  2163. log.info("屏蔽底部悬浮工具栏");
  2164. CSDNUtils.addBlockCSS(`#toolBarBox`);
  2165. },
  2166. /**
  2167. * 屏蔽左侧博客信息
  2168. */
  2169. shieldLeftBlogContainerAside() {
  2170. log.info("【屏蔽】左侧博客信息");
  2171. CSDNUtils.addBlockCSS(`aside.blog_container_aside`);
  2172. },
  2173. /**
  2174. * 【屏蔽】右侧目录信息
  2175. */
  2176. shieldRightDirectoryInformation() {
  2177. log.info("【屏蔽】右侧目录信息");
  2178. CSDNUtils.addBlockCSS("#rightAsideConcision", "#rightAside");
  2179. },
  2180. /**
  2181. * 屏蔽顶部Toolbar
  2182. */
  2183. shieldTopToolbar() {
  2184. log.info("屏蔽顶部Toolbar");
  2185. CSDNUtils.addBlockCSS(`#toolbarBox`);
  2186. },
  2187. /**
  2188. * 屏蔽文章内的选中搜索悬浮提示
  2189. */
  2190. shieldArticleSearchTip() {
  2191. log.info("屏蔽文章内的选中搜索悬浮提示");
  2192. CSDNUtils.addBlockCSS(`#articleSearchTip`);
  2193. },
  2194. /**
  2195. * 允许选择内容
  2196. */
  2197. allowSelectContent() {
  2198. log.info("允许选择内容");
  2199. addStyle(`
  2200. #content_views,
  2201. #content_views pre,
  2202. #content_views pre code {
  2203. user-select: text !important;
  2204. }
  2205. `);
  2206. }
  2207. };
  2208. const WenkuCSS = "#chatgpt-article-detail\r\n > div.layout-center\r\n > div.main\r\n > div.article-box\r\n > div.cont.first-show.forbid {\r\n max-height: unset !important;\r\n height: auto !important;\r\n overflow: auto !important;\r\n}\r\n\r\n.forbid {\r\n user-select: text !important;\r\n}\r\n";
  2209. const ShieldCSS$3 = "/* wenku顶部横幅 */\r\n#app > div > div.main.pb-32 > div > div.top-bar,\r\n/* 底部展开全文 */\r\n#chatgpt-article-detail > div.layout-center > div.main > div.article-box > div.cont.first-show.forbid > div.open {\r\n display: none !important;\r\n}";
  2210. const CSDNWenKu = {
  2211. init() {
  2212. addStyle(WenkuCSS);
  2213. addStyle(ShieldCSS$3);
  2214. PopsPanel.execMenu("csdn-wenku-shieldResourceRecommend", () => {
  2215. this.shieldResourceRecommend();
  2216. });
  2217. PopsPanel.execMenu("csdn-wenku-shieldRightUserInfo", () => {
  2218. this.shieldRightUserInfo();
  2219. });
  2220. PopsPanel.execMenu("csdn-wenku-shieldRightToolBar", () => {
  2221. this.shieldRightToolBar();
  2222. });
  2223. },
  2224. /**
  2225. * 【屏蔽】资源推荐
  2226. */
  2227. shieldResourceRecommend() {
  2228. log.info("【屏蔽】资源推荐");
  2229. CSDNUtils.addBlockCSS("#recommend");
  2230. },
  2231. /**
  2232. * 【屏蔽】右侧用户信息
  2233. */
  2234. shieldRightUserInfo() {
  2235. log.info("【屏蔽】右侧用户信息");
  2236. CSDNUtils.addBlockCSS(".layout-right");
  2237. },
  2238. /**
  2239. * 【屏蔽】右侧悬浮工具栏
  2240. */
  2241. shieldRightToolBar() {
  2242. log.info("【屏蔽】右侧悬浮工具栏");
  2243. CSDNUtils.addBlockCSS(".csdn-side-toolbar");
  2244. }
  2245. };
  2246. const CSDNLink = {
  2247. init() {
  2248. PopsPanel.execMenu("csdn-link-jumpRedirect", () => {
  2249. this.jumpRedirect();
  2250. });
  2251. },
  2252. /**
  2253. * 去除CSDN拦截其它网址的url并自动跳转
  2254. */
  2255. jumpRedirect() {
  2256. if (window.location.hostname === "link.csdn.net" && window.location.search.startsWith("?target")) {
  2257. window.stop();
  2258. let search = window.location.search.replace(/^\?target=/gi, "");
  2259. search = decodeURIComponent(search);
  2260. let newURL = search;
  2261. log.success(`跳转链接 ${newURL}`);
  2262. window.location.href = newURL;
  2263. }
  2264. }
  2265. };
  2266. const CSDN = {
  2267. init() {
  2268. if (CSDNRouter.isLink()) {
  2269. log.info("Router: 中转链接");
  2270. CSDNLink.init();
  2271. } else if (CSDNRouter.isHuaWeiCloudBlog()) {
  2272. log.info("Router: 华为云联盟");
  2273. CSDNHuaWeiCloud.init();
  2274. } else if (CSDNRouter.isBlog()) {
  2275. log.info("Router: 博客");
  2276. CSDNBlog.init();
  2277. } else if (CSDNRouter.isWenKu()) {
  2278. log.info("Router: 文库");
  2279. CSDNWenKu.init();
  2280. } else {
  2281. log.error("暂未适配,请反馈开发者:" + globalThis.location.href);
  2282. }
  2283. }
  2284. };
  2285. const M_CSDNLink = {
  2286. init() {
  2287. PopsPanel.execMenu("m-csdn-link-jumpRedirect", () => {
  2288. CSDNLink.jumpRedirect();
  2289. });
  2290. }
  2291. };
  2292. const ShieldCSS$2 = "/* 右下角的 免费赢华为平板xxxx */\r\n.org-main-content .siderbar-box {\r\n display: none !important;\r\n}\r\n";
  2293. const M_CSDNHuaWeiCloud = {
  2294. init() {
  2295. addStyle(ShieldCSS$2);
  2296. PopsPanel.execMenu("m-csdn-hua-wei-cloud-autoExpandContent", () => {
  2297. CSDNHuaWeiCloud.autoExpandContent();
  2298. });
  2299. }
  2300. };
  2301. const ShieldCSS$1 = "#operate,.feed-Sign-span,\r\n.view_comment_box,\r\n.weixin-shadowbox.wap-shadowbox,\r\n.feed-Sign-span,\r\n.user-desc.user-desc-fix,\r\n.comment_read_more_box,\r\n#content_views pre.set-code-hide .hide-preCode-box,\r\n/* 登录弹窗 */\r\n.passport-login-container,\r\n.hljs-button[data-title='登录后复制'],\r\n.article-show-more,\r\n#treeSkill,\r\ndiv.btn_open_app_prompt_div,\r\ndiv.readall_box,\r\ndiv.aside-header-fixed,\r\ndiv.feed-Sign-weixin,\r\ndiv.ios-shadowbox {\r\n display: none !important;\r\n}\r\n";
  2302. const MBlogCSS = "#mainBox {\r\n width: auto;\r\n}\r\n.user-desc.user-desc-fix {\r\n height: auto !important;\r\n overflow: auto !important;\r\n}\r\n.component-box .praise {\r\n background: #ff5722;\r\n border-radius: 5px;\r\n padding: 0px 8px;\r\n height: auto;\r\n}\r\n.component-box .praise,\r\n.component-box .share {\r\n color: #fff;\r\n}\r\n.component-box a {\r\n display: inline-block;\r\n font-size: xx-small;\r\n}\r\n.component-box {\r\n display: inline;\r\n margin: 0;\r\n position: relative;\r\n white-space: nowrap;\r\n}\r\n.csdn-edu-title {\r\n background: #4d6de1;\r\n border-radius: 5px;\r\n padding: 0px 8px;\r\n height: auto;\r\n color: #fff !important;\r\n}\r\n\r\n.GM-csdn-dl {\r\n padding: 0.24rem 0.32rem;\r\n width: 100%;\r\n justify-content: space-between;\r\n -webkit-box-pack: justify;\r\n border-bottom: 1px solid #f5f6f7 !important;\r\n}\r\n.GM-csdn-title {\r\n font-size: 0.3rem;\r\n color: #222226;\r\n letter-spacing: 0;\r\n line-height: 0.44rem;\r\n font-weight: 600;\r\n /*max-height: .88rem;*/\r\n word-break: break-all;\r\n overflow: hidden;\r\n display: -webkit-box;\r\n -webkit-box-orient: vertical;\r\n -webkit-line-clamp: 2;\r\n}\r\n.GM-csdn-title a {\r\n word-break: break-all;\r\n color: #222226;\r\n font-weight: 600;\r\n}\r\n.GM-csdn-title em,\r\n.GM-csdn-content em {\r\n font-style: normal;\r\n color: #fc5531;\r\n}\r\n.GM-csdn-content {\r\n /*max-width: 5.58rem;*/\r\n overflow: hidden;\r\n text-overflow: ellipsis;\r\n display: -webkit-box;\r\n -webkit-line-clamp: 1;\r\n -webkit-box-orient: vertical;\r\n color: #555666;\r\n font-size: 0.24rem;\r\n line-height: 0.34rem;\r\n max-height: 0.34rem;\r\n word-break: break-all;\r\n -webkit-box-flex: 1;\r\n -ms-flex: 1;\r\n flex: 1;\r\n margin-top: 0.16rem;\r\n}\r\n.GM-csdn-img img {\r\n width: 2.18rem;\r\n height: 1.58rem;\r\n /*margin-left: .16rem*/\r\n}\r\n";
  2303. const M_CSDNBlog = {
  2304. init() {
  2305. this.addCSS();
  2306. PopsPanel.execMenu("m-csdn-blog-shieldTopToolbar", () => {
  2307. this.shieldTopToolbar();
  2308. });
  2309. PopsPanel.execMenu("m-csdn-blog-notLimitCodePreMaxHeight", () => {
  2310. this.notLimitCodePreMaxHeight();
  2311. });
  2312. PopsPanel.execMenu("m-csdn-blog-notLimitCommentMaxHeight", () => {
  2313. this.notLimitCommentMaxHeight();
  2314. });
  2315. PopsPanel.execMenu("m-csdn-blog-allowSelectText", () => {
  2316. this.allowSelectText();
  2317. });
  2318. PopsPanel.execMenu("m-csdn-blog-autoExpandContent", () => {
  2319. this.autoExpandContent();
  2320. });
  2321. if (!PopsPanel.getValue("m-csdn-blog-bottomArticleEnable")) {
  2322. this.blockBottomArticle();
  2323. }
  2324. if (!PopsPanel.getValue("m-csdn-blog-comment-enable")) {
  2325. this.blockComment();
  2326. }
  2327. domutils.ready(() => {
  2328. PopsPanel.execMenu("m-csdn-blog-removeAds", () => {
  2329. this.removeAds();
  2330. });
  2331. PopsPanel.execMenu("m-csdn-blog-refactoringRecommendation", () => {
  2332. this.refactoringRecommendation();
  2333. });
  2334. PopsPanel.execMenu("m-csdn-blog-unBlockCopy", () => {
  2335. CSDNBlog.unBlockCopy();
  2336. });
  2337. });
  2338. },
  2339. addCSS() {
  2340. addStyle(ShieldCSS$1);
  2341. addStyle(MBlogCSS);
  2342. },
  2343. /**
  2344. * 屏蔽顶部Toolbar
  2345. */
  2346. shieldTopToolbar() {
  2347. log.info("屏蔽顶部Toolbar");
  2348. CSDNUtils.addBlockCSS("#csdn-toolbar");
  2349. addStyle(`
  2350. /* 内容顶部要归位 */
  2351. body #main,
  2352. .margin_sides{
  2353. margin-top: unset !important;
  2354. padding-top: unset !important;
  2355. }
  2356. #article .article_title{
  2357. margin-top: .32rem !important;
  2358. padding-top: unset !important;
  2359. }
  2360. `);
  2361. },
  2362. /**
  2363. * 重构底部推荐
  2364. */
  2365. refactoringRecommendation() {
  2366. function refactoring() {
  2367. log.info("重构底部推荐");
  2368. document.querySelectorAll(
  2369. ".container-fluid"
  2370. ).forEach((item) => {
  2371. var _a2, _b;
  2372. let url = "";
  2373. let title = "";
  2374. let content = "";
  2375. let img = "";
  2376. let isCSDNDownload = false;
  2377. let isCSDNEduDownload = false;
  2378. if (item.hasAttribute("data-url")) {
  2379. url = item.getAttribute("data-url");
  2380. title = (_a2 = item.querySelector(".recommend_title div.left")) == null ? void 0 : _a2.innerHTML;
  2381. if (!item.querySelector(".text")) {
  2382. return;
  2383. }
  2384. content = (_b = item.querySelector(".text")) == null ? void 0 : _b.innerHTML;
  2385. if (item.querySelectorAll(".recommend-img").length) {
  2386. item.querySelectorAll(".recommend-img").forEach((item2) => {
  2387. img += item2.innerHTML;
  2388. });
  2389. }
  2390. } else {
  2391. log.info("节点上无data-url");
  2392. url = item.querySelector("a[data-type]").getAttribute("href");
  2393. title = item.querySelector(".recommend_title div.left").innerHTML;
  2394. content = item.querySelector(".text").innerHTML;
  2395. }
  2396. var _URL_ = new URL(url);
  2397. if (_URL_.host === "download.csdn.net" || _URL_.host === "www.iteye.com" && _URL_.pathname.match(/^\/resource/gi)) {
  2398. log.info("该链接为csdn资源下载");
  2399. isCSDNDownload = true;
  2400. title = `<div class="component-box"><a class="praise" href="javascript:;">CSDN下载</a></div>` + title;
  2401. } else if (_URL_.origin.match(/edu.csdn.net/gi)) {
  2402. isCSDNEduDownload = true;
  2403. log.info("该链接为csdn学院下载");
  2404. title = `<div class="component-box"><a class="csdn-edu-title" href="javascript:;">CSDN学院</a></div>` + title;
  2405. }
  2406. item.setAttribute("class", "GM-csdn-dl");
  2407. item.setAttribute("data-url", url);
  2408. item.innerHTML = `<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>`;
  2409. item.addEventListener("click", function() {
  2410. if (PopsPanel.getValue("m-csdn-blog-openNewTab")) {
  2411. window.open(url, "_blank");
  2412. } else {
  2413. window.location.href = url;
  2414. }
  2415. });
  2416. if ((isCSDNDownload || isCSDNEduDownload) && PopsPanel.getValue("m-csdn-blog-removeResourceArticle")) {
  2417. item.remove();
  2418. }
  2419. });
  2420. }
  2421. let lockFunction = new utils.LockFunction(refactoring, 50);
  2422. utils.waitNode("#recommend").then(($recommend) => {
  2423. log.info("重构底部推荐");
  2424. lockFunction.run();
  2425. utils.mutationObserver($recommend, {
  2426. callback: () => {
  2427. lockFunction.run();
  2428. },
  2429. config: { childList: true, subtree: true, attributes: true }
  2430. });
  2431. });
  2432. },
  2433. /**
  2434. * 屏蔽底部文章
  2435. */
  2436. blockBottomArticle() {
  2437. log.info("屏蔽底部文章");
  2438. CSDNUtils.addBlockCSS("#recommend");
  2439. },
  2440. /**
  2441. * 屏蔽评论
  2442. */
  2443. blockComment() {
  2444. log.info("屏蔽评论");
  2445. CSDNUtils.addBlockCSS("#comment");
  2446. },
  2447. /**
  2448. * 去除广告
  2449. */
  2450. removeAds() {
  2451. log.info("去除广告");
  2452. CSDNUtils.waitForElementToRemove(".passport-login-container");
  2453. CSDNUtils.waitForElementToRemove(
  2454. ".btn_open_app_prompt_box.detail-open-removed"
  2455. );
  2456. CSDNUtils.waitForElementToRemove(".add-firstAd");
  2457. CSDNUtils.waitForElementToRemove("div.feed-Sign-weixin");
  2458. CSDNUtils.waitForElementToRemove("div.ios-shadowbox");
  2459. },
  2460. /**
  2461. * 不限制代码块最大高度
  2462. */
  2463. notLimitCodePreMaxHeight() {
  2464. log.info("不限制代码块最大高度");
  2465. addStyle(`
  2466. pre{
  2467. max-height: unset !important;
  2468. }
  2469. `);
  2470. },
  2471. /**
  2472. * 不限制评论区最大高度
  2473. */
  2474. notLimitCommentMaxHeight() {
  2475. log.info("不限制评论区最大高度");
  2476. addStyle(`
  2477. #comment{
  2478. max-height: none !important;
  2479. }
  2480. `);
  2481. },
  2482. /**
  2483. * 允许选择文字
  2484. */
  2485. allowSelectText() {
  2486. log.info("允许选择文字");
  2487. addStyle(`
  2488. #content_views,
  2489. #content_views pre,
  2490. #content_views pre code{
  2491. webkit-touch-callout: text !important;
  2492. -webkit-user-select: text !important;
  2493. -khtml-user-select: text !important;
  2494. -moz-user-select: text !important;
  2495. -ms-user-select: text !important;
  2496. user-select: text !important;
  2497. }
  2498. `);
  2499. },
  2500. /**
  2501. * 自动展开内容
  2502. */
  2503. autoExpandContent() {
  2504. log.info("自动展开内容");
  2505. addStyle(`
  2506. #content_views pre.set-code-hide,
  2507. .article_content{
  2508. height: 100% !important;
  2509. overflow: auto !important;
  2510. }
  2511. `);
  2512. }
  2513. };
  2514. const ShieldCSS = "/* 右下角的买一年送3个月的广告图标 */\r\n.blind_box {\r\n display: none !important;\r\n}\r\n";
  2515. const M_CSDNWenKu = {
  2516. init() {
  2517. addStyle(ShieldCSS);
  2518. PopsPanel.execMenu("m-csdn-wenku-shieldBottomToolbar", () => {
  2519. this.shieldBottomToolbar();
  2520. });
  2521. },
  2522. /**
  2523. * 【屏蔽】底部工具栏
  2524. */
  2525. shieldBottomToolbar() {
  2526. log.info("【屏蔽】底部工具栏");
  2527. CSDNUtils.addBlockCSS(`.page-container > div.btn`);
  2528. }
  2529. };
  2530. const CSDNBlockCSS = "/* 右下角悬浮图标 买1年送3个月 */\r\n.page-container .blind_box,\r\n/* 底部工具栏右边的 开会员按钮(低至xx元/次) */\r\n.page-container .btn .ml-12,\r\n/* 登录弹窗 */\r\n.passport-login-container,\r\n/* 通用广告className匹配 */\r\n.ads {\r\n display: none !important;\r\n}\r\n";
  2531. const M_CSDNDownload = {
  2532. init() {
  2533. PopsPanel.execMenu("m-csdn-download-removeAds", () => {
  2534. addStyle(CSDNBlockCSS);
  2535. });
  2536. PopsPanel.execMenuOnce(
  2537. "m-csdn-download-automaticallyExpandResourceIntroduction",
  2538. () => {
  2539. this.automaticallyExpandResourceIntroduction();
  2540. }
  2541. );
  2542. },
  2543. /**
  2544. * 自动展开资源介绍
  2545. */
  2546. automaticallyExpandResourceIntroduction() {
  2547. log.info("自动展开资源介绍");
  2548. CSDNUtils.addBlockCSS("label.unfold-font");
  2549. addStyle(`
  2550. .resource-desc{
  2551. max-height: unset !important;
  2552. overflow: unset !important;
  2553. }
  2554. `);
  2555. }
  2556. };
  2557. const M_CSDN = {
  2558. init() {
  2559. if (CSDNRouter.isLink()) {
  2560. log.info("Router: 中转链接");
  2561. M_CSDNLink.init();
  2562. } else if (CSDNRouter.isHuaWeiCloudBlog()) {
  2563. log.info("Router: 华为云联盟");
  2564. M_CSDNHuaWeiCloud.init();
  2565. } else if (CSDNRouter.isBlog()) {
  2566. log.info("Router: 博客");
  2567. M_CSDNBlog.init();
  2568. } else if (CSDNRouter.isWenKu()) {
  2569. log.info("Router: 文库");
  2570. M_CSDNWenKu.init();
  2571. } else if (CSDNRouter.isDownload()) {
  2572. log.info("Router: 资源下载");
  2573. M_CSDNDownload.init();
  2574. } else {
  2575. log.error("暂未适配,请反馈开发者:" + globalThis.location.href);
  2576. }
  2577. }
  2578. };
  2579. PopsPanel.init();
  2580. let isMobile = utils.isPhone();
  2581. let CHANGE_ENV_SET_KEY = "change_env_set";
  2582. let chooseMode = _GM_getValue(CHANGE_ENV_SET_KEY);
  2583. GM_Menu.add({
  2584. key: CHANGE_ENV_SET_KEY,
  2585. text: `⚙ 自动: ${isMobile ? "移动端" : "PC端"}`,
  2586. autoReload: false,
  2587. isStoreValue: false,
  2588. showText(text) {
  2589. if (chooseMode == null) {
  2590. return text;
  2591. }
  2592. return text + ` 手动: ${chooseMode == 1 ? "移动端" : chooseMode == 2 ? "PC端" : "未知"}`;
  2593. },
  2594. callback: () => {
  2595. let allowValue = [0, 1, 2];
  2596. let chooseText = window.prompt(
  2597. "请输入当前脚本环境判定\n\n自动判断: 0\n移动端: 1\nPC端: 2",
  2598. "0"
  2599. );
  2600. if (!chooseText) {
  2601. return;
  2602. }
  2603. let chooseMode2 = parseInt(chooseText);
  2604. if (isNaN(chooseMode2)) {
  2605. Qmsg.error("输入的不是规范的数字");
  2606. return;
  2607. }
  2608. if (!allowValue.includes(chooseMode2)) {
  2609. Qmsg.error("输入的值必须是0或1或2");
  2610. return;
  2611. }
  2612. if (chooseMode2 == 0) {
  2613. _GM_deleteValue(CHANGE_ENV_SET_KEY);
  2614. } else {
  2615. _GM_setValue(CHANGE_ENV_SET_KEY, chooseMode2);
  2616. }
  2617. }
  2618. });
  2619. if (chooseMode != null) {
  2620. log.info(`手动判定为${chooseMode === 1 ? "移动端" : "PC端"}`);
  2621. if (chooseMode == 1) {
  2622. M_CSDN.init();
  2623. } else if (chooseMode == 2) {
  2624. CSDN.init();
  2625. } else {
  2626. Qmsg.error("意外,手动判定的值不在范围内");
  2627. _GM_deleteValue(CHANGE_ENV_SET_KEY);
  2628. }
  2629. } else {
  2630. if (isMobile) {
  2631. log.info("自动判定为移动端");
  2632. M_CSDN.init();
  2633. } else {
  2634. log.info("自动判定为PC端");
  2635. CSDN.init();
  2636. }
  2637. }
  2638.  
  2639. })(Qmsg, DOMUtils, Utils);