பயனர்:Jayarathina/wikt.js
குறிப்பு - சேமித்த பின்னர், நீங்கள் செய்த மாற்றங்களைக் காண்பதற்கு உங்கள் உலவியின் இடைமாற்று அகற்றப்பட வேண்டும்.
- மொஸில்லா பயர்பாக்ஸ் / சபாரி: Shift+Reload, அல்லது Ctrl-F5 அல்லது Ctrl-R (⌘-R Mac ல்)
- கூகிள் குரோம் Ctrl-Shift-R அழுத்தவும். (⌘-Shift-R Mac ல்) ;
- இண்டர்நெட் எக்ஸ்ப்ளோரர்: Ctrl-Refresh அல்லது Ctrl-F5 ஐ அழுத்தவும்.
- ஒபேரா: Tools → Preferences இல் இடைமாற்றை அகற்றவும்;
//IF YOU ARE COPYING THIS CODE FOR YOUR TOOL INTO THIS WIKI, PLEASE DO **NOT** USE THE SAME NAMESPACE: customizeToolbar22 AND interWikiLinker2. Thanks.
var customizeToolbar22 = function () {//<<---- Please do not use this name
$('#wpTextbox1').wikiEditor('addToToolbar', {
'sections' : {
'interWikiLinker2' : {//<<---- Please do not use this name
'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($('#wpTextbox1').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();
}
}
}
}
}
}
}
}
});
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(/\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
}
$('#wpTextbox1').val(txtBxVal);
};
var requestCnt = 0, serverUp = false;
var filterRedLinks = function () {
var myString = $('#wpTextbox1').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
$('#wpTextbox1').prop('readonly', true);
$('#wpTextbox1').css({'background-color' : '#F0F0F0'});
document.body.style.cursor = "wait";
}
};
var getlanglinks = function (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"){
var expr = new RegExp('^.*\\[\\['+ data.query.pages[page].title +'\\]\\].*$', 'gmi') ;
var match = $('#wpTextbox1').val().match(expr);
$('#wpTextbox1').val( $('#wpTextbox1').val().replace(expr, "") );
$('#wpTextbox1').val( $('#wpTextbox1').val() + "\r\n" + match.join("\r\n") );
$('#wpTextbox1').val( $('#wpTextbox1').val().replace(/^\s*\n/gm, "") );
}
}
} catch (e) {
//msgBx.append(' »» இணைப்பில்லை ('+e.message+')' ).css('background', '#fed' );
}
})
.always(function() {
requestCnt--;
if (requestCnt == 0) {
$('#wpTextbox1').prop('readonly', false);
$('#wpTextbox1').css({'background-color' : '#FFFFFF'});
document.body.style.cursor = 'default';
}
});
setTimeout(function() {
if (!serverUp && requestCnt != 0){
alert('தரவு வழங்கல் பிழை.');
$('#wpTextbox1').prop('readonly', false);
$('#wpTextbox1').css({'background-color' : '#FFFFFF'});
document.body.style.cursor = 'default';
$('.msgDisplay_floatingMenu').show();
requestCnt = 0;
}
}, 10000);
};
};
/* 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(customizeToolbar22);
});
}
});
}