Bug fix for permalinks

This commit is contained in:
Jesper Wrang 2017-11-02 00:27:27 +01:00
parent 1696d3c2ad
commit 92aad75ec7
3 changed files with 15 additions and 9 deletions

View file

@ -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: {

View file

@ -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"
var clientID = "";

View file

@ -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) {