mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 12:37:05 +03:00
refactor: remove dead code, add more types
This commit is contained in:
@@ -21,8 +21,8 @@ module.exports = {
|
|||||||
rules: {
|
rules: {
|
||||||
// TODO: Remove warn rules when not needed anymore
|
// TODO: Remove warn rules when not needed anymore
|
||||||
"@typescript-eslint/no-this-alias": "warn",
|
"@typescript-eslint/no-this-alias": "warn",
|
||||||
"no-self-assign": "warn",
|
"no-self-assign": "off",
|
||||||
"@typescript-eslint/no-empty-interface": "warn",
|
"@typescript-eslint/no-empty-interface": "off",
|
||||||
"@typescript-eslint/ban-types": "warn",
|
"@typescript-eslint/ban-types": "warn",
|
||||||
},
|
},
|
||||||
settings: {
|
settings: {
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ import * as CompileConfig from "../config.json";
|
|||||||
|
|
||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
import { Registration } from "./types";
|
import { Registration } from "./types";
|
||||||
|
|
||||||
// Make the config public for debugging purposes
|
// Make the config public for debugging purposes
|
||||||
(<any> window).SB = Config;
|
|
||||||
|
window.SB = Config;
|
||||||
|
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
const utils = new Utils({
|
const utils = new Utils({
|
||||||
@@ -70,7 +72,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//add help page on install
|
//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 let's the config sync to run fully before checking.
|
||||||
// This is required on Firefox
|
// This is required on Firefox
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
|
||||||
import Config from "../config"
|
|
||||||
import * as CompileConfig from "../../config.json";
|
import * as CompileConfig from "../../config.json";
|
||||||
import CategorySkipOptionsComponent from "./CategorySkipOptionsComponent";
|
import CategorySkipOptionsComponent from "./CategorySkipOptionsComponent";
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,6 @@ import * as React from "react";
|
|||||||
|
|
||||||
import Config from "../config"
|
import Config from "../config"
|
||||||
import { CategorySkipOption } from "../types";
|
import { CategorySkipOption } from "../types";
|
||||||
import Utils from "../utils";
|
|
||||||
|
|
||||||
const utils = new Utils();
|
|
||||||
|
|
||||||
export interface CategorySkipOptionsProps {
|
export interface CategorySkipOptionsProps {
|
||||||
category: string;
|
category: string;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export interface NoticeState {
|
|||||||
|
|
||||||
class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
|
class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
|
||||||
countdownInterval: NodeJS.Timeout;
|
countdownInterval: NodeJS.Timeout;
|
||||||
idSuffix: any;
|
idSuffix: string;
|
||||||
|
|
||||||
amountOfPreviousNotices: number;
|
amountOfPreviousNotices: number;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import * as React from "react";
|
|||||||
export interface NoticeTextSelectionProps {
|
export interface NoticeTextSelectionProps {
|
||||||
text: string,
|
text: string,
|
||||||
idSuffix: string,
|
idSuffix: string,
|
||||||
onClick?: (event: React.MouseEvent) => any
|
onClick?: (event: React.MouseEvent) => unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NoticeTextSelectionState {
|
export interface NoticeTextSelectionState {
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ import * as React from "react";
|
|||||||
import * as CompileConfig from "../../config.json";
|
import * as CompileConfig from "../../config.json";
|
||||||
import Config from "../config"
|
import Config from "../config"
|
||||||
import { ContentContainer, SponsorHideType, SponsorTime } from "../types";
|
import { ContentContainer, SponsorHideType, SponsorTime } from "../types";
|
||||||
|
|
||||||
import Utils from "../utils";
|
|
||||||
const utils = new Utils();
|
|
||||||
|
|
||||||
import NoticeComponent from "./NoticeComponent";
|
import NoticeComponent from "./NoticeComponent";
|
||||||
import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
|
import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
|
||||||
|
|
||||||
@@ -42,7 +38,7 @@ export interface SkipNoticeState {
|
|||||||
|
|
||||||
downvoting: boolean;
|
downvoting: boolean;
|
||||||
choosingCategory: 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;
|
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 self = this;
|
||||||
const maxCountdownTime = function() {
|
const maxCountdownTime = function() {
|
||||||
const sponsorTime = self.segments[index];
|
const sponsorTime = self.segments[index];
|
||||||
@@ -458,14 +454,11 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
unskipText: buttonText,
|
unskipText: buttonText,
|
||||||
|
|
||||||
unskipCallback: (index) => this.reskip(index),
|
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,
|
maxCountdownTime: maxCountdownTime,
|
||||||
|
|
||||||
countdownTime: maxCountdownTime()
|
countdownTime: maxCountdownTime()
|
||||||
}
|
} as SkipNoticeState;
|
||||||
}
|
}
|
||||||
|
|
||||||
reskip(index: number): void {
|
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({
|
this.setState({
|
||||||
messages,
|
messages,
|
||||||
messageOnClick: (event) => onClick(event)
|
messageOnClick: (event) => onClick(event)
|
||||||
@@ -521,7 +514,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addVoteButtonInfo(message): void {
|
addVoteButtonInfo(message: string): void {
|
||||||
this.setState({
|
this.setState({
|
||||||
thanksForVotingText: message
|
thanksForVotingText: message
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ interface SBConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SBObject {
|
export interface SBObject {
|
||||||
configListeners: Array<Function>;
|
configListeners: Array<Function>;
|
||||||
defaults: SBConfig;
|
defaults: SBConfig;
|
||||||
localConfig: SBConfig;
|
localConfig: SBConfig;
|
||||||
|
|||||||
19
src/globals.d.ts
vendored
Normal file
19
src/globals.d.ts
vendored
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -119,8 +119,7 @@ class Utils {
|
|||||||
const rule = {
|
const rule = {
|
||||||
id: "invidious",
|
id: "invidious",
|
||||||
conditions,
|
conditions,
|
||||||
// This API is experimental and not visible by the TypeScript compiler
|
actions: [new chrome.declarativeContent.RequestContentScript({
|
||||||
actions: [new (<any> chrome.declarativeContent).RequestContentScript({
|
|
||||||
allFrames: true,
|
allFrames: true,
|
||||||
js: self.js,
|
js: self.js,
|
||||||
css: self.css
|
css: self.css
|
||||||
|
|||||||
Reference in New Issue
Block a user