Added status if the video is in the database and fixed some errors.

This commit is contained in:
Ajay Ramachandran 2019-07-09 00:05:27 -04:00
parent 2f32ead924
commit fc8257e491
3 changed files with 38 additions and 5 deletions

View file

@ -9,10 +9,16 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
SponsorsLookup(request.id); SponsorsLookup(request.id);
} }
//message from popup script //messages from popup script
if (request.message === 'sponsorStart') { if (request.message === 'sponsorStart') {
sponsorMessageStarted(); sponsorMessageStarted();
} }
if (request.message === 'infoFound') {
sendResponse({
found: true
})
}
}); });
function SponsorsLookup(id) { function SponsorsLookup(id) {

View file

@ -7,6 +7,14 @@
<div class="main"> <div class="main">
<center> <center>
<h1>SponsorBlock</h1> <h1>SponsorBlock</h1>
<!-- If the video was found in the database -->
<div id="videoFound">
</div>
<br/>
<div> <div>
<button id="sponsorStart">Sponsorship Starts</button> <button id="sponsorStart">Sponsorship Starts</button>
</div> </div>

View file

@ -8,10 +8,10 @@ var startTimeChosen = false;
var videoTimes = []; var videoTimes = [];
//load video times //load video times
chrome.storage.local.get(['videoTimes'], function(result) { chrome.storage.local.get(['videoTimes'], function(result) {
if (result.videoTimes != undefined) { if (result.videoTimes != undefined && result.videoTimes != []) {
videoTimes = result.videoTimes; videoTimes = result.videoTimes;
if (videoTimes[videoTimes.length - 1].length < 2) { if (videoTimes[videoTimes.length - 1]!= undefined && videoTimes[videoTimes.length - 1].length < 2) {
startTimeChosen = true; startTimeChosen = true;
} }
@ -19,16 +19,35 @@ chrome.storage.local.get(['videoTimes'], function(result) {
} }
}); });
//check if this video's sponsors are known
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
chrome.tabs.sendMessage(
tabs[0].id,
{from: 'popup', message: 'infoFound'},
infoFound
);
})
function infoFound(request) {
if (request.found) {
document.getElementById("videoFound").innerHTML = "This video's sponsors are in the database!"
} else {
document.getElementById("videoFound").innerHTML = "No sponsors found"
}
}
function sendSponsorStartMessage() { function sendSponsorStartMessage() {
//the content script will get the message if a YouTube page is open //the content script will get the message if a YouTube page is open
chrome.tabs.query({ chrome.tabs.query({
active: true, active: true,
currentWindow: true currentWindow: true
}, tabs => { }, tabs => {
// ...and send a request for the DOM info...
chrome.tabs.sendMessage( chrome.tabs.sendMessage(
tabs[0].id, tabs[0].id,
{from: 'popup', subject: 'DOMInfo', message: 'sponsorStart'} {from: 'popup', message: 'sponsorStart'}
); );
}); });
} }