直接跳转知乎、简书的外链

直接跳转知乎和简书的外链

目前为 2020-06-17 提交的版本。查看 最新版本

// ==UserScript==ww
// @name         直接跳转知乎、简书的外链
// @namespace    https://github.com/XanderWang
// @version      0.1.0
// @description  直接跳转知乎和简书的外链
// @author       XanderWang
// @icon         https://i.loli.net/2020/05/29/DxSmHAy2o53FdUY.png
// @match        *://*.shiyanlou.com/*
// @match        *://*.jianshu.com/*
// @match        *://*.zhihu.com/*
// @match        *://*.csdn.net/*
// @match        *://*.imooc.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    // Your code here...
    function addLink(e) {
        e.preventDefault()
        var pagelink = '\nRead more: ' + document.location.href
        var copytext = window.getSelection()
        var clipdata = e.clipboardData || window.clipboardData
        if (clipdata) {
            clipdata.setData('Text', copytext)
        }
    }
    document.addEventListener('copy', addLink)

    function jumpUrl() {
        /// 获取所有 a 标签
        var documents = document.getElementsByTagName("a");
        for (var i = 0; i < documents.length; i++) {
            var _href = decodeURIComponent(documents[i].href)
            var _hrefArrays = _href.split("http")
            if( _hrefArrays.length == 3 ) {
                var realHref = "http" + _hrefArrays[2]
                console.log('ori', _href, 'real', realHref)
                documents[i].href = realHref
            }
            // if(_href.indexOf("link.jianshu.com") != -1) {
            //     documents[i].href = decodeURIComponent(_href.split("?t=")[1])
            // } else if(_href.indexOf("link.zhihu.com") != -1) {
            //     documents[i].href = decodeURIComponent(_href.split("target==")[1])
            // }
        }
    }
    jumpUrl();
    window.onscroll = function() { 
        setTimeout(function() { 
            jumpUrl()
        }, 500)
    }
    
})();

QingJ © 2025

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