-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
119 lines (110 loc) · 2.19 KB
/
script.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
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
const COLORS = [
'rebeccapurple',
'magenta',
'lime',
'violet',
'red',
'cyan',
'yellow',
'springgreen',
'aqua',
'orange',
'crimson',
'coral',
'deeppink',
'dodgerblue',
'gold'
]
const ICONS = [
'!',
'"',
'#',
'$',
'&',
')',
'*',
'/',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
':',
'?',
'@',
'B',
'C',
'A',
'D',
'E',
'K',
'L',
'O',
'V',
'W',
'X',
'Y',
'Z',
'\\',
']',
'^',
'_',
'`',
'b',
'e',
'g',
'i',
'm',
'n',
'o',
'u',
'v',
'z',
'y',
'{',
'|',
'~',
'Ä',
'I',
'U'
]
const changeColorButton = document.getElementById('change-color')
const changeIconButton = document.getElementById('change-icon')
const changePatternButton = document.getElementById('change-pattern')
const icon = document.getElementById('icon')
const nametagHeader = document.getElementById('nametag__header')
const nametagFooter = document.getElementById('nametag__footer')
changeColorButton.addEventListener('click', changeColor)
changeIconButton.addEventListener('click', changeIcon)
changePatternButton.addEventListener('click', changePattern)
function changeIcon () {
const maxIdx = ICONS.length - 1
const idx = Math.floor(Math.random() * Math.floor(maxIdx))
const newIcon = ICONS[idx]
icon.innerText = newIcon
}
function changeColor () {
const maxIdx = COLORS.length - 1
const idx = Math.floor(Math.random() * Math.floor(maxIdx))
const newColor = COLORS[idx]
nametagHeader.style.background = newColor
nametagFooter.style.background = newColor
}
function changePattern () {
const newPattern = Math.floor(Math.random() * 36) + 1
document.body.style.background = 'url(/images/' + newPattern + '.gif)'
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('url').innerText = window.location
document.getElementById('library-url').href = `beaker://library/${window.location}`
// is this a Dat-supported website? If so, use a dat:// URL for the beakerbrowser.com link
const beakerLink = document.getElementById('beaker-url')
if (window.DatArchive) {
beakerLink.href = 'dat://beakerbrowser.com'
} else {
beakerLink.href = 'https://beakerbrowser.com'
}
})