Emilia Clarke Emilia Clarke - 2 months ago 7
Javascript Question

How would I edit this simple chrome extension to change the font color of ALL elements on a page to red?

At the moment, it only works for some web pages, and it only changes some of the text's color.

background.js

chrome.browserAction.onClicked.addListener(function(tab) {
// No tabs or host permissions needed!
console.log('Turning ' + tab.url + ' red!');
chrome.tabs.executeScript({
code: 'document.body.style.color="red"'
});
});

Answer

Iterate through ALL tags and change the color :

var el = document.getElementsByTagName("*");
for (var i=0; i < el.length; i++) 
{    
    el[i].style.color = "Red";
}

Tested this, works on Google & Stackoverflow

P.S. The JS code needs to go in executeScript