// ==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 // @downloadURL none // ==/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=''+arg1+'' 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); })();