Made it keep checking for submitted sponsor times every 10 seconds on recent videos.

This commit is contained in:
Ajay Ramachandran 2019-07-21 21:08:23 -04:00
parent 2d00cfffdf
commit 52ec50a132
2 changed files with 35 additions and 1 deletions

View file

@ -29,4 +29,6 @@ None at the moment
# Credit
The awesome [Invidious API](https://github.com/omarroth/invidious/wiki/API) is used to grab the time the video was published.
Some i made by <a href="https://www.flaticon.com/authors/gregor-cresnar" title="Gregor Cresnar">Gregor Cresnar</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> and are licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>

View file

@ -131,8 +131,21 @@ function sponsorsLookup(id) {
v.ontimeupdate = function () {
sponsorCheck(sponsorTimes);
};
} else {
} else if (xmlhttp.readyState == 4) {
sponsorDataFound = false;
//check if this video was uploaded recently
//use the invidious api to get the time published
sendRequestToCustomServer('GET', "https://invidio.us/api/v1/videos/" + id, function(xmlhttp, error) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
let unixTimePublished = JSON.parse(xmlhttp.responseText).published;
//if less than 3 days old
if ((Date.now() / 1000) - unixTimePublished < 259200) {
setTimeout(() => sponsorsLookup(id), 10000);
}
}
});
}
});
}
@ -551,6 +564,25 @@ function sendRequestToServer(type, address, callback) {
xmlhttp.send();
}
function sendRequestToCustomServer(type, fullAddress, callback) {
let xmlhttp = new XMLHttpRequest();
xmlhttp.open(type, fullAddress, true);
if (callback != undefined) {
xmlhttp.onreadystatechange = function () {
callback(xmlhttp, false);
};
xmlhttp.onerror = function(ev) {
callback(xmlhttp, true);
};
}
//submit this request
xmlhttp.send();
}
function getYouTubeVideoID(url) { // Returns with video id else returns false
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp);