2016-10-16 13:13:34 +02:00
var extraClassAdded = false ;
var inFullScreen = false ;
var cssmod = "" ;
var zoomStep = 0.05 ;
2016-10-18 23:07:28 +02:00
var whatdo _persistence = true ;
var last _whatdo = "reset" ;
2016-11-16 19:52:09 +01:00
var debugmsg = true ;
2016-10-20 23:34:45 +02:00
var ctlbar _classnames = [ "ytp-chrome-controls" ] ;
var serviceArray = [ ".video-stream" ] ; //Youtube
2016-10-16 13:13:34 +02:00
2016-10-22 20:49:15 +02:00
var buttons = [ ] ;
2016-11-29 19:54:05 +01:00
console . log ( "????" ) ;
2016-10-22 20:49:15 +02:00
$ ( "<style>" )
. prop ( "type" , "text/css" )
. html ( " \
. uw - button { \
display : inline - block ; \
height : 100 % ! important ; \
2016-10-23 20:47:14 +02:00
background - size : 75 % 75 % ; \
2016-10-22 20:49:15 +02:00
background - repeat : no - repeat ; \
background - position : center center ; \
2016-10-23 20:47:14 +02:00
} \
. uw - button : hover { \
background - color : rgba ( 192 , 0 , 0 , 0.66 ) ; \
} \
. uw - setmenu { \
display : none ; \
position : absolute ; \
background - color : rgba ( 0 , 0 , 0 , 0.66 ) ; \
right : 0 px ; \
} \
. uw - setmenu - item { \
font - family : \ "Oxygen\" ; \
color : # ffffff ! important ; \
width : 90 % ; \
padding - left : 10 % ; \
} \
. uw - setmenu - item : hover { \
background - color : rgba ( 192 , 0 , 0 , 0.66 ) ; \
} \
. show { \
display : block ; \
2016-11-15 22:28:39 +01:00
} \
. uw - ext - settings - bg { \
display : none ; \
position : absolute ! important ; \
width : 100 % ! important ; \
height : 100 % ! important ; \
z - index : 1000 ! important ; \
\
background - color : rgba ( 0 , 0 , 0 , 0.69 ) ! important ; \
color : # fff ! important ; \
font - family : 'Oxygen' ! important ; \
text - align : center ; \
\
} \
. uw - ext - settings - content { \
display : inline - block ; \
min - width : 75 % ; \
max - width : 90 % ; \
text - align : left ; \
padding : 2 em ! important ; \
font - size : 1.4 em ; \
font - family : 'Oxygen' ! important ; \
} \
. uw _top { \
z - index : 1337 ; \
} \
. uw - h1 { \
font - size : 4 em ! important ; \
color : # f46007 ! important ; \
font - family : 'Oxygen' ! important ; \
} \
. uw _settings _tab { \
font - size : 1.4 em ! important ; \
padding - left : 1 em ; \
color : # ddd ! important ; \
} \
. uw _settings _tab : hover { \
font - size : 1.6 em ; \
padding - left : 1.6 em ; \
color : # ffdb6e ! important ; \
} \
2016-11-29 19:54:05 +01:00
. uw _settings _tabbar { \
display : inline - block ; \
float : left ; \
width : 15 em ; \
} \
. uw _settings _container { \
display : inline - block ; \
float : right ; \
width : calc ( 99 % - 15 em ) ; \
} \
. uw _settings _kbshortcuts _label { \
display : inline - block ; \
width : 15 em ; \
} \
. uw _settings _kbshortcuts _input { \
width : 1.5 em ; \
} \
2016-11-15 22:28:39 +01:00
" )
2016-10-22 20:49:15 +02:00
. appendTo ( "head" ) ;
2016-11-15 22:28:39 +01:00
2016-11-16 19:52:09 +01:00
// Yeah hi /r/badcode.
// Anyway, because nazi localstorage flat out refuses to store arrays:
var DEFAULT _KEYBINDINGS = {
1 : { action : "fitw" ,
2016-11-15 22:28:39 +01:00
key : 'w' ,
modifiers : [ ]
} ,
2016-11-16 19:52:09 +01:00
2 : {
action : "fith" ,
2016-11-15 22:28:39 +01:00
key : 'e' ,
modifiers : [ ]
} ,
2016-11-16 19:52:09 +01:00
3 : {
2016-11-15 22:28:39 +01:00
action : "reset" ,
key : 'r' ,
modifiers : [ ]
} ,
2016-11-16 19:52:09 +01:00
4 : {
2016-11-15 22:28:39 +01:00
action : "zoom" ,
key : "z" ,
modifiers : [ ]
} ,
2016-11-16 19:52:09 +01:00
5 : {
2016-11-15 22:28:39 +01:00
action : "unzoom" ,
key : "u" ,
modifiers : [ ]
} ,
2016-11-16 19:52:09 +01:00
6 : {
2016-11-15 22:28:39 +01:00
action : "char" ,
targetAR : ( 21 / 9 ) ,
key : "d" ,
modifiers : [ ]
} ,
2016-11-16 19:52:09 +01:00
7 : {
2016-11-15 22:28:39 +01:00
action : "char" ,
targetAR : ( 16 / 9 ) ,
key : "s" ,
modifiers : [ ]
} ,
2016-11-16 19:52:09 +01:00
8 : {
2016-11-15 22:28:39 +01:00
action : "char" ,
targetAR : ( 16 / 10 ) ,
key : "x" ,
modifiers : [ ]
} ,
2016-11-16 19:52:09 +01:00
9 : {
2016-11-15 22:28:39 +01:00
action : "char" ,
targetAR : ( 4 / 3 ) ,
key : "a" ,
modifiers : [ ]
}
2016-11-16 19:52:09 +01:00
} ;
var KEYBINDS = { } ;
var ask4keybinds = browser . storage . local . get ( "ultrawidify_keybinds" ) ;
ask4keybinds . then ( ( res ) => {
if ( res . length == 1 && jQuery . isEmptyObject ( res [ 0 ] ) ) {
if ( debugmsg )
console . log ( "uw::<init keybinds> | No keybindings found. Loading default keybinds as keybinds" ) ;
browser . storage . local . set ( { ultrawidify _keybinds : DEFAULT _KEYBINDINGS } ) ;
KEYBINDS = DEFAULT _KEYBINDINGS ;
}
else {
KEYBINDS = res [ 0 ] . ultrawidify _keybinds ;
}
console . log ( "res. " , res [ 0 ] . ultrawidify _keybinds ) ;
} ) ;
2016-11-15 22:28:39 +01:00
2016-10-16 13:13:34 +02:00
$ ( document ) . ready ( function ( ) {
2016-10-22 20:49:15 +02:00
if ( debugmsg )
console . log ( "==========================================================================================" ) ;
2016-10-16 13:13:34 +02:00
2016-11-15 22:28:39 +01:00
$ ( document ) . keydown ( function ( event ) { // Tukaj ugotovimo, katero tipko smo pritisnili
// 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 ( ! ( inFullScreen || (
( document . activeElement . getAttribute ( "role" ) != "textbox" ) &&
( document . activeElement . getAttribute ( "type" ) != "text" )
) ) ) {
if ( debugmsg )
console . log ( "We're writing a comment or something. Doing nothing" ) ;
return ;
}
2016-11-16 19:52:09 +01:00
console . log ( KEYBINDS ) ;
2016-11-15 22:28:39 +01:00
console . log ( "we pressed a key: " , event . key , " | keydown: " , event . keydown ) ;
2016-11-16 19:52:09 +01:00
for ( i in KEYBINDS ) {
console . log ( "i: " , i , "keybinds[i]:" , KEYBINDS [ i ] ) ;
if ( event . key == KEYBINDS [ i ] . key ) {
2016-11-15 22:28:39 +01:00
console . log ( "Key matches!" ) ;
//Tipka se ujema. Preverimo še modifierje:
//Key matches. Let's check if modifiers match, too:
var mods = true ;
2016-11-16 19:52:09 +01:00
for ( var j = 0 ; j < KEYBINDS [ i ] . modifiers . length ; j ++ ) {
if ( KEYBINDS [ i ] . modifiers [ j ] == "ctrl" )
2016-11-15 22:28:39 +01:00
mods &= event . ctrlKey ;
2016-11-16 19:52:09 +01:00
else if ( KEYBINDS [ i ] . modifiers [ j ] == "alt" )
2016-11-15 22:28:39 +01:00
mods &= event . altKey ;
2016-11-16 19:52:09 +01:00
else if ( KEYBINDS [ i ] . modifiers [ j ] == "shift" )
2016-11-15 22:28:39 +01:00
mods &= event . shiftKey ;
}
2016-11-16 19:52:09 +01:00
console . log ( "we pressed a key: " , event . key , " | mods match?" , mods , "keybinding: " , KEYBINDS [ i ] ) ;
2016-11-15 22:28:39 +01:00
if ( mods ) {
2016-11-16 19:52:09 +01:00
if ( KEYBINDS [ i ] . action == "char" ) {
changeCSS ( "char" , KEYBINDS [ i ] . targetAR ) ;
2016-11-15 22:28:39 +01:00
return ;
}
2016-11-16 19:52:09 +01:00
changeCSS ( "anything goes" , KEYBINDS [ i ] . action ) ;
2016-11-15 22:28:39 +01:00
return ;
}
}
2016-10-16 13:13:34 +02:00
}
} ) ;
document . addEventListener ( "mozfullscreenchange" , function ( event ) {
2016-10-22 20:49:15 +02:00
onFullScreenChange ( ) ;
2016-10-16 13:13:34 +02:00
inFullScreen = ( window . innerHeight == window . screen . height && window . innerWidth == window . screen . width ) ;
inFullScreen ? onFullscreenOn ( ) : onFullscreenOff ( ) ;
} ) ;
2016-10-20 23:34:45 +02:00
// Dodajmo gumbe na video
// let's add buttons to the video
addCtlButtons ( 0 ) ;
2016-10-16 13:13:34 +02:00
} ) ;
2016-11-29 19:54:05 +01:00
//UI helpers
function saveKeybinds ( ) {
console . log ( $ ( 'uw_kbshortcuts_form' ) . serializeArray ( ) ) ;
}
//BEGIN UI
2016-10-20 23:34:45 +02:00
function addCtlButtons ( provider _id ) {
2016-10-22 20:49:15 +02:00
// Gumb za nastavitve je bolj kot ne vselej prisoten, zato širino tega gumba uporabimo kot širino naših gumbov
// Settings button is more or less always there, so we use its width as width of our buttons
var button _width = document . getElementsByClassName ( "ytp-button ytp-settings-button" ) [ 0 ] . scrollWidth ;
2016-10-23 20:47:14 +02:00
var button _def = [ "fitw" , "fith" , "reset" , "zoom" , "uzoom" , "settings" ] ;
2016-10-20 23:34:45 +02:00
if ( debugmsg )
console . log ( "uw::addCtlButtons | trying to add buttons" ) ;
var button _panel ;
2016-10-22 20:49:15 +02:00
2016-11-29 19:54:05 +01:00
// Če je ta dodatek že nameščen, potem odstranimo vse elemente. Vsi top-level elementi imajo definiran prazen razred
// uw_element, prek katerega jih naberemo na kup. Ta del kode je tu bolj ali manj zaradi debugiranja.
//
// If this addon is already installed, we have to remove all prevously added elements (to avoid duplicating).
// The easiest way to gather all of them is to tack an empty class, 'uw_element,' to each top-level element we add.
// This is here mostly because debugging, but could also be useful in case of unforseen happenings.
var previousElements = document . getElementsByClassName ( "uw_element" ) ;
if ( previousElements && previousElements . length > 0 )
for ( var i = 0 ; i < previousElements . length ; i ++ )
previousElements [ i ] . parentNode . removeChild ( previousElements [ i ] ) ;
2016-10-22 20:49:15 +02:00
// If we're on youtube:
2016-10-20 23:34:45 +02:00
if ( provider _id == 0 ) {
2016-10-22 20:49:15 +02:00
var rctl = document . getElementsByClassName ( "ytp-right-controls" ) [ 0 ] ;
2016-10-23 20:47:14 +02:00
for ( var i = 5 ; i >= 0 ; i -- ) {
2016-10-20 23:34:45 +02:00
buttons [ i ] = document . createElement ( 'div' ) ;
2016-10-22 20:49:15 +02:00
buttons [ i ] . style . backgroundImage = 'url(' + imageToUrl ( "/img/ytplayer-icons/" + button _def [ i ] + ".png" ) + ')' ;
buttons [ i ] . style . width = ( button _width * 0.75 ) + "px" ;
2016-10-23 20:47:14 +02:00
// buttons[i].style.marginLeft = (button_width * 0.3) + "px";
buttons [ i ] . style . paddingLeft = ( button _width * 0.15 ) + "px" ;
buttons [ i ] . style . paddingRight = ( button _width * 0.15 ) + "px" ;
2016-11-29 19:54:05 +01:00
buttons [ i ] . className += " uw-button uw_element" ;
2016-10-22 20:49:15 +02:00
$ ( rctl ) . prepend ( buttons [ i ] ) ;
2016-10-20 23:34:45 +02:00
}
2016-10-23 20:47:14 +02:00
buttons [ 0 ] . onclick = function ( ) { changeCSS ( "fit" , "fitw" ) } ;
buttons [ 1 ] . onclick = function ( ) { changeCSS ( "fit" , "fith" ) } ;
buttons [ 2 ] . onclick = function ( ) { changeCSS ( "reset" , "reset" ) } ;
buttons [ 3 ] . onclick = function ( ) { changeCSS ( "fit" , "zoom" ) } ;
buttons [ 4 ] . onclick = function ( ) { changeCSS ( "fit" , "unzoom" ) } ;
// Knof za nastavitve ima še vgnezden meni, ki ga dodamo tu (privzeto je ta meni skrit)
// Settings button contains a menu that's nested in the element. By default, that menu is
// hidden.
buttons [ 5 ] . onclick = function ( ) { showMenu ( "uw-smenu" ) } ;
buttons [ 5 ] . id = "uw-settings-button" ;
var settings _menu = document . createElement ( "div" ) ;
var smenu _settings = document . createElement ( "div" ) ;
var smenu _ar = document . createElement ( "div" ) ;
var smenu _ar _menu = document . createElement ( "div" ) ;
var smenu _reset = document . createElement ( "div" ) ;
2016-11-29 19:54:05 +01:00
var smenu _fitw = document . createElement ( "div" ) ;
var smenu _fith = document . createElement ( "div" ) ;
var smenu _zoom = document . createElement ( "div" ) ;
var smenu _unzoom = document . createElement ( "div" ) ;
2016-10-23 20:47:14 +02:00
var smenu _ar _options = [ ] ;
buttons [ 5 ] . appendChild ( settings _menu ) ;
2016-11-29 19:54:05 +01:00
settings _menu . appendChild ( smenu _settings ) ; //TODO: uncomment that to re-enable settings screen. This line should only be disabled for builds and commits until the settings screen is finalized
settings _menu . appendChild ( smenu _zoom ) ;
settings _menu . appendChild ( smenu _unzoom ) ;
2016-10-23 20:47:14 +02:00
settings _menu . appendChild ( smenu _reset ) ;
2016-11-29 19:54:05 +01:00
settings _menu . appendChild ( smenu _fith ) ;
settings _menu . appendChild ( smenu _fitw ) ;
settings _menu . appendChild ( smenu _ar ) ;
2016-10-23 20:47:14 +02:00
for ( var i = 0 ; i < 4 ; i ++ ) {
smenu _ar _options [ i ] = document . createElement ( "div" ) ;
2016-11-29 19:54:05 +01:00
smenu _ar _options [ i ] . className = "uw-setmenu-item uw_element" ;
2016-10-23 20:47:14 +02:00
smenu _ar _menu . appendChild ( smenu _ar _options [ i ] ) ;
}
settings _menu . id = "uw-smenu" ;
2016-11-29 19:54:05 +01:00
settings _menu . className = "uw-setmenu uw_element" ;
2016-10-23 20:47:14 +02:00
smenu _settings . id = "uw-smenu_settings" ;
2016-11-29 19:54:05 +01:00
smenu _settings . className = "uw-setmenu-item uw_element" ;
2016-10-23 20:47:14 +02:00
smenu _ar . id = "uw-smenu_ar" ;
2016-11-29 19:54:05 +01:00
smenu _ar . className = "uw-setmenu-item uw_element" ;
smenu _fitw . className += "uw-setmenu-item" ;
smenu _fith . className += "uw-setmenu-item" ;
smenu _reset . className += "uw-setmenu-item" ;
smenu _zoom . className += "uw-setmenu-item" ;
smenu _unzoom . className += "uw-setmenu-item" ;
2016-10-23 20:47:14 +02:00
smenu _ar _menu . id = "uw-armenu" ;
2016-11-29 19:54:05 +01:00
smenu _ar _menu . className = "uw-setmenu uw_element" ;
2016-10-23 20:47:14 +02:00
// Stvari, ki se spreminjajo, se določijo tukaj
// Things that can change are defined here
settings _menu . style . bottom = ( button _width * 1.5 ) + "px" ;
settings _menu . style . width = ( button _width * 7.5 ) + "px" ;
settings _menu . style . fontSize = ( button _width * 0.50 ) + "px" ;
smenu _ar _menu . style . right = ( button _width * 7.5 ) + "px" ;
smenu _ar _menu . style . width = ( button _width * 2.5 ) + "px" ;
smenu _ar _menu . style . bottom = "0px" ;
2016-11-29 19:54:05 +01:00
smenu _fitw . style . width = ( button _width * 7.5 ) + "px" ;
smenu _fitw . style . fontSize = ( button _width * 0.50 ) + "px" ;
// smenu_fitw.style = (button_width * ) + "px";
smenu _fith . style . width = ( button _width * 7.5 ) + "px" ;
smenu _fith . style . fontSize = ( button _width * 0.5 ) + "px" ;
// smenu_fith.style = (button_width * ) + "px";
smenu _reset . style . width = ( button _width * 7.5 ) + "px" ;
smenu _reset . style . fontSize = ( button _width * 0.5 ) + "px" ;
// smenu_reset.style = (button_width * ) + "px";
smenu _zoom . style . width = ( button _width * 7.5 ) + "px" ;
smenu _zoom . style . fontSize = ( button _width * 0.5 ) + "px" ;
// smenu_zoom.style = (button_width * ) + "px";
smenu _unzoom . style . width = ( button _width * 7.5 ) + "px" ;
smenu _unzoom . style . fontSize = ( button _width * 0.5 ) + "px" ;
// smenu_unzoom.style = (button_width * ) + "px";
2016-10-23 20:47:14 +02:00
// Tukaj se določa notranji HTML knofov
// Inner HTML of elements is defined here
smenu _ar . innerHTML = "Force aspect ratio" ;
smenu _ar . appendChild ( smenu _ar _menu ) ;
2016-11-15 22:28:39 +01:00
smenu _settings . innerHTML = "Settings" ;
2016-10-23 20:47:14 +02:00
smenu _ar _options [ 0 ] . innerHTML = "4:3" ;
smenu _ar _options [ 1 ] . innerHTML = "16:10" ;
smenu _ar _options [ 2 ] . innerHTML = "16:9" ;
smenu _ar _options [ 3 ] . innerHTML = "21:9" ;
2016-11-29 19:54:05 +01:00
smenu _fitw . innerHTML = "Fit width" ;
smenu _fith . innerHTML = "Fit height" ;
smenu _reset . innerHTML = "Reset" ;
smenu _zoom . innerHTML = "Zoom in" ;
smenu _unzoom . innerHTML = "Zoom out" ;
2016-10-23 20:47:14 +02:00
// Pritisneš gumb, nekej zakon se more narest.
// — Bioware
// ( https://www.youtube.com/watch?v=hMcVZQI6ybw | [NVZD] )
//
// Press the button, something awesome has to happen.
// — Bioware
// ( https://www.youtube.com/watch?v=hMcVZQI6ybw | [NSFW] )
$ ( smenu _ar ) . on ( "mouseenter" , function ( ) { showMenu ( "uw-armenu" ) } ) ;
$ ( smenu _ar ) . on ( "mouseleave" , function ( ) { showMenu ( "uw-armenu" ) } ) ;
smenu _ar _options [ 0 ] . onclick = function ( ) { changeCSS ( "char" , ( 4 / 3 ) ) } ;
smenu _ar _options [ 1 ] . onclick = function ( ) { changeCSS ( "char" , ( 16 / 10 ) ) } ;
smenu _ar _options [ 2 ] . onclick = function ( ) { changeCSS ( "char" , ( 16 / 9 ) ) } ;
smenu _ar _options [ 3 ] . onclick = function ( ) { changeCSS ( "char" , ( 21 / 9 ) ) } ;
2016-11-15 22:28:39 +01:00
console . log ( smenu _settings ) ;
smenu _settings . onclick = function ( ) { showSettings ( ) } ;
2016-11-29 19:54:05 +01:00
smenu _fitw . onclick = function ( ) { changeCSS ( "fit" , "fitw" ) } ;
smenu _fith . onclick = function ( ) { changeCSS ( "fit" , "fith" ) } ;
smenu _reset . onclick = function ( ) { changeCSS ( "reset" , "reset" ) } ;
smenu _zoom . onclick = function ( ) { changeCSS ( "fit" , "zoom" ) } ;
smenu _unzoom . onclick = function ( ) { changeCSS ( "fit" , "unzoom" ) } ;
2016-11-15 22:28:39 +01:00
//BEGIN SETTINGS WINDOW
var e _player ;
if ( inIframe ( ) )
e _player = document . getElementById ( "player" ) ;
else
e _player = document . getElementById ( "movie_player" ) ;
var menu _panel = document . createElement ( 'div' ) ;
menu _panel . id = "uw_settings_panel" ;
2016-11-29 19:54:05 +01:00
menu _panel . className = "uw-ext-settings-bg uw_element" ;
console . log ( "boo" ) ;
var kbs _actions = [
{ action : "fitw" , label : "Fit width:" } ,
{ action : "fith" , label : "Fit height:" } ,
{ action : "reset" , label : "Reset:" } ,
{ action : "zoom" , label : "Zoom in:" } ,
{ action : "unzoom" , label : "Zoom out:" } ,
{ action : "ar219" , label : "Force 21:9" } ,
{ action : "ar169" , label : "Force 16:9" } ,
{ action : "ar1610" , label : "Force 16:10" } ,
{ action : "ar43" , label : "Force 4:3" }
] ;
var form = "" ;
for ( var i = 0 ; i < kbs _actions . length ; i ++ ) {
form += " < div class = 'uw_top uw_settings_kbshortcuts_line' > \
< div class = 'uw_top uw_settings_kbshortcuts_label' > " + kbs_actions[i].label + " < / d i v > \
< input type = 'checkbox' value = '" + kbs_actions[i].action + "_ctrl' > Ctrl + \
< input type = 'checkbox' value = '" + kbs_actions[i].action + "_shift' > Shift + \
< input type = 'checkbox' value = '" + kbs_actions[i].action + "_alt' > Alt + \
< input type = 'text' name = '" + kbs_actions[i].action + "_letter' maxlength = '1' class = 'uw_settings_kbshortcuts_input' > < / d i v > " ;
}
2016-11-15 22:28:39 +01:00
var settings _content = document . createElement ( 'div' ) ;
2016-11-29 19:54:05 +01:00
var savekb = document . createElement ( 'div' ) ;
savekb . className = 'uw_kbshortcuts_button' ;
savekb . onclick = function ( ) { saveKeybinds ( ) } ;
savekb . innerHTML = "Save" ;
2016-11-15 22:28:39 +01:00
settings _content . className = "uw-ext-settings-content" ;
settings _content . innerHTML = " < h1 class = 'uw_top uw-h1' > SETTINGS < / h 1 > \
< div class = 'uw_top uw_settings_tabbar' > \
< div class = 'uw_top uw_settings_tab' > Shortcuts < / d i v > \
<!-- - < div class = 'uw_top uw_settings_tab' > Customize UI < / d i v > - - - > \
< div class = 'uw_top uw_settings_tab' > About < / d i v > \
< div class = 'uw_top uw_settings_tab' id = 'uw_close_settings_view' > Close settings < / d i v > \
2016-11-29 19:54:05 +01:00
< / d i v > \
< div class = 'uw_top uw_settings_container' id = 'uw_settings_container' > \
< div class = 'uw_top uw_settings_panel' id = 'uw_settings_kbshortcuts' > \
< div > NOTE : some keys can ' t be rebound here ( namely : keys in use by the player and some other quirky keys ) . Use the settings page instead . < / d i v > \
< form id = 'uw_kbshortcuts_form' > " + form + " < / f o r m > \
< div id = 'uw_kbshortcuts_buttonrow' > < div class = 'uw_settings_button' > Back < / d i v > \
< / d i v > \
2016-11-15 22:28:39 +01:00
< / d i v > "
e _player . appendChild ( menu _panel ) ;
menu _panel . appendChild ( settings _content ) ;
2016-11-29 19:54:05 +01:00
2016-11-15 22:28:39 +01:00
document . getElementById ( 'uw_close_settings_view' ) . onclick = function ( ) { hideSettings ( ) } ;
2016-11-29 19:54:05 +01:00
2016-11-15 22:28:39 +01:00
//END SETTINGS WINDOW
2016-10-20 23:34:45 +02:00
}
2016-10-22 20:49:15 +02:00
2016-10-23 20:47:14 +02:00
2016-10-20 23:34:45 +02:00
if ( debugmsg )
console . log ( "uw::addCtlButtons | buttons added" ) ;
}
2016-11-29 19:54:05 +01:00
//END UI
2016-11-15 22:28:39 +01:00
function showSettings ( ) {
document . getElementById ( "uw_settings_panel" ) . style . display = "block" ;
}
function hideSettings ( ) {
document . getElementById ( "uw_settings_panel" ) . style . display = "none" ;
}
2016-11-29 19:54:05 +01:00
// function saveKeybinds(){
// console.log($('uw_kbshortcuts_form').serializeArray());
// }
2016-11-15 22:28:39 +01:00
2016-10-22 21:25:19 +02:00
// Ta funkcija se proži, ko vstopimo ali izstopimo iz celozaslonskega načina
// This function gets triggered by full screen state change
2016-10-22 20:49:15 +02:00
function onFullScreenChange ( ) {
// Popravimo velikost gumbov
// Let's fix the button size:
var button _width = document . getElementsByClassName ( "ytp-button ytp-settings-button" ) [ 0 ] . scrollWidth ;
2016-10-23 20:47:14 +02:00
for ( var i = 5 ; i >= 0 ; i -- ) {
2016-10-22 20:49:15 +02:00
buttons [ i ] . style . width = ( button _width * 0.75 ) + "px" ;
2016-10-23 20:47:14 +02:00
buttons [ i ] . style . paddingLeft = ( button _width * 0.15 ) + "px" ;
buttons [ i ] . style . paddingRight = ( button _width * 0.15 ) + "px" ;
2016-10-22 20:49:15 +02:00
}
2016-10-23 20:47:14 +02:00
document . getElementById ( "uw-smenu" ) . style . bottom = ( button _width * 1.5 ) + "px" ;
2016-10-22 20:49:15 +02:00
}
2016-10-22 21:25:19 +02:00
// Ta funkcija se proži, ko gremo v celozaslonski način
// This function triggers when we enter fullscreen mode
2016-10-16 13:13:34 +02:00
function onFullscreenOn ( ) {
}
2016-10-22 21:25:19 +02:00
// Ta funkcija se proži, ko gremo ven iz celozaslonskega načina
// This function triggers when we leave fullscreen mode
2016-10-16 13:13:34 +02:00
function onFullscreenOff ( ) {
2016-10-22 21:25:19 +02:00
2016-10-16 13:13:34 +02:00
}
2016-10-23 20:47:14 +02:00
function changeCSS ( type , what _do ) {
hideMenu ( "uw-armenu" ) ;
hideMenu ( "uw-smenu" ) ;
2016-10-20 23:34:45 +02:00
2016-10-18 23:07:28 +02:00
var e _video = document . getElementsByClassName ( "video-stream" ) [ 0 ] ;
var video = { "width" : e _video . scrollWidth , "height" : e _video . scrollHeight }
var e _player ;
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
if ( inIframe ( ) )
e _player = document . getElementById ( "player" )
else
e _player = document . getElementById ( "movie_player" ) ;
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
var player = { "width" : e _player . clientWidth , "height" : e _player . clientHeight }
// Youtube predvajalnik privzeto resetira CSS ob prehodu v/iz fullscreen. Tukaj shranimo zadnje dejanje,
// da ga lahko onFullscreenOff/onFullscreenOn uveljavita.
//
// Youtube player resets CSS on fullscreen state change. Here we save the last action taken, so
// onFullscreenOff/onFullscreenOn are able to preserve it (if we want).
last _whatdo = what _do ;
// -----------------------------------------------------------------------------------------
// Handlanje dejanj se zgodi pod to črto
//
// Handling actions happens below this line
// -----------------------------------------------------------------------------------------
2016-10-23 20:47:14 +02:00
if ( type == "char" ) {
// char = CHange Aspect Ratio
char ( what _do , video , player ) ;
2016-10-18 23:07:28 +02:00
return ;
}
if ( what _do == "reset" ) {
if ( debugmsg )
console . log ( "uw::changeCSS | issuing reset." ) ;
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
resetCSS ( video , player ) ;
2016-10-16 13:13:34 +02:00
return ;
}
// Velikost videa spreminjamo samo, če smo v celozaslonskem načinu ALI če NE pišemo komentarja
// Videa ne spreminjamo tudi, če uporabljamo vrstico za iskanje.
//
// We only change video size when we're in full screen OR if we are NOT writing a comment.
// We also leave video alone if we're using the search bar
if ( inFullScreen || (
( document . activeElement . getAttribute ( "role" ) != "textbox" ) &&
( document . activeElement . getAttribute ( "type" ) != "text" )
) )
2016-10-18 23:07:28 +02:00
changeCSS _nofs ( what _do , video , player ) ;
2016-10-16 13:13:34 +02:00
}
2016-10-23 20:47:14 +02:00
function char ( new _ar , video , player ) {
// Kot vhodni argument dobimo razmerje stranic. Problem je, ker pri nekaterih ločljivostih lahko razmerje stranic
// videa/našega zaslona minimalno odstopa od idealnega razmerja — npr 2560x1080 ni natanko 21:9, 1920x1080 ni
// natanko 16:9. Zato ob podanem razmerju stranic izračunamo dejansko razmerje stranic.
//
// The aspect ratio we get as an argument is an ideal aspect ratio. Some (most) resolutions' aspect ratios differ
// from that ideal aspect ratio (by a minimal amount) — e.g. 2560x1080 isn't exactly 21:9, 1920x1080 isn't exactly
// 16:9. What is more, both 3440x1440 and 2560x1080 are considered "21:9", but their aspect ratios are slightly
// different. This has the potential to result in annoying black bars, so we correct the aspect ratio we're given
// to something that's slightly more correct.
var ar ;
var res _219 = [ [ 2560 , 1080 ] , [ 3440 , 1440 ] ] ;
var res _169 = [ [ 1920 , 1080 ] , [ 1280 , 720 ] , [ 1366 , 768 ] ] ;
if ( new _ar == ( 21 / 9 ) ) {
for ( var i = 0 ; i < res _219 . length ; i ++ ) {
if ( player . height == res _219 [ i ] [ 1 ] ) {
ar = res _219 [ i ] [ 0 ] / res _219 [ i ] [ 1 ] ;
set _video _ar ( ar , video , player ) ;
return ;
}
}
}
else if ( new _ar == ( 16 / 9 ) ) {
for ( var i = 0 ; i < res _169 . length ; i ++ ) {
if ( player . height == res _169 [ i ] [ 1 ] ) {
ar = res _169 [ i ] [ 0 ] / res _169 [ i ] [ 1 ] ;
set _video _ar ( ar , video , player ) ;
return ;
}
}
}
set _video _ar ( new _ar , video , player ) ;
}
2016-10-18 23:07:28 +02:00
/ * T u k a j p o v e m o , k a k š n o r a z m e r j e s t r a n i c i m a v i d e o .
// Kaj to pomeni:
// Mi rečemo, da ima video razmerje stranic 16:9. Dejanski video
// ima razmerje 4:3. To pomeni, da ima video zgoraj in spodaj črno
// obrobo, ki je nočemo, zato video povečamo toliko, da se ta obroba odreže.
2016-10-23 20:47:14 +02:00
//
// OBROB TUKAJ NE DODAJAMO.
2016-10-18 23:07:28 +02:00
//
// With this function, we specify the aspect ratio of the video.
// What does this mean?
// If we specify that the aspect ratio of a video is 16:9 when video is
// actually 4:3, that means the video has black bars above and below.
// We zoom the video just enough for the black lines to disappear.
2016-10-23 20:47:14 +02:00
//
// WE DO NOT ADD ANY BLACK BORDERS. If we get to a scenario when we'd have to add
// black borders, we do nothing instead.
2016-10-18 23:07:28 +02:00
* /
function set _video _ar ( aspect _ratio , video , player ) {
var video _ar = video . width / video . height ;
var display _ar = player . width / player . height ;
if ( debugmsg )
console . log ( "uw::set_video_ar | aspect ratio: " + aspect _ratio + "; video_ar: " + video _ar + "; display_ar: " + display _ar ) ;
2016-10-23 20:47:14 +02:00
console . log ( "uw::set_video_ar | player dimensions: " + player . width + "x" + player . height + "; video dimensions: " + video . width + "x" + video . height ) ;
2016-10-18 23:07:28 +02:00
if ( aspect _ratio * 1.1 > video _ar && video _ar > aspect _ratio * 0.9 ) {
// Ta hack nas reši problema, ki ga predstavlja spodnji if stavek — če se legit 21:9 videu na 16:9 monitorju
// obreže na 16:9, potem ga s klicem te funkcije ne moremo spremeniti nazaj na 21:9. Vendar pa bi za tak primer
// radi imeli izjemo.
//
// This hack solves the problem that the bottom if statement presents. If we crop a 21:9 video on a 16:9 monitor,
// we can't change it back to 21:9 in this function, even though we kinda want that to happen — so we add an
// exception.
if ( debugmsg )
console . log ( "uw::set_video_ar | ar matches our display ar. resetting" ) ;
resetCSS ( video , player ) ;
return ;
}
//Širina, višina, top, left za nov video
//Width, height, top and left for the new video
var nv = { "w" : 0 , "h" : 0 , "top" : 0 , "left" : 0 } ;
2016-10-16 13:13:34 +02:00
/ *
2016-10-18 23:07:28 +02:00
// Video hočemo pretvoriti v video z drugačnim razmerjem stranic.
// To storimo tako, da širino videa nastavimo relativno na višino prikazovalnika, torej:
//
// širina = višina_prikazovalnika * razmerje_stranic
// višina = širina / video_ar
//
//
//
// ----------------------------------------------------------------------------------------------
//
// In this case, the video is narrower than we want (think 4:3, which we want to make into 16:9)
// We achieve this by setting video width relative to the display width, so:
//
// width = display_height * aspect_ratio
// height = width / video_ar
//
* /
if ( video _ar <= aspect _ratio ) {
if ( debugmsg ) {
console . log ( "uw::set_video_ar | reached pre-calc. Video is taller than ar. target ar: " + aspect _ratio ) ;
}
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
nv . w = player . height * aspect _ratio ;
nv . h = nv . w / video _ar ;
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
nv . top = ( player . height - nv . h ) / 2 ;
nv . left = ( player . width - nv . w ) / 2 ;
}
else {
if ( debugmsg ) {
console . log ( "uw::set_video_ar | reached pre-calc. Video is wider than ar. target ar: " + aspect _ratio ) ;
}
nv . h = player . width / aspect _ratio ;
nv . w = nv . h * video _ar ;
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
nv . top = ( player . height - nv . h ) / 2 ;
nv . left = ( player . width - nv . w ) / 2 ;
}
2016-10-23 20:47:14 +02:00
if ( nv . w > ( player . width * 1.1 ) && nv . h > ( player . height * 1.1 ) )
return ;
2016-10-18 23:07:28 +02:00
applyCSS ( nv ) ;
}
function resetCSS ( video , player ) {
if ( debugmsg )
console . log ( "uw::resetCSS | resetting video size" ) ;
var nv = { "w" : 0 , "h" : 0 , "top" : 0 , "left" : 0 } ;
var vidaspect = video . width / video . height ;
var scraspect = player . width / player . height ;
if ( vidaspect > scraspect ) { // Video je širši od okna | video is wider than window
nv . w = player . width ;
nv . h = player . width / video . width * video . height ;
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
// Lahko se zgodi, da je prišlo do zaokroževalne napake ter da je dejanska višina videa le nekaj pikslov drugačna,
// kot višina predvajalnika. V tem primeru zavržemo prej dobljeni rezultat in namesto tega privzamemo, da je višina
// videa enaka višini predvajalnika.
//
// It's possible to have a rounding error where calculated height of the video is only a few pixels different from
// the player height. In such cases, we discard the calculated video height and use player height instead.
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
if ( player . height - 4 < nv . h && nv . h < player . height + 4 )
nv . h = player . height ;
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
nv . top = ( player . height - nv . h ) / 2 ;
nv . left = 0 ;
}
else {
nv . h = player . height ;
nv . w = player . height / video . height * video . width ;
if ( player . width - 4 < nv . w && nv . w < player . width + 4 )
nv . w = player . width ;
nv . top = 0 ; //itak zasedemo 100% višine
nv . left = ( player . width - nv . w ) / 2 ;
2016-10-16 13:13:34 +02:00
}
2016-10-18 23:07:28 +02:00
applyCSS ( nv ) ;
}
function changeCSS _nofs ( what _do , video , player ) {
var w ;
var h ;
var top ;
var left ;
var ar = video . width / video . height ;
2016-11-15 22:28:39 +01:00
if ( what _do == "fitw" || what _do == "fit-width" ) {
2016-10-16 13:13:34 +02:00
// Ker bi bilo lepo, da atribut 'top' spremenimo hkrati z width in height, moramo najprej naračunati,
// za kakšen faktor se poviša višina. To potrebujemo, da se pravilno izračuna offset.
//
// 100vw = window.innerWidth
2016-10-18 23:07:28 +02:00
// window.innerWidth / videoWidth = x
2016-10-16 13:13:34 +02:00
//
// Če pomnožimo videoHeight z x, dobimo novo višino videa. Nova višina videa je lahko večja ali manjša
// kot višina ekrana. Če je višina videa manjša kot višina ekrana, bo top pozitiven, drugače negativen:
//
2016-10-18 23:07:28 +02:00
// nvideoh = x * videoWidth
// top = (window.innerHeight - nvideoh) / 2
2016-10-16 13:13:34 +02:00
//
// Z 2 delimo, ker hočemo video vertikalno poravnati.
2016-10-18 23:07:28 +02:00
w = player . width ;
h = player . width / video . width * video . height ;
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
top = ( player . height - h ) / 2 ;
2016-10-16 13:13:34 +02:00
left = 0 ; // Ker zavzamemo vso širino | cos we take up all the width
}
2016-11-15 22:28:39 +01:00
if ( what _do == "fith" || what _do == "fit-height" ) {
2016-10-18 23:07:28 +02:00
h = player . height ;
w = player . height / video . height * video . width ;
2016-10-16 13:13:34 +02:00
top = 0 ; //itak zasedemo 100% višine
2016-10-18 23:07:28 +02:00
left = ( player . width - w ) / 2 ;
2016-10-16 13:13:34 +02:00
}
if ( what _do == "zoom" ) {
// Video povečujemo na tak način, da sta zoom in unzoom povečata oz. zmanjšata video za enak korak
// We do this so zoom and unzoom steps change video sizes for the same amount
2016-10-18 23:07:28 +02:00
h = video . height + ( player . height * zoomStep ) ;
w = video . width + ( player . height * zoomStep * ar ) ;
2016-10-16 13:13:34 +02:00
/ * Z a k a j r a č u n a m o š i r i n o n a t a k n a č i n ?
//
// Predstavljajte si, da imamo 2100:900 video v 1600:900 škatli, zoomStep = 0.1. Če bi širino računali po formuli:
//
// širina = širina_videa + (širina zaslona * zoomStep)
//
// Potem bi bila nova velikost videa 2260 x 990. Razmerje stranic: 2.28 (moglo bi biti 2.33 — video je popačen).
// Zaradi tega novo širino rajši povečamo za razliko_v_višini * razmerje_stranic
//
// 2100 + (900 * 0.1 * (2100/900)) =
// 2100 + (90 * 2.333) = 2310
//
// Razmerje stranic (2310x990) je tako 2.333 — tako, kot bi moglo biti.
//
//
// ============================================================================================================
//
// Why did we calculate width this way?
//
// Imagine we have a 2100x900 video in a 1600:900 container, zoomStep = 0.1. If we calculated width using this:
//
// width = video_width + (container_width * zoomStep)
//
// then the new size would be 2260 x 990. This gives us an aspect ratio of 2.28 instead of 2.33 (which is what it
// should be). Because of that we rather increase the width by delta_height * aspect_ratio:
//
// 2100 + (900 * 0.1 * (2100/900)) =
// 2100 + (90 * 2.333) = 2310
//
// This gives us the correct aspect ratio and prevents video deformations.
* /
2016-10-18 23:07:28 +02:00
top = ( player . height - h ) / 2
left = ( player . width - w ) / 2 ;
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
if ( h > player . height * 4 ) {
2016-11-15 22:28:39 +01:00
if ( debugmsg ) {
console . log ( "But this video is ... I mean, it's fucking huge. This is bigger than some rooms, this is bigger than some people's flats!" ) ;
// Insert obligatory omnishambles & coffee machine quote here
console . log ( "(No really, mate, you took this way too far already. Can't let you do that, Dave.)" ) ;
}
2016-10-16 13:13:34 +02:00
return ;
}
}
if ( what _do == "unzoom" ) {
// Video povečujemo na tak način, da sta zoom in unzoom povečata oz. zmanjšata video za enak korak
// We do this so zoom and unzoom steps change video sizes for the same amount
2016-10-18 23:07:28 +02:00
h = video . height - ( player . height * zoomStep ) ;
w = video . width - ( player . height * zoomStep * ar ) ;
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
top = ( player . height - h ) / 2
left = ( player . width - w ) / 2 ;
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
if ( h < player . height * 0.25 ) {
2016-11-15 22:28:39 +01:00
if ( debugmsg ) {
console . log ( "don't you think this is small enough already? You don't need to resize the video all the way down to the size smaller than your penis." ) ;
console . log ( "(if you're a woman, substitute 'penis' with whatever the female equivalent is.)" ) ;
}
2016-10-16 13:13:34 +02:00
return ;
}
}
2016-10-18 23:07:28 +02:00
var dimensions = { h : h , w : w , top : top , left : left } ;
applyCSS ( dimensions ) ;
}
function applyCSS ( dimensions ) {
dimensions . top += "px" ;
dimensions . left += "px" ;
dimensions . w += "px" ;
dimensions . h += "px" ;
$ ( "video" ) . css ( { "width" : dimensions . w , "height" : dimensions . h , "top" : dimensions . top , "left" : dimensions . left } ) ;
2016-10-16 13:13:34 +02:00
2016-10-18 23:07:28 +02:00
if ( debugmsg )
console . log ( "uw::applycss | css applied" ) ;
2016-10-16 13:13:34 +02:00
}
2016-10-18 23:07:28 +02:00
function inIframe ( ) {
2016-10-16 13:13:34 +02:00
try {
return window . self !== window . top ;
} catch ( e ) {
return true ;
}
}
2016-10-22 20:49:15 +02:00
function imageToUrl ( img ) {
return chrome . extension . getURL ( img ) ;
}
2016-10-23 20:47:14 +02:00
function showMenu ( id ) {
if ( debugmsg )
console . log ( "uw::showMenu | toggling menu with id " + id ) ;
document . getElementById ( id ) . classList . toggle ( "show" ) ;
}
function hideMenu ( id ) {
document . getElementById ( id ) . classList . remove ( "show" ) ;
}