Greasy Fork is available in English.

[via]知乎直接看 修改

不用打开知乎app,直接看文章

  1. // ==UserScript==
  2. // @name [via]知乎直接看 修改
  3. // @version 3.0
  4. // @license Anti 996 License
  5. // @namespace https://viayoo.com/
  6. // @homepageURL https://app.viayoo.com/addons/16
  7. // @author 谷花泰
  8. // @modifier qidian55
  9. // @description 不用打开知乎app,直接看文章
  10. // @run-at document-start
  11. // @match *://zhihu.com/*
  12. // @match *://www.zhihu.com/*
  13. // @exclude *://www.zhihu.com/search?*
  14.  
  15.  
  16. // @grant none
  17. // @webRequest {"selector":"https://static.zhihu.com/heifetz/mobile.app.55f00d73470cd90b80cf.js","action":"cancel"}
  18. // ==/UserScript==
  19. (function () {
  20. Object.defineProperties(window.navigator, {
  21. 'userAgent': {
  22. enumerable: true,
  23. value: 'Mozilla/5.0 (Windows Phone 10)'
  24. },
  25. 'appVersion': {
  26. enumerable: true,
  27. value: '5.0 (Windows Phone 10)'
  28. },
  29. 'platform': {
  30. enumerable: true,
  31. value: 'Win32'
  32. }
  33. });
  34. class FixView {
  35. constructor() {
  36. this.init();
  37. };
  38. init() {
  39. const search = document.querySelector('.MobileAppHeader-searchBox');
  40. !search && this.addSearch();
  41. };
  42. addSearch() {
  43. const menu = document.querySelector('.MobileAppHeader-actions');
  44. const searchBox = document.createElement('div');
  45. const search = document.createElement('div');
  46. searchBox.setAttribute('style', `
  47. width: 100%;
  48. height: 100%;
  49. display: flex;
  50. align-items: center;
  51. justify-content: center;
  52. `);
  53. searchBox.className = 'via-zhihu-search';
  54. search.setAttribute('style', `
  55. width: 80%;
  56. height: 32px;
  57. border-radius: 20px;
  58. border: 1px solid #ebebeb;
  59. background-color: rgba(235, 235, 235, 0.7);
  60. display: flex;
  61. align-items: center;
  62. padding-left: 10px;
  63. `);
  64. search.addEventListener('click', () => {
  65. location.href = 'https://www.zhihu.com/search?type=content&q=';
  66. }, true);
  67. search.innerHTML = this.getSearchSvg();
  68. searchBox.appendChild(search);
  69. menu.parentNode.insertBefore(searchBox, menu);
  70. };
  71. getSearchSvg() {
  72. return `<svg class="Zi Zi--Search" fill="#999" viewBox="0 0 24 24" width="18" height="18"><path d="M17.068 15.58a8.377 8.377 0 0 0 1.774-5.159 8.421 8.421 0 1 0-8.42 8.421 8.38 8.38 0 0 0 5.158-1.774l3.879 3.88c.957.573 2.131-.464 1.488-1.49l-3.879-3.878zm-6.647 1.157a6.323 6.323 0 0 1-6.316-6.316 6.323 6.323 0 0 1 6.316-6.316 6.323 6.323 0 0 1 6.316 6.316 6.323 6.323 0 0 1-6.316 6.316z" fill-rule="evenodd"></path></svg>`;
  73. };
  74. };
  75. function hideDownApp() {
  76. const style = document.createElement('style');
  77. style.innerHTML = `
  78. .MobileAppHeader-downloadLink, .css-wfkf2m, .css-1gapyfo, .css-189wwwq, DIV.Popover, .MBannerAd, .RelatedReadings, .HotQuestions, .KfeCollection-VipRecommendCard, .css-1ildg7g, DIV.oia-action-bar
  79. {
  80. display: none !important;
  81. }
  82. .css-1aq8hf9 {
  83. width: 80% !important;
  84. }
  85. `;
  86. document.querySelector('head').appendChild(style);
  87. };
  88. function observe({ targetNode, config = {}, callback = () => { } }) {
  89. if (!targetNode) {
  90. return;
  91. };
  92.  
  93. config = Object.assign({
  94. attributes: true,
  95. childList: true,
  96. subtree: true
  97. }, config);
  98.  
  99. const observer = new MutationObserver(callback);
  100. observer.observe(targetNode, config);
  101. };
  102. try {
  103. console.log('嘿嘿嘿');
  104. observe({
  105. targetNode: document.documentElement,
  106. config: {
  107. attributes: false
  108. },
  109. callback(mutations, observer) {
  110. const mysearch = document.querySelector('.via-zhihu-search');
  111. const menu = document.querySelector('.MobileAppHeader-actions');
  112. const zhihuSearch = document.querySelector('.MobileAppHeader-searchBox');
  113. if (!mysearch && menu && !zhihuSearch) {
  114. new FixView();
  115. };
  116. }
  117. });
  118. hideDownApp();
  119. } catch (err) {
  120. console.log('知乎直接看:', err)
  121. };
  122. })();