Switchable encapsulation of polysulfides in the transition between sulfur and lithium sulfide