User:Zackmann08/scripts/rollback.js
// <nowiki>
function waitForElement(selector) {
return new Promise(resolve => {
// Check if it already exists
const element = document.querySelector(selector);
if (element) {
return resolve(element);
}
// Observe changes if it doesn't exist yet
const observer = new MutationObserver(mutations => {
const element = document.querySelector(selector);
if (element) {
resolve(element);
observer.disconnect(); // Stop observing once found
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
function unknownRollback(){
mw.notify('Rolling back unknown addition...', {type: 'warn'});
var oldid = document.getElementById('mw-diff-otitle1').querySelector('a').href.match(/\d+$/)[0];
mw.loader.using("mediawiki.api", function () {
var api = new mw.Api();
api.get( {
action: 'query',
prop: 'revisions',
revids: oldid,
rvprop: 'content',
rvslots: 'main'
} ).then( function ( data ) {
// Access the text from the response
var pageId = Object.keys(data.query.pages)[0];
var content = data.query.pages[pageId].revisions[0].slots.main['*'];
api.postWithEditToken( {
action: "edit",
title: mw.config.get('wgPageName'),
undoafter: oldid,
undo: mw.config.get('wgCurRevisionId'),
summary: 'Edit(s) introduced 1 or more [[CAT:UNKNOWN|unknown parameters]], therefore reverting. Please [[WP:PREVIEW|preview]] your edits to check for errors.',
text: content
}).done ( function ( data ) {
if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {
var talk_page = document.querySelector('#mw-diff-ntitle2 .mw-usertoollinks a').href;
document.querySelector('#ca-view a').click();
window.open(talk_page, '_blank');
// window.location.replace('https://en.wikipedia.org/wiki/' + mw.config.get('wgPageName'));
}
});
});
});
}
var linktext = '<span> || </span><a href="javascript:unknownRollback();" style="font-weight: bold;"><span style="color: black;">[</span><span style="color: blue;">UNKNOWN</span><span style="color: black;">]</span></a>';
$(document).ready(function() {
if (document.getElementById('mw-diff-otitle1')){
(async () => {
await waitForElement(".tw-rollback-link-vandalism");
document.getElementsByClassName('tw-rollback-link-vandalism')[0].insertAdjacentHTML('afterend', linktext);
})();
}
});
// </nowiki>
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.