From dfbe21200bbb9f782d374f86a7fa662773e7f4c4 Mon Sep 17 00:00:00 2001 From: Eduardo Rosendo Date: Sun, 31 Mar 2024 18:01:35 -0400 Subject: [PATCH 01/10] feat(toolbar): Implements logic to display gift badge icon --- src/toolbar_button.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/toolbar_button.js b/src/toolbar_button.js index 80d98455..6e4b55dd 100644 --- a/src/toolbar_button.js +++ b/src/toolbar_button.js @@ -28,6 +28,13 @@ function updateToolbarButton(tab) { }; chrome.storage.local.get('options', function(items){ + + if ('dismiss_class_action_info' in items['options']) { + chrome.browserAction.setBadgeText({}); + } else { + chrome.browserAction.setBadgeText({ text: '🎁' }); + } + if (tab === null || tab === undefined) { // There's code in Firefox that can be called before the defaults are set // and before the tab is even established. Catch that, and handle it or From 79ecdb9f39e03adf5c3ae828b538cdee5bb9e7f9 Mon Sep 17 00:00:00 2001 From: Eduardo Rosendo Date: Sun, 31 Mar 2024 18:02:16 -0400 Subject: [PATCH 02/10] feat(popup): Tweaks the options.html file to add a new banner --- src/assets/css/style.css | 19 ++++++++++ src/options.html | 78 ++++++++++++++++++++++++++++++---------- 2 files changed, 78 insertions(+), 19 deletions(-) diff --git a/src/assets/css/style.css b/src/assets/css/style.css index 3e3168ad..62de46a8 100644 --- a/src/assets/css/style.css +++ b/src/assets/css/style.css @@ -54,6 +54,13 @@ padding: 20px; height: 100%; display: grid; +} + +.grid-with-banner { + grid-template-rows: [header] auto [main] auto [footer] 42px; +} + +.regular-grid { grid-template-rows: [header] 42px [main] auto [footer] 42px; } @@ -533,6 +540,18 @@ footer #version { border-color: #255885; } +.info-banner { + background-color: #CCE5FF; + border-color: #B8DAFF; + border-radius: 4px; + padding: 28px 20px; + margin-bottom: 10px; +} + +.info-banner #message-section p{ + color: #004085 +} + /* For printed pages, we want to hide anything that we add. */ @media print { [class^="recap-"], [id^="recap-"] { /* Any class or ID that starts with `recap-` */ diff --git a/src/options.html b/src/options.html index 4df96dd8..d49c5089 100644 --- a/src/options.html +++ b/src/options.html @@ -9,29 +9,69 @@ -
+
+
- - - + +
+ -
From 82050c6e7fb2989d37d15c01697e125db2ed06fd Mon Sep 17 00:00:00 2001 From: Eduardo Rosendo Date: Tue, 2 Apr 2024 12:16:17 -0400 Subject: [PATCH 06/10] feat(background): Adds a helper method to refresh the toolbar upon installation. --- src/background.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/background.js b/src/background.js index 161f1628..f95cef29 100644 --- a/src/background.js +++ b/src/background.js @@ -4,6 +4,14 @@ exportInstance(Notifier); exportInstance(Recap); +function saveOptionsAndUpdateToolbar(options) { + chrome.storage.local.set({ options: options }, function () { + chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { + updateToolbarButton(tabs[0]); + }); + }); +} + function setDefaultOptions(details) { // Set options to their default values. console.debug('RECAP: Setting default options after install/upgrade.'); @@ -22,7 +30,7 @@ function setDefaultOptions(details) { }; if ($.isEmptyObject(items)) { console.debug('RECAP: New install. Attempting to set defaults.'); - chrome.storage.local.set({options: defaults}); + saveOptionsAndUpdateToolbar(defaults) console.debug('RECAP: Set the defaults on new install successfully.'); } else { console.debug('RECAP: Existing install. Attempting to set new ' + @@ -52,7 +60,7 @@ function setDefaultOptions(details) { } } console.debug('RECAP: Persisting new settings object.'); - chrome.storage.local.set({options: items.options}); + saveOptionsAndUpdateToolbar(items.options) } }); } From 59d0df304f658511f264f86bcbaf8708ab2fbfcf Mon Sep 17 00:00:00 2001 From: Eduardo Rosendo Date: Tue, 2 Apr 2024 12:40:58 -0400 Subject: [PATCH 07/10] feat(popup): Adds logic to dismiss badge when the popup closes --- src/background.js | 11 +++++++++++ src/options.js | 5 +++++ src/toolbar_button.js | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/background.js b/src/background.js index f95cef29..31412ac1 100644 --- a/src/background.js +++ b/src/background.js @@ -195,3 +195,14 @@ chrome.tabs.onUpdated.addListener(async function (tabId, details, tab) { chrome.tabs.onActivated.addListener(function(activeInfo){ getTabById(activeInfo.tabId, updateToolbarButton); }); + +chrome.runtime.onConnect.addListener(function (port) { + if (port.name === 'popup') { + port.onDisconnect.addListener(function () { + chrome.storage.local.get('options', function (items) { + items.options['dismiss_bagde'] = true; + saveOptionsAndUpdateToolbar(items.options); + }); + }); + } +}); diff --git a/src/options.js b/src/options.js index 4ce39766..44a4a2d6 100644 --- a/src/options.js +++ b/src/options.js @@ -137,4 +137,9 @@ function showHideReceiptsWarning (tabs){ save_options() }); } + + // Use the messaging APIs to set up a Port between the popup and background + // page. We should get a onDisconnect event in the background page when + // the popup goes away. + chrome.runtime.connect({ name: "popup" }); })(); diff --git a/src/toolbar_button.js b/src/toolbar_button.js index 6e4b55dd..1dbfe0fe 100644 --- a/src/toolbar_button.js +++ b/src/toolbar_button.js @@ -29,7 +29,7 @@ function updateToolbarButton(tab) { chrome.storage.local.get('options', function(items){ - if ('dismiss_class_action_info' in items['options']) { + if ('dismiss_bagde' in items['options'] && items['options']['dismiss_bagde']) { chrome.browserAction.setBadgeText({}); } else { chrome.browserAction.setBadgeText({ text: '🎁' }); From c048e132ac1acb39c3480577d413d2ca946dc75f Mon Sep 17 00:00:00 2001 From: Eduardo Rosendo Date: Tue, 2 Apr 2024 13:07:55 -0400 Subject: [PATCH 08/10] feat(options): Updates the save_options helper to avoid overriding the storage --- src/options.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/options.js b/src/options.js index 44a4a2d6..96623c78 100644 --- a/src/options.js +++ b/src/options.js @@ -26,23 +26,25 @@ function load_options() { } function save_options() { - let options = {}; - for (let i = 0; i < inputs.length; i++) { - if (inputs[i].type === 'checkbox' || inputs[i].type === 'radio') { - options[inputs[i].id] = inputs[i].checked; - } else if (inputs[i].type === 'text') { - options[inputs[i].id] = inputs[i].value; + chrome.storage.local.get('options', function (items) { + let options = items.options; + for (let i = 0; i < inputs.length; i++) { + if (inputs[i].type === 'checkbox' || inputs[i].type === 'radio') { + options[inputs[i].id] = inputs[i].checked; + } else if (inputs[i].type === 'text') { + options[inputs[i].id] = inputs[i].value; + } } - } - let banner = document.getElementById('header-banner'); - if (!banner) { - options['dismiss_class_action_info'] = true; - } + let banner = document.getElementById('header-banner'); + if (!banner) { + options['dismiss_class_action_info'] = true; + } - chrome.storage.local.set({ options: options }, function () { - chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { - updateToolbarButton(tabs[0]); + chrome.storage.local.set({ options: options }, function () { + chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { + updateToolbarButton(tabs[0]); + }); }); }); } From fb76144478ec50b36bec0051ed45800a02359b56 Mon Sep 17 00:00:00 2001 From: Eduardo Rosendo Date: Tue, 2 Apr 2024 16:33:35 -0400 Subject: [PATCH 09/10] feat(background): Adds helper method to compute and save the variant --- src/background.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/background.js b/src/background.js index 31412ac1..429cc6cb 100644 --- a/src/background.js +++ b/src/background.js @@ -4,6 +4,13 @@ exportInstance(Notifier); exportInstance(Recap); +function chooseVariant(details) { + const options = ['A-A', 'A-C', 'B-B', 'B-D']; + const randomIndex = Math.floor(Math.random() * options.length); + let variant = options[randomIndex]; + chrome.storage.local.set({ variant: variant }); +} + function saveOptionsAndUpdateToolbar(options) { chrome.storage.local.set({ options: options }, function () { chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { @@ -186,6 +193,7 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { chrome.runtime.onInstalled.addListener(setDefaultOptions); chrome.runtime.onInstalled.addListener(showNotificationTab); +chrome.runtime.onInstalled.addListener(chooseVariant); // Watches all the tabs so we can update their toolbar buttons on navigation. chrome.tabs.onUpdated.addListener(async function (tabId, details, tab) { From bc6f9334a0aae333866a667741a39e5ea98425cd Mon Sep 17 00:00:00 2001 From: Eduardo Rosendo Date: Tue, 2 Apr 2024 18:13:27 -0400 Subject: [PATCH 10/10] refactor(popup): Strips style attributes in the options.html file --- src/assets/css/style.css | 22 ++++++++++++++++++++-- src/options.html | 10 +++++----- src/options.js | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/assets/css/style.css b/src/assets/css/style.css index 62de46a8..02c38777 100644 --- a/src/assets/css/style.css +++ b/src/assets/css/style.css @@ -548,8 +548,26 @@ footer #version { margin-bottom: 10px; } -.info-banner #message-section p{ - color: #004085 +#info-banner-message { + font-size: 16px; + color: #004085; +} + +.banner-icon-container { + padding-top: 12.5px; + padding-right: 20px; + padding-bottom: 12.5px; +} + +#banner-icon { + width: 24px; +} + +#dismiss-banner { + padding-left: 20px; +} +#dismiss-banner button { + width: 16px; } /* For printed pages, we want to hide anything that we add. */ diff --git a/src/options.html b/src/options.html index 42b658e7..165641dc 100644 --- a/src/options.html +++ b/src/options.html @@ -15,8 +15,8 @@
-
-
+ -

+

We helped win the PACER class action lawsuit and we’re just getting started.

-
-
diff --git a/src/options.js b/src/options.js index 96623c78..209364b3 100644 --- a/src/options.js +++ b/src/options.js @@ -132,7 +132,7 @@ function showHideReceiptsWarning (tabs){ let ver = document.getElementById('version'); ver.textContent = `(version ${chrome.runtime.getManifest().version})`; - let dismiss_button = document.getElementById('dismiss-info'); + let dismiss_button = document.querySelector("#dismiss-banner button"); if (dismiss_button) { dismiss_button.addEventListener('click', function (e) { removeInfoBanner();