Number Simplifier

Simplifies reading big numbers.

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Number Simplifier
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Simplifies reading big numbers.
// @author       Paran
// @licence      MIT
// @match        *://*/*
// @grant        none
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// ==/UserScript==
(function() {
    'use strict';

    // Create a context menu item
    document.addEventListener('contextmenu', function(event) {
        let selectedText = window.getSelection().toString().trim();
        if (isValidNumber(selectedText)) {
            let numberInShortForm = convertNumberToShortForm(selectedText);
            showPopup(numberInShortForm, event.pageX, event.pageY);
        }
    });

    // Also handle double-click
    document.addEventListener('dblclick', function(event) {
        let selectedText = window.getSelection().toString().trim();
        if (isValidNumber(selectedText)) {
            let numberInShortForm = convertNumberToShortForm(selectedText);
            showPopup(numberInShortForm, event.pageX, event.pageY);
        }
    });

    function isValidNumber(text) {
        return /^[\d,.\$\£\€\¥\₹]+$/.test(text.replace(/,/g, '').replace(/[\$\£\€\¥\₹]/g, ''));
    }

    function convertNumberToShortForm(num) {
        num = parseFloat(num.replace(/,/g, '').replace(/[\$\£\€\¥\₹]/g, ''));
        if (num >= 1e12) {
            return (num / 1e12).toFixed(1) + 'T';
        } else if (num >= 1e9) {
            return (num / 1e9).toFixed(1) + 'B';
        } else if (num >= 1e6) {
            return (num / 1e6).toFixed(1) + 'M';
        } else if (num >= 1e3) {
            return (num / 1e3).toFixed(1) + 'K';
        } else {
            return num.toString();
        }
    }

    function showPopup(text, x, y) {
        let popup = document.createElement('div');
        popup.style.position = 'absolute';
        popup.style.left = `${x}px`;
        popup.style.top = `${y + 20}px`;
        popup.style.background = '#fff9c4';
        popup.style.border = '1px solid #ffd700';
        popup.style.padding = '10px';
        popup.style.borderRadius = '4px';
        popup.style.boxShadow = '0px 0px 10px rgba(255, 215, 0, 0.5)';
        popup.style.zIndex = '1000';
        popup.style.transform = 'translateX(-50%)';
        popup.innerText = text;

        let arrow = document.createElement('div');
        arrow.style.position = 'absolute';
        arrow.style.left = '50%';
        arrow.style.top = '-10px';
        arrow.style.width = '0';
        arrow.style.height = '0';
        arrow.style.borderLeft = '10px solid transparent';
        arrow.style.borderRight = '10px solid transparent';
        arrow.style.borderBottom = '10px solid #fff9c4';
        arrow.style.transform = 'translateX(-50%)';
        popup.appendChild(arrow);

        document.body.appendChild(popup);

        setTimeout(() => {
            popup.remove();
        }, 1000);
    }
})();