less hacky javascript detection of filename