I read some articles about hacks that have hacked routers which inject ads on websites a visitor visits that replace adsense ads
Is it really possible? How can a router hack inject javascript code into browser I dont understand
I'm not sure exactly what type of attack you are referencing but consider this...if an attacker controls your router what is to stop them from making any arbitrary change to unencrypted data? The packets pass through the router and the router could (if desired) make any change to the packet that the attacker desires (assuming he has taught the router how to make the changes properly). If the data is encrypted end to end this becomes much more difficult to pull off (still possible through a more complex attack path).