all repos — Private-Trackers-Spreadsheet @ e270edad7b82735c2c54dfb92adeb6fd5997e8fc

A spreadsheet providing detailed information about private trackers

assets/js/app.js (view raw)

 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
// Theme switcher component
function themeSwitcher() {
    return {
        isDark: true,
        accentColor: '#6366f1', // Default indigo
        showColorPicker: false,
        accentColors: [
            { name: 'Red', value: '#e74c3c' },
            { name: 'Blue', value: '#3498db' },
            { name: 'Green', value: '#27ae60' },
            { name: 'Purple', value: '#9b59b6' },
            { name: 'Orange', value: '#f39c12' },
            { name: 'Teal', value: '#1abc9c' },
            { name: 'Pink', value: '#e91e63' },
            { name: 'Indigo', value: '#6366f1' }
        ],
        init() {
            // Check for saved preferences
            const savedTheme = localStorage.getItem('theme');
            const savedAccent = localStorage.getItem('accentColor');

            this.isDark = savedTheme ? savedTheme === 'dark' : true;
            this.accentColor = savedAccent || '#6366f1'; // Default to indigo

            this.applyTheme();
            this.applyAccentColor();
        },
        toggleTheme() {
            this.isDark = !this.isDark;
            this.applyTheme();
            localStorage.setItem('theme', this.isDark ? 'dark' : 'light');
        },
        setAccentColor(color) {
            this.accentColor = color;
            this.applyAccentColor();
            localStorage.setItem('accentColor', color);
            this.showColorPicker = false;
        },
        applyTheme() {
            document.documentElement.setAttribute('data-theme', this.isDark ? 'dark' : 'light');
        },
        applyAccentColor() {
            document.documentElement.style.setProperty('--accent-primary', this.accentColor);

            // Calculate complementary colors based on the accent
            const hex = this.accentColor.replace('#', '');
            const r = parseInt(hex.substr(0, 2), 16);
            const g = parseInt(hex.substr(2, 2), 16);
            const b = parseInt(hex.substr(4, 2), 16);

            // Create rgba variants for gradients and hover effects
            document.documentElement.style.setProperty('--accent-rgb', `${r}, ${g}, ${b}`);
            document.documentElement.style.setProperty('--hover-bg', `rgba(${r}, ${g}, ${b}, 0.05)`);

            // Update all gradient variants
            document.documentElement.style.setProperty('--gradient-red',
                `linear-gradient(135deg, rgba(${r}, ${g}, ${b}, 0.1) 0%, rgba(${r}, ${g}, ${b}, 0.05) 100%)`);
            document.documentElement.style.setProperty('--gradient-header',
                `linear-gradient(135deg, rgba(${r}, ${g}, ${b}, 0.1) 0%, rgba(${r}, ${g}, ${b}, 0.05) 100%)`);

            // Update icon glow effect
            document.documentElement.style.setProperty('--icon-glow',
                `drop-shadow(0 0 10px rgba(${r}, ${g}, ${b}, 0.5))`);

            // Update text shadow effects
            document.documentElement.style.setProperty('--text-glow',
                `0 0 10px rgba(${r}, ${g}, ${b}, 0.5)`);
                
            // Update scrollbar styling to match accent color
            document.documentElement.style.setProperty('--scrollbar-thumb', 
                `rgba(${r}, ${g}, ${b}, 0.3)`);
        }
    }
}

