Mutation observer added plus cs cleanup

This commit is contained in:
Maxim Stewart 2019-11-17 22:59:05 -06:00
parent d2509adf68
commit faed6edee5
3 changed files with 33 additions and 12 deletions

View File

@ -9,8 +9,9 @@ Better YouTube + works to improve the YouTube experience by providing quick acce
* It allows for quick access to the YouTube video slug. * It allows for quick access to the YouTube video slug.
* It lets Unix, Linux, and MacOS systems the ability to download the video using native app calls. * It lets Unix, Linux, and MacOS systems the ability to download the video using native app calls.
# Version: 1.4.0 # Version: 1.4.3
Updating for Firefox AMO * Added mutation observation for (un)fullscreen action.
* Cleaned up some log cruft and fixed CSS...
# 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

@ -13,6 +13,10 @@
let count = 0; let count = 0;
let OSName = ""; let OSName = "";
// Options for the observer (which mutations to observe)
const config = { attributes: true };
const preSetupProc = () => { const preSetupProc = () => {
if (navigator.appVersion.indexOf("Win")!=-1) OSName = "Windows"; if (navigator.appVersion.indexOf("Win")!=-1) OSName = "Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName = "MacOS"; if (navigator.appVersion.indexOf("Mac")!=-1) OSName = "MacOS";
@ -117,7 +121,14 @@
ytFloatBttn.addEventListener("click", toggleFloat); ytFloatBttn.addEventListener("click", toggleFloat);
ytDownloadBttn.addEventListener("click", downloadVideo); ytDownloadBttn.addEventListener("click", downloadVideo);
video.addEventListener("wheel", manageVolume); video.addEventListener("wheel", manageVolume);
video.addEventListener("dblclick", controlManager);
// Observer target for fullscreen action...
targetNode = document.getElementsByTagName('ytd-app')[0];
// Create an observer instance linked to the callback function
const observer = new MutationObserver(mutationcallback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
// Dragable window for floating video // Dragable window for floating video
dragVideo(poppedContainer); dragVideo(poppedContainer);
@ -161,16 +172,24 @@
} }
// Functions // Functions
const controlManager = () => { // Callback function to execute when mutations are observed
setTimeout(function () { const mutationcallback = (mutationsList, observer) => {
if (window.innerHeight !== screen.height) { for(let mutation of mutationsList) {
ytEnhancerMenu.style.display = "block"; if (mutation.type === 'attributes') {
slugInputTag.style.display = "block"; controlManager(mutation.target);
} else {
ytEnhancerMenu.style.display = "none";
slugInputTag.style.display = "none";
} }
}, 200); }
};
const controlManager = (elm) => {
attrib = elm.getAttribute('masthead-hidden_');
if (attrib == null) { // if out of fullscreen
ytEnhancerMenu.style.display = "block";
slugInputTag.style.display = "block";
} else { // if fullscreen
ytEnhancerMenu.style.display = "none";
slugInputTag.style.display = "none";
}
} }
const downloadVideo = () => { const downloadVideo = () => {

View File

@ -11,6 +11,7 @@
left: 35%; left: 35%;
width: 10em; width: 10em;
text-align: center; text-align: center;
color: #fff;
} }
#enhancerMenuIDRef, #slugCopyZone { #enhancerMenuIDRef, #slugCopyZone {