Last active
April 16, 2024 19:39
-
-
Save jwcounts/6f70d0bb4015fbd06a64d7faa18823b1 to your computer and use it in GitHub Desktop.
PBS GA LivePlayer Parent Message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inIframe = () => { | |
try { | |
return window.self !== window.top; | |
} catch (e) { | |
return true; | |
} | |
} | |
window.addEventListener('DOMContentLoaded', (event) => { | |
if ( inIframe() ) { | |
console.log( 'loading in iframe' ); | |
let channelTitle = window.livePlayerContextBridge.feed_name; | |
let channelId = window.livePlayerContextBridge.feed_cid; | |
window.parent.postMessage({'message': 'iframeload', 'payload': {'channelTitle':channelTitle,'channelId':channelId}, 'sender': 'pbslls'},'*'); | |
let channelSelect = document.querySelectorAll('select.multi-livestream-overlay__channel-select'); | |
Array.from(channelSelect).forEach( (cs) => { | |
cs.addEventListener('change', function() { | |
let channelTitle = this.options[this.selectedIndex].text; | |
let channelId = this.value; | |
window.parent.postMessage({'message': 'channelChange','payload': {'channelTitle':channelTitle,'channelId':channelId}, 'sender': 'pbslls'},'*'); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment