Advertisement
Guest User

Untitled

a guest
Jan 30th, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. javascript:(function(){
  2. 'use strict';
  3.  
  4.  
  5. function showToast(message, duration = 3000) {
  6. const toast = document.createElement('div');
  7. toast.textContent = message;
  8. toast.style.position = 'fixed';
  9. toast.style.bottom = '20px';
  10. toast.style.right = '20px';
  11. toast.style.padding = '10px';
  12. toast.style.margin = '10px';
  13. toast.style.borderRadius = '5px';
  14. toast.style.background = 'rgba(0, 0, 0, 0.7)';
  15. toast.style.color = 'white';
  16. toast.style.zIndex = '9999';
  17. toast.style.maxWidth = '300px';
  18. toast.style.textAlign = 'center';
  19. toast.style.transition = 'opacity 0.5s';
  20.  
  21. document.body.appendChild(toast);
  22.  
  23. setTimeout(() => {
  24. toast.style.opacity = '0';
  25. setTimeout(() => document.body.removeChild(toast), 500);
  26. }, duration);
  27. }
  28.  
  29.  
  30. async function approveComment(fullname) {
  31. try {
  32. const modhash = await fetch('/api/me.json', { credentials: 'include' })
  33. .then(response => response.json())
  34. .then(data => data.data.modhash);
  35.  
  36. const response = await fetch('/api/approve', {
  37. method: 'POST',
  38. headers: {
  39. 'Content-Type': 'application/x-www-form-urlencoded',
  40. },
  41. body: `id=${fullname}&uh=${modhash}`,
  42. credentials: 'include',
  43. });
  44.  
  45. if (response.ok) {
  46. showToast('Comment approved!', 2000);
  47. } else {
  48. showToast('Failed to approve comment.', 2000);
  49. }
  50. } catch (error) {
  51. console.error('Error approving comment:', error);
  52. showToast('Error approving comment. Check console for details.', 2000);
  53. }
  54. }
  55.  
  56.  
  57. async function approveUser(username, subreddit) {
  58. try {
  59. const modhash = await fetch('/api/me.json', { credentials: 'include' })
  60. .then(response => response.json())
  61. .then(data => data.data.modhash);
  62.  
  63. const response = await fetch(`/r/${subreddit}/api/approve`, {
  64. method: 'POST',
  65. headers: {
  66. 'Content-Type': 'application/x-www-form-urlencoded',
  67. },
  68. body: `name=${username}&uh=${modhash}`,
  69. credentials: 'include',
  70. });
  71.  
  72. if (response.ok) {
  73. showToast('User approved!', 2000);
  74. } else {
  75. showToast('Failed to approve user.', 2000);
  76. }
  77. } catch (error) {
  78. console.error('Error approving user:', error);
  79. showToast('Error approving user. Check console for details.', 2000);
  80. }
  81. }
  82.  
  83.  
  84. function injectApproveButtons() {
  85. document.querySelectorAll('.comment .tagline a.author').forEach(authorLink => {
  86. const comment = authorLink.closest('.comment');
  87. const fullname = comment.getAttribute('data-fullname');
  88. const existingButton = comment.querySelector('.approve-button');
  89. if (existingButton) return;
  90.  
  91. const approveButton = document.createElement('button');
  92. approveButton.textContent = 'Approve';
  93. approveButton.className = 'approve-button';
  94. approveButton.style.marginLeft = '5px';
  95. approveButton.style.padding = '2px 5px';
  96. approveButton.style.border = '1px solid #555';
  97. approveButton.style.borderRadius = '3px';
  98. approveButton.style.background = '#333';
  99. approveButton.style.color = 'white';
  100. approveButton.style.cursor = 'pointer';
  101. approveButton.addEventListener('click', () => approveComment(fullname));
  102. authorLink.parentNode.insertBefore(approveButton, authorLink.nextSibling);
  103. });
  104. }
  105.  
  106.  
  107. function injectApproveUserButtons() {
  108. document.querySelectorAll('.comment .tagline a.author').forEach(authorLink => {
  109. const comment = authorLink.closest('.comment');
  110. const username = authorLink.textContent.trim();
  111. const subreddit = window.location.pathname.split('/')[2];
  112. const existingButton = comment.querySelector('.approve-user-button');
  113. if (existingButton) return;
  114.  
  115. const approveUserButton = document.createElement('button');
  116. approveUserButton.textContent = 'Approve User';
  117. approveUserButton.className = 'approve-user-button';
  118. approveUserButton.style.marginLeft = '5px';
  119. approveUserButton.style.padding = '2px 5px';
  120. approveUserButton.style.border = '1px solid #555';
  121. approveUserButton.style.borderRadius = '3px';
  122. approveUserButton.style.background = '#333';
  123. approveUserButton.style.color = 'white';
  124. approveUserButton.style.cursor = 'pointer';
  125. approveUserButton.addEventListener('click', () => approveUser(username, subreddit));
  126. authorLink.parentNode.insertBefore(approveUserButton, authorLink.nextSibling);
  127. });
  128. }
  129.  
  130.  
  131. injectApproveButtons();
  132. injectApproveUserButtons();
  133.  
  134.  
  135. const observer = new MutationObserver(() => {
  136. injectApproveButtons();
  137. injectApproveUserButtons();
  138. });
  139. observer.observe(document.body, {
  140. childList: true,
  141. subtree: true,
  142. });
  143.  
  144.  
  145. window.addEventListener('beforeunload', () => observer.disconnect());
  146. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement