مستخدم:HitomiAkane/arzAutocorrect.js
ملحوظه: بعد التسييف، ممكن تحتاج تفضى كاش البراوزر بتاعك عشان تشوف التغييرات اللى عملتها، بالطريقه دى:
- فايرفوكس وسفارى: دوس ⇧ Shift مع Reload او Ctrl-F5 او Ctrl-R (اللى هو: Command-R على ماكنتوش)
- جوجل كروم: دوس Ctrl-Shift-R (اللى هو: Command-Shift-R على ماكنتوش)
- انترنت اكسبلورر: دوس Ctrl مع Refresh فى نفس الوقت، او Ctrl-F5
- كونكرر: دوس Reload او F5
- اوبرا: فضى الكاش من Tools → Preferences
/*
الشرح في صفحة النقاش
*/
var autoCorrectCommandCount = 0, VISUAL = 1, SOURCE = 2;
function ReSequence(){ReSequence.parent.apply(this, arguments);} //like ve.ui.Sequence, with the regular expressions
OO.inheritClass(ReSequence, ve.ui.Sequence);
ReSequence.prototype.match = function (data, offset, plaintext) {
var execResult;
if (this.data instanceof RegExp){
execResult = this.data.exec(plaintext);
return execResult && new ve.Range(offset - execResult[1].length, offset);
}
return ReSequence.parent.prototype.match.apply(this, arguments);
};
function autoCorrectFromTo (from, to, strip, mode) {
var name = 'acc-' + (autoCorrectCommandCount++), seq;
ve.ui.commandRegistry.register( //create and register the command
new ve.ui.Command(name, 'content', 'insert', {args: [to, true, true]})
);
seq = new ReSequence(/*sequence*/ name, /*command*/ name, from, strip);//create and register the sequence
if (!mode || mode === VISUAL){
ve.ui.sequenceRegistry.register(seq);
}
if ((!mode || mode === SOURCE) && ve.ui.wikitextSequenceRegistry){
ve.ui.wikitextSequenceRegistry.register(seq);
}
}
autoCorrectFromTo('ي ', 'ى ', 2);
autoCorrectFromTo('ي.', 'ى.', 2);
autoCorrectFromTo('ي,', 'ى,', 2);
autoCorrectFromTo('ي،', 'ى،', 2);
/*
autoCorrectFromTo('ى ', 'ي ', 2);
autoCorrectFromTo('ى.', 'ي.', 2);
autoCorrectFromTo('ى,', 'ي,', 2);
autoCorrectFromTo('ى،', 'ي،', 2);
*/
autoCorrectFromTo('ة ', 'ه ', 2);
autoCorrectFromTo('ة.', 'ه.', 2);
autoCorrectFromTo('ة,', 'ه,', 2);
autoCorrectFromTo('ة،', 'ه،', 2);
autoCorrectFromTo('...', '…', 2);
autoCorrectFromTo('<<', '«', 2);
autoCorrectFromTo('>>', '»', 2);
autoCorrectFromTo(' 1/2 ', ' ½ ', 5);
autoCorrectFromTo(' 1/4 ', ' ¼ ', 5);
autoCorrectFromTo(' 3/4 ', ' ¾ ', 5);