Implemented Minimal DARKMode

This commit is contained in:
TheSheref 2021-11-05 11:03:34 +02:00
parent eca7f06e21
commit 247fa1103c
6 changed files with 1263 additions and 399 deletions

View file

@ -35,11 +35,82 @@
display: block; display: block;
margin: 0 auto; margin: 0 auto;
} }
.theme-switch-wrapper {
margin: 20px;
}
.theme-switch {
display: inline-block;
height: 40px;
position: relative;
width: 65px;
}
.theme-switch input {
display: none;
}
.slider {
background: #000;
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
font-size: 13px;
transition: 0.4s;
}
.slider p:after {
color: #fff;
float: right;
margin: 0 5px 0 0;
content: "OFF";
transition: 0.4s;
}
input:checked + .slider p:after {
float: left;
color: #000;
content: "ON";
margin: 0 0 0 5px;
}
.slider:before {
background: #fff;
top: 8px;
content: "";
height: 26px;
left: 4px;
position: absolute;
transition: 0.4s;
width: 26px;
}
input:checked + .slider {
background-color: #fff;
}
input:checked + .slider:before {
transform: translateX(28px);
background: #000;
}
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style> </style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.min.js"></script> <!--THIS LIBRARY SUCKS!--> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.min.js"></script> <!--THIS LIBRARY SUCKS!-->
<script src="speedtest.js"></script> <script src="speedtest.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var s = null var s = null;
var xAxesColor='#000';
var yAxesColor='#000';
function runTest() { function runTest() {
var chart1ctx = document.getElementById('chart1Area').getContext('2d') var chart1ctx = document.getElementById('chart1Area').getContext('2d')
var chart2ctx = document.getElementById('chart2Area').getContext('2d') var chart2ctx = document.getElementById('chart2Area').getContext('2d')
@ -150,6 +221,11 @@
}, },
ticks: { ticks: {
beginAtZero: true beginAtZero: true
},
gridLines: {
display: true ,
color:xAxesColor,
lineWidth:0.1
} }
}], }],
yAxes: [{ yAxes: [{
@ -157,6 +233,11 @@
scaleLabel: 'Speed', scaleLabel: 'Speed',
ticks: { ticks: {
beginAtZero: true beginAtZero: true
},
gridLines: {
display:true,
color:yAxesColor,
lineWidth:0.1
} }
}] }]
} }
@ -180,6 +261,11 @@
}, },
ticks: { ticks: {
beginAtZero: true beginAtZero: true
},
gridLines: {
display: true ,
color:xAxesColor,
lineWidth:0.1
} }
}], }],
yAxes: [{ yAxes: [{
@ -187,6 +273,11 @@
scaleLabel: 'Latency', scaleLabel: 'Latency',
ticks: { ticks: {
beginAtZero: true beginAtZero: true
},
gridLines: {
display:true,
color:yAxesColor,
lineWidth:0.1
} }
}] }]
} }
@ -251,6 +342,58 @@
<a href="javascript:abortTest()" id="abortBtn">Abort</a> <a href="javascript:abortTest()" id="abortBtn">Abort</a>
</div> </div>
<a href="javascript:runTest()" id="startBtn">Run speedtest</a> <a href="javascript:runTest()" id="startBtn">Run speedtest</a>
<div id='darkMode'>
<h3>DARKMODE</h3>
<div class="theme-switch-wrapper">
<label class="theme-switch" for="checkbox">
<input type="checkbox" id="checkbox" />
<div class="slider round">
<p></p>
</div>
</div>
<br/><br/> Charts by <a href="http://www.chartjs.org/">Chart.js</a><br/><br/><a href="https://github.com/librespeed/speedtest">Source code</a> <br/><br/> Charts by <a href="http://www.chartjs.org/">Chart.js</a><br/><br/><a href="https://github.com/librespeed/speedtest">Source code</a>
<script>
//DARMODE
const toggleSwitch = document.querySelector(
'.theme-switch input[type="checkbox"]'
);
function switchTheme(e) {
if (e.target.checked) {
toggleDarkMode();
} else {
toggleDarkMode();
}
}
toggleSwitch.addEventListener("change", switchTheme, true);
var countToggleDark = 0;
function toggleDarkMode() {
if (countToggleDark == 0) {
document.querySelector("html").style.background = "#000";
document.querySelector("body").style.background = "#000";
document.querySelector("html").style.color = "#fdfdfd";
document.querySelector("body").style.color = "#fdfdfd";
document.querySelector("#startBtn").style.border =
"0.15em solid #fff";
document.querySelector("#startBtn").style.color = "#fff";
xAxesColor="#fff";
yAxesColor="#fff";
countToggleDark++;
} else {
document.querySelector("html ").style.background = "#fdfdfd";
document.querySelector("body").style.background = "#fdfdfd";
document.querySelector("html").style.color = "#202020";
document.querySelector("body").style.color = "#202020";
document.querySelector("#startBtn").style.border =
"0.15em solid #000";
document.querySelector("#startBtn").style.color = "#6060AA";
xAxesColor="#000";
yAxesColor="#000";
countToggleDark = 0;
}
}
</script>
</body> </body>
</html> </html>

