diff options
author | Official Noob <[email protected]> | 2018-06-23 15:06:18 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2018-06-23 15:06:18 +0100 |
commit | efb172cc6c1e5a2537d6d7a6b61602c4c3bf5e2b (patch) | |
tree | 6d49b4ee3c5bb5af57bc27d36039d9689ebd25c7 | |
parent | 9e3c5734b041133740acb5c0dce67f542da59a2c (diff) | |
download | SponsorBlock-efb172cc6c1e5a2537d6d7a6b61602c4c3bf5e2b.tar.gz SponsorBlock-efb172cc6c1e5a2537d6d7a6b61602c4c3bf5e2b.zip |
Create ContentScript.js
-rw-r--r-- | ContentScript.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/ContentScript.js b/ContentScript.js new file mode 100644 index 00000000..983a627c --- /dev/null +++ b/ContentScript.js @@ -0,0 +1,31 @@ +var v = $('video') +video_id = youtube_parser(document.URL); + +if(video_id){ +SponsorsLookup(video_id); +} + +function SponsorsLookup(id){ +var xmlhttp = new XMLHttpRequest(); +xmlhttp.open('GET', 'https://officialnoob.github.io/YTSponsorSkip-Dataset/'+id, true); +xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { + Sponsors = JSON.parse(xmlhttp.responseText); + v.ontimeupdate = function() {SponsorCheck()}; + } +}; +xmlhttp.send(null); +} + +function SponsorCheck() { + Sponsors.forEach(function(el, index) { + if((Math.floor(v.currentTime)) == el[0]){ + v.currentTime = el[1]; + } +});} + +function youtube_parser(url){ + var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; + var match = url.match(regExp); + return (match&&match[7].length==11)? match[7] : false; +} |