More refactoring. Submenus still don't work for some reason.

This commit is contained in:
Tamius Han 2017-03-23 13:20:59 +01:00
parent 0d943df844
commit c20bac3b5f

101
js/uw.js
View File

@ -248,14 +248,14 @@ var UW_SITES = {
buttonSizeBase: "x", buttonSizeBase: "x",
}, },
uiParent: { uiParent: {
name: "placeholder", name: "player-controls-wrapper",
isClass: true, isClass: true,
insertStrat: "append" insertStrat: "append"
}, },
autoar_imdb:{ autoar_imdb:{
enabled: true, enabled: true,
title: "dummy please replace", title: "player-status-main-title",
isClass: false isClass: true
} }
}, },
dummy: { dummy: {
@ -609,6 +609,9 @@ function extsetup_comms(){
//BEGIN periodic functions //BEGIN periodic functions
//Because onUpdated event isn't reliable enough for what we're doing on netflix. //Because onUpdated event isn't reliable enough for what we're doing on netflix.
function periodic() { function periodic() {
//NOTE: this entire function needs to be tested if it still works
if(debugmsg_periodic) if(debugmsg_periodic)
console.log("uw::periodic started!"); console.log("uw::periodic started!");
@ -623,7 +626,9 @@ function periodic() {
var w = window.innerWidth; var w = window.innerWidth;
var h = window.innerHeight; var h = window.innerHeight;
if(winsize.w != w && winsize.h != h){ if(winsize.w != w && winsize.h != h){
console.log("uw::periodic | detected change in window size. Triggering css change"); if(debugmsg)
console.log("uw::periodic | detected change in window size. Triggering css change");
winsize.w = w; winsize.w = w;
winsize.h = h; winsize.h = h;
@ -631,41 +636,49 @@ function periodic() {
if(last_whatdo.what_do != "zoom" && last_whatdo.what_do != "unzoom"/* && last_whatdo.type != "autoar"*/){ if(last_whatdo.what_do != "zoom" && last_whatdo.what_do != "unzoom"/* && last_whatdo.type != "autoar"*/){
changeCSS(last_whatdo.type, last_whatdo.what_do); changeCSS(last_whatdo.type, last_whatdo.what_do);
} }
updateUICSS(); updateUICSS();
} }
var controls = document.getElementsByClassName("player-controls-wrapper")[0]; if(SITE_PROPS.uiParent.isClass)
var controls = document.getElementsByClassName(SITE_PROPS.uiParent.name)[0];
else
var controls = document.getElementById(SITE_PROPS.uiParent.name);
if(controls){ if(controls){
if(debugmsg_periodic) if(debugmsg_periodic)
console.log("uw::periodic | we found controls!"); console.log("uw::periodic | we found controls!");
var ind = controls.className.indexOf("display-none"); // var ind = controls.className.indexOf("display-none");
if(debugmsg_periodic) // if(debugmsg_periodic)
console.log("uw::periodic | ind:",ind,"last ind:",netflix_cltbar_visibility); // console.log("uw::periodic | ind:",ind,"last ind:",netflix_cltbar_visibility);
// controls must be visible. We must have not called updateCtlButtonSize before. // controls must be visible. We must have not called updateCtlButtonSize before.
if( ind != netflix_cltbar_visibility ){ // if( ind != netflix_cltbar_visibility ){
if(debugmsg) // if(debugmsg)
console.log("uw::periodic | toggled visibility"); // console.log("uw::periodic | toggled visibility");
netflix_cltbar_visibility = ind; // netflix_cltbar_visibility = ind;
if(ind == -1) // if(ind == -1)
updateUICSS(); // updateUICSS();
} // }
} }
if(page_url.indexOf("netflix.com") != -1 && autoar_enabled){ if( autoar_enabled ){
//Netflix-specific stuff
var qntitle = document.querySelector(".player-status-main-title"); var titleElement;
if(SITE_PROPS.autoar_imdb.isClass)
titleElement = document.querySelector("." + SITE_PROPS.autoar_imdb.title);
else
titleElement = document.querySelector("#" + SITE_PROPS.autoar_imdb.title);
var ntitle = ""; var ntitle = "";
//querySelector lahko vrne null, zato moramo preveriti, kaj smo dobili — drugače se .textContent pritožuje. //querySelector lahko vrne null, zato moramo preveriti, kaj smo dobili — drugače se .textContent pritožuje.
//querySelector can return null, in which case .textContent will complain. //querySelector can return null, in which case .textContent will complain.
if(qntitle) if(qntitle)
ntitle = qntitle.textContent; ntitle = titleElement.textContent;
else{ else{
char_got_ar = false; char_got_ar = false;
return; return;
} }
if(qntitle && ntitle && ntitle != title){ if(titleElement && ntitle && ntitle != title){
if(debugmsg || debugmsg_message || debugmsg_autoar) if(debugmsg || debugmsg_message || debugmsg_autoar)
console.log("uw::periodic | title changed. New title:",ntitle,"Old title:",title); console.log("uw::periodic | title changed. New title:",ntitle,"Old title:",title);
@ -816,7 +829,7 @@ function uinit(){
SITE_ENABLED = site.enabled; SITE_ENABLED = site.enabled;
SITE_TYPE = site.type; SITE_TYPE = site.type;
SITE_URL_RULES = site.urlRules; SITE_URL_RULES = site.urlRules;
SITE_PROPS = site;
if(debugmsg) if(debugmsg)
console.log("uw::uinit | are we in iframe?", inIframe(), "does the site have a separate config for iframe?", site.iframe ? true : false ); console.log("uw::uinit | are we in iframe?", inIframe(), "does the site have a separate config for iframe?", site.iframe ? true : false );
@ -1346,7 +1359,7 @@ function updateUICSS(){
function getBaseButtonWidth(){ function getBaseButtonWidth(){
try{ try{
// Na različnih straneh širino gumba poberemo na različne načine. // Na različnih straneh širino gumba poberemo na različne načine.
if(button_size_base == "y") if(BUTTON_SIZE_BASE == "y")
return document.getElementsByClassName(SAMPLE_BUTTON_CLASS)[SAMPLE_BUTTON_INDEX].scrollHeight; return document.getElementsByClassName(SAMPLE_BUTTON_CLASS)[SAMPLE_BUTTON_INDEX].scrollHeight;
else else
return document.getElementsByClassName(SAMPLE_BUTTON_CLASS)[SAMPLE_BUTTON_INDEX].scrollWidth; return document.getElementsByClassName(SAMPLE_BUTTON_CLASS)[SAMPLE_BUTTON_INDEX].scrollWidth;
@ -1814,25 +1827,29 @@ function onFullscreenOff(){
} }
function manual_autoar(){ function manual_autoar(){
if(page_url.indexOf("netflix.com") != -1){ if(! SITE_PROPS.autoar_imdb.enabled)
var ntitle = document.querySelector(".player-status-main-title"); return;
//querySelector lahko vrne null, zato moramo preveriti, kaj smo dobili — drugače se .textContent pritožuje. if(SITE_PROPS.autoar_imdb.isClass)
//querySelector can return null, in which case .textContent will complain. var ntitle = document.querySelector("."+ SITE_PROPS.autoar_imdb.title); // NOTE: needs to be tested
if(!ntitle) else
return; var ntitle = document.querySelector("#"+ SITE_PROPS.autoar_imdb.title); // NOTE: needs to be tested
var title = ntitle.textContent; //querySelector lahko vrne null, zato moramo preveriti, kaj smo dobili — drugače se .textContent pritožuje.
//querySelector can return null, in which case .textContent will complain.
char_got_ar = false; if(!ntitle)
last_whatdo = {type: "autoar", what_do:"autoar"}; return;
var sending = browser.runtime.sendMessage({ var title = ntitle.textContent;
type: "gibAspectRatio",
title: title char_got_ar = false;
}); last_whatdo = {type: "autoar", what_do:"autoar"};
var sending = browser.runtime.sendMessage({
type: "gibAspectRatio",
title: title
});
// sending.then( function(){}, function(err1, err2){console.log("uw::periodic: there was an error while sending a message", err1, err2)} ); // sending.then( function(){}, function(err1, err2){console.log("uw::periodic: there was an error while sending a message", err1, err2)} );
}
} }
@ -1855,8 +1872,6 @@ function changeCSS(type, what_do){
var video = { width: evideo.videoWidth, height: evideo.videoHeight }; var video = { width: evideo.videoWidth, height: evideo.videoHeight };
var nplayer = { width: PLAYER.clientWidth, height: PLAYER.clientHeight }; var nplayer = { width: PLAYER.clientWidth, height: PLAYER.clientHeight };
console.log("uw::changeCSS | video:", video, "nplayer: (player)", nplayer);
if(debugmsg) if(debugmsg)
console.log("uw::changeCSS | video dimensions:",video.width,"x",video.height,"; player:",nplayer.width,"x",nplayer.height); console.log("uw::changeCSS | video dimensions:",video.width,"x",video.height,"; player:",nplayer.width,"x",nplayer.height);