92 lines
4.3 KiB
JavaScript
92 lines
4.3 KiB
JavaScript
/* money-trace · merchant logos via Brandfetch CDN.
|
|
High-precision alias map (description regex -> brand domain). We only show a
|
|
logo when a description confidently maps to a known brand; everything else
|
|
falls back to a coloured initial. No guessing of arbitrary websites. */
|
|
(function(){
|
|
'use strict';
|
|
const CLIENT_ID = '1idZRzFTMDBLO5z-dbd';
|
|
// [regex on UPPERCASED description, brand name, domain]
|
|
const ALIAS = [
|
|
[/UBER\s*EATS|UBR.*EATS|PS UBER EATS/, 'Uber Eats','ubereats.com'],
|
|
[/\bUBER\b|\bUBR\b/, 'Uber','uber.com'],
|
|
[/RAPPI/, 'Rappi','rappi.com'],
|
|
[/MERCADO ?PAGO|MERPAGO|\bMP\b/, 'Mercado Pago','mercadopago.cl'],
|
|
[/APPLE/, 'Apple','apple.com'],
|
|
[/NETFLIX/, 'Netflix','netflix.com'],
|
|
[/SPOTIFY/, 'Spotify','spotify.com'],
|
|
[/\bTEMU\b/, 'Temu','temu.com'],
|
|
[/ALIEXPRESS/, 'AliExpress','aliexpress.com'],
|
|
[/\bAMAZON\b/, 'Amazon','amazon.com'],
|
|
[/\bSHEIN\b/, 'Shein','shein.com'],
|
|
[/CABIFY/, 'Cabify','cabify.com'],
|
|
[/\bDIDI\b/, 'DiDi','didiglobal.com'],
|
|
[/PAYPAL/, 'PayPal','paypal.com'],
|
|
[/PAYSEND/, 'Paysend','paysend.com'],
|
|
[/\bMC ?DONALD/, 'McDonalds','mcdonalds.com'],
|
|
[/\bKFC\b/, 'KFC','kfc.com'],
|
|
[/STA ISABEL|SANTA ISABEL/, 'Santa Isabel','santaisabel.cl'],
|
|
[/\bJUMBO\b/, 'Jumbo','jumbo.cl'],
|
|
[/HIP ?LIDER|\bLIDER\b/, 'Lider','lider.cl'],
|
|
[/TOTTUS/, 'Tottus','tottus.cl'],
|
|
[/UNIMARC/, 'Unimarc','unimarc.cl'],
|
|
[/\bCOPEC\b/, 'Copec','copec.cl'],
|
|
[/\bSHELL\b/, 'Shell','shell.com'],
|
|
[/FALABELLA/, 'Falabella','falabella.com'],
|
|
[/RIPLEY/, 'Ripley','ripley.cl'],
|
|
[/SODIMAC/, 'Sodimac','sodimac.cl'],
|
|
[/\bPARIS\b/, 'Paris','paris.cl'],
|
|
[/\bENTEL\b/, 'Entel','entel.cl'],
|
|
[/\bWOM\b/, 'WOM','wom.cl'],
|
|
[/MOVISTAR/, 'Movistar','movistar.cl'],
|
|
[/\bCLARO\b/, 'Claro','claro.cl'],
|
|
[/TURBUS|TUR BUS/, 'Turbus','turbus.cl'],
|
|
[/CRUZ VERDE/, 'Cruz Verde','cruzverde.cl'],
|
|
[/SALCOBRAND/, 'Salcobrand','salcobrand.cl'],
|
|
[/AHUMADA/, 'Farmacias Ahumada','farmaciasahumada.cl'],
|
|
[/INTEGRAMEDICA/, 'IntegraMedica','integramedica.cl'],
|
|
[/\bGOOGLE\b/, 'Google','google.com'],
|
|
[/MICROSOFT/, 'Microsoft','microsoft.com'],
|
|
[/\bOPENAI\b/, 'OpenAI','openai.com'],
|
|
[/ANTHROPIC/, 'Anthropic','anthropic.com'],
|
|
[/HETZNER/, 'Hetzner','hetzner.com'],
|
|
[/SITEGROUND/, 'SiteGround','siteground.com'],
|
|
[/ADIDAS/, 'adidas','adidas.com'],
|
|
[/NEW BALANCE/, 'New Balance','newbalance.com'],
|
|
[/\bENEL\b/, 'Enel','enel.cl'],
|
|
[/SERVIPAG/, 'Servipag','servipag.com'],
|
|
[/SENCILLITO/, 'Sencillito','sencillito.com'],
|
|
[/\bSKY\b/, 'Sky Airline','skyairline.com'],
|
|
[/LATAM/, 'LATAM','latamairlines.com'],
|
|
];
|
|
const PALETTE = ['#5b8def','#e0729a','#6fb86f','#d9a14b','#9b7fd4','#54b3c4','#cf7d56','#7d8aa0'];
|
|
const COLORS = new Map();
|
|
function colorOf(key){
|
|
if(COLORS.has(key)) return COLORS.get(key);
|
|
let h=0; for(let i=0;i<key.length;i++) h=(h*31+key.charCodeAt(i))>>>0;
|
|
const c=PALETTE[h%PALETTE.length]; COLORS.set(key,c); return c;
|
|
}
|
|
const esc = s => String(s||'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
|
function brandOf(desc){
|
|
const s=(desc||'').toUpperCase();
|
|
for(const [re,name,domain] of ALIAS) if(re.test(s)) return {name,domain};
|
|
return null;
|
|
}
|
|
function initialOf(desc){
|
|
const m=(desc||'').replace(/^(PS|PAGO:?|MERPAGO|PAYU|MP|DL|CV|COMPRA|PREPAGO)\b[\s\*:—-]*/i,'').trim();
|
|
const ch=(m||desc||'?').replace(/[^A-Za-z0-9]/g,'').charAt(0).toUpperCase();
|
|
return ch||'?';
|
|
}
|
|
// returns an HTML string: a brand logo <img> with initial fallback, or just the initial chip
|
|
function html(desc, size){
|
|
size = size||22;
|
|
const b = brandOf(desc);
|
|
const key = b ? b.domain : (desc||'');
|
|
const init = b ? b.name.charAt(0).toUpperCase() : initialOf(desc);
|
|
const fb = '<span class="mlogo mlogo-fb" style="width:'+size+'px;height:'+size+'px;background:'+colorOf(key)+'">'+esc(init)+'</span>';
|
|
if(!b) return fb;
|
|
const url='https://cdn.brandfetch.io/'+b.domain+'/w/'+(size*2)+'/h/'+(size*2)+'?c='+CLIENT_ID;
|
|
return '<img class="mlogo" src="'+url+'" width="'+size+'" height="'+size+'" loading="lazy" alt="'+esc(b.name)+'" title="'+esc(b.name)+'" data-fb="'+esc(fb)+'" onerror="this.outerHTML=this.getAttribute("data-fb")">';
|
|
}
|
|
window.MTlogo = { html, brandOf };
|
|
})();
|