mirror of
https://github.com/gurnec/removeddit.git
synced 2026-03-11 08:54:27 +00:00
Removerd old javascript template files
This commit is contained in:
parent
0fb3db9e84
commit
1a1715a983
10 changed files with 0 additions and 531 deletions
|
|
@ -1,17 +1,3 @@
|
|||
|
||||
// HTML parsing
|
||||
const HTML = (function () {
|
||||
return {
|
||||
parse(htmlString) {
|
||||
const tmpDiv = document.createElement('div')
|
||||
tmpDiv.innerHTML = htmlString
|
||||
return tmpDiv.childNodes.length === 0 ? '' : tmpDiv.childNodes[0].nodeValue
|
||||
},
|
||||
main: document.getElementById('main'),
|
||||
}
|
||||
}())
|
||||
|
||||
|
||||
// UTC time handling, very usefull when dealing with elasticsearch
|
||||
var Time = (function () {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
let app = (function () {
|
||||
return {
|
||||
loadPage() {
|
||||
Status.loading("Loading subreddit...");
|
||||
document.title = Reddit.isAll ? "all subreddits" : Reddit.subreddit;
|
||||
HTML.main.innerHTML += _.templates.subredditInfo({subreddit: Reddit.subreddit, time: Vars.time});
|
||||
|
||||
var urlData = {
|
||||
subreddit: Reddit.subreddit,
|
||||
time: Time.difference(Vars.time),
|
||||
page: Vars.page,
|
||||
postPerPage: Vars.postPerPage
|
||||
};
|
||||
|
||||
Fetch2.get(ElasticSearch.threadURL+_.templates.elasticSubreddit(urlData), "Could not get removed posts")
|
||||
.then(Fetch2.json)
|
||||
.then(function(json){
|
||||
var startPostNr = (Vars.page - 1) * Vars.postPerPage + 1;
|
||||
|
||||
_.forEach(json.hits.hits, function(subreddit, i){
|
||||
HTML.main.innerHTML += _.templates.thread({thread: subreddit._source, postNr: startPostNr+i});
|
||||
});
|
||||
|
||||
var start = Math.max(Vars.page - 3, 1);
|
||||
var end = Math.min(start + 9, Math.ceil(json.hits.total/Vars.postPerPage));
|
||||
var urlBase = document.location.href.split("?")[0] + "?t=" + Vars.time + "&page=";
|
||||
HTML.main.innerHTML += _.templates.subredditPagination({start:start,end:end,currentPage:Vars.page,urlBase:urlBase});
|
||||
Status.success();
|
||||
})
|
||||
.catch(Fetch2.handleError);
|
||||
},
|
||||
}
|
||||
}());
|
||||
|
||||
206
js/thread.js
206
js/thread.js
|
|
@ -1,206 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
var app = (function(){
|
||||
return {
|
||||
loadPage: function() {
|
||||
Status.loading("Loading thread...");
|
||||
var urlData = {id: parseInt(Reddit.threadID, 36)};
|
||||
|
||||
Promise.all([
|
||||
Fetch2.get(ElasticSearch.threadURL+_.templates.elasticThread(urlData), "Could not get thread")
|
||||
.then(Fetch2.json)
|
||||
.then(function(json){
|
||||
HTML.main.innerHTML += _.templates.thread({thread: json.hits.hits[0]._source});
|
||||
return json;
|
||||
})
|
||||
.catch(Fetch2.handleError),
|
||||
|
||||
Fetch2.get(ElasticSearch.commentURL+_.templates.elasticComments(urlData), "Could not get removed comments")
|
||||
.then(Fetch2.json)
|
||||
.catch(Fetch2.handleError)
|
||||
])
|
||||
.then(function(promises){
|
||||
var commentData = {
|
||||
removedComments: promises[1].hits.total,
|
||||
totalComments: promises[0].hits.hits[0]._source.num_comments
|
||||
};
|
||||
|
||||
HTML.main.innerHTML += _.templates.threadInfo(commentData);
|
||||
Comments.addComments(promises[1]);
|
||||
Status.loading("Getting remaining comments...");
|
||||
})
|
||||
.then(function getRemainingComments() {
|
||||
return Fetch2.get(ElasticSearch.commentURL+_.templates.elasticCommentIDs({ids:Comments.missing}), "Could not get remaining comments")
|
||||
.then(Fetch2.json)
|
||||
.then(function(json){
|
||||
Comments.addComments(json);
|
||||
|
||||
if(Comments.missing.length !== 0) {
|
||||
return getRemainingComments();
|
||||
}
|
||||
});
|
||||
})
|
||||
.then(function(){
|
||||
// Make sure to get the permalink comment (even if it's not related to removed/deleted stuff)
|
||||
if(Comments.isPermalink && !_.includes(Comments.IDs, Comments.getRoot())) {
|
||||
var urlData = {ids: [Comments.to10(Comments.getRoot())]};
|
||||
return Fetch2.get(ElasticSearch.commentURL+_.templates.elasticCommentIDs(urlData), "Could not find the specific comment asked for")
|
||||
.then(Fetch2.json)
|
||||
.then(function(json){
|
||||
Comments.addComments(json);
|
||||
});
|
||||
}
|
||||
})
|
||||
.then(function(){
|
||||
HTML.main.innerHTML += '<div id="'+Reddit.threadID+'"></div>';
|
||||
Status.loading("Generating comments...");
|
||||
Comments.generate();
|
||||
Status.success();
|
||||
})
|
||||
.catch(Fetch2.handleError);
|
||||
}
|
||||
}})();
|
||||
|
||||
|
||||
var Comments = (function() {
|
||||
return {
|
||||
IDs: [], // The comments we found
|
||||
lookup: {},
|
||||
missing: [],
|
||||
isPermalink: (Reddit.permalink !== undefined && Reddit.permalink !== ""),
|
||||
|
||||
|
||||
|
||||
addComments: function(json){
|
||||
|
||||
Comments.IDs = _.union(Comments.IDs, _.map(json.hits.hits, function(comment){
|
||||
return Comments.to36(comment._id);
|
||||
}));
|
||||
|
||||
_.forEach(json.hits.hits, function(comment){
|
||||
comment._source.parent_id = _.isNil(comment._source.parent_id) ? Reddit.threadID : Comments.to36(comment._source.parent_id);
|
||||
Comments.lookup[Comments.to36(comment._id)] = comment._source;
|
||||
});
|
||||
|
||||
Comments.missing = _.reduce(json.hits.hits, function(array, comment){
|
||||
if(comment._source.parent_id !== Reddit.threadID && !_.includes(Comments.IDs, comment._source.parent_id)) {
|
||||
array.push(Comments.to10(comment._source.parent_id));
|
||||
}
|
||||
return array;
|
||||
}, []);
|
||||
},
|
||||
|
||||
getRoot: function() {
|
||||
if(Reddit.permalink !== undefined && Reddit.permalink !== "") {
|
||||
return Reddit.permalink;
|
||||
}
|
||||
|
||||
return Reddit.threadID;
|
||||
},
|
||||
|
||||
generate: function(){
|
||||
//console.log("asdf ",_.includes(Comments.ids, "dms36h7"))
|
||||
Comments.IDs = _.sortBy(_.uniq(Comments.IDs), function(id) {
|
||||
return Comments.lookup[id].score;
|
||||
});
|
||||
|
||||
var createdComments = [];
|
||||
|
||||
if(Comments.isPermalink) {
|
||||
var urlData = {
|
||||
id: Comments.permalink,
|
||||
comment: Comments.lookup[Reddit.permalink]
|
||||
}
|
||||
document.getElementById(Reddit.threadID).innerHTML += _.templates.comment(urlData);
|
||||
createdComments.push(Reddit.permalink);
|
||||
} else {
|
||||
createdComments.push(Reddit.threadID);
|
||||
}
|
||||
|
||||
var didSomething;
|
||||
|
||||
while(Comments.IDs.length > 0) {
|
||||
didSomething = false;
|
||||
|
||||
for(var i = Comments.IDs.length - 1; i >= 0; i--) {
|
||||
var id = Comments.IDs[i];
|
||||
var parentID = Comments.lookup[id].parent_id;
|
||||
|
||||
if(_.includes(createdComments, parentID)) {
|
||||
document.getElementById(parentID).innerHTML += (_.templates.comment({id:id, comment: Comments.lookup[id]}));
|
||||
createdComments.push(id);
|
||||
Comments.IDs.splice(i, 1);
|
||||
didSomething = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Fail safe (parents missing for the rest of the comments, shouldn't happend but oh well :D)
|
||||
if(!didSomething) {
|
||||
console.error("Didn't generate all comments correctly");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
/*
|
||||
|
||||
var ThreadHTML = (function(){
|
||||
// I actually haven't found a better way of doing this...
|
||||
// Imgur has image-links with no indication that they are actually images
|
||||
var imageHosts = ["i.redd.it", "flickr.com", "i.imgur.com", "imgur.com", "m.imgur.com"];
|
||||
|
||||
var createThread = function(data) {
|
||||
var thread = data[0].data.children[0].data;
|
||||
Comments.setTotalComments(thread.num_comments);
|
||||
document.title = thread.title+" : "+thread.subreddit;
|
||||
|
||||
var defaultThumbnails = ["self", "default", "image", "nsfw"];
|
||||
var thumbnail = '<a href="'+thread.permalink+'" class="thumbnail';
|
||||
if(thread.thumbnail === "") {
|
||||
thumbnail = "";
|
||||
} else if(_.includes(defaultThumbnails, thread.thumbnail)) {
|
||||
thumbnail += ' thumbnail-'+thread.thumbnail+'"></a>';
|
||||
} else {
|
||||
thumbnail += '"><img src="'+thread.thumbnail+'" width="'+(thread.thumbnail_width * 0.5)+'" height="'+(thread.thumbnail_height * 0.5)+'"></a>';
|
||||
}
|
||||
|
||||
var threadDiv = document.createElement("div");
|
||||
threadDiv.className = "thread";
|
||||
threadDiv.innerHTML = ' \
|
||||
<div class="thread-score-box"> \
|
||||
<div class="vote upvote"></div> \
|
||||
<div class="thread-score">'+Format.prettyScore(thread.score)+'</div> \
|
||||
<div class="vote downvote"></div> \
|
||||
</div>'+
|
||||
thumbnail+
|
||||
'<div class="thread-content"> \
|
||||
'+(thread.link_flair_text !== null ? '<span class="link-flair">'+thread.link_flair_text+'</span>' : '') +
|
||||
'<a class="thread-title" href="'+thread.url+'">'+thread.title+'</a> \
|
||||
<span class="domain">('+thread.domain+')</span> \
|
||||
<div class="thread-info"> \
|
||||
submitted <span class="thread-time">'+Format.prettyDate(thread.created_utc)+'</span> by \
|
||||
<a class="thread-author author" href="https://www.reddit.com/user/'+thread.author+'">'+thread.author+'</a> to \
|
||||
<a class="subreddit-link author" href="/r/'+thread.subreddit+'">/r/'+thread.subreddit+'</a> \
|
||||
</div>' +
|
||||
(thread.selftext !== '' ? '<div class="thread-selftext user-text">'+Format.parse(thread.selftext)+'</div>':'') +
|
||||
'<div class="total-comments"> \
|
||||
<a class="grey-link" href="'+thread.permalink+'"><b>'+thread.num_comments+' comments</b></a> \
|
||||
<a class="grey-link" href="https://www.reddit.com'+thread.permalink+'"><b>reddit</b></a> \
|
||||
</div>' +
|
||||
(thread.media !== null ? HTML.parse(thread.media_embed.content) : '') +
|
||||
(_.includes(imageHosts, thread.domain) && _.has(thread, "preview") ? '<a href="'+thread.url+'"><img class="thread-image" src="'+thread.preview.images[0].source.url+'"></a>' : '') +
|
||||
'</div> \
|
||||
';
|
||||
mainDiv.appendChild(threadDiv);
|
||||
return data;
|
||||
};
|
||||
|
||||
|
||||
|
||||
})();*/
|
||||
|
||||
if(isSupported) {
|
||||
app.loadPage();
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"query":{
|
||||
"ids":{
|
||||
"values":[<%= ids.join() %>]
|
||||
}
|
||||
},
|
||||
"_source":[
|
||||
"author","body","created_utc","parent_id","score"
|
||||
]
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"query":{
|
||||
"term":{
|
||||
"link_id":<%= id %>
|
||||
}
|
||||
},
|
||||
"_source":[
|
||||
"author","body","created_utc","parent_id","score"
|
||||
],
|
||||
"size":5
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
{
|
||||
"query":{
|
||||
"bool":{
|
||||
"must":[
|
||||
<% if(_.toLower(subreddit) !== "all") { %>
|
||||
{
|
||||
"term":{
|
||||
"subreddit":"<%= _.toLower(subreddit) %>"
|
||||
}
|
||||
},
|
||||
<% } %>
|
||||
{
|
||||
"range":{
|
||||
"created_utc":{
|
||||
"gt":<%= time %>
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"_source":[
|
||||
"author","url","subreddit","link_flair_text","score","title","created_utc","num_comments","domain","permalink","id","thumbnail","thumbnail_height","thumbnail_width"
|
||||
],
|
||||
"sort":[
|
||||
{"score":"desc"}
|
||||
],
|
||||
"from":<%= (page-1)*postPerPage %>,
|
||||
"size":<%= postPerPage %>
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"query":{
|
||||
"term":{
|
||||
"id":"<%= id %>"
|
||||
}
|
||||
},
|
||||
"_source":[
|
||||
"author","created_utc","domain","link_flair_text","num_comments","url","subreddit","score","title","selftext","permalink","thumbnail","thumbnail_height","thumbnail_width"
|
||||
],
|
||||
"size":1
|
||||
}
|
||||
|
|
@ -14,8 +14,3 @@ export const fetchComments = (commentIDs, auth) => (
|
|||
.then(results => results.data.children)
|
||||
.then(commentsData => commentsData.map(commentData => commentData.data))
|
||||
)
|
||||
|
||||
const debug = results => {
|
||||
console.log(JSON.parse(JSON.stringify(results)))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,182 +1,2 @@
|
|||
export { getPost } from './thread'
|
||||
export { getComments } from './comment'
|
||||
// Status.loading("Getting removed comments...");
|
||||
// HandleIDs.removed();
|
||||
// ThreadHTML.createCommentInfo(Comments.removed.length);
|
||||
// return Fetch2.multiple(URLs.format(URLs.pushshiftComments, Comments.removed), null, "data")
|
||||
// .catch(function(error){
|
||||
// return Promise.reject("Could not get removed comments");
|
||||
// });
|
||||
// })
|
||||
// .then(function(removedComments){
|
||||
// Status.loading("Generating comments...");
|
||||
// return Comments.generate(removedComments);
|
||||
// })
|
||||
// .then(function(){
|
||||
// Status.success();
|
||||
// })
|
||||
// .catch(function(error) {
|
||||
// if(_.includes(_.toLower(error), "error")) {
|
||||
// Status.error(error);
|
||||
// } else {
|
||||
// Status.error("Error: "+error);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }})();
|
||||
|
||||
// // ------------------------------------------------------------------------------
|
||||
// // ----------------------- Store and genrates comments --------------------------
|
||||
// // ------------------------------------------------------------------------------
|
||||
// var Comments = (function() {
|
||||
// var totalComments;
|
||||
// var toBeCreated = [];
|
||||
|
||||
// var getParentComments = function(toLookup){
|
||||
// var newCommentsToLookup = [];
|
||||
// var commentsToFetch = [];
|
||||
|
||||
// _.forEach(toLookup, function(id){
|
||||
// var parentID = lookup[id].parent_id.split("_")[1];
|
||||
|
||||
// if(parentID === Reddit.threadID) {} // Has no parent (is parent of thread)
|
||||
// else if(_.includes(Comments.toBeCreated, parentID)) {} // Parent already exists, do nothing
|
||||
// else if(_.includes(newCommentsToLookup, parentID)) {} // Parent already exists (this iteration)
|
||||
// else if(_.has(lookup, parentID)) {
|
||||
// newCommentsToLookup.push(parentID);
|
||||
// } else{
|
||||
// commentsToFetch.push(parentID);
|
||||
// }
|
||||
|
||||
// Comments.toBeCreated.push(id);
|
||||
// });
|
||||
|
||||
// return new Promise(function(resolve, reject){
|
||||
// if(_.uniq(commentsToFetch).length !== 0) {
|
||||
// fetch(URLs.singleComments + _.join(_.map(_.uniq(commentsToFetch),function(comments){
|
||||
// return "t1_" + comments;
|
||||
// })), Reddit.init)
|
||||
// .then(Fetch2.json)
|
||||
// .then(function(json){
|
||||
// _.forEach(json.data.children, function(comment) {
|
||||
// lookup[comment.data.id] = comment.data;
|
||||
// newCommentsToLookup.push(comment.data.id);
|
||||
// });
|
||||
// })
|
||||
// .then(function(){
|
||||
// resolve();
|
||||
// });
|
||||
|
||||
// } else {
|
||||
// resolve();
|
||||
// }
|
||||
// })
|
||||
// .then(function(){
|
||||
// if(newCommentsToLookup.length !== 0) {
|
||||
// return getParentComments(newCommentsToLookup)
|
||||
// }
|
||||
// });
|
||||
|
||||
// };
|
||||
|
||||
// allIDs: [], // All the comments that we were suppose to find
|
||||
// removed: [],
|
||||
// deleted: [],
|
||||
// toBeCreated: toBeCreated,
|
||||
|
||||
// getTotalComments: function() { return totalComments; },
|
||||
// setTotalComments: function(total) { totalComments = total; },
|
||||
|
||||
// getRoot: function() {
|
||||
// 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){
|
||||
// if(_.includes(Comments.deleted, comment.id)) {
|
||||
// comment["deleted"] = true;
|
||||
// } else {
|
||||
// comment["removed"] = true;
|
||||
// }
|
||||
|
||||
// Comments.lookup[comment.id] = comment;
|
||||
// });
|
||||
|
||||
// Comments.removed = _.map(removedComments, function(comment){
|
||||
// return comment.id;
|
||||
// });
|
||||
|
||||
// return getParentComments(Comments.removed)
|
||||
// .then(function(){
|
||||
// ThreadHTML.createCommentSection();
|
||||
// ThreadHTML.createComments();
|
||||
// })
|
||||
// }
|
||||
// }})();
|
||||
|
||||
// var removed = function(){
|
||||
// Comments.removed = _.difference(Comments.allIDs, Comments.ids);
|
||||
|
||||
// Comments.ids.forEach(function(id){
|
||||
// if(! _.has(Comments.lookup, id)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if(Comments.lookup[id].body === "[removed]") {
|
||||
// Comments.removed.push(id);
|
||||
// } else if (Comments.lookup[id].body === "[deleted]"){
|
||||
// Comments.removed.push(id);
|
||||
// Comments.deleted.push(id);
|
||||
// }
|
||||
// });
|
||||
|
||||
// Comments.removed = _.uniq(Comments.removed);
|
||||
// };
|
||||
|
||||
|
||||
// // ------------------------------------------------------------------------------
|
||||
// // ---------------------------- Generating HTML ---------------------------------
|
||||
// // ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// var createComments = function(){
|
||||
// var commentsToCreate = _.sortBy(_.uniq(Comments.toBeCreated), function(id) {
|
||||
// return Comments.lookup[id].score;
|
||||
// });
|
||||
|
||||
// var createdComments = [Comments.getRoot()];
|
||||
// var didSomething = false;
|
||||
|
||||
// while(commentsToCreate.length > 0) {
|
||||
// didSomething = false;
|
||||
|
||||
// for(var i = commentsToCreate.length - 1; i >= 0; i--) {
|
||||
// var id = commentsToCreate[i];
|
||||
// var parentID = Comments.lookup[id].parent_id.split("_")[1];
|
||||
|
||||
// if(_.includes(createdComments, parentID)) {
|
||||
// document.getElementById(parentID).appendChild(createComment(Comments.lookup[id]));
|
||||
// createdComments.push(id);
|
||||
// commentsToCreate.splice(i, 1);
|
||||
// didSomething = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Fail safe (parents missing for the rest of the comments, shouldn't happend but oh well :D)
|
||||
// if(!didSomething) {
|
||||
// console.error("Didn't generate all comments correctly");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
|
|
|
|||
|
|
@ -13,31 +13,3 @@ import '../sass/main.sass'
|
|||
// </Provider>,
|
||||
// document.getElementById('app')
|
||||
// )
|
||||
import { getComments } from 'api/reddit'
|
||||
import { getComments as getAllComments } from 'api/pushshift'
|
||||
|
||||
getAllComments('6z1hch')
|
||||
// .then(comments => comments.filter((val, i) => i < 100))
|
||||
.then(comments => {
|
||||
const ids = comments.map(comment => comment.id)
|
||||
// push to state
|
||||
return getComments(ids)
|
||||
})
|
||||
//
|
||||
// .then(getComments)
|
||||
.then(redditComments => {
|
||||
const removed = []
|
||||
const deleted = []
|
||||
|
||||
redditComments.forEach(comment => {
|
||||
if (comment.body === '[removed]') {
|
||||
removed.push(comment.id)
|
||||
} else if (comment.body === '[deleted]') {
|
||||
deleted.push(comment.id)
|
||||
}
|
||||
})
|
||||
|
||||
console.log('deleted', deleted)
|
||||
console.log('removed', removed)
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue