2017-09-24 01:54:46 +02:00
|
|
|
|
if(Debug.debug)
|
|
|
|
|
console.log("\n\n\n\n\n\n ——— Sᴛλʀᴛɪɴɢ Uʟᴛʀᴀᴡɪᴅɪꜰʏ ———\n << ʟᴏᴀᴅɪɴɢ ᴍᴀɪɴ ꜰɪʟᴇ >>\n\n\n\n");
|
2017-04-27 20:03:36 +02:00
|
|
|
|
|
2018-01-02 03:36:29 +01:00
|
|
|
|
// global-ish
|
2018-01-20 22:59:31 +01:00
|
|
|
|
|
2018-01-02 03:36:29 +01:00
|
|
|
|
var _main_last_fullscreen;
|
|
|
|
|
|
2018-01-18 22:34:42 +01:00
|
|
|
|
var _player_dimensions_last;
|
|
|
|
|
|
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
|
2017-12-29 23:34:40 +01:00
|
|
|
|
await Settings.init();
|
2017-12-17 22:56:07 +01:00
|
|
|
|
var scpromise = SitesConf.init();
|
|
|
|
|
var kbpromise = Keybinds.init();
|
2017-12-29 23:34:40 +01:00
|
|
|
|
|
2017-12-17 22:56:07 +01:00
|
|
|
|
ExtensionConf.init();
|
|
|
|
|
|
|
|
|
|
// počakamo, da so nastavitve naložene
|
|
|
|
|
// wait for settings to load
|
|
|
|
|
await scpromise;
|
|
|
|
|
await kbpromise;
|
|
|
|
|
|
2016-11-16 19:52:09 +01:00
|
|
|
|
|
2017-12-17 22:56:07 +01:00
|
|
|
|
if(Debug.debug)
|
|
|
|
|
console.log("configuration should be loaded now");
|
|
|
|
|
// 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)
|
|
|
|
|
console.log("uw::document.ready | document is ready. Starting ar script ...");
|
2017-12-17 22:56:07 +01:00
|
|
|
|
|
2017-12-02 21:09:08 +01:00
|
|
|
|
if(SitesConf.getMode(window.location.hostname) == "blacklist" ){
|
|
|
|
|
if(Debug.debug)
|
|
|
|
|
console.log("uw::document.ready | site", window.location.hostname, "is blacklisted.");
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-17 22:56:07 +01:00
|
|
|
|
if( ExtensionConf.mode == "none" ){
|
2017-12-02 21:09:08 +01:00
|
|
|
|
if(Debug.debug)
|
|
|
|
|
console.log("uw::document.ready | Extension is soft-disabled via popup");
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-12-17 22:56:07 +01:00
|
|
|
|
if( ExtensionConf.mode == "whitelist" && SitesConf.getMode(window.location.hostname) != "whitelist"){
|
2017-12-02 21:09:08 +01:00
|
|
|
|
if(Debug.debug)
|
|
|
|
|
console.log("uw::document.ready | extension is set to run on whitelisted sites only, but site ", window.location.hostname, "is not on whitelist.");
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-29 23:34:40 +01:00
|
|
|
|
|
|
|
|
|
|
2017-12-31 18:26:59 +01:00
|
|
|
|
if(Settings.arDetect.enabled == "global"){
|
|
|
|
|
if(Debug.debug)
|
|
|
|
|
console.log("[uw::main] Aspect ratio detection is enabled. Starting ArDetect");
|
2018-01-20 22:59:31 +01:00
|
|
|
|
// ArDetect.arSetup();
|
2017-12-31 18:26:59 +01:00
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
if(Debug.debug)
|
|
|
|
|
console.log("[uw::main] Aspect ratio detection is disabled. This is in settings:", Settings.arDetect.enabled);
|
|
|
|
|
}
|
2017-01-02 17:45:51 +01:00
|
|
|
|
|
2018-01-11 22:43:25 +01:00
|
|
|
|
browser.runtime.onMessage.addListener(receiveMessage);
|
2018-01-18 22:34:42 +01:00
|
|
|
|
setInterval( ghettoOnChange, 33);
|
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-01-20 22:59:31 +01:00
|
|
|
|
|
|
|
|
|
var _video_recheck_counter = 0;
|
|
|
|
|
var _video_recheck_period = 60; // on this many retries
|
|
|
|
|
|
|
|
|
|
function ghettoOnChange(){
|
|
|
|
|
|
|
|
|
|
if(_video_recheck_counter++ > _video_recheck_period){
|
|
|
|
|
_video_recheck_counter = 0;
|
|
|
|
|
|
|
|
|
|
if(GlobalVars.video === null){
|
|
|
|
|
var video = document.getElementsByTagName("video")[0];
|
|
|
|
|
if(video !== undefined)
|
|
|
|
|
GlobalVars.video = video;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(GlobalVars.video === null)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-01-18 22:34:42 +01:00
|
|
|
|
if(_player_dimensions_last === undefined){
|
2018-01-20 22:59:31 +01:00
|
|
|
|
_player_dimensions_last = PlayerDetect.getPlayerDimensions( GlobalVars.video );
|
2018-01-02 03:36:29 +01:00
|
|
|
|
}
|
2018-01-18 22:34:42 +01:00
|
|
|
|
|
2018-01-20 22:59:31 +01:00
|
|
|
|
var newPlayerDims = PlayerDetect.getPlayerDimensions( GlobalVars.video );
|
|
|
|
|
|
|
|
|
|
if (newPlayerDims == undefined)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
GlobalVars.playerDimeimensions = newPlayerDims;
|
|
|
|
|
|
2018-01-18 22:34:42 +01:00
|
|
|
|
if ( newPlayerDims.width != _player_dimensions_last.width ||
|
|
|
|
|
newPlayerDims.height != _player_dimensions_last.height){
|
|
|
|
|
|
|
|
|
|
Resizer.restore();
|
2018-01-02 03:36:29 +01:00
|
|
|
|
}
|
2018-01-18 22:34:42 +01:00
|
|
|
|
|
|
|
|
|
_player_dimensions_last = newPlayerDims;
|
2018-01-02 03:36:29 +01:00
|
|
|
|
}
|
2017-12-29 23:34:40 +01:00
|
|
|
|
|
2018-01-18 22:34:42 +01:00
|
|
|
|
|
|
|
|
|
var _main_fscheck_tries = 3;
|
|
|
|
|
|
|
|
|
|
// function fullScreenCheck(count) {
|
|
|
|
|
// if(count >= _main_fscheck_tries){
|
|
|
|
|
// if(Debug.debug){
|
|
|
|
|
// console.log("[uw::fullScreenCheck] ok really, I guess.");
|
|
|
|
|
// }
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// var fsnow = FullScreenDetect.isFullScreen();
|
|
|
|
|
//
|
|
|
|
|
// // we restore, always — esp. now that we also do things in non-fullscreen
|
|
|
|
|
//
|
|
|
|
|
// // if(fsnow){
|
|
|
|
|
// // full screen is on
|
|
|
|
|
// // Resizer.restore();
|
|
|
|
|
// // }
|
|
|
|
|
// // else{
|
|
|
|
|
// // Resizer.reset();
|
|
|
|
|
// // }
|
|
|
|
|
//
|
|
|
|
|
// // kaj pa, če je FullScreenDetect vrnil narobno vrednost?
|
|
|
|
|
// // what if FullScreenDetect was not right? Let's verify; if it was wrong we re-trigger it in about 100 ms.
|
|
|
|
|
//
|
|
|
|
|
// if(fsnow != _main_last_fullscreen){
|
|
|
|
|
//
|
|
|
|
|
// // posodobimo vrednost / update value
|
|
|
|
|
// _main_last_fullscreen = fsnow;
|
|
|
|
|
//
|
|
|
|
|
// // če je to res, count pa je večji kot 0, potem smo imeli prav.
|
|
|
|
|
// // if that's the case and count is greater than 0, then we were right at some point.
|
|
|
|
|
// if(Debug.debug && count > 0){
|
|
|
|
|
// console.log("[uw::fullScreenCheck] fucking knew it")
|
|
|
|
|
// }
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// else{
|
|
|
|
|
// // dobili smo event za spremembo celozaslonskega stanja. Stanje se ni spremenilo. Hmmm.
|
|
|
|
|
// // we got an event for fullscreen state change. State is unchanged. Hmmm.
|
|
|
|
|
// if(Debug.debug){
|
|
|
|
|
// console.log("[uw::fullScreenCheck] oh _really_? 🤔🤔🤔 -- fullscreen state", FullScreenDetect.isFullScreen());
|
|
|
|
|
// }
|
|
|
|
|
// count++;
|
|
|
|
|
// setTimeout(fullScreenCheck, 200, count);
|
|
|
|
|
// }
|
|
|
|
|
// console.log("-------------------------------");
|
|
|
|
|
// }
|
|
|
|
|
|
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"){
|
|
|
|
|
var anyVideos = PageInfo.hasVideos();
|
2018-01-08 22:48:45 +01:00
|
|
|
|
|
2018-01-20 22:59:31 +01:00
|
|
|
|
if(Debug.debug)
|
|
|
|
|
console.log("[uw::receiveMessage] returning response:", {response: {"hasVideos": anyVideos }});
|
|
|
|
|
|
2018-01-11 22:43:25 +01:00
|
|
|
|
if(BrowserDetect.usebrowser == "firefox")
|
|
|
|
|
return Promise.resolve({response: {"hasVideos": anyVideos }});
|
|
|
|
|
|
|
|
|
|
sendResponse({response: {"hasVideos":anyVideos}});
|
|
|
|
|
return true;
|
2017-12-30 18:36:08 +01:00
|
|
|
|
}
|
2018-01-10 23:16:07 +01:00
|
|
|
|
else if(message.cmd == "get-config"){
|
|
|
|
|
|
|
|
|
|
var config = {};
|
|
|
|
|
config.videoAlignment = Settings.miscFullscreenSettings.videoFloat;
|
|
|
|
|
config.arConf = {};
|
|
|
|
|
config.arConf.enabled_global = Settings.arDetect.enabled == "global";
|
|
|
|
|
|
|
|
|
|
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});
|
|
|
|
|
|
|
|
|
|
sendResponse({response: config});
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if(message.newAr == "auto"){
|
|
|
|
|
ArDetect.stop(); // just in case
|
|
|
|
|
ArDetect.arSetup();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
ArDetect.stop();
|
|
|
|
|
|
|
|
|
|
// we aren't in full screen, but we will want aspect ratio to be fixed when we go to
|
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);
|
|
|
|
|
|
|
|
|
|
Settings.miscFullscreenSettings.videoFloat = message.newFloat;
|
|
|
|
|
Settings.save();
|
|
|
|
|
}
|
2017-12-30 18:36:08 +01:00
|
|
|
|
else if(message.cmd == "stop-autoar"){
|
2017-12-29 23:34:40 +01:00
|
|
|
|
ArDetect.stop();
|
|
|
|
|
}
|
2017-12-30 18:36:08 +01:00
|
|
|
|
else if(message.cmd == "reload-settings"){
|
2017-12-29 23:34:40 +01:00
|
|
|
|
Settings.reload();
|
|
|
|
|
}
|
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-20 22:59:31 +01:00
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
main();
|
|
|
|
|
});
|