Open vadykoo opened 9 months ago
a91216cf27
)[!TIP] I can email you next time I complete a pull request if you set up your email here!
Here are the GitHub Actions logs prior to making any changes:
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.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
popup.js
✓ https://github.com/vadykoo/boykottRussianBrands/commit/adb2ac99c3e58ad01d1e77b5369a44f7f6865868 Edit
Modify popup.js with contents:
• Add a new function `createTooltipSettingCheckbox` that creates a checkbox for enabling/disabling tooltips. This function should create a checkbox element, label it appropriately (e.g., "Enable Tooltips"), and append it to the popup's DOM.
• Add an event listener to the new checkbox that sends a message to the background script when the checkbox's state changes. The message should contain an action, such as `{ action: "toggleTooltipSetting", enabled: checkbox.checked }`.
• Call `createTooltipSettingCheckbox` within the `DOMContentLoaded` event listener to ensure the checkbox is created when the popup is loaded.
• Modify the `chrome.storage.local.get` call within the `DOMContentLoaded` event listener to also retrieve the tooltip setting from local storage and set the checkbox's checked state accordingly.
--- +++ @@ -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); + }); + });
popup.js
✓ Edit
Check popup.js with contents:
Ran GitHub Actions for adb2ac99c3e58ad01d1e77b5369a44f7f6865868:
background.js
✓ https://github.com/vadykoo/boykottRussianBrands/commit/1dc85b1c0733ca5ac7d6be74a6a2c5ad831a4dcd Edit
Modify background.js with contents:
• Add a new key-value pair to the `chrome.storage.local.get` call within the `saveDefaultBrandDataToStorage` function to include a default value for the tooltip setting, such as `{ tooltipEnabled: true }`.
• Add a new case in the `chrome.runtime.onMessage.addListener` function to handle the `"toggleTooltipSetting"` action. This case should update the `tooltipEnabled` value in local storage based on the message received.
• Update the `fetchBrandDataFromGithub` function to merge the `tooltipEnabled` setting from local storage with the fetched brand data before resolving the promise.
--- +++ @@ -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) => {
background.js
✓ Edit
Check background.js with contents:
Ran GitHub Actions for 1dc85b1c0733ca5ac7d6be74a6a2c5ad831a4dcd:
content_script.js
✓ https://github.com/vadykoo/boykottRussianBrands/commit/ecf545a6d6c0269277c07d1a77b89c3a302e8733 Edit
Modify content_script.js with contents:
• Modify the `chrome.storage.local.get` call to also retrieve the `tooltipEnabled` setting.
• Update the `traverseAndAddEmojis` function call to pass the `tooltipEnabled` setting as an argument.
• Modify the `traverseAndAddEmojis` function to conditionally add tooltips to emojis based on the `tooltipEnabled` setting. If `tooltipEnabled` is false, the function should not add any tooltip attributes to the emoji elements.
--- +++ @@ -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); } } }); }
content_script.js
✓ Edit
Check content_script.js with contents:
Ran GitHub Actions for ecf545a6d6c0269277c07d1a77b89c3a302e8733:
I have finished reviewing the code for completeness. I did not find errors for sweep/need_to_add_to_popup_settings_that_shoul
.
💡 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.
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)