mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-07 12:07:11 +03:00
Made it display the downloaded sponsor times in the popup as well.
This commit is contained in:
@@ -7,6 +7,9 @@ if(id = getYouTubeVideoID(document.URL)){ // Direct Links
|
|||||||
//was sponsor data found when doing SponsorsLookup
|
//was sponsor data found when doing SponsorsLookup
|
||||||
var sponsorDataFound = false;
|
var sponsorDataFound = false;
|
||||||
|
|
||||||
|
//the actual sponsorTimes if loaded
|
||||||
|
var sponsorTimes = undefined;
|
||||||
|
|
||||||
//the video
|
//the video
|
||||||
var v;
|
var v;
|
||||||
|
|
||||||
@@ -28,8 +31,10 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (request.message === 'isInfoFound') {
|
if (request.message === 'isInfoFound') {
|
||||||
|
//send the sponsor times along with if it's found
|
||||||
sendResponse({
|
sendResponse({
|
||||||
found: sponsorDataFound
|
found: sponsorDataFound,
|
||||||
|
sponsorTimes: sponsorTimes
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,10 @@
|
|||||||
<!-- If the video was found in the database -->
|
<!-- If the video was found in the database -->
|
||||||
<div id="videoFound">
|
<div id="videoFound">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="downloadedSponsorMessageTimes">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|||||||
31
popup.js
31
popup.js
@@ -67,6 +67,8 @@ function infoFound(request) {
|
|||||||
|
|
||||||
if (request.found) {
|
if (request.found) {
|
||||||
document.getElementById("videoFound").innerHTML = "This video's sponsors are in the database!"
|
document.getElementById("videoFound").innerHTML = "This video's sponsors are in the database!"
|
||||||
|
|
||||||
|
displayDownloadedVideoTimes(request);
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("videoFound").innerHTML = "No sponsors found"
|
document.getElementById("videoFound").innerHTML = "No sponsors found"
|
||||||
}
|
}
|
||||||
@@ -95,8 +97,6 @@ function sendSponsorStartMessage() {
|
|||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||||
if (request.message == "time") {
|
if (request.message == "time") {
|
||||||
let timeMessage = request.time.toFixed(2) + "s";
|
|
||||||
|
|
||||||
let videoTimesIndex = videoTimes.length - (startTimeChosen ? 1 : 0);
|
let videoTimesIndex = videoTimes.length - (startTimeChosen ? 1 : 0);
|
||||||
|
|
||||||
if (videoTimes[videoTimesIndex] == undefined) {
|
if (videoTimes[videoTimesIndex] == undefined) {
|
||||||
@@ -124,12 +124,25 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
|||||||
|
|
||||||
//display the video times from the array
|
//display the video times from the array
|
||||||
function displayVideoTimes() {
|
function displayVideoTimes() {
|
||||||
//make sure the div is empty first
|
//set it to the message
|
||||||
document.getElementById("sponsorMessageTimes").innerHTML = "";
|
document.getElementById("sponsorMessageTimes").innerHTML = getVideoTimesMessage(videoTimes);
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < videoTimes.length; i++) {
|
//display the video times from the array at the top, in a different section
|
||||||
for (let s = 0; s < videoTimes[i].length; s++) {
|
function displayDownloadedVideoTimes(request) {
|
||||||
let timeMessage = videoTimes[i][s] + "s";
|
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 this is an end time
|
||||||
if (s == 1) {
|
if (s == 1) {
|
||||||
timeMessage = " to " + timeMessage;
|
timeMessage = " to " + timeMessage;
|
||||||
@@ -138,9 +151,11 @@ function displayVideoTimes() {
|
|||||||
timeMessage = ", " + timeMessage;
|
timeMessage = ", " + timeMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("sponsorMessageTimes").innerHTML += timeMessage;
|
sponsorTimesMessage += timeMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return sponsorTimesMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearTimes() {
|
function clearTimes() {
|
||||||
|
|||||||
Reference in New Issue
Block a user