20 lines
466 B
JavaScript
20 lines
466 B
JavaScript
|
|
const state ={height: -1, url: ''};
|
|
|
|
function urlWithoutOrigin(url){
|
|
return url.replace(new URL(url).origin, "");
|
|
}
|
|
|
|
function sendEvent(){
|
|
const height = document.documentElement.offsetHeight;
|
|
const url = urlWithoutOrigin(document.URL);
|
|
if(height === state.height && url === state.url){
|
|
return;
|
|
}
|
|
state.height = height;
|
|
state.url = url;
|
|
const event = {... state};
|
|
window.parent.postMessage(event, "*");
|
|
}
|
|
|
|
window.setInterval(sendEvent, 100) |