Skip to content

Commit

Permalink
Improve youtube UX
Browse files Browse the repository at this point in the history
auto-scroll to current transcript, change language and jump to current time
  • Loading branch information
blackforestboi committed Jul 23, 2024
1 parent 6151801 commit a76788a
Show file tree
Hide file tree
Showing 6 changed files with 347 additions and 22 deletions.
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-common
13 changes: 10 additions & 3 deletions src/content-scripts/content_script/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ import * as anchoring from '@worldbrain/memex-common/lib/annotations'
import type { TaskState } from 'ui-logic-core/lib/types'
import debounce from 'lodash/debounce'
import { updateNudgesCounter } from 'src/util/nudges-utils'
import { fetchYoutubeTranscript } from 'src/util/fetch-youtube-transcript'
import {
fetchAvailableTranscriptLanguages,
fetchYoutubeTranscript,
} from 'src/util/fetch-youtube-transcript'

// Content Scripts are separate bundles of javascript code that can be loaded
// on demand by the browser, as needed. This main function manages the initialisation
Expand Down Expand Up @@ -999,8 +1002,12 @@ export async function main(
}

const transcriptFunctions = {
fetchTranscript: async (videoId: string) => {
return (await fetchYoutubeTranscript(videoId, true))?.transcriptText
fetchTranscript: async (videoId: string, language: string) => {
return (await fetchYoutubeTranscript(videoId, language, true))
?.transcriptText
},
fetchAvailableTranscriptLanguages: async (videoId: string) => {
return await fetchAvailableTranscriptLanguages(videoId)
},
}

Expand Down
4 changes: 2 additions & 2 deletions src/dashboard-refactor/styled-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const Icon = (props: IconProps) => {
)
}

export const LoadingContainer = ({ children }) => {
export const LoadingContainer = ({ children, height = '100%' }) => {
const Container = styled.div`
width: 100%;
display: flex;
Expand All @@ -93,7 +93,7 @@ export const LoadingContainer = ({ children }) => {
grid-gap: 20px;
color: ${(props) => props.theme.colors.greyScale6};
font-size: 20px;
height: 100%;
height: ${height ?? '100%'};
`
return <Container>{children}</Container>
}
Expand Down
2 changes: 1 addition & 1 deletion src/page-analysis/background/analyse-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const analysePage: PageAnalyzer = async (options) => {
}

if (videoId) {
let transcriptJSON = await fetchYoutubeTranscript(videoId)
let transcriptJSON = await fetchYoutubeTranscript(videoId, 'en')

if (transcriptJSON != null) {
content.fullText =
Expand Down
Loading

0 comments on commit a76788a

Please sign in to comment.