2018-01-24 23:15:54 +01:00
if ( Debug . debug ) {
2017-09-24 01:54:46 +02:00
console . log ( "\n\n\n\n\n\n ——— Sᴛλʀᴛɪ ɴɢ Uʟᴛʀᴀᴡ ɪ ᴅɪ ꜰʏ ———\n << ʟᴏᴀᴅɪɴɢ ᴍᴀɪɴ ꜰɪʟᴇ >>\n\n\n\n" ) ;
2018-01-24 23:15:54 +01:00
try {
if ( window . self !== window . top ) {
console . log ( "%cWe aren't in an iframe." , "color: #afc, background: #174" ) ;
}
else {
console . log ( "%cWe are in an iframe!" , "color: #fea, background: #d31" , window . self , window . top ) ;
}
} catch ( e ) {
console . log ( "%cWe are in an iframe!" , "color: #fea, background: #d31" ) ;
}
}
2017-12-02 21:09:08 +01:00
// load all settings from localStorage:
2017-01-04 23:23:41 +01:00
2017-12-17 22:56:07 +01:00
async function main ( ) {
if ( Debug . debug )
2017-12-29 23:34:40 +01:00
console . log ( "[uw::main] loading configuration ..." ) ;
2017-12-17 22:56:07 +01:00
// load settings
2018-03-13 23:55:38 +01:00
var isSlave = true ;
await Settings . init ( isSlave ) ;
2017-12-17 22:56:07 +01:00
var scpromise = SitesConf . init ( ) ;
var kbpromise = Keybinds . init ( ) ;
2017-12-29 23:34:40 +01:00
2018-04-25 20:39:52 +02:00
// reset current css stuff in GlobalVars
GlobalVars . correctedVideoDimensions . top = null ;
GlobalVars . correctedVideoDimensions . left = null ;
GlobalVars . correctedVideoDimensions . width = null ;
GlobalVars . correctedVideoDimensions . height = null ;
GlobalVars . currentCss = { top : null , left : null } ;
2017-12-17 22:56:07 +01:00
// počakamo, da so nastavitve naložene
// wait for settings to load
await scpromise ;
await kbpromise ;
2018-01-28 02:35:05 +01:00
// globalVars: lastAr type = original
GlobalVars . lastAr = { type : "original" } ;
2017-12-17 22:56:07 +01:00
if ( Debug . debug )
2018-03-11 00:49:29 +01:00
console . log ( "[uw::main] configuration should be loaded now" ) ;
2017-12-17 22:56:07 +01:00
// start autoar and setup everything
2016-11-16 19:52:09 +01:00
2017-12-02 21:09:08 +01:00
2017-09-24 01:54:46 +02:00
if ( Debug . debug )
2018-03-11 00:49:29 +01:00
console . log ( "[uw::main] | document is ready. Starting ar script ..." ) ;
2017-12-17 22:56:07 +01:00
2018-03-11 00:49:29 +01:00
if ( ! SitesConf . isEnabled ( window . location . hostname ) ) {
2017-12-02 21:09:08 +01:00
if ( Debug . debug )
2018-03-11 00:49:29 +01:00
console . log ( "[uw:main] | site" , window . location . hostname , "is blacklisted." ) ;
2017-12-02 21:09:08 +01:00
return ;
2018-02-04 17:39:26 +01:00
}
2017-12-29 23:34:40 +01:00
2018-04-22 14:35:40 +02:00
// if(SitesConf.isArEnabled(window.location.hostname)){
// if(Debug.debug)
// console.log("[uw::main] Aspect ratio detection is enabled. Starting ArDetect");
// ArDetect.arSetup();
// }
// console.log("[uw::main] ExtensionConf:", ExtensionConf);
2018-03-13 23:55:38 +01:00
if ( ExtensionConf . arDetect . mode == "blacklist" ) {
2017-12-31 18:26:59 +01:00
if ( Debug . debug )
2018-03-13 23:55:38 +01:00
console . log ( "[uw::main] Aspect ratio detection is enabled (mode=" , ExtensionConf . arDetect . mode , "). Starting ArDetect" ) ;
2018-02-04 17:39:26 +01:00
ArDetect . arSetup ( ) ;
2017-12-31 18:26:59 +01:00
}
else {
if ( Debug . debug )
2018-03-13 23:55:38 +01:00
console . log ( "[uw::main] Aspect ratio detection is disabled. Mode:" , ExtensionConf . arDetect . mode ) ;
2017-12-31 18:26:59 +01:00
}
2017-01-02 17:45:51 +01:00
2018-01-11 22:43:25 +01:00
browser . runtime . onMessage . addListener ( receiveMessage ) ;
2018-03-08 22:22:42 +01:00
setInterval ( ghettoOnChange , 100 ) ;
2018-02-05 22:46:38 +01:00
setInterval ( ghettoUrlWatcher , 500 ) ;
// ko se na ticevki zamenja video, console.log pravi da ultrawidify spremeni razmerje stranic. preglej element
// in pogled na predvajalnik pravita, da se to ni zgodilo. Iz tega sledi, da nam ticevka povozi css, ki smo ga
// vsilili. To super duper ni kul, zato uvedemo nekaj protiukrepov.
//
// when you change a video on youtube, console.log says that ultrawidify changes aspect ratio. inspect element
// and a look at youtube player, on the other hand, say this didn't happen. It seems that youtube overrides our
// css, and this is super duper uncool. Therefore, extra checks and measures.
setInterval ( Resizer . antiCssOverride , 200 ) ;
2017-12-17 22:56:07 +01:00
}
2018-01-02 03:36:29 +01:00
2018-01-18 22:34:42 +01:00
// tukaj gledamo, ali se je velikost predvajalnika spremenila. Če se je, ponovno prožimo resizer
// here we check (in the most ghetto way) whether player size has changed. If it has, we retrigger resizer.
2018-01-02 03:36:29 +01:00
2018-03-08 22:22:42 +01:00
var _video _recheck _counter = 5 ;
2018-03-07 21:42:40 +01:00
var _video _recheck _period = 1 ; // on this many retries
2018-01-20 22:59:31 +01:00
function ghettoOnChange ( ) {
2018-02-02 00:21:29 +01:00
2018-01-20 22:59:31 +01:00
if ( _video _recheck _counter ++ > _video _recheck _period ) {
_video _recheck _counter = 0 ;
2018-02-04 17:39:26 +01:00
if ( GlobalVars . video == null ||
GlobalVars . video == undefined ||
GlobalVars . video . videoWidth == 0 ||
GlobalVars . video . videoHeight == 0 ) {
2018-01-20 22:59:31 +01:00
var video = document . getElementsByTagName ( "video" ) [ 0 ] ;
2018-02-04 17:39:26 +01:00
if ( video !== undefined &&
video !== null &&
video . videoWidth > 0 &&
video . videoHeight > 0 ) {
2018-02-06 00:36:48 +01:00
if ( Debug . debug ) {
console . log ( "%c[uw::ghettoOnChange] detected video. registering!" , "color: #99f, background: #000" ) ;
2018-04-25 20:39:52 +02:00
console . log ( "[uw::ghettoOnChange] just for shits and giggles, let's see what's happened with GlobalVars.playerDimensions:" , GlobalVars . playerDimensions )
2018-02-06 00:36:48 +01:00
}
2018-04-25 20:39:52 +02:00
// zaznali smo novo <video> značko. Zaradi tega bomo resetirali GlobalVars.playerDimensions
// a new <video> has been detected. We'll be resetting GlobalVars.playerDimensions
GlobalVars . playerDimensions = PlayerDetect . getPlayerDimensions ( video ) ;
2018-01-20 22:59:31 +01:00
GlobalVars . video = video ;
2018-01-27 20:27:11 +01:00
Comms . sendToBackgroundScript ( { "cmd" : "register-video" } ) ;
2018-01-26 00:09:08 +01:00
}
2018-01-20 22:59:31 +01:00
}
}
2018-04-22 15:11:48 +02:00
if ( ! GlobalVars . video )
2018-01-20 22:59:31 +01:00
return ;
2018-02-26 22:38:17 +01:00
if ( GlobalVars . playerDimensions == null ) {
GlobalVars . playerDimensions = PlayerDetect . getPlayerDimensions ( GlobalVars . video ) ;
if ( GlobalVars . playerDimensions == undefined ) {
GlobalVars . playerDimensions = null ;
return ;
}
2018-01-02 03:36:29 +01:00
}
2018-01-18 22:34:42 +01:00
2018-02-26 22:38:17 +01:00
if ( PlayerDetect . checkPlayerSizeChange ( ) ) {
2018-03-14 23:51:13 +01:00
if ( Debug . debug ) {
console . log ( "[uw::ghettoOnChange] change detected" ) ;
}
2018-02-26 22:38:17 +01:00
GlobalVars . playerDimensions = PlayerDetect . getPlayerDimensions ( GlobalVars . video ) ;
if ( GlobalVars . playerDimensions == undefined ) {
GlobalVars . playerDimensions = null ;
return ;
}
2018-01-18 22:34:42 +01:00
2018-04-22 15:11:48 +02:00
Resizer . restore ( ) ; // note: this returns true if change goes through, false otherwise.
2018-01-02 03:36:29 +01:00
}
2018-03-14 23:51:13 +01:00
// sometimes, checkPlayerSizeChange might not detect a change to fullscreen. This means we need to
// trick it into doing that
if ( GlobalVars . playerDimensions . fullscreen != PlayerDetect . isFullScreen ( ) ) {
if ( Debug . debug ) {
console . log ( "[uw::ghettoOnChange] fullscreen switch detected" ) ;
}
GlobalVars . playerDimensions = PlayerDetect . getPlayerDimensions ( GlobalVars . video ) ;
if ( GlobalVars . playerDimensions == undefined ) {
GlobalVars . playerDimensions = null ;
return ;
}
Resizer . restore ( ) ;
}
2018-01-02 03:36:29 +01:00
}
2017-12-29 23:34:40 +01:00
2018-02-05 22:46:38 +01:00
function ghettoUrlWatcher ( ) {
if ( GlobalVars . lastUrl != window . location . href ) {
if ( Debug . debug ) {
console . log ( "[uw::ghettoUrlWatcher] URL has changed. Trying to retrigger autoAr" ) ;
}
GlobalVars . video = null ;
GlobalVars . lastUrl = window . location . href ;
2018-04-22 15:11:48 +02:00
// Resizer.reset();
2018-02-05 22:46:38 +01:00
main ( ) ;
}
}
2018-02-01 00:26:16 +01:00
2018-01-18 22:34:42 +01:00
2017-12-29 23:34:40 +01:00
// comms
2018-01-11 22:43:25 +01:00
function receiveMessage ( message , sender , sendResponse ) {
2017-12-29 23:34:40 +01:00
if ( Debug . debug )
console . log ( "[uw::receiveMessage] we received a message." , message ) ;
2017-12-30 18:36:08 +01:00
if ( message . cmd == "has-videos" ) {
2018-01-24 23:15:54 +01:00
var anyVideos = GlobalVars . video != null ;
2018-01-08 22:48:45 +01:00
2018-01-20 22:59:31 +01:00
if ( Debug . debug )
2018-01-24 23:15:54 +01:00
console . log ( "[uw::receiveMessage] are there any videos on this page?" , anyVideos , GlobalVars . video , this ) ;
2018-01-20 22:59:31 +01:00
2018-01-11 22:43:25 +01:00
if ( BrowserDetect . usebrowser == "firefox" )
return Promise . resolve ( { response : { "hasVideos" : anyVideos } } ) ;
2018-01-27 20:13:23 +01:00
try {
sendResponse ( { response : { "hasVideos" : anyVideos } } ) ;
return true ;
}
catch ( chromeIsShitError ) { }
return ;
2017-12-30 18:36:08 +01:00
}
2018-01-10 23:16:07 +01:00
else if ( message . cmd == "get-config" ) {
var config = { } ;
2018-03-13 23:55:38 +01:00
config . videoAlignment = ExtensionConf . miscFullscreenSettings . videoFloat ;
2018-01-10 23:16:07 +01:00
config . arConf = { } ;
2018-03-13 23:55:38 +01:00
config . arConf . enabled _global = ExtensionConf . arDetect . enabled == "global" ;
2018-01-10 23:16:07 +01:00
2018-03-11 18:00:47 +01:00
2018-01-10 23:16:07 +01:00
var keybinds = Keybinds . getKeybinds ( ) ;
if ( Debug . debug )
console . log ( "[uw-bg::_uwbg_rcvmsg] Keybinds.fetch returned this:" , keybinds ) ;
config . keyboardShortcuts = keybinds ;
// predvidevajmo, da je enako. Če je drugače, bomo popravili ko dobimo odgovor
// assume current is same as global & change that when you get response from content script
config . arConf . enabled _current = ArDetect . isRunning ( ) ;
2018-01-11 22:43:25 +01:00
if ( BrowserDetect . usebrowser == "firefox" )
return Promise . resolve ( { response : config } ) ;
2018-01-27 20:13:23 +01:00
try {
sendResponse ( { response : config } ) ;
}
catch ( chromeIsShitError ) { } ;
2018-01-11 22:43:25 +01:00
return true ;
2017-12-30 18:36:08 +01:00
}
2018-01-08 22:48:45 +01:00
2017-12-30 18:36:08 +01:00
else if ( message . cmd == "force-ar" ) {
2017-12-29 23:34:40 +01:00
if ( Debug . debug )
console . log ( "[uw::receiveMessage] we're being commanded to change aspect ratio to" , message . newAr ) ;
2018-02-01 00:26:16 +01:00
if ( message . arType == "legacy" ) {
ArDetect . stop ( ) ;
Resizer . legacyAr ( message . newAr ) ;
2017-12-29 23:34:40 +01:00
}
else {
ArDetect . stop ( ) ;
2018-01-18 22:34:42 +01:00
Resizer . setAr ( message . newAr ) ;
2017-12-29 23:34:40 +01:00
}
2017-12-30 18:36:08 +01:00
}
else if ( message . cmd == "force-video-float" ) {
2017-12-29 23:34:40 +01:00
if ( Debug . debug )
console . log ( "[uw::receiveMessage] we're aligning video to" , message . newFloat ) ;
2018-03-13 23:55:38 +01:00
ExtensionConf . miscFullscreenSettings . videoFloat = message . newFloat ;
Settings . save ( ExtensionConf ) ;
2017-12-29 23:34:40 +01:00
}
2017-12-30 18:36:08 +01:00
else if ( message . cmd == "stop-autoar" ) {
2017-12-29 23:34:40 +01:00
ArDetect . stop ( ) ;
}
2018-03-13 23:55:38 +01:00
else if ( message . cmd == "update-settings" ) {
if ( Debug . debug ) {
console . log ( "[uw] we got sent new ExtensionConf to abide by:" , cmd . newConf ) ;
}
ExtensionConf = cmd . newConf ;
2017-12-29 23:34:40 +01:00
}
2018-03-13 23:55:38 +01:00
// else if(message.cmd == "enable-autoar"){
// if(Debug.debug){
// console.log("[uw] enabling autoar.");
// }
// ExtensionConf.autoAr.mode == "blacklist";
// Settings.save(ExtensionConf);
// }
// else if(message.cmd == "disable-autoar"){
// if(Debug.debug){
// console.log("[uw] disabling autoar.");
// }
// ExtensionConf.autoAr.mode == "disabled";
// Settings.save(ExtensionConf);
// }
2018-01-10 23:16:07 +01:00
if ( message . cmd == "testing" ) {
2018-01-11 22:43:25 +01:00
if ( Browserdetect . usebrowser = "firefox" )
return Promise . resolve ( { response : "test response hier" } ) ;
sendResponse ( { response : "test response hier" } ) ;
return true ;
2018-01-10 23:16:07 +01:00
}
2017-12-29 23:34:40 +01:00
}
2017-12-30 02:58:24 +01:00
2018-01-24 23:15:54 +01:00
// $(document).ready(function() {
2018-01-20 22:59:31 +01:00
main ( ) ;
2018-01-24 23:15:54 +01:00
// });