Made it display the downloaded sponsor times in the popup as well.

This commit is contained in:
Ajay Ramachandran 2019-07-09 18:03:56 -04:00
parent 52f95a0a84
commit 63ecc88392
3 changed files with 33 additions and 9 deletions

View file

@ -7,6 +7,9 @@ if(id = getYouTubeVideoID(document.URL)){ // Direct Links
//was sponsor data found when doing SponsorsLookup
var sponsorDataFound = false;
//the actual sponsorTimes if loaded
var sponsorTimes = undefined;
//the video
var v;
@ -28,8 +31,10 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
}
if (request.message === 'isInfoFound') {
//send the sponsor times along with if it's found
sendResponse({
found: sponsorDataFound
found: sponsorDataFound,
sponsorTimes: sponsorTimes
})
}

View file

@ -18,6 +18,10 @@
</div>
<div id="downloadedSponsorMessageTimes">
</div>
<br/>
<div>

View file

@ -67,6 +67,8 @@ function infoFound(request) {
if (request.found) {
document.getElementById("videoFound").innerHTML = "This video's sponsors are in the database!"
displayDownloadedVideoTimes(request);
} else {
document.getElementById("videoFound").innerHTML = "No sponsors found"
}
@ -95,8 +97,6 @@ function sendSponsorStartMessage() {
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
if (request.message == "time") {
let timeMessage = request.time.toFixed(2) + "s";
let videoTimesIndex = videoTimes.length - (startTimeChosen ? 1 : 0);
if (videoTimes[videoTimesIndex] == undefined) {
@ -124,12 +124,25 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
//display the video times from the array
function displayVideoTimes() {
//make sure the div is empty first
document.getElementById("sponsorMessageTimes").innerHTML = "";
//set it to the message
document.getElementById("sponsorMessageTimes").innerHTML = getVideoTimesMessage(videoTimes);
}
for (let i = 0; i < videoTimes.length; i++) {
for (let s = 0; s < videoTimes[i].length; s++) {
let timeMessage = videoTimes[i][s] + "s";
//display the video times from the array at the top, in a different section
function displayDownloadedVideoTimes(request) {
if (request.sponsorTimes != undefined) {
//set it to the message
document.getElementById("downloadedSponsorMessageTimes").innerHTML = getVideoTimesMessage(request.sponsorTimes);
}
}
//get the message that visually displays the video times
function getVideoTimesMessage(sponsorTimes) {
let sponsorTimesMessage = "";
for (let i = 0; i < sponsorTimes.length; i++) {
for (let s = 0; s < sponsorTimes[i].length; s++) {
let timeMessage = sponsorTimes[i][s].toFixed(1) + "s";
//if this is an end time
if (s == 1) {
timeMessage = " to " + timeMessage;
@ -138,9 +151,11 @@ function displayVideoTimes() {
timeMessage = ", " + timeMessage;
}
document.getElementById("sponsorMessageTimes").innerHTML += timeMessage;
sponsorTimesMessage += timeMessage;
}
}
return sponsorTimesMessage;
}
function clearTimes() {