Replace true url

将页面中所有text为网址,href却不一致的a标签替换的工具

目前為 2019-12-23 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Replace true url
// @namespace    https://www.frank6.com/
// @version      0.2
// @description  将页面中所有text为网址,href却不一致的a标签替换的工具
// @author       Frank
// @grant        none
// @include      http*
// ==/UserScript==
// @require      https://code.jquery.com/jquery-3.3.1.min.js
(function() {
    'use strict';
    $('a').each(function(index,item){
        var regex = /^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*(:\d+)?(\/((\.)?(\?)?=?&?[a-zA-Z0-9_-](\?)?)*)*$/i;
        if(regex.test(item.text)){
            item.href = item.text;
        }
    });
})();