Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Storj Pricing
- // @namespace http://tampermonkey.net/
- // @version 0.3
- // @description Convert bandwidth to earnings for Storj dashboard
- // @author You
- // @match http://192.168.1.65:14002/
- // ==/UserScript==
- const currency = "CAD"
- window.addEventListener('load', () => {
- const [$target] = document.getElementsByClassName('info-area__title')
- const { textContent } = $target
- const json = response => response.json()
- updateBenefits()
- setInterval(updateBenefits, 30 * 1000)
- function updateBenefits() {
- Promise.all([
- fetch('https://api.coinpaprika.com/v1/tickers/storj-storj?quotes='+currency).then(json),
- fetch('https://api.exchangeratesapi.io/latest?base=USD').then(json),
- fetch(`${document.location.href}/api/satellites`).then(json)
- ])
- .then(([priceData, exchangeRateData, satellites]) => {
- const priceStorj = priceData.quotes[currency].price
- const rateExchange = exchangeRateData.rates[currency]
- const { data: { bandwidthDaily, storageDaily } } = satellites
- const pricePerGbBandwidthNormal = (20 * rateExchange) / 1000; // $20USD/TB
- const pricePerGbBandwidth = (10 * rateExchange) / 1000; // $10USD/TB
- const pricePerGbStorage = (1.5 * rateExchange) / 1000; // $1.5USD/TB
- const bandwidthNormal = bandwidthDaily.reduce((acc, row) => acc + row.egress.usage, 0) / 1000000000
- const bandwidth = bandwidthDaily.reduce((acc, row) => acc + row.egress.audit + row.egress.repair, 0) / 1000000000
- const storage = storageDaily.reduce((acc, row) => acc + row.atRestTotal, 0) / 1000000000 / 730
- const sum = ((bandwidthNormal * pricePerGbBandwidthNormal) + (bandwidth * pricePerGbBandwidth) + (storage * pricePerGbStorage)).toFixed(6);
- $target.textContent = `${textContent} (Value = $${sum} ${currency} or ${(sum / priceStorj).toFixed(6)} STORJ)`;
- })
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement