This is something I came up with because suggested some kind of automated poll evaluation for his "UPick the story" series. There he gives a couple of options to the people and asks them which one they would like to read about, then has to go through every comment and count them.
The idea is to filter all comments by a keyword so you will only have relevant comments and provide some additional informations about what users picked.
preparation
For getting all comments on a post there needs to be the author of the post and the permalink. In addition a keyword to search for in the comment is required.
I started creating a basic HTML file providing the input fields needed. Furthermore I added steem-js to access the data on the blockchain and jQuery for convenience with handling events. Finally some basic StyleSheet was added to neatly arrange all elements.
The result can be seen here.
JavaScript
After filling in all neccessary data the script has to
- get all comments to relevant post
- search the body of the comments for the keyword
- display comments where keyword is found
These actions will be triggered by clicking on the search link.
$('.button-search')
.click(function(){
var author = $('#search_author').val();
var permlink = $('#search_permlink').val();
var key = $('#search_key').val();
// get all comments on a post from the api
steem.api.getContentReplies(author, permlink, function(err, results) {
var showResults = results;
// if search key is set, filter resultss
if(key) {
showResults = [];
$(results)
.each(function() {
var comment = this;
var comment_body = comment['body'];
if (comment_body.toLowerCase().indexOf( key.toLowerCase() ) >= 0) {
showResults.push(comment);
}
});
}
var users = [];
var commentListHTML = '';
// iterate through comments to be displayed
// collect data, prepare html
$(showResults)
.each(function(){
// add user to the list
var user = this['author'];
if(!(user in users)) {
users.push(user);
}
// process comment data to html
commentListHTML += commentToHTML(this);
});
// evaluation of processed data
var evaluationHTML = evaluationToHTML(key, users);
var content = evaluationHTML + commentListHTML;
$('#content').html(content);
});
});
See full source on GitHub.
future development
Right now this is something I just wanted to do because I couldn't stop thinking about how it can be done. So to get it out of my system I had to sit down and write it. Feature development and polishing will take a lot more time than the couple of hours I put into this until now. I don't have a use case for this right now so no need for me to develop this any further, spending my time for something no one wants to use. However, if there are people out there which like to use this kind of tool I will happily continue working on it.
Additional features I can think of:
- additional informations about upvoting / resteeming on the post
- add multiple search keys, evaluating all your options in one go
- keyword highlighting
- handle users with multiple options
- charts
If you like to see these please say so. Also let me know which features you come up. What would make your life on steem easier?
graphic design
As you can see this is a really plain design of the page. It works but it could use someone who actually knows how to design a frontend like this. If this is something you can do please contact me. I value a good design so there won't be anything I want for free.
To get in touch please leave a comment or write a direct message on Discord @DerAsmo#9548.