Test My Speed PLZ

added a new option to test speed (just by loading photo from github servers so i guess its kinda good) & added a message if you blocking JS
This commit is contained in:
Esmail EL BoB
2019-07-26 05:12:28 +02:00
parent 673821c214
commit e7c6c500ce
3 changed files with 72 additions and 3 deletions

View File

@@ -22,9 +22,11 @@ Although The Website Uses *WebRTC* To Check IPs & Most Of Us Disabled It But Thi
## ----------------------------------------
# What's New ?
## (For Users):
1. *Nothing*
1. *Added* **Speed Test** *Feature*
2. *Added A Message To Notify User If He Block JS*
## (For Devs):
1. *Nothing*
1. *Nothing, Sorry*
## ----------------------------------------
# How To Edit Codes
1. **Clone Project Files**: `git clone https://github.com/EsmailELBoBDev2/Whatismyip.git` (*You Not Need*: **README.md** *&* **LICENSE** *Files*)

View File

@@ -1,6 +1,7 @@
<!DOCTYPE HTML>
<html>
<head>
<title>What Is My IP Address ?</title>
<meta charset="UTF-8">
@@ -11,6 +12,9 @@
</header>
<body>
<noscript>
<h2>hmm, i guess you disabled JS so please enable it to see the magic! :)</h2>
</noscript>
<div id="IP">
<h2>Your Public IP Is: </h2>
<h2 id="ip"></h2>
@@ -49,6 +53,10 @@
<div id="USERAGENT">
<h2>Your User-Agent Is: <a id="useragent"></a></h2>
</div>
<p>ــــــــــــــــــــــ</p>
<div id="SPEEDTEST">
<h2>Your Net's Speed Is: <br> <a id="speedtest"></a></h2>
</div>
<script src="main.js"></script>
</body>

61
main.js
View File

@@ -348,6 +348,64 @@ function checkUserAgent() {
}
// ـــــــــــــــــــــــــــــــــــ
// Speed Test
// navigator.connection.downlink
function checkSpeed() {
var imageAddr = "https://user-images.githubusercontent.com/28893833/61922983-db6bd600-af51-11e9-8486-949606a1497c.jpg";
var downloadSize = 4995374; //bytes
function ShowProgressMessage(msg) {
var oProgress = document.getElementById("speedtest");
if (oProgress) {
var actualHTML = (typeof msg == "string") ? msg : msg.join("<br />");
oProgress.innerHTML = actualHTML;
}
}
function InitiateSpeedDetection() {
ShowProgressMessage("Loading the image, please wait...");
window.setTimeout(MeasureConnectionSpeed, 1);
};
if (window.addEventListener) {
window.addEventListener('load', InitiateSpeedDetection, false);
} else if (window.attachEvent) {
window.attachEvent('onload', InitiateSpeedDetection);
}
function MeasureConnectionSpeed() {
var startTime, endTime;
var download = new Image();
download.onload = function () {
endTime = (new Date()).getTime();
showResults();
}
download.onerror = function (err, msg) {
ShowProgressMessage("Invalid image, or error downloading");
}
startTime = (new Date()).getTime();
var cacheBuster = "?nnn=" + startTime;
download.src = imageAddr + cacheBuster;
function showResults() {
var duration = (endTime - startTime) / 1000;
var bitsLoaded = downloadSize * 8;
var speedBps = (bitsLoaded / duration).toFixed(2);
var speedKbps = (speedBps / 1024).toFixed(2);
var speedMbps = (speedKbps / 1024).toFixed(2);
ShowProgressMessage([
speedBps + " bps",
speedKbps + " kbps",
speedMbps + " Mbps"
]);
}
}
}
// ـــــــــــــــــــــــــــــــــــ
// <*>RUN ALL OF THEM, BABY!<*> \\
checkLang();
checkScreen();
@@ -355,4 +413,5 @@ checkMobile();
checkCookies();
checkBrowser();
checkOS();
checkUserAgent();
checkUserAgent();
checkSpeed();