Greasy Fork

Greasy Fork is available in English.

loc添加超链接

添加超链接的同时,能够清除斯巴达、搬瓦工、vir、hetzner、dmit、绿云、RN的aff

目前为 2022-04-23 提交的版本。查看 最新版本

// ==UserScript==
// @name         loc添加超链接
// @namespace    http://tampermonkey.net/
// @version      0.4.2
// @description  添加超链接的同时,能够清除斯巴达、搬瓦工、vir、hetzner、dmit、绿云、RN的aff
// @author       Faxlok
// @match        https://hostloc.com/thread-*.html
// @match        https://hostloc.com/forum.php?mod=viewthread&tid=*&highlight=*
// @match        https://hostloc.com/forum.php?mod=viewthread&tid=*&page=*
// @icon         https://www.google.com/s2/favicons?domain=hostloc.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
       var content = document.querySelectorAll(".pcb");
       const regex = new RegExp('(?<!font size="2"><a href=")((?<!src="|href=")https?:\/\/.*?)(<|&nbsp;|,|,|[\u4e00-\u9fa5])', 'gm');

       for (var i = 0; i < content.length; i++)
       {
           //console.log(content[i].innerHTML);
           //console.log(regex.test(content[i].innerHTML));

           // 转换为超链接
           if (regex.test(content[i].innerHTML))
           {
             content[i].innerHTML = content[i].innerHTML.replace(regex,'<a href="$1" target="_blank">$1</a><');
           }
           // 去掉aff
           content[i].innerHTML = content[i].innerHTML.replace(/aff\.php/gm,'cart.php').replace(/aff=\d+/gm,'a=add').replace(/\/aff\/\w*|ref=\w+/gm,'');
       }
})();