Skip to content

Commit

Permalink
Added the netwrok speed test extension
Browse files Browse the repository at this point in the history
  • Loading branch information
thevijayshankersharma committed May 20, 2024
1 parent e68b4f5 commit 1843093
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
Binary file added Network speed/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions Network speed/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"manifest_version": 3,
"name": "Network Speed Test Extension",
"version": "1.0",
"description": "Check your network speed directly from your browser.",
"permissions": [
"storage"
],
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icon.png",
"48": "icon.png",
"128": "icon.png"
}
},
"icons": {
"16": "icon.png",
"48": "icon.png",
"128": "icon.png"
},
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self'"
}
}

52 changes: 52 additions & 0 deletions Network speed/popup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
body {
font-family: Arial, sans-serif;
background: linear-gradient(135deg, #e0e0e0, #f5f5f5);
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.container {
width: 250px;
height: 250px;
background-color: #fff;
border-radius: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
padding: 20px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

h1 {
text-align: center;
color: #333;
margin-bottom: 20px;
}

button {
padding: 12px 24px;
font-size: 18px;
cursor: pointer;
background-color: #4caf50;
color: #fff;
border: none;
border-radius: 5px;
transition: background-color 0.3s;
}

button:hover {
background-color: #45a049;
}

#result {
text-align: center;
font-size: 18px;
font-weight: bold;
margin-top: 20px;
color: #4caf50;
}
17 changes: 17 additions & 0 deletions Network speed/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Network Speed Test</title>
<link rel="stylesheet" href="popup.css">
</head>
<body>
<div class="container">
<h1>Network Speed Test</h1>
<button id="startButton">Start Test</button>
<div id="result"></div>
</div>
<script src="popup.js"></script>
</body>
</html>
40 changes: 40 additions & 0 deletions Network speed/popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
document.addEventListener("DOMContentLoaded", function () {
const startButton = document.getElementById("startButton");
const resultDiv = document.getElementById("result");

startButton.addEventListener("click", function () {
const fileSize = 20 * 1024 * 1024; // 50 MB file
const numParallelRequests = 5; // Number of parallel requests
let totalSpeed = 0;

const fetchAndMeasureSpeed = async () => {
const startTime = performance.now();
const url = "data:application/octet-stream;base64," + "A".repeat(fileSize);
try {
const response = await fetch(url);
const endTime = performance.now();
const duration = (endTime - startTime) / 1000; // in seconds
const speedMbps = (fileSize * 8) / (duration * 1024 * 1024); // Mbps
return speedMbps;
} catch (error) {
console.error("Error fetching data:", error);
return 0;
}
};

const requests = Array.from({ length: numParallelRequests }, fetchAndMeasureSpeed);

Promise.all(requests)
.then(speeds => {
speeds.forEach(speed => {
totalSpeed += speed;
});
const averageSpeed = totalSpeed / numParallelRequests;
resultDiv.innerText = `Your average network speed is approximately ${averageSpeed.toFixed(2)} Mbps`;
})
.catch(error => {
console.error("Error fetching data:", error);
resultDiv.innerText = "Error occurred during speed test";
});
});
});

0 comments on commit 1843093

Please sign in to comment.