مستخدم:Majed/ReplaceAndFix.js
Documentation for this user script can be added at مستخدم:Majed/ReplaceAndFix. |
ملاحظة: بعد الحفظ، قد يلزمك إفراغ الكاش لرؤية التغييرات.
/*
سكربت لعمل استبدالات وأصلاحات للنص محددة مسبقا
المكتبات المطلوبة: jQuery + jQuery UI
مستخدم:Majed
*/
// إنشاء الزر والخيارات
//ثم وضع الزر بعد مربع الملخص في صندوق التحرير
$( "#wpSummary" ).after('<button type="button" id="openOpts" >مهام متكررة</button>'
+'<div id="mOptions" title="خيارات استبدال وإصلاح النص">'
+'<p><label><input type="checkbox" id="TransMonths" value="TransMonths">تعريب أشهر السنة </label></p>'
+'<p><label><input type="checkbox" id="HideParentheses" value="HideParentheses">إخفاء ما بين الأقواس من الوصلة </label></p>'
+'<p><label><input type="checkbox" id="EngTM" value="EngTM"> (بالإنجليزية:) إلى {{إنجليزية|}}</label></p>'
+'<p><label><input type="checkbox" id="MergeLines" value="MergeLines">دمج الأسطر الفارغة </label></p>'
+'<p><label><input type="checkbox" id="NoExtraSpace" value="NoExtraSpace"> مسح المسافة الفارغة الزائدة من صندوق المعلومات</label></p>'
+'<p><label><input type="checkbox" id="DeleteEngIW" value="DeleteEngIW">حذف الوصلة الداخلية الإنجليزية </label></p>'
+'<p><label><input type="checkbox" id="ArComma" value="ArComma">استبدال الفاصلة الإنجليزية بالعربية </label></p'
+'<p><label><input type="checkbox" id="DeleteLinkText" value="DeleteLinkText">حذف نص الوصلة </label></p'
+'<p><label><input type="checkbox" id="DeleteLinkLeaveText" value="DeleteLinkLeaveText">حذف الوصلة وترك نص الوصلة</label></p'
+'<p><label><input type="checkbox" id="DeleteEnLinkLeaveText" value="DeleteEnLinkLeaveText">حذف الوصلة الإنجليزية وترك نصها</label></p'
+'<p><label><input type="checkbox" id="DeleteLinkLeaveYear" value="DeleteLinkLeaveYear">حذف الوصلة وترك السنة </label></p'
+'<p><label><input type="checkbox" id="YearAsLinkText" value="YearAsLinkText">السنة كنص للوصلة</label></p'
+'<p><label><input type="checkbox" id="DeleteEngText" value="DeleteEngText">حذف نص إنجليزي لوصلة عربية</label></p'
+'<p><label><input type="checkbox" id="ShortLink" value="ShortLink">وصلة قصيرة</label></p'
+'<p><label><input type="checkbox" id="DeleteTags" value="DeleteTags">حذف التاقات </label></p'
+'<p><label><input type="checkbox" id="DeleteRefs" value="DeleteRefs">حذف المراجع </label></p'
+'<p><label><input type="checkbox" id="DeleteSmall" value="DeleteSmall">حذف Small</label></p'
+'<p><label><input type="checkbox" id="DeleteComments" value="DeleteComments">حذف التعليقات</label></p'
+'<p><label><input type="checkbox" id="DeleteSec" value="DeleteSec">حذف قسم</label></p'
+'<p><label><input type="checkbox" id="Navbox" value="Navbox">تعريب صندوق التصفح</label></p'
+'</div>');
//إنشاء النافذة
$(function() {
checkState = [];
var buttons = {
'اختيار الكل': select,
'إلغاء الاختيار': deselect,
'إلغاء': cancel,
'حفظ': save
};
$('#openOpts').click(function() { $('#mOptions').dialog('open'); });
$('#mOptions').dialog({
autoOpen: false,
modal: true,
buttons: buttons,
width: 400,
position: 'center',
open: openDialog
});
});
function openDialog() {
$(':checkbox', this).each(function() {
$(this).prop('original', $(this).is(':checked'));
});
}
//------------------------------------------------------------------------------
// دالة الحفظ
function save() {
var finalText = document.getElementById('wpTextbox1').value; //النص الأصلي
// استبدال بقالب إنجليزية
if ($('#EngTM').is(':checked')) {
finalText = finalText.replace(/\(بالإنجليزية:(.+?)\)/g, '{{إنجليزية|$1}}');
}
//دمج الأسطر الفارغة
if ($('#MergeLines').is(':checked')) {
finalText = finalText.replace(/\n{3,}/g, '\n\n');
}
//مسح المسافة الزائدة من صندوق المعلومات
if ($('#NoExtraSpace').is(':checked')) {
finalText = finalText.replace(/\|(.+?)\s{2,}=/g, '|$1 =');
finalText = finalText.replace(/\|\s{2,}(.+?)=/g, '| $1=');
}
//تعريب أشهر السنة
if ($('#TransMonths').is(':checked')) {
finalText = finalText.replace(/\bJanuary\b/g, 'يناير');
finalText = finalText.replace(/\bFebruary\b/g, 'فبراير');
finalText = finalText.replace(/\bMarch\b/g, 'مارس');
finalText = finalText.replace(/\bApril\b/g, 'أبريل');
finalText = finalText.replace(/\bMay\b/g, 'مايو');
finalText = finalText.replace(/\bJune\b/g, 'يونيو');
finalText = finalText.replace(/\bJuly\b/g, 'يوليو');
finalText = finalText.replace(/\bAugust\b/g, 'أغسطس');
finalText = finalText.replace(/\bSeptember\b/g, 'سبتمبر');
finalText = finalText.replace(/\bOctober\b/g, 'أكتوبر');
finalText = finalText.replace(/\bNovember\b/g, 'نوفمبر');
finalText = finalText.replace(/\bDecember\b/g, 'ديسمبر');
}
//إخفاء ما بين الأقواس من الوصلة
if ($('#HideParentheses').is(':checked')) {
finalText = finalText.replace(/\)\]\]/g, ')|]]');
}
//حذف الوصلة الداخلية الإنجليزية
if ($('#DeleteEngIW').is(':checked')) {
finalText = finalText.replace(/\[\[([A-Za-z].+?)\]\]|\[\[(\d+.+?[A-Za-z])\]\]/g, '');
}
//استبدال الفاصلة الإنجليزية بالعربية
if ($('#ArComma').is(':checked')) {
finalText = finalText.replace(/, /g, '، ');
}
//حذف نص الوصلة
if ($('#DeleteLinkText').is(':checked')) {
finalText = finalText.replace(/(\[\[[^\]]+?)(\|.+?)(\]\])/g, '$1$3');
}
//حذف التاقات
if ($('#DeleteTags').is(':checked')) {
finalText = finalText.replace(/<\w+?>.+?<\/\w+?>/m, '');
}
//حذف المراجع
if ($('#DeleteRefs').is(':checked')) {
finalText = finalText.replace(/<ref name=".+?">.+?<\/ref>/g, '');
finalText = finalText.replace(/<ref>.+?<\/ref>/g, '');
finalText = finalText.replace(/<ref name\s*=.+?\/>/g, '');
}
//حذف Small
if ($('#DeleteSmall').is(':checked')) {
finalText = finalText.replace(/<small>.+?<\/small>/g, '');
}
//تعريب صندوق التصفح
if ($('#Navbox').is(':checked')) {
finalText = finalText.replace(/\|\s*name\s*=/g, '| اسم =');
finalText = finalText.replace(/\|\s*title\s*=/g, '| عنوان =');
finalText = finalText.replace(/\|\s*state\s*=/g, '| وضع =');
finalText = finalText.replace(/\|\s*above\s*=/g, '| اعلى =');
finalText = finalText.replace(/\|\s*group(\d)\s*=/g, '| مجموعة$1 =');
finalText = finalText.replace(/\|\s*list(\d)\s*=/g, '| قائمة$1 =');
finalText = finalText.replace(/\|\s*above\s*=/g, '| اعلى =');
finalText = finalText.replace(/\|\s*below\s*=/g, '| ادنى =');
finalText = finalText.replace(/Category:/g, 'تصنيف:');
}
//حذف التعليقات
if ($('#DeleteComments').is(':checked')) {
finalText = finalText.replace(/<!--.+?-->/g, '');
}
//حذف الوصلة وترك نص الوصلة
if ($('#DeleteLinkLeaveText').is(':checked')) {
finalText = finalText.replace(/\[\[[^\]]+?\|(.+?)\]\]/g, '$1');
}
//حذف الوصلة الإنجليزية وترك نصها
if ($('#DeleteEnLinkLeaveText').is(':checked')) {
finalText = finalText.replace(/\[\[[\d\w\s–'\(\):]+?\w\|(.+?)\]\]/g, '$1');
}
//حذف الوصلة وترك السنة
if ($('#DeleteLinkLeaveYear').is(':checked')) {
finalText = finalText.replace(/\[\[(\d{4}) [A-Za-z\|].+?\]\]/g, '$1');
finalText = finalText.replace(/\[\[\d\d\d\d[-–]\d\d.+?\|(\d\d\d\d-\d\d)\]\]/g, '$1');
}
//استخدام السنة كنص للوصلة
if ($('#YearAsLinkText').is(':checked')) {
//للنص الإنجليزي
finalText = finalText.replace(/(\[\[[A-z\s–'\(\):]+? )(\d\d\d\d)\]\]/g, '$1$2|$2]]'); //السنة في النهاية
finalText = finalText.replace(/\[\[(\d\d\d\d)( [A-z\s–'\(\):]+?)\]\]/g, '[[$1$2|$1]]'); //السنة في البداية
finalText = finalText.replace(/(\[\[[A-z\s–'\(\):]+? )(\d\d\d\d)( [A-z\s–'\(\):]+?)\]\]/g, '$1$2$3|$2]]'); //السنة في الوسط
//للنص العربي
finalText = finalText.replace(/(\[\[[\u0600}-\u06FF\s–'\(\):]+? )(\d\d\d\d)\]\]/g, '$1$2|$2]]'); //السنة في النهاية
finalText = finalText.replace(/(\[\[[\u0600}-\u06FF\s–'\(\):]+? )(\d\d\d\d)( [\u0600}-\u06FF\s–'\(\):]+?)\]\]/g, '$1$2$3|$2]]'); //السنة في الوسط
}
//حذف النص الإنجليزي لوصلة عربية
if ($('#DeleteEngText').is(':checked')) {
finalText = finalText.replace(/\[\[([\u0600-\u06FF\s]+)\|[A-Za-z\s]+\]\]/g, '[[$1]]');
}
//وصلة قصيرة
if ($('#ShortLink').is(':checked')) {
finalText = finalText.replace(/(\[\[.+? )(\w{4,})(\]\])/g, '$1$2|$2$3');
finalText = finalText.replace(/(\[\[.+? )([\u0600-\u06FF]{4,})(\]\])/g, '$1$2|$2$3');
}
//حذف قسم
if ($('#DeleteSec').is(':checked')) {
var SecName = prompt("أدخل اسم القسم", "");
if (SecName !== null) {
SecName = SecName.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
var re = new RegExp("==\s*"+SecName+"\s*==(.|[\r\n])+?==","g");
finalText = finalText.replace(re, '==');
}
}
$('#wpTextbox1').val(finalText); //حفظ النص
$(this).dialog('close'); //إغلاق النافذة
}
//------------------------------------------------------------------------------
// دالة اختيار الكل
function select() {
$(':checkbox', this).prop('checked', true);
}
//دالة إلغاء الاختيار
function deselect() {
$(':checkbox', this).prop('checked', false);
}
//دالة إلغاء الأمر
function cancel() {
$(this).find('input[type="checkbox"]').each(function() {
$(this).prop('checked', $(this).prop('original'));
});
$(this).dialog('close');
}
//------------------------------------------------------------------------------
// حذف القسم
$(".mw-headline").dblclick(function(){
if (confirm('هل تريد حذف القسم ؟')) {
var finalText = $('#wpTextbox1').val();
var SecName = $(this).text();
SecName = SecName.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
var re = new RegExp("==\s*"+SecName+"\s*==(.|[\r\n])+?==","g");
finalText = finalText.replace(re, '==');
$('#wpTextbox1').val(finalText);
}
});