From d32fc6ab8672a6b8f424d28678c1c7c3deda128a Mon Sep 17 00:00:00 2001 From: Fluffy Jenkins Date: Tue, 21 Jan 2020 22:02:53 +0000 Subject: [PATCH 1/3] Fixed url parsing breaking with text formatting! <3 --- scripts/communityModules/chat/FloofChat.html | 48 +++++++++++++++++--- scripts/communityModules/chat/FloofChat.js | 20 ++++++-- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/scripts/communityModules/chat/FloofChat.html b/scripts/communityModules/chat/FloofChat.html index ccfc547b2e..feca052665 100644 --- a/scripts/communityModules/chat/FloofChat.html +++ b/scripts/communityModules/chat/FloofChat.html @@ -52,6 +52,22 @@ var $ChatLog; // The scrolling chat log. var $ChatInputText; // The text field for entering text. var userName; + var urlRegEx = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;,:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+,~%\/\.\w\-]*)?\??(?:[\-\+=&;,:%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g; + + function reverseMatches(msg) { + var con = []; + var matches = msg.match(urlRegEx); + if (matches === null) { + matches = []; + } + for (var i = 0; i <= matches.length; i++) { + var sp = msg.split(matches[i], 2); + console.log(sp); + con.push(sp[0]); + msg = sp[1]; + } + return con; + } //Start George Function //Function provided by George Deac @@ -62,11 +78,30 @@ $.fn.linky = function (options) { return this.each(function () { - var $el = $(this), - linkifiedContent = _linkify($el, options); - var formattedContent = replaceFormatting(linkifiedContent); + var $el = $(this); + var content = $el.html(); - $el.html(formattedContent); + var match = content.match(urlRegEx); + var matchLength = match === null ? 0 : match.length; + var cons = reverseMatches(content); + + var con = []; + var tent = []; + var con_tent = []; + + for (var i = 0; i < matchLength; i++) { + tent.push(_linkify(match[i], options)); + } + + for (var i = 0; i < cons.length; i++) { + con.push(replaceFormatting(cons[i])); + } + + for (var i = 0; i < con.length; i++) { + con_tent.push(con[i], tent[i]); + } + + $el.html(con_tent.join("")); }); }; @@ -92,9 +127,8 @@ linkTo: "twitter" // Let's default to Twitter }, extendedOptions = $.extend(defaultOptions, options), - elContent = $el.html(), + elContent = $el, // Regular expression courtesy of Matthew O'Riordan, see: http://goo.gl/3syEKK - urlRegEx = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;,:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+,~%\/\.\w\-]*)?\??(?:[\-\+=&;,:%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g, matches; // Linkifying URLs @@ -121,7 +155,7 @@ // For any URLs present, unless they are already identified within // an `a` element, linkify them. function _linkifyUrls(matches, $el) { - var elContent = $el.html(); + var elContent = $el; $.each(matches, function () { diff --git a/scripts/communityModules/chat/FloofChat.js b/scripts/communityModules/chat/FloofChat.js index 2e9a08f241..8028fd95d9 100644 --- a/scripts/communityModules/chat/FloofChat.js +++ b/scripts/communityModules/chat/FloofChat.js @@ -112,10 +112,15 @@ function connectWebSocket(timeout) { console.log('disconnected'); timeout = timeout | 0; - if (!shutdownBool && timeout < (30 * 1000)) { + if (!shutdownBool) { + if (timeout > (30 * 1000)) { + timeout = 30 * 1000; + } else if (timeout < (30 * 1000)) { + timeout += 1000; + } Script.setTimeout(function () { connectWebSocket(timeout); - }, timeout + 1000); + }, timeout); } else { wsReady = -1; } @@ -128,13 +133,18 @@ function sendWS(msg, timeout) { ws.send(JSON.stringify(msg)); } else { timeout = timeout | 0; - if (!shutdownBool && timeout < (30 * 1000)) { + if (!shutdownBool) { + if (timeout > (30 * 1000)) { + timeout = 30 * 1000; + } else if (timeout < (30 * 1000)) { + timeout += 1000; + } Script.setTimeout(function () { if (wsReady === -1) { connectWebSocket(); } sendWS(msg, timeout); - }, timeout + 1000); + }, timeout); } } } @@ -181,7 +191,7 @@ function go2(msg) { var dest = false; var domainsList = []; try { - domainsList = Script.require("http://metaverse.darlingvr.club:8081/goto.json"); + domainsList = Script.require(gotoJSONUrl + "?" + Date.now()); } catch (e) { // } From 553b7d1f38020fbfd4984f56e8f0b14ae7174946 Mon Sep 17 00:00:00 2001 From: Fluffy Jenkins Date: Tue, 21 Jan 2020 22:54:35 +0000 Subject: [PATCH 2/3] Code Review Changes --- scripts/communityModules/chat/FloofChat.html | 29 ++++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/scripts/communityModules/chat/FloofChat.html b/scripts/communityModules/chat/FloofChat.html index feca052665..23c30adf69 100644 --- a/scripts/communityModules/chat/FloofChat.html +++ b/scripts/communityModules/chat/FloofChat.html @@ -55,18 +55,17 @@ var urlRegEx = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;,:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+,~%\/\.\w\-]*)?\??(?:[\-\+=&;,:%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g; function reverseMatches(msg) { - var con = []; + var result = []; var matches = msg.match(urlRegEx); if (matches === null) { matches = []; } for (var i = 0; i <= matches.length; i++) { - var sp = msg.split(matches[i], 2); - console.log(sp); - con.push(sp[0]); - msg = sp[1]; + var split = msg.split(matches[i], 2); + result.push(split[0]); + msg = split[1]; } - return con; + return result; } //Start George Function @@ -83,25 +82,25 @@ var match = content.match(urlRegEx); var matchLength = match === null ? 0 : match.length; - var cons = reverseMatches(content); + var messageParts = reverseMatches(content); - var con = []; - var tent = []; - var con_tent = []; + var messageFormatted = []; + var urlLinkified = []; + var completeMessage = []; for (var i = 0; i < matchLength; i++) { - tent.push(_linkify(match[i], options)); + urlLinkified.push(_linkify(match[i], options)); } - for (var i = 0; i < cons.length; i++) { - con.push(replaceFormatting(cons[i])); + for (var i = 0; i < messageParts.length; i++) { + messageFormatted.push(replaceFormatting(messageParts[i])); } for (var i = 0; i < con.length; i++) { - con_tent.push(con[i], tent[i]); + completeMessage.push(messageFormatted[i], urlLinkified[i]); } - $el.html(con_tent.join("")); + $el.html(completeMessage.join("")); }); }; From f77f629cad671be922020cc7c86bff153f99dab9 Mon Sep 17 00:00:00 2001 From: Fluffy Jenkins Date: Wed, 22 Jan 2020 02:56:53 +0000 Subject: [PATCH 3/3] Fixed bug caused by code review changes uwu --- scripts/communityModules/chat/FloofChat.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/communityModules/chat/FloofChat.html b/scripts/communityModules/chat/FloofChat.html index 23c30adf69..04410ff44b 100644 --- a/scripts/communityModules/chat/FloofChat.html +++ b/scripts/communityModules/chat/FloofChat.html @@ -96,7 +96,7 @@ messageFormatted.push(replaceFormatting(messageParts[i])); } - for (var i = 0; i < con.length; i++) { + for (var i = 0; i < messageFormatted.length; i++) { completeMessage.push(messageFormatted[i], urlLinkified[i]); }