@@ -18,6 +18,54 @@ const normalizeWebhookRecord = (webhook) => {
1818 } ;
1919} ;
2020
21+ // Helper to create a webhook list item
22+ const createWebhookListItem = ( webhook ) => {
23+ const listItem = document . createElement ( "li" ) ;
24+ listItem . dataset . id = webhook . id ;
25+ listItem . draggable = true ;
26+ listItem . classList . add ( "webhook-item" ) ;
27+
28+ const dragHandle = document . createElement ( "span" ) ;
29+ dragHandle . classList . add ( "drag-handle" ) ;
30+ dragHandle . textContent = "\u2630" ; // common drag icon
31+
32+ const textContent = document . createElement ( "div" ) ;
33+ textContent . classList . add ( "webhook-info" ) ;
34+
35+ const labelSpan = document . createElement ( "span" ) ;
36+ labelSpan . classList . add ( "label" ) ;
37+ labelSpan . textContent = `${ webhook . emoji ? webhook . emoji + ' ' : '' } ${ webhook . label } ` ;
38+
39+ const urlSpan = document . createElement ( "span" ) ;
40+ urlSpan . classList . add ( "url" ) ;
41+ urlSpan . textContent = webhook . url ;
42+
43+ textContent . appendChild ( labelSpan ) ;
44+ textContent . appendChild ( urlSpan ) ;
45+
46+ const deleteButton = document . createElement ( "button" ) ;
47+ // Use localized text for the button
48+ deleteButton . textContent = browser . i18n . getMessage ( "optionsDeleteButton" ) ;
49+ deleteButton . classList . add ( "delete-btn" ) ;
50+
51+ // Add edit button
52+ const editButton = document . createElement ( "button" ) ;
53+ editButton . textContent = browser . i18n . getMessage ( "optionsEditButton" ) || "Edit" ;
54+ editButton . classList . add ( "edit-btn" ) ;
55+
56+ const duplicateButton = document . createElement ( "button" ) ;
57+ duplicateButton . textContent = browser . i18n . getMessage ( "optionsDuplicateButton" ) || "Duplicate" ;
58+ duplicateButton . classList . add ( "duplicate-btn" ) ;
59+
60+ listItem . appendChild ( dragHandle ) ;
61+ listItem . appendChild ( textContent ) ;
62+ listItem . appendChild ( editButton ) ;
63+ listItem . appendChild ( duplicateButton ) ;
64+ listItem . appendChild ( deleteButton ) ;
65+
66+ return listItem ;
67+ } ;
68+
2169// Function to load and display webhooks
2270const loadWebhooks = async ( ) => {
2371 const { webhooks = [ ] , groups = [ ] } = await browser . storage . sync . get ( [ "webhooks" , "groups" ] ) ;
@@ -77,49 +125,7 @@ const loadWebhooks = async () => {
77125
78126 // Add webhooks in this group
79127 groupWebhooks . forEach ( ( webhook ) => {
80- const listItem = document . createElement ( "li" ) ;
81- listItem . dataset . id = webhook . id ;
82- listItem . draggable = true ;
83- listItem . classList . add ( "webhook-item" ) ;
84-
85- const dragHandle = document . createElement ( "span" ) ;
86- dragHandle . classList . add ( "drag-handle" ) ;
87- dragHandle . textContent = "\u2630" ; // common drag icon
88-
89- const textContent = document . createElement ( "div" ) ;
90- textContent . classList . add ( "webhook-info" ) ;
91-
92- const labelSpan = document . createElement ( "span" ) ;
93- labelSpan . classList . add ( "label" ) ;
94- labelSpan . textContent = `${ webhook . emoji ? webhook . emoji + ' ' : '' } ${ webhook . label } ` ;
95-
96- const urlSpan = document . createElement ( "span" ) ;
97- urlSpan . classList . add ( "url" ) ;
98- urlSpan . textContent = webhook . url ;
99-
100- textContent . appendChild ( labelSpan ) ;
101- textContent . appendChild ( urlSpan ) ;
102-
103- const deleteButton = document . createElement ( "button" ) ;
104- // Use localized text for the button
105- deleteButton . textContent = browser . i18n . getMessage ( "optionsDeleteButton" ) ;
106- deleteButton . classList . add ( "delete-btn" ) ;
107-
108- // Add edit button
109- const editButton = document . createElement ( "button" ) ;
110- editButton . textContent = browser . i18n . getMessage ( "optionsEditButton" ) || "Edit" ;
111- editButton . classList . add ( "edit-btn" ) ;
112-
113- const duplicateButton = document . createElement ( "button" ) ;
114- duplicateButton . textContent = browser . i18n . getMessage ( "optionsDuplicateButton" ) || "Duplicate" ;
115- duplicateButton . classList . add ( "duplicate-btn" ) ;
116-
117- listItem . appendChild ( dragHandle ) ;
118- listItem . appendChild ( textContent ) ;
119- listItem . appendChild ( editButton ) ;
120- listItem . appendChild ( duplicateButton ) ;
121- listItem . appendChild ( deleteButton ) ;
122- list . appendChild ( listItem ) ;
128+ list . appendChild ( createWebhookListItem ( webhook ) ) ;
123129 } ) ;
124130 }
125131 } ) ;
@@ -135,49 +141,7 @@ const loadWebhooks = async () => {
135141
136142 // Add ungrouped webhooks
137143 ungroupedWebhooks . forEach ( ( webhook ) => {
138- const listItem = document . createElement ( "li" ) ;
139- listItem . dataset . id = webhook . id ;
140- listItem . draggable = true ;
141- listItem . classList . add ( "webhook-item" ) ;
142-
143- const dragHandle = document . createElement ( "span" ) ;
144- dragHandle . classList . add ( "drag-handle" ) ;
145- dragHandle . textContent = "\u2630" ; // common drag icon
146-
147- const textContent = document . createElement ( "div" ) ;
148- textContent . classList . add ( "webhook-info" ) ;
149-
150- const labelSpan = document . createElement ( "span" ) ;
151- labelSpan . classList . add ( "label" ) ;
152- labelSpan . textContent = `${ webhook . emoji ? webhook . emoji + ' ' : '' } ${ webhook . label } ` ;
153-
154- const urlSpan = document . createElement ( "span" ) ;
155- urlSpan . classList . add ( "url" ) ;
156- urlSpan . textContent = webhook . url ;
157-
158- textContent . appendChild ( labelSpan ) ;
159- textContent . appendChild ( urlSpan ) ;
160-
161- const deleteButton = document . createElement ( "button" ) ;
162- // Use localized text for the button
163- deleteButton . textContent = browser . i18n . getMessage ( "optionsDeleteButton" ) ;
164- deleteButton . classList . add ( "delete-btn" ) ;
165-
166- // Add edit button
167- const editButton = document . createElement ( "button" ) ;
168- editButton . textContent = browser . i18n . getMessage ( "optionsEditButton" ) || "Edit" ;
169- editButton . classList . add ( "edit-btn" ) ;
170-
171- const duplicateButton = document . createElement ( "button" ) ;
172- duplicateButton . textContent = browser . i18n . getMessage ( "optionsDuplicateButton" ) || "Duplicate" ;
173- duplicateButton . classList . add ( "duplicate-btn" ) ;
174-
175- listItem . appendChild ( dragHandle ) ;
176- listItem . appendChild ( textContent ) ;
177- listItem . appendChild ( editButton ) ;
178- listItem . appendChild ( duplicateButton ) ;
179- listItem . appendChild ( deleteButton ) ;
180- list . appendChild ( listItem ) ;
144+ list . appendChild ( createWebhookListItem ( webhook ) ) ;
181145 } ) ;
182146 }
183147 }
0 commit comments