From 7170568dbe3c9ed7de5f1e62baae0b0c8284495e Mon Sep 17 00:00:00 2001 From: Ayushya Amitabh Date: Fri, 5 Jun 2020 00:42:47 -0400 Subject: [PATCH] v1.3.3-beta/HBO support --- app/package.json | 2 +- app/public/manifest.json | 5 ++-- app/src/Api.js | 2 ++ app/src/VideoListener.js | 49 ++++++++++++++++++++++++++++++++++++++-- app/src/index.js | 1 + functions/package.json | 2 +- package.json | 2 +- 7 files changed, 56 insertions(+), 7 deletions(-) diff --git a/app/package.json b/app/package.json index 02aedcb..f60cf96 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "watch-party-crx", - "version": "1.3.2", + "version": "1.3.3", "private": true, "dependencies": { "@giphy/js-fetch-api": "^1.5.8", diff --git a/app/public/manifest.json b/app/public/manifest.json index 9c73ac0..be355dd 100644 --- a/app/public/manifest.json +++ b/app/public/manifest.json @@ -1,7 +1,7 @@ { "name": "Watch Party", "short_name": "WP", - "version": "1.3.2", + "version": "1.3.3", "description": "Watch streamed content together.", "background": { "page": "popup.html" @@ -13,6 +13,7 @@ "https://*.disneyplus.com/*", "https://*.youtube.com/*", "https://play.hbonow.com/*", + "https://play.hbomax.com/*", "http://localhost/*" ], "content_security_policy": "script-src 'self' https://www.gstatic.com/ https://*.firebaseio.com https://www.googleapis.com; object-src 'self'", @@ -48,7 +49,7 @@ "css": ["/static/css/app.css"] }, { - "matches": ["https://play.hbonow.com/*"], + "matches": ["https://play.hbonow.com/*", "https://play.hbomax.com/*"], "run_at": "document_idle", "js": ["/static/js/content.js"], "css": ["/static/css/app.css"] diff --git a/app/src/Api.js b/app/src/Api.js index 5f24bbe..1764ca4 100644 --- a/app/src/Api.js +++ b/app/src/Api.js @@ -17,6 +17,7 @@ export const PLAYER_SOURCE = { DISNEY: 'https://www.disneyplus.', YOUTUBE: 'https://www.youtube.', HBONOW: 'https://play.hbonow.', + HBOMAX: 'https://play.hbomax.', LOCAL: 'http://localhost', }; @@ -28,6 +29,7 @@ export const getPlayerSource = () => { if (HREF.startsWith(PLAYER_SOURCE.DISNEY)) return PLAYER_SOURCE.DISNEY; if (HREF.startsWith(PLAYER_SOURCE.YOUTUBE)) return PLAYER_SOURCE.YOUTUBE; if (HREF.startsWith(PLAYER_SOURCE.HBONOW)) return PLAYER_SOURCE.HBONOW; + if (HREF.startsWith(PLAYER_SOURCE.HBOMAX)) return PLAYER_SOURCE.HBOMAX; if (HREF.startsWith(PLAYER_SOURCE.LOCAL)) return PLAYER_SOURCE.LOCAL; }; diff --git a/app/src/VideoListener.js b/app/src/VideoListener.js index 3561710..903c4f4 100644 --- a/app/src/VideoListener.js +++ b/app/src/VideoListener.js @@ -81,6 +81,10 @@ export default class VideoListener { case PLAYER_SOURCE.HULU: window.postMessage({ type: 'SEEK', time: serverPlayer.time }, '*'); break; + case PLAYER_SOURCE.HBOMAX: + case PLAYER_SOURCE.HBONOW: + this.video.element.currentTime = serverPlayer.time; + break; default: break; } @@ -90,7 +94,9 @@ export default class VideoListener { case PLAYER_STATUS.PAUSED: if ( PLAYER_SOURCE.HULU === this.video.source || - PLAYER_SOURCE.NETFLIX === this.video.source + PLAYER_SOURCE.NETFLIX === this.video.source || + PLAYER_SOURCE.HBOMAX === this.video.source || + PLAYER_SOURCE.HBONOW === this.video.source ) window.postMessage({ type: 'PAUSE', time: serverPlayer.time }, '*'); else await this.video.element.pause(); @@ -98,7 +104,9 @@ export default class VideoListener { case PLAYER_STATUS.PLAYING: if ( PLAYER_SOURCE.HULU === this.video.source || - PLAYER_SOURCE.NETFLIX === this.video.source + PLAYER_SOURCE.NETFLIX === this.video.source || + PLAYER_SOURCE.HBOMAX === this.video.source || + PLAYER_SOURCE.HBONOW === this.video.source ) window.postMessage({ type: 'PLAY', time: serverPlayer.time }, '*'); else @@ -162,6 +170,11 @@ export default class VideoListener { const yshow = document.querySelector('h1.title').innerText; const yepisode = document.querySelector('yt-formatted-string.super-title').innerText; return yshow === '' && yepisode === '' ? null : yshow + '\n' + yepisode; + case PLAYER_SOURCE.HBOMAX: + case PLAYER_SOURCE.HBONOW: + const hboshow = document.querySelector('#hboUpperTitle').innerText; + const hboepisode = document.querySelector('#hboLowerTitle').innerText; + return hboshow === '' && hboepisode === '' ? null : hboshow + '\n' + hboepisode; default: break; } @@ -285,6 +298,38 @@ export default class VideoListener { ); } break; + case PLAYER_SOURCE.HBOMAX: + case PLAYER_SOURCE.HBONOW: + const hboSeekInject = `window.seekScriptLoaded=!0;var getVideoPlayer=function(){var e=document.querySelector('video.default')._dispNode;return e;},seekInteraction=function(e){if(e.source==window){if(e.data.type&&e.data.type==="PAUSE"){getVideoPlayer().pause();}if(e.data.type&&e.data.type==="PLAY"){getVideoPlayer().play();}e.data.type&&"teardown"==e.data.type&&(window.removeEventListener("message",seekInteraction,!1),window.seekScriptLoaded=!1)}};window.addEventListener("message",seekInteraction,!1);`; + const hboSeekInjectScript = document.createElement('script'); + hboSeekInjectScript.text = hboSeekInject; + document.head.appendChild(hboSeekInjectScript); + const hboVideoElement = document.querySelector('video.default'); + if (hboVideoElement) { + const bottomHalf = + hboVideoElement.parentNode.parentNode.parentNode.parentNode.parentNode.children[1]; + bottomHalf.children[0].id = 'hboUpperTitle'; + bottomHalf.children[1].id = 'hboLowerTitle'; + this.firstTimeSync(hboVideoElement); + } else { + setInterval( + this.video.element + ? null + : () => { + var hve = document.querySelector('video.default'); + if (hve !== null && (this.video.element !== hve || this.video.element === null)) { + const bottomHalf = + hboVideoElement.parentNode.parentNode.parentNode.parentNode.parentNode + .children[1]; + bottomHalf.children[0].id = 'hboUpperTitle'; + bottomHalf.children[1].id = 'hboLowerTitle'; + this.firstTimeSync(hve); + } + }, + 1000 + ); + } + break; case PLAYER_SOURCE.LOCAL: const localVideoElement = document.getElementsByTagName('video')[0]; if (localVideoElement) { diff --git a/app/src/index.js b/app/src/index.js index 37f7987..c610880 100644 --- a/app/src/index.js +++ b/app/src/index.js @@ -54,6 +54,7 @@ switch (getPlayerSource()) { document.body.classList.add('youtube'); break; case PLAYER_SOURCE.HBONOW: + case PLAYER_SOURCE.HBOMAX: document.body.classList.add('hbo'); break; case PLAYER_SOURCE.LOCAL: diff --git a/functions/package.json b/functions/package.json index 00e9559..763ab5d 100644 --- a/functions/package.json +++ b/functions/package.json @@ -1,6 +1,6 @@ { "name": "watch-party-api", - "version": "1.3.2", + "version": "1.3.3", "description": "Cloud Functions for Watch Party", "scripts": { "lint": "eslint .", diff --git a/package.json b/package.json index 627afc4..238dcd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "watch-party", - "version": "1.3.2", + "version": "1.3.3", "description": "Watch Party", "scripts": { "start": "firebase emulators:start",