aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2019-07-21 21:08:23 -0400
committerAjay Ramachandran <[email protected]>2019-07-21 21:08:23 -0400
commit52ec50a13262d9a2b00c2249e151a1f7d2f085ce (patch)
treeda676ce56743f76cc664d10283ab53a21ca80a04
parent2d00cfffdfac4a5e30fcef55c576ceec650de28a (diff)
downloadSponsorBlock-52ec50a13262d9a2b00c2249e151a1f7d2f085ce.tar.gz
SponsorBlock-52ec50a13262d9a2b00c2249e151a1f7d2f085ce.zip
Made it keep checking for submitted sponsor times every 10 seconds on recent videos.
-rw-r--r--README.md2
-rw-r--r--content.js34
2 files changed, 35 insertions, 1 deletions
diff --git a/README.md b/README.md
index 70756792..72e4bb2e 100644
--- a/README.md
+++ b/README.md
@@ -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> \ No newline at end of file
diff --git a/content.js b/content.js
index f27120c5..eba49faf 100644
--- a/content.js
+++ b/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);