diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..7c7a3c8 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + "presets": [ + "@babel/preset-react", + "@babel/preset-es2015" + ], + "plugins": [ + "@babel/plugin-transform-async-to-generator" + ] +} \ No newline at end of file diff --git a/about.html b/about.html deleted file mode 100644 index 2dc57d7..0000000 --- a/about.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - Removeddit - - - - - - - - -
- -
-
-
-

About

-

Display removed (by mods) and deleted (by users) comments/threads from Reddit.

-

Usage: Drag this bookmarklet Removeddit - to your bookmark bar and use it to get from reddit to removeddit.

Alternatively you can manually replace the reddit in the URL to removeddit.
E.g. https://www.removeddit.com/r/TwoXChromosomes/comments/6z1hch/ -

-

Created by Jesper Wrang and uses Jason Baumgartner service for getting removed comments.

-

TODO

- -

Links/Contact

-

For feedback and bug reports:

- -

Code on Github.

-
-
- - \ No newline at end of file diff --git a/compile.sh b/compile.sh deleted file mode 100755 index 4948d63..0000000 --- a/compile.sh +++ /dev/null @@ -1,12 +0,0 @@ -### Use these for production - -pug -P -o . pug/about.pug pug/thread.pug pug/subreddit.pug pug/search.pug -sass --sourcemap=none --style expanded sass/main.sass static/css/style.css -lodash include=defaultTo,toLower,includes,parseInt,has,isNil,uniq,property,map,forEach,join,sortBy,get,now,template -p -o static/js/libraries/lodash.custom.min.js -lodash template="jst/*.jst" -p -o static/js/libraries/lodash.templates.min.js - -### Use these in development - -#pug --watch -P -o . pug/about.pug pug/thread.pug pug/subreddit.pug pug/search.pug -#sass --watch --sourcemap=none --style expanded sass/main.sass:static/css/style.css -#lodash template="jst/*.jst" -d -o static/js/libraries/lodash.templates.min.js diff --git a/static/js/functions.js b/js/functions.js similarity index 100% rename from static/js/functions.js rename to js/functions.js diff --git a/static/js/libraries/js.cookie.js b/js/libraries/js.cookie.js similarity index 100% rename from static/js/libraries/js.cookie.js rename to js/libraries/js.cookie.js diff --git a/static/js/libraries/lodash.custom.min.js b/js/libraries/lodash.custom.min.js similarity index 100% rename from static/js/libraries/lodash.custom.min.js rename to js/libraries/lodash.custom.min.js diff --git a/js/libraries/lodash.templates.min.js b/js/libraries/lodash.templates.min.js new file mode 100644 index 0000000..8912629 --- /dev/null +++ b/js/libraries/lodash.templates.min.js @@ -0,0 +1,328 @@ +;(function() { + var undefined; + + var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; + + var freeSelf = typeof self == 'object' && self && self.Object === Object && self; + + var root = freeGlobal || freeSelf || Function('return this')(); + + var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports; + + var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module; + + var _ = root._ || {}; + + /*----------------------------------------------------------------------------*/ + + var templates = { + 'comment': {}, + 'elasticCommentIDs': {}, + 'elasticComments': {}, + 'elasticSubreddit': {}, + 'elasticThread': {}, + 'search': {}, + 'subredditInfo': {}, + 'subredditPagination': {}, + 'thread': {}, + 'threadInfo': {} + }; + + templates['comment'] = function(obj) { + obj || (obj = {}); + var __t, __p = '', __j = Array.prototype.join; + function print() { __p += __j.call(arguments, '') } + with (obj) { + + var isRemoved = _.has(comment,"removed"); + var isDeleted = _.has(comment,"deleted"); + + var commentCss = "comment comment-" + (isRemoved ? "removed" : (isDeleted ? "deleted" : (comment.depth % 2 == 0 ? "even" : "odd"))); + __p += '\n\n
\n
\n [–]\n \n ' + + ((__t = ( comment.author+(isDeleted ? " (deleted by user)" : "") )) == null ? '' : __t) + + '\n \n ' + + ((__t = ( Format.prettyScore(comment.score) )) == null ? '' : __t) + + ' point' + + ((__t = ( ((comment.score == 1) ? "": "s") )) == null ? '' : __t) + + '\n ' + + ((__t = ( Format.prettyDate(comment.created_utc) )) == null ? '' : __t) + + '\n
\n
\n ' + + ((__t = ( (comment.body === "[removed]" && isRemoved ? "

