// ==UserScript== // @name Gazelle stats since last // @version 0.85 // @description Displays the changes in stats on PTH and PTP // @author Chameleon // @include http*://*passtheheadphones.me/* // @include http*://*passthepopcorn.me/* // @include http*://apollo.rip/* // @grant GM_getValue // @grant GM_setValue // @namespace https://greasyfork.org/users/87476 // @downloadURL https://update.greasyfork.icu/scripts/26184/Gazelle%20stats%20since%20last.user.js // @updateURL https://update.greasyfork.icu/scripts/26184/Gazelle%20stats%20since%20last.meta.js // ==/UserScript== (function() { 'use strict'; if((window.location.href.indexOf("threadid=1781") != -1 && window.location.host.indexOf('headphones') != -1) || (window.location.href.indexOf("threadid=30532") != -1 && window.location.host.indexOf('popcorn') != -1)) showSettings(); 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[2].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); var settings = getSettings(); if(settings.persistTime && oldStats.time) { var difTime = (new Date())-oldStats.time; if(difTime > settings.persistTime*60000) window.localStorage.lastStats = JSON.stringify(currentStats); } else window.localStorage.lastStats = JSON.stringify(currentStats); var difTime=false; if(oldStats.time) { difTime = (new Date())-oldStats.time; } var li=false; if(settings.showBuffer) { li=document.createElement('li'); if(window.location.host.indexOf('popcorn') != -1) li.setAttribute('class', 'user-info-bar__item'); var before=document.getElementById('stats_ratio'); before.parentNode.insertBefore(li, before); li.innerHTML='Buffer: '+renderStats((currentStats.up/1.05)-currentStats.down)+''; } var change = {up:currentStats.up-oldStats.up, down:currentStats.down-oldStats.down, ratio:Math.round((currentStats.ratio-oldStats.ratio)*100)/100}; if(settings.profileOnly && window.location.href.indexOf(document.getElementById('nav_userinfo').getElementsByTagName('a')[0].href) == -1) return; if(change.up != 0 || settings.noChange) { statspans[0].innerHTML += ' ('+renderStats(change.up)+')'; if(difTime) statspans[0].title = (prettyTime(difTime))+' ago'; } if(change.down != 0 || settings.noChange) { statspans[1].innerHTML += ' ('+renderStats(change.down)+')'; if(difTime) statspans[1].title = (prettyTime(difTime))+' ago'; } if((change.up != 0 || change.down != 0 || settings.noChange) && settings.showBuffer) { var span=li.getElementsByTagName('span')[0]; span.innerHTML += ' ('+renderStats((change.up/1.05)-change.down)+')'; if(difTime) span.title = (prettyTime(difTime))+' ago'; } if(change.ratio != 0 || settings.noChange) { statspans[2].innerHTML += ' ('+change.ratio+')'; if(difTime) statspans[2].title = (prettyTime(difTime))+' ago'; } if(settings.alert && (change.up != 0 || change.down != 0 || change.ratio != 0)) alert('Up: '+renderStats(change.up)+', Down: '+renderStats(change.down)+', Buffer: '+renderStats((change.up/1.05)-change.down)+', Ratio: '+change.ratio); })(); function prettyTime(time) { var t=time; if(t/60000 < 1) return Math.round(time/1000)+'s'; if(t/(60000*60) < 1) return Math.round(time/60000)+'m'; if(t/(60000*60*24) < 1) return Math.round(time/(60000*60))+'h'; return Math.round(time/(60000*60*24))+'d '+(Math.round((time%(60000*60*24))/(60000*60)))+'h'; } function showSettings() { var before = document.getElementsByClassName('forum_post')[0]; var div = document.createElement('div'); before.parentNode.insertBefore(div, before); div.setAttribute('style', 'width: 100%; text-align: center; padding-bottom: 10px;'); div.setAttribute('class', 'box'); div.innerHTML = '