Skip to content

Instantly share code, notes, and snippets.

@bantic
Created March 4, 2020 02:33
Show Gist options
  • Save bantic/9943a60047213021d1de7af6b4214669 to your computer and use it in GitHub Desktop.
Save bantic/9943a60047213021d1de7af6b4214669 to your computer and use it in GitHub Desktop.
chrome.runtime.onMessage.addListener(function(color) {
if (color === 'changeToYellow') {
document.body.style.color = 'yellow';
}
});
<div>
<button id="button1">First</button>
<button id="button2">Second</button>
</div>
document.getElementById('button1').addEventListener('click', function(){
// make the page yellow
alert('button 1 was clikced');
chrome.tabs.query({active...}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, 'changeToYellow');
})
})
document.getElementById('button2').addEventListener('click', function(){
alert('button 2 was clikced');
// make the page blue
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment