aboutsummaryrefslogtreecommitdiffhomepage
path: root/ContentScript.js
blob: 571eb9fb9a97afbc5844b9b4e49c93604dd8b99a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var v = document.querySelector('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;
}