Created
October 16, 2019 01:29
-
-
Save mrsheepsheep/6e6ac8665e15f1eca5bf7b9cd90cd22e to your computer and use it in GitHub Desktop.
Elite Dangerous Web Journal hook snippet
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
window.addEventListener("message", (message) => { | |
console.log(message) | |
if (message.source != window) { | |
return // Important, don't trust any other sources | |
} | |
if (message.data.origin && message.data.origin === 'Elite Dangerous Web Journal') { // Simple check | |
console.log('Received event:', message.data.eventName) | |
switch (message.data.eventName) { | |
case 'enabled': // Message received when the user clicks the extension. Script is injected and ready to communicate. | |
console.log('Enabled. Sending getJournal event') | |
window.postMessage({ // Ask for initial, full journal data | |
origin: 'Elite Dangerous Web Journal', | |
eventName: 'getJournal' | |
}) | |
break; | |
case 'disabled': | |
console.log('Extension has been disabled.') | |
break | |
case 'journal': | |
const journal = message.data.data // Full journal, array of events | |
console.log('Received initial journal data') | |
journal.forEach((journalEvent) => { | |
/* | |
Do what you want with existing journal data | |
*/ | |
console.log(journalEvent) | |
}) | |
break; | |
case 'event': | |
const event = message.data.data // Single event | |
console.log('Received single event', event.event) | |
/* | |
Do what you want with live events | |
*/ | |
break; | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment