diff options
author | Ajay Ramachandran <[email protected]> | 2020-12-17 13:20:48 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-17 13:20:48 -0500 |
commit | c30038fd26e86b9e6253e4bbacbd51385ebf7fc4 (patch) | |
tree | e0eac3a4ce18b0def48a2bd7c55fc80b668df040 | |
parent | 1b4bee1b90c71fc4a393bb375e363430f4c9ac02 (diff) | |
parent | 2afe5109127a68cb12f9716ad302e338c378a0bd (diff) | |
download | SponsorBlock-c30038fd26e86b9e6253e4bbacbd51385ebf7fc4.tar.gz SponsorBlock-c30038fd26e86b9e6253e4bbacbd51385ebf7fc4.zip |
Merge pull request #578 from FoseFx/fosefx-eslint-fix
Fix eslint warnings
-rw-r--r-- | .eslintrc.js | 4 | ||||
-rw-r--r-- | src/background.ts | 6 | ||||
-rw-r--r-- | src/components/CategoryChooserComponent.tsx | 1 | ||||
-rw-r--r-- | src/components/CategorySkipOptionsComponent.tsx | 3 | ||||
-rw-r--r-- | src/components/NoticeComponent.tsx | 2 | ||||
-rw-r--r-- | src/components/NoticeTextSectionComponent.tsx | 2 | ||||
-rw-r--r-- | src/components/SkipNoticeComponent.tsx | 19 | ||||
-rw-r--r-- | src/config.ts | 27 | ||||
-rw-r--r-- | src/content.ts | 24 | ||||
-rw-r--r-- | src/globals.d.ts | 19 | ||||
-rw-r--r-- | src/js-components/previewBar.ts | 14 | ||||
-rw-r--r-- | src/options.ts | 14 | ||||
-rw-r--r-- | src/popup.ts | 13 | ||||
-rw-r--r-- | src/types.ts | 88 | ||||
-rw-r--r-- | src/utils.ts | 3 |
15 files changed, 165 insertions, 74 deletions
diff --git a/.eslintrc.js b/.eslintrc.js index ad68956e..3ea331c5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -21,8 +21,8 @@ module.exports = { rules: { // TODO: Remove warn rules when not needed anymore "@typescript-eslint/no-this-alias": "warn", - "no-self-assign": "warn", - "@typescript-eslint/no-empty-interface": "warn", + "no-self-assign": "off", + "@typescript-eslint/no-empty-interface": "off", "@typescript-eslint/ban-types": "warn", }, settings: { diff --git a/src/background.ts b/src/background.ts index 71ce4e09..e9643667 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 -(<any> 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<NoticeProps, NoticeState> { 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<SkipNoticeProps, SkipNoticeSta }); } - getUnskippedModeInfo(index: number, buttonText: string) { + getUnskippedModeInfo(index: number, buttonText: string): SkipNoticeState { const self = this; const maxCountdownTime = function() { const sponsorTime = self.segments[index]; @@ -458,14 +454,11 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta return { unskipText: buttonText, - unskipCallback: (index) => 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<SkipNoticeProps, SkipNoticeSta } } - setNoticeInfoMessageWithOnClick(onClick: (event: React.MouseEvent) => 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<SkipNoticeProps, SkipNoticeSta }); } - addVoteButtonInfo(message): void { + addVoteButtonInfo(message: string): void { this.setState({ thanksForVotingText: message }); diff --git a/src/config.ts b/src/config.ts index e622ef05..2a40dbf6 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(); @@ -58,8 +58,8 @@ interface SBConfig { } } -interface SBObject { - configListeners: Array<Function>; +export interface SBObject { + configListeners: Array<(changes: StorageChangesObject) => unknown>; defaults: SBConfig; localConfig: SBConfig; config: SBConfig; @@ -275,8 +275,8 @@ function decodeStoredItem<T>(id: string, data: T): T | SBMap<string, SponsorTime return data; } -function configProxy(): any { - chrome.storage.onChanged.addListener((changes, namespace) => { +function configProxy(): SBConfig { + chrome.storage.onChanged.addListener((changes: {[key: string]: chrome.storage.StorageChange}) => { for (const key in changes) { Config.localConfig[key] = decodeStoredItem(key, changes[key].newValue); } @@ -286,8 +286,8 @@ function configProxy(): any { } }); - const handler: ProxyHandler<any> = { - set(obj, prop, value) { + const handler: ProxyHandler<SBConfig> = { + set<K extends keyof SBConfig>(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<K extends keyof SBConfig>(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(<string> prop); return true; @@ -311,11 +311,11 @@ function configProxy(): any { }; - return new Proxy({handler}, handler); + return new Proxy<SBConfig>({handler} as unknown as SBConfig, handler); } function fetchConfig(): Promise<void> { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { chrome.storage.sync.get(null, function(items) { Config.localConfig = <SBConfig> <unknown> items; // Data is ready resolve(); @@ -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]); diff --git a/src/content.ts b/src/content.ts index 5124030d..be96ef29 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, VideoInfo, StorageChangesObject } from "./types"; import { ContentContainer } from "./types"; import Utils from "./utils"; @@ -25,9 +25,9 @@ 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; +let channelID: string; // Skips are scheduled to ensure precision. // Skips are rescheduled every seeking event. @@ -115,7 +115,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": @@ -182,7 +182,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": @@ -368,7 +368,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 { @@ -402,7 +402,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(); @@ -753,7 +753,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) { @@ -811,7 +811,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); } @@ -1064,7 +1064,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(); }); @@ -1448,8 +1448,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); } @@ -1596,7 +1594,7 @@ function sendRequestToCustomServer(type, fullAddress, callback) { callback(xmlhttp, false); }; - xmlhttp.onerror = function(ev) { + xmlhttp.onerror = function() { callback(xmlhttp, true); }; } 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/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 979dac6b..186e442a 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 -(<any> 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); @@ -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 aba3d8c0..42859d3c 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 { @@ -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<void> { const messageHandler = new MessageHandler(messageListener); @@ -45,7 +47,14 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> { 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", diff --git a/src/types.ts b/src/types.ts index d7818e01..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<boolean>, + changeStartSponsorButton: (showStartSponsor: boolean, uploadButtonVisible: boolean) => Promise<boolean>, previewTime: (time: number, unpause?: boolean) => void, - videoInfo: any, + videoInfo: VideoInfo, getRealCurrentTime: () => number } } @@ -78,8 +78,86 @@ 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; +type StorageChangesObject = { [key: string]: chrome.storage.StorageChange }; + export { FetchResponse, VideoDurationResponse, @@ -91,5 +169,7 @@ export { SponsorHideType, PreviewBarOption, Registration, - BackgroundScriptContainer + BackgroundScriptContainer, + VideoInfo, + StorageChangesObject, }; diff --git a/src/utils.ts b/src/utils.ts index 6f30a854..c15d3ff6 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 (<any> chrome.declarativeContent).RequestContentScript({ + actions: [new chrome.declarativeContent.RequestContentScript({ allFrames: true, js: self.js, css: self.css |