Skip to content

Commit

Permalink
Improve OS detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
blast007 committed Dec 10, 2018
1 parent ba19f98 commit f23fa2c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
5 changes: 3 additions & 2 deletions LICENSES.md
Expand Up @@ -13,15 +13,15 @@ Documentation and video/image assets created for the website should be licensed
- assets/images/media/
- assets/images/screenshots/

### GNU LGPL 2.0
### GNU LGPL 2.1
- assets/images/home/blue_laser.png
- assets/images/home/blue_super_bullet.png
- assets/images/home/guided_missile.png
- assets/bzflag.svg
- favicon.ico

### MIT License
- assets/js/main.js
- assets/js/main.js (except for the getOS function)
- assets/js/screenshots.js
- _data
- _datasets
Expand Down Expand Up @@ -74,6 +74,7 @@ Documentation and video/image assets created for the website should be licensed
- Operating system logos are copyright and/or trademark their respective owners.
- [highlight.js (just the monokai.css file for styling)](https://highlightjs.org/) - BSD 3-Clause "New" or "Revised" License
- _sass/vendor/highlightjs/
- assets/js/main.js - [(the getOS function only)](https://stackoverflow.com/a/38241481) by [Vladyslav Turak](https://stackoverflow.com/users/4815056/vladyslav-turak) - CC BY-SA 3.0 Unported

---

Expand Down
3 changes: 2 additions & 1 deletion _pages/credits.html.twig
Expand Up @@ -14,7 +14,7 @@ permalink: /credits/

## Graphics

- The BZFlag logo (the red tank icon) and the favicon (the blue tank icon) is copyright Tim Riker and licensed under the GNU LGPL 2.0.
- The BZFlag logo, the weapon images, and the favicon (the blue tank icon) are copyright Tim Riker and licensed under the GNU LGPL 2.1.
- [Megaphone by Creative Stall](https://thenounproject.com/icon/147531/) from the Noun Project - CC-BY 3.0 US License
- [debug by Lemon Liu](https://thenounproject.com/icon/83827/) from the Noun Project - CC-BY 3.0 US License
- [Book by Deemak Daksina](https://thenounproject.com/icon/1230262/) from the Noun Project - CC-BY 3.0 US License
Expand All @@ -28,6 +28,7 @@ permalink: /credits/

- [PhotoSwipe](http://photoswipe.com/) by Dmitry Semenov - MIT License (with one exception: "Do not create a public WordPress plugin based on it")
- [Plyr](https://github.com/selz/plyr) - MIT License
- [getOS function](https://stackoverflow.com/a/38241481) by [Vladyslav Turak](https://stackoverflow.com/users/4815056/vladyslav-turak) - CC BY-SA 3.0 Unported

## CSS/SCSS

Expand Down
39 changes: 22 additions & 17 deletions assets/js/main.js
Expand Up @@ -5,24 +5,29 @@
*
* @returns {string}
*/
function guessOS() {
if (navigator.appVersion.indexOf('Win') !== -1) {
return 'Windows';
function getOS() {
// Source: https://stackoverflow.com/a/38241481
// Author: Vladyslav Turak (https://stackoverflow.com/users/4815056/vladyslav-turak)
// License: http://creativecommons.org/licenses/by-sa/3.0/
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
macosPlatforms = ['Macintosh', 'MacIntel'],
windowsPlatforms = ['Win32', 'Win64', 'Windows'],
iosPlatforms = ['iPhone', 'iPad', 'iPod'];

if (macosPlatforms.indexOf(platform) !== -1) {
return 'macos';
} else if (iosPlatforms.indexOf(platform) !== -1) {
return 'ios';
} else if (windowsPlatforms.indexOf(platform) !== -1) {
return 'windows';
} else if (/Android/.test(userAgent)) {
return 'android';
} else if (/Linux/.test(platform)) {
return 'linux';
}

if (navigator.appVersion.indexOf('Mac') !== -1) {
return 'macOS';
}

if (navigator.appVersion.indexOf('X11') !== -1) {
return 'UNIX';
}

if (navigator.appVersion.indexOf('Linux') !== -1) {
return 'Linux';
}

return 'Unknown';
return 'unknown';
}

/**
Expand All @@ -40,7 +45,7 @@ function replaceDomClass(find, replace) {
// - Detect the OS from CSS
// - Detect JS usage from CSS

replaceDomClass('os-unknown', 'os-' + guessOS().toLowerCase());
replaceDomClass('os-unknown', 'os-' + getOS());
replaceDomClass('no-js', 'js');

// Mobile menu support
Expand Down

0 comments on commit f23fa2c

Please sign in to comment.