// this doesn't properly deal with eg, .gov.uk .co.ck etc function parseDomain(host){ var chunks = host.split(".") if (chunks.length == 1) return chunks[0] else return chunks[chunks.length - 2] } function escapeHtml(txt) { if (!txt) { return ""; } // txt = annoyingCaps(txt) return $("").text(txt).html() } URLRegex = /((\b(http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi; PicRegex = /\.(jpg|jpeg|png|gif|bmp|svg|fid)$/i; RecipRegex = /(^|\s)@\w+/g; TopicRegex = /(^|\s)#\w+/g; function getImagesAsArray(text) { var imgs = [] var urls = text.match(URLRegex) if (urls === null) return imgs for (var i = 0; i' + text + ' '; } function recipientReplace(atText, recips) { recips = recips || []; var space = ''; if (atText[0] == ' ') { atText = atText.slice(1); space = ' '; } var nick = atText.slice(1).toLowerCase(); var matchedRecip; for (var i = 0; i < recips.length; i++) { if (recips[i].toLowerCase() == nick) { matchedRecip = recips[i]; break; } } if (matchedRecip) { return space + '@' + matchedRecip + ''; } else { return space + atText; } } function linkify(text, recips) { LastMsgContainsImage = false; var recipWrapper = function(text) { return recipientReplace(text, recips); }; return text .replace(URLRegex, linkReplace) .replace(RecipRegex, recipWrapper) .replace(TopicRegex, topicReplace); } // use this in escapeHtml to turn everyone's text lIkE tHiS function annoyingCaps(text){ var chunks = text.split(" ") for(var i=0; i"; } else if (type == 'youtube') { Youtube.startAnimation(); return "" + "" + "" } else if (type == 'midi') { return ' '+uri.file+'' } else if (type == 'wav') { return ' '+uri.file+'' } else return "" + url + ""; } function getUriType(uri){ if (PicRegex.test(uri.file.toLowerCase())) return "image"; var domain = parseDomain(uri.host) if (domain == "gstatic" && uri.path == "/images" && 'q' in uri.queryKey) return "image"; // actual image url = uri.queryKey['q'].split(":").slice(2).join(":") but often the original image is broken... if (domain == "youtube" && ('v' in uri.queryKey || uri.anchor.indexOf('v') != -1)) return "youtube"; if (uri.path.substr(-4) == ".mid" || uri.path.substr(-5) == ".midi") return "midi" if (uri.path.substr(-4) == ".wav") return "wav" return "link"; } function linkifyWithoutImage(text) { LastMsgContainsImage = false return text.replace(URLRegex, linkReplaceWithoutImage); } function linkReplaceWithoutImage(url){ var urlWithoutParams = url.replace(/\?.*$/i, ""); linkUrl = url.indexOf('http://') == 0 ? url : 'http://' + url; return "" + url + "" }