mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 01:01:55 +01:00
Made it keep checking for submitted sponsor times every 10 seconds on recent videos.
This commit is contained in:
parent
2d00cfffdf
commit
52ec50a132
2 changed files with 35 additions and 1 deletions
|
@ -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>
|
34
content.js
34
content.js
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue