Usuario:Ignacio Rodríguez/Botonera.js
Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.
- Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
- Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
- Internet Explorer/Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
- Opera: Presiona Ctrl+F5.
/***************************************************************
* Botonera
* TODO: Documentar, etc. Cargar lista de regex desde otra parte?
***************************************************************/
// Check if we're editing a page.
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
// Add a hook handler.
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
// Configure a new toolbar entry on the given $textarea jQuery object.
$textarea.wikiEditor( 'addToToolbar', {
section: 'proofreadpage-tools',
groups: {
advanced: {
label: 'Avanzado' // or use mw.msg() for a localized label, see above
}
},
group: 'advanced',
tools: { cleanOCR: {
label: 'Limpiar OCR',type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/f/fe/OOjs_UI_icon_checkAll.svg/20px-OOjs_UI_icon_checkAll.svg.png',
action: {type: 'callback', execute: function ( context ) {pageCleanup()}}
},
header: {label: 'Agregar encabezado',type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/9/99/Tabler-icons_arrow-bar-to-up.svg/24px-Tabler-icons_arrow-bar-to-up.svg.png',
action: {type: 'callback', execute: function ( context ) {cabeceraPagina()}}
},
footer: {label: 'Agregar pie de página',type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/e/e6/Tabler-icons_arrow-bar-to-down.svg/24px-Tabler-icons_arrow-bar-to-down.svg.png',
action: {type: 'callback', execute: function ( context ) {piePagina()}}
},
makeref: {label: 'Hacer referencia',type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/f/f8/Tabler-icons_code.svg/24px-Tabler-icons_code.svg.png',
action: {type: 'callback', execute: function ( context ) {makeReference()}}
},
smallcaps: {label: 'Versalitas',type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/b/b5/Tabler-icons_text-size.svg/24px-Tabler-icons_text-size.svg.png',
action: {type: 'callback', execute: function ( context ) {versalita()} }
},
upper: {label: 'A mayúsculas',type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/8/8d/Tabler-icons_letter-case-upper.svg/24px-Tabler-icons_letter-case-upper.svg.png',
action: {type: 'callback', execute: function ( context ) {mayus()} }
},
lower: {label: 'A minúsculas',type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/d/d4/Tabler-icons_letter-case-lower.svg/24px-Tabler-icons_letter-case-lower.svg.png',
action: {type: 'callback', execute: function ( context ) {minus()} }
},
orthoOld: {label: 'Arcaizar ortografía',type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/2/2d/OOjs_UI_icon_searchDiacritics.svg/20px-OOjs_UI_icon_searchDiacritics.svg.png',
action: {type: 'callback', execute: function ( context ) { orthoOld()} }
},
regexp: {label: 'Editor de regex',type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/c/cd/OOjs_UI_icon_regular-expression.svg/24px-OOjs_UI_icon_regular-expression.svg.png',
action: {type: 'callback', execute: function ( context ) { $('#ts-link-0').click() } }
},
}
} );
$('[rel="cleanOCR"]').attr('accesskey', "2");
$('[rel="header"]').attr('accesskey', "3");
$('[rel="footer"]').attr('accesskey', "4");
$('[rel="makeref"]').attr('accesskey', "h");
$('[rel="lower"]').attr('accesskey', "-");
$('[rel="smallcaps"]').attr('accesskey', "+");
$('[title="Negrita"]').attr('accesskey', "n");
$('[title="Cursiva"]').attr('accesskey', "k");
} );
}
/******************************************************************************
* Funciones recreadas acá
* A lo bruto pq no tengo posibilidades de replicar la lógica de TemplateScript
* Está todo en el historial si alguien del futuro puede hacerlo
* ****************************************************************************/
// Roman numeral functions
// From http://blog.stevenlevithan.com/archives/javascript-roman-numeral-converter
function int_to_roman( num ) {
if ( Number( num ) === 0 ) {
return false;
}
var digits = String( Number( num ) ).split( '' ),
key = [ '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
'', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
'', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
],
roman = '',
i = 3;
while ( i-- ) {
roman = ( key[ +digits.pop() + ( i * 10 ) ] || '' ) + roman;
}
return Array( +digits.join( '' ) + 1 ).join( 'M' ) + roman;
}
function roman_to_int( in_str ) {
var str = in_str.toUpperCase(),
validator =
/^M*(?:D?C{0,3}|C[MD])(?:L?X{0,3}|X[CL])(?:V?I{0,3}|I[XV])$/,
token = /[MDLV]|C[MD]?|X[CL]?|I[XV]?/g,
key = {
M: 1000,
CM: 900,
D: 500,
CD: 400,
C: 100,
XC: 90,
L: 50,
XL: 40,
X: 10,
IX: 9,
V: 5,
IV: 4,
I: 1
},
num = 0,
m;
if ( !( str && validator.test( str ) ) ) { return false; }
while ( ( m = token.exec( str ) ) ) { num += key[ m[ 0 ] ]; }
return num;
}
var write_to = function(target, text){
target.focus();
document.execCommand("selectAll");
target.textSelection('replaceSelection', text);
};
var pageCleanup = function(context) {
var $textbox = $( '#wpTextbox1' );
var text = $textbox.val();
// push <noinclude> content at the top & bottom into the header & footer
if (text.match(/^<noinclude\>/)) {
var e = text.indexOf("</noinclude>");
$('#wpHeaderTextbox').val(function(i, val) {
return $.trim(val + "\n" + text.substr(11, e-11).replace(/^\s+|\s+$/g, ''));
});
text = text.substr(e+12);
}
if (text.match(/<\/noinclude\>$/)) {
var s = text.lastIndexOf("<noinclude>");
$('#wpFooterTextbox').val(function(i, val) {
return $.trim(text.substr(s+11, text.length-s-11-12).replace(/^\s+|\s+$/g, '') + "\n" + val);
});
text = text.substr(0, s);
}
// clean up text
text = text
// remove trailing spaces at the end of each line
.replace(/ +\n/g, '\n')
// remove trailing whitespace preceding a hard line break
.replace(/ +<br *\/?>/g, '<br />')
// remove trailing whitespace and numerals at the end of page text
// (numerals are nearly always page numbers in the footer)
.replace(/[\s\d]+$/g, '')
.replace(/^[\s\d]+/g, '')
// quitar restos de OCR de Google
.replace(/Digitized.{8,15}$/g, '')
// quitar Biblioteca Nacional de España
.replace(/(© )?Biblioteca Nacional de España/g, '')
// remove trailing spaces at the end of refs
.replace(/ +<\/ref>/g, '</ref>')
// remove trailing spaces at the end of template calls
.replace(/ +}}/g, '}}')
// convert double-hyphen to mdash (avoiding breaking HTML comment syntax)
.replace(/([^\!])--([^>])/g, '$1—$2')
// remove spacing around mdash, but only if it has spaces on both sides
// (we don't want to remove the trailing space from "...as follows:— ",
// bearing in mind that the space will already be gone if at end of line).
.replace(/ +— +/g, '—')
// aparecer "guiones suaves"
//.replace(/\u00AD/g, '-')
// join words that are hyphenated across a line break
// (but leave "|-" table syntax alone)
.replace(/([^\|])[\-¬\u00AD]\n/g, '$1');
// clean up pages if they don't have <poem>
if (text.indexOf('<poem>') == -1) {
text = text
// lines that start with " should probably be new lines,
// if the previous line ends in punctuation,
// other than a comma or semicolon
// and let's get rid of trailing space while we're at it
.replace(/([^\n\w,;])\n\" */g, '$1\n\n"')
// nueva línea y abre comillas (o cierra en algunos casos)
// probablemente sea continuación de las comillas, excepto
// si precede un punto (creo que de eso se encarga la expresión)
// anterior, pero mejor estar seguros.
.replace(/([^\n\.:])\n["«»]/g, '$1 ')
// lines that end with " should probably precede a new line,
// unless preceded by a comma,
// or unless the new line starts with a lower-case letter;
// and let's get rid of preceding space while we're at it
.replace(/([^,])\ *\"\n([^a-z\n])/g, '$1"\n\n$2')
//nueva línea y emdash probablemente es un diálogo y debería ser un nuevo párrafo
.replace(/([^\n])\n—/g, '$1\n\n—')
// remove single line breaks; preserve multiple.
// but not if there's a tag, template or table syntax either side of the line break
.replace(/([^>}\|\n])\n([^:#\*<{\|\n])/g, '$1 $2')
// collapse sequences of spaces into a single space
.replace(/ +/g, ' ');
}
// more page cleanup
text = text
// dump spurious hard breaks at the end of paragraphs
.replace(/<br *\/?>\n\n/g, '\n\n')
//caracteres fantasma
.replace(/[�]/g, '')
// remove unwanted spaces around punctuation marks
.replace(/ ([;:\?!,\.])/g, '$1')
// unicodify
.replace(/—/g, '—')
.replace(/–/g, '–')
.replace(/"/g, '"')
// straighten quotes and apostrophes.
.replace(/[“”]/g, '"')
.replace(/[‘’`]/g, '\'')
//OCR fixes
// números
.replace(/([a-zA-ZáéíoúüÁÉÍÓU])1([a-zA-ZáéíoúüÁÉÍÓU])/g, '$1l$2')
// .replace(/([a-zA-ZáéíoúüÁÉÍÓU])1/g, '$1l')
// .replace(/([a-zA-ZáéíoúüÁÉÍÓU])0/g, '$1o')
.replace(/([a-zA-ZáéíoúüÁÉÍÓU])0([a-zA-ZáéíoúüÁÉÍÓU])/g, '$1o$2')
.replace(/([a-zA-ZáéíoúüÁÉÍÓU])[58~]([a-zA-ZáéíoúüÁÉÍÓU])/g, '$1s$2')
.replace(/([a-zA-ZáéíoúüÁÉÍÓU])6/g, '$1ó')
.replace(/([a-zA-ZáéíoúüÁÉÍÓU])0/g, '$1o')
.replace(/([a-zA-ZáéíoúüÁÉÍÓU])6([a-zA-ZáéíoúüÁÉÍÓU])/g, '$1é$2')
.replace(/!([a-záéíóú])/g, 'l$1')
.replace(/([a-záéíóú])l·([a-záéíóú])/g, '$1r$2')
.replace(/_/g, '—')
//.replace(/ \(l/g, ' d')
.replace(/([^IVXLCDM])I\)/g, '$1P') //defensa contra números romanos
.replace(/([a-záéíóú])U/g, '$1u')
//partículas y consonantongos que no existen, o casi no existen en español
//.replace(/(!)c([.,;:!?}{\]\[\|\s]|$)/g, 'e$1') // c final --> e
.replace(/aiia/g, 'ana')
.replace(/abn([.,;:!?}{\]\[\|\s]|$)/g, 'aba$1')
.replace(/aiit/g, 'ant')
.replace(/ hl([aeiouáéíóú])/g, 'bl$1')
//.replace(/hr/g, 'br')
.replace(/bn([^eiou ,.\n])/g, 'bu$1')
.replace(/cb/g, 'ch')
.replace(/Cb/g, 'Ch')
.replace(/chn([.,;:!?}{\]\[\|\s]|$)/g, 'cha$1')
.replace(/([ae])iit([eo])/g,'$1nt$2')
.replace(/([ae])ute(s?[.,;:!?}{\]\[\|\s]|$)/g, '$1nte$2')
.replace(/([scgp])nn/g,'$1un')
//.replace(/clas([.,;:!?}{\]\[\|\s]|$)/g,'das$1')
.replace(/dn([ds])([.,;:!?}{\]\[\|\s]|$)/g,'da$1$2')
.replace(/ rlic/g, ' dic')
.replace(/ [rc]lil/g, ' dil')
.replace(/clel/g, 'del')
.replace(/ cles/g, ' des')
.replace(/ clis/g, ' dis')
.replace(/clici/g, 'dici')
.replace(/clig/g, 'dig')
.replace(/clv/g, 'dv')
.replace(/cou/g, 'con')
.replace(/ lr/g, ' h')
.replace(/ hn/g, ' hu')
.replace(/nii/g, 'mi')
.replace(/ iia/g, ' na')
.replace(/iinp/g, 'imp')
.replace(/inip/g, 'imp')
.replace(/inb/g, 'mb')
.replace(/cne/g, 'cue')
.replace(/cleb/g, 'deb')
.replace(/snf/g, 'suf')
.replace(/ln([dn])/g, 'lu$1')
.replace(/rn([pb])/g, 'm$1')
.replace(/ iuc/g, ' inc')
.replace(/ llc/g, ' lle')
.replace(/ inu(?!b)/g, ' mu') // inubicable
.replace(/ rn/g, ' m')
.replace(/rrn/g, 'rm')
.replace(/mh/g, 'mb')
.replace(/nibr/g, 'mbr')
.replace(/mcn/g, 'men')
.replace(/iiip/g, 'mp')
.replace(/inp/g, 'mp')
.replace(/enip(?!o)/g, 'emp')
.replace(/onip/g, 'omp')
.replace(/ nne/g, ' nue')
.replace(/clia/g, 'cha')
.replace(/ lia/g, ' ha')
.replace(/([^um])irn([^o])/g, '$1im$2')
.replace(/([ae])iid/g, '$1nd')
.replace(/((?!eu|Eu).{2})cli([jrd])/g, '$1di$2')
.replace(/clist/g, 'dist')
.replace(/cnto([.,;:!?}{\]\[\|\s]|$)/g,'ento$1')
.replace(/nndo([.,;:!?}{\]\[\|\s]|$)/g,'ando$1')
.replace(/ii([.,;:!?}{\]\[\|\s]|$)/g,'n$1')
.replace(/cl([.,;:!?}{\]\[\|\s]|$)/g,'d$1')
.replace(/fc/g, 'fe')
.replace(/gnl/g,'gul')
.replace(/jni/g,'jui')
.replace(/lln([.,;:!?}{\]\[\|\s]|$)/g,'lla$1')
.replace(/nlt/g,'nst')
.replace(/iic/g,'nc')
.replace(/oncli/g,'ondi')
.replace(/pcr/g,'per')
.replace(/pne/g,'pue')
.replace(/oue/g,'one')
.replace(/([rl])cs([.,;:!?}{\]\[\|\s]|$)/g,'$1es$2')
.replace(/rcg/g,'reg')
.replace(/([^eé])tn/g, '$1tu')
.replace(/ sne/g,' sue')//etnia, étnico
.replace(/tc([lm])/g,'te$1')
.replace(/tiir/g,'tur')
// .replace(/urne/g,'ume')
.replace(/ Jni/g,' Uni')
.replace(/ vne/g,' vue')
.replace(/xol/g,'xcl')
.replace(/ gn/g,' gu')
.replace(/dn([oa])/g,'du$1')
.replace(/ oo/g,' co')
.replace(/([n])eoe/g,'$1ece')
.replace(/ncs/g,'nes')
.replace(/i\//g,'y')
.replace(/ i[)>]/g,' p')
.replace(/(?<=[a-z] )Ja (?![Jj]a)/g, 'la ') // evitar modificar Ja ja ja
//fi --> ñ
.replace(/ afio/g,' año')
.replace(/ afiad/g,' añad')
.replace(/ifia/g,'iña')
.replace(/compafi/g, 'compañ')
.replace(/([Ee])spa[fi]ia/g,'$1spaña')
.replace(/([Ee])spa[fi]iol/g,'$1spañol')
.replace(/afier/g,'añer')
.replace(/tafia/g,'taña')
.replace(/([Ss])efia([lrb])/g,'$1eña$2')
.replace(/([Ss])efior/g,'$1eñor')
.replace(/efio([ .,\n])/g,'eño$1')
.replace(/mafio([ .,\n])/g,'maño$1')
.replace(/trafio/g,'traño')
.replace(/empefi(?=o|a)/g, 'empeñ')
// tl —————> d (exepto en casos como atlas, y palabras aztecas)
.replace(/otl/g,'od')
.replace(/utl/g,'ud')
.replace(/tlo([.,;:!?}{\]\[\|\s]|$)/g,'do$1')
.replace(/itla/g,'ida')
// OCR a español (gracias Aleator)
.replace(/([Qq])(?:ll|n|li)/g, '$1u')
.replace(/([Qq])(?:o|a|tl|u)([eié])/g, '$1u$2')
//.replace(/([Qq])(?:o|a|tl|u)á/g, '$1ué')
.replace(/([Qq])[aou][cers]/g, '$1ue')
.replace(/([Qq])lll/g, '$1ue')
.replace(/d([A-ZÁÉÍÓÚ])/g,'¿$1')
.replace(/ d([qcdhp])/g,' ¿$1')
.replace(/([a-zó])[P]"/g,'$1?"')
.replace(/([a-zó])[P]([ ,\n])/g,'$1?$2')
.replace(/ DO /g,' no ')
.replace(/ UTI /g,' un ')
.replace(/ UD /g,' un ')
.replace(/ UDA /g,' una ')
.replace(/ u n /g,' un ')
.replace(/ n /g,' a ')
.replace(/ d /g,' el ')
.replace(/ im /g, ' un ')
.replace(/ ima /g, ' una ')
.replace(/ tari /g, ' tan ')
.replace(/ ([Aa])sl /g,' $sí ')
.replace(/ \'[lI]\'/g, ' T')
.replace(/]([a-záéíóú])/g,'l$1')
.replace(/fi/g,'fi')
.replace(/fl/g,'fl')
.replace(/ £[1l] /g,' El ')
.replace(/((?!para).{4})noi([ao])/g,'$1nci$2')
.replace(/au([.,;:!?}{\]\[\|\s]|$)/g, 'an$1')
.replace(/aha([.,;:!?}{\]\[\|\s]|$)/g, 'aba$1')
.replace(/ahan([.,;:!?}{\]\[\|\s]|$)/g, 'aban$1')
.replace(/ (a[iïíìl!1I]g[anou][nu])/g, ' algun')
.replace(/(ag[un]a)/g, 'agua')
.replace(/ afio /g, ' año ')
.replace(/ ao/g, ' au')
.replace(/hle([.,;:!?}{\]\[\|\s]|$)/g, 'ble$1')
.replace(/ oen/g, ' cen')
.replace(/c[iïíìl!1I][56d][un]([.,;:!?}{\]\[\|\s]|$)/g, 'ción$1')
.replace(/oio[un]/g, 'cion ')
.replace(/oió[un]/g, 'ción ')
.replace(/(c[iïíìl!1I][56d][ns][ce][8s] )/g, 'ciones ')
.replace(/( co[ir]no )/g, ' como ')
.replace(/( co[un][iïíìl!1I]o )/g, ' como ')
.replace(/( eomo )/g, ' como ')
.replace(/( [oce][op]n )/g, ' con ')
.replace(/cb/g, 'ch')
.replace(/ Kn/g, 'En')
.replace(/c[ïl!1I]o([.,;:!?}{\]\[\|\s]|$)/g, 'cio$1')
.replace(/dn([.,;:!?}{\]\[\|\s]|$)/g, 'da$1')
.replace(/tlar([.,;:!?}{\]\[\|\s]|$)/g, 'dar$1')
.replace(/tla([.,;:!?}{\]\[\|\s]|$)/g, 'da$1')
.replace(/( [tc][li]e )/g, ' de ')
.replace(/( d[ocs] )/g, ' de ')
.replace(/( ¿c )/g, ' de ')
.replace(/( c[li][ce]l )/g, ' del ')
.replace(/( d[ce][iïíìl!1I] )/g, ' del ')
.replace(/(d[ce][s8])/g, 'des')
.replace(/(d[ïì1I])/g, 'di')
.replace(/([BE][iïíìl!1I] )/g, 'El ')
.replace(/(EUa )/g, 'Ella ')
.replace(/ eua /g, ' ella')
.replace(/( [ce][iïíìl!1I] )/g, ' el ')
.replace(/( [ce][iïíìl!1I][iïíìl!1I]a)/g, ' ella')
.replace(/( [ce][iïíìl!1I][iïíìl!1I]o)/g, ' ello')
.replace(/(eU)/g, 'ell')
.replace(/cm(?!\.)/g, 'em')
.replace(/[BE][nqu] /g, 'En ')
.replace(/ cnal/g, ' cual')
.replace(/ cn/g, ' en')
.replace(/(?!cudo)[ce][un]do([.,;:!?}{\]\[\|\s]|$)/g, 'endo$1') // escudo, zancudo, picudo...`
.replace(/ [ce][un] /g, ' en ')
.replace(/[ce]n[lt] /g, 'ent ')
.replace(/[ce][un][lt]o[un][ce][ce]s/g, 'entonces')
.replace(/E[un][lt]o[un][ce][ce]s/g, 'Entonces')
.replace(/ [ce]n[it]r[ce]/g, ' entre')
.replace(/ [ce][as] /g, ' es ')
.replace(/[ce][8s][ce]ri/g, 'escri')
.replace(/ [ce][s8][lt]([aáà])([ t])/g, ' est$1$2')
.replace(/ [ce]t[ce]([.,;:!?}{\]\[\|\s]|$)/g, ' etc$1')
.replace(/ é[8s][tl]([aoe])/g, ' ést$1')
.replace(/exlr/g, 'extr')
.replace(/(g[iïíìl!1I][6é]s)/g, 'glés')
.replace(/(?!ma)(..)g[nu]é/g, '$1gué') //con excepción para magnético
.replace(/gn[ce]/g, 'gne')
.replace(/gu[ce]/g, 'gue')
.replace(/ha[nu] /g, 'han ')
.replace(/ ba /g, ' ha ')
.replace(/ h[ns]b/g, ' hab')
.replace(/ H[ns]b/g, ' Hab')
.replace(/ hah/g, ' hab')
.replace(/ Hah/g, ' Hab')
.replace(/[bh][oe]mbr[ce]/g, 'hombre')
.replace(/horn([^eoi])/g, 'hom$1')
.replace(/ (?!in|Ia)[iïíìl!1I][na] /g, ' la ')
.replace(/ [iïíìl!1I][na][a8s] /g, ' las ')
.replace(/ [iïíìl!1I]o /g, ' lo ')
.replace(/ [iïíìl!1I][oO0][a8s] /g, ' los ')
.replace(/lloa([.,;:!?}{\]\[\|\s]|$)/g, 'llos$1')
.replace(/llaa([.,;:!?}{\]\[\|\s]|$)/g, 'llas$1')
.replace(/loient[ec]([.,;:!?}{\]\[\|\s]|$)/g, 'lmente$1')
.replace(/m[ce][un]t[ce]([.,;:!?}{\]\[\|\s]|$)/g, 'mente$1')
.replace(/m[ce]ot[ce]([.,;:!?}{\]\[\|\s]|$)/g, 'mente$1')
.replace(/(?!te|ve|po|.r|vi|Te|Po)(..)ni[ce]nt[ce]([.,;:!?}{\]\[\|\s]|$)/g, '$1mente$2') //excepción para teniente, poniente, conveniente, interviniente, concerniente y similares
.replace(/ mne/g, ' mue')
.replace(/ misino([.,;:!?}{\]\[\|\s]|$)/g, ' mismo$1')
.replace(/(Q[anou][ce])/g, 'Que')
.replace(/([çq][anou][ce])/g, 'que')
.replace(/([çq]ii[ce])/g, 'que')
.replace(/q[a-záéíóú]e/g, 'que')
.replace(/q[a-záéíóú]é/g, 'qué')
.replace(/([çq][anou][óé])/g, 'qué')
.replace(/ [sB][ec] /g, ' se ')
.replace(/ sn /g, ' su ')
.replace(/ tau /g, ' tan ')
.replace(/trn([.,;:!?}{\]\[\|\s]|$)/g, 'tra$1')
.replace(/ TJ([a-z])/g, ' U$1')
.replace(/ [un][un] /g, ' un ')
.replace(/ [un](?:[un]|ii)a /g, ' una ')
.replace(/ o[un]a /g, ' una ')
.replace(/ \'?"?[lv] /g, ' y ')
.replace(/(•)/g, '.')
//.replace(/[lt!]'(?!')/g, 'r') -- demasiados falsos positivos
.replace(/i([A-ZÁÉÍÓÚ])/g,'¡$1')
//paréntesis en palabras
.replace(/\(\)/g,'o')
.replace(/\(\'\)/g,'ó')
.replace(/l\)([a-záéíóú])/g,'b$1')
.replace(/\(\(/g,'«')
.replace(/\)\)/g,'»')
.replace(/\(pi/g,'qu')
.replace(/\(]/g,'q')
.replace(/([^\]])]\)/g,'$1p')
//espacio después de punto o coma
.replace(/(\.)([A-ZÁÉÍÓÚ])/g,'$1 $2')
.replace(/([,;:!\?])([a-záéíóú])/g,'$1 $2')
//.replace(/([a-záéíóú][a-záéíóú][a-záéíóú])\. ([a-záéíóú][a-záéíóú])/g,'$1, $2') demasiados falsos positivos con abreviaturas
.replace(/([a-záéíóú])\'([a-záéíóú])/g,'$1 $2')
.replace(/\.-/g, '.—')
.replace(/\^ /g, ', ')
//.replace(/ P /g, '? ')
.replace(/[.,][.,][.,]/g, '...')
.replace(/([¿¡]) /g, '$1')
.replace(/\( /g, '(')
.replace(/ \)/g, ')');
$textbox.focus();
write_to($textbox, text);
};
function splitPagina(tpp) {
var testo = ["", "", ""];
testo[0] = tpp.substring(0, tpp.indexOf("</noinclude>") + 12);
testo[2] = tpp.substring(tpp.lastIndexOf("<noinclude>"));
testo[1] = tpp.substring(testo[0].length, tpp.length - testo[2].length);
testo[0] = $.trim(testo[0].replace(/<noinclude\><pagequality.+?>/,"").replace("</noinclude>",""));
return testo;
}
var cabeceraPagina = function(){
var offsets = [-2, -4, 2, 4, -1, 1];
window.off_slot = window.off_slot || 0;
if (window.off_slot > offsets.length) { return }
pageName=$("#firstHeadingTitle").html(); // obtenerlo directamente del HTML para compatibilidad con EIS
var t=(/(.+\/)(\d+)$/).exec(pageName);
var offset = offsets[window.off_slot];
var t_n = t[2]*1 + offset;
title = t[1] + t_n;
var api = new mw.Api();
api.get( {
action: 'query',
prop: 'revisions',
titles: title,
rvprop:"content"
} ).done( function ( data ) {
$.each(data.query.pages, function(index,value) {
if (data.query.pages[index].missing!==undefined) {
window.off_slot++;
cabeceraPagina();
} else {
split = splitPagina(data.query.pages[index].revisions[0]["*"]);
console.log('split', split);
if (split[0]) {
addCabecera(split[0], offset); }
else {
window.off_slot++;
cabeceraPagina(); }
}
});
});
};
var getNewHeader = function(cab, off){
rexp0 = /{{ *c(?:entrar)?\|[^|}]*?(\d+)[^|}]*}}}/i;
var match = cab.match(rexp0);
if (match) {
num = match[1];
return cab.replace(num, num*1 - off);
}
rexp1 = /{{ *(?:cp|rh)\|([^|]*)\|*([^|]*)\|*([^|]*?)}}/i;
match = cab.match(rexp1);
if (match){
// dar vuelta recto-verso
if (off % 2 != 0){ cab = cab.replace(rexp1, "{{cp|$3|$2|$1}}")}
verso = /{{ *(?:cp|rh) *\|[^|}]*?(\d+)/i;
recto = /{{ *(?:cp|rh)\|[^|}]*?\|[^|}]*\|[^|}]*?(\d+)/i;
if (verso.test(cab)) {
match = cab.match(verso)[1];
} else if (recto.test(cab)){
match = cab.match(recto)[1];
} else if (/(\d+)/.test(cab)){ // x si cae algo
match = cab.match(/(\d+)/)[1];
}
return cab.replace(match, match*1 - off);
} else if (/(\d+)/.test(cab)){
match = cab.match(/(\d+)/)[1];
return cab.replace(match, match*1 - off);
}
console.log('cab', cab);
return cab;
};
var addCabecera = function(data, offset) {
$header = $("#wpHeaderTextbox");
$header.focus();
try {
nuevoCab = getNewHeader(data, offset);
write_to($header, nuevoCab);
}
catch (error) {
console.log(error);
write_to($header, data);
}
};
/**
* As you work your way through the page, when you encounter a reference, just mark it with <ref></ref> tags and continue.
* Once you've got to the end of the page and proofed the references, simply highlight each reference in turn,
* and use this function to move it to its proper position.
* @param {object} editor The script helpers for the page.
*/
var makeReference = function() {
var editbox = $('#wpTextbox1').get(0);
editbox.focus();
var refStart = editbox.selectionStart;
var refEnd = editbox.selectionEnd;
var firstref = editbox.value.indexOf('<ref></ref>');
if (firstref != -1) {
editbox.value = editbox.value.slice(0,firstref+5)
+ editbox.value.slice(refStart, refEnd)
+ editbox.value.slice(firstref+5, refStart)
+ editbox.value.slice(refEnd);
}
piePagina(context);
};
/**
* Insert formatted references into the footer box if needed.
* @param {object} editor The script helpers for the page.
*/
var piePagina = function() {
var editbox = $('#wpTextbox1').get(0);
var $footbox = $('#wpFooterTextbox');
var footvaal = $footbox.val();
var footerbox = '';
var group = editbox.value.match(/<ref *group *= *["']*([^\s]+)["']* *>/); //
var endtable = editbox.value.match(/\n\|-\s*$/); //si termina con una tabla, agregar arreglos para cerrarla correctamente
if (editbox.value.indexOf("<ref") == -1 && editbox.value.indexOf("{{#tag:ref") == -1) {
}
else if (footval.indexOf("{{listaref") == -1) {
if (endtable){
footerbox = "{{npt}}\n|}";
}
footerbox += '\n{{listaref}}';
if (group){
footerbox += '\n{{listaref|group='+group[1]+'}}';
}
}
var final = footval + footerbox;
$footbox.focus();
write_to($footbox, final.trim());
};
/**
* Mark the selected text with {{sc}}. If the text is uppercase, it will be converted to titlecase.
*/
var versalita = function() {
var $textbox = $( '#wpTextbox1' );
text = $textbox.textSelection( 'getSelection');
if (text == text.toUpperCase()){
text = _titlecase(text);}
$textbox.textSelection('replaceSelection', '{{may|' + text + '}}');
};
/**
* Convert the text to uppercase.
* @param {object} editor The script helpers for the page.
*/
var mayus = function() {
var $textbox = $( '#wpTextbox1' );
text = $textbox.textSelection( 'getSelection');
$textbox.textSelection( 'replaceSelection', text.toUpperCase());
};
var minus = function() {
var $textbox = $( '#wpTextbox1' );
text = $textbox.textSelection( 'getSelection');
$textbox.textSelection( 'replaceSelection', text.toLowerCase());
};
function orthoOld() {
var $textbox = $( '#wpTextbox1' );
var text = $( '#wpTextbox1' ).val();
$textbox.focus();
text = text.replace(/ a /g,' á ')
.replace(/ o /g,' ó ')
.replace(/ e /g,' é ')
.replace(/ión\b/g,'ion')
;
write_to($textbox, text);
}
var _titlecase = function(text) {
// split text into individual words and examine them one by one
var words = text.toLowerCase().split(" ");
$.each(words, function(i, word) {
switch(word) {
case "a":
case "á":
case "e":
case "é":
case "i":
case "y":
case "o":
case "ó":
case "u":
case "el":
case "la":
case "los":
case "las":
case "un":
case "una":
case "unos":
case "de":
case "del":
return; // don't capitalise articles, "to" as part of an infinitive, prepositions or short conjunctions
default: // capitalise everything else
// capitalise words in parentheses
if (word.substring(0, 1) == '(' ) {
words[i] = word.substring(0, 2).toUpperCase() + word.substring(2, words[i].length);
return;
}
words[i] = word.substring(0, 1).toUpperCase() + word.substring(1, words[i].length);
return;
}
});
// capitalise first word regardless
words[0] = words[0].substring(0, 1).toUpperCase() + words[0].substring(1, words[0].length);
//
// capitalise last word regardless
// var last = words.length-1;
// words[last] = words[last].substring(0, 1).toUpperCase() + words[last].substring(1, words[last].length);
// reconstruct title
return words.join(' ');
};