mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 13:07:05 +03:00
Merge pull request #101 from ajayyy/experimental
Better lookups + userID generator improvements
This commit is contained in:
@@ -262,5 +262,21 @@ function sendRequestToServer(type, address, callback) {
|
|||||||
xmlhttp.send();
|
xmlhttp.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
//uuid generator function from https://gist.github.com/jed/982883
|
function generateUUID(length = 36) {
|
||||||
function generateUUID(a){return a?(a^Math.random()*16>>a/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,generateUUID)}
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
18
content.js
18
content.js
@@ -29,6 +29,10 @@ var lastTime = -1;
|
|||||||
//the actual time (not video time) that the last skip happened
|
//the actual time (not video time) that the last skip happened
|
||||||
var lastUnixTimeSkipped = -1;
|
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
|
//the last time in the video a sponsor was skipped
|
||||||
//used for the go back button
|
//used for the go back button
|
||||||
var lastSponsorTimeSkipped = null;
|
var lastSponsorTimeSkipped = null;
|
||||||
@@ -195,6 +199,7 @@ function videoIDChange(id) {
|
|||||||
sponsorTimes = null;
|
sponsorTimes = null;
|
||||||
UUIDs = null;
|
UUIDs = null;
|
||||||
sponsorVideoID = id;
|
sponsorVideoID = id;
|
||||||
|
sponsorLookupRetries = 0;
|
||||||
|
|
||||||
//see if there is a video start time
|
//see if there is a video start time
|
||||||
youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL);
|
youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL);
|
||||||
@@ -275,7 +280,8 @@ function sponsorsLookup(id) {
|
|||||||
|
|
||||||
getChannelID();
|
getChannelID();
|
||||||
|
|
||||||
} else if (xmlhttp.readyState == 4) {
|
sponsorLookupRetries = 0;
|
||||||
|
} else if (xmlhttp.readyState == 4 && xmlhttp.status == 404) {
|
||||||
sponsorDataFound = false;
|
sponsorDataFound = false;
|
||||||
|
|
||||||
//check if this video was uploaded recently
|
//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
|
//clear the sponsor times
|
||||||
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||||
chrome.storage.sync.set({[sponsorTimeKey]: []});
|
chrome.storage.sync.set({[sponsorTimeKey]: []});
|
||||||
|
|
||||||
|
//request the sponsors from the server again
|
||||||
|
sponsorsLookup(currentVideoID);
|
||||||
} else {
|
} else {
|
||||||
//for a more detailed error message, they should check the popup
|
//for a more detailed error message, they should check the popup
|
||||||
//show that the upload failed
|
//show that the upload failed
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "SponsorBlock for YouTube - Skip Sponsorships",
|
"name": "SponsorBlock for YouTube - Skip Sponsorships",
|
||||||
"short_name": "SponsorBlock",
|
"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.",
|
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user