-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (25 loc) · 925 Bytes
/
script.js
File metadata and controls
26 lines (25 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const imageElem = document.getElementById('swag');
const LeaveMeAlone = (onAnotherTabAlreadyOpen, onNewTabOpen = null) => {
const ANNOUNCEMENT_BOARDCAST = "I_AM_ON";
const ALREADY_OPEN_BROADCAST = "ANOTHER_OPEN";
const broadCast = new BroadcastChannel("cruderkat_channel");
broadCast.onmessage = e => {
if(e.data === ANNOUNCEMENT_BOARDCAST) {
if(onNewTabOpen) {
onNewTabOpen();
}
else {
broadCast.postMessage(ALREADY_OPEN_BROADCAST);
}
}
else if(e.data === ALREADY_OPEN_BROADCAST) {
onAnotherTabAlreadyOpen();
}
};
broadCast.postMessage(ANNOUNCEMENT_BOARDCAST);
};
LeaveMeAlone(() => {
alert("Are you sure you want to open a new window?");
imageElem.src = "https://c.tenor.com/pb06GKyRor0AAAAd/justin-timberlake-stare.gif";
document.title = "LOL.........";
});