From e7c6c500cef0e980fe22d14684c28c2efd576b3f Mon Sep 17 00:00:00 2001 From: Esmail EL BoB Date: Fri, 26 Jul 2019 05:12:28 +0200 Subject: [PATCH] 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 --- README.md | 6 ++++-- index.html | 8 +++++++ main.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 34d8d43..8c0de1a 100644 --- a/README.md +++ b/README.md @@ -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*) diff --git a/index.html b/index.html index eaadfbc..8ca3225 100644 --- a/index.html +++ b/index.html @@ -1,6 +1,7 @@ + What Is My IP Address ? @@ -11,6 +12,9 @@ +

Your Public IP Is:

@@ -49,6 +53,10 @@

Your User-Agent Is:

+

ــــــــــــــــــــــ

+
+

Your Net's Speed Is:

+
diff --git a/main.js b/main.js index 081ccfc..e47798c 100644 --- a/main.js +++ b/main.js @@ -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("
"); + 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(); \ No newline at end of file +checkUserAgent(); +checkSpeed(); \ No newline at end of file