-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
490 lines (407 loc) · 16 KB
/
index.html
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
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Noticias JORNAL OGLOBO - 24h</title>
<link href="./css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="loader.css">
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://unpkg.com/tippy.js@6/animations/scale-subtle.css" />
<script src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.js"
integrity="sha512-/McISOEKVzVvgu12/1Hk8dSrbKBShnKn79/R50ysl5qWR1zgj347kOT8LJJvInxHDSPmiBG9vg5AhMx6rcELJg=="
crossorigin="anonymous"></script>
<script src="highlight.js"></script>
</head>
<body>
<div class="wrapper">
<ul class="nav nav-tabs" id="canais" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link active" id="oglobo-tab" data-bs-toggle="tab" data-bs-target="#oglobo" role="tab" href="#"
aria-controls="oglobo" aria-selected="true">OGlobo</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="g1-tab" data-bs-toggle="tab" data-bs-target="#g1" href="#" role="tab" aria-controls="g1"
aria-selected="false">G1(Regiões)</a>
</li>
</ul>
<div class="tab-content" id="canaisContent">
<div class="tab-pane fade show active" role="tabpanel" aria-labelledby="oglobo-tab" id="oglobo">
<div class="search-container">
<div class="newsCounter">
<h2 class="noticias"></h2>
<div class="categorias"></div>
<h2 class="excluidas"></h2>
<div class="categorias"></div>
</div>
<div>
<input id="searchbar" type="search" placeholder="Busca">
<button class="search-btn"><i class="fa fa-search"></i></button>
</div>
</div>
<div id="messager" style="display: none;">
<h1>Oops! 😢</h1><br />
<h2 style="margin: unset;">Essa busca não retornou nenhum resultado.</h2>
</div>
<div id="news-container"></div>
</div>
<div class="tab-pane fade" role="tabpanel" aria-labelledby="g1-tab" id="g1">
<div class="container-fluid">
<div class="row">
<div class="col">
</div>
</div>
<div class="row">
<div class="col">
<div class="mb-3 my-3 d-flex align-items-center">
<strong id="loadingMessage">Loading News...</strong>
</div>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="25" aria-valuemin="0"
aria-valuemax="100">0%
</div>
</div>
</div>
</div>
<div id="form-holder" style="display:none" class="row">
<div class="col d-flex flex-column justify-content-center p-4">
<form>
<h5>Selecione as regiões para download dos dados</h5>
<fieldset style="display:flex;flex-flow:column;justify-content:center">
<label>
Sul
<input checked type="checkbox">
</label>
<label>
Sudeste
<input checked type="checkbox">
</label>
<label>
Centro-oeste
<input checked type="checkbox">
</label>
<label>
Norte
<input checked type="checkbox">
</label>
<label>
Nordeste
<input checked type="checkbox">
</label>
</fieldset>
<button type="submit" class="my-3 p-1 px-3" style="margin-right:auto">Baixar Planilhas</button>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="icons">
<button class="to-top"><i class="fa fa-arrow-up"></i></button>
<button hidden class="refresh"><i class="fa fa-refresh"></i></button>
<div class="image-hider"><img src="./icon.png"></div>
</div>
<div class="lds-roller">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<script src="toCSV.js"></script>
<script src="https://unpkg.com/@popperjs/core@2"></script>
<script src="https://unpkg.com/tippy.js@6"></script>
<script>
(async () => {
const scraperData = await fetch('https://oglobo-scraper.s3-sa-east-1.amazonaws.com/latest.json').then(x => {
document.querySelector('.lds-roller').toggleAttribute('hidden')
return x.json()
})
console.log(
`\n✅ Notícias Atuais: ${scraperData.newsCount}\n\n❌ Noticias Excluidas: ${scraperData.excludedCount}\n\n`
)
window.data = scraperData.data
window.excluded = scraperData.excluded
const noticiasCounter = $('.search-container h2.noticias')
noticiasCounter.text(`✅ Notícias Recentes: ${scraperData.newsCount}`)
const excludedCounter = $('.search-container h2.excluidas')
excludedCounter.text(`❌ Noticias Excluidas: ${scraperData.excludedCount}`);
setupClick([noticiasCounter, excludedCounter])
function setupClick(titles) {
titles.forEach(title => {
title.on('click', () => {
title.next().toggleClass('expanded')
})
})
}
makeCards(scraperData.data)
window.categorizadasExcluidas = Object.entries(scraperData.categorized.exclusions)
window.categorizadas = Object.entries(scraperData.categorized.news)
categorizadas.sort((a, b) => a[1].length < b[1].length ? 1 : -1)
categorizadasExcluidas.sort((a, b) => a[1].length < b[1].length ? 1 : -1)
categorizadas.forEach(([cat, newsArray]) => {
console.log(cat + ' ' + newsArray.length)
let button = document.createElement('template')
let content = `<button data-news="${cat}">${cat} - ${newsArray.length}</button>`
button.innerHTML = content
document.querySelector('.categorias:first-of-type').appendChild(button.content.firstChild)
})
categorizadasExcluidas.forEach(([cat, newsArray]) => {
console.log(cat + ' ' + newsArray.length)
let button = document.createElement('template')
let content = `<button data-news="${cat}" class="excluded">${cat} - ${newsArray.length}</button>`
button.innerHTML = content
document.querySelector('.categorias:last-of-type').appendChild(button.content.firstChild)
})
if (sessionStorage.latestNews && data[0].titulo != sessionStorage.latestNews) {
window.scrollTo({
top: 0,
behavior: 'smooth'
})
} else if (sessionStorage.scrollTop != "undefined") {
window.scrollTo({
top: sessionStorage.scrollTop
});
}
})()
</script>
<script>
let g1 = document.querySelector('#g1-tab')
g1.addEventListener('shown.bs.tab', async () => {
let data = await fetchG1()
window.entries = Object.entries(data)
document.querySelector('#loadingMessage').innerText = 'Notícias carregadas.'
$('#form-holder').show()
})
let form = document.querySelector('form')
form.addEventListener('submit', (e) => {
e.preventDefault()
let results = [...e.target.querySelectorAll('input')].map(x => {
let key = x.parentNode.innerText.toLowerCase().trim();
return {
[key]: x.checked
}
}).filter(x => Object.values(x)[0] == true).map(x => Object.keys(x)[0])
console.log(results)
let data = window.entries.filter(x => results.includes(x[0]))
let dateString = new Date()
dateString = dateString.toLocaleDateString().replaceAll('/', '-')
data.forEach((reg) => getCSV(reg[1], `${dateString}_${reg[0]}`));
})
</script>
<script>
$('.image-hider').click(toggleImages)
$('.to-top').click(scrollUp)
$('.refresh').click(() => {
$('button').removeClass('active');
window.currentCategory = undefined
clearCards()
makeCards(window.data)
document.querySelector('button.refresh').setAttribute('hidden', true);
})
function toggleImages() {
let images = document.querySelectorAll('.main-section div:first-child')
images.forEach((div) => {
div.toggleAttribute('hidden')
div.style.flex = '0 0 0 100%'
})
let otherDiv = document.querySelectorAll('.main-section div:last-child')
otherDiv.forEach((div) => div.classList.toggle('full-flex'))
}
function scrollUp() {
window.scrollTo({
top: 0,
behavior: "smooth"
})
}
</script>
<script>
$.expr[":"].CIcontains = $.expr.createPseudo(function (arg) {
if (arg.split(',').filter(Boolean).length > 1) {
return function (elem) {
let text = $(elem).text().toUpperCase()
return arg.split(',').some(x => text.includes(x.toUpperCase()));
};
} else {
return function (elem) {
return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
}
});
$('.search-btn').click(search)
$('input[type=search]').on('search', search);
function search() {
let searchbar = $('input[type=search]')
searchbar.blur()
// get the text from the box
let curr_text = searchbar.val();
// pass it to the function
if (curr_text == '') {
$(".card").show();
$(".card").removeHighlight();
$('#messager').hide()
return null
}
filterResults(curr_text);
}
function filterResults(curr_text) {
// hide all results
$('#messager').hide()
$(".card").hide();
$(".card").removeHighlight();
let array = curr_text.split(',')
// ... except those which are selected
jQuery.each(array, function (idx, val) {
// console.log(val)
val = val.trim()
if (val == 'undefined' || val == '' || val.includes(' ')) {
alert(
'Preencha corretamente a busca, seguindo o padrão:\npalavra1,palavra2,palavra3(etc)\n(sem espaços em branco, ou vírgulas solitárias)'
)
}
$(`.card:CIcontains(${val})`).show();
$(`.card:CIcontains(${val})`).highlight(val);
})
!$('.card').is(':visible') ? $('#messager').fadeIn(200) : null
// ... except those which are selected
// $(".card:CIcontains('" + curr_text + "')").show();
// $(".card:CIcontains('" + curr_text + "')").highlight(curr_text);
}
</script>
<script>
$('body').on('click', '.card', copyURL)
var tippyInstance
window.addEventListener('DOMContentLoaded', () => {
tippyInstance = setupTippyInstance()
})
function setupTippyInstance() {
console.log('tippy setup')
tippy.setDefaultProps({
animation: 'scale-subtle',
duration: 150,
content: 'Link Copiado!',
hideOnClick: false,
touch: false,
onShow(instance) {
setTimeout(() => {
instance.hide();
instance.disable();
}, 800);
}
});
var init = tippy(document.body, {
trigger: 'click',
showOnCreate: true,
followCursor: 'true',
})
init.hide()
init.disable()
return init
}
function copyURL() {
const link = $(this).find('a').attr('href')
// const title = $(this).find('h2').text()
// const subtitle = $(this).find('h4').text()
// const content = `<a href="${link}">${link}</a>`
// copyToClip(content)
// function copyToClip(str) {
// function listener(e) {
// e.clipboardData.setData("text/html", str);
// e.clipboardData.setData("text/plain", str);
// e.preventDefault();
// }
// document.addEventListener("copy", listener);
// document.execCommand("copy");
// document.removeEventListener("copy", listener);
// };
const textArea = document.createElement("textarea");
textArea.value = link;
document.body.appendChild(textArea);
textArea.select();
document.execCommand("Copy");
textArea.remove();
if (!tippyInstance.state.isEnabled) {
tippyInstance.enable()
tippyInstance.show()
}
}
function makeCards(data) {
data.forEach((x, i) => {
let content = `<div class="title">
<h1>${i + 1}</h1>
<p>Publicado em: ${new Date(x.publicadoEm).toLocaleString()}</p>
</div>
<div class="main-section">
<div>
<img src="${x.imagens.length > 0 ? x.imagens[0].url : 'noimage-found.png'}">
</div>
<div>
<b>Categoria: ${x.secao.nome}</b><br>
<h2><a class="link" target="_blank" href="${x.url}">${x.titulo}</a></h2>
<h4>${x.subTitulo}</h4>
</div>
</div>
`
let container = document.createElement('div')
container.classList.add('card')
container.dataset.category = x.secao.nome
container.innerHTML = content
document.getElementById('news-container').appendChild(container)
})
}
</script>
<script>
$(window).on('unload', function () {
sessionStorage.scrollTop = $(this).scrollTop();
sessionStorage.latestNews = this.data[0].titulo
});
$(document).ready(function () {
if (sessionStorage.scrollTop != "undefined") {
$(window).scrollTop(sessionStorage.scrollTop, {
behaviour: 'smooth'
});
}
document.querySelector('.newsCounter').addEventListener('click', (e) => {
const isButton = event.target.nodeName === 'BUTTON';
if (!isButton) {
return;
}
const button = event.target
loadCategoryNews(button, button.className)
})
});
function loadCategoryNews(button, status = undefined) {
const category = button.dataset.news
if (window.currentCategory == category) {
button.classList.remove('active')
window.currentCategory = undefined
document.querySelector('button.refresh').toggleAttribute('hidden')
clearCards()
makeCards(window.data)
return;
}
// document.querySelectorAll('button').forEach( button => button.classList.remove('active'))
$('button').removeClass('active')
button.classList.add('active')
clearCards()
const data = (status == 'excluded' ? window.categorizadasExcluidas.filter(x => x.includes(category))[0][1] :
window.categorizadas.filter(x => x.includes(category))[0][1])
makeCards(data)
window.currentCategory = category
document.querySelector('button.refresh').removeAttribute('hidden')
}
function clearCards() {
document.querySelectorAll('.card').forEach(card => card.remove())
}
</script>
<script src="./js/bootstrap.bundle.min.js"></script>
<script src="fetchg1.js"></script>
</body>
</html>