Linkify Plain Text URLs

Turn plain text URLs into clickable links

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Linkify Plain Text URLs
// @version      1.0.2
// @author       salad: https://greasyfork.org/en/users/241444-salad
// @description  Turn plain text URLs into clickable links
// @namespace    https://greasyfork.org/users/241444
// @include      *
// @run-at       document-idle
// @grant        GM.registerMenuCommand
// @license      GPL-3.0-only
// ==/UserScript==

/* dunno who wrote this. I just converted a bookmarklet to a userscript. */

(function () {

  function linkifyPlainText() {

    document.body.normalize();

    function linkifyNode(n) {
      var M, R, currentNode;
      if (n.nodeType == 3) {
        const urlPosition = n.data.search(/https?:\/\/[^\s]*/);

        if (urlPosition < 0) return;

        M = n.splitText(urlPosition);
        R = M.splitText(RegExp.lastMatch.length);
        const linkTag = document.createElement("A");
        linkTag.href = M.data;
        linkTag.appendChild(M);
        R.parentNode.insertBefore(linkTag, R);

      } else if (n.tagName != "STYLE" && n.tagName != "SCRIPT" && n.tagName != "A")

      for (let i = 0; currentNode = n.childNodes[i]; ++i) {
        linkifyNode(currentNode);
      }
    }

    linkifyNode(document.body);

  }

  GM.registerMenuCommand('Linkify Plain Text URLs', linkifyPlainText);

})();