codebybrody commited on
Commit
2e36fe1
·
verified ·
1 Parent(s): 117b68d

Upload 7 files

Browse files
scripts/ImageNinja HD/_metadata/generated_indexed_rulesets/_ruleset1 ADDED
Binary file (971 Bytes). View file
 
scripts/ImageNinja HD/background.js ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const downloadMap = new Map();
2
+
3
+ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
4
+ if (request.action === 'registerDownload') {
5
+ downloadMap.set(request.url, request.filename);
6
+ sendResponse({ success: true });
7
+ return true;
8
+ }
9
+ });
10
+
11
+ chrome.downloads.onDeterminingFilename.addListener((item, suggest) => {
12
+ if (downloadMap.has(item.url)) {
13
+ suggest({ filename: downloadMap.get(item.url), conflictAction: 'uniquify' });
14
+ } else {
15
+ suggest();
16
+ }
17
+ return true;
18
+ });
scripts/ImageNinja HD/icon.svg ADDED
scripts/ImageNinja HD/manifest.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "manifest_version": 3,
3
+ "name": "Descargador de Imágenes",
4
+ "version": "1.0",
5
+ "description": "Descarga todas las imágenes de la página web donde te encuentres.",
6
+ "icons": {
7
+ "128": "icon.svg"
8
+ },
9
+ "permissions": [
10
+ "activeTab",
11
+ "scripting",
12
+ "downloads",
13
+ "storage",
14
+ "declarativeNetRequest",
15
+ "declarativeNetRequestWithHostAccess"
16
+ ],
17
+ "background": {
18
+ "service_worker": "background.js"
19
+ },
20
+ "host_permissions": [
21
+ "<all_urls>"
22
+ ],
23
+ "declarative_net_request": {
24
+ "rule_resources": [
25
+ {
26
+ "id": "ruleset_1",
27
+ "enabled": true,
28
+ "path": "rules.json"
29
+ }
30
+ ]
31
+ },
32
+ "action": {
33
+ "default_popup": "popup.html",
34
+ "default_title": "Descargar Imágenes",
35
+ "default_icon": "icon.svg"
36
+ }
37
+ }
scripts/ImageNinja HD/popup.html ADDED
@@ -0,0 +1,527 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="es">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <style>
6
+ :root {
7
+ --bg-color: #0b0c10;
8
+ --surface-color: #12141a;
9
+ --border-color: #272a33;
10
+ --text-color: #c9d1d9;
11
+ --text-muted: #8b949e;
12
+ --accent-color: #e11d48; /* Rojo Carmesí */
13
+ --accent-hover: #be123c; /* Rojo Oscuro */
14
+ --danger-color: #f85149;
15
+ }
16
+
17
+ body {
18
+ min-width: 800px;
19
+ min-height: 560px;
20
+ width: 100vw;
21
+ height: 100vh;
22
+ margin: 0;
23
+ /* removed fixed sizes */
24
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
25
+ background-color: var(--bg-color);
26
+ color: var(--text-color);
27
+ display: flex;
28
+ flex-direction: column;
29
+ overflow: hidden;
30
+ }
31
+
32
+ ::-webkit-scrollbar { width: 8px; height: 8px; }
33
+ ::-webkit-scrollbar-track { background: var(--bg-color); }
34
+ ::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
35
+ ::-webkit-scrollbar-thumb:hover { background: #555; }
36
+
37
+ .header-panel {
38
+ padding: 10px 14px;
39
+ background: linear-gradient(180deg, var(--surface-color) 0%, var(--bg-color) 100%);
40
+ border-bottom: 1px solid var(--border-color);
41
+ display: flex;
42
+ flex-direction: column;
43
+ gap: 10px;
44
+ flex-shrink: 0;
45
+ }
46
+
47
+ .header-row {
48
+ display: grid;
49
+ grid-template-columns: 1fr 1fr;
50
+ gap: 14px;
51
+ }
52
+
53
+ .group-title {
54
+ font-size: 10px;
55
+ text-transform: uppercase;
56
+ letter-spacing: 0.5px;
57
+ color: var(--text-muted);
58
+ font-weight: 600;
59
+ margin-bottom: 4px;
60
+ display: flex;
61
+ align-items: center;
62
+ gap: 4px;
63
+ }
64
+
65
+ .info-icon {
66
+ background: rgba(255,255,255,0.1);
67
+ color: #fff;
68
+ border-radius: 50%;
69
+ width: 12px;
70
+ height: 12px;
71
+ display: inline-flex;
72
+ align-items: center;
73
+ justify-content: center;
74
+ font-size: 9px;
75
+ font-family: monospace;
76
+ font-weight: bold;
77
+ cursor: help;
78
+ }
79
+
80
+ input[type="text"], input[type="number"], select {
81
+ background-color: rgba(255, 255, 255, 0.02);
82
+ color: var(--text-color);
83
+ border: 1px solid var(--border-color);
84
+ border-radius: 6px;
85
+ padding: 6px 8px;
86
+ font-size: 12px;
87
+ outline: none;
88
+ transition: all 0.2s;
89
+ }
90
+
91
+ input[type="text"]:focus, input[type="number"]:focus, select:focus {
92
+ border-color: var(--accent-color);
93
+ background-color: rgba(225, 29, 72, 0.05); /* Rojo transparente */
94
+ }
95
+
96
+ /* Solucionar el menú desplegable blanco en Windows */
97
+ select option {
98
+ background-color: var(--surface-color);
99
+ color: var(--text-color);
100
+ }
101
+
102
+ .flex-row { display: flex; gap: 6px; width: 100%; align-items: center; }
103
+ .flex-row input[type="text"] { flex-grow: 1; }
104
+ .flex-row select { width: 110px; }
105
+
106
+ .sliders-container {
107
+ display: flex;
108
+ gap: 8px;
109
+ }
110
+
111
+ .slider-box {
112
+ flex: 1;
113
+ display: flex;
114
+ align-items: center;
115
+ gap: 6px;
116
+ background: rgba(255,255,255,0.02);
117
+ padding: 4px 8px;
118
+ border-radius: 6px;
119
+ border: 1px solid var(--border-color);
120
+ }
121
+
122
+ .slider-box span { font-size: 11px; color: var(--text-muted); font-weight: 500; }
123
+ .slider-box input[type="range"] { flex-grow: 1; height: 3px; accent-color: var(--accent-color); }
124
+ .slider-box input[type="number"] { width: 40px; padding: 2px; text-align: center; border: none; background: rgba(0,0,0,0.2); }
125
+
126
+ .options-grid {
127
+ display: grid;
128
+ grid-template-columns: 1fr 1fr;
129
+ gap: 8px;
130
+ }
131
+
132
+ .custom-checkbox {
133
+ display: flex;
134
+ align-items: flex-start;
135
+ gap: 8px;
136
+ padding: 6px 8px;
137
+ background: rgba(255,255,255,0.02);
138
+ border: 1px solid var(--border-color);
139
+ border-radius: 6px;
140
+ cursor: pointer;
141
+ transition: all 0.2s;
142
+ }
143
+
144
+ .custom-checkbox:hover {
145
+ background: rgba(255,255,255,0.05);
146
+ border-color: #444c56;
147
+ }
148
+
149
+ .custom-checkbox input[type="checkbox"] {
150
+ margin-top: 2px;
151
+ accent-color: var(--accent-color);
152
+ width: 13px;
153
+ height: 13px;
154
+ cursor: pointer;
155
+ }
156
+
157
+ .checkbox-text {
158
+ display: flex;
159
+ flex-direction: column;
160
+ gap: 1px;
161
+ }
162
+
163
+ .checkbox-text b { font-size: 11.5px; font-weight: 500; color: #fff; }
164
+ .checkbox-text small { font-size: 9.5px; color: var(--text-muted); line-height: 1.2; }
165
+
166
+ .select-bar {
167
+ margin-top: 0px;
168
+ padding-top: 8px;
169
+ border-top: 1px dashed var(--border-color);
170
+ display: flex;
171
+ align-items: center;
172
+ justify-content: space-between;
173
+ }
174
+
175
+ .select-all-label {
176
+ display: flex;
177
+ align-items: center;
178
+ gap: 8px;
179
+ font-size: 13px;
180
+ font-weight: 500;
181
+ cursor: pointer;
182
+ }
183
+
184
+ .select-all-label input {
185
+ accent-color: var(--accent-color);
186
+ width: 16px;
187
+ height: 16px;
188
+ cursor: pointer;
189
+ }
190
+
191
+ /* GRID DE IMÁGENES */
192
+ .grid-container {
193
+ flex-grow: 1;
194
+ overflow-y: auto;
195
+ padding: 14px;
196
+ display: grid;
197
+ grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
198
+ grid-auto-rows: max-content;
199
+ align-content: start;
200
+ gap: 16px;
201
+ background-color: var(--bg-color);
202
+ }
203
+
204
+ .image-card {
205
+ position: relative;
206
+ background-color: var(--surface-color);
207
+ border: 1px solid var(--border-color);
208
+ border-radius: 8px;
209
+ overflow: hidden;
210
+ display: flex;
211
+ flex-direction: column;
212
+ transition: all 0.2s;
213
+ }
214
+
215
+ .image-card.selected {
216
+ border-color: var(--accent-color);
217
+ box-shadow: 0 0 0 2px rgba(225, 29, 72, 0.3); /* Resplandor rojo */
218
+ }
219
+
220
+ .image-wrapper {
221
+ position: relative;
222
+ width: 100%;
223
+ aspect-ratio: 1 / 1.4;
224
+ background-color: rgba(0,0,0,0.5);
225
+ display: flex;
226
+ align-items: center;
227
+ justify-content: center;
228
+ }
229
+
230
+ .image-wrapper img {
231
+ max-width: 100%;
232
+ max-height: 100%;
233
+ object-fit: contain;
234
+ }
235
+
236
+ .card-checkbox {
237
+ position: absolute;
238
+ top: 8px;
239
+ left: 8px;
240
+ width: 20px;
241
+ height: 20px;
242
+ accent-color: var(--accent-color);
243
+ cursor: pointer;
244
+ z-index: 10;
245
+ background: rgba(0,0,0,0.6);
246
+ border-radius: 4px;
247
+ box-shadow: 0 2px 4px rgba(0,0,0,0.3);
248
+ }
249
+
250
+ .card-actions {
251
+ position: absolute;
252
+ top: 8px;
253
+ right: 8px;
254
+ display: flex;
255
+ gap: 6px;
256
+ background: rgba(0, 0, 0, 0.7);
257
+ padding: 4px;
258
+ border-radius: 6px;
259
+ z-index: 10;
260
+ backdrop-filter: blur(4px);
261
+ }
262
+
263
+ .icon-btn {
264
+ background: none;
265
+ border: none;
266
+ color: #fff;
267
+ cursor: pointer;
268
+ padding: 5px;
269
+ border-radius: 4px;
270
+ display: flex;
271
+ align-items: center;
272
+ justify-content: center;
273
+ transition: background 0.2s;
274
+ }
275
+
276
+ .icon-btn:hover { background-color: rgba(255,255,255,0.2); }
277
+ .icon-btn svg {
278
+ width: 16px;
279
+ height: 16px;
280
+ fill: none;
281
+ stroke: currentColor;
282
+ stroke-width: 2;
283
+ stroke-linecap: round;
284
+ stroke-linejoin: round;
285
+ }
286
+
287
+ .card-info {
288
+ padding: 8px;
289
+ font-size: 11px;
290
+ color: var(--text-color);
291
+ display: flex;
292
+ flex-direction: column;
293
+ gap: 6px;
294
+ background: var(--surface-color);
295
+ }
296
+
297
+ .url-bar {
298
+ background: rgba(0,0,0,0.7);
299
+ padding: 5px;
300
+ position: absolute;
301
+ bottom: 0;
302
+ left: 0;
303
+ right: 0;
304
+ font-size: 10px;
305
+ color: #ddd;
306
+ white-space: nowrap;
307
+ overflow: hidden;
308
+ text-overflow: ellipsis;
309
+ backdrop-filter: blur(2px);
310
+ }
311
+
312
+ .footer {
313
+ padding: 14px 16px;
314
+ background-color: var(--surface-color);
315
+ border-top: 1px solid var(--border-color);
316
+ display: flex;
317
+ justify-content: space-between;
318
+ align-items: center;
319
+ gap: 12px;
320
+ flex-shrink: 0;
321
+ }
322
+
323
+ .footer-inputs {
324
+ display: flex;
325
+ gap: 5px;
326
+ flex-grow: 1;
327
+ }
328
+
329
+ .btn-download {
330
+ background-color: var(--accent-color);
331
+ color: #fff; /* Que se lea bien sobre el rojo */
332
+ border: none;
333
+ border-radius: 6px;
334
+ padding: 10px 16px;
335
+ font-size: 14px;
336
+ font-weight: 600;
337
+ cursor: pointer;
338
+ display: flex;
339
+ align-items: center;
340
+ gap: 8px;
341
+ white-space: nowrap;
342
+ transition: all 0.2s;
343
+ box-shadow: 0 4px 14px 0 rgba(225, 29, 72, 0.2); /* Sombra roja */
344
+ }
345
+
346
+ .btn-download:hover {
347
+ background-color: var(--accent-hover);
348
+ transform: translateY(-1px);
349
+ }
350
+ .btn-download:disabled {
351
+ background-color: #30363d;
352
+ color: #8b949e;
353
+ cursor: not-allowed;
354
+ box-shadow: none;
355
+ transform: none;
356
+ }
357
+
358
+ .btn-clean {
359
+ background-color: rgba(255, 255, 255, 0.05);
360
+ border: 1px solid var(--border-color);
361
+ color: var(--text-muted);
362
+ border-radius: 4px;
363
+ padding: 4px 8px;
364
+ font-size: 11px;
365
+ cursor: pointer;
366
+ display: flex;
367
+ align-items: center;
368
+ gap: 4px;
369
+ transition: all 0.2s;
370
+ }
371
+ .btn-clean:hover {
372
+ background-color: rgba(225, 29, 72, 0.1);
373
+ border-color: var(--accent-color);
374
+ color: #fff;
375
+ }
376
+
377
+ .loader {
378
+ display: flex;
379
+ flex-direction: column;
380
+ align-items: center;
381
+ justify-content: center;
382
+ height: 100%;
383
+ color: var(--text-muted);
384
+ grid-column: span 4;
385
+ }
386
+ </style>
387
+ </head>
388
+ <body>
389
+
390
+ <div class="header-panel">
391
+
392
+ <div class="header-row">
393
+ <!-- Filtros Principales -->
394
+ <div>
395
+ <div class="group-title">
396
+ Filtros de Contenido
397
+ <span class="info-icon" title="Usa un texto para buscar en las URLs o filtra por formato (jpg, png, etc.)">?</span>
398
+ </div>
399
+ <div class="flex-row">
400
+ <input type="text" id="filterUrl" placeholder="Buscar palabras clave en la URL..." title="Escribe palabras clave para filtrar imágenes" />
401
+ <select id="filterExt" title="Filtrar por extensión">
402
+ <option value="all">Formato: Todos</option>
403
+ <option value="jpg">Solo JPG</option>
404
+ <option value="jpeg">Solo JPEG</option>
405
+ <option value="png">Solo PNG</option>
406
+ <option value="webp">Solo WEBP</option>
407
+ <option value="gif">Solo GIF</option>
408
+ <option value="svg">Solo SVG</option>
409
+ <option value="avif">Solo AVIF</option>
410
+ <option value="bmp">Solo BMP</option>
411
+ <option value="tiff">Solo TIFF</option>
412
+ <option value="tif">Solo TIF</option>
413
+ <option value="ico">Solo ICO</option>
414
+ <option value="heic">Solo HEIC</option>
415
+ <option value="heif">Solo HEIF</option>
416
+ <option value="jxl">Solo JXL</option>
417
+ </select>
418
+ </div>
419
+ </div>
420
+
421
+ <!-- Tamaño Mínimo -->
422
+ <div>
423
+ <div class="group-title">
424
+ Tamaño Mínimo Requerido
425
+ <span class="info-icon" title="Oculta logos pequeños, iconos y botones ajustando el tamaño mínimo.">?</span>
426
+ </div>
427
+ <div class="sliders-container">
428
+ <div class="slider-box" title="Filtra imágenes más pequeñas que este ancho">
429
+ <span>Ancho</span>
430
+ <input type="range" id="minWidth" min="0" max="2500" value="0" step="10">
431
+ <input type="number" id="minWidthVal" value="0">
432
+ </div>
433
+ <div class="slider-box" title="Filtra imágenes más pequeñas que este alto">
434
+ <span>Alto</span>
435
+ <input type="range" id="minHeight" min="0" max="2500" value="0" step="10">
436
+ <input type="number" id="minHeightVal" value="0">
437
+ </div>
438
+ </div>
439
+ </div>
440
+ </div>
441
+
442
+ <!-- Opciones Avanzadas -->
443
+ <div>
444
+ <div class="options-grid">
445
+ <label class="custom-checkbox" title="Especial para galerías de Cómics: Abre las miniaturas en la sombra para atraparlas en Calidad Original.">
446
+ <input type="checkbox" id="forceHD">
447
+ <div class="checkbox-text">
448
+ <b>Forzar HD (Lhentai/Galerías)</b>
449
+ <small>Extracción profunda original</small>
450
+ </div>
451
+ </label>
452
+
453
+ <label class="custom-checkbox" title="Crea subcarpetas automáticas (4K, 1080p, etc.) según la resolución de cada imagen.">
454
+ <input type="checkbox" id="separateQuality">
455
+ <div class="checkbox-text">
456
+ <b>Separar por Calidad</b>
457
+ <small>Carpetas (4K, 1080p...)</small>
458
+ </div>
459
+ </label>
460
+
461
+ <label class="custom-checkbox" title="Renombra los archivos como pag_01, pag_02 de acuerdo a su orden en la página, ignorando el nombre original.">
462
+ <input type="checkbox" id="renameSequential" checked>
463
+ <div class="checkbox-text">
464
+ <b>Renombrar a "pag_X"</b>
465
+ <small>Ordena pag_01, pag_02...</small>
466
+ </div>
467
+ </label>
468
+
469
+ <label class="custom-checkbox" title="Modo Inteligente: Detecta y selecciona automáticamente solo las páginas del cómic, ignorando banners, menús y publicidad.">
470
+ <input type="checkbox" id="smartComic" checked>
471
+ <div class="checkbox-text">
472
+ <b>Modo Solo Cómic 🎯</b>
473
+ <small>Filtra logos y banners</small>
474
+ </div>
475
+ </label>
476
+ </div>
477
+ </div>
478
+
479
+ <!-- Barra Inferior Cabecera -->
480
+ <div class="select-bar">
481
+ <label class="select-all-label">
482
+ <input type="checkbox" id="selectAll">
483
+ Seleccionar Todo (<span id="selectedCount">0</span> de <span id="totalCount">0</span>)
484
+ </label>
485
+ <div style="display: flex; gap: 8px; align-items: center;">
486
+ <label class="btn-clean" style="cursor: pointer;" title="Ocultar automáticamente imágenes que no cargan">
487
+ <input type="checkbox" id="cleanBrokenToggle" style="accent-color: var(--accent-color); margin: 0;">
488
+ Ocultar Rotas
489
+ </label>
490
+ <span style="font-size: 11px; color: var(--text-muted);">
491
+ Imágenes listas para guardar
492
+ </span>
493
+ </div>
494
+ </div>
495
+
496
+ </div>
497
+
498
+ <div class="grid-container" id="imageGrid">
499
+ <div class="loader">
500
+ <h3 style="margin: 0;">Analizando página...</h3>
501
+ <p style="font-size: 13px;">Buscando imágenes disponibles</p>
502
+ </div>
503
+ </div>
504
+
505
+ <div class="footer">
506
+ <div class="footer-inputs">
507
+ <!-- Botón Pantalla Completa -->
508
+ <button id="fullscreenBtn" class="icon-btn" title="Pantalla Completa" style="background: rgba(255,255,255,0.1); margin-right: 5px; padding: 0 10px; border-radius: 6px;">
509
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="fill: none; width: 18px; height: 18px; display: block;"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"></path></svg>
510
+ </button>
511
+
512
+ <!-- Input 100% de la subcarpeta -->
513
+ <input type="text" id="subfolder" placeholder="Ej: Dragon_Ball_Z_Caps" title="Se creará esta carpeta dentro de 'Descargas'. Déjalo vacío para 'comics_completos'" style="width: 100%;">
514
+ </div>
515
+ <button id="downloadBtn" class="btn-download" disabled>
516
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
517
+ <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
518
+ <polyline points="7 10 12 15 17 10"></polyline>
519
+ <line x1="12" y1="15" x2="12" y2="3"></line>
520
+ </svg>
521
+ Descargar (<span id="btnCounter">0</span>)
522
+ </button>
523
+ </div>
524
+
525
+ <script src="popup.js"></script>
526
+ </body>
527
+ </html>
scripts/ImageNinja HD/popup.js ADDED
@@ -0,0 +1,711 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // --- ESTADO GLOBAL ---
2
+ const state = {
3
+ allImages: [],
4
+ filteredImages: [],
5
+ selectedImages: new Set(),
6
+ lastSelectedIdx: -1,
7
+ isHDSearching: false,
8
+ downloadMap: new Map(),
9
+ isDragging: false,
10
+ dragMode: true,
11
+ dragStartIdx: -1,
12
+ dragSavedSelection: new Set()
13
+ };
14
+
15
+ // --- ELEMENTOS DEL DOM ---
16
+ const DOM = {
17
+ grid: document.getElementById('imageGrid'),
18
+ filterUrl: document.getElementById('filterUrl'),
19
+ filterExt: document.getElementById('filterExt'),
20
+ minWidth: document.getElementById('minWidth'),
21
+ minWidthVal: document.getElementById('minWidthVal'),
22
+ minHeight: document.getElementById('minHeight'),
23
+ minHeightVal: document.getElementById('minHeightVal'),
24
+ forceHD: document.getElementById('forceHD'),
25
+ separateQuality: document.getElementById('separateQuality'),
26
+ renameSequential: document.getElementById('renameSequential'),
27
+ smartComic: document.getElementById('smartComic'),
28
+ selectAll: document.getElementById('selectAll'),
29
+ selectedCount: document.getElementById('selectedCount'),
30
+ totalCount: document.getElementById('totalCount'),
31
+ downloadBtn: document.getElementById('downloadBtn'),
32
+ btnCounter: document.getElementById('btnCounter'),
33
+ fullscreenBtn: document.getElementById('fullscreenBtn'),
34
+ subfolderInput: document.getElementById('subfolder'),
35
+ cleanBrokenToggle: document.getElementById('cleanBrokenToggle')
36
+ };
37
+
38
+ // --- INICIALIZACIÓN ---
39
+ document.addEventListener('DOMContentLoaded', async () => {
40
+ await loadSettings();
41
+ initListeners();
42
+
43
+ const params = new URLSearchParams(window.location.search);
44
+ const targetTabId = params.get('tabId');
45
+ let tab;
46
+
47
+ if (targetTabId) {
48
+ try {
49
+ tab = await chrome.tabs.get(parseInt(targetTabId));
50
+ DOM.fullscreenBtn.title = 'Minimizar a Ventana Flotante';
51
+ DOM.fullscreenBtn.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="fill: none; width: 18px; height: 18px; display: block;"><path d="M8 3v3h-3m18 2h-3V5m-18 11h3v3m10 2v-3h3m-5-5l7-7M3 21l7-7"></path></svg>';
52
+ DOM.fullscreenBtn.onclick = () => window.close();
53
+ } catch(e) {
54
+ console.error("No se pudo obtener el tab original", e);
55
+ }
56
+ } else {
57
+ const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
58
+ tab = tabs[0];
59
+ }
60
+
61
+ if (!tab) return;
62
+ window.currentContextTabId = tab.id;
63
+
64
+ // Dynamic DNR: Some sites (like Poringa) strictly require the exact Page URL as the Referer.
65
+ try {
66
+ if (chrome.declarativeNetRequest && tab.url) {
67
+ await chrome.declarativeNetRequest.updateDynamicRules({
68
+ removeRuleIds: [999],
69
+ addRules: [{
70
+ id: 999,
71
+ priority: 2,
72
+ action: {
73
+ type: "modifyHeaders",
74
+ requestHeaders: [
75
+ { header: "Referer", operation: "set", value: tab.url },
76
+ { header: "Origin", operation: "set", value: new URL(tab.url).origin }
77
+ ],
78
+ responseHeaders: [
79
+ { header: "Access-Control-Allow-Origin", operation: "set", value: "*" },
80
+ { header: "Cross-Origin-Resource-Policy", operation: "remove" }
81
+ ]
82
+ },
83
+ condition: {
84
+ urlFilter: new URL(tab.url).hostname.replace('www.', ''),
85
+ resourceTypes: ["image", "xmlhttprequest", "other", "main_frame", "sub_frame"]
86
+ }
87
+ }]
88
+ });
89
+ }
90
+ } catch (e) {
91
+ console.error("Dynamic DNR failed", e);
92
+ }
93
+
94
+ chrome.scripting.executeScript({
95
+ target: { tabId: tab.id },
96
+ function: getImagesFromPageDOM,
97
+ }, (results) => {
98
+ if (chrome.runtime.lastError || !results?.[0]?.result) {
99
+ DOM.grid.innerHTML = '<div class="loader"><p style="color: var(--danger-color)">Error al obtener imágenes.</p></div>';
100
+ return;
101
+ }
102
+
103
+ // Procesar imágenes únicas
104
+ const uniqueMap = new Map();
105
+ results[0].result.forEach(img => {
106
+ if (!uniqueMap.has(img.src) && img.src.startsWith('http')) {
107
+ uniqueMap.set(img.src, img);
108
+ }
109
+ });
110
+
111
+ state.allImages = Array.from(uniqueMap.values());
112
+ if (DOM.selectAll.checked) {
113
+ state.allImages.forEach(img => state.selectedImages.add(img.src));
114
+ }
115
+ applyFilters();
116
+
117
+ // AUTO-START HD si estaba activo
118
+ if (DOM.forceHD.checked) {
119
+ updateHDUrls();
120
+ }
121
+ });
122
+ });
123
+
124
+ function initListeners() {
125
+ // Sincronización de Sliders
126
+ const handleSizeInput = (slider, valBox) => {
127
+ valBox.value = slider.value;
128
+ applyFilters();
129
+ if (DOM.forceHD.checked) updateHDUrls();
130
+ saveSettings();
131
+ };
132
+
133
+ DOM.minWidth.addEventListener('input', () => handleSizeInput(DOM.minWidth, DOM.minWidthVal));
134
+ DOM.minHeight.addEventListener('input', () => handleSizeInput(DOM.minHeight, DOM.minHeightVal));
135
+ DOM.minWidthVal.addEventListener('input', () => { DOM.minWidth.value = DOM.minWidthVal.value; applyFilters(); saveSettings(); });
136
+ DOM.minHeightVal.addEventListener('input', () => { DOM.minHeight.value = DOM.minHeightVal.value; applyFilters(); saveSettings(); });
137
+
138
+ // Guardado persistente en cambios finales
139
+ DOM.minWidth.addEventListener('change', saveSettings);
140
+ DOM.minHeight.addEventListener('change', saveSettings);
141
+
142
+ // Filtros
143
+ DOM.filterUrl.addEventListener('input', () => { applyFilters(); saveSettings(); });
144
+ DOM.filterExt.addEventListener('change', () => { applyFilters(); saveSettings(); });
145
+ DOM.forceHD.addEventListener('change', () => { updateHDUrls(); saveSettings(); });
146
+ DOM.separateQuality.addEventListener('change', saveSettings);
147
+ DOM.renameSequential.addEventListener('change', saveSettings);
148
+ DOM.smartComic.addEventListener('change', () => { applyFilters(); saveSettings(); });
149
+ DOM.subfolderInput.addEventListener('input', saveSettings);
150
+
151
+ // Acciones globales
152
+ DOM.selectAll.addEventListener('change', (e) => {
153
+ if (e.target.checked) {
154
+ state.filteredImages.forEach(img => state.selectedImages.add(img.src));
155
+ } else {
156
+ state.selectedImages.clear();
157
+ }
158
+ updateSelectionVisuals();
159
+ saveSettings();
160
+ });
161
+
162
+ DOM.downloadBtn.addEventListener('click', async () => {
163
+ const toDownload = state.filteredImages.filter(img => state.selectedImages.has(img.src));
164
+ if (toDownload.length === 0) return;
165
+
166
+ // Determinar subcarpeta única basada en el historial para no mezclar galerías
167
+ const baseSf = DOM.subfolderInput.value.trim().replace(/[\\:*?"<>|]/g, "") || 'comics_completos';
168
+ const uniqueSf = await getUniqueSubfolder(baseSf);
169
+
170
+ toDownload.forEach((img, idx) => downloadImage(img, idx, toDownload.length, uniqueSf));
171
+ });
172
+
173
+ if (DOM.fullscreenBtn) {
174
+ DOM.fullscreenBtn.addEventListener('click', () => {
175
+ const params = new URLSearchParams(window.location.search);
176
+ if (!params.has('tabId') && window.currentContextTabId) {
177
+ chrome.tabs.create({ url: chrome.runtime.getURL('popup.html?tabId=' + window.currentContextTabId) });
178
+ }
179
+ });
180
+ }
181
+
182
+ window.addEventListener('mouseup', () => state.isDragging = false);
183
+ window.addEventListener('mouseleave', () => state.isDragging = false);
184
+
185
+ if (DOM.cleanBrokenToggle) {
186
+ DOM.cleanBrokenToggle.addEventListener('change', () => {
187
+ applyFilters();
188
+ saveSettings();
189
+ });
190
+ }
191
+ }
192
+
193
+ // --- LÓGICA DE NEGOCIO ---
194
+
195
+ function saveSettings() {
196
+ if (typeof chrome === 'undefined' || !chrome.storage) return;
197
+ const settings = {
198
+ filterUrl: DOM.filterUrl.value,
199
+ filterExt: DOM.filterExt.value,
200
+ minWidth: DOM.minWidth.value,
201
+ minHeight: DOM.minHeight.value,
202
+ forceHD: DOM.forceHD.checked,
203
+ separateQuality: DOM.separateQuality.checked,
204
+ renameSequential: DOM.renameSequential.checked,
205
+ smartComic: DOM.smartComic.checked,
206
+ subfolder: DOM.subfolderInput.value,
207
+ selectAll: DOM.selectAll.checked,
208
+ cleanBroken: DOM.cleanBrokenToggle ? DOM.cleanBrokenToggle.checked : false
209
+ };
210
+ chrome.storage.local.set({ extensionSettings: settings });
211
+ }
212
+
213
+ async function loadSettings() {
214
+ return new Promise((resolve) => {
215
+ if (typeof chrome === 'undefined' || !chrome.storage) return resolve();
216
+ chrome.storage.local.get(['extensionSettings'], (res) => {
217
+ const s = res.extensionSettings;
218
+ if (s) {
219
+ DOM.filterUrl.value = s.filterUrl || '';
220
+ DOM.filterExt.value = s.filterExt || 'all';
221
+ DOM.minWidth.value = s.minWidth ?? 0;
222
+ DOM.minWidthVal.value = s.minWidth ?? 0;
223
+ DOM.minHeight.value = s.minHeight ?? 0;
224
+ DOM.minHeightVal.value = s.minHeight ?? 0;
225
+ DOM.forceHD.checked = !!s.forceHD;
226
+ DOM.separateQuality.checked = !!s.separateQuality;
227
+ DOM.renameSequential.checked = s.renameSequential !== false; // Activo por defecto
228
+ DOM.smartComic.checked = s.smartComic !== false;
229
+ DOM.subfolderInput.value = s.subfolder || '';
230
+ DOM.selectAll.checked = !!s.selectAll;
231
+ if (DOM.cleanBrokenToggle) {
232
+ DOM.cleanBrokenToggle.checked = !!s.cleanBroken;
233
+ }
234
+ }
235
+ resolve();
236
+ });
237
+ });
238
+ }
239
+
240
+ function applyFilters() {
241
+ const w = parseInt(DOM.minWidth.value) || 0;
242
+ const h = parseInt(DOM.minHeight.value) || 0;
243
+ const text = DOM.filterUrl.value.toLowerCase();
244
+ const ext = DOM.filterExt.value;
245
+
246
+ state.filteredImages = state.allImages.filter(img => {
247
+ if (DOM.cleanBrokenToggle && DOM.cleanBrokenToggle.checked && img.isBroken) return false;
248
+
249
+ // Exempt direct links, kemono thumbs, and actively searching HD images from size filtering initially
250
+ const isExempt = img.hdSearching || (!img.hdFound && (img.isDirectLink || img.isKemonoThumb));
251
+ if (!isExempt && (img.width < w || img.height < h)) return false;
252
+ if (ext !== 'all' && getExtension(img.src) !== ext) return false;
253
+ if (text && !img.src.toLowerCase().includes(text)) return false;
254
+ return true;
255
+ });
256
+
257
+ if (DOM.smartComic && DOM.smartComic.checked && state.filteredImages.length > 0) {
258
+ const dirInfo = {};
259
+ state.filteredImages.forEach(img => {
260
+ if (img.hdSearching || (!img.hdFound && (img.isDirectLink || img.isKemonoThumb))) return;
261
+ try {
262
+ const url = img.originalSrc || img.src;
263
+ if (!url.startsWith('http')) return;
264
+ const urlObj = new URL(url);
265
+ const pathStr = urlObj.pathname;
266
+ const dirPath = urlObj.origin + pathStr.substring(0, pathStr.lastIndexOf('/'));
267
+
268
+ if (!dirInfo[dirPath]) dirInfo[dirPath] = 0;
269
+ if (img.width >= 300 && img.height >= 300) {
270
+ dirInfo[dirPath] += 2;
271
+ } else {
272
+ dirInfo[dirPath] += 1;
273
+ }
274
+ } catch(e) {}
275
+ });
276
+
277
+ let mainDir = '';
278
+ let maxScore = 0;
279
+ for (const [dir, score] of Object.entries(dirInfo)) {
280
+ if (score > maxScore) {
281
+ maxScore = score;
282
+ mainDir = dir;
283
+ }
284
+ }
285
+
286
+ state.filteredImages = state.filteredImages.filter(img => {
287
+ if (img.hdSearching || (!img.hdFound && (img.isDirectLink || img.isKemonoThumb))) return true;
288
+
289
+ try {
290
+ const url = img.originalSrc || img.src;
291
+ const urlObj = new URL(url);
292
+ const pathStr = urlObj.pathname;
293
+ const dirPath = urlObj.origin + pathStr.substring(0, pathStr.lastIndexOf('/'));
294
+
295
+ if (maxScore >= 4) {
296
+ return dirPath === mainDir && img.width >= 300 && img.height >= 300;
297
+ } else {
298
+ return img.width >= 300 && img.height >= 300;
299
+ }
300
+ } catch {
301
+ return true;
302
+ }
303
+ });
304
+ }
305
+
306
+ // Limpiar selección de lo que ya no es visible
307
+ const visibleSrcs = new Set(state.filteredImages.map(i => i.src));
308
+ state.selectedImages.forEach(src => {
309
+ if (!visibleSrcs.has(src)) state.selectedImages.delete(src);
310
+ });
311
+
312
+ render();
313
+ }
314
+
315
+ async function updateHDUrls() {
316
+ if (!DOM.forceHD.checked) {
317
+ state.allImages.forEach(img => {
318
+ if (img.originalSrc) {
319
+ img.src = img.originalSrc;
320
+ img.width = img.origWidth;
321
+ img.height = img.origHeight;
322
+ }
323
+ img.hdSearching = false;
324
+ img.hdFound = false;
325
+ });
326
+ applyFilters();
327
+ return;
328
+ }
329
+
330
+ // Backup original y flag searching
331
+ state.allImages.forEach(img => {
332
+ if (!img.originalSrc) {
333
+ img.originalSrc = img.src;
334
+ img.origWidth = img.width;
335
+ img.origHeight = img.height;
336
+ }
337
+ });
338
+
339
+ state.filteredImages.forEach(img => {
340
+ if (img.inLink && img.linkHref && !img.hdFound && !img.hdSearching) {
341
+ img.hdSearching = true;
342
+ }
343
+ // Quick Fix Kemono
344
+ if (!img.hdFound && img.src.includes('kemono.') && img.src.includes('/thumbnail/data/')) {
345
+ img.src = img.src.replace('/thumbnail/data/', '/data/');
346
+ img.linkHref = img.src; // So the fetch block below sets the proper dimensions via fallback
347
+ img.hdSearching = true;
348
+ }
349
+ });
350
+
351
+ render();
352
+
353
+ let queue = state.filteredImages.map((img, idx) => ({img, idx})).filter(x => x.img.hdSearching);
354
+ const limit = 5;
355
+ let active = 0;
356
+
357
+ await new Promise(resolve => {
358
+ if (queue.length === 0) return resolve();
359
+
360
+ const processNext = async () => {
361
+ if (queue.length === 0 && active === 0) return resolve();
362
+
363
+ while (active < limit && queue.length > 0) {
364
+ active++;
365
+ const {img, idx} = queue.shift();
366
+
367
+ try {
368
+ const resp = await fetch(img.linkHref);
369
+ const html = await resp.text();
370
+ const doc = new DOMParser().parseFromString(html, 'text/html');
371
+
372
+ let foundSrc = doc.querySelector('#image-container img, .fit-horizontal img, #gimg, .gallery-image img, figure img, .post__content img')?.getAttribute('src');
373
+
374
+ if (!foundSrc && img.linkHref.match(/\.(jpg|jpeg|png|webp|gif|svg|avif|bmp|tiff|tif|ico|heic|heif|jxl)$/i)) foundSrc = img.linkHref;
375
+
376
+ if (!foundSrc) {
377
+ const folder = (new URL(img.originalSrc)).pathname.split('/').slice(0,-1).join('/');
378
+ foundSrc = Array.from(doc.querySelectorAll('img'))
379
+ .map(i => i.getAttribute('src'))
380
+ .find(s => s?.includes(folder) && !s.match(/t\.(jpg|jpeg|png|webp|gif|svg|avif|bmp|tiff|tif|ico|heic|heif|jxl)$/i) && !s.includes('logo'));
381
+ }
382
+
383
+ if (foundSrc) {
384
+ const fullUrl = foundSrc.startsWith('http') ? foundSrc : new URL(foundSrc, img.linkHref).href;
385
+ img.src = fullUrl;
386
+ await new Promise(r => {
387
+ const t = new Image();
388
+ t.onload = () => { img.width = t.naturalWidth; img.height = t.naturalHeight; img.hdFound = true; r(); };
389
+ t.onerror = r;
390
+ t.src = fullUrl;
391
+ });
392
+ }
393
+ } catch {}
394
+
395
+ img.hdSearching = false;
396
+ updateCardForHD(idx);
397
+ active--;
398
+ processNext();
399
+ }
400
+ };
401
+ processNext();
402
+ });
403
+ }
404
+
405
+ // --- RENDERIZADO ---
406
+
407
+ function updateCardForHD(idx) {
408
+ const cards = DOM.grid.querySelectorAll('.image-card');
409
+ const card = cards[idx];
410
+ if (!card) return;
411
+ const img = state.filteredImages[idx];
412
+
413
+ let info = `${img.width} × ${img.height}`;
414
+ let style = '';
415
+ if (DOM.forceHD.checked) {
416
+ if (img.hdSearching) { info = '🔎 Buscando...'; style = 'color: #f39c12; font-size: 11px;'; }
417
+ else if (img.hdFound) { info = `🌟 HD: ${img.width}×${img.height}`; style = 'color: #2ecc71; font-weight: bold;'; }
418
+ else { info = '❌ Normal'; style = 'color: #e74c3c; font-size: 11px;'; }
419
+ }
420
+
421
+ const span = card.querySelector('.card-info span');
422
+ if (span) {
423
+ span.innerHTML = info;
424
+ span.setAttribute('style', style);
425
+ }
426
+
427
+ if (img.hdFound) {
428
+ const imgEl = card.querySelector('.image-wrapper img');
429
+ if (imgEl && imgEl.src !== img.src) imgEl.src = img.src;
430
+ const urlBar = card.querySelector('.url-bar');
431
+ if (urlBar && urlBar.textContent !== img.src) urlBar.textContent = img.src;
432
+ }
433
+ }
434
+
435
+ function render() {
436
+ const scroll = DOM.grid.scrollTop;
437
+ DOM.grid.innerHTML = '';
438
+
439
+ if (state.filteredImages.length === 0) {
440
+ DOM.grid.innerHTML = '<div class="loader"><p>No se encontraron imágenes.</p></div>';
441
+ } else {
442
+ state.filteredImages.forEach((img, idx) => {
443
+ const isSelected = state.selectedImages.has(img.src);
444
+ const card = document.createElement('div');
445
+ card.className = `image-card ${isSelected ? 'selected' : ''}`;
446
+
447
+ let info = `${img.width} × ${img.height}`;
448
+ let style = '';
449
+ if (DOM.forceHD.checked) {
450
+ if (img.hdSearching) { info = '🔎 Buscando...'; style = 'color: #f39c12; font-size: 11px;'; }
451
+ else if (img.hdFound) { info = `🌟 HD: ${img.width}×${img.height}`; style = 'color: #2ecc71; font-weight: bold;'; }
452
+ else { info = '❌ Normal'; style = 'color: #e74c3c; font-size: 11px;'; }
453
+ }
454
+
455
+ card.innerHTML = `
456
+ <input type="checkbox" class="card-checkbox" ${isSelected ? 'checked' : ''}>
457
+ <div class="card-actions">
458
+ <button class="icon-btn btn-ext"><svg viewBox="0 0 24 24"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg></button>
459
+ <button class="icon-btn btn-dl"><svg viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg></button>
460
+ </div>
461
+ <div class="image-wrapper"><img src="${img.src}" loading="lazy" /><div class="url-bar">${img.src}</div></div>
462
+ <div class="card-info"><span style="${style}">${info}</span></div>
463
+ `;
464
+
465
+ card.querySelector('.btn-ext').onclick = (e) => { e.stopPropagation(); chrome.tabs.create({ url: img.src }); };
466
+ card.querySelector('.btn-dl').onclick = async (e) => {
467
+ e.stopPropagation();
468
+ const baseSf = DOM.subfolderInput.value.trim().replace(/[\\:*?"<>|]/g, "") || 'comics_completos';
469
+ const uniqueSf = await getUniqueSubfolder(baseSf);
470
+ downloadImage(img, idx, state.filteredImages.length, uniqueSf);
471
+ };
472
+
473
+ // Evitar que el navegador intente arrastrar la imagen nativamente
474
+ const imgEl = card.querySelector('img');
475
+ imgEl.addEventListener('dragstart', (e) => e.preventDefault());
476
+ imgEl.addEventListener('error', () => {
477
+ img.isBroken = true;
478
+ if (DOM.cleanBrokenToggle && DOM.cleanBrokenToggle.checked) {
479
+ card.style.display = 'none';
480
+ state.selectedImages.delete(img.src);
481
+ updateSelectionVisuals();
482
+ }
483
+ });
484
+
485
+ card.addEventListener('mousedown', (e) => {
486
+ if (e.target.closest('.card-actions')) return;
487
+ e.preventDefault();
488
+ if (e.shiftKey) {
489
+ toggleSelection(idx, true);
490
+ } else {
491
+ state.isDragging = true;
492
+ state.dragStartIdx = idx;
493
+ state.dragMode = !state.selectedImages.has(img.src);
494
+ state.dragSavedSelection = new Set(state.selectedImages);
495
+ updateDragSelection(idx);
496
+ }
497
+ });
498
+
499
+ card.addEventListener('mouseenter', (e) => {
500
+ if (state.isDragging) {
501
+ updateDragSelection(idx);
502
+ }
503
+ });
504
+
505
+ DOM.grid.appendChild(card);
506
+ });
507
+ }
508
+
509
+ updateSelectionVisuals();
510
+ DOM.grid.scrollTop = scroll;
511
+ }
512
+
513
+ function updateSelectionVisuals() {
514
+ const cards = DOM.grid.querySelectorAll('.image-card');
515
+ state.filteredImages.forEach((img, idx) => {
516
+ const isSelected = state.selectedImages.has(img.src);
517
+ const card = cards[idx];
518
+ if (card) {
519
+ if (isSelected) card.classList.add('selected');
520
+ else card.classList.remove('selected');
521
+
522
+ const checkbox = card.querySelector('.card-checkbox');
523
+ if (checkbox) checkbox.checked = isSelected;
524
+ }
525
+ });
526
+
527
+ // Update counters
528
+ DOM.selectedCount.textContent = state.selectedImages.size;
529
+ DOM.btnCounter.textContent = state.selectedImages.size;
530
+ DOM.selectAll.checked = state.filteredImages.length > 0 && state.selectedImages.size === state.filteredImages.length;
531
+ DOM.downloadBtn.disabled = state.selectedImages.size === 0;
532
+ }
533
+
534
+ function updateDragSelection(currentIdx) {
535
+ state.selectedImages = new Set(state.dragSavedSelection);
536
+ const start = Math.min(state.dragStartIdx, currentIdx);
537
+ const end = Math.max(state.dragStartIdx, currentIdx);
538
+
539
+ for (let i = start; i <= end; i++) {
540
+ const src = state.filteredImages[i].src;
541
+ if (state.dragMode) state.selectedImages.add(src);
542
+ else state.selectedImages.delete(src);
543
+ }
544
+
545
+ state.lastSelectedIdx = currentIdx;
546
+ updateSelectionVisuals();
547
+ }
548
+
549
+ function toggleSelection(idx, shift, forceState = null) {
550
+ const img = state.filteredImages[idx];
551
+ const isCurrentlySelected = state.selectedImages.has(img.src);
552
+
553
+ if (shift && state.lastSelectedIdx !== -1) {
554
+ const start = Math.min(state.lastSelectedIdx, idx);
555
+ const end = Math.max(state.lastSelectedIdx, idx);
556
+ const shouldSelect = !state.selectedImages.has(state.filteredImages[state.lastSelectedIdx].src);
557
+
558
+ for (let i = start; i <= end; i++) {
559
+ const src = state.filteredImages[i].src;
560
+ if (shouldSelect) state.selectedImages.add(src);
561
+ else state.selectedImages.delete(src);
562
+ }
563
+ } else {
564
+ if (forceState !== null) {
565
+ if (forceState) state.selectedImages.add(img.src);
566
+ else state.selectedImages.delete(img.src);
567
+ } else {
568
+ if (isCurrentlySelected) state.selectedImages.delete(img.src);
569
+ else state.selectedImages.add(img.src);
570
+ }
571
+ state.lastSelectedIdx = idx;
572
+ }
573
+ updateSelectionVisuals();
574
+ }
575
+
576
+ // --- UTILIDADES ---
577
+
578
+ function getExtension(url) {
579
+ let e = url.split('.').pop().split(/[#?]/)[0].toLowerCase();
580
+ return ['jpg','jpeg','png','webp','gif','svg','avif','bmp','tiff','tif','ico','heic','heif','jxl'].includes(e) ? e : 'desconocido';
581
+ }
582
+
583
+ function getQualityFolder(width, height) {
584
+ const max = Math.max(width, height);
585
+ const min = Math.min(width, height);
586
+ if (min >= 2160 || max >= 3840) return '4K';
587
+ if (min >= 1440 || max >= 2560) return '2K';
588
+ if (min >= 1080 || max >= 1920) return '1080p';
589
+ if (min >= 720 || max >= 1280) return '720p';
590
+ return 'Normal';
591
+ }
592
+
593
+ function downloadImage(img, idx = 0, totalItems = 1, uniqueSf = null) {
594
+ const url = img.src || img; // Fallback
595
+ const width = img.width || 0;
596
+ const height = img.height || 0;
597
+
598
+ const ext = getExtension(url) === 'desconocido' ? 'jpg' : getExtension(url);
599
+
600
+ let sf = uniqueSf;
601
+ if (!sf) {
602
+ sf = DOM.subfolderInput.value.trim().replace(/[\\:*?"<>|]/g, "") || 'comics_completos';
603
+ }
604
+
605
+ if (DOM.separateQuality && DOM.separateQuality.checked && width > 0 && height > 0) {
606
+ const quality = getQualityFolder(width, height);
607
+ sf = `${sf}/${quality}`;
608
+ }
609
+
610
+ let name = url.split('/').pop().split(/[#?]/)[0].slice(0, 50) || `img_${idx + 1}`;
611
+
612
+ if (DOM.renameSequential && DOM.renameSequential.checked) {
613
+ const padLength = Math.max(2, String(totalItems).length);
614
+ name = `pag_${String(idx + 1).padStart(padLength, '0')}`;
615
+ }
616
+
617
+ const filename = `${sf}/${name}.${ext}`;
618
+
619
+ if (url.includes('poringa.') || url.includes('chochox.')) {
620
+ fetch(url)
621
+ .then(r => { if(!r.ok) throw new Error('Fetch failed'); return r.blob(); })
622
+ .then(blob => {
623
+ const blobUrl = URL.createObjectURL(blob);
624
+ chrome.runtime.sendMessage({ action: 'registerDownload', url: blobUrl, filename: filename }, () => {
625
+ chrome.downloads.download({ url: blobUrl, saveAs: false });
626
+ });
627
+ })
628
+ .catch(e => {
629
+ console.warn("Blob fetch failed, falling back to direct download", e);
630
+ chrome.runtime.sendMessage({ action: 'registerDownload', url: url, filename: filename }, () => {
631
+ chrome.downloads.download({ url, saveAs: false });
632
+ });
633
+ });
634
+ return;
635
+ }
636
+
637
+ chrome.runtime.sendMessage({ action: 'registerDownload', url: url, filename: filename }, () => {
638
+ chrome.downloads.download({ url, saveAs: false });
639
+ });
640
+ }
641
+
642
+ async function getUniqueSubfolder(baseFolder) {
643
+ if (!baseFolder) return 'comics_completos';
644
+ return new Promise(resolve => {
645
+ if (typeof chrome === 'undefined' || !chrome.downloads) {
646
+ resolve(baseFolder);
647
+ return;
648
+ }
649
+ chrome.downloads.search({ query: [baseFolder] }, (items) => {
650
+ let maxSuffix = -1;
651
+ const baseLower = baseFolder.toLowerCase();
652
+
653
+ for (const item of items) {
654
+ if (item.filename) {
655
+ const normalized = item.filename.replace(/\\/g, '/');
656
+ const parts = normalized.split('/');
657
+
658
+ for (let i = 0; i < parts.length - 1; i++) {
659
+ const partLower = parts[i].toLowerCase();
660
+ if (partLower === baseLower) {
661
+ maxSuffix = Math.max(maxSuffix, 0);
662
+ } else if (partLower.startsWith(baseLower + ' (')) {
663
+ const suffixStr = partLower.substring(baseLower.length);
664
+ const match = suffixStr.match(/^ \((\d+)\)$/);
665
+ if (match) {
666
+ maxSuffix = Math.max(maxSuffix, parseInt(match[1], 10));
667
+ }
668
+ }
669
+ }
670
+ }
671
+ }
672
+
673
+ if (maxSuffix === -1) {
674
+ resolve(baseFolder);
675
+ } else {
676
+ resolve(`${baseFolder} (${maxSuffix + 1})`);
677
+ }
678
+ });
679
+ });
680
+ }
681
+
682
+ function getImagesFromPageDOM() {
683
+ const results = [];
684
+ document.querySelectorAll('img').forEach(img => {
685
+ let p = img.parentElement, inLink = false, linkHref = null;
686
+ while(p && p.tagName !== 'BODY') {
687
+ if (p.tagName === 'A') { inLink = true; linkHref = p.href; break; }
688
+ p = p.parentElement;
689
+ }
690
+ let src = img.getAttribute('data-src') || img.getAttribute('data-lazy-src') || img.getAttribute('data-opt-src') || img.src;
691
+
692
+ // Si la URL es relativa, la convertimos a absoluta usando la URL actual de la página
693
+ try {
694
+ if (src && !src.startsWith('data:') && !src.startsWith('blob:')) {
695
+ src = new URL(src, window.location.href).href;
696
+ }
697
+ } catch(e) {}
698
+
699
+ if (src?.startsWith('http')) {
700
+ const isKemonoThumb = src.includes('kemono.') && src.includes('/thumbnail/data/');
701
+ results.push({ src, width: img.naturalWidth || 0, height: img.naturalHeight || 0, inLink, linkHref, isKemonoThumb });
702
+ }
703
+ });
704
+
705
+ document.querySelectorAll('.post__files a, .post__file a, .fileThumb, a[href*="kemono."]').forEach(a => {
706
+ if (a.href.match(/\.(jpg|jpeg|png|webp|gif|svg|avif|bmp|tiff|tif|ico|heic|heif|jxl)$/i)) {
707
+ results.push({ src: a.href, width: 0, height: 0, inLink: true, linkHref: a.href, isDirectLink: true });
708
+ }
709
+ });
710
+ return results;
711
+ }
scripts/ImageNinja HD/rules.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "id": 1,
4
+ "priority": 1,
5
+ "action": {
6
+ "type": "modifyHeaders",
7
+ "requestHeaders": [
8
+ {
9
+ "header": "Referer",
10
+ "operation": "set",
11
+ "value": "https://www.poringa.net/"
12
+ },
13
+ {
14
+ "header": "Origin",
15
+ "operation": "set",
16
+ "value": "https://www.poringa.net"
17
+ }
18
+ ],
19
+ "responseHeaders": [
20
+ {
21
+ "header": "Cross-Origin-Resource-Policy",
22
+ "operation": "remove"
23
+ },
24
+ {
25
+ "header": "Access-Control-Allow-Origin",
26
+ "operation": "set",
27
+ "value": "*"
28
+ }
29
+ ]
30
+ },
31
+ "condition": {
32
+ "urlFilter": "poringa.net",
33
+ "resourceTypes": ["main_frame", "sub_frame", "stylesheet", "script", "image", "font", "object", "xmlhttprequest", "ping", "csp_report", "media", "websocket", "other"]
34
+ }
35
+ }
36
+ ]