DON’T USE USERAGENT.
Really. No. Just not. Pass away.
If you go this way, you will only ensure that the day they launch a new browser, or when one of the current mobile browsers changes its value from user agent, your site will get all broken up for many people. I’ve seen this happen before.
There are two elegant ways to know if you should serve a mobile version of your site or not.
Check the screen size in hand. Kind like this:
if (screen.width < 640 || screen.height < 480) {
// sirva a versão pra celular
} else if (screen.width < 1024 || screen.height < 768) {
// talvez seja uma boa usar versão pra tablet
} else {
// sirva a versão normal
}
This form is for small, smaller cases, proof of concept maybe. Note that this form may be dated in a few years: if mobile phones keep the trend of having screen resolution increasing, this strategy will eventually stop working.
Use a library such as Modernizr, that has a functionality called "Feature detection". This is a much more elaborate way of knowing what the user’s browser can understand and render. It goes beyond determining only the size factor of the user’s device. Based on what you get when using the Modernizr API you define if and how it will serve some content.
Take a look at the documentation.
You can also use the Bootstrap to facilitate styling work. You can write a single HTML that automatically fits and looks beautiful on mobile, tablet, desktop and screen.
Edit: you say you would like to improve the user experience by putting or removing buttons, etc.
Maybe what you’re really interested in is knowing if the device has a touch screen, right? So you can serve an interface made to be played if there is support, and a clickable interface otherwise.
Many laptops nowadays have touch screen. I have one with a very large screen and run Windows and Chrome on it. Every site that uses the simple reading of user agent is already broken by default for me.
The correct way to verify this with Modernizr is:
var euDevoServirConteudoTouch = Modernizr.touch;
That’s much more accurate than reading the user agent, because then you know if the user will use a touch-sensitive device regardless of the device being mobile.