From 21104a3964054cc9c0fbdebe9a37a00d2845a12e Mon Sep 17 00:00:00 2001 From: "adamlui@protonmail.com" Date: Sun, 15 Sep 2024 05:14:31 +0000 Subject: [PATCH] =?UTF-8?q?Updated=20log=20highlighting=20to=20ignore=20lo?= =?UTF-8?q?wercase=20state=20words=20=E2=86=9E=20[auto-sync=20from=20`adam?= =?UTF-8?q?lui/chatgpt-apps`]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- greasemonkey/bravegpt.user.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/greasemonkey/bravegpt.user.js b/greasemonkey/bravegpt.user.js index 2e78554a..3b1fcb30 100644 --- a/greasemonkey/bravegpt.user.js +++ b/greasemonkey/bravegpt.user.js @@ -148,7 +148,7 @@ // @description:zu Yengeza izimpendulo ze-AI ku-Brave Search (inikwa amandla yi-GPT-4o!) // @author KudoAI // @namespace https://kudoai.com -// @version 2024.9.14.6 +// @version 2024.9.14.7 // @license MIT // @icon https://media.bravegpt.com/images/icons/bravegpt/icon48.png?0a9e287 // @icon64 https://media.bravegpt.com/images/icons/bravegpt/icon64.png?0a9e287 @@ -265,7 +265,10 @@ msg: { working: 'color: #ff8000', warning: 'color: red' } }, - regEx: { greenVals: /\b(?:true|ON|\d+)\b|success\W?/i, redVals: /\b(?:false|OFF)\b|error\W?/i, purpVals: /[ '"]\w+['"]?: /i }, + regEx: { + greenVals: { caseInsensitive: /\b(?:true|\d+)\b|success\W?/i, caseSensitive: /\bON\b/ }, + redVals: { caseInsensitive: /\b(?:false)\b|error\W?/i, caseSensitive: /\BOFF\b/ }, + purpVals: /[ '"]\w+['"]?: /i }, prettifyObj(obj) { return JSON.stringify(obj) .replace(/([{,](?=")|(?:"):)/g, '$1 ') // append spaces to { and " @@ -286,14 +289,23 @@ prefixStyle = log.styles.prefix.base + log.styles.prefix[msgType], baseMsgStyle = log.styles.msg[msgType], msgStyles = [] + // Combine regex + const allPatterns = Object.values(log.regEx).flatMap(val => + val instanceof RegExp ? [val] : Object.values(val).filter(val => val instanceof RegExp)) + const combinedPattern = new RegExp(allPatterns.map(pattern => pattern.source).join('|'), 'g') + // Combine args into finalMsg, color chars let finalMsg = logType == 'error' && args.length == 1 ? 'ERROR: ' : '' args.forEach((arg, idx) => { - finalMsg += idx == 1 ? ': ' : idx > 1 ? ' ' : '' // separate multi-args - finalMsg += arg?.toString().replace(new RegExp(Object.values(log.regEx).map(value => value.source).join('|'), 'ig'), match => { - if (log.regEx.greenVals.test(match)) { msgStyles.push('color: green', baseMsgStyle) ; return `%c${match}%c` } - else if (log.regEx.redVals.test(match)) { msgStyles.push('color: red', baseMsgStyle) ; return `%c${match}%c` } - else if (log.regEx.purpVals.test(match)) { msgStyles.push('color: #dd29f4', baseMsgStyle) ; return `%c${match}%c` } + finalMsg += idx > 0 ? (idx === 1 ? ': ' : ' ') : '' // separate multi-args + finalMsg += arg?.toString().replace(combinedPattern, match => { + const matched = ( + Object.values(log.regEx.greenVals).some(val => { + if (val.test(match)) { msgStyles.push('color: green', baseMsgStyle) ; return true }}) + || Object.values(log.regEx.redVals).some(val => { + if (val.test(match)) { msgStyles.push('color: red', baseMsgStyle) ; return true }})) + if (!matched && log.regEx.purpVals.test(match)) { msgStyles.push('color: #dd29f4', baseMsgStyle) } + return `%c${match}%c` }) })