mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
commit
1bab5063aa
3 changed files with 71 additions and 7 deletions
|
@ -12,6 +12,7 @@ import PreviewBar from "./js-components/previewBar";
|
|||
import SkipNotice from "./render/SkipNotice";
|
||||
import SkipNoticeComponent from "./components/SkipNoticeComponent";
|
||||
import SubmissionNotice from "./render/SubmissionNotice";
|
||||
import { Message, MessageResponse } from "./messageTypes";
|
||||
|
||||
// Hack to get the CSS loaded on permission-based sites (Invidious)
|
||||
utils.wait(() => Config.config !== null, 5000, 10).then(addCSS);
|
||||
|
@ -115,7 +116,7 @@ const skipNoticeContentContainer: ContentContainer = () => ({
|
|||
//get messages from the background script and the popup
|
||||
chrome.runtime.onMessage.addListener(messageListener);
|
||||
|
||||
function messageListener(request: any, sender: unknown, sendResponse: (response: any) => void): void {
|
||||
function messageListener(request: Message, sender: unknown, sendResponse: (response: MessageResponse) => void): void {
|
||||
//messages from popup script
|
||||
switch(request.message){
|
||||
case "update":
|
||||
|
@ -172,7 +173,6 @@ function messageListener(request: any, sender: unknown, sendResponse: (response:
|
|||
break;
|
||||
case "submitTimes":
|
||||
submitSponsorTimes();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1222,7 +1222,7 @@ function updateSponsorTimesSubmitting(getFromConfig = true) {
|
|||
}
|
||||
}
|
||||
|
||||
async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
||||
async function changeStartSponsorButton(showStartSponsor: boolean, uploadButtonVisible: boolean): Promise<boolean> {
|
||||
if(!sponsorVideoID) return false;
|
||||
|
||||
//if it isn't visible, there is no data
|
||||
|
@ -1423,7 +1423,7 @@ function dontShowNoticeAgain() {
|
|||
closeAllSkipNotices();
|
||||
}
|
||||
|
||||
function sponsorMessageStarted(callback) {
|
||||
function sponsorMessageStarted(callback: (response: MessageResponse) => void) {
|
||||
video = document.querySelector('video');
|
||||
|
||||
//send back current time
|
||||
|
|
63
src/messageTypes.ts
Normal file
63
src/messageTypes.ts
Normal file
|
@ -0,0 +1,63 @@
|
|||
//
|
||||
// Message and Response Types
|
||||
//
|
||||
|
||||
import { SponsorTime } from "./types";
|
||||
|
||||
interface BaseMessage {
|
||||
from?: string;
|
||||
}
|
||||
|
||||
interface DefaultMessage {
|
||||
message:
|
||||
"update"
|
||||
| "sponsorStart"
|
||||
| "sponsorDataChanged"
|
||||
| "isInfoFound"
|
||||
| "getVideoID"
|
||||
| "getChannelID"
|
||||
| "isChannelWhitelisted"
|
||||
| "submitTimes";
|
||||
}
|
||||
|
||||
interface BoolValueMessage {
|
||||
message: "whitelistChange";
|
||||
value: boolean;
|
||||
}
|
||||
|
||||
interface ChangeStartSponsorButtonMessage {
|
||||
message: "changeStartSponsorButton";
|
||||
showStartSponsor: boolean;
|
||||
uploadButtonVisible: boolean;
|
||||
}
|
||||
|
||||
export type Message = BaseMessage & (DefaultMessage | BoolValueMessage | ChangeStartSponsorButtonMessage);
|
||||
|
||||
interface IsInfoFoundMessageResponse {
|
||||
found: boolean;
|
||||
sponsorTimes: SponsorTime[];
|
||||
}
|
||||
|
||||
interface GetVideoIdResponse {
|
||||
videoID: string;
|
||||
}
|
||||
|
||||
interface GetChannelIDResponse {
|
||||
channelID: string;
|
||||
}
|
||||
|
||||
interface SponsorStartResponse {
|
||||
time: number;
|
||||
}
|
||||
|
||||
interface IsChannelWhitelistedResponse {
|
||||
value: boolean;
|
||||
}
|
||||
|
||||
export type MessageResponse =
|
||||
IsInfoFoundMessageResponse
|
||||
| GetVideoIdResponse
|
||||
| GetChannelIDResponse
|
||||
| SponsorStartResponse
|
||||
| IsChannelWhitelistedResponse;
|
||||
|
|
@ -2,11 +2,12 @@ import Config from "./config";
|
|||
|
||||
import Utils from "./utils";
|
||||
import { SponsorTime, SponsorHideType } from "./types";
|
||||
import { Message, MessageResponse } from "./messageTypes";
|
||||
const utils = new Utils();
|
||||
|
||||
interface MessageListener {
|
||||
(request: any, sender: unknown, callback: (response: any) => void): void;
|
||||
}
|
||||
(request: Message, sender: unknown, sendResponse: (response: MessageResponse) => void): void;
|
||||
}
|
||||
|
||||
class MessageHandler {
|
||||
messageListener: MessageListener;
|
||||
|
@ -15,7 +16,7 @@ class MessageHandler {
|
|||
this.messageListener = messageListener;
|
||||
}
|
||||
|
||||
sendMessage(id: number, request, callback?) {
|
||||
sendMessage(id: number, request: Message, callback?) {
|
||||
if (this.messageListener) {
|
||||
this.messageListener(request, null, callback);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue