Skip to content

Instantly share code, notes, and snippets.

@holgersindbaek
Created September 20, 2017 13:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holgersindbaek/68f6db82f507967a51ca75c527faeff6 to your computer and use it in GitHub Desktop.
Save holgersindbaek/68f6db82f507967a51ca75c527faeff6 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="./styles.css">
</head>
<body>
<div id="topbar">
<p>Solitaire</p>
</div>
<div id="offline_error">
<p>Solitaire is not available offline.</p>
</div>
<script>
// Function to find parameter
const getParams = query => {
if (!query) {
return { };
}
return (/^[?#]/.test(query) ? query.slice(1) : query)
.split('&')
.reduce((params, param) => {
let [key, value] = param.split('=');
params[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : '';
return params;
}, { });
};
// Add webview
const webview = document.createElement('webview');
webview.id = 'webview';
webview.preload = './electronPreload.js';
document.body.appendChild(webview);
// Detect if online
const loadSite = () => {
const offlineElement = document.getElementById('offline_error');
if (navigator.onLine) {
webview.src = getParams(window.location.search).environment === 'production' ? 'https://solitairegamecenter.com/klondike?platform=desktop' : 'http://localhost:3000/klondike?platform=desktop';
clearTimeout(onlineCheckTimer);
offlineElement.style.display = 'none';
} else {
offlineElement.style.display = 'block';
}
}
const onlineCheckTimer = setInterval(loadSite, 1000);
loadSite();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment