Changeset View
Changeset View
Standalone View
Standalone View
extension/content-script.js
Show First 20 Lines • Show All 462 Lines • ▼ Show 20 Line(s) | 458 | function loadMpris() { | |||
---|---|---|---|---|---|
463 | 463 | | |||
464 | var observer = new MutationObserver(function (mutations) { | 464 | var observer = new MutationObserver(function (mutations) { | ||
465 | mutations.forEach(function (mutation) { | 465 | mutations.forEach(function (mutation) { | ||
466 | mutation.addedNodes.forEach(function (node) { | 466 | mutation.addedNodes.forEach(function (node) { | ||
467 | if (typeof node.matches !== "function" || typeof node.querySelectorAll !== "function") { | 467 | if (typeof node.matches !== "function" || typeof node.querySelectorAll !== "function") { | ||
468 | return; | 468 | return; | ||
469 | } | 469 | } | ||
470 | 470 | | |||
471 | // first check whether the node itself is audio/video | 471 | // Check whether the node itself or any of its children is a player | ||
472 | var players = Array.from(node.querySelectorAll("video,audio")); | ||||
472 | if (node.matches("video,audio")) { | 473 | if (node.matches("video,audio")) { | ||
473 | registerPlayer(node); | 474 | players.unshift(node); | ||
474 | return; | | |||
475 | } | 475 | } | ||
476 | 476 | | |||
477 | // if not, check whether any of its children are | | |||
478 | var players = node.querySelectorAll("video,audio"); | | |||
479 | players.forEach(function (player) { | 477 | players.forEach(function (player) { | ||
480 | registerPlayer(player); | 478 | registerPlayer(player); | ||
481 | }); | 479 | }); | ||
482 | }); | 480 | }); | ||
483 | 481 | | |||
484 | mutation.removedNodes.forEach(function (node) { | 482 | mutation.removedNodes.forEach(function (node) { | ||
485 | if (typeof node.matches !== "function" || typeof node.querySelectorAll !== "function") { | 483 | if (typeof node.matches !== "function" || typeof node.querySelectorAll !== "function") { | ||
486 | return; | 484 | return; | ||
487 | } | 485 | } | ||
488 | 486 | | |||
487 | // Check whether the node itself or any of its children is the current player | ||||
488 | var players = Array.from(node.querySelectorAll("video,audio")); | ||||
489 | if (node.matches("video,audio")) { | 489 | if (node.matches("video,audio")) { | ||
490 | if (node == activePlayer) { | 490 | players.unshift(node); | ||
491 | sendPlayerGone(); | | |||
492 | } | | |||
493 | return; | | |||
494 | } | 491 | } | ||
495 | 492 | | |||
496 | var players = node.querySelectorAll("video,audio"); | | |||
497 | players.forEach(function (player) { | 493 | players.forEach(function (player) { | ||
498 | if (player == activePlayer) { | 494 | if (player == activePlayer) { | ||
499 | sendPlayerGone(); | 495 | sendPlayerGone(); | ||
500 | return; | 496 | return; | ||
501 | } | 497 | } | ||
502 | }); | 498 | }); | ||
503 | }); | 499 | }); | ||
504 | }); | 500 | }); | ||
▲ Show 20 Lines • Show All 195 Lines • Show Last 20 Lines |