View file

@ -78,9 +78,9 @@ function I(id){return document.getElementById(id);}
box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1); box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
} }
#startStopBtn.running{ #startStopBtn.running{
background-color:#FF3030; background-color:#FF3030!important;
border-color:#FF6060; border-color:#FF6060!important;
color:#FFFFFF; color:#FFFFFF!important;
} }
#startStopBtn:before{ #startStopBtn:before{
content:"Start"; content:"Start";
@ -147,6 +147,74 @@ function I(id){return document.getElementById(id);}
} }
} }
.theme-switch-wrapper {
margin: 20px;
}
.theme-switch {
display: inline-block;
height: 40px;
position: relative;
width: 65px;
}
.theme-switch input {
display: none;
}
.slider {
background: #000;
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
font-size: 13px;
transition: 0.4s;
}
.slider p:after {
color: #fff;
float: right;
margin: 0 5px 0 0;
content: "OFF";
transition: 0.4s;
}
input:checked + .slider p:after {
float: left;
color: #000;
content: "ON";
margin: 0 0 0 5px;
}
.slider:before {
background: #fff;
top: 8px;
content: "";
height: 26px;
left: 4px;
position: absolute;
transition: 0.4s;
width: 26px;
}
input:checked + .slider {
background-color: #fff;
}
input:checked + .slider:before {
transform: translateX(28px);
background: #000;
}
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style> </style>
</head> </head>
<body> <body>
@ -166,9 +234,60 @@ function I(id){return document.getElementById(id);}
</div> </div>
</div> </div>
</div> </div>
<div id='darkMode'>
<h3>DARKMODE</h3>
<div class="theme-switch-wrapper">
<label class="theme-switch" for="checkbox">
<input type="checkbox" id="checkbox" />
<div class="slider round">
<p></p>
</div>
</div>
<a href="https://github.com/librespeed/speedtest">Source code</a> <a href="https://github.com/librespeed/speedtest">Source code</a>
<script type="text/javascript"> <script type="text/javascript">
initUI(); initUI();
//DARMODE
const toggleSwitch = document.querySelector(
'.theme-switch input[type="checkbox"]'
);
function switchTheme(e) {
if (e.target.checked) {
toggleDarkMode();
} else {
toggleDarkMode();
}
}
toggleSwitch.addEventListener("change", switchTheme, true);
var countToggleDark = 0;
function toggleDarkMode() {
if (countToggleDark == 0) {
document.querySelector("html").style.background = "#000";
document.querySelector("body").style.background = "#000";
document.querySelector("html").style.color = "#fdfdfd";
document.querySelector("body").style.color = "#fdfdfd";
document.querySelector("#startStopBtn").style.border =
"0.15em solid #996cb4";
document.querySelector("#startStopBtn").style.color = "#996cb4";
document.querySelector("h1").style.color = "#d3cfcf";
document.querySelector("#dlText").style.color = "#996cb4";
countToggleDark++;
} else {
document.querySelector("html ").style.background = "#fdfdfd";
document.querySelector("body").style.background = "#fdfdfd";
document.querySelector("html").style.color = "#202020";
document.querySelector("body").style.color = "#202020";
document.querySelector("#startStopBtn").style.border =
"0.15em solid #6060FF";
document.querySelector("#startStopBtn").style.color = "#6060AA";
document.querySelector("h1").style.color = "#404040";
document.querySelector("#dlText").style.color = "#000";
countToggleDark = 0;
}
}
</script> </script>
</body> </body>
</html> </html>

View file

