Raw Source
willem.maligmail.com / Getalinstellingen

// ==UserScript==
// @name         Getalinstellingen
// @namespace    https://openuserjs.org/scripts/willem.maligmail.com
// @version      1.0.2
// @description  Transform number formatting on webpages
// @author       Willem Mali
// @match        *://*/*
// //@icon         none
// @grant        none
// @updateURL https://openuserjs.org/meta/willem.maligmail.com/Getalinstellingen.meta.js
// @license MIT
// ==/UserScript==
(function() {
     'use strict';
     var style = document.createElement('style');
     style.type = 'text/css';
     style.innerHTML = '.gtl { } /* <---- CUSTOM NUMERAL CSS STYLING GOES IN THESE BRACKETS! Like: color: #FFFFFF; background-color: #000000;}*/';
     document.getElementsByTagName('head')[0].appendChild(style);
     var yvrit_ltr = function(gtlN,rsulutzi=4){
         //return gtlN;
         if (rsulutzi >= 4) {
              gtlN = gtlN
              .replace(/1000/g, "א")
              .replace(/2000/g, "ב")
              .replace(/3000/g, "ג")
              .replace(/4000/g, "ד")
              .replace(/5000/g, "ה")
              .replace(/6000/g, "ו")
              .replace(/7000/g, "ז")
              .replace(/8000/g, "ח")
              .replace(/9000/g, "ט");
          }
          if (rsulutzi >= 3) {
              gtlN = gtlN
              .replace(/100/g, "ק")
              .replace(/200/g, "ר")
              .replace(/300/g, "ש")
              .replace(/400/g, "ת")
              // not used due to splitter sofistication:
              .replace(/500/g, "תק")
              .replace(/600/g, "תר")
              .replace(/700/g, "תש")
              .replace(/800/g, "תת")
              .replace(/900/g, "תתק");
          }
          if (rsulutzi >= 2) {
              gtlN = gtlN
              .replace(/10/g, "י")
              .replace(/20/g, "כ")
              .replace(/30/g, "ל")
              .replace(/40/g, "מ")
              .replace(/50/g, "נ")
              .replace(/60/g, "ס")
              .replace(/70/g, "ע")
              .replace(/80/g, "פ")
              .replace(/90/g, "צ");
          }
          if (rsulutzi >= 1) {
              gtlN = gtlN
              .replace(/1/g, "א")
              .replace(/2/g, "ב")
              .replace(/3/g, "ג")
              .replace(/4/g, "ד")
              .replace(/5/g, "ה")
              .replace(/6/g, "ו")
              .replace(/7/g, "ז")
              .replace(/8/g, "ח")
              .replace(/9/g, "ט")
              .replace(/0/g, "י")
              ;
          }
         return gtlN
              .replace(/\^/g, "ערבי ");
    }
    var sflt = function(gtl_aN, afstrufa=true,f=yvrit_ltr){
        var nmr = Number(gtl_aN);
        var tkst = "";
        // nmro vuvN da tiN-dijnd vr-aioN niua kuda vur gtlN alo "tiN-dijnd-viF"
        if (nmr > 9999 || nmr < 1 || nmr % 1 > 0) {
           // outside conversion capacities, so "just label it Arabic"
           // (assumption being that it was Arabic in the first place)
           // return f("^"+gtl, 1);
           // alternatively, don't change anything:
           return nmr;
        }
        var mdn_otK = true;
        if(nmr>1000){tkst+=(""+(nmr-(nmr%1000)))+((afstrufa)?"'":""); nmr%=1000;}
        // jrg dt da "
        mdn_otK = false; var mdn_otK_vlgr = nmr;
        while(nmr>=400){tkst+="400";nmr-=400;} // overlaps with yvrit_ltr (Hebrew token formatting function), obviating part of it
        if(nmr>=300){tkst+="300";nmr-=300;}
        if(nmr>=200){tkst+="200";nmr-=200;}
        if(nmr>=100){tkst+="100";nmr-=100;}
        if(nmr>=90) {tkst+="90"; nmr-=90;}
        if(nmr>=80) {tkst+="80"; nmr-=80;}
        if(nmr>=70) {tkst+="70"; nmr-=70;}
        if(nmr>=60) {tkst+="60"; nmr-=60;}
        if(nmr>=50) {tkst+="50"; nmr-=50;}
        if(nmr>=40) {tkst+="40"; nmr-=40;}
        if(nmr>=30) {tkst+="30"; nmr-=30;}
        if(nmr>=20) {tkst+="20"; nmr-=20;}
        if (mdn_otK_vlgr != nmr) mdn_otK = true;
        if(nmr>=10){if(nmr!=15&&nmr!=16){tkst+="10";nmr-=10;}else{tkst+="9";nmr-=9;}}
        if(nmr>0){tkst+=((mdn_otK&&afstrufa&&tkst.length>0)?"\"":"")+String(nmr);console.log(nmr);nmr=0;}
        return f(tkst);
    };
    var gF_ur = sflt;
    var tkst = document.body.innerHTML;
    console.log("gtlN anfoN...");
    tkst = tkst.replace(/>[^<>]+</g, function(match, p1, p2, p3, offset, string){
          return match.replace(/[0-9]+/g, function(match, p1, p2, p3, offset, string){
              var g = gF_ur(match);
               g = "<span dir=\"rtl\" class=\"gtl\">"+g+"</span>";
                return g;
            });
        });
 //   });
    document.body.innerHTML = tkst; // TODO: somehow NOT replace the whole page wholesale?
    console.log("gtlN angfot.");
})();