-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-magic.js
44 lines (40 loc) · 1.23 KB
/
make-magic.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
// Create random set of color themes
const themes = [
'#f14357',
'#53a2e3',
'#f4ad49',
'#6757e2',
'#69de92',
'#e7654d',
'#f04576',
'#52c7eb',
];
const index = Math.floor(Math.random() * themes.length);
const index_2 = index === 0 ? index + 1 : index - 1;
// Change CSS Variables
document.body.style.setProperty('--main-color', themes[index]);
// Styled Console Log
console.log(
"hello",
`color: #fff; font-size: 30px; background-image: linear-gradient(to right, ${themes[index]}, ${themes[index_2]});`
);
console.log(
"%cYou're curious about my site, right? Feel free to explore it! I hope you find something useful👏",
`color: #fff; font-size: 18px; background-color: ${themes[index]}`
);
// Counter line of code (LOC)
function counterLOC(el) {
const counterEl = document.getElementsByClassName(el);
for (let i = 0; i < counterEl.length; i++) {
counterEl[i].setAttribute('data-line', i + 1);
}
}
counterLOC('js-line-html');
counterLOC('js-line-css');
// Years old
function yearsOld(birthday) {
var ageDifMs = Date.now() - birthday.getTime();
var ageDate = new Date(ageDifMs);
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
document.getElementById('years-old').textContent = yearsOld(new Date(1992, 9, 3));