מדיה ויקי:Gadget-rcPatrol.js: הבדלים בין גרסאות בדף
מראה
ניסיון |
|||
| שורה 12: | שורה 12: | ||
function patrol(rcid) { | function patrol(rcid) { | ||
$. | $.ajax({ | ||
url: mw.util.wikiScript('api'), | |||
type: 'post', | |||
data: {action: 'patrol', rcid: 13200144, token: "junk", format: 'json'}, | |||
success: function(data, textStatus, jqXHR) { | |||
if (data && data.patrol) | |||
mw.util.jsMessage('העריכה בדף ' + data.patrol.title + ' סומנה כבדוקה'); | |||
else { | |||
var desc = (data && data.error && data.error.info) || ''; | |||
mw.util.jsMessage('<span style="color:red">אירעה שגיאה ' + desc + '</span>'); | |||
} | |||
}, | |||
error: function(jqXHR, textStatus, errorThrown) { | |||
mw.util.jsMessage(jqXHR + '<br/>' + textStatus + '<br/>' + errorThrown); | |||
} | |||
} | |||
); | |||
} | } | ||
גרסה מ־21:43, 10 ביולי 2012
/* Allows to mark pages as patrolled from the Recentchanges or Watchlist page.
*
* Written by [[User:Yonidebest]]
*/
if ($.inArray(wgCanonicalSpecialPageName, ["Recentchanges", "Watchlist", "Recentchangeslinked"]) + 1)
$(document).ready(function() {
var params = {action: 'query', list: 'recentchanges', rctoken: 'patrol', rclimit: 1, format: 'json'};
$.getJSON(mw.util.wikiScript('api'), params, function(data) {
var token = data.query.recentchanges[0].patroltoken;
function patrol(rcid) {
$.ajax({
url: mw.util.wikiScript('api'),
type: 'post',
data: {action: 'patrol', rcid: 13200144, token: "junk", format: 'json'},
success: function(data, textStatus, jqXHR) {
if (data && data.patrol)
mw.util.jsMessage('העריכה בדף ' + data.patrol.title + ' סומנה כבדוקה');
else {
var desc = (data && data.error && data.error.info) || '';
mw.util.jsMessage('<span style="color:red">אירעה שגיאה ' + desc + '</span>');
}
},
error: function(jqXHR, textStatus, errorThrown) {
mw.util.jsMessage(jqXHR + '<br/>' + textStatus + '<br/>' + errorThrown);
}
}
);
}
function addCheckbox(elem, abbr) {
var a = elem.find('a[href*="rcid="]');
if (!a.length)
return;
var matches = a.attr('href').match(/rcid=(\d+)/);
if (matches) {
var rcid = matches[1];
abbr.before($('<input>', {'type': 'checkbox'}).change(function() {patrol(rcid); $(this).remove();}));
abbr.remove();
}
}
// collect tds in "enhanced" rc list
$('td.mw-enhanced-rc').each(function() {
var td = $(this);
var abbr = td.find('abbr.unpatrolled');
var sib = td.siblings();
if (sib.find('.mw-collapsible-toggle').length)
return;
addCheckbox(sib, abbr);
});
$('li.mw-line-odd, li.mw-line-even').each(function() {
addCheckbox($(this), $(this).find('abbr.unpatrolled'));
});
}); // getJSON
}); // document.ready