Optimizations and changes.

This commit is contained in:
Tamius Han 2018-01-20 22:59:31 +01:00
parent 3b3430ddce
commit 85a6a680b9
6 changed files with 64 additions and 52 deletions

View File

@ -34,6 +34,10 @@ var DEFAULT_KEYBINDINGS = {
var _kbd_process = function (event) { // Tukaj ugotovimo, katero tipko smo pritisnili
if(Debug.debug && Debug.keyboard ){
console.log("%c[Keybinds::_kbd_process] we pressed a key: ", "color: #ff0", event.key , " | keydown: ", event.keydown, "event:", event);
}
// 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
@ -46,9 +50,6 @@ var _kbd_process = function (event) { // Tukaj ugotovimo, katero tipko
return;
}
if(Debug.debug && Debug.keyboard ){
console.log("[Keybinds::_kbd_process] we pressed a key: ", event.key , " | keydown: ", event.keydown, "event:", event);
}
// building modifiers list:
var modlist = "";

View File

@ -35,19 +35,12 @@ var _pd_isFullScreen = function(){
var _pd_getPlayerDimensions = function(element){
if(_pd_isFullScreen()){
if(Debug.debug){
console.log("[PlayerDetect::_pd_getPlayerDimensions] video is full screen, returning player dimensions!");
}
return {
width: screen.width,
height: screen.height
};
}
if(Debug.debug){
console.log("[PlayerDetect::_pd_getPlayerDimensions] video is not full screen. Looking for player.");
}
var playerCandidateNode = element;
// in case our <video> is bigger than player in one dimension but smaller in the other

View File

@ -169,7 +169,7 @@ var setVideoAr = function(aspect_ratio, video, player){
var _res_reset = function(force){
dimensions = {top: "", left: "", width: "100%", height: "100%"};
$("video").css({"position": "relative", "width": dimensions.width,"height": dimensions.height,"top": dimensions.top, "left": dimensions.left});
GlobalVars.video.css({"position": "relative", "width": dimensions.width,"height": dimensions.height,"top": dimensions.top, "left": dimensions.left});
if(Debug.debug)
console.log("[Resizer::_res_reset] css applied. Dimensions/pos: w:",dimensions.width,"; h:",dimensions.height,"; top:",dimensions.top,"; left:",dimensions.left);
@ -181,21 +181,20 @@ var _res_reset = function(force){
// 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 vid = $("video")[0];
var vid = GlobalVars.video;
var ar = screen.width / screen.height;
var fileAr = vid.videoWidth / vid.videoHeight;
if(action == "fitw"){
_res_setAr_kbd( ar > fileAr ? ar : fileAr);
_res_setAr( ar > fileAr ? ar : fileAr);
return;
}
if(action == "fith"){
_res_setAr_kbd( ar < fileAr ? ar : fileAr);
_res_setAr( ar < fileAr ? ar : fileAr);
return;
}
if(action == "reset"){
_res_setAr_kbd(fileAr);
// this.reset(true);
_res_setAr(fileAr);
return;
}
if(action == "autoar"){
@ -209,7 +208,7 @@ var _res_setAr = function(ar, playerDimensions){
this._currentAr = ar;
var vid = $("video")[0];
var vid = GlobalVars.video;
// Dejansko razmerje stranic datoteke/<video> značke
@ -229,8 +228,12 @@ var _res_setAr = function(ar, playerDimensions){
}
if(playerDimensions === undefined)
if(playerDimensions === undefined){
playerDimensions = PlayerDetect.getPlayerDimensions(vid);
if(Debug.debug)
console.log("[Resizer::_res_setAr] playerDimensions are undefined, trying to determine new ones ... new dimensions:",playerDimensions);
}
if(Debug.debug){
console.log("[Resizer::_res_setAr] Player dimensions?",playerDimensions);
@ -305,7 +308,7 @@ var _res_setStyleString = function(vid, styleString, count){
vid.setAttribute("style", styleString);
if(_res_restore_wd){
var vid2 = $("video")[0];
var vid2 = GlobalVars.video;
if(
styleString.indexOf("width: " + vid2.style.width) == -1 ||
@ -352,9 +355,8 @@ function _res_applyCss(dimensions){
// misc.
dimensions.position = "position: absolute !important";
dimensions.margin = "margin: 0px !important";
// dimensions.objectFit = "object-fit: cover !important";
var vid = $("video")[0];
var vid = GlobalVars.video;
if(Debug.debug)
console.log("[Resizer::_res_applyCss] trying to apply css. Css strings: ", dimensions, "video tag: ", vid);
@ -387,6 +389,11 @@ function _res_applyCss(dimensions){
}
else if(styleArray[i].startsWith("position:")){
styleArray[i] = dimensions.position;
delete dimensions.position;
}
else if(styleArray[i].startsWith("margin:")){
styleArray[i] = dimensions.margin;
delete dimensions.margin;
}
}
}
@ -398,29 +405,6 @@ function _res_applyCss(dimensions){
for(var key in dimensions)
styleArray.push( dimensions[key] );
// problem: last element can get duplicated a lot.
// solution: check if last element is a duplicate. if it is, remove first occurence (keep last)
// repeat until no element is removed
var dups = false;
// debugger;
do{
dups = false;
var last = styleArray.length - 1;
var i = last;
while(i --> 0){
if(styleArray[i] === styleArray[last]){
dups = true;
styleArray.splice(i, 1);
--last; // correct the index
}
}
} while(dups);
// build style string back
var styleString = "";
for(var i in styleArray)

5
js/run/GlobalVars.js Normal file
View File

@ -0,0 +1,5 @@
var GlobalVars = {
video: null,
player: null,
playerDimensions: null
}

View File

@ -2,6 +2,7 @@ if(Debug.debug)
console.log("\n\n\n\n\n\n ——— Sᴛλʀᴛɪɴɢ Uʟᴛʀᴀɪɪʏ ———\n << ʟᴏᴀᴅɪɴɢ ᴍᴀɪɴ ꜰɪʟᴇ >>\n\n\n\n");
// global-ish
var _main_last_fullscreen;
var _player_dimensions_last;
@ -30,7 +31,6 @@ async function main(){
// start autoar and setup everything
// $(document).ready(function() {
if(Debug.debug)
console.log("uw::document.ready | document is ready. Starting ar script ...");
@ -59,7 +59,7 @@ async function main(){
if(Settings.arDetect.enabled == "global"){
if(Debug.debug)
console.log("[uw::main] Aspect ratio detection is enabled. Starting ArDetect");
ArDetect.arSetup();
// ArDetect.arSetup();
}
else{
if(Debug.debug)
@ -74,13 +74,37 @@ async function main(){
// 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 _video_recheck_counter = 0;
var _video_recheck_period = 60; // on this many retries
function ghettoOnChange(){
if(_video_recheck_counter++ > _video_recheck_period){
_video_recheck_counter = 0;
if(GlobalVars.video === null){
var video = document.getElementsByTagName("video")[0];
if(video !== undefined)
GlobalVars.video = video;
}
}
var newPlayerDims = PlayerDetect.getPlayerDimensions($("video")[0]);
if(GlobalVars.video === null)
return;
if(_player_dimensions_last === undefined){
_player_dimensions_last = PlayerDetect.getPlayerDimensions( GlobalVars.video );
}
var newPlayerDims = PlayerDetect.getPlayerDimensions( GlobalVars.video );
if (newPlayerDims == undefined)
return;
GlobalVars.playerDimeimensions = newPlayerDims;
if ( newPlayerDims.width != _player_dimensions_last.width ||
newPlayerDims.height != _player_dimensions_last.height){
@ -148,6 +172,9 @@ function receiveMessage(message, sender, sendResponse) {
if(message.cmd == "has-videos"){
var anyVideos = PageInfo.hasVideos();
if(Debug.debug)
console.log("[uw::receiveMessage] returning response:", {response: {"hasVideos": anyVideos }});
if(BrowserDetect.usebrowser == "firefox")
return Promise.resolve({response: {"hasVideos": anyVideos }});
@ -217,5 +244,6 @@ function receiveMessage(message, sender, sendResponse) {
}
main();
$(document).ready(function() {
main();
});

View File

@ -16,6 +16,7 @@
"js/dep/jquery-3.1.1.js",
"js/dep/chrome/chrome-extension-async.js",
"js/run/GlobalVars.js",
"js/lib/BrowserDetect.js",
"js/lib/StorageManager.js",
"js/lib/Comms.js",