dodo021 / Spectrum++

// ==UserScript==
// @name         Spectrum++
// @namespace    http://twitter.com/dodo021_
// @version      0.3.2
// @description  Add usefull informations on Spectrum Protocol website
// @author       dodo021
// @match        https://terra.spec.finance/vaults
// @icon         https://www.google.com/s2/favicons?domain=spec.finance
// @grant        none
// @license      MIT
// @updateURL    https://openuserjs.org/meta/dodo021/Spectrum++.meta.js
// ==/UserScript==
// If you want to send any tips, you can send them to terra1acp2rn4fw2fglycgmy9ggpy7u4a4l08fv0rvj7

(function() {
    'use strict';

    function insertBefore(referenceNode, newNode) {
        referenceNode.parentNode.insertBefore(newNode, referenceNode.previousSibling);
    }

    setInterval(function() {
        let $modalOpen = document.querySelector('.cdk-overlay-pane') ? true : false;

        if($modalOpen == false) {
            return;
        }

        const $grid = document.querySelector('.cdk-overlay-pane > mdb-modal-container > div > div > app-vault-dialog > div.modal-body > div.row.g-1');
        const $formRow = document.querySelector('.cdk-overlay-pane > mdb-modal-container > div > div > app-vault-dialog > div.modal-body > div > div.row.tab-container.g-0');
        const $poolApr = document.querySelector('.cdk-overlay-pane > mdb-modal-container > div > div > app-vault-dialog > div.modal-body > div > div.col-12.col-md-4 > div > div > h3 > div > span.ng-star-inserted > span > span');
        const $poolApy = document.querySelector('.cdk-overlay-pane > mdb-modal-container > div > div > app-vault-dialog > div.modal-body > div > div.col-12.col-md-4 > div > div > h3 > div > span.fs-6.fw-bold.text-primary');
        const $valueDeposited = document.querySelector('.cdk-overlay-pane > mdb-modal-container > div > div > app-vault-dialog > div.modal-body > div > div:nth-child(4) > div > div > h3 > span');

        if($valueDeposited == null) {
            return;
        }

        const valueDeposited = Number($valueDeposited.innerText.replace('(', '').replace(')', '').replace('$', '').replace(',', ''));
        const poolApr = Number($poolApr.innerText.replace('%', '').replace(',', ''));
        const poolApy = Number($poolApy.innerText.replace('%', '').replace(',', ''));
        let dailyUSTRewards = 0;
        let dailySpecRewards = 0;
        let yearlyUSTRewards = 0;

        dailyUSTRewards = valueDeposited * (poolApr / 100) / 365;
        yearlyUSTRewards = valueDeposited * (poolApy / 100);

        let $extraInfoRow = document.querySelector('.cdk-overlay-pane > mdb-modal-container > div > div > app-vault-dialog > div.modal-body > div > div.row-extra-info');

        if(!$extraInfoRow) {
            $extraInfoRow = document.createElement('div')
            $extraInfoRow.classList.add('mt-1');
            $extraInfoRow.classList.add('col-12');
            $extraInfoRow.classList.add('row-extra-info');
            $extraInfoRow.innerHTML  = `<div class="row g-1">
            <div class="col col-mb">
            <div class="card box-left">
            <div class="card-body">
            <p class="card-text sub-topic">Current daily auto-compounded value</p>
            <h3 class="card-title">$${dailyUSTRewards.toFixed(3)}</h3>
            </div>
            </div>
            </div>

            <div class="col col-mb">
            <div class="card box-left">
            <div class="card-body">
            <p class="card-text sub-topic">Estimated annual reward</p>
            <h3 class="card-title">$${yearlyUSTRewards.toFixed(3)}</h3>
            </div>
            </div>
            </div>
            </div>`;

            insertBefore($formRow, $extraInfoRow);
        }
    }, 1000);
})();