The following JS can be used in sandboxes:
fetch('/changemgmt/listOutboundChangeSet.apexp', {
credentials: 'same-origin'
}).then(function(response) {
return response.text();
}).then(function(text) {
var p = new DOMParser();
var d = p.parseFromString(text, 'text/html');
var thisOrgEl = d.getElementById('thisOrg');
var sandboxName = thisOrgEl.children[0].innerText.split('\n')[0];
});
Need to test this out in a production org