dowellkin / Schedule1-calculator profit

// ==UserScript==
// @name         Schedule1-calculator profit
// @namespace    http://tampermonkey.net/
// @version      2025-04-03
// @description  try to take over the world!
// @author       You
// @match        https://schedule1-calculator.com/all_seeds
// @icon         https://www.google.com/s2/favicons?sz=64&domain=schedule1-calculator.com
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    document.addEventListener("DOMContentLoaded", () => {
        const container = document.querySelector('#seedsContainer');

        const config = { attributes: true, childList: true, subtree: true };

        // Callback function to execute when mutations are observed
        const callback = (mutationList, observer) => {
            for (const mutation of mutationList) {
                if (mutation.type === "childList") {
                    const nodes = Array.from(mutation.addedNodes).filter(node => node.tagName == 'DIV')

                    nodes.forEach(node => {
                        const textNode = node.querySelector('.card-text');
                        const text = textNode.innerText;
                        const costMatched = text.match(/Cost: \$(\d*\.*\d)/im);
                        const sellMatched = text.match(/Sell: \$(\d*\.*\d)/im);

                        const cost = parseFloat(costMatched[1]);
                        const sell = parseFloat(sellMatched[1]);
                        const profit = sell - cost;

                        textNode.append(document.createElement('br'));
                        const strong = document.createElement('strong');
                        strong.innerText = 'Profit: ';

                        textNode.append(strong);
                        textNode.append("$" + profit.toFixed(2));
                    });
                }
            }
        };

        // Create an observer instance linked to the callback function
        const observer = new MutationObserver(callback);

        // Start observing the target node for configured mutations
        observer.observe(container, config);
    });

    // Your code here...
})();