diff --git a/js/conf/ExtensionConf.js b/js/conf/ExtensionConf.js index 41c003d..a5407ab 100644 --- a/js/conf/ExtensionConf.js +++ b/js/conf/ExtensionConf.js @@ -2,6 +2,7 @@ if(Debug.debug) console.log("Loading: ExtensionConf.js"); var ExtensionConf = { + basicExtensionMode: "blacklist", extensionMode: "whitelist", // how should this extension work? // 'blacklist' - work everywhere except blacklist // 'whitelist' - only work on whitelisted sites @@ -223,7 +224,8 @@ var ExtensionConf = { // // status, arStatus, statusEmbedded: // - // * enabled — always allow + // * enabled — always allow, full + // * basic — allow, but only the basic version without playerData // * default — allow if default is to allow, block if default is to block // * disabled — never allow // diff --git a/js/lib/Settings.js b/js/lib/Settings.js index 63fc05d..e65cf81 100644 --- a/js/lib/Settings.js +++ b/js/lib/Settings.js @@ -1,3 +1,13 @@ +var ExtensionMode = Object.freeze( + { + AutoDisabled: -2, + Disabled: -1, + Default: 0, + Basic: 1, + Full: 2 + } +); + class Settings { constructor(activeSettings, updateCallback) { @@ -177,6 +187,7 @@ class Settings { // status, arStatus, statusEmbedded: // // * enabled — always allow + // * basic — only allow fullscreen // * default — allow if default is to allow, block if default is to block // * disabled — never allow @@ -190,6 +201,49 @@ class Settings { return this.active.sites[site]; } + getExtensionMode(site) { + if (!site) { + site = window.location.hostname; + + if (!site) { + console.log("[Settings::canStartExtension] window.location.hostname is null or undefined:", window.location.hostname) + console.log("active settings:", this.active) + return ExtensionMode.Disabled; + } + } + + try { + // if site-specific settings don't exist for the site, we use default mode: + if (! this.active.sites[site]) { + if (this.active.extensionMode === "blacklist") { + return ExtensionMode.Full; + } else { + return this.active.basicExtensionMode === "blacklist" ? ExtensionMode.Basic : ExtensionMode.Disabled; + } + } + + if (this.active.sites[site].status === 'enabled') { + return ExtensionMode.Full; + } else if (this.active.sites[site].status === 'basic') { + return ExtensionMode.Basic; + } else if (this.active.sites[site].status === 'default') { + if (this.active.extensionMode === "blacklist") { + return ExtensionMode.Full; + } else { + return this.active.basicExtensionMode === "blacklist" ? ExtensionMode.Basic : ExtensionMode.Disabled; + } + } else { + return ExtensionMode.Disabled; + } + + } catch(e){ + if(Debug.debug){ + console.log("[Settings.js::canStartExtension] Something went wrong — are settings defined/has init() been called?\nSettings object:", this) + } + return ExtensionMode.Disabled; + } + } + canStartExtension(site) { // returns 'true' if extension can be started on a given site. Returns false if we shouldn't run. if (!site) { @@ -202,14 +256,14 @@ class Settings { } } - if (Debug.debug) { - // let's just temporarily disable debugging while recursively calling - // this function to get extension status on current site without duplo - // console logs (and without endless recursion) - Debug.debug = false; - const cse = this.canStartExtension(site); - Debug.debug = true; - } + // if (Debug.debug) { + // // let's just temporarily disable debugging while recursively calling + // // this function to get extension status on current site without duplo + // // console logs (and without endless recursion) + // Debug.debug = false; + // const cse = this.canStartExtension(site); + // Debug.debug = true; + // } try{ // if site is not defined, we use default mode: if (! this.active.sites[site]) { diff --git a/js/lib/VideoData.js b/js/lib/VideoData.js index 8186d9b..fec233d 100644 --- a/js/lib/VideoData.js +++ b/js/lib/VideoData.js @@ -5,15 +5,21 @@ class VideoData { this.video = video; this.destroyed = false; this.settings = settings; + this.pageInfo = pageInfo; + this.extensionMode = pageInfo.extensionMode; + + // POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji) // NOTE: ORDERING OF OBJ INITIALIZATIONS IS IMPORTANT (arDetect needs to go last) - this.player = new PlayerData(this); + if (pageInfo.extensionMode === ExtensionMode.Full) { + this.player = new PlayerData(this); + } this.resizer = new Resizer(this); this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting // player dimensions need to be in: // this.player.dimensions - this.pageInfo = pageInfo; + this.vdid = (Math.random()*100).toFixed(); if (Debug.init) { console.log("[VideoData::ctor] Created videoData with vdid", this.vdid); @@ -101,7 +107,9 @@ class VideoData { this.paused = false; try { this.resizer.start(); - this.player.start(); + if (this.player) { + this.player.start(); + } } catch (e) { if(Debug.debug){ console.log("[VideoData.js::resume] cannot resume for reasons. Will destroy videoData. Error here:", e); diff --git a/js/modules/PageInfo.js b/js/modules/PageInfo.js index 2eb84a2..3e9e99e 100644 --- a/js/modules/PageInfo.js +++ b/js/modules/PageInfo.js @@ -2,13 +2,14 @@ if(Debug.debug) console.log("Loading: PageInfo.js"); class PageInfo { - constructor(comms, settings){ + constructor(comms, settings, extensionMode){ this.hasVideos = false; this.siteDisabled = false; this.videos = []; this.settings = settings; this.lastUrl = window.location.href; + this.extensionMode = extensionMode; this.rescan(RescanReason.PERIODIC); this.scheduleUrlCheck(); diff --git a/js/uw.js b/js/uw.js index c493db5..3cdc801 100644 --- a/js/uw.js +++ b/js/uw.js @@ -50,7 +50,10 @@ class UW { // če smo razširitev onemogočili v nastavitvah, ne naredimo ničesar // If extension is soft-disabled, don't do shit - if(! this.settings.canStartExtension()){ + + extensionMode = this.settings.getExtensionMode(); + + if(extensionMode === ExtensionMode.Disabled){ if(Debug.debug) { console.log("[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED") } diff --git a/res/popup/popup.html b/res/popup/popup.html index 6b6dcbd..b9c673e 100644 --- a/res/popup/popup.html +++ b/res/popup/popup.html @@ -45,7 +45,16 @@