diff --git a/src/common/js/utils.ts b/src/common/js/utils.ts index 990473b..1536751 100644 --- a/src/common/js/utils.ts +++ b/src/common/js/utils.ts @@ -1,3 +1,12 @@ export async function sleep(timeout) { return new Promise( (resolve, reject) => setTimeout(() => resolve(), timeout)); } + +/** + * Creates deep copy of an object + * @param obj + * @returns + */ +export function _cp(obj) { + return JSON.parse(JSON.stringify(obj)); +} diff --git a/src/ext/lib/PlayerPickerHelper.js b/src/ext/lib/PlayerPickerHelper.js deleted file mode 100644 index 5aac89b..0000000 --- a/src/ext/lib/PlayerPickerHelper.js +++ /dev/null @@ -1,189 +0,0 @@ -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.hostname; - 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