diff --git a/static/functions.js b/static/functions.js index b052ad2..7bd6fc0 100644 --- a/static/functions.js +++ b/static/functions.js @@ -36,6 +36,7 @@ return { init: init, subreddit: window.location.pathname.split("/")[2], threadID: window.location.pathname.split("/")[4], + permalink: window.location.pathname.split("/")[6], fetchToken: function() { return fetch("https://www.reddit.com/api/v1/access_token", { headers: { diff --git a/static/id.js b/static/id.js index 10a4b5b..ecf94f0 100644 --- a/static/id.js +++ b/static/id.js @@ -1,3 +1,3 @@ // Change this to your own client ID: https://www.reddit.com/prefs/apps // The app NEEDS TO BE an installed app and NOT a web apps -var clientID = "YSidAws9twqCZg" \ No newline at end of file +var clientID = ""; \ No newline at end of file diff --git a/static/thread.js b/static/thread.js index 2228df5..2a0d105 100644 --- a/static/thread.js +++ b/static/thread.js @@ -130,13 +130,18 @@ return { setTotalComments: function(total) { totalComments = total; }, getRoot: function() { - if(window.location.pathname.split("/").length >= 7) { - if(window.location.pathname.split("/")[6] !== "") { - return window.location.pathname.split("/")[6]; - } - } - - return Reddit.threadID; + if(Reddit.permalink !== undefined && Reddit.permalink === "") { + return Reddit.threadID; + } + + if(Reddit.permalink === undefined) { + return Reddit.threadID; + } + + if(_.has(Comments.lookup, Reddit.permalink)) { + return Comments.lookup[Reddit.permalink].parent_id.split("_")[1]; + } + return ""; }, generate: function(removedComments) { removedComments.forEach(function(comment){ @@ -320,7 +325,7 @@ var ThreadHTML = (function(){ return Comments.lookup[id].score; }); - var createdComments = [Reddit.threadID]; + var createdComments = [Comments.getRoot()]; var didSomething = false; while(commentsToCreate.length > 0) {