Change the behavior of cancel button or add a new button which triggers a script when clicked

Hi All,

We regularly use jenkins cancel button on the UI to cancel any running jobs or in queue one’s.
But we want to change the behavior of this button or add a new button (in pipeline page) to trigger a customised shell / python script.
Please provide any insight on the above things.

Thank you.