Changeset View
Changeset View
Standalone View
Standalone View
extension/content-script.js
Show First 20 Lines • Show All 346 Lines • ▼ Show 20 Line(s) | 343 | document.addEventListener("DOMContentLoaded", function() { | |||
---|---|---|---|---|---|
347 | // TODO figure out somehow when a <video> tag is added dynamically and autoplays | 347 | // TODO figure out somehow when a <video> tag is added dynamically and autoplays | ||
348 | // as can happen on Ajax-heavy pages like YouTube | 348 | // as can happen on Ajax-heavy pages like YouTube | ||
349 | // could also be done if we just look for the "audio playing in this tab" and only then check for player? | 349 | // could also be done if we just look for the "audio playing in this tab" and only then check for player? | ||
350 | // cf. "checkPlayer" event above | 350 | // cf. "checkPlayer" event above | ||
351 | 351 | | |||
352 | var observer = new MutationObserver(function (mutations) { | 352 | var observer = new MutationObserver(function (mutations) { | ||
353 | mutations.forEach(function (mutation) { | 353 | mutations.forEach(function (mutation) { | ||
354 | mutation.addedNodes.forEach(function (node) { | 354 | mutation.addedNodes.forEach(function (node) { | ||
355 | if (node.tagName === "VIDEO" || node.tagName === "AUDIO") { | 355 | if (typeof node.querySelectorAll !== "function") { | ||
356 | registerPlayer(node); | 356 | return; | ||
357 | } | 357 | } | ||
358 | var players = node.querySelectorAll("video,audio"); | ||||
359 | players.forEach(function (player) { | ||||
360 | registerPlayer(player); | ||||
361 | }); | ||||
broulik: `if (typeof node.querySelectorAll !== "function")`
also coding style, add braces | |||||
358 | }); | 362 | }); | ||
359 | }); | 363 | }); | ||
360 | }); | 364 | }); | ||
361 | 365 | | |||
362 | observer.observe(document.documentElement, { | 366 | observer.observe(document.documentElement, { | ||
363 | childList: true, | 367 | childList: true, | ||
364 | subtree: true | 368 | subtree: true | ||
365 | }); | 369 | }); | ||
▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines |
if (typeof node.querySelectorAll !== "function")
also coding style, add braces