mirror of
https://github.com/FranP-code/wii-shop-extension.git
synced 2025-10-12 23:52:52 +00:00
Stop music playback on popup close, if possible
This commit is contained in:
@@ -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
|
// Show notification on extension install
|
||||||
chrome.runtime.onInstalled.addListener(function () {
|
chrome.runtime.onInstalled.addListener(function () {
|
||||||
// Set most options
|
// Set most options
|
||||||
|
|||||||
10
js/popup.js
10
js/popup.js
@@ -13,6 +13,12 @@ chrome.storage.local.get(function (data) {
|
|||||||
// Button link functionality
|
// Button link functionality
|
||||||
document.querySelectorAll('button[data-link]').forEach(function (el) {
|
document.querySelectorAll('button[data-link]').forEach(function (el) {
|
||||||
el.addEventListener('click', function () {
|
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)
|
||||||
Reference in New Issue
Block a user