From 2f5e57eb9925ad1a0a16504092e1213d9ed41bc0 Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Wed, 4 Dec 2019 21:55:08 +0200 Subject: [PATCH 01/13] Strategies POC --- src/content/Control.Strategies.js | 30 ++++++++++++++++++++++ src/content/Service.js | 18 +++++++++++++ src/content/ServicesRegistry.js | 27 ++++++++++++++++++++ src/content/Status.Strategies.js | 18 +++++++++++++ src/content/Status.Types.js | 5 ++++ src/content/index.js | 42 +++++++++++++++++++++++++------ 6 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 src/content/Control.Strategies.js create mode 100644 src/content/Service.js create mode 100644 src/content/ServicesRegistry.js create mode 100644 src/content/Status.Strategies.js create mode 100644 src/content/Status.Types.js diff --git a/src/content/Control.Strategies.js b/src/content/Control.Strategies.js new file mode 100644 index 0000000..7b53a17 --- /dev/null +++ b/src/content/Control.Strategies.js @@ -0,0 +1,30 @@ + +import { Status } from './Status.Types.js'; + +export class BaseControlStrategy { + static play() {} + static pause() {} +} + +export class oneOfTheVideos extends BaseControlStrategy { + static getVideosArray() { + return Array.from(document.getElementsByTagName('video')); + } + + static pause() { + oneOfTheVideos.getVideosArray() + .filter((player) => !player.paused) + .forEach((player) => { + player.pause(); + }); + } + + static play() { + oneOfTheVideos.getVideosArray() + .filter((player) => player.paused && player.played.length > 0) + .forEach((player) => { + player.play(); + }); + } + +} diff --git a/src/content/Service.js b/src/content/Service.js new file mode 100644 index 0000000..1746fcc --- /dev/null +++ b/src/content/Service.js @@ -0,0 +1,18 @@ +/* Base Service class */ +export class Service { + constructor(options) { + this.options = options; + } + + getStatus() { + return this.options.statusStrategy.getStatus(); + } + + play() { + this.options.controlStrategy.play(); + } + + pause() { + this.options.controlStrategy.pause(); + } +} diff --git a/src/content/ServicesRegistry.js b/src/content/ServicesRegistry.js new file mode 100644 index 0000000..1e8c136 --- /dev/null +++ b/src/content/ServicesRegistry.js @@ -0,0 +1,27 @@ +import { Service } from './Service.js'; +import * as StatusStrategies from './Status.Strategies.js'; +import * as ControlStrategies from './Control.Strategies.js'; + +export const servicesRegistry = [ + { + hosts: ['ted.com', 'facebook.com', 'kickstarter.com', 'music.youtube.com' ], // we can add support fields, like `host: string`, `hosts: Array` + options: { + statusStrategy: StatusStrategies.oneOfTheVideosPlaying, + controlStrategy: ControlStrategies.oneOfTheVideos + } + }, +]; + +export function getService(domain) { + const matchedService = servicesRegistry.find(serviceConfig => { + return serviceConfig.host === domain + || serviceConfig.hosts.includes(domain) + || serviceConfig.hostPattern.match(domain); + }); + + if (!matchedService) { + return; + } + + return new Service(matchedService.options); +} diff --git a/src/content/Status.Strategies.js b/src/content/Status.Strategies.js new file mode 100644 index 0000000..51fcedd --- /dev/null +++ b/src/content/Status.Strategies.js @@ -0,0 +1,18 @@ +import { Status } from './Status.Types.js'; + +export class BaseStatusStrategy { + static getStatus() {} +} + +/* A shared mixin for when there is a video tag on page */ +export class oneOfTheVideosPlaying extends BaseStatusStrategy { + static getStatus() { + let status = Status.PAUSED; + const videos = document.getElementsByTagName("video"); + if (videos.length > 0) { + const hasPlayingVideo = Array.from(videos).some((player) => !player.paused); + status = hasPlayingVideo ? Status.PLAYING : Status.PAUSED; + } + return status; + } +} diff --git a/src/content/Status.Types.js b/src/content/Status.Types.js new file mode 100644 index 0000000..5b18cf3 --- /dev/null +++ b/src/content/Status.Types.js @@ -0,0 +1,5 @@ +/* Status Types */ +export const Status = { + PAUSED: "paused", + PLAYING: "playing" +}; diff --git a/src/content/index.js b/src/content/index.js index 697c02b..a0c1273 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -1,5 +1,7 @@ /* StoPlay Content JS */ import { CheckTimer } from './CheckTimer.js'; +import { getService } from './ServicesRegistry.js'; +import { Status } from './Status.Types.js'; function safeGetElementTextContentByQuery(query) { try { @@ -25,11 +27,6 @@ const StoPlay = { let button = null; -const Status = { - PAUSED: "paused", - PLAYING: "playing" -}; - const CHECK_TIMEOUT = 1000; const TITLE_TIMEOUT = 10000; @@ -48,6 +45,8 @@ class Provider { this.customLastPlayerSelector = null; this.customLastPauseSelector = null; + this.service = null; + chrome.storage.sync.get({ enabled: true, providers: [] @@ -55,7 +54,16 @@ class Provider { this.timer = new CheckTimer({ delay: CHECK_TIMEOUT, - callback: this.checkStatus.bind(this), + callback: () => { + let status; + if (this.service) { + status = this.service.getStatus(); + console.log('service getstatus', status); + } else { + status = checkStatus(); + } + this.__changeState(status); + }, recursive: true }); this.checkTitleInterval = new CheckTimer({ @@ -165,7 +173,12 @@ class Provider { clearSubDomains = "bandcamp.com"; } if (clearSubDomains) this.host = clearSubDomains; + this.service = getService(this.host); + + return this.host; + } + providerAllowed() { return (this.allowed.indexOf(this.host) >= 0); } @@ -553,13 +566,20 @@ class Provider { break; } - status && this.__changeState(status); + return status; } pause() { let p, selector, selectorQuery, playerPauseButton; if (this.status === Status.PLAYING) { + if (this.service) { + this.service.pause(); + // #TODO: remove duplication for POC + this.__changeState(Status.PAUSED); + return; + } + switch(this.host) { case "radiolist.com.ua": if (this.customLastPlayerSelector) { @@ -832,6 +852,14 @@ class Provider { let p, selector, selectorQuery, playerPlayButton; if (this.status !== Status.PLAYING) { + if (this.service) { + this.service.play(); + // #TODO: remove duplication for POC + this.__changeState(Status.PLAYING); + return; + + } + switch(this.host) { case "radiolist.com.ua": if (this.customLastPlayerSelector) { From 2b122fa53d761a9c3618957df3e8f4f7f14f6520 Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Thu, 5 Dec 2019 01:07:07 +0200 Subject: [PATCH 02/13] Add some simple services --- src/content/Control.Strategies.js | 13 +++ src/content/Service.js | 14 ++- src/content/ServicesRegistry.js | 155 +++++++++++++++++++++++++++--- src/content/Status.Strategies.js | 9 +- src/content/index.js | 6 +- 5 files changed, 178 insertions(+), 19 deletions(-) diff --git a/src/content/Control.Strategies.js b/src/content/Control.Strategies.js index 7b53a17..52002b8 100644 --- a/src/content/Control.Strategies.js +++ b/src/content/Control.Strategies.js @@ -6,6 +6,19 @@ export class BaseControlStrategy { static pause() {} } + +export class clickSelector extends BaseControlStrategy { + static pause() { + let el = document.querySelector(arguments[0]); + return el ? el.click() : null; + } + + static play() { + clickSelector.pause(); + } +} + + export class oneOfTheVideos extends BaseControlStrategy { static getVideosArray() { return Array.from(document.getElementsByTagName('video')); diff --git a/src/content/Service.js b/src/content/Service.js index 1746fcc..2907b54 100644 --- a/src/content/Service.js +++ b/src/content/Service.js @@ -1,18 +1,26 @@ /* Base Service class */ export class Service { + /** + @param options {Object} + @param options.statusStrategy {Class} + @param options.statusArgs {Array} (optional) + @param options.controlStrategy {Class} + @param options.playArgs {Array} (optional) + @param options.pauseArgs {Array} (optional) + */ constructor(options) { this.options = options; } getStatus() { - return this.options.statusStrategy.getStatus(); + return this.options.statusStrategy.getStatus.apply(null, this.options.statusArgs); } play() { - this.options.controlStrategy.play(); + this.options.controlStrategy.play.apply(null, this.options.playArgs); } pause() { - this.options.controlStrategy.pause(); + this.options.controlStrategy.pause.apply(null, this.options.pauseArgs); } } diff --git a/src/content/ServicesRegistry.js b/src/content/ServicesRegistry.js index 1e8c136..5f9af55 100644 --- a/src/content/ServicesRegistry.js +++ b/src/content/ServicesRegistry.js @@ -2,22 +2,153 @@ import { Service } from './Service.js'; import * as StatusStrategies from './Status.Strategies.js'; import * as ControlStrategies from './Control.Strategies.js'; -export const servicesRegistry = [ - { - hosts: ['ted.com', 'facebook.com', 'kickstarter.com', 'music.youtube.com' ], // we can add support fields, like `host: string`, `hosts: Array` +// #TODO: move it to build-time +function oneSelectorHelper(hosts, statusArgs, playArgs, pauseArgs) { + return { + hosts, options: { - statusStrategy: StatusStrategies.oneOfTheVideosPlaying, - controlStrategy: ControlStrategies.oneOfTheVideos + statusStrategy: StatusStrategies.checkSelector, + statusArgs: [ statusArgs ], + controlStrategy: ControlStrategies.clickSelector, + playArgs: [ playArgs ], + pauseArgs: [ pauseArgs ] } - }, -]; + }; +} + +function getOneSelector() { + return [ + [ + [ 'vimeo.com', 'player.vimeo.com' ], + '.play.state-playing', + '.play.state-paused', + '.play.state-playing' + ], [ + [ 'vk.com' ], + '.top_audio_player.top_audio_player_playing', + '.top_audio_player_play', + '.top_audio_player_play' + ], [ + [ 'muzebra.com' ], + '.player.jp-state-playing', + '.player.jp-play', + '.player.jp-pause' + ], [ + [ 'music.yandex.ru', 'music.yandex.ua' ], + '.player-controls__btn_play.player-controls__btn_pause', + '.player-controls__btn_play', + '.player-controls__btn_pause' + ], [ + [ 'mixcloud.com' ], + '.player-control.pause-state', + '.player-control', + '.player-control' + ], [ + [ 'soundcloud.com' ], + '.playControl.playing', + '.playControl', + '.playControl.playing' + ], [ + [ 'jazzradio.com', 'rockradio.com', 'radiotunes.com', 'classicalradio.com', 'zenradio.com' ], + '#play-button .icon-pause', + '#play-button .ctl', + '#play-button .ctl' + ], [ + [ 'v5player.slipstreamradio.com', 'accuradio.com' ], + '#playerPauseButton', + '#playerPlayButton', + '#playerPauseButton' + ], [ + [ 'open.spotify.com' ], + ".control-button[class*='pause']", + ".control-button[class*='play']", + ".control-button[class*='pause']" + ], [ + [ 'bandcamp.com' ], + '.inline_player .playbutton.playing', + '.inline_player .playbutton', + '.inline_player .playbutton.playing' + ], [ + [ 'promodj.com' ], + '.playerr_bigplaybutton .playerr_bigpausebutton', + '.playerr_bigplaybutton .playerr_bigplaybutton', + '.playerr_bigplaybutton .playerr_bigpausebutton' + ], [ + [ 'courses.prometheus.org.ua' ], + '.video-controls .video_control.pause', + '.video-controls .video_control.play', + '.video-controls .video_control.pause' + ], [ + [ 'coursera.org' ], + '.c-video-control.vjs-control.vjs-playing', + '.c-video-control.vjs-control.vjs-paused', + '.c-video-control.vjs-control.vjs-playing' + ], [ + [ 'di.fm' ], + '#webplayer-region .controls .icon-pause', + '#webplayer-region .controls .icon-play', + '#webplayer-region .controls .icon-pause' + ], [ + [ 'audible.ca', 'audible.com', 'audible.com.au' ], + '#adbl-cloud-player-controls .adblPauseButton:not(.bc-hidden)', + '#adbl-cloud-player-controls .adblPauseButton:not(.bc-hidden)', + '#adbl-cloud-player-controls .adblPauseButton:not(.bc-hidden)' + ], [ + [ 'coub.com' ], + '.coub.active[play-state="playing"]', + '.coub.active .viewer__replay', + '.coub.active .viewer__click', + ], [ + [ 'livestream.com' ], + '.playback-control .play-holder.lsp-hidden', + '.playback-control .play-holder', + '.playback-control .pause-holder' + ], [ + [ 'beatport.com' ], + '#Player__pause-button', + '#Player__play-button', + '#Player__pause-button' + ], [ + [ 'radio.garden' ], + '.icon-toggle.mod-mute .icon-button.mod-sound', + '.icon-toggle.mod-mute .icon-button.mod-muted', + '.icon-toggle.mod-mute .icon-button.mod-sound' + ] + ].map(item => oneSelectorHelper.apply(null, item)); + +} + +export const servicesRegistry = () => { + + return getOneSelector().concat([ + { + hosts: [ 'radiolist.com.ua' ], + options: { + statusStrategy: StatusStrategies.checkSelector, + statusArgs: [ '.jouele-status-playing .jouele-info-control-button-icon_pause' ], + controlStrategy: ControlStrategies.clickSelector, + playArgs: [], + pauseArgs: [] + } + }, { + hosts: [ 'hearthis.at' ], + options: { + statusStrategy: StatusStrategies.checkSelector, + statusArgs: [ 'body.play' ], + controlStrategy: { /* custom */}, + } + }, { + hosts: ['ted.com', 'facebook.com', 'kickstarter.com', 'music.youtube.com' ], + options: { + statusStrategy: StatusStrategies.oneOfTheVideosPlaying, + controlStrategy: ControlStrategies.oneOfTheVideos, + } + }, + ]) +}; export function getService(domain) { - const matchedService = servicesRegistry.find(serviceConfig => { - return serviceConfig.host === domain - || serviceConfig.hosts.includes(domain) - || serviceConfig.hostPattern.match(domain); - }); + const matchedService = servicesRegistry().find(serviceConfig => serviceConfig.hosts.includes(domain)); if (!matchedService) { return; diff --git a/src/content/Status.Strategies.js b/src/content/Status.Strategies.js index 51fcedd..75e5603 100644 --- a/src/content/Status.Strategies.js +++ b/src/content/Status.Strategies.js @@ -4,7 +4,14 @@ export class BaseStatusStrategy { static getStatus() {} } -/* A shared mixin for when there is a video tag on page */ +export class checkSelector extends BaseStatusStrategy { + static getStatus() { + let el = document.querySelector(arguments[0]); + return el ? Status.PLAYING : Status.PAUSED; + } +} + +/* when there are video tags on page */ export class oneOfTheVideosPlaying extends BaseStatusStrategy { static getStatus() { let status = Status.PAUSED; diff --git a/src/content/index.js b/src/content/index.js index a0c1273..c7e7bf9 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -58,9 +58,8 @@ class Provider { let status; if (this.service) { status = this.service.getStatus(); - console.log('service getstatus', status); } else { - status = checkStatus(); + status = this.checkStatus(); } this.__changeState(status); }, @@ -120,7 +119,8 @@ class Provider { } _detectProviderAndStartCheckInterval() { - if (this.detectProvider()) { + this.detectProvider(); + if (this.providerAllowed()) { this.timer.start(); this.checkTitleInterval.start(); From ec75544460a57737f82ca9dea186675035be8e6c Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Thu, 5 Dec 2019 15:35:38 +0200 Subject: [PATCH 03/13] Update src/content/Status.Strategies.js Co-Authored-By: Oleksandr Karpov --- src/content/Status.Strategies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/Status.Strategies.js b/src/content/Status.Strategies.js index 75e5603..ba5a5ff 100644 --- a/src/content/Status.Strategies.js +++ b/src/content/Status.Strategies.js @@ -5,7 +5,7 @@ export class BaseStatusStrategy { } export class checkSelector extends BaseStatusStrategy { - static getStatus() { + static getStatus(className) { let el = document.querySelector(arguments[0]); return el ? Status.PLAYING : Status.PAUSED; } From 2fee76c7afa630db49f1b7a8c0d7c21fd1a1d581 Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Thu, 5 Dec 2019 15:35:45 +0200 Subject: [PATCH 04/13] Update src/content/Status.Strategies.js Co-Authored-By: Oleksandr Karpov --- src/content/Status.Strategies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/Status.Strategies.js b/src/content/Status.Strategies.js index ba5a5ff..9d91d77 100644 --- a/src/content/Status.Strategies.js +++ b/src/content/Status.Strategies.js @@ -6,7 +6,7 @@ export class BaseStatusStrategy { export class checkSelector extends BaseStatusStrategy { static getStatus(className) { - let el = document.querySelector(arguments[0]); + let el = document.querySelector(className); return el ? Status.PLAYING : Status.PAUSED; } } From ce0275a6b3058ef6bc2d662ed21fe7f6782beb69 Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Thu, 5 Dec 2019 15:35:54 +0200 Subject: [PATCH 05/13] Update src/content/Control.Strategies.js Co-Authored-By: Oleksandr Karpov --- src/content/Control.Strategies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/Control.Strategies.js b/src/content/Control.Strategies.js index 52002b8..65e4acb 100644 --- a/src/content/Control.Strategies.js +++ b/src/content/Control.Strategies.js @@ -8,7 +8,7 @@ export class BaseControlStrategy { export class clickSelector extends BaseControlStrategy { - static pause() { + static pause(className) { let el = document.querySelector(arguments[0]); return el ? el.click() : null; } From 43f614855613de9d05efb72f66e7d66cb79b6139 Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Thu, 5 Dec 2019 15:36:02 +0200 Subject: [PATCH 06/13] Update src/content/Control.Strategies.js Co-Authored-By: Oleksandr Karpov --- src/content/Control.Strategies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/Control.Strategies.js b/src/content/Control.Strategies.js index 65e4acb..b12b77b 100644 --- a/src/content/Control.Strategies.js +++ b/src/content/Control.Strategies.js @@ -9,7 +9,7 @@ export class BaseControlStrategy { export class clickSelector extends BaseControlStrategy { static pause(className) { - let el = document.querySelector(arguments[0]); + let element = document.querySelector(className); return el ? el.click() : null; } From 02deb6e8a090c4fbb2e7f65467493b1c1471fbf3 Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Thu, 5 Dec 2019 15:36:16 +0200 Subject: [PATCH 07/13] Update src/content/Control.Strategies.js Co-Authored-By: Oleksandr Karpov --- src/content/Control.Strategies.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/content/Control.Strategies.js b/src/content/Control.Strategies.js index b12b77b..0e94057 100644 --- a/src/content/Control.Strategies.js +++ b/src/content/Control.Strategies.js @@ -10,7 +10,11 @@ export class BaseControlStrategy { export class clickSelector extends BaseControlStrategy { static pause(className) { let element = document.querySelector(className); - return el ? el.click() : null; + if (!element) { + return; + } + + element.click(); } static play() { From c5f6f1c5e5ec1168a3f1265f5b7ac684d5411498 Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Thu, 5 Dec 2019 15:40:54 +0200 Subject: [PATCH 08/13] Add play args --- src/content/Control.Strategies.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/content/Control.Strategies.js b/src/content/Control.Strategies.js index 0e94057..3f596c2 100644 --- a/src/content/Control.Strategies.js +++ b/src/content/Control.Strategies.js @@ -8,7 +8,7 @@ export class BaseControlStrategy { export class clickSelector extends BaseControlStrategy { - static pause(className) { + static play(className) { let element = document.querySelector(className); if (!element) { return; @@ -17,8 +17,8 @@ export class clickSelector extends BaseControlStrategy { element.click(); } - static play() { - clickSelector.pause(); + static pause(className) { + clickSelector.play(className); } } From 038603e0bbd8cf90c6f50e17b92b6631d9fcc349 Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Sun, 8 Dec 2019 22:01:41 +0200 Subject: [PATCH 09/13] Add stored selector strategies and radiolist.com.ua --- src/content/Control.Strategies.js | 26 ++++++++++++++++++++++++++ src/content/Service.js | 6 +++--- src/content/ServicesRegistry.js | 6 ++---- src/content/Status.Strategies.js | 13 +++++++++++++ 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/content/Control.Strategies.js b/src/content/Control.Strategies.js index 3f596c2..98aa4f0 100644 --- a/src/content/Control.Strategies.js +++ b/src/content/Control.Strategies.js @@ -22,6 +22,32 @@ export class clickSelector extends BaseControlStrategy { } } +/* clicking the storedSelector, injected by the Service */ +export class clickStoredSelector extends BaseControlStrategy { + static play() { + if (this.selector) { + this.selector.click(); + } + } + + static pause() { + clickStoredSelector.play.call(this); + } +} + +/* custom for jouele, based on its buttons position */ +export class joueleStoredSelector extends BaseControlStrategy { + static pause() { + clickStoredSelector.pause.call(this); + } + + static play() { + if (this.selector) { + this.selector.previousSibling.click(); + } + } +} + export class oneOfTheVideos extends BaseControlStrategy { static getVideosArray() { diff --git a/src/content/Service.js b/src/content/Service.js index 2907b54..9da3263 100644 --- a/src/content/Service.js +++ b/src/content/Service.js @@ -13,14 +13,14 @@ export class Service { } getStatus() { - return this.options.statusStrategy.getStatus.apply(null, this.options.statusArgs); + return this.options.statusStrategy.getStatus.apply(this, this.options.statusArgs); } play() { - this.options.controlStrategy.play.apply(null, this.options.playArgs); + this.options.controlStrategy.play.apply(this, this.options.playArgs); } pause() { - this.options.controlStrategy.pause.apply(null, this.options.pauseArgs); + this.options.controlStrategy.pause.apply(this, this.options.pauseArgs); } } diff --git a/src/content/ServicesRegistry.js b/src/content/ServicesRegistry.js index 5f9af55..f370c29 100644 --- a/src/content/ServicesRegistry.js +++ b/src/content/ServicesRegistry.js @@ -124,11 +124,9 @@ export const servicesRegistry = () => { { hosts: [ 'radiolist.com.ua' ], options: { - statusStrategy: StatusStrategies.checkSelector, + statusStrategy: StatusStrategies.checkSelectorAndStore, statusArgs: [ '.jouele-status-playing .jouele-info-control-button-icon_pause' ], - controlStrategy: ControlStrategies.clickSelector, - playArgs: [], - pauseArgs: [] + controlStrategy: ControlStrategies.joueleStoredSelector } }, { hosts: [ 'hearthis.at' ], diff --git a/src/content/Status.Strategies.js b/src/content/Status.Strategies.js index 9d91d77..d23b151 100644 --- a/src/content/Status.Strategies.js +++ b/src/content/Status.Strategies.js @@ -4,6 +4,7 @@ export class BaseStatusStrategy { static getStatus() {} } +/* simple check for selector */ export class checkSelector extends BaseStatusStrategy { static getStatus(className) { let el = document.querySelector(className); @@ -11,6 +12,18 @@ export class checkSelector extends BaseStatusStrategy { } } +/* check for selector and store it */ +export class checkSelectorAndStore extends BaseStatusStrategy { + static getStatus(className, storeSelector) { + let el = document.querySelector(className); + if (el) { + // this is the Service context + this.selector = el; + } + return el ? Status.PLAYING : Status.PAUSED; + } +} + /* when there are video tags on page */ export class oneOfTheVideosPlaying extends BaseStatusStrategy { static getStatus() { From f59679435ea241072f75441b38e625d0caff0dcb Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Sun, 8 Dec 2019 22:38:51 +0200 Subject: [PATCH 10/13] Simple media strategy; add netflix, megogo, dailymotion --- src/content/Control.Strategies.js | 13 +++++++++++++ src/content/ServicesRegistry.js | 27 +++++++++++++++++++++++++++ src/content/Status.Strategies.js | 11 +++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/content/Control.Strategies.js b/src/content/Control.Strategies.js index 98aa4f0..f8ff800 100644 --- a/src/content/Control.Strategies.js +++ b/src/content/Control.Strategies.js @@ -22,6 +22,19 @@ export class clickSelector extends BaseControlStrategy { } } +/* class for standard audio/video media elements */ +export class mediaToggle extends BaseControlStrategy { + static play(className) { + let element = document.querySelector(className); + element && element.paused && element.play(); + } + + static pause(className) { + let element = document.querySelector(className); + element && !element.paused && element.pause(); + } +} + /* clicking the storedSelector, injected by the Service */ export class clickStoredSelector extends BaseControlStrategy { static play() { diff --git a/src/content/ServicesRegistry.js b/src/content/ServicesRegistry.js index f370c29..6a8c2ca 100644 --- a/src/content/ServicesRegistry.js +++ b/src/content/ServicesRegistry.js @@ -128,6 +128,33 @@ export const servicesRegistry = () => { statusArgs: [ '.jouele-status-playing .jouele-info-control-button-icon_pause' ], controlStrategy: ControlStrategies.joueleStoredSelector } + }, { + hosts: [ 'megogo.net' ], + options: { + statusStrategy: StatusStrategies.mediaSelector, + statusArgs: [ 'video[class*="player:video"]' ], + controlStrategy: ControlStrategies.mediaToggle, + playArgs: [ 'video[class*="player:video"]' ], + pauseArgs: [ 'video[class*="player:video"]' ] + } + }, { + hosts: [ 'dailymotion.com' ], + options: { + statusStrategy: StatusStrategies.mediaSelector, + statusArgs: [ '#dmp_Video' ], + controlStrategy: ControlStrategies.mediaToggle, + playArgs: [ '#dmp_Video' ], + pauseArgs: [ '#dmp_Video' ] + } + }, { + hosts: [ 'netflix.com' ], + options: { + statusStrategy: StatusStrategies.mediaSelector, + statusArgs: [ '.VideoContainer video' ], + controlStrategy: ControlStrategies.mediaToggle, + playArgs: [ '.VideoContainer video' ], + pauseArgs: [ '.VideoContainer video' ] + } }, { hosts: [ 'hearthis.at' ], options: { diff --git a/src/content/Status.Strategies.js b/src/content/Status.Strategies.js index d23b151..c479066 100644 --- a/src/content/Status.Strategies.js +++ b/src/content/Status.Strategies.js @@ -12,6 +12,17 @@ export class checkSelector extends BaseStatusStrategy { } } +/* simple check for media state */ +export class mediaSelector extends BaseStatusStrategy { + static getStatus(className) { + let el = document.querySelector(className); + if (el && el.paused === false) { + return Status.PLAYING; + } + return Status.PAUSED; + } +} + /* check for selector and store it */ export class checkSelectorAndStore extends BaseStatusStrategy { static getStatus(className, storeSelector) { From 711208b24be864f501aae4e6f001174050353cd2 Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Sun, 8 Dec 2019 22:47:23 +0200 Subject: [PATCH 11/13] Add egghead, udemy, musicforprogramming, netflix --- src/content/ServicesRegistry.js | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/content/ServicesRegistry.js b/src/content/ServicesRegistry.js index 6a8c2ca..e29b187 100644 --- a/src/content/ServicesRegistry.js +++ b/src/content/ServicesRegistry.js @@ -155,6 +155,42 @@ export const servicesRegistry = () => { playArgs: [ '.VideoContainer video' ], pauseArgs: [ '.VideoContainer video' ] } + }, { + hosts: [ 'egghead.io' ], + options: { + statusStrategy: StatusStrategies.mediaSelector, + statusArgs: [ '.bitmovinplayer-container video' ], + controlStrategy: ControlStrategies.mediaToggle, + playArgs: [ '.bitmovinplayer-container video' ], + pauseArgs: [ '.bitmovinplayer-container video' ] + } + }, { + hosts: [ 'udemy.com' ], + options: { + statusStrategy: StatusStrategies.mediaSelector, + statusArgs: [ 'video' ], + controlStrategy: ControlStrategies.mediaToggle, + playArgs: [ 'video' ], + pauseArgs: [ 'video' ] + } + }, { + hosts: [ 'musicforprogramming.net' ], + options: { + statusStrategy: StatusStrategies.mediaSelector, + statusArgs: [ '#player' ], + controlStrategy: ControlStrategies.mediaToggle, + playArgs: [ '#player' ], + pauseArgs: [ '#player' ] + } + }, { + hosts: [ 'netflix.com' ], + options: { + statusStrategy: StatusStrategies.mediaSelector, + statusArgs: [ '.VideoContainer video' ], + controlStrategy: ControlStrategies.mediaToggle, + playArgs: [ '.VideoContainer video' ], + pauseArgs: [ '.VideoContainer video' ] + } }, { hosts: [ 'hearthis.at' ], options: { From dc56eb5f2cfd617478d36a321f74ab3573727b24 Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Fri, 13 Dec 2019 11:52:56 +0200 Subject: [PATCH 12/13] Remove obsolete providers --- src/background/ProvidersList.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/background/ProvidersList.js b/src/background/ProvidersList.js index 3c08501..8c5ddfe 100644 --- a/src/background/ProvidersList.js +++ b/src/background/ProvidersList.js @@ -28,13 +28,10 @@ export const ProvidersList = [ 'musicforprogramming.net', 'muzebra.com', 'netflix.com', - 'new.vk.com', 'open.spotify.com', 'play.google.com', - 'play.mubert.com', 'play.spotify.com', 'player.vimeo.com', - 'pleer.net', 'promodj.com', 'radio.garden', 'radiolist.com.ua', From ea490d01b885b4665e6e4c3e2ab08a558620b521 Mon Sep 17 00:00:00 2001 From: Alex Buznik Date: Sun, 12 Jan 2020 22:51:39 +0200 Subject: [PATCH 13/13] Minor Gruntfile changes --- Gruntfile.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index a04ff21..8384cf0 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -100,6 +100,13 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-webstore-upload'); + // watcher + grunt.registerTask('default', [ 'watch' ]); + // pack & run dev version locally + grunt.registerTask('pack', [ 'rollup', 'zip' ]); + + // CI stuff below + // Alias task for release grunt.registerTask('makeRelease', function (type) { type = type ? type : 'patch'; // Default release type @@ -109,10 +116,8 @@ module.exports = function(grunt) { grunt.task.run('exec:push_release'); }); - grunt.registerTask('default', [ 'watch' ]); // to make release run this one grunt.registerTask('build', [ 'makeRelease' ]); - grunt.registerTask('pack', [ 'rollup', 'zip' ]); // only should be run by CI, not manually grunt.registerTask('deploy', ['pack', 'webstore_upload']); };