2022-04-21 23:05:56 -04:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
export default ({ store, isHMR, app }, inject) => {
|
|
|
|
inject('preventMultitabs', main)
|
|
|
|
}
|
|
|
|
function main(store) {
|
|
|
|
const id = Date.now()
|
|
|
|
window.id = id
|
|
|
|
window.localStorage.setItem('firstTab', id)
|
|
|
|
|
|
|
|
const onLocalStorageEvent = function(e) {
|
|
|
|
// the second tab will write its id to this key. The first one will notice it
|
|
|
|
if (e.key === 'firstTab') {
|
|
|
|
const newID = Date.now()
|
|
|
|
console.log('Another tab detected. Setting the new page id', newID)
|
|
|
|
setTimeout(() => {
|
|
|
|
window.localStorage.secondTab = newID // this is going to be a message for the second tab
|
|
|
|
}, 200)
|
|
|
|
}
|
|
|
|
|
|
|
|
// the second tab proccesses the message
|
|
|
|
if (e.key === 'secondTab' && window.id.toString() === window.localStorage.firstTab) {
|
|
|
|
console.log('There is another tab that already opened. We will close this one')
|
|
|
|
window.multipleTabsDetected = true
|
|
|
|
window.onbeforeunload = null
|
|
|
|
window.alert(
|
2023-06-13 08:57:35 -04:00
|
|
|
'Multiple tabs opened. Your page will be closed. Please only use single instance of https://tornado.ws'
|
2022-04-21 23:05:56 -04:00
|
|
|
)
|
2023-06-13 08:57:35 -04:00
|
|
|
window.location = 'https://t.me/TornadoOfficial'
|
2022-04-21 23:05:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// this event will only trigger when a window other than itself makes changes to local storage.
|
|
|
|
setTimeout(() => {
|
|
|
|
window.addEventListener('storage', onLocalStorageEvent, false)
|
|
|
|
}, 100)
|
|
|
|
}
|