I think you are on to something here.
Some kind of combination of your previous script and this one, based on whether or not you have a selection(?) perhaps?
I.e. If you have a selection it does a replacement (above script). And if no selection, it pops up a dialog box and prompts you for the number of times to replicate the current line (previous script), replacing the digits. (So long as there are no other digits in the text).
Thanks again for your feedback!