aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2019-08-11 23:24:17 -0400
committerGitHub <[email protected]>2019-08-11 23:24:17 -0400
commit66b6985c5ec1d39ba01fba1f461a11c632aaac4f (patch)
treef4a96b6451fd25b35ed250a58867d1086ff18bfd
parent455189d9164be01e0b41b925084fd1c6197ecdba (diff)
parent0025785a7803371c7c3138a844c55d1f0c3ecd4f (diff)
downloadSponsorBlock-66b6985c5ec1d39ba01fba1f461a11c632aaac4f.tar.gz
SponsorBlock-66b6985c5ec1d39ba01fba1f461a11c632aaac4f.zip
Merge pull request #101 from ajayyy/experimental1.0.31
Better lookups + userID generator improvements
-rw-r--r--background.js20
-rw-r--r--content.js18
-rw-r--r--manifest.json2
3 files changed, 36 insertions, 4 deletions
diff --git a/background.js b/background.js
index 5d0189c6..752653ec 100644
--- a/background.js
+++ b/background.js
@@ -262,5 +262,21 @@ function sendRequestToServer(type, address, callback) {
xmlhttp.send();
}
-//uuid generator function from https://gist.github.com/jed/982883
-function generateUUID(a){return a?(a^Math.random()*16>>a/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,generateUUID)}
+function generateUUID(length = 36) {
+ let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ let result = "";
+ let isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
+ if (window.crypto && window.crypto.getRandomValues) {
+ values = new Uint32Array(length);
+ window.crypto.getRandomValues(values);
+ for (i = 0; i < length; i++) {
+ result += charset[values[i] % charset.length];
+ }
+ return result;
+ } else {
+ for (let i = 0; i < length; i++) {
+ result += charset[Math.floor(Math.random() * charset.length)];
+ }
+ return result;
+ }
+}
diff --git a/content.js b/content.js
index 07dae739..c1060415 100644
--- a/content.js
+++ b/content.js
@@ -29,6 +29,10 @@ var lastTime = -1;
//the actual time (not video time) that the last skip happened
var lastUnixTimeSkipped = -1;
+//the amount of times the sponsor lookup has retried
+//this only happens if there is an error
+var sponsorLookupRetries = 0;
+
//the last time in the video a sponsor was skipped
//used for the go back button
var lastSponsorTimeSkipped = null;
@@ -195,6 +199,7 @@ function videoIDChange(id) {
sponsorTimes = null;
UUIDs = null;
sponsorVideoID = id;
+ sponsorLookupRetries = 0;
//see if there is a video start time
youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL);
@@ -275,7 +280,8 @@ function sponsorsLookup(id) {
getChannelID();
- } else if (xmlhttp.readyState == 4) {
+ sponsorLookupRetries = 0;
+ } else if (xmlhttp.readyState == 4 && xmlhttp.status == 404) {
sponsorDataFound = false;
//check if this video was uploaded recently
@@ -290,6 +296,13 @@ function sponsorsLookup(id) {
}
}
});
+
+ sponsorLookupRetries = 0;
+ } else if (xmlhttp.readyState == 4 && sponsorLookupRetries < 15) {
+ //some error occurred, try again in a second
+ setTimeout(() => sponsorsLookup(id), 1000);
+
+ sponsorLookupRetries++;
}
});
@@ -1048,6 +1061,9 @@ function sendSubmitMessage(){
//clear the sponsor times
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
chrome.storage.sync.set({[sponsorTimeKey]: []});
+
+ //request the sponsors from the server again
+ sponsorsLookup(currentVideoID);
} else {
//for a more detailed error message, they should check the popup
//show that the upload failed
diff --git a/manifest.json b/manifest.json
index e80a30f6..45311399 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
{
"name": "SponsorBlock for YouTube - Skip Sponsorships",
"short_name": "SponsorBlock",
- "version": "1.0.30",
+ "version": "1.0.31",
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
"content_scripts": [
{