Skip to content

Instantly share code, notes, and snippets.

@matey-jack
Last active June 2, 2017 12:35
Show Gist options
  • Save matey-jack/b8ec25d9f40d609444ed944746bc4c15 to your computer and use it in GitHub Desktop.
Save matey-jack/b8ec25d9f40d609444ed944746bc4c15 to your computer and use it in GitHub Desktop.
Monthly Payments for Buying a Home on ImmobilienScout24.de
// ==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