Greasy Fork is available in English.
网页中文本转为可点击链接 添加颜色下划线
当前为
// ==UserScript==
// @name 网页文本转链接
// @description 网页中文本转为可点击链接 添加颜色下划线
// @version 2.4
// @author WJ
// @match *://*/*
// @license MIT
// @grant none
// @namespace http://greasyfork.icu/users/914996
// ==/UserScript==
(function(){
document.head.insertAdjacentHTML('beforeend','<style>.url-link{color:#348A87;text-decoration:underline}</style>');
const r=/\b[\w.:/?=%&#-]{3,}\.(?:app|aero|aer|art|asia|beer|biz|cat|cc|chat|ci|cloud|club|cn|com|cool|coop|co|dev|edu|email|fit|fun|gov|group|hk|host|icu|info|ink|int|io|jobs|kim|love|ltd|luxe|me|mil|mobi|moe|museum|name|net|nl|network|one|online|org|plus|post|press|pro|red|ren|run|ru|shop|site|si|space|store|tech|tel|top|travel|tv|tw|uk|us|video|vip|wang|website|wiki|wml|work|ws|xin|xyz|yoga|zone)(?!\w)[\w.:/?=%&#-]*/gi;
const w=document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT,{acceptNode:n=>['TEXTAREA','BUTTON','SCRIPT','SELECT','OPTION','STYLE','CODE','PRE','A'].includes(n.parentNode.tagName)?0:1});
const p=[];
while(n=w.nextNode()){
if(!r.test(n.textContent))continue;
const s=document.createElement('span');
s.innerHTML=n.textContent.replace(r,m=>`<a href="${/^https?:\/\//i.test(m)?'':'https://'}${m}" class="url-link" target="_blank">${m}</a>`);
p.push([n,s])};
p.forEach(([n,s])=>n.parentNode.replaceChild(s,n));
})();