To insert the same code on the purchase confirmation page, I've been able to able Anaraky's GPL-licensed GDRT extension, which creates a Block and uses
$this->getData('pageType') on a class that extends Mage_Core_Block_Abstract to only insert the block on the desired page.
e.g. in a custom module, app/code/local/Alleyne/FCT/Block/Script.php
But for the newsletter confirmation, I can't just filter by page type -- I only want to trigger it when the newsletter subscription action is taking place (which happens to be on the home page).