User:Anton199/customRollback.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes.
- Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
- Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
- Opera, Konqueror and Safari users can just click the Reload button.
- Chrome: press Ctrl+F5 or Shift+F5
/**
* Adds a rollback link which allows for the use of a custom rollback summary
* @author sactage <sactage@gmail.com>
* @version 1.3.0
*/
$(function customSummaryRollbackLink() {
window.anton199 = window.anton199 || {};
window.anton199.rollback = window.anton199.rollback || {allowNoSummary: false, addNewLink: false, useAjax: true, removeLinkClass: false};
var rollbackContainer = $("span.mw-rollback-link");
if (!rollbackContainer.length)
return false;
$.each(rollbackContainer, function (index, element) { // Iterate over each rollback container
var $link = $($(element).children("a")[0]);
if (!window.anton199.rollback.addNewLink) { // Don't add a new link
$link.attr("id", "rollback-custom-summary").click(function(event) {
event.preventDefault();
var summary = prompt("Enter a custom rollback summary");
if (summary == null || (!summary && !window.anton199.rollback.allowNoSummary))
return false;
$(this).attr('href', $(this).attr('href') + (summary ? '&summary=' + encodeURIComponent(summary) : ""));
if (window.anton199.rollback.useAjax) {
$.ajax({type: "GET", url: this.href }).done(function() {
$link.css({color: "grey"}).text("gone!").removeAttr("href");
if (window.anton199.rollback.removeLinkClass)
$link.addClass("rollback-gone").parent().removeClass("mw-rollback-link");
});
} else {
window.location = this.href;
}
});
} else { // Add a new link
var $newLink = $("<a id=\"rollback-custom-summary\">rollback (custom summary)</a>");
$newLink.attr('href', $link.attr('href')).insertAfter($link).before(" | ").click(function(event) {
event.preventDefault();
var summary = prompt("Enter a custom rollback summary");
if (summary == null || (!summary && !window.anton199.rollback.allowNoSummary))
return false;
$(this).attr('href', $(this).attr('href') + (summary ? '&summary=' + encodeURIComponent(summary) : ""));
if (window.anton199.rollback.useAjax) {
$.ajax({type: "GET", url: this.href }).done(function() {
$newLink.css({color: "grey"}).text("gone!").removeAttr("href");
if (window.anton199.rollback.removeLinkClass)
$newLink.addClass("rollback-gone").parent().removeClass("mw-rollback-link");
});
} else {
window.location = this.href;
}
});
}
});
});