Skip to content

Commit

Permalink
Use embed URLs for URL field on youtube videos
Browse files Browse the repository at this point in the history
  • Loading branch information
killergerbah committed Aug 4, 2024
1 parent 12fad84 commit f7f4dfa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion extension/src/controllers/anki-ui-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class AnkiUiController {

this._prepareShow(context);
const client = await this._client(context);
const url = context.url;
const url = context.url(subtitle.start, subtitle.end);
const themeType = await context.settings.getSingle('themeType');

const state: AnkiUiInitialState = {
Expand Down
22 changes: 15 additions & 7 deletions extension/src/services/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ document.addEventListener('asbplayer-netflix-enabled', (e) => {
});
document.dispatchEvent(new CustomEvent('asbplayer-query-netflix'));

const youtube = /(m|www)\.youtube\.com/.test(window.location.host);

enum RecordingState {
requested,
started,
Expand Down Expand Up @@ -174,10 +176,6 @@ export default class Binding {
return this._synced;
}

get url() {
return window.location !== window.parent.location ? document.referrer : document.location.href;
}

get speedChangeStep() {
return this._speedChangeStep;
}
Expand Down Expand Up @@ -948,7 +946,7 @@ export default class Binding {
surroundingSubtitles: surroundingSubtitles,
record: this.recordMedia,
screenshot: this.takeScreenshot,
url: this.url,
url: this.url(subtitle.start, subtitle.end),
mediaTimestamp: this.video.currentTime * 1000,
subtitleFileName: this.subtitleFileName(subtitle.track),
postMineAction: postMineAction,
Expand Down Expand Up @@ -985,7 +983,7 @@ export default class Binding {
playbackRate: this.video.playbackRate,
screenshot: this.recordingMediaWithScreenshot,
videoDuration: this.video.duration * 1000,
url: this.url,
url: this.url(this.recordingMediaStartedTimestamp!, currentTimestamp),
subtitleFileName: this.subtitleFileName(),
...this._imageCaptureParams,
...this._surroundingSubtitlesAroundInterval(this.recordingMediaStartedTimestamp!, currentTimestamp),
Expand Down Expand Up @@ -1022,7 +1020,7 @@ export default class Binding {
record: this.recordMedia,
postMineAction: postMineAction,
screenshot: this.takeScreenshot,
url: this.url,
url: this.url(timestamp),
subtitleFileName: this.subtitleFileName(),
imageDelay: this.imageDelay,
...this._imageCaptureParams,
Expand Down Expand Up @@ -1365,4 +1363,14 @@ export default class Binding {

chrome.runtime.sendMessage(command);
}

url(start: number, end?: number) {
if (youtube) {
const toSeconds = (ms: number) => Math.floor(ms / 1000);
const embedUrl = `https://www.youtube.com/embed/Khqwm3np9wc?start=${toSeconds(start)}&autoplay=1`;
return end === undefined ? embedUrl : `${embedUrl}&end=${toSeconds(end)}`;
}

return window.location !== window.parent.location ? document.referrer : document.location.href;
}
}

0 comments on commit f7f4dfa

Please sign in to comment.