From 3680fd234af4f422d2f11d790471f18935020d08 Mon Sep 17 00:00:00 2001 From: Berat Nakip Date: Mon, 11 May 2020 18:25:38 +0300 Subject: [PATCH] JSON parse bugfix --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d225b67..de9c1f7 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ exports.getUserByUsername = username => ( $('body').children().each((i, e) => { eleHTML = $(e).html() if (eleHTML.indexOf('window._sharedData') > -1) { - resolve(JSON.parse(eleHTML.split('"ProfilePage":[')[1].split(']},"hostname"')[0]).graphql.user); + resolve(JSON.parse(eleHTML.substring(21).slice(0, -1)).entry_data.ProfilePage[0].graphql.user); return false; } }) @@ -36,7 +36,7 @@ exports.getUserIdFromUsername = username => ( $('body').children().each((i, e) => { eleHTML = $(e).html(); if (eleHTML.indexOf('window._sharedData') > -1) { - resolve(JSON.parse(eleHTML.split('"ProfilePage":[')[1].split(']},"hostname"')[0]).graphql.user.id); + resolve(JSON.parse(eleHTML.substring(21).slice(0, -1)).entry_data.ProfilePage[0].graphql.user.id); return false; } }) @@ -168,7 +168,7 @@ exports.getUserProfilePicture = (username) => ( $('body').children().each((i, e) => { eleHTML = $(e).html() if (eleHTML.indexOf('window._sharedData') > -1) { - resolve(JSON.parse(eleHTML.split('"ProfilePage":[')[1].split(']},"hostname"')[0]).graphql.user.profile_pic_url_hd) + resolve(JSON.parse(eleHTML.substring(21).slice(0, -1)).entry_data.ProfilePage[0].graphql.user.profile_pic_url_hd); return false; } })