Added countdown to skip notice

This commit is contained in:
Ajay Ramachandran
2019-08-19 17:08:31 -04:00
parent cbab026f27
commit db2af83a34
2 changed files with 26 additions and 6 deletions

View File

@@ -45,9 +45,6 @@
"noticeTitle": { "noticeTitle": {
"message": "Sponsor Skipped" "message": "Sponsor Skipped"
}, },
"noticeClosingMessage": {
"message": "closes in 7s"
},
"reportButtonTitle": { "reportButtonTitle": {
"message": "Report" "message": "Report"
}, },

View File

@@ -5,7 +5,10 @@ class SkipNotice {
constructor(parent, UUID) { constructor(parent, UUID) {
this.parent = parent; this.parent = parent;
this.UUID = UUID; this.UUID = UUID;
//the countdown until this notice closes
this.countdownTime = 7;
//add notice //add notice
let amountOfPreviousNotices = document.getElementsByClassName("sponsorSkipNotice").length; let amountOfPreviousNotices = document.getElementsByClassName("sponsorSkipNotice").length;
@@ -50,7 +53,8 @@ class SkipNotice {
closeButtonContainer.style.top = "11px"; closeButtonContainer.style.top = "11px";
let timeLeft = document.createElement("span"); let timeLeft = document.createElement("span");
timeLeft.innerText = chrome.i18n.getMessage("noticeClosingMessage"); timeLeft.id = "sponsorSkipNoticeTimeLeft" + this.UUID;
timeLeft.innerText = this.countdownTime + "s";
timeLeft.className = "sponsorSkipObject sponsorSkipNoticeTimeLeft"; timeLeft.className = "sponsorSkipObject sponsorSkipNoticeTimeLeft";
let hideButton = document.createElement("img"); let hideButton = document.createElement("img");
@@ -148,7 +152,26 @@ class SkipNotice {
referenceNode.prepend(noticeElement); referenceNode.prepend(noticeElement);
//add closing listener //add closing listener
setTimeout(this.close.bind(this), 7000); this.countdownInterval = setInterval(this.countdown.bind(this), 1000);
}
//called every second to lower the countdown before hiding the notice
countdown() {
this.countdownTime--;
if (this.countdownTime <= 0) {
//remove this from setInterval
clearInterval(this.countdownInterval);
//time to close this notice
this.close();
return;
}
//update the timer display
let timeLeft = document.getElementById("sponsorSkipNoticeTimeLeft" + this.UUID);
timeLeft.innerText = this.countdownTime + "s";
} }
afterDownvote() { afterDownvote() {