Greasy Fork is available in English.

Fineco MyCards: Mostra soltanto le operazioni della carta di credito

Questo script aggiunge un bottone nella pagina "My Cards" di FinecoBank.com che consente di visualizzare la lista (e l'ammontare totale) delle sole operazioni con carta di credito.

Versione datata 21/07/2022. Vedi la nuova versione l'ultima versione.

// ==UserScript==
// @name           Fineco MyCards: Show only the credit card transactions
// @name:it        Fineco MyCards: Mostra soltanto le operazioni della carta di credito
// @description    This script adds a button in the page "My Cards" of FinecoBank.com that allows to show the list (and the total amount) of the only credit card transactions.
// @description:it Questo script aggiunge un bottone nella pagina "My Cards" di FinecoBank.com che consente di visualizzare la lista (e l'ammontare totale) delle sole operazioni con carta di credito.
// @match          https://finecobank.com/conto-e-carte/mycards*
// @require        https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @grant          none
//// @run-at         document-start
// @version        1.0.6
// @author         Cyrano68
// @license        MIT
// @namespace https://greasyfork.org/users/788550
// ==/UserScript==

(function()
{
    "use strict";

    console.log("==> FinecoMyCards_ShowOnlyCC: HELLO! Loading script...");

    var timerId = 0;

    document.addEventListener("DOMContentLoaded", onDOMContentLoaded);
    window.addEventListener("load", onWindowLoaded);

    function onDOMContentLoaded()
    {
        console.log("==> FinecoMyCards_ShowOnlyCC: onDOMContentLoaded");
        // DO NOTHING!
    }

    function onWindowLoaded()
    {
        console.log("==> FinecoMyCards_ShowOnlyCC: onWindowLoaded");
        // Start a timer that periodically checks if all the data (the list of transactions) have been loaded.
        timerId = setInterval(checkDataLoaded, 250);
    }

    function checkDataLoaded()
    {
        if ($("div.movimenti-container").length > 0)
        {
            console.log("==> FinecoMyCards_ShowOnlyCC: checkDataLoaded -> TRUE");
            // All the data have been loaded... stop the timer and add the button that will allow (when clicked) to show only the credit card entries.
            clearInterval(timerId);
            addMyButton();
        }
        else
        {
            console.log("==> FinecoMyCards_ShowOnlyCC: checkDataLoaded -> FALSE");
        }
    }

    function addMyButton()
    {
        console.log("==> FinecoMyCards_ShowOnlyCC: addMyButton");
        // Create a new button that will allow (when clicked) to show only the credit card entries.
        var myButton = $("<button/>", {id: "myButton", text: "SHOW ONLY CREDIT CARD", click: showOnlyCC});
        // The button is placed before the list of transactions.
        $("div.movimenti-container").before(myButton);
    }

    function showOnlyCC()
    {
        // First of all delete the span tag (eventually added in a previous click) that shows the total amount of the credit card transactions.
        var mySpan = $("span#mySpan");
        if (mySpan.length > 0)
        {
            mySpan.remove();
        }

        // Then remove the bancomat entries.
        var bancomat = $("div.text-right > img[src$='Bancomat.svg']");
        console.log("==> FinecoMyCards_ShowOnlyCC: showOnlyCC - bancomat.length=" + bancomat.length);

        // Sometimes there is a problem when the bancomat entries are removed. In details, it happens when in the same day there is a visa entry and a bancomat entry.
        // After the bancomat entry is removed if I try to expand the visa entry (in order to see the details of the transaction) an error is generated.
        // Therefore it is better to hide the bancomat entries.
        var removeEntries = false;

        if (removeEntries)
        {
            // The bancomat entries will be removed.
            bancomat.closest("div.accordionWrapper").remove();

            // Then start a one-shot timer that will remove empty entries from the page.
            setTimeout(removeEmptyDayWrapper, 100);
        }
        else
        {
            // The bancomat entries will be hidden.
            bancomat.closest("div.accordionWrapper").hide();
        }

        // Finally calculate the total amount of the credit card transactions.
        var entriesRemoved = removeEntries
        calculateTotalCC(entriesRemoved);
    }

    function calculateTotalCC(entriesRemoved)
    {
        console.log("==> FinecoMyCards_ShowOnlyCC: calculateTotalCC - entriesRemoved=" + entriesRemoved);
        var cc;
        if (entriesRemoved)
        {
            // The bancomat entries have been removed.
            cc = $("div.text-right.amountDetail > span.detailAmount");
        }
        else
        {
            // The bancomat entries have been hidden.
            cc = $("div.text-right.amountDetail > span.detailAmount:visible");
        }

        var totalCC = 0;
        console.log("==> FinecoMyCards_ShowOnlyCC: calculateTotalCC - cc.length=" + cc.length);
        cc.each(function(index)
        {
            //console.log("==> FinecoMyCards_ShowOnlyCC: calculateTotalCC - index=" + index);
            var amountText =  $(this).text().slice(0,-4);
            var amountText2;

            // Try to understand the type of decimal point (dot or comma) used in the page (it is supposed that there are always two digits after the decimal point).
            if (amountText.slice(-3,-2) == ",")
            {
                // The decimal point is a comma (",")... therefore remove the "thousand" separators (".") and transform the comma decimal point in dot decimal point.
                amountText2 = amountText.replace(/\./g,"").replace(/\,/g,".");
            }
            else
            {
                // The decimal point is a dot (".")... Therefore only remove the "thousand" separators (",").
                amountText2 = amountText.replace(/\,/g,"");
            }

            // Now the variable "amountText2" is a string that contains numbers and at most the dot decimal point... i.e it can be parsed with "parseFloat".
            var amountValue = parseFloat(amountText2);
            totalCC += amountValue;

            if (index == cc.length - 1)
            {
                addMySpan(totalCC);
            }
        });
    }

    function addMySpan(totalCC)
    {
        console.log("==> FinecoMyCards_ShowOnlyCC: addMySpan - totalCC=" + totalCC);
        // Add a span (next to the new button) that shows the total amount of the credit card transactions.
        var totalCCText = " TOTAL: " + Number(Math.abs(totalCC)).toLocaleString() + " €";
        var mySpan = $("<span/>", {id: "mySpan", style: "color:blue;font-weight:bold"}).html(totalCCText);
        $("button#myButton").after(mySpan);
    }

    function removeEmptyDayWrapper()
    {
        var emptyDayWrapper = $("div.monthWrapper > div.dayWrapper:empty");
        console.log("==> FinecoMyCards_ShowOnlyCC: removeEmptyDayWrapper - emptyDayWrapper.length=" + emptyDayWrapper.length);
        emptyDayWrapper.remove();
    }

    console.log("==> FinecoMyCards_ShowOnlyCC: Script loaded");
})();