Last active
April 17, 2017 17:27
-
-
Save eliemichel/1c6f27be406a22a0d5114020c616d3e8 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 seloger.com | |
* 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 seloger.com | |
* | |
* Existe aussi pour pap.fr : | |
* https://gist.github.com/eliemichel/e292bae7b439e15cf7da37ae518f08dc | |
* | |
* MIT Licence -- Copyright (c) 2017, Élie Michel | |
*/ | |
var listings = document.querySelectorAll('.cartouche'); | |
for (var i = 0 ; i < listings.length ; ++i) { | |
var c = listings[i]; | |
var price = parseFloat(c.querySelector('.price').innerText.replace(',', '.').replace(String.fromCharCode(160), '').match(/[\d.]+€/)[0]); | |
var props = c.querySelector('.properties').querySelectorAll('li'); | |
var surf = 0; | |
var chambres = 0; | |
for (var j = 0 ; j < props.length ; ++j) { | |
m = props[j].innerText.replace(',', '.').match(/([\d.]+)\s?m²/); if (null != m) {surf = parseFloat(m[1]); } | |
m = props[j].innerText.replace(',', '.').match(/([\d]+)\s?chb/); if (null != m) {chambres = parseInt(m[1]); } | |
} | |
if (c.querySelector('.ratio') == null) { | |
c.querySelector('.locality').insertAdjacentHTML('afterend', '<div><b class="ratio"></b></div>'); | |
} | |
if (c.querySelector('.ratio-chambres') == null) { | |
c.querySelector('.ratio').parentElement.insertAdjacentHTML('afterend', '<div><b class="ratio-chambres"></b></div>'); | |
} | |
c.querySelector('.ratio').innerText = (Math.round(price/surf*10.0)/10.0) + ' €/m²'; | |
c.querySelector('.ratio-chambres').innerText = (Math.round(price/chambres*10.0)/10.0) + ' €/chb'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment