I'm currently making my first chrome extension that makes some HTML changes(filters posts) based on the presence of a particular keyword. This however works just for the first time the page is loaded, and the extension clicked, and not when more stories are loaded. I read that livequery helps, but for some reason that too isn't working, maybe it's depreciated.
Currently, I'm sending a message from the background script to execute the filtering.
content.js
chrome.runtime.onMessage.addListener(function(message, sender, response){
if(message.type=="color-divs"){
var divs = document.getElementsByClassName("userContent");
var blacklist = [
"Trump"
]
for(var i=0; i<blacklist.length; i++){
for(var j=0; j<divs.length; j++){
var ps = divs[j].getElementsByTagName('p');
var p = ps[0];
if(p.innerHTML.indexOf(blacklist[i]) != -1 ){
alert("lol");
var parent = divs[j].parentNode;
for(var k = 0; k<parent.childNodes.length; k++){
alert(parent.childNodes[k].className);
if (parent.childNodes[k].className == "_5x46") {
parent.childNodes[k].style.opacity = "0.0";
}
if (parent.childNodes[k].className == "_5pbx userContent") {
parent.childNodes[k].style.backgroundColor = "black";
}
if (parent.childNodes[k].className == "_3x-2") {
parent.childNodes[k].style.opacity = "0.0";
}
}
}
}
}
}
});