diff --git a/src/content-script/site-adapters/reddit/index.mjs b/src/content-script/site-adapters/reddit/index.mjs index f1dcb24..2c687ce 100644 --- a/src/content-script/site-adapters/reddit/index.mjs +++ b/src/content-script/site-adapters/reddit/index.mjs @@ -3,10 +3,10 @@ import { cropText } from '../../../utils' export default { inputQuery: async () => { try { - const title = document.querySelector('[id*="post-title"]').textContent + const title = document.querySelector('[id*="post-title"]')?.textContent const description = document.querySelector( 'shreddit-post > div.text-neutral-content', - ).textContent + )?.textContent const texts = document.querySelectorAll('shreddit-comment div.md') let answers = '' for (let i = 0; i < texts.length; i++) { diff --git a/src/utils/crop-text.mjs b/src/utils/crop-text.mjs index 88130fd..16bdc5e 100644 --- a/src/utils/crop-text.mjs +++ b/src/utils/crop-text.mjs @@ -35,7 +35,7 @@ export async function cropText( tiktoken = true, ) { const userConfig = await getUserConfig() - const k = Models[userConfig.modelName].desc.match(/[- ]*([0-9]+)k/)?.[1] + const k = Models[userConfig.modelName].desc.match(/[- (]*([0-9]+)k/)?.[1] if (k) { maxLength = Number(k) * 1000 maxLength -= 100 + clamp(userConfig.maxResponseTokenLength, 1, maxLength - 1000)