Skip to content

Commit

Permalink
Simplify button visibility logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Sep 9, 2024
1 parent 11ae144 commit f789197
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 62 deletions.
73 changes: 38 additions & 35 deletions src/components/playerButtons/PlayerButtonGroupComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand All @@ -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>
);
}
Expand Down
41 changes: 14 additions & 27 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit f789197

Please sign in to comment.