Made the skip notice work with TypeScript.

This commit is contained in:
Ajay Ramachandran
2020-02-01 18:17:48 -05:00
parent 20a09d3d27
commit 4bd410f04e
2 changed files with 30 additions and 13 deletions

View File

@@ -73,6 +73,19 @@ var sponsorTimesSubmitting = [];
//this is used to close the popup on YouTube when the other popup opens //this is used to close the popup on YouTube when the other popup opens
var popupInitialised = false; var popupInitialised = false;
// Contains all of the functions and variables needed by the skip notice
var skipNoticeContentContainer = {
vote,
dontShowNoticeAgain,
unskipSponsorTime,
sponsorTimes,
UUIDs,
v,
reskipSponsorTime,
hiddenSponsorTimes,
updatePreviewBar
};
//get messages from the background script and the popup //get messages from the background script and the popup
chrome.runtime.onMessage.addListener(messageListener); chrome.runtime.onMessage.addListener(messageListener);
@@ -564,7 +577,7 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
if (openNotice) { if (openNotice) {
//send out the message saying that a sponsor message was skipped //send out the message saying that a sponsor message was skipped
if (!SB.config.dontShowNotice) { if (!SB.config.dontShowNotice) {
let skipNotice = new SkipNotice(this, currentUUID, SB.config.disableAutoSkip); let skipNotice = new SkipNotice(this, currentUUID, SB.config.disableAutoSkip, skipNoticeContentContainer);
//TODO: Remove this when Invidious support is old //TODO: Remove this when Invidious support is old
if (SB.config.invidiousUpdateInfoShowCount < 5) { if (SB.config.invidiousUpdateInfoShowCount < 5) {

View File

@@ -7,16 +7,20 @@ class SkipNotice {
parent: HTMLElement; parent: HTMLElement;
UUID: string; UUID: string;
manualSkip: boolean; manualSkip: boolean;
// Contains functions and variables from the content script needed by the skip notice
contentContainer: any;
maxCountdownTime: () => number; maxCountdownTime: () => number;
countdownTime: any; countdownTime: any;
countdownInterval: NodeJS.Timeout; countdownInterval: NodeJS.Timeout;
unskipCallback: any; unskipCallback: any;
idSuffix: any; idSuffix: any;
constructor(parent: HTMLElement, UUID: string, manualSkip: boolean = false) { constructor(parent: HTMLElement, UUID: string, manualSkip: boolean = false, contentContainer) {
this.parent = parent; this.parent = parent;
this.UUID = UUID; this.UUID = UUID;
this.manualSkip = manualSkip; this.manualSkip = manualSkip;
this.contentContainer = contentContainer;
let noticeTitle = chrome.i18n.getMessage("noticeTitle"); let noticeTitle = chrome.i18n.getMessage("noticeTitle");
@@ -124,7 +128,7 @@ class SkipNotice {
downvoteButton.id = "sponsorTimesDownvoteButtonsContainer" + this.idSuffix; downvoteButton.id = "sponsorTimesDownvoteButtonsContainer" + this.idSuffix;
downvoteButton.className = "sponsorSkipObject voteButton"; downvoteButton.className = "sponsorSkipObject voteButton";
downvoteButton.src = chrome.extension.getURL("icons/report.png"); downvoteButton.src = chrome.extension.getURL("icons/report.png");
downvoteButton.addEventListener("click", () => vote(0, this.UUID, this)); downvoteButton.addEventListener("click", () => this.contentContainer.vote(0, this.UUID, this));
downvoteButton.setAttribute("title", chrome.i18n.getMessage("reportButtonInfo")); downvoteButton.setAttribute("title", chrome.i18n.getMessage("reportButtonInfo"));
//add downvote and report text to container //add downvote and report text to container
@@ -152,7 +156,7 @@ class SkipNotice {
let dontShowAgainButton = document.createElement("button"); let dontShowAgainButton = document.createElement("button");
dontShowAgainButton.innerText = chrome.i18n.getMessage("Hide"); dontShowAgainButton.innerText = chrome.i18n.getMessage("Hide");
dontShowAgainButton.className = "sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton"; dontShowAgainButton.className = "sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton";
dontShowAgainButton.addEventListener("click", dontShowNoticeAgain); dontShowAgainButton.addEventListener("click", this.contentContainer.dontShowNoticeAgain);
// Don't let them hide it if manually skipping // Don't let them hide it if manually skipping
if (!this.manualSkip) { if (!this.manualSkip) {
@@ -251,7 +255,7 @@ class SkipNotice {
} }
unskip() { unskip() {
unskipSponsorTime(this.UUID); this.contentContainer.unskipSponsorTime(this.UUID);
this.unskippedMode(chrome.i18n.getMessage("reskip")); this.unskippedMode(chrome.i18n.getMessage("reskip"));
} }
@@ -267,8 +271,8 @@ class SkipNotice {
//change max duration to however much of the sponsor is left //change max duration to however much of the sponsor is left
this.maxCountdownTime = function() { this.maxCountdownTime = function() {
let sponsorTime = sponsorTimes[UUIDs.indexOf(this.UUID)]; let sponsorTime = this.contentContainer.sponsorTimes[this.contentContainer.UUIDs.indexOf(this.UUID)];
let duration = Math.round(sponsorTime[1] - v.currentTime); let duration = Math.round(sponsorTime[1] - this.contentContainer.v.currentTime);
return Math.max(duration, 4); return Math.max(duration, 4);
}; };
@@ -278,7 +282,7 @@ class SkipNotice {
} }
reskip() { reskip() {
reskipSponsorTime(this.UUID); this.contentContainer.reskipSponsorTime(this.UUID);
//change reskip button to a unskip button //change reskip button to a unskip button
let unskipButton = this.changeUnskipButton(chrome.i18n.getMessage("unskip")); let unskipButton = this.changeUnskipButton(chrome.i18n.getMessage("unskip"));
@@ -296,7 +300,7 @@ class SkipNotice {
if (this.manualSkip) { if (this.manualSkip) {
this.changeNoticeTitle(chrome.i18n.getMessage("noticeTitle")); this.changeNoticeTitle(chrome.i18n.getMessage("noticeTitle"));
vote(1, this.UUID, this); this.contentContainer.vote(1, this.UUID, this);
} }
} }
@@ -320,14 +324,14 @@ class SkipNotice {
//remove this sponsor from the sponsors looked up //remove this sponsor from the sponsors looked up
//find which one it is //find which one it is
for (let i = 0; i < sponsorTimes.length; i++) { for (let i = 0; i < this.contentContainer.sponsorTimes.length; i++) {
if (UUIDs[i] == this.UUID) { if (this.contentContainer.UUIDs[i] == this.UUID) {
//this one is the one to hide //this one is the one to hide
//add this as a hidden sponsorTime //add this as a hidden sponsorTime
hiddenSponsorTimes.push(i); this.contentContainer.hiddenSponsorTimes.push(i);
updatePreviewBar(); this.contentContainer.updatePreviewBar();
break; break;
} }
} }