You can use coinhive's
HTTP API for that. Everything is well documented there.
But I recommend you use
WebMinePool for mining script. Its much better and higher paying with a nice and trusted dev! With webminepool you can even pay your users for
command line mining. It also has the
feature you requested.