Last active
June 2, 2017 12:35
-
-
Save matey-jack/b8ec25d9f40d609444ed944746bc4c15 to your computer and use it in GitHub Desktop.
Monthly Payments for Buying a Home on ImmobilienScout24.de
This file contains 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 Monthly Payments for Buying a Home | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description show monthly payments (Hausgeld + mortgage rate) given a sales expose and user-definable down payment | |
// @author [email protected] | |
// @match https://www.immobilienscout24.de/* | |
// @grant none | |
// @require http://code.jquery.com/jquery-latest.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function getPrice(priceString) { | |
return priceString.replace(/ /g, '').replace('.', '').replace('€', ''); | |
} | |
function getPrices(pricesString) { | |
return pricesString.split('-').map(getPrice); | |
} | |
function getRate(price) { | |
// later use .toLocaleString() | |
return (price / 300).toFixed(2).replace('.', ','); | |
} | |
$(document).ready(function() { | |
$('div.result-list-entry__criteria').each(function(i, el) { | |
if (i<2) console.log('entry: ' + i); | |
var price_element = $(el).find('dl.result-list-entry__primary-criterion:eq(0) > dd'); | |
// debugging: price_element.css('background-color', '#f99'); | |
var prices = getPrices(price_element.text()); | |
var monthly_rates = prices.map(getRate).join(' - '); | |
var html = '<dl class="grid-item result-list-entry__primary-criterion ">' + | |
'<dd class="font-nowrap font-line-xs">' + monthly_rates + ' €</dd>' + | |
'<dt class="font-s onlyLarge">mtl. Rate</dt>' + | |
'</dl>'; | |
var element_last = $(el).find('dl.result-list-entry__primary-criterion:eq(2)'); | |
$(html).insertAfter(element_last); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment