From f789197d02f55f6d8085a0bfebb3dffa439bb6b9 Mon Sep 17 00:00:00 2001 From: hanyd <hanyd@bsbsb.top> Date: Mon, 9 Sep 2024 16:04:59 +0800 Subject: [PATCH] Simplify button visibility logic --- .../PlayerButtonGroupComponent.tsx | 73 ++++++++++--------- src/content.ts | 41 ++++------- 2 files changed, 52 insertions(+), 62 deletions(-) diff --git a/src/components/playerButtons/PlayerButtonGroupComponent.tsx b/src/components/playerButtons/PlayerButtonGroupComponent.tsx index 3e76a819..5e6d38d9 100644 --- a/src/components/playerButtons/PlayerButtonGroupComponent.tsx +++ b/src/components/playerButtons/PlayerButtonGroupComponent.tsx @@ -2,6 +2,7 @@ import { ConfigProvider, Popconfirm, theme } from "antd"; import * as React from "react"; import InfoButtonComponent from "./InfoButton"; import PlayerButtonComponent from "./PlayerButtonComponent"; +import Config from "../../config"; interface PlayerButtonGroupProps { startSegmentCallback: () => void; @@ -31,9 +32,10 @@ function PlayerButtonGroupComponent({ return ( <ConfigProvider theme={{ token: { colorPrimary: "#00aeec" }, algorithm: theme.darkAlgorithm }}> - <InfoButtonComponent infoCallback={infoCallback}></InfoButtonComponent> + <div style={{ display: Config.config.hideVideoPlayerControls ? "none" : "contents" }}> + <InfoButtonComponent infoCallback={infoCallback}></InfoButtonComponent> - {/* <PlayerButtonComponent + {/* <PlayerButtonComponent baseID="info" title="openPopup" imageName="PlayerInfoIconSponsorBlocker.svg" @@ -42,44 +44,45 @@ function PlayerButtonGroupComponent({ onClick={infoCallback} ></PlayerButtonComponent> */} - <PlayerButtonComponent - baseID="submit" - title="OpenSubmissionMenu" - imageName="PlayerUploadIconSponsorBlocker.svg" - isDraggable={false} - onClick={submitCallback} - ></PlayerButtonComponent> - - <Popconfirm - title={chrome.i18n.getMessage("clearThis")} - description={getPopconfirmDescription()} - onConfirm={deleteCallback} - okText={chrome.i18n.getMessage("confirm")} - cancelText={chrome.i18n.getMessage("cancel")} - > <PlayerButtonComponent - baseID="delete" - title="clearTimes" - imageName="PlayerDeleteIconSponsorBlocker.svg" + baseID="submit" + title="OpenSubmissionMenu" + imageName="PlayerUploadIconSponsorBlocker.svg" isDraggable={false} + onClick={submitCallback} ></PlayerButtonComponent> - </Popconfirm> - <PlayerButtonComponent - baseID="cancelSegment" - title="sponsorCancel" - imageName="PlayerCancelSegmentIconSponsorBlocker.svg" - isDraggable={false} - onClick={cancelSegmentCallback} - ></PlayerButtonComponent> + <Popconfirm + title={chrome.i18n.getMessage("clearThis")} + description={getPopconfirmDescription()} + onConfirm={deleteCallback} + okText={chrome.i18n.getMessage("confirm")} + cancelText={chrome.i18n.getMessage("cancel")} + > + <PlayerButtonComponent + baseID="delete" + title="clearTimes" + imageName="PlayerDeleteIconSponsorBlocker.svg" + isDraggable={false} + ></PlayerButtonComponent> + </Popconfirm> - <PlayerButtonComponent - baseID="startSegment" - title="sponsorStart" - imageName="PlayerStartIconSponsorBlocker.svg" - isDraggable={false} - onClick={startSegmentCallback} - ></PlayerButtonComponent> + <PlayerButtonComponent + baseID="cancelSegment" + title="sponsorCancel" + imageName="PlayerCancelSegmentIconSponsorBlocker.svg" + isDraggable={false} + onClick={cancelSegmentCallback} + ></PlayerButtonComponent> + + <PlayerButtonComponent + baseID="startSegment" + title="sponsorStart" + imageName="PlayerStartIconSponsorBlocker.svg" + isDraggable={false} + onClick={startSegmentCallback} + ></PlayerButtonComponent> + </div> </ConfigProvider> ); } diff --git a/src/content.ts b/src/content.ts index 1068769f..0d31974b 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1925,36 +1925,23 @@ function updateEditButtonsOnPlayer(): void { // Don't try to update the buttons if we aren't on a Bilibili video page if (!getVideoID()) return; - const buttonsEnabled = !Config.config.hideVideoPlayerControls; - - let creatingSegment = false; - let submitButtonVisible = false; - let deleteButtonVisible = false; - - // Only check if buttons should be visible if they're enabled - if (buttonsEnabled) { - creatingSegment = isSegmentCreationInProgress(); - - // Show only if there are any segments to submit - submitButtonVisible = sponsorTimesSubmitting.length > 0; - - // Show only if there are any segments to delete - deleteButtonVisible = - sponsorTimesSubmitting.length > 1 || (sponsorTimesSubmitting.length > 0 && !creatingSegment); - } + const creatingSegment = isSegmentCreationInProgress(); + // Show only if there are any segments to submit + const submitButtonVisible = sponsorTimesSubmitting.length > 0; + // Show only if there are any segments to delete + const deleteButtonVisible = + sponsorTimesSubmitting.length > 1 || (sponsorTimesSubmitting.length > 0 && !creatingSegment); // Update the elements - playerButtons.startSegment.button.style.display = buttonsEnabled ? "unset" : "none"; - playerButtons.cancelSegment.button.style.display = buttonsEnabled && creatingSegment ? "unset" : "none"; + playerButtons.startSegment.button.style.display = "unset"; + playerButtons.cancelSegment.button.style.display = creatingSegment ? "unset" : "none"; - if (buttonsEnabled) { - if (creatingSegment) { - playerButtons.startSegment.image.src = chrome.runtime.getURL("icons/PlayerStopIconSponsorBlocker.svg"); - playerButtons.startSegment.button.setAttribute("title", chrome.i18n.getMessage("sponsorEnd")); - } else { - playerButtons.startSegment.image.src = chrome.runtime.getURL("icons/PlayerStartIconSponsorBlocker.svg"); - playerButtons.startSegment.button.setAttribute("title", chrome.i18n.getMessage("sponsorStart")); - } + if (creatingSegment) { + playerButtons.startSegment.image.src = chrome.runtime.getURL("icons/PlayerStopIconSponsorBlocker.svg"); + playerButtons.startSegment.button.setAttribute("title", chrome.i18n.getMessage("sponsorEnd")); + } else { + playerButtons.startSegment.image.src = chrome.runtime.getURL("icons/PlayerStartIconSponsorBlocker.svg"); + playerButtons.startSegment.button.setAttribute("title", chrome.i18n.getMessage("sponsorStart")); } playerButtons.submit.button.style.display =