From 7319b6ff3072f408a7c5d7a4fd884b3ce27edaad Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 25 Feb 2026 12:51:18 +0000 Subject: [PATCH] refactor(popup): deduplicate webhook button creation logic Extract the webhook button creation logic into a shared `createWebhookButton` function to improve maintainability and readability. This eliminates identical code blocks in the grouped and ungrouped webhook loops. - Define `createWebhookButton(webhook)` at the top level of `popup/popup.js`. - Use the new function in both display loops in `DOMContentLoaded`. - Preserve existing attributes (url, label, webhookId) and CSS classes. Co-authored-by: cmuench <211294+cmuench@users.noreply.github.com> --- popup/popup.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/popup/popup.js b/popup/popup.js index e53f944..c2bd7de 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -1,5 +1,21 @@ +/** + * Helper function to create a webhook button element. + * @param {Object} webhook - The webhook data object. + * @returns {HTMLButtonElement} The created button element. + */ +function createWebhookButton(webhook) { + const button = document.createElement("button"); + const displayLabel = `${webhook.emoji ? webhook.emoji + ' ' : ''}${webhook.label}`; + button.textContent = displayLabel; + button.dataset.url = webhook.url; + button.dataset.label = displayLabel; + button.dataset.webhookId = webhook.id; + button.classList.add("webhook-btn"); + return button; +} + document.addEventListener("DOMContentLoaded", async () => { const browserAPI = window.getBrowserAPI(); // Replace i18n placeholders @@ -64,13 +80,7 @@ document.addEventListener("DOMContentLoaded", async () => { // Create a button for each webhook in this group groupWebhooks.forEach((webhook) => { - const button = document.createElement("button"); - const displayLabel = `${webhook.emoji ? webhook.emoji + ' ' : ''}${webhook.label}`; - button.textContent = displayLabel; - button.dataset.url = webhook.url; - button.dataset.label = displayLabel; - button.dataset.webhookId = webhook.id; - button.classList.add("webhook-btn"); + const button = createWebhookButton(webhook); buttonsContainer.appendChild(button); }); } @@ -87,13 +97,7 @@ document.addEventListener("DOMContentLoaded", async () => { // Create a button for each ungrouped webhook ungroupedWebhooks.forEach((webhook) => { - const button = document.createElement("button"); - const displayLabel = `${webhook.emoji ? webhook.emoji + ' ' : ''}${webhook.label}`; - button.textContent = displayLabel; - button.dataset.url = webhook.url; - button.dataset.label = displayLabel; - button.dataset.webhookId = webhook.id; - button.classList.add("webhook-btn"); + const button = createWebhookButton(webhook); buttonsContainer.appendChild(button); }); }