Triplanar mapping from Local Space - problem when scaling. How to make it work?

To be honest I am clueless where this should be hooked up really. I am hooking nodes somewhat randomly for days already and my opinion that I can brute force solutions like that diminishes hah… I don’t have the needed knowledge.