create account

怎么用JS写个自动点赞程序? by ericet

View this thread on: hive.blogpeakd.comecency.com
· @ericet ·
$6.24
怎么用JS写个自动点赞程序?
<center>![image.png](https://files.steempeak.com/file/steempeak/ericet/tR4dcIIc-image.png)
(Image Source : [Pixabay](https://cdn.pixabay.com/photo/2013/07/12/13/50/smiley-147407_960_720.png))</center>

有没有好奇steemauto,steemrewarding的自动点赞是怎么实现的?

想不想自己写个属于自己的点赞程序?

其实理解原理这些点赞程序是很容易写的

steeemjs提供了一个点赞的function:

~~~
steem.broadcast.vote(postingKey, account, author, permlink, weight, function(err, result) {
    console.log(err, result);
});
~~~

只需填入相应的信息点赞程序就完成了。比如:
~~~
steem.broadcast.vote("发帖密钥", "账号", "ericet", "krwp-9zgk9bfvin", 10000, function(err, result) {
    console.log(err, result);
});
~~~

好了,点赞程序写完了。运行后会自动给我的帖子:https://steempeak.com/cn/@ericet/krwp-9zgk9bfvin 点个满赞。

是不是很简单?但是没啥实际用处。下面来添加一些功能,比如看到有新帖就自动点赞

在[上一篇](https://steempeak.com/cn/@ericet/js-nddsi4obip)里介绍过一个function:steem.api.streamTransactions。这个function会实时查看发布到区块链上的操作。

加上这个function和点赞的function就可以给所有新帖自动点赞了。

~~~
const steem = require("steem");
const steemid = 'steemid';
const postingKey = 'postingKey';

start();

function start() {
    steem.api.streamTransactions("head", function(err, result) {
        if (result &amp;&amp; !err) {
            let txType = result.operations[0][0];
            let txData = result.operations[0][1];
            if (txType == "comment" && txData.parent_author == '') {
		upvote(txData.author,txData.permlink);
	    }
        } else {
            console.log("Error found", err);
                start();
        }
    });
}

function upvote(author,permlink){
	steem.broadcast.vote(postingKey, steemid, author, permlink, 10000, function(err, result) {
    		console.log(err, result);
	});

}

~~~

再加个新功能,点赞后自动留言:

~~~
const steem = require("steem");
const steemid = 'steemid';
const postingKey = 'postingKey';

start();

function start() {
    steem.api.streamTransactions("head", function(err, result) {
        if (result &amp;&amp; !err) {
            let txType = result.operations[0][0];
            let txData = result.operations[0][1];
            if (txType == "comment" && txData.parent_author == '') {
		upvote(txData.author,txData.permlink);
		reply(author,permlink);
	    }
        } else {
            console.log("Error found", err);
                start();
        }
    });
}

function upvote(author,permlink){
	steem.broadcast.vote(postingKey, steemid, author, permlink, 10000, function(err, result) {
    		console.log(err, result);
	});

}
function reply(author,permlink){
	const timeStr = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '');
    	const newParentPermlink = txData.parent_permlink.replace(/(-\d{8}t\d{9}z)/g, '');
    	var replyPermlink = 're-' + txData.author.replace(/\./g, '') + '-' + txData.permlink + '-' + new Date().toISOString().replace(/-|:|\./g, '').toLowerCase();
    steem.broadcast.comment(
        postingKey,
        author,
        permlink,
        steemid,
        replyPermlink ,
        "",
        "HELLO!",
        '{"app":"test"}',
        function(err, result) {
            console.log(err, result);
        });


}

~~~

运行后,会自动点赞新帖并且给予“HELLO”的回复。

**特别说明,这个程序没有考虑任何点赞时机和调整点赞比例,如果你真要运行这个程序,做好VP被抽干,回复被踩,没有任何审查收益的心理准备。**

这个程序只作为参考,你可以调整一下点赞比例,点赞时机后会是一个不错的赚审查机器人。
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 613 others
properties (23)
authorericet
permlinkjs
categorycn
json_metadata{"tags":["cn","cn-reader","whalepower","cn-stem","steem-guides","steemstem","cn-programming","build-it","esteem","esteem-cn","palnet","zzan","mediaofficials","actnearn","marlians","neoxian","lassecash","upfundme","sct","sct-cn","sct-freeboard"],"image":["https://files.steempeak.com/file/steempeak/ericet/tR4dcIIc-image.png"],"links":["https://cdn.pixabay.com/photo/2013/07/12/13/50/smiley-147407_960_720.png","https://steempeak.com/cn/@ericet/krwp-9zgk9bfvin","https://steempeak.com/cn/@ericet/js-nddsi4obip"],"app":"esteem/2.2.1-mobile","format":"markdown","community":"esteemapp"}
created2019-09-16 14:18:30
last_update2019-09-16 14:18:30
depth0
children11
last_payout2019-09-23 14:18:30
cashout_time1969-12-31 23:59:59
total_payout_value2.979 HBD
curator_payout_value3.262 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,147
author_reputation195,650,625,080,393
root_title怎么用JS写个自动点赞程序?
beneficiaries
0.
accountesteemapp
weight1,000
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,632,373
net_rshares18,096,578,122,345
author_curate_reward""
vote details (677)
@build-it.assist ·
Hi, @ericet!

Thank you for using the #build-it tag. This post has been rewarded by @build-it.curator with BUILD tokens in the form of an upvote. [Build-it](https://www.build-it.io/trending) is a new tribe on the steem blockchain that serves as a central hub for DIY contents on steemit. 

We encourage steemians to post their DIY articles via our [website.](https://www.build-it.io/trending) Have a question? Join us on [Discord](https://discord.gg/XW5ER8E) and [telegram](https://t.me/build_it_diy)

This project is run and supported by our witness [@gulfwaves.net](https://steempeak.com/@gulfwaves.net). If you like what we do, [vote for us as a witness](https://steemconnect.com/sign/account-witness-vote?witness=gulfwaves.net&approve=1) on the steem blockchain.
properties (22)
authorbuild-it.assist
permlinkpxyx9v
categorycn
json_metadata{"tags":["cn","build-it"],"users":["ericet","build-it.curator"],"links":["https://www.build-it.io/trending","https://discord.gg/XW5ER8E","https://t.me/build_it_diy","https://steempeak.com/@gulfwaves.net","https://steemconnect.com/sign/account-witness-vote?witness=gulfwaves.net&approve=1"],"app":"buildit/0.1"}
created2019-09-17 09:05:57
last_update2019-09-17 09:05:57
depth1
children1
last_payout2019-09-24 09:05:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length766
author_reputation216,046,753,962
root_title怎么用JS写个自动点赞程序?
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,658,330
net_rshares0
@ericet ·
$0.02
thank you
👍  ,
properties (23)
authorericet
permlinkre-build-itassist-pxz7p7
categorycn
json_metadata{"tags":["cn"],"app":"steempeak/1.16.1"}
created2019-09-17 12:51:06
last_update2019-09-17 12:51:06
depth2
children0
last_payout2019-09-24 12:51:06
cashout_time1969-12-31 23:59:59
total_payout_value0.012 HBD
curator_payout_value0.011 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length9
author_reputation195,650,625,080,393
root_title怎么用JS写个自动点赞程序?
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,663,176
net_rshares111,090,447,698
author_curate_reward""
vote details (2)
@cnbuddy ·
你那里天气如何?新人吗?[《steemit指南》](http://steemh.org/)拿一份吧,以免迷路; 另外一定要去 @team-cn 的新手村看看,超级热闹的大家庭。倘若你想让我隐形,请回复“取消”。
properties (22)
authorcnbuddy
permlinkre-ericet-js-20190916t144340745z
categorycn
json_metadata""
created2019-09-16 14:43:42
last_update2019-09-16 14:43:42
depth1
children0
last_payout2019-09-23 14:43:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length105
author_reputation-1,449,160,991,441
root_title怎么用JS写个自动点赞程序?
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,633,095
net_rshares0
@esteemapp ·
Thanks for using **eSteem**! <br>Your post has been voted as a part of [eSteem encouragement program](https://steemit.com/esteem/@good-karma/encouragement-program-continues-82eafcd10a299). Keep up the good work! Install [Android](https://play.google.com/store/apps/details?id=app.esteem.mobile.android), [iOS](https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=1451896376&mt=8) Mobile app or [Windows, Mac, Linux](https://github.com/esteemapp/esteem-surfer/releases) Surfer app, if you haven't already!<br>Learn more: https://esteem.app <br>Join our discord: https://discord.gg/8eHupPq
properties (22)
authoresteemapp
permlinkre-2019916t1626363z
categorycn
json_metadata{"tags":["esteem"],"app":"esteem/2.0-welcome","format":"markdown+html","community":"esteem.app"}
created2019-09-16 14:26:36
last_update2019-09-16 14:26:36
depth1
children0
last_payout2019-09-23 14:26:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length601
author_reputation420,443,679,514,793
root_title怎么用JS写个自动点赞程序?
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,632,595
net_rshares0
@inaction ·
加油!@ericet,
来自鸽子在Marlians的支持。
👍  
properties (23)
authorinaction
permlinkre-js-20190916t143626z
categorycn
json_metadata"{"app": "rewarding/0.1.5"}"
created2019-09-16 14:36:27
last_update2019-09-16 14:36:27
depth1
children0
last_payout2019-09-23 14:36:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length30
author_reputation98,894,156,169
root_title怎么用JS写个自动点赞程序?
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,632,899
net_rshares2,545,578
author_curate_reward""
vote details (1)
@steemstem ·
re-ericet-js-20190918t200321455z
<div class='text-justify'> <div class='pull-left'> <center> <br /> <img width='200' src='https://res.cloudinary.com/drrz8xekm/image/upload/v1553698283/weenlqbrqvvczjy6dayw.jpg'> </center>  <br/> </div> 

This post has been voted on by the **SteemSTEM curation team** and voting trail. It is elligible for support from @curie and @minnowbooster.<br /> 

If you appreciate the work we are doing, then consider supporting our witness [@stem.witness](https://steemconnect.com/sign/account_witness_vote?approve=1&witness=stem.witness). Additional witness support to the [curie witness](https://steemconnect.com/sign/account_witness_vote?approve=1&witness=curie) would be appreciated as well.<br /> 

For additional information please join us on the [SteemSTEM discord]( https://discord.gg/BPARaqn) and to get to know the rest of the community!<br />

Please consider using the <a href='https://www.steemstem.io'>steemstem.io</a> app and/or including @steemstem in the list of beneficiaries of this post. This could yield a stronger support from SteemSTEM.
properties (22)
authorsteemstem
permlinkre-ericet-js-20190918t200321455z
categorycn
json_metadata{"app":"bloguable-bot"}
created2019-09-18 20:03:33
last_update2019-09-18 20:03:33
depth1
children0
last_payout2019-09-25 20:03:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,050
author_reputation262,017,435,115,313
root_title怎么用JS写个自动点赞程序?
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,708,434
net_rshares0
@wherein ·
加油!村长
👍  
properties (23)
authorwherein
permlinkpxyd6i
categorycn
json_metadata{"tags":["cn","palnet","zzan","mediaofficials","actnearn","marlians","neoxian","lassecash","upfundme","sct","sct-cn","sct-freeboard"],"app":"steemcn/0.1"}
created2019-09-17 01:51:54
last_update2019-09-17 01:51:54
depth1
children1
last_payout2019-09-24 01:51:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5
author_reputation57,671,186,137,282
root_title怎么用JS写个自动点赞程序?
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,649,508
net_rshares24,383,847
author_curate_reward""
vote details (1)
@ericet ·
谢谢

Posted using [Partiko iOS](https://partiko.app/referral/ericet)
👍  
properties (23)
authorericet
permlinkericet-re-wherein-pxyd6i-20190917t015548823z
categorycn
json_metadata{"app":"partiko","client":"ios"}
created2019-09-17 01:55:48
last_update2019-09-17 01:55:48
depth2
children0
last_payout2019-09-24 01:55:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length67
author_reputation195,650,625,080,393
root_title怎么用JS写个自动点赞程序?
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,649,577
net_rshares692,371,411
author_curate_reward""
vote details (1)
@yellowbird · (edited)
程序就是 天书 😳
👍  
properties (23)
authoryellowbird
permlinkyellowbird-re-ericet-js-20190916t142650485z
categorycn
json_metadata{"app":"partiko","client":"android"}
created2019-09-16 14:26:51
last_update2019-09-16 14:27:06
depth1
children1
last_payout2019-09-23 14:26:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length9
author_reputation117,611,750,601,828
root_title怎么用JS写个自动点赞程序?
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,632,603
net_rshares14,093,595
author_curate_reward""
vote details (1)
@ericet ·
其实和学外语一样,知道基本语法就可以写了。
👍  
properties (23)
authorericet
permlinkre-yellowbird-pxxi3u
categorycn
json_metadata{"tags":["cn"],"app":"steempeak/1.16.1"}
created2019-09-16 14:40:42
last_update2019-09-16 14:40:42
depth2
children0
last_payout2019-09-23 14:40:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length21
author_reputation195,650,625,080,393
root_title怎么用JS写个自动点赞程序?
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,633,019
net_rshares117,086,733
author_curate_reward""
vote details (1)
@yysb ·
加油!@ericet
鸽子在mediaofficials支持你。
👍  
properties (23)
authoryysb
permlinkre-js-20190916t143833z
categorycn
json_metadata"{"app": "rewarding/0.1.5"}"
created2019-09-16 14:38:33
last_update2019-09-16 14:38:33
depth1
children0
last_payout2019-09-23 14:38:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length33
author_reputation96,341,621,268
root_title怎么用JS写个自动点赞程序?
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,632,956
net_rshares2,593,749
author_curate_reward""
vote details (1)