مدیاویکی:Gadget-fileShahbazReport.js: تفاوت میان نسخهها
ظاهر
imported>Jeeputer تغییر رنگ ایندیکیتور بسته به طول توضیحات |
imported>Jeeputer (درجا) |
||
| خط ۸۷: | خط ۸۷: | ||
colour = '#35A400'; | colour = '#35A400'; | ||
} | } | ||
console.log(colour) | |||
rationaleInput.setLabel( | rationaleInput.setLabel( | ||
نسخهٔ ۸ ژانویهٔ ۲۰۲۵، ساعت ۱۳:۵۰
//<nowiki>
$(function(){
if (mw.config.get('wgPageName') !== 'ویکیپدیا:سامانه_شهباز/گزارش_اشتباه') {
return;
}
var reportText = '';
var api = new mw.Api();
var targetSpan = $('#shahbaz-report-button');
var activationButton = new OO.ui.ButtonWidget({
label: 'افزودن گزارش تازه',
flags: [
'primary',
'progressive'
],
id: 'shabaz-report-activate'
});
function createField(widget, config) {
return new OO.ui.FieldLayout(widget, config || {});
}
var diffInput = new OO.ui.TextInputWidget({
icon: 'history',
placeholder: '[[ویژه:تفاوت/12345678]] یا 12345678',
required: true,
validate: /\b(?:\d{8,10}){1}\b/i
});
var rationaleInput = new OO.ui.MultilineTextInputWidget({
autosize: true,
required: true,
allowLinebreaks: false
});
var submitButton = new OO.ui.ButtonWidget({
label: 'ثبت گزارش',
flags: [
'primary',
'progressive'
],
desabled: true
});
var fieldset = new OO.ui.FieldsetLayout({
label: 'ملزومات گزارش'
});
var progressBar = new OO.ui.FieldLayout(
new OO.ui.ProgressBarWidget({
inline: true
}), {
label: 'در حال ثبت گزارش...',
align: 'top'
}
);
progressBar.toggle(false);
fieldset.addItems([
progressBar,
createField(
diffInput,
{
label: 'پیوند، عنوان یا شناسهٔ تفاوت',
align: 'top'
}
),
createField(
rationaleInput,
{
label: 'استدلال یا دلیل',
align: 'top',
help: 'دلیل اشتباه بودن واگردانی ربات را به اختصار بنویسید. نیازی به امضا نیست',
helpInline: true
}
),
createField(
submitButton
)
]);
var updateOnChange = function() {
diffLength = diffInput.getInputLength();
rationaleLength = rationaleInput.getInputLength();
var colour = 'color: ';
if (rationaleLength > 300) {
colour += '#D30000';
} else if (rationaleLength > 200) {
colour = '#CC9000';
} else {
colour = '#35A400';
}
console.log(colour)
rationaleInput.setLabel(
$('<span>')
.css({colour})
.text(String(mw.language.convertNumber(rationaleLength)))
);
diffInput.setLabel('');
if (!diffLength || !rationaleLength) {
submitButton.setDisabled(true);
} else {
submitButton.setDisabled(false);
}
};
function createText(diff, rationale) {
reportText = '\n* ' + "'''[[ویژه:تفاوت/" + diff + "]]''': " + rationale + ' ~~~~';
}
var parent = $('<div>')
.css({'max-width': '400px', 'margin': 'auto'})
.attr('id', 'shahbaz-report-parent');
targetSpan.replaceWith(parent.append(activationButton.$element));
activationButton.on('click', function() {
activationButton.toggle(false);
parent.append(fieldset.$element);
updateOnChange();
diffInput.on('change', updateOnChange);
rationaleInput.on('change', updateOnChange);
submitButton.on('click', function() {
var diffValidity = diffInput.getValidity();
diffValidity.done(function() {
var diff = diffInput.getValue();
diff = diff.match(/\b\d{8,10}\b/)[0];
var rationale = rationaleInput.getValue();
createText(diff, rationale);
diffInput.setDisabled(true);
rationaleInput.setDisabled(true);
submitButton.setDisabled(true);
progressBar.toggle(true);
api.postWithToken('csrf', {
action: 'edit',
title: 'ویکیپدیا:سامانه شهباز/گزارش اشتباه',
appendtext: reportText,
notminor: true,
summary: 'گزارش واگردانی اشتباه ربات در [[ویژه:تفاوت/' + diff + ']]'
}).done(function(result) {
progressBar.setLabel('در حال تازهسازی صفحه...');
location.reload();
});
});
diffValidity.fail(function() {
diffInput.setLabel(
$('<span>')
.css('color', 'red')
.text('نامعتبر')
);
});
});
});
});
//</nowiki>