பயனர்: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 txt;
var customizeToolbar = function () {
	txt = $('#wpTextbox1');
	txt.wikiEditor('addToToolbar', {
		'sections' : {
			'interWikiLinker' : {
				'type' : 'toolbar',
				'label' : 'விக்சனரி ',
				'groups' : {
					'insert2' : {
						'tools' : {
							'addWikiBracketsToWords' : {
								labelMsg : 'சொற்களுக்கு இணைப்பு குறியிடுக',
								type : 'button',
								icon : '//upload.wikimedia.org/wikipedia/commons/4/4e/Emblem-brackets.svg',
								action : {
									type : 'callback',
									execute : function (context) {
										addRemoveBrackets(txt.val().indexOf("#[["));
									}
								}
							},
							'redLinkFilter' : {
								labelMsg : 'சிகப்பு இணைப்புகளை மட்டும் வடிகட்டு',
								type : 'button',
								icon : '//upload.wikimedia.org/wikipedia/commons/thumb/2/20/Go-jump.svg/200px-Go-jump.svg.png',
								action : {
									type : 'callback',
									execute : function (context) {
										if(requestCnt == 0) filterRedLinks();
									}
								}
							}
						}
					}
				}
			}
		}
	});
};

/* 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 () {
				$(document).ready(customizeToolbar);
			});
		}
	});
}

var requestCnt = 0, serverUp = false;

function filterRedLinks() {
	var myString = txt.val();
	var regex = /\[\[(.*)\]\]/gm;

	var matches, processTxt = [];
	while (matches = regex.exec(myString)) {
		processTxt.push(matches[1]);
	}
	requestCnt = 0, serverUp = false;
	for (var cnt = 0; cnt < processTxt.length; cnt = cnt+45) {
		var rqTxt = processTxt.slice(cnt, cnt+45); 
		var val = rqTxt.join("|"); 
		getlanglinks(val);
	}

	if(requestCnt != 0){//links found but none is valid. Did not pass above filters
		txt.prop('readonly', true);
		txt.css({'background-color' : '#F0F0F0'});
		document.body.style.cursor = "wait";
	}
}

function getlanglinks(val) {//DO NOT MERGE THIS FUNCTION WITH ABOVE; Val HAS TO BE PRESISTANT
	requestCnt++;
	//Don't use fail or error function. error not called for cross site request and fail not called if time-out is not set
	//Time-out can't be set because of non constant reply time.
	$.ajax({
		url : '//ta.wiktionary.org/w/api.php?action=query&format=json&callback=?',
		dataType : 'json',
		type: "GET",
		cache : true,
		data : {
			titles : val,
		}
	})
	.done(function(data) {
		serverUp = true;
		try {
			var page;
			for (page in data.query.pages) {
				if(typeof (data.query.pages[page].missing ) === "undefined"){					
					txt.val( txt.val().replace( new RegExp('^.*\\[\\['+ data.query.pages[page].title +'\\]\\].*$', 'gmi'), "") );
				}
			}
		} catch (e) {
			//msgBx.append(' &raquo;&raquo; இணைப்பில்லை ('+e.message+')' ).css('background', '#fed' );
		}
	})
	.always(function() {
		requestCnt--;
		if (requestCnt == 0) {
			txt.prop('readonly', false);
			txt.css({'background-color' : '#FFFFFF'});
			document.body.style.cursor = 'default';
		}
	});

	setTimeout(function() {
		if (!serverUp && requestCnt != 0){
			alert('தரவு வழங்கல் பிழை.');
			txt.prop('readonly', false);
			txt.css({'background-color' : '#FFFFFF'});
			document.body.style.cursor = 'default';
			$('.msgDisplay_floatingMenu').show();
			requestCnt = 0;
		}
	}, 10000);
}

function addRemoveBrackets(addOrRemove) {//addOrRemove == -1 add else remove
	var txtBxVal = txt.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, ""); 
		}
	}
	txtBxVal = arrayOfLines.join('\r\n');
	
	
	if(addOrRemove != -1 ){//remove
		txtBxVal = txtBxVal.replace(/\[\[|\]\]/gim, "");
	}

	txtBxVal = txtBxVal.replace(/\d/gm, "");// remove digits
	txtBxVal = txtBxVal.replace(/[ ]{2,}/gm, " ");// replace multiple space to single space

	txtBxVal = txtBxVal.replace(/>|\.|,|:|;|</gm, "");//remove some special chars

	txtBxVal = txtBxVal.replace(/\-*\s*$/gm, "");//remove hyphen at end
	txtBxVal = txtBxVal.replace(/\s*\-\s*/g, "-");//space before and after hyphen

	txtBxVal = txtBxVal.replace(/([\u0B80-\u0BFF]+)-([\u0B80-\u0BFF]+)/g, "$1$2");//hyphen between tamil words removed
	
	txtBxVal = txtBxVal.replace(/[\(|\)]/gm, "");//remove simple brackets
	txtBxVal = txtBxVal.replace(/\[.*?\]/gm, "");//remove square brackets and its content
	
	
	txtBxVal = txtBxVal.replace(/^(\s*)(.*)$/gim, "$2");//trim left
	txtBxVal = txtBxVal.replace(/\s+($)/gm, "$1");//trim right
	
	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
	}
	txt.val(txtBxVal);
}
"https://ta.wiktionary.org/w/index.php?title=பயனர்:Info-farmer/wikt.js&oldid=1905852" இலிருந்து மீள்விக்கப்பட்டது