I found a GitHub repository that is useful to me, but it lacks a feature-work on netflix I require. I opened an issue to request the feature, but the author seems currently occupied with other projects and won’t be updating it for now. Attempting to modify the code myself, I encountered some issues such as Uncaught TypeError: Cannot read properties of null (reading 'currentTime')
that I couldn’t resolve. Now, I’m seeking assistance on StackOverflow to overcome these challenges.
I tried to revise the if statement to :
if (window.location.href.includes("youtube.com/watch") || window.location.href.includes("netflix.com/watch"))
and added a function to distinguish between netflix and youtube so as to get their URL
function getVideoPlatform()
{
const youtubePattern = /youtube.com/watch?v=/;
const netflixPattern = /netflix.com/watch//;
const url = window.location.href;
if (youtubePattern.test(url))
{
return "youtube";
} else if (netflixPattern.test(url))
{
return "netflix";
} else
{
return "unknown";
}
}
then a function to generate netflix timestamp and a if statement to differentiate
function timestampGen(url, time)
{
url = url.split('?')[0];
time = time | 0;
url = url + '?t=' + time;
return url;
}
if (platform === "youtube")
{
current_time = document.querySelector(".video-stream").currentTime.toFixed() || 0;
} else if (platform === "netflix")
{
current_time = timestampGen() || 0;
} else
{
console.error("Unsupported platform");
return; // Exit the function if the platform is unsupported
}
var timestamped_url;
if (platform === "youtube")
{
timestamped_url = "https://youtu.be/" + videoId + "?t=" + current_time;
} else if (platform === "netflix")
{
timestamped_url = "https://www.netflix.com/watch/" + videoId + "?t=" + current_time;
}
I also changed JSON file to "matches": [ "*://*.youtube.com/watch*", "*://*.netflix.com/watch*" ]
, but it seems i just keep get the error Uncaught TypeError: Cannot read properties of null (reading 'currentTime')
I feel like this repo should be helpful for generating netflix timestamp but I don’t know how to integrate it.