URL Linkify

Replace URLs in text with clickable links

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         URL Linkify
// @namespace    http://tampermonkey/url-linkify
// @version      1.1
// @description  Replace URLs in text with clickable links
// @author       Hoopengo
// @match        https://www.google.com/sorry/index*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @license      Apache 2.0
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const urlRegex = /URL:\s*(\S+)/g; // regex to match "URL: ..." strings
    const textNodes = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);

    while (textNodes.nextNode()) {
        const textNode = textNodes.currentNode;

        if (textNode.nodeType === Node.TEXT_NODE && textNode.textContent.match(urlRegex)) {
            const urlMatches = textNode.textContent.match(urlRegex);

            for (let i = 0; i < urlMatches.length; i++) {
                const url = urlMatches[i].replace('URL:', '').trim();
                const link = document.createElement('a');
                link.href = url;
                link.textContent = url;

                // replace the URL text with the link element
                const replacementNode = textNode.splitText(textNode.textContent.indexOf(urlMatches[i]));
                replacementNode.replaceWith(link);
            }
        }
    }
})();