systeme de themes qui fonctionnouille
All checks were successful
Deploy XIP / deploy (push) Successful in 34s
All checks were successful
Deploy XIP / deploy (push) Successful in 34s
This commit is contained in:
62
frontend/src/composables/useMessageItem.ts
Normal file
62
frontend/src/composables/useMessageItem.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { type GeoInfo } from '@/composables/useMessages';
|
||||
import { getIpColorWithPerks, getIpGlowWithPerks, getIpGlow } from '@/composables/ipColor';
|
||||
import { usePerks } from '@/composables/usePerks';
|
||||
import { useCustomStyles } from '@/composables/useCustomStyles';
|
||||
import { useMyPerks } from '@/composables/useMessages';
|
||||
|
||||
export function useMessageItem() {
|
||||
const { perksFor } = usePerks();
|
||||
const { myPerks } = useMyPerks();
|
||||
const { prefs } = useCustomStyles();
|
||||
|
||||
function perksOf(m: { authorIp: string; authorPerks?: any }) {
|
||||
return m.authorPerks ?? perksFor(m.authorIp);
|
||||
}
|
||||
|
||||
function ipStyle(m: { authorIp: string; authorPerks?: any }) {
|
||||
const ip = m.authorIp;
|
||||
const override = prefs.ipColors[ip];
|
||||
if (override && override !== 'auto') {
|
||||
return { color: override, textShadow: getIpGlow(override) };
|
||||
}
|
||||
const p = perksOf(m);
|
||||
return { color: getIpColorWithPerks(ip, p), textShadow: getIpGlowWithPerks(ip, p) };
|
||||
}
|
||||
|
||||
function petsLeft(m: { authorIp: string; authorPerks?: any }) {
|
||||
const ip = m.authorIp;
|
||||
if (ip in prefs.ipPets) return prefs.ipPets[ip];
|
||||
return (perksOf(m)?.pets ?? [])
|
||||
.filter((x: any) => x.position === 'left' || x.position === 'both')
|
||||
.map((x: any) => x.char).join('');
|
||||
}
|
||||
|
||||
function petsRight(m: { authorIp: string; authorPerks?: any }) {
|
||||
const ip = m.authorIp;
|
||||
if (ip in prefs.ipPets) return '';
|
||||
return (perksOf(m)?.pets ?? [])
|
||||
.filter((x: any) => x.position === 'right' || x.position === 'both')
|
||||
.map((x: any) => x.char).join('');
|
||||
}
|
||||
|
||||
function fmt(date: string) {
|
||||
return new Date(date).toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
|
||||
function geoLabel(geo?: GeoInfo | null): string {
|
||||
if (!geo) return '';
|
||||
if (!geo.countryCode) return 'Local';
|
||||
const place = geo.city || geo.country;
|
||||
if (geo.lat != null && geo.lon != null) {
|
||||
return `${place} · ${geo.lat.toFixed(4)}, ${geo.lon.toFixed(4)}`;
|
||||
}
|
||||
return place;
|
||||
}
|
||||
|
||||
function geoLink(geo?: GeoInfo | null): string {
|
||||
if (!geo || geo.lat == null || geo.lon == null) return 'https://maps.google.com';
|
||||
return `https://www.google.com/maps/search/?api=1&query=${geo.lat},${geo.lon}`;
|
||||
}
|
||||
|
||||
return { perksOf, ipStyle, petsLeft, petsRight, fmt, geoLabel, geoLink, myPerks, prefs };
|
||||
}
|
||||
Reference in New Issue
Block a user