Chrome browser plugin for showing Steemit voting power

in #utopian-io6 years ago (edited)

Repository

https://github.com/AnatoliyStrizhak/steemit/tree/master/voting_power

Introduction

Hello, everybody. I know that there are enough services to learn your Voting Power, for example steemd.com or busy.org, but I like the usual Steemit interface (in night mode), so I decided to make my own chrome browser plugin wich embeds votting battery in top menu of steemit.com

Some details

The heart of the plug-in was the js library steem-js. I think it does not need a presentation.

The algorithm of operation is quite simple. When switching to steemit.com, an additional element with Id pwr is created by plugin in the top menu and the function get_pwr is called, which refers to api steemit via steem.js.

if(location.hostname.match(/steemit.com/i) && document.getElementById("content") && document.getElementsByClassName("small-7 large-4 columns Header__buttons"))
{
    var node = document.createElement("div");
    node.id = "pwr";
    node.innerHTML = "<img src="+bat1+" id='pwr_img' style='height:20px! important; margin-left:10px;' title=''&rt;";
    document.getElementsByClassName("small-7 large-4 columns Header__buttons")[0].appendChild(node);
    get_pwr();
}

Depending on the voting power level, the corresponding image of the battery is substituted (bat1, bat2, bat3). The images themselves are stored in variables as base64 strings.

function get_pwr()
{
    steem.api.getAccounts(['astrizak'], function(err, response){
        var res=response[0]['voting_power']/100;

        if(res<60) {document.getElementById('pwr_img').src = bat3;}

        if(res>70){document.getElementById('pwr_img').src = bat2;}

        if(res>90){document.getElementById('pwr_img').src = bat1;}

        document.getElementById('pwr_img').title = res+"%";
    });
}

In addition, for the created pwr element, the plugin adds a click event handler and when you click on the battery image, the function get_pwr is called again, to update the voting power status.

document.addEventListener('click', function(e) {
    var target = e.target
    currentItem = target.parentElement;
    if (currentItem.id == "pwr")
    {
        get_pwr();
    }
}, false);

To install the plugin, it is enough to save the contents of the repository. Next, you need to change the username of steemit user in the function get_pwr in steem api call ( steem.api.getAccounts (['astrizak'] ).

Then go to the browser menu Extensions, click "Load Unpacked extension" and specify the location of the plug-in. Well, in addition, you can select the option "Hide from toolbar", since the icon in the browser panel does not carry any load (for now).

shot2.png

That's all. The code is very simple. Anyone who wants to use my solution can easily modify it for his own needs.

In future, I plan to add automatic voting power status updates and maybe will add some sort of config menu to enter username and vp status thresholds.

Thanks for reading. I will be happy if my work is useful to someone.

Resources

https://github.com/steemit/steem-js

Sort:  

Thank you for the contribution and the extension. It's simple yet effective.

First, you don't have to use "Introduction" and "Post Body" headers, and I don't suggest using. Instead, it's better to use relevant headers for each section of your post.

And I think that this extension might be improved significantly in the future. Besides automatic updating, maybe you can create a dropdown menu and add information related with VP inside. In example, time to recover and last upvotes would be great features.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks for your review, Roj. You right, formating is not my superpower, but I'll try to fix it in next post.

@resteemator is a new bot casting votes for its followers. Follow @resteemator and vote this comment to increase your chance to be voted in the future!

Hey @astrizak
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.29
TRX 0.11
JST 0.031
BTC 68465.88
ETH 3766.15
USDT 1.00
SBD 3.66