play stop fixed
This commit is contained in:
parent
2ba348ac98
commit
be1c2eb98a
1 changed files with 23 additions and 24 deletions
47
content.js
47
content.js
|
|
@ -12,7 +12,6 @@ const PHOTOS = [
|
||||||
|
|
||||||
const CANVAS_SELECTOR = ".VibeWidgetAnimation_root__7fpeP > canvas:nth-child(1)";
|
const CANVAS_SELECTOR = ".VibeWidgetAnimation_root__7fpeP > canvas:nth-child(1)";
|
||||||
const ROOT_SELECTOR = ".VibeWidgetAnimation_root__7fpeP";
|
const ROOT_SELECTOR = ".VibeWidgetAnimation_root__7fpeP";
|
||||||
const PLAY_INDICATOR_SELECTOR = ".VibeResetButton_root__ju8pE";
|
|
||||||
|
|
||||||
let container = null;
|
let container = null;
|
||||||
let currentEl = null;
|
let currentEl = null;
|
||||||
|
|
@ -87,38 +86,38 @@ function showVideo(width, height) {
|
||||||
video.play().catch(() => {});
|
video.play().catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
function syncFromIndicator(indicator, width, height) {
|
function watchForPlayer(width, height) {
|
||||||
if (indicator.getAttribute("aria-hidden") === "true") {
|
const PLAY_BTN_SELECTOR = ".VibePlayerControls_playButton__vnoer";
|
||||||
if (PHOTOS.length > 0) {
|
|
||||||
showPhoto(width, height);
|
|
||||||
} else {
|
|
||||||
currentEl?.pause?.();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showVideo(width, height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function watchForPlayIndicator(width, height) {
|
const isPlaying = (btn) => btn.getAttribute("aria-label") === "Pause";
|
||||||
const bind = (indicator) => {
|
|
||||||
syncFromIndicator(indicator, width, height);
|
const sync = (btn) => {
|
||||||
new MutationObserver(() => syncFromIndicator(indicator, width, height)).observe(indicator, {
|
if (isPlaying(btn)) {
|
||||||
|
showVideo(width, height);
|
||||||
|
} else if (PHOTOS.length > 0) {
|
||||||
|
showPhoto(width, height);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const bind = (btn) => {
|
||||||
|
sync(btn);
|
||||||
|
new MutationObserver(() => sync(btn)).observe(btn, {
|
||||||
attributes: true,
|
attributes: true,
|
||||||
attributeFilter: ["aria-hidden"],
|
attributeFilter: ["aria-label"],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const indicator = document.querySelector(PLAY_INDICATOR_SELECTOR);
|
const btn = document.querySelector(PLAY_BTN_SELECTOR);
|
||||||
if (indicator) {
|
if (btn) {
|
||||||
bind(indicator);
|
bind(btn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const waitObserver = new MutationObserver(() => {
|
const waitObserver = new MutationObserver(() => {
|
||||||
const indicator = document.querySelector(PLAY_INDICATOR_SELECTOR);
|
const el = document.querySelector(PLAY_BTN_SELECTOR);
|
||||||
if (indicator) {
|
if (el) {
|
||||||
waitObserver.disconnect();
|
waitObserver.disconnect();
|
||||||
bind(indicator);
|
bind(el);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
waitObserver.observe(document.body, { childList: true, subtree: true });
|
waitObserver.observe(document.body, { childList: true, subtree: true });
|
||||||
|
|
@ -146,7 +145,7 @@ function replaceAnimation(canvas) {
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
|
|
||||||
showVideo(w, h);
|
showVideo(w, h);
|
||||||
watchForPlayIndicator(w, h);
|
watchForPlayer(w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
const observer = new MutationObserver(() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue