1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-10 18:06:22 +00:00

Move functions outside plugin definition

They don't need to be there if they aren't used by patches.
This commit is contained in:
Grzesiek11 2024-06-24 05:52:18 +02:00
parent b99fe6c70a
commit 7ddb889195
No known key found for this signature in database
GPG key ID: 4A5445FB68CDB5C4

View file

@ -20,6 +20,32 @@ import { Devs } from "@utils/constants";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
// Compute a 64-bit FNV-1a hash of the passed data
function hash(data: ArrayBuffer) {
const fnvPrime = 1099511628211n;
const offsetBasis = 14695981039346656037n;
let result = offsetBasis;
for (const byte of new Uint8Array(data)) {
result ^= BigInt(byte);
result = (result * fnvPrime) % 2n**32n;
}
return result;
}
// Calculate a CSS color string based on the user ID
function calculateNameColorForUser(id: bigint) {
const idBuffer = new ArrayBuffer(16);
{
const idView = new DataView(idBuffer);
idView.setBigUint64(0, id);
}
const idHash = hash(idBuffer);
return `hsl(${idHash % 360n}, 100%, ${settings.store.lightness}%)`;
}
const settings = definePluginSettings({ const settings = definePluginSettings({
lightness: { lightness: {
description: "Lightness, in %. Change if the colors are too light or too dark.", description: "Lightness, in %. Change if the colors are too light or too dark.",
@ -43,32 +69,7 @@ export default definePlugin({
}, },
], ],
settings, settings,
// Calculate a CSS color string based on the user ID
calculateNameColorForContext(context: any) { calculateNameColorForContext(context: any) {
return this.calculateNameColorForUser(BigInt(context.message.author.id)); return calculateNameColorForUser(BigInt(context.message.author.id));
},
calculateNameColorForUser(id: bigint) {
// Compute a 64-bit FNV-1a hash of the passed data
function hash(data: ArrayBuffer) {
const fnvPrime = 1099511628211n;
const offsetBasis = 14695981039346656037n;
let result = offsetBasis;
for (const byte of new Uint8Array(data)) {
result ^= BigInt(byte);
result = (result * fnvPrime) % 2n**32n;
}
return result;
}
const idBuffer = new ArrayBuffer(16);
{
const idView = new DataView(idBuffer);
idView.setBigUint64(0, id);
}
const idHash = hash(idBuffer);
return `hsl(${idHash % 360n}, 100%, ${settings.store.lightness}%)`;
}, },
}); });