User:DIVINE/MobileRollback.js

// Mobile Rollback

// Function to rollback an edit function rollbackEdit(revisionId) { // API URL for rollback var apiUrl = 'https://en.wikipedia.org/w/api.php'; // Parameters for rollback API request var params = { action: 'rollback', format: 'json', formatversion: 2, token: mw.user.tokens.get('csrfToken'), title: mw.config.get('wgPageName'), user: mw.config.get('wgUserName'), revision: revisionId }; // Make the API request $.post(apiUrl, params) .done(function(data) {     if (data && data.rollback && data.rollback.status === 'success') {        // Rollback successful        console.log('Rollback successful!');      } else {        // Rollback failed        console.log('Rollback failed!');      }    }) .fail(function {     console.log('Failed to make rollback request!');    }); }

// Function to handle rollback button click function handleRollbackClick(event) { var revisionId = event.target.dataset.revisionId; if (revisionId) { rollbackEdit(revisionId); } }

// Function to add rollback buttons to each revision on the page function addRollbackButtons { // Select all revision elements var revisionElements = document.querySelectorAll('.mw-changeslist .mw-changeslist-diff'); // Loop through each revision element revisionElements.forEach(function(revisionElement) {   var rollbackLink = document.createElement('a');    rollbackLink.href = '#';    rollbackLink.textContent = 'Rollback';    rollbackLink.setAttribute('data-revision-id', revisionElement.dataset.rcid);    rollbackLink.addEventListener('click', handleRollbackClick);    // Append the rollback link to the revision element    revisionElement.appendChild(rollbackLink);  }); }

// Check if we're on a Wikipedia page with revision history if (mw.config.get('wgCanonicalSpecialPageName') === 'Recentchanges') { // Wait for the page to load $(document).ready(function {   // Add rollback buttons to the page    addRollbackButtons;  }); }