From 69dee25ea8d95aeacf338c5f4a80604f3a219f13 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 30 Jul 2019 20:43:45 +0100 Subject: [PATCH] "Improvements" to the Ref system --- popup.js | 75 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/popup.js b/popup.js index 71aa4e87..43a646df 100644 --- a/popup.js +++ b/popup.js @@ -1,32 +1,39 @@ -// References var SB = {}; -SB.sponsorStart = document.getElementById("sponsorStart"); -SB.clearTimes = document.getElementById("clearTimes"); -SB.submitTimes = document.getElementById("submitTimes"); -SB.showNoticeAgain = document.getElementById("showNoticeAgain"); -SB.hideVideoPlayerControls = document.getElementById("hideVideoPlayerControls"); -SB.showVideoPlayerControls = document.getElementById("showVideoPlayerControls"); -SB.hideInfoButtonPlayerControls = document.getElementById("hideInfoButtonPlayerControls"); -SB.showInfoButtonPlayerControls = document.getElementById("showInfoButtonPlayerControls"); -SB.hideDeleteButtonPlayerControls = document.getElementById("hideDeleteButtonPlayerControls"); -SB.showDeleteButtonPlayerControls = document.getElementById("showDeleteButtonPlayerControls"); -SB.disableSponsorViewTracking = document.getElementById("disableSponsorViewTracking"); -SB.enableSponsorViewTracking = document.getElementById("enableSponsorViewTracking"); -SB.optionsButton = document.getElementById("optionsButton"); -SB.reportAnIssue = document.getElementById("reportAnIssue"); +["sponsorStart", +"clearTimes", +"submitTimes", +"showNoticeAgain", +"hideVideoPlayerControls", +"showVideoPlayerControls", +"hideInfoButtonPlayerControls", +"showInfoButtonPlayerControls", +"hideDeleteButtonPlayerControls", +"showDeleteButtonPlayerControls", +"disableSponsorViewTracking", +"enableSponsorViewTracking", +"optionsButton", +"reportAnIssue", // sponsorTimesContributions -SB.sponsorTimesContributionsContainer = document.getElementById("sponsorTimesContributionsContainer"); -SB.sponsorTimesContributionsDisplay = document.getElementById("sponsorTimesContributionsDisplay"); -SB.sponsorTimesContributionsDisplayEndWord = document.getElementById("sponsorTimesContributionsDisplayEndWord"); +"sponsorTimesContributionsContainer", +"sponsorTimesContributionsDisplay", +"sponsorTimesContributionsDisplayEndWord", // sponsorTimesViewsDisplay -SB.sponsorTimesViewsContainer = document.getElementById("sponsorTimesViewsDisplayContainer"); -SB.sponsorTimesViewsDisplay = document.getElementById("sponsorTimesViewsDisplayDisplay"); -SB.sponsorTimesViewsDisplayEndWord = document.getElementById("sponsorTimesViewsDisplayDisplayEndWord"); +"sponsorTimesViewsContainer", +"sponsorTimesViewsDisplay", +"sponsorTimesViewsDisplayEndWord", // discordButtons -SB.discordButtonContainer = document.getElementById("discordButtonContainer"); -SB.hideDiscordButton = document.getElementById("hideDiscordButton"); +"discordButtonContainer", +"hideDiscordButton", +// More + "submissionSection", + "mainControls", + "loadingIndicator", + "videoFound", + "sponsorMessageTimes", + "downloadedSponsorMessageTimes", +].forEach(id => SB[id] = document.getElementById(id)); //setup click listeners SB.sponsorStart.addEventListener("click", sendSponsorStartMessage); @@ -186,7 +193,7 @@ function loadTabData(tabs) { displaySponsorTimes(); //show submission section - document.getElementById("submissionSection").style.display = "unset"; + submissionSection.style.display = "unset"; showSubmitTimesIfNecessary(); } @@ -214,15 +221,15 @@ function infoFound(request) { isYouTubeTab = true; //remove loading text - document.getElementById("mainControls").style.display = "unset" - document.getElementById("loadingIndicator").innerHTML = ""; + SB.mainControls.style.display = "unset" + SB.loadingIndicator.innerHTML = ""; if (request.found) { - document.getElementById("videoFound").innerHTML = "This video's sponsors are in the database!" + SB.videoFound.innerHTML = "This video's sponsors are in the database!" displayDownloadedSponsorTimes(request); } else { - document.getElementById("videoFound").innerHTML = "No sponsors found" + SB.videoFound.innerHTML = "No sponsors found" } } } @@ -266,30 +273,28 @@ function startSponsorCallback(response) { displaySponsorTimes(); //show submission section - document.getElementById("submissionSection").style.display = "unset"; + SB.submissionSection.style.display = "unset"; showSubmitTimesIfNecessary(); } //display the video times from the array function displaySponsorTimes() { - //set it to the message - let sponsorMessageTimes = document.getElementById("sponsorMessageTimes"); //remove all children - while (sponsorMessageTimes.firstChild) { - sponsorMessageTimes.removeChild(sponsorMessageTimes.firstChild); + while (SB.sponsorMessageTimes.firstChild) { + SB.sponsorMessageTimes.removeChild(SB.sponsorMessageTimes.firstChild); } //add sponsor times - sponsorMessageTimes.appendChild(getSponsorTimesMessageDiv(sponsorTimes)); + SB.sponsorMessageTimes.appendChild(getSponsorTimesMessageDiv(sponsorTimes)); } //display the video times from the array at the top, in a different section function displayDownloadedSponsorTimes(request) { if (request.sponsorTimes != undefined) { //set it to the message - document.getElementById("downloadedSponsorMessageTimes").innerHTML = getSponsorTimesMessage(request.sponsorTimes); + SB.downloadedSponsorMessageTimes.innerHTML = getSponsorTimesMessage(request.sponsorTimes); //add them as buttons to the issue reporting container let container = document.getElementById("issueReporterTimeButtons");