Improve user agent matching code in PaperScript.

Fixes #511.