Created
May 3, 2022 16:09
-
-
Save rafaelgallani/0326b4995728c0653f7abff1771c45a5 to your computer and use it in GitHub Desktop.
Shows the lowest (allowed) bid for a property
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Show lowest possible bid price | |
| // @version 1 | |
| // @grant none | |
| // @match http://*.quintoandar.com.br/imovel/* | |
| // @match https://*.quintoandar.com.br/imovel/* | |
| // @match http://*.quintoandar.com.br/alugar/imovel/* | |
| // @match https://*.quintoandar.com.br/alugar/imovel/* | |
| // ==/UserScript== | |
| ( () => { | |
| const addLowestPriceToProductPage = () => { | |
| const parseValueInBRL = ( valueInBRL ) => Number( valueInBRL.replace( '.', '' ).replace( 'R$', '' ).trim() ); | |
| const priceElement = document.querySelector( '[data-testid="house-pricebox"] ul>li:last-of-type' ); | |
| const parentElement = priceElement.parentNode; | |
| const priceTextElement = priceElement.querySelector( 'span' ); | |
| const rentTextElement = document.querySelector( '[data-testid="house-pricebox"] ul>li:first-of-type span' ); | |
| const fullPrice = parseValueInBRL( priceTextElement.textContent ); | |
| const rentPrice = parseValueInBRL( rentTextElement.textContent ); | |
| const lowestPossiblePrice = `R$ ${ Math.ceil( ( fullPrice - rentPrice ) + ( rentPrice * 0.7 ) ).toLocaleString('pt-BR') }`; | |
| const priceRegex = /R\$ \d{1,}\.\d{3}/; | |
| const newElementHTML = priceElement.outerHTML | |
| .replace( "Total", "Total - negociado" ) | |
| .replace( priceRegex, lowestPossiblePrice.toLocaleString('pt-BR') ) | |
| .replace( '>', ' style="filter: opacity(0.65);">' ); | |
| parentElement.innerHTML += newElementHTML; | |
| } | |
| const addLowestPriceToSearchPage = () => { | |
| const parseValueInBRL = ( valueInBRL ) => Number( valueInBRL.replace( '.', '' ).replace( 'R$', '' ).trim() ); | |
| const priceRegex = /\d{1,}\.\d{3}/; | |
| const rentElements = document.querySelectorAll( '[data-testid="house-card-rent"]' ); | |
| rentElements.forEach( rentElement => { | |
| const parentElement = rentElement.parentNode; | |
| // Don't want to deal with elements we've already handled before. | |
| if ( parentElement.classList.contains( 'handled' ) ) { | |
| return; | |
| } | |
| let [ rentPrice ] = rentElement.textContent.match( priceRegex ); | |
| const [ priceElement ] = rentElement.nextElementSibling.children; | |
| let [ fullPrice ] = priceElement.textContent.match( priceRegex ); | |
| const priceTextElement = priceElement.querySelector( 'span' ); | |
| const rentTextElement = document.querySelector( '[data-testid="house-pricebox"] ul>li:first-of-type span' ); | |
| fullPrice = parseValueInBRL( fullPrice ); | |
| rentPrice = parseValueInBRL( rentPrice ); | |
| const lowestPossiblePrice = `R$ ${ Math.ceil( ( fullPrice - rentPrice ) + ( rentPrice * 0.7 ) ).toLocaleString('pt-BR') }`; | |
| const newPriceElement = priceElement.parentElement.cloneNode( true ); | |
| const newPriceTextElement = newPriceElement.querySelector( 'strong' ); | |
| newPriceTextElement.textContent = `Neg. ${lowestPossiblePrice}`; | |
| parentElement.insertBefore( newPriceElement, priceElement.parentElement ); | |
| // Adds the class to the parent element so we know it was already handled. | |
| parentElement.classList.add( 'handled' ); | |
| }); | |
| } | |
| if ( window.location.pathname.startsWith('/imovel') ) { | |
| addLowestPriceToProductPage(); | |
| } else { | |
| setInterval( () => { | |
| addLowestPriceToSearchPage(); | |
| }, 3000); | |
| } | |
| } )(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment