diff --git a/goon/browserassets/js/browserOutput.js b/goon/browserassets/js/browserOutput.js index 565a3535982..f700d2ff028 100644 --- a/goon/browserassets/js/browserOutput.js +++ b/goon/browserassets/js/browserOutput.js @@ -72,6 +72,8 @@ var opts = { 'enableEmoji': true }; +var regexHasError = false; //variable to check if regex has excepted + function outerHTML(el) { var wrap = document.createElement('div'); wrap.appendChild(el.cloneNode(true)); @@ -91,6 +93,19 @@ if (typeof String.prototype.trim !== 'function') { }; } +//Polyfill for string.prototype.includes. Why the fuck. Just why the fuck. +if (!String.prototype.includes) { + String.prototype.includes = function(search, start) { + 'use strict'; + + if (search instanceof RegExp) { + throw TypeError('first argument must not be a RegExp'); + } + if (start === undefined) { start = 0; } + return this.indexOf(search, start) !== -1; + }; +} + //Shit fucking piece of crap that doesn't work god fuckin damn it function linkify(text) { var rex = /((?:$1") //disabling regex disables html matching too + if(el.innerText.toString().toLowerCase().includes(opts.highlightTerms[i].toLowerCase())) //match normally + el.innerHTML = ''+el.innerHTML+'' //encloseincludes continue; } + var rexp; + try{ + rexp = new RegExp(opts.highlightTerms[i],"gmi") + } catch(e){ + el.innerHTML+='
Your highlight regex - '+opts.highlightTerms[i]+' - is malformed. Thrown exception: '+e+'' + regexHasError = true; + return; + } el.innerHTML = el.innerHTML.replace(rexp,"$0") //i cant figure out a proper, non snowflakey way to let people select the group that gets highlighted } } @@ -575,7 +598,7 @@ $(function() { 'spingDisabled': getCookie('pingdisabled'), 'shighlightTerms': getCookie('highlightterms'), 'shighlightColor': getCookie('highlightcolor'), - 'shighlightRegexEnable': getCookie('highlightregexenable'), + 'shighlightRegexEnable': getCookie('highlightregexenable') == "true", 'shideSpam': getCookie('hidespam'), 'darkChat': getCookie('darkChat'), }; @@ -1027,6 +1050,8 @@ $(function() { } else { opts.highlightColor = color; } + regexHasError = false; //they changed the regex so it might be valid now + var $popup = $('#highlightPopup').closest('.popup'); $popup.remove();