Online-Harmonic-Detection-Based System Stabilization Function for Grid-Forming Inverters Under Various Grid Conditions