Added "don't show this again" button to the notics

This commit is contained in:
Ajay Ramachandran
2019-07-09 22:10:25 -04:00
parent 81f88a3656
commit 257c045f7b
3 changed files with 70 additions and 5 deletions

View File

@@ -26,21 +26,31 @@ var lastTime;
//used for the go back button //used for the go back button
var lastSponsorTimeSkipped = null; var lastSponsorTimeSkipped = null;
//if the notice should not be shown
//happens when the user click's the "Don't show notice again" button
var dontShowNotice = false;
chrome.storage.local.get(["dontShowNoticeAgain"], function(result) {
let dontShowNoticeAgain = result.dontShowNoticeAgain;
if (dontShowNoticeAgain != undefined) {
dontShowNotice = dontShowNoticeAgain;
}
});
chrome.runtime.onMessage.addListener( // Detect URL Changes chrome.runtime.onMessage.addListener( // Detect URL Changes
function(request, sender, sendResponse) { function(request, sender, sendResponse) {
//message from background script //message from background script
if (request.message === 'ytvideoid') { if (request.message == "ytvideoid") {
//reset sponsor data found check //reset sponsor data found check
sponsorDataFound = false; sponsorDataFound = false;
sponsorsLookup(request.id); sponsorsLookup(request.id);
} }
//messages from popup script //messages from popup script
if (request.message === 'sponsorStart') { if (request.message == "sponsorStart") {
sponsorMessageStarted(); sponsorMessageStarted();
} }
if (request.message === 'isInfoFound') { if (request.message == "isInfoFound") {
//send the sponsor times along with if it's found //send the sponsor times along with if it's found
sendResponse({ sendResponse({
found: sponsorDataFound, found: sponsorDataFound,
@@ -48,11 +58,15 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
}) })
} }
if (request.message === 'getVideoID') { if (request.message == "getVideoID") {
sendResponse({ sendResponse({
videoID: getYouTubeVideoID(document.URL) videoID: getYouTubeVideoID(document.URL)
}) })
} }
if (request.message == "showNoticeAgain") {
dontShowNotice = false;
}
}); });
function sponsorsLookup(id) { function sponsorsLookup(id) {
@@ -112,6 +126,11 @@ function goBackToPreviousTime() {
//Opens the notice that tells the user that a sponsor was just skipped //Opens the notice that tells the user that a sponsor was just skipped
function openSkipNotice(){ function openSkipNotice(){
if (dontShowNotice) {
//don't show, return
return;
}
var noticeElement = document.createElement("div"); var noticeElement = document.createElement("div");
noticeElement.id = 'sponsorSkipNotice' noticeElement.id = 'sponsorSkipNotice'
@@ -146,8 +165,16 @@ function openSkipNotice(){
hideButton.style.marginTop = "5px"; hideButton.style.marginTop = "5px";
hideButton.addEventListener("click", closeSkipNotice); hideButton.addEventListener("click", closeSkipNotice);
var dontShowAgainButton = document.createElement("button");
dontShowAgainButton.innerText = "Don't Show This Again";
dontShowAgainButton.style.fontSize = "13px";
dontShowAgainButton.style.color = "#000000";
dontShowAgainButton.style.marginTop = "5px";
dontShowAgainButton.addEventListener("click", dontShowNoticeAgain);
buttonContainer.appendChild(goBackButton); buttonContainer.appendChild(goBackButton);
buttonContainer.appendChild(hideButton); buttonContainer.appendChild(hideButton);
buttonContainer.appendChild(dontShowAgainButton);
noticeElement.appendChild(noticeMessage); noticeElement.appendChild(noticeMessage);
noticeElement.appendChild(buttonContainer); noticeElement.appendChild(buttonContainer);
@@ -168,6 +195,14 @@ function closeSkipNotice(){
} }
} }
function dontShowNoticeAgain() {
chrome.storage.local.set({"dontShowNoticeAgain": true});
dontShowNotice = true;
closeSkipNotice();
}
function sponsorMessageStarted() { function sponsorMessageStarted() {
let v = document.querySelector('video'); let v = document.querySelector('video');

View File

@@ -40,6 +40,10 @@
<br/> <br/>
<button id="submitTimes">Submit Times</button> <button id="submitTimes">Submit Times</button>
<br/>
<button id="showNoticeAgain" style="display: none">Show Notice Again</button>
</div> </div>
</div> </div>
</center> </center>

View File

@@ -1,6 +1,8 @@
//setup click listeners
document.getElementById("sponsorStart").addEventListener("click", sendSponsorStartMessage); document.getElementById("sponsorStart").addEventListener("click", sendSponsorStartMessage);
document.getElementById("clearTimes").addEventListener("click", clearTimes); document.getElementById("clearTimes").addEventListener("click", clearTimes);
document.getElementById("submitTimes").addEventListener("click", submitTimes); document.getElementById("submitTimes").addEventListener("click", submitTimes);
document.getElementById("showNoticeAgain").addEventListener("click", showNoticeAgain);
//if true, the button now selects the end time //if true, the button now selects the end time
var startTimeChosen = false; var startTimeChosen = false;
@@ -14,6 +16,15 @@ var currentVideoID = null;
//is this a YouTube tab? //is this a YouTube tab?
var isYouTubeTab = false; var isYouTubeTab = false;
//if the don't show notice again variable is true, an option to
// disable should be available
chrome.storage.local.get(["dontShowNoticeAgain"], function(result) {
let dontShowNoticeAgain = result.dontShowNoticeAgain;
if (dontShowNoticeAgain != undefined && dontShowNoticeAgain) {
document.getElementById("showNoticeAgain").style.display = "unset";
}
});
//if no response comes by this point, give up //if no response comes by this point, give up
setTimeout(function() { setTimeout(function() {
if (!isYouTubeTab) { if (!isYouTubeTab) {
@@ -51,7 +62,7 @@ function loadTabData(tabs) {
//check if this video's sponsors are known //check if this video's sponsors are known
chrome.tabs.sendMessage( chrome.tabs.sendMessage(
tabs[0].id, tabs[0].id,
{from: 'popup', message: 'isInfoFound'}, {message: 'isInfoFound'},
infoFound infoFound
); );
} }
@@ -180,6 +191,21 @@ function submitTimes() {
} }
} }
function showNoticeAgain() {
chrome.storage.local.set({"dontShowNoticeAgain": false});
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
message: "showNoticeAgain"
});
});
document.getElementById("showNoticeAgain").style.display = "none";
}
//converts time in seconds to minutes:seconds //converts time in seconds to minutes:seconds
function getFormattedTime(seconds) { function getFormattedTime(seconds) {
let minutes = Math.floor(seconds / 60); let minutes = Math.floor(seconds / 60);