Created
January 12, 2022 16:54
-
-
Save saaiful/97de32d937c0882d78d9aa5e0f2bd3f6 to your computer and use it in GitHub Desktop.
Fast.com (spped chart in graph)
This file contains hidden or 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
// ==UserScript== | |
// @name Fast.com (spped chart in graph) | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description spped chart in graph | |
// @author Saiful Islam | |
// @match https://fast.com/ | |
// @icon https://www.google.com/s2/favicons?domain=fast.com | |
// @require http://code.jquery.com/jquery-3.4.1.min.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var checkSpeed = setInterval(function(){ | |
console.log('Checking...'); | |
var speed = $("#speed-value.succeeded").text(); | |
var unit = $("#speed-units").text(); | |
if(unit=="Kbps"){ speed = Number(speed) / 1024; } | |
if(speed){ | |
var old_data = JSON.parse(localStorage.getItem('fast_speed')); | |
if(!old_data){ | |
old_data = []; | |
} | |
var new_data = {'speed': speed, 'time': new Date().toLocaleString()}; | |
old_data.push(new_data); | |
var stringify = JSON.stringify(old_data); | |
localStorage.setItem('fast_speed', stringify); | |
var dates = []; | |
var speeds = []; | |
$.each(old_data, function(i,v){ | |
dates.push(v.time); | |
speeds.push(v.speed); | |
}); | |
var json_chart = {type:'bar',data:{labels:dates, datasets:[{label:'Speed',data:speeds}]}}; | |
var image_url = "https://quickchart.io/chart?c=" + JSON.stringify(json_chart); | |
console.log(image_url); | |
$('.your-speed-message').html('<img src=\'' + image_url + '\' width="100%" /><br><a href="javascript:{};" onclick="localStorage.setItem(\'fast_speed\', null);">Reset Graph</a>'); | |
console.log(stringify); | |
console.log('https://jsontochart.com/'); | |
clearInterval(checkSpeed); | |
setTimeout(function(){ window.location.reload(); }, 1000*60*5); | |
} | |
}, 1000*5); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment