Skip to content

Instantly share code, notes, and snippets.

@helton
Last active August 21, 2017 18:53
Show Gist options
  • Save helton/914c6c7d80462fa893d285a260fa5754 to your computer and use it in GitHub Desktop.
Save helton/914c6c7d80462fa893d285a260fa5754 to your computer and use it in GitHub Desktop.
Calcula o total mensal de apartamentos do Zap Imóveis
function reaisStrToInteger(reais) {
return parseInt(reais
.match(/R\$ ([0-9]+(\.[0-9]+)?)$/)[1]
.replace('.', ''));
}
if (window.location.href.match(/https:\/\/www\.zapimoveis\.com\.br\/oferta\/(venda|aluguel)\+apartamento/)) {
const aluguel = reaisStrToInteger(document.querySelector('.value-ficha').innerText.replace(/\n/g, ''));
let iptu = 0;
let condominio = 0;
const itens = document.querySelectorAll('.informacoes-imovel .pull-right li > span.text-info');
itens.forEach(item => {
const tipo = item.innerText.trim();
const valor = reaisStrToInteger(item.previousSibling.data.trim());
if (tipo == 'IPTU') {
iptu = valor;
} else if (tipo.match(/^CONDOM.NIO$/)) {
condominio = valor;
}
});
const total = aluguel + condominio + iptu;
alert(`Total mensal desse apartamento: R$ ${total},00.`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment