audio-only-youtube
audio-only-youtube copied to clipboard
Remember playback state?
Something default YouTube does.
Can the extension support this, too?
It seems this one can: https://github.com/craftwar/youtube-audio
Chrome extension is missing
I think a reasonable way to get round this would be to have the extension figure out the - Share + Start time, and then reload the page with that info, might be more clunky though so it could be an enabled feature that opt-in.
Let's say we watch a movie for a few minutes, and our eyes get tired. Alas, this extension seems to only know about starting again way back at the beginning.
It could be something like this
let savedTime;
let isPaused;
async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function waitForVideo() {
let videoElement;
while (true) {
videoElement = document.querySelector('video');
if (videoElement && videoElement.readyState >= 3) {
break;
}
await sleep(500);
}
return videoElement;
}
async function saveCurrentTimeAndState() {
const videoElement = await waitForVideo();
savedTime = videoElement.currentTime;
isPaused = videoElement.paused;
}
async function restoreCurrentTimeAndState() {
const videoElement = await waitForVideo();
videoElement.currentTime = savedTime;
if (isPaused) {
videoElement.pause();
} else {
videoElement.play();
}
}
// To save the current time and state before reloading the page
await saveCurrentTimeAndState();
// To restore the saved time and state after reloading the page
await restoreCurrentTimeAndState();