Last active
April 17, 2017 17:27
-
-
Save eliemichel/e292bae7b439e15cf7da37ae518f08dc to your computer and use it in GitHub Desktop.
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
/** | |
* Extrait de code à exécuter dans la console du navigateur pour ajouter | |
* sous les prix le prix au mètre-carré et le prix par chambre dans les | |
* résultats de logement sur pap.fr | |
* Fonctionne au 17/04/2017, mais puisque le code est très ad-hoc il faudra | |
* sûrement le mettre à jour à chaque màj de pap.fr | |
* | |
* Existe aussi pour seloger.com : | |
* https://gist.github.com/eliemichel/1c6f27be406a22a0d5114020c616d3e8 | |
* | |
* MIT Licence -- Copyright (c) 2017, Élie Michel | |
*/ | |
var listings = document.querySelectorAll('.search-results-item'); | |
for (var i = 0 ; i < listings.length ; ++i) { | |
var c = listings[i]; | |
var price = parseFloat(c.querySelector('.price').innerText.replace('.', '').replace(',', '.').replace(' ', '').match(/[\d.]+\s?€/)[0]); | |
var surf = 0; | |
var chambres = 0; | |
var props = c.querySelectorAll('.item-summary li'); | |
for (var j = 0 ; j < props.length ; ++j) { | |
m = props[j].innerText.replace(',', '.').replace('\n', ' ').match(/^Surface.*?([\d.]+)\s?m2/); | |
if (null != m) { surf = parseFloat(m[1]); } | |
m = props[j].innerText.replace(',', '.').replace('\n', ' ').match(/^Chambres.*?([\d]+)/); | |
if (null != m) { chambres = parseInt(m[1]); } | |
} | |
if (c.querySelector('.ratio') == null) { | |
c.querySelector('.item-summary').insertAdjacentHTML('beforeend', '<li>Ratio<strong><span class="ratio"></span> <small>€/m²</small></strong></li>'); | |
} | |
if (c.querySelector('.ratio-chambres') == null) { | |
c.querySelector('.item-summary').insertAdjacentHTML('beforeend', '<li>Par chb<strong><span class="ratio-chambres"></span> <small>€/chb</small></strong></li>'); | |
} | |
c.querySelector('.ratio').innerText = (Math.round(price/surf*10.0)/10.0); | |
c.querySelector('.ratio-chambres').innerText = (Math.round(price/chambres*10.0)/10.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment