From 64e28e8074212fa8bae9bd0a01034bcf041e0a7b Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sun, 22 Apr 2018 14:35:40 +0200 Subject: [PATCH] Another attempt at fixing the youtube search popup. --- .vscode/launch.json | 14 ++++++++++++++ js/lib/PlayerDetect.js | 4 ++-- js/modules/ArDetect.js | 11 ++++++++++- js/modules/Resizer.js | 21 ++++++++++++++++++--- js/uw.js | 12 ++++++------ 5 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..a053d23 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${file}" + } + ] +} \ No newline at end of file diff --git a/js/lib/PlayerDetect.js b/js/lib/PlayerDetect.js index fbc951d..beb9637 100644 --- a/js/lib/PlayerDetect.js +++ b/js/lib/PlayerDetect.js @@ -127,7 +127,7 @@ var _pd_getPlayerDimensions = function(startElement, elementNames){ // returns 'true' if there was a change. var _pd_checkPlayerSizeChange = function(){ - console.log("Player:", GlobalVars.playerDimensions, "Node:", GlobalVars.playerDimensions.element) + // console.log("Player:", GlobalVars.playerDimensions, "Node:", GlobalVars.playerDimensions.element) if(Debug.debug){ if(GlobalVars.playerDimensions.element == undefined) @@ -140,7 +140,7 @@ var _pd_checkPlayerSizeChange = function(){ } if(GlobalVars.playerDimensions.width != GlobalVars.playerDimensions.element.offsetWidth || GlobalVars.playerDimensions.height != GlobalVars.playerDimensions.element.offsetHeight ){ - console.log("[PlayerDetect] player size changed. reason: dimension change"); + console.log("[PlayerDetect] player size changed. reason: dimension change. Old dimensions?", GlobalVars.playerDimensions.width, GlobalVars.playerDimensions.height, "new dimensions:", GlobalVars.playerDimensions.element.offsetWidth, GlobalVars.playerDimensions.element.offsetHeight); } } diff --git a/js/modules/ArDetect.js b/js/modules/ArDetect.js index 7bd581c..8eab60b 100644 --- a/js/modules/ArDetect.js +++ b/js/modules/ArDetect.js @@ -53,7 +53,7 @@ var _arSetup = function(cwidth, cheight){ var vid = document.getElementsByTagName("video")[0]; - if(vid === undefined){ + if(vid === undefined || vid === null){ _ard_setup_timer = setTimeout(_arSetup, 1000); return; } @@ -294,6 +294,15 @@ var _ard_vdraw_but_for_reals = function() { if(this._forcehalt) return; + + if(! GlobalVars.video){ + if(Debug.debug || Debug.warnings_critical) + console.log("[ArDetect::_ard_vdraw] Video went missing. Stopping current instance of automatic detection and trying to start a new one.") + _ard_stop(); + this._forcehalt = true; + _arSetup(); + return; + } var fallbackMode = false; var startTime = performance.now(); diff --git a/js/modules/Resizer.js b/js/modules/Resizer.js index 2dae419..686293d 100644 --- a/js/modules/Resizer.js +++ b/js/modules/Resizer.js @@ -47,11 +47,11 @@ var _res_char = function(newAr, video, player){ // Skrbi za "stare" možnosti, kot na primer "na širino zaslona", "na višino zaslona" in "ponastavi". // Približevanje opuščeno. // handles "legacy" options, such as 'fit to widht', 'fit to height' and 'reset'. No zoom tho -var _res_legacyAr = function(action){ +var _res_legacyAr = function(action){ var vid = GlobalVars.video; var ar; - if(GlobalVars.playerDimensions === null || GlobalVars.playerDimensions === undefined){ + if(! GlobalVars.playerDimensions ){ ar = screen.width / screen.height; } else{ @@ -98,7 +98,7 @@ var _res_setAr = function(ar){ if(vid == null || vid==undefined || vid.videoWidth == 0 || vid.videoHeight == 0){ if(Debug.debug) - console.log("[Resizer::_res_setAr] I lied. Tricked you! You thought there is a video, didn't you? Never would be.", vid); // of course that's thorin reference -> https://youtu.be/OY5gGkeQn1c?t=1m20s + console.log("[Resizer::_res_setAr] I lied. Tricked you! You thought there's gonna be a video, didn't you? Never would be.", vid); // of course that's thorin reference -> https://youtu.be/OY5gGkeQn1c?t=1m20s return; } } @@ -209,6 +209,12 @@ var _res_setStyleString = function(vid, styleString, count){ if(_res_restore_wd){ var vid2 = GlobalVars.video; + + if(vid2 == undefined || vid2 == null){ + if(Debug.debug) + console.log("[Resizer::_res_setStyleString] Video element went missing, nothing to do here.") + return; + } if( styleString.indexOf("width: " + vid2.style.width) == -1 || @@ -236,6 +242,12 @@ var _res_setStyleString = function(vid, styleString, count){ } function _res_applyCss(dimensions){ + + if(GlobalVars.video == undefined || GlobalVars.video == null){ + if(Debug.debug) + console.log("[Resizer::_res_applyCss] Video went missing, doing nothing."); + return; + } if(Debug.debug) console.log("[Resizer::_res_applyCss] Starting to apply css. this is what we're getting in:", dimensions); @@ -323,6 +335,9 @@ var _res_antiCssOverride = function(){ if(GlobalVars.currentCss.top === null) return; + // this means video went missing. + if(GlobalVars.video == undefined || GlobalVars.video == null) + return; var styleArrayStr = GlobalVars.video.getAttribute('style'); diff --git a/js/uw.js b/js/uw.js index 1f18126..a30d7e8 100644 --- a/js/uw.js +++ b/js/uw.js @@ -47,12 +47,12 @@ async function main(){ return; } -// if(SitesConf.isArEnabled(window.location.hostname)){ -// if(Debug.debug) -// console.log("[uw::main] Aspect ratio detection is enabled. Starting ArDetect"); -// ArDetect.arSetup(); -// } -// console.log("[uw::main] ExtensionConf:", ExtensionConf); + // if(SitesConf.isArEnabled(window.location.hostname)){ + // if(Debug.debug) + // console.log("[uw::main] Aspect ratio detection is enabled. Starting ArDetect"); + // ArDetect.arSetup(); + // } + // console.log("[uw::main] ExtensionConf:", ExtensionConf); if(ExtensionConf.arDetect.mode == "blacklist"){ if(Debug.debug)