页面小优化(知乎/CSDN/简书)

(知乎:移除登录(不可用)弹窗、免登录(不可用)查看回答;CSDN:移除登录(不可用)弹窗、免登录(不可用)复制;简书:移除登录(不可用)弹窗;)

  1. // ==UserScript==
  2. // @name 页面小优化(知乎/CSDN/简书)
  3. // @icon https://avatars.githubusercontent.com/u/43409097?v=4
  4. // @namespace http://tampermonkey.net/
  5. // @version 2.1.0
  6. // @description (知乎:移除登录(不可用)弹窗、免登录(不可用)查看回答;CSDN:移除登录(不可用)弹窗、免登录(不可用)复制;简书:移除登录(不可用)弹窗;)
  7. // @author leekbillow
  8. // @homepage https://github.com/leekbillow/customTampermonkey
  9. // @match https://*.zhihu.com/*
  10. // @match https://*.blog.csdn.net/*
  11. // @match https://*.jianshu.com/*
  12. // @grant GM_addStyle
  13. // @grant GM_setClipboard
  14. // @grant GM_xmlhttpRequest
  15. // @run-at document-end
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. "use strict";
  20.  
  21. switch (true) {
  22. case /\bblog\.csdn\.net\b(?!\.)/.test(location.hostname): {
  23. // CSDN
  24. GM_addStyle(`
  25. .passport-login-container,
  26. #passportbox
  27. {
  28. display:none!important
  29. }
  30. code
  31. {
  32. user-select:text!important;
  33. }
  34. .hljs-button
  35. {
  36. display:none!important;
  37. }
  38. `);
  39. document.body.querySelector("#content_views").oncopy = function () {
  40. GM_setClipboard(getSelection().toString());
  41. };
  42. break;
  43. }
  44. case /\bzhihu\.com\b(?!\.)/.test(location.hostname): {
  45. // 知乎
  46. // 不移除搜索结果
  47. if (location.pathname === "/search") document.querySelector(".List").removeChild = () => null;
  48. //添加限制样式
  49. let bhuStyle = GM_addStyle(`
  50. .Modal-wrapper,
  51. .Modal-backdrop,
  52. .signFlowModal
  53. {
  54. display:none!important;
  55. }
  56. `);
  57. // 弹窗数量,专栏为2
  58. let rubbishDialogQuantity = 1 + /\bzhuanlan\.zhihu\.com\b(?!\.)/.test(location.hostname),
  59. clicked = [];
  60. // 取消首次自动弹出登录(不可用)框,解除监听
  61. let removeStyle = function () {
  62. bhuStyle.remove();
  63. },
  64. targetNode = document.body,
  65. observerOptions = {
  66. childList: true,
  67. subtree: true,
  68. },
  69. observer = new MutationObserver(function (mutationList, observer) {
  70. let rubbishDialogCloseButtons = document.querySelectorAll(".Modal-closeButton");
  71. if (rubbishDialogCloseButtons.length > 0) {
  72. // 关闭弹窗
  73. rubbishDialogCloseButtons.forEach((E) => {
  74. if (clicked.includes(E)) return;
  75. E.click();
  76. clicked.push(E);
  77. if (--rubbishDialogQuantity < 1) {
  78. observer.disconnect();
  79. let loginButton = document.querySelector(".AppHeader-login");
  80. loginButton && (loginButton.onclick = () => removeStyle());
  81. }
  82. });
  83. // 添加查看回答按钮
  84. const extendxButtons = document.querySelectorAll(".Button.ContentItem-rightButton.ContentItem-expandButton");
  85. extendxButtons.forEach((E) => {
  86. const url = E.parentElement.parentElement.querySelector('.ContentItem.AnswerItem>[itemprop="url"]').getAttribute("content"),
  87. answerId = url.split("/").pop(),
  88. directViewButton = E.cloneNode();
  89. directViewButton.innerHTML = "我™要看回答";
  90. directViewButton.setAttribute("style", "bottom: 35px");
  91. directViewButton.onclick = async () => {
  92. try {
  93. const { responseText } = await GM.xmlHttpRequest({
  94. method: "get",
  95. url: `https://www.zhihu.com/appview/v2/answer/${answerId}?native=0&omni=1&sds=2&X-AD=canvas_version%3Av%3D5.1%3Bsetting%3Acad%3D0&seg_like_open=0`,
  96. }),
  97. newWindow = window.open("", answerId, "popup,width=850,height=1000,left=200,top=200"),
  98. content = responseText,
  99. document = newWindow.document;
  100. newWindow.sandbox = "allow-same-origin";
  101. document.open();
  102. document.write(content);
  103. document.close();
  104. newWindow.onload = () => {
  105. const imgs = document.querySelectorAll("[data-actualsrc]"),
  106. scripts = document.querySelectorAll("script"),
  107. norequiredSelector = [".css-199kefw", ".css-i8ps43", ".css-1gcwqws", ".css-1yuc9s4", ".AnswerToolbar-wrapper"];
  108. imgs.forEach((img) => {
  109. img.setAttribute("src", img.getAttribute("data-actualsrc"));
  110. });
  111. scripts.forEach((script) => script.remove());
  112. norequiredSelector.forEach((selector) => document.querySelector(selector)?.remove());
  113. document.querySelector(".AnswerPage-content").style = "user-select:text";
  114. };
  115. } catch (err) {
  116. console.log(err);
  117. }
  118. };
  119. E.insertAdjacentElement("afterend", directViewButton);
  120. });
  121. } else return;
  122. });
  123. observer.observe(targetNode, observerOptions);
  124. //3秒后移除监听
  125. setTimeout(() => (observer.disconnect(), removeStyle()), 3000);
  126. break;
  127. }
  128. case /\bjianshu\.com\b(?!\.)/.test(location.hostname): {
  129. // 简书
  130. GM_addStyle(`
  131. body>div:last-child
  132. {
  133. display:none!important
  134. }
  135. body
  136. {
  137. overflow:auto!important
  138. }
  139. `);
  140. break;
  141. }
  142. default:
  143. break;
  144. }
  145. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址