Created
March 4, 2020 02:33
-
-
Save bantic/9943a60047213021d1de7af6b4214669 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
chrome.runtime.onMessage.addListener(function(color) { | |
if (color === 'changeToYellow') { | |
document.body.style.color = 'yellow'; | |
} | |
}); |
This file contains hidden or 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
<div> | |
<button id="button1">First</button> | |
<button id="button2">Second</button> | |
</div> |
This file contains hidden or 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
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