mirror of
https://github.com/gurnec/removeddit.git
synced 2026-03-11 08:54:27 +00:00
Better structure for seperating pages and components
This commit is contained in:
parent
be06df8442
commit
503c4c383a
11 changed files with 431 additions and 145 deletions
|
|
@ -2,27 +2,20 @@ import React from 'react'
|
|||
import {
|
||||
BrowserRouter,
|
||||
Switch,
|
||||
Route
|
||||
Route,
|
||||
IndexRoute
|
||||
} from 'react-router-dom'
|
||||
|
||||
// Pages
|
||||
import Menu from 'components/Menu'
|
||||
import About from 'components/About'
|
||||
import Thread from 'components/Thread'
|
||||
import {About, Thread, Subreddit} from 'pages'
|
||||
|
||||
export default class App extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
statusText: null,
|
||||
statusImage: null
|
||||
}
|
||||
|
||||
this.onStatusChange = this.onStatusChange.bind(this)
|
||||
}
|
||||
|
||||
handleStatusChange(text, image) {
|
||||
handleStatusChange(text, image) {
|
||||
this.setState({
|
||||
statusText: text,
|
||||
statusImage: image
|
||||
|
|
@ -33,14 +26,11 @@ export default class App extends React.Component {
|
|||
return (
|
||||
<BrowserRouter basename={__dirname}>
|
||||
<>
|
||||
<Menu statusText={this.state.statusText} statusImage={this.state.statusImage} />
|
||||
<Menu />
|
||||
<Switch>
|
||||
<IndexRoute component={Thread} />
|
||||
<Route exact path='/' component={Thread} />
|
||||
<Route path='/about' component={About}/>
|
||||
<Route path='/r/:subreddit/comments' onStatusChange={this.handleStatusChange} component={Thread}/>
|
||||
{/* <Route path='/:board/:pageNr' component={Board} />
|
||||
<Route path='/:board/thread/:thread' component={Thread}/>
|
||||
<Route component={Home} /> */}
|
||||
<Route path='/r/:subreddit/comments' component={Thread}/>
|
||||
</Switch>
|
||||
</>
|
||||
</BrowserRouter>
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
import React from 'react'
|
||||
|
||||
export default class About extends React.Component {
|
||||
render () {
|
||||
return (
|
||||
<div id='main'>
|
||||
<div id='main-box'>
|
||||
<h2 className='about'>About</h2>
|
||||
<p>Display <b className='removed' title='Removed by mods'>removed</b> (by mods) and <b className='deleted' title='Deleted by users'>deleted</b> (by users) comments/threads from Reddit.</p>
|
||||
<p>
|
||||
<b>Usage</b>: Drag this bookmarklet
|
||||
<a className='bookmarklet' href="javascript: document.location = document.URL.replace('reddit.com','removeddit.com');">Removeddit</a>
|
||||
to your bookmark bar and use it to get from reddit to removeddit.
|
||||
<br/><br/>
|
||||
Alternatively you can manually replace the <i>reddit</i> in the URL to <i>removeddit</i>.
|
||||
<br/>
|
||||
E.g. <a href='/r/TwoXChromosomes/comments/6z1hch/'>https://www.removeddit.com/r/TwoXChromosomes/comments/6z1hch/</a>
|
||||
</p>
|
||||
<p>
|
||||
Created by <a href='https://github.com/JubbeArt/'>Jesper Wrang</a> and uses <a href='https://pushshift.io/'>Jason Baumgartner</a> service for getting removed comments.
|
||||
</p>
|
||||
<h2 className='todo'>TODO</h2>
|
||||
<ul>
|
||||
<li>Collapsing comments</li>
|
||||
<li>Get removed selftext of thread</li>
|
||||
<li>Subreddits!</li>
|
||||
<li>Maybe for specific users </li>
|
||||
</ul>
|
||||
<h2 className='contact'>Links/Contact</h2>
|
||||
<p style={{marginBottom:'8px'}}>For feedback and bug reports:</p>
|
||||
<ul>
|
||||
<li>email: removeddit (at) gmail.com</li>
|
||||
<li>reddit: <a href='https://www.reddit.com/user/Jubbeart/'>/u/JubbeArt</a></li>
|
||||
</ul>
|
||||
<p>
|
||||
<a href='https://github.com/JubbeArt/removeddit'>Code on Github.</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import React from 'react'
|
||||
import {Link} from 'react-router-dom'
|
||||
import StatusBox from 'components/StatusBox'
|
||||
|
||||
export default class Menu extends React.Component {
|
||||
|
|
@ -11,11 +12,10 @@ export default class Menu extends React.Component {
|
|||
</h1>
|
||||
<nav>
|
||||
<Link to='/r/all'>/r/all</Link>
|
||||
<Link to='/r/bestof/comments/7c8jof/'>thread</Link>
|
||||
<Link to='/about/'>about</Link>
|
||||
</nav>
|
||||
</div>
|
||||
<StatusBox text={this.props.statusText} image={this.props.statusImage} />
|
||||
<StatusBox />
|
||||
</header>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ export default class StatusBox extends React.Component {
|
|||
return (
|
||||
<div id='status'>
|
||||
{this.props.text &&
|
||||
<p id='status-text'>{this.props.text}</p>}
|
||||
<p id='status-text'>{lol}</p>}
|
||||
{this.props.image &&
|
||||
<img id='status-image' src={this.props.image}/>}
|
||||
<img id='status-image' src={lol}/>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
import React from 'react'
|
||||
import {prettyScore, statusImages, redditThumbnails} from 'utils'
|
||||
|
||||
export default class Thread extends React.Component {
|
||||
constructor() {
|
||||
super()
|
||||
|
||||
this.state = {
|
||||
url: '',
|
||||
thumbnailWidth: 70,
|
||||
thumbnailHeight: 70,
|
||||
thumbnail: '',
|
||||
position: 0,
|
||||
score: 0
|
||||
}
|
||||
}
|
||||
|
||||
handleStateChange(text, image) {
|
||||
this.props.onStateChange(text, image)
|
||||
}
|
||||
|
||||
render () {
|
||||
const url = this.props.url.replace('reddit.com', 'removeddit.com')
|
||||
let thumbnail
|
||||
const thumbnailWidth = this.state.thumbnail_width ? this.state.thumbnail_width * 0.5 : 70
|
||||
const thumbnailHeight = this.state.thumbnail_height ? this.state.thumbnail_height * 0.5 : 70
|
||||
|
||||
if(redditThumbnails.includes(this.state.thumbnail)) {
|
||||
thumbnail = <a href={url} className='thumbnail thumbnail-${this.props..thumbnail}'></a>
|
||||
} else {
|
||||
thumbnail = (
|
||||
<a href={url}>
|
||||
<img className='thumbnail' src={this.state.thumbnail} width='<%= thumbnailWidth %>' height='<%= thumbnailHeight %>'/>
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='thread'>
|
||||
{this.state.position &&
|
||||
<span className='post-rank'>{this.state.position}</span>}
|
||||
<div className='thread-score-box'>
|
||||
<div className='vote upvote'></div>
|
||||
<div className='thread-score'>{prettyScore(this.state.score)}</div>
|
||||
<div className='vote downvote'></div>
|
||||
</div>
|
||||
{thumbnail}
|
||||
<div className='thread-content'>
|
||||
|
||||
<a className='thread-title' href={this.props.url}>{this.state.title}</a>
|
||||
{thread.link_flair_text &&
|
||||
<span className='link-flair'>{this.state.link_flair_text}</span>}
|
||||
<span className='domain'>({this.state.domain})</span>
|
||||
<div className='thread-info'>
|
||||
submitted <span className='thread-time'>{prettyDate(this.state.created_utc)}</span> by
|
||||
<a className='thread-author author' href={`https://www.reddit.com/user/${this.state.author}`}>{this.state.author}</a>
|
||||
{/* <% if(Reddit.isAll){ %>
|
||||
to <a className='subreddit-link author' href='/r/<%= thread.subreddit %>'>/r/<%= thread.subreddit %></a>
|
||||
<% } %> */}
|
||||
</div>
|
||||
<div className='total-comments'>
|
||||
<a className='grey-link' href='<%= thread.permalink %>'>
|
||||
<b>{this.state.num_comments} comments</b>
|
||||
</a>
|
||||
<a className='grey-link' href={`https://www.reddit.com${this.state.permalink}`}>
|
||||
<b>reddit</b>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -7,9 +7,4 @@ import App from './App'
|
|||
ReactDOM.render(
|
||||
<App />,
|
||||
document.getElementById("app")
|
||||
)
|
||||
|
||||
|
||||
// import Reddit from './reddit'
|
||||
|
||||
// Reddit.comments(1,2).then(() => console.log('lololololololol'))
|
||||
)
|
||||
40
src/js/pages/About.js
Normal file
40
src/js/pages/About.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import React from 'react'
|
||||
|
||||
export default (props) => {
|
||||
return (
|
||||
<div id='main'>
|
||||
<div id='main-box'>
|
||||
<h2 className='about'>About</h2>
|
||||
<p>Display <b className='removed' title='Removed by mods'>removed</b> (by mods) and <b className='deleted' title='Deleted by users'>deleted</b> (by users) comments/threads from Reddit.</p>
|
||||
<p>
|
||||
<b>Usage</b>: Drag this bookmarklet
|
||||
<a className='bookmarklet' href="javascript: document.location = document.URL.replace('reddit.com','removeddit.com');">Removeddit</a>
|
||||
to your bookmark bar and use it to get from reddit to removeddit.
|
||||
<br/><br/>
|
||||
Alternatively you can manually replace the <i>reddit</i> in the URL to <i>removeddit</i>.
|
||||
<br/>
|
||||
E.g. <a href='/r/TwoXChromosomes/comments/6z1hch/'>https://www.removeddit.com/r/TwoXChromosomes/comments/6z1hch/</a>
|
||||
</p>
|
||||
<p>
|
||||
Created by <a href='https://github.com/JubbeArt/'>Jesper Wrang</a> and uses <a href='https://pushshift.io/'>Jason Baumgartner</a> service for getting removed comments.
|
||||
</p>
|
||||
<h2 className='todo'>TODO</h2>
|
||||
<ul>
|
||||
<li>Collapsing comments</li>
|
||||
<li>Get removed selftext of thread</li>
|
||||
<li>Subreddits!</li>
|
||||
<li>Maybe for specific users </li>
|
||||
</ul>
|
||||
<h2 className='contact'>Links/Contact</h2>
|
||||
<p style={{marginBottom:'8px'}}>For feedback and bug reports:</p>
|
||||
<ul>
|
||||
<li>email: removeddit (at) gmail.com</li>
|
||||
<li>reddit: <a href='https://www.reddit.com/user/Jubbeart/'>/u/JubbeArt</a></li>
|
||||
</ul>
|
||||
<p>
|
||||
<a href='https://github.com/JubbeArt/removeddit'>Code on Github.</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import React from 'react'
|
||||
|
||||
export default class Thread extends React.Component {
|
||||
export default class Subreddit extends React.Component {
|
||||
render() {
|
||||
return <h1>Subreddit</h1>
|
||||
}
|
||||
70
src/js/pages/Thread.js
Normal file
70
src/js/pages/Thread.js
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import React from 'react'
|
||||
import {prettyScore, statusImages, redditThumbnails} from 'utils'
|
||||
|
||||
export default class Thread extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
url: '',
|
||||
thumbnailWidth: 70,
|
||||
thumbnailHeight: 70,
|
||||
thumbnail: '',
|
||||
position: 0,
|
||||
score: 0
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
// const url = this.props.url.replace('reddit.com', 'removeddit.com')
|
||||
// let thumbnail
|
||||
// const thumbnailWidth = this.state.thumbnail_width ? this.state.thumbnail_width * 0.5 : 70
|
||||
// const thumbnailHeight = this.state.thumbnail_height ? this.state.thumbnail_height * 0.5 : 70
|
||||
|
||||
// if(redditThumbnails.includes(this.state.thumbnail)) {
|
||||
// thumbnail = <a href={url} className='thumbnail thumbnail-${this.props..thumbnail}'></a>
|
||||
// } else {
|
||||
// thumbnail = (
|
||||
// <a href={url}>
|
||||
// <img className='thumbnail' src={this.state.thumbnail} width='<%= thumbnailWidth %>' height='<%= thumbnailHeight %>'/>
|
||||
// </a>
|
||||
// )
|
||||
// }
|
||||
|
||||
return (
|
||||
<h1>Lol</h1>
|
||||
// <div className='thread'>
|
||||
// {this.state.position &&
|
||||
// <span className='post-rank'>{this.state.position}</span>}
|
||||
// <div className='thread-score-box'>
|
||||
// <div className='vote upvote'></div>
|
||||
// <div className='thread-score'>{prettyScore(this.state.score)}</div>
|
||||
// <div className='vote downvote'></div>
|
||||
// </div>
|
||||
// {thumbnail}
|
||||
// <div className='thread-content'>
|
||||
|
||||
// <a className='thread-title' href={this.props.url}>{this.state.title}</a>
|
||||
// {thread.link_flair_text &&
|
||||
// <span className='link-flair'>{this.state.link_flair_text}</span>}
|
||||
// <span className='domain'>({this.state.domain})</span>
|
||||
// <div className='thread-info'>
|
||||
// submitted <span className='thread-time'>{prettyDate(this.state.created_utc)}</span> by
|
||||
// <a className='thread-author author' href={`https://www.reddit.com/user/${this.state.author}`}>{this.state.author}</a>
|
||||
// {/* <% if(Reddit.isAll){ %>
|
||||
// to <a className='subreddit-link author' href='/r/<%= thread.subreddit %>'>/r/<%= thread.subreddit %></a>
|
||||
// <% } %> */}
|
||||
// </div>
|
||||
// <div className='total-comments'>
|
||||
// <a className='grey-link' href='<%= thread.permalink %>'>
|
||||
// <b>{this.state.num_comments} comments</b>
|
||||
// </a>
|
||||
// <a className='grey-link' href={`https://www.reddit.com${this.state.permalink}`}>
|
||||
// <b>reddit</b>
|
||||
// </a>
|
||||
// </div>
|
||||
// </div>
|
||||
// </div>
|
||||
)
|
||||
}
|
||||
}
|
||||
3
src/js/pages/index.js
Normal file
3
src/js/pages/index.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export {default as About} from './About'
|
||||
export {default as Subreddit} from './Subreddit'
|
||||
export {default as Thread} from './Thread'
|
||||
|
|
@ -35,5 +35,308 @@ const fetchToken = () => {
|
|||
export default {
|
||||
comments(subreddit, threadID) {
|
||||
return fetchToken()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reddit.fetchToken()
|
||||
// .then(function(){
|
||||
// return Promise.all([
|
||||
// fetch(URLs.thread, Reddit.init)
|
||||
// .then(Fetch2.json)
|
||||
// .then(ThreadHTML.createThread)
|
||||
// .catch(function(error) {
|
||||
// return Promise.reject("Could not get thread from Reddit");
|
||||
// }),
|
||||
|
||||
// fetch(URLs.pushshiftIDs)
|
||||
// .then(Fetch2.json)
|
||||
// .then(_.property("data"))
|
||||
// .catch(function(error) {
|
||||
// return Promise.reject("Could not get removed comment IDs");
|
||||
// }),
|
||||
// ])
|
||||
// })
|
||||
// .then(function(results) {
|
||||
// var thread = results[0];
|
||||
// Comments.allIDs = results[1];
|
||||
|
||||
// Status.loading("Loading comments from reddit...");
|
||||
// HandleIDs.normal(thread);
|
||||
// return HandleIDs.morechildren()
|
||||
// .catch(function(error){
|
||||
// return Promise.reject("Could not get comments from Reddit (moreChildren)");
|
||||
// });
|
||||
// })
|
||||
// .then(function(){
|
||||
// return Promise.all(_.map(_.uniq(Comments.countinuethread), function(id) {
|
||||
// return fetch(URLs.thread+"/_/"+id.split("_")[1], Reddit.init)
|
||||
// .then(Fetch2.json)
|
||||
// .catch(function(error){ return Promise.reject("Could not get comments from Reddit (continueThisThread)") })
|
||||
// }))
|
||||
// .catch(function(error){
|
||||
// return Promise.reject("Could not get comments from Reddit (continueThisThread)");
|
||||
// });
|
||||
// })
|
||||
// .then(function(smallerThreads){
|
||||
// _.forEach(smallerThreads, function(thread){
|
||||
// HandleIDs.normal(thread);
|
||||
// })
|
||||
// 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 lookup = {};
|
||||
// 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)
|
||||
// }
|
||||
// });
|
||||
|
||||
// };
|
||||
|
||||
// return {
|
||||
// ids: [], // The comments we found
|
||||
// morechildren: [],
|
||||
// countinuethread: [],
|
||||
|
||||
// allIDs: [], // All the comments that we were suppose to find
|
||||
// removed: [],
|
||||
// deleted: [],
|
||||
// toBeCreated: toBeCreated,
|
||||
// lookup: lookup,
|
||||
|
||||
// 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();
|
||||
// })
|
||||
// }
|
||||
// }})();
|
||||
|
||||
|
||||
|
||||
// // ------------------------------------------------------------------------------
|
||||
// // ----------------- Handle comments from different requests --------------------
|
||||
// // ------------------------------------------------------------------------------
|
||||
// var HandleIDs = (function(){
|
||||
// var normal = function(thread){
|
||||
// return _.flatten(_.map(thread[1].data.children, Extract.normal))
|
||||
// };
|
||||
|
||||
// var morechildren = function(){
|
||||
// return Promise.all(_.map(_.uniq(Comments.morechildren), function(idArray){
|
||||
// return Fetch2.multiple(URLs.format(URLs.moreChildren, idArray), Reddit.init);
|
||||
// }))
|
||||
// .then(function(responseArrays){
|
||||
// Comments.morechildren.length = 0;
|
||||
// _.forEach(responseArrays, function(responseArray){
|
||||
// _.forEach(responseArray, function(response){
|
||||
// _.forEach(response.jquery[10][3][0], function(comment){
|
||||
// Extract.normal(comment);
|
||||
// })
|
||||
// });
|
||||
// });
|
||||
// }).then(function(){
|
||||
// if(Comments.morechildren.length !== 0) {
|
||||
// return morechildren();
|
||||
// }
|
||||
// });
|
||||
// };
|
||||
|
||||
// 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);
|
||||
// };
|
||||
|
||||
// return {
|
||||
// normal: normal,
|
||||
// morechildren: morechildren,
|
||||
// removed: removed
|
||||
// };
|
||||
// })();
|
||||
|
||||
|
||||
// // ------------------------------------------------------------------------------
|
||||
// // ----------------------- Extract ID from comments -----------------------------
|
||||
// // ------------------------------------------------------------------------------
|
||||
// var Extract = (function(){
|
||||
// var normal = function(comment){
|
||||
// var data = comment.data;
|
||||
|
||||
// if(comment.kind == "more") { // "Show more"-comment
|
||||
// if(data.id === "_") { // = "continue this thread" comment
|
||||
// Comments.countinuethread.push(data.parent_id);
|
||||
// } else if(data.children.length < data.count){ // "Load more"-comment (that is missing some of its children)
|
||||
// Comments.morechildren.push(data.children);
|
||||
// }
|
||||
// Comments.ids.push.apply(Comments.ids, data.children);
|
||||
// } else { // Normal comment
|
||||
// if(data.replies) {
|
||||
// data.replies.data.children.forEach(function(child){
|
||||
// normal(child);
|
||||
// });
|
||||
// delete data.replies;
|
||||
// }
|
||||
|
||||
// Comments.ids.push(data.id);
|
||||
// Comments.lookup[data.id] = data;
|
||||
// }
|
||||
// };
|
||||
|
||||
// return {
|
||||
// normal: normal
|
||||
// };
|
||||
// })();
|
||||
|
||||
|
||||
// // ------------------------------------------------------------------------------
|
||||
// // ---------------------------- 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;
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in a new issue