Perhaps pull scope || scope.ownerDocument out into a var (called e.g. ownerDocument) and then call evaluate on that, rather than repeating all the args to evaluate here and above?

Similarly in getContrastRatioProperties().