Correcting loading degredation issues from prior fixes

This commit is contained in:
2025-10-04 12:31:07 -05:00
parent 73eea44c7e
commit 5bcbf04917
3 changed files with 32 additions and 26 deletions

View File

@@ -12,8 +12,8 @@ Better YouTube + works to improve the YouTube experience by providing quick acce
* It shows volume level as you scroll. * It shows volume level as you scroll.
* It lets Unix, Linux, and MacOS systems have the ability to download the video using native app calls. * It lets Unix, Linux, and MacOS systems have the ability to download the video using native app calls.
# Version: 1.6.1 # Version: 1.6.4
* Fixing click dead zones; changesd dl icon. * Fixing the prior fix causing load degredation
# Download # Download
https://addons.mozilla.org/en-US/firefox/addon/better-youtube-plus/ https://addons.mozilla.org/en-US/firefox/addon/better-youtube-plus/

View File

@@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Better Youtube +", "name": "Better Youtube +",
"version": "1.6.3", "version": "1.6.4",
"description": "Enhancements for Youtube to have a better experience.", "description": "Enhancements for Youtube to have a better experience.",
"browser_specific_settings": { "browser_specific_settings": {
@@ -17,7 +17,7 @@
], ],
"content_scripts": [{ "content_scripts": [{
"matches": ["*://www.youtube.com/*"], "matches": ["https://www.youtube.com/watch=?v=*"],
"js": ["inject.js"], "js": ["inject.js"],
"run_at": "document_start", "run_at": "document_start",
"all_frames": true "all_frames": true

View File

@@ -68,34 +68,40 @@
let isEndlessWatch = false; let isEndlessWatch = false;
let shouldHideVol = true; let shouldHideVol = true;
let OSName = ""; let OSName = "";
let count = 0;
// confirm dialog elm // confirm dialog elm
const isYoutubeMusic = window.location.hostname === 'music.youtube.com'; let dialogElementQueryRef = 'yt-confirm-dialog-renderer';
let dialogElementQueryRef = isYoutubeMusic ? 'ytmusic-you-there-renderer' : 'yt-confirm-dialog-renderer';
// Options for the observer (which mutations to observe) // Options for the observer (which mutations to observe)
let observer, observer2; let fullscreenObserver, endlessPlayObserver;
const observerConfig = { attributes: true }; const observerConfig = { attributes: true };
const observerConfig2 = { childList: true, subtree: true }; const observerConfig2 = { childList: true, subtree: true };
// Start init // Start init
let existCondition = setInterval(function() { // YouTube is a SPA — watch for page changes
if (document.getElementById("masthead-container")) { const loadObserver = new MutationObserver(() => {
clearInterval(existCondition); checkPageLoad();
});
loadObserver.observe(document.body, { childList: true, subtree: true });
function isYouTubePageLoaded() {
const videoPlayer = document.querySelector('video');
const titleElement = document.querySelector('#title h1');
return videoPlayer && titleElement && titleElement.textContent.trim().length > 0;
}
function checkPageLoad() {
if (isYouTubePageLoaded()) {
console.log("YouTube page fully loaded.");
loadObserver.disconnect();
setupProcess(); setupProcess();
count = 0;
} else { } else {
if (count == 12) { // ~ 6 sec through half sec loops console.log("Waiting for YouTube content...");
count = 0;
clearInterval(existCondition);
setupProcess();
} else {
count++;
}
} }
}, 500); }
const setupProcess = () => { const setupProcess = () => {
loadUI(); loadUI();
@@ -210,18 +216,18 @@
// Observer target for fullscreen action... // Observer target for fullscreen action...
let targetNode = document.getElementsByTagName('ytd-app')[0]; let targetNode = document.getElementsByTagName('ytd-app')[0];
// Create an observer instance linked to the callback function // Create an observer instance linked to the callback function
observer = new MutationObserver(mutationCallback); fullscreenObserver = new MutationObserver(mutationCallback);
// Start observing the target node for configured mutations // Start observing the target node for configured mutations
observer.observe(targetNode, observerConfig); fullscreenObserver.observe(targetNode, observerConfig);
// ---- Endless play obsever ---- // ---- Endless play obsever ----
// Create an observer instance linked to the callback function // Create an observer instance linked to the callback function
observer2 = new MutationObserver(mutationCallback); endlessPlayObserver = new MutationObserver(mutationCallback);
// Start observing the target node for configured mutations // Start observing the target node for configured mutations
if (endlessPlayTag.checked == true) { if (endlessPlayTag.checked == true) {
this.isEndlessWatch = true; this.isEndlessWatch = true;
console.log("Endless play checked. Starting observer..."); console.log("Endless play checked. Starting observer...");
observer2.observe(document, observerConfig2); endlessPlayObserver.observe(document, observerConfig2);
} }
} }
@@ -273,12 +279,12 @@
endlessPlayTag.setAttribute("checked", false); endlessPlayTag.setAttribute("checked", false);
this.isEndlessWatch = false; this.isEndlessWatch = false;
console.log("Stopping endless play..."); console.log("Stopping endless play...");
observer2.disconnect(); endlessPlayObserver.disconnect();
} else { } else {
endlessPlayTag.setAttribute("checked", true); endlessPlayTag.setAttribute("checked", true);
this.isEndlessWatch = true; this.isEndlessWatch = true;
console.log("Starting endless play..."); console.log("Starting endless play...");
observer2.observe(confirmDialogElement, observerConfig2); endlessPlayObserver.observe(document, observerConfig2);
} }
} }