Currently, there is no way for the user script itself to know what URL it was downloaded from.
This comes useful if the same script is deployed to multiple environments (i.e. can be installed from different URLs) and needs to make an AJAX call to a resource on the same environment that it came from.
For example, if my script is installed from
http://dev.mysite.com/GM/myGM.user.js OR http://qa.mysite.com/GM/myGM.user.js
I'd like GM_info.script.downloadUrl to return the appropriate URL so I could determine the host and call
http://dev.mysite.com/AJAX/GetData OR http://qa.mysite.com/AJAX/GetData.
The only workaround I could come up with is to have a
// @resource downloadHost getHost.php
where getHost.php determines where it's being served from and ouputs the path to itself. For example, if you browsed to
http://dev.mysite.com/GM/getHost.php the response would be "http://dev.mysite.com/GM/".
Then in my user script I can call GM_getResourceText('downloadHost') and it would return me "http://dev.mysite.com/GM/" no matter what URL my script runs at.
Such workaround is an overkill though and it would be so much easier if you could expose script's original download URL via a property like GM_info.script.downloadUrl.
This is probably a reasonable request. Might need to spend some time thinking about privacy implications.
Another possible (simpler?) workaround: put a file named "environment.js" next to each script. // @require environment.js and have each one assign a value to a particular variable. No special server side logic, just another file.
// @require environment.js