Użytkownik:Expert3222/quickPatrol.js: Różnice pomiędzy wersjami
Z Nondanych
m |
|||
Linia 117: | Linia 117: | ||
$(elem).find(".patrolButton").on("click", function() |
$(elem).find(".patrolButton").on("click", function() |
||
{ |
{ |
||
patrolChange(oldid, false, false); |
patrolModule.patrolChange(oldid, false, false); |
||
}); |
}); |
||
}).fail(function(error) |
}).fail(function(error) |
||
Linia 128: | Linia 128: | ||
$(".patrolButton").on("click", function() |
$(".patrolButton").on("click", function() |
||
{ |
{ |
||
resetLastClick(); |
patrolModule.resetLastClick(); |
||
patrolChange($(this).attr("data-diff"), false, false); |
patrolModule.patrolChange($(this).attr("data-diff"), false, false); |
||
}); |
}); |
||
} |
} |
||
Linia 187: | Linia 187: | ||
var revid = $button.find("a").attr("data-revision"); |
var revid = $button.find("a").attr("data-revision"); |
||
$button.find("a").replaceWith(spinnerCode); |
$button.find("a").replaceWith(spinnerCode); |
||
resetLastClick(); |
patrolModule.resetLastClick(); |
||
patrolChange(revid).done(function() |
patrolModule.patrolChange(revid).done(function() |
||
{ |
{ |
||
$button.find("div").replaceWith(RCPatrolSuccessCode); |
$button.find("div").replaceWith(RCPatrolSuccessCode); |
||
Linia 208: | Linia 208: | ||
$button.find("a").replaceWith(spinnerCode); |
$button.find("a").replaceWith(spinnerCode); |
||
resetLastClick(); |
patrolModule.resetLastClick(); |
||
patrolPage(pageid).done(function() |
patrolModule.patrolPage(pageid).done(function() |
||
{ |
{ |
||
$button.find("div").replaceWith(RCMultiplePatrolSuccessCode); |
$button.find("div").replaceWith(RCMultiplePatrolSuccessCode); |
||
Linia 249: | Linia 249: | ||
$button.find("a").replaceWith(spinnerCode); |
$button.find("a").replaceWith(spinnerCode); |
||
resetLastClick(); |
patrolModule.resetLastClick(); |
||
patrolRangeOfChanges(to, from).done(function() |
patrolModule.patrolRangeOfChanges(to, from).done(function() |
||
{ |
{ |
||
$button.find("div").replaceWith(RCMultiplePatrolSuccessCode); |
$button.find("div").replaceWith(RCMultiplePatrolSuccessCode); |
||
Linia 267: | Linia 267: | ||
$button.find("a").replaceWith(spinnerCode); |
$button.find("a").replaceWith(spinnerCode); |
||
patrolModule.resetLastClick(); |
|||
patrolPage(pageid).done(function() |
patrolModule.patrolPage(pageid).done(function() |
||
{ |
{ |
||
$button.find("div").replaceWith(RCMultiplePatrolSuccessCode); |
$button.find("div").replaceWith(RCMultiplePatrolSuccessCode); |
Wersja z 19:08, 15 maj 2020
/*
* gadżet do szybkiego oznaczania wersji jako sprawdzonych na OZ, nowych stronach i widoku diffów
* autor: Expert3222
* drobne modyfikacje, backend: Ostrzyciel
*/
// TODO: $(this) na $this (do zmiennej), lepsza wydajność będzie
mw.loader.load('/wiki/Użytkownik:Expert3222/patrolModule.js?action=raw&ctype=text/javascript');
var spinnerCode = "<div class='mw-spinner mw-spinner-small mw-spinner-inline' title='...'></div>";
var RCPatrolSuccessCode = "<img src='https://nonsa.pl/images/2/26/Za.svg.png' width='15px' height='15px' /> <span style='color: green;' class='patrolButtonClicked'>zrobione</span>";
var RCPatrolFailureCode = "<img src='https://nonsa.pl/images/a/a8/Przeciw.svg.png' width='15px' height='15px' /> <span style='color: red;' class='patrolButtonClicked'>błąd</span>";
var RCMultiplePatrolSuccessCode = "<img src='https://nonsa.pl/images/2/26/Za.svg.png' width='15px' height='15px' /> <span style='color: green;' class='multiplePatrolButtonClicked'>zrobione</span>";
var RCMultiplePatrolFailureCode = "<img src='https://nonsa.pl/images/a/a8/Przeciw.svg.png' width='15px' height='15px' /> <span style='color: red;' class='multiplePatrolButtonClicked'>błąd</span>";
$(document).ready(function()
{
if (mw.config.get("wgCanonicalSpecialPageName") === "Recentchanges")
{
makePatrolButtons();
if (!!$('.mw-rcfilters-enabled').length) //wzięte od Polskacafe z gadżetu RollWithReason
{
setInterval(makePatrolButtons, 2000);
}
}
else if (mw.config.get("wgCanonicalSpecialPageName") == "Newpages")
{
makeNewpagesPatrolLinks();
}
else if (mw.util.getParamValue("diff") !== null)
{
makeDiffPagePatrolButtons();
setInterval(makeDiffPagePatrolButtons, 2000); //"przeglądaj historię interaktywnie" na górze
}
else if ($(".patrollink").length > 0) //footer
{
$(".patrollink-page a").off("click").click(processFooterPatrol); //remove default click handler and attach our own
}
else if (mw.config.get("wgCanonicalSpecialPageName") == "MobileDiff")
{
//TODO
/*var oldid = mw.util.getParamValue("oldid", $("#mw-mf-diff-info a").attr("href"));
alert("oldid = " + oldid);
var urlArray = window.location.href.split("/");
var curid = urlArray[urlArray.length - 1];
alert("curid = " + curid);
var title = $("#mw-mf-diff-info a").text();
makeDiffViewRevidsList(oldid, curid, title);*/
}
});
function makePatrolButtons()
{
$(".patrollink-page").each(function()
{
var $tbody = goUpUntilTag($(this), "tbody");
var lines = $tbody.find("tr");
var firstLine = $(lines).first();
if (lines.length >= 2 && $(firstLine).hasClass("mw-changeslist-reviewstatus-unpatrolled") && $(firstLine).find(".multiplePatrolButtonClicked").length === 0)
{
var $button = $(firstLine).find(".patrollink-page a");
if (!isEventBound($button))
{
$(firstLine).find(".patrollink-page a").on("click", function()
{
processMultipleChangeRCPatrol($tbody);
});
}
}
});
var $button = $(".patrollink-single a");
if (!isEventBound($button))
{
$button.on("click", function()
{
processRCChangePatrol($(this).parent());
});
}
}
function makeNewpagesPatrolLinks()
{
$("li.not-patrolled").each(function()
{
if (typeof $(this).find(".mw-newpages-oldtitle") == "undefined")
{
var oldid = $(this).attr("data-mw-revid");
$(this).find("span.mw-newpages-history a").after(" • <span class='patrolButton' title='Oznacz tę stronę jako sprawdzoną' data-diff='" + oldid + "'><a>patrol</a></span>");
}
else
{
var api = new mw.Api(),
elem = $(this),
pageName = $(this).find(".mw-newpages-pagename").attr("title");
api.post(
{
action: 'query',
format: 'json',
formatversion: '2',
prop: 'revisions',
titles: pageName,
rvprop: 'ids',
rvlimit: '1',
rvdir: 'newer'
}).done(function(data)
{
var oldid = data.query.pages[0].revisions[0].revid;
$(elem).find("span.mw-newpages-history a").after(" • <span class='patrolButton' title='Oznacz tę stronę jako sprawdzoną' data-diff='" + oldid + "'><a>patrol</a></span>");
$(elem).find(".patrolButton").on("click", function()
{
patrolModule.patrolChange(oldid, false, false);
});
}).fail(function(error)
{
console.log(error);
});
}
});
$(".patrolButton").on("click", function()
{
patrolModule.resetLastClick();
patrolModule.patrolChange($(this).attr("data-diff"), false, false);
});
}
//helper function to process multiple change RC patrol, including spinner etc.
function processMultipleChangeRCPatrol($tbody)
{
var deferred = $.Deferred(),
failureCount = 0,
successCount = 0,
multiplePatrolButton = $tbody.find(".patrollink-page"),
$buttons = $tbody.find(".patrollink-single"),
buttonsCount = $buttons.length;
console.dir(multiplePatrolButton);
multiplePatrolButton.find("a").replaceWith(spinnerCode);
$buttons.each(function()
{
processRCChangePatrol($(this))
.done(function()
{
++successCount;
}).fail(function()
{
++failureCount;
}).always(function()
{
if (successCount == buttonsCount) //wszystkie wywołania AJAX do patrolowania zakończyły się pomyślnie
{
deferred.resolve(successCount, failureCount);
multiplePatrolButton.find("div").replaceWith(RCMultiplePatrolSuccessCode);
$tbody.find("tr:first-child abbr.unpatrolled").replaceWith(" ");
}
else if (successCount + failureCount == buttonsCount) //wszystkie zakończyły się, niekoniecznie pomyślnie
{
deferred.reject(successCount, failureCount);
multiplePatrolButton.find("div").replaceWith(RCMultiplePatrolFailureCode);
}
});
});
/*if (buttonsCount == 0)
{
multiplePatrolButton.replaceWith("<span><img src='https://nonsa.pl/images/2/26/Za.svg.png' width='15px' height='15px' /> <span style='color: green;' class='multiplePatrolButtonClicked'>zrobione</span></span>");
$tbody.find("tr:first-child abbr.unpatrolled").replaceWith(" ");
}*/
return deferred.promise();
}
//helper function to process one RC link including spinner etc.
function processRCChangePatrol($button)
{
var deferred = $.Deferred();
var revid = $button.find("a").attr("data-revision");
$button.find("a").replaceWith(spinnerCode);
patrolModule.resetLastClick();
patrolModule.patrolChange(revid).done(function()
{
$button.find("div").replaceWith(RCPatrolSuccessCode);
goUpUntilTag($button, "tr").find("abbr.unpatrolled").replaceWith(" ");
deferred.resolve();
}).fail(function()
{
$button.find("div").replaceWith(RCPatrolFailureCode);
deferred.reject();
});
return deferred.promise();
}
function processFooterPatrol()
{
var $button = $(".patrollink-page");
var pageid = $button.find("a").attr("data-pageid");
$button.find("a").replaceWith(spinnerCode);
patrolModule.resetLastClick();
patrolModule.patrolPage(pageid).done(function()
{
$button.find("div").replaceWith(RCMultiplePatrolSuccessCode);
}).fail(function(error)
{
console.log(error);
$button.find("div").replaceWith(RCMultipleFailureSuccessCode);
});
}
function makeDiffPagePatrolButtons()
{
var $button = $(".patrollink-range a");
if (!isEventBound($button))
{
$button.click(function()
{
processDiffPageRangePatrol();
});
}
$button = $(".patrollink-page a");
if (!isEventBound($button))
{
$button.click(function()
{
processDiffPageFullPatrol();
});
}
}
//helper function to process diff page range patrol including spinner etc.
function processDiffPageRangePatrol()
{
var $button = $(".patrollink-range");
var to = $button.find("a").attr("data-revision-max");
var from = $button.find("a").attr("data-revision-min");
$button.find("a").replaceWith(spinnerCode);
patrolModule.resetLastClick();
patrolModule.patrolRangeOfChanges(to, from).done(function()
{
$button.find("div").replaceWith(RCMultiplePatrolSuccessCode);
}).fail(function(error)
{
console.log(error);
$button.find("div").replaceWith(RCMultipleFailureSuccessCode);
});
}
function processDiffPageFullPatrol()
{
var $button = $(".patrollink-page");
var pageid = $button.find("a").attr("data-pageid");
$button.find("a").replaceWith(spinnerCode);
patrolModule.resetLastClick();
patrolModule.patrolPage(pageid).done(function()
{
$button.find("div").replaceWith(RCMultiplePatrolSuccessCode);
}).fail(function(error)
{
console.log(error);
$button.find("div").replaceWith(RCMultipleFailureSuccessCode);
});
}
function processGroupMarksAndButtons($anchor) //usuwa grupowy wykrzyknik i przycisk patrolowania, jak zajdzie potrzeba
{
var $parent = $anchor;
while ($parent.prop("tagName") != "TABLE" && $parent.prop("tagName") != "BODY")
{
$parent = $parent.parent();
}
//wszystkie rozwijalne zmiany/pliki spatrolowane, drugi warunek po to,
//zeby nie ignorowalo sytuacji, gdy zmiany nie udalo sie spatrolowac
if ($parent.find(".patrolButton").length === 0 && $parent.find("abbr.unpatrolled").length == 1)
{
$parent.find("abbr.unpatrolled").replaceWith(" ");
$parent.find(".multiplePatrolButton").replaceWith("<span><img src='https://nonsa.pl/images/2/26/Za.svg.png' width='15px' height='15px' /> <span style='color: green;' class='multiplePatrolButtonClicked'>zrobione</span></span>");
}
}
function goUpUntilTag($anchor, tag)
{
tag = tag.toUpperCase();
while ($anchor.prop("tagName") != tag && $anchor.prop("tagName") != "BODY")
{
$anchor = $anchor.parent();
}
return $anchor;
}
function isEventBound($element)
{
var events = $._data($element.get(0), "events");
return events != null;
}