Optimizations and changes.
This commit is contained in:
parent
3b3430ddce
commit
85a6a680b9
@ -34,6 +34,10 @@ var DEFAULT_KEYBINDINGS = {
|
|||||||
|
|
||||||
var _kbd_process = function (event) { // Tukaj ugotovimo, katero tipko smo pritisnili
|
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
|
// Tipke upoštevamo samo, če smo v celozaslonskem načinu oz. če ne pišemo komentarja
|
||||||
// v nasprotnem primeru ne naredimo nič.
|
// v nasprotnem primeru ne naredimo nič.
|
||||||
// We only take actions if we're in full screen or not writing a comment
|
// 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;
|
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:
|
// building modifiers list:
|
||||||
var modlist = "";
|
var modlist = "";
|
||||||
|
@ -35,19 +35,12 @@ var _pd_isFullScreen = function(){
|
|||||||
var _pd_getPlayerDimensions = function(element){
|
var _pd_getPlayerDimensions = function(element){
|
||||||
|
|
||||||
if(_pd_isFullScreen()){
|
if(_pd_isFullScreen()){
|
||||||
if(Debug.debug){
|
|
||||||
console.log("[PlayerDetect::_pd_getPlayerDimensions] video is full screen, returning player dimensions!");
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
width: screen.width,
|
width: screen.width,
|
||||||
height: screen.height
|
height: screen.height
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Debug.debug){
|
|
||||||
console.log("[PlayerDetect::_pd_getPlayerDimensions] video is not full screen. Looking for player.");
|
|
||||||
}
|
|
||||||
|
|
||||||
var playerCandidateNode = element;
|
var playerCandidateNode = element;
|
||||||
|
|
||||||
// in case our <video> is bigger than player in one dimension but smaller in the other
|
// in case our <video> is bigger than player in one dimension but smaller in the other
|
||||||
|
@ -169,7 +169,7 @@ var setVideoAr = function(aspect_ratio, video, player){
|
|||||||
var _res_reset = function(force){
|
var _res_reset = function(force){
|
||||||
dimensions = {top: "", left: "", width: "100%", height: "100%"};
|
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)
|
if(Debug.debug)
|
||||||
console.log("[Resizer::_res_reset] css applied. Dimensions/pos: w:",dimensions.width,"; h:",dimensions.height,"; top:",dimensions.top,"; left:",dimensions.left);
|
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.
|
// 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
|
// 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 = $("video")[0];
|
var vid = GlobalVars.video;
|
||||||
var ar = screen.width / screen.height;
|
var ar = screen.width / screen.height;
|
||||||
var fileAr = vid.videoWidth / vid.videoHeight;
|
var fileAr = vid.videoWidth / vid.videoHeight;
|
||||||
|
|
||||||
if(action == "fitw"){
|
if(action == "fitw"){
|
||||||
_res_setAr_kbd( ar > fileAr ? ar : fileAr);
|
_res_setAr( ar > fileAr ? ar : fileAr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(action == "fith"){
|
if(action == "fith"){
|
||||||
_res_setAr_kbd( ar < fileAr ? ar : fileAr);
|
_res_setAr( ar < fileAr ? ar : fileAr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(action == "reset"){
|
if(action == "reset"){
|
||||||
_res_setAr_kbd(fileAr);
|
_res_setAr(fileAr);
|
||||||
// this.reset(true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(action == "autoar"){
|
if(action == "autoar"){
|
||||||
@ -209,7 +208,7 @@ var _res_setAr = function(ar, playerDimensions){
|
|||||||
|
|
||||||
this._currentAr = ar;
|
this._currentAr = ar;
|
||||||
|
|
||||||
var vid = $("video")[0];
|
var vid = GlobalVars.video;
|
||||||
|
|
||||||
|
|
||||||
// Dejansko razmerje stranic datoteke/<video> značke
|
// 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);
|
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){
|
if(Debug.debug){
|
||||||
console.log("[Resizer::_res_setAr] Player dimensions?",playerDimensions);
|
console.log("[Resizer::_res_setAr] Player dimensions?",playerDimensions);
|
||||||
@ -305,7 +308,7 @@ var _res_setStyleString = function(vid, styleString, count){
|
|||||||
vid.setAttribute("style", styleString);
|
vid.setAttribute("style", styleString);
|
||||||
|
|
||||||
if(_res_restore_wd){
|
if(_res_restore_wd){
|
||||||
var vid2 = $("video")[0];
|
var vid2 = GlobalVars.video;
|
||||||
|
|
||||||
if(
|
if(
|
||||||
styleString.indexOf("width: " + vid2.style.width) == -1 ||
|
styleString.indexOf("width: " + vid2.style.width) == -1 ||
|
||||||
@ -352,9 +355,8 @@ function _res_applyCss(dimensions){
|
|||||||
// misc.
|
// misc.
|
||||||
dimensions.position = "position: absolute !important";
|
dimensions.position = "position: absolute !important";
|
||||||
dimensions.margin = "margin: 0px !important";
|
dimensions.margin = "margin: 0px !important";
|
||||||
// dimensions.objectFit = "object-fit: cover !important";
|
|
||||||
|
|
||||||
var vid = $("video")[0];
|
var vid = GlobalVars.video;
|
||||||
|
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
console.log("[Resizer::_res_applyCss] trying to apply css. Css strings: ", dimensions, "video tag: ", vid);
|
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:")){
|
else if(styleArray[i].startsWith("position:")){
|
||||||
styleArray[i] = dimensions.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)
|
for(var key in dimensions)
|
||||||
styleArray.push( dimensions[key] );
|
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
|
// build style string back
|
||||||
var styleString = "";
|
var styleString = "";
|
||||||
for(var i in styleArray)
|
for(var i in styleArray)
|
||||||
|
5
js/run/GlobalVars.js
Normal file
5
js/run/GlobalVars.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
var GlobalVars = {
|
||||||
|
video: null,
|
||||||
|
player: null,
|
||||||
|
playerDimensions: null
|
||||||
|
}
|
44
js/uw.js
44
js/uw.js
@ -2,6 +2,7 @@ if(Debug.debug)
|
|||||||
console.log("\n\n\n\n\n\n ——— Sᴛλʀᴛɪɴɢ Uʟᴛʀᴀᴡɪᴅɪꜰʏ ———\n << ʟᴏᴀᴅɪɴɢ ᴍᴀɪɴ ꜰɪʟᴇ >>\n\n\n\n");
|
console.log("\n\n\n\n\n\n ——— Sᴛλʀᴛɪɴɢ Uʟᴛʀᴀᴡɪᴅɪꜰʏ ———\n << ʟᴏᴀᴅɪɴɢ ᴍᴀɪɴ ꜰɪʟᴇ >>\n\n\n\n");
|
||||||
|
|
||||||
// global-ish
|
// global-ish
|
||||||
|
|
||||||
var _main_last_fullscreen;
|
var _main_last_fullscreen;
|
||||||
|
|
||||||
var _player_dimensions_last;
|
var _player_dimensions_last;
|
||||||
@ -30,7 +31,6 @@ async function main(){
|
|||||||
// start autoar and setup everything
|
// start autoar and setup everything
|
||||||
|
|
||||||
|
|
||||||
// $(document).ready(function() {
|
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
console.log("uw::document.ready | document is ready. Starting ar script ...");
|
console.log("uw::document.ready | document is ready. Starting ar script ...");
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ async function main(){
|
|||||||
if(Settings.arDetect.enabled == "global"){
|
if(Settings.arDetect.enabled == "global"){
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
console.log("[uw::main] Aspect ratio detection is enabled. Starting ArDetect");
|
console.log("[uw::main] Aspect ratio detection is enabled. Starting ArDetect");
|
||||||
ArDetect.arSetup();
|
// ArDetect.arSetup();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(Debug.debug)
|
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
|
// 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.
|
// 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 ||
|
if ( newPlayerDims.width != _player_dimensions_last.width ||
|
||||||
newPlayerDims.height != _player_dimensions_last.height){
|
newPlayerDims.height != _player_dimensions_last.height){
|
||||||
|
|
||||||
@ -148,6 +172,9 @@ function receiveMessage(message, sender, sendResponse) {
|
|||||||
if(message.cmd == "has-videos"){
|
if(message.cmd == "has-videos"){
|
||||||
var anyVideos = PageInfo.hasVideos();
|
var anyVideos = PageInfo.hasVideos();
|
||||||
|
|
||||||
|
if(Debug.debug)
|
||||||
|
console.log("[uw::receiveMessage] returning response:", {response: {"hasVideos": anyVideos }});
|
||||||
|
|
||||||
if(BrowserDetect.usebrowser == "firefox")
|
if(BrowserDetect.usebrowser == "firefox")
|
||||||
return Promise.resolve({response: {"hasVideos": anyVideos }});
|
return Promise.resolve({response: {"hasVideos": anyVideos }});
|
||||||
|
|
||||||
@ -217,5 +244,6 @@ function receiveMessage(message, sender, sendResponse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
main();
|
main();
|
||||||
|
});
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
"js/dep/jquery-3.1.1.js",
|
"js/dep/jquery-3.1.1.js",
|
||||||
"js/dep/chrome/chrome-extension-async.js",
|
"js/dep/chrome/chrome-extension-async.js",
|
||||||
|
|
||||||
|
"js/run/GlobalVars.js",
|
||||||
"js/lib/BrowserDetect.js",
|
"js/lib/BrowserDetect.js",
|
||||||
"js/lib/StorageManager.js",
|
"js/lib/StorageManager.js",
|
||||||
"js/lib/Comms.js",
|
"js/lib/Comms.js",
|
||||||
|
Loading…
Reference in New Issue
Block a user