مدیاویکی:Gadget-fileShahbazReport.js: تفاوت میان نسخهها
ظاهر
imported>Jeeputer ابزار برای گزارش اشتباه ربات شهباز (درجا) |
imported>Jeeputer (درجا) |
||
| (۴ نسخهٔ میانیِ ایجادشده توسط همین کاربر نشان داده نشد) | |||
| خط ۱: | خط ۱: | ||
//<nowiki> | //<nowiki> | ||
$(function(){ | $(function(){ | ||
if (mw.config.get('wgPageName') !== 'ویکیپدیا:سامانه_شهباز/گزارش_اشتباه') { | |||
return; | |||
} | |||
var reportText = ''; | var reportText = ''; | ||
var api = new mw.Api(); | |||
var targetSpan = $('#shahbaz-report-button'); | var targetSpan = $('#shahbaz-report-button'); | ||
var activationButton = new OO.ui.ButtonWidget({ | var activationButton = new OO.ui.ButtonWidget({ | ||
| خط ۴۱: | خط ۴۲: | ||
label: 'ملزومات گزارش' | label: 'ملزومات گزارش' | ||
}); | }); | ||
var progressBar = new OO.ui.FieldLayout( | |||
new OO.ui.ProgressBarWidget({ | |||
inline: true | |||
}), { | |||
label: 'در حال ثبت گزارش...', | |||
align: 'top' | |||
} | |||
); | |||
progressBar.toggle(false); | |||
fieldset.addItems([ | fieldset.addItems([ | ||
progressBar, | |||
createField( | createField( | ||
diffInput, | diffInput, | ||
| خط ۶۷: | خط ۷۸: | ||
diffLength = diffInput.getInputLength(); | diffLength = diffInput.getInputLength(); | ||
rationaleLength = rationaleInput.getInputLength(); | rationaleLength = rationaleInput.getInputLength(); | ||
rationaleInput.setLabel(String(mw.language.convertNumber(rationaleLength))); | var colour; | ||
if (rationaleLength > 300) { | |||
colour = '#D30000'; | |||
} else if (rationaleLength > 200) { | |||
colour = '#CC9000'; | |||
} else if (rationaleLength === 0) { | |||
colour = '#72777d'; | |||
} else { | |||
colour = '#35A400'; | |||
} | |||
console.log(colour); | |||
rationaleInput.setLabel( | |||
$('<span>') | |||
.css('color', colour) | |||
.text(String(mw.language.convertNumber(rationaleLength))) | |||
); | |||
diffInput.setLabel(''); | diffInput.setLabel(''); | ||
if (!diffLength || !rationaleLength) { | if (!diffLength || !rationaleLength) { | ||
| خط ۷۷: | خط ۱۰۵: | ||
function createText(diff, rationale) { | function createText(diff, rationale) { | ||
reportText = '\n* ' + "'''[[ویژه:تفاوت/" + diff + "]]''': " + rationale + ' ~~~~'; | |||
reportText = '\n* ' + "'''[[ویژه:تفاوت/" + | |||
} | } | ||
| خط ۹۵: | خط ۱۲۲: | ||
var diffValidity = diffInput.getValidity(); | var diffValidity = diffInput.getValidity(); | ||
diffValidity.done(function() { | 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() { | diffValidity.fail(function() { | ||
نسخهٔ کنونی تا ۸ ژانویهٔ ۲۰۲۵، ساعت ۱۳:۵۵
//<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;
if (rationaleLength > 300) {
colour = '#D30000';
} else if (rationaleLength > 200) {
colour = '#CC9000';
} else if (rationaleLength === 0) {
colour = '#72777d';
} else {
colour = '#35A400';
}
console.log(colour);
rationaleInput.setLabel(
$('<span>')
.css('color', 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>