ciencuadras.com price per square meter

Show the price per square meter in the search results of ciencuadras.com

Από την 02/12/2019. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         ciencuadras.com price per square meter
// @namespace    https://github.com/healarconr
// @version      0.1
// @description  Show the price per square meter in the search results of ciencuadras.com
// @author       Hernán Alarcón
// @match        https://www.ciencuadras.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    function calculatePricePerSquareMeter() {
        calculatePricePerSquareMeterInSearchResults();
    }
    function calculatePricePerSquareMeterInSearchResults() {
        const properties = document.querySelectorAll('.inmuebles-results > app-card');
        for (const property of properties) {
            try {
                let pricePerSquareMeterElement = property.querySelector('p.pricePerSquareMeter');
                if (pricePerSquareMeterElement) {
                    pricePerSquareMeterElement.remove();
                }
                const priceNode = property.querySelector('h3');
                const price = findPrice(priceNode.textContent);
                const area = findArea(property.querySelector('li:nth-child(3)').textContent)
                const pricePerSquareMeter = (price / area).toLocaleString('es-CO', {style:'currency', currency: 'COP'}) + '/m\u00B2';
                pricePerSquareMeterElement = document.createElement('p');
                pricePerSquareMeterElement.className = 'pricePerSquareMeter';
                pricePerSquareMeterElement.style.fontSize = 'smaller';
                pricePerSquareMeterElement.style.fontWeight = 'normal';
                pricePerSquareMeterElement.appendChild(document.createTextNode(pricePerSquareMeter));
                priceNode.parentNode.insertBefore(pricePerSquareMeterElement, priceNode.nextSibling);
            } catch (e) {
                // Do nothing
            }
        }
    }
    function findPrice(value) {
        return parseFloat(value.match(/[\d.,]+/)[0].replace(/\./g, ''));
    }
    function findArea(value) {
        return parseFloat(value.match(/[\d.]+/)[0]);
    }
    const propertiesContainer = document.querySelector('.inmuebles-results');
    if (propertiesContainer) {
        setInterval(calculatePricePerSquareMeterInSearchResults, 1000);
        new MutationObserver(calculatePricePerSquareMeter).observe(propertiesContainer, {childList: true});
    }
    calculatePricePerSquareMeter();
    setTimeout(calculatePricePerSquareMeter, 2000);
})();