Skip to content

Commit

Permalink
fix(loop button): check box wouldn't check / uncheck
Browse files Browse the repository at this point in the history
when changed from player right click menu
  • Loading branch information
VampireChicken12 committed Nov 7, 2023
1 parent 4e0ea0e commit 043b1cc
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/features/loopButton/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { waitForSpecificMessage } from "@/src/utils/utilities";
import { loopButtonClickListener, makeLoopIcon } from "./utils";
import { addFeatureItemToMenu, removeFeatureItemFromMenu } from "../featureMenu/utils";
import eventManager from "@/src/utils/EventManager";
import { addFeatureItemToMenu, getFeatureMenuItem, removeFeatureItemFromMenu } from "../featureMenu/utils";
import eventManager, { type FeatureName } from "@/src/utils/EventManager";

export async function addLoopButton() {
// Wait for the "options" message from the content script
Expand All @@ -28,6 +28,30 @@ export async function addLoopButton() {
listener: loopButtonClickListener,
isToggle: true
});
const loopChangedHandler = (mutationList: MutationRecord[]) => {
for (const mutation of mutationList) {
if (mutation.type === "attributes") {
const { attributeName, target } = mutation;
if (attributeName === "loop") {
const { loop } = target as HTMLVideoElement;
const featureName: FeatureName = "loopButton";
// Get the feature menu
const featureMenu = document.querySelector("#yte-feature-menu") as HTMLDivElement | null;
if (!featureMenu) return;

// Check if the feature item already exists in the menu
const featureExistsInMenu = featureMenu.querySelector(`#yte-feature-${featureName}`) as HTMLDivElement | null;
if (featureExistsInMenu) {
const menuItem = getFeatureMenuItem(featureName);
if (!menuItem) return;
menuItem.ariaChecked = loop ? "true" : "false";
}
}
}
}
};
const loopChangeMutationObserver = new MutationObserver(loopChangedHandler);
loopChangeMutationObserver.observe(videoElement, { attributes: true, attributeFilter: ["loop"] });
}
export function removeLoopButton() {
removeFeatureItemFromMenu("loopButton");
Expand Down

0 comments on commit 043b1cc

Please sign in to comment.