diff options
author | Florrie <towerofnix@gmail.com> | 2019-03-26 11:16:04 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2019-03-26 11:16:04 -0300 |
commit | 7dbcbe1ebb08cf3201df644561bc8de357e8f9ba (patch) | |
tree | 6ec67f6c17af463910749f30721566ecc4f635b5 /extension | |
parent | a6b148696d4430656708148787af5b6f738ec9a1 (diff) |
Diffstat (limited to 'extension')
-rw-r--r-- | extension/interactive-bgm.js | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/extension/interactive-bgm.js b/extension/interactive-bgm.js index 2bafe54..9c0e5dd 100644 --- a/extension/interactive-bgm.js +++ b/extension/interactive-bgm.js @@ -1,18 +1,17 @@ const sendURL = () => { - browser.runtime.sendMessage({urlString: location.toString()}); + if (!document.hidden) { + browser.runtime.sendMessage({urlString: location.toString()}); + } }; window.addEventListener('focus', sendURL); +window.addEventListener('popstate', sendURL); +document.addEventListener('visibilitychange', sendURL); +sendURL(); -document.addEventListener('visibilitychange', () => { - if (!document.hidden) { - sendURL(); - } -}); - -if (!document.hidden) { - sendURL(); -} +// Some things we just can't reliably detect through event, like the location being changed via JS. +// To catch those, we poll regularly. +setInterval(sendURL, 1000); let isShowingCreateTrack = false; |