לדלג לתוכן

מדיה ויקי:Gadget-IsBlock.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
אין תקציר עריכה
מ 65 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-IsBlock.js יובאו
 
(31 גרסאות ביניים של 5 משתמשים אינן מוצגות)
שורה 1: שורה 1:
mw.loader.using( [ 'mediawiki.api' ] ).then( function() {
$( function() {
function isAnon(m, x){
if ($( '.blockRequestUserName ').length === 0) return;
new mw.Api().get({
var list = {};
"action": "query",
 
"format": "json",
// collect all {{לחסום}} requests. note that it's an object, keyed by user name.
"list": "blocks",
// so, if there are multiple requests for same users, we only ask for one, and remember for each
"bkip": m
// all the spans we want to update for this user.
}).done(function(ans) {
$( '.blockRequestUserName ').each( function() {
logs = ans;
var span = $( this ),
if (logs.query.blocks.length > 0) {$('.blockRequestUserName')[x].append(" (" + m + " נחסמ/ה על ידי " + logs.query.blocks["0"].by + ")")}
username = span.data( 'username' );
});
(list[username] = (list[username] || [])).push(span);
}
});
function isUser(m, x){
 
new mw.Api().get({
// filter all anons to one list, and registered to another.
"action": "query",
var anons = Object.keys(list).filter( mw.util.isIPAddress );
"format": "json",
var registered = Object.keys(list).filter( function(u) { return !mw.util.isIPAddress(u) } );
"list": "blocks",
"bkusers": m
// construct an api object to be used below
}).done(function(ans) {
var api = new mw.Api();
logs = ans;
if (logs.query.blocks.length > 0) {$('.blockRequestUserName')[x].append((" (" + m + " נחסמ/ה על ידי " + logs.query.blocks["0"].by + ")"))}
// start sending api calls. for anons ("bkip" parameter), we can only ask one at a time.
});
anons.forEach( function(anon) {
}
api.get( {
var b = $('#bodyContent')["0"].innerHTML;
list: 'blocks',
var anon;
bkip: anon
var list = {};
})
$('.blockRequestUserName').each( function() {
.done( reportBlocks );
  var span = $(this); // this is one such span.
});
  var username = span.data('username');
  if (list[username]) {
      list[username].push(span);
// for registered, we can ask for up to 50 at a time.
    } else {
// todo: check list length, use .slice() or .splice() to chuck them in batches of 50.
        list[username] = [ span ];
if (registered.length) {
    }
api.get( {
});
list: 'blocks',
var users_to_query = Object.keys(list);
bkusers: registered.join('|')
for (x in list.undefined){
})
anon = mw.util.isIPv4Address(list.undefined[x][0].children["0"].innerText) || mw.util.isIPv6Address(list.undefined[x][0].children["0"].innerText);  
.done( reportBlocks );
anon ? isAnon(list.undefined[x][0].children["0"].innerText, x) : isUser(list.undefined[x][0].children["0"].innerText, x);
}
}
// when query returns, see if there are any blocks, and if there are, add the block marker.
// note that list[user] is an array of all the spans in the page requesting to block this user.
// typically this array will be of length 1, but it can be more.
function reportBlocks( data ) {
if (data && data.query && data.query.blocks )
data.query.blocks.forEach( function(block) {
var user = decodeURIComponent( block.user ); // the api returns the user name encoded.
addBlockedMarker( list[user] || [], block.by );
});
}
function addBlockedMarker( spans, by ) {
spans.forEach( function(span) {
span
.text(' | חסומ/ה')
.attr('title', 'נחסמ/ה על ידי '  + by);
});
}
});
});

גרסה אחרונה מ־13:14, 5 בדצמבר 2022

$( function() {
	if ($( '.blockRequestUserName ').length === 0) return;
	var list = {};

	// collect all {{לחסום}} requests. note that it's an object, keyed by user name.
	// so, if there are multiple requests for same users, we only ask for one, and remember for each
	// all the spans we want to update for this user.
	$( '.blockRequestUserName ').each( function() {
		var span = $( this ),
			username = span.data( 'username' );
		(list[username] = (list[username] || [])).push(span);
	});

	// filter all anons to one list, and registered to another.
	var anons = Object.keys(list).filter( mw.util.isIPAddress );
	var registered = Object.keys(list).filter( function(u) { return !mw.util.isIPAddress(u) } );
	
	// construct an api object to be used below
	var api = new mw.Api();
	
	// start sending api calls. for anons ("bkip" parameter), we can only ask one at a time.
	anons.forEach( function(anon) {
		api.get( {
			list: 'blocks',
			bkip: anon
		})
		.done( reportBlocks );
	});
	
	
	// for registered, we can ask for up to 50 at a time.
	// todo: check list length, use .slice() or .splice() to chuck them in batches of 50.
	if (registered.length) {
		api.get( {
			list: 'blocks',
			bkusers: registered.join('|')
		})
		.done( reportBlocks );
	}
	
	// when query returns, see if there are any blocks, and if there are, add the block marker.
	// note that list[user] is an array of all the spans in the page requesting to block this user.
	// typically this array will be of length 1, but it can be more.
	function reportBlocks( data ) {
		if (data && data.query && data.query.blocks )
			data.query.blocks.forEach( function(block) {
				var user = decodeURIComponent( block.user ); // the api returns the user name encoded.
				addBlockedMarker( list[user] || [], block.by );
			});
	}
	
	function addBlockedMarker( spans, by ) {
		spans.forEach( function(span) {
			span
			.text(' | חסומ/ה')
			.attr('title', 'נחסמ/ה על ידי '  + by);
		});
	}
});