How do you change an embedded video on tampermonkey?

465 Views Asked by At

So I'm fairly new to tampermonkey. I just need to know, say I had a video on a website. For example, on the MyMaths page: https://www.mymaths.co.uk/primary.html it has a video about cumnor primary school at this youtube url: https://youtu.be/D5kVFVwkdLs and say I wanted to replace it with another video, say, "How to safely remove asbestos" at youtube url: https://www.youtube.com/watch?v=L_1xtqwfLrU

This may be something rally obvious that I'm missing but could anyone help me? Thanks.

1

There are 1 best solutions below

0
CennoxX On

This depends on how the video is embedded. If it is embedded like the video on the startpage of mymaths.co.uk: <iframe src="https://www.youtube.com/embed/D5kVFVwkdLs?rel=0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" width="560" height="315" frameborder="0"></iframe> you would simply try to get the src, which in this case is set in the first iframe-tag and replace it.

document.getElementsByTagName("iframe")[0].src = document.getElementsByTagName("iframe")[0].src.replace("D5kVFVwkdLs","L_1xtqwfLrU");