Tried my hand at fixing memory leak. ArDetect — no dice. Ghetto watcher for changes in player size now saves the HTML element that's deemed to be the player frame and uses said node for size tests in subsequent iterations (as opposed to searching for player node on every frame). Also hopefully fixed the bug with custom settings for individual sites not

getting saved.
This commit is contained in:
Tamius Han 2018-02-26 22:38:17 +01:00
parent 7b5453ec03
commit 3bd28842e1
6 changed files with 40 additions and 30 deletions

View File

@ -10,7 +10,7 @@ Debug = {
debugStorage: true,
showArDetectCanvas: true,
flushStoredSettings: false,
playerDetectDebug: false
playerDetectDebug: false,
arDetect: {
edgeDetect: true
}

View File

@ -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)});
}

View File

@ -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
}

View File

@ -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;
}

View File

@ -2,6 +2,7 @@ var GlobalVars = {
video: null,
player: null,
playerDimensions: null,
playerElement: null,
lastAr: null,
lastUrl: "",
currentCss: {

View File

@ -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;
}