diff --git a/js/conf/ExtensionConf.js b/js/conf/ExtensionConf.js new file mode 100644 index 0000000..5bbe740 --- /dev/null +++ b/js/conf/ExtensionConf.js @@ -0,0 +1,15 @@ +// blacklist - ban blacklist. +// whitelist - ban all except whitelist +// none - ban all +var _ec_mode = "blacklist" + + +var _ec_init = function() { + console.log("pls implement"); + console.log("this: ", this); +} + +ExtensionConf = { + mode: _ec_mode, + init: _ec_init +} diff --git a/js/conf/Keybinds.js b/js/conf/Keybinds.js index 31c4446..eacf5a2 100644 --- a/js/conf/Keybinds.js +++ b/js/conf/Keybinds.js @@ -55,7 +55,7 @@ var DEFAULT_KEYBINDINGS = [ key: "a", modifiers: [] } -}; +]; // functions @@ -70,12 +70,12 @@ var _kbd_callback = function(keys) { } var _kbd_setup_init = function() { - StorageManager.getopt("keybinds", _kbd_callback); + return StorageManager.getopt("keybinds", _kbd_callback); } -var _kbd_setup_apply = function(var keybinds){ +var _kbd_setup_apply = function(keybinds){ if(Debug.debug || Debug.keyboard) console.log("uw::keydownSetup | starting keybord shortcut setup"); @@ -161,6 +161,6 @@ var _kbd_setup_apply = function(var keybinds){ // _kbd_setup_init(); var Keybinds = { - init: _kbd_setup_init(), - apply: _kbd_setup_apply() + init: _kbd_setup_init, + apply: _kbd_setup_apply } diff --git a/js/conf/Settings.js b/js/conf/Settings.js index 8fde9f1..29351bc 100644 --- a/js/conf/Settings.js +++ b/js/conf/Settings.js @@ -4,6 +4,10 @@ if(Debug.debug) console.log("Loading: Settings.js"); +var _se_init = function(){ + console.log("pls load settings from localstorage here"); +} + Settings = { arDetect: { enabled: "global", @@ -17,5 +21,6 @@ Settings = { }, miscFullscreenSettings: { videoFloat: "center", - } + }, + init: _se_init } diff --git a/js/conf/SitesConf.js b/js/conf/SitesConf.js index 8fde3d8..5e179fa 100644 --- a/js/conf/SitesConf.js +++ b/js/conf/SitesConf.js @@ -42,10 +42,10 @@ var _sc_prepareNonfsPlayer = function(){ } var _sc_getMode = function(site){ - if(! SITES[site] ) + if(! this.sites[site] ) return "global"; - return SITES[site].enabled; + return this.sites[site].enabled; } @@ -53,14 +53,14 @@ var _sc_getMode = function(site){ var _sc_callback = function(conf) { if (conf === null || conf === {} || conf === [] || conf == ""){ StorageManager.setopt( {"sitesconf": _sc_SITES} ); - SITES = _sc_SITES; + this.sites = _sc_SITES; } - SITES = conf; + this.sites = conf; } var _sc_init = function() { - StorageManager.getopt("sitesconf", _kbd_callback); + return StorageManager.getopt("sitesconf", _sc_callback); } @@ -129,22 +129,13 @@ var _sc_SITES = { } } } - "vid.me": { - enabled: "global", - type: "official", - autoAr: { - passive: false; - active: true; - nonfs: true; - } - } } -_sc_init(); - var SitesConf = { nonfsArDetectEnabled: _sc_nonfsAutoar, getPlayerTag: _sc_getPlayerTag, prepareNonfsPlayer: _sc_prepareNonfsPlayer, - getMode: _sc_getMode + getMode: _sc_getMode, + init: _sc_init, + sites: null } diff --git a/js/conf/uiconf.js b/js/conf/uiconf.js deleted file mode 100644 index 6d8377a..0000000 --- a/js/conf/uiconf.js +++ /dev/null @@ -1,116 +0,0 @@ - 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" - } - } - - diff --git a/js/lib/StorageManager.js b/js/lib/StorageManager.js index 48a65ab..ab2ba07 100644 --- a/js/lib/StorageManager.js +++ b/js/lib/StorageManager.js @@ -2,16 +2,16 @@ // setopt, getopt, delopt. They set/get/delete stuff from the storage var _sm_setopt = function(item){ - browser.storage.local.set(item); + return browser.storage.local.set(item); } var _sm_getopt = function(prop, callback){ if(BrowserDetect.usebrowser == "chrome") - browser.storage.local.get(prop, callback); + return browser.storage.local.get(prop, callback); else - browser.storage.local.get(prop).then(callback); + return browser.storage.local.get(prop).then(callback); } var _sm_delopt = function(item){ - browser.storage.local.remove(item); + return browser.storage.local.remove(item); } var StorageManager = { diff --git a/js/uw.js b/js/uw.js index 41c9105..a841f02 100644 --- a/js/uw.js +++ b/js/uw.js @@ -3,15 +3,33 @@ if(Debug.debug) // load all settings from localStorage: +async function main(){ + if(Debug.debug) + console.log("loading configuration ..."); -// start autoar and setup everything + // load settings + Settings.init(); + var scpromise = SitesConf.init(); + var kbpromise = Keybinds.init(); + + ExtensionConf.init(); + console.log(scpromise); + + // počakamo, da so nastavitve naložene + // wait for settings to load + await scpromise; + await kbpromise; -$(document).ready(function() { + if(Debug.debug) + console.log("configuration should be loaded now"); + // start autoar and setup everything + + +// $(document).ready(function() { if(Debug.debug) console.log("uw::document.ready | document is ready. Starting ar script ..."); -// - + if(SitesConf.getMode(window.location.hostname) == "blacklist" ){ if(Debug.debug) console.log("uw::document.ready | site", window.location.hostname, "is blacklisted."); @@ -19,13 +37,13 @@ $(document).ready(function() { return; } - if( ExtensionConf.getMode() == "none" ){ + if( ExtensionConf.mode == "none" ){ if(Debug.debug) console.log("uw::document.ready | Extension is soft-disabled via popup"); return; } - if( ExtensionConf.getMode() == "whitelist" && SitesConf.getMode(window.location.hostname) != "whitelist"){ + if( ExtensionConf.mode == "whitelist" && SitesConf.getMode(window.location.hostname) != "whitelist"){ 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."); @@ -34,7 +52,6 @@ $(document).ready(function() { ArDetect.arSetup(); - document.addEventListener("mozfullscreenchange", function( event ) { if(FullScreenDetect.isFullScreen()){ // full screen is on @@ -44,4 +61,7 @@ $(document).ready(function() { } }); -}); +// }); +} + +main(); diff --git a/manifest.json b/manifest.json index 258c69c..3ec90d4 100644 --- a/manifest.json +++ b/manifest.json @@ -17,10 +17,14 @@ "js": [ "js/dep/jquery-3.1.1.js", + "js/lib/BrowserDetect.js", + "js/lib/StorageManager.js", + "js/conf/Debug.js", "js/conf/Settings.js", "js/conf/SitesConf.js", "js/conf/Status.js", + "js/conf/ExtensionConf.js", "js/lib/FullScreenDetect.js",