mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 21:47:06 +03:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlock
This commit is contained in:
4291
package-lock.json
generated
4291
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -38,7 +38,7 @@
|
|||||||
"ts-loader": "^9.4.2",
|
"ts-loader": "^9.4.2",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "4.9",
|
"typescript": "4.9",
|
||||||
"web-ext": "^8.2.0",
|
"web-ext": "^8.9.0",
|
||||||
"webpack": "^5.94.0",
|
"webpack": "^5.94.0",
|
||||||
"webpack-cli": "^4.10.0",
|
"webpack-cli": "^4.10.0",
|
||||||
"webpack-merge": "^5.8.0"
|
"webpack-merge": "^5.8.0"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import * as CompileConfig from "../config.json";
|
|||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
import { Registration } from "./types";
|
import { Registration } from "./types";
|
||||||
import "content-scripts-register-polyfill";
|
import "content-scripts-register-polyfill";
|
||||||
import { sendRealRequestToCustomServer, setupBackgroundRequestProxy } from "../maze-utils/src/background-request-proxy";
|
import { sendRealRequestToCustomServer, serializeOrStringify, setupBackgroundRequestProxy } from "../maze-utils/src/background-request-proxy";
|
||||||
import { setupTabUpdates } from "../maze-utils/src/tab-updates";
|
import { setupTabUpdates } from "../maze-utils/src/tab-updates";
|
||||||
import { generateUserID } from "../maze-utils/src/setup";
|
import { generateUserID } from "../maze-utils/src/setup";
|
||||||
|
|
||||||
@@ -227,33 +227,16 @@ async function submitVote(type: number, UUID: string, category: string, videoID:
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&videoID=" + videoID + "&userID=" + userID + typeSection);
|
const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&videoID=" + videoID + "&userID=" + userID + typeSection);
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
return {
|
|
||||||
successType: 1,
|
|
||||||
responseText: await response.text()
|
|
||||||
};
|
|
||||||
} else if (response.status == 405) {
|
|
||||||
//duplicate vote
|
|
||||||
return {
|
|
||||||
successType: 0,
|
|
||||||
statusCode: response.status,
|
|
||||||
responseText: await response.text()
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
//error while connect
|
|
||||||
return {
|
|
||||||
successType: -1,
|
|
||||||
statusCode: response.status,
|
|
||||||
responseText: await response.text()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
return {
|
return {
|
||||||
successType: -1,
|
status: response.status,
|
||||||
statusCode: -1,
|
ok: response.ok,
|
||||||
responseText: ""
|
responseText: await response.text(),
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error while voting:", e);
|
||||||
|
return {
|
||||||
|
error: serializeOrStringify(e),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,4 +246,4 @@ async function asyncRequestToServer(type: string, address: string, data = {}) {
|
|||||||
const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress;
|
const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress;
|
||||||
|
|
||||||
return await (sendRealRequestToCustomServer(type, serverAddress + address, data));
|
return await (sendRealRequestToCustomServer(type, serverAddress + address, data));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import { downvoteButtonColor, SkipNoticeAction } from "../utils/noticeUtils";
|
|||||||
import { VoteResponse } from "../messageTypes";
|
import { VoteResponse } from "../messageTypes";
|
||||||
import { AnimationUtils } from "../../maze-utils/src/animationUtils";
|
import { AnimationUtils } from "../../maze-utils/src/animationUtils";
|
||||||
import { Tooltip } from "../render/Tooltip";
|
import { Tooltip } from "../render/Tooltip";
|
||||||
import { getErrorMessage } from "../../maze-utils/src/formating";
|
import { formatJSErrorMessage, getLongErrorMessage } from "../../maze-utils/src/formating";
|
||||||
|
import { logRequest } from "../../maze-utils/src/background-request-proxy";
|
||||||
|
|
||||||
export interface CategoryPillProps {
|
export interface CategoryPillProps {
|
||||||
vote: (type: number, UUID: SegmentUUID, category?: Category) => Promise<VoteResponse>;
|
vote: (type: number, UUID: SegmentUUID, category?: Category) => Promise<VoteResponse>;
|
||||||
@@ -127,15 +128,19 @@ class CategoryPillComponent extends React.Component<CategoryPillProps, CategoryP
|
|||||||
const response = await this.props.vote(type, this.state.segment.UUID);
|
const response = await this.props.vote(type, this.state.segment.UUID);
|
||||||
await stopAnimation();
|
await stopAnimation();
|
||||||
|
|
||||||
if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) {
|
if ("error" in response) {
|
||||||
|
console.error("[SB] Caught error while attempting to vote on a FV label", response.error);
|
||||||
|
alert(formatJSErrorMessage(response.error));
|
||||||
|
} else if (response.ok || response.status === 429) {
|
||||||
this.setState({
|
this.setState({
|
||||||
open: false,
|
open: false,
|
||||||
show: type === 1
|
show: type === 1
|
||||||
});
|
});
|
||||||
|
|
||||||
this.closeTooltip();
|
this.closeTooltip();
|
||||||
} else if (response.statusCode !== 403) {
|
} else if (response.status !== 403) {
|
||||||
alert(getErrorMessage(response.statusCode, response.responseText));
|
logRequest({headers: null, ...response}, "SB", "vote on FV label");
|
||||||
|
alert(getLongErrorMessage(response.status, response.responseText));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import { downvoteButtonColor, SkipNoticeAction } from "../utils/noticeUtils";
|
|||||||
import { VoteResponse } from "../messageTypes";
|
import { VoteResponse } from "../messageTypes";
|
||||||
import { AnimationUtils } from "../../maze-utils/src/animationUtils";
|
import { AnimationUtils } from "../../maze-utils/src/animationUtils";
|
||||||
import { Tooltip } from "../render/Tooltip";
|
import { Tooltip } from "../render/Tooltip";
|
||||||
import { getErrorMessage } from "../../maze-utils/src/formating";
|
import { formatJSErrorMessage, getLongErrorMessage } from "../../maze-utils/src/formating";
|
||||||
|
import { logRequest } from "../../maze-utils/src/background-request-proxy";
|
||||||
|
|
||||||
export interface ChapterVoteProps {
|
export interface ChapterVoteProps {
|
||||||
vote: (type: number, UUID: SegmentUUID, category?: Category) => Promise<VoteResponse>;
|
vote: (type: number, UUID: SegmentUUID, category?: Category) => Promise<VoteResponse>;
|
||||||
@@ -119,12 +120,16 @@ class ChapterVoteComponent extends React.Component<ChapterVoteProps, ChapterVote
|
|||||||
const response = await this.props.vote(type, this.state.segment.UUID);
|
const response = await this.props.vote(type, this.state.segment.UUID);
|
||||||
await stopAnimation();
|
await stopAnimation();
|
||||||
|
|
||||||
if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) {
|
if ("error" in response){
|
||||||
|
console.error("[SB] Caught error while attempting to vote on a chapter", response.error);
|
||||||
|
alert(formatJSErrorMessage(response.error));
|
||||||
|
} else if (response.ok || response.status == 429) {
|
||||||
this.setState({
|
this.setState({
|
||||||
show: type === 1
|
show: type === 1
|
||||||
});
|
});
|
||||||
} else if (response.statusCode !== 403) {
|
} else if (response.status !== 403) {
|
||||||
alert(getErrorMessage(response.statusCode, response.responseText));
|
logRequest({headers: null, ...response}, "SB", "vote on chapter");
|
||||||
|
alert(getLongErrorMessage(response.status, response.responseText));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { defaultPreviewTime } from "../utils/constants";
|
|||||||
import { getVideo, getVideoDuration } from "../../maze-utils/src/video";
|
import { getVideo, getVideoDuration } from "../../maze-utils/src/video";
|
||||||
import { AnimationUtils } from "../../maze-utils/src/animationUtils";
|
import { AnimationUtils } from "../../maze-utils/src/animationUtils";
|
||||||
import { Tooltip } from "../render/Tooltip";
|
import { Tooltip } from "../render/Tooltip";
|
||||||
|
import { logRequest } from "../../maze-utils/src/background-request-proxy";
|
||||||
|
|
||||||
export interface SponsorTimeEditProps {
|
export interface SponsorTimeEditProps {
|
||||||
index: number;
|
index: number;
|
||||||
@@ -781,23 +782,26 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
if (this.props.contentContainer().channelIDInfo.status !== ChannelIDStatus.Found) return;
|
if (this.props.contentContainer().channelIDInfo.status !== ChannelIDStatus.Found) return;
|
||||||
|
|
||||||
this.fetchingSuggestions = true;
|
this.fetchingSuggestions = true;
|
||||||
const result = await asyncRequestToServer("GET", "/api/chapterNames", {
|
try {
|
||||||
description,
|
const result = await asyncRequestToServer("GET", "/api/chapterNames", {
|
||||||
channelID: this.props.contentContainer().channelIDInfo.id
|
description,
|
||||||
});
|
channelID: this.props.contentContainer().channelIDInfo.id
|
||||||
|
});
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
try {
|
|
||||||
const names = JSON.parse(result.responseText) as {description: string}[];
|
const names = JSON.parse(result.responseText) as {description: string}[];
|
||||||
this.setState({
|
this.setState({
|
||||||
suggestedNames: names.map(n => ({
|
suggestedNames: names.map(n => ({
|
||||||
label: n.description
|
label: n.description
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
} catch (e) {} //eslint-disable-line no-empty
|
} else if (result.status !== 404) {
|
||||||
|
logRequest(result, "SB", "chapter suggestion")
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("[SB] Caught error while fetching chapter suggestions", e);
|
||||||
|
} finally {
|
||||||
|
this.fetchingSuggestions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fetchingSuggestions = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
configUpdate(): void {
|
configUpdate(): void {
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ const syncDefaults = {
|
|||||||
hideSkipButtonPlayerControls: false,
|
hideSkipButtonPlayerControls: false,
|
||||||
hideDiscordLaunches: 0,
|
hideDiscordLaunches: 0,
|
||||||
hideDiscordLink: false,
|
hideDiscordLink: false,
|
||||||
invidiousInstances: ["invidious.snopyta.org"], // leave as default
|
invidiousInstances: [],
|
||||||
supportInvidious: false,
|
supportInvidious: false,
|
||||||
serverAddress: CompileConfig.serverAddress,
|
serverAddress: CompileConfig.serverAddress,
|
||||||
minDuration: 0,
|
minDuration: 0,
|
||||||
@@ -583,4 +583,4 @@ export function generateDebugDetails(): string {
|
|||||||
output.config.skipRules = output.config.skipRules.length;
|
output.config.skipRules = output.config.skipRules.length;
|
||||||
|
|
||||||
return JSON.stringify(output, null, 4);
|
return JSON.stringify(output, null, 4);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import { importTimes } from "./utils/exporter";
|
|||||||
import { ChapterVote } from "./render/ChapterVote";
|
import { ChapterVote } from "./render/ChapterVote";
|
||||||
import { openWarningDialog } from "./utils/warnings";
|
import { openWarningDialog } from "./utils/warnings";
|
||||||
import { extensionUserAgent, isFirefoxOrSafari, waitFor } from "../maze-utils/src";
|
import { extensionUserAgent, isFirefoxOrSafari, waitFor } from "../maze-utils/src";
|
||||||
import { getErrorMessage, getFormattedTime } from "../maze-utils/src/formating";
|
import { formatJSErrorMessage, getFormattedTime, getLongErrorMessage } from "../maze-utils/src/formating";
|
||||||
import { getChannelIDInfo, getVideo, getIsAdPlaying, getIsLivePremiere, setIsAdPlaying, checkVideoIDChange, getVideoID, getYouTubeVideoID, setupVideoModule, checkIfNewVideoID, isOnInvidious, isOnMobileYouTube, isOnYouTubeMusic, isOnYTTV, getLastNonInlineVideoID, triggerVideoIDChange, triggerVideoElementChange, getIsInline, getCurrentTime, setCurrentTime, getVideoDuration, verifyCurrentTime, waitForVideo } from "../maze-utils/src/video";
|
import { getChannelIDInfo, getVideo, getIsAdPlaying, getIsLivePremiere, setIsAdPlaying, checkVideoIDChange, getVideoID, getYouTubeVideoID, setupVideoModule, checkIfNewVideoID, isOnInvidious, isOnMobileYouTube, isOnYouTubeMusic, isOnYTTV, getLastNonInlineVideoID, triggerVideoIDChange, triggerVideoElementChange, getIsInline, getCurrentTime, setCurrentTime, getVideoDuration, verifyCurrentTime, waitForVideo } from "../maze-utils/src/video";
|
||||||
import { Keybind, StorageChangesObject, isSafari, keybindEquals, keybindToString } from "../maze-utils/src/config";
|
import { Keybind, StorageChangesObject, isSafari, keybindEquals, keybindToString } from "../maze-utils/src/config";
|
||||||
import { findValidElement } from "../maze-utils/src/dom"
|
import { findValidElement } from "../maze-utils/src/dom"
|
||||||
@@ -53,6 +53,7 @@ import { onVideoPage } from "../maze-utils/src/pageInfo";
|
|||||||
import { getSegmentsForVideo } from "./utils/segmentData";
|
import { getSegmentsForVideo } from "./utils/segmentData";
|
||||||
import { getCategoryDefaultSelection, getCategorySelection } from "./utils/skipRule";
|
import { getCategoryDefaultSelection, getCategorySelection } from "./utils/skipRule";
|
||||||
import { getSkipProfileBool, getSkipProfileIDForTab, hideTooShortSegments, setCurrentTabSkipProfile } from "./utils/skipProfiles";
|
import { getSkipProfileBool, getSkipProfileIDForTab, hideTooShortSegments, setCurrentTabSkipProfile } from "./utils/skipProfiles";
|
||||||
|
import { FetchResponse, logRequest } from "../maze-utils/src/background-request-proxy";
|
||||||
|
|
||||||
cleanPage();
|
cleanPage();
|
||||||
|
|
||||||
@@ -172,7 +173,7 @@ let popupInitialised = false;
|
|||||||
|
|
||||||
let submissionNotice: SubmissionNotice = null;
|
let submissionNotice: SubmissionNotice = null;
|
||||||
|
|
||||||
let lastResponseStatus: number;
|
let lastResponseStatus: number | Error | string;
|
||||||
|
|
||||||
// Contains all of the functions and variables needed by the skip notice
|
// Contains all of the functions and variables needed by the skip notice
|
||||||
const skipNoticeContentContainer: ContentContainer = () => ({
|
const skipNoticeContentContainer: ContentContainer = () => ({
|
||||||
@@ -1335,15 +1336,19 @@ function handleExistingChaptersChannelChange() {
|
|||||||
|
|
||||||
async function lockedCategoriesLookup(): Promise<void> {
|
async function lockedCategoriesLookup(): Promise<void> {
|
||||||
const hashPrefix = (await getHash(getVideoID(), 1)).slice(0, 4);
|
const hashPrefix = (await getHash(getVideoID(), 1)).slice(0, 4);
|
||||||
const response = await asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix);
|
try {
|
||||||
|
const response = await asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
try {
|
|
||||||
const categoriesResponse = JSON.parse(response.responseText).filter((lockInfo) => lockInfo.videoID === getVideoID())[0]?.categories;
|
const categoriesResponse = JSON.parse(response.responseText).filter((lockInfo) => lockInfo.videoID === getVideoID())[0]?.categories;
|
||||||
if (Array.isArray(categoriesResponse)) {
|
if (Array.isArray(categoriesResponse)) {
|
||||||
lockedCategories = categoriesResponse;
|
lockedCategories = categoriesResponse;
|
||||||
}
|
}
|
||||||
} catch (e) { } //eslint-disable-line no-empty
|
} else if (response.status !== 404) {
|
||||||
|
logRequest(response, "SB", "locked categories")
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`[SB] Caught error while looking up category locks for hashprefix ${hashPrefix}`, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1742,7 +1747,11 @@ function sendTelemetryAndCount(skippingSegments: SponsorTime[], secondsSkipped:
|
|||||||
counted = true;
|
counted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fullSkip) asyncRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + segment.UUID + "&videoID=" + getVideoID());
|
if (fullSkip) asyncRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + segment.UUID + "&videoID=" + getVideoID())
|
||||||
|
.then(r => {
|
||||||
|
if (!r.ok) logRequest(r, "SB", "segment skip log");
|
||||||
|
})
|
||||||
|
.catch(e => console.warn("[SB] Caught error while attempting to log segment skip", e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2302,25 +2311,29 @@ function clearSponsorTimes() {
|
|||||||
async function vote(type: number, UUID: SegmentUUID, category?: Category, skipNotice?: SkipNoticeComponent): Promise<VoteResponse> {
|
async function vote(type: number, UUID: SegmentUUID, category?: Category, skipNotice?: SkipNoticeComponent): Promise<VoteResponse> {
|
||||||
if (skipNotice !== null && skipNotice !== undefined) {
|
if (skipNotice !== null && skipNotice !== undefined) {
|
||||||
//add loading info
|
//add loading info
|
||||||
skipNotice.addVoteButtonInfo.bind(skipNotice)(chrome.i18n.getMessage("Loading"))
|
skipNotice.addVoteButtonInfo(chrome.i18n.getMessage("Loading"))
|
||||||
skipNotice.setNoticeInfoMessage.bind(skipNotice)();
|
skipNotice.setNoticeInfoMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await voteAsync(type, UUID, category);
|
const response = await voteAsync(type, UUID, category);
|
||||||
if (response != undefined) {
|
if (response != undefined) {
|
||||||
//see if it was a success or failure
|
//see if it was a success or failure
|
||||||
if (skipNotice != null) {
|
if (skipNotice != null) {
|
||||||
if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) {
|
if ("error" in response) {
|
||||||
|
skipNotice.setNoticeInfoMessage(formatJSErrorMessage(response.error))
|
||||||
|
skipNotice.resetVoteButtonInfo();
|
||||||
|
} else if (response.ok || response.status === 429) {
|
||||||
//success (treat rate limits as a success)
|
//success (treat rate limits as a success)
|
||||||
skipNotice.afterVote.bind(skipNotice)(utils.getSponsorTimeFromUUID(sponsorTimes, UUID), type, category);
|
skipNotice.afterVote(utils.getSponsorTimeFromUUID(sponsorTimes, UUID), type, category);
|
||||||
} else if (response.successType == -1) {
|
} else {
|
||||||
if (response.statusCode === 403 && response.responseText.startsWith("Vote rejected due to a tip from a moderator.")) {
|
logRequest({headers: null, ...response}, "SB", "vote on segment");
|
||||||
|
if (response.status === 403 && response.responseText.startsWith("Vote rejected due to a tip from a moderator.")) {
|
||||||
openWarningDialog(skipNoticeContentContainer);
|
openWarningDialog(skipNoticeContentContainer);
|
||||||
} else {
|
} else {
|
||||||
skipNotice.setNoticeInfoMessage.bind(skipNotice)(getErrorMessage(response.statusCode, response.responseText))
|
skipNotice.setNoticeInfoMessage(getLongErrorMessage(response.status, response.responseText))
|
||||||
}
|
}
|
||||||
|
|
||||||
skipNotice.resetVoteButtonInfo.bind(skipNotice)();
|
skipNotice.resetVoteButtonInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2357,7 +2370,7 @@ async function voteAsync(type: number, UUID: SegmentUUID, category?: Category):
|
|||||||
category: category,
|
category: category,
|
||||||
videoID: getVideoID()
|
videoID: getVideoID()
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
if (response.successType === 1) {
|
if (response.ok === true) {
|
||||||
// Change the sponsor locally
|
// Change the sponsor locally
|
||||||
const segment = utils.getSponsorTimeFromUUID(sponsorTimes, UUID);
|
const segment = utils.getSponsorTimeFromUUID(sponsorTimes, UUID);
|
||||||
if (segment) {
|
if (segment) {
|
||||||
@@ -2486,13 +2499,23 @@ async function sendSubmitMessage(): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await asyncRequestToServer("POST", "/api/skipSegments", {
|
let response: FetchResponse;
|
||||||
videoID: getVideoID(),
|
try {
|
||||||
userID: Config.config.userID,
|
response = await asyncRequestToServer("POST", "/api/skipSegments", {
|
||||||
segments: sponsorTimesSubmitting,
|
videoID: getVideoID(),
|
||||||
videoDuration: getVideoDuration(),
|
userID: Config.config.userID,
|
||||||
userAgent: extensionUserAgent(),
|
segments: sponsorTimesSubmitting,
|
||||||
});
|
videoDuration: getVideoDuration(),
|
||||||
|
userAgent: extensionUserAgent(),
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[SB] Caught error while attempting to submit segments", e);
|
||||||
|
// Show that the upload failed
|
||||||
|
playerButtons.submit.button.style.animation = "unset";
|
||||||
|
playerButtons.submit.image.src = chrome.runtime.getURL("icons/PlayerUploadFailedIconSponsorBlocker.svg");
|
||||||
|
alert(formatJSErrorMessage(e));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
stopAnimation();
|
stopAnimation();
|
||||||
@@ -2537,7 +2560,8 @@ async function sendSubmitMessage(): Promise<boolean> {
|
|||||||
if (response.status === 403 && response.responseText.startsWith("Submission rejected due to a tip from a moderator.")) {
|
if (response.status === 403 && response.responseText.startsWith("Submission rejected due to a tip from a moderator.")) {
|
||||||
openWarningDialog(skipNoticeContentContainer);
|
openWarningDialog(skipNoticeContentContainer);
|
||||||
} else {
|
} else {
|
||||||
alert(getErrorMessage(response.status, response.responseText));
|
logRequest(response, "SB", "segment submission");
|
||||||
|
alert(getLongErrorMessage(response.status, response.responseText));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export async function tryShowingDeArrowPromotion() {
|
|||||||
const title = deArrowDataJson?.[getVideoID()]?.titles?.[0];
|
const title = deArrowDataJson?.[getVideoID()]?.titles?.[0];
|
||||||
if (title && title.title && (title.locked || title.votes > 0)) {
|
if (title && title.title && (title.locked || title.votes > 0)) {
|
||||||
Config.config.showDeArrowPromotion = false;
|
Config.config.showDeArrowPromotion = false;
|
||||||
|
|
||||||
tooltip = new Tooltip({
|
tooltip = new Tooltip({
|
||||||
text: chrome.i18n.getMessage("DeArrowTitleReplacementSuggestion") + "\n\n" + title.title,
|
text: chrome.i18n.getMessage("DeArrowTitleReplacementSuggestion") + "\n\n" + title.title,
|
||||||
linkOnClick: () => {
|
linkOnClick: () => {
|
||||||
@@ -71,4 +71,4 @@ function badTitle(title: string): boolean {
|
|||||||
|
|
||||||
export function hideDeArrowPromotion(): void {
|
export function hideDeArrowPromotion(): void {
|
||||||
if (tooltip) tooltip.close();
|
if (tooltip) tooltip.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ export type Message = BaseMessage & (DefaultMessage | BoolValueMessage | IsInfoF
|
|||||||
|
|
||||||
export interface IsInfoFoundMessageResponse {
|
export interface IsInfoFoundMessageResponse {
|
||||||
found: boolean;
|
found: boolean;
|
||||||
status: number;
|
status: number | string | Error;
|
||||||
sponsorTimes: SponsorTime[];
|
sponsorTimes: SponsorTime[];
|
||||||
time: number;
|
time: number;
|
||||||
onMobileYouTube: boolean;
|
onMobileYouTube: boolean;
|
||||||
@@ -128,11 +128,13 @@ export type MessageResponse =
|
|||||||
| LogResponse
|
| LogResponse
|
||||||
| LoopedChapterResponse;
|
| LoopedChapterResponse;
|
||||||
|
|
||||||
export interface VoteResponse {
|
export type VoteResponse = {
|
||||||
successType: number;
|
status: number;
|
||||||
statusCode: number;
|
ok: boolean;
|
||||||
responseText: string;
|
responseText: string;
|
||||||
}
|
} | {
|
||||||
|
error: Error | string;
|
||||||
|
};
|
||||||
|
|
||||||
interface ImportSegmentsResponse {
|
interface ImportSegmentsResponse {
|
||||||
importedSegments: SponsorTime[];
|
importedSegments: SponsorTime[];
|
||||||
|
|||||||
@@ -603,6 +603,8 @@ function activatePrivateTextChange(element: HTMLElement) {
|
|||||||
if (userInfo.warnings > 0 || userInfo.banned) {
|
if (userInfo.warnings > 0 || userInfo.banned) {
|
||||||
setButton.classList.add("hidden");
|
setButton.classList.add("hidden");
|
||||||
}
|
}
|
||||||
|
}).catch(e => {
|
||||||
|
console.error("[SB] Caught error while fetching user info for the new user ID", e)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export enum LoadingStatus {
|
|||||||
SegmentsFound,
|
SegmentsFound,
|
||||||
NoSegmentsFound,
|
NoSegmentsFound,
|
||||||
ConnectionError,
|
ConnectionError,
|
||||||
|
JSError,
|
||||||
StillLoading,
|
StillLoading,
|
||||||
NoVideo
|
NoVideo
|
||||||
}
|
}
|
||||||
@@ -25,6 +26,7 @@ export enum LoadingStatus {
|
|||||||
export interface LoadingData {
|
export interface LoadingData {
|
||||||
status: LoadingStatus;
|
status: LoadingStatus;
|
||||||
code?: number;
|
code?: number;
|
||||||
|
error?: Error | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type SkipProfileAction = "forJustThisVideo" | "forThisChannel" | "forThisTab" | "forAnHour" | null;
|
type SkipProfileAction = "forJustThisVideo" | "forThisChannel" | "forThisTab" | "forAnHour" | null;
|
||||||
@@ -289,7 +291,9 @@ function getVideoStatusText(status: LoadingData): string {
|
|||||||
case LoadingStatus.NoSegmentsFound:
|
case LoadingStatus.NoSegmentsFound:
|
||||||
return chrome.i18n.getMessage("sponsor404");
|
return chrome.i18n.getMessage("sponsor404");
|
||||||
case LoadingStatus.ConnectionError:
|
case LoadingStatus.ConnectionError:
|
||||||
return chrome.i18n.getMessage("connectionError") + status.code;
|
return `${chrome.i18n.getMessage("connectionError")} ${chrome.i18n.getMessage("errorCode").replace("{code}", `${status.code}`)}`;
|
||||||
|
case LoadingStatus.JSError:
|
||||||
|
return `${chrome.i18n.getMessage("connectionError")} ${status.error}`;
|
||||||
case LoadingStatus.StillLoading:
|
case LoadingStatus.StillLoading:
|
||||||
return chrome.i18n.getMessage("segmentsStillLoading");
|
return chrome.i18n.getMessage("segmentsStillLoading");
|
||||||
case LoadingStatus.NoVideo:
|
case LoadingStatus.NoVideo:
|
||||||
@@ -324,6 +328,11 @@ function segmentsLoaded(response: IsInfoFoundMessageResponse, props: SegmentsLoa
|
|||||||
props.setStatus({
|
props.setStatus({
|
||||||
status: LoadingStatus.SegmentsFound
|
status: LoadingStatus.SegmentsFound
|
||||||
});
|
});
|
||||||
|
} else if (typeof response.status !== "number") {
|
||||||
|
props.setStatus({
|
||||||
|
status: LoadingStatus.JSError,
|
||||||
|
error: response.status,
|
||||||
|
})
|
||||||
} else if (response.status === 404 || response.status === 200) {
|
} else if (response.status === 404 || response.status === 200) {
|
||||||
props.setStatus({
|
props.setStatus({
|
||||||
status: LoadingStatus.NoSegmentsFound
|
status: LoadingStatus.NoSegmentsFound
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ActionType, SegmentUUID, SponsorHideType, SponsorTime, VideoID } from "
|
|||||||
import Config from "../config";
|
import Config from "../config";
|
||||||
import { waitFor } from "../../maze-utils/src";
|
import { waitFor } from "../../maze-utils/src";
|
||||||
import { shortCategoryName } from "../utils/categoryUtils";
|
import { shortCategoryName } from "../utils/categoryUtils";
|
||||||
import { getErrorMessage, getFormattedTime } from "../../maze-utils/src/formating";
|
import { formatJSErrorMessage, getFormattedTime, getShortErrorMessage } from "../../maze-utils/src/formating";
|
||||||
import { AnimationUtils } from "../../maze-utils/src/animationUtils";
|
import { AnimationUtils } from "../../maze-utils/src/animationUtils";
|
||||||
import { asyncRequestToServer } from "../utils/requests";
|
import { asyncRequestToServer } from "../utils/requests";
|
||||||
import { Message, MessageResponse, VoteResponse } from "../messageTypes";
|
import { Message, MessageResponse, VoteResponse } from "../messageTypes";
|
||||||
@@ -11,6 +11,7 @@ import { LoadingStatus } from "./PopupComponent";
|
|||||||
import GenericNotice from "../render/GenericNotice";
|
import GenericNotice from "../render/GenericNotice";
|
||||||
import { exportTimes } from "../utils/exporter";
|
import { exportTimes } from "../utils/exporter";
|
||||||
import { copyToClipboardPopup } from "./popupUtils";
|
import { copyToClipboardPopup } from "./popupUtils";
|
||||||
|
import { logRequest } from "../../maze-utils/src/background-request-proxy";
|
||||||
|
|
||||||
interface SegmentListComponentProps {
|
interface SegmentListComponentProps {
|
||||||
videoID: VideoID;
|
videoID: VideoID;
|
||||||
@@ -192,20 +193,26 @@ function SegmentListItem({ segment, videoID, currentTime, isVip, startingLooped,
|
|||||||
onClick={async (e) => {
|
onClick={async (e) => {
|
||||||
const stopAnimation = AnimationUtils.applyLoadingAnimation(e.currentTarget, 0.3);
|
const stopAnimation = AnimationUtils.applyLoadingAnimation(e.currentTarget, 0.3);
|
||||||
|
|
||||||
if (segment.UUID.length > 60) {
|
try {
|
||||||
copyToClipboardPopup(segment.UUID, sendMessage);
|
if (segment.UUID.length > 60) {
|
||||||
} else {
|
copyToClipboardPopup(segment.UUID, sendMessage);
|
||||||
const segmentIDData = await asyncRequestToServer("GET", "/api/segmentID", {
|
} else {
|
||||||
UUID: segment.UUID,
|
const segmentIDData = await asyncRequestToServer("GET", "/api/segmentID", {
|
||||||
videoID: videoID
|
UUID: segment.UUID,
|
||||||
});
|
videoID: videoID
|
||||||
|
});
|
||||||
if (segmentIDData.ok && segmentIDData.responseText) {
|
if (segmentIDData.ok && segmentIDData.responseText) {
|
||||||
copyToClipboardPopup(segmentIDData.responseText, sendMessage);
|
copyToClipboardPopup(segmentIDData.responseText, sendMessage);
|
||||||
|
} else {
|
||||||
|
logRequest(segmentIDData, "SB", "segment UUID resolution");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[SB] Caught error while attempting to resolve and copy segment UUID", e);
|
||||||
|
} finally {
|
||||||
|
stopAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
stopAnimation();
|
|
||||||
}}/>
|
}}/>
|
||||||
{
|
{
|
||||||
segment.actionType === ActionType.Chapter &&
|
segment.actionType === ActionType.Chapter &&
|
||||||
@@ -298,14 +305,24 @@ async function vote(props: {
|
|||||||
}) as VoteResponse;
|
}) as VoteResponse;
|
||||||
|
|
||||||
if (response != undefined) {
|
if (response != undefined) {
|
||||||
|
let messageDuration = 1_500;
|
||||||
// See if it was a success or failure
|
// See if it was a success or failure
|
||||||
if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) {
|
if ("error" in response) {
|
||||||
|
// JS error
|
||||||
|
console.error("[SB] Caught error while attempting to submit a vote", response.error);
|
||||||
|
props.setVoteMessage(formatJSErrorMessage(response.error));
|
||||||
|
messageDuration = 10_000;
|
||||||
|
}
|
||||||
|
else if (response.ok || response.status === 429) {
|
||||||
// Success (treat rate limits as a success)
|
// Success (treat rate limits as a success)
|
||||||
props.setVoteMessage(chrome.i18n.getMessage("voted"));
|
props.setVoteMessage(chrome.i18n.getMessage("voted"));
|
||||||
} else if (response.successType == -1) {
|
} else {
|
||||||
props.setVoteMessage(getErrorMessage(response.statusCode, response.responseText));
|
// Error
|
||||||
|
logRequest({headers: null, ...response}, "SB", "vote on segment");
|
||||||
|
props.setVoteMessage(getShortErrorMessage(response.status, response.responseText));
|
||||||
|
messageDuration = 10_000;
|
||||||
}
|
}
|
||||||
setTimeout(() => props.setVoteMessage(null), 1500);
|
setTimeout(() => props.setVoteMessage(null), messageDuration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,4 +450,4 @@ function ImportSegments(props: ImportSegmentsProps) {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { getHash } from "../../maze-utils/src/hash";
|
import { getHash } from "../../maze-utils/src/hash";
|
||||||
import { getErrorMessage } from "../../maze-utils/src/formating";
|
import { formatJSErrorMessage, getShortErrorMessage } from "../../maze-utils/src/formating";
|
||||||
import Config from "../config";
|
import Config from "../config";
|
||||||
import { asyncRequestToServer } from "../utils/requests";
|
import { asyncRequestToServer } from "../utils/requests";
|
||||||
import PencilIcon from "../svg-icons/pencilIcon";
|
import PencilIcon from "../svg-icons/pencilIcon";
|
||||||
import ClipboardIcon from "../svg-icons/clipboardIcon";
|
import ClipboardIcon from "../svg-icons/clipboardIcon";
|
||||||
import CheckIcon from "../svg-icons/checkIcon";
|
import CheckIcon from "../svg-icons/checkIcon";
|
||||||
import { showDonationLink } from "../utils/configUtils";
|
import { showDonationLink } from "../utils/configUtils";
|
||||||
|
import { FetchResponse, logRequest } from "../../maze-utils/src/background-request-proxy";
|
||||||
|
|
||||||
export const YourWorkComponent = () => {
|
export const YourWorkComponent = () => {
|
||||||
const [isSettingUsername, setIsSettingUsername] = React.useState(false);
|
const [isSettingUsername, setIsSettingUsername] = React.useState(false);
|
||||||
@@ -21,10 +22,16 @@ export const YourWorkComponent = () => {
|
|||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const values = ["userName", "viewCount", "minutesSaved", "vip", "permissions", "segmentCount"];
|
const values = ["userName", "viewCount", "minutesSaved", "vip", "permissions", "segmentCount"];
|
||||||
const result = await asyncRequestToServer("GET", "/api/userInfo", {
|
let result: FetchResponse;
|
||||||
publicUserID: await getHash(Config.config!.userID!),
|
try {
|
||||||
values
|
result = await asyncRequestToServer("GET", "/api/userInfo", {
|
||||||
});
|
publicUserID: await getHash(Config.config!.userID!),
|
||||||
|
values
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[SB] Caught error while fetching user info", e);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
const userInfo = JSON.parse(result.responseText);
|
const userInfo = JSON.parse(result.responseText);
|
||||||
@@ -38,6 +45,8 @@ export const YourWorkComponent = () => {
|
|||||||
|
|
||||||
setShowDonateMessage(Config.config.showDonationLink && Config.config.donateClicked <= 0 && Config.config.showPopupDonationCount < 5
|
setShowDonateMessage(Config.config.showDonationLink && Config.config.donateClicked <= 0 && Config.config.showPopupDonationCount < 5
|
||||||
&& viewCount < 50000 && !Config.config.isVip && Config.config.skipCount > 10 && showDonationLink());
|
&& viewCount < 50000 && !Config.config.isVip && Config.config.skipCount > 10 && showDonationLink());
|
||||||
|
} else {
|
||||||
|
logRequest(result, "SB", "user info");
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
@@ -94,10 +103,12 @@ export const YourWorkComponent = () => {
|
|||||||
setUsername(newUsername);
|
setUsername(newUsername);
|
||||||
setIsSettingUsername(!isSettingUsername);
|
setIsSettingUsername(!isSettingUsername);
|
||||||
} else {
|
} else {
|
||||||
setUsernameSubmissionStatus(getErrorMessage(result.status, result.responseText));
|
logRequest(result, "SB", "username change");
|
||||||
|
setUsernameSubmissionStatus(getShortErrorMessage(result.status, result.responseText));
|
||||||
}
|
}
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
setUsernameSubmissionStatus(`${chrome.i18n.getMessage("Error")}: ${e}`);
|
console.error("[SB] Caught error while requesting a username change", e)
|
||||||
|
setUsernameSubmissionStatus(formatJSErrorMessage(e));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
@@ -205,4 +216,4 @@ function getFormattedHours(minutes) {
|
|||||||
const days = Math.floor(minutes / 1440) % 365;
|
const days = Math.floor(minutes / 1440) % 365;
|
||||||
const hours = Math.floor(minutes / 60) % 24;
|
const hours = Math.floor(minutes / 60) % 24;
|
||||||
return (years > 0 ? years + chrome.i18n.getMessage("yearAbbreviation") + " " : "") + (days > 0 ? days + chrome.i18n.getMessage("dayAbbreviation") + " " : "") + (hours > 0 ? hours + chrome.i18n.getMessage("hourAbbreviation") + " " : "") + (minutes % 60).toFixed(1);
|
return (years > 0 ? years + chrome.i18n.getMessage("yearAbbreviation") + " " : "") + (days > 0 ? days + chrome.i18n.getMessage("dayAbbreviation") + " " : "") + (hours > 0 ? hours + chrome.i18n.getMessage("hourAbbreviation") + " " : "") + (minutes % 60).toFixed(1);
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/utils.ts
21
src/utils.ts
@@ -6,6 +6,8 @@ import { waitFor } from "../maze-utils/src";
|
|||||||
import { findValidElementFromSelector } from "../maze-utils/src/dom";
|
import { findValidElementFromSelector } from "../maze-utils/src/dom";
|
||||||
import { isSafari } from "../maze-utils/src/config";
|
import { isSafari } from "../maze-utils/src/config";
|
||||||
import { asyncRequestToServer } from "./utils/requests";
|
import { asyncRequestToServer } from "./utils/requests";
|
||||||
|
import { FetchResponse, logRequest } from "../maze-utils/src/background-request-proxy";
|
||||||
|
import { formatJSErrorMessage, getLongErrorMessage } from "../maze-utils/src/formating";
|
||||||
|
|
||||||
export default class Utils {
|
export default class Utils {
|
||||||
|
|
||||||
@@ -276,13 +278,24 @@ export default class Utils {
|
|||||||
|| !Config.config.trackDownvotes) return;
|
|| !Config.config.trackDownvotes) return;
|
||||||
|
|
||||||
if (segmentUUID.length < 60) {
|
if (segmentUUID.length < 60) {
|
||||||
const segmentIDData = await asyncRequestToServer("GET", "/api/segmentID", {
|
let segmentIDData: FetchResponse;
|
||||||
UUID: segmentUUID,
|
try {
|
||||||
videoID
|
segmentIDData = await asyncRequestToServer("GET", "/api/segmentID", {
|
||||||
});
|
UUID: segmentUUID,
|
||||||
|
videoID
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[SB] Caught error while trying to resolve the segment UUID to be hidden", e);
|
||||||
|
alert(`${chrome.i18n.getMessage("segmentHideFailed")}\n${formatJSErrorMessage(e)}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (segmentIDData.ok && segmentIDData.responseText) {
|
if (segmentIDData.ok && segmentIDData.responseText) {
|
||||||
segmentUUID = segmentIDData.responseText;
|
segmentUUID = segmentIDData.responseText;
|
||||||
|
} else {
|
||||||
|
logRequest(segmentIDData, "SB", "segment UUID resolution");
|
||||||
|
alert(`${chrome.i18n.getMessage("segmentHideFailed")}\n${getLongErrorMessage(segmentIDData.status, segmentIDData.responseText)}`);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,17 +2,6 @@ import Config from "../config";
|
|||||||
import * as CompileConfig from "../../config.json";
|
import * as CompileConfig from "../../config.json";
|
||||||
import { FetchResponse, sendRequestToCustomServer } from "../../maze-utils/src/background-request-proxy";
|
import { FetchResponse, sendRequestToCustomServer } from "../../maze-utils/src/background-request-proxy";
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a request to a custom server
|
|
||||||
*
|
|
||||||
* @param type The request type. "GET", "POST", etc.
|
|
||||||
* @param address The address to add to the SponsorBlock server address
|
|
||||||
* @param callback
|
|
||||||
*/
|
|
||||||
export function asyncRequestToCustomServer(type: string, url: string, data = {}, headers = {}): Promise<FetchResponse> {
|
|
||||||
return sendRequestToCustomServer(type, url, data, headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a request to the SponsorBlock server with address added as a query
|
* Sends a request to the SponsorBlock server with address added as a query
|
||||||
*
|
*
|
||||||
@@ -23,25 +12,5 @@ export function asyncRequestToCustomServer(type: string, url: string, data = {},
|
|||||||
export async function asyncRequestToServer(type: string, address: string, data = {}, headers = {}): Promise<FetchResponse> {
|
export async function asyncRequestToServer(type: string, address: string, data = {}, headers = {}): Promise<FetchResponse> {
|
||||||
const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress;
|
const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress;
|
||||||
|
|
||||||
return await (asyncRequestToCustomServer(type, serverAddress + address, data, headers));
|
return await (sendRequestToCustomServer(type, serverAddress + address, data, headers));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a request to the SponsorBlock server with address added as a query
|
|
||||||
*
|
|
||||||
* @param type The request type. "GET", "POST", etc.
|
|
||||||
* @param address The address to add to the SponsorBlock server address
|
|
||||||
* @param callback
|
|
||||||
*/
|
|
||||||
export function sendRequestToServer(type: string, address: string, callback?: (response: FetchResponse) => void): void {
|
|
||||||
const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress;
|
|
||||||
|
|
||||||
// Ask the background script to do the work
|
|
||||||
chrome.runtime.sendMessage({
|
|
||||||
message: "sendRequest",
|
|
||||||
type,
|
|
||||||
url: serverAddress + address
|
|
||||||
}, (response) => {
|
|
||||||
callback(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,7 @@ import { ActionTypes, SponsorSourceType, SponsorTime, VideoID } from "../types";
|
|||||||
import { getHashParams } from "./pageUtils";
|
import { getHashParams } from "./pageUtils";
|
||||||
import { asyncRequestToServer } from "./requests";
|
import { asyncRequestToServer } from "./requests";
|
||||||
import { extensionUserAgent } from "../../maze-utils/src";
|
import { extensionUserAgent } from "../../maze-utils/src";
|
||||||
|
import { logRequest, serializeOrStringify } from "../../maze-utils/src/background-request-proxy";
|
||||||
|
|
||||||
const segmentDataCache = new DataCache<VideoID, SegmentResponse>(() => {
|
const segmentDataCache = new DataCache<VideoID, SegmentResponse>(() => {
|
||||||
return {
|
return {
|
||||||
@@ -18,7 +19,7 @@ const pendingList: Record<VideoID, Promise<SegmentResponse>> = {};
|
|||||||
|
|
||||||
export interface SegmentResponse {
|
export interface SegmentResponse {
|
||||||
segments: SponsorTime[] | null;
|
segments: SponsorTime[] | null;
|
||||||
status: number;
|
status: number | Error | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSegmentsForVideo(videoID: VideoID, ignoreCache: boolean): Promise<SegmentResponse> {
|
export async function getSegmentsForVideo(videoID: VideoID, ignoreCache: boolean): Promise<SegmentResponse> {
|
||||||
@@ -37,8 +38,18 @@ export async function getSegmentsForVideo(videoID: VideoID, ignoreCache: boolean
|
|||||||
const pendingData = fetchSegmentsForVideo(videoID);
|
const pendingData = fetchSegmentsForVideo(videoID);
|
||||||
pendingList[videoID] = pendingData;
|
pendingList[videoID] = pendingData;
|
||||||
|
|
||||||
const result = await pendingData;
|
let result: Awaited<typeof pendingData>;
|
||||||
delete pendingList[videoID];
|
try {
|
||||||
|
result = await pendingData;
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[SB] Caught error while fetching segments", e);
|
||||||
|
return {
|
||||||
|
segments: null,
|
||||||
|
status: serializeOrStringify(e),
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
delete pendingList[videoID];
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -82,6 +93,7 @@ async function fetchSegmentsForVideo(videoID: VideoID): Promise<SegmentResponse>
|
|||||||
segmentDataCache.setupCache(videoID);
|
segmentDataCache.setupCache(videoID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (response.status !== 404) logRequest(response, "SB", "skip segments");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
segments: null,
|
segments: null,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { getHash } from "../../maze-utils/src/hash";
|
|||||||
import { logWarn } from "./logger";
|
import { logWarn } from "./logger";
|
||||||
import { asyncRequestToServer } from "./requests";
|
import { asyncRequestToServer } from "./requests";
|
||||||
import { getCategorySelection } from "./skipRule";
|
import { getCategorySelection } from "./skipRule";
|
||||||
|
import { FetchResponse, logRequest } from "../../maze-utils/src/background-request-proxy";
|
||||||
|
|
||||||
export interface VideoLabelsCacheData {
|
export interface VideoLabelsCacheData {
|
||||||
category: Category;
|
category: Category;
|
||||||
@@ -24,8 +25,15 @@ async function getLabelHashBlock(hashPrefix: string): Promise<LabelCacheEntry |
|
|||||||
return cachedEntry;
|
return cachedEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await asyncRequestToServer("GET", `/api/videoLabels/${hashPrefix}?hasStartSegment=true`);
|
let response: FetchResponse;
|
||||||
|
try {
|
||||||
|
response = await asyncRequestToServer("GET", `/api/videoLabels/${hashPrefix}?hasStartSegment=true`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[SB] Caught error while fetching video labels", e)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
|
logRequest(response, "SB", "video labels");
|
||||||
// No video labels or server down
|
// No video labels or server down
|
||||||
labelCache[hashPrefix] = {
|
labelCache[hashPrefix] = {
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
@@ -85,4 +93,4 @@ export async function getHasStartSegment(videoID: VideoID): Promise<boolean | nu
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import { objectToURI } from "../../maze-utils/src";
|
import { objectToURI } from "../../maze-utils/src";
|
||||||
|
import { FetchResponse, logRequest } from "../../maze-utils/src/background-request-proxy";
|
||||||
|
import { formatJSErrorMessage, getLongErrorMessage } from "../../maze-utils/src/formating";
|
||||||
import { getHash } from "../../maze-utils/src/hash";
|
import { getHash } from "../../maze-utils/src/hash";
|
||||||
import Config from "../config";
|
import Config from "../config";
|
||||||
import GenericNotice, { NoticeOptions } from "../render/GenericNotice";
|
import GenericNotice, { NoticeOptions } from "../render/GenericNotice";
|
||||||
@@ -12,15 +14,26 @@ export interface ChatConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function openWarningDialog(contentContainer: ContentContainer): Promise<void> {
|
export async function openWarningDialog(contentContainer: ContentContainer): Promise<void> {
|
||||||
const userInfo = await asyncRequestToServer("GET", "/api/userInfo", {
|
let userInfo: FetchResponse;
|
||||||
publicUserID: await getHash(Config.config.userID),
|
try {
|
||||||
values: ["warningReason"]
|
userInfo = await asyncRequestToServer("GET", "/api/userInfo", {
|
||||||
});
|
publicUserID: await getHash(Config.config.userID),
|
||||||
|
values: ["warningReason"]
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[SB] Caught error while trying to fetch user's active warnings", e)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (userInfo.ok) {
|
if (userInfo.ok) {
|
||||||
const warningReason = JSON.parse(userInfo.responseText)?.warningReason;
|
const warningReason = JSON.parse(userInfo.responseText)?.warningReason;
|
||||||
const userNameData = await asyncRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID);
|
let userName = "";
|
||||||
const userName = userNameData.ok ? JSON.parse(userNameData.responseText).userName : "";
|
try {
|
||||||
|
const userNameData = await asyncRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID);
|
||||||
|
userName = userNameData.ok ? JSON.parse(userNameData.responseText).userName : "";
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("[SB] Caught non-fatal error while trying to resolve user's username", e);
|
||||||
|
}
|
||||||
const publicUserID = await getHash(Config.config.userID);
|
const publicUserID = await getHash(Config.config.userID);
|
||||||
|
|
||||||
let notice: GenericNotice = null;
|
let notice: GenericNotice = null;
|
||||||
@@ -42,15 +55,22 @@ export async function openWarningDialog(contentContainer: ContentContainer): Pro
|
|||||||
{
|
{
|
||||||
name: chrome.i18n.getMessage("warningConfirmButton"),
|
name: chrome.i18n.getMessage("warningConfirmButton"),
|
||||||
listener: async () => {
|
listener: async () => {
|
||||||
const result = await asyncRequestToServer("POST", "/api/warnUser", {
|
let result: FetchResponse;
|
||||||
userID: Config.config.userID,
|
try {
|
||||||
enabled: false
|
result = await asyncRequestToServer("POST", "/api/warnUser", {
|
||||||
});
|
userID: Config.config.userID,
|
||||||
|
enabled: false
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[SB] Caught error while trying to acknowledge user's active warning", e);
|
||||||
|
alert(formatJSErrorMessage(e));
|
||||||
|
}
|
||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
notice?.close();
|
notice?.close();
|
||||||
} else {
|
} else {
|
||||||
alert(`${chrome.i18n.getMessage("warningError")} ${result.status}`);
|
logRequest(result, "SB", "warning acknowledgement");
|
||||||
|
alert(getLongErrorMessage(result.status, result.responseText));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
@@ -58,6 +78,8 @@ export async function openWarningDialog(contentContainer: ContentContainer): Pro
|
|||||||
};
|
};
|
||||||
|
|
||||||
notice = new GenericNotice(contentContainer, "warningNotice", options);
|
notice = new GenericNotice(contentContainer, "warningNotice", options);
|
||||||
|
} else {
|
||||||
|
logRequest(userInfo, "SB", "user's active warnings");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user