mirror of
https://codeberg.org/vlw/disneyplus-pip.git
synced 2025-09-14 02:33:41 +02:00
fix: PIP controls inject timeout
This commit is contained in:
parent
f676e4cb70
commit
c18d3a86dc
2 changed files with 16 additions and 23 deletions
|
@ -2,34 +2,17 @@ class PIPController {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.element = null;
|
this.element = null;
|
||||||
|
|
||||||
const config = {
|
|
||||||
childList: true,
|
|
||||||
subtree: true
|
|
||||||
}
|
|
||||||
|
|
||||||
const mutationTimeout = 500;
|
|
||||||
let mutating = null;
|
|
||||||
let prevHref = null;
|
|
||||||
|
|
||||||
// SPA navigation handler
|
// SPA navigation handler
|
||||||
this.observer = new MutationObserver(() => {
|
this.observer = new MutationObserver(() => {
|
||||||
if (this.isPlayerPage()) {
|
if (this.isPlayerPage()) {
|
||||||
clearTimeout(mutating);
|
this.injectPipControls();
|
||||||
|
|
||||||
// Wait for mutation to stop
|
|
||||||
mutating = setTimeout(() => {
|
|
||||||
// Attempt to inject PIP controls
|
|
||||||
if (prevHref !== window.location.href) {
|
|
||||||
this.injectPipControls();
|
|
||||||
prevHref = window.location.href;
|
|
||||||
}
|
|
||||||
}, mutationTimeout);
|
|
||||||
} else {
|
|
||||||
prevHref = window.location.href;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.observer.observe(window.document.body, config);
|
this.observer.observe(window.document.body, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the page is /video/
|
// Returns true if the page is /video/
|
||||||
|
@ -56,6 +39,7 @@ class PIPController {
|
||||||
const type = "button";
|
const type = "button";
|
||||||
|
|
||||||
const pip = document.createElement(type);
|
const pip = document.createElement(type);
|
||||||
|
pip.id = "pip-btn";
|
||||||
pip.type = type;
|
pip.type = type;
|
||||||
pip.role = type;
|
pip.role = type;
|
||||||
pip.tabindex = "0";
|
pip.tabindex = "0";
|
||||||
|
@ -68,8 +52,17 @@ class PIPController {
|
||||||
return pip;
|
return pip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PIP element has been created and injected into the DOM
|
||||||
|
hasPipControls() {
|
||||||
|
return document.getElementById("pip-btn") ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
// Insert the PIP toggle button and enable PIP on the video element
|
// Insert the PIP toggle button and enable PIP on the video element
|
||||||
injectPipControls() {
|
injectPipControls() {
|
||||||
|
if (this.hasPipControls()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
this.element = document.getElementsByTagName("video")[0];
|
this.element = document.getElementsByTagName("video")[0];
|
||||||
|
|
||||||
if (!this.isPlayerPage() || !this.element) {
|
if (!this.isPlayerPage() || !this.element) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "Disney+ PIP",
|
"name": "Disney+ PIP",
|
||||||
"description": "Adds Picture-in-Picture (PIP) support for Disney+",
|
"description": "Adds Picture-in-Picture (PIP) support for Disney+",
|
||||||
"version": "1.0",
|
"version": "1.1",
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"activeTab"
|
"activeTab"
|
||||||
|
|
Loading…
Add table
Reference in a new issue