surfasb pointed out that a basic router can't do this because they normally don't look at application layer traffic.
While there are scripts for open-source router firmware available, they aren't foolproof and require a good knowledge of what you're doing. Even then, they don't work all the time, and introduce latency (see below). Doing it wrong could brick the router.
You would need an appliance that can inspect traffic and block the things you specify. One example that I use is Untangle. You would place an appliance like this between your router and your devices. Untangle could also work as a router itself, in which case you could eliminate your current router.
Another option is getting a router/firewall that can inspect application traffic, which are usually pretty expensive. Cisco offers some options, though, in it's ASA line of firewalls.
Be aware that unless you plan on spending a lot of money, technology that could do what you are asking is going to make the internet slow (latency). The better solution would be to simply install ad-blocking software on your client machines.