I actually found this trick yesterday minutes after posting, and it seems to be working quite well. At the top of the js file you include the following code and since it's run as the DOM is being built, the last <script> tag in the document has to be the one you are in. Thus:
var scripts = document.getElementsByTagName('script');
var script = scripts[scripts.length - 1];
var pathWithFile = script.getAttribute("src");
var path = pathWithFile.indexOf('/') >= 0
? pathWithFile.match(/^(.+)\//)[0]
: '';
It's working quite well.