-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck.js
More file actions
39 lines (34 loc) · 846 Bytes
/
check.js
File metadata and controls
39 lines (34 loc) · 846 Bytes
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
'use strict';
const url = 'https://nemly-json.now.sh';
const colors = [
'#ffc300',
'#ffba04',
'#ffb108',
'#ffa80d',
'#ff9f11',
'#ff9615',
'#ff8d1a',
'#ff841e',
'#ff7b22',
'#ff7226',
'#ff692b',
'#ff602f',
'#ff5733',
];
const template = (id, word, colorhex) => (
`<div style="display: inline;" id="${id}">
<mark style="background-color: ${colorhex}; color: black;">
${word}
</mark>
</div>`
);
fetch(url).then((response) => {
const data = response.json()
data.then(res => {
res.map(({ word, id, relevance }) => {
const selected = (relevance >= 0 && relevance <= 1) ? (relevance * 10) : 0;
const colorhex = colors[selected];
document.body.innerHTML = document.body.innerHTML.split(word).join(template(id, word, colorhex));
});
});
}).catch(err => console.error(err));