Commit 3ba5d473 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇 Committed by Fushan Wen
Browse files

Check whether removed DOM node was a player

The player might not have been in the DOM in the first place
(e.g. an audio player), so just checking for whether it is in the DOM
at the end looks like a nice optimization but often ends up just
considering the player gone when *any* DOM element got removed.
parent 5b57c8be
Pipeline #206269 passed with stage
in 47 seconds
......@@ -577,23 +577,37 @@ function loadMpris() {
});
});
nodesRemoved = nodesRemoved || mutation.removedNodes.length > 0;
});
mutation.removedNodes.forEach((node) => {
if (typeof node.matches !== "function") {
return;
}
if (activePlayer && nodesRemoved) {
// One of the removed nodes could be activePlayer
// If it is still in the visible DOM, don't consider it gone
if (document.body.contains(activePlayer)) {
return;
}
// Check whether the node itself or any of its children is the current player
const players = findAllPlayersFromNode(node);
if (node.matches("video,audio")) {
players.unshift(node);
}
// If the player got temporarily added by us, don't consider it gone
if (activePlayer.dataset.pbiPausedForDomRemoval === "true") {
return;
}
for (let player of players) {
if (player !== activePlayer) {
continue;
}
sendPlayerGone();
}
// If the player is still in the visible DOM, don't consider it gone
if (document.body.contains(player)) {
continue;
}
// If the player got temporarily added by us, don't consider it gone
if (player.dataset.pbiPausedForDomRemoval === "true") {
continue;
}
sendPlayerGone();
break;
}
});
});
});
window.addEventListener("pagehide", function () {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment