vadykoo / boykottRussianBrands

2 stars 0 forks source link

Sweep: need to add to popup settings that should be stored as others in the storage #8

Open vadykoo opened 9 months ago

vadykoo commented 9 months ago

This setting will be enable tooltip So when it is disabled when the use mouseover to emoji tooltip is not appear and when it is enabled it is appearing it is usual checkbox somewhere in the popup

Checklist - [X] Modify `popup.js` ✓ https://github.com/vadykoo/boykottRussianBrands/commit/adb2ac99c3e58ad01d1e77b5369a44f7f6865868 [Edit](https://github.com/vadykoo/boykottRussianBrands/edit/sweep/need_to_add_to_popup_settings_that_shoul/popup.js#L2-L98) - [X] Running GitHub Actions for `popup.js` ✓ [Edit](https://github.com/vadykoo/boykottRussianBrands/edit/sweep/need_to_add_to_popup_settings_that_shoul/popup.js#L2-L98) - [X] Modify `background.js` ✓ https://github.com/vadykoo/boykottRussianBrands/commit/1dc85b1c0733ca5ac7d6be74a6a2c5ad831a4dcd [Edit](https://github.com/vadykoo/boykottRussianBrands/edit/sweep/need_to_add_to_popup_settings_that_shoul/background.js#L23-L246) - [X] Running GitHub Actions for `background.js` ✓ [Edit](https://github.com/vadykoo/boykottRussianBrands/edit/sweep/need_to_add_to_popup_settings_that_shoul/background.js#L23-L246) - [X] Modify `content_script.js` ✓ https://github.com/vadykoo/boykottRussianBrands/commit/ecf545a6d6c0269277c07d1a77b89c3a302e8733 [Edit](https://github.com/vadykoo/boykottRussianBrands/edit/sweep/need_to_add_to_popup_settings_that_shoul/content_script.js#L213-L247) - [X] Running GitHub Actions for `content_script.js` ✓ [Edit](https://github.com/vadykoo/boykottRussianBrands/edit/sweep/need_to_add_to_popup_settings_that_shoul/content_script.js#L213-L247)
sweep-ai[bot] commented 9 months ago

🚀 Here's the PR! #9

See Sweep's progress at the progress dashboard!
Sweep Basic Tier: I'm using GPT-4. You have 5 GPT-4 tickets left for the month and 3 for the day. (tracking ID: a91216cf27)

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).
Install Sweep Configs: Pull Request

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)

GitHub Actions✓

Here are the GitHub Actions logs prior to making any changes:

Sandbox logs for 06c7e52
Checking popup.js for syntax errors... ✅ popup.js has no syntax errors! 1/1 ✓
Checking popup.js for syntax errors...
✅ popup.js has no syntax errors!

Sandbox passed on the latest master, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/vadykoo/boykottRussianBrands/blob/06c7e5211d21e87a728864e72d363624e666154b/background.js#L23-L246 https://github.com/vadykoo/boykottRussianBrands/blob/06c7e5211d21e87a728864e72d363624e666154b/popup.js#L2-L98 https://github.com/vadykoo/boykottRussianBrands/blob/06c7e5211d21e87a728864e72d363624e666154b/content_script.js#L213-L247

Step 2: ⌨️ Coding

--- 
+++ 
@@ -60,7 +60,11 @@

 // Send a message to the background script when the popup is opened
 document.addEventListener("DOMContentLoaded", () => {
-  chrome.runtime.sendMessage({ action: "fetchBrandData" });
+  chrome.runtime.sendMessage({ action: "fetchBrandData" }, () => {
+    chrome.storage.local.get({ tooltipEnabled: true }, ({ tooltipEnabled }) => {
+      createTooltipSettingCheckbox(tooltipEnabled);
+    });
+  });

@@ -87,6 +91,35 @@
           }
         );
       }
+  // Create the tooltip setting checkbox
+  function createTooltipSettingCheckbox(enabled) {
+    const settingsForm = document.getElementById("settingsForm");
+    const tooltipSettingTemplate = document.getElementById("tooltipSettingTemplate");
+    const tooltipSettingContainer = tooltipSettingTemplate.content.cloneNode(true);
+
+    const tooltipCheckbox = tooltipSettingContainer.querySelector(".tooltipCheckbox");
+    tooltipCheckbox.checked = enabled;
+
+    const label = tooltipSettingContainer.querySelector(".tooltipLabel");
+    label.textContent = "Enable Tooltips";
+
+    settingsForm.appendChild(tooltipSettingContainer);
+
+    // Add event listener to toggle tooltip setting and send message to background script
+    tooltipCheckbox.addEventListener("change", () => {
+      const toggleData = {
+        action: "toggleTooltipSetting",
+        enabled: tooltipCheckbox.checked,
+      };
+      chrome.runtime.sendMessage(toggleData, (response) => {
+        if (chrome.runtime.lastError) {
+          console.error(chrome.runtime.lastError.message);
+        } else {
+          console.log(`Tooltip setting toggled: ${tooltipCheckbox.checked}`);
+        }
+      });
+    });
+  }
     });

     chrome.storage.local.get({ customBrands: [] }, ({ customBrands }) => {
@@ -263,4 +296,10 @@

     console.log('usersett', userSettings);
   });