// AlpineJS component for main tracker table
function trackerTable() {
    return {
        trackers: [],
        search: '',
        sortColumn: '',
        sortDirection: 'asc',
        showStickyHeader: false,
        stickyHeaderLeft: 0,
        stickyHeaderWidth: 0,
        selectedTrackers: [],
        showCompareModal: false,
        tooltip: {
            show: false,
            text: '',
            x: 0,
            y: 0
        },
        init() {
            this.loadTrackers();
            // Set up scroll listener for sticky header
            this.setupStickyHeader();
        },
        setupStickyHeader() {
            const handleScroll = () => {
                const tableContainer = document.querySelector('.tracker-table__container');
                const originalHeader = document.querySelector('.tracker-table__main thead');
                const tableSection = document.querySelector('.tracker-table');
                
                if (!tableContainer || !originalHeader || !tableSection) return;
                
                const containerRect = tableContainer.getBoundingClientRect();
                const headerRect = originalHeader.getBoundingClientRect();
                const tableSectionRect = tableSection.getBoundingClientRect();
                const navbar = document.querySelector('.tracker-navbar');
                const navbarHeight = navbar ? navbar.offsetHeight : 85;
                
                // Show sticky header when:
                // 1. Original header is above viewport
                // 2. We haven't scrolled past the entire table section
                const headerOutOfView = headerRect.bottom < navbarHeight + 20;
                const stillInTableSection = tableSectionRect.bottom > navbarHeight + 60;
                const shouldShow = headerOutOfView && stillInTableSection;
                
                this.showStickyHeader = shouldShow;
                
                if (shouldShow) {
                    // Position sticky header to match the table container
                    this.stickyHeaderLeft = Math.max(0, containerRect.left);
                    this.stickyHeaderWidth = Math.min(containerRect.width, window.innerWidth - this.stickyHeaderLeft - 20);
                    
                    // Match column widths after a brief delay to ensure DOM is ready
                    this.$nextTick(() => {
                        this.matchColumnWidths();
                    });
                }
            };
            
            // Throttle scroll events for better performance
            let ticking = false;
            const throttledScroll = () => {
                if (!ticking) {
                    requestAnimationFrame(() => {
                        handleScroll();
                        ticking = false;
                    });
                    ticking = true;
                }
            };
            
            window.addEventListener('scroll', throttledScroll);
            window.addEventListener('resize', throttledScroll);
            
            // Initial call
            handleScroll();
        },
        matchColumnWidths() {
            // Get the original table header cells
            const originalCells = document.querySelectorAll('.tracker-table__main thead th');
            const stickyCells = document.querySelectorAll('.tracker-table__sticky-table thead th');
            
            if (originalCells.length !== stickyCells.length) return;
            
            // Copy widths from original to sticky header
            originalCells.forEach((originalCell, index) => {
                if (stickyCells[index]) {
                    const width = originalCell.getBoundingClientRect().width;
                    stickyCells[index].style.width = `${width}px`;
                    stickyCells[index].style.minWidth = `${width}px`;
                    stickyCells[index].style.maxWidth = `${width}px`;
                }
            });
        },
        async loadTrackers() {
            try {
                const res = await fetch('./trackers.json');
                const data = await res.json();
                this.trackers = data.trackers || [];
            } catch (error) {
                console.error('Error loading trackers:', error);
            }
        },
        get filteredTrackers() {
            let filtered = this.trackers;

            if (this.search) {
                const s = this.search.toLowerCase();
                filtered = this.trackers.filter(tracker =>
                    Object.values(tracker).some(v => String(v).toLowerCase().includes(s))
                );
            }

            if (this.sortColumn) {
                filtered.sort((a, b) => {
                    let aVal = a[this.sortColumn] || '';
                    let bVal = b[this.sortColumn] || '';

                    // Always put "-" values at the end regardless of sort direction
                    if (aVal === '-' && bVal !== '-') return 1;
                    if (bVal === '-' && aVal !== '-') return -1;
                    if (aVal === '-' && bVal === '-') return 0;

                    // Special handling for Mozilla Observatory grades
                    if (this.sortColumn === 'Observatory Grade') {
                        aVal = this.parseGrade(aVal);
                        bVal = this.parseGrade(bVal);
                    }
                    // Special handling for numeric values with commas (Users, Torrents, Peers)
                    else if (['Users', 'Torrents', 'Peers'].includes(this.sortColumn)) {
                        aVal = this.parseNumber(aVal);
                        bVal = this.parseNumber(bVal);
                    }
                    // Handle other numeric values
                    else if (!isNaN(aVal) && !isNaN(bVal) && aVal !== '' && bVal !== '') {
                        aVal = parseFloat(aVal);
                        bVal = parseFloat(bVal);
                    } else {
                        aVal = String(aVal).toLowerCase();
                        bVal = String(bVal).toLowerCase();
                    }

                    if (this.sortDirection === 'asc') {
                        return aVal > bVal ? 1 : -1;
                    } else {
                        return aVal < bVal ? 1 : -1;
                    }
                });
            }

            return filtered;
        },
        showTooltip(event, text) {
            const rect = event.target.getBoundingClientRect();
            this.tooltip.text = text;
            this.tooltip.x = rect.left + rect.width / 2;
            this.tooltip.y = rect.top - 70;
            this.tooltip.show = true;
        },
        hideTooltip() {
            this.tooltip.show = false;
        },
        parseNumber(value) {
            if (!value || value === '-' || value === 'N/A') return Number.NEGATIVE_INFINITY;
            // Remove commas and convert to number
            const cleaned = String(value).replace(/,/g, '');
            const num = parseFloat(cleaned);
            return isNaN(num) ? Number.NEGATIVE_INFINITY : num;
        },
        parseGrade(grade) {
            if (!grade || grade === '-' || grade === 'N/A') return Number.POSITIVE_INFINITY;

            // Remove spaces and convert to uppercase for consistent parsing
            const cleanGrade = String(grade).replace(/\s+/g, '').toUpperCase();

            const gradeMap = {
                'A+': 1,
                'A': 2,
                'A-': 3,
                'B+': 4,
                'B': 5,
                'B-': 6,
                'C+': 7,
                'C': 8,
                'C-': 9,
                'D+': 10,
                'D': 11,
                'D-': 12,
                'F': 13
            };

            return gradeMap[cleanGrade] || Number.POSITIVE_INFINITY;
        },
        sortBy(column) {
            if (this.sortColumn === column) {
                this.sortDirection = this.sortDirection === 'asc' ? 'desc' : 'asc';
            } else {
                this.sortColumn = column;
                this.sortDirection = 'asc';
            }
        },
        
        // Tracker comparison functions
        isInSelectedTrackers(tracker) {
            return this.selectedTrackers.some(t => t.Name === tracker.Name);
        },
        
        toggleTrackerSelection(tracker) {
            if (this.isInSelectedTrackers(tracker)) {
                this.selectedTrackers = this.selectedTrackers.filter(t => t.Name !== tracker.Name);
            } else {
                if (this.selectedTrackers.length < 4) {
                    this.selectedTrackers.push(tracker);
                }
            }
        },
        
        openCompareModal() {
            if (this.selectedTrackers.length >= 2) {
                this.showCompareModal = true;
                document.body.classList.add('modal-open');
            }
        },
        
        closeCompareModal() {
            this.showCompareModal = false;
            document.body.classList.remove('modal-open');
        },
        
        removeFromComparison(tracker) {
            this.selectedTrackers = this.selectedTrackers.filter(t => t.Name !== tracker.Name);
            if (this.selectedTrackers.length < 2) {
                this.closeCompareModal();
            }
        }
    }
}

