Wolfar / Buffs

// ==UserScript==
// @namespace    https://openuserjs.org/users/Wolfar
// @name         Buffs
// @version      0.0.0
// @description  Show Buffs time in profile page
// @include      https://*.e-sim.org/profile.html*
// @license      MIT
// @grant        none
// ==/UserScript==

// ==OpenUserJS==
// @author Wlfar
// ==/OpenUserJs==

if(document.querySelector('strong').innerHTML === "Buffs" || document.querySelector('strong').innerHTML === "Debuffs" ) {
    let server = window.location.host.split('.')[1] ? window.location.host.split('.')[0] : false;
    let parent = document.querySelector('.profile-row');
    let username = document.querySelector('.big-login').innerHTML;
    let text = document.createElement('a');
    parent.appendChild(text);
    fetch('https://e-sim-api.herokuapp.com/https:/'+ server + '.e-sim.org/buffs.html', {
        mode: 'cors',
        method: 'get',
        dataType: 'json'
    }).then(function (response) {
        return response.json();
    }).then(function (response) {
        for(let i=0; i < response.length; i++) {
            if(response[i].nick === username) {
            text.innerHTML = "debuff ends: " + response[i].debuff_ends + "\n buffed at: " + response[i].buffed_at;
            }
        }
    }).catch(function (error) {
        console.error(error);
    })
}