2017-04-27 20:03:36 +02:00
// Autogenerated using buildext. This file should not be modified — modify source files instead.
2017-05-23 21:00:38 +02:00
//BEGIN included from lib/debuginit.js
var debugmsg = true ;
var debugmsg _click = false ;
var debugmsg _message = false ;
var debugmsg _autoar = false ;
var debugmsg _periodic = false ;
var debugmsg _ui = true ;
var force _conf _reload = true ;
if ( debugmsg || debugmsg _click || debugmsg _message || debugmsg _autoar ) {
console . log ( "\n\n\n\n\n\n\n\n\n\n\n\n\n\n. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " ) ;
console . log ( "\nLoading ultrawidify (uw)\nIf you can see this, extension at least tried to load\n\nRandom number: " , Math . floor ( Math . random ( ) * 20 ) + 1 , "\n" ) ;
if ( debugmsg )
console . log ( "Logging all" ) ;
if ( debugmsg _click )
console . log ( "Logging debugmsg_click" ) ;
if ( debugmsg _message )
console . log ( "Logging debugmsg_message" ) ;
if ( debugmsg _autoar )
console . log ( "Logging autoar" ) ;
console . log ( ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " ) ;
}
//END included from lib/debuginit.js
2017-04-27 20:03:36 +02:00
//BEGIN included from conf/uiconf.js
var UW _UI _BUTTONS = {
fitw : {
native _bar : true ,
has _submenu : false ,
button : true ,
icon : "/res/img/ytplayer-icons/fitw.png" ,
text : "Fit to width" ,
onclick : function ( ) { changeCSS ( "fit" , "fitw" ) }
} ,
fith : {
native _bar : true ,
has _submenu : false ,
button : true ,
icon : "/res/img/ytplayer-icons/fith.png" ,
text : "Fit to height" ,
onclick : function ( ) { changeCSS ( "fit" , "fith" ) }
} ,
reset : {
native _bar : true ,
has _submenu : false ,
button : true ,
icon : "/res/img/ytplayer-icons/reset.png" ,
text : "Reset" ,
onclick : function ( ) { changeCSS ( "reset" , "reset" ) }
} ,
zoom : {
native _bar : true ,
has _submenu : false ,
button : true ,
icon : "/res/img/ytplayer-icons/zoom.png" ,
text : "Zoom" ,
onclick : function ( ) { changeCSS ( "fit" , "zoom" ) }
} ,
unzoom : {
native _bar : true ,
has _submenu : false ,
button : true ,
icon : "/res/img/ytplayer-icons/unzoom.png" ,
text : "Unzoom" ,
onclick : function ( ) { changeCSS ( "fit" , "unzoom" ) }
} ,
zoom : {
native _bar : true ,
has _submenu : false ,
button : true ,
icon : "/res/img/ytplayer-icons/zoom.png" ,
text : "Reset" ,
onclick : function ( ) { changeCSS ( "fit" , "zoom" ) }
} ,
autoar : {
native _bar : false ,
has _submenu : false ,
button : false ,
text : "Detect aspect ratio via 3rd party" ,
onclick : function ( ) { manual _autoar ( ) }
} ,
settings : {
native _bar : true ,
button : true ,
icon : "/res/img/ytplayer-icons/settings.png" ,
text : "Settings" ,
has _submenu : true ,
submenu : [ "fitw" , "fith" , "reset" , "zoom" , "unzoom" , "autoar" , "ar" ] ,
top _level : true ,
submenu _id : "uw_settings_menu" ,
onclick : function ( ) { toggleMenu ( "uw_settings_menu" ) }
} ,
ar : {
native _bar : false ,
button : false ,
text : "Force aspect ratio" ,
has _submenu : true ,
submenu : [ "ar219" , "ar169" , "ar1610" , "ar43" ] ,
submenu _id : "uw_force_ar_menu" ,
onclick : function ( ) { showMenu ( "uw_force_ar_menu" ) }
} ,
ar219 : {
native _bar : false ,
button : false ,
text : "21:9" ,
has _submenu : false ,
onclick : function ( ) { changeCSS ( "char" , ( 21 / 9 ) ) ; }
} ,
ar169 : {
native _bar : false ,
button : false ,
text : "16:9" ,
has _submenu : false ,
onclick : function ( ) { changeCSS ( "char" , ( 16 / 9 ) ) ; }
} ,
ar1610 : {
native _bar : false ,
button : false ,
text : "16:10" ,
has _submenu : false ,
onclick : function ( ) { changeCSS ( "char" , ( 1.6 ) ) ; }
} ,
ar43 : {
native _bar : false ,
button : false ,
text : "4:3" ,
has _submenu : false ,
onclick : function ( ) { changeCSS ( "char" , ( 4 / 3 ) ) ; }
}
}
var UW _UI _BANLIST = {
youtube : {
autoar : "all"
} ,
netflix : {
settings : "all"
}
}
//END included from conf/uiconf.js
//BEGIN included from conf/sitesconf.js
var UW _SITES = {
youtube : {
enabled : true ,
type : "official" ,
urlRules : [ "youtu" ] ,
player : {
name : "movie_player" ,
isClass : false ,
} ,
iframe : {
name : "player" ,
isClass : false
} ,
2017-05-23 21:00:38 +02:00
ui : {
uiMode : "native" ,
uiconf : {
sampleButton : {
class : "ytp-button ytp-settings-button" ,
index : 0 ,
buttonSizeBase : "x" ,
} ,
uiParent : {
name : "ytp-right-controls" ,
isClass : true ,
insertStrat : "prepend" ,
} ,
uiOffset : {
offsetBy : "10vh" ,
offsetType : "css"
}
}
2017-04-27 20:03:36 +02:00
} ,
autoar _imdb : {
enabled : false
}
} ,
netflix : {
enabled : true ,
type : "official" ,
urlRules : [ "netflix" ] ,
player : {
name : "placeholder" ,
isClass : true ,
} ,
2017-05-23 21:00:38 +02:00
ui : {
uiMode : "native" ,
uiconf : {
sampleButton : {
class : "ytp-button ytp-settings-button" ,
index : 0 ,
buttonSizeBase : "x" ,
} ,
uiParent : {
name : "player-controls-wrapper" ,
isClass : true ,
insertStrat : "append"
} ,
uiOffset : {
offsetBy : "0px" ,
offsetType : "css"
}
}
2017-04-27 20:03:36 +02:00
} ,
autoar _imdb : {
enabled : true ,
title : "player-status-main-title" ,
isClass : true
}
} ,
dummy : {
type : "add new site" ,
urlRules : [ "" ] ,
player : {
name : "" ,
isClass : false ,
} ,
sampleButton : {
class : "ytp-button ytp-settings-button" ,
index : 0 ,
buttonSizeBase : "x" ,
} ,
uiParent : {
name : "" ,
isClass : false ,
insertStrat : "prepend" ,
} ,
autoar _imdb : {
enabled : false
}
}
}
//END included from conf/sitesconf.js
//BEGIN included from conf/keybinds.js
// Yeah hi /r/badcode.
// Anyway, because nazi localstorage flat out refuses to store arrays:
var DEFAULT _KEYBINDINGS = {
0 : { action : "fitw" ,
key : 'w' ,
modifiers : [ ]
} ,
1 : {
action : "fith" ,
key : 'e' ,
modifiers : [ ]
} ,
2 : {
action : "reset" ,
key : 'r' ,
modifiers : [ ]
} ,
3 : {
action : "zoom" ,
key : "z" ,
modifiers : [ ]
} ,
4 : {
action : "unzoom" ,
key : "u" ,
modifiers : [ ]
} ,
5 : {
action : "char" ,
targetAR : ( 21 / 9 ) ,
key : "d" ,
modifiers : [ ]
} ,
6 : {
action : "char" ,
targetAR : ( 16 / 9 ) ,
key : "s" ,
modifiers : [ ]
} ,
7 : {
action : "char" ,
targetAR : ( 16 / 10 ) ,
key : "x" ,
modifiers : [ ]
} ,
8 : {
action : "char" ,
targetAR : ( 4 / 3 ) ,
key : "c" ,
modifiers : [ ]
} ,
9 : {
action : "autoar" ,
key : "a" ,
modifiers : [ ]
}
} ;
//END included from conf/keybinds.js
//BEGIN included from lib/libopts.js
2017-05-23 21:00:38 +02:00
// setopt, getopt, delopt. Shrani oz. dobi oz. briše stvari iz skladišča
// setopt, getopt, delopt. They set/get/delete stuff from the storage
2017-04-27 20:03:36 +02:00
function setopt ( item ) {
browser . storage . local . set ( item ) ;
}
function getopt ( prop , callback ) {
if ( usebrowser == "chrome" )
browser . storage . local . get ( prop , callback ) ;
else
browser . storage . local . get ( prop ) . then ( callback ) ;
}
2017-05-23 21:00:38 +02:00
function delopt ( item ) {
browser . storage . local . remove ( item ) ;
}
2017-04-27 20:03:36 +02:00
//END included from lib/libopts.js
//BEGIN included from lib/browser_autodetect.js
2017-05-23 21:00:38 +02:00
var browser _autodetect = true ;
2017-04-27 20:03:36 +02:00
usebrowser = "firefox" ;
if ( typeof browser === "undefined" ) { // This means we're probably not on Firefox.
if ( chrome ) {
browser = chrome ;
usebrowser = "chrome" ;
}
}
else {
usebrowser = "firefox" ;
}
//END included from lib/browser_autodetect.js
//BEGIN included from lib/optinit.js
IGNORE _STORAGE _CHANGES = true ;
// getopt( "ultrawidify_uiban", function (opt) {
// if(! opt || opt.ultrawidify_uiban === undefined){
// if(debugmsg)
// console.log("uw::extsetup_uiban | ui ban missing from storage. Setting defaults.");
// browser.storage.local.set({ultrawidify_uiban: UW_UI_BANLIST});
// }
// }
IGNORE _STORAGE _CHANGES = false ;
//END included from lib/optinit.js
2017-05-23 21:00:38 +02:00
//BEGIN included from conf/uwvars.js
//END included from conf/uwvars.js
2017-01-21 18:31:47 +01:00
2017-05-23 21:00:38 +02:00
//BEGIN included from lib/player_ui.js
var UICONF ;
function uinit ( ) {
if ( debugmsg )
console . log ( "player_ui::uinit | initializing elements from the webpage" ) ;
var site = UW _SITES [ SITE ] ;
if ( debugmsg )
console . log ( "player_ui::uinit | site data:" , site , "\n\n\nsite.player.name:" , site . player . name , "\nsite.player.isClass:" , site . player . isClass ) ;
SITE _ENABLED = site . enabled ;
SITE _TYPE = site . type ;
SITE _URL _RULES = site . urlRules ;
SITE _PROPS = site ;
2017-01-15 23:36:47 +01:00
2017-01-21 21:09:36 +01:00
if ( debugmsg )
2017-05-23 21:00:38 +02:00
console . log ( "player_ui::uinit | are we in iframe?" , inIframe ( ) , "does the site have a separate config for iframe?" , site . iframe ? true : false ) ;
2017-01-21 21:09:36 +01:00
2017-05-23 21:00:38 +02:00
if ( inIframe ( ) && site . iframe ) {
console . log ( "player_ui::uinit | we're in iframe." ) ;
PLAYER = site . iframe . isClass ? document . getElementsByClassName ( site . iframe . name ) [ 0 ] : document . getElementById ( site . iframe . name ) ;
}
else {
PLAYER = site . player . isClass ? document . getElementsByClassName ( site . player . name ) [ 0 ] : document . getElementById ( site . player . name ) ;
}
2017-01-15 23:36:47 +01:00
2017-05-23 21:00:38 +02:00
//
if ( site . ui . uiMode == "native" )
NATIVE _UI = true ;
else
NATIVE _UI = false ;
2017-01-21 21:09:36 +01:00
2017-05-23 21:00:38 +02:00
UICONF = site . ui . uiconf ;
2017-01-17 00:15:03 +01:00
2017-05-23 21:00:38 +02:00
console . log ( "player_ui::uinit |\nsite.ui.uiMode: " , site . ui . uiMode , "\nsite.ui.uiMode.uiconf:" , site . ui . uiconf , "\nUICONF: " , UICONF ) ;
IMDB _AUTOAR _ALLOWED = site . autoar _imdb . enabled ;
if ( debugmsg )
console . log ( "player_ui::uinit | initializing elements from the webpage" ) ;
2016-12-04 23:02:15 +01:00
}
2017-01-21 18:31:47 +01:00
2017-05-23 21:00:38 +02:00
function buildUInative ( ) {
/ * * T h i s f u n c t i o n b u i l d s U I i n t h e n a t i v e b a r .
*
* /
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::buildUInative | starting ..." ) ;
if ( ui _anchor ) {
console . log ( "player_ui::buildUInative | anchor found, doing nothing" ) ;
return ;
}
if ( ! ui _anchor )
mkanchor ( ) ;
if ( UW _UI _MODE == "none" ) {
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::buildUInative | usersettings say UI shouldn't be displayed. UI will not be built." ) ;
return ;
}
if ( UW _UI _MODE == "compact" ) {
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::buildUInative | usersettings say UI should be compact if possible. Checking if possible." ) ;
if ( UW _UI _BANLIST [ SITE ] . settings !== undefined && UW _UI _BANLIST [ SITE ] . settings != "noban" ) {
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::buildUInative | compact ui is not possible on this site. Reverting to full." ) ;
UW _UI _MODE == "all" ;
}
}
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::buildUInative | starting to build UI" ) ;
var el ;
if ( UW _UI _MODE == "compact" ) { // no need for loop if all we add is the 'settings' buton
el = UW _UI _BUTTONS . settings ;
uiel = mkbutton ( el ) ;
uiel . appendChild ( mksubmenu ( el ) ) ;
ui _anchor . appendChild ( uiel ) ;
}
else {
for ( key in UW _UI _BUTTONS ) {
el = UW _UI _BUTTONS [ key ] ;
if ( UW _UI _BANLIST [ SITE ] [ key ] ) {
if ( debugmsg )
console . log ( "player_ui::buildUInative | we don't show" , key , "on site" , SITE , ". Doing nothing." ) ;
continue ;
}
if ( ! el . native _bar )
continue ;
var uiel ; //ui element
if ( el . button ) {
uiel = mkbutton ( el ) ;
}
if ( ! uiel )
continue ;
ui _anchor . appendChild ( uiel ) ;
if ( el . has _submenu ) {
uiel . appendChild ( mksubmenu ( el ) ) ;
}
}
}
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::buildUInative | ui finished" ) ;
}
2017-02-13 23:04:21 +01:00
2017-05-23 21:00:38 +02:00
function mksubmenu ( el ) {
var submenu = document . createElement ( "div" ) ;
submenu . id = el . submenu _id ;
submenu . className = "uw_element uw_submenu" ;
for ( var i = 0 ; i < el . submenu . length ; i ++ ) {
if ( UW _UI _BANLIST [ SITE ] [ el . submenu [ i ] ] ) {
if ( debugmsg )
console . log ( "player_ui::mksubmenu | we don't show" , el . submenu [ i ] , "on site" , SITE , ". Doing nothing." ) ;
continue ;
}
submenu . appendChild ( mkmenuitem ( el . submenu [ i ] ) ) ;
}
return submenu ;
}
2017-02-16 23:59:11 +01:00
2017-05-23 21:00:38 +02:00
function mkmenuitem ( key ) {
var el = UW _UI _BUTTONS [ key ] ;
var item = document . createElement ( "div" ) ;
item . textContent = el . text ;
item . className = "uw-setmenu-item uw_element" ;
item . onclick = function ( event ) { event . stopPropagation ( ) ; el . onclick ( ) ; hideAllMenus ( ) ; } ;
if ( el . has _submenu ) {
item . appendChild ( mksubmenu ( el ) ) ;
if ( debugmsg ) {
console . log ( "player_ui::mkmenuitem | we are:" , el , "; do we have parent?" , el . parent , "parent id:" , UW _UI _BUTTONS [ el . parent ] . submenu _id , UW _UI _BUTTONS [ el . parent ] . submenu _id === "uw_settings_menu" ) ;
}
if ( el . parent )
$ ( item ) . on ( "mouseenter" , function ( ) {
// We determine where the submenu goes - to the left or to the right. showMenu handles position,
// this function gets sizes of all objects
var div = document . getElementById ( UW _UI _BUTTONS [ el . parent ] . submenu _id ) ;
var supmenusize = div . getBoundingClientRect ( ) ;
div = document . getElementById ( el . submenu _id ) ;
var submenusize = div . getBoundingClientRect ( ) ;
var playersize = player . getBoundingClientRect ( ) ;
if ( debugmsg )
console . log ( "player_ui::mouseenter | parent menu size:" , supmenusize , "submenu size:" , submenusize , "player size:" , playersize ) ;
showMenu ( el . submenu _id , { parent : supmenusize , submenu : submenusize , player : playersize } ) ;
} ) ;
else
$ ( item ) . on ( "mouseenter" , function ( ) { showMenu ( el . submenu _id ) } ) ;
$ ( item ) . on ( "mouseleave" , function ( ) { hideMenu ( el . submenu _id ) } ) ;
}
return item ;
}
2017-04-27 20:03:36 +02:00
2017-05-23 21:00:38 +02:00
function mkanchor ( ) {
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::mkanchor | starting.\nNATIVE_UI: " , NATIVE _UI ) ;
if ( NATIVE _UI !== true ) {
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::mkanchor | we don't use native UI, calling mkanchor_notify(common=true) to take over" ) ;
mkanchor _notify ( true ) ;
return ;
}
else {
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::mkanchor | will make anchor for notifications, calling mkanchor_notify(common=false)" ) ;
mkanchor _notify ( false ) ;
}
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::mkanchor | anchor for notifications created." ) ;
ui _anchor = document . createElement ( "div" ) ;
ui _anchor . className = "uw_ui_anchor" ;
ui _anchor . id = "uw_ui_anchor" ;
if ( UICONF . uiParent . insertStrat == "prepend" ) {
$ ( document . getElementsByClassName ( UICONF . uiParent . name ) [ 0 ] ) . prepend ( ui _anchor ) ;
}
else {
document . getElementsByClassName ( UICONF . uiParent . name ) [ 0 ] . appendChild ( ui _anchor ) ;
}
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::mkanchor | anchor created." ) ;
}
2017-04-27 20:03:36 +02:00
2017-05-23 21:00:38 +02:00
function mkanchor _notify ( common ) {
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::mkanchor_common | starting.\n\ncommon anchor: " , common , "\nUICONF: " , UICONF , "\nUICONF.uiOffset: " , UICONF . uiOffset ) ;
if ( document . getElementById ( "uw_common_anchor" ) )
return ;
var anchor = document . createElement ( "div" ) ;
anchor . className = "uw_common_anchor" ;
anchor . id = "uw_common_anchor" ;
// Izračunamo zamik zaradi drugih elementov na zaslonu
// Let's calculate offset due to other elements on the screen
var offsetTop = "0px" ;
if ( UICONF . uiOffset . offsetType == "element_id" || UICONF . uiOffset . offsetType == "element_class" ) {
var blockingElement ;
if ( UICONF . uiOffset . offsetType == "element_id" )
blockingElement = document . getElementById ( UICONF . uiOffset . offsetBy ) ;
else
blockingElement = document . getElementsByClassName ( UICONF . uiOffset . offsetBy ) [ 0 ] ;
offsetTop = blockingElement . offsetTop + blockingElement . offsetHeight + "px" ;
}
else if ( UICONF . uiOffset . offsetType == "css" )
offsetTop = UICONF . uiOffset . offsetBy ;
if ( debugmsg || debugmsg _ui )
console . log ( "player_ui::mkanchor_notify | notification box will be offset by this much:" , offsetTop ) ;
var padding = document . createElement ( "div" ) ;
padding . style . width = "100%" ;
padding . style . height = offsetTop ;
anchor . appendChild ( padding ) ;
var notification _box = document . createElement ( "div" ) ;
notification _box . style . width = "50%" ;
notification _box . style . height = "25%" ;
notification _box . textContent = "test box" ;
if ( debugmsg )
console . log ( "player_ui::mkanchor_notify | this is our notification box: " , notification _box ) ;
anchor . appendChild ( notification _box ) ;
PLAYER . appendChild ( anchor ) ;
}
function mkbutton ( el ) {
if ( debugmsg | debugmsg _ui )
console . log ( "player_ui::mkbutton | trying to make a button" , el . text ) ;
var button = document . createElement ( "div" ) ;
button . style . backgroundImage = 'url(' + resourceToUrl ( el . icon ) + ')' ;
button . className += " uw_button uw_element" ;
button . onclick = function ( event ) { event . stopPropagation ( ) ; el . onclick ( ) } ;
if ( debugmsg | debugmsg _ui )
console . log ( "player_ui::mkbutton | button completed" ) ;
return button ;
}
//END included from lib/player_ui.js
2017-01-21 18:31:47 +01:00
2017-01-02 12:29:43 +01:00
const playercheck _recursion _depth _limit = 3 ;
2016-12-04 23:02:15 +01:00
2017-01-21 21:09:36 +01:00
var uw _autoar _default = true ; // true - autoar enabled. False - autoar disabled
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 ;
2017-01-17 22:35:04 +01:00
var last _whatdo = { type : "autoar" , what _do : "reset" } ;
2017-02-20 23:40:47 +01:00
var page _url = window . location . toString ( ) ; // S pomočjo page_url določimo, na kateri spletni strani smo.
var SITE ;
2016-10-20 23:34:45 +02:00
var ctlbar _classnames = [ "ytp-chrome-controls" ] ;
2017-01-04 00:07:34 +01:00
var serviceArray = [ ".video-stream" ] ; //Youtube
2016-10-16 13:13:34 +02:00
2016-10-22 20:49:15 +02:00
var buttons = [ ] ;
2017-04-18 20:48:29 +02:00
var IGNORE _STORAGE _CHANGES = false ;
2017-01-02 12:29:43 +01:00
//BEGIN determining which site we're on and the associated names
var ui _anchor ;
var player ;
var vid _el ;
2017-02-28 20:02:20 +01:00
var SAMPLE _BUTTON _CLASS ; // Class of a sample button
var SAMPLE _BUTTON _INDEX = 0 ; // index of a sample button
2017-01-17 00:15:03 +01:00
var button _size _base = "x" ; // Determines if size of extension buttons is defined by width or height of sample button
var char _strat = "contain" ;
2017-01-17 22:35:04 +01:00
var char _got _ar = false ;
var char _arx ;
var char _ary ;
2017-01-21 22:53:12 +01:00
var autoar _enabled ;
2017-01-02 12:29:43 +01:00
var video _wrap ;
2017-04-18 20:48:29 +02:00
2017-01-04 23:23:41 +01:00
// Here we store the window size, so we know when to trigger css change.
var winsize = { w : window . innerWidth , h : window . innerHeight } ;
2017-01-17 00:15:03 +01:00
// Video title for third party
var title = "" ;
2017-01-04 23:23:41 +01:00
// provider-specific variables
var netflix _cltbar _visibility = - 1 ; // -1 for invisible, anything non-negative for visible
var netflix _periodic _timer ;
2017-01-21 18:31:47 +01:00
// Stuff for other browsers
if ( usebrowser == "chrome" ) {
browser = chrome ;
}
2017-04-27 20:03:36 +02:00
2017-03-13 20:34:59 +01:00
browser . storage . local . set ( { ultrawidify _siterules : UW _SITES } ) ;
2017-02-20 23:40:47 +01:00
//Na reloadu vselej odstrani vmesnik od prej
//Always remove previous UI on extension reload
var previousElements = document . getElementsByClassName ( "uw_element" ) ;
if ( previousElements ) {
while ( previousElements . length > 0 ) {
previousElements [ 0 ] . parentNode . removeChild ( previousElements [ 0 ] ) ;
}
}
2017-01-03 20:56:01 +01:00
function init ( force _reload ) {
2017-01-02 12:29:43 +01:00
if ( debugmsg )
console . log ( "uw::init | starting init" ) ;
2017-02-22 13:53:40 +01:00
2017-02-15 20:34:47 +01:00
var el ;
for ( key in UW _UI _BUTTONS ) {
el = UW _UI _BUTTONS [ key ] ;
if ( el . submenu _id ) {
// We defined submenus. Now let's add parent info to each submenu.
for ( var i = 0 ; i < el . submenu . length ; i ++ ) {
UW _UI _BUTTONS [ el . submenu [ i ] ] . parent = key ;
}
}
}
2017-02-20 23:40:47 +01:00
if ( debugmsg )
2017-05-23 21:00:38 +02:00
console . log ( "uw | %cpage_url: " + page _url , "color: #99F" ) ;
2017-04-27 20:03:36 +02:00
2017-01-02 12:29:43 +01:00
//Youtube:
if ( page _url . indexOf ( "youtu" ) != - 1 ) {
if ( debugmsg )
console . log ( "uw::init | we're on youtube. Page url:" , page _url ) ;
2017-04-27 20:03:36 +02:00
2017-01-02 12:29:43 +01:00
video _wrap = "video-stream" ;
2017-01-02 17:45:51 +01:00
return true ;
2017-01-02 12:29:43 +01:00
}
//Netflix:
if ( page _url . indexOf ( "netflix.com" ) != - 1 ) {
if ( debugmsg )
console . log ( "uw::init | we're on netflix. Page url:" , page _url ) ;
player = document . getElementById ( "playerContainer" ) ;
var tmp = document . getElementsByClassName ( "player-status" ) [ 0 ] ;
if ( ! tmp )
return false ;
vid _el = document . getElementsByTagName ( "video" ) [ 0 ] ;
2017-02-28 20:02:20 +01:00
SAMPLE _BUTTON _CLASS = "player-control-button player-fill-screen" ;
2017-01-02 12:29:43 +01:00
video _wrap = "player-video-wrapper" ;
button _size _base = "y" ;
2017-01-02 17:45:51 +01:00
return true ;
2017-01-02 12:29:43 +01:00
}
2017-01-02 17:45:51 +01:00
return false ;
2017-01-02 12:29:43 +01:00
}
//END
2016-11-29 19:54:05 +01:00
2016-12-04 23:02:15 +01:00
//BEGIN ADDING CSS
// Če ponovno naložimo dodatek, potem odstranimo star CSS. Lahko se zgodi, da je Tam spremenil CSS in hoče
// preveriti, če stvari zgledajo tako kot morajo. Če ima en razred/id več nasprotujoćih si definicij, potem
// nam to lahko povzroča težave. Za uporabnike je načeloma odstranjevanje obstoječega CSS brezpredmetno, ker
// uporabnik ponavadi ne bo reloadal razširitve.
//
// If we reload the extension, then we also remove our old CSS. It can easily happen that Tam changed CSS a bit
// and wants to see if things look roughly the way they should. We do this because if a class/id has multiple
// mutually exclusive definitions, we can get some problems with CSS not working the way it should. People who
// aren't Tam generally don't see the benefit as they won't reload the extension — let alone reload the extension
// after messing with CSS.
2017-04-27 20:03:36 +02:00
2017-02-22 13:53:40 +01:00
var ui _anchor = document . getElementById ( "uw_ui_anchor" ) ;
2016-12-04 23:02:15 +01:00
var uwcss = document . getElementsByClassName ( "uw_css" ) ;
while ( uwcss && uwcss . length > 0 )
uwcss [ 0 ] . parentNode . removeChild ( uwcss [ 0 ] ) ;
// funkcija pomagač za ustvarjanje css linkov
// helper function for creating css links
function addLink ( css _url ) {
var link = document . createElement ( "link" ) ;
link . className = "uw_css" ;
link . setAttribute ( "rel" , "stylesheet" ) ;
link . setAttribute ( "type" , "text/css" ) ;
link . setAttribute ( "href" , resourceToUrl ( css _url ) ) ;
$ ( "head" ) . append ( link ) ;
}
// Vsaka stran dobi uw_common.css
// We add uw_common.css on every page
addLink ( "res/css/uw_common.css" ) ;
// Če smo na Youtube/youtube popupu, dodamo css za youtube elemente
// If we're on youtube/youtube popup, we add css for youtube elements
if ( page _url . indexOf ( "youtu" ) != - 1 ) {
addLink ( "res/css/uw_yt.css" ) ;
}
2017-01-02 12:29:43 +01:00
if ( page _url . indexOf ( "netflix.com" ) != - 1 ) {
addLink ( "res/css/uw_netflix.css" ) ;
}
2016-12-04 23:02:15 +01:00
//END ADDING CSS
2017-01-04 23:23:41 +01:00
2017-02-20 23:40:47 +01:00
2016-12-21 23:25:05 +01:00
var last _location = "" ;
2017-01-19 21:29:54 +01:00
2017-01-21 18:31:47 +01:00
var KEYBINDS = { } ;
2017-01-02 12:29:43 +01:00
//END keybind-related stuff
//BEGIN comms with uw-bg
2017-02-20 23:40:47 +01:00
function extsetup _comms ( ) {
if ( debugmsg )
console . log ( "uw | Setting up comms with background scripts" ) ;
2016-11-16 19:52:09 +01:00
2017-02-20 23:40:47 +01:00
var num _of _msg = 0 ;
browser . runtime . onMessage . addListener ( function ( message , sender , stuff ) {
if ( debugmsg || debugmsg _message )
console . log ( "uw::onMessage | message number: " , num _of _msg ++ , "; message:" , message ) ;
if ( message . message && message . message == "page-change" ) {
if ( document . getElementsByClassName ( "uw_element" ) . length === 0 ) {
if ( debugmsg )
console . log ( "uw::onMessage | page was updated but control buttons aren't there. Trying to readd." )
init ( ) ;
addCtlButtons ( 0 ) ;
}
// We don't do that if we zoomed or unzoomed
if ( last _whatdo . what _do != "zoom" && last _whatdo . what _do != "unzoom" )
changeCSS ( last _whatdo . type , last _whatdo . what _do ) ;
2017-01-03 20:56:01 +01:00
2017-02-20 23:40:47 +01:00
// Velikost gumbov posodobimo v vsakem primeru
// We update the button size in any case
2017-02-22 13:53:40 +01:00
updateUICSS ( ) ;
2017-02-20 23:40:47 +01:00
if ( debugmsg )
console . log ( "uw::onMessage | message number:" , num _of _msg , " »» everything is done. Buttons: " , document . getElementsByClassName ( "uw-button" ) ) ;
2017-01-03 20:56:01 +01:00
}
2017-02-20 23:40:47 +01:00
if ( message . type && message . type == "arInfo" ) {
char _got _ar = true ;
char _arx = message . arx ;
char _ary = message . ary ;
if ( debugmsg || debugmsg _message || debugmsg _autoar )
console . log ( "uw::onMessage | got aspect ratio (" , char _arx , "/" , char _ary , "), launching autochar" ) ;
autochar ( ) ;
}
2017-01-14 15:17:26 +01:00
2017-02-20 23:40:47 +01:00
} ) ;
2016-12-21 23:25:05 +01:00
2017-02-20 23:40:47 +01:00
// browser.runtime.onMessage.addListener(request => {
// console.log("Message from the background script:");
// console.log(request.greeting);
// return Promise.resolve({response: "Hi from content script"});
// });
2017-01-17 00:15:03 +01:00
2017-02-20 23:40:47 +01:00
if ( debugmsg )
console . log ( "uw | Comms with background scripts: done" ) ;
}
2017-01-17 00:15:03 +01:00
//END comms with uw-bg
//BEGIN periodic functions
2017-01-04 23:23:41 +01:00
//Because onUpdated event isn't reliable enough for what we're doing on netflix.
function periodic ( ) {
2017-03-23 13:20:59 +01:00
//NOTE: this entire function needs to be tested if it still works
2017-01-04 23:23:41 +01:00
if ( debugmsg _periodic )
console . log ( "uw::periodic started!" ) ;
if ( document . getElementsByClassName ( "uw_element" ) . length === 0 ) {
if ( debugmsg )
console . log ( "uw::periodic | no buttons detected. Readding." ) ;
init ( ) ;
2017-02-22 13:53:40 +01:00
buildUInative ( ) ;
updateUICSS ( ) ;
2017-01-04 23:23:41 +01:00
}
var w = window . innerWidth ;
var h = window . innerHeight ;
if ( winsize . w != w && winsize . h != h ) {
2017-03-23 13:20:59 +01:00
if ( debugmsg )
console . log ( "uw::periodic | detected change in window size. Triggering css change" ) ;
2017-01-04 23:23:41 +01:00
winsize . w = w ;
winsize . h = h ;
2017-01-14 15:17:26 +01:00
// We don't do that if we zoomed or unzoomed
2017-01-21 18:31:47 +01:00
if ( last _whatdo . what _do != "zoom" && last _whatdo . what _do != "unzoom" /* && last_whatdo.type != "autoar"*/ ) {
2017-01-14 15:17:26 +01:00
changeCSS ( last _whatdo . type , last _whatdo . what _do ) ;
}
2017-03-23 13:20:59 +01:00
2017-02-22 13:53:40 +01:00
updateUICSS ( ) ;
2017-01-04 23:23:41 +01:00
}
2017-03-23 13:20:59 +01:00
if ( SITE _PROPS . uiParent . isClass )
var controls = document . getElementsByClassName ( SITE _PROPS . uiParent . name ) [ 0 ] ;
else
var controls = document . getElementById ( SITE _PROPS . uiParent . name ) ;
2017-01-04 23:23:41 +01:00
if ( controls ) {
if ( debugmsg _periodic )
console . log ( "uw::periodic | we found controls!" ) ;
2017-04-27 20:03:36 +02:00
2017-01-04 23:23:41 +01:00
}
2017-01-21 21:09:36 +01:00
2017-03-23 13:20:59 +01:00
if ( autoar _enabled ) {
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 ) ;
2017-01-17 00:15:03 +01:00
var ntitle = "" ;
//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.
if ( qntitle )
2017-03-23 13:20:59 +01:00
ntitle = titleElement . textContent ;
2017-01-21 21:09:36 +01:00
else {
2017-01-17 22:35:04 +01:00
char _got _ar = false ;
2017-01-21 21:09:36 +01:00
return ;
}
2017-03-23 13:20:59 +01:00
if ( titleElement && ntitle && ntitle != title ) {
2017-01-21 21:09:36 +01:00
if ( debugmsg || debugmsg _message || debugmsg _autoar )
2017-01-17 00:15:03 +01:00
console . log ( "uw::periodic | title changed. New title:" , ntitle , "Old title:" , title ) ;
2017-01-17 22:35:04 +01:00
char _got _ar = false ;
2017-01-17 00:15:03 +01:00
title = ntitle ;
var sending = browser . runtime . sendMessage ( {
type : "gibAspectRatio" ,
title : title
} ) ;
2017-01-21 18:31:47 +01:00
// sending.then( function(){}, function(err1, err2){console.log("uw::periodic: there was an error while sending a message", err1, err2)} );
2017-01-17 00:15:03 +01:00
}
}
2017-01-04 23:23:41 +01:00
}
2017-01-17 00:15:03 +01:00
//END periodic functions
2017-01-04 23:23:41 +01:00
2016-11-16 19:52:09 +01:00
2016-10-16 13:13:34 +02:00
$ ( document ) . ready ( function ( ) {
2016-10-22 20:49:15 +02:00
if ( debugmsg )
2016-12-21 23:25:05 +01:00
console . log ( "uw::document.ready | document is ready. Starting extension setup ..." ) ;
extSetup ( ) ;
} ) ;
//BEGIN EXTENSION SETUP
2017-02-22 13:53:40 +01:00
function extSetup ( force _reload ) {
2016-12-21 23:25:05 +01:00
if ( debugmsg )
console . log ( "==============================================================================================" ) ;
last _location = window . location ;
2016-12-29 19:41:54 +01:00
2017-02-20 23:40:47 +01:00
// SITE = "";
2016-12-29 19:41:54 +01:00
2017-02-22 13:53:40 +01:00
if ( force _reload ) {
ui _anchor . parentNode . removeChild ( ui _anchor ) ;
ui _anchor = null ;
}
2016-12-21 23:25:05 +01:00
if ( debugmsg ) {
2017-02-20 23:40:47 +01:00
console . log ( "uw::extSetup | our current location is:" , last _location , "(page_url says" , page _url , ")" ) ;
2017-01-02 17:45:51 +01:00
console . log ( "uw::extSetup | initiating extension" ) ;
}
var ini = init ( ) ;
if ( debugmsg ) {
console . log ( "uw::extSetup | init exited with" , ini ) ;
2016-12-21 23:25:05 +01:00
console . log ( "uw::extSetup | removing existing keydown event from document (useful if extension was previously loaded and we navigated to a different video)" ) ;
}
$ ( document ) . off ( "keydown" ) ;
2016-10-16 13:13:34 +02:00
2016-12-21 23:25:05 +01:00
if ( debugmsg )
console . log ( "uw::extSetup | setting up keyboard shortcuts" ) ;
2017-01-02 17:45:51 +01:00
2017-01-21 21:09:36 +01:00
loadFromStorage ( ) ;
2017-01-04 23:23:41 +01:00
2017-02-20 23:40:47 +01:00
//extsetup_stage2 gets called in loadFromStorage, on siterules
}
2017-02-22 13:53:40 +01:00
var EXTSETUP _STAGES = {
site : false ,
uiban : false ,
uimode : false ,
}
function stagetracker ( op ) {
2017-02-20 23:40:47 +01:00
if ( op == "clear" ) {
if ( debugmsg )
2017-02-22 13:53:40 +01:00
console . log ( "uw::stagetracker | %cclearing progress (state)" , "color: #fff" ) ;
for ( key in EXTSETUP _STAGES )
EXTSETUP _STAGES [ key ] = false ;
2017-02-20 23:40:47 +01:00
return ;
}
2017-02-22 13:53:40 +01:00
EXTSETUP _STAGES [ op ] = true ;
var all _done = true ;
var unfinished _stages = "" ;
for ( key in EXTSETUP _STAGES ) {
all _done &= EXTSETUP _STAGES [ key ] ;
if ( debugmsg && ! EXTSETUP _STAGES [ key ] ) {
unfinished _stages += "<" + key + "> " ;
}
2017-02-20 23:40:47 +01:00
}
2017-02-22 13:53:40 +01:00
if ( debugmsg )
console . log ( "uw::stagetracker | added stage" , op , all _done ? " | all stages finished" : ( " | missing stages: " + unfinished _stages ) ) ;
return all _done ;
}
2017-05-23 21:00:38 +02:00
2017-02-22 13:53:40 +01:00
function extsetup _stage2 ( op ) {
2017-04-18 20:48:29 +02:00
if ( debugmsg )
console . log ( "uw::extSetup (stage 2) | %cStarting the function. op=" , "color: #fff" , op ) ;
2017-02-22 13:53:40 +01:00
if ( ! stagetracker ( op ) ) {
2017-02-20 23:40:47 +01:00
if ( debugmsg )
2017-02-22 13:53:40 +01:00
console . log ( "uw::extSetup (stage 2) | %cSome stages are still uncompleted, doing nothing." , "color: #fff" ) ;
return false ;
2017-02-20 23:40:47 +01:00
}
2017-04-18 20:48:29 +02:00
extsetup _listener ( ) ;
2017-02-20 23:40:47 +01:00
// SITE se nastavi v funkciji loadFromStorage. Če ni nastavljen, potem nismo na znani/podprti strani
// SITE is set in loadFromStorage. If SITE is still undefined at this point, then we aren't on a known page.
if ( debugmsg ) {
2017-05-23 21:00:38 +02:00
console . log ( "\n\n\n\nuw::extSetup (stage 2) | --------- ENTERING STAGE 2 OF SETUP -----------" ) ;
2017-01-04 23:23:41 +01:00
}
2017-02-20 23:40:47 +01:00
if ( SITE ) {
2017-05-23 21:00:38 +02:00
if ( debugmsg ) {
console . log ( "uw::extSetup (stage 2) | site found, starting config" ) ;
console . log ( "starting uinit ..." ) ;
console . log ( "progress: %c | |" , "background-color: #161211; color: #f51;" )
}
2017-02-28 20:02:20 +01:00
uinit ( ) ;
2017-05-23 21:00:38 +02:00
if ( debugmsg ) {
console . log ( "uw::extSetup (stage 2)\nprogress: %c |===> |\nuinit complete\n\n" , "background-color: #161211; color: #f51;" ) ;
}
2017-02-20 23:40:47 +01:00
keydownSetup ( ) ;
2017-05-23 21:00:38 +02:00
if ( debugmsg )
console . log ( "uw::extSetup (stage 2)\nprogress: %c |=======> |\nkeydownSetup complete\n\n" , "background-color: #161211;color: #f51;" ) ;
2017-02-20 23:40:47 +01:00
extsetup _comms ( ) ;
2017-05-23 21:00:38 +02:00
if ( debugmsg )
console . log ( "uw::extSetup (stage 2)\nprogress: %c |============> |\nextSetup complete; starting buildUInative\n\n" , "background-color: #161211; color: #f51;" ) ;
2017-02-20 23:40:47 +01:00
buildUInative ( ) ;
2017-05-23 21:00:38 +02:00
if ( debugmsg )
console . log ( "uw::extSetup (stage 2)\nprogress: %c |=================> |\nbuildUInative complete\n\n" , "background-color: #161211; color: #f51;" ) ;
2017-02-20 23:40:47 +01:00
updateUICSS ( ) ;
2017-05-23 21:00:38 +02:00
if ( debugmsg )
console . log ( "uw::extSetup (stage 2)\nprogress: %c |========================|\nupdateUICSS complete\n\n" , "background-color: #161211; color: #f51;" ) ;
2017-02-20 23:40:47 +01:00
if ( page _url . indexOf ( "netflix.com" ) != - 1 ) {
console . log ( "uw::extSetup (stage 2) | starting netflix-specific setup steps" ) ;
if ( netflix _periodic _timer )
clearInterval ( netflix _periodic _timer ) ;
netflix _periodic _timer = setInterval ( function ( ) { periodic ( ) ; } , 100 ) ;
}
}
else {
if ( debugmsg ) {
console . log ( "uw::extSetup (stage 2) |%c SITE appears to be undefined. This means we aren't on a known/supported site. Ultrawidify shouldn't be loaded." , 'background-color: #fa6607; color: #000;' , "\n(note: this usually happens once after reloading this extension. If that's the case, chances are everything is fine, since this function runs twice — once with correct page_url and once with wrong one" ) ;
debugger ;
}
}
2016-12-21 23:25:05 +01:00
if ( debugmsg )
2017-02-20 23:40:47 +01:00
console . log ( "======================================[ setup finished ]======================================\n\n\n\n\n" ) ;
2016-12-21 23:25:05 +01:00
}
2017-02-22 13:53:40 +01:00
2017-01-21 21:09:36 +01:00
function loadFromStorage ( ) {
if ( debugmsg || debugmsg _autoar )
console . log ( "uw::loadFromStorage | loading stuff from storage." ) ;
2017-02-20 23:40:47 +01:00
extsetup _stage2 ( "clear" ) ;
2017-02-22 13:53:40 +01:00
getopt ( "ultrawidify_uiban" , function ( data ) {
2017-04-18 20:48:29 +02:00
IGNORE _STORAGE _CHANGES = true ;
2017-02-22 13:53:40 +01:00
extsetup _uiban ( data ) ;
extsetup _stage2 ( "uiban" ) ;
2017-04-18 20:48:29 +02:00
IGNORE _STORAGE _CHANGES = false ;
2017-02-22 13:53:40 +01:00
} ) ;
getopt ( "ultrawidify_siterules" , function ( data ) {
2017-04-18 20:48:29 +02:00
IGNORE _STORAGE _CHANGES = true ;
2017-02-22 13:53:40 +01:00
extsetup _siterules ( data ) ;
2017-04-18 20:48:29 +02:00
console . log ( "sss" ) ;
2017-02-22 13:53:40 +01:00
extsetup _stage2 ( "site" ) ;
2017-04-18 20:48:29 +02:00
IGNORE _STORAGE _CHANGES = false ;
2017-02-22 13:53:40 +01:00
} ) ;
getopt ( "ultrawidify_ui" , function ( data ) {
2017-04-18 20:48:29 +02:00
IGNORE _STORAGE _CHANGES = true ;
2017-02-22 13:53:40 +01:00
extsetup _ui _mode ( data ) ;
2017-04-18 20:48:29 +02:00
console . log ( "sasa" ) ;
2017-02-22 13:53:40 +01:00
extsetup _stage2 ( "uimode" ) ;
2017-04-18 20:48:29 +02:00
IGNORE _STORAGE _CHANGES = false ;
} ) ;
getopt ( "ultrawidify_autoar" , function ( data ) {
IGNORE _STORAGE _CHANGES = true ;
extsetup _autoar ( data )
IGNORE _STORAGE _CHANGES = false ;
} ) ;
getopt ( "ultrawidify_keybinds" , function ( data ) {
IGNORE _STORAGE _CHANGES = true ;
extsetup _keybinds ( data ) ;
IGNORE _STORAGE _CHANGES = false ;
2017-02-22 13:53:40 +01:00
} ) ;
2017-01-21 21:09:36 +01:00
}
2016-12-21 23:25:05 +01:00
function keydownSetup ( ) {
2017-01-02 17:45:51 +01:00
if ( debugmsg )
console . log ( "uw::keydownSetup | starting keybord shortcut setup" ) ;
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 || (
2016-12-21 23:25:05 +01:00
( document . activeElement . getAttribute ( "role" ) != "textbox" ) &&
( document . activeElement . getAttribute ( "type" ) != "text" )
2016-11-15 22:28:39 +01:00
) ) ) {
if ( debugmsg )
console . log ( "We're writing a comment or something. Doing nothing" ) ;
return ;
}
2017-01-17 00:15:03 +01:00
if ( debugmsg || debugmsg _message ) {
2016-12-21 23:25:05 +01:00
// console.log(KEYBINDS);
2016-12-08 22:34:32 +01:00
console . log ( "we pressed a key: " , event . key , " | keydown: " , event . keydown ) ;
2016-12-21 23:25:05 +01:00
if ( event . key == 'p' ) {
console . log ( "uw/keydown: attempting to send message" )
var sending = browser . runtime . sendMessage ( {
2017-01-17 00:15:03 +01:00
type : "debug" ,
message : "Test message, please ignore"
2016-12-21 23:25:05 +01:00
} ) ;
sending . then ( function ( ) { } , function ( ) { console . log ( "uw/keydown: there was an error while sending a message" ) } ) ;
console . log ( "uw/keydown: test message sent! (probably)" ) ;
return ;
}
2016-12-08 22:34:32 +01:00
}
2016-12-21 23:25:05 +01:00
2016-11-16 19:52:09 +01:00
for ( i in KEYBINDS ) {
2016-12-08 22:34:32 +01:00
if ( debugmsg )
console . log ( "i: " , i , "keybinds[i]:" , KEYBINDS [ i ] ) ;
2016-12-21 23:25:05 +01:00
2016-11-16 19:52:09 +01:00
if ( event . key == KEYBINDS [ i ] . key ) {
2016-12-08 22:34:32 +01:00
if ( debugmsg )
console . log ( "Key matches!" ) ;
2016-11-15 22:28:39 +01:00
//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-12-08 22:34:32 +01:00
if ( debugmsg )
console . log ( "we pressed a key: " , event . key , " | mods match?" , mods , "keybinding: " , KEYBINDS [ i ] ) ;
2016-11-15 22:28:39 +01:00
if ( mods ) {
2017-01-09 20:31:07 +01:00
event . stopPropagation ( ) ;
2017-01-21 18:31:47 +01:00
console . log ( "uw::keydown | keys match. Taking action." ) ;
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 ;
}
2017-01-19 21:29:54 +01:00
if ( KEYBINDS [ i ] . action == "autoar" ) {
manual _autoar ( ) ;
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
}
} ) ;
2016-12-21 23:25:05 +01:00
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-12-21 23:25:05 +01:00
}
2016-11-29 19:54:05 +01:00
2017-02-20 23:40:47 +01:00
function extsetup _siterules ( opt ) {
if ( debugmsg )
console . log ( "%cuw::extsetup_siterules | setting up site rules settings" , "color: #88f;" ) ;
2017-02-22 13:53:40 +01:00
// if(usebrowser == "chrome")
2017-02-20 23:40:47 +01:00
var obj = opt ;
2017-02-22 13:53:40 +01:00
// else
// var obj = opt[0];
2017-02-20 23:40:47 +01:00
2017-04-18 20:48:29 +02:00
if ( ! opt || obj . ultrawidify _siterules === undefined ) {
2017-03-02 20:06:53 +01:00
if ( debugmsg )
console . log ( "uw::extsetup_siterules | site url rules missing from storage. Setting defaults." ) ;
browser . storage . local . set ( { ultrawidify _siterules : UW _SITES } ) ;
}
else {
UW _SITES = obj . ultrawidify _siterules ;
}
2017-02-20 23:40:47 +01:00
if ( debugmsg )
console . log ( "uw::extsetup_siterules | UW_SITES:" , UW _SITES , "current site:" , SITE ) ;
var match ;
for ( key in UW _SITES ) {
var el = UW _SITES [ key ] ;
if ( debugmsg ) {
console . log ( "uw::extsetup_siterules | key:" , key , "; el:" , el , location ) ;
}
match = false ;
for ( var i = 0 ; i < el . urlRules . length ; i ++ ) {
if ( debugmsg )
console . log ( "uw::extsetup_siterules | page_url:" , page _url , "; el.urlRules[" + i + "]:" , el . urlRules [ i ] , "; last_location.indexOf(el.urlRules[" + i + "]):" , page _url . indexOf ( el . urlRules [ i ] ) ) ;
match |= page _url . indexOf ( el . urlRules [ i ] ) != - 1 ;
}
if ( match ) {
if ( debugmsg )
console . log ( "uw::extsetup_siterules | we are on site" , key ) ;
SITE = key ;
return true ;
}
}
if ( debugmsg )
console . log ( "%cuw::extsetup_siterules | page_url is unknown or incorrect. Stalling extension setup" , "color:#fa6607" , "\n(NOTE: In some cases, stalling like that could be result of this extension script running twice)" ) ;
debugging
return false ;
}
2017-01-21 18:31:47 +01:00
function extsetup _autoar ( opt ) {
2017-02-20 23:40:47 +01:00
if ( debugmsg )
console . log ( "%cuw::extsetup_autoar | setting up autoar settings" , "color: #88f;" ) ;
2017-02-22 13:53:40 +01:00
// if(usebrowser == "chrome")
2017-02-20 23:40:47 +01:00
var obj = opt ;
2017-02-22 13:53:40 +01:00
// else
// var obj = opt[0];
2017-01-21 22:53:12 +01:00
2017-01-21 21:09:36 +01:00
//Naslov resetiramo v vsakem primeru
//We always reset the title
title = "" ;
2017-01-21 22:53:12 +01:00
if ( obj === undefined )
return ;
2017-04-18 20:48:29 +02:00
2017-01-21 22:53:12 +01:00
if ( obj . ultrawidify _autoar === undefined ) {
2017-01-21 21:09:36 +01:00
if ( debugmsg || debugmsg _autoar )
console . log ( "uw::extsetup_autoar | autoar setting unavailavle in storage. Setting defaults." ) ;
browser . storage . local . set ( { ultrawidify _autoar : uw _autoar _default } ) ;
autoar _enabled = uw _autoar _default ;
2017-01-21 18:31:47 +01:00
}
else
2017-01-21 22:53:12 +01:00
autoar _enabled = obj . ultrawidify _autoar ;
2017-01-21 21:09:36 +01:00
2017-04-18 20:48:29 +02:00
2017-01-21 21:09:36 +01:00
if ( debugmsg || debugmsg _autoar )
console . log ( "uw::extsetup_autoar | autoar" , ( autoar _enabled ? "enabled" : "disabled" ) , "opt: " , opt ) ;
if ( ! autoar _enabled )
last _whatdo = { type : "reset" , what _do : "reset" } ;
2017-01-21 18:31:47 +01:00
}
2017-02-20 23:40:47 +01:00
function extsetup _uiban ( opt ) {
if ( debugmsg )
console . log ( "%cuw::extsetup_uiban | setting uiban" , "color: #88f;" ) ;
2017-04-27 20:03:36 +02:00
if ( ! opt || opt . ultrawidify _uiban === undefined ) {
2017-02-20 23:40:47 +01:00
if ( debugmsg )
console . log ( "uw::extsetup_uiban | ui ban missing from storage. Setting defaults." ) ;
browser . storage . local . set ( { ultrawidify _uiban : UW _UI _BANLIST } ) ;
}
else
2017-04-27 20:03:36 +02:00
UW _UI _BANLIST = opt . ultrawidify _uiban ;
2017-04-18 20:48:29 +02:00
}
function extsetup _listener ( ) {
if ( debugmsg )
console . log ( "uw::extsetup_listener | setting up listeners" ) ;
browser . storage . onChanged . addListener ( function ( ) {
if ( IGNORE _STORAGE _CHANGES ) {
if ( debugmsg )
console . log ( "uw::<storage change> | %c We are ignoring storage changes at the moment. Doing nothing." , "color: #fa6607" )
return ;
}
if ( debugmsg ) {
console . log ( "uw::<storage change> |%c calling extSetup from storage.onChanged" , "color:#99f" ) ;
}
extSetup ( true ) ;
} ) ;
2017-02-20 23:40:47 +01:00
}
2017-03-21 21:23:03 +01:00
function extsetup _ui _mode ( opt ) {
2017-04-18 20:48:29 +02:00
if ( ! opt || opt . ultrawidify _ui === undefined )
2017-02-22 13:53:40 +01:00
UW _UI _MODE = "all" ;
else
UW _UI _MODE = opt . ultrawidify _ui ;
console . log ( "uw::extsetup_ui_mode | ui mode:" , UW _UI _MODE ) ;
}
2017-01-21 18:31:47 +01:00
function extsetup _keybinds ( res ) {
2017-02-20 23:40:47 +01:00
if ( debugmsg )
console . log ( "%cuw::extsetup_keybinds | setting up autoar settings" , "color: #88f;" ) ;
2017-02-22 13:53:40 +01:00
// if(usebrowser == "chrome")
2017-02-20 23:40:47 +01:00
var obj = res ;
2017-02-22 13:53:40 +01:00
// else
// var obj = res[0];
2017-01-21 22:53:12 +01:00
if ( typeof uw _keybinds _storage _set === "undefined" && ( jQuery . isEmptyObject ( obj ) || jQuery . isEmptyObject ( obj . ultrawidify _keybinds ) ) ) {
2017-01-21 18:31:47 +01:00
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 ;
2017-01-21 21:09:36 +01:00
uw _keybinds _storage _set = true ;
2017-01-21 18:31:47 +01:00
}
else {
2017-01-21 22:53:12 +01:00
if ( Object . keys ( obj . ultrawidify _keybinds ) . length == Object . keys ( DEFAULT _KEYBINDINGS ) . length )
KEYBINDS = obj . ultrawidify _keybinds ;
2017-01-21 18:31:47 +01:00
else {
2017-01-21 22:53:12 +01:00
KEYBINDS = obj . ultrawidify _keybinds ;
2017-01-21 18:31:47 +01:00
// remap 4:3 keybind from 'a' to 'c', but only if the keybind wasn't changed
2017-01-21 22:53:12 +01:00
var old _keybinds = Object . keys ( obj . ultrawidify _keybinds ) ;
2017-01-21 18:31:47 +01:00
if ( KEYBINDS [ old _keybinds - 1 ] . key == "a" && KEYBINDS [ old _keybinds - 1 ] . modifiers == [ ] ) {
KEYBINDS [ old _keybinds - 1 ] . key == "c" ;
}
KEYBINDS [ old _keybinds ] = { action : "autoar" , key : "a" , modifiers : [ ] } ;
}
}
2017-01-21 22:53:12 +01:00
// console.log("res. ", obj.ultrawidify_keybinds);
2017-01-21 18:31:47 +01:00
}
2016-11-29 19:54:05 +01:00
//BEGIN UI
2017-01-02 12:29:43 +01:00
function check4player ( recursion _depth ) {
2016-12-21 23:25:05 +01:00
try {
2017-02-28 20:02:20 +01:00
var button _width = document . getElementsByClassName ( SAMPLE _BUTTON _CLASS ) [ SAMPLE _BUTTON _INDEX ] . scrollWidth ;
2016-12-21 23:25:05 +01:00
return true ;
}
catch ( e ) {
// Zato, ker predvajalnik ni vselej prisoten. Če predvajalnik ni prisoten,
// potem tudi knofov ni. Kar pomeni problem.
//
// Because the player isn't always there, and when the player isn't there the buttons aren't, either.
// In that case, the above statement craps out, throws an exception and trashes the extension.
if ( debugmsg )
console . log ( "uw::addCtlButtons | seems there was a fuckup and no buttons were found on this page. No player (and therefore no buttons) found." ) ;
2017-01-02 12:29:43 +01:00
if ( ! recursion _depth )
recursion _depth = 0 ;
// If buttons weren't found, we relaunch init() just
init ( ) ;
return recursion _depth < playercheck _recursion _depth _limit ? check4player ( ++ recursion _depth ) : false ;
2016-12-21 23:25:05 +01:00
}
return false ;
}
2017-02-13 23:04:21 +01:00
2017-02-15 20:34:47 +01:00
function hideAllMenus ( ) {
var el ;
for ( key in UW _UI _BUTTONS ) {
el = UW _UI _BUTTONS [ key ] ;
if ( el . submenu _id )
hideMenu ( el . submenu _id ) ;
}
}
2017-02-13 23:04:21 +01:00
function updateUICSS ( ) {
2017-02-15 20:34:47 +01:00
//BEGIN INIT
2017-02-13 23:04:21 +01:00
var buttons = document . getElementsByClassName ( "uw_button" ) ;
var button _width = getBaseButtonWidth ( ) ;
if ( debugmsg )
console . log ( "uw::updateUICSS | resizing buttons. This are our buttons:" , buttons , " | a button is this wide:" , button _width ) ;
if ( button _width == - 1 || buttons . length == 0 ) { //this means there's no ui
if ( debugmsg )
console . log ( "uw::updateUICSS | UI wasn't detected, stopping" ) ;
return ;
}
if ( debugmsg ) {
console . log ( "uw::updateUICSS | checks passed. Starting to resize ..." ) ;
console . log ( "uw::updateUICSS | we have this many elements:" , buttons . length , buttons ) ;
}
2017-02-15 20:34:47 +01:00
//END INIT
//BEGIN update buttons
2017-02-13 23:04:21 +01:00
for ( var i = 0 ; i < buttons . length ; i ++ ) {
buttons [ i ] . style . width = ( button _width * 0.75 ) + "px" ;
buttons [ i ] . style . height = ( button _width ) + "px" ;
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-12-21 23:25:05 +01:00
2016-10-20 23:34:45 +02:00
2017-02-13 23:04:21 +01:00
//END update buttons
2017-02-15 20:34:47 +01:00
//BEGIN update menus
var el ;
var div ;
for ( key in UW _UI _BUTTONS ) {
el = UW _UI _BUTTONS [ key ] ;
if ( el . submenu _id ) {
div = document . getElementById ( el . submenu _id ) ;
if ( el . top _level ) {
if ( alignToBottom ( ) ) {
div . style . bottom = button _width * 1.2 + "px" ;
}
}
else {
if ( alignToBottom ( ) ) {
div . style . bottom = "0px" ;
}
// this is tricky. We need to find the best place to put the (sub)menu.
}
}
}
2017-02-13 23:04:21 +01:00
2017-02-15 20:34:47 +01:00
//END menus
2017-02-13 23:04:21 +01:00
}
function getBaseButtonWidth ( ) {
try {
// Na različnih straneh širino gumba poberemo na različne načine.
2017-03-23 13:20:59 +01:00
if ( BUTTON _SIZE _BASE == "y" )
2017-02-28 20:02:20 +01:00
return document . getElementsByClassName ( SAMPLE _BUTTON _CLASS ) [ SAMPLE _BUTTON _INDEX ] . scrollHeight ;
2017-02-13 23:04:21 +01:00
else
2017-02-28 20:02:20 +01:00
return document . getElementsByClassName ( SAMPLE _BUTTON _CLASS ) [ SAMPLE _BUTTON _INDEX ] . scrollWidth ;
2017-02-13 23:04:21 +01:00
}
catch ( e ) {
// Zato, ker predvajalnik ni vselej prisoten. Če predvajalnik ni prisoten,
// potem tudi knofov ni. Kar pomeni problem.
//
// Because the player isn't always there, and when the player isn't there the buttons aren't, either.
// In that case, the above statement craps out, throws an exception and trashes the extension.
if ( debugmsg )
console . log ( "uw::getBaseButtonWidth | seems there was a fuckup and no buttons were found on this page. No player (and therefore no buttons) found." ) ;
return - 1 ;
}
}
2017-02-15 20:34:47 +01:00
2017-02-13 23:04:21 +01:00
var align _to = "bottom" ; //TODO — unhardcode
function alignToBottom ( ) {
return align _to == "bottom" ;
}
2017-01-03 20:56:01 +01:00
2016-11-29 19:54:05 +01:00
//END UI
2016-12-21 23:25:05 +01:00
//END EXTENSION SETUP
2016-11-29 19:54:05 +01:00
2016-12-07 23:58:43 +01:00
function onOpen ( ) {
if ( debugmsg )
console . log ( "uw | Options page opened" ) ;
2016-11-15 22:28:39 +01:00
}
2016-12-07 23:58:43 +01:00
function onError ( err ) {
2017-02-13 23:04:21 +01:00
if ( debugmsg ) {
2016-12-07 23:58:43 +01:00
console . log ( ` Error: ${ error } ` ) ;
console . log ( "uw | Error opening the page" , err ) ;
}
2016-11-15 22:28:39 +01:00
}
2016-11-29 19:54:05 +01:00
2016-12-07 23:58:43 +01:00
function showSettings ( ) {
2017-01-02 17:45:51 +01:00
2016-12-07 23:58:43 +01:00
}
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:
2017-02-28 20:02:20 +01:00
var button _width = document . getElementsByClassName ( SAMPLE _BUTTON _CLASS ) [ SAMPLE _BUTTON _INDEX ] . 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-12-04 12:01:38 +01:00
//Sedaj poglejmo še, če lahko v nadzorno vrstico spravimo vse gumbe
//Let's see if we can get all the buttons in the control bar
2017-01-02 12:29:43 +01:00
// var rctl = document.getElementsByClassName("ytp-right-controls")[0];
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
}
2017-01-19 21:29:54 +01:00
function manual _autoar ( ) {
2017-03-23 13:20:59 +01:00
if ( ! SITE _PROPS . autoar _imdb . enabled )
return ;
if ( SITE _PROPS . autoar _imdb . isClass )
var ntitle = document . querySelector ( "." + SITE _PROPS . autoar _imdb . title ) ; // NOTE: needs to be tested
else
var ntitle = document . querySelector ( "#" + SITE _PROPS . autoar _imdb . title ) ; // NOTE: needs to be tested
//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.
if ( ! ntitle )
return ;
var title = ntitle . textContent ;
char _got _ar = false ;
last _whatdo = { type : "autoar" , what _do : "autoar" } ;
var sending = browser . runtime . sendMessage ( {
type : "gibAspectRatio" ,
title : title
} ) ;
2017-01-21 18:31:47 +01:00
// sending.then( function(){}, function(err1, err2){console.log("uw::periodic: there was an error while sending a message", err1, err2)} );
2017-01-19 21:29:54 +01:00
}
2016-10-23 20:47:14 +02:00
function changeCSS ( type , what _do ) {
2017-01-15 23:36:47 +01:00
if ( debugmsg )
2017-03-21 21:23:03 +01:00
console . log ( "uw::changeCSS | starting function. type:" , type , "; what_do:" , what _do , "\nPlayer element is this:" , PLAYER ) ;
2017-01-23 21:18:01 +01:00
// hideMenu("uw-armenu");
// hideMenu("uw-smenu");
2016-10-20 23:34:45 +02:00
2016-10-16 13:13:34 +02:00
2017-01-04 23:23:41 +01:00
var evideo = $ ( "video" ) [ 0 ] ;
2017-01-04 00:07:34 +01:00
2017-01-04 23:23:41 +01:00
if ( ! evideo ) {
if ( debugmsg )
console . log ( "uw::changeCSS | no video element found. Doing nothing." ) ;
return ;
}
2016-10-16 13:13:34 +02:00
2017-01-14 15:48:46 +01:00
var video = { width : evideo . videoWidth , height : evideo . videoHeight } ;
2017-02-28 20:02:20 +01:00
var nplayer = { width : PLAYER . clientWidth , height : PLAYER . clientHeight } ;
2016-10-18 23:07:28 +02:00
2017-01-04 00:07:34 +01:00
if ( debugmsg )
console . log ( "uw::changeCSS | video dimensions:" , video . width , "x" , video . height , "; player:" , nplayer . width , "x" , nplayer . height ) ;
2016-10-18 23:07:28 +02:00
// 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).
2017-01-04 00:07:34 +01:00
last _whatdo = { type : type , what _do : what _do } ;
2016-10-18 23:07:28 +02:00
// -----------------------------------------------------------------------------------------
// Handlanje dejanj se zgodi pod to črto
//
// Handling actions happens below this line
// -----------------------------------------------------------------------------------------
2017-01-17 22:35:04 +01:00
if ( type == "autoar" ) {
autochar ( ) ;
return ;
}
2016-10-23 20:47:14 +02:00
if ( type == "char" ) {
2017-01-04 00:07:34 +01:00
2017-01-02 12:29:43 +01:00
if ( debugmsg )
console . log ( "uw::changeCSS | trying to change aspect ratio." ) ;
2017-01-04 00:07:34 +01:00
2016-10-23 20:47:14 +02:00
// char = CHange Aspect Ratio
2017-01-02 12:29:43 +01:00
char ( what _do , video , nplayer ) ;
2016-10-18 23:07:28 +02:00
return ;
}
if ( what _do == "reset" ) {
2017-01-04 00:07:34 +01:00
2016-10-18 23:07:28 +02:00
if ( debugmsg )
console . log ( "uw::changeCSS | issuing reset." ) ;
2016-10-16 13:13:34 +02:00
2017-01-02 12:29:43 +01:00
resetCSS ( video , nplayer ) ;
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" )
2017-01-02 12:29:43 +01:00
) ) {
if ( debugmsg )
console . log ( "uw::changeCSS | trying to fit width or height" ) ;
2017-01-04 00:07:34 +01:00
2017-01-02 12:29:43 +01:00
changeCSS _nofs ( what _do , video , nplayer ) ;
}
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 ) ;
}
2017-01-17 22:35:04 +01:00
function autochar ( ) {
2017-01-17 00:15:03 +01:00
2017-01-17 22:35:04 +01:00
if ( debugmsg || debugmsg _autoar )
console . log ( "uw::autochar | starting. Did we get ar?" , char _got _ar , "What about arx and ary?" , char _arx , char _ary ) ;
2017-01-17 00:15:03 +01:00
2017-01-17 22:35:04 +01:00
if ( ! char _got _ar )
return ;
2017-01-17 00:15:03 +01:00
2017-01-17 22:35:04 +01:00
if ( ! char _arx || ! char _ary )
return ;
2017-01-17 00:15:03 +01:00
2017-01-17 22:35:04 +01:00
var ar = char _arx / char _ary ;
2017-01-21 21:09:36 +01:00
if ( ar ) {
2017-01-17 22:35:04 +01:00
set _best _fit ( ar ) ;
2017-01-21 21:09:36 +01:00
last _whatdo = { type : "autoar" , what _do : "autoar" } ;
}
2017-01-17 00:15:03 +01:00
}
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 ;
2016-12-08 22:34:32 +01:00
if ( debugmsg ) {
2016-10-18 23:07:28 +02:00
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-12-08 22:34:32 +01:00
}
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 ;
}
2016-12-04 23:02:15 +01:00
// Širina, višina, top, left za nov video
// Width, height, top and left for the new video
2016-10-18 23:07:28 +02:00
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 ) ;
}
2017-01-17 22:35:04 +01:00
// Ta funkcija ugotovi, kako se kvadrat s podanim razmerjem stranic najbolj prilega ekranu
// Predpostavimo, da so ćrne obrobe vselej zgoraj in spodaj, nikoli levo in desno.
//
// This function determines how a rectangle with a given aspect ratio best fits the monitor
// We assume letterbox is always letterbox, never pillarbox.
function set _best _fit ( ar ) {
if ( debugmsg || debugmsg _autoar )
console . log ( "uw::set_best_fit | got ar:" , ar ) ;
2017-02-28 20:02:20 +01:00
var player = { width : PLAYER . clientWidth , height : PLAYER . clientHeight } ;
2017-01-21 18:31:47 +01:00
var player _ar = player . width / player . height ;
2017-01-17 22:35:04 +01:00
var evideo = $ ( "video" ) [ 0 ] ;
var video = { width : evideo . videoWidth , height : evideo . videoHeight } ;
var video _ar = video . width / video . height ;
// Ob predpostavki, da je argument 'ar' pravilen, naračunamo dimenzije videa glede na širino in višino predvajalnika
// Kot rezultat laho dobimo dve možnosti:
// A: naračunana širina je širša, kot naš zaslon —> za računanje uporabimo širino (letterbox zgoraj/spodaj,
// levo/desno pa ne)
// B: naračunana širina je ožja, kot naš zaslon —> za računanje uporabimo višino (letterbox levo/desno,
// zgoraj/spodaj pa ne)
if ( debugmsg || debugmsg _autoar )
console . log ( "uw::set_best_fit | here's all we got. ar:" , ar , "player:" , player , "video:" , video ) ;
var tru _width = player . height * ar ;
var tru _height = player . width / ar ;
var nv = { w : "" , h : "" , top : "" , left : "" } ;
2017-01-21 21:09:36 +01:00
if ( ar >= video _ar ) {
if ( ar >= player _ar ) {
if ( debugmsg || debugmsg _autoar )
console . log ( "uw::set_best_fit | aspect ratio is wider than player ar." )
nv . h = player . width / video _ar ;
nv . w = nv . h * ar ;
}
else {
if ( debugmsg || debugmsg _autoar )
console . log ( "uw::set_best_fit | aspect ratio is narrower than player ar." , ( player . height * ar ) , nv )
nv . w = player . height * ar ;
nv . h = nv . w / video _ar ;
}
2017-01-17 22:35:04 +01:00
}
else {
2017-01-21 21:09:36 +01:00
if ( ar >= player _ar ) {
if ( debugmsg || debugmsg _autoar )
console . log ( "uw::set_best_fit | aspect ratio is wider than player ar." )
nv . h = player . width / ar ;
nv . w = nv . h * video _ar ;
}
else {
if ( debugmsg || debugmsg _autoar )
console . log ( "uw::set_best_fit | aspect ratio is narrower than player ar." , ( player . height * ar ) , nv )
nv . w = player . height * video _ar ;
nv . h = nv . w / ar ;
}
2017-01-17 22:35:04 +01:00
}
2017-01-21 21:09:36 +01:00
if ( debugmsg || debugmsg _autoar )
console . log ( "uw::set_best_fit | new video width and height processed. nv so far:" , nv )
2017-01-17 22:35:04 +01:00
nv . top = ( player . height - nv . h ) / 2 ;
nv . left = ( player . width - nv . w ) / 2 ;
if ( debugmsg || debugmsg _autoar )
console . log ( "uw::set_best_fit | tru width:" , tru _width , "(player width:" , player . width , "); new video size:" , nv ) ;
applyCSS ( nv ) ;
2017-01-21 21:09:36 +01:00
console . log ( "uw::set_best_fit | css applied" ) ;
2017-01-17 22:35:04 +01:00
}
2016-10-18 23:07:28 +02:00
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 ) {
2017-01-02 12:29:43 +01:00
if ( debugmsg ) {
console . log ( "uw::changeCSS_nofs | arguments: what_do:" , what _do , "; video:" , video , "; player:" , player ) ;
}
2016-10-18 23:07:28 +02:00
var w ;
var h ;
var top ;
var left ;
2017-01-02 12:29:43 +01:00
var evideo = $ ( "video" ) [ 0 ] ;
2017-01-14 11:03:53 +01:00
var video = { width : evideo . videoWidth , height : evideo . videoHeight , scrollw : evideo . scrollWidth , scrollh : evideo . scrollWidth } ;
2017-01-02 12:29:43 +01:00
var ar = video . width / video . height ;
if ( debugmsg ) {
console . log ( "uw::changeCSS_nofs | video dimensions:" , video . width , "x" , video . height , "; ar:" , ar ) ;
}
2016-10-18 23:07:28 +02:00
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
2017-01-04 00:07:34 +01:00
if ( debugmsg )
console . log ( "uw::changeCSS_nofs | w:" , w , "; h:" , h ) ;
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
2017-01-14 15:17:26 +01:00
h = video . scrollh + ( player . height * zoomStep ) ;
w = video . scrollw + ( 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
2017-01-14 11:03:53 +01:00
h = video . scrollh - ( player . height * zoomStep ) ;
w = video . scrollw - ( 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 ) ;
}
2017-01-21 18:31:47 +01:00
function applyCSS ( dimensions ) {
2017-01-17 22:35:04 +01:00
dimensions . top = Math . round ( dimensions . top ) + "px" ;
dimensions . left = Math . round ( dimensions . left ) + "px" ;
dimensions . w = Math . round ( dimensions . w ) + "px" ;
dimensions . h = Math . round ( dimensions . h ) + "px" ;
2016-10-18 23:07:28 +02:00
$ ( "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 )
2017-01-02 12:29:43 +01:00
console . log ( "uw::applycss | css applied. Dimensions/pos: w:" , dimensions . w , "; h:" , dimensions . h , "; top:" , dimensions . top , "; left:" , dimensions . left ) ;
2016-10-16 13:13:34 +02:00
}
2016-10-18 23:07:28 +02:00
function inIframe ( ) {
2017-03-21 21:23:03 +01:00
if ( debugmsg )
console . log ( "uw::inIframe | checking if we're in an iframe" ) ;
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
2016-12-04 23:02:15 +01:00
function resourceToUrl ( img ) {
2016-10-22 20:49:15 +02:00
return chrome . extension . getURL ( img ) ;
}
2016-10-23 20:47:14 +02:00
2017-02-16 23:59:11 +01:00
function showMenu ( id , sizes ) {
2017-01-23 21:18:01 +01:00
if ( debugmsg ) {
2017-01-15 18:56:36 +01:00
console . log ( "uw::showMenu | showing menu with id " , id , "\n\n" , document . getElementById ( id ) ) ;
2017-01-23 21:18:01 +01:00
}
2017-02-18 20:19:24 +01:00
var div = document . getElementById ( id ) ;
console . log ( "showMenu | asasdas" , sizes ) ;
div . classList . add ( "show" ) ;
console . log ( "showMenu | asasdas" ) ;
2017-02-16 23:59:11 +01:00
if ( sizes ) {
2017-02-18 20:19:24 +01:00
console . log ( "uw::showMenu" , sizes ) ;
var player _leftmost = sizes . player . left ;
var parent _leftmost = sizes . parent . left ;
var player _rightmost = sizes . player . left + sizes . player . width ;
var parent _rightmost = sizes . parent . left + sizes . parent . width ;
if ( debugmsg ) {
console . log ( "uw::showMenu | space on left:" , parent _leftmost - player _leftmost , "| space on right:" , player _rightmost - parent _rightmost ) ;
}
// if:
// space left of the parent is bigger than space right of the parent
if ( ( parent _leftmost - player _leftmost ) > ( player _rightmost - parent _rightmost ) ) {
//player goes to the left side
if ( debugmsg ) {
console . log ( "uw::showMenu | setting position on the submenu relative to the parent. left:" , - div . getBoundingClientRect ( ) . width )
}
div . style . left = ( - div . getBoundingClientRect ( ) . width ) + "px" ;
}
else {
2017-02-22 13:53:40 +01:00
if ( debugmsg )
alert ( "this wasn't defined yet. pls do this. ctrl+f rivianpoint" ) ;
2017-02-18 20:19:24 +01:00
div . style . left = sizes . parent . width + "px" ;
}
2017-02-15 20:34:47 +01:00
}
2016-12-02 23:30:21 +01:00
}
2017-02-15 20:34:47 +01:00
2016-12-02 23:30:21 +01:00
function toggleMenu ( id ) {
2017-01-15 23:36:47 +01:00
if ( debugmsg || debugmsg _click )
2017-01-15 18:56:36 +01:00
console . log ( "uw::toggleMenu | toggling menu with id" , id , "\n\n" , document . getElementById ( id ) ) ;
2016-10-23 20:47:14 +02:00
document . getElementById ( id ) . classList . toggle ( "show" ) ;
}
function hideMenu ( id ) {
2016-12-02 23:30:21 +01:00
if ( debugmsg )
console . log ( "uw::hideMenu | hiding menu with id " + id ) ;
2017-01-04 00:07:34 +01:00
if ( document . getElementById ( id ) ) //Safety check in case there's no element with such id
document . getElementById ( id ) . classList . remove ( "show" ) ;
2016-10-23 20:47:14 +02:00
}