Changeset View
Changeset View
Standalone View
Standalone View
extension/content-script.js
Show First 20 Lines • Show All 546 Lines • ▼ Show 20 Line(s) | 498 | function loadMpris() { | |||
---|---|---|---|---|---|
547 | 547 | | |||
548 | observer.observe(document.documentElement, { | 548 | observer.observe(document.documentElement, { | ||
549 | childList: true, | 549 | childList: true, | ||
550 | subtree: true | 550 | subtree: true | ||
551 | }); | 551 | }); | ||
552 | 552 | | |||
553 | // Observe changes to the <title> tag in case it is updated after the player has started playing | 553 | // Observe changes to the <title> tag in case it is updated after the player has started playing | ||
554 | var titleTag = document.querySelector("head > title"); | 554 | var titleTag = document.querySelector("head > title"); | ||
555 | let oldPageTitle = ""; | ||||
555 | if (titleTag) { | 556 | if (titleTag) { | ||
556 | var titleObserver = new MutationObserver(function (mutations) { | 557 | var titleObserver = new MutationObserver(function (mutations) { | ||
557 | mutations.forEach(function (mutation) { | 558 | mutations.forEach(function (mutation) { | ||
558 | var pageTitle = mutation.target.textContent; | 559 | var pageTitle = mutation.target.textContent; | ||
559 | if (pageTitle) { | 560 | if (pageTitle && oldPageTitle !== pageTitle) { | ||
560 | sendMessage("mpris", "titlechange", { | 561 | sendMessage("mpris", "titlechange", { | ||
561 | pageTitle: pageTitle | 562 | pageTitle: pageTitle | ||
562 | }); | 563 | }); | ||
563 | } | 564 | } | ||
565 | oldPageTitle = pageTitle; | ||||
564 | }); | 566 | }); | ||
565 | }); | 567 | }); | ||
566 | 568 | | |||
567 | titleObserver.observe(titleTag, { | 569 | titleObserver.observe(titleTag, { | ||
568 | childList: true, // text content is technically a child node | 570 | childList: true, // text content is technically a child node | ||
569 | subtree: true, | 571 | subtree: true, | ||
570 | characterData: true | 572 | characterData: true | ||
571 | }); | 573 | }); | ||
▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines |