diff --git a/src/ext/lib/video-data/VideoData.js b/src/ext/lib/video-data/VideoData.js index 3f7b34c..adf3bfb 100644 --- a/src/ext/lib/video-data/VideoData.js +++ b/src/ext/lib/video-data/VideoData.js @@ -16,6 +16,16 @@ class VideoData { this.vdid = (Math.random()*100).toFixed(); this.userCssClassName = `uw-fuck-you-and-do-what-i-tell-you_${this.vdid}`; + + // We'll replace cssWatcher (in resizer) with mutationObserver + const observerConf = { + attributes: true, + // attributeFilter: ['style', 'class'], + attributeOldValue: true, + }; + this.observer = new MutationObserver(this.onVideoDimensionsChanged); + this.observer.observe(video, observerConf); + // POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji) // NOTE: ORDERING OF OBJ INITIALIZATIONS IS IMPORTANT (arDetect needs to go last) this.player = new PlayerData(this); @@ -38,7 +48,32 @@ class VideoData { this.pageInfo.initMouseActionHandler(this); - this.video.classList.add(this.userCssClassName); + this.video.classList.add(this.userCssClassName); // this also needs to be applied BEFORE we initialize resizer! + } + + onVideoDimensionsChanged(mutationList, observer) { + for (let mutation of mutationList) { + if (mutation.type === 'attributes') { + console.log("video attributes were changed:", mutation) + if (mutation.attributeName === 'class') { + if (!this.video.classList.contains(this.userCssClassName)) { + console.log("class changed!") + // force the page to include our class in classlist, if the classlist has been removed + this.video.classList.add(this.userCssClassName); + + // } else if () { + // this bug should really get + } else { + this.restoreAr(); + } + } else if (mutation.attributeName === 'style' && mutation.attributeOldValue !== this.video.getAttribute('style')) { + console.log("style changed") + // if size of the video has changed, this may mean we need to recalculate/reapply + // last calculated aspect ratio + this.restoreAr(); + } + } + } } firstTimeArdInit(){ diff --git a/src/ext/lib/video-transform/Resizer.js b/src/ext/lib/video-transform/Resizer.js index 5fb32a6..3681d85 100644 --- a/src/ext/lib/video-transform/Resizer.js +++ b/src/ext/lib/video-transform/Resizer.js @@ -24,8 +24,6 @@ class Resizer { this.stretcher = new Stretcher(this.conf); this.zoom = new Zoom(this.conf); - this.cssCheckDisabled = false; - // load up default values this.correctedVideoDimensions = {}; this.currentCss = {}; @@ -33,16 +31,6 @@ class Resizer { this.currentPlayerStyleString = ""; this.currentCssValidFor = {}; - // restore watchdog. While true, applyCss() tries to re-apply new css until this value becomes false again - // value becomes false when width and height of