ACT.Zhihu.DM.Stay

Stay in web not app, browsing experience optimization.

  1. // ==UserScript==
  2. // @name ACT.Zhihu.DM.Stay
  3. // @name:zh-CN ACT.知乎.DM.Stay
  4. // @description Stay in web not app, browsing experience optimization.
  5. // @description:zh-CN 留在网络而非应用,网站浏览体验优化。
  6. // @author ACTCD
  7. // @version 20220722.1
  8. // @license GPL-3.0-or-later
  9. // @namespace ACTCD/Userscripts
  10. // @supportURL https://github.com/ACTCD/Userscripts#contact
  11. // @homepageURL https://github.com/ACTCD/Userscripts
  12. // @match *://*.zhihu.com/*
  13. // @grant none
  14. // @inject-into content
  15. // @run-at document-start
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. "use strict";
  20.  
  21. if (location.href == "https://www.zhihu.com/signin?next=%2F")
  22. location.replace("https://www.zhihu.com/explore"); // Index Login jump
  23.  
  24. function cleaner() {
  25. //=D
  26. document.querySelector(".Modal-wrapper button.Modal-closeButton")?.click(); // Cover Login banner
  27. //=D/search
  28. document
  29. .querySelector(".SearchBar-tool input")
  30. ?.setAttribute("placeholder", ""); // Recommended
  31. document
  32. .querySelectorAll(".AutoComplete-menu .AutoComplete-group")
  33. .forEach((e) => {
  34. e.querySelector(".SearchBar-topSearchItem") &&
  35. e.style.setProperty("display", "none"); // Recommended
  36. });
  37. //=D/question
  38. document.querySelector(".QuestionHeader .QuestionRichText-more")?.click(); // Content collapse
  39. document
  40. .querySelector(".QuestionHeader-footer.is-fixed")
  41. ?.classList.remove("is-fixed"); // Fix space
  42. //=M/search
  43. document
  44. .querySelector(".MobileAppHeader-searchBox input[type=search]")
  45. ?.setAttribute("placeholder", ""); // Recommended
  46. //=M/question
  47. document.querySelector(".ContentItem-expandButton")?.click(); // Content collapse
  48. document
  49. .querySelector(".RichContent-actions.is-fixed")
  50. ?.classList.remove("is-fixed"); // Fix space
  51. //=Common
  52. document
  53. .querySelectorAll('a[href^="https://link.zhihu.com/"]')
  54. .forEach((e) => {
  55. const url = new URL(e.href);
  56. e.href = url.searchParams.get("target") ?? e.href;
  57. });
  58. }
  59.  
  60. new MutationObserver(cleaner).observe(document, {
  61. subtree: true,
  62. childList: true,
  63. });
  64.  
  65. function DOMContentLoaded() {
  66. cleaner();
  67. }
  68.  
  69. if (document.readyState === "loading") {
  70. document.addEventListener("DOMContentLoaded", DOMContentLoaded);
  71. } else {
  72. DOMContentLoaded();
  73. }
  74.  
  75. const style = document.createElement("style");
  76. style.textContent = `/* Global style */
  77. /*=D/question */
  78. .Question-mainColumnLogin { display: none !important; } /* Embed Login banner */
  79. .List .Pc-word { display: none !important; } /* AD */
  80. .Sticky .AppBanner { display: none !important; } /* Embed App banner */
  81. .Sticky .Pc-card { display: none !important; } /* AD */
  82. /*=M */
  83. .MobileAppHeader-downloadLink { visibility: hidden !important; } /* Top App banner */
  84. .OpenInAppButton,.OpenInApp { display: none !important; } /* Float App banner */
  85. /*=M/explore */
  86. #js-openInApp { display: none !important; } /* Top App banner */
  87. /*=M/search */
  88. .MobileHotSearch-container { display: none !important; } /* Recommended */
  89. .MobileHistorySearch-container { padding-top: 15px !important; } /* Fix space */
  90. /*=M/question */
  91. .RelatedReadings { display: none !important; } /* Recommended */
  92. .HotQuestions { display: none !important; } /* Recommended */
  93. .MBannerAd { display: none !important; } /* AD */
  94. `;
  95.  
  96. if (document.head) {
  97. document.head.append(style);
  98. } else {
  99. new MutationObserver((mutationList, observer) => {
  100. document.head && (observer.disconnect(), document.head.append(style));
  101. }).observe(document, { subtree: true, childList: true });
  102. }
  103. })();