From 4ee0a221cd9ca8c262d7f272f0845526110dc633 Mon Sep 17 00:00:00 2001 From: Will Minnis Date: Sat, 12 Sep 2020 15:57:55 -0700 Subject: [PATCH 1/2] Added Amazon Smile links to the site list, and added a listener for tab changes so the music properly stops if the shopping tab is changed or closed. --- js/background.js | 17 ++++++++++++++++- js/site-list.js | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/js/background.js b/js/background.js index c9f8de8..5dbf34b 100644 --- a/js/background.js +++ b/js/background.js @@ -31,6 +31,21 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo) { }) }) +// Detect shopping tab becoming inactive/closed, if the domain matches a shopping site, play music +chrome.tabs.onActivated.addListener(function(activeInfo) { + chrome.tabs.get(activeInfo.tabId, function(tab) { + var url = new URL(tab.url) + var domain = url.hostname.toString().replace('www.','') + console.log(domain) + if (!siteList.includes(domain)) { + themeAudio.pause() + } + else { + themeAudio.play() + } + }) +}) + // Show notification on extension install chrome.runtime.onInstalled.addListener(function() { chrome.notifications.create({ @@ -39,4 +54,4 @@ chrome.runtime.onInstalled.addListener(function() { 'title': 'Wii Shop Music extension installed!', 'message': 'The Wii Shop theme will now play when you visit shopping websites.' }) -}) \ No newline at end of file +}) diff --git a/js/site-list.js b/js/site-list.js index 5fee2a5..608c6b2 100644 --- a/js/site-list.js +++ b/js/site-list.js @@ -12,7 +12,21 @@ const siteList = [ 'amazon.com.mx', 'amazon.nl', 'amazon.es', - 'amazon.co.uk', + 'smile.amazon.co.uk', + 'smile.amazon.com', + 'smile.amazon.com.au', + 'smile.amazon.com.br', + 'smile.amazon.ca', + 'smile.amazon.cn', + 'smile.amazon.fr', + 'smile.amazon.de', + 'smile.amazon.in', + 'smile.amazon.it', + 'smile.amazon.co.jp', + 'smile.amazon.com.mx', + 'smile.amazon.nl', + 'smile.amazon.es', + 'smile.amazon.co.uk', 'bestbuy.com', 'bhphotovideo.com', 'ebay.com', @@ -42,4 +56,4 @@ const siteList = [ 'flipkart.com', 'qvc.com', 'shopping.google.com' -] \ No newline at end of file +] From d9bb2fee55cb8b6359b17f9c48665f3217d19ff5 Mon Sep 17 00:00:00 2001 From: Will Minnis Date: Sat, 12 Sep 2020 15:57:55 -0700 Subject: [PATCH 2/2] Added Amazon Smile links to the site list, and added a listener for tab changes so the music properly stops if the shopping tab is changed or closed. --- js/background.js | 17 ++++++++++++++++- js/site-list.js | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/js/background.js b/js/background.js index c9f8de8..5dbf34b 100644 --- a/js/background.js +++ b/js/background.js @@ -31,6 +31,21 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo) { }) }) +// Detect shopping tab becoming inactive/closed, if the domain matches a shopping site, play music +chrome.tabs.onActivated.addListener(function(activeInfo) { + chrome.tabs.get(activeInfo.tabId, function(tab) { + var url = new URL(tab.url) + var domain = url.hostname.toString().replace('www.','') + console.log(domain) + if (!siteList.includes(domain)) { + themeAudio.pause() + } + else { + themeAudio.play() + } + }) +}) + // Show notification on extension install chrome.runtime.onInstalled.addListener(function() { chrome.notifications.create({ @@ -39,4 +54,4 @@ chrome.runtime.onInstalled.addListener(function() { 'title': 'Wii Shop Music extension installed!', 'message': 'The Wii Shop theme will now play when you visit shopping websites.' }) -}) \ No newline at end of file +}) diff --git a/js/site-list.js b/js/site-list.js index 5fee2a5..74de131 100644 --- a/js/site-list.js +++ b/js/site-list.js @@ -13,6 +13,21 @@ const siteList = [ 'amazon.nl', 'amazon.es', 'amazon.co.uk', + 'smile.amazon.co.uk', + 'smile.amazon.com', + 'smile.amazon.com.au', + 'smile.amazon.com.br', + 'smile.amazon.ca', + 'smile.amazon.cn', + 'smile.amazon.fr', + 'smile.amazon.de', + 'smile.amazon.in', + 'smile.amazon.it', + 'smile.amazon.co.jp', + 'smile.amazon.com.mx', + 'smile.amazon.nl', + 'smile.amazon.es', + 'smile.amazon.co.uk', 'bestbuy.com', 'bhphotovideo.com', 'ebay.com', @@ -42,4 +57,4 @@ const siteList = [ 'flipkart.com', 'qvc.com', 'shopping.google.com' -] \ No newline at end of file +]