Skip to content

Instantly share code, notes, and snippets.

@AdrienHorgnies
Last active August 28, 2024 17:07
Show Gist options
  • Save AdrienHorgnies/71d32a861ebf097a02113122778fbb9b to your computer and use it in GitHub Desktop.
Save AdrienHorgnies/71d32a861ebf097a02113122778fbb9b to your computer and use it in GitHub Desktop.
function deleteComments() {
document.querySelectorAll('shreddit-profile-comment').forEach(el => {
comment_id = el.getAttribute('comment-id')
csrf_token = document.cookie.split("csrf_token=")[1].split(';')[0]
fetch("https://www.reddit.com/svc/shreddit/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ "operation": "DeleteComment", "variables": { "input": { "commentId": comment_id } }, "csrf_token": csrf_token })
}).then(res => {
if (!res.ok) {
throw new Error('Network response was not ok');
}
return res.json();
}).then(data => {
if (data.errors.length === 0) {
console.log("deleting comment", comment_id, "was successful")
} else {
console.error("deleting comment", comment_id, "failed:", data.errors)
}
}).catch(err => {
console.error("Error:", err)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment