v1.6.4/add funimation

This commit is contained in:
2020-08-28 15:24:23 -04:00
parent b5a9c8db64
commit 475dcdd5e8
6 changed files with 70 additions and 11 deletions
+2
View File
@@ -32,6 +32,7 @@ export const PLAYER_SOURCE = {
CRUNCHYROLL: 'crunchyroll.',
APPLE: 'tv.apple.',
VIKI: 'viki.',
FUNIMATION: 'funimation.',
LOCAL: 'localhost',
};
@@ -49,6 +50,7 @@ export const getPlayerSource = () => {
if (HREF.includes(PLAYER_SOURCE.CRUNCHYROLL)) return PLAYER_SOURCE.CRUNCHYROLL;
if (HREF.includes(PLAYER_SOURCE.APPLE)) return PLAYER_SOURCE.APPLE;
if (HREF.includes(PLAYER_SOURCE.VIKI)) return PLAYER_SOURCE.VIKI;
if (HREF.includes(PLAYER_SOURCE.FUNIMATION)) return PLAYER_SOURCE.FUNIMATION;
if (HREF.includes(PLAYER_SOURCE.LOCAL)) return PLAYER_SOURCE.LOCAL;
};
+4 -5
View File
@@ -507,11 +507,10 @@ export default class Chat extends Component {
message: 'Functionality may be buggy, HBO has a horrible design.',
},
{
condition: () => getPlayerSource() === PLAYER_SOURCE.GOOGLEPLAY,
message: 'Functionality may be buggy, support on this site is in testing.',
},
{
condition: () => getPlayerSource() === PLAYER_SOURCE.CRUNCHYROLL,
condition: () =>
getPlayerSource() === PLAYER_SOURCE.APPLE ||
getPlayerSource() === PLAYER_SOURCE.FUNIMATION ||
getPlayerSource() === PLAYER_SOURCE.VIKI,
message: 'Functionality may be buggy, support on this site is in testing.',
},
{
+55 -3
View File
@@ -71,6 +71,7 @@ export default class VideoListener {
// REMOVE LISTENER BEFORE SYNCING
switch (this.video.source) {
case PLAYER_SOURCE.CRUNCHYROLL:
case PLAYER_SOURCE.FUNIMATION:
window.removeEventListener('watchParty', this.crunchyRollListener);
break;
default:
@@ -80,7 +81,11 @@ export default class VideoListener {
}
await this.timeout(250);
// SEEK
if (Math.abs(serverPlayer.time - this.video.element.currentTime) > 1.5) {
if (
!!!this.video.element.currentTime ||
(this.video.element.currentTime &&
Math.abs(serverPlayer.time - this.video.element.currentTime) > 1.5)
) {
switch (serverPlayer.source) {
case PLAYER_SOURCE.NETFLIX:
window.postMessage({ type: 'SEEK', time: serverPlayer.time * 1000 }, '*');
@@ -131,6 +136,16 @@ export default class VideoListener {
})
);
break;
case PLAYER_SOURCE.FUNIMATION:
window.postMessage(
JSON.stringify({
watchPartyDirection: 'TO_SCRIPT',
type: 'WATCH_PARTY_SEEK',
status: serverPlayer.status,
time: serverPlayer.time,
})
);
break;
case PLAYER_SOURCE.APPLE:
this.video.element.currentTime = serverPlayer.time;
break;
@@ -153,7 +168,8 @@ export default class VideoListener {
window.postMessage({ type: 'PAUSE', time: serverPlayer.time }, '*');
} else if (
PLAYER_SOURCE.CRUNCHYROLL === this.video.source ||
PLAYER_SOURCE.PEACOCK === this.video.source
PLAYER_SOURCE.PEACOCK === this.video.source ||
PLAYER_SOURCE.FUNIMATION === this.video.source
) {
window.postMessage(
JSON.stringify({
@@ -177,7 +193,8 @@ export default class VideoListener {
window.postMessage({ type: 'PLAY', time: serverPlayer.time }, '*');
} else if (
PLAYER_SOURCE.CRUNCHYROLL === this.video.source ||
PLAYER_SOURCE.PEACOCK === this.video.source
PLAYER_SOURCE.PEACOCK === this.video.source ||
PLAYER_SOURCE.FUNIMATION === this.video.source
) {
window.postMessage(
JSON.stringify({
@@ -200,6 +217,7 @@ export default class VideoListener {
// RE-ADD LISTENERS FOR FUTURE SYNC
switch (this.video.source) {
case PLAYER_SOURCE.CRUNCHYROLL:
case PLAYER_SOURCE.FUNIMATION:
window.addEventListener('watchParty', this.crunchyRollListener);
break;
default:
@@ -292,6 +310,16 @@ export default class VideoListener {
const docTitleSplit = document.title.split('|');
if (docTitleSplit.length > 1) return docTitleSplit[0].trim();
else return null;
case PLAYER_SOURCE.FUNIMATION:
const funimationShowContainer = document.querySelector(nS.show);
const funimationEpisodeContainer = document.querySelector(nS.episode);
const funimationShow = funimationShowContainer ? funimationShowContainer.innerText : '';
const funimationEpisode = funimationEpisodeContainer
? funimationEpisodeContainer.innerText.replace(/\n/gi, '')
: '';
return funimationShow === '' && funimationEpisode === ''
? null
: funimationShow + '\n' + funimationEpisode;
default:
break;
}
@@ -331,6 +359,7 @@ export default class VideoListener {
});
switch (this.video.source) {
case PLAYER_SOURCE.CRUNCHYROLL:
case PLAYER_SOURCE.FUNIMATION:
window.postMessage(
JSON.stringify({
watchPartyDirection: 'TO_SCRIPT',
@@ -643,6 +672,28 @@ export default class VideoListener {
);
}
break;
case PLAYER_SOURCE.FUNIMATION:
const funimationInject = `var sendToWatchPartyApp=function(pS,pT){var customWatchPartyEvent=new CustomEvent('watchParty',{detail:{watchPartyDirection:'TO_APP',type:'WATCH_PARTY_PLAYER_UPDATE',status:pS,time:pT}});window.dispatchEvent(customWatchPartyEvent)},watchPartyGetTimeAndSend=function(pS){const playerIframe=document.querySelector('.video-player-container iframe#player');if(playerIframe){const player=playerIframe.contentWindow.document.querySelector('video');if(player){sendToWatchPartyApp(pS,player.currentTime)}}},watchPartySendPlaying=function(){watchPartyGetTimeAndSend('PLAYING')},watchPartySendPaused=function(){watchPartyGetTimeAndSend('PAUSED')},watchPartyInteraction=function(e){const data=JSON.parse(e.data);const playerIframe=document.querySelector('.video-player-container iframe#player');if(playerIframe){const player=playerIframe.contentWindow.document.querySelector('video');if(player){if(data.watchPartyDirection==='TO_SCRIPT'){if(data.type==='WATCH_PARTY_ADD_LISTENERS'){player.addEventListener('playing',watchPartySendPlaying);player.addEventListener('pause',watchPartySendPaused)}else if(data.type==='WATCH_PARTY_SEEK'){const playerNode=playerIframe.contentWindow.document.querySelector('#brightcove-player');if(playerNode){playerNode.player.currentTime(data.time)}}else if(data.type==='WATCH_PARTY_STATUS'){if(data.status==='PAUSED')player.pause();if(data.status==='PLAYING')player.play()}}}}};window.addEventListener("message",watchPartyInteraction);`;
const funimationInjectScript = document.createElement('script');
funimationInjectScript.text = funimationInject;
document.head.appendChild(funimationInjectScript);
const funimationIframe = document.querySelector(this.selectors[PLAYER_SOURCE.FUNIMATION]);
if (funimationIframe) {
this.firstTimeSync(funimationIframe);
} else {
setInterval(
this.video.element
? null
: () => {
const fif = document.querySelector(this.selectors[PLAYER_SOURCE.FUNIMATION]);
if (fif) {
this.firstTimeSync(fif);
}
},
1000
);
}
break;
case PLAYER_SOURCE.LOCAL:
const localVideoElement = document.getElementsByTagName('video')[0];
if (localVideoElement) {
@@ -656,6 +707,7 @@ export default class VideoListener {
end() {
switch (this.video.source) {
case PLAYER_SOURCE.CRUNCHYROLL:
case PLAYER_SOURCE.FUNIMATION:
window.removeEventListener('watchParty', this.crunchyRollListener);
break;
default:
+2 -1
View File
@@ -231,7 +231,8 @@ body.apple .thread-wrapper .ReactVirtualized__Grid__innerScrollContainer {
body.hulu #party_wrapper *,
body.peacock #party_wrapper *,
body.disney #party_wrapper *,
body.apple #party_wrapper * {
body.apple #party_wrapper *,
body.funimation #party_wrapper * {
box-sizing: inherit;
}
+3
View File
@@ -100,6 +100,9 @@ switch (getPlayerSource()) {
case PLAYER_SOURCE.VIKI:
document.body.classList.add('viki');
break;
case PLAYER_SOURCE.FUNIMATION:
document.body.classList.add('funimation');
break;
case PLAYER_SOURCE.LOCAL:
document.body.classList.add('local');
break;