User:Shrikarsan/co.js
Asani: Bayan wallafawa, zaku yi juyar da cache na browser din ku dan ganin sauye-sauye.
- Firefox / Safari: Rike Shift asanda kuke danna Reload, ko danna kodai Ctrl-F5 ko kuma Ctrl-R (⌘-R akan Mac)
- Google Chrome: Danna Ctrl-Shift-R (⌘-Shift-R akan Mac)
- Internet Explorer / Edge: Rike Ctrl asanda kuke danna Refresh, ko latsa Ctrl-F5
- Opera: Danna Ctrl-F5.
/**
* Blendet eine „Auto-Format“-Funktion in der Werkzeugleiste ein, die viele typische Wikifizierungs-Fehler
* automatisch korrigiert. Eine ausführliche Beschreibung ist auf der Diskussionsseite zu finden.
* (<nowiki> zur Umgehung von [[bugzilla:8761]].)
*/
(function( $, mw ) {
if ( typeof mw !== 'object' || (mw.config.get( 'wgAction' ) !== 'edit' && mw.config.get( 'wgAction' ) !== 'submit') ||
typeof $ !== 'function' ) {
return;
}
autoFormat2 = {
click: function( a ) {
if ( window.wikEd && window.wikEd.useWikEd ) {
wikEd.UpdateTextarea();
}
var e = document.forms['editform'].elements, textbox = e['wpTextbox1'], summary = e['wpSummary'];
if ( !textbox ) {
return;
}
if ( !a || !a.nodeType || a.nodeName === 'IMG' ) {
$( a && a.nodeType ? a : 'img[rel=autoFormatter2]' ).css( {
backgroundColor: '',
opacity: ''
} );
}
this.clickedElement = a;
this.isAll = false;
this.isDisambiguation = /\{\{\s*[Bb]egriffsklärung\s*[|}]/.test( textbox.value );
this.lang = mw.config.get( 'wgContentLanguage' );
this.localisation = typeof window.autoFormatLocalisation === 'undefined' ||
window.autoFormatLocalisation === true ? this.lang : window.autoFormatLocalisation;
this.cleanElement( textbox );
summary.value = this.cleanInternalLinks( summary.value );
if ( window.wikEd && window.wikEd.useWikEd ) {
wikEd.UpdateFrame();
}
return false;
},
isChanged: function( oldValue, newValue ) {
/* Entfernte Leerräume am Textende zählen nie als Änderung */
oldValue = oldValue.replace( /\s+$/, '' );
newValue = newValue.replace( /\s+$/, '' );
/* Entfernte Leerräume am Zeilenende nicht als Änderung anzeigen, aber trotzdem ersetzen */
var changed = oldValue.replace( /[\t\r ]+\n/g, '\n' ) !== newValue;
var a = this.clickedElement;
if ( !a || !a.nodeType || a.nodeName === 'IMG' ) {
$( a && a.nodeType ? a : 'img[rel=autoFormatter2]' ).css( {
backgroundColor: changed ? '#FFD700' : '',
borderRadius: changed ? '3px' : '',
opacity: changed ? '' : '.4'
} );
} else if ( a && a.style ) {
a.style.color = changed ? 'gold' : 'silver';
}
/* Normalisierte Zeilenumbrüche nie als Änderung werten, das vermeidet Flackern */
return changed || oldValue.replace( /\r+$/gm, '' ) !== newValue;
},
cleanElement: function( e ) {
e.focus();
if ( typeof e.selectionStart === 'number' ) {
var scroll = e.scrollTop, s1 = e.selectionStart, s2 = e.selectionEnd;
if ( s2 > s1 && (s1 > 0 || s2 < e.value.length) ) {
var t = this.cleanText( e.value.substring( s1, s2 ) );
if ( t === false ) {
return;
}
var newValue = e.value.substr( 0, s1 ) + t + e.value.substr( s2 );
e.value = newValue;
/* Fix for Opera */
s2 = s1 + t.length + (e.value.length - newValue.length);
} else if ( !this.cleanAll( e ) ) {
return;
}
e.selectionStart = s1;
e.selectionEnd = s2;
e.scrollTop = scroll;
} else if ( typeof document.selection === 'object' ) {
var range = document.selection.createRange();
if ( range.text.length ) {
var t = this.cleanText( range.text );
if ( t !== false ) {
range.text = t;
}
} else {
this.cleanAll( e );
}
} else {
this.cleanAll( e );
}
},
cleanAll: function( e ) {
this.isAll = true;
var t = this.cleanText( e.value );
if ( t !== false ) {
e.value = t.replace( /^\s*\n/, '' );
}
return t !== false;
},
cleanText: function( t ) {
wikt3EditSummary(txt);
var oldValue = t;
t = t.replace(/^(\s*)([\u0B80-\u0BFF]+)(.*)$/gim, "{{User:Shrikarsan/noun-ta|$2$3}}");
t = t.replace(/\s+($)/gm, "$1");
t = t.replace(/($)/gm, "$1");
t = t.replace(/([\{\{]+)([\U\s\e\r]+)/g, "$1subst:$2");
t = t.replace(/([\;]+)([\s*]+)([\u0B80-\u0BFF]+)/g, "\r\n|$2$3");
t = t.replace(/[;]\s*/gm, ';\r\n');
t = t.replace(/\;*\s*$/gm, "");
t = t.replace(/^(.+)\s*(\d\d\. )/gm, '$1\r\n# ');
t = t.replace(/^(.+)\s*(\d\. )/gm, '$1\r\n# ');
t = t.replace(/^(.+)\s+(\([a-z]+\) )/gm, '$1\r\n$2');
t = t.replace(/\.\*\*\*/g, "\r\n#");
t = t.replace(/\*\*\*/g, "");
t = t.replace(/\a\|.*($)/gm, "a|");
t = t.replace(/^(\s*)(.*)$/gim, "$2");
t = t.replace(/\s+($)/gm, "$1");
return this.isChanged( oldValue, t ) ? t : false;
},
};
var addRemoveBrackets = function (addOrRemove) {//addOrRemove == -1 add else remove
var txtBxVal = $('#wpTextbox1').val().trim();
var arrayOfLines = txtBxVal.match(/[^\r\n]+/g);
var patt = new RegExp("[\u0B80-\u0BFF]");
var arrayLength = arrayOfLines.length;
for (var i = 0; i < arrayLength; i++) {
if( patt.test(arrayOfLines[i]) ){
arrayOfLines[i] = arrayOfLines[i].replace(/[^\u0B80-\u0BFF \-\.\,\{\}]/g, ""); //replace everything elseexcept -,.,,, {,} and tamil letters
}
}
txtBxVal = arrayOfLines.join('\r\n');
if(addOrRemove != -1 ){//remove
txtBxVal = txtBxVal.replace(/\}\}/gim, "");
txtBxVal = txtBxVal.replace(/\#\s*/gim, "");
txtBxVal = txtBxVal.replace(/\{\{/gim, "");
}
txtBxVal = txtBxVal.replace(/[ ]{2,}/gm, " ");
txtBxVal = txtBxVal.replace(/\s*\,/g, ".");
txtBxVal = txtBxVal.replace(/\s*\./g, ".");
txtBxVal = txtBxVal.replace(/[/,]/gm, ".");
txtBxVal = txtBxVal.replace(/[/,]{2,}/gm, ".");
txtBxVal = txtBxVal.replace(/[/.]{2,}/gm, ".");
txtBxVal = txtBxVal.replace(/\s*\,/g, ".");
txtBxVal = txtBxVal.replace(/\s*\./g, ".");
txtBxVal = txtBxVal.replace(/([\u0B80-\u0BFF]+)([\.]+)([\u0B80-\u0BFF]+)/g, "$1$2 $3");
txtBxVal = txtBxVal.replace(/([\u0B80-\u0BFF]+)([\.]+)([\u0B80-\u0BFF]+)/g, "$1$2 $3");
if(addOrRemove == -1 ){//add
txtBxVal = txtBxVal.replace(/^(\s*)(.*)$/gim, "#{{$2");//trim left and add bracket
txtBxVal = txtBxVal.replace(/\s+($)/gm, "$1");//trim right
txtBxVal = txtBxVal.replace(/($)/gm, "}}$1");// add bracket
}
$('#wpTextbox1').val(txtBxVal);
};
function wikt3EditSummary(inputText) {
var txt = document.forms.editform.wpSummary;
var tag;
if( typeof wikt3Tag === 'undefined' ) {
tag = '[[பயனர்:Shrikarsan|ஸ்ரீகர்சனின்]] [[பயனர்:Shrikarsan/விக்சனரி 3|விக்சனரி 3]] கருவியின் மூலம் தொகுக்கப்பட்டது';
} else {
tag = wikt3Tag;
}
if( tag.match(/[^\s]/) ) {
if( txt.value.indexOf(tag) == -1 ) {
if( txt.value.match(/[^\*\/\s][^\/\s]?\s*$/) ) {
txt.value += ' | ';
}
txt.value += tag;
}
}
}
if ( mw.user.options.get( 'usebetatoolbar' ) ) {
mw.loader.using( 'ext.wikiEditor', function() {
$( document ).ready( function() {
$('#wpTextbox1').wikiEditor('addToToolbar', {
'sections' : {
'Wikt3Shrikarsan' : {//<<---- Please do not use this name
'type' : 'toolbar',
'label' : 'விக்சனரி 3',
'groups' : {
'Wikt3insert' : {
'label': 'கருவிகள்:',
'tools' : {
'autoFormatter2' : {
label : 'cite-gen-label',
type : 'button',
icon : '//upload.wikimedia.org/wikipedia/commons/e/e0/Accessories-text-editor.svg',
action : {
type : 'callback',
execute : function () { return autoFormat2.click( this ); }
}
},
}
}
}
}
}
});
} );
} );
}
})( jQuery, mediaWiki );