diff options
author | Ajay Ramachandran <[email protected]> | 2021-06-09 14:57:24 -0400 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2021-06-09 14:57:24 -0400 |
commit | dacf766b4ab30e98d2d4c2fa9f8dd24daae1c9ad (patch) | |
tree | cfbbf16d88ffcd19fc89ac008e111f51c8742930 | |
parent | 4932fc6f45f58f4dbd90d24377336ff100999f17 (diff) | |
download | SponsorBlock-dacf766b4ab30e98d2d4c2fa9f8dd24daae1c9ad.tar.gz SponsorBlock-dacf766b4ab30e98d2d4c2fa9f8dd24daae1c9ad.zip |
Fix potential infinite loop in skip notice
-rw-r--r-- | src/render/SkipNotice.tsx | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/render/SkipNotice.tsx b/src/render/SkipNotice.tsx index 526d2d1c..d259029f 100644 --- a/src/render/SkipNotice.tsx +++ b/src/render/SkipNotice.tsx @@ -24,6 +24,10 @@ class SkipNotice { //get reference node let referenceNode = document.getElementById("player-container-id") || document.getElementById("movie_player") || document.querySelector("#player-container .video-js"); + // YouTube Music + if (new URL(document.URL).host === "music.youtube.com") { + referenceNode = document.querySelector("#main-panel.ytmusic-player-page"); + } if (referenceNode == null) { //for embeds const player = document.getElementById("player"); @@ -31,16 +35,13 @@ class SkipNotice { 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")) { + while (index < player.children.length && (!referenceNode.classList.contains("html5-video-player") || !referenceNode.classList.contains("ytp-embed"))) { referenceNode = player.children[index] as HTMLElement; index++; } } - // YouTube Music - if (new URL(document.URL).host === "music.youtube.com") { - referenceNode = document.querySelector("#main-panel.ytmusic-player-page"); - } + const amountOfPreviousNotices = document.getElementsByClassName("sponsorSkipNotice").length; //this is the suffix added at the end of every id |