File size: 7,504 Bytes
596aae4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
(() => {
    if (window.__xExtractorActive) return;
    window.__xExtractorActive = true;

    const collectedVideos = new Map(); // url -> { url, title, thumb }
    
    const container = document.createElement('div');
    container.id = 'x-extractor-ui';
    container.style.cssText = `
        position: fixed;
        bottom: 20px;
        right: 20px;
        background: #000;
        color: #fff;
        padding: 15px;
        border-radius: 10px;
        border: 1px solid #333;
        z-index: 999999;
        font-family: sans-serif;
        box-shadow: 0 4px 12px rgba(255,255,255,0.2);
        display: flex;
        flex-direction: column;
        gap: 10px;
        min-width: 250px;
    `;
    
    const titleDisplay = document.createElement('div');
    titleDisplay.innerHTML = '<b>Extractor de Videos X</b>';
    titleDisplay.style.textAlign = 'center';
    titleDisplay.style.fontSize = '15px';
    
    const countDisplay = document.createElement('div');
    countDisplay.textContent = '0 videos encontrados';
    countDisplay.style.fontWeight = 'bold';
    countDisplay.style.textAlign = 'center';
    countDisplay.style.fontSize = '18px';
    countDisplay.style.color = '#1da1f2';
    
    const statusDisplay = document.createElement('div');
    statusDisplay.textContent = 'Listo para escanear.';
    statusDisplay.style.textAlign = 'center';
    statusDisplay.style.fontSize = '12px';
    statusDisplay.style.color = '#888';
    
    const autoScanBtn = document.createElement('button');
    autoScanBtn.textContent = 'Iniciar Búsqueda Automática (Scroll)';
    autoScanBtn.style.cssText = `
        background: #1da1f2;
        color: white;
        border: none;
        padding: 10px;
        border-radius: 6px;
        cursor: pointer;
        font-weight: bold;
    `;
    
    const copyBtn = document.createElement('button');
    copyBtn.textContent = 'Copiar Enlaces';
    copyBtn.style.cssText = `
        background: #8b5cf6;
        color: white;
        border: none;
        padding: 10px;
        border-radius: 6px;
        cursor: pointer;
        font-weight: bold;
    `;
    
    const closeBtn = document.createElement('button');
    closeBtn.id = 'x-close-btn';
    closeBtn.textContent = 'Cerrar Extractor';
    closeBtn.style.cssText = `
        background: #27272a;
        color: white;
        border: 1px solid #3f3f46;
        padding: 8px;
        border-radius: 6px;
        cursor: pointer;
        font-size: 13px;
    `;

    container.appendChild(titleDisplay);
    container.appendChild(countDisplay);
    container.appendChild(statusDisplay);
    container.appendChild(autoScanBtn);
    container.appendChild(copyBtn);
    container.appendChild(closeBtn);
    document.body.appendChild(container);
    
    let scanInterval = null;
    let isScanning = false;
    let maxRetries = 10; // Aumentar reintentos antes de rendirse
    
    autoScanBtn.onclick = () => {
        if (isScanning) {
            clearInterval(scanInterval);
            isScanning = false;
            autoScanBtn.textContent = 'Continuar Búsqueda';
            autoScanBtn.style.background = '#1da1f2';
            statusDisplay.textContent = 'Búsqueda pausada.';
            return;
        }
        
        isScanning = true;
        autoScanBtn.textContent = 'Detener Búsqueda';
        autoScanBtn.style.background = '#e0245e';
        statusDisplay.textContent = 'Haciendo scroll y buscando videos...';
        
        let lastHeight = 0;
        let retries = 0;
        
        scanInterval = setInterval(() => {
            // Scroll progresivo en lugar de ir directo al fondo para no atascar React
            window.scrollBy(0, 1000);
            
            // Buscar enlaces a videos o tweets que parezcan videos
            const links = document.querySelectorAll('a[href*="/status/"]');
            
            links.forEach(a => {
                let cleanUrl = a.href.split('?')[0]; 
                
                // Es un video si tiene /video/ en la URL, o si tiene un div indicando duración (ej. "4:13")
                let isVideo = cleanUrl.includes('/video/');
                if (!isVideo && a.innerText && /^\d+:\d+$/.test(a.innerText.trim())) {
                    isVideo = true;
                }
                // Si el link de la cuadricula no termina en /video/1, se lo agregamos si estamos seguros que es video
                if (isVideo && !cleanUrl.includes('/video/')) {
                    if (!cleanUrl.endsWith('/')) cleanUrl += '/';
                    cleanUrl += 'video/1';
                }

                if (isVideo && !collectedVideos.has(cleanUrl)) {
                    collectedVideos.set(cleanUrl, true);
                    
                    // Feedback visual (borde verde y opacidad)
                    a.style.outline = '4px solid #10b981';
                    a.style.opacity = '0.8';
                    a.style.position = 'relative';
                    
                    // Agregar marca de verificación visual si no la tiene
                    if (!a.querySelector('.x-check-mark')) {
                        const check = document.createElement('div');
                        check.className = 'x-check-mark';
                        check.innerHTML = '✓';
                        check.style.cssText = 'position:absolute; top:10px; right:10px; background:#10b981; color:white; border-radius:50%; width:30px; height:30px; display:flex; align-items:center; justify-content:center; font-weight:bold; font-size:16px; z-index:20; box-shadow:0 2px 5px rgba(0,0,0,0.5);';
                        a.appendChild(check);
                    }
                }
            });
            
            countDisplay.textContent = collectedVideos.size + ' videos encontrados';
            
            let currentScroll = window.scrollY || document.documentElement.scrollTop;
            if (currentScroll === lastHeight) {
                retries++;
                // Darle un pequeño empujón hacia arriba y abajo por si se atascó
                if (retries === 3) window.scrollBy(0, -500);
                if (retries === 4) window.scrollBy(0, 800);
                
                if (retries >= maxRetries) {
                    clearInterval(scanInterval);
                    isScanning = false;
                    autoScanBtn.textContent = 'Búsqueda finalizada';
                    autoScanBtn.style.background = '#1da1f2';
                    autoScanBtn.disabled = true;
                    statusDisplay.textContent = 'Llegaste al final de la página.';
                }
            } else {
                retries = 0;
            }
            lastHeight = currentScroll;
        }, 1000); 
    };
    
    copyBtn.onclick = () => {
        if (collectedVideos.size === 0) return;
        const urls = Array.from(collectedVideos.keys());
        const text = urls.join('\n');
        
        navigator.clipboard.writeText(text).then(() => {
            const ogText = copyBtn.textContent;
            copyBtn.textContent = '¡Copiados!';
            copyBtn.style.background = '#10b981';
            setTimeout(() => {
                copyBtn.textContent = ogText;
                copyBtn.style.background = '#8b5cf6';
            }, 2000);
        });
    };
    
    closeBtn.onclick = () => {
        if (scanInterval) clearInterval(scanInterval);
        isScanning = false;
        container.remove();
        window.__xExtractorActive = false;
    };
})();