Nice script, great job!
About the offline charging problem, as @thecoolkid
said, there's no fix at this moment, but when I was using custom ROMs, I was used to flash a hugely debloated stock system.img (~300MB) that was not able even to boot to system (and broke my data when I tried to lol), but it was able to boot to offline charging screen. So after charging, I needed to flash or restore the GSI's system image.
Well, if we could do repartitioning, maybe we could create a new partition (a "system_offlinecharging", for example), flash this debloated system.img to this partition and edit boot's fstab in order to assign the system partition to this new partition when booting from offline charging. Not sure if it would work, but maybe we can try it.