From 2fb39ce6ac67c31be927e20777f8309e218f9209 Mon Sep 17 00:00:00 2001 From: Maxim Stewart Date: Sat, 16 May 2020 01:19:12 -0500 Subject: [PATCH] touchup on observer logic --- README.md | 7 ++----- src/manifest.json | 2 +- src/scripts/betterYoutube.js | 33 ++++++++++++++++++++++----------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 58ede39..35d2975 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,8 @@ Better YouTube + works to improve the YouTube experience by providing quick acce * 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. -# Version: 1.5.0 -* Refactored code. -* Resolved volume change not always sticking on Linux. (I think fixed...) -* Added a quick volume indicator when scrolling. -* Added NonStop watch mode. +# Version: 1.5.1 +* Fixed observer logic. # Download https://addons.mozilla.org/en-US/firefox/addon/better-youtube-plus/ diff --git a/src/manifest.json b/src/manifest.json index 855172b..1e0cc74 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Better Youtube +", - "version": "1.5.0", + "version": "1.5.1", "description": "Enhancements for Youtube to have a better experience.", "applications": { diff --git a/src/scripts/betterYoutube.js b/src/scripts/betterYoutube.js index f231316..ca96889 100644 --- a/src/scripts/betterYoutube.js +++ b/src/scripts/betterYoutube.js @@ -45,10 +45,13 @@ let videoTimeLength, videoTimeCurent, ytRangeStart, ytRangeEnd, slugInputTag, endlessPlayTag, ytVideoIntervalLoop; let poppedContainer, videoSlug, volumeLbl, part; - let loopingInterval = false; - let shouldHideVol = true; - let OSName = ""; - let count = 0; + let modalHasBeenClosed = false; + let loopingInterval = false; + // Default to false b/c if tag checked it sets this in setupProc and elsewhere. + let isEndlessWatch = false; + let shouldHideVol = true; + let OSName = ""; + let count = 0; // confirm dialog elm const isYoutubeMusic = window.location.hostname === 'music.youtube.com'; @@ -63,13 +66,13 @@ const preSetupProc = () => { // Look to add saving image from video elm. // path = "/html/body/ytd-app/div/ytd-page-manager/ytd-watch-flexy/div[4]/div[1]/div/div[1]/div/div/div/ytd-player/div/div/div[1]/video" - // elm = document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; + // elm = document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if (navigator.appVersion.indexOf("Win")!=-1) OSName = "Windows"; if (navigator.appVersion.indexOf("Mac")!=-1) OSName = "MacOS"; if (navigator.appVersion.indexOf("X11")!=-1) OSName = "UNIX"; if (navigator.appVersion.indexOf("Linux")!=-1) OSName = "Linux"; - // check if we've loaded elements already... + // Check if we've loaded elements already... if (!document.getElementById("slugCopyZone")) { document.body.insertAdjacentHTML( 'beforeend', slugTemplate ); document.body.insertAdjacentHTML( 'beforeend', menuTemplate ); @@ -161,6 +164,7 @@ // Start observing the target node for configured mutations if (endlessPlayTag.checked == true) { endlessPlayTag.setAttribute("checked", true); + isEndlessWatch = true; console.log("Endless play checked. Starting observer..."); observer2.observe(document, observerConfig2); } @@ -173,10 +177,16 @@ if (mutation.type === 'attributes') { controlManager(mutation.target); } else if (mutation.type === 'childList') { - let elm = document.querySelector(dialogElementQueryRef).parentElement; - elmDisplayState = elm.style.display; - if (elmDisplayState !== 'none') { - clickDialog(); + if (isEndlessWatch) { + let elm = document.querySelector(dialogElementQueryRef).parentElement; + elmDisplayState = elm.style.display; + if (elmDisplayState !== 'none' && !modalHasBeenClosed) { + clickDialog(); + modalHasBeenClosed = true; + setTimeout(function () { + modalHasBeenClosed = false; + }, 5000); + } } } } @@ -205,14 +215,15 @@ isChecked = endlessPlayTag.getAttribute("checked"); if (isChecked) { endlessPlayTag.setAttribute("checked", false); + isEndlessWatch = false; console.log("Stopping endless play..."); observer2.disconnect(); } else { endlessPlayTag.setAttribute("checked", true); + isEndlessWatch = true; console.log("Starting endless play..."); observer2.observe(confirmDialogElement, observerConfig2); } - console.log(observer2); } const showThumbImageVew = (e) => {