From 5d0559aebd4fead6c4e8ee9725ff25d859ef59c0 Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Mon, 14 Dec 2020 23:37:35 +0100 Subject: refactor: remove dead code, add more types --- src/background.ts | 6 ++++-- src/components/CategoryChooserComponent.tsx | 1 - src/components/CategorySkipOptionsComponent.tsx | 3 --- src/components/NoticeComponent.tsx | 2 +- src/components/NoticeTextSectionComponent.tsx | 2 +- src/components/SkipNoticeComponent.tsx | 19 ++++++------------- src/config.ts | 2 +- src/globals.d.ts | 19 +++++++++++++++++++ src/utils.ts | 3 +-- 9 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 src/globals.d.ts (limited to 'src') diff --git a/src/background.ts b/src/background.ts index 2bab479f..5d7ad4c5 100644 --- a/src/background.ts +++ b/src/background.ts @@ -2,8 +2,10 @@ import * as CompileConfig from "../config.json"; import Config from "./config"; import { Registration } from "./types"; + // Make the config public for debugging purposes -( window).SB = Config; + +window.SB = Config; import Utils from "./utils"; const utils = new Utils({ @@ -70,7 +72,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { }); //add help page on install -chrome.runtime.onInstalled.addListener(function (object) { +chrome.runtime.onInstalled.addListener(function () { // This let's the config sync to run fully before checking. // This is required on Firefox setTimeout(function() { diff --git a/src/components/CategoryChooserComponent.tsx b/src/components/CategoryChooserComponent.tsx index 19d9d589..bb86e10f 100644 --- a/src/components/CategoryChooserComponent.tsx +++ b/src/components/CategoryChooserComponent.tsx @@ -1,6 +1,5 @@ import * as React from "react"; -import Config from "../config" import * as CompileConfig from "../../config.json"; import CategorySkipOptionsComponent from "./CategorySkipOptionsComponent"; diff --git a/src/components/CategorySkipOptionsComponent.tsx b/src/components/CategorySkipOptionsComponent.tsx index b190223d..3cc03527 100644 --- a/src/components/CategorySkipOptionsComponent.tsx +++ b/src/components/CategorySkipOptionsComponent.tsx @@ -2,9 +2,6 @@ import * as React from "react"; import Config from "../config" import { CategorySkipOption } from "../types"; -import Utils from "../utils"; - -const utils = new Utils(); export interface CategorySkipOptionsProps { category: string; diff --git a/src/components/NoticeComponent.tsx b/src/components/NoticeComponent.tsx index 94b3fd56..9fff3be4 100644 --- a/src/components/NoticeComponent.tsx +++ b/src/components/NoticeComponent.tsx @@ -28,7 +28,7 @@ export interface NoticeState { class NoticeComponent extends React.Component { countdownInterval: NodeJS.Timeout; - idSuffix: any; + idSuffix: string; amountOfPreviousNotices: number; diff --git a/src/components/NoticeTextSectionComponent.tsx b/src/components/NoticeTextSectionComponent.tsx index cbcbb7b2..5e74a1d6 100644 --- a/src/components/NoticeTextSectionComponent.tsx +++ b/src/components/NoticeTextSectionComponent.tsx @@ -3,7 +3,7 @@ import * as React from "react"; export interface NoticeTextSelectionProps { text: string, idSuffix: string, - onClick?: (event: React.MouseEvent) => any + onClick?: (event: React.MouseEvent) => unknown } export interface NoticeTextSelectionState { diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index 5618c907..cd7b8205 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -2,10 +2,6 @@ import * as React from "react"; import * as CompileConfig from "../../config.json"; import Config from "../config" import { ContentContainer, SponsorHideType, SponsorTime } from "../types"; - -import Utils from "../utils"; -const utils = new Utils(); - import NoticeComponent from "./NoticeComponent"; import NoticeTextSelectionComponent from "./NoticeTextSectionComponent"; @@ -42,7 +38,7 @@ export interface SkipNoticeState { downvoting: boolean; choosingCategory: boolean; - thanksForVotingText: boolean; //null until the voting buttons should be hidden + thanksForVotingText: string; //null until the voting buttons should be hidden actionState: SkipNoticeAction; } @@ -447,7 +443,7 @@ class SkipNoticeComponent extends React.Component this.reskip(index), - - //change max duration to however much of the sponsor is left + // change max duration to however much of the sponsor is left maxCountdownTime: maxCountdownTime, - countdownTime: maxCountdownTime() - } + } as SkipNoticeState; } reskip(index: number): void { @@ -508,7 +501,7 @@ class SkipNoticeComponent extends React.Component any, ...messages: string[]): void { + setNoticeInfoMessageWithOnClick(onClick: (event: React.MouseEvent) => unknown, ...messages: string[]): void { this.setState({ messages, messageOnClick: (event) => onClick(event) @@ -521,7 +514,7 @@ class SkipNoticeComponent extends React.Component; defaults: SBConfig; localConfig: SBConfig; diff --git a/src/globals.d.ts b/src/globals.d.ts new file mode 100644 index 00000000..ed8547a0 --- /dev/null +++ b/src/globals.d.ts @@ -0,0 +1,19 @@ +import { SBObject } from "./config"; +declare global { + interface Window { SB: SBObject; } + // Remove this once the API becomes stable and types are shipped in @types/chrome + namespace chrome { + namespace declarativeContent { + export interface RequestContentScriptOptions { + allFrames?: boolean; + css?: string[]; + instanceType?: "declarativeContent.RequestContentScript"; + js?: string[]; + matchAboutBlanck?: boolean; + } + export class RequestContentScript { + constructor(options: RequestContentScriptOptions); + } + } + } +} diff --git a/src/utils.ts b/src/utils.ts index 149d99cf..65392ad2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -119,8 +119,7 @@ class Utils { const rule = { id: "invidious", conditions, - // This API is experimental and not visible by the TypeScript compiler - actions: [new ( chrome.declarativeContent).RequestContentScript({ + actions: [new chrome.declarativeContent.RequestContentScript({ allFrames: true, js: self.js, css: self.css -- cgit v1.2.3 From 7756a89960b88a61a3df49ef55a45d4dc55131dd Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Tue, 15 Dec 2020 12:58:44 +0100 Subject: refactor: remove more unused variables --- src/config.ts | 4 ++-- src/content.ts | 10 ++++------ src/options.ts | 10 +++++----- 3 files changed, 11 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/config.ts b/src/config.ts index b2c85d32..f06ba3b0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -276,7 +276,7 @@ function decodeStoredItem(id: string, data: T): T | SBMap { + chrome.storage.onChanged.addListener((changes) => { for (const key in changes) { Config.localConfig[key] = decodeStoredItem(key, changes[key].newValue); } @@ -315,7 +315,7 @@ function configProxy(): any { } function fetchConfig(): Promise { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { chrome.storage.sync.get(null, function(items) { Config.localConfig = items; // Data is ready resolve(); diff --git a/src/content.ts b/src/content.ts index cded9c45..18b7a646 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1,6 +1,6 @@ import Config from "./config"; -import { SponsorTime, CategorySkipOption, CategorySelection, VideoID, SponsorHideType, FetchResponse } from "./types"; +import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse } from "./types"; import { ContentContainer } from "./types"; import Utils from "./utils"; @@ -740,7 +740,7 @@ function startSkipScheduleCheckingForStartSponsors() { * Get the video info for the current tab from YouTube */ function getVideoInfo() { - sendRequestToCustomServer('GET', "https://www.youtube.com/get_video_info?video_id=" + sponsorVideoID, function(xmlhttp, error) { + sendRequestToCustomServer('GET', "https://www.youtube.com/get_video_info?video_id=" + sponsorVideoID, function(xmlhttp) { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { const decodedData = decodeURIComponent(xmlhttp.responseText).match(/player_response=([^&]*)/)[1]; if (!decodedData) { @@ -1051,7 +1051,7 @@ function createButton(baseID, title, callback, imageName, isDraggable=false): bo newButton.classList.add("playerButton"); newButton.classList.add("ytp-button"); newButton.setAttribute("title", chrome.i18n.getMessage(title)); - newButton.addEventListener("click", (event: Event) => { + newButton.addEventListener("click", () => { callback(); }); @@ -1435,8 +1435,6 @@ function submitSponsorTimes() { //it can't update to this info yet closeInfoMenu(); - const currentVideoID = sponsorVideoID; - if (sponsorTimesSubmitting !== undefined && sponsorTimesSubmitting.length > 0) { submissionNotice = new SubmissionNotice(skipNoticeContentContainer, sendSubmitMessage); } @@ -1583,7 +1581,7 @@ function sendRequestToCustomServer(type, fullAddress, callback) { callback(xmlhttp, false); }; - xmlhttp.onerror = function(ev) { + xmlhttp.onerror = function() { callback(xmlhttp, true); }; } diff --git a/src/options.ts b/src/options.ts index 979dac6b..c5631f7b 100644 --- a/src/options.ts +++ b/src/options.ts @@ -2,7 +2,7 @@ import Config from "./config"; import * as CompileConfig from "../config.json"; // Make the config public for debugging purposes -( window).SB = Config; +window.SB = Config; import Utils from "./utils"; import CategoryChooser from "./render/CategoryChooser"; @@ -107,7 +107,7 @@ async function init() { // Permission needed on Firefox if (utils.isFirefox()) { - const permissionSuccess = await new Promise((resolve, reject) => { + const permissionSuccess = await new Promise((resolve) => { chrome.permissions.request({ origins: [textChangeInput.value + "/"], permissions: [] @@ -202,7 +202,7 @@ async function init() { * * @param {String} element */ -function optionsConfigUpdateListener(changes) { +function optionsConfigUpdateListener() { const optionsContainer = document.getElementById("options"); const optionsElements = optionsContainer.querySelectorAll("*"); @@ -243,7 +243,7 @@ function invidiousInstanceAddInit(element: HTMLElement, option: string) { const button = element.querySelector(".trigger-button"); const setButton = element.querySelector(".text-change-set"); - setButton.addEventListener("click", async function(e) { + setButton.addEventListener("click", async function() { if (textBox.value == "" || textBox.value.includes("/") || textBox.value.includes("http")) { alert(chrome.i18n.getMessage("addInvidiousInstanceError")); } else { @@ -269,7 +269,7 @@ function invidiousInstanceAddInit(element: HTMLElement, option: string) { }); const resetButton = element.querySelector(".invidious-instance-reset"); - resetButton.addEventListener("click", function(e) { + resetButton.addEventListener("click", function() { if (confirm(chrome.i18n.getMessage("resetInvidiousInstanceAlert"))) { // Set to a clone of the default Config.config[option] = Config.defaults[option].slice(0); -- cgit v1.2.3 From b7ea5689c75fdb6aca0867c74e8687d08a8f62b1 Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Tue, 15 Dec 2020 13:33:38 +0100 Subject: refactor(types): add VideoInfo interface --- src/content.ts | 4 +-- src/types.ts | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/content.ts b/src/content.ts index 18b7a646..f176980a 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1,6 +1,6 @@ import Config from "./config"; -import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse } from "./types"; +import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo } from "./types"; import { ContentContainer } from "./types"; import Utils from "./utils"; @@ -25,7 +25,7 @@ let sponsorTimes: SponsorTime[] = null; let sponsorVideoID: VideoID = null; // JSON video info -let videoInfo: any = null; +let videoInfo: VideoInfo = null; //the channel this video is about let channelID; diff --git a/src/types.ts b/src/types.ts index d7818e01..423adf1e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -78,6 +78,82 @@ interface BackgroundScriptContainer { unregisterFirefoxContentScript: (id: string) => void } +interface VideoInfo { + responseContext: { + serviceTrackingParams: Array<{service: string, params: Array<{key: string, value: string}>}>, + webResponseContextExtensionData: { + hasDecorated: boolean + } + }, + playabilityStatus: { + status: string, + playableInEmbed: boolean, + miniplayer: { + miniplayerRenderer: { + playbackMode: string + } + } + }; + streamingData: unknown; + playbackTracking: unknown; + videoDetails: { + videoId: string, + title: string, + lengthSeconds: string, + keywords: string[], + channelId: string, + isOwnerViewing: boolean, + shortDescription: string, + isCrawlable: boolean, + thumbnail: { + thumbnails: Array<{url: string, width: number, height: number}> + }, + averageRating: number, + allowRatings: boolean, + viewCount: string, + author: string, + isPrivate: boolean, + isUnpluggedCorpus: boolean, + isLiveContent: boolean, + }; + playerConfig: unknown; + storyboards: unknown; + microformat: { + playerMicroformatRenderer: { + thumbnail: { + thumbnails: Array<{url: string, width: number, height: number}> + }, + embed: { + iframeUrl: string, + flashUrl: string, + width: number, + height: number, + flashSecureUrl: string, + }, + title: { + simpleText: string, + }, + description: { + simpleText: string, + }, + lengthSeconds: string, + ownerProfileUrl: string, + externalChannelId: string, + availableCountries: string[], + isUnlisted: boolean, + hasYpcMetadata: boolean, + viewCount: string, + category: string, + publishDate: string, + ownerChannelName: string, + uploadDate: string, + } + }; + trackingParams: string; + attestation: unknown; + messages: unknown; +} + type VideoID = string; export { @@ -91,5 +167,6 @@ export { SponsorHideType, PreviewBarOption, Registration, - BackgroundScriptContainer + BackgroundScriptContainer, + VideoInfo, }; -- cgit v1.2.3 From dc36e8097dbbdad0dd80bc314d14d7e6129dc3d2 Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Tue, 15 Dec 2020 13:34:02 +0100 Subject: refactor: remove unused function --- src/config.ts | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src') diff --git a/src/config.ts b/src/config.ts index f06ba3b0..f2f8f479 100644 --- a/src/config.ts +++ b/src/config.ts @@ -439,11 +439,6 @@ async function setupConfig() { Config.config = config; } -// Reset config -function resetConfig() { - Config.config = Config.defaults; -} - function convertJSON(): void { Object.keys(Config.localConfig).forEach(key => { Config.localConfig[key] = decodeStoredItem(key, Config.localConfig[key]); -- cgit v1.2.3 From 094ef84f15f6ddbdfe45b3d0f56f0f4821ff972c Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Tue, 15 Dec 2020 14:24:29 +0100 Subject: refactor(types): add StorageChangesObject type --- src/config.ts | 6 +++--- src/content.ts | 4 ++-- src/types.ts | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/config.ts b/src/config.ts index f2f8f479..4726ae4c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,5 @@ import * as CompileConfig from "../config.json"; -import { CategorySelection, CategorySkipOption, PreviewBarOption, SponsorTime } from "./types"; +import { CategorySelection, CategorySkipOption, PreviewBarOption, SponsorTime, StorageChangesObject } from "./types"; import Utils from "./utils"; const utils = new Utils(); @@ -59,7 +59,7 @@ interface SBConfig { } export interface SBObject { - configListeners: Array; + configListeners: Array<(changes: StorageChangesObject) => unknown>; defaults: SBConfig; localConfig: SBConfig; config: SBConfig; @@ -276,7 +276,7 @@ function decodeStoredItem(id: string, data: T): T | SBMap { + chrome.storage.onChanged.addListener((changes: {[key: string]: chrome.storage.StorageChange}) => { for (const key in changes) { Config.localConfig[key] = decodeStoredItem(key, changes[key].newValue); } diff --git a/src/content.ts b/src/content.ts index f176980a..1e5743b1 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1,6 +1,6 @@ import Config from "./config"; -import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo } from "./types"; +import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject } from "./types"; import { ContentContainer } from "./types"; import Utils from "./utils"; @@ -179,7 +179,7 @@ function messageListener(request: any, sender: any, sendResponse: (response: any * * @param {String} changes */ -function contentConfigUpdateListener(changes) { +function contentConfigUpdateListener(changes: StorageChangesObject) { for (const key in changes) { switch(key) { case "hideVideoPlayerControls": diff --git a/src/types.ts b/src/types.ts index 423adf1e..1d282cbe 100644 --- a/src/types.ts +++ b/src/types.ts @@ -156,6 +156,8 @@ interface VideoInfo { type VideoID = string; +type StorageChangesObject = { [key: string]: chrome.storage.StorageChange }; + export { FetchResponse, VideoDurationResponse, @@ -169,4 +171,5 @@ export { Registration, BackgroundScriptContainer, VideoInfo, + StorageChangesObject, }; -- cgit v1.2.3 From 09c527417def476887de7d8344686d857e5ad87c Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Tue, 15 Dec 2020 18:29:47 +0100 Subject: refactor: type 'config' Proxy --- src/config.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/config.ts b/src/config.ts index 4726ae4c..2a40dbf6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -275,7 +275,7 @@ function decodeStoredItem(id: string, data: T): T | SBMap { for (const key in changes) { Config.localConfig[key] = decodeStoredItem(key, changes[key].newValue); @@ -286,8 +286,8 @@ function configProxy(): any { } }); - const handler: ProxyHandler = { - set(obj, prop, value) { + const handler: ProxyHandler = { + set(obj: SBConfig, prop: K, value: SBConfig[K]) { Config.localConfig[prop] = value; chrome.storage.sync.set({ @@ -297,13 +297,13 @@ function configProxy(): any { return true; }, - get(obj, prop): any { + get(obj: SBConfig, prop: K): SBConfig[K] { const data = Config.localConfig[prop]; return obj[prop] || data; }, - deleteProperty(obj, prop) { + deleteProperty(obj: SBConfig, prop: keyof SBConfig) { chrome.storage.sync.remove( prop); return true; @@ -311,7 +311,7 @@ function configProxy(): any { }; - return new Proxy({handler}, handler); + return new Proxy({handler} as unknown as SBConfig, handler); } function fetchConfig(): Promise { -- cgit v1.2.3 From c0d910decd4c088989d42a6473ba84721babbf36 Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Tue, 15 Dec 2020 19:54:33 +0100 Subject: refactor: more types and dead code removal --- src/content.ts | 10 +++++----- src/js-components/previewBar.ts | 14 +++++++------- src/options.ts | 4 ++-- src/popup.ts | 2 +- src/types.ts | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/content.ts b/src/content.ts index 1e5743b1..8f895cd5 100644 --- a/src/content.ts +++ b/src/content.ts @@ -27,7 +27,7 @@ let sponsorVideoID: VideoID = null; // JSON video info let videoInfo: VideoInfo = null; //the channel this video is about -let channelID; +let channelID: string; // Skips are scheduled to ensure precision. // Skips are rescheduled every seeking event. @@ -112,7 +112,7 @@ const skipNoticeContentContainer: ContentContainer = () => ({ //get messages from the background script and the popup chrome.runtime.onMessage.addListener(messageListener); -function messageListener(request: any, sender: any, sendResponse: (response: any) => void): void { +function messageListener(request: any, sender: unknown, sendResponse: (response: any) => void): void { //messages from popup script switch(request.message){ case "update": @@ -363,7 +363,7 @@ function handleMobileControlsMutations(): void { if (previewBar !== null) { if (document.body.contains(previewBar.container)) { - updatePreviewBarPositionMobile(document.getElementsByClassName(mobileYouTubeSelector)[0]); + updatePreviewBarPositionMobile(document.getElementsByClassName(mobileYouTubeSelector)[0] as HTMLElement); return; } else { @@ -397,7 +397,7 @@ function createPreviewBar(): void { const el = document.querySelectorAll(selector); if (el && el.length && el[0]) { - previewBar = new PreviewBar(el[0], onMobileYouTube, onInvidious); + previewBar = new PreviewBar(el[0] as HTMLElement, onMobileYouTube, onInvidious); updatePreviewBar(); @@ -798,7 +798,7 @@ function getYouTubeVideoID(url: string) { /** * This function is required on mobile YouTube and will keep getting called whenever the preview bar disapears */ -function updatePreviewBarPositionMobile(parent: Element) { +function updatePreviewBarPositionMobile(parent: HTMLElement) { if (document.getElementById("previewbar") === null) { previewBar.updatePosition(parent); } diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts index f5ab07fa..a1f4e2c3 100644 --- a/src/js-components/previewBar.ts +++ b/src/js-components/previewBar.ts @@ -11,14 +11,14 @@ const utils = new Utils(); class PreviewBar { container: HTMLUListElement; - parent: any; + parent: HTMLElement; onMobileYouTube: boolean; onInvidious: boolean; timestamps: number[][]; types: string[]; - constructor(parent: any, onMobileYouTube: boolean, onInvidious: boolean) { + constructor(parent: HTMLElement, onMobileYouTube: boolean, onInvidious: boolean) { this.container = document.createElement('ul'); this.container.id = 'previewbar'; this.parent = parent; @@ -47,16 +47,16 @@ class PreviewBar { let mouseOnSeekBar = false; - seekBar.addEventListener("mouseenter", (event) => { + seekBar.addEventListener("mouseenter", () => { mouseOnSeekBar = true; }); - seekBar.addEventListener("mouseleave", (event) => { + seekBar.addEventListener("mouseleave", () => { mouseOnSeekBar = false; categoryTooltip.classList.add("sbHidden"); }); - const observer = new MutationObserver((mutations, observer) => { + const observer = new MutationObserver((mutations) => { if (!mouseOnSeekBar) return; // See if mutation observed is only this ID (if so, ignore) @@ -112,7 +112,7 @@ class PreviewBar { }); } - updatePosition(parent: any): void { + updatePosition(parent: HTMLElement): void { //below the seek bar // this.parent.insertAdjacentElement("afterEnd", this.container); @@ -126,7 +126,7 @@ class PreviewBar { } //on the seek bar - this.parent.insertAdjacentElement("afterBegin", this.container); + this.parent.insertAdjacentElement("afterbegin", this.container); } updateColor(segment: string, color: string, opacity: string): void { diff --git a/src/options.ts b/src/options.ts index c5631f7b..186e442a 100644 --- a/src/options.ts +++ b/src/options.ts @@ -536,7 +536,7 @@ function copyDebugOutputToClipboard() { .then(() => { alert(chrome.i18n.getMessage("copyDebugInformationComplete")); }) - .catch((err) => { + .catch(() => { alert(chrome.i18n.getMessage("copyDebugInformationFailed")); }); -} \ No newline at end of file +} diff --git a/src/popup.ts b/src/popup.ts index 1ccc7cae..5fb87bcf 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -5,7 +5,7 @@ import { SponsorTime, SponsorHideType } from "./types"; const utils = new Utils(); interface MessageListener { - (request: any, sender: any, callback: (response: any) => void): void; + (request: any, sender: unknown, callback: (response: any) => void): void; } class MessageHandler { diff --git a/src/types.ts b/src/types.ts index 1d282cbe..64afe352 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,7 +3,7 @@ import SkipNoticeComponent from "./components/SkipNoticeComponent"; interface ContentContainer { (): { - vote: (type: any, UUID: any, category?: string, skipNotice?: SkipNoticeComponent) => void, + vote: (type: number, UUID: string, category?: string, skipNotice?: SkipNoticeComponent) => void, dontShowNoticeAgain: () => void, unskipSponsorTime: (segment: SponsorTime) => void, sponsorTimes: SponsorTime[], @@ -15,9 +15,9 @@ interface ContentContainer { onMobileYouTube: boolean, sponsorSubmissionNotice: SubmissionNotice, resetSponsorSubmissionNotice: () => void, - changeStartSponsorButton: (showStartSponsor: any, uploadButtonVisible: any) => Promise, + changeStartSponsorButton: (showStartSponsor: boolean, uploadButtonVisible: boolean) => Promise, previewTime: (time: number, unpause?: boolean) => void, - videoInfo: any, + videoInfo: VideoInfo, getRealCurrentTime: () => number } } -- cgit v1.2.3 From 2afe5109127a68cb12f9716ad302e338c378a0bd Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Tue, 15 Dec 2020 20:10:19 +0100 Subject: refactor(types): add PageElements type --- src/popup.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/popup.ts b/src/popup.ts index 5fb87bcf..b5d83e6c 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -37,6 +37,8 @@ class MessageHandler { } } + + //make this a function to allow this to run on the content page async function runThePopup(messageListener?: MessageListener): Promise { const messageHandler = new MessageHandler(messageListener); @@ -45,7 +47,14 @@ async function runThePopup(messageListener?: MessageListener): Promise { await utils.wait(() => Config.config !== null); - const PageElements: any = {}; + type InputPageElements = { + whitelistToggle?: HTMLInputElement, + toggleSwitch?: HTMLInputElement, + usernameInput?: HTMLInputElement, + }; + type PageElements = { [key: string]: HTMLElement } & InputPageElements + + const PageElements: PageElements = {}; [ "sponsorblockPopup", -- cgit v1.2.3