toggle button to turn on and off split view

Hi, I'm looking for a way to enter into native split view mode and exit the fullscreen mode with the same button on my touch bar once taped a second time. My macbook pro M1 is on Big sur. I've found topics here talking about Applescript but I tried to implement the script and it doesn't work. To be honest, I don't understand anything about variables, if, else stuff like that.