-}+}
+  // Call createTooltipSettingCheckbox within the DOMContentLoaded event listener
+  document.addEventListener("DOMContentLoaded", () => {
+    chrome.storage.local.get({ tooltipEnabled: true }, ({ tooltipEnabled }) => {
+      createTooltipSettingCheckbox(tooltipEnabled);
+    });
+  });

Ran GitHub Actions for adb2ac99c3e58ad01d1e77b5369a44f7f6865868:

--- 
+++ 
@@ -31,7 +31,7 @@
 };

 function saveDefaultBrandDataToStorage() {
-  chrome.storage.local.get({ brandData: null }, ({ brandData }) => {
+  chrome.storage.local.get({ brandData: null, tooltipEnabled: true }, ({ brandData, tooltipEnabled }) => {
     if (!brandData) {
       // If brandData is not in local storage, fetch the defaultBrandData
       fetchDefaultBrandDataFromGithub().then((defaultBrandData) => {
@@ -48,6 +48,12 @@
 saveDefaultBrandDataToStorage();

 chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
+  if (message.action === "toggleTooltipSetting") {
+    chrome.storage.local.set({ tooltipEnabled: message.enabled }, () => {
+      sendResponse({ success: true });
+    });
+    return true;
+  }
   if (message.action === "fetchBrandData") {
     fetchBrandDataFromGithub().then((brandData) => {
       console.log(brandData);
@@ -158,6 +164,13 @@
 function fetchBrandDataFromGithub() {
   return fetch("https://raw.githubusercontent.com/vadykoo/russianBrandsInUkraine/master/russianInternationalBrandsNew.json")
   .then((response) => response.json())
+    .then((fetchedBrandData) => {
+      return chrome.storage.local.get({ tooltipEnabled: true })
+        .then(({ tooltipEnabled }) => {
+          fetchedBrandData.tooltipEnabled = tooltipEnabled;
+          return fetchedBrandData;
+        });
+    })
   .then((fetchedBrandData) => {
     return new Promise((resolve, reject) => {
       fetchDefaultBrandDataFromGithub().then((defaultBrandData) => {

Ran GitHub Actions for 1dc85b1c0733ca5ac7d6be74a6a2c5ad831a4dcd:

--- 
+++ 
@@ -189,7 +189,7 @@

 // Function to traverse and add emojis to all text nodes on the page
-function traverseAndAddEmojis(node, brandData) {
+function traverseAndAddEmojis(node, brandData, tooltipEnabled) {
   if (node.nodeType === Node.TEXT_NODE) {
     addEmojisToTextNode(node, brandData);
   } else if (
@@ -201,7 +201,7 @@
     let i = 0;
     function processNextChild() {
       if (i < node.childNodes.length) {
-        traverseAndAddEmojis(node.childNodes[i], brandData);
+        if (tooltipEnabled) { traverseAndAddEmojis(node.childNodes[i], brandData, tooltipEnabled); }
         i++;
         processNextChild();
       }
@@ -213,7 +213,7 @@

 // Retrieve brandData from local storage or use default values
 chrome.storage.local.get(
-  { brandData: null, extensionEnabled: true },
+  { brandData: null, extensionEnabled: true, tooltipEnabled: true },
   ({ brandData, extensionEnabled }) => {
     if (!extensionEnabled) {
       console.log("Extension is disabled");
@@ -231,7 +231,7 @@
       let pendingMutations = false;

       requestIdleCallback(() => {
-        traverseAndAddEmojis(document.body, brandData);
+        traverseAndAddEmojis(document.body, brandData, tooltipEnabled);
       });

       observer = new MutationObserver((mutationsList) => {
@@ -248,7 +248,7 @@
               if (node.nodeType === Node.TEXT_NODE) {
                 addEmojisToTextNode(node, brandData);
               } else if (node.nodeType === Node.ELEMENT_NODE) {
-                traverseAndAddEmojis(node, brandData);
+                if (tooltipEnabled) { traverseAndAddEmojis(node, brandData, tooltipEnabled); }
               }
             });
           }
@@ -264,7 +264,7 @@
                 if (node.nodeType === Node.TEXT_NODE) {
                   addEmojisToTextNode(node, brandData);
                 } else if (node.nodeType === Node.ELEMENT_NODE) {
-                  traverseAndAddEmojis(node, brandData);
+                  if (tooltipEnabled) { traverseAndAddEmojis(node, brandData, tooltipEnabled); }
                 }
               });
             }

Ran GitHub Actions for ecf545a6d6c0269277c07d1a77b89c3a302e8733:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/need_to_add_to_popup_settings_that_shoul.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord

This is an automated message generated by Sweep AI.