mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-10 09:56:24 +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:
parent
b99fe6c70a
commit
7ddb889195
1 changed files with 27 additions and 26 deletions
|
@ -20,6 +20,32 @@ import { Devs } from "@utils/constants";
|
|||
import { definePluginSettings } from "@api/Settings";
|
||||
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({
|
||||
lightness: {
|
||||
description: "Lightness, in %. Change if the colors are too light or too dark.",
|
||||
|
@ -43,32 +69,7 @@ export default definePlugin({
|
|||
},
|
||||
],
|
||||
settings,
|
||||
// Calculate a CSS color string based on the user ID
|
||||
calculateNameColorForContext(context: any) {
|
||||
return this.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}%)`;
|
||||
return calculateNameColorForUser(BigInt(context.message.author.id));
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue