Usuário:Cósmico/vector.js
Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5.
var numforms = 0;
var wikEdAutoUpdateUrl;
function refbuttons() {
if (mwCustomEditButtons && document.getElementById('toolbar') && wikEdAutoUrl === null) {
button = document.createElement('a');
button.href = URL;
button.title = "Inserir referência";
buttonimage = document.createElement('img');
buttonimage.src = "http://up.wiki.x.io/wikipedia/commons/e/ea/Button_easy_cite.png";
buttonimage.alt = "Inserir referência";
button.appendChild(buttonimage);
document.getElementById('toolbar').appendChild(button);
if (navigator.userAgent.indexOf('MSIE') == -1) {
citemain = document.createElement('div');
citemain.style.display = 'none';
citemain.setAttribute('Id', 'citeselect');
citemain.appendChild( addOption("citeWeb()", "Web") );
citemain.appendChild( addOption("citeNews()", "Notícia") );
citemain.appendChild( addOption("citeBook()", "Livro") );
citemain.appendChild( addOption("citeJournal()", "Jornal") );
citemain.appendChild( addOption("citeNamedRef()", "Múltiplas referências") );
citemain.appendChild( addOption("dispErrors()", "Verificar erros") );
citemain.appendChild( addOption("hideInitial()", "Cancelar") );
document.getElementById('wpTextbox1').parentNode.insertBefore(citemain, document.getElementById('wpTextbox1'));
}
else {
selection = '<div id="citeselect" style="display:none"><input type="button" value="Web" onclick="citeWeb()" />'+
'<input type="button" value="Notícia" onclick="citeNews()" />'+
'<input type="button" value="Livro" onclick="citeBook()" />'+
'<input type="button" value="Jornal" onclick="citeJournal()" />'+
'<input type="button" value="Múltiplas referêrncias" onclick="citeNamedRef()" />'+
'<input type="button" value="Verificar erros" onclick="dispErrors()" />'+
'<input type="button" value="Cancelar" onclick="hideInitial()" /></div>';
document.getElementById('editform').innerHTML = selection + document.getElementById('editform').innerHTML;
}
}
}
function addOption(script, text) {
option = document.createElement('input');
option.setAttribute('type', 'button');
option.setAttribute('onclick', script);
option.setAttribute("value", text);
return option;
}
function hideInitial() {
document.getElementById('citeselect').style.display = 'none';
oldFormHide();
}
function oldFormHide() {
if (numforms !== 0) {
document.getElementById('citediv'+numforms).style.display = 'none';
}
if (document.getElementById('errorform') !== null) {
document.getElementById('citeselect').removeChild(document.getElementById('errorform'));
}
}
function easyCiteMain() {
document.getElementById('citeselect').style.display = '';
}
function getTime() {
var time = new Date();
var nowdate = time.getUTCDate();
if (nowdate<10) { nowdate = "0"+ nowdate.toString(); }
var nowmonth = time.getUTCMonth()+1;
if (nowmonth<10) { nowmonth = "0"+ nowmonth.toString(); }
var nowyear = time.getUTCFullYear();
newtime = nowdate + '/' + nowmonth + '/' + nowyear;
return (newtime);
}
function citeWeb() {
citeNewsWeb("citar web");
}
function citeNews() {
citeNewsWeb("citar notícia");
}
function citeNewsWeb(templatename) {
oldFormHide();
template = templatename;
var legend;
if (template == "citar web") {
legend = "Citar fonte da web";
} else {
legend = "Citar fonte de notícia";
}
newtime = getTime();
numforms++;
form = '<div id="citediv'+numforms+'">'+
'<fieldset><legend>'+legend+'</legend>'+
'<table cellspacing="5">'+
'<input type="hidden" value="'+template+'" id="template">'+
'<tr><td width="120"><label for="url"> URL: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="url"></td>'+
'<td width="120"><label for="titulo"> Título: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="titulo"></td></tr>'+
'<tr><td width="120"><label for="arquivourl"> Arquivo: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="arquivourl"></td>'+
'<td width="120"><label for="arquivodata"> Data de arquivamento: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="arquivodata"></td></tr>'+
'<tr><td width="120"><label for="ultimo"> Último nome: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="ultimo"></td>'+
'<td width="120"><label for="primeiro"> Primeiro nome: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="primeiro"></td></tr>'+
'<tr><td width="120"><label for="coautores"> Co-autores: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="coautores"></td>'+
'<td width="120"><label for="data"> Data da publicação: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="data"></td></tr>'+
'<tr><td width="120"><label for="obra"> Obra: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="obra"></td>'+
'<td width="120"><label for="publicado"> Editora: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="publicado"></td></tr>'+
'<tr><td width="120"><label for="formato"> Formato: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="formato"></td>'+
'<td width="120"><label for="lingua"> Idioma: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="lingua"></td></tr>'+
'<tr><td width="120"><label for="acessodata"> Data de acesso: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="acessodata" value="'+ newtime +'"></td>'+
'<td width="120"><label for="refname"> Nome da referência: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="refname"></td></tr>'+
'</table>'+
'<input type="button" value="Adicionar fonte" onClick="addcites()">'+
'</fieldset></div>';
document.getElementById('citeselect').innerHTML += form;
}
function citeBook() {
oldFormHide();
template = "Ref-livro";
numforms++;
form = '<div id="citediv'+numforms+'">'+
'<fieldset><legend>Citar fonte de livro</legend>'+
'<table cellspacing="5">'+
'<input type="hidden" value="'+template+'" id="template">'+
'<tr><td width="120"><label for="sobrenome"> Sobrenome: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="sobrenome"></td>'+
'<td width="120"><label for="nome"> Nome: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="nome"></td></tr>'+
'<tr><td width="120"><label for="coautores"> Co-autores: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="coautores"></td>'+
'<td width="120"><label for="outros"> Outros: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="outros"></td></tr>'+
'<tr><td width="120"><label for="título"> Título: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="título"></td>'+
'<td width="120"><label for="editor"> Editora: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="editor"></td></tr>'+
'<tr><td width="120"><label for="edição"> Edição: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="edição"></td>'+
'<td width="120"><label for="local"> Local: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="local"></td></tr>'+
'<tr><td width="120"><label for="publicação"> Data da publicação: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="publicação"></td>'+
'<td width="120"><label for="páginas"> Página(s): </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="páginas"></td></tr>'+
'<tr><td width="120"><label for="capítulo"> Capítulo: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="capítulo"></td>'+
'<td width="120"><label for="URLcapítulo"> URL do capítulo: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="URLcapítulo"></td></tr>'+
'<tr><td width="120"><label for="URL"> URL: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="URL"></td>'+
'<td width="120"><label for="acessodata"> Data de acesso: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="acessodata"></td></tr>'+
'<tr><td width="120"><label for="id"> ISBN: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="id"></td>'+
'<td width="120"><label for="cita"> Cita: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="cita"></td></tr>'+
'<tr><td width="120"><label for="linkautor"> Link da autor: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="linkautor"></td>'+
'<td width="120"><label for="accessdate"> Data de acesso: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="accessdate"></td></tr>'+
'<td width="120"><label for="refname"> Nome da referência: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="refname"></td></tr>'+
'</table>'+
'<input type="button" value="Adicionar fonte" onClick="addcites()">'+
'</fieldset></div>';
document.getElementById('citeselect').innerHTML += form;
}
function citeJournal() {
oldFormHide();
template = "Citar jornal";
numforms++;
form = '<div id="citediv'+numforms+'">'+
'<fieldset><legend>Citar fonte de jornal</legend>'+
'<table cellspacing="5">'+
'<input type="hidden" value="'+template+'" id="template">'+
'<tr><td width="120"><label for="ultimo"> Último nome: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="ultimo"></td>'+
'<td width="120"><label for="primeiro"> Primeiro nome: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="primeiro"></td></tr>'+
'<tr><td width="120"><label for="coautores"> Co-autores: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="coautores"></td>'+
'<td width="120"><label for="data"> Data da publicação: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="data"></td></tr>'+
'<tr><td width="120"><label for="titulo"> Título: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="titulo"></td>'+
'<td width="120"><label for="jornal"> Jornal: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="jornal"></td></tr>'+
'<tr><td width="120"><label for="editora"> Editora: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="editora"></td>'+
'<td width="120"><label for="local"> Local: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="local"></td></tr>'+
'<tr><td width="120"><label for="volume"> Volume: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="volume"></td>'+
'<td width="120"><label for="formato"> Formato: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="formato"></td></tr>'+
'<tr><td width="120"><label for="paginas"> Páginas: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="paginas"></td>'+
'<td width="120"><label for="issn"> ISSN: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="issn"></td></tr>'+
'<tr><td width="120"><label for="oclc"> OCLC: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="oclc"></td>'+
'<td width="120"><label for="idioma"> Idioma: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="idioma"></td></tr>'+
'<tr><td width="120"><label for="url"> URL: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="url"></td>'+
'<td width="120"><label for="accessadoem"> Data de acesso: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="accessadoem"></td></tr>'+
'<tr><td width="120"><label for="refname"> Nome da referência: </label></td>'+
'<td width="400"><input type="text" style="width:100%" id="refname"></td></tr>'+
'</table>'+
'<input type="button" value="Adicionar fonte" onClick="addcites()">'+
'</fieldset></div>';
document.getElementById('citeselect').innerHTML += form;
}
function addcites(template) {
cites = document.getElementById('citediv'+numforms).getElementsByTagName('input');
var citebegin = '<ref';
var citename = '';
var citeinner = '';
for (var i=0; i<cites.length-1; i++) {
if (cites[i].value !== '' && cites[i].id !== "refname" && cites[i].id !== "template") {
citeinner += "|" + cites[i].id + "=" + cites[i].value;
}
else if (cites[i].value !== '' && cites[i].id == "refname" && cites[i].id !== "template") {
citebegin += ' name="' + cites[i].value + '"';
}
else if (cites[i].value !== '' && cites[i].id !== "refname" && cites[i].id == "template") {
citename = '>{{' + cites[i].value;
}
}
cite = citebegin + citename + citeinner + "}}</ref>";
insertTags(cite, '', '');
document.getElementById('citediv'+numforms).style.display = 'none';
}
function getNamedRefs(calls) {
text = document.getElementById('wpTextbox1').value;
var regex;
if (calls) {
regex = /< *?ref +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^'"\s]*?[^\/]\b)) *?\/ *?>/gi; //
} else {
regex = /< *?ref +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^'"\s]*?[^\/]\b)) *?>/gi; //
}
var namedrefs = [];
var i=0;
var nr=true;
do {
ref = regex.exec(text);
if(ref !== null){
if (ref[5]) {
namedrefs[i] = ref[5];
} else if (ref[3]) {
namedrefs[i] = ref[3];
} else {
namedrefs[i] = ref[6];
}
i++;
} else {
nr=false;
}
} while (nr===true);
return namedrefs;
}
function citeNamedRef() {
namedrefs = getNamedRefs(false);
if (namedrefs === '') {
oldFormHide();
numforms++;
out = '<div id="citediv'+numforms+'"><fieldset>'+
'<legend>Por favor, selecione uma referência a repetir no texto:</legend>Não há múltiplas referências no texto (<tt><ref name="Nome"></tt>).</fieldset></div>';
document.getElementById('citeselect').innerHTML += out;
}
else {
oldFormHide();
numforms++;
form = '<div id="citediv'+numforms+'">'+
'<fieldset><legend>Referências no artigo</legend>'+
'<table cellspacing="5">'+
'<tr><td><label for="namedrefs"> Nomes das referências no texto</label></td>'+
'<td><select name="namedrefs" id="namedrefs">';
for (var i=0;i<namedrefs.length;i++) {
form+= '<option value="'+namedrefs[i]+'">'+namedrefs[i]+'</option>';
}
form+= '</select>'+
'</td></tr></table>'+
'<input type="button" value="Adicionar fonte" onClick="addnamedcite()">'+
'</fieldset></div>';
document.getElementById('citeselect').innerHTML += form;
}
}
function addnamedcite() {
var name = document.getElementById('citediv'+numforms).getElementsByTagName('select')[0].value;
ref = '<ref name="'+name+'" />';
insertTags(ref, '', '');
document.getElementById('citediv'+numforms).style.display = 'none';
}
function getAllRefs() {
text = document.getElementById('wpTextbox1').value;
regex = /< *?ref( +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^'"\s]*?[^\/]\b)))? *?>((.|\n)*?)< *?\/? *?ref *?>/gim; //"
var allrefs = [];
var i=0;
var nr=true;
do {
ref = regex.exec(text);
if(ref !== null){
if (ref[0].search(/[^\s]{150}/) != -1) {
ref[0] = ref[0].replace(/\|([^\s])/g, "| $1");
}
ref[0] = ref[0].replace(/</g, "<");
ref[0] = ref[0].replace(/>/g, ">");
allrefs[i] = ref[0];
i++;
} else {
nr=false;
}
} while (nr===true);
return allrefs;
}
function NRcallError(namedrefs, refname) {
for (var i=0; i<namedrefs.length; i++) {
if (namedrefs[i] == refname) {
return true;
}
}
return false;
}
function errorCheck() {
var allrefs = getAllRefs();
var allrefscontent = [];
var samecontentexclude = [];
var sx=0;
var templateexclude = [];
var tx=0;
var skipcheck = false;
var namedrefcalls = getNamedRefs(true);
for (var i=0; i<allrefs.length; i++) {
allrefscontent[i] = allrefs[i].replace(/< *?ref( +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^'"\s]*?[^\/]\b)))? *?>((.|\n)*?)< *?\/? *?ref *?>/gim, "$8"); //"
}
var namedrefs = getNamedRefs(false);
var errorlist = [];
var q=0;
unclosed = document.getElementById('unclosed').checked;
samecontent = document.getElementById('samecontent').checked;
templates = document.getElementById('templates').checked;
repeated = document.getElementById('repeated').checked;
undef = document.getElementById('undef').checked;
for (; i<allrefs.length; i++) {
if (allrefs[i].search(/< *?\/ *?ref *?>/) == -1 && unclosed) {
errorlist[q] = '<tr><td width="75%"><tt>'+allrefs[i]+'</tt></td>';
errorlist[q] += '<td width="25%">Unclosed <tt><ref></tt> tag</td></tr>';
q++;
}
if (samecontent) {
for (var d=0; d<samecontentexclude.length; d++) {
if (allrefscontent[i] == samecontentexclude[d]) {
skipcheck = true;
}
}
var p=0;
while (p<allrefs.length && !skipcheck) {
if (allrefscontent[i] == allrefscontent[p] && i != p) {
errorlist[q] = '<tr><td width="75%"><tt>'+allrefscontent[i]+'</tt></td>';
errorlist[q] += '<td width="25%">Múltiplas referências deste conteúdo <a href="http://pt.wiki.x.io/wiki/Wikipedia:Livro de estilo/Notas de rodapé">devem ser usadas uma vez</a></td></tr>';
q++;
samecontentexclude[sx] = allrefscontent[i];
sx++;
break;
}
p++;
}
skipcheck=false;
}
if (allrefscontent[i].search(/\{\{cite/i) == -1 && allrefscontent[i].search(/\{\{citation/i) == -1 && allrefscontent[i].search(/\{\{Comic (book|strip) reference/i) == -1 && allrefscontent[i].search(/\{\{Editorial cartoon reference/i) == -1 && allrefscontent[i].search(/\{\{harv/i) == -1 && templates) {
for (var x=0; x<templateexclude.length; x++) {
if (allrefscontent[i] == templateexclude[x]) {
skipcheck = true;
}
}
if (!skipcheck) {
errorlist[q] = '<tr><td width="75%"><tt>'+allrefs[i]+'</tt></td>';
errorlist[q] += '<td width="25%">Não usa uma <a href="http://pt.wiki.x.io/wiki/Categoria:!Predefinições para referências">predefinição de referência</a></td></tr>';
q++;
templateexclude[tx] = allrefscontent[i];
tx++;
}
skipcheck = false;
}
}
if (repeated) {
var repeatnameexclude = [];
var rx=0;
for (var k=0; k<namedrefs.length; k++) {
for (var d=0; d<repeatnameexclude.length; d++) {
if (namedrefs[k] == repeatnameexclude[d]) {
skipcheck = true;
}
}
var z=0;
while (z<namedrefs.length && !skipcheck) {
if (namedrefs[k] == namedrefs[z] && k != z) {
errorlist[q] = '<tr><td width="75%"><tt>'+namedrefs[k]+'</tt></td>';
errorlist[q] += '<td width="25%">Múltiplas referências são dados os mesmos <a href="http://pt.wiki.x.io/wiki/Wikipedia:Livro de estilo/Notas de rodapé">nome</a></td></tr>';
q++;
repeatnameexclude[rx] = namedrefs[z];
rx++;
break;
}
z++;
}
skipcheck = false;
}
}
if (undef) {
var undefexclude = [];
var ux=0;
for (var p=0; p<namedrefcalls.length; p++) {
for (var d=0; d<undefexclude.length; d++) {
if (allrefscontent[i] == undefexclude[d]) {
skipcheck = true;
}
}
if (!skipcheck) {
if (!NRcallError(namedrefs, namedrefcalls[p])) {
errorlist[q] = '<tr><td width="75%"><tt>'+namedrefcalls[p]+'</tt></td>';
errorlist[q] += '<td width="25%">Uma <a href="http://pt.wiki.x.io/wiki/Wikipedia:Livro_de_estilo/Notas de rodapé#Múltiplas utilizações da mesma nota de rodapé">Referência repetida</a> é usada mas não definida</td></tr>';
q++;
undefexclude[ux] = namedrefs[p];
ux++;
}
}
skipcheck = false;
}
}
if (q > 0) {
return errorlist;
} else {
return 0;
}
}
function dispErrors() {
oldFormHide();
form = '<div id="errorform"><fieldset>'+
'<legend>Verificar erros</legend>'+
'<b>Procurar por:</b><br/>'+
'<input type="checkbox" id="unclosed" /> Tags de referências abertas <tt>(<ref>)</tt>.<br/>'+
'<input type="checkbox" id="samecontent" /> Referências com o mesmo conteúdo.<br/>'+
'<input type="checkbox" id="templates" /> Referências que não usam uma <a href="http://pt.wiki.x.io/wiki/Categoria:!Predefinições para referências">predefinição de referência.</a><br/>'+
'<input type="checkbox" id="repeated" /> Múltiplas referências com o mesmo nome.<br/>'+
'<input type="checkbox" id="undef" /> Uso de referências com nomes indefinidos.<br/>'+
'<input type="button" id="errorchecksubmit" value="Verificar" onclick="doErrorCheck()"/>'+
'</fieldset></div>';
document.getElementById('citeselect').innerHTML += form;
}
function doErrorCheck() {
var errors = errorCheck();
document.getElementById('citeselect').removeChild(document.getElementById('errorform'));
if (errors === 0) {
if (numforms !== 0) {
document.getElementById('citediv'+numforms).style.display = 'none';
}
numforms++;
out = '<div id="citediv'+numforms+'"><fieldset>'+
'<legend>Verificação de erros</legend>Nenhum erro encontrado!</fieldset></div>';
document.getElementById('citeselect').innerHTML += out;
}
else {
if (numforms !== 0) {
document.getElementById('citediv'+numforms).style.display = 'none';
}
numforms++;
form = '<div id="citediv'+numforms+'">'+
'<fieldset><legend>Verificação de erros</legend>'+
'<table border="1px">';
for (var i=0; i<errors.length; i++) {
form+=errors[i];
}
form+= '</table>'+
'</fieldset></div>';
document.getElementById('citeselect').innerHTML += form;
}
}
hookEvent("load", refbuttons);