mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 21:47:06 +03:00
Made it generate and submit a userID defining this user.
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
var previousVideoID = null
|
var previousVideoID = null
|
||||||
|
|
||||||
|
//the id of this user, randomly generated once per install
|
||||||
|
var userID = null;
|
||||||
|
|
||||||
chrome.tabs.onUpdated.addListener( // On tab update
|
chrome.tabs.onUpdated.addListener( // On tab update
|
||||||
function(tabId, changeInfo, tab) {
|
function(tabId, changeInfo, tab) {
|
||||||
if (changeInfo != undefined && changeInfo.url != undefined) {
|
if (changeInfo != undefined && changeInfo.url != undefined) {
|
||||||
@@ -16,8 +19,6 @@ chrome.tabs.onUpdated.addListener( // On tab update
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||||
if (request.message == "submitTimes") {
|
if (request.message == "submitTimes") {
|
||||||
submitTimes(request.videoID);
|
submitTimes(request.videoID);
|
||||||
@@ -42,9 +43,13 @@ function submitTimes(videoID) {
|
|||||||
//submit these times
|
//submit these times
|
||||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
let xmlhttp = new XMLHttpRequest();
|
let xmlhttp = new XMLHttpRequest();
|
||||||
//submit the sponsorTime
|
|
||||||
xmlhttp.open('GET', 'http://localhost/api/postVideoSponsorTimes?videoID=' + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1], true);
|
let userIDStorage = getUserID(function(userIDStorage) {
|
||||||
xmlhttp.send();
|
//submit the sponsorTime
|
||||||
|
xmlhttp.open('GET', 'http://localhost/api/postVideoSponsorTimes?videoID=' + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1]
|
||||||
|
+ "&userID=" + userIDStorage, true);
|
||||||
|
xmlhttp.send();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -72,13 +77,38 @@ function videoIDChange(currentVideoID) {
|
|||||||
previousVideoID = currentVideoID;
|
previousVideoID = currentVideoID;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log(currentVideoID)
|
|
||||||
previousVideoID = currentVideoID;
|
previousVideoID = currentVideoID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUserID(callback) {
|
||||||
|
if (userID != null) {
|
||||||
|
callback(userID);
|
||||||
|
}
|
||||||
|
|
||||||
|
//if it is not cached yet, grab it from storage
|
||||||
|
chrome.storage.local.get(["userID"], function(result) {
|
||||||
|
let userIDStorage = result.userID;
|
||||||
|
if (userIDStorage != undefined) {
|
||||||
|
userID = userIDStorage;
|
||||||
|
callback(userID);
|
||||||
|
} else {
|
||||||
|
//generate a userID
|
||||||
|
userID = generateUUID();
|
||||||
|
|
||||||
|
//save this UUID
|
||||||
|
chrome.storage.local.set({"userID": userID});
|
||||||
|
|
||||||
|
callback(userID);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getYouTubeVideoID(url) { // Return video id or false
|
function getYouTubeVideoID(url) { // Return video id or false
|
||||||
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
||||||
var match = url.match(regExp);
|
var match = url.match(regExp);
|
||||||
return (match && match[7].length == 11) ? match[7] : false;
|
return (match && match[7].length == 11) ? match[7] : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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)}
|
||||||
@@ -108,7 +108,7 @@ function sponsorCheck(sponsorTimes) { // Video skipping
|
|||||||
//send out the message saying that a sponsor message was skipped
|
//send out the message saying that a sponsor message was skipped
|
||||||
openSkipNotice();
|
openSkipNotice();
|
||||||
|
|
||||||
// setTimeout(closeSkipNotice, 2500);
|
setTimeout(closeSkipNotice, 2500);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTime = v.currentTime;
|
lastTime = v.currentTime;
|
||||||
|
|||||||
Reference in New Issue
Block a user