Skip to content

Instantly share code, notes, and snippets.

@DeflatedPickle
Last active February 19, 2018 10:09
Show Gist options
  • Save DeflatedPickle/63e7c1abcecf2470812543ab0d117660 to your computer and use it in GitHub Desktop.
Save DeflatedPickle/63e7c1abcecf2470812543ab0d117660 to your computer and use it in GitHub Desktop.
A NodeJS script that switches CSS depending on the current OS (for Electron).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
<script rel="script" type="text/javascript" src="switcher.js"></script>
</head>
<body>
<h1>Title</h1>
</body>
</html>
body {
background: darkgray;
}
body {
background: white;
}
const os = require("os");
function loadCSS(path) {
if (!document.getElementById) {
document.write('<link rel="stylesheet" type="text/css" href=path>');
}
}
switch (os.platform()) {
case "win32":
console.log("Windows");
loadCSS("win32.css");
break;
case "darwin":
console.log("OSX");
loadCSS("osx.css");
break;
case "linux":
console.log("Linux");
loadCSS("linux.css");
break;
default:
console.log("Other: %s", os.platform());
}
body {
background: lightgray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment