CSDN优化

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

  1. // ==UserScript==
  2. // @name CSDN优化
  3. // @namespace https://github.com/WhiteSevs/TamperMonkeyScript
  4. // @version 2025.4.5
  5. // @author WhiteSevs
  6. // @description 支持PC和手机端、屏蔽广告、优化浏览体验、重定向拦截的Url、自动展开全文、自动展开代码块、全文居中、允许复制内容、去除复制内容的小尾巴、自定义屏蔽元素等
  7. // @license GPL-3.0-only
  8. // @icon data:image/png;base64,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
  9. // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues
  10. // @match *://*.csdn.net/*
  11. // @require https://fastly.jsdelivr.net/gh/WhiteSevs/TamperMonkeyScript@86be74b83fca4fa47521cded28377b35e1d7d2ac/lib/CoverUMD/index.js
  12. // @require https://fastly.jsdelivr.net/npm/@whitesev/utils@2.6.4/dist/index.umd.js
  13. // @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.5.1/dist/index.umd.js
  14. // @require https://fastly.jsdelivr.net/npm/@whitesev/pops@2.0.2/dist/index.umd.js
  15. // @require https://fastly.jsdelivr.net/npm/qmsg@1.3.0/dist/index.umd.js
  16. // @connect blog.csdn.net
  17. // @connect mp-action.csdn.net
  18. // @grant GM_deleteValue
  19. // @grant GM_getResourceText
  20. // @grant GM_getValue
  21. // @grant GM_info
  22. // @grant GM_registerMenuCommand
  23. // @grant GM_setValue
  24. // @grant GM_unregisterMenuCommand
  25. // @grant GM_xmlhttpRequest
  26. // @grant unsafeWindow
  27. // @run-at document-start
  28. // ==/UserScript==
  29.  
  30. (function (Qmsg, DOMUtils, Utils, pops) {
  31. 'use strict';
  32.  
  33. var _a;
  34. var _GM_deleteValue = /* @__PURE__ */ (() => typeof GM_deleteValue != "undefined" ? GM_deleteValue : void 0)();
  35. var _GM_getResourceText = /* @__PURE__ */ (() => typeof GM_getResourceText != "undefined" ? GM_getResourceText : void 0)();
  36. var _GM_getValue = /* @__PURE__ */ (() => typeof GM_getValue != "undefined" ? GM_getValue : void 0)();
  37. var _GM_info = /* @__PURE__ */ (() => typeof GM_info != "undefined" ? GM_info : void 0)();
  38. var _GM_registerMenuCommand = /* @__PURE__ */ (() => typeof GM_registerMenuCommand != "undefined" ? GM_registerMenuCommand : void 0)();
  39. var _GM_setValue = /* @__PURE__ */ (() => typeof GM_setValue != "undefined" ? GM_setValue : void 0)();
  40. var _GM_unregisterMenuCommand = /* @__PURE__ */ (() => typeof GM_unregisterMenuCommand != "undefined" ? GM_unregisterMenuCommand : void 0)();
  41. var _GM_xmlhttpRequest = /* @__PURE__ */ (() => typeof GM_xmlhttpRequest != "undefined" ? GM_xmlhttpRequest : void 0)();
  42. var _unsafeWindow = /* @__PURE__ */ (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)();
  43. var _monkeyWindow = /* @__PURE__ */ (() => window)();
  44. const CommonUtil = {
  45. /**
  46. * 移除元素(未出现也可以等待出现)
  47. * @param selector 元素选择器
  48. */
  49. waitRemove(...args) {
  50. args.forEach((selector) => {
  51. utils.waitNodeList(selector).then((nodeList) => {
  52. nodeList.forEach((item) => item.remove());
  53. });
  54. });
  55. },
  56. /**
  57. * 添加屏蔽CSS
  58. * @param args
  59. * @example
  60. * addBlockCSS("")
  61. * addBlockCSS("","")
  62. * addBlockCSS(["",""])
  63. */
  64. addBlockCSS(...args) {
  65. let selectorList = [];
  66. if (args.length === 0) {
  67. return;
  68. }
  69. if (args.length === 1 && typeof args[0] === "string" && args[0].trim() === "") {
  70. return;
  71. }
  72. args.forEach((selector) => {
  73. if (Array.isArray(selector)) {
  74. selectorList = selectorList.concat(selector);
  75. } else {
  76. selectorList.push(selector);
  77. }
  78. });
  79. return addStyle(`${selectorList.join(",\n")}{display: none !important;}`);
  80. },
  81. /**
  82. * 设置GM_getResourceText的style内容
  83. * @param resourceMapData 资源数据
  84. * @example
  85. * setGMResourceCSS({
  86. * keyName: "ViewerCSS",
  87. * url: "https://example.com/example.css",
  88. * })
  89. */
  90. setGMResourceCSS(resourceMapData) {
  91. let cssText = typeof _GM_getResourceText === "function" ? _GM_getResourceText(resourceMapData.keyName) : "";
  92. if (typeof cssText === "string" && cssText) {
  93. addStyle(cssText);
  94. } else {
  95. CommonUtil.loadStyleLink(resourceMapData.url);
  96. }
  97. },
  98. /**
  99. * 添加<link>标签
  100. * @param url
  101. * @example
  102. * loadStyleLink("https://example.com/example.css")
  103. */
  104. async loadStyleLink(url) {
  105. let $link = document.createElement("link");
  106. $link.rel = "stylesheet";
  107. $link.type = "text/css";
  108. $link.href = url;
  109. domutils.ready(() => {
  110. document.head.appendChild($link);
  111. });
  112. },
  113. /**
  114. * 添加<script>标签
  115. * @param url
  116. * @example
  117. * loadStyleLink("https://example.com/example.js")
  118. */
  119. async loadScript(url) {
  120. let $script = document.createElement("script");
  121. $script.src = url;
  122. return new Promise((resolve) => {
  123. $script.onload = () => {
  124. resolve(null);
  125. };
  126. (document.head || document.documentElement).appendChild($script);
  127. });
  128. },
  129. /**
  130. * 将url修复,例如只有search的链接修复为完整的链接
  131. *
  132. * 注意:不包括http转https
  133. * @param url 需要修复的链接
  134. * @example
  135. * 修复前:`/xxx/xxx?ss=ssss`
  136. * 修复后:`https://xxx.xxx.xxx/xxx/xxx?ss=ssss`
  137. * @example
  138. * 修复前:`//xxx/xxx?ss=ssss`
  139. * 修复后:`https://xxx.xxx.xxx/xxx/xxx?ss=ssss`
  140. * @example
  141. * 修复前:`https://xxx.xxx.xxx/xxx/xxx?ss=ssss`
  142. * 修复后:`https://xxx.xxx.xxx/xxx/xxx?ss=ssss`
  143. * @example
  144. * 修复前:`xxx/xxx?ss=ssss`
  145. * 修复后:`https://xxx.xxx.xxx/xxx/xxx?ss=ssss`
  146. */
  147. fixUrl(url) {
  148. url = url.trim();
  149. if (url.match(/^http(s|):\/\//i)) {
  150. return url;
  151. } else {
  152. if (!url.startsWith("/")) {
  153. url += "/";
  154. }
  155. url = window.location.origin + url;
  156. return url;
  157. }
  158. },
  159. /**
  160. * http转https
  161. * @param url 需要修复的链接
  162. * @example
  163. * 修复前:
  164. * 修复后:
  165. * @example
  166. * 修复前:
  167. * 修复后:
  168. */
  169. fixHttps(url) {
  170. if (url.startsWith("https://")) {
  171. return url;
  172. }
  173. if (!url.startsWith("http://")) {
  174. return url;
  175. }
  176. let urlObj = new URL(url);
  177. urlObj.protocol = "https:";
  178. return urlObj.toString();
  179. }
  180. };
  181. const _SCRIPT_NAME_ = "CSDN优化";
  182. const utils = Utils.noConflict();
  183. const domutils = DOMUtils.noConflict();
  184. const __pops = pops;
  185. const log = new utils.Log(
  186. _GM_info,
  187. _unsafeWindow.console || _monkeyWindow.console
  188. );
  189. const SCRIPT_NAME = ((_a = _GM_info == null ? void 0 : _GM_info.script) == null ? void 0 : _a.name) || _SCRIPT_NAME_;
  190. const DEBUG = false;
  191. log.config({
  192. debug: DEBUG,
  193. logMaxCount: 1e3,
  194. autoClearConsole: true,
  195. tag: true
  196. });
  197. Qmsg.config(
  198. Object.defineProperties(
  199. {
  200. html: true,
  201. autoClose: true,
  202. showClose: false
  203. },
  204. {
  205. position: {
  206. get() {
  207. return PopsPanel.getValue("qmsg-config-position", "bottom");
  208. }
  209. },
  210. maxNums: {
  211. get() {
  212. return PopsPanel.getValue("qmsg-config-maxnums", 5);
  213. }
  214. },
  215. showReverse: {
  216. get() {
  217. return PopsPanel.getValue("qmsg-config-showreverse", true);
  218. }
  219. },
  220. zIndex: {
  221. get() {
  222. let maxZIndex = Utils.getMaxZIndex();
  223. let popsMaxZIndex = pops.config.InstanceUtils.getPopsMaxZIndex().zIndex;
  224. return Utils.getMaxValue(maxZIndex, popsMaxZIndex) + 100;
  225. }
  226. }
  227. }
  228. )
  229. );
  230. const GM_Menu = new utils.GM_Menu({
  231. GM_getValue: _GM_getValue,
  232. GM_setValue: _GM_setValue,
  233. GM_registerMenuCommand: _GM_registerMenuCommand,
  234. GM_unregisterMenuCommand: _GM_unregisterMenuCommand
  235. });
  236. const httpx = new utils.Httpx(_GM_xmlhttpRequest);
  237. httpx.interceptors.response.use(void 0, (data) => {
  238. log.error("拦截器-请求错误", data);
  239. if (data.type === "onabort") {
  240. Qmsg.warning("请求取消");
  241. } else if (data.type === "onerror") {
  242. Qmsg.error("请求异常");
  243. } else if (data.type === "ontimeout") {
  244. Qmsg.error("请求超时");
  245. } else {
  246. Qmsg.error("其它错误");
  247. }
  248. return data;
  249. });
  250. httpx.config({
  251. logDetails: DEBUG
  252. });
  253. ({
  254. Object: {
  255. defineProperty: _unsafeWindow.Object.defineProperty
  256. },
  257. Function: {
  258. apply: _unsafeWindow.Function.prototype.apply,
  259. call: _unsafeWindow.Function.prototype.call
  260. },
  261. Element: {
  262. appendChild: _unsafeWindow.Element.prototype.appendChild
  263. },
  264. setTimeout: _unsafeWindow.setTimeout
  265. });
  266. const addStyle = utils.addStyle.bind(utils);
  267. const $ = document.querySelector.bind(document);
  268. const $$ = document.querySelectorAll.bind(document);
  269. const KEY = "GM_Panel";
  270. const ATTRIBUTE_INIT = "data-init";
  271. const ATTRIBUTE_KEY = "data-key";
  272. const ATTRIBUTE_DEFAULT_VALUE = "data-default-value";
  273. const ATTRIBUTE_INIT_MORE_VALUE = "data-init-more-value";
  274. const PROPS_STORAGE_API = "data-storage-api";
  275. const CSDNRouter = {
  276. /**
  277. * 判断是否是华为云联盟
  278. * + huaweicloud.csdn.net
  279. */
  280. isHuaWeiCloudBlog() {
  281. return Boolean(/huaweicloud.csdn.net/i.test(window.location.origin));
  282. },
  283. /**
  284. * 判断是否是博客
  285. * + blog.csdn.net
  286. */
  287. isBlog() {
  288. return Boolean(/blog.csdn.net/i.test(window.location.origin));
  289. },
  290. /**
  291. * 博客帖子
  292. */
  293. isBlogArticle() {
  294. return this.isBlog() && window.location.pathname.includes("/article/details/");
  295. },
  296. /**
  297. * 判断是否是文库
  298. * + wenku.csdn.net
  299. */
  300. isWenKu() {
  301. return Boolean(/wenku.csdn.net/i.test(window.location.origin));
  302. },
  303. /**
  304. * 判断是否是链接
  305. * + link.csdn.net
  306. */
  307. isLink() {
  308. return window.location.hostname === "link.csdn.net";
  309. },
  310. /**
  311. * 判断是否是搜索
  312. * + so.csdn.net
  313. */
  314. isSo() {
  315. return window.location.hostname === "so.csdn.net";
  316. },
  317. /**
  318. * 判断是否是C知道
  319. * + so.csdn.net/know
  320. * + /chat
  321. * + /so/ai
  322. */
  323. isSoCKnow() {
  324. return this.isSo() && (window.location.pathname.startsWith("/chat") || window.location.pathname.startsWith("/so/ai"));
  325. },
  326. /**
  327. * 判断是否是资源页面
  328. * + download.csdn.net
  329. */
  330. isDownload() {
  331. return window.location.hostname === "download.csdn.net";
  332. }
  333. };
  334. const UISlider = function(text, key, defaultValue, min, max, changeCallBack, getToolTipContent, description, step) {
  335. let result = {
  336. text,
  337. type: "slider",
  338. description,
  339. attributes: {},
  340. props: {},
  341. getValue() {
  342. return this.props[PROPS_STORAGE_API].get(key, defaultValue);
  343. },
  344. getToolTipContent(value) {
  345. if (typeof getToolTipContent === "function") {
  346. return getToolTipContent(value);
  347. } else {
  348. return `${value}`;
  349. }
  350. },
  351. callback(event, value) {
  352. if (typeof changeCallBack === "function") {
  353. if (changeCallBack(event, value)) {
  354. return;
  355. }
  356. }
  357. this.props[PROPS_STORAGE_API].set(key, value);
  358. },
  359. min,
  360. max,
  361. step
  362. };
  363. Reflect.set(result.attributes, ATTRIBUTE_KEY, key);
  364. Reflect.set(result.attributes, ATTRIBUTE_DEFAULT_VALUE, defaultValue);
  365. Reflect.set(result.props, PROPS_STORAGE_API, {
  366. get(key2, defaultValue2) {
  367. return PopsPanel.getValue(key2, defaultValue2);
  368. },
  369. set(key2, value) {
  370. PopsPanel.setValue(key2, value);
  371. }
  372. });
  373. return result;
  374. };
  375. const UISwitch = function(text, key, defaultValue, clickCallBack, description, afterAddToUListCallBack) {
  376. let result = {
  377. text,
  378. type: "switch",
  379. description,
  380. attributes: {},
  381. props: {},
  382. getValue() {
  383. return Boolean(
  384. this.props[PROPS_STORAGE_API].get(key, defaultValue)
  385. );
  386. },
  387. callback(event, __value) {
  388. let value = Boolean(__value);
  389. log.success(`${value ? "开启" : "关闭"} ${text}`);
  390. if (typeof clickCallBack === "function") {
  391. if (clickCallBack(event, value)) {
  392. return;
  393. }
  394. }
  395. this.props[PROPS_STORAGE_API].set(key, value);
  396. },
  397. afterAddToUListCallBack
  398. };
  399. Reflect.set(result.attributes, ATTRIBUTE_KEY, key);
  400. Reflect.set(result.attributes, ATTRIBUTE_DEFAULT_VALUE, defaultValue);
  401. Reflect.set(result.props, PROPS_STORAGE_API, {
  402. get(key2, defaultValue2) {
  403. return PopsPanel.getValue(key2, defaultValue2);
  404. },
  405. set(key2, value) {
  406. PopsPanel.setValue(key2, value);
  407. }
  408. });
  409. return result;
  410. };
  411. const SettingUIBlog = {
  412. id: "panel-blog",
  413. title: "博客",
  414. isDefault() {
  415. return CSDNRouter.isBlog();
  416. },
  417. forms: [
  418. {
  419. type: "forms",
  420. text: "",
  421. forms: [
  422. {
  423. type: "deepMenu",
  424. text: "文章",
  425. forms: [
  426. {
  427. type: "forms",
  428. text: "",
  429. forms: [
  430. {
  431. text: "布局屏蔽",
  432. type: "deepMenu",
  433. forms: [
  434. {
  435. text: "",
  436. type: "forms",
  437. forms: [
  438. UISwitch(
  439. "【屏蔽】登录弹窗",
  440. "csdn-blog-shieldLoginDialog",
  441. true
  442. ),
  443. UISwitch(
  444. "【屏蔽】左侧博客信息",
  445. "csdn-blog-shieldLeftBlogContainerAside",
  446. false
  447. ),
  448. UISwitch(
  449. "【屏蔽】右侧目录信息",
  450. "csdn-blog-shieldRightDirectoryInformation",
  451. false
  452. ),
  453. UISwitch(
  454. "【屏蔽】底部的悬浮工具栏",
  455. "csdn-blog-shieldBottomFloatingToolbar",
  456. false
  457. )
  458. ]
  459. }
  460. ]
  461. },
  462. {
  463. text: "右侧悬浮工具栏",
  464. type: "deepMenu",
  465. forms: [
  466. {
  467. text: "功能",
  468. type: "forms",
  469. forms: [
  470. UISwitch(
  471. "启用",
  472. "csdn-blog-rightToolbarEnable",
  473. true,
  474. void 0,
  475. "创作中心,隐藏/显示侧栏,新手引导,客服、举报..."
  476. ),
  477. UISwitch(
  478. "【添加按钮】前往评论",
  479. "csdn-blog-addGotoRecommandButton",
  480. true,
  481. void 0,
  482. "在悬浮工具栏最后面添加"
  483. ),
  484. UISlider(
  485. "right偏移",
  486. "csdn-blog-rightToolbarRightOffset",
  487. 90,
  488. 0,
  489. document.documentElement.clientWidth,
  490. (event, value) => {
  491. let csdnSideToolbar = document.querySelector(
  492. ".csdn-side-toolbar"
  493. );
  494. domutils.css(csdnSideToolbar, {
  495. right: value + "px"
  496. });
  497. },
  498. (value) => {
  499. return `当前:${value}px,默认:90px`;
  500. }
  501. ),
  502. UISlider(
  503. "top偏移",
  504. "csdn-blog-rightToolbarTopOffset",
  505. 140,
  506. 0,
  507. document.documentElement.clientHeight,
  508. (event, value) => {
  509. let csdnSideToolbar = document.querySelector(
  510. ".csdn-side-toolbar"
  511. );
  512. domutils.css(csdnSideToolbar, {
  513. top: value + "px"
  514. });
  515. },
  516. (value) => {
  517. return `当前:${value}px,默认:90px`;
  518. }
  519. )
  520. ]
  521. },
  522. {
  523. text: "屏蔽",
  524. type: "forms",
  525. forms: [
  526. UISwitch(
  527. "【屏蔽】创作中心",
  528. "csdn-blog-rightToolbarCreativeCenter",
  529. false
  530. ),
  531. UISwitch(
  532. "【屏蔽】显示/隐藏侧栏",
  533. "csdn-blog-rightToolbarShowOrSidebar",
  534. false
  535. ),
  536. UISwitch(
  537. "【屏蔽】新手引导",
  538. "csdn-blog-rightToolbarBeginnerGuidance",
  539. false
  540. ),
  541. UISwitch(
  542. "【屏蔽】客服",
  543. "csdn-blog-rightToolbarCustomerService",
  544. false
  545. ),
  546. UISwitch(
  547. "【屏蔽】举报",
  548. "csdn-blog-rightToolbarReport",
  549. false
  550. ),
  551. UISwitch(
  552. "【屏蔽】返回顶部",
  553. "csdn-blog-rightToolbarBackToTop",
  554. false
  555. )
  556. ]
  557. }
  558. ]
  559. },
  560. {
  561. text: "内容",
  562. type: "deepMenu",
  563. forms: [
  564. {
  565. text: "功能",
  566. type: "forms",
  567. forms: [
  568. UISwitch(
  569. "点击代码块自动展开",
  570. "csdn-blog-clickPreCodeAutomatically",
  571. true,
  572. void 0,
  573. "当鼠标点击代码块区域时,将自动展开内容"
  574. ),
  575. UISwitch(
  576. "自动展开代码块",
  577. "csdn-blog-autoExpandCodeContent",
  578. true,
  579. void 0,
  580. "懒人操作,免手动点击展开"
  581. ),
  582. UISwitch(
  583. "自动展开内容",
  584. "csdn-blog-autoExpandContent",
  585. true,
  586. void 0,
  587. "懒人操作,免手动点击展开"
  588. ),
  589. UISwitch(
  590. "全文居中",
  591. "csdn-blog-articleCenter",
  592. true,
  593. function(event, enable) {
  594. if (enable) {
  595. alert(
  596. "为了更好的呈现效果,请开启功能:【屏蔽】左侧博客信息、【屏蔽】右侧目录信息"
  597. );
  598. }
  599. },
  600. "自动屏蔽左侧和右侧的信息,且将文章居中"
  601. ),
  602. UISwitch(
  603. "允许选择内容",
  604. "csdn-blog-allowSelectContent",
  605. true,
  606. void 0
  607. )
  608. ]
  609. },
  610. {
  611. text: "屏蔽",
  612. type: "forms",
  613. forms: [
  614. UISwitch(
  615. "【屏蔽】底部xx技能树",
  616. "csdn-blog-shieldBottomSkillTree",
  617. false
  618. ),
  619. UISwitch(
  620. "【屏蔽】选中文字悬浮栏",
  621. "csdn-blog-shieldArticleSearchTip",
  622. false,
  623. void 0,
  624. "选中文字弹出的,例如:搜索、评论、笔记"
  625. )
  626. ]
  627. }
  628. ]
  629. },
  630. {
  631. text: "评论区",
  632. type: "deepMenu",
  633. forms: [
  634. {
  635. text: "",
  636. type: "forms",
  637. forms: [
  638. UISwitch(
  639. "启用",
  640. "csdn-blog-blockComment",
  641. true,
  642. void 0,
  643. "关闭是屏蔽评论区"
  644. ),
  645. UISwitch(
  646. "优化评论区的位置",
  647. "csdn-blog-restoreComments",
  648. true
  649. )
  650. ]
  651. }
  652. ]
  653. },
  654. {
  655. text: "底部文章",
  656. type: "deepMenu",
  657. forms: [
  658. {
  659. text: "",
  660. type: "forms",
  661. forms: [
  662. UISwitch(
  663. "启用",
  664. "csdn-blog-bottomRecommendArticleEnable",
  665. true,
  666. void 0,
  667. "关闭是屏蔽底部文章"
  668. ),
  669. UISwitch(
  670. "标识CSDN下载",
  671. "csdn-blog-identityCSDNDownload",
  672. true,
  673. void 0,
  674. "使用红框标识"
  675. ),
  676. UISwitch(
  677. "移除资源下载的文章",
  678. "csdn-blog-removeResourceDownloadArticle",
  679. false,
  680. void 0,
  681. "download.csdn.net<br>www.iteye.com<br>edu.csdn.net"
  682. )
  683. ]
  684. }
  685. ]
  686. }
  687. ]
  688. }
  689. ]
  690. }
  691. ]
  692. },
  693. {
  694. text: "",
  695. type: "forms",
  696. forms: [
  697. {
  698. text: "全局布局屏蔽",
  699. type: "deepMenu",
  700. forms: [
  701. {
  702. text: "",
  703. type: "forms",
  704. forms: [
  705. UISwitch(
  706. "【屏蔽】顶部工具栏",
  707. "csdn-blog-shieldTopToolbar",
  708. false
  709. )
  710. ]
  711. }
  712. ]
  713. },
  714. {
  715. text: "劫持/拦截",
  716. type: "deepMenu",
  717. forms: [
  718. {
  719. text: "",
  720. type: "forms",
  721. forms: [
  722. UISwitch(
  723. "拦截-复制的小尾巴",
  724. "csdn-blog-removeClipboardHijacking",
  725. true
  726. ),
  727. UISwitch(
  728. "劫持-禁止复制",
  729. "csdn-blog-unBlockCopy",
  730. true,
  731. void 0,
  732. "允许点击复制按钮进行复制"
  733. )
  734. ]
  735. }
  736. ]
  737. }
  738. ]
  739. }
  740. ]
  741. };
  742. const SettingUILink = {
  743. id: "panel-link",
  744. title: "链接",
  745. isDefault() {
  746. return CSDNRouter.isLink();
  747. },
  748. forms: [
  749. {
  750. text: "功能",
  751. type: "forms",
  752. forms: [
  753. UISwitch(
  754. "重定向链接",
  755. "csdn-link-jumpRedirect",
  756. true,
  757. void 0,
  758. "自动跳转至被拦截的Url链接"
  759. )
  760. ]
  761. }
  762. ]
  763. };
  764. const SettingUIHuaWeiCloud = {
  765. id: "panel-hua-wei-cloud",
  766. title: "华为云开发者联盟",
  767. isDefault() {
  768. return CSDNRouter.isHuaWeiCloudBlog();
  769. },
  770. forms: [
  771. {
  772. text: "功能",
  773. type: "forms",
  774. forms: [
  775. UISwitch("自动展开全文", "csdn-hua-wei-cloud-autoExpandContent", true)
  776. ]
  777. },
  778. {
  779. text: "屏蔽",
  780. type: "forms",
  781. forms: [
  782. UISwitch(
  783. "【屏蔽】云开发者任务挑战活动",
  784. "csdn-hua-wei-cloud-shieldCloudDeveloperTaskChallengeEvent",
  785. true
  786. ),
  787. UISwitch(
  788. "【屏蔽】左侧悬浮按钮",
  789. "csdn-hua-wei-cloud-shieldLeftFloatingButton",
  790. false,
  791. function(event, enable) {
  792. if (enable) {
  793. alert(
  794. "开启后将屏蔽【当前阅读量】、【点赞按钮】、【评论按钮】、【分享按钮】"
  795. );
  796. }
  797. }
  798. ),
  799. UISwitch(
  800. "【屏蔽】右侧栏",
  801. "csdn-hua-wei-cloud-blockRightColumn",
  802. false,
  803. function(event, enable) {
  804. if (enable) {
  805. alert(
  806. "开启后将屏蔽【相关产品】-【活动日历】-【运营活动】-【热门标签】"
  807. );
  808. }
  809. }
  810. ),
  811. UISwitch(
  812. "【屏蔽】底部推荐内容",
  813. "csdn-hua-wei-cloud-blockRecommendedContentAtTheBottom",
  814. false
  815. ),
  816. UISwitch(
  817. "【屏蔽】底部更多推荐",
  818. "csdn-hua-wei-cloud-shieldTheBottomForMoreRecommendations",
  819. false
  820. )
  821. ]
  822. }
  823. ]
  824. };
  825. const SettingUIWenKu = {
  826. id: "panel-wenku",
  827. title: "资源",
  828. isDefault() {
  829. return CSDNRouter.isLink();
  830. },
  831. forms: [
  832. {
  833. text: "屏蔽",
  834. type: "forms",
  835. forms: [
  836. UISwitch(
  837. "【屏蔽】资源推荐",
  838. "csdn-wenku-shieldResourceRecommend",
  839. false
  840. ),
  841. UISwitch(
  842. "【屏蔽】右侧用户信息",
  843. "csdn-wenku-shieldRightUserInfo",
  844. false
  845. ),
  846. UISwitch(
  847. "【屏蔽】右侧悬浮工具栏",
  848. "csdn-wenku-shieldRightToolBar",
  849. false
  850. )
  851. ]
  852. }
  853. ]
  854. };
  855. const SettingUISo = {
  856. id: "panel-so",
  857. title: "搜索",
  858. isDefault() {
  859. return CSDNRouter.isSo();
  860. },
  861. forms: [
  862. {
  863. text: "C知道-功能",
  864. type: "forms",
  865. forms: [UISwitch("去除水印", "csdn-so-cknow-removeMaskCover", true)]
  866. }
  867. ]
  868. };
  869. const MSettingUIBlog = {
  870. id: "m-panel-blog",
  871. title: "博客",
  872. isDefault() {
  873. return CSDNRouter.isBlog();
  874. },
  875. forms: [
  876. {
  877. type: "forms",
  878. text: "",
  879. forms: [
  880. {
  881. type: "deepMenu",
  882. text: "文章",
  883. forms: [
  884. {
  885. text: "",
  886. type: "forms",
  887. forms: [
  888. {
  889. type: "deepMenu",
  890. text: "顶部工具栏",
  891. forms: [
  892. {
  893. type: "forms",
  894. text: "",
  895. forms: [
  896. UISwitch(
  897. "启用",
  898. "m-csdn-blog-shieldTopToolbar",
  899. false,
  900. void 0,
  901. "关闭是屏蔽顶部工具栏"
  902. )
  903. ]
  904. }
  905. ]
  906. },
  907. {
  908. text: "内容",
  909. type: "deepMenu",
  910. forms: [
  911. {
  912. text: "",
  913. type: "forms",
  914. forms: [
  915. UISwitch(
  916. "允许选中文字",
  917. "m-csdn-blog-allowSelectText",
  918. true,
  919. void 0,
  920. "设置user-select: text;"
  921. ),
  922. UISwitch(
  923. "自动展开",
  924. "m-csdn-blog-autoExpandContent",
  925. true,
  926. void 0,
  927. "包括内容、代码块"
  928. ),
  929. UISwitch(
  930. "不限制代码块的最大高度",
  931. "m-csdn-blog-notLimitCodePreMaxHeight",
  932. false,
  933. void 0,
  934. "让代码块的高度直接被撑开"
  935. )
  936. ]
  937. }
  938. ]
  939. },
  940. {
  941. text: "评论",
  942. type: "deepMenu",
  943. forms: [
  944. {
  945. text: "",
  946. type: "forms",
  947. forms: [
  948. UISwitch(
  949. "启用",
  950. "m-csdn-blog-comment-enable",
  951. true,
  952. void 0,
  953. "关闭是屏蔽评论区"
  954. ),
  955. UISwitch(
  956. "不限制评论区的最大高度",
  957. "m-csdn-blog-notLimitCommentMaxHeight",
  958. true,
  959. void 0,
  960. "让评论区高度直接被撑开"
  961. )
  962. ]
  963. }
  964. ]
  965. },
  966. {
  967. text: "底部文章",
  968. type: "deepMenu",
  969. forms: [
  970. {
  971. text: "",
  972. type: "forms",
  973. forms: [
  974. UISwitch(
  975. "启用",
  976. "m-csdn-blog-bottomArticleEnable",
  977. true,
  978. void 0,
  979. "关闭是屏蔽底部文章"
  980. ),
  981. UISwitch(
  982. "移除资源下载",
  983. "m-csdn-blog-removeResourceArticle",
  984. false,
  985. void 0,
  986. "download.csdn.net<br>www.iteye.com<br>edu.csdn.net"
  987. ),
  988. UISwitch(
  989. "重构",
  990. "m-csdn-blog-refactoringRecommendation",
  991. true,
  992. void 0,
  993. "文章的样式统一"
  994. ),
  995. UISwitch(
  996. "新标签页打开",
  997. "m-csdn-blog-openNewTab",
  998. true,
  999. void 0,
  1000. "新标签页打开文章"
  1001. )
  1002. ]
  1003. }
  1004. ]
  1005. },
  1006. {
  1007. type: "deepMenu",
  1008. text: "底部工具栏",
  1009. forms: [
  1010. {
  1011. type: "forms",
  1012. text: "",
  1013. forms: [
  1014. UISwitch(
  1015. "启用",
  1016. "m-csdn-blog-bottom-toolbar-enable",
  1017. false,
  1018. void 0,
  1019. "关闭是屏蔽底部工具栏"
  1020. ),
  1021. UISwitch(
  1022. "常驻底部",
  1023. "m-csdn-blog-bottom-toolbar-always-bottom",
  1024. false,
  1025. void 0,
  1026. "开启后底部工具栏不随下滑滚动而隐藏"
  1027. ),
  1028. UISwitch(
  1029. "优化收藏按钮",
  1030. "m-csdn-blog-bottom-toolbar-optimizationCollectButton",
  1031. false,
  1032. void 0,
  1033. "可以自行选择收藏夹"
  1034. )
  1035. ]
  1036. }
  1037. ]
  1038. }
  1039. ]
  1040. }
  1041. ]
  1042. }
  1043. ]
  1044. },
  1045. {
  1046. type: "forms",
  1047. text: "",
  1048. forms: [
  1049. {
  1050. text: "功能",
  1051. type: "deepMenu",
  1052. forms: [
  1053. {
  1054. text: "",
  1055. type: "forms",
  1056. forms: [
  1057. UISwitch(
  1058. "【屏蔽】广告",
  1059. "m-csdn-blog-removeAds",
  1060. true,
  1061. void 0,
  1062. "包括:登录弹窗、打开APP、ios版本提示等"
  1063. ),
  1064. UISwitch(
  1065. "允许复制",
  1066. "m-csdn-blog-unBlockCopy",
  1067. true,
  1068. void 0,
  1069. "允许点击复制按钮进行复制"
  1070. )
  1071. ]
  1072. }
  1073. ]
  1074. }
  1075. ]
  1076. }
  1077. ]
  1078. };
  1079. const MSettingUILink = {
  1080. id: "m-panel-link",
  1081. title: "链接",
  1082. isDefault() {
  1083. return CSDNRouter.isLink();
  1084. },
  1085. forms: [
  1086. {
  1087. text: "功能",
  1088. type: "forms",
  1089. forms: [
  1090. UISwitch(
  1091. "重定向链接",
  1092. "m-csdn-link-jumpRedirect",
  1093. true,
  1094. void 0,
  1095. "自动跳转至被拦截的Url链接"
  1096. )
  1097. ]
  1098. }
  1099. ]
  1100. };
  1101. const MSettingUISo = {
  1102. id: "panel-so",
  1103. title: "搜索",
  1104. isDefault() {
  1105. return CSDNRouter.isSo();
  1106. },
  1107. forms: [
  1108. {
  1109. text: "C知道-功能",
  1110. type: "forms",
  1111. forms: [UISwitch("去除水印", "m-csdn-so-cknow-removeMaskCover", true)]
  1112. }
  1113. ]
  1114. };
  1115. const MSettingUIWenKu = {
  1116. id: "m-panel-wenku",
  1117. title: "文库",
  1118. isDefault() {
  1119. return CSDNRouter.isWenKu();
  1120. },
  1121. forms: [
  1122. {
  1123. text: "屏蔽",
  1124. type: "forms",
  1125. forms: [
  1126. UISwitch(
  1127. "【屏蔽】底部工具栏",
  1128. "m-csdn-wenku-shieldBottomToolbar",
  1129. false
  1130. )
  1131. ]
  1132. }
  1133. ]
  1134. };
  1135. const MSettingUIHuaWeiCloud = {
  1136. id: "m-panel-hua-wei-cloud",
  1137. title: "华为云开发者联盟",
  1138. isDefault() {
  1139. return CSDNRouter.isHuaWeiCloudBlog();
  1140. },
  1141. forms: [
  1142. {
  1143. text: "功能",
  1144. type: "forms",
  1145. forms: [
  1146. UISwitch(
  1147. "自动展开全文",
  1148. "m-csdn-hua-wei-cloud-autoExpandContent",
  1149. true
  1150. )
  1151. ]
  1152. },
  1153. {
  1154. text: "屏蔽",
  1155. type: "forms",
  1156. forms: [
  1157. UISwitch(
  1158. "【屏蔽】底部加入社区",
  1159. "m-csdn-hua-wei-cloud-blockBottomJoinTheCommunity",
  1160. true
  1161. )
  1162. ]
  1163. }
  1164. ]
  1165. };
  1166. const MSettingUIDownload = {
  1167. id: "m-panel-download",
  1168. title: "资源",
  1169. isDefault() {
  1170. return CSDNRouter.isDownload();
  1171. },
  1172. forms: [
  1173. {
  1174. text: "功能",
  1175. type: "forms",
  1176. forms: [
  1177. UISwitch(
  1178. "自动展开资源介绍",
  1179. "m-csdn-download-automaticallyExpandResourceIntroduction",
  1180. true,
  1181. void 0,
  1182. "屏蔽资源介绍【展开全部】按钮并展开资源介绍"
  1183. )
  1184. ]
  1185. },
  1186. {
  1187. text: "屏蔽",
  1188. type: "forms",
  1189. forms: [
  1190. UISwitch(
  1191. "【屏蔽】广告",
  1192. "m-csdn-download-removeAds",
  1193. true,
  1194. void 0,
  1195. "包括:登录弹窗、会员降价等"
  1196. )
  1197. ]
  1198. }
  1199. ]
  1200. };
  1201. const UISelect = function(text, key, defaultValue, data, callback, description) {
  1202. let selectData = [];
  1203. if (typeof data === "function") {
  1204. selectData = data();
  1205. } else {
  1206. selectData = data;
  1207. }
  1208. let result = {
  1209. text,
  1210. type: "select",
  1211. description,
  1212. attributes: {},
  1213. props: {},
  1214. getValue() {
  1215. return this.props[PROPS_STORAGE_API].get(key, defaultValue);
  1216. },
  1217. callback(event, isSelectedValue, isSelectedText) {
  1218. let value = isSelectedValue;
  1219. log.info(`选择:${isSelectedText}`);
  1220. this.props[PROPS_STORAGE_API].set(key, value);
  1221. if (typeof callback === "function") {
  1222. callback(event, value, isSelectedText);
  1223. }
  1224. },
  1225. data: selectData
  1226. };
  1227. Reflect.set(result.attributes, ATTRIBUTE_KEY, key);
  1228. Reflect.set(result.attributes, ATTRIBUTE_DEFAULT_VALUE, defaultValue);
  1229. Reflect.set(result.props, PROPS_STORAGE_API, {
  1230. get(key2, defaultValue2) {
  1231. return PopsPanel.getValue(key2, defaultValue2);
  1232. },
  1233. set(key2, value) {
  1234. PopsPanel.setValue(key2, value);
  1235. }
  1236. });
  1237. return result;
  1238. };
  1239. const SettingUICommon = {
  1240. id: "component-common",
  1241. title: "通用",
  1242. forms: [
  1243. {
  1244. text: "Toast配置",
  1245. type: "forms",
  1246. forms: [
  1247. UISelect(
  1248. "Toast位置",
  1249. "qmsg-config-position",
  1250. "bottom",
  1251. [
  1252. {
  1253. value: "topleft",
  1254. text: "左上角"
  1255. },
  1256. {
  1257. value: "top",
  1258. text: "顶部"
  1259. },
  1260. {
  1261. value: "topright",
  1262. text: "右上角"
  1263. },
  1264. {
  1265. value: "left",
  1266. text: "左边"
  1267. },
  1268. {
  1269. value: "center",
  1270. text: "中间"
  1271. },
  1272. {
  1273. value: "right",
  1274. text: "右边"
  1275. },
  1276. {
  1277. value: "bottomleft",
  1278. text: "左下角"
  1279. },
  1280. {
  1281. value: "bottom",
  1282. text: "底部"
  1283. },
  1284. {
  1285. value: "bottomright",
  1286. text: "右下角"
  1287. }
  1288. ],
  1289. (event, isSelectValue, isSelectText) => {
  1290. log.info("设置当前Qmsg弹出位置" + isSelectText);
  1291. },
  1292. "Toast显示在页面九宫格的位置"
  1293. ),
  1294. UISelect(
  1295. "最多显示的数量",
  1296. "qmsg-config-maxnums",
  1297. 3,
  1298. [
  1299. {
  1300. value: 1,
  1301. text: "1"
  1302. },
  1303. {
  1304. value: 2,
  1305. text: "2"
  1306. },
  1307. {
  1308. value: 3,
  1309. text: "3"
  1310. },
  1311. {
  1312. value: 4,
  1313. text: "4"
  1314. },
  1315. {
  1316. value: 5,
  1317. text: "5"
  1318. }
  1319. ],
  1320. void 0,
  1321. "限制Toast显示的数量"
  1322. ),
  1323. UISwitch(
  1324. "逆序弹出",
  1325. "qmsg-config-showreverse",
  1326. false,
  1327. void 0,
  1328. "修改Toast弹出的顺序"
  1329. )
  1330. ]
  1331. }
  1332. // {
  1333. // text: "Cookie配置",
  1334. // type: "forms",
  1335. // forms: [
  1336. // UISwitch(
  1337. // "启用",
  1338. // "httpx-use-cookie-enable",
  1339. // false,
  1340. // void 0,
  1341. // "启用后,将根据下面的配置进行添加cookie"
  1342. // ),
  1343. // UISwitch(
  1344. // "使用document.cookie",
  1345. // "httpx-use-document-cookie",
  1346. // false,
  1347. // void 0,
  1348. // "自动根据请求的域名来设置对应的cookie"
  1349. // ),
  1350. // UITextArea(
  1351. // "tieba.baidu.com",
  1352. // "httpx-cookie-tieba.baidu.com",
  1353. // "",
  1354. // void 0,
  1355. // void 0,
  1356. // "Cookie格式:xxx=xxxx;xxx=xxxx"
  1357. // ),
  1358. // ],
  1359. // },
  1360. ]
  1361. };
  1362. const MSettingUICommon = {
  1363. id: "component-common",
  1364. title: "通用",
  1365. forms: [
  1366. {
  1367. text: "Toast配置",
  1368. type: "forms",
  1369. forms: [
  1370. UISelect(
  1371. "Toast位置",
  1372. "qmsg-config-position",
  1373. "bottom",
  1374. [
  1375. {
  1376. value: "topleft",
  1377. text: "左上角"
  1378. },
  1379. {
  1380. value: "top",
  1381. text: "顶部"
  1382. },
  1383. {
  1384. value: "topright",
  1385. text: "右上角"
  1386. },
  1387. {
  1388. value: "left",
  1389. text: "左边"
  1390. },
  1391. {
  1392. value: "center",
  1393. text: "中间"
  1394. },
  1395. {
  1396. value: "right",
  1397. text: "右边"
  1398. },
  1399. {
  1400. value: "bottomleft",
  1401. text: "左下角"
  1402. },
  1403. {
  1404. value: "bottom",
  1405. text: "底部"
  1406. },
  1407. {
  1408. value: "bottomright",
  1409. text: "右下角"
  1410. }
  1411. ],
  1412. (event, isSelectValue, isSelectText) => {
  1413. log.info("设置当前Qmsg弹出位置" + isSelectText);
  1414. },
  1415. "Toast显示在页面九宫格的位置"
  1416. ),
  1417. UISelect(
  1418. "最多显示的数量",
  1419. "qmsg-config-maxnums",
  1420. 3,
  1421. [
  1422. {
  1423. value: 1,
  1424. text: "1"
  1425. },
  1426. {
  1427. value: 2,
  1428. text: "2"
  1429. },
  1430. {
  1431. value: 3,
  1432. text: "3"
  1433. },
  1434. {
  1435. value: 4,
  1436. text: "4"
  1437. },
  1438. {
  1439. value: 5,
  1440. text: "5"
  1441. }
  1442. ],
  1443. void 0,
  1444. "限制Toast显示的数量"
  1445. ),
  1446. UISwitch(
  1447. "逆序弹出",
  1448. "qmsg-config-showreverse",
  1449. false,
  1450. void 0,
  1451. "修改Toast弹出的顺序"
  1452. )
  1453. ]
  1454. }
  1455. // {
  1456. // text: "Cookie配置",
  1457. // type: "forms",
  1458. // forms: [
  1459. // UISwitch(
  1460. // "启用",
  1461. // "httpx-use-cookie-enable",
  1462. // false,
  1463. // void 0,
  1464. // "启用后,将根据下面的配置进行添加cookie"
  1465. // ),
  1466. // UISwitch(
  1467. // "使用document.cookie",
  1468. // "httpx-use-document-cookie",
  1469. // false,
  1470. // void 0,
  1471. // "自动根据请求的域名来设置对应的cookie"
  1472. // ),
  1473. // UITextArea(
  1474. // "tieba.baidu.com",
  1475. // "httpx-cookie-tieba.baidu.com",
  1476. // "",
  1477. // void 0,
  1478. // void 0,
  1479. // "Cookie格式:xxx=xxxx;xxx=xxxx"
  1480. // ),
  1481. // ],
  1482. // },
  1483. ]
  1484. };
  1485. const PanelUISize = {
  1486. /**
  1487. * 一般设置界面的尺寸
  1488. */
  1489. setting: {
  1490. get width() {
  1491. return window.innerWidth < 550 ? "88vw" : "550px";
  1492. },
  1493. get height() {
  1494. return window.innerHeight < 450 ? "70vh" : "450px";
  1495. }
  1496. }
  1497. };
  1498. const PopsPanel = {
  1499. /** 数据 */
  1500. $data: {
  1501. __data: null,
  1502. __oneSuccessExecMenu: null,
  1503. __onceExec: null,
  1504. __listenData: null,
  1505. /**
  1506. * 菜单项的默认值
  1507. */
  1508. get data() {
  1509. if (PopsPanel.$data.__data == null) {
  1510. PopsPanel.$data.__data = new utils.Dictionary();
  1511. }
  1512. return PopsPanel.$data.__data;
  1513. },
  1514. /**
  1515. * 成功只执行了一次的项
  1516. */
  1517. get oneSuccessExecMenu() {
  1518. if (PopsPanel.$data.__oneSuccessExecMenu == null) {
  1519. PopsPanel.$data.__oneSuccessExecMenu = new utils.Dictionary();
  1520. }
  1521. return PopsPanel.$data.__oneSuccessExecMenu;
  1522. },
  1523. /**
  1524. * 成功只执行了一次的项
  1525. */
  1526. get onceExec() {
  1527. if (PopsPanel.$data.__onceExec == null) {
  1528. PopsPanel.$data.__onceExec = new utils.Dictionary();
  1529. }
  1530. return PopsPanel.$data.__onceExec;
  1531. },
  1532. /** 脚本名,一般用在设置的标题上 */
  1533. get scriptName() {
  1534. return SCRIPT_NAME;
  1535. },
  1536. /** 菜单项的总值在本地数据配置的键名 */
  1537. key: KEY,
  1538. /** 菜单项在attributes上配置的菜单键 */
  1539. attributeKeyName: ATTRIBUTE_KEY,
  1540. /** 菜单项在attributes上配置的菜单默认值 */
  1541. attributeDefaultValueName: ATTRIBUTE_DEFAULT_VALUE
  1542. },
  1543. /** 监听器 */
  1544. $listener: {
  1545. /**
  1546. * 值改变的监听器
  1547. */
  1548. get listenData() {
  1549. if (PopsPanel.$data.__listenData == null) {
  1550. PopsPanel.$data.__listenData = new utils.Dictionary();
  1551. }
  1552. return PopsPanel.$data.__listenData;
  1553. }
  1554. },
  1555. init() {
  1556. this.initPanelDefaultValue();
  1557. this.initExtensionsMenu();
  1558. },
  1559. initExtensionsMenu() {
  1560. if (_unsafeWindow.top !== _unsafeWindow.self) {
  1561. return;
  1562. }
  1563. GM_Menu.add([
  1564. {
  1565. key: "show_pops_panel_setting",
  1566. text: "⚙ PC端设置",
  1567. autoReload: false,
  1568. isStoreValue: false,
  1569. showText(text) {
  1570. return text;
  1571. },
  1572. callback: () => {
  1573. this.showPanel();
  1574. }
  1575. },
  1576. {
  1577. key: "m_show_pops_panel_setting",
  1578. text: "⚙ 移动端端设置",
  1579. autoReload: false,
  1580. isStoreValue: false,
  1581. showText(text) {
  1582. return text;
  1583. },
  1584. callback: () => {
  1585. this.showMPanel();
  1586. }
  1587. },
  1588. {
  1589. key: "gotoCSDNCKnow",
  1590. text: "⚙ 前往C知道",
  1591. isStoreValue: false,
  1592. autoReload: false,
  1593. showText(text) {
  1594. return text;
  1595. },
  1596. callback() {
  1597. window.open("https://so.csdn.net/chat", "_blank");
  1598. }
  1599. }
  1600. ]);
  1601. },
  1602. /** 初始化菜单项的默认值保存到本地数据中 */
  1603. initPanelDefaultValue() {
  1604. let that = this;
  1605. function initDefaultValue(config) {
  1606. if (!config.attributes) {
  1607. return;
  1608. }
  1609. let needInitConfig = {};
  1610. let key = config.attributes[ATTRIBUTE_KEY];
  1611. if (key != null) {
  1612. needInitConfig[key] = config.attributes[ATTRIBUTE_DEFAULT_VALUE];
  1613. }
  1614. let __attr_init__ = config.attributes[ATTRIBUTE_INIT];
  1615. if (typeof __attr_init__ === "function") {
  1616. let __attr_result__ = __attr_init__();
  1617. if (typeof __attr_result__ === "boolean" && !__attr_result__) {
  1618. return;
  1619. }
  1620. }
  1621. let initMoreValue = config.attributes[ATTRIBUTE_INIT_MORE_VALUE];
  1622. if (initMoreValue && typeof initMoreValue === "object") {
  1623. Object.assign(needInitConfig, initMoreValue);
  1624. }
  1625. let needInitConfigList = Object.keys(needInitConfig);
  1626. if (!needInitConfigList.length) {
  1627. log.warn(["请先配置键", config]);
  1628. return;
  1629. }
  1630. needInitConfigList.forEach((__key) => {
  1631. let __defaultValue = needInitConfig[__key];
  1632. if (that.$data.data.has(__key)) {
  1633. log.warn("请检查该key(已存在): " + __key);
  1634. }
  1635. that.$data.data.set(__key, __defaultValue);
  1636. });
  1637. }
  1638. function loopInitDefaultValue(configList) {
  1639. for (let index = 0; index < configList.length; index++) {
  1640. let configItem = configList[index];
  1641. initDefaultValue(configItem);
  1642. let childForms = configItem.forms;
  1643. if (childForms && Array.isArray(childForms)) {
  1644. loopInitDefaultValue(childForms);
  1645. }
  1646. }
  1647. }
  1648. let contentConfigList = this.getPanelContentConfig().concat(
  1649. this.getMPanelContentConfig()
  1650. );
  1651. for (let index = 0; index < contentConfigList.length; index++) {
  1652. let leftContentConfigItem = contentConfigList[index];
  1653. if (!leftContentConfigItem.forms) {
  1654. continue;
  1655. }
  1656. let rightContentConfigList = leftContentConfigItem.forms;
  1657. if (rightContentConfigList && Array.isArray(rightContentConfigList)) {
  1658. loopInitDefaultValue(rightContentConfigList);
  1659. }
  1660. }
  1661. },
  1662. /**
  1663. * 设置值
  1664. * @param key 键
  1665. * @param value 值
  1666. */
  1667. setValue(key, value) {
  1668. let locaData = _GM_getValue(KEY, {});
  1669. let oldValue = locaData[key];
  1670. locaData[key] = value;
  1671. _GM_setValue(KEY, locaData);
  1672. if (this.$listener.listenData.has(key)) {
  1673. this.$listener.listenData.get(key).callback(key, oldValue, value);
  1674. }
  1675. },
  1676. /**
  1677. * 获取值
  1678. * @param key 键
  1679. * @param defaultValue 默认值
  1680. */
  1681. getValue(key, defaultValue) {
  1682. let locaData = _GM_getValue(KEY, {});
  1683. let localValue = locaData[key];
  1684. if (localValue == null) {
  1685. if (this.$data.data.has(key)) {
  1686. return this.$data.data.get(key);
  1687. }
  1688. return defaultValue;
  1689. }
  1690. return localValue;
  1691. },
  1692. /**
  1693. * 删除值
  1694. * @param key 键
  1695. */
  1696. deleteValue(key) {
  1697. let locaData = _GM_getValue(KEY, {});
  1698. let oldValue = locaData[key];
  1699. Reflect.deleteProperty(locaData, key);
  1700. _GM_setValue(KEY, locaData);
  1701. if (this.$listener.listenData.has(key)) {
  1702. this.$listener.listenData.get(key).callback(key, oldValue, void 0);
  1703. }
  1704. },
  1705. /**
  1706. * 监听调用setValue、deleteValue
  1707. * @param key 需要监听的键
  1708. * @param callback
  1709. */
  1710. addValueChangeListener(key, callback, option) {
  1711. let listenerId = Math.random();
  1712. this.$listener.listenData.set(key, {
  1713. id: listenerId,
  1714. key,
  1715. callback
  1716. });
  1717. if (option) {
  1718. if (option.immediate) {
  1719. callback(key, this.getValue(key), this.getValue(key));
  1720. }
  1721. }
  1722. return listenerId;
  1723. },
  1724. /**
  1725. * 移除监听
  1726. * @param listenerId 监听的id
  1727. */
  1728. removeValueChangeListener(listenerId) {
  1729. let deleteKey = null;
  1730. for (const [key, value] of this.$listener.listenData.entries()) {
  1731. if (value.id === listenerId) {
  1732. deleteKey = key;
  1733. break;
  1734. }
  1735. }
  1736. if (typeof deleteKey === "string") {
  1737. this.$listener.listenData.delete(deleteKey);
  1738. } else {
  1739. console.warn("没有找到对应的监听器");
  1740. }
  1741. },
  1742. /**
  1743. * 主动触发菜单值改变的回调
  1744. * @param key 菜单键
  1745. * @param newValue 想要触发的新值,默认使用当前值
  1746. * @param oldValue 想要触发的旧值,默认使用当前值
  1747. */
  1748. triggerMenuValueChange(key, newValue, oldValue) {
  1749. if (this.$listener.listenData.has(key)) {
  1750. let listenData = this.$listener.listenData.get(key);
  1751. if (typeof listenData.callback === "function") {
  1752. let value = this.getValue(key);
  1753. let __newValue = value;
  1754. let __oldValue = value;
  1755. if (typeof newValue !== "undefined" && arguments.length > 1) {
  1756. __newValue = newValue;
  1757. }
  1758. if (typeof oldValue !== "undefined" && arguments.length > 2) {
  1759. __oldValue = oldValue;
  1760. }
  1761. listenData.callback(key, __oldValue, __newValue);
  1762. }
  1763. }
  1764. },
  1765. /**
  1766. * 判断该键是否存在
  1767. * @param key 键
  1768. */
  1769. hasKey(key) {
  1770. let locaData = _GM_getValue(KEY, {});
  1771. return key in locaData;
  1772. },
  1773. /**
  1774. * 自动判断菜单是否启用,然后执行回调
  1775. * @param key
  1776. * @param callback 回调
  1777. * @param [isReverse=false] 逆反判断菜单启用
  1778. */
  1779. execMenu(key, callback, isReverse = false) {
  1780. if (!(typeof key === "string" || typeof key === "object" && Array.isArray(key))) {
  1781. throw new TypeError("key 必须是字符串或者字符串数组");
  1782. }
  1783. let runKeyList = [];
  1784. if (typeof key === "object" && Array.isArray(key)) {
  1785. runKeyList = [...key];
  1786. } else {
  1787. runKeyList.push(key);
  1788. }
  1789. let value = void 0;
  1790. for (let index = 0; index < runKeyList.length; index++) {
  1791. const runKey = runKeyList[index];
  1792. if (!this.$data.data.has(runKey)) {
  1793. log.warn(`${key} 键不存在`);
  1794. return;
  1795. }
  1796. let runValue = PopsPanel.getValue(runKey);
  1797. if (isReverse) {
  1798. runValue = !runValue;
  1799. }
  1800. if (!runValue) {
  1801. break;
  1802. }
  1803. value = runValue;
  1804. }
  1805. if (value) {
  1806. callback(value);
  1807. }
  1808. },
  1809. /**
  1810. * 自动判断菜单是否启用,然后执行回调,只会执行一次
  1811. * @param key
  1812. * @param callback 回调
  1813. * @param getValueFn 自定义处理获取当前值,值true是启用并执行回调,值false是不执行回调
  1814. * @param handleValueChangeFn 自定义处理值改变时的回调,值true是启用并执行回调,值false是不执行回调
  1815. */
  1816. execMenuOnce(key, callback, getValueFn, handleValueChangeFn) {
  1817. if (typeof key !== "string") {
  1818. throw new TypeError("key 必须是字符串");
  1819. }
  1820. if (!this.$data.data.has(key)) {
  1821. log.warn(`${key} 键不存在`);
  1822. return;
  1823. }
  1824. if (this.$data.oneSuccessExecMenu.has(key)) {
  1825. return;
  1826. }
  1827. this.$data.oneSuccessExecMenu.set(key, 1);
  1828. let __getValue = () => {
  1829. let localValue = PopsPanel.getValue(key);
  1830. return typeof getValueFn === "function" ? getValueFn(key, localValue) : localValue;
  1831. };
  1832. let resultStyleList = [];
  1833. let dynamicPushStyleNode = ($style) => {
  1834. let __value = __getValue();
  1835. let dynamicResultList = [];
  1836. if ($style instanceof HTMLStyleElement) {
  1837. dynamicResultList = [$style];
  1838. } else if (Array.isArray($style)) {
  1839. dynamicResultList = [
  1840. ...$style.filter(
  1841. (item) => item != null && item instanceof HTMLStyleElement
  1842. )
  1843. ];
  1844. }
  1845. if (__value) {
  1846. resultStyleList = resultStyleList.concat(dynamicResultList);
  1847. } else {
  1848. for (let index = 0; index < dynamicResultList.length; index++) {
  1849. let $css = dynamicResultList[index];
  1850. $css.remove();
  1851. dynamicResultList.splice(index, 1);
  1852. index--;
  1853. }
  1854. }
  1855. };
  1856. let changeCallBack = (currentValue) => {
  1857. let resultList = [];
  1858. if (currentValue) {
  1859. let result = callback(currentValue, dynamicPushStyleNode);
  1860. if (result instanceof HTMLStyleElement) {
  1861. resultList = [result];
  1862. } else if (Array.isArray(result)) {
  1863. resultList = [
  1864. ...result.filter(
  1865. (item) => item != null && item instanceof HTMLStyleElement
  1866. )
  1867. ];
  1868. }
  1869. }
  1870. for (let index = 0; index < resultStyleList.length; index++) {
  1871. let $css = resultStyleList[index];
  1872. $css.remove();
  1873. resultStyleList.splice(index, 1);
  1874. index--;
  1875. }
  1876. resultStyleList = [...resultList];
  1877. };
  1878. this.addValueChangeListener(
  1879. key,
  1880. (__key, oldValue, newValue) => {
  1881. let __newValue = newValue;
  1882. if (typeof handleValueChangeFn === "function") {
  1883. __newValue = handleValueChangeFn(__key, newValue, oldValue);
  1884. }
  1885. changeCallBack(__newValue);
  1886. }
  1887. );
  1888. let value = __getValue();
  1889. if (value) {
  1890. changeCallBack(value);
  1891. }
  1892. },
  1893. /**
  1894. * 父子菜单联动,自动判断菜单是否启用,然后执行回调,只会执行一次
  1895. * @param key 菜单键
  1896. * @param childKey 子菜单键
  1897. * @param callback 回调
  1898. * @param replaceValueFn 用于修改mainValue,返回undefined则不做处理
  1899. */
  1900. execInheritMenuOnce(key, childKey, callback, replaceValueFn) {
  1901. let that = this;
  1902. const handleInheritValue = (key2, childKey2) => {
  1903. let mainValue = that.getValue(key2);
  1904. let childValue = that.getValue(childKey2);
  1905. if (typeof replaceValueFn === "function") {
  1906. let changedMainValue = replaceValueFn(mainValue, childValue);
  1907. if (changedMainValue !== void 0) {
  1908. return changedMainValue;
  1909. }
  1910. }
  1911. return mainValue;
  1912. };
  1913. this.execMenuOnce(
  1914. key,
  1915. callback,
  1916. () => {
  1917. return handleInheritValue(key, childKey);
  1918. },
  1919. () => {
  1920. return handleInheritValue(key, childKey);
  1921. }
  1922. );
  1923. this.execMenuOnce(
  1924. childKey,
  1925. () => {
  1926. },
  1927. () => false,
  1928. () => {
  1929. this.triggerMenuValueChange(key);
  1930. return false;
  1931. }
  1932. );
  1933. },
  1934. /**
  1935. * 根据key执行一次
  1936. * @param key
  1937. */
  1938. onceExec(key, callback) {
  1939. if (typeof key !== "string") {
  1940. throw new TypeError("key 必须是字符串");
  1941. }
  1942. if (this.$data.onceExec.has(key)) {
  1943. return;
  1944. }
  1945. callback();
  1946. this.$data.onceExec.set(key, 1);
  1947. },
  1948. /**
  1949. * 显示设置面板
  1950. */
  1951. showPanel() {
  1952. __pops.panel({
  1953. title: {
  1954. text: `${SCRIPT_NAME}-PC端设置`,
  1955. position: "center",
  1956. html: false,
  1957. style: ""
  1958. },
  1959. content: this.getPanelContentConfig(),
  1960. mask: {
  1961. enable: true,
  1962. clickEvent: {
  1963. toClose: true,
  1964. toHide: false
  1965. }
  1966. },
  1967. width: PanelUISize.setting.width,
  1968. height: PanelUISize.setting.height,
  1969. drag: true,
  1970. only: true
  1971. });
  1972. },
  1973. /**
  1974. * 显示设置面板
  1975. */
  1976. showMPanel() {
  1977. __pops.panel({
  1978. title: {
  1979. text: `${SCRIPT_NAME}-移动端设置`,
  1980. position: "center",
  1981. html: false,
  1982. style: ""
  1983. },
  1984. content: this.getMPanelContentConfig(),
  1985. mask: {
  1986. enable: true,
  1987. clickEvent: {
  1988. toClose: true,
  1989. toHide: false
  1990. }
  1991. },
  1992. width: PanelUISize.setting.width,
  1993. height: PanelUISize.setting.height,
  1994. drag: true,
  1995. only: true
  1996. });
  1997. },
  1998. /**
  1999. * 获取配置内容
  2000. */
  2001. getPanelContentConfig() {
  2002. let configList = [
  2003. SettingUICommon,
  2004. SettingUIBlog,
  2005. SettingUILink,
  2006. SettingUIHuaWeiCloud,
  2007. SettingUIWenKu,
  2008. SettingUISo
  2009. ];
  2010. return configList;
  2011. },
  2012. /**
  2013. * 获取配置内容
  2014. */
  2015. getMPanelContentConfig() {
  2016. let configList = [
  2017. MSettingUICommon,
  2018. MSettingUIBlog,
  2019. MSettingUILink,
  2020. MSettingUIHuaWeiCloud,
  2021. MSettingUIWenKu,
  2022. MSettingUISo,
  2023. MSettingUIDownload
  2024. ];
  2025. return configList;
  2026. }
  2027. };
  2028. 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";
  2029. const CSDNHuaWeiCloud = {
  2030. init() {
  2031. addStyle(ShieldCSS$4);
  2032. PopsPanel.execMenuOnce(
  2033. "csdn-hua-wei-cloud-shieldCloudDeveloperTaskChallengeEvent",
  2034. () => {
  2035. return this.shieldCloudDeveloperTaskChallengeEvent();
  2036. }
  2037. );
  2038. PopsPanel.execMenuOnce("csdn-hua-wei-cloud-autoExpandContent", () => {
  2039. return this.autoExpandContent();
  2040. });
  2041. PopsPanel.execMenuOnce(
  2042. "csdn-hua-wei-cloud-shieldLeftFloatingButton",
  2043. () => {
  2044. return this.shieldLeftFloatingButton();
  2045. }
  2046. );
  2047. PopsPanel.execMenuOnce("csdn-hua-wei-cloud-blockRightColumn", () => {
  2048. return this.blockRightColumn();
  2049. });
  2050. PopsPanel.execMenuOnce(
  2051. "csdn-hua-wei-cloud-blockRecommendedContentAtTheBottom",
  2052. () => {
  2053. return this.blockRecommendedContentAtTheBottom();
  2054. }
  2055. );
  2056. PopsPanel.execMenuOnce(
  2057. "csdn-hua-wei-cloud-shieldTheBottomForMoreRecommendations",
  2058. () => {
  2059. return this.shieldTheBottomForMoreRecommendations();
  2060. }
  2061. );
  2062. },
  2063. /**
  2064. * 自动展开内容
  2065. */
  2066. autoExpandContent() {
  2067. log.info("自动展开全文");
  2068. return [
  2069. CommonUtil.addBlockCSS("div.article-show-more"),
  2070. addStyle(`
  2071. /* 自动展开全文 */
  2072. .main-content .user-article{
  2073. height: auto !important;
  2074. overflow: auto !important;
  2075. }
  2076. `)
  2077. ];
  2078. },
  2079. /**
  2080. * 屏蔽云开发者任务挑战活动
  2081. */
  2082. shieldCloudDeveloperTaskChallengeEvent() {
  2083. log.info("屏蔽云开发者任务挑战活动");
  2084. return CommonUtil.addBlockCSS(".luck-draw-modal-warp");
  2085. },
  2086. /**
  2087. * 屏蔽左侧悬浮按钮
  2088. */
  2089. shieldLeftFloatingButton() {
  2090. log.info("屏蔽左侧悬浮按钮,包括当前阅读量、点赞按钮、评论按钮、分享按钮");
  2091. return CommonUtil.addBlockCSS("div.toolbar-wrapper.article-interact-bar");
  2092. },
  2093. /**
  2094. * 屏蔽右侧栏
  2095. */
  2096. blockRightColumn() {
  2097. log.info("屏蔽右侧栏,包括相关产品-活动日历-运营活动-热门标签");
  2098. return CommonUtil.addBlockCSS("div.page-home-right.dp-aside-right");
  2099. },
  2100. /**
  2101. * 屏蔽底部推荐内容
  2102. */
  2103. blockRecommendedContentAtTheBottom() {
  2104. log.info("屏蔽底部推荐内容");
  2105. return CommonUtil.addBlockCSS("div.recommend-card-box");
  2106. },
  2107. /**
  2108. * 屏蔽底部更多推荐
  2109. */
  2110. shieldTheBottomForMoreRecommendations() {
  2111. log.info("屏蔽底部更多推荐");
  2112. return CommonUtil.addBlockCSS("div.more-article");
  2113. }
  2114. };
  2115. 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';
  2116. const CSDNBlogArticleRightToolBar = {
  2117. init() {
  2118. PopsPanel.execMenuOnce(
  2119. "csdn-blog-rightToolbarEnable",
  2120. () => {
  2121. return this.shieldRightToolbar();
  2122. },
  2123. (_, value) => {
  2124. return !value;
  2125. },
  2126. (_, newValue) => {
  2127. return !newValue;
  2128. }
  2129. );
  2130. PopsPanel.execMenuOnce("csdn-blog-rightToolbarCreativeCenter", () => {
  2131. return this.shieldCreativeCenter();
  2132. });
  2133. PopsPanel.execMenuOnce("csdn-blog-rightToolbarShowOrSidebar", () => {
  2134. return this.shieldShowOrSidebar();
  2135. });
  2136. PopsPanel.execMenuOnce("csdn-blog-rightToolbarBeginnerGuidance", () => {
  2137. return this.shieldBeginnerGuidance();
  2138. });
  2139. PopsPanel.execMenuOnce("csdn-blog-rightToolbarCustomerService", () => {
  2140. return this.shieldCustomerService();
  2141. });
  2142. PopsPanel.execMenuOnce("csdn-blog-rightToolbarReport", () => {
  2143. return this.shieldReport();
  2144. });
  2145. PopsPanel.execMenuOnce("csdn-blog-rightToolbarBackToTop", () => {
  2146. return this.shieldBackToTop();
  2147. });
  2148. this.initRightToolbarOffset();
  2149. domutils.ready(() => {
  2150. PopsPanel.execMenuOnce("csdn-blog-addGotoRecommandButton", () => {
  2151. this.addGotoRecommandButton();
  2152. });
  2153. });
  2154. },
  2155. /**
  2156. * 【添加】前往评论按钮,在返回顶部的下面
  2157. */
  2158. addGotoRecommandButton() {
  2159. log.info("【添加】前往评论按钮,在返回顶部的上面");
  2160. let gotoRecommandNode = document.createElement("a");
  2161. gotoRecommandNode.className = "option-box";
  2162. gotoRecommandNode.setAttribute("data-type", "gorecommand");
  2163. gotoRecommandNode.innerHTML = /*html*/
  2164. `
  2165. <img src="https://g.csdnimg.cn/side-toolbar/3.6/images/customer.png" alt="" srcset="">
  2166. <span class="show-txt" style="opacity:100;">前往<br>评论</span>
  2167. `;
  2168. gotoRecommandNode.addEventListener("click", function() {
  2169. let toolbarBoxElement = document.querySelector("#toolBarBox");
  2170. if (!toolbarBoxElement || !toolbarBoxElement.getClientRects().length) {
  2171. let $pcCommentBox = $("#pcCommentBox");
  2172. if ($pcCommentBox && $pcCommentBox.getClientRects().length) {
  2173. toolbarBoxElement = $pcCommentBox;
  2174. } else {
  2175. log.error("评论区处于隐藏状态");
  2176. return;
  2177. }
  2178. }
  2179. log.info("滚动到评论");
  2180. let toolbarBoxOffsetTop = toolbarBoxElement.getBoundingClientRect().top + window.scrollY;
  2181. let csdnToolBarElement = document.querySelector(
  2182. "#csdn-toolbar"
  2183. );
  2184. let csdnToolBarStyles = window.getComputedStyle(csdnToolBarElement);
  2185. let csdnToolBarHeight = csdnToolBarElement.clientHeight - parseFloat(csdnToolBarStyles.paddingTop) - parseFloat(csdnToolBarStyles.paddingBottom);
  2186. window.scrollTo({
  2187. top: toolbarBoxOffsetTop - csdnToolBarHeight - 8,
  2188. left: 0,
  2189. behavior: "smooth"
  2190. });
  2191. });
  2192. utils.waitNode(".csdn-side-toolbar").then(() => {
  2193. let targetElement = document.querySelector(
  2194. ".csdn-side-toolbar a:nth-last-child(2)"
  2195. );
  2196. targetElement.parentElement.insertBefore(
  2197. gotoRecommandNode,
  2198. targetElement.nextSibling
  2199. );
  2200. });
  2201. },
  2202. /**
  2203. * 初始化右侧工具栏的偏移(top、right)
  2204. */
  2205. initRightToolbarOffset() {
  2206. log.info("初始化右侧工具栏的偏移(top、right)");
  2207. addStyle(
  2208. /*css*/
  2209. `
  2210. .csdn-side-toolbar{
  2211. left: unset !important;
  2212. }
  2213. `
  2214. );
  2215. utils.waitNode(".csdn-side-toolbar").then(($sideToolbar) => {
  2216. domutils.css($sideToolbar, {
  2217. top: parseInt(PopsPanel.getValue("csdn-blog-rightToolbarTopOffset")) + "px",
  2218. right: parseInt(PopsPanel.getValue("csdn-blog-rightToolbarRightOffset")) + "px"
  2219. });
  2220. });
  2221. },
  2222. /**
  2223. * 屏蔽右侧工具栏
  2224. */
  2225. shieldRightToolbar() {
  2226. log.info("屏蔽右侧工具栏");
  2227. return CommonUtil.addBlockCSS(`div.csdn-side-toolbar`);
  2228. },
  2229. /**
  2230. * 【屏蔽】创作中心
  2231. */
  2232. shieldCreativeCenter() {
  2233. log.info("【屏蔽】创作中心");
  2234. return CommonUtil.addBlockCSS(
  2235. ".csdn-side-toolbar .sidetool-writeguide-box"
  2236. );
  2237. },
  2238. /**
  2239. * 【屏蔽】显示/隐藏侧栏
  2240. */
  2241. shieldShowOrSidebar() {
  2242. log.info("【屏蔽】显示/隐藏侧栏");
  2243. return CommonUtil.addBlockCSS(".csdn-side-toolbar a.sidecolumn");
  2244. },
  2245. /**
  2246. * 【屏蔽】新手引导
  2247. */
  2248. shieldBeginnerGuidance() {
  2249. log.info("【屏蔽】新手引导");
  2250. return CommonUtil.addBlockCSS(
  2251. '.csdn-side-toolbar a.option-box[data-type="guide"]'
  2252. );
  2253. },
  2254. /**
  2255. * 【屏蔽】客服
  2256. */
  2257. shieldCustomerService() {
  2258. log.info("【屏蔽】客服");
  2259. return CommonUtil.addBlockCSS(
  2260. '.csdn-side-toolbar a.option-box[data-type="cs"]'
  2261. );
  2262. },
  2263. /**
  2264. * 【屏蔽】举报
  2265. */
  2266. shieldReport() {
  2267. log.info("【屏蔽】举报");
  2268. return CommonUtil.addBlockCSS(
  2269. '.csdn-side-toolbar a.option-box[data-type="report"]'
  2270. );
  2271. },
  2272. /**
  2273. * 【屏蔽】返回顶部
  2274. */
  2275. shieldBackToTop() {
  2276. log.info("【屏蔽】返回顶部");
  2277. return CommonUtil.addBlockCSS(
  2278. '.csdn-side-toolbar a.option-box[data-type="gotop"]'
  2279. );
  2280. }
  2281. };
  2282. const CSDNBlogArticle = {
  2283. init() {
  2284. CSDNBlogArticleRightToolBar.init();
  2285. PopsPanel.execMenuOnce("csdn-blog-articleCenter", () => {
  2286. return this.articleCenter();
  2287. });
  2288. PopsPanel.execMenuOnce("csdn-blog-shieldLoginDialog", () => {
  2289. return this.shieldLoginDialog();
  2290. });
  2291. PopsPanel.execMenuOnce("csdn-blog-autoExpandContent", () => {
  2292. return this.autoExpandContent();
  2293. });
  2294. PopsPanel.execMenuOnce("csdn-blog-autoExpandCodeContent", () => {
  2295. return this.autoExpandCodeContent();
  2296. });
  2297. PopsPanel.execMenuOnce(
  2298. "csdn-blog-blockComment",
  2299. () => {
  2300. return this.blockComment();
  2301. },
  2302. (_, value) => {
  2303. return !value;
  2304. },
  2305. (_, newValue) => {
  2306. return !newValue;
  2307. }
  2308. );
  2309. PopsPanel.execMenuOnce(
  2310. "csdn-blog-bottomRecommendArticleEnable",
  2311. () => {
  2312. return this.shieldBottomRecommendArticle();
  2313. },
  2314. (_, value) => {
  2315. return !value;
  2316. },
  2317. (_, newValue) => {
  2318. return !newValue;
  2319. }
  2320. );
  2321. PopsPanel.execMenuOnce("csdn-blog-shieldBottomSkillTree", () => {
  2322. return this.shieldBottomSkillTree();
  2323. });
  2324. PopsPanel.execMenuOnce("csdn-blog-shieldBottomFloatingToolbar", () => {
  2325. return this.shieldBottomFloatingToolbar();
  2326. });
  2327. PopsPanel.execMenuOnce("csdn-blog-shieldLeftBlogContainerAside", () => {
  2328. return this.shieldLeftBlogContainerAside();
  2329. });
  2330. PopsPanel.execMenuOnce("csdn-blog-shieldRightDirectoryInformation", () => {
  2331. return this.shieldRightDirectoryInformation();
  2332. });
  2333. PopsPanel.execMenuOnce("csdn-blog-shieldArticleSearchTip", () => {
  2334. return this.shieldArticleSearchTip();
  2335. });
  2336. PopsPanel.execMenuOnce("csdn-blog-allowSelectContent", () => {
  2337. return this.allowSelectContent();
  2338. });
  2339. domutils.ready(() => {
  2340. PopsPanel.execMenuOnce("csdn-blog-identityCSDNDownload", () => {
  2341. this.identityCSDNDownload();
  2342. });
  2343. PopsPanel.execMenuOnce("csdn-blog-clickPreCodeAutomatically", () => {
  2344. this.clickPreCodeAutomatically();
  2345. });
  2346. PopsPanel.execMenuOnce("csdn-blog-restoreComments", () => {
  2347. this.restoreComments();
  2348. });
  2349. });
  2350. },
  2351. /**
  2352. * 点击代码块自动展开
  2353. */
  2354. clickPreCodeAutomatically() {
  2355. log.info("点击代码块自动展开");
  2356. document.addEventListener("click", function(event) {
  2357. var _a2;
  2358. let $click = event.target;
  2359. if ($click.localName !== "pre") {
  2360. return;
  2361. }
  2362. $click.style.setProperty("height", "auto");
  2363. (_a2 = $click.querySelector(".hide-preCode-box")) == null ? void 0 : _a2.remove();
  2364. });
  2365. },
  2366. /**
  2367. * 恢复评论到正确位置
  2368. */
  2369. restoreComments() {
  2370. log.info("恢复评论到正确位置-第一条评论");
  2371. utils.waitNode(".first-recommend-box").then(($firstRecommendBox) => {
  2372. let recommendBoxElement = document.querySelector(
  2373. ".recommend-box.insert-baidu-box.recommend-box-style"
  2374. );
  2375. recommendBoxElement.insertBefore(
  2376. $firstRecommendBox,
  2377. recommendBoxElement.firstChild
  2378. );
  2379. });
  2380. log.info("恢复评论到正确位置-第二条评论");
  2381. utils.waitNode(".second-recommend-box").then(($secondRecommendBox) => {
  2382. let recommendBoxElement = document.querySelector(
  2383. ".recommend-box.insert-baidu-box.recommend-box-style"
  2384. );
  2385. recommendBoxElement.insertBefore(
  2386. $secondRecommendBox,
  2387. recommendBoxElement.firstChild
  2388. );
  2389. });
  2390. },
  2391. /**
  2392. * 标识CSDN下载的链接
  2393. */
  2394. identityCSDNDownload() {
  2395. log.info("标识CSDN下载的链接");
  2396. document.querySelectorAll(
  2397. ".recommend-item-box[data-url*='https://download.csdn.net/']"
  2398. ).forEach((item) => {
  2399. if (PopsPanel.getValue("csdn-blog-removeResourceDownloadArticle")) {
  2400. item.remove();
  2401. } else {
  2402. item.querySelector(".content-box").style.setProperty("border", "2px solid red");
  2403. }
  2404. });
  2405. },
  2406. /**
  2407. * 全文居中
  2408. */
  2409. articleCenter() {
  2410. log.info("全文居中");
  2411. return addStyle(BlogArticleCenterCSS);
  2412. },
  2413. /**
  2414. * 屏蔽登录弹窗
  2415. */
  2416. shieldLoginDialog() {
  2417. log.info("屏蔽登录弹窗");
  2418. return CommonUtil.addBlockCSS(`.passport-login-container`);
  2419. },
  2420. /**
  2421. * 自动展开代码块
  2422. */
  2423. autoExpandCodeContent() {
  2424. log.info("自动展开代码块");
  2425. return [
  2426. CommonUtil.addBlockCSS("pre.set-code-hide .hide-preCode-box"),
  2427. addStyle(
  2428. /*css*/
  2429. `
  2430. pre.set-code-hide{
  2431. height: auto !important;
  2432. }
  2433. /* 自动展开代码块 */
  2434. .comment-list-box,
  2435. main div.blog-content-box pre {
  2436. max-height: none !important;
  2437. }
  2438. `
  2439. )
  2440. ];
  2441. },
  2442. /**
  2443. * 自动展开全文
  2444. */
  2445. autoExpandContent() {
  2446. log.info("自动展开全文");
  2447. return addStyle(
  2448. /*css*/
  2449. `
  2450. /* 自动展开全文 */
  2451. #article_content,
  2452. .user-article.user-article-hide {
  2453. height: auto !important;
  2454. overflow: auto !important;
  2455. }
  2456. `
  2457. );
  2458. },
  2459. /**
  2460. * 屏蔽评论区
  2461. */
  2462. blockComment() {
  2463. log.info("屏蔽评论区");
  2464. return CommonUtil.addBlockCSS(`#pcCommentBox`);
  2465. },
  2466. /**
  2467. * 屏蔽底部推荐文章
  2468. */
  2469. shieldBottomRecommendArticle() {
  2470. log.info("屏蔽底部推荐文章");
  2471. return CommonUtil.addBlockCSS(`main > div.recommend-box`);
  2472. },
  2473. /**
  2474. * 屏蔽底部xx技能树
  2475. */
  2476. shieldBottomSkillTree() {
  2477. log.info("屏蔽底部xx技能树");
  2478. return CommonUtil.addBlockCSS(`#treeSkill`);
  2479. },
  2480. /**
  2481. * 屏蔽底部悬浮工具栏
  2482. */
  2483. shieldBottomFloatingToolbar() {
  2484. log.info("屏蔽底部悬浮工具栏");
  2485. return CommonUtil.addBlockCSS(`#toolBarBox`);
  2486. },
  2487. /**
  2488. * 屏蔽左侧博客信息
  2489. */
  2490. shieldLeftBlogContainerAside() {
  2491. log.info("【屏蔽】左侧博客信息");
  2492. return CommonUtil.addBlockCSS(`aside.blog_container_aside`);
  2493. },
  2494. /**
  2495. * 【屏蔽】右侧目录信息
  2496. */
  2497. shieldRightDirectoryInformation() {
  2498. log.info("【屏蔽】右侧目录信息");
  2499. return CommonUtil.addBlockCSS("#rightAsideConcision", "#rightAside");
  2500. },
  2501. /**
  2502. * 屏蔽文章内的选中搜索悬浮提示
  2503. */
  2504. shieldArticleSearchTip() {
  2505. log.info("屏蔽文章内的选中搜索悬浮提示");
  2506. return CommonUtil.addBlockCSS(`#articleSearchTip`);
  2507. },
  2508. /**
  2509. * 允许选择内容
  2510. */
  2511. allowSelectContent() {
  2512. log.info("允许选择内容");
  2513. return addStyle(
  2514. /*css*/
  2515. `
  2516. #content_views,
  2517. #content_views pre,
  2518. #content_views pre code {
  2519. user-select: text !important;
  2520. }
  2521. `
  2522. );
  2523. }
  2524. };
  2525. 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";
  2526. 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}";
  2527. const CSDNWenKu = {
  2528. init() {
  2529. addStyle(WenkuCSS);
  2530. addStyle(ShieldCSS$3);
  2531. PopsPanel.execMenuOnce("csdn-wenku-shieldResourceRecommend", () => {
  2532. return this.shieldResourceRecommend();
  2533. });
  2534. PopsPanel.execMenuOnce("csdn-wenku-shieldRightUserInfo", () => {
  2535. return this.shieldRightUserInfo();
  2536. });
  2537. PopsPanel.execMenuOnce("csdn-wenku-shieldRightToolBar", () => {
  2538. return this.shieldRightToolBar();
  2539. });
  2540. },
  2541. /**
  2542. * 【屏蔽】资源推荐
  2543. */
  2544. shieldResourceRecommend() {
  2545. log.info("【屏蔽】资源推荐");
  2546. return CommonUtil.addBlockCSS("#recommend");
  2547. },
  2548. /**
  2549. * 【屏蔽】右侧用户信息
  2550. */
  2551. shieldRightUserInfo() {
  2552. log.info("【屏蔽】右侧用户信息");
  2553. return CommonUtil.addBlockCSS(".layout-right");
  2554. },
  2555. /**
  2556. * 【屏蔽】右侧悬浮工具栏
  2557. */
  2558. shieldRightToolBar() {
  2559. log.info("【屏蔽】右侧悬浮工具栏");
  2560. return CommonUtil.addBlockCSS(".csdn-side-toolbar");
  2561. }
  2562. };
  2563. const CSDNLink = {
  2564. init() {
  2565. PopsPanel.execMenuOnce("csdn-link-jumpRedirect", () => {
  2566. this.jumpRedirect();
  2567. });
  2568. },
  2569. /**
  2570. * 去除CSDN拦截其它网址的url并自动跳转
  2571. * @example
  2572. * https://link.csdn.net/?target=https%3A%2F%2Fjaist.dl.sourceforge.net%2Fproject%2Fportecle%2Fv1.11%2Fportecle-1.11.zip
  2573. */
  2574. jumpRedirect() {
  2575. try {
  2576. let urlSearchParams = new URLSearchParams(window.location.search);
  2577. const URL_KEY = "target";
  2578. if (urlSearchParams.has(URL_KEY)) {
  2579. let target = urlSearchParams.get(URL_KEY);
  2580. let jumpUrl = decodeURIComponent(target);
  2581. log.success(`跳转链接:${jumpUrl}`);
  2582. window.location.href = jumpUrl;
  2583. } else {
  2584. log.error("解析跳转的链接失败,原因:搜索参数中没有target参数");
  2585. }
  2586. } catch (error) {
  2587. Qmsg.error("跳转链接失败:" + error.message);
  2588. }
  2589. }
  2590. };
  2591. 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/* 全屏双十一红包 */\r\n.csdn-reapck-select {\r\n display: none !important;\r\n}\r\n";
  2592. 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";
  2593. const CSDNBlog = {
  2594. init() {
  2595. this.addCSS();
  2596. PopsPanel.execMenuOnce("csdn-blog-shieldTopToolbar", () => {
  2597. return this.shieldTopToolbar();
  2598. });
  2599. domutils.ready(() => {
  2600. PopsPanel.execMenuOnce("csdn-blog-removeClipboardHijacking", () => {
  2601. this.removeClipboardHijacking();
  2602. });
  2603. PopsPanel.execMenuOnce("csdn-blog-unBlockCopy", () => {
  2604. this.unBlockCopy();
  2605. });
  2606. });
  2607. },
  2608. /**
  2609. * 添加屏蔽CSS和功能CSS
  2610. */
  2611. addCSS() {
  2612. log.info("添加屏蔽CSS和功能CSS");
  2613. return [addStyle(BlogShieldCSS), addStyle(BlogCSS)];
  2614. },
  2615. /**
  2616. * 去除剪贴板劫持
  2617. */
  2618. removeClipboardHijacking() {
  2619. log.info("去除剪贴板劫持");
  2620. let $article_copyright = document.querySelector(".article-copyright");
  2621. if ($article_copyright) {
  2622. $article_copyright.remove();
  2623. }
  2624. if (_unsafeWindow.articleType) {
  2625. _unsafeWindow.articleType = 0;
  2626. }
  2627. if (_unsafeWindow.csdn && _unsafeWindow.csdn.copyright && _unsafeWindow.csdn.copyright.textData) {
  2628. _unsafeWindow.csdn.copyright.textData = "";
  2629. }
  2630. if (_unsafeWindow.csdn && _unsafeWindow.csdn.copyright && _unsafeWindow.csdn.copyright.htmlData) {
  2631. _unsafeWindow.csdn.copyright.htmlData = "";
  2632. }
  2633. },
  2634. /**
  2635. * 取消禁止复制
  2636. */
  2637. unBlockCopy() {
  2638. log.info("取消禁止复制");
  2639. domutils.on(
  2640. document,
  2641. "click",
  2642. function(event) {
  2643. let $click = event.target;
  2644. let $parent = $click.parentElement;
  2645. if (!$click.classList.contains("hljs-button")) {
  2646. return;
  2647. }
  2648. let $code = $parent.querySelector("code");
  2649. $code = $code || $parent;
  2650. utils.preventEvent(event);
  2651. let copyText = $code.innerText;
  2652. log.info(
  2653. "点击复制按钮复制内容:" + (copyText.length > 8 ? copyText.substring(0, 8) + "..." : copyText)
  2654. );
  2655. utils.setClip(copyText);
  2656. $click.setAttribute("data-title", "复制成功");
  2657. },
  2658. {
  2659. capture: true
  2660. }
  2661. );
  2662. let changeDataTitle = new utils.LockFunction(function(event) {
  2663. let $mouse = event.target;
  2664. if ($mouse.localName !== "pre") {
  2665. return;
  2666. }
  2667. let $hljsBtn = $mouse.querySelector(".hljs-button");
  2668. if ($hljsBtn) {
  2669. $hljsBtn.setAttribute("data-title", "复制");
  2670. }
  2671. });
  2672. domutils.on(
  2673. document,
  2674. ["mouseenter", "mouseleave"],
  2675. function(event) {
  2676. changeDataTitle.run(event);
  2677. },
  2678. {
  2679. capture: true
  2680. }
  2681. );
  2682. utils.waitNode("#content_views").then(($content_views) => {
  2683. var _a2;
  2684. if (_unsafeWindow.$) {
  2685. (_a2 = _unsafeWindow.$("#content_views")) == null ? void 0 : _a2.unbind("copy");
  2686. }
  2687. domutils.on(
  2688. $content_views,
  2689. "copy",
  2690. function(event) {
  2691. utils.preventEvent(event);
  2692. let selectText = _unsafeWindow.getSelection();
  2693. let copyText = selectText == null ? void 0 : selectText.toString();
  2694. log.info(
  2695. "Ctrl+C复制内容:" + (copyText.length > 8 ? copyText.substring(0, 8) + "..." : copyText)
  2696. );
  2697. utils.setClip(copyText);
  2698. return false;
  2699. },
  2700. {
  2701. capture: true
  2702. }
  2703. );
  2704. });
  2705. utils.waitNode(".hljs-button").then(() => {
  2706. setTimeout(() => {
  2707. $$(".hljs-button").forEach(($el) => {
  2708. $el.removeAttribute("onclick");
  2709. $el.removeAttribute("data-report-click");
  2710. $el.setAttribute("data-title", "复制");
  2711. });
  2712. }, 250);
  2713. });
  2714. },
  2715. /**
  2716. * 屏蔽顶部Toolbar
  2717. */
  2718. shieldTopToolbar() {
  2719. log.info("屏蔽顶部Toolbar");
  2720. return CommonUtil.addBlockCSS("#toolbarBox", "#csdn-toolbar");
  2721. }
  2722. };
  2723. const CSDN = {
  2724. init() {
  2725. if (CSDNRouter.isLink()) {
  2726. log.info("Router: 中转链接");
  2727. CSDNLink.init();
  2728. } else if (CSDNRouter.isHuaWeiCloudBlog()) {
  2729. log.info("Router: 华为云联盟");
  2730. CSDNHuaWeiCloud.init();
  2731. } else if (CSDNRouter.isBlog()) {
  2732. log.info("Router: 博客");
  2733. CSDNBlog.init();
  2734. if (CSDNRouter.isBlogArticle()) {
  2735. log.info("Router: 帖子");
  2736. CSDNBlogArticle.init();
  2737. }
  2738. } else if (CSDNRouter.isWenKu()) {
  2739. log.info("Router: 文库");
  2740. CSDNWenKu.init();
  2741. } else {
  2742. log.error("暂未适配,请反馈开发者:" + globalThis.location.href);
  2743. }
  2744. }
  2745. };
  2746. const M_CSDNLink = {
  2747. init() {
  2748. PopsPanel.execMenuOnce("m-csdn-link-jumpRedirect", () => {
  2749. CSDNLink.jumpRedirect();
  2750. });
  2751. }
  2752. };
  2753. const ShieldCSS$2 = "/* 右下角的 免费赢华为平板xxxx */\r\n.org-main-content .siderbar-box {\r\n display: none !important;\r\n}\r\n";
  2754. const M_CSDNHuaWeiCloud = {
  2755. init() {
  2756. addStyle(ShieldCSS$2);
  2757. PopsPanel.execMenuOnce("m-csdn-hua-wei-cloud-autoExpandContent", () => {
  2758. return CSDNHuaWeiCloud.autoExpandContent();
  2759. });
  2760. PopsPanel.execMenuOnce(
  2761. "m-csdn-hua-wei-cloud-blockBottomJoinTheCommunity",
  2762. () => {
  2763. return this.blockBottomJoinTheCommunity();
  2764. }
  2765. );
  2766. },
  2767. /**
  2768. * 【屏蔽】底部加入社区
  2769. */
  2770. blockBottomJoinTheCommunity() {
  2771. log.info("【屏蔽】底部加入社区");
  2772. return CommonUtil.addBlockCSS(".user-desc");
  2773. }
  2774. };
  2775. const ApiResponseCheck = {
  2776. isSuccessResponse(data) {
  2777. if (data == null) {
  2778. return false;
  2779. }
  2780. if (typeof data === "string") {
  2781. data = utils.toJSON(data);
  2782. }
  2783. return (data == null ? void 0 : data.code) === 200;
  2784. }
  2785. };
  2786. const CSDNFavoriteApi = {
  2787. /**
  2788. * 获取收藏夹信息
  2789. * @param url 当前url
  2790. */
  2791. async folderListWithCheck(url) {
  2792. let response = await httpx.get(
  2793. `https://mp-action.csdn.net/interact/wrapper/pc/favorite/v1/api/folderListWithCheck`,
  2794. {
  2795. data: {
  2796. url
  2797. },
  2798. fetch: true,
  2799. allowInterceptConfig: false,
  2800. headers: {
  2801. "User-Agent": utils.getRandomPCUA()
  2802. }
  2803. }
  2804. );
  2805. log.info(response);
  2806. if (!response.status || !ApiResponseCheck.isSuccessResponse(response.data.responseText)) {
  2807. log.error("获取收藏夹信息失败,请求异常");
  2808. Qmsg.error("获取收藏夹信息失败");
  2809. return;
  2810. }
  2811. let data = utils.toJSON(response.data.responseText);
  2812. return data.data.result;
  2813. },
  2814. /**
  2815. * 添加到某个收藏夹
  2816. */
  2817. async addFavoriteInFolds(requestData) {
  2818. let response = await httpx.post(
  2819. "https://mp-action.csdn.net/interact/wrapper/pc/favorite/v1/api/addFavoriteInFolds",
  2820. {
  2821. fetch: true,
  2822. data: requestData,
  2823. headers: {
  2824. "Content-Type": "application/json",
  2825. "User-Agent": utils.getRandomPCUA()
  2826. },
  2827. allowInterceptConfig: false
  2828. }
  2829. );
  2830. log.info(response);
  2831. if (!response.status || !ApiResponseCheck.isSuccessResponse(response.data.responseText)) {
  2832. log.error("添加收藏失败,请求异常", response);
  2833. Qmsg.error("添加收藏失败,请求异常");
  2834. return;
  2835. }
  2836. return true;
  2837. },
  2838. /**
  2839. * 检查收藏夹信息
  2840. * @param url
  2841. * @returns
  2842. * + true 已收藏
  2843. * + false 未收藏
  2844. */
  2845. async checkFavoriteByUrl(url) {
  2846. debugger;
  2847. let response = await httpx.get(
  2848. `https://mp-action.csdn.net/interact/wrapper/pc/favorite/v1/api/checkFavoriteByUrl`,
  2849. {
  2850. data: {
  2851. url
  2852. },
  2853. fetch: true,
  2854. allowInterceptConfig: false,
  2855. headers: {
  2856. "User-Agent": utils.getRandomPCUA()
  2857. }
  2858. }
  2859. );
  2860. log.info(response);
  2861. if (!response.status || !ApiResponseCheck.isSuccessResponse(response.data.responseText)) {
  2862. log.error("检查收藏夹状态失败,请求异常");
  2863. Qmsg.error("检查收藏夹状态失败,请求异常");
  2864. return;
  2865. }
  2866. let data = utils.toJSON(response.data.responseText);
  2867. return data.data;
  2868. },
  2869. /**
  2870. * 创建收藏夹
  2871. */
  2872. async createFolder(config) {
  2873. let response = await httpx.post(
  2874. `https://mp-action.csdn.net/interact/wrapper/pc/favorite/v1/api/createFolder`,
  2875. {
  2876. data: config,
  2877. fetch: true,
  2878. headers: {
  2879. Accept: "application/json, text/javascript, */*; q=0.01",
  2880. "Content-Type": "application/json",
  2881. "User-Agent": utils.getRandomPCUA()
  2882. },
  2883. allowInterceptConfig: false
  2884. }
  2885. );
  2886. log.info(response);
  2887. if (!response.status || !ApiResponseCheck.isSuccessResponse(response.data.responseText)) {
  2888. Qmsg.error("创建收藏夹失败");
  2889. return;
  2890. }
  2891. let data = utils.toJSON(response.data.responseText);
  2892. return data.data;
  2893. }
  2894. };
  2895. const M_CSDNBlogArticle = {
  2896. init() {
  2897. PopsPanel.execMenuOnce(
  2898. "m-csdn-blog-shieldTopToolbar",
  2899. () => {
  2900. return this.shieldTopToolbar();
  2901. },
  2902. (_, value) => !value,
  2903. (_, value) => !value
  2904. );
  2905. PopsPanel.execMenuOnce("m-csdn-blog-notLimitCodePreMaxHeight", () => {
  2906. return this.notLimitCodePreMaxHeight();
  2907. });
  2908. PopsPanel.execMenuOnce("m-csdn-blog-notLimitCommentMaxHeight", () => {
  2909. return this.notLimitCommentMaxHeight();
  2910. });
  2911. PopsPanel.execMenuOnce("m-csdn-blog-allowSelectText", () => {
  2912. return this.allowSelectText();
  2913. });
  2914. PopsPanel.execMenuOnce("m-csdn-blog-autoExpandContent", () => {
  2915. return this.autoExpandContent();
  2916. });
  2917. PopsPanel.execMenuOnce(
  2918. "m-csdn-blog-bottomArticleEnable",
  2919. () => {
  2920. return this.blockBottomArticle();
  2921. },
  2922. (_, value) => !value,
  2923. (_, value) => !value
  2924. );
  2925. PopsPanel.execMenuOnce(
  2926. "m-csdn-blog-comment-enable",
  2927. () => {
  2928. return this.blockComment();
  2929. },
  2930. (_, value) => !value,
  2931. (_, value) => !value
  2932. );
  2933. PopsPanel.execMenuOnce(
  2934. "m-csdn-blog-bottom-toolbar-enable",
  2935. () => {
  2936. return this.blockBottomToolBar();
  2937. },
  2938. (_, value) => !value,
  2939. (_, value) => !value
  2940. );
  2941. PopsPanel.execMenuOnce("m-csdn-blog-bottom-toolbar-always-bottom", () => {
  2942. return this.bottomToolBarAlwaysShow();
  2943. });
  2944. domutils.ready(() => {
  2945. PopsPanel.execMenuOnce("m-csdn-blog-removeAds", () => {
  2946. return this.removeAds();
  2947. });
  2948. PopsPanel.execMenuOnce("m-csdn-blog-refactoringRecommendation", () => {
  2949. this.refactoringRecommendation();
  2950. });
  2951. PopsPanel.execMenuOnce("m-csdn-blog-unBlockCopy", () => {
  2952. CSDNBlog.unBlockCopy();
  2953. });
  2954. PopsPanel.execMenuOnce(
  2955. "m-csdn-blog-bottom-toolbar-optimizationCollectButton",
  2956. () => {
  2957. this.optimizationCollectButton();
  2958. }
  2959. );
  2960. });
  2961. },
  2962. /**
  2963. * 屏蔽顶部Toolbar
  2964. */
  2965. shieldTopToolbar() {
  2966. log.info("屏蔽顶部Toolbar");
  2967. return [
  2968. CommonUtil.addBlockCSS("#csdn-toolbar"),
  2969. addStyle(
  2970. /*css*/
  2971. `
  2972. /* 内容顶部要归位 */
  2973. body #main,
  2974. .margin_sides{
  2975. margin-top: unset !important;
  2976. padding-top: unset !important;
  2977. }
  2978. #article .article_title{
  2979. margin-top: .32rem !important;
  2980. padding-top: unset !important;
  2981. }
  2982. `
  2983. )
  2984. ];
  2985. },
  2986. /**
  2987. * 重构底部推荐
  2988. */
  2989. refactoringRecommendation() {
  2990. function refactoring() {
  2991. document.querySelectorAll(".container-fluid").forEach((item) => {
  2992. var _a2, _b;
  2993. let url = "";
  2994. let title = "";
  2995. let content = "";
  2996. let img = "";
  2997. let isCSDNDownload = false;
  2998. let isCSDNEduDownload = false;
  2999. if (item.hasAttribute("data-url")) {
  3000. url = item.getAttribute("data-url");
  3001. title = (_a2 = item.querySelector(".recommend_title div.left")) == null ? void 0 : _a2.innerHTML;
  3002. if (!item.querySelector(".text")) {
  3003. return;
  3004. }
  3005. content = (_b = item.querySelector(".text")) == null ? void 0 : _b.innerHTML;
  3006. if (item.querySelectorAll(".recommend-img").length) {
  3007. item.querySelectorAll(".recommend-img").forEach((item2) => {
  3008. img += item2.innerHTML;
  3009. });
  3010. }
  3011. } else {
  3012. url = item.querySelector("a[data-type]").getAttribute("href");
  3013. title = item.querySelector(".recommend_title div.left").innerHTML;
  3014. content = item.querySelector(".text").innerHTML;
  3015. }
  3016. var _URL_ = new URL(url);
  3017. if (_URL_.host === "download.csdn.net" || _URL_.host === "www.iteye.com" && _URL_.pathname.match(/^\/resource/gi)) {
  3018. isCSDNDownload = true;
  3019. title = `<div class="component-box"><a class="praise" href="javascript:;">CSDN下载</a></div>` + title;
  3020. } else if (_URL_.origin.match(/edu.csdn.net/gi)) {
  3021. isCSDNEduDownload = true;
  3022. title = `<div class="component-box"><a class="csdn-edu-title" href="javascript:;">CSDN学院</a></div>` + title;
  3023. }
  3024. item.setAttribute("class", "GM-csdn-dl");
  3025. item.setAttribute("data-url", url);
  3026. 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>`;
  3027. item.addEventListener("click", function() {
  3028. if (PopsPanel.getValue("m-csdn-blog-openNewTab")) {
  3029. window.open(url, "_blank");
  3030. } else {
  3031. window.location.href = url;
  3032. }
  3033. });
  3034. if ((isCSDNDownload || isCSDNEduDownload) && PopsPanel.getValue("m-csdn-blog-removeResourceArticle")) {
  3035. item.remove();
  3036. }
  3037. });
  3038. }
  3039. let lockFunction = new utils.LockFunction(refactoring, 50);
  3040. utils.waitNode("#recommend").then(($recommend) => {
  3041. log.info("重构底部推荐");
  3042. lockFunction.run();
  3043. utils.mutationObserver($recommend, {
  3044. callback: () => {
  3045. lockFunction.run();
  3046. },
  3047. config: { childList: true, subtree: true, attributes: true }
  3048. });
  3049. });
  3050. },
  3051. /**
  3052. * 屏蔽底部文章
  3053. */
  3054. blockBottomArticle() {
  3055. log.info("屏蔽底部文章");
  3056. return CommonUtil.addBlockCSS("#recommend");
  3057. },
  3058. /**
  3059. * 屏蔽评论
  3060. */
  3061. blockComment() {
  3062. log.info("屏蔽评论");
  3063. return CommonUtil.addBlockCSS("#comment");
  3064. },
  3065. /**
  3066. * 去除广告
  3067. */
  3068. removeAds() {
  3069. log.info("去除广告");
  3070. return [
  3071. /* 登录窗口 */
  3072. CommonUtil.waitRemove(".passport-login-container"),
  3073. /* 打开APP */
  3074. CommonUtil.waitRemove(".btn_open_app_prompt_box.detail-open-removed"),
  3075. /* 广告 */
  3076. CommonUtil.waitRemove(".add-firstAd"),
  3077. /* 打开CSDN APP 小程序看全文 */
  3078. CommonUtil.waitRemove("div.feed-Sign-weixin"),
  3079. /* ios版本提示 */
  3080. CommonUtil.waitRemove("div.ios-shadowbox")
  3081. ];
  3082. },
  3083. /**
  3084. * 不限制代码块最大高度
  3085. */
  3086. notLimitCodePreMaxHeight() {
  3087. log.info("不限制代码块最大高度");
  3088. return addStyle(
  3089. /*css*/
  3090. `
  3091. pre{
  3092. max-height: unset !important;
  3093. }
  3094. `
  3095. );
  3096. },
  3097. /**
  3098. * 不限制评论区最大高度
  3099. */
  3100. notLimitCommentMaxHeight() {
  3101. log.info("不限制评论区最大高度");
  3102. return addStyle(
  3103. /*css*/
  3104. `
  3105. #comment{
  3106. max-height: none !important;
  3107. }
  3108. `
  3109. );
  3110. },
  3111. /**
  3112. * 允许选择文字
  3113. */
  3114. allowSelectText() {
  3115. log.info("允许选择文字");
  3116. return addStyle(
  3117. /*css*/
  3118. `
  3119. #content_views,
  3120. #content_views pre,
  3121. #content_views pre code{
  3122. webkit-touch-callout: text !important;
  3123. -webkit-user-select: text !important;
  3124. -khtml-user-select: text !important;
  3125. -moz-user-select: text !important;
  3126. -ms-user-select: text !important;
  3127. user-select: text !important;
  3128. }
  3129. `
  3130. );
  3131. },
  3132. /**
  3133. * 自动展开内容
  3134. */
  3135. autoExpandContent() {
  3136. log.info("自动展开内容");
  3137. return addStyle(
  3138. /*css*/
  3139. `
  3140. #content_views pre.set-code-hide,
  3141. .article_content{
  3142. height: 100% !important;
  3143. overflow: auto !important;
  3144. }
  3145. `
  3146. );
  3147. },
  3148. /**
  3149. * 屏蔽底部工具栏
  3150. */
  3151. blockBottomToolBar() {
  3152. log.info(`屏蔽底部工具栏`);
  3153. return CommonUtil.addBlockCSS("#operate");
  3154. },
  3155. /**
  3156. * 底部工具栏常驻
  3157. */
  3158. bottomToolBarAlwaysShow() {
  3159. log.info(`底部工具栏常驻`);
  3160. return addStyle(
  3161. /*css*/
  3162. `
  3163. /* 底部工具栏 */
  3164. #operate {
  3165. bottom: 0 !important;
  3166. }
  3167. `
  3168. );
  3169. },
  3170. /**
  3171. * 优化收藏按钮
  3172. */
  3173. optimizationCollectButton() {
  3174. log.info(`优化收藏按钮`);
  3175. utils.waitNode("#operate .collect-btn", 1e4).then(($collectBtn) => {
  3176. if (!$collectBtn) {
  3177. return;
  3178. }
  3179. domutils.on(
  3180. $collectBtn,
  3181. "click",
  3182. async (event) => {
  3183. utils.preventEvent(event);
  3184. let $isCollect = $collectBtn.querySelector(".collect");
  3185. let $unCollect = $collectBtn.querySelector(".uncollect");
  3186. let folderInfo = await CSDNFavoriteApi.folderListWithCheck(
  3187. window.location.origin + window.location.pathname
  3188. );
  3189. if (!folderInfo) {
  3190. return;
  3191. }
  3192. let isFavoriteFolderIdList = [];
  3193. folderInfo.forEach((item) => {
  3194. if (item.IsFavorite) {
  3195. isFavoriteFolderIdList.push(item.ID);
  3196. }
  3197. });
  3198. let createCollectItem = (data) => {
  3199. let folderId = data.ID;
  3200. let $item = domutils.createElement(
  3201. "li",
  3202. {
  3203. className: "csdn-collection-item",
  3204. innerHTML: (
  3205. /*html*/
  3206. `
  3207. <div class="csdn-collection-item_left">
  3208. <div class="csdn-collection-item_title">
  3209. <span class="title-m">${data.Name}</span>
  3210. </div>
  3211. <span class="csdn-collection-item_ext">
  3212. <span class="csdn-collection-item_length">${data.FavoriteNum}条内容</span>
  3213. <span class="dot">・</span>
  3214. <span class="csdn-collection-controls">${data.IsPrivate ? "私密" : "公开"}</span>
  3215. </span>
  3216. </div>
  3217. <span class="collect-btn">${data.IsFavorite ? "已收藏" : "收藏"}</span>
  3218. `
  3219. )
  3220. },
  3221. {
  3222. "data-is-collect": data.IsFavorite
  3223. }
  3224. );
  3225. $item.querySelector(".title-m");
  3226. let $contentLength = $item.querySelector(
  3227. ".csdn-collection-item_length"
  3228. );
  3229. $item.querySelector(
  3230. ".csdn-collection-controls"
  3231. );
  3232. let $collectBtn2 = $item.querySelector(".collect-btn");
  3233. domutils.on($collectBtn2, "click", async (event2) => {
  3234. let articleDetailUrl = _unsafeWindow.articleDetailUrl;
  3235. if (articleDetailUrl == null) {
  3236. articleDetailUrl = window.location.origin + window.location.pathname;
  3237. }
  3238. let articleId = _unsafeWindow.articleId;
  3239. if (articleId == null) {
  3240. log.error("获取文章ID失败");
  3241. Qmsg.error("获取文章ID失败");
  3242. return;
  3243. }
  3244. let username = _unsafeWindow.username;
  3245. if (username == null) {
  3246. log.error("获取文章作者失败");
  3247. Qmsg.error("获取文章作者失败");
  3248. return;
  3249. }
  3250. let articleTitle = _unsafeWindow.articleTitle;
  3251. if (articleTitle == null) {
  3252. articleTitle = document.title.replace(/-CSDN博客$/, "");
  3253. }
  3254. if (articleTitle == null) {
  3255. log.error("获取文章标题失败");
  3256. Qmsg.error("获取文章标题失败");
  3257. return;
  3258. }
  3259. let articleDesc = _unsafeWindow.articleDesc;
  3260. if (articleDesc == null) {
  3261. let $meta = $("meta[name='description']");
  3262. if ($meta) {
  3263. articleDesc = $meta.getAttribute("content");
  3264. }
  3265. }
  3266. if (articleDesc == null) {
  3267. log.error("获取文章描述失败");
  3268. Qmsg.error("获取文章描述失败");
  3269. return;
  3270. }
  3271. let folderIdList = [...isFavoriteFolderIdList];
  3272. let $loading = Qmsg.loading("处理中...");
  3273. try {
  3274. let checkResponse = await CSDNFavoriteApi.checkFavoriteByUrl(
  3275. articleDetailUrl
  3276. );
  3277. if (checkResponse == null) {
  3278. return;
  3279. }
  3280. log.info(folderId, checkResponse);
  3281. let toCollect = !checkResponse[folderId];
  3282. if (toCollect) {
  3283. log.info(`添加收藏`);
  3284. folderIdList.push(folderId);
  3285. } else {
  3286. log.info(`取消收藏`);
  3287. folderIdList.splice(folderIdList.indexOf(folderId), 1);
  3288. }
  3289. let response = await CSDNFavoriteApi.addFavoriteInFolds({
  3290. author: username,
  3291. url: articleDetailUrl,
  3292. source: "blog",
  3293. sourceId: articleId,
  3294. title: articleTitle,
  3295. description: articleDesc,
  3296. fromType: "PC",
  3297. username: data.Username,
  3298. folderIdList
  3299. });
  3300. if (!response) {
  3301. return;
  3302. }
  3303. let check_isCollect = await CSDNFavoriteApi.checkFavoriteByUrl(articleDetailUrl);
  3304. if (check_isCollect == null) {
  3305. return;
  3306. }
  3307. log.info(folderId, check_isCollect);
  3308. $item.setAttribute(
  3309. "data-is-collect",
  3310. (!!check_isCollect[folderId]).toString()
  3311. );
  3312. if (toCollect) {
  3313. if (!check_isCollect[folderId]) {
  3314. log.error("收藏失败", check_isCollect, folderId);
  3315. Qmsg.error("收藏失败");
  3316. } else {
  3317. log.success("收藏成功");
  3318. Qmsg.success("收藏成功");
  3319. domutils.text($collectBtn2, "已收藏");
  3320. if (!isFavoriteFolderIdList.includes(folderId)) {
  3321. isFavoriteFolderIdList.push(folderId);
  3322. }
  3323. data.FavoriteNum++;
  3324. }
  3325. } else {
  3326. if (!check_isCollect[folderId]) {
  3327. log.success("取消收藏成功");
  3328. Qmsg.success("取消收藏成功");
  3329. domutils.text($collectBtn2, "收藏");
  3330. if (isFavoriteFolderIdList.includes(folderId)) {
  3331. isFavoriteFolderIdList.splice(
  3332. isFavoriteFolderIdList.indexOf(folderId),
  3333. 1
  3334. );
  3335. }
  3336. data.FavoriteNum--;
  3337. } else {
  3338. log.error("取消收藏失败", check_isCollect, folderId);
  3339. Qmsg.error("取消收藏失败");
  3340. }
  3341. }
  3342. domutils.text($contentLength, `${data.FavoriteNum}条内容`);
  3343. let findValue = Object.values(check_isCollect).find(
  3344. (item) => item
  3345. );
  3346. if (findValue) {
  3347. domutils.show($isCollect, false);
  3348. domutils.hide($unCollect, false);
  3349. } else {
  3350. domutils.show($unCollect, false);
  3351. domutils.hide($isCollect, false);
  3352. }
  3353. $loading.close();
  3354. } catch (error) {
  3355. log.error(error);
  3356. } finally {
  3357. $loading.close();
  3358. }
  3359. });
  3360. return $item;
  3361. };
  3362. let $alert = __pops.alert({
  3363. title: {
  3364. text: "添加收藏夹",
  3365. position: "center"
  3366. },
  3367. content: {
  3368. text: (
  3369. /*html*/
  3370. `
  3371. <ul class="csdn-collection-items"></ul>
  3372. `
  3373. ),
  3374. html: true
  3375. },
  3376. btn: {
  3377. ok: {
  3378. enable: false
  3379. }
  3380. },
  3381. width: PanelUISize.setting.width,
  3382. height: PanelUISize.setting.height,
  3383. drag: true,
  3384. mask: {
  3385. enable: true
  3386. },
  3387. style: (
  3388. /*css*/
  3389. `
  3390. .csdn-collection-items{
  3391. --font-size: 16px;
  3392. }
  3393. .csdn-collection-items{
  3394. font-size: var(--font-size);
  3395. font-weight: 400;
  3396. padding: 0 20px 0;
  3397. margin: 24px 0;
  3398. overflow: auto;
  3399. -ms-scroll-chaining: none;
  3400. overscroll-behavior: contain;
  3401. }
  3402. .csdn-collection-item{
  3403. width: 100%;
  3404. height: 62px;
  3405. line-height: normal;
  3406. position: relative;
  3407. padding: 8px 12px;
  3408. cursor: pointer;
  3409. display: -webkit-box;
  3410. display: -ms-flexbox;
  3411. display: flex;
  3412. -webkit-box-align: center;
  3413. -ms-flex-align: center;
  3414. align-items: center;
  3415. -webkit-box-pack: justify;
  3416. -ms-flex-pack: justify;
  3417. justify-content: space-between;
  3418. border-bottom: 1px solid #f0f0f5;
  3419. }
  3420. .csdn-collection-item_left{
  3421. line-height: normal;
  3422. flex: 1;
  3423. overflow: hidden;
  3424. }
  3425. .csdn-collection-item_title{
  3426. overflow: hidden;
  3427. text-overflow: ellipsis;
  3428. white-space: nowrap;
  3429. width: 100%;
  3430. }
  3431. .csdn-collection-item_ext{
  3432. font-weight: 400;
  3433. color: #999aaa;
  3434. line-height: 17px;
  3435. margin-top: 8px;
  3436. font-size: .8em;
  3437. overflow: hidden;
  3438. text-overflow: ellipsis;
  3439. white-space: nowrap;
  3440. width: 100%;
  3441. display: inline-flex;
  3442. align-items: center;
  3443. }
  3444. .collect-btn{
  3445. color: #555666;
  3446. font-size: var(--font-size);
  3447. width: 64px;
  3448. height: 30px;
  3449. line-height: 30px;
  3450. border-radius: 20px;
  3451. text-align: center;
  3452. -webkit-transition: all .2s;
  3453. transition: all .2s;
  3454. border: 1px solid #ccccd8;
  3455. }
  3456. .csdn-collection-item[data-is-collect="true"] .collect-btn{
  3457. color: #999aaa;
  3458. background: rgba(232, 232, 237, .3);
  3459. border: 1px solid #e8e8ed;
  3460. }
  3461. /* .csdn-collection-item:hover{
  3462. background: #f5f6f7;
  3463. }
  3464. .csdn-collection-item:hover .collect-btn{
  3465. border: 1px solid #555666;
  3466. } */
  3467. `
  3468. )
  3469. });
  3470. let $collectionContainer = $alert.$shadowRoot.querySelector(
  3471. ".csdn-collection-items"
  3472. );
  3473. folderInfo.forEach((folderInfoItem) => {
  3474. let $item = createCollectItem(folderInfoItem);
  3475. $collectionContainer.appendChild($item);
  3476. });
  3477. },
  3478. { capture: true }
  3479. );
  3480. });
  3481. }
  3482. };
  3483. const ShieldCSS$1 = "/* 右下角的买一年送3个月的广告图标 */\r\n.blind_box {\r\n display: none !important;\r\n}\r\n";
  3484. const M_CSDNWenKu = {
  3485. init() {
  3486. addStyle(ShieldCSS$1);
  3487. PopsPanel.execMenuOnce("m-csdn-wenku-shieldBottomToolbar", () => {
  3488. return this.shieldBottomToolbar();
  3489. });
  3490. },
  3491. /**
  3492. * 【屏蔽】底部工具栏
  3493. */
  3494. shieldBottomToolbar() {
  3495. log.info("【屏蔽】底部工具栏");
  3496. return CommonUtil.addBlockCSS(`.page-container > div.btn`);
  3497. }
  3498. };
  3499. 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";
  3500. const M_CSDNDownload = {
  3501. init() {
  3502. PopsPanel.execMenuOnce("m-csdn-download-removeAds", () => {
  3503. return addStyle(CSDNBlockCSS);
  3504. });
  3505. PopsPanel.execMenuOnce(
  3506. "m-csdn-download-automaticallyExpandResourceIntroduction",
  3507. () => {
  3508. return this.automaticallyExpandResourceIntroduction();
  3509. }
  3510. );
  3511. },
  3512. /**
  3513. * 自动展开资源介绍
  3514. */
  3515. automaticallyExpandResourceIntroduction() {
  3516. log.info("自动展开资源介绍");
  3517. return [
  3518. CommonUtil.addBlockCSS("label.unfold-font"),
  3519. addStyle(
  3520. /*css*/
  3521. `
  3522. .resource-desc{
  3523. max-height: unset !important;
  3524. overflow: unset !important;
  3525. }
  3526. `
  3527. )
  3528. ];
  3529. }
  3530. };
  3531. const ShieldCSS = ".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/* 底部评论工具栏的抢沙发图片 */\r\n.comment-sofa-flag {\r\n display: none !important;\r\n}\r\n";
  3532. 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";
  3533. const M_CSDNBlog = {
  3534. init() {
  3535. this.addCSS();
  3536. },
  3537. /**
  3538. * 添加屏蔽CSS
  3539. */
  3540. addCSS() {
  3541. return [addStyle(ShieldCSS), addStyle(MBlogCSS)];
  3542. }
  3543. };
  3544. const M_CSDN = {
  3545. init() {
  3546. if (CSDNRouter.isLink()) {
  3547. log.info("Router: 中转链接");
  3548. M_CSDNLink.init();
  3549. } else if (CSDNRouter.isHuaWeiCloudBlog()) {
  3550. log.info("Router: 华为云联盟");
  3551. M_CSDNHuaWeiCloud.init();
  3552. } else if (CSDNRouter.isBlog()) {
  3553. log.info("Router: 博客");
  3554. M_CSDNBlog.init();
  3555. if (CSDNRouter.isBlogArticle()) {
  3556. log.info("Router: 文章");
  3557. M_CSDNBlogArticle.init();
  3558. }
  3559. } else if (CSDNRouter.isWenKu()) {
  3560. log.info("Router: 文库");
  3561. M_CSDNWenKu.init();
  3562. } else if (CSDNRouter.isDownload()) {
  3563. log.info("Router: 资源下载");
  3564. M_CSDNDownload.init();
  3565. } else {
  3566. log.error("暂未适配,请反馈开发者:" + globalThis.location.href);
  3567. }
  3568. }
  3569. };
  3570. PopsPanel.init();
  3571. let isMobile = utils.isPhone();
  3572. let CHANGE_ENV_SET_KEY = "change_env_set";
  3573. let chooseMode = _GM_getValue(CHANGE_ENV_SET_KEY);
  3574. GM_Menu.add({
  3575. key: CHANGE_ENV_SET_KEY,
  3576. text: `⚙ 自动: ${isMobile ? "移动端" : "PC端"}`,
  3577. autoReload: false,
  3578. isStoreValue: false,
  3579. showText(text) {
  3580. if (chooseMode == null) {
  3581. return text;
  3582. }
  3583. return text + ` 手动: ${chooseMode == 1 ? "移动端" : chooseMode == 2 ? "PC端" : "未知"}`;
  3584. },
  3585. callback: () => {
  3586. let allowValue = [0, 1, 2];
  3587. let chooseText = window.prompt(
  3588. "请输入当前脚本环境判定\n\n自动判断: 0\n移动端: 1\nPC端: 2",
  3589. "0"
  3590. );
  3591. if (!chooseText) {
  3592. return;
  3593. }
  3594. let chooseMode2 = parseInt(chooseText);
  3595. if (isNaN(chooseMode2)) {
  3596. Qmsg.error("输入的不是规范的数字");
  3597. return;
  3598. }
  3599. if (!allowValue.includes(chooseMode2)) {
  3600. Qmsg.error("输入的值必须是0或1或2");
  3601. return;
  3602. }
  3603. if (chooseMode2 == 0) {
  3604. _GM_deleteValue(CHANGE_ENV_SET_KEY);
  3605. } else {
  3606. _GM_setValue(CHANGE_ENV_SET_KEY, chooseMode2);
  3607. }
  3608. }
  3609. });
  3610. if (chooseMode != null) {
  3611. log.info(`手动判定为${chooseMode === 1 ? "移动端" : "PC端"}`);
  3612. if (chooseMode == 1) {
  3613. M_CSDN.init();
  3614. } else if (chooseMode == 2) {
  3615. CSDN.init();
  3616. } else {
  3617. Qmsg.error("意外,手动判定的值不在范围内");
  3618. _GM_deleteValue(CHANGE_ENV_SET_KEY);
  3619. }
  3620. } else {
  3621. if (isMobile) {
  3622. log.info("自动判定为移动端");
  3623. M_CSDN.init();
  3624. } else {
  3625. log.info("自动判定为PC端");
  3626. CSDN.init();
  3627. }
  3628. }
  3629.  
  3630. })(Qmsg, DOMUtils, Utils, pops);