Skip to content

Instantly share code, notes, and snippets.

@stackcoder
Last active April 23, 2021 08:31
Show Gist options
  • Save stackcoder/c3ded8d225447094c0162d5a0245850d to your computer and use it in GitHub Desktop.
Save stackcoder/c3ded8d225447094c0162d5a0245850d to your computer and use it in GitHub Desktop.
Show flat prices on eBay Kleinanzeigen as price per square meter
// ==UserScript==
// @name Price Per Square Meter
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Display price per square meter
// @author You
// @match https://www.ebay-kleinanzeigen.de/s-wohnung-kaufen/*
// @match https://www.ebay-kleinanzeigen.de/s-auf-zeit-wg/*
// @match https://www.ebay-kleinanzeigen.de/s-immobilien/*
// @match https://www.ebay-kleinanzeigen.de/s-wohnung-mieten/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const $resList = document.querySelectorAll(".aditem");
for (let $resEntry of $resList) {
const $tags = $resEntry.querySelectorAll(".tag-small");
const $area = $tags ? Array.from($tags).find(tag => tag.textContent.includes("m²")) : null;
const $price = $resEntry.querySelector(".aditem-main--middle--price");
if ($area == null || $price == null) {
continue;
}
const price = $price.textContent.trim().replace(" €", "").replace(".", "");
const area = $area.textContent.trim().replace(" m²", "").replace(".", "").replace(",", ".");
const result = parseFloat(price) / parseFloat(area);
const $patch = document.createElement("span");
$patch.style = "color: red; margin-left: 1em;";
$patch.textContent = `${result.toFixed(0)} €/m²`;
$price.appendChild($patch);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment