-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
1775 lines (1609 loc) · 83.5 KB
/
code.js
File metadata and controls
1775 lines (1609 loc) · 83.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name Vinted Country & City Filter (client-side)
// @namespace https://greasyfork.org/en/users/1550823-nigel1992
// @version 1.4.7
// @description Adds a country and city indicator to Vinted items and allows client-side visual filtering by including/excluding selected countries. The script uses Vinted’s public item API to retrieve country and city information. It does not perform purchases, send messages, or modify anything on Vinted servers.
// @author Nigel1992
// @license MIT
// @match https://www.vinted.nl/*
// @match https://www.vinted.be/*
// @match https://www.vinted.fr/*
// @match https://www.vinted.it/*
// @match https://www.vinted.es/*
// @match https://www.vinted.de/*
// @match https://www.vinted.se/*
// @match https://www.vinted.lt/*
// @match https://www.vinted.pl/*
// @match https://www.vinted.cz/*
// @match https://www.vinted.hu/*
// @match https://www.vinted.sk/*
// @match https://www.vinted.pt/*
// @match https://www.vinted.lu/*
// @match https://www.vinted.ro/*
// @match https://www.vinted.gr/*
// @match https://www.vinted.bg/*
// @match https://www.vinted.si/*
// @match https://www.vinted.hr/*
// @match https://www.vinted.ie/*
// @match https://www.vinted.com/*
// @match https://www.vinted.at/* // Austria 🇦🇹
// @match https://www.vinted.dk/* // Denmark 🇩🇰 (placeholder)
// @match https://www.vinted.fi/* // Finland 🇫🇮 (placeholder)
// @match https://www.vinted.co.uk/* // United Kingdom 🇬🇧 (placeholder)
// @grant none
// @run-at document-end
// ==/UserScript==
(function () {
// Check if user is logged in to Vinted
function isUserLoggedIn() {
// Check for the presence of <figure class="header-avatar">, which only appears when logged in
return !!document.querySelector('figure.header-avatar');
}
// Skip login check if captcha is being shown (isPausedForCaptcha or captcha warning visible)
const captchaWarning = document.getElementById('vinted-captcha-warning');
// Do not show login warning when visiting API endpoints directly (e.g., /api/...)
if (!isUserLoggedIn() && !(window.isPausedForCaptcha || (captchaWarning && captchaWarning.style.display === 'block')) && !window.location.pathname.includes('/api/')) {
const msg = '⚠️ [Vinted Country & City Filter] You must be logged in to Vinted for this script to work. Please log in and refresh the page.';
const banner = document.createElement('div');
banner.textContent = msg;
banner.style.position = 'fixed';
banner.style.top = '0';
banner.style.left = '0';
banner.style.width = '100vw';
banner.style.background = '#ffefc1';
banner.style.color = '#a00';
banner.style.fontSize = '18px';
banner.style.textAlign = 'center';
banner.style.zIndex = '2147483647';
banner.style.padding = '16px 0';
banner.style.boxShadow = '0 2px 8px rgba(0,0,0,0.08)';
banner.style.fontFamily = 'inherit';
banner.style.fontWeight = 'bold';
banner.style.letterSpacing = '0.5px';
banner.style.userSelect = 'none';
// Add margin to body so banner doesn't cover top nav
document.body.style.marginTop = '56px';
document.body.appendChild(banner);
return;
}
'use strict';
/* =========================
Page Filter - Only run on homepage and catalog pages
========================== */
function isAllowedPage() {
const path = location.pathname;
// Allow: homepage ("/"), catalog pages ("/catalog/..."), and search results
return path === '/' ||
path.startsWith('/catalog') ||
path.startsWith('/vetements') || // French catalog
path.startsWith('/kleding') || // Dutch catalog
path.startsWith('/ropa') || // Spanish catalog
path.startsWith('/abbigliamento') || // Italian catalog
path.startsWith('/kleidung') || // German catalog
path.startsWith('/kläder'); // Swedish catalog
}
// Exit early if not on an allowed page
if (!isAllowedPage()) {
return;
}
/*
USER INFORMATION (Greasy Fork transparency):
- This script retrieves country and city information via Vinted’s own API:
/api/v2/items/{id}/details
- Filtering is purely visual (opacity and grayscale) and does not affect
Vinted search results or server-side filters.
- The script may temporarily pause if Vinted returns a 403 (captcha)
or 429 (rate limit). In this case the user must manually solve the captcha.
- No data is sent to third parties. The script contains no tracking,
advertising, miners, or other self-gain functionality.
*/
/* =========================
Settings & state
========================== */
let includedCountries = JSON.parse(sessionStorage.getItem('vinted_included_countries') || '[]');
// Normalize any previously saved entries
includedCountries = includedCountries.map(c => normalizeCountryName(c));
let isFilterEnabled = sessionStorage.getItem('vinted_filter_enabled') !== 'false'; // Default: enabled
let isProcessing = false;
let isPausedForCaptcha = false;
let captchaPopup = null;
let captchaCheckInterval = null;
let isWaitingForEnglish = false;
let englishCheckComplete = false;
let darkMode = sessionStorage.getItem('vinted_dark_mode') === 'true';
let countrySectionCollapsed = sessionStorage.getItem('vinted_country_collapsed') === 'true';
let isPaused = false;
let flaggedSellers = new Set(JSON.parse(localStorage.getItem('vinted_flagged_sellers') || '[]'));
let hasShownCaptchaAlert = false;
let activeTab = sessionStorage.getItem('vinted_active_tab') || 'main';
const processedItems = new Map();
const queue = [];
const CACHE_PREFIX = 'vinted_item_';
const PRESETS_PREFIX = 'vinted_preset_';
const countryToFlag = {
'netherlands': '🇳🇱',
'belgium': '🇧🇪',
'france': '🇫🇷',
'germany': '🇩🇪',
'spain': '🇪🇸',
'italy': '🇮🇹',
'portugal': '🇵🇹',
'poland': '🇵🇱',
'united kingdom': '🇬🇧',
'uk': '🇬🇧',
'sweden': '🇸🇪',
'denmark': '🇩🇰',
'finland': '🇫🇮',
'ireland': '🇮🇪',
'austria': '🇦🇹',
'romania': '🇷🇴',
'greece': '🇬🇷',
'bulgaria': '🇧🇬',
'slovenia': '🇸🇮',
'croatia': '🇭🇷',
'czech republic': '🇨🇿',
'hungary': '🇭🇺',
'slovakia': '🇸🇰',
'lithuania': '🇱🇹',
'luxembourg': '🇱🇺'
};
// Normalize country names returned by the API to canonical keys used throughout the script
function normalizeCountryName(name) {
if (!name) return '';
const s = String(name).toLowerCase().trim();
if (s === 'uk' || s === 'gb' || s.includes('united kingdom') || s.includes('great britain')) return 'united kingdom';
if (s.includes('czech')) return 'czech republic';
if (s.includes('slovak')) return 'slovakia';
if (s.includes('luxembourg')) return 'luxembourg';
if (s.includes('ireland')) return 'ireland';
const keywords = ['netherlands','belgium','france','germany','spain','italy','portugal','poland','sweden','denmark','finland','austria','romania','greece','bulgaria','slovenia','croatia','lithuania','hungary'];
for (const kw of keywords) {
if (s.includes(kw)) return kw;
}
// Fallback: collapse multiple spaces into single space
return s.replace(/\s+/g, ' ');
}
/* =========================
Auto Captcha Solver
========================== */
function openCaptchaPopup() {
const apiUrl = `https://${location.hostname}/api/v2/items/1/details`;
// Close existing popup if any
if (captchaPopup && !captchaPopup.closed) {
captchaPopup.close();
}
// Open small popup window
captchaPopup = window.open(
apiUrl,
'VintedCaptcha',
'width=500,height=600,scrollbars=yes,resizable=yes'
);
// Check if popup was blocked
if (!captchaPopup || captchaPopup.closed || typeof captchaPopup.closed === 'undefined') {
console.warn('[Vinted Filter] Popup was blocked by browser. Please allow popups for this site and refresh the page.');
updateStatusMessage('⚠️ Popup blocked! Please allow popups for this site in your browser settings, then refresh the page and try again.');
alert('Vinted Filter: Popup was blocked! Please allow popups for this site in your browser settings, then refresh the page and try again.');
return false;
} else {
updateStatusMessage('A popup window has been opened to automatically solve the captcha. Please complete the captcha in the popup window. The script will automatically detect when it\'s solved and continue processing. If you do not see a popup, check your browser\'s popup settings.');
}
// Start checking if captcha is solved
startCaptchaCheck();
return true;
}
function startCaptchaCheck() {
// Clear any existing interval
if (captchaCheckInterval) {
clearInterval(captchaCheckInterval);
}
captchaCheckInterval = setInterval(async () => {
try {
// Try to fetch the API to see if captcha is solved
const response = await fetch(
`https://${location.hostname}/api/v2/items/1/details`,
{ credentials: 'include' }
);
// If we get a 200 immediately, captcha is solved; close popup right away
if (response.ok && response.status === 200) {
onCaptchaSolved();
return;
}
// If we no longer get 403, captcha is solved
if (response.status !== 403) {
const text = await response.text();
try {
let data = JSON.parse(text);
// Handle array response: [{"code":104,...}]
if (Array.isArray(data)) {
data = data[0] || {};
}
// Check if we get the "not found" response or valid data (means captcha is solved)
if (data.code === 104 || data.message_code === 'not_found' || data.item) {
console.log('[Vinted Filter] Captcha solved! Response:', data);
onCaptchaSolved();
return;
}
} catch (parseError) {
// If response is not JSON but status is OK, captcha might be solved
if (response.ok) {
console.log('[Vinted Filter] Captcha appears solved (non-JSON response)');
onCaptchaSolved();
return;
}
// Also check if the HTML response contains "message_code" (captcha solved)
if (text.includes('message_code')) {
console.log('[Vinted Filter] Captcha solved! Found message_code in HTML response');
onCaptchaSolved();
return;
}
}
}
} catch (e) {
console.log('[Vinted Filter] Captcha check error:', e);
// Ignore errors, keep checking
}
}, 1500); // Check every 1.5 seconds
}
function onCaptchaSolved() {
// Stop checking
if (captchaCheckInterval) {
clearInterval(captchaCheckInterval);
captchaCheckInterval = null;
}
hasShownCaptchaAlert = false;
// Close popup - try multiple times to ensure it closes
if (captchaPopup && !captchaPopup.closed) {
console.log('[Vinted Filter] Attempting to close captcha popup...');
try {
captchaPopup.close();
} catch (e) {
console.warn('[Vinted Filter] Error closing popup:', e);
}
// Retry closing after a short delay in case it didn't work immediately
setTimeout(() => {
if (captchaPopup && !captchaPopup.closed) {
console.log('[Vinted Filter] Retrying popup close...');
try {
captchaPopup.close();
} catch (e) {
console.warn('[Vinted Filter] Error on retry:', e);
}
}
captchaPopup = null;
}, 500);
} else {
captchaPopup = null;
}
// Resume processing
isPausedForCaptcha = false;
const warningEl = document.getElementById('vinted-captcha-warning');
if (warningEl) {
warningEl.style.display = 'none';
}
updateStatusMessage('✅ Captcha solved! Resuming...');
// Small delay before resuming
setTimeout(() => {
updateStatusMessage('Processing items...');
}, 1500);
}
/* =========================
UI Menu - Enhanced GUI
========================== */
function createMenu() {
// Don't show menu on API pages
if (location.pathname.startsWith('/api')) return;
if (document.getElementById('vinted-filter-menu')) return;
const menu = document.createElement('div');
menu.id = 'vinted-filter-menu';
const maxHeight = Math.max(window.innerHeight * 0.5, 300); // 50% of screen height, min 300px
menu.style.cssText = `
position: fixed;
top: 80px;
right: 20px;
z-index: 9999999;
background: linear-gradient(135deg, ${darkMode ? '#1e1e1e 0%, #2d2d2d 100%' : '#ffffff 0%, #f8f9fa 100%'});
border: 2px solid #007782;
padding: 20px;
border-radius: 16px;
box-shadow: 0 12px 40px rgba(0,119,130,0.3);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
min-width: 280px;
max-width: 320px;
max-height: ${maxHeight}px;
overflow-y: auto;
transition: all 0.3s ease;
color: ${darkMode ? '#fff' : '#333'};
`;
const hiddenCount = Array.from(processedItems.values()).filter(item => item.country && !includedCountries.includes(item.country) && includedCountries.length > 0).length;
menu.innerHTML = `
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 2px solid ${darkMode ? '#444' : '#e0e0e0'};">
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 24px;">🌍</span>
<strong style="color: #007782; font-size: 18px; font-weight: 600;">Location Filter</strong>
</div>
<div style="display: flex; gap: 4px;">
<button id="vinted-dark-toggle" style="background: none; border: none; font-size: 18px; cursor: pointer; color: #666; padding: 4px 8px; border-radius: 4px; transition: background 0.2s;" title="Toggle dark mode">${darkMode ? '☀️' : '🌙'}</button>
<button id="vinted-pause-toggle" style="background: none; border: none; font-size: 18px; cursor: pointer; color: #666; padding: 4px 8px; border-radius: 4px; transition: background 0.2s;" title="${isPaused ? 'Resume processing' : 'Pause processing'}">${isPaused ? '▶' : '⏸'}</button>
<button id="vinted-toggle-menu" style="background: none; border: none; font-size: 20px; cursor: pointer; color: #666; padding: 4px 8px; border-radius: 4px; transition: background 0.2s;" title="Minimize (Alt+V)">−${hiddenCount > 0 ? ` (${hiddenCount})` : ''}</button>
</div>
</div>
<div id="vinted-tab-bar" style="display: flex; gap: 8px; margin-bottom: 12px;">
<button class="vinted-tab-btn" data-tab="main">Main</button>
<button class="vinted-tab-btn" data-tab="settings">Settings</button>
</div>
<div id="vinted-menu-content">
<div id="vinted-tab-main" class="vinted-tab-panel" style="display: ${activeTab === 'main' ? 'block' : 'none'};">
<div style="
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px;
background: ${darkMode ? '#333' : '#f0f9f9'};
border-radius: 10px;
margin-bottom: 12px;
border: 2px solid #007782;
">
<span style="color: ${darkMode ? '#ddd' : '#333'}; font-weight: 500; font-size: 14px;">Filter Active</span>
<label style="
position: relative;
display: inline-block;
width: 50px;
height: 26px;
cursor: pointer;
">
<input type="checkbox" id="vinted-filter-toggle" ${isFilterEnabled ? 'checked' : ''} style="
opacity: 0;
width: 0;
height: 0;
">
<span id="vinted-toggle-slider" style="
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: ${isFilterEnabled ? '#007782' : '#ccc'};
transition: 0.3s;
border-radius: 26px;
">
<span style="
position: absolute;
content: '';
height: 20px;
width: 20px;
left: ${isFilterEnabled ? '27px' : '3px'};
bottom: 3px;
background-color: white;
transition: 0.3s;
border-radius: 50%;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
"></span>
</span>
</label>
</div>
<div style="background: ${darkMode ? '#333' : '#f5f5f5'}; border-radius: 10px; padding: 12px; margin-bottom: 12px;">
<div id="vinted-match-count" style="
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
" title="Items not excluded by your country filter (shown at full opacity)">
<span style="color: ${darkMode ? '#aaa' : '#666'}; font-size: 13px; font-weight: 500;">✅ Shown Items:</span>
<span id="vinted-match-number" style="
background: #4caf50;
color: white;
padding: 4px 12px;
border-radius: 12px;
font-weight: 600;
font-size: 14px;
min-width: 40px;
text-align: center;
">0</span>
</div>
<div id="vinted-total-count" style="
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
" title="Total number of items on the current page that have been scanned for location data">
<span style="color: ${darkMode ? '#aaa' : '#666'}; font-size: 13px; font-weight: 500;">📦 Total on Page:</span>
<span id="vinted-total-number" style="
background: #2196f3;
color: white;
padding: 4px 12px;
border-radius: 12px;
font-weight: 600;
font-size: 14px;
min-width: 40px;
text-align: center;
">0</span>
</div>
<div id="vinted-queue-count" style="
display: flex;
align-items: center;
justify-content: space-between;
" title="Items currently waiting to be scanned for location data via the API">
<span style="color: ${darkMode ? '#aaa' : '#666'}; font-size: 13px; font-weight: 500;">⏳ In Queue:</span>
<span id="vinted-queue-number" style="
background: #ff9800;
color: white;
padding: 4px 12px;
border-radius: 12px;
font-weight: 600;
font-size: 14px;
min-width: 40px;
text-align: center;
">0</span>
</div>
</div>
<div id="vinted-progress-bar-container" style="
background: #e0e0e0;
border-radius: 10px;
height: 8px;
margin-bottom: 12px;
overflow: hidden;
display: none;
">
<div id="vinted-progress-bar" style="
background: linear-gradient(90deg, #007782, #00a8b5);
height: 100%;
width: 0%;
transition: width 0.3s ease;
border-radius: 10px;
"></div>
</div>
<div id="vinted-language-warning" style="
display: none;
background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
border: 2px solid #ffc107;
padding: 14px;
border-radius: 10px;
font-size: 13px;
margin-bottom: 12px;
">
<div style="
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
font-weight: 600;
color: #856404;
">
<span style="font-size: 20px;">⚠️</span>
<span>Language Warning</span>
</div>
<p style="margin: 0; color: #856404; line-height: 1.5;">
This script only works when Vinted is set to <strong>English</strong>. Please change your language to English in your Vinted settings to use this filter.
</p>
</div>
<div id="vinted-status-message" style="
font-size: 12px;
color: ${darkMode ? '#aaa' : '#666'};
text-align: center;
padding: 8px;
background: ${darkMode ? '#333' : '#f9f9f9'};
border-radius: 8px;
margin-bottom: 12px;
min-height: 20px;
">Ready to filter items...</div>
<div id="vinted-captcha-warning" style="
display: none;
background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
border: 2px solid #f44336;
padding: 14px;
border-radius: 10px;
font-size: 13px;
margin-top: 12px;
">
<div style="
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
font-weight: 600;
color: #c62828;
">
<span style="font-size: 20px;">🔓</span>
<span>Auto-Solving Captcha</span>
</div>
<p style="margin: 0; color: #555; line-height: 1.5;">
A popup window has been opened to automatically solve the captcha. Please complete the captcha in the popup window. The script will automatically detect when it's solved and continue processing.
</p>
</div>
<div style="display: flex; gap: 8px; margin-top: 12px;">
<button id="vinted-reset-stats" style="
flex: 1;
padding: 10px;
background: #9c27b0;
color: white;
border: none;
border-radius: 8px;
font-weight: 500;
cursor: pointer;
font-size: 12px;
transition: background 0.2s;
" onmouseover="this.style.background='#7b1fa2'" onmouseout="this.style.background='#9c27b0'" title="Reset stats counters">📊 Reset Stats</button>
<button id="vinted-clear-cache" style="
flex: 1;
padding: 10px;
background: #757575;
color: white;
border: none;
border-radius: 8px;
font-weight: 500;
cursor: pointer;
font-size: 12px;
transition: background 0.2s;
" onmouseover="this.style.background='#616161'" onmouseout="this.style.background='#757575'" title="Clear cached item data">
🗑️ Clear Cache
</button>
</div>
<div style="display: flex; gap: 8px; margin-top: 8px;">
<a href="https://greasyfork.org/en/scripts/559753-vinted-country-city-filter-client-side/feedback" target="_blank" style="
flex: 1;
padding: 8px;
background: #007782;
color: white;
border: none;
border-radius: 8px;
font-weight: 500;
cursor: pointer;
font-size: 11px;
text-align: center;
text-decoration: none;
transition: background 0.2s;
" onmouseover="this.style.background='#005f6b'" onmouseout="this.style.background='#007782'">
💬 Feedback
</a>
<a href="https://greasyfork.org/en/scripts/559753-vinted-country-city-filter-client-side/feedback" target="_blank" style="
flex: 1;
padding: 8px;
background: #dc3545;
color: white;
border: none;
border-radius: 8px;
font-weight: 500;
cursor: pointer;
font-size: 11px;
text-align: center;
text-decoration: none;
transition: background 0.2s;
" onmouseover="this.style.background='#c82333'" onmouseout="this.style.background='#dc3545'">
🐛 Report Issue
</a>
</div>
</div>
<div id="vinted-tab-settings" class="vinted-tab-panel" style="display: ${activeTab === 'settings' ? 'block' : 'none'};">
<div id="vinted-presets-section" style="margin-bottom: 16px; padding: 12px; background: ${darkMode ? '#333' : '#f5f5f5'}; border-radius: 10px;">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;">
<label style="color: ${darkMode ? '#ddd' : '#333'}; font-weight: 500; font-size: 14px;">Presets:</label>
<button id="vinted-quick-save-preset" style="
padding: 4px 8px;
background: #007782;
color: white;
border: none;
border-radius: 6px;
font-weight: 500;
cursor: pointer;
font-size: 11px;
transition: background 0.2s;
" onmouseover="this.style.background='#005f6b'" onmouseout="this.style.background='#007782'" title="Save current filter as preset">💾 Save</button>
</div>
<select id="vinted-preset-select" style="
width: 100%;
padding: 6px;
background: ${darkMode ? '#444' : 'white'};
color: ${darkMode ? '#fff' : '#000'};
border: 1px solid #007782;
border-radius: 6px;
cursor: pointer;
font-size: 12px;
margin-bottom: 6px;
">
<option value="">-- Select preset --</option>
</select>
<div style="display: flex; gap: 6px;">
<button id="vinted-load-preset" style="
flex: 1;
padding: 6px;
background: #4caf50;
color: white;
border: none;
border-radius: 6px;
font-weight: 500;
cursor: pointer;
font-size: 11px;
transition: background 0.2s;
" onmouseover="this.style.background='#388e3c'" onmouseout="this.style.background='#4caf50'" title="Load selected preset">Load</button>
<button id="vinted-delete-preset" style="
flex: 1;
padding: 6px;
background: #f44336;
color: white;
border: none;
border-radius: 6px;
font-weight: 500;
cursor: pointer;
font-size: 11px;
transition: background 0.2s;
" onmouseover="this.style.background='#d32f2f'" onmouseout="this.style.background='#f44336'" title="Delete selected preset">Delete</button>
</div>
<div style="display: flex; gap: 6px; margin-top: 6px;">
<button id="vinted-export-presets" style="
flex: 1;
padding: 6px;
background: #2196f3;
color: white;
border: none;
border-radius: 6px;
font-weight: 500;
cursor: pointer;
font-size: 11px;
transition: background 0.2s;
" onmouseover="this.style.background='#1976d2'" onmouseout="this.style.background='#2196f3'" title="Export all presets as JSON">📥 Export</button>
<button id="vinted-import-presets" style="
flex: 1;
padding: 6px;
background: #ff9800;
color: white;
border: none;
border-radius: 6px;
font-weight: 500;
cursor: pointer;
font-size: 11px;
transition: background 0.2s;
" onmouseover="this.style.background='#f57c00'" onmouseout="this.style.background='#ff9800'" title="Import presets from JSON">📤 Import</button>
</div>
</div>
<div id="vinted-filter-options" style="${isFilterEnabled ? '' : 'opacity: 0.5; pointer-events: none;'}">
<div style="margin-bottom: 16px;">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;">
<label style="display: block; color: ${darkMode ? '#ddd' : '#333'}; font-weight: 500; font-size: 14px;">
Include Countries:
</label>
<button id="vinted-toggle-countries" style="
background: #007782;
color: white;
border: none;
border-radius: 4px;
padding: 2px 8px;
font-size: 11px;
cursor: pointer;
transition: background 0.2s;
" onmouseover="this.style.background='#005f6b'" onmouseout="this.style.background='#007782'" title="${countrySectionCollapsed ? 'Expand' : 'Collapse'}">${countrySectionCollapsed ? '▶' : '▼'}</button>
</div>
<div id="vinted-country-checkboxes" style="
display: ${countrySectionCollapsed ? 'none' : 'grid'};
grid-template-columns: 1fr 1fr;
gap: 8px;
max-height: 200px;
overflow-y: auto;
">
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-netherlands" style="margin: 0;">
<span>🇳🇱 Netherlands</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-belgium" style="margin: 0;">
<span>🇧🇪 Belgium</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-france" style="margin: 0;">
<span>🇫🇷 France</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-germany" style="margin: 0;">
<span>🇩🇪 Germany</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-spain" style="margin: 0;">
<span>🇪🇸 Spain</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-italy" style="margin: 0;">
<span>🇮🇹 Italy</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-portugal" style="margin: 0;">
<span>🇵🇹 Portugal</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-poland" style="margin: 0;">
<span>🇵🇱 Poland</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-sweden" style="margin: 0;">
<span>🇸🇪 Sweden</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-denmark" style="margin: 0;">
<span>🇩🇰 Denmark</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-finland" style="margin: 0;">
<span>🇫🇮 Finland</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-united-kingdom" style="margin: 0;">
<span>🇬🇧 United Kingdom</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-ireland" style="margin: 0;">
<span>🇮🇪 Ireland</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-austria" style="margin: 0;">
<span>🇦🇹 Austria</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-romania" style="margin: 0;">
<span>🇷🇴 Romania</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-greece" style="margin: 0;">
<span>🇬🇷 Greece</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-bulgaria" style="margin: 0;">
<span>🇧🇬 Bulgaria</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-slovenia" style="margin: 0;">
<span>🇸🇮 Slovenia</span>
</label>
<label style="display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; cursor: pointer; transition: background 0.2s; color: ${darkMode ? '#ddd' : '#333'};" onmouseover="this.style.background='${darkMode ? '#444' : '#f0f0f0'}'" onmouseout="this.style.background='transparent'">
<input type="checkbox" id="include-croatia" style="margin: 0;">
<span>🇭🇷 Croatia</span>
</label>
</div>
</div>
</div>
</div>
<div style="
text-align: center;
font-size: 10px;
color: ${darkMode ? '#555' : '#999'};
margin-top: 12px;
padding-top: 8px;
border-top: 1px solid ${darkMode ? '#444' : '#eee'};
">
v1.4.7 • Jan 29, 2026
</div>
</div>
`;
document.body.appendChild(menu);
// Tab handling
const tabButtons = Array.from(menu.querySelectorAll('.vinted-tab-btn'));
const tabPanels = {
main: menu.querySelector('#vinted-tab-main'),
settings: menu.querySelector('#vinted-tab-settings')
};
function setActiveTab(tab) {
activeTab = tab;
sessionStorage.setItem('vinted_active_tab', tab);
tabButtons.forEach(btn => {
const isActive = btn.dataset.tab === tab;
btn.classList.toggle('vinted-tab-active', isActive);
btn.setAttribute('aria-pressed', isActive ? 'true' : 'false');
});
Object.entries(tabPanels).forEach(([key, panel]) => {
if (!panel) return;
const isActive = key === tab;
panel.style.display = isActive ? 'block' : 'none';
panel.classList.toggle('vinted-tab-panel-active', isActive);
if (isActive) {
// restart animation for repeat visits
panel.classList.remove('vinted-tab-panel-animate');
void panel.offsetWidth;
panel.classList.add('vinted-tab-panel-animate');
} else {
panel.classList.remove('vinted-tab-panel-animate');
}
});
}
tabButtons.forEach(btn => {
btn.addEventListener('click', () => setActiveTab(btn.dataset.tab));
});
setActiveTab(activeTab);
// Dark mode toggle
document.getElementById('vinted-dark-toggle').addEventListener('click', () => {
darkMode = !darkMode;
sessionStorage.setItem('vinted_dark_mode', darkMode);
// Recreate menu to apply theme
document.getElementById('vinted-filter-menu').remove();
});
// Pause/Resume toggle
const pauseBtn = document.getElementById('vinted-pause-toggle');
pauseBtn.addEventListener('click', () => {
isPaused = !isPaused;
pauseBtn.textContent = isPaused ? '▶' : '⏸';
pauseBtn.title = isPaused ? 'Resume processing' : 'Pause processing';
if (isPaused) {
updateStatusMessage('⏸ Paused');
} else {
updateStatusMessage('▶ Resuming...');
setTimeout(() => updateStatusMessage('Processing items...'), 800);
applyFilter();
}
});
// Country section collapse toggle
document.getElementById('vinted-toggle-countries').addEventListener('click', () => {
countrySectionCollapsed = !countrySectionCollapsed;
sessionStorage.setItem('vinted_country_collapsed', countrySectionCollapsed);
const checkboxes = document.getElementById('vinted-country-checkboxes');
const btn = document.getElementById('vinted-toggle-countries');
if (countrySectionCollapsed) {
checkboxes.style.display = 'none';
btn.textContent = '▶';
} else {
checkboxes.style.display = 'grid';
btn.textContent = '▼';
}
});
// Preset management functions
function getPresets() {
const presetsJson = localStorage.getItem('vinted_presets') || '{}';
return JSON.parse(presetsJson);
}
function savePreset(name, data) {
const presets = getPresets();
presets[name] = data;
localStorage.setItem('vinted_presets', JSON.stringify(presets));
refreshPresetSelect();
}
function deletePreset(name) {
const presets = getPresets();
delete presets[name];
localStorage.setItem('vinted_presets', JSON.stringify(presets));
refreshPresetSelect();
}
function loadPreset(name) {
const presets = getPresets();
if (presets[name]) {
// Normalize any stored values to canonical keys
includedCountries = (presets[name].countries || []).map(c => normalizeCountryName(c));
sessionStorage.setItem('vinted_included_countries', JSON.stringify(includedCountries));
// Update checkboxes
document.querySelectorAll('#vinted-country-checkboxes input[type="checkbox"]').forEach(cb => {
const raw = cb.id.replace('include-', '').replace(/-/g, ' ');
const key = normalizeCountryName(raw);
cb.checked = includedCountries.includes(key);
});
applyFilter();
updateStatusMessage(`Preset "${name}" loaded!`);
}
}
function refreshPresetSelect() {
const select = document.getElementById('vinted-preset-select');
const presets = getPresets();
select.innerHTML = '<option value="">-- Select preset --</option>';
Object.keys(presets).forEach(name => {
const option = document.createElement('option');
option.value = name;
option.textContent = name;
select.appendChild(option);
});
}
refreshPresetSelect();
// Quick save preset
document.getElementById('vinted-quick-save-preset').addEventListener('click', () => {
const name = prompt('Enter preset name:', '');
if (name && name.trim()) {
savePreset(name.trim(), { countries: includedCountries });
updateStatusMessage(`Preset "${name}" saved!`);
}
});
// Load preset
document.getElementById('vinted-load-preset').addEventListener('click', () => {
const select = document.getElementById('vinted-preset-select');
if (select.value) {
loadPreset(select.value);
}
});
// Delete preset
document.getElementById('vinted-delete-preset').addEventListener('click', () => {
const select = document.getElementById('vinted-preset-select');
if (select.value && confirm(`Delete preset "${select.value}"?`)) {
deletePreset(select.value);
updateStatusMessage('Preset deleted!');
}
});
// Export presets
document.getElementById('vinted-export-presets').addEventListener('click', () => {
const presets = getPresets();
const json = JSON.stringify(presets, null, 2);
const blob = new Blob([json], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'vinted-presets.json';
a.click();
URL.revokeObjectURL(url);
updateStatusMessage('Presets exported!');
});
// Import presets
document.getElementById('vinted-import-presets').addEventListener('click', () => {
const input = document.createElement('input');
input.type = 'file';
input.accept = 'application/json';
input.addEventListener('change', (e) => {