RIC0H / RGL Linkify Main

// ==UserScript==
// @name         RGL Linkify Main
// @namespace    RGL Linkify Main
// @description  Turns plain text links into hyperlinks on the RenegadeLine forum
// @include      https://renegadeline.com
// @include      https://renegadeline.com/*
// @version      1.4
// @author       RIC0H
// @grant        none
// @license      MIT
// @updateURL    https://openuserjs.org/src/scripts/RIC0H/RGL_Linkify_Main.user.js
// @downloadURL  https://openuserjs.org/src/scripts/RIC0H/RGL_Linkify_Main.user.js
// ==/UserScript==

// allow pasting

	var urlRegex = /\b(https?:\/\/[^\s+\"\<\>]+)/ig;
	var snapTextElements = document.evaluate("//text()[not(ancestor::a) " + 
		"and not(ancestor::script) and not(ancestor::style) and " + 
		"contains(translate(., 'HTTP', 'http'), 'http')]", 
		document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
	for (var i = snapTextElements.snapshotLength - 1; i >= 0; i--) {
		var elmText = snapTextElements.snapshotItem(i);
		if (urlRegex.test(elmText.nodeValue)) {
			var elmSpan = document.createElement("span");
			var sURLText = elmText.nodeValue;
			elmText.parentNode.replaceChild(elmSpan, elmText);
			urlRegex.lastIndex = 0;
			for (var match = null, lastLastIndex = 0;
				 (match = urlRegex.exec(sURLText)); ) { 
				elmSpan.appendChild(document.createTextNode(
				sURLText.substring(lastLastIndex, match.index))); 
				var elmLink = document.createElement("a"); 
				elmLink.setAttribute("href", match[0]); 
				elmLink.appendChild(document.createTextNode(match[0])); 
				elmSpan.appendChild(elmLink); 
				lastLastIndex = urlRegex.lastIndex;
			}
			elmSpan.appendChild(document.createTextNode(
				sURLText.substring(lastLastIndex)));
			elmSpan.normalize();
		}
	}