Added support for embedded videos.

Resolved https://github.com/ajayyy/SponsorBlock/issues/12
This commit is contained in:
Ajay Ramachandran
2019-08-01 20:55:47 -04:00
parent efe512b561
commit 3d1be7158d
2 changed files with 21 additions and 1 deletions

View File

@@ -722,6 +722,20 @@ function openSkipNotice(UUID){
noticeElement.appendChild(buttonContainer); noticeElement.appendChild(buttonContainer);
let referenceNode = document.getElementById("movie_player"); let referenceNode = document.getElementById("movie_player");
if (referenceNode == null) {
//for embeds
let player = document.getElementById("player");
referenceNode = player.firstChild;
let index = 1;
//find the child that is the video player (sometimes it is not the first)
while (!referenceNode.classList.contains("html5-video-player") || !referenceNode.classList.contains("ytp-embed")) {
referenceNode = player.children[index];
index++;
}
}
referenceNode.prepend(noticeElement); referenceNode.prepend(noticeElement);
} }
@@ -1009,5 +1023,10 @@ function getYouTubeVideoID(url) { // Returns with video id else returns false
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp); var match = url.match(regExp);
var id = new URL(url).searchParams.get("v"); var id = new URL(url).searchParams.get("v");
if (url.includes("/embed/")) {
//it is an embed, don't search for v
id = match[7];
}
return (match && match[7].length == 11) ? id : false; return (match && match[7].length == 11) ? id : false;
} }

View File

@@ -1,13 +1,14 @@
{ {
"name": "SponsorBlock for YouTube - Skip Sponsorships", "name": "SponsorBlock for YouTube - Skip Sponsorships",
"short_name": "SponsorBlock", "short_name": "SponsorBlock",
"version": "1.0.25", "version": "1.0.26",
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.", "description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
"content_scripts": [ "content_scripts": [
{ {
"matches": [ "matches": [
"https://*.youtube.com/*" "https://*.youtube.com/*"
], ],
"all_frames": true,
"js": [ "js": [
"config.js", "config.js",
"content.js", "content.js",