rualark / Log Highlighter

// ==UserScript==
// @name     Log Highlighter
// @version  1.3
// @author   aark
// @grant    none
// @license  MIT
// @include  https://storage.*
// @include  https://paste.*
// @updateURL https://openuserjs.org/meta/rualark/Log_Highlighter.meta.js
// @downloadURL https://openuserjs.org/src/scripts/rualark/Log_Highlighter.user.js
// ==/UserScript==

function highlight(st, pattern, color, word=true) {
  let rpattern = pattern;
  if (word) {
    rpattern = '\\b' + rpattern + '\\b';
  }
  rpattern = `(${rpattern})(?!(.(?!<span ))*<\/span>)`;
  const regexp = new RegExp(rpattern, 'gi');
  return st.replace(regexp, `<span style="color:${color}">${pattern}</span>`)
}

function highlightInSt(st) {
    st = highlight(st, '\nE ', 'red', false);
    st = highlight(st, 'critical', 'red');
    st = highlight(st, 'fatal', 'red');
    st = highlight(st, 'unable to', 'red');
    st = highlight(st, 'did not pass', 'red');
    st = highlight(st, 'teardown', 'red');
    st = highlight(st, 'object has no attribute', 'red');
    st = highlight(st, 'AttributeError', 'red');
    st = highlight(st, 'Unable to', 'red');
    st = highlight(st, 'No pairs found', 'red');
    st = highlight(st, 'Core dump', 'red');
    st = highlight(st, 'Warnings', 'red');
    st = highlight(st, 'Warning', 'red');
    st = highlight(st, 'AssertionError', 'red');
    st = highlight(st, 'Errors', 'red');
    st = highlight(st, 'Error', 'red');
    st = highlight(st, 'Failed', 'red');
    st = highlight(st, 'Failure', 'red');
    st = highlight(st, 'Fail', 'red');
    st = highlight(st, 'Killed', 'red');
    st = highlight(st, 'uncaught exception', 'red');
    st = highlight(st, 'unhandled exception', 'red');
    st = highlight(st, 'Exceptions', 'red');
    st = highlight(st, 'Exception', 'red');
    st = highlight(st, 'Terminated', 'red');
    st = highlight(st, 'Termination', 'red');
    st = highlight(st, 'Successful', 'green');
    st = highlight(st, 'Success', 'green');
    st = highlight(st, 'Good', 'green');
    st = highlight(st, 'OK', 'green');
  	return st;
}

function highlightLog() {
  let els = document.getElementsByTagName("*");
  for(let i = 0, l = els.length; i < l; i++) {
    let el = els[i];
    let st = el.innerHTML;
    if (!st.includes('\n')) continue;
    st = highlightInSt(st);
    el.innerHTML = st;
  }
}

setTimeout(highlightLog, 2000);