It seems that the only thing you need to do to allow arbitrary selectors is to remove this if statement.