mirror of
https://github.com/gurnec/removeddit.git
synced 2026-03-11 08:54:27 +00:00
Added support for permalinks
This commit is contained in:
parent
17d3a8a3f7
commit
166846671f
4 changed files with 45 additions and 21 deletions
12
README.md
12
README.md
|
|
@ -8,7 +8,7 @@ This is a done by comparing the comments found from Reddit API and comments from
|
|||
# The "I just want to get this shit running" guide
|
||||
Using [Ubuntu 16.04](http://releases.ubuntu.com/16.04/) and [nginx](https://www.nginx.com/resources/wiki/)
|
||||
```
|
||||
sudo git clone git@github.com:JubbeArt/removeddit.git /var/www/
|
||||
sudo git clone https://github.com/JubbeArt/removeddit.git /var/www/removeddit
|
||||
sudo apt install -y nginx
|
||||
sudo cp /var/www/removeddit/config/basic /etc/nginx/sites-available/default
|
||||
```
|
||||
|
|
@ -55,7 +55,7 @@ Change both the "server_name" in the config to your domain name.
|
|||
## SSL with Let's encrypt
|
||||
Read the full guide [here](https://certbot.eff.org/#ubuntutyakkety-nginx). Start of by installing the Let's Encrypt client [certbot](https://certbot.eff.org/)
|
||||
```
|
||||
sudo apt install software-properties-common
|
||||
sudo apt install -y software-properties-common
|
||||
sudo add-apt-repository ppa:certbot/certbot
|
||||
sudo apt update
|
||||
sudo apt install -y python-certbot-nginx
|
||||
|
|
@ -64,18 +64,18 @@ sudo apt install -y python-certbot-nginx
|
|||
Copy the Let's Encrypt config file for our site
|
||||
```
|
||||
sudo mkdir /etc/letsencrypt/configs
|
||||
cp /var/www/removeddit/config/letsencrypt /etc/letsencrypt/configs/removeddit.com.conf
|
||||
cp /var/www/removeddit/config/letsencrypt.conf /etc/letsencrypt/configs/removeddit.com.conf
|
||||
```
|
||||
|
||||
In this config file change the domains and the email for your own. The email is tells when the certificates are close to expiring.
|
||||
In this config file change the domains and the email address for your own. The emails tells you when the certificates are close to expiring.
|
||||
|
||||
This is when the webmasters start praying to God Almighty, for only He can deside the fate of the certbot.
|
||||
This is when the webmasters start praying to God, for only He can deside the fate of the certbot.
|
||||
Forgive me, Father, for I have sinned. Just don't fuck up certs you asshole.
|
||||
```
|
||||
sudo certbot --config /etc/letsencrypt/configs/removeddit.com.conf certonly
|
||||
```
|
||||
|
||||
You'll now have a valid SSL certificate (hopefully)! You might have to edit the path for `ssl_certificate` and `ssl_certificate_key` in `/etc/nginx/sites-available/removeddit.com` depending on where the certs are located. (Should be in `/etc/letsencrypt/live/`)
|
||||
You'll now have a valid SSL certificate (hopefully)! You now have to uncomment the `ssl_certificate` and `ssl_certificate_key` in `/etc/nginx/sites-available/removeddit.com` and maybe change the path depending on where the certs are located (check in `/etc/letsencrypt/live/`).
|
||||
|
||||
## Automated renewal of certs
|
||||
The certificate expires after 90 days so we want a way to atomatically update the certs.
|
||||
|
|
|
|||
|
|
@ -9,8 +9,9 @@ server {
|
|||
access_log /var/log/nginx/removeddit/access.log;
|
||||
error_log /var/log/nginx/removeddit/error.log;
|
||||
|
||||
ssl_certificate /etc/letsencrypt/live/removeddit.com/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/removeddit.com/privkey.pem;
|
||||
# Uncomment these after you've received the certificates
|
||||
#ssl_certificate /etc/letsencrypt/live/removeddit.com/fullchain.pem;
|
||||
#ssl_certificate_key /etc/letsencrypt/live/removeddit.com/privkey.pem;
|
||||
|
||||
location / {
|
||||
try_files /index.html /index.html =404;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
<h2 style="color:#CA302C; margin-top:5px">About</h2>
|
||||
<p>
|
||||
This is a site for viewing removed comments from Reddit.
|
||||
It was created by Jesper Wrang and uses <a href="https://pushshift.io/">Jason Baumgartner</a> service for getting removed comments.</p>
|
||||
It was 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>
|
||||
<p>
|
||||
<b>How to use</b>: go to any Reddit thread and replace the <i>reddit</i> in the URL with <i>removeddit</i>
|
||||
<br>E.g.
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ if(pathname.length <= 4) {
|
|||
const subreddit = pathname[2]
|
||||
const threadID = pathname[4]
|
||||
|
||||
const root = getCommentContext() === "" ? threadID : getCommentContext()
|
||||
|
||||
const redditTokenURL = "https://www.reddit.com/api/v1/access_token"
|
||||
const redditThreadURL = `https://oauth.reddit.com/r/${subreddit}/comments/${threadID}`
|
||||
const redditMorechildrenURL = `https://oauth.reddit.com/api/morechildren?link_id=t3_${threadID}&children=`
|
||||
|
|
@ -149,7 +151,7 @@ function extractMorechildrenIDs(comments) {
|
|||
comments.jquery[14][3][0].forEach(comment => {
|
||||
if(comment.kind == "more") {
|
||||
if(comment.data.id === "_") {
|
||||
console.log("From more, continue: " + comment.data.parent_id)
|
||||
//console.log("From more, continue: " + comment.data.parent_id)
|
||||
continuethisthreadIDs.push(comment.data.parent_id)
|
||||
} else {
|
||||
const children = comment.data.children
|
||||
|
|
@ -184,11 +186,11 @@ async function getRemovedComments(allCommentIDs) {
|
|||
idsDiff = [...new Set(idsDiff)]
|
||||
|
||||
generateCommentInfo(idsDiff.length)
|
||||
console.log("All ids :", allCommentIDs)
|
||||
console.log("Comments ids (dup): ", commentIDs)
|
||||
console.log("With/without dups: ", commentIDs.length, new Set(commentIDs).size)
|
||||
console.log("Difference: ", idsDiff)
|
||||
console.log("Lookup size:", commentLookup.size)
|
||||
//console.log("All ids :", allCommentIDs)
|
||||
//console.log("Comments ids (dup): ", commentIDs)
|
||||
//console.log("With/without dups: ", commentIDs.length, new Set(commentIDs).size)
|
||||
//console.log("Difference: ", idsDiff)
|
||||
//console.log("Lookup size:", commentLookup.size)
|
||||
return fetchMultiple(pushshiftCommentsURL, idsDiff, null, ["data"], true)
|
||||
}
|
||||
|
||||
|
|
@ -198,7 +200,7 @@ async function getRemovedComments(allCommentIDs) {
|
|||
// ------------------------------------------------------------------------------
|
||||
|
||||
async function generateComments(removedComments) {
|
||||
const commentSection = generateHTML(`<div id="${threadID}"></div>`)
|
||||
const commentSection = generateHTML(`<div id="${threadID === root ? threadID : "0000000"}"></div>`)
|
||||
mainDiv.appendChild(commentSection)
|
||||
|
||||
removedComments.forEach(comment => {
|
||||
|
|
@ -232,7 +234,7 @@ async function getCommentsToGenerate(commentsToLookup) {
|
|||
else if(commentLookup.has(parentID)) {
|
||||
newCommentsToLookup.push(parentID)
|
||||
} else{
|
||||
console.error("Comment doesn't exists, but lets try it anyway :D")
|
||||
//console.error("Comment doesn't exists, but lets try it anyway :D")
|
||||
commentsToFetch.push(parentID)
|
||||
}
|
||||
|
||||
|
|
@ -241,10 +243,10 @@ async function getCommentsToGenerate(commentsToLookup) {
|
|||
|
||||
if(commentsToFetch.length !== 0) {
|
||||
const newComments = await fetch(redditSingleCommentURL + commentsToFetch.map(x => "t1_" + x).join(), redditInit).then(json)
|
||||
console.log(newComments)
|
||||
//console.log(newComments)
|
||||
|
||||
newComments.data.children.forEach(x => {
|
||||
console.log(x.data.id)
|
||||
//console.log(x.data.id)
|
||||
commentLookup.set(x.data.id, x.data)
|
||||
newCommentsToLookup.push(x.data.id)
|
||||
})
|
||||
|
|
@ -256,7 +258,12 @@ async function getCommentsToGenerate(commentsToLookup) {
|
|||
}
|
||||
|
||||
function createComments() {
|
||||
const createdCommentIDs = [threadID]
|
||||
const createdCommentIDs = [threadID === root ? threadID : "0000000"]
|
||||
|
||||
if(root !== threadID) {
|
||||
commentLookup.get(root).parent_id = "t1_0000000"
|
||||
}
|
||||
|
||||
let id, parentID
|
||||
let didSomething
|
||||
|
||||
|
|
@ -266,8 +273,10 @@ function createComments() {
|
|||
for(let i = commentsToCreate.length -1; i >= 0; i--) {
|
||||
id = commentsToCreate[i]
|
||||
parentID = commentLookup.get(id).parent_id.split("_")[1]
|
||||
//console.log(parentID)
|
||||
|
||||
if(createdCommentIDs.includes(parentID)) {
|
||||
//console.error("True :" + parentID)
|
||||
document.getElementById(parentID).appendChild(createComment(commentLookup.get(id)))
|
||||
createdCommentIDs.push(id)
|
||||
commentsToCreate.splice(i, 1)
|
||||
|
|
@ -333,7 +342,7 @@ function createComment(comment) {
|
|||
</div>
|
||||
<div class="comment-body">${comment.body === "[removed]" && isRemoved ? "<p>[likely removed by automoderator]</p>" : markdown.render(comment.body)}</div>
|
||||
<div class="comment-links">
|
||||
<a href="https://todo.com">permalink</a>
|
||||
<a href="/r/${subreddit}/comments/${threadID}/_/${comment.id}/">permalink</a>
|
||||
</div>
|
||||
</div>
|
||||
`)
|
||||
|
|
@ -413,6 +422,20 @@ function displayError(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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue