Renamed all instances of "videoTimes" to "sponsorTimes"

This commit is contained in:
Ajay Ramachandran
2019-07-09 19:46:55 -04:00
parent a1f645ea0e
commit 0df04a65fe
2 changed files with 33 additions and 33 deletions

View File

@@ -34,16 +34,16 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
function submitTimes(videoID) { function submitTimes(videoID) {
//get the video times from storage //get the video times from storage
let sponsorTimeKey = 'videoTimes' + videoID; let sponsorTimeKey = 'sponsorTimes' + videoID;
chrome.storage.local.get([sponsorTimeKey], function(result) { chrome.storage.local.get([sponsorTimeKey], function(result) {
let videoTimes = result[sponsorTimeKey]; let sponsorTimes = result[sponsorTimeKey];
if (videoTimes != undefined && videoTimes != []) { if (sponsorTimes != undefined && sponsorTimes != []) {
//submit these times //submit these times
for (let i = 0; i < videoTimes.length; i++) { for (let i = 0; i < sponsorTimes.length; i++) {
let xmlhttp = new XMLHttpRequest(); let xmlhttp = new XMLHttpRequest();
//submit the sponsorTime //submit the sponsorTime
xmlhttp.open('GET', 'http://localhost/api/postVideoSponsorTimes?videoID=' + videoID + "&startTime=" + videoTimes[i][0] + "&endTime=" + videoTimes[i][1], true); xmlhttp.open('GET', 'http://localhost/api/postVideoSponsorTimes?videoID=' + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1], true);
xmlhttp.send(); xmlhttp.send();
} }
} }
@@ -54,11 +54,11 @@ function videoIDChange(currentVideoID) {
//warn them if they had unsubmitted times //warn them if they had unsubmitted times
if (previousVideoID != null) { if (previousVideoID != null) {
//get the sponsor times from storage //get the sponsor times from storage
let sponsorTimeKey = 'videoTimes' + previousVideoID; let sponsorTimeKey = 'sponsorTimes' + previousVideoID;
chrome.storage.local.get([sponsorTimeKey], function(result) { chrome.storage.local.get([sponsorTimeKey], function(result) {
let videoTimes = result[sponsorTimeKey]; let sponsorTimes = result[sponsorTimeKey];
if (videoTimes != undefined && videoTimes.length > 0) { if (sponsorTimes != undefined && sponsorTimes.length > 0) {
//warn them that they have unsubmitted sponsor times //warn them that they have unsubmitted sponsor times
chrome.notifications.create("stillThere" + Math.random(), { chrome.notifications.create("stillThere" + Math.random(), {
type: "basic", type: "basic",

View File

@@ -6,7 +6,7 @@ document.getElementById("submitTimes").addEventListener("click", submitTimes);
var startTimeChosen = false; var startTimeChosen = false;
//the start and end time pairs (2d) //the start and end time pairs (2d)
var videoTimes = []; var sponsorTimes = [];
//current video ID of this tab //current video ID of this tab
var currentVideoID = null; var currentVideoID = null;
@@ -32,17 +32,17 @@ function loadTabData(tabs) {
currentVideoID = getYouTubeVideoID(tabs[0].url); currentVideoID = getYouTubeVideoID(tabs[0].url);
//load video times for this video //load video times for this video
let videoTimeKey = "videoTimes" + currentVideoID; let sponsorTimeKey = "sponsorTimes" + currentVideoID;
chrome.storage.local.get([videoTimeKey], function(result) { chrome.storage.local.get([sponsorTimeKey], function(result) {
videoTimes = result[videoTimeKey]; sponsorTimes = result[sponsorTimeKey];
if (videoTimes != undefined && videoTimes != []) { if (sponsorTimes != undefined && sponsorTimes != []) {
if (videoTimes[videoTimes.length - 1]!= undefined && videoTimes[videoTimes.length - 1].length < 2) { if (sponsorTimes[sponsorTimes.length - 1]!= undefined && sponsorTimes[sponsorTimes.length - 1].length < 2) {
startTimeChosen = true; startTimeChosen = true;
} }
displayVideoTimes(); displaySponsorTimes();
} else { } else {
videoTimes = [] sponsorTimes = []
} }
}); });
@@ -70,7 +70,7 @@ 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); displayDownloadedSponsorTimes(request);
} else { } else {
document.getElementById("videoFound").innerHTML = "No sponsors found" document.getElementById("videoFound").innerHTML = "No sponsors found"
} }
@@ -99,16 +99,16 @@ 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 videoTimesIndex = videoTimes.length - (startTimeChosen ? 1 : 0); let sponsorTimesIndex = sponsorTimes.length - (startTimeChosen ? 1 : 0);
if (videoTimes[videoTimesIndex] == undefined) { if (sponsorTimes[sponsorTimesIndex] == undefined) {
videoTimes[videoTimesIndex] = []; sponsorTimes[sponsorTimesIndex] = [];
} }
videoTimes[videoTimesIndex][startTimeChosen ? 1 : 0] = request.time; sponsorTimes[sponsorTimesIndex][startTimeChosen ? 1 : 0] = request.time;
let videoTimeKey = "videoTimes" + currentVideoID; let sponsorTimeKey = "sponsorTimes" + currentVideoID;
chrome.storage.local.set({[videoTimeKey]: videoTimes}); chrome.storage.local.set({[sponsorTimeKey]: sponsorTimes});
//update startTimeChosen variable //update startTimeChosen variable
if (!startTimeChosen) { if (!startTimeChosen) {
@@ -120,26 +120,26 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
} }
//display video times on screen //display video times on screen
displayVideoTimes(); displaySponsorTimes();
} }
}); });
//display the video times from the array //display the video times from the array
function displayVideoTimes() { function displaySponsorTimes() {
//set it to the message //set it to the message
document.getElementById("sponsorMessageTimes").innerHTML = getVideoTimesMessage(videoTimes); document.getElementById("sponsorMessageTimes").innerHTML = getSponsorTimesMessage(sponsorTimes);
} }
//display the video times from the array at the top, in a different section //display the video times from the array at the top, in a different section
function displayDownloadedVideoTimes(request) { function displayDownloadedSponsorTimes(request) {
if (request.sponsorTimes != undefined) { if (request.sponsorTimes != undefined) {
//set it to the message //set it to the message
document.getElementById("downloadedSponsorMessageTimes").innerHTML = getVideoTimesMessage(request.sponsorTimes); document.getElementById("downloadedSponsorMessageTimes").innerHTML = getSponsorTimesMessage(request.sponsorTimes);
} }
} }
//get the message that visually displays the video times //get the message that visually displays the video times
function getVideoTimesMessage(sponsorTimes) { function getSponsorTimesMessage(sponsorTimes) {
let sponsorTimesMessage = ""; let sponsorTimesMessage = "";
for (let i = 0; i < sponsorTimes.length; i++) { for (let i = 0; i < sponsorTimes.length; i++) {
@@ -161,12 +161,12 @@ function getVideoTimesMessage(sponsorTimes) {
} }
function clearTimes() { function clearTimes() {
videoTimes = []; sponsorTimes = [];
let videoTimeKey = "videoTimes" + currentVideoID; let sponsorTimeKey = "sponsorTimes" + currentVideoID;
chrome.storage.local.set({[videoTimeKey]: videoTimes}); chrome.storage.local.set({[sponsorTimeKey]: sponsorTimes});
displayVideoTimes(); displaySponsorTimes();
} }
function submitTimes() { function submitTimes() {