Merge pull request #101 from ajayyy/experimental

Better lookups + userID generator improvements
This commit is contained in:
Ajay Ramachandran
2019-08-11 23:24:17 -04:00
committed by GitHub
3 changed files with 36 additions and 4 deletions

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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": [
{