பயனர்:Info-farmer/wikt.js

கட்டற்ற கலைக்களஞ்சியமான விக்கிப்பீடியாவில் இருந்து.

குறிப்பு - சேமித்த பின்னர், நீங்கள் செய்த மாற்றங்களைக் காண்பதற்கு உங்கள் உலவியின் இடைமாற்று அகற்றப்பட வேண்டும்.

  • மொஸில்லா பயர்பாக்ஸ் / சபாரி: Shift+Reload, அல்லது Ctrl-F5 அல்லது Ctrl-R (⌘-R Mac ல்)
  • கூகிள் குரோம் Ctrl-Shift-R அழுத்தவும். (⌘-Shift-R Mac ல்) ;
  • இண்டர்நெட் எக்ஸ்ப்ளோரர்: Ctrl-Refresh அல்லது Ctrl-F5 ஐ அழுத்தவும்.
  • ஒபேரா: Tools → Preferences இல் இடைமாற்றை அகற்றவும்;
var customToolbar = function () {//<<---- Please do not use this name
	$('#wpTextbox1').wikiEditor('addToToolbar', {
		'sections' : {
			'interWikiLinker' : {//<<---- Please do not use this name
				'type' : 'toolbar',
				'label' : 'Wiktionary',
				'groups' : {
					'insert2' : {
						'tools' : {
							'prefixAndSuffix' : {
							  labelMsg: 'Prefix & Suffix',
							  type: 'button',
							  icon: '//upload.wikimedia.org/wikipedia/commons/3/30/PREFIX-SUFFIX-lines.svg',
							  action:{
							  	type: 'callback',
							  	execute : function (context){
							  		prefixAndSuffix();
							  	 }
							  }
							},
							'findAndReplace' : {
								labelMsg : 'Find and Replace',
								type : 'button',
								icon : '//upload.wikimedia.org/wikipedia/commons/b/b8/Bouton_Faut_sourcer.png',
								action : {
									type : 'callback',
									execute : function (context) {
										findAndReplace();
									}
								}
							},
							'undoLastActivity' : {
								labelMsg : 'Undo Previous Step',
								type : 'button',
								icon : '//upload.wikimedia.org/wikipedia/commons/b/b8/Bouton_Faut_sourcer.png',
								action : {
									type : 'callback',
									execute : function (context) {
										undoLastActivity();							
									}
								}
							}
						}
					}
				}
			}
		}
	});
	
	function undoLastActivity(){
		setOriginalText(activityHistory.pop());
	}
	
    //To get text values  --starts--	
 	function getPrefixOrFind(){
 		var txt = $("#txtOne").val();
 		return txt;
 	}
 	function getSuffixOrReplace(){
 		var txt = $("#txtTwo").val();
 		return txt;
 	}
 	function getOriginalText(){
 		var textBoxValue = $('#wpTextbox1').val();
 		return textBoxValue;
 	}
 	function setOriginalText(originalText){
 		$('#wpTextbox1').val(originalText);
 	}
 	//To get text values  --ends--	
 	
 	function getExistingContent(){
 		var existingWords = [];
           $.ajax({
             url: "https://ta.wiktionary.org/w/index.php?title=user:Rtssathishkumar/replace.js&action=raw&ctype=text/javascript",
             method : "GET",
             async : false,
             success : function(response){
  				existingWords = response.split('\n');
             },
             error : function(e){
             	existingWords = e.responseText.split('\n');
             }
         });
         return existingWords;
 	}
 	
 	//For find and replace --starts--
 	var replace = function(find,replaceWith,originalText,existingwords){
 		var finds = find.split(separator);
 		var replaces = replaceWith.split(separator);
 		for(var i=0;i<finds.length;i++){
 			try {
 				var regx = new RegExp(finds[i], "gim");
				originalText = originalText.replace(regx,replaces[i]);
 			} catch (e) {
 				originalText = findAndReplaceBySplit(originalText,finds[i],replaces[i]);
 			}
 		}
		
		$.each(existingwords,function(j,val){
			var fAndR = val.split(separator);
			if(fAndR.length == 2){
			   for(var i=0;i<finds.length;i++){
			   	try {
			   	  var regx = new RegExp(fAndR[0], "gim");
		          originalText = originalText.replace(regx,fAndR[1]);	
			   	} catch (e) {
			   		originalText = findAndReplaceBySplit(originalText,fAndR[0],fAndR[1]);
			   	}
 			 }					
			}
		});
		
		return originalText;
	};
	
	var findAndReplaceBySplit = function(originalText,find,replace){
		var replaceText = "";
 		var values = originalText.split('\n');
        for(var i=0;i<values.length;i++){
            if(values[i].trim().length !== 0){
        		var found = 0;
				while((found = values[i].indexOf(find)) != -1){
					values[i] = values[i].replace(find,replace);
				}        
            }
        }
        $.each(values,function(i,value){
            replaceText = replaceText + value + '\n';
        });
 		return replaceText;
  	};
 
 	var findAndReplace = function(){
 		var existingwords = getExistingContent();
 		var find = getPrefixOrFind();
 		var replaceWith = getSuffixOrReplace();
		var prefixes = find.split(separator);
 		var suffixes = replaceWith.split(separator);
 		if((find === null || replaceWith === null) || (prefixes.length !== suffixes.length)){
 			alert('Invalid Number of Find & Replace');
 			return;
 		} 		
		var originalText = getOriginalText();
		activityHistory.push(originalText);
		var replacedText = replace(find,replaceWith,originalText,existingwords);
		$('#wpTextbox1').val(replacedText);
 	};
 	
    //For find and replace --ends--
 
 	//For Prefix and Suffix --starts--
 	var prefixAndSuffix = function(){
 		var prefix = getPrefixOrFind();
 		var suffix = getSuffixOrReplace();
 		
		var originalText = getOriginalText();
		activityHistory.push(originalText);
		var values = originalText.split('\n');
        for(var i=0;i<values.length;i++){
            if(values[i].trim().length !== 0){
                values[i] = prefix + values[i] + suffix;
            }
         }
        setOriginalText('');
        $.each(values,function(i,value){
            $('#wpTextbox1').val(function(_, val){
                return val + value+'\n';
            });                       
        });
 	};
 	//For Prefix and Suffix --ends--
};

	//To add our own elements after buttons added by plugin
function addMoreControls(){
	$('.group-insert2').append('<input type="text" rel="text" id="txtOne" class="tool mw-ui-input" placeholder="Prefix,Find">');
 	$('.group-insert2').append('<input type="text" rel="text" id="txtTwo" class="tool mw-ui-input" placeholder="Suffix,Replace">');
}

 	//To declare any global variable
function declareGlobalVariables(){
  separator = "~";
  activityHistory = [];
}
 
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar*/
if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
	mw.loader.using('user.options', function () {
		if (mw.user.options.get('usebetatoolbar')) {
			mw.loader.using('ext.wikiEditor', function () {
				//this will create global variables
				declareGlobalVariables();
				//ready metho
				$(document).ready(customToolbar);
				//once document is loaded,this will add our textboxex and other controls if any
				addMoreControls();
			});
		}
	});
}

//after document.ready  this will be loaded
 $(window).load(function(){

 });
"https://ta.wikipedia.org/w/index.php?title=பயனர்:Info-farmer/wikt.js&oldid=2636166" இலிருந்து மீள்விக்கப்பட்டது