Merge pull request #132 from ajayyy/experimental-ajay

More checks + popup fix
This commit is contained in:
Ajay Ramachandran 2019-08-23 20:31:29 -04:00 committed by GitHub
commit dcbd7ba4cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 4 deletions

View file

@ -147,11 +147,29 @@ function submitVote(type, UUID, callback) {
function submitTimes(videoID, callback) {
//get the video times from storage
let sponsorTimeKey = 'sponsorTimes' + videoID;
chrome.storage.sync.get([sponsorTimeKey, "userID"], function(result) {
chrome.storage.sync.get([sponsorTimeKey, "userID"], async function(result) {
let sponsorTimes = result[sponsorTimeKey];
let userID = result.userID;
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
let durationResult = await new Promise((resolve, reject) => {
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
message: "getVideoDuration"
}, (response) => resolve(response));
});
});
//check if a sponsor exceeds the duration of the video
for (let i = 0; i < sponsorTimes.length; i++) {
if (sponsorTimes[i][1] > durationResult.duration) {
sponsorTimes[i][1] = durationResult.duration;
}
}
//submit these times
for (let i = 0; i < sponsorTimes.length; i++) {
//submit the sponsorTime

View file

@ -128,6 +128,12 @@ function messageListener(request, sender, sendResponse) {
})
}
if (request.message == "getVideoDuration") {
sendResponse({
duration: v.duration
});
}
if (request.message == "skipToTime") {
v.currentTime = request.time;
}
@ -329,6 +335,9 @@ function sponsorsLookup(id) {
}
//check database for sponsor times
//made true once a setTimeout has been created to try again after a server error
let recheckStarted = false;
sendRequestToServer('GET', "/api/getVideoSponsorTimes?videoID=" + id, function(xmlhttp) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
sponsorDataFound = true;
@ -364,7 +373,9 @@ function sponsorsLookup(id) {
});
sponsorLookupRetries = 0;
} else if (xmlhttp.readyState == 4 && sponsorLookupRetries < 90) {
} else if (xmlhttp.readyState == 4 && sponsorLookupRetries < 90 && !recheckStarted) {
recheckStarted = true;
//some error occurred, try again in a second
setTimeout(() => sponsorsLookup(id), 1000);
@ -953,6 +964,15 @@ function submitSponsorTimes() {
let sponsorTimes = result[sponsorTimeKey];
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
//check if a sponsor exceeds the duration of the video
for (let i = 0; i < sponsorTimes.length; i++) {
if (sponsorTimes[i][1] > v.duration) {
sponsorTimes[i][1] = v.duration;
}
}
//update sponsorTimes
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes);
confirmMessage += "\n\n" + chrome.i18n.getMessage("confirmMSG");
if(!confirm(confirmMessage)) return;

View file

@ -981,7 +981,7 @@ function runThePopup() {
//set it to false
function resetStartTimeChosen() {
startTimeChosen = false;
SB.sponsorStart.innerHTML = "SP_START";
SB.sponsorStart.innerHTML = chrome.i18n.getMessage("sponsorStart");
}
//hides and shows the submit times button when needed
@ -1278,7 +1278,7 @@ function runThePopup() {
if (chrome.tabs != undefined) {
//add the width restriction (because Firefox)
document.getElementById("sponorBlockStyleSheet").sheet.insertRule('.popupBody { width: 300 }', 0);
document.getElementById("sponorBlockStyleSheet").sheet.insertRule('.popupBody { width: 325 }', 0);
//this means it is actually opened in the popup
runThePopup();