-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserscript_globo.js
More file actions
473 lines (406 loc) · 16.1 KB
/
Copy pathuserscript_globo.js
File metadata and controls
473 lines (406 loc) · 16.1 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
// ==UserScript==
// @name Auto Carregar Matérias - Globo.com
// @namespace http://tampermonkey.net/
// @version 2.0
// @description Carrega automaticamente todo o conteúdo das matérias clicando em "Continuar lendo"
// @author Você
// @match *://*.globo.com/*
// @match *://*.extra.globo.com/*
// @match *://*.g1.globo.com/*
// @match *://*.oglobo.globo.com/*
// @grant none
// @run-at document-ready
// ==/UserScript==
(function() {
'use strict';
// Configurações
const config = {
autoStart: true, // Iniciar automaticamente
clickDelay: 800, // Delay após clicar (ms)
checkInterval: 300, // Intervalo para verificar o botão (ms)
maxAttempts: 5, // Máximo de tentativas
showProgress: true, // Mostrar indicador de progresso
scrollAfterClick: true, // Rolar após clicar
removePaywall: true // Tentar remover paywall
};
let attempts = 0;
let isRunning = false;
let progressDiv = null;
let observer = null;
// Seletores específicos do Globo.com baseados no HTML analisado
const selectors = {
// Seletores principais do botão "Continuar lendo"
continueButton: [
'#mc-read-more-btn',
'.mc-read-more-btn',
'button[class*="read-more"]',
'button[id*="read-more"]'
],
// Container do artigo
articleContainer: [
'#mc-article-body',
'.mc-article-body',
'.mrf-article-body'
],
// Wrapper do botão
buttonWrapper: [
'#mc-read-more-wrapper',
'.mc-read-more-wrapper'
],
// Conteúdo protegido/cortado
protectedContent: [
'.wall.protected-content',
'.cropped-block',
'.paywall'
]
};
// Criar indicador de progresso
function createProgressIndicator() {
if (progressDiv) return;
progressDiv = document.createElement('div');
progressDiv.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
background: linear-gradient(135deg, #007bff, #0056b3);
color: white;
padding: 12px 20px;
border-radius: 10px;
z-index: 999999;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
font-size: 14px;
font-weight: 500;
box-shadow: 0 4px 20px rgba(0,123,255,0.3);
max-width: 280px;
line-height: 1.4;
border: 1px solid rgba(255,255,255,0.2);
backdrop-filter: blur(10px);
transition: all 0.3s ease;
`;
document.body.appendChild(progressDiv);
// Adicionar estilo de animação
if (!document.querySelector('#globo-auto-loader-styles')) {
const style = document.createElement('style');
style.id = 'globo-auto-loader-styles';
style.textContent = `
@keyframes pulse {
0% { opacity: 1; transform: scale(1); }
50% { opacity: 0.8; transform: scale(1.05); }
100% { opacity: 1; transform: scale(1); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.globo-spinner {
display: inline-block;
width: 16px;
height: 16px;
border: 2px solid rgba(255,255,255,0.3);
border-radius: 50%;
border-top-color: white;
animation: spin 1s ease-in-out infinite;
}
`;
document.head.appendChild(style);
}
}
// Atualizar indicador de progresso
function updateProgress(message, type = 'loading') {
if (!config.showProgress) return;
if (!progressDiv) createProgressIndicator();
let icon = '';
let bgColor = '#007bff';
switch(type) {
case 'loading':
icon = '<div class="globo-spinner"></div>';
bgColor = '#007bff';
break;
case 'success':
icon = '✅';
bgColor = '#28a745';
break;
case 'warning':
icon = '⚠️';
bgColor = '#ffc107';
break;
case 'error':
icon = '❌';
bgColor = '#dc3545';
break;
}
progressDiv.innerHTML = `
<div style="display: flex; align-items: center; gap: 10px;">
<div>${icon}</div>
<div>${message}</div>
</div>
`;
progressDiv.style.background = `linear-gradient(135deg, ${bgColor}, ${bgColor}dd)`;
}
// Remover indicador de progresso
function removeProgress(delay = 3000) {
if (progressDiv) {
setTimeout(() => {
if (progressDiv && progressDiv.parentNode) {
progressDiv.style.opacity = '0';
progressDiv.style.transform = 'translateY(-20px)';
setTimeout(() => {
if (progressDiv && progressDiv.parentNode) {
progressDiv.parentNode.removeChild(progressDiv);
progressDiv = null;
}
}, 300);
}
}, delay);
}
}
// Encontrar elemento por múltiplos seletores
function findElement(selectorArray) {
for (const selector of selectorArray) {
const element = document.querySelector(selector);
if (element && isElementVisible(element)) {
return element;
}
}
return null;
}
// Verificar se elemento está visível
function isElementVisible(element) {
if (!element) return false;
const rect = element.getBoundingClientRect();
const style = window.getComputedStyle(element);
return (
rect.width > 0 &&
rect.height > 0 &&
style.display !== 'none' &&
style.visibility !== 'hidden' &&
style.opacity !== '0' &&
!element.hasAttribute('disabled')
);
}
// Rolar suavemente até o elemento
function scrollToElement(element, offset = -100) {
if (!element) return;
const elementTop = element.getBoundingClientRect().top + window.pageYOffset;
const offsetTop = elementTop + offset;
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
// Remover paywall/conteúdo protegido
function removePaywallElements() {
if (!config.removePaywall) return;
// Remover elementos de paywall
const paywallElements = document.querySelectorAll('.paywall, .wall, .subscription-required');
paywallElements.forEach(el => {
el.style.display = 'none';
});
// Remover classe 'cropped' do artigo
const article = findElement(selectors.articleContainer);
if (article) {
article.classList.remove('cropped');
}
// Mostrar conteúdo protegido
const protectedContent = document.querySelectorAll('.protected-content, .cropped-block');
protectedContent.forEach(el => {
el.style.display = 'block';
el.style.visibility = 'visible';
el.style.opacity = '1';
});
}
// Função principal para carregar conteúdo
function loadMoreContent() {
if (isRunning) return;
isRunning = true;
attempts++;
updateProgress(`Procurando mais conteúdo... (${attempts}/${config.maxAttempts})`, 'loading');
// Procurar pelo botão "Continuar lendo"
const continueButton = findElement(selectors.continueButton);
if (continueButton) {
updateProgress(`Carregando conteúdo... (${attempts}/${config.maxAttempts})`, 'loading');
// Rolar até o botão se configurado
if (config.scrollAfterClick) {
scrollToElement(continueButton, -50);
}
// Simular clique no botão
setTimeout(() => {
try {
// Tentar vários métodos de clique
continueButton.click();
// Backup: dispatch event
const clickEvent = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
continueButton.dispatchEvent(clickEvent);
// Remover elementos de paywall
setTimeout(() => {
removePaywallElements();
}, 100);
console.log('🔄 Globo Auto-Loader: Botão clicado, conteúdo carregado');
} catch (error) {
console.error('Erro ao clicar no botão:', error);
}
// Aguardar e tentar novamente
setTimeout(() => {
isRunning = false;
if (attempts < config.maxAttempts) {
loadMoreContent();
} else {
updateProgress('Todo o conteúdo foi carregado!', 'success');
removeProgress();
console.log('✅ Globo Auto-Loader: Processo finalizado');
}
}, config.clickDelay);
}, 200);
} else {
// Não encontrou botão
if (attempts < config.maxAttempts) {
setTimeout(() => {
isRunning = false;
loadMoreContent();
}, config.checkInterval);
} else {
updateProgress('Conteúdo totalmente carregado!', 'success');
removeProgress();
isRunning = false;
console.log('✅ Globo Auto-Loader: Nenhum botão encontrado, conteúdo completo');
}
}
}
// Resetar e tentar novamente
function resetAndRetry() {
attempts = 0;
isRunning = false;
if (observer) {
observer.disconnect();
}
startAutoLoader();
}
// Criar botão de controle manual
function createControlButton() {
const controlBtn = document.createElement('button');
controlBtn.innerHTML = '📖 Auto-Load';
controlBtn.title = 'Clique para recarregar automaticamente o conteúdo da matéria';
controlBtn.style.cssText = `
position: fixed;
bottom: 20px;
right: 20px;
background: linear-gradient(135deg, #007bff, #0056b3);
color: white;
border: none;
padding: 12px 16px;
border-radius: 8px;
cursor: pointer;
z-index: 999998;
font-size: 14px;
font-weight: 600;
box-shadow: 0 4px 15px rgba(0,123,255,0.4);
transition: all 0.3s ease;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
border: 1px solid rgba(255,255,255,0.2);
backdrop-filter: blur(10px);
`;
controlBtn.addEventListener('mouseenter', () => {
controlBtn.style.transform = 'scale(1.05) translateY(-2px)';
controlBtn.style.boxShadow = '0 6px 20px rgba(0,123,255,0.5)';
});
controlBtn.addEventListener('mouseleave', () => {
controlBtn.style.transform = 'scale(1) translateY(0)';
controlBtn.style.boxShadow = '0 4px 15px rgba(0,123,255,0.4)';
});
controlBtn.addEventListener('click', () => {
controlBtn.style.transform = 'scale(0.95)';
setTimeout(() => {
controlBtn.style.transform = 'scale(1)';
resetAndRetry();
}, 150);
});
document.body.appendChild(controlBtn);
}
// Observar mudanças na página
function createPageObserver() {
observer = new MutationObserver((mutations) => {
let shouldCheck = false;
mutations.forEach((mutation) => {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
// Verificar se foi adicionado novo conteúdo
for (const node of mutation.addedNodes) {
if (node.nodeType === Node.ELEMENT_NODE) {
if (node.matches && (
node.matches('.cropped-block') ||
node.matches('.mc-read-more-wrapper') ||
node.matches('[class*="content"]')
)) {
shouldCheck = true;
break;
}
}
}
}
});
if (shouldCheck && !isRunning) {
setTimeout(() => {
if (!isRunning) {
loadMoreContent();
}
}, 500);
}
});
// Observar mudanças no corpo da página
observer.observe(document.body, {
childList: true,
subtree: true
});
}
// Verificar se é uma página de artigo
function isArticlePage() {
return (
findElement(selectors.articleContainer) !== null ||
document.querySelector('article') !== null ||
window.location.pathname.includes('/noticia/') ||
window.location.pathname.includes('/materia/')
);
}
// Iniciar o auto-loader
function startAutoLoader() {
if (!isArticlePage()) {
console.log('🔍 Globo Auto-Loader: Não é uma página de artigo');
return;
}
console.log('🚀 Globo Auto-Loader: Script iniciado');
createPageObserver();
if (config.autoStart) {
// Aguardar um pouco para a página carregar completamente
setTimeout(() => {
loadMoreContent();
}, 1000);
}
}
// Inicialização principal
function init() {
// Aguardar DOM estar pronto
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
setTimeout(startAutoLoader, 500);
});
} else {
setTimeout(startAutoLoader, 500);
}
// Adicionar botão de controle
setTimeout(createControlButton, 1500);
// Adicionar atalhos de teclado
document.addEventListener('keydown', (e) => {
// Ctrl + Shift + L para recarregar
if (e.ctrlKey && e.shiftKey && e.key === 'L') {
e.preventDefault();
resetAndRetry();
}
});
console.log('📖 Globo Auto-Loader v2.0 carregado! Use Ctrl+Shift+L para recarregar manualmente.');
}
// Iniciar script
init();
})();