Probing charmonium-like XYZ states in hadron–hadron ultraperipheral collisions and electron–proton scattering