to the best of my understanding, the google API console does not accept wild card characters in the domain registration. you have to enter the entire domain with out trying to use wild card characters when generating the api key.
also I believe the API key is now optional, both under the V2 and Newer V3 api.
instead of trying use javascript to fudge the api key, leave it out altogether.