SteemIt: Javascript Function to Get Original Post from Comment's PermLink - 如何从评论的 PermLink 得到原文的链接?
Image Credit: Pixabay.com
@nationalpark suggests me add 'original post URL' in my tool: SteemIt Tool to Recover Deleted Comments/Posts , and here is the way that a permlink for a comment is organized.
For example,
re-tvb-re-justyy-re-tvb-45qr3w-20171011t144205534z
If we split the permlink string by '-', the last group is obviously the timestamp which we can discard. The rest are in the form of 're-author' where the last group is the original author.
We can split the string and handle the logics straightforward, but the best way is to use the regular expression to match this pattern. The following is the Javascript script function that does the job.
var restore = function(url) {
var pat = /(re-\w+-)*((\w+\-)*)/g;
var my = pat.exec(url);
if (my[1] && my[2]) {
var author = my[1].split('-')[1];
var link = my[2].slice(0, -1);
return 'https://steemit.com/@' + author + '/' + link;
}
return null;
}
For example,
console.log("re-tvb-re-justyy-re-tvb-45qr3w-20171011t144205534z");
The original steemit post URL is given:
"https://steemit.com/@tvb/45qr3w"
Image Credit: Pixabay.com
昨天, @nationalpark 建议在我那工具: Steemit 查看被删除的评论 里加上原文的链接,并且告诉我如何从评论的 permlink 得到原文的链接,比如:
re-tvb-re-justyy-re-tvb-45qr3w-20171011t144205534z
如果把字符串以 连接符 - 分组,那么最后一个显示是时间 (timestamp), 评论会以 re-作者- 这种方式连接,而最后一组re-tvb 中表示 tvb 是作者, 然后 justyy 回复了,然后 tvb 又回复了。
我们可以写一个函数用 split 分组然后再依次处理,但是有点麻烦,最简单的方法就是按正则表达式,\w 匹配字母, () 取得分组, * 表示匹配0个或多个, + 匹配1个或多个.
用 Javascript 来写就是:
var restore = function(url) {
var pat = /(re-\w+-)*((\w+\-)*)/g;
var my = pat.exec(url);
if (my[1] && my[2]) {
var author = my[1].split('-')[1];
var link = my[2].slice(0, -1);
return 'https://steemit.com/@' + author + '/' + link;
}
return null;
}
比如:
console.log("re-tvb-re-justyy-re-tvb-45qr3w-20171011t144205534z");
输出STEEMIT原文链接:
"https://steemit.com/@tvb/45qr3w"
@justyy 是 https://justyy.com 的博主,在 @tumutanzi 大哥 的介绍下加入 STEEMIT,写些帖子挣些小钱养家糊口。
@justyy 也是CN 区的点赞机器人,对优质内容点赞,只要代理给 @justyy 每天收利息(年化率14.6%)并能获得一次至少2倍(VP 200%+)的点赞,大鱼 @htliao 都加入了这个计划(530 SP)表示支持。
如何从评论的 PermLink 得到原文的链接(Javascript)?
Get Original Post from Comment’s PermLink
Steemit 在线工具和API接口
SteemIt Tools and APIs
我又变成了道具哈哈
姐,赶紧去睡觉,女人养颜美容是很重要的
@eileenbeach has voted on behalf of @minnowpond. If you would like to recieve upvotes from minnowponds team on all your posts, simply FOLLOW @minnowpond.