// ==UserScript==
// @name anobagual
// @namespace yadaa
// @description Conta quantas espécies de aves da lista do usuário tiveram seu registro em determinado local
// @include http://www.wikiaves.com/especies.php?*&o=3&ef=
// @include http://www.wikiaves.com.br/especies.php?*&o=3&ef=
// @version 1.2
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @require https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012
// @grant GM_addStyle
// @downloadURL none
// ==/UserScript==
var extrato,seletor,seletorb,seletorc,quiqui,queque,tt,pen,tem,extcid,cc,dd,temest;
var barrawidth=0;
var pe = "&p=";
var emno = " com registros fotográficos em ";
if(!('contains' in String.prototype)){String.prototype.contains = function(str, startIndex){return -1 !== String.prototype.indexOf.call(this, str, startIndex);};}
function comeca() {
var lugar = '.ttPage';
$(lugar).append($('\
\
'));
$("#botaum").click (analisa);
}
function analisa() {
//TODO: mudar pagina antes da analize para &o=3
var lugarbarra = '.ttPage > form:nth-child(1) > fieldset:nth-child(1)';
$(lugarbarra).append($('\
\
\
'));
var tabela = document.getElementsByClassName('especies') [0];
var local = document.getElementById("selLocal");
var localb = "/"+local.options[local.selectedIndex].text;
var localc = "/RS";
document.getElementById("selLocal").disabled = true;
document.getElementById("botaum").disabled = true;
$(".textpadding > div:nth-child(6) > b:nth-child(1) > a:nth-child(1)").text("");
$(".textpadding > div:nth-child(6) > b:nth-child(2) > a:nth-child(1)").text("");
$(".textpadding > div:nth-child(6) > b:nth-child(3) > a:nth-child(1)").text("");
$(".titulo > td:nth-child(1) > a:nth-child(1)").removeAttr("href");
$(".titulo > td:nth-child(2) > a:nth-child(1)").removeAttr("href");
$(".titulo > td:nth-child(3) > a:nth-child(1)").removeAttr("href");
$(".titulo > td:nth-child(4) > a:nth-child(1)").removeAttr("href");
$(".titulo > td:nth-child(5) > a:nth-child(1)").removeAttr("href");
//emno=" ";
extcid = conecta("especies.php?&t=e&e=20");
for (var i = 2, row; i<=tabela.rows.length; i++) {
row = tabela.rows[i];
pen = Math.ceil(parseFloat($("tr.especie:nth-child("+i+") > td:nth-child(5) > a:nth-child(1)").text())/10);
seletorc = 'tr.especie:nth-child(' + i + ') > td:nth-child(3) > a:nth-child(1)';
quuquu = $(seletorc).text();
if (!extcid.contains(quuquu)){
var cuia = 'tr.especie:nth-child(' + i + ')';
$(cuia).hide();
}
else{
seletor = 'tr.especie:nth-child(' + i + ') > td:nth-child(5) > a:nth-child(1)';
seletorb = 'tr.especie:nth-child(' + i + ') > td:nth-child(4) > a:nth-child(1)';
quiqui = $(seletor).attr('href'); //registros foto
queque = $(seletorb).attr('href'); //registros sons
if (quiqui === undefined) { //SOH SOM
var cuia = 'tr.especie:nth-child(' + i + ')';
$(cuia).hide();
}
else { // imagem E som ou soh imagem
for (var k=1;k<=pen;k++){
cc=(conecta(quiqui+pe+k));
cc=cc.replace("./2018","YADA");
cc=cc.replace("2018/2018","YADA");
if (localb==="fora do Estado"){
for (var g=0;g b:nth-child(2)").text(contar(tabela));
$(".total").append(emno + localb.substring(1)+" no RS.");
$(".total").get(0).scrollIntoView();
elem.style.width = "100%";
document.getElementById("label").innerHTML = "100%";
console.log(converte(localb));
postarGoogle();
}
function contar(atabela) {
tt = 0;
for (var i = 1, row; i<=atabela.rows.length; i++) {
row = atabela.rows[i];
var cuia = 'tr.especie:nth-child(' + i + ')';
if ($(cuia).is(':visible')){
tt++; //$(cuia).css("background-color","red");
}
}
return (tt);
}
function conecta(x){
var xhr;
xhr = new XMLHttpRequest();
xhr.open('GET', x, false);
xhr.send();
extrato = xhr.response;
return (extrato);
}
function converte(cidade){ //cidade
valorcidade = cidade;
return valorcidade;
}
function postarGoogle(){
var usuarionome = $(".textpadding > a:nth-child(4)").text();
var lifers = $(".total > b:nth-child(2)").text();
var data = new Date(Date.now()).toLocaleString();
$.ajax({
url: "https://docs.google.com/forms/d/e/1FAIpQLSc_pL1htbmjGjQxP95zhMzsavJOdJBIwWwvX82DA5Vv3Lt88w/formResponse",
data: { "entry.101800956" : usuarionome, "entry.1450640523" : lifers, "entry.412480081" : data },
type: "POST",
dataType: "xml",
statusCode: {
0: function (){
usuarionome;
lifers;
data;
},
200: function (){
usuarionome;
lifers;
data;
}
}
});
}
waitForKeyElements('.ttPage', comeca);