知乎直接看

不用打开app就能看知乎回答、看评论,去广告,使用此脚本不要登录知乎账号,否则会被知乎禁止浏览

// ==UserScript==
// @name  知乎直接看
// @author  大萌主
// @version      7.9
// @description 不用打开app就能看知乎回答、看评论,去广告,使用此脚本不要登录知乎账号,否则会被知乎禁止浏览
// @match  *://www.zhihu.com/*
// @exclude https://www.zhihu.com/search?*
// @exclude *://zhuanlan.zhihu.com/*
// @run-at document-start
// @namespace https://greasyfork.org/users/452911
// ==/UserScript==

//知乎直接看
(function(){
    var customUserAgent = 'Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/84.0.4147.105 mobile Safari/537.36 SearchCraft baiduboxapp';
 
    Object.defineProperty(navigator, 'userAgent', {
        value: customUserAgent,
        writable: false
    });

    console.log(navigator.userAgent);
})();

function updateElements() {
  // 获取所有button元素
  const buttons = document.querySelectorAll('button');

  // 为每个button元素添加点击事件处理程序
  buttons.forEach((button) => {
    button.addEventListener('click', () => {
      setTimeout(() => {
        // 获取所有具有类名.css-1k10w8f的元素
        const elements = document.querySelectorAll('.css-1k10w8f');

        // 遍历这些元素,并更新它们的文本内容
        elements.forEach((element) => {
          element.textContent = "双击关闭评论";
        });
      }, 500); // 500毫秒延迟
    });
  });
}

// 每隔5秒执行updateElements函数
setInterval(updateElements, 5000);

document.addEventListener('dblclick', function() {
    var element = document.querySelector('.css-169m58j');
    if (element) {
        var event = new MouseEvent('click', {
            view: window,
            bubbles: true,
            cancelable: true
        });
        element.dispatchEvent(event);
    }
});

setTimeout(function(){
    //执行css
    const style = document.createElement('style');
    style.innerHTML = `
        DIV.KfeCollection-VipRecommendCard,
        A.MBannerAd,
        A.MHotFeedAd,
        .MRelateFeedAd,
        .WeiboAd-wrap,
        div[id^="div-gpt-ad"] {
            display: none !important;
        }
        DIV.css-tpyajk {
            width: 55%;
        }
    `;
    document.head.appendChild(style);
}, 1000);

if (!window.location.href.includes("/question/")) {
    setTimeout(function() {
        'use strict';

        // 创建一个包含搜索图标的元素 (使用图片)
        var searchIcon = document.createElement("div");
        searchIcon.innerHTML = "<img src='https://s11.ax1x.com/2024/03/04/pFB6YeU.png' style='width: 23px; height: 23px;'>";
        searchIcon.style.cssText = "position: fixed; top: 15px; left: 200px; cursor: pointer; z-index: 2;";

        // 设置点击搜索图标时的处理函数
        searchIcon.onclick = function() {
            window.location.href = "https://www.zhihu.com/search?type=content&q=";
        };

        // 将搜索图标添加到页面中
        document.body.appendChild(searchIcon);
    }, 500); // 延迟500毫秒执行
}