Skip to content

Commit

Permalink
feat(background): Adds helper method to compute and save the variant
Browse files Browse the repository at this point in the history
  • Loading branch information
ERosendo committed Apr 2, 2024
1 parent c048e13 commit fb76144
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit fb76144

Please sign in to comment.