Skip to content

Commit

Permalink
Shortened regex ↞ [auto-sync from adamlui/ai-web-extensions]
Browse files Browse the repository at this point in the history
  • Loading branch information
kudo-sync-bot committed Nov 14, 2024
1 parent 72cea99 commit be5a146
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions greasemonkey/duckduckgpt.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
// @description:zu Yengeza izimpendulo ze-AI ku-DuckDuckGo (inikwa amandla yi-GPT-4o!)
// @author KudoAI
// @namespace https://kudoai.com
// @version 2024.11.14
// @version 2024.11.14.1
// @license MIT
// @icon https://media.ddgpt.com/images/icons/duckduckgpt/icon48.png?af89302
// @icon64 https://media.ddgpt.com/images/icons/duckduckgpt/icon64.png?af89302
Expand Down Expand Up @@ -241,7 +241,7 @@
}
app.urls.assetHost = app.urls.gitHub.replace('github.com', 'cdn.jsdelivr.net/gh') + `@${app.latestAssetCommitHash}`
app.urls.update = app.urls.greasyFork.replace('https://', 'https://update.')
.replace(/(\d+)-?([a-zA-Z-]*)$/, (_, id, name) => `${id}/${ name || 'script' }.meta.js`)
.replace(/(\d+)-?([a-z-]*)$/i, (_, id, name) => `${id}/${ name || 'script' }.meta.js`)

// Init ENV info
const env = { browser: {}, scriptManager: (() => { try { return GM_info.scriptHandler } catch (err) { return 'unknown' }})() };
Expand Down Expand Up @@ -276,11 +276,11 @@

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 },
redVals: { caseInsensitive: /\bfalse\b|error\W?/i, caseSensitive: /\BOFF\b/ },
purpVals: /[ '"]\w+['"]?: / },

prettifyObj(obj) { return JSON.stringify(obj)
.replace(/([{,](?=")|(?:"):)/g, '$1 ') // append spaces to { and "
.replace(/([{,](?=")|":)/g, '$1 ') // append spaces to { and "
.replace(/((?<!})})/g, ' $1') // prepend spaces to }
.replace(/"/g, '\'') // replace " w/ '
},
Expand Down Expand Up @@ -3077,7 +3077,7 @@
if (caller.api == 'MixerBox AI') { // pre-process chunks
const extractedChunks = Array.from(chunk.matchAll(/data:(.*)/g), match => match[1]
.replace(/\[SPACE\]/g, ' ').replace(/\[NEWLINE\]/g, '\n'))
.filter(match => !/(?:message_(?:start|end)|done)/.test(match))
.filter(match => !/message_(?:start|end)|done/.test(match))
chunk = extractedChunks.join('')
}
accumulatedChunks = apis[caller.api].accumulatesText ? chunk : accumulatedChunks + chunk
Expand Down Expand Up @@ -3161,7 +3161,7 @@
try { // to show response or return related queries
const extractedData = Array.from(resp.responseText.matchAll(/data:(.*)/g), match => match[1]
.replace(/\[SPACE\]/g, ' ').replace(/\[NEWLINE\]/g, '\n'))
.filter(match => !/(?:message_(?:start|end)|done)/.test(match))
.filter(match => !/message_(?:start|end)|done/.test(match))
respText = extractedData.join('') ; handleProcessCompletion()
} catch (err) { handleProcessError(err) }
}
Expand Down

0 comments on commit be5a146

Please sign in to comment.