Please note that this classifies as a customization request, so I can’t guarantee that my suggestions will work in any case.
I would probably make it into a function, and use it something like this, together with the filter:
I have not tested this, I just put together based on your code. Basically you will have to change lines 35 and 38 to return the URLs you need.Best,
If you like my products, don't forget to rate them on codecanyon :)