I guess you could always use a site collection token in your URL.
~sitecollection
URLs and tokens in SharePoint 2013
If that don't work out for you, this blog post has a lot of great examples when working with masterpages and references. Use Site Url in SharePoint
Update
Try using a scriptlink instead. I'm unsure if encoding is needed thought. Try to have a blank space instead of %20
in /Style%20Library/
.
<SharePoint:Scriptlink runat="server" Name="~sitecollection/Style%20Library/Custom JS/HideTreeViewFolder.js" Language="javascript" />