Last active
August 28, 2024 17:07
-
-
Save AdrienHorgnies/71d32a861ebf097a02113122778fbb9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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