Created
January 18, 2018 15:50
-
-
Save tsertkov/f40ea2d07b293b51686c1e53a8ccbaf3 to your computer and use it in GitHub Desktop.
Dashboard rotator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>Dashboard Rotator</title> | |
<script> | |
var dashboardDisplayTimeout = 120000; | |
var dashboards = [{ | |
name: 'Tab1', | |
url: 'https://tab1.example.com' | |
}, { | |
name: 'Tab2', | |
url: 'https://tab2.example.com' | |
}, { | |
name: 'Tab3', | |
url: 'https://tab3.example.com' | |
}]; | |
var activeDashboardIdx = 0; | |
var activeWindow; | |
document.addEventListener('DOMContentLoaded', main); | |
function main() { | |
renderDashboardsList(); | |
loadDashboard(dashboards[activeDashboardIdx]); | |
rotateDashboard(); | |
} | |
function rotateDashboard() { | |
setTimeout(() => { | |
activeDashboardIdx++; | |
if (activeDashboardIdx >= dashboards.length) { | |
activeDashboardIdx = 0; | |
} | |
loadDashboard(dashboards[activeDashboardIdx]); | |
rotateDashboard(); | |
}, dashboardDisplayTimeout); | |
} | |
function loadDashboard(dashboard) { | |
if (activeWindow) activeWindow.close(); | |
activeWindow = window.open('about:blank', dashboard.name); | |
activeWindow.location.href = dashboard.url; | |
} | |
function renderDashboardsList() { | |
var ul = document.getElementById('dashboards'); | |
dashboards.forEach(function (dashboard) { | |
ul.innerHTML += `<li>${dashboard.name}</li>`; | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<h1>Dashboard rotator</h1> | |
<ul id="dashboards"></ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment