os.js
· 504 B · JavaScript
Raw
var htmlElement = document.documentElement;
if (navigator.platform.match(/(Mac)/i)) {
htmlElement.className = 'Mac'
}
if (navigator.platform.match(/(Linux)/i)) {
htmlElement.className = 'Linux'
} else {
htmlElement.className = 'Windows'
}
document.addEventListener('click', function(event) {
var target = event.target;
if (target.getAttribute && target.getAttribute('data-action') === 'switch-os') {
event.preventDefault();
htmlElement.className = target.getAttribute('data-os')
}
})
1 | var htmlElement = document.documentElement; |
2 | if (navigator.platform.match(/(Mac)/i)) { |
3 | htmlElement.className = 'Mac' |
4 | } |
5 | if (navigator.platform.match(/(Linux)/i)) { |
6 | htmlElement.className = 'Linux' |
7 | } else { |
8 | htmlElement.className = 'Windows' |
9 | } |
10 | document.addEventListener('click', function(event) { |
11 | var target = event.target; |
12 | if (target.getAttribute && target.getAttribute('data-action') === 'switch-os') { |
13 | event.preventDefault(); |
14 | htmlElement.className = target.getAttribute('data-os') |
15 | } |
16 | }) |
17 |