Cleanup code, replace audio with versions from MarioCubeLite

This commit is contained in:
Corbin Davenport
2021-03-08 13:38:03 -05:00
parent 4a2b146226
commit 8ebe48a11c
3 changed files with 21 additions and 24 deletions

View File

@@ -17,9 +17,8 @@ var themeAudio = new Audio(chrome.extension.getURL('wii-shop-theme.ogg'))
themeAudio.volume = 0.5 themeAudio.volume = 0.5
themeAudio.loop = true themeAudio.loop = true
// Detect new page loads in active tab, if the domain matches a shopping site, play music // Function for checking if music should be playing in current tab
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo) { function checkMusic(tabs) {
chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
var url = new URL(tabs[0].url) var url = new URL(tabs[0].url)
var domain = url.hostname.toString().replace('www.', '') var domain = url.hostname.toString().replace('www.', '')
console.log(domain) console.log(domain)
@@ -28,21 +27,19 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo) {
} else { } else {
themeAudio.pause() themeAudio.pause()
} }
}
// Detect new page loads in active tab, if the domain matches a shopping site, play music
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo) {
chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
checkMusic(tabs)
}) })
}) })
// Detect shopping tab becoming inactive/closed, if the domain matches a shopping site, play music // Detect shopping tab becoming inactive/closed, if the domain matches a shopping site, play music
chrome.tabs.onActivated.addListener(function (activeInfo) { chrome.tabs.onActivated.addListener(function (activeInfo) {
chrome.tabs.get(activeInfo.tabId, function(tab) { chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
var url = new URL(tab.url) checkMusic(tabs)
var domain = url.hostname.toString().replace('www.','')
console.log(domain)
if (!siteList.includes(domain)) {
themeAudio.pause()
}
else {
themeAudio.play()
}
}) })
}) })

BIN
wii-shop-banner-theme.ogg Normal file

Binary file not shown.

Binary file not shown.