Skip to content

Commit

Permalink
change youtube/index.mjs to not confuse chatgpt or run out of tokens (#…
Browse files Browse the repository at this point in the history
…205 @iamsirsammy)

* change youtube/index.mjs to not confuse chatgpt or run out of tokens

* Update index.mjs
  • Loading branch information
iamsirsammy authored Apr 14, 2023
1 parent ba94457 commit b2cd54e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/content-script/site-adapters/youtube/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { cropText } from '../../../utils'
import { config } from '../index.mjs'

function replaceHtmlEntities(htmlString) { // This function was written by ChatGPT and modified by me (iamsirsammy)
const doc = new DOMParser().parseFromString(htmlString.replace("&", "&"), 'text/html');
return doc.documentElement.innerText;
}

export default {
init: async (hostname, userConfig, getInput, mountComponent) => {
try {
Expand Down Expand Up @@ -41,12 +46,14 @@ export default {
let subtitleContent = ''
while (subtitleData.indexOf('">') !== -1) {
subtitleData = subtitleData.substring(subtitleData.indexOf('">') + 2)
subtitleContent += subtitleData.substring(0, subtitleData.indexOf('<')) + ','
subtitleContent += subtitleData.substring(0, subtitleData.indexOf('<')) + ' '
}

subtitleContent = replaceHtmlEntities(subtitleContent)

return cropText(
`Provide a brief summary of the video using concise language and incorporating the video title.` +
`The video title is:"${title}".The subtitle content is as follows:\n${subtitleContent}`,
`Provide a brief summary of the following video using concise language, still including all the important details, and incorporating the video title.` +
`The video title is "${title}". The subtitle content is as follows:\n${subtitleContent}`,
)
} catch (e) {
console.log(e)
Expand Down

0 comments on commit b2cd54e

Please sign in to comment.