New Reddit Submission Delete

Automatically deletes all submissions on your userpage

질문, 리뷰하거나, 이 스크립트를 신고하세요.
  1. "use strict";
  2. // ==UserScript==
  3. // @name New Reddit Submission Delete
  4. // @version 1.0
  5. // @description Automatically deletes all submissions on your userpage
  6. // @author RootInit
  7. // @match https://www.reddit.com/user/*
  8. // @grant none
  9. // @license GPL V3
  10. // @namespace https://greasyfork.org/users/1312559
  11. // ==/UserScript==
  12. //
  13. //
  14. const DELAY = 800;
  15. // For debugging
  16. window.deleteNext = deleteNext;
  17. // Program begins here
  18. (async () => {
  19. const deleteConfirmation = confirm("Are you sure you want to delete ALL comments/posts?");
  20. if (deleteConfirmation) {
  21. // Get API token
  22. const token = getCSRFToken();
  23. if (token === null) {
  24. alert("Failed to get csrf_token. Unable to continue.");
  25. return;
  26. }
  27. // Loop deleting
  28. while (await deleteNext()) {
  29. await new Promise(resolve => setTimeout(resolve, DELAY));
  30. // Scroll down to load more
  31. window.scrollTo(0, document.body.scrollHeight);
  32. }
  33. }
  34. })();
  35. function getCSRFToken() {
  36. const match = document.cookie.match(RegExp('(?:^|;\\s*)csrf_token=([^;]*)'));
  37. if (match === null) {
  38. return null;
  39. }
  40. return match[1];
  41. }
  42. async function deleteNext() {
  43. const next = document.querySelector("shreddit-post, shreddit-profile-comment");
  44. if (next == null) {
  45. alert("No submissions found. Done.");
  46. return false;
  47. }
  48. let operation = "";
  49. let input;
  50. switch (next.tagName) {
  51. case "SHREDDIT-POST":
  52. operation = "DeletePost";
  53. input = { "postId": next.getAttribute("id") };
  54. break;
  55. case "SHREDDIT-PROFILE-COMMENT":
  56. operation = "DeleteComment";
  57. input = { "commentId": next.getAttribute("comment-id") };
  58. break;
  59. default:
  60. alert("Error: Invalid tag. This error should be impossible.");
  61. return false;
  62. }
  63. const data = {
  64. "operation": operation,
  65. "variables": {
  66. "input": input
  67. },
  68. "csrf_token": getCSRFToken()
  69. };
  70. const res = await graphqlPostRequest(JSON.stringify(data));
  71. if (res.status !== 200) {
  72. alert(`Error: Bad http response ${res.status}:\n${res.statusText}`);
  73. return false;
  74. }
  75. next.remove();
  76. return true;
  77. }
  78. async function graphqlPostRequest(body) {
  79. const response = await fetch("https://www.reddit.com/svc/shreddit/graphql", {
  80. "credentials": "include",
  81. "headers": {
  82. "User-Agent": navigator.userAgent,
  83. "Accept": "application/json",
  84. "Accept-Language": "en-US,en;q=0.5",
  85. "Content-Type": "application/json",
  86. "Sec-Fetch-Dest": "empty",
  87. "Sec-Fetch-Mode": "cors",
  88. "Sec-Fetch-Site": "same-origin",
  89. "Priority": "u=1"
  90. },
  91. "referrer": window.location.href,
  92. "body": body,
  93. "method": "POST",
  94. "mode": "cors"
  95. });
  96. return response;
  97. }