From 3bd28842e16c6c6622fcfe7dcc531615b585b410 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Mon, 26 Feb 2018 22:38:17 +0100 Subject: [PATCH] =?UTF-8?q?Tried=20my=20hand=20at=20fixing=20memory=20leak?= =?UTF-8?q?.=20ArDetect=20=E2=80=94=20no=20dice.=20Ghetto=20watcher=20for?= =?UTF-8?q?=20changes=20in=20player=20size=20now=20saves=20the=20HTML=20el?= =?UTF-8?q?ement=20that's=20deemed=20to=20be=20the=20player=20frame=20and?= =?UTF-8?q?=20uses=20said=20node=20for=20size=20tests=20in=20subsequent=20?= =?UTF-8?q?iterations=20(as=20opposed=20to=20searching=20for=20player=20no?= =?UTF-8?q?de=20on=20every=20frame).=20Also=20hopefully=20fixed=20the=20bu?= =?UTF-8?q?g=20with=20custom=20settings=20for=20individual=20sites=20not?= =?UTF-8?q?=20getting=20saved.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/conf/Debug.js | 2 +- js/conf/Settings.js | 1 + js/lib/PlayerDetect.js | 24 +++++++++++++++++------- js/modules/ArDetect.js | 8 +++++--- js/run/GlobalVars.js | 1 + js/uw.js | 34 +++++++++++++++------------------- 6 files changed, 40 insertions(+), 30 deletions(-) diff --git a/js/conf/Debug.js b/js/conf/Debug.js index 6cb96c2..154958e 100644 --- a/js/conf/Debug.js +++ b/js/conf/Debug.js @@ -10,7 +10,7 @@ Debug = { debugStorage: true, showArDetectCanvas: true, flushStoredSettings: false, - playerDetectDebug: false + playerDetectDebug: false, arDetect: { edgeDetect: true } diff --git a/js/conf/Settings.js b/js/conf/Settings.js index c66d3a7..7087b8e 100644 --- a/js/conf/Settings.js +++ b/js/conf/Settings.js @@ -26,6 +26,7 @@ var _se_init = async function(neverFlushStored){ else{ var actualSettings = JSON.parse(newSettings["uw-settings"]); if(actualSettings.version === undefined || actualSettings.version != uwVersion){ + this.version = uwVersion; console.log("[Settings::_se_init()] extension was updated, replacing settings"); StorageManager.setopt({"uw-settings": JSON.stringify(this)}); } diff --git a/js/lib/PlayerDetect.js b/js/lib/PlayerDetect.js index a451211..a503648 100644 --- a/js/lib/PlayerDetect.js +++ b/js/lib/PlayerDetect.js @@ -34,12 +34,7 @@ var _pd_isFullScreen = function(){ var _pd_getPlayerDimensions = function(element){ - if(_pd_isFullScreen()){ - return { - width: screen.width, - height: screen.height - }; - } + if(element == null){ if(Debug.debug) console.log("[PlayerDetect::_pd_getPlayerDimensions] element is not valid, doing nothing.", element) @@ -88,14 +83,29 @@ var _pd_getPlayerDimensions = function(element){ var dims = { width: candidate_width, - height: candidate_height + height: candidate_height, + element: playerCandidateNode }; return dims; } +// returns 'true' if there was a change. +var _pd_checkPlayerSizeChange = function(){ + if(GlobalVars.playerDimensions.element == undefined) + return true; + + if(GlobalVars.playerDimensions.width != GlobalVars.playerDimensions.element.offsetWidth || GlobalVars.playerDimensions.height != GlobalVars.playerDimensions.element.offsetHeight ){ + return true; + } + + return false; +} + + var PlayerDetect = { getPlayerDimensions: _pd_getPlayerDimensions, + checkPlayerSizeChange: _pd_checkPlayerSizeChange, isFullScreen: _pd_isFullScreen } diff --git a/js/modules/ArDetect.js b/js/modules/ArDetect.js index 347a551..06ce88c 100644 --- a/js/modules/ArDetect.js +++ b/js/modules/ArDetect.js @@ -21,6 +21,8 @@ var _ard_canvasWidth; var _ard_canvasHeight; var _ard_canvasDrawWindowHOffset = 0; +var localSettings = {}; + // **** FUNCTIONS **** // var _arSetup = function(cwidth, cheight){ @@ -324,8 +326,8 @@ var _ard_vdraw = function (vid, context, w, h, conf){ if(currentMaxVal < GlobalVars.arDetect.blackLevel){ GlobalVars.arDetect.blackLevel = currentMaxVal; } - } + cols = null; if(!isLetter){ // Če ne zaznamo letterboxa, kličemo reset. Lahko, da je bilo razmerje stranic popravljeno na roke. Možno je tudi, @@ -646,7 +648,7 @@ function _ard_edgeDetect(context, samples){ blackEdgeViolation = true; if(Debug.debug && Debug.debugArDetect && Debug.arDetect.edgeDetect) - console.log(("[ArDetect::_ard_edgeDetect] detected black edge violation at i="+i+"; sample.top="+sample.top + "\n--"), imageData, context.getImageData(sampleStart, sample.top - 2, sampleWidth, 1)); + console.log(("[ArDetect::_ard_edgeDetect] detected black edge violation at i="+i+"; sample.top="+sample.top + "\n--")/*, imageData, context.getImageData(sampleStart, sample.top - 2, sampleWidth, 1)*/); break; } @@ -689,7 +691,7 @@ function _ard_edgeDetect(context, samples){ imageData[i+1] > blackbarTreshold || imageData[i+2] > blackbarTreshold ){ blackEdgeViolation = true; - console.log(("[ArDetect::_ard_edgeDetect] detected black edge violation at i="+i+"; sample.top="+sample.top + "\n--"), imageData, context.getImageData(sampleStart, sample.top - 2, sampleWidth, 1)); + console.log(("[ArDetect::_ard_edgeDetect] detected black edge violation at i="+i+"; sample.top="+sample.top + "\n--")/*, imageData, context.getImageData(sampleStart, sample.top - 2, sampleWidth, 1)*/); break; } diff --git a/js/run/GlobalVars.js b/js/run/GlobalVars.js index c4b2898..c7cf5bf 100644 --- a/js/run/GlobalVars.js +++ b/js/run/GlobalVars.js @@ -2,6 +2,7 @@ var GlobalVars = { video: null, player: null, playerDimensions: null, + playerElement: null, lastAr: null, lastUrl: "", currentCss: { diff --git a/js/uw.js b/js/uw.js index c9570e1..aa49024 100644 --- a/js/uw.js +++ b/js/uw.js @@ -13,12 +13,6 @@ if(Debug.debug){ } -// global-ish - -var _main_last_fullscreen; - -var _player_dimensions_last; - // load all settings from localStorage: async function main(){ @@ -115,24 +109,26 @@ function ghettoOnChange(){ if(GlobalVars.video === null) return; - if(_player_dimensions_last === undefined){ - _player_dimensions_last = PlayerDetect.getPlayerDimensions( GlobalVars.video ); + if(GlobalVars.playerDimensions == null){ + GlobalVars.playerDimensions = PlayerDetect.getPlayerDimensions( GlobalVars.video ); + + + if(GlobalVars.playerDimensions == undefined){ + GlobalVars.playerDimensions = null; + return; + } } - var newPlayerDims = PlayerDetect.getPlayerDimensions( GlobalVars.video ); - - if (newPlayerDims == undefined) - return; - - GlobalVars.playerDimensions = newPlayerDims; - - if ( newPlayerDims.width != _player_dimensions_last.width || - newPlayerDims.height != _player_dimensions_last.height){ + if(PlayerDetect.checkPlayerSizeChange()){ + GlobalVars.playerDimensions = PlayerDetect.getPlayerDimensions( GlobalVars.video ); + + if(GlobalVars.playerDimensions == undefined){ + GlobalVars.playerDimensions = null; + return; + } Resizer.restore(); } - - _player_dimensions_last = newPlayerDims; }