Stop music playback on popup close, if possible

This commit is contained in:
Corbin Davenport
2022-01-23 01:51:07 -05:00
parent 09cf40353c
commit f113f287fb
2 changed files with 18 additions and 2 deletions

View File

@@ -57,6 +57,16 @@ chrome.tabs.onActivated.addListener(function (activeInfo) {
})
})
// Listen for pause/play commands from popup
chrome.runtime.onMessage.addListener(function (request) {
if (request === 'pause') {
themeAudio.src = ''
} else if (request === 'play') {
themeAudio.src = currentMusic
themeAudio.play()
}
})
// Show notification on extension install
chrome.runtime.onInstalled.addListener(function () {
// Set most options

View File

@@ -13,6 +13,12 @@ chrome.storage.local.get(function (data) {
// Button link functionality
document.querySelectorAll('button[data-link]').forEach(function (el) {
el.addEventListener('click', function () {
chrome.tabs.create({ url: el.getAttribute('data-link') })
chrome.tabs.create({ url: el.getAttribute('data-link') })
})
})
})
// Pause music when page closes
// This only works on the popup opened from the notification, not the browserAction button
window.addEventListener("beforeunload", function (e) {
chrome.runtime.sendMessage('pause')
}, false)