diff --git a/src/ext/conf/ExtensionConf.js b/src/ext/conf/ExtensionConf.js index ab10aaa..b2a5076 100644 --- a/src/ext/conf/ExtensionConf.js +++ b/src/ext/conf/ExtensionConf.js @@ -927,7 +927,30 @@ var ExtensionConf = { stretch: Stretch.Default, videoAlignment: VideoAlignment.Default, keyboardShortcutsEnabled: ExtensionMode.Default, - + DOM: { + video: { + manual: false, + querySelectors: '', + }, + player: { + manual: true, + useRelativeAncestor: true, + querySelectors: '', + videoAncestor: 1, + playerNodeCss: '', + } + } + // videoElement: { // extra stuff for video tag + // querySelectors: [], // array of strings with css selectors + // userCss: [], // additional styles that user can define for video element + // }, + // playerElement: { + // querySelectors: [], // array of strings with css selectors + // videoAncestor: 1, // if not falsey, the number represents how far up the DOM (in nodes) + // from video the player lies. Can also be object (valid properties are + // 'fullscreen', 'embed' and 'normal') + // userCss: [], + // } }, } } diff --git a/src/ext/lib/Settings.js b/src/ext/lib/Settings.js index 57fff06..91b6eba 100644 --- a/src/ext/lib/Settings.js +++ b/src/ext/lib/Settings.js @@ -236,8 +236,10 @@ class Settings { 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) + if (Debug.debug) { + console.log("[Settings::canStartExtension] window.location.hostname is null or undefined:", window.location.hostname) + console.log("active settings:", this.active) + } return ExtensionMode.Disabled; } } @@ -288,17 +290,17 @@ class Settings { // } try{ // if site is not defined, we use default mode: - if (! this.active.sites[site]) { - return this.active.sites['@global'].mode === ExtensionMode.Enabled; - } + if (! this.active.sites[site]) { + return this.active.sites['@global'].mode === ExtensionMode.Enabled; + } - if(this.active.sites['@global'].mode === ExtensionMode.Enabled) { - return this.active.sites[site].mode !== ExtensionMode.Disabled; - } else if (this.active.sites['@global'].mode === ExtensionMode.Whitelist) { - return this.active.sites[site].mode === ExtensionMode.Enabled; - } else { - return false; - } + if(this.active.sites['@global'].mode === ExtensionMode.Enabled) { + return this.active.sites[site].mode !== ExtensionMode.Disabled; + } else if (this.active.sites['@global'].mode === ExtensionMode.Whitelist) { + return this.active.sites[site].mode === ExtensionMode.Enabled; + } else { + return false; + } } catch(e){ if(Debug.debug){ console.log("[Settings.js::canStartExtension] Something went wrong — are settings defined/has init() been called?\nSettings object:", this) diff --git a/src/ext/lib/video-data/PageInfo.js b/src/ext/lib/video-data/PageInfo.js index a361ecd..2f7cda9 100644 --- a/src/ext/lib/video-data/PageInfo.js +++ b/src/ext/lib/video-data/PageInfo.js @@ -65,11 +65,30 @@ class PageInfo { this.actionHandlerInitQueue = []; } + getVideos(host) { + if (this.settings.active.sites[host] + && this.settings.active.sites[host].DOM + && this.settings.active.sites[host].DOM.video + && this.settings.active.sites[host].DOM.video.manual + && this.settings.active.sites[host].DOM.video.querySelector){ + const videos = document.querySelectorAll(this.settings.active.sites[host].DOM.video.querySelector); + + if (videos.length) { + return videos; + } else { + if (Debug.debug) { + console.log("[PageInfo::getVideos] Finding videos by querySelector failed. Trying fallback mode as well."); + } + } + } + return document.getElementsByTagName('video'); + } + rescan(rescanReason){ const oldVideoCount = this.videos.length; try{ - var vids = document.getElementsByTagName('video'); + var vids = this.getVideos(window.location.host); if(!vids || vids.length == 0){ this.hasVideos = false; diff --git a/src/ext/lib/video-data/PlayerData.js b/src/ext/lib/video-data/PlayerData.js index d11defb..8ce595f 100644 --- a/src/ext/lib/video-data/PlayerData.js +++ b/src/ext/lib/video-data/PlayerData.js @@ -224,16 +224,115 @@ class PlayerData { } + collectionHas(collection, element) { + for (let i = 0, len = a.length; i < len; i++) { + if (a[i] == b) { + return true; + } + } + return false; + } - getPlayerDimensions(elementNames){ - // element names — reserved for future use. If element names are provided, this function should return first element that - // has classname or id that matches at least one in the elementNames array. - var element = this.video.parentNode; + getPlayer() { + const host = window.location.host; + let element = this.video.parentNode; if(! element ){ - if(Debug.debug) - console.log("[PlayerDetect::_pd_getPlayerDimensions] element is not valid, doing nothing.", element) + if(Debug.debug) { + console.log("[PlayerDetect::_pd_getPlayer] element is not valid, doing nothing.", element) + } + if(this.element) { + const ths = this; + } + this.element = undefined; + this.dimensions = undefined; + return; + } + + if (this.settings.active.sites[host] + && this.settings.active.sites[host].DOM + && this.settings.active.sites[host].DOM.player + && this.settings.active.sites[host].DOM.player.manual) { + if (this.settings.active.sites[host].DOM.player.useRelativeAncestor + && this.settings.active.sites[host].DOM.player.videoAncestor) { + + let parentsLeft = this.settings.active.sites[host].DOM.player.videoAncestor - 1; + while (parentsLeft --> 0) { + element = element.parentNode; + } + if (element) { + return element; + } + } else if (this.settings.active.sites[host].DOM.player.querySelectors) { + const allSelectors = document.querySelectorAll(this.settings.active.sites[host].DOM.player.querySelectors); + while (element && !this.collectionHas(allSelectors, element)) { + element = element.parentNode; + } + if (element) { + return element; + } + } + } + + + var trustCandidateAfterGrows = 2; // if candidate_width or candidate_height increases in either dimensions this many + // times, we say we found our player. (This number ignores weird elements) + // in case our