Oil trims gains, but heads for third weekly rise on demand recovery