I want to edit two specific lines in some websites, automatically after loading. I want to edit <div >
to <div style="display:none">
, and <div style="display:none">
to <div >
. The part to edit will be the same, on the sites, but i can´t say in which line, so it needed to be searched. It doesn´t matter, if this happens before or after the page loaded. I looked at Tampermonkey and Stylus, for example. Or is there a better solution?
CodePudding user response:
Use this snippet.
// Gets all elements with className 1 given in quotes and takes the first element of that list by using [0]
const divOne = document.getElementsByClassName("1")[0];
changeDisplayOnElement(divOne);
//Similarly
const divTwo = document.getElementsByClassName("2")[0];
changeDisplayOnElement(divTwo);
//change the property display under style to none, if it's block
function changeDisplayOnElement(element){
element.style.display = element.style.display === "none" ? "block" : "none";
}