document.getElementById('changeColor').addEventListener('click', () => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
function: changeBackgroundColor
});
});
});
function changeBackgroundColor() {
document.body.style.backgroundColor =
document.body.style.backgroundColor === 'yellow' ? 'white' : 'yellow';
}
chrome.tabs.query
: This API retrieves the active tab in the current window.chrome.scripting.executeScript
: Executes a script in the context of the active tab. In this case, it changes the background color of the webpage.