diff --git a/js/background.js b/js/background.js index 6c42ae0..c6e5458 100644 --- a/js/background.js +++ b/js/background.js @@ -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 diff --git a/js/popup.js b/js/popup.js index 2c123c9..4cf96ba 100644 --- a/js/popup.js +++ b/js/popup.js @@ -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') }) }) - }) \ No newline at end of file +}) + +// 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) \ No newline at end of file