İstifadəçi:Qədir/ManageBlocks.js
(İstifadəçi:Gadir/ManageBlocks.js səhifəsindən yönləndirilmişdir)
// Blokları rahat idarə etmək üçün skript
(function() {
if (mw.config.get('wgUserName') === null) return; // giriş yoxdursa çıx
// Yalnız inzibatçılar görsün
if (!mw.config.get('wgUserGroups').includes('sysop')) return;
var currentUser = mw.config.get('wgUserName');
var pageName = mw.config.get('wgPageName'); // səhifə adı
var decodedPageName = decodeURIComponent(pageName); // URL-dən çıxarılmış ad
// Öz istifadəçi səhifən, müzakirən və töhfələr səhifən göstərmə
if (
decodedPageName === 'İstifadəçi:' + currentUser ||
decodedPageName === 'İstifadəçi_müzakirəsi:' + currentUser ||
decodedPageName === 'Xüsusi:Töhfələr/' + currentUser
) {
return;
}
// Yalnız aşağıdakı səhifələrdə işləsin
if (
!decodedPageName.startsWith('İstifadəçi:') &&
!decodedPageName.startsWith('İstifadəçi_müzakirəsi:') &&
!decodedPageName.startsWith('Xüsusi:Töhfələr/')
) {
return;
}
// İstifadəçi adını ayır
var username;
if (decodedPageName.startsWith('Xüsusi:Töhfələr/')) {
username = decodedPageName.split('/')[1];
} else {
username = decodedPageName.split(':')[1];
}
var api = new mw.Api();
// Blok statusunu yoxlamaq üçün API çağırışı
api.get({
action: 'query',
list: 'blocks',
bkusers: username,
format: 'json'
}).done(function(data) {
var isBlocked = false;
if (data.query.blocks && data.query.blocks.length > 0) {
isBlocked = true;
}
addButtons(isBlocked);
});
// Blokla və ya Bloku dəyiş / Ləğv et düymələrini əlavə edən funksiya
function addButtons(isBlocked) {
var userHeader = document.querySelector('h1#firstHeading, h1.page-header, #content h1');
if (!userHeader) return;
var container = document.createElement('div');
container.style.marginTop = '8px';
if (!isBlocked) {
var blockBtn = document.createElement('button');
blockBtn.textContent = 'Blokla';
blockBtn.style.backgroundColor = '#d9534f';
blockBtn.style.color = 'white';
blockBtn.style.border = 'none';
blockBtn.style.padding = '5px 12px';
blockBtn.style.fontWeight = 'bold';
blockBtn.style.cursor = 'pointer';
blockBtn.style.borderRadius = '3px';
blockBtn.onclick = function() {
window.location.href = mw.util.getUrl('Special:BlockUser/' + username);
};
container.appendChild(blockBtn);
} else {
var changeBtn = document.createElement('button');
changeBtn.textContent = 'Bloku dəyiş';
changeBtn.style.backgroundColor = '#f0ad4e';
changeBtn.style.color = 'white';
changeBtn.style.border = 'none';
changeBtn.style.padding = '5px 12px';
changeBtn.style.fontWeight = 'bold';
changeBtn.style.cursor = 'pointer';
changeBtn.style.borderRadius = '3px';
changeBtn.style.marginRight = '10px';
changeBtn.onclick = function() {
window.location.href = mw.util.getUrl('Special:BlockUser/' + username);
};
var revokeBtn = document.createElement('button');
revokeBtn.textContent = 'Bloku ləğv et';
revokeBtn.style.backgroundColor = '#0275d8';
revokeBtn.style.color = 'white';
revokeBtn.style.border = 'none';
revokeBtn.style.padding = '5px 12px';
revokeBtn.style.fontWeight = 'bold';
revokeBtn.style.cursor = 'pointer';
revokeBtn.style.borderRadius = '3px';
revokeBtn.onclick = function() {
window.location.href = mw.util.getUrl('Special:Unblock/' + username);
};
container.appendChild(changeBtn);
container.appendChild(revokeBtn);
}
userHeader.parentNode.insertBefore(container, userHeader.nextSibling);
}
})();