Is it possible to add a timer to this

Yes, something similar came up before, you can use setTimeout().