Skip to content

Commit a04bc46

Browse files
authored
change youtube/index.mjs to not confuse chatgpt or run out of tokens (#205 @iamsirsammy)
* change youtube/index.mjs to not confuse chatgpt or run out of tokens * Update index.mjs
1 parent e1f3213 commit a04bc46

File tree

1 file changed

+10
-3
lines changed
  • src/content-script/site-adapters/youtube

1 file changed

+10
-3
lines changed

src/content-script/site-adapters/youtube/index.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { cropText } from '../../../utils'
22
import { config } from '../index.mjs'
33

4+
function replaceHtmlEntities(htmlString) { // This function was written by ChatGPT and modified by me (iamsirsammy)
5+
const doc = new DOMParser().parseFromString(htmlString.replace("&", "&"), 'text/html');
6+
return doc.documentElement.innerText;
7+
}
8+
49
export default {
510
init: async (hostname, userConfig, getInput, mountComponent) => {
611
try {
@@ -41,12 +46,14 @@ export default {
4146
let subtitleContent = ''
4247
while (subtitleData.indexOf('">') !== -1) {
4348
subtitleData = subtitleData.substring(subtitleData.indexOf('">') + 2)
44-
subtitleContent += subtitleData.substring(0, subtitleData.indexOf('<')) + ','
49+
subtitleContent += subtitleData.substring(0, subtitleData.indexOf('<')) + ' '
4550
}
4651

52+
subtitleContent = replaceHtmlEntities(subtitleContent)
53+
4754
return cropText(
48-
`Provide a brief summary of the video using concise language and incorporating the video title.` +
49-
`The video title is:"${title}".The subtitle content is as follows:\n${subtitleContent}`,
55+
`Provide a brief summary of the following video using concise language, still including all the important details, and incorporating the video title.` +
56+
`The video title is "${title}". The subtitle content is as follows:\n${subtitleContent}`,
5057
)
5158
} catch (e) {
5259
console.log(e)

0 commit comments

Comments
 (0)