链接转换transformation to links

将网页内容中的链接转换为可点击跳转,免去手动复制

目前為 2022-06-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         链接转换transformation to links
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  将网页内容中的链接转换为可点击跳转,免去手动复制
// @author       code200
// @match        *://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @license      GPL License
// ==/UserScript==

(function() {
    const reg=/(^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$)|(http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)/g;
    GM_registerMenuCommand('已转换:' + (GM_getValue('transformation_count')==undefined?0:GM_getValue('transformation_count')) + '次(点击重置)', () => {
               GM_setValue('transformation_count', 0)
                        history.go(0);
            });
    let exclude=new Map;
    exclude.set('A',1);
    exclude.set('SCRIPT',1);
    function getNode(ele){
        var array = ele.childNodes;
        for(var i = 0;i < array.length;i++){
            var childNode = array[i];
            if(childNode.nodeType == 1){
                getNode(childNode);
            }else if(childNode.nodeType == 3){
                var textContent=childNode.textContent;
                if(reg.test(String(textContent))){
                    //if(exclude.get(childNode.parentElement.tagName)===1){
                    //    return;
                    //}
                    let newTextContent=textContent.replace(reg,function(arg1,arg2,arg3,arg4){
                        let textContent='<a href="'+arg1+'" style="color: red !important;border-bottom: 1px solid red !important;text-shadow: 0px 2px 10px #000 !important;" target="_blank">'+arg1+'</a>'
                        return textContent;
                    })
                    childNode.parentElement.innerHTML=newTextContent;
                    if(GM_getValue('transformation_count')==undefined){
                        GM_setValue('transformation_count', 1);
                    }else{
                        GM_setValue('transformation_count', GM_getValue('transformation_count')+1);
                    }

                }
            }
        }
    }
    setTimeout(()=>{
        var nodes = document.body;
        getNode(nodes);
    },1000);



})();