Ola Hallengren Index maintenance on servers with Availability Groups
Yes, the script is intelligent enough.

This is explicitly stated in the FAQ:


  How should I configure IndexOptimize for an Availability Group?
  
  Indexes can only be rebuilt or reorganized and statistics only updated
  on the primary replica in an availability group. IndexOptimize has a
  check for this.
  
  The jobs should be configured identically and be enabled and scheduled
  on all the replicas.