Does the code scan file type by reading the URL and checking tag?
You can use existing JavaScript tools to parse out the attributes of a url and maybe in same cases there might be some dynamic stuff going on where you may want to fetch the entire url with the attributes.