6
I made an extension for Google Chrome that’s working. The goal is to change the color of the images' pixels on all web pages.
To do this on the pages loaded in the tabs already open, I use the following code (in background.js file):
function executeScriptsInExistingTabs(){
chrome.windows.getAll(null, function(wins) {
for (var j = 0; j < wins.length; ++j) {
chrome.tabs.getAllInWindow(wins[j].id, function(tabs) {
for (var i = 0; i < tabs.length; ++i) {
if (tabs[i].url.indexOf("chrome://") != 0) {
chrome.tabs.executeScript(tabs[i].id, { file: 'muda_conteudo.js' });
chrome.browserAction.setIcon({path: "on.png", tabId:tabs[i].id});
}
}
});
}
});
}
To change the color, tabs that will be opened after the activation of the extension, use the following code (in the background.js file):
chrome.tabs.onUpdated.addListener(function(tabid, info, tab) {
if (flag){
if (info.status == "complete") {
chrome.tabs.executeScript(tabid, {file:"muda_conteudo.js"});
chrome.browserAction.setIcon({path: "on.png", tabId:tab.id})
}
}
});
Everything works perfectly, but when a new tab is opened, you first see the original images and only a few microseconds are replaced by the images recolored. I would like to correct that. Someone has an idea how to do it ?
The event you are using waits for the content to finish loading on the tab and then applies the script. As the operation you want to do depends on the content loaded, I don’t know if there is another way.
– bfavaretto
I don’t know if this works but, I think you can add a "Visible:Hidden" in the image tags, so they keep loading and you can wait for all content to finish loading to run your script and show them.
– Jan Cássio
Thanks for the suggestion, but it won’t do in this case. The extension is prepared to work with any web page that is loaded in the browser, particularly all those that are not created by me. So I can’t define the state of the images.
– user3059287