@@ -18,44 +18,43 @@ export async function fetchAllUrls() {
18
18
}
19
19
20
20
data . forEach ( item => {
21
- const shortUrl = `${ window . location . origin } /${ item . hash } ` ;
22
-
21
+ const shortUrl = `link.codegeekery.com /${ item . hash } ` ;
22
+
23
23
const li = document . createElement ( 'li' ) ;
24
24
li . classList . add ( 'url-item' ) ;
25
-
26
- // Nuevo div para organizar internamente (flex)
25
+
26
+ // Div wrapper
27
27
const contentWrapper = document . createElement ( 'div' ) ;
28
- contentWrapper . className = 'url-content-wrapper' ;
29
-
28
+ contentWrapper . className = 'url-content-wrapper' ; // clase flex
29
+
30
+ // El span
30
31
const span = document . createElement ( 'span' ) ;
31
- span . textContent = shortUrl ;
32
+ span . textContent = item . hash ;
32
33
span . className = 'short-url' ;
33
-
34
- // Al hacer clic en el enlace, copiar al portapapeles
34
+
35
35
span . addEventListener ( 'click' , async function ( ) {
36
36
try {
37
37
await navigator . clipboard . writeText ( shortUrl ) ;
38
38
span . textContent = '¡Copiado!' ;
39
39
setTimeout ( ( ) => {
40
- span . textContent = shortUrl ;
40
+ span . textContent = item . hash ;
41
41
} , 2000 ) ;
42
42
} catch ( err ) {
43
43
console . error ( 'Error al copiar:' , err ) ;
44
44
alert ( 'Error al copiar el enlace. Intenta manualmente.' ) ;
45
45
}
46
46
} ) ;
47
-
48
- // Botón de eliminar
47
+
48
+ // Botón eliminar
49
49
const deleteBtn = document . createElement ( 'button' ) ;
50
50
deleteBtn . className = 'delete-btn' ;
51
51
deleteBtn . textContent = 'Eliminar' ;
52
52
deleteBtn . onclick = async ( ) => {
53
53
const authCode = document . getElementById ( 'authCode' ) . value ;
54
-
55
- // Limpia errores anteriores
54
+
56
55
document . querySelectorAll ( '.error-message' ) . forEach ( e => e . remove ( ) ) ;
57
56
document . querySelectorAll ( '.form-group' ) . forEach ( e => e . classList . remove ( 'error' ) ) ;
58
-
57
+
59
58
try {
60
59
await deleteUrl ( item . hash , authCode ) ;
61
60
fetchAllUrls ( ) ;
@@ -72,23 +71,24 @@ export async function fetchAllUrls() {
72
71
} ) ;
73
72
}
74
73
} ;
75
-
76
-
77
- // Insertamos el span y el botón dentro del div
74
+
75
+ // Insertamos el span y el botón dentro del mismo contentWrapper
78
76
contentWrapper . appendChild ( span ) ;
79
77
contentWrapper . appendChild ( deleteBtn ) ;
80
-
81
- // Insertamos el div dentro del li
78
+
79
+ // Insertamos el contentWrapper dentro del li
82
80
li . appendChild ( contentWrapper ) ;
83
-
84
- // Insertamos el li dentro de la lista
81
+
82
+ // Insertamos el li en la lista
85
83
list . appendChild ( li ) ;
86
84
} ) ;
85
+
87
86
} catch ( err ) {
88
87
const list = document . getElementById ( 'urlsList' ) ;
89
88
list . innerHTML = `<li>Error al cargar las URLs: ${ err . message } </li>` ;
90
89
}
91
90
}
92
91
92
+
93
93
// Cargar URLs automáticamente al cargar la página
94
94
window . addEventListener ( 'DOMContentLoaded' , fetchAllUrls ) ;
0 commit comments