-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
64 lines (57 loc) · 1.69 KB
/
app.js
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
let domains = []
let errors = []
let greyscale = []
// submit button function
document.querySelector('#textareaForm').addEventListener('submit', function (e) {
e.preventDefault()
removeLogos()
domains = e.target.elements.textarea.value.split('\n')
getChecked()
getLogos(domains)
const scrollToLogos = document.querySelector("#logos")
scrollToLogos.scrollIntoView({behavior: 'smooth'})
})
// clear button function
document.querySelector('#clearButton').addEventListener('click', function (e) {
e.preventDefault()
removeLogos()
})
// set greyscale button
document.querySelector('#greyscale').addEventListener('change', function (e) {
e.preventDefault()
removeLogos()
const checkCheckbox = document.getElementById("greyscale").checked
if (checkCheckbox) {
greyscale = '&greyscale=true'
getLogos(domains)
} else {
greyscale = []
getLogos(domains)
}
})
// Get logos
const getLogos = function (domains) {
domains.forEach((domain) => {
const logo = document.createElement('img')
logo.id = 'logo'
logo.src = 'https://logo.clearbit.com/' + domain + '?size=200' + greyscale
logo.onerror = function () {
logo.remove()
errors.push(domain)
}
document.querySelector('#logos').appendChild(logo)
})
}
// Remove logos
const removeLogos = () => {
document.querySelectorAll('#logo').forEach(e => e.parentNode.removeChild(e))
}
// Check greyscale checkbox
getChecked = () => {
const checkCheckbox = document.getElementById("greyscale").checked
if (checkCheckbox) {
greyscale = '&greyscale=true'
} else {
greyscale = []
}
}