// AlpineJS component for Jackett table
function jackettTable() {
    return {
        jackettTrackers: [],
        search: '',
        sortColumn: '',
        sortDirection: 'asc',
        get filteredJackettTrackers() {
            let filtered = this.jackettTrackers;

            if (this.search) {
                const s = this.search.toLowerCase();
                filtered = this.jackettTrackers.filter(tracker =>
                    Object.values(tracker).some(v => String(v).toLowerCase().includes(s))
                );
            }

            if (this.sortColumn) {
                filtered.sort((a, b) => {
                    let aVal = a[this.sortColumn] || '';
                    let bVal = b[this.sortColumn] || '';
                    aVal = String(aVal).toLowerCase();
                    bVal = String(bVal).toLowerCase();

                    if (this.sortDirection === 'asc') {
                        return aVal > bVal ? 1 : -1;
                    } else {
                        return aVal < bVal ? 1 : -1;
                    }
                });
            }

            return filtered;
        },
        sortJackettBy(column) {
            if (this.sortColumn === column) {
                this.sortDirection = this.sortDirection === 'asc' ? 'desc' : 'asc';
            } else {
                this.sortColumn = column;
                this.sortDirection = 'asc';
            }
        },
        async init() {
            try {
                const res = await fetch('./trackers2.json');
                const data = await res.json();
                this.jackettTrackers = data.trackers || [];
            } catch (error) {
                console.error('Error loading Jackett trackers:', error);
            }
        }
    }
}