Changes the ?t= parameter when pausing. Other version: https://greasyfork.org/en/scripts/455475-youtube-resumer
< Valutazione su Youtube Resumer (using the url)
Oh you are right, there is no way around flooding the browser history. I tried using the session storage but it's not as smooth since it loads at 0 and then jumps to the time set. So I just change the url when pausing, but you can use the session storage instead of the url if you want:
(async () => {
function l(...args){
console.log(`[Youtube Resumer]`, ...args)
}
function findVideo(){
return document.querySelector('video')
}
//remove ?t=
//TODO call when first loading the page
function cleanUrl(){
const url = new URL(window.location.href)
url.searchParams.delete('t')
window.history.replaceState(null, null, url)
}
function save(video){
const seconds = parseInt(video.currentTime)
window.sessionStorage.setItem('time', seconds)
}
function listen(){
const video = findVideo()
video.addEventListener('timeupdate', () => {
save(video)
//TODO test whether the saved value causes problems when going to another video
})
}
let listening = false //the video element exists even if you go back to the home page, so no need to readd event listeners
//Event for each page change
document.addEventListener("yt-navigate-finish", function() {
l('navigate-finish')
//Match page with video
if(window.location.href.match(new RegExp('https://www.youtube.com/watch\\?v=.'))) {
//Add video listener once
if(!listening){
l('listening')
listen()
listening = true
}
//Resume where you left off
let time = window.sessionStorage.getItem('time')
if(time !== null){
let seconds = parseInt(time)
let video = findVideo()
video.currentTime = seconds
}
}
});
})();
Here is a version that stores time locally https://greasyfork.org/en/scripts/455475-youtube-resumer
Works.. It automatically updates the URL bar so than if you want to copy link at current time it's easier.
HOWEVER! In MOST cases we want to copy the url without the time... So I will not be using this script, since it's rare than I will need to right click and copy url at current time.
The worse part of this is that it fills your browsing history with one video.. For this alone I would never use this script.
Also I should mention the obvious, that the title is misleading.