The KE Ratio on PeakD with Tampermonkey - Just a Prototype

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@louis88·
102.997 HBD
The KE Ratio on PeakD with Tampermonkey - Just a Prototype
Maybe some of you on HIVE have seen it before, there’s something called a KE Ratio for every account. It shows how much a user has earned from author rewards plus curation rewards over time. If you divide this total by the user's current Hive Power, you get the KE Ratio. It’s a small but interesting number that shows how efficiently someone is using their stake.

Some more details about this were shared by @azircon a while ago, and there’s even a cool tool where you can check your own value at: https://beebalanced.streamlit.app.

Today I saw someone asking about it in the Hive Chat, so I thought why not build a small prototype? And that’s what this is. A simple Tampermonkey script that shows the KE Ratio directly on PeakD.com, next to the reputation number of each user in your feed. It works like this: for every user shown in the post list, the script makes a request to the API by @techcoderx, gets the author rewards, curation rewards, and Hive Power, calculates the ratio, and then shows it nicely beside the reputation.

### Current Trending - Some Screenshots of the Result

<div class="pull-left"><div class="text-justify">

![image.png](https://files.peakd.com/file/peakd-hive/louis88/23swkXpNuuPvnJctTE5HrVtZuFiw3Fg8yDKQpLnNyKj5taZgCwGZm89dSTdQRrfEDZ1i9.png)

</div></div>
<div class="pull-right"><div class="text-justify">

![image.png](https://files.peakd.com/file/peakd-hive/louis88/23tkjqVTUMPgXVApYFQLZNADN5UCGf3V3AhCzhRwH98X1KXdFiiKLZkqyEPqm6gvMS5r3.png)

</div></div>

---

<div class="pull-left"><div class="text-justify">

![image.png](https://files.peakd.com/file/peakd-hive/louis88/23wBfr9rfLx6FKyVyD45bRgQzUcTjfB2LCL3Giu38rNfgrMPnWeWhRYMUeUsjTHB5xy7G.png)

</div></div>
<div class="pull-right"><div class="text-justify">

![image.png](https://files.peakd.com/file/peakd-hive/louis88/23u5VNzpTvnjK1qzwGbB5Ekr8QiAeiDmKCWAuUE4NrCxte4BaoRVYjef1CXJKjLyUjLj5.png)

</div></div>

---


### The Tampermonkey Script

```
// ==UserScript==
// @name         PeakD KE-Ratio Viewer (Styled)
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Display KE-Ratio on PeakD next to user reputation label with consistent styling and tooltip
// @author       louis88
// @match        https://peakd.com/*
// @grant        GM_xmlhttpRequest
// @connect      techcoderx.com
// @run-at       document-end
// ==/UserScript==

(function () {
  'use strict';

  const KE_CACHE = {};

  function getUsernameFromHref(href) {
    const match = href.match(/\/@([\w\-.]+)/);
    return match ? match[1] : null;
  }

  function calculateKERatio(data) {
    const posting = parseFloat(data.posting_rewards) / 1000;
    const curation = parseFloat(data.curation_rewards) / 1000;
    const vesting = parseFloat(data.vesting_balance) / 1000;
    if (vesting === 0) return null;
    return ((posting + curation) / vesting).toFixed(2);
  }

  function fetchKE(username, callback) {
    if (KE_CACHE[username]) {
      callback(KE_CACHE[username]);
      return;
    }

    GM_xmlhttpRequest({
      method: 'GET',
      url: `https://techcoderx.com/hafbe-api/accounts/${username}`,
      onload: function (response) {
        try {
          const json = JSON.parse(response.responseText);
          const ke = calculateKERatio(json);
          KE_CACHE[username] = ke;
          callback(ke);
        } catch (e) {
          console.error("KE parse error", e);
          callback(null);
        }
      },
      onerror: function () {
        console.error("Failed to fetch KE data for", username);
        callback(null);
      }
    });
  }

  function insertKELabel(container, keRatio) {
    if (!keRatio) return;

    const label = document.createElement("span");
    label.textContent = `KE: ${keRatio}`;
    label.classList.add("label");
    label.title = "KE Ratio = (Author Rewards + Curation Rewards) / HP";

    // Match PeakD visual style a bit
    label.style.display = "inline-block";
    label.style.padding = "4px 6px 4px 6px";
    label.style.fontSize = "95%";
    label.style.fontWeight = "500";
    label.style.color = "#fff";
    label.style.backgroundColor = "#313437"; // Muted dark gray
    label.style.borderRadius = "0.25em";
    label.style.marginLeft = "6px";
    label.style.lineHeight = "1";
    label.style.verticalAlign = "baseline";
    label.style.whiteSpace = "nowrap";
    label.style.textAlign = "center";
    label.style.textTransform = "uppercase";
    label.style.letterSpacing = ".1px";

    container.appendChild(label);
  }

  function processUsers() {
    const userLinks = document.querySelectorAll('a[href^="/@"]');
    userLinks.forEach(link => {
      const username = getUsernameFromHref(link.getAttribute("href"));
      if (!username) return;

      const repLabel = link.parentElement?.querySelector(".reputation-label");
      if (!repLabel || repLabel.dataset.keInjected) return;

      repLabel.dataset.keInjected = "true";
      fetchKE(username, (ke) => {
        insertKELabel(repLabel.parentElement, ke);
      });
    });
  }

  // Initial run
  processUsers();

  // Run again on DOM changes (dynamic content)
  const observer = new MutationObserver(() => {
    processUsers();
  });

  observer.observe(document.body, { childList: true, subtree: true });
})();
```

To try it yourself, just install Tampermonkey on https://www.tampermonkey.net, copy the script into a new userscript, and visit PeakD. It will load automatically for each user you see in the normal Feeds.

That’s all for now. It’s just a prototype, but it works. Maybe I’ll add more features later like color coding or sorting, but for now, it does exactly what it needs to: show the KE Ratio live on PeakD.

More Reads about the KE-Ratio: https://peakd.com/@azircon/ke-ratio-as-a-guide


--- 

<div class="pull-left"><div class="text-justify">

[![image.png](https://files.peakd.com/file/peakd-hive/louis88/23v4Zbq5TQyn3aFGQ7YcUyQJQCHhh556WQfTgmeR6EtVe1RWUURNc89oCX25ZFnUHAXww.png)](https://vote.hive.uno/@louis.witness)

##### Vote for my Hive Witness
U can vote for my Witness using Hive Keychain here:  https://vote.hive.uno/@louis.witness

</div></div>
<div class="pull-right"><div class="text-justify">


[![image.png](https://files.peakd.com/file/peakd-hive/louis88/24241zs2F4mEKWwVa9y2CkqHjUcR7Rh2EyRQEXZA5vfHdjEMnq8Ej8R4cWxT1jgAtXQHP.png)](https://primersion.com/he-witnesses)

##### Vote for my Hive Engine Witness

Vote for my Witness on Hive-Engine using Primersion Tool: https://primersion.com/he-witnesses <sup>Enter your Username and search for louis.witness</sup>
</div></div>
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,