diff --git a/src/ext/lib/comms/CommsClient.js b/src/ext/lib/comms/CommsClient.js index 82c7d78..5b2a5e1 100644 --- a/src/ext/lib/comms/CommsClient.js +++ b/src/ext/lib/comms/CommsClient.js @@ -160,7 +160,7 @@ class CommsClient { console.log(`[CommsClient::registerVideo] <${this.commsId}>`, "Registering video for current page."); } if (this.pageInfo) { - if (this.pageInfo.videos.length) { + if (this.pageInfo.hasVideo()) { this.port.postMessage({cmd: "has-video"}); } } else { diff --git a/src/ext/lib/video-data/PageInfo.js b/src/ext/lib/video-data/PageInfo.js index bb74628..12b5e51 100644 --- a/src/ext/lib/video-data/PageInfo.js +++ b/src/ext/lib/video-data/PageInfo.js @@ -9,7 +9,7 @@ if(Debug.debug) class PageInfo { - constructor(comms, settings, extensionMode){ + constructor(comms, settings, extensionMode, readOnly = false){ this.hasVideos = false; this.siteDisabled = false; this.videos = []; @@ -28,6 +28,8 @@ class PageInfo { this.scheduleUrlCheck(); this.currentZoomScale = 1; + + console.log("PAGEINFO: STARTING IN READ ONLY MODE?", readOnly) } destroy() { @@ -93,6 +95,11 @@ class PageInfo { return document.getElementsByTagName('video'); } + hasVideo() { + console.log("DO WE HAVE VIDEO?", this.readOnly ? this.hasVideos : this.videos.length) + return this.readOnly ? this.hasVideos : this.videos.length; + } + rescan(rescanReason){ const oldVideoCount = this.videos.length; @@ -124,6 +131,17 @@ class PageInfo { // if video lacks either of the two properties, we skip all further checks cos pointless if(video.offsetWidth && video.offsetHeight){ this.hasVideos = true; + + if (this.readOnly) { + console.log("FOUDN A VIDEO") + // in lite mode, we're done. This is all the info we want, but we want to actually start doing + // things that interfere with the website. We still want to be runnig a rescan, tho. + + if(rescanReason == RescanReason.PERIODIC){ + this.scheduleRescan(RescanReason.PERIODIC); + } + return; + } } else { continue; } @@ -147,6 +165,7 @@ class PageInfo { if (Debug.debug && Debug.periodic && Debug.videoRescan) { console.log("[PageInfo::rescan] found new video candidate:", video, "NOTE:: Video initialization starts here:\n--------------------------------\n") } + v = new VideoData(video, this.settings, this); // console.log("[PageInfo::rescan] v is:", v) v.initArDetection(); diff --git a/src/ext/uw.js b/src/ext/uw.js index 37a3aea..584dc6b 100644 --- a/src/ext/uw.js +++ b/src/ext/uw.js @@ -65,15 +65,23 @@ class UW { console.log("[uw::init] Extension mode:" + (extensionMode < 0 ? "disabled" : extensionMode == '1' ? 'basic' : 'full')); } - if(extensionMode === ExtensionMode.Disabled){ - if(Debug.debug) { + const isSiteDisabled = extensionMode === ExtensionMode.Disabled + + if (isSiteDisabled) { + if (this.settings.getExtensionMode('@global') === ExtensionMode.Disabled) { + if (Debug.debug) { + console.log("[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED") + } console.log("[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED") + return; } - return; } try { - this.pageInfo = new PageInfo(this.comms, this.settings, extensionMode); + if (isSiteDisabled) { + console.log("STARTING EXTENSION IN READ ONLY MODE") + } + this.pageInfo = new PageInfo(this.comms, this.settings, extensionMode, isSiteDisabled); if(Debug.debug){ console.log("[uw.js::setup] pageInfo initialized. Here's the object:", this.pageInfo); } @@ -83,11 +91,14 @@ class UW { console.log("[uw.js::setup] will try to initate ActionHandler. Settings are:", this.settings, this.settings.active) } - this.actionHandler = new ActionHandler(this.pageInfo); - this.actionHandler.init(); - - if(Debug.debug) { - console.log("[uw.js::setup] ActionHandler initiated:", this.actionHandler); + // start action handler only if extension is enabled for this site + if (!isSiteDisabled) { + this.actionHandler = new ActionHandler(this.pageInfo); + this.actionHandler.init(); + + if(Debug.debug) { + console.log("[uw.js::setup] ActionHandler initiated:", this.actionHandler); + } } } catch (e) {