@@ -24,26 +24,23 @@
- Note that this site is in it's early stages of development, meaning the site is unstable and will contain bugs.
If you find something that doesn't work please contact me at:
removeddit (at) gmail.com
TODO
- Collapsing comments
- Get removed selftext of thread -
- Get nested "continue this thread"-comments to work +
- Subreddits! +
- Maybe for specific users
Acknowledgement
+ +Links/Contact
For feedback and bug reports:
- email: removeddit (at) gmail.com diff --git a/static/fetch.js b/static/fetch.js new file mode 100644 index 0000000..f2f466d --- /dev/null +++ b/static/fetch.js @@ -0,0 +1,466 @@ +(function(self) { + 'use strict'; + + if (self.fetch) { + return + } + + var support = { + searchParams: 'URLSearchParams' in self, + iterable: 'Symbol' in self && 'iterator' in Symbol, + blob: 'FileReader' in self && 'Blob' in self && (function() { + try { + new Blob() + return true + } catch(e) { + return false + } + })(), + formData: 'FormData' in self, + arrayBuffer: 'ArrayBuffer' in self + } + + if (support.arrayBuffer) { + var viewClasses = [ + '[object Int8Array]', + '[object Uint8Array]', + '[object Uint8ClampedArray]', + '[object Int16Array]', + '[object Uint16Array]', + '[object Int32Array]', + '[object Uint32Array]', + '[object Float32Array]', + '[object Float64Array]' + ] + + var isDataView = function(obj) { + return obj && DataView.prototype.isPrototypeOf(obj) + } + + var isArrayBufferView = ArrayBuffer.isView || function(obj) { + return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1 + } + } + + function normalizeName(name) { + if (typeof name !== 'string') { + name = String(name) + } + if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) { + throw new TypeError('Invalid character in header field name') + } + return name.toLowerCase() + } + + function normalizeValue(value) { + if (typeof value !== 'string') { + value = String(value) + } + return value + } + + // Build a destructive iterator for the value list + function iteratorFor(items) { + var iterator = { + next: function() { + var value = items.shift() + return {done: value === undefined, value: value} + } + } + + if (support.iterable) { + iterator[Symbol.iterator] = function() { + return iterator + } + } + + return iterator + } + + function Headers(headers) { + this.map = {} + + if (headers instanceof Headers) { + headers.forEach(function(value, name) { + this.append(name, value) + }, this) + } else if (Array.isArray(headers)) { + headers.forEach(function(header) { + this.append(header[0], header[1]) + }, this) + } else if (headers) { + Object.getOwnPropertyNames(headers).forEach(function(name) { + this.append(name, headers[name]) + }, this) + } + } + + Headers.prototype.append = function(name, value) { + name = normalizeName(name) + value = normalizeValue(value) + var oldValue = this.map[name] + this.map[name] = oldValue ? oldValue+','+value : value + } + + Headers.prototype['delete'] = function(name) { + delete this.map[normalizeName(name)] + } + + Headers.prototype.get = function(name) { + name = normalizeName(name) + return this.has(name) ? this.map[name] : null + } + + Headers.prototype.has = function(name) { + return this.map.hasOwnProperty(normalizeName(name)) + } + + Headers.prototype.set = function(name, value) { + this.map[normalizeName(name)] = normalizeValue(value) + } + + Headers.prototype.forEach = function(callback, thisArg) { + for (var name in this.map) { + if (this.map.hasOwnProperty(name)) { + callback.call(thisArg, this.map[name], name, this) + } + } + } + + Headers.prototype.keys = function() { + var items = [] + this.forEach(function(value, name) { items.push(name) }) + return iteratorFor(items) + } + + Headers.prototype.values = function() { + var items = [] + this.forEach(function(value) { items.push(value) }) + return iteratorFor(items) + } + + Headers.prototype.entries = function() { + var items = [] + this.forEach(function(value, name) { items.push([name, value]) }) + return iteratorFor(items) + } + + if (support.iterable) { + Headers.prototype[Symbol.iterator] = Headers.prototype.entries + } + + function consumed(body) { + if (body.bodyUsed) { + return Promise.reject(new TypeError('Already read')) + } + body.bodyUsed = true + } + + function fileReaderReady(reader) { + return new Promise(function(resolve, reject) { + reader.onload = function() { + resolve(reader.result) + } + reader.onerror = function() { + reject(reader.error) + } + }) + } + + function readBlobAsArrayBuffer(blob) { + var reader = new FileReader() + var promise = fileReaderReady(reader) + reader.readAsArrayBuffer(blob) + return promise + } + + function readBlobAsText(blob) { + var reader = new FileReader() + var promise = fileReaderReady(reader) + reader.readAsText(blob) + return promise + } + + function readArrayBufferAsText(buf) { + var view = new Uint8Array(buf) + var chars = new Array(view.length) + + for (var i = 0; i < view.length; i++) { + chars[i] = String.fromCharCode(view[i]) + } + return chars.join('') + } + + function bufferClone(buf) { + if (buf.slice) { + return buf.slice(0) + } else { + var view = new Uint8Array(buf.byteLength) + view.set(new Uint8Array(buf)) + return view.buffer + } + } + + function Body() { + this.bodyUsed = false + + this._initBody = function(body) { + this._bodyInit = body + if (!body) { + this._bodyText = '' + } else if (typeof body === 'string') { + this._bodyText = body + } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { + this._bodyBlob = body + } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { + this._bodyFormData = body + } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { + this._bodyText = body.toString() + } else if (support.arrayBuffer && support.blob && isDataView(body)) { + this._bodyArrayBuffer = bufferClone(body.buffer) + // IE 10-11 can't handle a DataView body. + this._bodyInit = new Blob([this._bodyArrayBuffer]) + } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) { + this._bodyArrayBuffer = bufferClone(body) + } else { + throw new Error('unsupported BodyInit type') + } + + if (!this.headers.get('content-type')) { + if (typeof body === 'string') { + this.headers.set('content-type', 'text/plain;charset=UTF-8') + } else if (this._bodyBlob && this._bodyBlob.type) { + this.headers.set('content-type', this._bodyBlob.type) + } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { + this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8') + } + } + } + + if (support.blob) { + this.blob = function() { + var rejected = consumed(this) + if (rejected) { + return rejected + } + + if (this._bodyBlob) { + return Promise.resolve(this._bodyBlob) + } else if (this._bodyArrayBuffer) { + return Promise.resolve(new Blob([this._bodyArrayBuffer])) + } else if (this._bodyFormData) { + throw new Error('could not read FormData body as blob') + } else { + return Promise.resolve(new Blob([this._bodyText])) + } + } + + this.arrayBuffer = function() { + if (this._bodyArrayBuffer) { + return consumed(this) || Promise.resolve(this._bodyArrayBuffer) + } else { + return this.blob().then(readBlobAsArrayBuffer) + } + } + } + + this.text = function() { + var rejected = consumed(this) + if (rejected) { + return rejected + } + + if (this._bodyBlob) { + return readBlobAsText(this._bodyBlob) + } else if (this._bodyArrayBuffer) { + return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer)) + } else if (this._bodyFormData) { + throw new Error('could not read FormData body as text') + } else { + return Promise.resolve(this._bodyText) + } + } + + if (support.formData) { + this.formData = function() { + return this.text().then(decode) + } + } + + this.json = function() { + return this.text().then(JSON.parse) + } + + return this + } + + // HTTP methods whose capitalization should be normalized + var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'] + + function normalizeMethod(method) { + var upcased = method.toUpperCase() + return (methods.indexOf(upcased) > -1) ? upcased : method + } + + function Request(input, options) { + options = options || {} + var body = options.body + + if (input instanceof Request) { + if (input.bodyUsed) { + throw new TypeError('Already read') + } + this.url = input.url + this.credentials = input.credentials + if (!options.headers) { + this.headers = new Headers(input.headers) + } + this.method = input.method + this.mode = input.mode + if (!body && input._bodyInit != null) { + body = input._bodyInit + input.bodyUsed = true + } + } else { + this.url = String(input) + } + + this.credentials = options.credentials || this.credentials || 'omit' + if (options.headers || !this.headers) { + this.headers = new Headers(options.headers) + } + this.method = normalizeMethod(options.method || this.method || 'GET') + this.mode = options.mode || this.mode || null + this.referrer = null + + if ((this.method === 'GET' || this.method === 'HEAD') && body) { + throw new TypeError('Body not allowed for GET or HEAD requests') + } + this._initBody(body) + } + + Request.prototype.clone = function() { + return new Request(this, { body: this._bodyInit }) + } + + function decode(body) { + var form = new FormData() + body.trim().split('&').forEach(function(bytes) { + if (bytes) { + var split = bytes.split('=') + var name = split.shift().replace(/\+/g, ' ') + var value = split.join('=').replace(/\+/g, ' ') + form.append(decodeURIComponent(name), decodeURIComponent(value)) + } + }) + return form + } + + function parseHeaders(rawHeaders) { + var headers = new Headers() + // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space + // https://tools.ietf.org/html/rfc7230#section-3.2 + var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ') + preProcessedHeaders.split(/\r?\n/).forEach(function(line) { + var parts = line.split(':') + var key = parts.shift().trim() + if (key) { + var value = parts.join(':').trim() + headers.append(key, value) + } + }) + return headers + } + + Body.call(Request.prototype) + + function Response(bodyInit, options) { + if (!options) { + options = {} + } + + this.type = 'default' + this.status = options.status === undefined ? 200 : options.status + this.ok = this.status >= 200 && this.status < 300 + this.statusText = 'statusText' in options ? options.statusText : 'OK' + this.headers = new Headers(options.headers) + this.url = options.url || '' + this._initBody(bodyInit) + } + + Body.call(Response.prototype) + + Response.prototype.clone = function() { + return new Response(this._bodyInit, { + status: this.status, + statusText: this.statusText, + headers: new Headers(this.headers), + url: this.url + }) + } + + Response.error = function() { + var response = new Response(null, {status: 0, statusText: ''}) + response.type = 'error' + return response + } + + var redirectStatuses = [301, 302, 303, 307, 308] + + Response.redirect = function(url, status) { + if (redirectStatuses.indexOf(status) === -1) { + throw new RangeError('Invalid status code') + } + + return new Response(null, {status: status, headers: {location: url}}) + } + + self.Headers = Headers + self.Request = Request + self.Response = Response + + self.fetch = function(input, init) { + return new Promise(function(resolve, reject) { + var request = new Request(input, init) + var xhr = new XMLHttpRequest() + + xhr.onload = function() { + var options = { + status: xhr.status, + statusText: xhr.statusText, + headers: parseHeaders(xhr.getAllResponseHeaders() || '') + } + options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL') + var body = 'response' in xhr ? xhr.response : xhr.responseText + resolve(new Response(body, options)) + } + + xhr.onerror = function() { + reject(new TypeError('Network request failed')) + } + + xhr.ontimeout = function() { + reject(new TypeError('Network request failed')) + } + + xhr.open(request.method, request.url, true) + + if (request.credentials === 'include') { + xhr.withCredentials = true + } else if (request.credentials === 'omit') { + xhr.withCredentials = false + } + + if ('responseType' in xhr && support.blob) { + xhr.responseType = 'blob' + } + + request.headers.forEach(function(value, name) { + xhr.setRequestHeader(name, value) + }) + + xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit) + }) + } + self.fetch.polyfill = true +})(typeof self !== 'undefined' ? self : this); diff --git a/static/functions.js b/static/functions.js new file mode 100644 index 0000000..b052ad2 --- /dev/null +++ b/static/functions.js @@ -0,0 +1,149 @@ +"use strict"; + +// Little display-bar in the upper right corner +var Status = (function(){ + var loadingText = document.getElementById("loading-text"); + var statusImage = document.getElementById("loading-image"); + var loadingImg = "/static/loading.gif"; + var successImg = "/static/done.png"; + var errorImg = "/static/error.png"; + +return { + loading: function(msg) { + statusImage.src = loadingImg + loadingText.innerHTML = msg + }, + + success: function(msg) { + msg = _.defaultTo(msg, "") + statusImage.src = successImg + loadingText.innerHTML = msg + }, + + error: function(msg) { + statusImage.src = errorImg + loadingText.innerHTML = "ERROR: " + msg + "" + console.error(msg) + } +}})() + + +// Reddit API +var Reddit = (function() { + var init = {headers: {"Authorization": ""}}; + +return { + init: init, + subreddit: window.location.pathname.split("/")[2], + threadID: window.location.pathname.split("/")[4], + fetchToken: function() { + return fetch("https://www.reddit.com/api/v1/access_token", { + headers: { + "Authorization": "Basic " + btoa(clientID + ":"), + "Content-Type": "application/x-www-form-urlencoded; charset=utf-8" + }, + method: "POST", + body: "grant_type="+encodeURIComponent("https://oauth.reddit.com/grants/installed_client")+"&device_id=DO_NOT_TRACK_THIS_DEVICE" + }) + .then(function(response) { return response.json() }) + .then(function(json) { + init.headers.Authorization = "bearer " + json.access_token; + }); + } +}})() + + +// Helper functions for fetch +var Fetch2 = (function(){ + var json = function(response) { + return response.json(); + }; + +return { + multiple: function(urls, init, jsonPath, flattening) { + flattening = _.defaultTo(flattening, true); + jsonPath = _.defaultTo(jsonPath, null); + + return Promise.all(_.map(urls, function(url) { + return fetch(url, init) + .then(json) + .then(function(jsonArray) { + if(! _.isNil(jsonPath)) { + return _.get(jsonArray, jsonPath); + } + return jsonArray; + }); + })) + .then(function(dataArray) { + if(flattening) { + return _.flatten(dataArray); + } + return dataArray; + }); + }, + json: json +}})() + +var URLs = (function(){ + var reddit = "https://oauth.reddit.com"; + var pushshift = "https://api.pushshift.io"; + var maxItemsPerRequest = 100; + + return { + format: function(url, data, chunkSize) { + chunkSize = _.defaultTo(chunkSize, maxItemsPerRequest); + var dataChunks = _.chunk(data, chunkSize); + return _.map(dataChunks, function(chunk) { return url + chunk; }) + }, + pushshiftComments:pushshift+"/reddit/comment/search?ids=", + pushshiftIDs: pushshift+"/reddit/submission/comment_ids/"+Reddit.threadID, + thread: reddit+"/r/"+Reddit.subreddit+"/comments/"+Reddit.threadID, + moreChildren: reddit+"/api/morechildren?link_id=t3_"+Reddit.threadID+"&children=", + singleComments: reddit+"/r/"+Reddit.subreddit+"/api/info/?id=" + }; +})() + + +// HTML parsing +var HTML = (function (){ +return { + parse: function(htmlString) { + var tmpDiv = document.createElement('div') + tmpDiv.innerHTML = htmlString + return tmpDiv.childNodes.length === 0 ? "" : tmpDiv.childNodes[0].nodeValue + } +}})() + + +// For text formatting +var Format = (function () { + var markdown = SnuOwnd.getParser(); +return { + parse: function(text){ + return markdown.render(text) + }, + // UTC -> "Reddit time format" (5 hours ago, just now, etc...) + prettyDate: function(createdUTC){ + var currentUTC = Math.floor((new Date()).getTime() / 1000); + var secondDiff = currentUTC - createdUTC; + var dayDiff = Math.floor(secondDiff / 86400); + + if(dayDiff < 0) return ""; + if(dayDiff == 0) { + if(secondDiff < 10) return "just now"; + if(secondDiff < 60) return secondDiff + " seconds ago"; + if(secondDiff < 120) return "a minute ago"; + if(secondDiff < 3600) return Math.floor(secondDiff / 60) + " minutes ago"; + if(secondDiff < 7200) return "an hour ago"; + if(secondDiff < 86400) return Math.floor(secondDiff / 3600) + " hours ago"; + } + if(dayDiff < 7) return dayDiff + " days ago"; + if(dayDiff < 31) return Math.floor(dayDiff / 7) + " weeks ago"; + if(dayDiff < 365) return Math.floor(dayDiff / 30) + " months ago"; + return Math.floor(dayDiff / 365) + " years ago"; + }, + // 12000 => 1.2k + prettyScore: function(score) { + return score >= 10000 ? (score / 1000).toFixed(1) + "k" : score; + } +}})() \ No newline at end of file diff --git a/static/id.js b/static/id.js index 55206f2..10a4b5b 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 -const clientID = "" \ No newline at end of file +var clientID = "YSidAws9twqCZg" \ No newline at end of file diff --git a/static/lodash.min.js b/static/lodash.min.js new file mode 100644 index 0000000..ca447f4 --- /dev/null +++ b/static/lodash.min.js @@ -0,0 +1,136 @@ +/** + * @license + * Lodash lodash.com/license | Underscore.js 1.8.3 underscorejs.org/LICENSE + */ +;(function(){function n(n,t){return n.set(t[0],t[1]),n}function t(n,t){return n.add(t),n}function r(n,t,r){switch(r.length){case 0:return n.call(t);case 1:return n.call(t,r[0]);case 2:return n.call(t,r[0],r[1]);case 3:return n.call(t,r[0],r[1],r[2])}return n.apply(t,r)}function e(n,t,r,e){for(var u=-1,i=null==n?0:n.length;++u"']/g,J=RegExp(G.source),Y=RegExp(H.source),Q=/<%-([\s\S]+?)%>/g,X=/<%([\s\S]+?)%>/g,nn=/<%=([\s\S]+?)%>/g,tn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,rn=/^\w*$/,en=/^\./,un=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,on=/[\\^$.*+?()[\]{}|]/g,fn=RegExp(on.source),cn=/^\s+|\s+$/g,an=/^\s+/,ln=/\s+$/,sn=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,hn=/\{\n\/\* \[wrapped with (.+)\] \*/,pn=/,? & /,_n=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,vn=/\\(\\)?/g,gn=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,dn=/\w*$/,yn=/^[-+]0x[0-9a-f]+$/i,bn=/^0b[01]+$/i,xn=/^\[object .+?Constructor\]$/,jn=/^0o[0-7]+$/i,wn=/^(?:0|[1-9]\d*)$/,mn=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,An=/($^)/,kn=/['\n\r\u2028\u2029\\]/g,En="[\\ufe0e\\ufe0f]?(?:[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]|\\ud83c[\\udffb-\\udfff])?(?:\\u200d(?:[^\\ud800-\\udfff]|(?:\\ud83c[\\udde6-\\uddff]){2}|[\\ud800-\\udbff][\\udc00-\\udfff])[\\ufe0e\\ufe0f]?(?:[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]|\\ud83c[\\udffb-\\udfff])?)*",On="(?:[\\u2700-\\u27bf]|(?:\\ud83c[\\udde6-\\uddff]){2}|[\\ud800-\\udbff][\\udc00-\\udfff])"+En,Sn="(?:[^\\ud800-\\udfff][\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]?|[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]|(?:\\ud83c[\\udde6-\\uddff]){2}|[\\ud800-\\udbff][\\udc00-\\udfff]|[\\ud800-\\udfff])",In=RegExp("['\u2019]","g"),Rn=RegExp("[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]","g"),zn=RegExp("\\ud83c[\\udffb-\\udfff](?=\\ud83c[\\udffb-\\udfff])|"+Sn+En,"g"),Wn=RegExp(["[A-Z\\xc0-\\xd6\\xd8-\\xde]?[a-z\\xdf-\\xf6\\xf8-\\xff]+(?:['\u2019](?:d|ll|m|re|s|t|ve))?(?=[\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000]|[A-Z\\xc0-\\xd6\\xd8-\\xde]|$)|(?:[A-Z\\xc0-\\xd6\\xd8-\\xde]|[^\\ud800-\\udfff\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000\\d+\\u2700-\\u27bfa-z\\xdf-\\xf6\\xf8-\\xffA-Z\\xc0-\\xd6\\xd8-\\xde])+(?:['\u2019](?:D|LL|M|RE|S|T|VE))?(?=[\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000]|[A-Z\\xc0-\\xd6\\xd8-\\xde](?:[a-z\\xdf-\\xf6\\xf8-\\xff]|[^\\ud800-\\udfff\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000\\d+\\u2700-\\u27bfa-z\\xdf-\\xf6\\xf8-\\xffA-Z\\xc0-\\xd6\\xd8-\\xde])|$)|[A-Z\\xc0-\\xd6\\xd8-\\xde]?(?:[a-z\\xdf-\\xf6\\xf8-\\xff]|[^\\ud800-\\udfff\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000\\d+\\u2700-\\u27bfa-z\\xdf-\\xf6\\xf8-\\xffA-Z\\xc0-\\xd6\\xd8-\\xde])+(?:['\u2019](?:d|ll|m|re|s|t|ve))?|[A-Z\\xc0-\\xd6\\xd8-\\xde]+(?:['\u2019](?:D|LL|M|RE|S|T|VE))?|\\d*(?:(?:1ST|2ND|3RD|(?![123])\\dTH)\\b)|\\d*(?:(?:1st|2nd|3rd|(?![123])\\dth)\\b)|\\d+",On].join("|"),"g"),Bn=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]"),Ln=/[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Un="Array Buffer DataView Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Map Math Object Promise RegExp Set String Symbol TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array WeakMap _ clearTimeout isFinite parseInt setTimeout".split(" "),Cn={}; +Cn["[object Float32Array]"]=Cn["[object Float64Array]"]=Cn["[object Int8Array]"]=Cn["[object Int16Array]"]=Cn["[object Int32Array]"]=Cn["[object Uint8Array]"]=Cn["[object Uint8ClampedArray]"]=Cn["[object Uint16Array]"]=Cn["[object Uint32Array]"]=true,Cn["[object Arguments]"]=Cn["[object Array]"]=Cn["[object ArrayBuffer]"]=Cn["[object Boolean]"]=Cn["[object DataView]"]=Cn["[object Date]"]=Cn["[object Error]"]=Cn["[object Function]"]=Cn["[object Map]"]=Cn["[object Number]"]=Cn["[object Object]"]=Cn["[object RegExp]"]=Cn["[object Set]"]=Cn["[object String]"]=Cn["[object WeakMap]"]=false; +var Dn={};Dn["[object Arguments]"]=Dn["[object Array]"]=Dn["[object ArrayBuffer]"]=Dn["[object DataView]"]=Dn["[object Boolean]"]=Dn["[object Date]"]=Dn["[object Float32Array]"]=Dn["[object Float64Array]"]=Dn["[object Int8Array]"]=Dn["[object Int16Array]"]=Dn["[object Int32Array]"]=Dn["[object Map]"]=Dn["[object Number]"]=Dn["[object Object]"]=Dn["[object RegExp]"]=Dn["[object Set]"]=Dn["[object String]"]=Dn["[object Symbol]"]=Dn["[object Uint8Array]"]=Dn["[object Uint8ClampedArray]"]=Dn["[object Uint16Array]"]=Dn["[object Uint32Array]"]=true, +Dn["[object Error]"]=Dn["[object Function]"]=Dn["[object WeakMap]"]=false;var Mn,Tn={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},$n=parseFloat,Fn=parseInt,Nn=typeof global=="object"&&global&&global.Object===Object&&global,Pn=typeof self=="object"&&self&&self.Object===Object&&self,Zn=Nn||Pn||Function("return this")(),qn=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Vn=qn&&typeof module=="object"&&module&&!module.nodeType&&module,Kn=Vn&&Vn.exports===qn,Gn=Kn&&Nn.process; +n:{try{Mn=Gn&&Gn.binding&&Gn.binding("util");break n}catch(n){}Mn=void 0}var Hn=Mn&&Mn.isArrayBuffer,Jn=Mn&&Mn.isDate,Yn=Mn&&Mn.isMap,Qn=Mn&&Mn.isRegExp,Xn=Mn&&Mn.isSet,nt=Mn&&Mn.isTypedArray,tt=j("length"),rt=w({"\xc0":"A","\xc1":"A","\xc2":"A","\xc3":"A","\xc4":"A","\xc5":"A","\xe0":"a","\xe1":"a","\xe2":"a","\xe3":"a","\xe4":"a","\xe5":"a","\xc7":"C","\xe7":"c","\xd0":"D","\xf0":"d","\xc8":"E","\xc9":"E","\xca":"E","\xcb":"E","\xe8":"e","\xe9":"e","\xea":"e","\xeb":"e","\xcc":"I","\xcd":"I","\xce":"I", +"\xcf":"I","\xec":"i","\xed":"i","\xee":"i","\xef":"i","\xd1":"N","\xf1":"n","\xd2":"O","\xd3":"O","\xd4":"O","\xd5":"O","\xd6":"O","\xd8":"O","\xf2":"o","\xf3":"o","\xf4":"o","\xf5":"o","\xf6":"o","\xf8":"o","\xd9":"U","\xda":"U","\xdb":"U","\xdc":"U","\xf9":"u","\xfa":"u","\xfb":"u","\xfc":"u","\xdd":"Y","\xfd":"y","\xff":"y","\xc6":"Ae","\xe6":"ae","\xde":"Th","\xfe":"th","\xdf":"ss","\u0100":"A","\u0102":"A","\u0104":"A","\u0101":"a","\u0103":"a","\u0105":"a","\u0106":"C","\u0108":"C","\u010a":"C", +"\u010c":"C","\u0107":"c","\u0109":"c","\u010b":"c","\u010d":"c","\u010e":"D","\u0110":"D","\u010f":"d","\u0111":"d","\u0112":"E","\u0114":"E","\u0116":"E","\u0118":"E","\u011a":"E","\u0113":"e","\u0115":"e","\u0117":"e","\u0119":"e","\u011b":"e","\u011c":"G","\u011e":"G","\u0120":"G","\u0122":"G","\u011d":"g","\u011f":"g","\u0121":"g","\u0123":"g","\u0124":"H","\u0126":"H","\u0125":"h","\u0127":"h","\u0128":"I","\u012a":"I","\u012c":"I","\u012e":"I","\u0130":"I","\u0129":"i","\u012b":"i","\u012d":"i", +"\u012f":"i","\u0131":"i","\u0134":"J","\u0135":"j","\u0136":"K","\u0137":"k","\u0138":"k","\u0139":"L","\u013b":"L","\u013d":"L","\u013f":"L","\u0141":"L","\u013a":"l","\u013c":"l","\u013e":"l","\u0140":"l","\u0142":"l","\u0143":"N","\u0145":"N","\u0147":"N","\u014a":"N","\u0144":"n","\u0146":"n","\u0148":"n","\u014b":"n","\u014c":"O","\u014e":"O","\u0150":"O","\u014d":"o","\u014f":"o","\u0151":"o","\u0154":"R","\u0156":"R","\u0158":"R","\u0155":"r","\u0157":"r","\u0159":"r","\u015a":"S","\u015c":"S", +"\u015e":"S","\u0160":"S","\u015b":"s","\u015d":"s","\u015f":"s","\u0161":"s","\u0162":"T","\u0164":"T","\u0166":"T","\u0163":"t","\u0165":"t","\u0167":"t","\u0168":"U","\u016a":"U","\u016c":"U","\u016e":"U","\u0170":"U","\u0172":"U","\u0169":"u","\u016b":"u","\u016d":"u","\u016f":"u","\u0171":"u","\u0173":"u","\u0174":"W","\u0175":"w","\u0176":"Y","\u0177":"y","\u0178":"Y","\u0179":"Z","\u017b":"Z","\u017d":"Z","\u017a":"z","\u017c":"z","\u017e":"z","\u0132":"IJ","\u0133":"ij","\u0152":"Oe","\u0153":"oe", +"\u0149":"'n","\u017f":"s"}),et=w({"&":"&","<":"<",">":">",'"':""","'":"'"}),ut=w({"&":"&","<":"<",">":">",""":'"',"'":"'"}),it=function w(En){function On(n){if(xu(n)&&!af(n)&&!(n instanceof Mn)){if(n instanceof zn)return n;if(ci.call(n,"__wrapped__"))return Pe(n)}return new zn(n)}function Sn(){}function zn(n,t){this.__wrapped__=n,this.__actions__=[],this.__chain__=!!t,this.__index__=0,this.__values__=F}function Mn(n){this.__wrapped__=n,this.__actions__=[],this.__dir__=1, +this.__filtered__=false,this.__iteratees__=[],this.__takeCount__=4294967295,this.__views__=[]}function Tn(n){var t=-1,r=null==n?0:n.length;for(this.clear();++t
-
- `
- mainDiv.appendChild(threadDiv)
-}
-function createComment(comment) {
- const isDeleted = deletedCommentIDs.includes(comment.id)
- const isRemoved = comment.hasOwnProperty("removed")
-
- return generateHTML(`
-
-
-
-
- ${prettyScore(thread.score)}
-
-
- ${thread.link_flair_text !== null ? ''+thread.link_flair_text+'' : ''}
- ${thread.title}
- (${thread.domain})
-
- ${thread.selftext !== '' ? '
' : ''}
-
- '+markdown.render(thread.selftext)+'
':''}
- ${totalComments} comments
- ${thread.media !== null ? parseHTML(thread.media_embed.content) : ''}
- ${imageHosts.includes(thread.domain) && thread.hasOwnProperty("preview") ? '
-
- `))
-}
-
-// Works for everything except iframes/script-tags, use "old fashion"-way in those cases (createElement etc...)
-function generateHTML(html) {
- return htmlParser.parseFromString(html, "text/html").body.firstChild
-}
-
-// "<" => "<"
-function parseHTML(html) {
- const dummy = document.createElement('div')
- dummy.innerHTML = html
- return dummy.childNodes.length === 0 ? "" : dummy.childNodes[0].nodeValue;
-}
-
-
-// ------------------------------------------------------------------------------
-// ----------------------------- AJAX-functions ---------------------------------
-// ------------------------------------------------------------------------------
-
-async function fetchMultiple(url, data, init, jsonWalkdown=[], flattening=false) {
- const responses = await Promise.all(splitArray(data, maxIDsPerRequest).map(singleRequestData => fetch(url + singleRequestData.join(), init)))
- let json = await Promise.all(responses.map(x => x.json()))
- jsonWalkdown.forEach(property =>{
- json.forEach((x, i) => json[i] = json[i][property])
- })
- return flattening ? flattenArray(json) : json
-}
-
-async function getToken() {
- const data = await fetch(redditTokenURL, tokenInit).then(json)
- return data.access_token
-}
-
-// ------------------------------------------------------------------------------
-// ---------------------- Other less interesting functions ----------------------
-// ------------------------------------------------------------------------------
-
-function splitArray(array, size) {
- const arraySplit = []
-
- for(let i = 0, len = array.length ; i < len; i += size) {
- arraySplit.push(array.slice(i, i + size))
- }
-
- return arraySplit
-}
-
-function flattenArray(arrays) {
- return arrays.reduce((array, item) => { return array.concat(item) }, [])
-}
-
-function setLoadingText(text) {
- loadingText.innerHTML = text
-}
-
-function json(x) {
- return x.json()
-}
-
-function displayError(errorMsg) {
- statusImage.src = errorImageSrc
- setLoadingText("ERROR: " + errorMsg + "")
- console.error(errorMsg)
-}
-
-function getCommentContext() {
- let commentToot = ""
-
- if(window.location.pathname.split("/").length >= 7) {
- commentToot = window.location.pathname.split("/")[6]
- }
-
- if(window.location.hash.length === 8) {
- commentToot = window.location.hash.substring(1)
- }
-
- return commentToot
-}
-
-// UTC -> "Reddit time format" (5 hours ago, just now, etc...)
-function prettyDate(createdUTC) {
- const currentUTC = Math.floor((new Date()).getTime() / 1000)
- const secondDiff = currentUTC - createdUTC
- const dayDiff = Math.floor(secondDiff / 86400)
-
- if(dayDiff < 0)
- return ''
-
- if(dayDiff == 0) {
- if(secondDiff < 10)
- return "just now"
- if(secondDiff < 60)
- return secondDiff + " seconds ago"
- if(secondDiff < 120)
- return "a minute ago"
- if(secondDiff < 3600)
- return Math.floor(secondDiff / 60) + " minutes ago"
- if(secondDiff < 7200)
- return "an hour ago"
- if(secondDiff < 86400)
- return Math.floor(secondDiff / 3600) + " hours ago"
- }
- //if(dayDiff == 1)
- // return "Yesterday"
- if(dayDiff < 7)
- return dayDiff + " days ago"
- if(dayDiff < 31)
- return Math.floor(dayDiff / 7) + " weeks ago"
- if(dayDiff < 365)
- return Math.floor(dayDiff / 30) + " months ago"
- return Math.floor(dayDiff / 365) + " years ago"
-}
-
-// 12000 => 1.2k
-function prettyScore(score) {
- return score >= 10000 ? (score / 1000).toFixed(1) + "k" : score
-}
\ No newline at end of file
diff --git a/static/style.css b/static/style.css
index 904b27b..bd12026 100644
--- a/static/style.css
+++ b/static/style.css
@@ -197,6 +197,11 @@ a:hover {
margin: 4px 0;
}
+.grey-link, .grey-link:link, .grey-link:visited, .grey-link:hover, .grey-link:focus, .grey-link:active {
+ color: #828282;
+}
+
+
#thread-selftext {
border: 1px solid #666;
border-radius: 7px;
@@ -270,6 +275,10 @@ a:hover {
background-color: #840c09/*#633636*/;
}
+.comment-deleted {
+ background-color: #00007D;
+}
+
.comment-odd {
background-color: #121212;
}
diff --git a/static/thread.js b/static/thread.js
new file mode 100644
index 0000000..2228df5
--- /dev/null
+++ b/static/thread.js
@@ -0,0 +1,382 @@
+"use strict";
+
+var app = (function(){
+return {
+ loadPage: function() {
+ // Just fucking crach if the user is retarded
+ if(_.isUndefined(Reddit.threadID) || _.isUndefined(Reddit.subreddit)) {
+ Status.error("Missing necessary parts of the URL");
+ return;
+ }
+
+ Status.loading("Loading thread...");
+ Reddit.fetchToken()
+ .then(function(){
+ return Promise.all([
+ fetch(URLs.thread, Reddit.init)
+ .then(Fetch2.json)
+ .then(ThreadHTML.createThread),
+
+ fetch(URLs.pushshiftIDs)
+ .then(Fetch2.json)
+ .then(_.property("data"))
+ ])
+ })
+ .then(function(results) {
+ var thread = results[0];
+ Comments.allIDs = results[1];
+
+ Status.loading("Loading comments from reddit...");
+ HandleIDs.normal(thread);
+ console.log("After normal", Comments.ids.length);
+ return HandleIDs.morechildren();
+ })
+ .then(function(){
+ console.log("After morechildren", Comments.ids.length);
+ return Promise.all(_.map(_.uniq(Comments.countinuethread), function(id) {
+ return fetch(URLs.thread+"/_/"+id.split("_")[1], Reddit.init)
+ .then(Fetch2.json)
+ }));
+ }).then(function(smallerThreads){
+ _.forEach(smallerThreads, function(thread){
+ HandleIDs.normal(thread);
+ })
+ console.log("After continueThisThread", Comments.ids.length);
+ console.log("Total", Comments.ids.length);
+ console.log("Unique", _.uniq(Comments.ids).length);
+ Status.loading("Getting removed comments...");
+ HandleIDs.removed();
+ console.log("Removed", Comments.removed.length);
+ ThreadHTML.createCommentInfo(Comments.removed.length);
+ return Fetch2.multiple(URLs.format(URLs.pushshiftComments, Comments.removed), null, "data");
+ })
+ .then(function(removedComments){
+ Status.loading("Generating comments...");
+ return Comments.generate(removedComments);
+ })
+ .then(function(){
+ Status.success();
+ });
+ }
+}})()
+
+// ------------------------------------------------------------------------------
+// ----------------------- 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(window.location.pathname.split("/").length >= 7) {
+ if(window.location.pathname.split("/")[6] !== "") {
+ return window.location.pathname.split("/")[6];
+ }
+ }
+
+ return Reddit.threadID;
+ },
+ 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(){
+ //console.log("Removed length", Comments.removed.length)
+ //console.log("ToBeCreated", Comments.toBeCreated);
+ 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 ThreadHTML = (function(){
+ var mainDiv = document.getElementById("main");
+ // 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 threadDiv = document.createElement("div");
+ threadDiv.innerHTML = ' \
+
- removed comments: ${removedCommentsAmount}/${totalComments} (${ (100 * removedCommentsAmount / totalComments).toFixed(1)}%)
-
- sorted by: top
- \
+
\
+ ';
+ mainDiv.appendChild(threadDiv);
+ return data;
+ };
+
+ var createCommentInfo = function(totalRemovedComments){
+ var div = document.createElement("div");
+ div.innerHTML = ' \
+ \
+ \
+
\
+ \
+ '+Format.prettyScore(thread.score)+'
\
+ \
+ \
+ '+(thread.link_flair_text !== null ? ''+thread.link_flair_text+'' : '') +
+ ''+thread.title+' \
+ ('+thread.domain+') \
+
' : '') +
+ '
\
+ \
+ submitted '+Format.prettyDate(thread.created_utc)+' by \
+ '+thread.author+' to \
+ /r/'+thread.subreddit+' \
+
' +
+ (thread.selftext !== '' ? ''+Format.parse(thread.selftext)+'
':'') +
+ '' +
+ (thread.media !== null ? HTML.parse(thread.media_embed.content) : '') +
+ (_.includes(imageHosts, thread.domain) && _.has(thread, "preview") ? ' \
+ removed comments: '+totalRemovedComments+'/'+Comments.getTotalComments()+' ('+(100 * totalRemovedComments / Comments.getTotalComments()).toFixed(1)+'%) \
+
\
+ sorted by: top
\
+ ';
+
+ mainDiv.appendChild(div);
+ };
+
+ var createCommentSection = function(){
+ var div = document.createElement("div");
+ div.id = Comments.getRoot();
+ mainDiv.appendChild(div);
+ };
+
+ var createComments = function(){
+ var commentsToCreate = _.sortBy(_.uniq(Comments.toBeCreated), function(id) {
+ return Comments.lookup[id].score;
+ });
+
+ var createdComments = [Reddit.threadID];
+ 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;
+ }
+ }
+ };
+
+ var createComment = function(comment){
+ var isRemoved = _.has(comment,"removed");
+ var isDeleted = _.has(comment,"deleted");
+
+ // Sorry
+ var commentCss = "comment-" + (isRemoved ? "removed" : (isDeleted ? "deleted" : (comment.depth % 2 == 0 ? "even" : "odd")));
+
+ var commentDiv = document.createElement("div");
+ commentDiv.id = comment.id;
+ commentDiv.className = "comment " + commentCss;
+ commentDiv.innerHTML = ' \
+ \
+ [–] \
+ '+comment.author+(isDeleted ? " (deleted by user)" : "")+' \
+ '+Format.prettyScore(comment.score)+' point'+((comment.score == 1) ? '': 's')+' \
+ '+Format.prettyDate(comment.created_utc)+' \
+
\
+ '+(comment.body === "[removed]" && isRemoved ? "
\
+ [likely removed by automoderator]
" : Format.parse(comment.body))+' \
+ permalink \
+
';
+
+ return commentDiv;
+ };
+
+ return {
+ createThread: createThread,
+ createCommentInfo: createCommentInfo,
+ createCommentSection: createCommentSection,
+ createComments: createComments
+ }
+})()
+
+app.loadPage()
\ No newline at end of file
diff --git a/thread.html b/thread.html
index e990955..2dba110 100644
--- a/thread.html
+++ b/thread.html
@@ -8,7 +8,7 @@
Removeddit [beta]
+Removeddit
@@ -17,8 +17,12 @@
+
+
+
-
+
+
-
[likely removed by automoderator]
" : markdown.render(comment.body)}