Merged FullScreenDetect into PlayerDetect. Youtube: switching between theater mode, full screen and normal mode works properly. Vimeo still broken.

This commit is contained in:
Tamius Han 2018-01-18 22:34:42 +01:00
parent 9265a336bc
commit 3b3430ddce
7 changed files with 102 additions and 129 deletions

View File

@ -37,7 +37,7 @@ var _kbd_process = function (event) { // Tukaj ugotovimo, katero tipko
// Tipke upoštevamo samo, če smo v celozaslonskem načinu oz. če ne pišemo komentarja
// v nasprotnem primeru ne naredimo nič.
// We only take actions if we're in full screen or not writing a comment
if( !(FullScreenDetect.isFullScreen() || (
if( !(PlayerDetect.isFullScreen() || (
(document.activeElement.getAttribute("role") != "textbox") &&
(document.activeElement.getAttribute("type") != "text")
))){

View File

@ -1,10 +0,0 @@
if(Debug.debug)
console.log("Loading: FullScreenDetect.js");
var _fsd_isFullScreen = function(){
return ( window.innerHeight == window.screen.height && window.innerWidth == window.screen.width);
}
var FullScreenDetect = {
isFullScreen: _fsd_isFullScreen
}

View File

@ -1,3 +1,10 @@
if(Debug.debug)
console.log("Loading: FullScreenDetect.js");
var _pd_isFullScreen = function(){
return ( window.innerHeight == window.screen.height && window.innerWidth == window.screen.width);
}
/* sprejme <video> tag (element
// vrne dimenzije predvajalnika (širina, višina)
@ -22,9 +29,12 @@
// root should be the player.
*/
var _pd_getPlayerDimensions = function(element){
if(FullScreenDetect.isFullScreen()){
if(_pd_isFullScreen()){
if(Debug.debug){
console.log("[PlayerDetect::_pd_getPlayerDimensions] video is full screen, returning player dimensions!");
}
@ -48,7 +58,7 @@ var _pd_getPlayerDimensions = function(element){
// <video> can't be root in a document, so we can do this
element = element.parentNode;
while(element.parentNode){
while(element != undefined){
// odstranimo čudne elemente, ti bi pokvarili zadeve
// remove weird elements, those would break our stuff
if ( element.offsetWidth == 0 || element.offsetHeight == 0){
@ -62,21 +72,24 @@ var _pd_getPlayerDimensions = function(element){
candidate_width = element.offsetWidth;
candidate_height = element.offsetHeight;
if(Debug.debug){
console.log("Found new candidate for player. Dimensions: w:", candidate_width, "h:",candidate_height);
}
// if(Debug.debug){
// console.log("Found new candidate for player. Dimensions: w:", candidate_width, "h:",candidate_height);
// }
}
element = element.parentNode;
}
return {
width: playerCandidateNode.offsetWidth,
height: playerCandidateNode.offsetHeight
var dims = {
width: candidate_width,
height: candidate_height
};
return dims;
}
var PlayerDetect = {
getPlayerDimensions: _pd_getPlayerDimensions
getPlayerDimensions: _pd_getPlayerDimensions,
isFullScreen: _pd_isFullScreen
}

View File

@ -202,12 +202,12 @@ var _ard_processAr = function(video, width, height, edge_h, edge_w, fallbackMode
}
// če je sprememba več od dovoljenega, spremeni razmerje stranic. Stvari se razlikujejo glede na to, ali smo v fullscreen ali ne
// if change is greater than allowed, change the aspect ratio. Whether we do that depends on whether we're in fullscreen.
// if( FullScreenDetect.isFullScreen() ){
// if( PlayerDetect.isFullScreen() ){
if(Debug.debug)
console.log("[ArDetect::_ard_processAr] attempting to fix aspect ratio. New aspect ratio: ", trueAr);
_ard_oldAr = trueAr;
Resizer.setAr_fs(trueAr);
Resizer.setAr(trueAr);
// }
// else{
// // če nismo v fullscreen, potem preverimo, ali naša stran dovoljuje ne-fs?

View File

@ -203,21 +203,15 @@ var _res_legacyAr = function(action){
}
}
var _res_setAr_kbd = function(ar){
// if(FullScreenDetect.isFullScreen()){
// if(Debug.debug)
// console.log("[Resizer::_res_setAr_kbd] We're in full screen. Setting ar to ", ar);
//
_res_setAr(ar);
// }
// else
// _res_setAr_nonfs(ar);
// TODO: check if site supports non-fs ar
}
var _res_setAr = function(ar, playerDimensions){
if(Debug.debug)
console.log("[Resizer::_res_setAr] trying to set ar. args are: ar->",ar,"; playerDimensions->",playerDimensions);
this._currentAr = ar;
var vid = $("video")[0];
// Dejansko razmerje stranic datoteke/<video> značke
// Actual aspect ratio of the file/<video> tag
var fileAr = vid.videoWidth / vid.videoHeight;
@ -225,9 +219,6 @@ var _res_setAr = function(ar, playerDimensions){
if(ar == "default")
ar = fileAr;
// Zabavno dejstvo: ta funkcija se kliče samo v fullscreen. Za ne-fs verzijo bo posebna funkcija, ker bo včasih verjetno treba
// spremeniti velikost predvajalnika
//
if(Debug.debug)
console.log("[Resizer::_res_setAr] ar is " ,ar, ", playerDimensions are ", playerDimensions);
@ -292,22 +283,6 @@ var _res_computeOffsets = function(vidDim, playerDim){
return offsets;
}
var _res_setAr_nonfs = function(ar){
var player = SitesConf.getPlayerTag();
SitesConf.prepareNonfsPlayer();
if(! player)
player = $("video")[0].parentNode;
var playerDimensions = {
width: player.offsetWidth,
height: player.offsetHeight
}
_res_setAr(ar, playerDimensions);
}
var _res_align = function(float){
if(! float)
float = Settings.miscFullscreenSettings.videoFloat;
@ -456,11 +431,6 @@ function _res_applyCss(dimensions){
}
var _res_setFsAr = function(ar){
this._currentAr = ar;
}
var _res_restore = function(){
if(Debug.debug){
console.log("[Resizer::_res_restore] attempting to restore aspect ratio. this & settings:", {'this': this, "settings": Settings} );
@ -470,7 +440,7 @@ var _res_restore = function(){
_res_restore_wd = true;
if(this._currentAr > 0)
_res_setAr_kbd(this._currentAr);
_res_setAr(this._currentAr);
// else
// _res_setAr_kbd("default");
}
@ -478,11 +448,8 @@ var _res_restore = function(){
var Resizer = {
_currentAr: -1,
align: _res_align,
setAr: _res_setAr_kbd,
setAr_fs: _res_setAr,
setAr_nonfs: _res_setAr_nonfs,
setAr: _res_setAr,
legacyAr: _res_legacyAr,
reset: _res_reset,
restore: _res_restore,
setFsAr: _res_setFsAr
restore: _res_restore
}

132
js/uw.js
View File

@ -4,6 +4,8 @@ if(Debug.debug)
// global-ish
var _main_last_fullscreen;
var _player_dimensions_last;
// load all settings from localStorage:
async function main(){
@ -64,77 +66,79 @@ async function main(){
console.log("[uw::main] Aspect ratio detection is disabled. This is in settings:", Settings.arDetect.enabled);
}
// preden karkoli delamo, se pozanimamo, ali smo v celozaslonskem načinu.
// ne bi smeli biti, načeloma
// je možnost, da smo i guess?
//
// before we add this event, determine initial fullscreen state.
// we shouldn't be
// there's a chance that we are tho, I guess
_main_last_fullscreen = FullScreenDetect.isFullScreen();
// Poslušamo za lovljenje spremembe iz navadnega načina v celozaslonski način in obratno.
// Listen for and handle changes to and from full screen.
$(document).bind('webkitfullscreenchange mozfullscreenchange fullscreenchange MSFullscreenChange', function(){
if(Debug.debug){
console.log("%c[uw::onfullscreenchange] are we in full screen?","color: #aaf", FullScreenDetect.isFullScreen());
}
// fullScreenCheck(0);
});
browser.runtime.onMessage.addListener(receiveMessage);
setInterval( ghettoOnChange, 33);
}
// tukaj gledamo, ali se je velikost predvajalnika spremenila. Če se je, ponovno prožimo resizer
// here we check (in the most ghetto way) whether player size has changed. If it has, we retrigger resizer.
function ghettoOnChange(){
if(_player_dimensions_last === undefined){
_player_dimensions_last = PlayerDetect.getPlayerDimensions($("video")[0]);
}
var newPlayerDims = PlayerDetect.getPlayerDimensions($("video")[0]);
if ( newPlayerDims.width != _player_dimensions_last.width ||
newPlayerDims.height != _player_dimensions_last.height){
Resizer.restore();
}
_player_dimensions_last = newPlayerDims;
}
var _main_fscheck_tries = 3;
function fullScreenCheck(count) {
if(count >= _main_fscheck_tries){
if(Debug.debug){
console.log("[uw::fullScreenCheck] ok really, I guess.");
}
return;
}
var fsnow = FullScreenDetect.isFullScreen();
// we restore, always — esp. now that we also do things in non-fullscreen
// if(fsnow){
// full screen is on
// Resizer.restore();
// function fullScreenCheck(count) {
// if(count >= _main_fscheck_tries){
// if(Debug.debug){
// console.log("[uw::fullScreenCheck] ok really, I guess.");
// }
// return;
// }
//
// var fsnow = FullScreenDetect.isFullScreen();
//
// // we restore, always — esp. now that we also do things in non-fullscreen
//
// // if(fsnow){
// // full screen is on
// // Resizer.restore();
// // }
// // else{
// // Resizer.reset();
// // }
//
// // kaj pa, če je FullScreenDetect vrnil narobno vrednost?
// // what if FullScreenDetect was not right? Let's verify; if it was wrong we re-trigger it in about 100 ms.
//
// if(fsnow != _main_last_fullscreen){
//
// // posodobimo vrednost / update value
// _main_last_fullscreen = fsnow;
//
// // če je to res, count pa je večji kot 0, potem smo imeli prav.
// // if that's the case and count is greater than 0, then we were right at some point.
// if(Debug.debug && count > 0){
// console.log("[uw::fullScreenCheck] fucking knew it")
// }
// return;
// }
// else{
// Resizer.reset();
// // dobili smo event za spremembo celozaslonskega stanja. Stanje se ni spremenilo. Hmmm.
// // we got an event for fullscreen state change. State is unchanged. Hmmm.
// if(Debug.debug){
// console.log("[uw::fullScreenCheck] oh _really_? 🤔🤔🤔 -- fullscreen state", FullScreenDetect.isFullScreen());
// }
// count++;
// setTimeout(fullScreenCheck, 200, count);
// }
// kaj pa, če je FullScreenDetect vrnil narobno vrednost?
// what if FullScreenDetect was not right? Let's verify; if it was wrong we re-trigger it in about 100 ms.
if(fsnow != _main_last_fullscreen){
// posodobimo vrednost / update value
_main_last_fullscreen = fsnow;
// če je to res, count pa je večji kot 0, potem smo imeli prav.
// if that's the case and count is greater than 0, then we were right at some point.
if(Debug.debug && count > 0){
console.log("[uw::fullScreenCheck] fucking knew it")
}
return;
}
else{
// dobili smo event za spremembo celozaslonskega stanja. Stanje se ni spremenilo. Hmmm.
// we got an event for fullscreen state change. State is unchanged. Hmmm.
if(Debug.debug){
console.log("[uw::fullScreenCheck] oh _really_? 🤔🤔🤔 -- fullscreen state", FullScreenDetect.isFullScreen());
}
count++;
setTimeout(fullScreenCheck, 200, count);
}
console.log("-------------------------------");
}
// console.log("-------------------------------");
// }
// comms
function receiveMessage(message, sender, sendResponse) {
@ -186,7 +190,7 @@ function receiveMessage(message, sender, sendResponse) {
ArDetect.stop();
// we aren't in full screen, but we will want aspect ratio to be fixed when we go to
Resizer.setFsAr(message.newAr);
Resizer.setAr(message.newAr);
}
}
else if(message.cmd == "force-video-float"){

View File

@ -26,7 +26,6 @@
"js/conf/Status.js",
"js/conf/ExtensionConf.js",
"js/lib/FullScreenDetect.js",
"js/lib/PlayerDetect.js",
"js/modules/PageInfo.js",