@ -154,9 +154,9 @@ function initUI(){
box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1); box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
} }
#startStopBtn.running{ #startStopBtn.running{
background-color:#FF3030; background-color:#FF3030!important;
border-color:#FF6060; border-color:#FF6060!important;
color:#FFFFFF; color:#FFFFFF!important;
} }
#startStopBtn:before{ #startStopBtn:before{
content:"Start"; content:"Start";
@ -272,6 +272,78 @@ function initUI(){
font-size:0.8em; font-size:0.8em;
} }
} }
#darkMode{
margin-top:-100px;
}
.theme-switch-wrapper {
margin:5px;
}
.theme-switch {
display: inline-block;
height: 40px;
position: relative;
width: 65px;
}
.theme-switch input {
display: none;
}
.slider {
background: #000;
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
font-size: 13px;
transition: 0.4s;
}
.slider p:after {
color: #fff;
float: right;
margin: 0 5px 0 0;
content: "OFF";
transition: 0.4s;
}
input:checked + .slider p:after {
float: left;
color: #000;
content: "ON";
margin: 0 0 0 5px;
}
.slider:before {
background: #fff;
top: 8px;
content: "";
height: 26px;
left: 4px;
position: absolute;
transition: 0.4s;
width: 26px;
}
input:checked + .slider {
background-color: #fff;
}
input:checked + .slider:before {
transform: translateX(28px);
background: #000;
}
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style> </style>
<title>LibreSpeed Example</title> <title>LibreSpeed Example</title>
</head> </head>
@ -317,6 +389,15 @@ function initUI(){
<img src="" id="resultsImg" /> <img src="" id="resultsImg" />
</div> </div>
</div> </div>
<div id='darkMode'>
<h3>DARKMODE</h3>
<div class="theme-switch-wrapper">
<label class="theme-switch" for="checkbox">
<input type="checkbox" id="checkbox" />
<div class="slider round">
<p></p>
</div>
</div>
<a href="https://github.com/librespeed/speedtest">Source code</a> <a href="https://github.com/librespeed/speedtest">Source code</a>
</div> </div>
<div id="privacyPolicy" style="display:none"> <div id="privacyPolicy" style="display:none">
@ -360,6 +441,60 @@ function initUI(){
</div> </div>
<br/> <br/>
</div> </div>
<script type="text/javascript">setTimeout(function(){initUI()},100);</script> <script type="text/javascript">
setTimeout(function(){initUI()},100);
//DARMODE
const toggleSwitch = document.querySelector(
'.theme-switch input[type="checkbox"]'
);
function switchTheme(e) {
if (e.target.checked) {
toggleDarkMode();
} else {
toggleDarkMode();
}
}
toggleSwitch.addEventListener("change", switchTheme, true);
var countToggleDark = 0;
function toggleDarkMode() {
if (countToggleDark == 0) {
document.querySelector("html").style.background = "#000";
document.querySelector("body").style.background = "#000";
document.querySelector("html").style.color = "#fdfdfd";
document.querySelector("body").style.color = "#fdfdfd";
document.querySelector("#startStopBtn").style.border =
"0.15em solid #996cb4";
document.querySelector("#startStopBtn").style.color = "#996cb4";
document.querySelector("h1").style.color = "#d3cfcf";
document.querySelector("#dlText").style.color = "#996cb4";
document.querySelector("#pingText").style.color = "#b92323";
document.querySelector("#jitText").style.color = "#b92323";
ulColor='#fff';
meterBk=/Trident.*rv:(\d+\.\d+)/i.test(navigator.userAgent)?"#EAEAEA":"#c7c7c7";
progColor="#fff";
countToggleDark++;
} else {
document.querySelector("html ").style.background = "#fdfdfd";
document.querySelector("body").style.background = "#fdfdfd";
document.querySelector("html").style.color = "#202020";
document.querySelector("body").style.color = "#202020";
document.querySelector("#startStopBtn").style.border =
"0.15em solid #6060FF";
document.querySelector("#startStopBtn").style.color = "#6060AA";
document.querySelector("h1").style.color = "#404040";
document.querySelector("#dlText").style.color = "#000";
document.querySelector("#pingText").style.color = "#AA6060";
document.querySelector("#jitText").style.color = "#AA6060";
ulColor='#616161';
meterBk=/Trident.*rv:(\d+\.\d+)/i.test(navigator.userAgent)?"#EAEAEA":"#80808040";
progColor=meterBk;
countToggleDark = 0;
}
}
</script>
</body> </body>
</html> </html>

View file

@ -139,9 +139,9 @@ function initUI(){
box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1); box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
} }
#startStopBtn.running{ #startStopBtn.running{
background-color:#FF3030; background-color: #ff3030 !important;
border-color:#FF6060; border-color: #ff6060 !important;
color:#FFFFFF; color: #ffffff !important;
} }
#startStopBtn:before{ #startStopBtn:before{
content:"Start"; content:"Start";
@ -217,6 +217,78 @@ function initUI(){
font-size:0.8em; font-size:0.8em;
} }
} }
#darkMode{
margin-top:-100px;
}
.theme-switch-wrapper {
margin:5px;
}
.theme-switch {
display: inline-block;
height: 40px;
position: relative;
width: 65px;
}
.theme-switch input {
display: none;
}
.slider {
background: #000;
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
font-size: 13px;
transition: 0.4s;
}
.slider p:after {
color: #fff;
float: right;
margin: 0 5px 0 0;
content: "OFF";
transition: 0.4s;
}
input:checked + .slider p:after {
float: left;
color: #000;
content: "ON";
margin: 0 0 0 5px;
}
.slider:before {
background: #fff;
top: 8px;
content: "";
height: 26px;
left: 4px;
position: absolute;
transition: 0.4s;
width: 26px;
}
input:checked + .slider {
background-color: #fff;
}
input:checked + .slider:before {
transform: translateX(28px);
background: #000;
}
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style> </style>
<title>LibreSpeed Example</title> <title>LibreSpeed Example</title>
</head> </head>
@ -254,9 +326,73 @@ function initUI(){
<div id="ipArea"> <div id="ipArea">
<span id="ip"></span> <span id="ip"></span>
</div> </div>
</div>
<div id='darkMode'>
<h3>DARKMODE</h3>
<div class="theme-switch-wrapper">
<label class="theme-switch" for="checkbox">
<input type="checkbox" id="checkbox" />
<div class="slider round">
<p></p>
</div>
</div>
</label>
</div> </div>
<a href="https://github.com/librespeed/speedtest">Source code</a> <a href="https://github.com/librespeed/speedtest">Source code</a>
</div> </div>
<script type="text/javascript">setTimeout(function(){initUI()},100);</script> <script type="text/javascript">
setTimeout(function(){initUI()},100);
//DARMODE
const toggleSwitch = document.querySelector(
'.theme-switch input[type="checkbox"]'
);
function switchTheme(e) {
if (e.target.checked) {
toggleDarkMode();
} else {
toggleDarkMode();
}
}
toggleSwitch.addEventListener("change", switchTheme, true);
var countToggleDark = 0;
function toggleDarkMode() {
if (countToggleDark == 0) {
document.querySelector("html").style.background = "#000";
document.querySelector("body").style.background = "#000";
document.querySelector("html").style.color = "#fdfdfd";
document.querySelector("body").style.color = "#fdfdfd";
document.querySelector("#startStopBtn").style.border =
"0.15em solid #996cb4";
document.querySelector("#startStopBtn").style.color = "#996cb4";
document.querySelector("h1").style.color = "#d3cfcf";
document.querySelector("#dlText").style.color = "#996cb4";
document.querySelector("#pingText").style.color = "#b92323";
document.querySelector("#jitText").style.color = "#b92323";
ulColor='#fff';
meterBk=/Trident.*rv:(\d+\.\d+)/i.test(navigator.userAgent)?"#EAEAEA":"#c7c7c7";
progColor="#fff";
countToggleDark++;
} else {
document.querySelector("html ").style.background = "#fdfdfd";
document.querySelector("body").style.background = "#fdfdfd";
document.querySelector("html").style.color = "#202020";
document.querySelector("body").style.color = "#202020";
document.querySelector("#startStopBtn").style.border =
"0.15em solid #6060FF";
document.querySelector("#startStopBtn").style.color = "#6060AA";
document.querySelector("h1").style.color = "#404040";
document.querySelector("#dlText").style.color = "#000";
document.querySelector("#pingText").style.color = "#AA6060";
document.querySelector("#jitText").style.color = "#AA6060";
ulColor='#616161';
meterBk=/Trident.*rv:(\d+\.\d+)/i.test(navigator.userAgent)?"#EAEAEA":"#80808040";
progColor=meterBk;
countToggleDark = 0;
}
}
</script>
</body> </body>
</html> </html>

View file

@ -1,161 +1,268 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no" /> <meta
<title>LibreSpeed Example</title> name="viewport"
<link rel="shortcut icon" href="favicon.ico"> content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no"
<script type="text/javascript" src="speedtest.js"></script> />
<script type="text/javascript"> <title>LibreSpeed Example</title>
<link rel="shortcut icon" href="favicon.ico" />
//INITIALIZE SPEEDTEST <script type="text/javascript" src="speedtest.js"></script>
var s=new Speedtest(); //create speedtest object <script type="text/javascript">
s.onupdate=function(data){ //callback to update data in UI //INITIALIZE SPEEDTEST
I("ip").textContent=data.clientIp; var s = new Speedtest(); //create speedtest object
I("dlText").textContent=(data.testState==1&&data.dlStatus==0)?"...":data.dlStatus; s.onupdate = function (data) {
I("ulText").textContent=(data.testState==3&&data.ulStatus==0)?"...":data.ulStatus; //callback to update data in UI
I("pingText").textContent=data.pingStatus; I("ip").textContent = data.clientIp;
I("jitText").textContent=data.jitterStatus; I("dlText").textContent =
} data.testState == 1 && data.dlStatus == 0 ? "..." : data.dlStatus;
s.onend=function(aborted){ //callback for test ended/aborted I("ulText").textContent =
I("startStopBtn").className=""; //show start button again data.testState == 3 && data.ulStatus == 0 ? "..." : data.ulStatus;
if(aborted){ //if the test was aborted, clear the UI and prepare for new test I("pingText").textContent = data.pingStatus;
I("jitText").textContent = data.jitterStatus;
};
s.onend = function (aborted) {
//callback for test ended/aborted
I("startStopBtn").className = ""; //show start button again
if (aborted) {
//if the test was aborted, clear the UI and prepare for new test
initUI(); initUI();
} }
} };
function startStop(){ //start/stop button pressed function startStop() {
if(s.getState()==3){ //start/stop button pressed
if (s.getState() == 3) {
//speedtest is running, abort //speedtest is running, abort
s.abort(); s.abort();
}else{ } else {
//test is not running, begin //test is not running, begin
s.start(); s.start();
I("startStopBtn").className="running"; I("startStopBtn").className = "running";
}
} }
}
//function to (re)initialize UI //function to (re)initialize UI
function initUI(){ function initUI() {
I("dlText").textContent=""; I("dlText").textContent = "";
I("ulText").textContent=""; I("ulText").textContent = "";
I("pingText").textContent=""; I("pingText").textContent = "";
I("jitText").textContent=""; I("jitText").textContent = "";
I("ip").textContent=""; I("ip").textContent = "";
} }
function I(id){return document.getElementById(id);} function I(id) {
</script> return document.getElementById(id);
}
</script>
<style type="text/css"> <style type="text/css">
html,body{ html,
border:none; padding:0; margin:0; body {
background:#FFFFFF; border: none;
color:#202020; padding: 0;
margin: 0;
background: #ffffff;
color: #202020;
} }
body{
text-align:center; body {
font-family:"Roboto",sans-serif; text-align: center;
font-family: "Roboto", sans-serif;
} }
h1{
color:#404040; h1 {
color: #404040;
} }
#startStopBtn{
display:inline-block; #startStopBtn {
margin:0 auto; display: inline-block;
color:#6060AA; margin: 0 auto;
background-color:rgba(0,0,0,0); color: #6060aa;
border:0.15em solid #6060FF; background-color: rgba(0, 0, 0, 0);
border-radius:0.3em; border: 0.15em solid #6060ff;
transition:all 0.3s; border-radius: 0.3em;
box-sizing:border-box; transition: all 0.3s;
width:8em; height:3em; box-sizing: border-box;
line-height:2.7em; width: 8em;
cursor:pointer; height: 3em;
box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1); line-height: 2.7em;
cursor: pointer;
box-shadow: 0 0 0 rgba(0, 0, 0, 0.1), inset 0 0 0 rgba(0, 0, 0, 0.1);
} }
#startStopBtn:hover{
box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1); #startStopBtn:hover {
box-shadow: 0 0 2em rgba(0, 0, 0, 0.1), inset 0 0 1em rgba(0, 0, 0, 0.1);
} }
#startStopBtn.running{
background-color:#FF3030; #startStopBtn.running {
border-color:#FF6060; background-color: #ff3030 !important;
color:#FFFFFF; border-color: #ff6060 !important;
color: #ffffff !important;
} }
#startStopBtn:before{
content:"Start"; #startStopBtn:before {
content: "Start";
} }
#startStopBtn.running:before{
content:"Abort"; #startStopBtn.running:before {
content: "Abort";
} }
#test{
margin-top:2em; #test {
margin-bottom:12em; margin-top: 2em;
margin-bottom: 12em;
} }
div.testArea{
display:inline-block; div.testArea {
width:14em; display: inline-block;
height:9em; width: 14em;
position:relative; height: 9em;
box-sizing:border-box; position: relative;
box-sizing: border-box;
} }
div.testName{
position:absolute; div.testName {
top:0.1em; left:0; position: absolute;
width:100%; top: 0.1em;
font-size:1.4em; left: 0;
z-index:9; width: 100%;
font-size: 1.4em;
z-index: 9;
} }
div.meterText{
position:absolute; div.meterText {
bottom:1.5em; left:0; position: absolute;
width:100%; bottom: 1.5em;
font-size:2.5em; left: 0;
z-index:9; width: 100%;
font-size: 2.5em;
z-index: 9;
} }
#dlText{
color:#6060AA; #dlText {
color: #6060aa;
} }
#ulText{
color:#309030; #ulText {
color: #309030;
} }
#pingText,#jitText{
color:#AA6060; #pingText,
#jitText {
color: #aa6060;
} }
div.meterText:empty:before{
color:#505050 !important; div.meterText:empty:before {
content:"0.00"; color: #505050 !important;
content: "0.00";
} }
div.unit{
position:absolute; div.unit {
bottom:2em; left:0; position: absolute;
width:100%; bottom: 2em;
z-index:9; left: 0;
width: 100%;
z-index: 9;
} }
div.testGroup{
display:inline-block; div.testGroup {
display: inline-block;
} }
@media all and (max-width:65em){
body{ @media all and (max-width: 65em) {
font-size:1.5vw; body {
font-size: 1.5vw;
} }
} }
@media all and (max-width:40em){
body{ @media all and (max-width: 40em) {
font-size:0.8em; body {
font-size: 0.8em;
} }
div.testGroup{
display:block; div.testGroup {
display: block;
margin: 0 auto; margin: 0 auto;
} }
} }
</style> .theme-switch-wrapper {
</head> margin: 20px;
<body> }
<h1>LibreSpeed Example</h1>
<div id="startStopBtn" onclick="startStop()"></div> .theme-switch {
<div id="test"> display: inline-block;
height: 40px;
position: relative;
width: 65px;
}
.theme-switch input {
display: none;
}
.slider {
background: #000;
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
font-size: 13px;
transition: 0.4s;
}
.slider p:after {
color: #fff;
float: right;
margin: 0 5px 0 0;
content: "OFF";
transition: 0.4s;
}
input:checked + .slider p:after {
float: left;
color: #000;
content: "ON";
margin: 0 0 0 5px;
}
.slider:before {
background: #fff;
top: 8px;
content: "";
height: 26px;
left: 4px;
position: absolute;
transition: 0.4s;
width: 26px;
}
input:checked + .slider {
background-color: #fff;
}
input:checked + .slider:before {
transform: translateX(28px);
background: #000;
}
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
</head>
<body>
<h1>LibreSpeed Example</h1>
<div id="startStopBtn" onclick="startStop()"></div>
<div id="test">
<div class="testGroup"> <div class="testGroup">
<div class="testArea"> <div class="testArea">
<div class="testName">Download</div> <div class="testName">Download</div>
@ -180,13 +287,66 @@ function I(id){return document.getElementById(id);}
<div class="unit">ms</div> <div class="unit">ms</div>
</div> </div>
</div> </div>
<div id="ipArea"> <div id="ipArea">IP Address: <span id="ip"></span></div>
IP Address: <span id="ip"></span>
</div> </div>
</div> <h3>DARKMODE</h3>
<a href="https://github.com/librespeed/speedtest">Source code</a> <div class="theme-switch-wrapper">
<script type="text/javascript"> <label class="theme-switch" for="checkbox">
<input type="checkbox" id="checkbox" />
<div class="slider round">
<p></p>
</div>
</label>
</div>
<a href="https://github.com/librespeed/speedtest">Source code</a>
<script type="text/javascript">
initUI(); initUI();
</script>
</body> //DARMODE
const toggleSwitch = document.querySelector(
'.theme-switch input[type="checkbox"]'
);
function switchTheme(e) {
if (e.target.checked) {
toggleDarkMode();
} else {
toggleDarkMode();
}
}
toggleSwitch.addEventListener("change", switchTheme, true);
var countToggleDark = 0;
function toggleDarkMode() {
if (countToggleDark == 0) {
document.querySelector("html").style.background = "#000";
document.querySelector("body").style.background = "#000";
document.querySelector("html").style.color = "#fdfdfd";
document.querySelector("body").style.color = "#fdfdfd";
document.querySelector("#startStopBtn").style.border =
"0.15em solid #996cb4";
document.querySelector("#startStopBtn").style.color = "#996cb4";
document.querySelector("h1").style.color = "#d3cfcf";
document.querySelector("#dlText").style.color = "#996cb4";
document.querySelector("#pingText").style.color = "#b92323";
document.querySelector("#jitText").style.color = "#b92323";
countToggleDark++;
} else {
document.querySelector("html ").style.background = "#fdfdfd";
document.querySelector("body").style.background = "#fdfdfd";
document.querySelector("html").style.color = "#202020";
document.querySelector("body").style.color = "#202020";
document.querySelector("#startStopBtn").style.border =
"0.15em solid #6060FF";
document.querySelector("#startStopBtn").style.color = "#6060AA";
document.querySelector("h1").style.color = "#404040";
document.querySelector("#dlText").style.color = "#6060AA";
document.querySelector("#pingText").style.color = "#AA6060";
document.querySelector("#jitText").style.color = "#AA6060";
countToggleDark = 0;
}
}
</script>
</body>
</html> </html>

