Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript:(function(){
- 'use strict';
- function showToast(message, duration = 3000) {
- const toast = document.createElement('div');
- toast.textContent = message;
- toast.style.position = 'fixed';
- toast.style.bottom = '20px';
- toast.style.right = '20px';
- toast.style.padding = '10px';
- toast.style.margin = '10px';
- toast.style.borderRadius = '5px';
- toast.style.background = 'rgba(0, 0, 0, 0.7)';
- toast.style.color = 'white';
- toast.style.zIndex = '9999';
- toast.style.maxWidth = '300px';
- toast.style.textAlign = 'center';
- toast.style.transition = 'opacity 0.5s';
- document.body.appendChild(toast);
- setTimeout(() => {
- toast.style.opacity = '0';
- setTimeout(() => document.body.removeChild(toast), 500);
- }, duration);
- }
- async function approveComment(fullname) {
- try {
- const modhash = await fetch('/api/me.json', { credentials: 'include' })
- .then(response => response.json())
- .then(data => data.data.modhash);
- const response = await fetch('/api/approve', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- },
- body: `id=${fullname}&uh=${modhash}`,
- credentials: 'include',
- });
- if (response.ok) {
- showToast('Comment approved!', 2000);
- } else {
- showToast('Failed to approve comment.', 2000);
- }
- } catch (error) {
- console.error('Error approving comment:', error);
- showToast('Error approving comment. Check console for details.', 2000);
- }
- }
- async function approveUser(username, subreddit) {
- try {
- const modhash = await fetch('/api/me.json', { credentials: 'include' })
- .then(response => response.json())
- .then(data => data.data.modhash);
- const response = await fetch(`/r/${subreddit}/api/approve`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- },
- body: `name=${username}&uh=${modhash}`,
- credentials: 'include',
- });
- if (response.ok) {
- showToast('User approved!', 2000);
- } else {
- showToast('Failed to approve user.', 2000);
- }
- } catch (error) {
- console.error('Error approving user:', error);
- showToast('Error approving user. Check console for details.', 2000);
- }
- }
- function injectApproveButtons() {
- document.querySelectorAll('.comment .tagline a.author').forEach(authorLink => {
- const comment = authorLink.closest('.comment');
- const fullname = comment.getAttribute('data-fullname');
- const existingButton = comment.querySelector('.approve-button');
- if (existingButton) return;
- const approveButton = document.createElement('button');
- approveButton.textContent = 'Approve';
- approveButton.className = 'approve-button';
- approveButton.style.marginLeft = '5px';
- approveButton.style.padding = '2px 5px';
- approveButton.style.border = '1px solid #555';
- approveButton.style.borderRadius = '3px';
- approveButton.style.background = '#333';
- approveButton.style.color = 'white';
- approveButton.style.cursor = 'pointer';
- approveButton.addEventListener('click', () => approveComment(fullname));
- authorLink.parentNode.insertBefore(approveButton, authorLink.nextSibling);
- });
- }
- function injectApproveUserButtons() {
- document.querySelectorAll('.comment .tagline a.author').forEach(authorLink => {
- const comment = authorLink.closest('.comment');
- const username = authorLink.textContent.trim();
- const subreddit = window.location.pathname.split('/')[2];
- const existingButton = comment.querySelector('.approve-user-button');
- if (existingButton) return;
- const approveUserButton = document.createElement('button');
- approveUserButton.textContent = 'Approve User';
- approveUserButton.className = 'approve-user-button';
- approveUserButton.style.marginLeft = '5px';
- approveUserButton.style.padding = '2px 5px';
- approveUserButton.style.border = '1px solid #555';
- approveUserButton.style.borderRadius = '3px';
- approveUserButton.style.background = '#333';
- approveUserButton.style.color = 'white';
- approveUserButton.style.cursor = 'pointer';
- approveUserButton.addEventListener('click', () => approveUser(username, subreddit));
- authorLink.parentNode.insertBefore(approveUserButton, authorLink.nextSibling);
- });
- }
- injectApproveButtons();
- injectApproveUserButtons();
- const observer = new MutationObserver(() => {
- injectApproveButtons();
- injectApproveUserButtons();
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true,
- });
- window.addEventListener('beforeunload', () => observer.disconnect());
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement