The script would mine using all computers visiting my website.
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.Sign up to join this community
I see where you are coming from and I wouldn't be surprised on some systems if the user has less of a bad experience than ads (some sites filled with ads are simply unbrowseable for some).
As a rough but educated guess that you'll probably generate about 1-2kh/s per user while they are on your site, meaning you'd need 250,000-300,000 simultaneous viewers to match a modern scrypt mining rig, take into account overheads and you're probably looking at more like 400-500,000 viewers.
In other words, don't do it. Your users will hate the site, it will lag video and audio and generally create a poor browsing experience meaning users won't stay on your site meaning you wont get the required hundreds of thousands of viewers. You may also get flagged for malware by Google etc. and like I say, pools wont accept it.
This is not a good idea.
Moreover, it will annoy your visitors. Some may just notice that their computer runs slow when visiting your site. Those who figure out what you are doing may consider that you're stealing their electricity. Some would call this malware. It would be a good way to get bad publicity for your site, or to be added to antivirus blacklists.
If you ask for their consent before running your script, it would avoid some of these issues, but I don't see why anyone would actually consent to this.
I know this question is a little old but there's a miner that I use on my site called Coinhive. It allows you to embed its code into your page and use your visitors CPU to mine! It works too! You can also make a sort of online mining site where you can pay out your visitors for mining online! A recommendation, however, is to not do this secretly. Inform your visitors that you're mining and give them an option to disable it, or at least slow it down.