diff --git a/src/ext/lib/PlayerPickerHelper.js b/src/ext/lib/PlayerPickerHelper.js new file mode 100644 index 0000000..e03eed2 --- /dev/null +++ b/src/ext/lib/PlayerPickerHelper.js @@ -0,0 +1,189 @@ +class PlayerPickerHelper { + constructor (settings, callbacks) { + this.settings = settings; + this.videos = document.selectElementsByTagName('video'); + this.selectedParentIndex = this.findPlayerForVideos(settings, this.videos)[0]; + this.savedCss = []; + this.markVideos(); + this.markIndexForAll(index); + this.markInitialQuerySelectors(); + } + + + + /* + * + * Internal functions + * + */ + saveBorder(element) { + if (this.savedCss.findIndex(x => x.element === element) !== -1) { + this.savedCss.push({element: element, border: element.style.border}); + } + } + restoreBorders() { + for (const e of this.savedCss) { + e.element.style.border = e.border; + } + } + + findPlayerForVideos(settings, videos) { + const playerIndexes = []; + for (const v of videos) { + playerIndexes.push(this.findPlayerForVideo(settings, v)); + } + return playerIndexes; + } + + findPlayerForVideo(settings, video) { + const host = window.location.host; + let element = video.parentNode; + + 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) { + + return this.settings.active.sites[host].DOM.player.videoAncestor; + } else if (this.settings.active.sites[host].DOM.player.querySelectors) { + const allSelectors = document.querySelectorAll(this.settings.active.sites[host].DOM.player.querySelectors); + let elementIndex = 1; + while (element && !this.collectionHas(allSelectors, element)) { + element = element.parentNode; + elementIndex++; + } + return elementIndex; + } + } + + let elementIndex = 0; + + 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