Skip to content

Instantly share code, notes, and snippets.

@danhollick
Created February 3, 2020 17:56
Show Gist options
  • Save danhollick/72b30c0ce5a73849d46ce5adfaf5be2c to your computer and use it in GitHub Desktop.
Save danhollick/72b30c0ce5a73849d46ce5adfaf5be2c to your computer and use it in GitHub Desktop.
Updating the UI
<div id="background">
<h3 id="foreground">The quick brown fox</h3>
</div>
<h2 id="contrast"> </h2>
<script>
window.onmessage = async event => {
const message = event.data.pluginMessage
console.log(message)
if (message.type === 'selectionChange') {
const background = document.getElementById('background')
const foreground = document.getElementById('foreground')
const contrast = document.getElementById('contrast')
background.style = `background-color: ${message.background};`
foreground.style = `color: ${message.foreground};`
contrast.textContent = message.contrast
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment