mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 21:17:01 +02:00
Fixed url parsing breaking with text formatting! <3
This commit is contained in:
parent
6bed25ee27
commit
d32fc6ab86
2 changed files with 56 additions and 12 deletions
|
@ -52,6 +52,22 @@
|
||||||
var $ChatLog; // The scrolling chat log.
|
var $ChatLog; // The scrolling chat log.
|
||||||
var $ChatInputText; // The text field for entering text.
|
var $ChatInputText; // The text field for entering text.
|
||||||
var userName;
|
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
|
//Start George Function
|
||||||
//Function provided by George Deac
|
//Function provided by George Deac
|
||||||
|
@ -62,11 +78,30 @@
|
||||||
|
|
||||||
$.fn.linky = function (options) {
|
$.fn.linky = function (options) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
var $el = $(this),
|
var $el = $(this);
|
||||||
linkifiedContent = _linkify($el, options);
|
var content = $el.html();
|
||||||
var formattedContent = replaceFormatting(linkifiedContent);
|
|
||||||
|
|
||||||
$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
|
linkTo: "twitter" // Let's default to Twitter
|
||||||
},
|
},
|
||||||
extendedOptions = $.extend(defaultOptions, options),
|
extendedOptions = $.extend(defaultOptions, options),
|
||||||
elContent = $el.html(),
|
elContent = $el,
|
||||||
// Regular expression courtesy of Matthew O'Riordan, see: http://goo.gl/3syEKK
|
// 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;
|
matches;
|
||||||
|
|
||||||
// Linkifying URLs
|
// Linkifying URLs
|
||||||
|
@ -121,7 +155,7 @@
|
||||||
// For any URLs present, unless they are already identified within
|
// For any URLs present, unless they are already identified within
|
||||||
// an `a` element, linkify them.
|
// an `a` element, linkify them.
|
||||||
function _linkifyUrls(matches, $el) {
|
function _linkifyUrls(matches, $el) {
|
||||||
var elContent = $el.html();
|
var elContent = $el;
|
||||||
|
|
||||||
$.each(matches, function () {
|
$.each(matches, function () {
|
||||||
|
|
||||||
|
|
|
@ -112,10 +112,15 @@ function connectWebSocket(timeout) {
|
||||||
console.log('disconnected');
|
console.log('disconnected');
|
||||||
|
|
||||||
timeout = timeout | 0;
|
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 () {
|
Script.setTimeout(function () {
|
||||||
connectWebSocket(timeout);
|
connectWebSocket(timeout);
|
||||||
}, timeout + 1000);
|
}, timeout);
|
||||||
} else {
|
} else {
|
||||||
wsReady = -1;
|
wsReady = -1;
|
||||||
}
|
}
|
||||||
|
@ -128,13 +133,18 @@ function sendWS(msg, timeout) {
|
||||||
ws.send(JSON.stringify(msg));
|
ws.send(JSON.stringify(msg));
|
||||||
} else {
|
} else {
|
||||||
timeout = timeout | 0;
|
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 () {
|
Script.setTimeout(function () {
|
||||||
if (wsReady === -1) {
|
if (wsReady === -1) {
|
||||||
connectWebSocket();
|
connectWebSocket();
|
||||||
}
|
}
|
||||||
sendWS(msg, timeout);
|
sendWS(msg, timeout);
|
||||||
}, timeout + 1000);
|
}, timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,7 +191,7 @@ function go2(msg) {
|
||||||
var dest = false;
|
var dest = false;
|
||||||
var domainsList = [];
|
var domainsList = [];
|
||||||
try {
|
try {
|
||||||
domainsList = Script.require("http://metaverse.darlingvr.club:8081/goto.json");
|
domainsList = Script.require(gotoJSONUrl + "?" + Date.now());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue