Skip to content

Commit 2878282

Browse files
committed
Reduced/eliminated backtracking in regex ↞ [auto-sync from https://github.com/adamlui/ai-web-extensions/tree/main/bravegpt]
1 parent 5741a17 commit 2878282

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

chatgpt/bravegpt/bravegpt.user.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
// @description:zu Yengeza izimpendulo ze-AI ku-Brave Search (inikwa amandla yi-GPT-4o!)
149149
// @author KudoAI
150150
// @namespace https://kudoai.com
151-
// @version 2025.3.22.1
151+
// @version 2025.3.23
152152
// @license MIT
153153
// @icon https://cdn.jsdelivr.net/gh/KudoAI/bravegpt@df624b0/assets/images/icons/bravegpt/icon48.png
154154
// @icon64 https://cdn.jsdelivr.net/gh/KudoAI/bravegpt@df624b0/assets/images/icons/bravegpt/icon64.png
@@ -511,7 +511,7 @@
511511
} catch (err) { // if bad response
512512
msgXHRtries++ ; if (msgXHRtries == 3) return resolve({}) // try original/region-stripped/EN only
513513
msgHref = env.browser.language.includes('-') && msgXHRtries == 1 ? // if regional lang on 1st try...
514-
msgHref.replace(/([^_]+_[^_]+)_[^/]*(\/.*)/, '$1$2') // ...strip region before retrying
514+
msgHref.replace(/(_locales\/[^_]+)_[^_]+(\/)/, '$1$2') // ...strip region before retrying
515515
: ( msgHostDir + 'en/messages.json' ) // else use default English messages
516516
fetchMsgs()
517517
}
@@ -1219,7 +1219,7 @@
12191219
else if (key.includes('rq')) toggle.relatedQueries()
12201220
else if (autoGenMatch) toggle.autoGen(autoGenMatch[0].toLowerCase())
12211221
else if (manualGenMatch) toggle.manualGen(manualGenMatch[0].toLowerCase())
1222-
else if (key.includes('Sidebar')) toggle.sidebar(/(.*?)Sidebar$/.exec(key)[1])
1222+
else if (key.includes('Sidebar')) toggle.sidebar(key.replace('Sidebar', ''))
12231223
else if (key.includes('anchor')) toggle.anchorMode()
12241224
else if (key.includes('bgAnimation')) toggle.animations('bg')
12251225
else if (key.includes('fgAnimation')) toggle.animations('fg')
@@ -1349,7 +1349,7 @@
13491349
const html = resp.responseText, dlLink = document.createElement('a')
13501350
dlLink.href = URL.createObjectURL(new Blob([html], { type: 'text/html' }))
13511351
dlLink.download /* filename */ = html.match(/<title>([^<]+)<\/title>/i)[1] // page title
1352-
.replace(/\s+[|/]+\s+/g, ' ') // convert suffix sep to space for hyphen-casing
1352+
.replace(/\s*[|/]+\s*/g, ' ') // convert symbols to space for hyphen-casing
13531353
.toLowerCase().trim().replace(/\s+/g, '-') // hyphen-case
13541354
+ '.html'
13551355
document.body.append(dlLink) ; dlLink.click() ; dlLink.remove() // download HTML
@@ -4266,9 +4266,9 @@
42664266
const msgChain = [], searchQuery = new URL(location.href).searchParams.get('q')
42674267
if (!config.autoGetDisabled || config.autoSummarize // Auto-Gen on
42684268
|| (config.prefixEnabled || config.suffixEnabled) // or Manual-Gen on
4269-
&& [config.prefixEnabled && /.*q=%2F/.test(location.href), // prefix required/present
4269+
&& [config.prefixEnabled && location.href.includes('q=%2F'), // prefix required/present
42704270
config.suffixEnabled // suffix required/present
4271-
&& /.*q=.*(?:%3F||%EF%BC%9F)(?:&|$)/.test(location.href)
4271+
&& /q=.*?(?:%3F||%EF%BC%9F)(?:&|$)/.test(location.href)
42724272
].filter(Boolean).length == (config.prefixEnabled + config.suffixEnabled) // validate both Manual-Gen modes
42734273
) { // auto-gen reply
42744274
msgChain.push({

0 commit comments

Comments
 (0)