View file

@ -1,181 +1,297 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no" /> <meta
<title>LibreSpeed Example</title> name="viewport"
<link rel="shortcut icon" href="favicon.ico"> content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no"
<script type="text/javascript" src="speedtest.js"></script> />
<script type="text/javascript"> <title>LibreSpeed Example</title>
<link rel="shortcut icon" href="favicon.ico" />
//INITIALIZE SPEEDTEST <script type="text/javascript" src="speedtest.js"></script>
var s=new Speedtest(); //create speedtest object <script type="text/javascript">
s.onupdate=function(data){ //callback to update data in UI //INITIALIZE SPEEDTEST
I("ip").textContent=data.clientIp; var s = new Speedtest(); //create speedtest object
I("dlText").textContent=(data.testState==1&&data.dlStatus==0)?"...":data.dlStatus; s.onupdate = function (data) {
I("ulText").textContent=(data.testState==3&&data.ulStatus==0)?"...":data.ulStatus; //callback to update data in UI
I("pingText").textContent=data.pingStatus; I("ip").textContent = data.clientIp;
I("jitText").textContent=data.jitterStatus; I("dlText").textContent =
var prog=(Number(data.dlProgress)*2+Number(data.ulProgress)*2+Number(data.pingProgress))/5; data.testState == 1 && data.dlStatus == 0 ? "..." : data.dlStatus;
I("progress").style.width=(100*prog)+"%"; I("ulText").textContent =
} data.testState == 3 && data.ulStatus == 0 ? "..." : data.ulStatus;
s.onend=function(aborted){ //callback for test ended/aborted I("pingText").textContent = data.pingStatus;
I("startStopBtn").className=""; //show start button again I("jitText").textContent = data.jitterStatus;
if(aborted){ //if the test was aborted, clear the UI and prepare for new test var prog =
(Number(data.dlProgress) * 2 +
Number(data.ulProgress) * 2 +
Number(data.pingProgress)) /
5;
I("progress").style.width = 100 * prog + "%";
};
s.onend = function (aborted) {
//callback for test ended/aborted
I("startStopBtn").className = ""; //show start button again
if (aborted) {
//if the test was aborted, clear the UI and prepare for new test
initUI(); initUI();
} }
} };
function startStop(){ //start/stop button pressed function startStop() {
if(s.getState()==3){ //start/stop button pressed
if (s.getState() == 3) {
//speedtest is running, abort //speedtest is running, abort
s.abort(); s.abort();
}else{ } else {
//test is not running, begin //test is not running, begin
s.start(); s.start();
I("startStopBtn").className="running"; I("startStopBtn").className = "running";
}
} }
}
//function to (re)initialize UI //function to (re)initialize UI
function initUI(){ function initUI() {
I("dlText").textContent=""; I("dlText").textContent = "";
I("ulText").textContent=""; I("ulText").textContent = "";
I("pingText").textContent=""; I("pingText").textContent = "";
I("jitText").textContent=""; I("jitText").textContent = "";
I("ip").textContent=""; I("ip").textContent = "";
} }
function I(id){return document.getElementById(id);} function I(id) {
</script> return document.getElementById(id);
}
</script>
<style type="text/css"> <style type="text/css">
html,body{ html,
border:none; padding:0; margin:0; body {
background:#FFFFFF; border: none;
color:#202020; padding: 0;
margin: 0;
background: #fdfdfd;
color: #202020;
} }
body{
text-align:center; body {
font-family:"Roboto",sans-serif; text-align: center;
font-family: "Roboto", sans-serif;
} }
h1{
color:#404040; h1 {
color: #404040;
} }
#startStopBtn{
display:inline-block; #startStopBtn {
margin:0 auto; display: inline-block;
color:#6060AA; margin: 0 auto;
background-color:rgba(0,0,0,0); color: #6060aa;
border:0.15em solid #6060FF; background-color: rgba(0, 0, 0, 0);
border-radius:0.3em; border: 0.15em solid #6060ff;
transition:all 0.3s; border-radius: 0.3em;
box-sizing:border-box; transition: all 0.3s;
width:8em; height:3em; box-sizing: border-box;
line-height:2.7em; width: 8em;
cursor:pointer; height: 3em;
box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1); line-height: 2.7em;
cursor: pointer;
box-shadow: 0 0 0 rgba(0, 0, 0, 0.1), inset 0 0 0 rgba(0, 0, 0, 0.1);
} }
#startStopBtn:hover{
box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1); #startStopBtn:hover {
box-shadow: 0 0 2em rgba(0, 0, 0, 0.1), inset 0 0 1em rgba(0, 0, 0, 0.1);
} }
#startStopBtn.running{
background-color:#FF3030; #startStopBtn.running {
border-color:#FF6060; background-color: #ff3030 !important;
color:#FFFFFF; border-color: #ff6060 !important;
color: #ffffff !important;
} }
#startStopBtn:before{
content:"Start"; #startStopBtn:before {
content: "Start";
} }
#startStopBtn.running:before{
content:"Abort"; #startStopBtn.running:before {
content: "Abort";
} }
#test{
margin-top:2em; #test {
margin-bottom:12em; margin-top: 2em;
margin-bottom: 12em;
} }
div.testArea{
display:inline-block; div.testArea {
width:14em; display: inline-block;
height:9em; width: 14em;
position:relative; height: 9em;
box-sizing:border-box; position: relative;
box-sizing: border-box;
} }
div.testName{
position:absolute; div.testName {
top:0.1em; left:0; position: absolute;
width:100%; top: 0.1em;
font-size:1.4em; left: 0;
z-index:9; width: 100%;
font-size: 1.4em;
z-index: 9;
} }
div.meterText{
position:absolute; div.meterText {
bottom:1.5em; left:0; position: absolute;
width:100%; bottom: 1.5em;
font-size:2.5em; left: 0;
z-index:9; width: 100%;
font-size: 2.5em;
z-index: 9;
} }
#dlText{
color:#6060AA; #dlText {
color: #6060aa;
} }
#ulText{
color:#309030; #ulText {
color: #309030;
} }
#pingText,#jitText{
color:#AA6060; #pingText,
#jitText {
color: #aa6060;
} }
div.meterText:empty:before{
color:#505050 !important; div.meterText:empty:before {
content:"0.00"; color: #505050 !important;
content: "0.00";
} }
div.unit{
position:absolute; div.unit {
bottom:2em; left:0; position: absolute;
width:100%; bottom: 2em;
z-index:9; left: 0;
width: 100%;
z-index: 9;
} }
div.testGroup{
display:inline-block; div.testGroup {
display: inline-block;
} }
@media all and (max-width:65em){
body{ @media all and (max-width: 65em) {
font-size:1.5vw; body {
font-size: 1.5vw;
} }
} }
@media all and (max-width:40em){
body{ @media all and (max-width: 40em) {
font-size:0.8em; body {
font-size: 0.8em;
} }
div.testGroup{
display:block; div.testGroup {
display: block;
margin: 0 auto; margin: 0 auto;
} }
} }
#progressBar{
width:90%; #progressBar {
height:0.3em; width: 90%;
background-color:#EEEEEE; height: 0.3em;
position:relative; background-color: #eeeeee;
display:block; position: relative;
margin:0 auto; display: block;
margin-bottom:2em; margin: 0 auto;
} margin-bottom: 2em;
#progress{
position:absolute;
top:0; left:0;
height:100%;
width:0%;
transition: width 2s;
background-color:#90BBFF;
} }
</style> #progress {
</head> position: absolute;
<body> top: 0;
<h1>LibreSpeed Example</h1> left: 0;
<div id="startStopBtn" onclick="startStop()"></div> height: 100%;
<div id="test"> width: 0%;
<div id="progressBar"><div id="progress"></div></div> transition: width 2s;
background-color: #90bbff;
}
.theme-switch-wrapper {
margin: 20px;
}
.theme-switch {
display: inline-block;
height: 40px;
position: relative;
width: 65px;
}
.theme-switch input {
display: none;
}
.slider {
background: #000;
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
font-size: 13px;
transition: 0.4s;
}
.slider p:after {
color: #fff;
float: right;
margin: 0 5px 0 0;
content: "OFF";
transition: 0.4s;
}
input:checked + .slider p:after {
float: left;
color: #000;
content: "ON";
margin: 0 0 0 5px;
}
.slider:before {
background: #fff;
top: 8px;
content: "";
height: 26px;
left: 4px;
position: absolute;
transition: 0.4s;
width: 26px;
}
input:checked + .slider {
background-color: #fff;
}
input:checked + .slider:before {
transform: translateX(28px);
background: #000;
}
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
</head>
<body>
<h1>LibreSpeed Example</h1>
<div id="startStopBtn" onclick="startStop()"></div>
<div id="test">
<div id="progressBar">
<div id="progress"></div>
</div>
<div class="testGroup"> <div class="testGroup">
<div class="testArea"> <div class="testArea">
<div class="testName">Download</div> <div class="testName">Download</div>
@ -200,13 +316,68 @@ function I(id){return document.getElementById(id);}
<div class="unit">ms</div> <div class="unit">ms</div>
</div> </div>
</div> </div>
<div id="ipArea"> <div id="ipArea">IP Address: <span id="ip"></span></div>
IP Address: <span id="ip"></span>
</div> </div>
</div> <h3>DARKMODE</h3>
<a href="https://github.com/librespeed/speedtest">Source code</a> <div class="theme-switch-wrapper">
<script type="text/javascript"> <label class="theme-switch" for="checkbox">
<input type="checkbox" id="checkbox" />
<div class="slider round">
<p></p>
</div>
</label>
</div>
<a href="https://github.com/librespeed/speedtest">Source code</a>
<script type="text/javascript">
initUI(); initUI();
</script> </script>
</body> </body>
<script>
//DARMODE
const toggleSwitch = document.querySelector(
'.theme-switch input[type="checkbox"]'
);
function switchTheme(e) {
if (e.target.checked) {
toggleDarkMode();
} else {
toggleDarkMode();
}
}
toggleSwitch.addEventListener("change", switchTheme, true);
var countToggleDark = 0;
function toggleDarkMode() {
if (countToggleDark == 0) {
document.querySelector("html").style.background = "#000";
document.querySelector("body").style.background = "#000";
document.querySelector("html").style.color = "#fdfdfd";
document.querySelector("body").style.color = "#fdfdfd";
document.querySelector("#startStopBtn").style.border ="0.15em solid #996cb4";
document.querySelector("#startStopBtn").style.color = "#996cb4";
document.querySelector("h1").style.color = "#d3cfcf";
document.querySelector("#dlText").style.color = "#996cb4";
document.querySelector("#pingText").style.color = "#b92323";
document.querySelector("#jitText").style.color = "#b92323";
document.querySelector("#progress").style.background = "#996cb4";
countToggleDark++;
} else {
document.querySelector("html ").style.background = "#fdfdfd";
document.querySelector("body").style.background = "#fdfdfd";
document.querySelector("html").style.color = "#202020";
document.querySelector("body").style.color = "#202020";
document.querySelector("#startStopBtn").style.border ="0.15em solid #6060FF";
document.querySelector("#startStopBtn").style.color = "#6060AA";
document.querySelector("h1").style.color = "#404040";
document.querySelector("#dlText").style.color = "#6060AA";
document.querySelector("#pingText").style.color = "#AA6060";
document.querySelector("#jitText").style.color = "#AA6060";
document.querySelector("#progress").style.background = "#90BBFF";
countToggleDark = 0;
}
}
</script>
</html> </html>