audio-only-youtube icon indicating copy to clipboard operation
audio-only-youtube copied to clipboard

Remember playback state?

Open orschiro opened this issue 5 years ago • 5 comments

Something default YouTube does.

Can the extension support this, too?

orschiro avatar Aug 05 '19 08:08 orschiro

It seems this one can: https://github.com/craftwar/youtube-audio

orschiro avatar Oct 23 '19 10:10 orschiro

Chrome extension is missing

godzfire avatar Mar 12 '20 00:03 godzfire

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.

Zefferis avatar Oct 28 '20 16:10 Zefferis

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.

jidanni avatar Jul 03 '21 06:07 jidanni

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();

aljgom avatar Oct 10 '23 09:10 aljgom