UPDATE V1.1:
Added custom refill settings to the script. Just set the lower and upper boundaries for the refill threshold and the script will refill when the number of cannonballs in your cannon is lower than a random value below the 2 boundaries you set.
By default the script will still refill when the cannon is empty.
EDIT: update is now live