forked from Sulagna-Dutta-Roy/GGExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the netwrok speed test extension
- Loading branch information
1 parent
e68b4f5
commit 1843093
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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'" | ||
} | ||
} | ||
|
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
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; | ||
} |
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
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> |
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
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"; | ||
}); | ||
}); | ||
}); |