NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name GGn stats change // @version 0.1 // @description Displays the changes in stats on GGn // @author NullPhantom // @include http*://*gazellegames.net/* // @updateURL https://openuserjs.org/meta/NullPhantom/GGn_stats_change.meta.js // ==/UserScript== (function() { 'use strict'; var currentStats = {}; var statspans = document.getElementById('userinfo_stats').querySelectorAll('span'); currentStats.up = parseStats(statspans[0].textContent); currentStats.down = parseStats(statspans[1].textContent); currentStats.ratio = parseFloat(statspans[3].textContent); if(isNaN(currentStats.ratio)) currentStats.ratio = 0; currentStats.time=(new Date())*1; var oldStats = window.localStorage.lastStats; if(!oldStats) oldStats = {up:currentStats.up, down:currentStats.down, ratio:currentStats.ratio}; else oldStats = JSON.parse(oldStats); window.localStorage.lastStats = JSON.stringify(currentStats); var change = {up:currentStats.up-oldStats.up, down:currentStats.down-oldStats.down, ratio:Math.round((currentStats.ratio-oldStats.ratio)*100)/100}; if(change.up != 0 || change.down != 0 || change.ratio != 0) alert('Up: '+renderStats(change.up)+', Down: '+renderStats(change.down)+', Buffer: '+renderStats(change.up-change.down)+', Ratio: '+change.ratio); })(); function renderStats(number) { var amount = number; var pow = 0; for(var i=10; i<=50; i=i+10) { if(Math.abs(amount)/Math.pow(2, i) > 1) pow=i/10; } var suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; return (Math.round(amount/Math.pow(2, pow*10)*100))/100+' '+suffixes[pow]; } function parseStats(string) { string=string.replace(/,/g, ''); var suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; var amount = parseFloat(string); if(string.indexOf(suffixes[1]) != -1) amount = amount*Math.pow(2, 10); else if(string.indexOf(suffixes[2]) != -1) amount = amount*Math.pow(2, 20); else if(string.indexOf(suffixes[3]) != -1) amount = amount*Math.pow(2, 30); else if(string.indexOf(suffixes[4]) != -1) amount = amount*Math.pow(2, 40); else if(string.indexOf(suffixes[5]) != -1) amount = amount*Math.pow(2, 50); return Math.round(amount); }