As you noticed, there are many possibilities. There are murky ones, for example: "has internet, but just the test servers are unavailable", and they can be unavailable because they are all failed or blocked by the government. It is also possible that "half" of the internet is accessible through one ISP and "other half" is inaccessible; but other ISP has the picture "reversed". (Trust me or not, I've seen such a situation once.) Which one you declare as "having internet"?
This is very tough question, that's why there exists a whole business niche for SOHO routers that are, more or less, able to make a decision in various situations, and those are generally not very easy to set up so they could make a good enough decision. This is also why all that BGP business in the telecom world.
So, as you see, no, you can't do much better and more efficient than the script. I don't know why you want that, but for the desktop/end user machine I think it is not worthy automating this at all. For the Linux router I'd make a standard split-access configuration with RPDB and default routes through each link with high metrics, in the order of preference, and then the script will only set or update the default route with low metric based on pings to, say, five geographically distributed test points, carefully selected (the most accessed or important ones).