fix IrcColors
This commit is contained in:
parent
0444831073
commit
7779e5a1ec
1 changed files with 34 additions and 16 deletions
|
|
@ -67,9 +67,8 @@ export default definePlugin({
|
|||
find: '="SYSTEM_TAG"',
|
||||
replacement: {
|
||||
// Override colorString with our custom color and disable gradients if applying the custom color.
|
||||
match: /&&null!=\i\.secondaryColor,(?<=colorString:(\i).+?(\i)=.+?)/,
|
||||
replace: (m, colorString, hasGradientColors) => `${m}` +
|
||||
`vcIrcColorsDummy=[${colorString},${hasGradientColors}]=$self.getMessageColorsVariables(arguments[0],${hasGradientColors}),`
|
||||
match: /(?<=colorString:\i,colorStrings:\i,colorRoleName:\i}=)(\i),/,
|
||||
replace: "$self.wrapMessageColorProps($1, arguments[0]),"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -82,11 +81,26 @@ export default definePlugin({
|
|||
}
|
||||
],
|
||||
|
||||
getMessageColorsVariables(context: any, hasGradientColors: boolean) {
|
||||
const colorString = this.calculateNameColorForMessageContext(context);
|
||||
const originalColorString = context?.author?.colorString;
|
||||
wrapMessageColorProps(colorProps: { colorString: string, colorStrings?: Record<"primaryColor" | "secondaryColor" | "tertiaryColor", string>; }, context: any) {
|
||||
try {
|
||||
const colorString = this.calculateNameColorForMessageContext(context);
|
||||
if (colorString === colorProps.colorString) {
|
||||
return colorProps;
|
||||
}
|
||||
|
||||
return [colorString, hasGradientColors && colorString === originalColorString];
|
||||
return {
|
||||
...colorProps,
|
||||
colorString,
|
||||
colorStrings: colorProps.colorStrings && {
|
||||
primaryColor: colorString,
|
||||
secondaryColor: undefined,
|
||||
tertiaryColor: undefined
|
||||
}
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("Failed to calculate message color strings:", e);
|
||||
return colorProps;
|
||||
}
|
||||
},
|
||||
|
||||
calculateNameColorForMessageContext(context: any) {
|
||||
|
|
@ -108,16 +122,20 @@ export default definePlugin({
|
|||
},
|
||||
|
||||
calculateNameColorForListContext(context: any) {
|
||||
const id = context?.user?.id;
|
||||
const colorString = context?.colorString;
|
||||
const color = calculateNameColorForUser(id);
|
||||
try {
|
||||
const id = context?.user?.id;
|
||||
const colorString = context?.colorString;
|
||||
const color = calculateNameColorForUser(id);
|
||||
|
||||
if (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) {
|
||||
return colorString;
|
||||
if (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) {
|
||||
return colorString;
|
||||
}
|
||||
|
||||
return (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString)
|
||||
? color
|
||||
: colorString;
|
||||
} catch (e) {
|
||||
console.error("Failed to calculate name color for list context:", e);
|
||||
}
|
||||
|
||||
return (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString)
|
||||
? color
|
||||
: colorString;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue