SteemIt: Javascript Function to Get Original Post from Comment’s PermLink


JS SteemIt: Javascript Function to Get Original Post from Comment's PermLink javascript SteemIt

NodeJs / Javascript

@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 time stamp 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.

1
2
3
4
5
6
7
8
9
10
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;
}
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,

1
console.log("re-tvb-re-justyy-re-tvb-45qr3w-20171011t144205534z");
console.log("re-tvb-re-justyy-re-tvb-45qr3w-20171011t144205534z");

The original steemit post URL is given:

"https://steemit.com/@tvb/45qr3w"

You may also like: SteemIt: 如何从评论的 PermLink 得到原文的链接(Javascript)?

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
310 words
Last Post: SteemSQL Tutorial - What are the Outgoing Votes for Big Whales?
Next Post: R Tutorial - Connecting to STEEMSQL

The Permanent URL is: SteemIt: Javascript Function to Get Original Post from Comment’s PermLink

Leave a Reply