[likely removed by automoderator]

" : Format.parse(comment.body)) )) == null ? '' : __t) + + '\n
\n \n
\n\n'; + + } + return __p + }; + + templates['elasticCommentIDs'] = function(obj) { + obj || (obj = {}); + var __t, __p = ''; + with (obj) { + __p += '{\n "query":{\n "ids":{\n "values":[' + + ((__t = ( ids.join() )) == null ? '' : __t) + + ']\n }\n },\n "_source":[\n "author","body","created_utc","parent_id","score"\n ]\n}'; + + } + return __p + }; + + templates['elasticComments'] = function(obj) { + obj || (obj = {}); + var __t, __p = ''; + with (obj) { + __p += '{\n "query":{\n "term":{\n "link_id":' + + ((__t = ( id )) == null ? '' : __t) + + '\n }\n },\n "_source":[\n "author","body","created_utc","parent_id","score"\n ],\n "size":20\n}'; + + } + return __p + }; + + templates['elasticSubreddit'] = function(obj) { + obj || (obj = {}); + var __t, __p = '', __j = Array.prototype.join; + function print() { __p += __j.call(arguments, '') } + with (obj) { + __p += '{\n "query":{\n "bool":{\n "must":[\n '; + if(_.toLower(subreddit) !== "all") { + __p += '\n {\n "term":{\n "subreddit":"' + + ((__t = ( _.toLower(subreddit) )) == null ? '' : __t) + + '"\n }\n },\n '; + } + __p += '\n {\n "range":{\n "created_utc":{\n "gt":' + + ((__t = ( time )) == null ? '' : __t) + + '\n }\n }\n }\n ]\n }\n },\n "_source":[\n "author","url","subreddit","link_flair_text","score","title","created_utc","num_comments","domain","permalink","id","thumbnail","thumbnail_height","thumbnail_width"\n ],\n "sort":[\n {"score":"desc"}\n ],\n "from":' + + ((__t = ( (page-1)*postPerPage )) == null ? '' : __t) + + ',\n "size":' + + ((__t = ( postPerPage )) == null ? '' : __t) + + '\n}'; + + } + return __p + }; + + templates['elasticThread'] = function(obj) { + obj || (obj = {}); + var __t, __p = ''; + with (obj) { + __p += '{\n "query":{\n "term":{\n "id":"' + + ((__t = ( id )) == null ? '' : __t) + + '"\n }\n },\n "_source":[\n "author","created_utc","domain","link_flair_text","num_comments","url","subreddit","score","title","selftext","permalink","thumbnail","thumbnail_height","thumbnail_width"\n ],\n "size":1\n}'; + + } + return __p + }; + + templates['search'] = function(obj) { + obj || (obj = {}); + var __t, __p = ''; + with (obj) { + __p += '\n var radioInput = function(name, displayNames, values) {\n var inputs = "";\n \n for(var i = 0, len = displayNames.length; i < len; i++){\n inputs += \'\';\n inputs += \'\';\n inputs += \'\';\n }\n return inputs;\n };\n\n var textInput = function(name){\n return \'\'; \n };\n\n var label = function(name, display) {\n return \'\';\n };\n\n var inputRow = function(text, input) {\n return \'
\'+text+\'\'+input+"
";\n };\n\n var selectTime = function() {\n var values = ["hour", "12hour", "day", "week", "month", "6month", "year", "all"];\n var display = ["past hour", "past 12 hours", "past day", "past week", "past month", "past 6 months", "past year", "all time"];\n var html = \'";\n };\n\n var select = function(name, display, values){\n var html = \'";\n };\n\nreturn {\n createSearch: function(){\n var searchBox = document.createElement("div");\n searchBox.id = "main-box";\n searchBox.className = "search-box";\n /*\n Comments:\n text (body) string\n title (title) string\n subreddit (subreddit) string\n author (author) string\n over_18 (over_18) sfw,nsfw,both *\n locked (locked) bool *\n between (after/before) "date"\n sort (sort) asc,desc\n */\n var html = inputRow(\'Im looking for: \', radioInput("thread", ["Thread","Comment"], ["true", "false"])); \n html += inputRow(label("text", "Text"), textInput("text"));\n html += inputRow(label("title","Title"), textInput("title"));\n html += inputRow(label("subreddit", "Subreddit"), textInput("subreddit"));\n html += inputRow(label("author", "Author"), textInput("author"));\n html += inputRow("Over 18: ", radioInput("over_18", ["Both","NSFW","SFW"], ["both","nsfw","sfw"]));\n html += inputRow("Locked: ", radioInput("locked", ["Both","True", "False"], ["both","true","false"]));\n html += inputRow("Removed: ", select("removed", ["Removed and non-removed", "Only removed", "Only deleted"], ["all", "removed", "deleted"]));\n html += inputRow("From:", selectTime());\n html += inputRow("Sort: ", select("sort", ["Highest score","Lowest score","Newest","Oldest"], ["score_desc","score_asc","time_desc","time_asc"]));\n html += \'\';\n html += \'\';\n searchBox.innerHTML = html;\n \n mainDiv.appendChild(searchBox);'; + + } + return __p + }; + + templates['subredditInfo'] = function(obj) { + obj || (obj = {}); + var __t, __p = '', __j = Array.prototype.join; + function print() { __p += __j.call(arguments, '') } + with (obj) { + __p += '
\n top post of /r/' + + ((__t = ( subreddit )) == null ? '' : __t) + + ' from:\n \';\n\t\t\tinputs += \'\';\n\t\t}\n\t\treturn inputs;\n\t};\n\n\tvar textInput = function(name){\n\t\treturn \'\'; \n\t};\n\n\tvar label = function(name, display) {\n\t\treturn \'\';\n\t};\n\n\tvar inputRow = function(text, input) {\n\t\treturn \'
\'+text+\'\'+input+"
";\n\t};\n\n\tvar selectTime = function() {\n\t\tvar values = ["hour", "12hour", "day", "week", "month", "6month", "year", "all"];\n\t\tvar display = ["past hour", "past 12 hours", "past day", "past week", "past month", "past 6 months", "past year", "all time"];\n\t\tvar html = \'";\n\t};\n\n\tvar select = function(name, display, values){\n\t\tvar html = \'";\n\t};\n\nreturn {\n\tcreateSearch: function(){\n\t\tvar searchBox = document.createElement("div");\n\t\tsearchBox.id = "main-box";\n\t\tsearchBox.className = "search-box";\n\t/*\n\t\tComments:\n\t\ttext\t\t\t(body)\t\tstring\n\t\ttitle \t\t(title)\t\tstring\n\t\tsubreddit\t\t(subreddit)\tstring\n\t\tauthor\t\t(author)\t\tstring\n\t\tover_18\t\t(over_18)\t\tsfw,nsfw,both *\n\t\tlocked\t\t(locked)\t\tbool *\n\t\tbetween\t\t(after/before)\t"date"\n\t\tsort \t\t(sort)\t\tasc,desc\n\t*/\n\t\tvar html = inputRow(\'Im looking for: \', radioInput("thread", ["Thread","Comment"], ["true", "false"]));\t\t\n\t\thtml += inputRow(label("text", "Text"), textInput("text"));\n\t\thtml += inputRow(label("title","Title"), textInput("title"));\n\t\thtml += inputRow(label("subreddit", "Subreddit"), textInput("subreddit"));\n\t\thtml += inputRow(label("author", "Author"), textInput("author"));\n\t\thtml += inputRow("Over 18: ", radioInput("over_18", ["Both","NSFW","SFW"], ["both","nsfw","sfw"]));\n\t\thtml += inputRow("Locked: ", radioInput("locked", ["Both","True", "False"], ["both","true","false"]));\n\t\thtml += inputRow("Removed: ", select("removed", ["Removed and non-removed", "Only removed", "Only deleted"], ["all", "removed", "deleted"]));\n\t\thtml += inputRow("From:", selectTime());\n\t\thtml += inputRow("Sort: ", select("sort", ["Highest score","Lowest score","Newest","Oldest"], ["score_desc","score_asc","time_desc","time_asc"]));\n\t\thtml += \'\';\n\t\thtml += \'\';\n\t\tsearchBox.innerHTML = html;\n\t\n\t\tmainDiv.appendChild(searchBox);'; -},subredditInfo:function(a){a||(a={});var b;with(a)a=""+('
\n\ttop post of /r/'+(null==(b=subreddit)?"":b)+' from:\n\t\t\t\t\t\n
"},subredditPagination:function(a){a||(a={});var b;with(a){a='"},thread:function(a){a||(a={});var b;with(a){a='
\n',typeof postNr!="undefined"&&(a+='\n\t'+(null==(b=postNr)?"":b)+"\n"),a+='\n\t
\n\t\t
\n\t\t
'+(null==(b=Format.prettyScore(thread.score))?"":b)+'
\n\t\t
\n\t
\n'; -var d=c.replace(thread.url,"https://www.reddit.com","https://www.removeddit.com");if(c.includes(["self","default","image","nsfw"],thread.thumbnail))a+='\n\t\t\n';else{var e=.5*c.defaultTo(thread.thumbnail_width,140),f=.5*c.defaultTo(thread.thumbnail_height,140);a+='\t\n\t\t\t\n\t\t\n'; -}a+='\n\t
\n\n\t\t'+(null==(b=thread.title)?"":b)+"\n",c.isNil(thread.link_flair_text)||(a+='\n\t\t'+(null==(b=thread.link_flair_text)?"":b)+"\n"),a+='\t\n\t\t('+(null==(b=thread.domain)?"":b)+')\n\t\t
\n\t\t\tsubmitted '+(null==(b=Format.prettyDate(thread.created_utc))?"":b)+' by\n\t\t\t'+(null==(b=thread.author)?"":b)+"\n\t\t", -Reddit.isAll&&(a+='\n\t\t\tto /r/'+(null==(b=thread.subreddit)?"":b)+"\n\t\t"),a+='\t\t\n\t\t
\n\t\t\n\t
\n
'; -}return a},threadInfo:function(a){a||(a={});var b;with(a)a=""+('
\n\tremoved comments: '+(null==(b=removedComments)?"":b)+"/"+(null==(b=totalComments)?"":b)+" ("+(null==(b=(100*removedComments/totalComments).toFixed(1))?"":b)+'%)\n
\n
sorted by: top
');return a}};typeof define=="function"&&typeof define.amd=="object"&&define.amd? define(["lodash"],function(t){c=t,t.templates=t.extend(t.templates||{},d)}):h?(c=require("lodash"),(h.exports=d).templates=d, -f.templates=d):c&&(c.templates=c.extend(c.templates||{},d))}).call(this); \ No newline at end of file diff --git a/subreddit.html b/subreddit.html deleted file mode 100644 index a8c6d14..0000000 --- a/subreddit.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - Removeddit - - - - - - - - -
- -
-

-
-
-
-
- - - - - - - - - \ No newline at end of file diff --git a/thread.html b/thread.html deleted file mode 100644 index a29dbf2..0000000 --- a/thread.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - Removeddit - - - - - - - - -
- -
-

-
-
-
-
- - - - - - - - - \ No newline at end of file diff --git a/webpack.common.js b/webpack.common.js index e10372a..0e7361a 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -2,20 +2,27 @@ const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const CleanWebpackPlugin = require('clean-webpack-plugin'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); + +const extractSass = new ExtractTextPlugin({ + filename: 'bundle.[contenthash].css', +}); + module.exports = { entry: [ - './src/js/index.js' + '@babel/polyfill', + 'whatwg-fetch', + './src/js/index.js', ], output: { path: path.resolve(__dirname, 'dist'), - filename: 'bundle.js', - publicPath: '/' + filename: 'bundle.[chunkhash].js', + publicPath: './' }, resolve: { modules: [ path.resolve('./src/js'), - path.resolve('./src'), path.resolve('./node_modules') ] }, @@ -23,20 +30,31 @@ module.exports = { loaders: [ { test: /\.js$/, - loader: 'babel-loader', exclude: /node_modules/, - query: { - presets: ["@babel/preset-react"], - } + use: [ + { + loader: 'babel-loader', + options: { + cacheDirectory: true + } + } + ] }, { test: /\.html$/, loader: 'html-loader' - }, + }, + { + test: /\.sass$/, + loader: extractSass.extract({ + use: ['css-loader','sass-loader'] + }) + } ] }, plugins: [ new CleanWebpackPlugin(['dist']), + extractSass, new HtmlWebpackPlugin({ template: 'src/index.html' }),