Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Several minor improvements #121

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/SponsorTimeEditComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CheckboxChangeEvent } from "antd/es/checkbox";
import * as React from "react";
import * as CompileConfig from "../../config.json";
import Config from "../config";
import { keybindToString } from "../config/config";
import { showMessage } from "../render/MessageNotice";
import { RectangleTooltip } from "../render/RectangleTooltip";
import { asyncRequestToServer } from "../requests/requests";
Expand Down Expand Up @@ -286,6 +287,11 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
<span
id={"sponsorTimePreviewButton" + this.idSuffix}
className="sponsorTimeEditButton"
{...(Config.config.previewKeybind && {
title: `${chrome.i18n.getMessage("preview")} (${keybindToString(
Config.config.previewKeybind
)})`,
})}
onClick={(e) => this.previewTime(e.ctrlKey, e.shiftKey)}
>
{chrome.i18n.getMessage("preview")}
Expand Down
8 changes: 7 additions & 1 deletion src/components/SubmissionNoticeComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import GenericNotice from "../render/GenericNotice";
import { Category, ContentContainer } from "../types";

import { ConfigProvider, Popover, theme } from "antd";
import { keybindToString } from "../config/config";
import { showMessage } from "../render/MessageNotice";
import { getGuidelineInfo } from "../utils/constants";
import { exportTimes } from "../utils/exporter";
import { getVideo } from "../utils/video";
import NoticeComponent from "./NoticeComponent";
import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
import SponsorTimeEditComponent from "./SponsorTimeEditComponent";
import { showMessage } from "../render/MessageNotice";

export interface SubmissionNoticeProps {
// Contains functions and variables from the content script needed by the skip notice
Expand Down Expand Up @@ -180,6 +181,11 @@ class SubmissionNoticeComponent extends React.Component<SubmissionNoticeProps, S
{/* Submit Button */}
<button
className="sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton"
{...(Config.config.actuallySubmitKeybind && {
title: `${chrome.i18n.getMessage("submit")} (${keybindToString(
Config.config.actuallySubmitKeybind
)})`,
})}
onClick={this.submit.bind(this)}
>
{chrome.i18n.getMessage("submit")}
Expand Down
9 changes: 7 additions & 2 deletions src/components/playerButtons/PlayerButtonComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import * as React from "react";
import { forwardRef } from "react";
import { Keybind, keybindToString } from "../../config/config";
import { getIconLink } from "../../config/configUtils";

interface PlayerButtonProps {
baseID: string;
title: string;
imageName: string;
keybind?: Keybind;
isDraggable?: boolean;
show?: boolean;
onClick?: () => void;
}

const PlayerButtonComponent = forwardRef<HTMLButtonElement, PlayerButtonProps>(function (
{ baseID, title, imageName, isDraggable = false, show = true, onClick },
{ baseID, title, imageName, keybind, isDraggable = false, show = true, onClick },
ref
) {
return (
Expand All @@ -30,7 +32,10 @@ const PlayerButtonComponent = forwardRef<HTMLButtonElement, PlayerButtonProps>(f
src={chrome.runtime.getURL("icons/" + getIconLink(imageName))}
draggable={isDraggable}
></img>
<div className="playerButtonTooltip">{chrome.i18n.getMessage(title)}</div>
<div className="playerButtonTooltip">
{chrome.i18n.getMessage(title)}
{keybind ? ` (${keybindToString(keybind)})` : ""}
</div>
</button>
);
});
Expand Down
2 changes: 2 additions & 0 deletions src/components/playerButtons/PlayerButtonGroupComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const PlayerButtonGroupComponent = React.forwardRef(function (
baseID="submit"
title="OpenSubmissionMenu"
imageName="PlayerUploadIconSponsorBlocker.svg"
keybind={Config.config.submitKeybind}
isDraggable={false}
show={showSubmitButton()}
onClick={submitCallback}
Expand Down Expand Up @@ -107,6 +108,7 @@ const PlayerButtonGroupComponent = React.forwardRef(function (
imageName={
isCreatingSegment() ? "PlayerStopIconSponsorBlocker.svg" : "PlayerStartIconSponsorBlocker.svg"
}
keybind={Config.config.startSponsorKeybind}
onClick={startSegmentCallback}
isDraggable={false}
></PlayerButtonComponent>
Expand Down
20 changes: 12 additions & 8 deletions src/document/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,26 @@ function overwriteFetch() {
.clone()
.text()
.then((res) => processURLRequest(new URL(urlStr, window.location.href), res))
.catch(() => {});
.catch((e) => {
console.error("[BSB] Error processing URL Request: ", e);
});
return response;
};
}

function overwriteXHR() {
const originalSend = XMLHttpRequest.prototype.send;

XMLHttpRequest.prototype.send = function (body?: Document | BodyInit | null) {
XMLHttpRequest.prototype.send = function (this: XMLHttpRequest, body?: Document | BodyInit | null) {
this.addEventListener("loadend", function () {
if (this.readyState === 4 && this.status >= 200 && this.status < 300) {
if (this.readyState === this.DONE && this.status >= 200 && this.status < 300) {
try {
const url = new URL(this.responseURL);
processURLRequest(url, this.responseText);
if (this.responseType === "" || this.responseType === "text") {
const url = new URL(this.responseURL);
processURLRequest(url, this.responseText);
}
} catch (e) {
console.debug("Failed to process request");
console.error("[BSB] Error processing URL Request: ", e);
}
}
});
Expand All @@ -49,13 +53,13 @@ function overwriteXHR() {
}

function processURLRequest(url: URL, responseText: string): void {
if (url.pathname.includes("/player/wbi/playurl")) {
if (url.pathname.startsWith("/player/wbi/playurl")) {
const response = JSON.parse(responseText) as BilibiliResponse<BiliPlayInfo>;
const cid = url.searchParams.get("cid");
if (cid && response?.data?.dash?.video) {
savePlayInfo(cid, playUrlResponseToPlayInfo(response.data));
}
} else if (url.pathname.includes("/x/player/wbi/v2")) {
} else if (url.pathname.startsWith("/x/player/wbi/v2")) {
const response = JSON.parse(responseText) as BilibiliResponse<BiliVideoDetail>;
saveAidFromDetail(response.data);
}
Expand Down
Loading