«Մասնակից:Xelgen/CleanupTools.js»–ի խմբագրումների տարբերություն

Content deleted Content added
No edit summary
No edit summary
Տող 1.
//CleanupTools v 0.23 (170414)
//CleanupTools is spin-off from SAETools targeting any page, as opposed to SAETools.
 
var SAEfileNameBeginning='Էջ:Հայկական_Սովետական_Հանրագիտարան_(Soviet_Armenian_Encyclopedia)_';
//var originalHyphenCount, originalSectionCount, originalNewLineCount;
 
 
/* Check if view is in edit mode and that the required modules are available and we're not on SAE page, as SAETools have similar features. Then, customize the toolbar */
/* Commented out, as currently check is done in users' common.js. May need to reenable this initalization call, in Gadgets. */
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 && mw.config.get( 'wgPageName' ).substr(0,66) !== SAEfileNameBeginning) {
$( '#wpTextbox1' ).on( 'wikiEditor-toolbar-doneInitialSections', function () {
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 && mw.config.get( 'wgPageName' ).substr(0,66) !== SAEfileNameBeginning) {
mw.loader.using( 'user.options', function () {
if /*mw.loader.using( mw.'user.options.get('usebetatoolbar'), function () {
if ( mw.user.options.get('usebetatoolbar') ) {
mw.loader.using( 'ext.wikiEditor.toolbar', function () {
mw.loader.using( 'userext.wikiEditor.optionstoolbar', function () {
$(window).load( CTInitialize );
} );
} );
}
}
} );
});
*/
} );
CTInitialize();
 
} );
function CTUpdateSummary()
{
var textarea = document.getElementById("wpTextbox1")
RemovedHyphenCount = originalHyphenCount-textarea.value.split("–\n").length;
textarea.value = textarea.value.replace(/-տողադարձեր/, '-տողադարձեր (' + RemovedHyphenCount +')');
}
 
 
function CTInitialize()
{
//Variables here may be unused, if we don't show count of hyphens/newlines removed.
//originalHyphenCount = document.getElementByIdcountHyphens("wpTextbox1").value.split(/[¬֊-\—-–]\n/g).length-1; //Let's calculate HyphenCount on page open, and calculate it at save, showing number of removed hyphens in Edit summar
originalSectionCount = (document.getElementById("wpTextbox1").value.split(/##/g).length-1)/2; //Same feautre for Sections
originalNewLineCount//originalSectionCount = (document.getElementById("wpTextbox1").value.split(/\n{1}##/g).length-1)/2; //AndSame samefeautre for New Line countSections
originalSectionCount//originalNewLineCount = (document.getElementById("wpTextbox1").value.split(/##\n{1}/g).length-1)/2; //SameAnd feautresame for SectionsNew Line count
addCTToolsButtons();
//To-Do Alt+1, Alt+2 etc are used to swtich between tabs in browsers, we need to override it or change hotkeys
$(document).keyup(function(evt)
{
Տող 60 ⟶ 59՝
}
});
}
 
//We're adding button here
function addCTToolsButtons ()
{
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'main',
Տող 126 ⟶ 127՝
} );
 
//Is separator in toolbar needed for 3 buttons?
 
//$(".group.group-insert").css("border-right","1px solid #DDDDDD");
 
}
 
varfunction removeNewLines = function () {
var text = document.getElementById("wpTextbox1").value;
origNewLineCount = text.split("\n").length;
Տող 146 ⟶ 147՝
 
 
varfunction removeHyphens = function() {
 
// [Ա-և] բոլոր հայերեն տառերը
Տող 153 ⟶ 154՝
 
var text = document.getElementById("wpTextbox1").value;
var origHyphenCount = text.splitcountHyphens("–\n").length;
 
//removing new lines between numbers, leaving dash intact
text = text.replace(/([0-9])[-֊¬-]\n([0-9])/g, "$1–$2");
//Regexp for not touching hidden Y is too complex to mantain,
//so instead of making it skip e-/nv we're making a dirty trick here
Տող 162 ⟶ 163՝
 
//Remove (we're very careful taking max 6 letter long words, not to brake dashed phrases)
text = text.replace(/([\s«\(])(([Ա-և](?!ը)){2,6})[-֊¬-]\n([ա-էթ-և]{1,5}[ա-և]|ը$)([\s,:։․՝»\)])/g, "$1$2$4$5");
//Remove (if part after hyphen is max 3 letters, then it can't be compound issues with Ev unsolved &
//we're very careful taking max 6 letter long words, not to brake dashed phrases)
text = text.replace(/([\s«\(])(([Ա-և](?!ը)){2,})[-֊¬-]\n([ա-էթ-և]{1,2}[ա-և]|ը$)([\s,:։․՝»\)])/g, "$1$2$4$5");
text = text.replace(/([\s«\(])([Ա-և][ա-էթ-և]|[Ա-և]{1}ու|ու[ա-թի–և]{1})[֊¬–-]\n([ա-էթ-և]{1,}[ա-և])([\s,:։՝»\)])/g, "$1$2$3$4"); //if first part has just 2 letters, it's not a dashed word, ու is basically one letter, so 2 special caes for that, and we're taking out ուժ as it can be compound word
 
text = text.replace(/([Ա-ԷԹ-Ֆա-էթ-և]{3,})[֊¬-]\n([ա-և]{0,3}թյուն(?:ը|ն|ներ|ների|ներից|ները|ներն|ներում)?|[ա-և]{0,3}թյամբ|[ա-և]{0,3}թյան(?:ը|ն|ներ|ների|ները|ներն|ներում)?|[ա-և]{0,2}յինը?|[ա-և]ում|յան|[ա-և]{0,2}կանը?|ներ[ա-և]{0,2})([\s,:։․՝»])/g, "$1$2$3"); //after being so careful, not to brake dashes where they should be, we need to take most common suffixes, and try to do some more work
 
//We're removing what we've done in dirty e-/nv trick here. Sorry for this.
Տող 174 ⟶ 175՝
 
document.getElementById("wpTextbox1").value = text;
removedHyphenCount = origHyphenCount-text.splitcountHyphens("–\n").length;
if (removedHyphenCount>0)
{
Տող 180 ⟶ 181՝
}
mw.notify('Հեռացվեց ' + removedHyphenCount + ' տողադարձ ' + origHyphenCount + '-ից');
};
 
 
varfunction fixArmPunctuation = function() {
var text = document.getElementById("wpTextbox1").value;
 
Տող 198 ⟶ 199՝
document.getElementById("wpTextbox1").value = text;
insertSummary('+հայ․ կետ․ ');
};
 
function countHyphens () {
var textarea =return document.getElementById("wpTextbox1").value.split(/[¬֊-\—-–]\n/g).length-1;
}
 
function insertSummary( text ) {
var sum = $('#wpSummary'), vv = sum.val();
if (vv.indexOf(text) !== -1) return;
if (/[^,; \/]$/.test(vv)) vv += ',';
if (/[^ ]$/.test(vv)) vv += ' ';
sum.val(vv + text);
}