From efb172cc6c1e5a2537d6d7a6b61602c4c3bf5e2b Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Sat, 23 Jun 2018 15:06:18 +0100 Subject: Create ContentScript.js --- ContentScript.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 ContentScript.js 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; +} -- cgit v1.2.3