[Javascript] アカウントヒストリーを表示してみました。

in Steem Japan5 years ago (edited)

こんにちは、@yasuです。

今回は、「steem.api.getAccountHistory」を使用しました。

いろいろな操作を確認できます。

直近の100件を表示しています。

これまでの他の関数とは違って、古い順に取得するので、順番を反転しました。

実行方法

https://ojagggyo.github.io/steemitapi/getaccounthistory.html
https://ojagggyo.github.io/steemitapi/getaccounthistory.0.1.html

実行結果

image.png

ソース

html

<!doctype html>
<html lang="en">
    <head>
        <title>getaccounthistory</title>
        <meta charset="utf-8">
        <script src="https://github.com/steemit/steem-js/releases/download/v0.7.7/steem.min.js"></script>
        <script src="https://ojagggyo.github.io/steemitapi/getaccounthistory.js"></script>
    </head>
    <body>        
        <p>アカウントヒストリーを表示します。</p>
    <input type="text" id="text1" size="20" value=yasu> <input type="button" value="表示する" onclick="clickBtn()" />
    <a id="progress"></a>
        <br/>
        <span id="text"></span>
    </body>
</html>

javascript
steem.api.setOptions({url: 'https://api.steemit.com'})

function donokuraimae(date){
    date1 = new Date(date);
    date1.setHours(date1.getHours() + 9);
    var now = new Date();
    sa = now - date1;
    if(sa >= 86400000){return Math.floor(sa / 86400000)+'日前';}
    if(sa >= 3600000){return Math.floor(sa / 3600000)+'時間前';}
    if(sa >= 60000){return Math.floor(sa / 60000)+'分前';}
    if(sa >= 1000){return Math.floor(sa / 1000)+'秒前';}
    return 'たった今';
}
        
function makeTable(records){
    html = '<table border=1 >';
    //テーブルのヘッダー
    html = html + '<tr>';
    html = html + '<th>timestamp</th><th>no</th><th>op</th><th></th>';
    html = html + '</tr>';
    //for(var i=0;i<records.length;i=i+1){
    for(var i=records.length-1;i>=0;i=i-1){
        html = html + '<tr>';
        html = html + '<td align=right>' + donokuraimae(records[i][1].timestamp) + '</td>';
        html = html + '<td>' + records[i][0] + '</td>';
        html = html + '<td>' + records[i][1].op[0] + '</td>';
        html = html + '<td>' + JSON.stringify(records[i][1].op[1]) + '</td>';
        html = html + '</tr>';
    }
    html = html + '</table>';
    document.getElementById("text").innerHTML = html;
}
        
async function aaa(){
    let out = [];
    let limit = 10;
    let lastlength = limit;
    let firstValue = -1;
    let author = document.getElementById("text1").value;
    while (firstValue != 0 && out.length < 100){    
        if(firstValue != -1 && firstValue < limit) limit = firstValue;//limitより小さいfirstValueでエラーになる問題の対応。
        let ret = await steem.api.getAccountHistoryAsync(author, firstValue, limit);
        firstValue = ret[0][0];
        ret.shift();
        lastlength = ret.length;
        out = ret.concat(out);
    }
    return out;
};

function clickBtn(){
    aaa().then(result => {      
        makeTable(result);
    }).catch(err => {
    });
}

参考

https://github.com/steemit/steem-js/tree/master/doc#get-account-history


ありがとうございました。

steemit サインアップ
https://ojagggyo.github.io/steemitsignup

steemit 知識
https://ojagggyo.github.io/steemittips

日本語 Steemit Discord (超初心者~誰でも)
https://discord.gg/zKJgfzS

image.png

Sort:  
 5 years ago 

@yasu さん、こんにちは。

image.png
Steemitチームがアップボートしてくれるので #steemexclusive のタグ、 パワーアップしたときは #club5050 のタグを使って下さい。
Power Up and use #club5050 #steemexclusive for more upvotes from Steemit team.
How to use #steemexclusive 使い方
How to use #club5050 使い方

💡 Curation Guide (アップボートガイド) 💡

  • Post about Japan (Japanese or English)
  • Set 10~30% reward to japansteemit
  • No upvote if you power down 100%
  • Upvote community posts
  • Follow our Curation Trail HERE
  • Delegate SP 100 SP 500 SP 1000 SP 2000 SP

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.083
BTC 60975.16
ETH 1569.36
USDT 1.00
SBD 0.47