I am building a Chrome Extension in which I want to edit the style of the web pages I visit by using keypress. I am trying to target all style elements (I tried it now by using *).
I found multiple parts of code online, all of which don't seem to work:
$("*").keypress(function(event){
if(event.which==65 {
$("*").css("background-color", "white");
}
}
Or:
$( "body" ).keydown(function( event) {
if (event.which == 65 {
$("body").css("color","white");
}
});
Or:
function changeColor() {
var color = document.getElementById("color").value;
document.body.style.background = color;
}
document.querySelector('#color').addEventListener('keydown', function(e) {
if (e.keyCode === 65) { // enter key
changeColor("red");
}
});
The ideal changes would be:
Key press a > change background to white
Key press b > change font to helvetica
Key press c > hide all images
Key press d > hide all text
At the moment I don't get any results at all (while changing the background in css immediately works).