更好的知乎

改造知乎,包括:去掉重定向,去掉赞赏。

目前为 2022-08-29 提交的版本。查看 最新版本

// ==UserScript==
// @name         更好的知乎
// @namespace    http://tampermonkey.net/
// @version      0.1.3
// @description  改造知乎,包括:去掉重定向,去掉赞赏。
// @author       Ihurryup
// @match        https://*.zhihu.com/*
// @icon         https://static.zhihu.com/heifetz/favicon.ico
// @grant        none
// @license      AGPL
// @note         2022-08-29  0.1.3  添加代码一键复制功能
// ==/UserScript==

          function addNewStyle(newStyle) {
            var styleElement = document.getElementById('styles_js');

            if (!styleElement) {
                styleElement = document.createElement('style');
                styleElement.type = 'text/css';
                styleElement.id = 'styles_js';
                document.getElementsByTagName('head')[0].appendChild(styleElement);
            }

            styleElement.appendChild(document.createTextNode(newStyle));
        }


    function clearRediction(){
        for(link of document.querySelectorAll("a.external")) {
            var href = link.href
            var res = href.match("target=(.+)")
            if(res != null) link.href = decodeURIComponent(res[1])
        }
        for(link of document.querySelectorAll("a.LinkCard")){
            var href = link.href
            var res = href.match("target=(.+)")
            if(res != null) link.href = decodeURIComponent(res[1])
        }
    }


(function() {
    'use strict';
    addNewStyle(" div.Reward { display: none; } ")
    addNewStyle(".hljs-btn{\
    display: none;\
    position: absolute;\
    right: 4px;\
    top: 4px;\
    font-size: 12px;\
    color: #ffffff;\
    background-color: #9999AA;\
    padding: 2px 8px;\
    margin: 8px;\
    border-radius: 4px;\
    cursor: pointer;\
    box-shadow: 0 2px 4px rgb(0 0 0 / 5%), 0 2px 4px rgb(0 0 0 / 5%);\
}\
.hljs-btn:after{content: attr(data-title)}\
div.highlight:hover .hljs-btn{display: block}\
")
    for(let pre of document.querySelectorAll("div.highlight>pre")){
        pre.style="position: relative;overflow-x: auto;"
        let btn = document.createElement("div")
        btn.className="hljs-btn"
        btn.setAttribute("data-title","复制")
        btn.onclick=function(){
            let text = pre.innerText
            if (navigator.clipboard) {
                navigator.clipboard.writeText(text)
                btn.setAttribute("data-title","已成功复制")
            }
            setTimeout(function(){
                btn.setAttribute("data-title","复制")
            },3500)
        }
        pre.appendChild(btn)
    }
    setInterval(clearRediction,1000)

    
    // Your code here...
})();

QingJ © 2025

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