<button type="button" id="but">Play</button>
let ev = new Event('my-event');
but.addEventListener('click', function () {
let variable = 'data';
window.dispatchEvent(ev)
})
window.addEventListener('my-event', function (e) {
alert('my-event run');
})