mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add /css-var slash command
- Add /css-var slash command to set CSS variables on some elements - Update gallery div id to something actually unique ("#draggable_gallery")
This commit is contained in:
@ -277,7 +277,7 @@ function makeMovable(id = 'gallery') {
|
|||||||
const newElement = $(template);
|
const newElement = $(template);
|
||||||
newElement.css('background-color', 'var(--SmartThemeBlurTintColor)');
|
newElement.css('background-color', 'var(--SmartThemeBlurTintColor)');
|
||||||
newElement.attr('forChar', id);
|
newElement.attr('forChar', id);
|
||||||
newElement.attr('id', `${id}`);
|
newElement.attr('id', `draggable_${id}`);
|
||||||
newElement.find('.drag-grabber').attr('id', `${id}header`);
|
newElement.find('.drag-grabber').attr('id', `${id}header`);
|
||||||
newElement.find('.dragTitle').text('Image Gallery');
|
newElement.find('.dragTitle').text('Image Gallery');
|
||||||
//add a div for the gallery
|
//add a div for the gallery
|
||||||
|
@ -3962,6 +3962,95 @@ $(document).ready(() => {
|
|||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
}));
|
}));
|
||||||
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
|
name: 'css-var',
|
||||||
|
/** @param {{to: string, varname: string }} args @param {string} value @returns {string} */
|
||||||
|
callback: (args, value) => {
|
||||||
|
// Map enum to target selector
|
||||||
|
const targetSelector = {
|
||||||
|
chat: '#chat',
|
||||||
|
background: '#bg1',
|
||||||
|
gallery: '#draggable_gallery',
|
||||||
|
zoomedAvatar: 'div.zoomed_avatar',
|
||||||
|
}[args.to || 'chat'];
|
||||||
|
|
||||||
|
if (!targetSelector) {
|
||||||
|
toastr.error(`Invalid target: ${args.to}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!args.varname) {
|
||||||
|
toastr.error('CSS variable name is required');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!args.varname.startsWith('--')) {
|
||||||
|
toastr.error('CSS variable names must start with "--"');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const elements = document.querySelectorAll(targetSelector);
|
||||||
|
if (elements.length === 0) {
|
||||||
|
toastr.error(`No elements found for ${args.to ?? 'chat'} with selector "${targetSelector}"`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.forEach(element => {
|
||||||
|
element.style.setProperty(args.varname, value);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.info(`Set CSS variable "${args.varname}" to "${value}" on "${targetSelector}"`);
|
||||||
|
},
|
||||||
|
namedArgumentList: [
|
||||||
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'varname',
|
||||||
|
description: 'CSS variable name (starting with double dashes)',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
}),
|
||||||
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'to',
|
||||||
|
description: 'The target element to which the CSS variable will be applied',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
enumList: [
|
||||||
|
new SlashCommandEnumValue('chat', null, enumTypes.enum, enumIcons.message),
|
||||||
|
new SlashCommandEnumValue('background', null, enumTypes.enum, enumIcons.image),
|
||||||
|
new SlashCommandEnumValue('zoomedAvatar', null, enumTypes.enum, enumIcons.character),
|
||||||
|
new SlashCommandEnumValue('gallery', null, enumTypes.enum, enumIcons.image),
|
||||||
|
],
|
||||||
|
defaultValue: 'chat',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
unnamedArgumentList: [
|
||||||
|
SlashCommandArgument.fromProps({
|
||||||
|
description: 'CSS variable value',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
helpString: `
|
||||||
|
<div>
|
||||||
|
Sets a CSS variable to a specified value on a target element.
|
||||||
|
<br />
|
||||||
|
Only setting of variable names is supported. They have to be prefixed with double dashes ("--exampleVar").
|
||||||
|
Setting actual CSS properties is not supported. Custom CSS in the theme settings can be used for that.
|
||||||
|
<br /><br />
|
||||||
|
<b>This value will be gone after a page reload!</b>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<strong>Example:</strong>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<pre><code>/css-var varname="--SmartThemeBodyColor" #ff0000</code></pre>
|
||||||
|
Sets the text color of the chat to red
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<pre><code>/css-var to=zoomedAvatar varname="--SmartThemeBlurStrength" 0</code></pre>
|
||||||
|
Remove the blur from the zoomed avatar
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'movingui',
|
name: 'movingui',
|
||||||
callback: setmovingUIPreset,
|
callback: setmovingUIPreset,
|
||||||
|
@ -37,6 +37,7 @@ export const enumIcons = {
|
|||||||
voice: '🎤',
|
voice: '🎤',
|
||||||
server: '🖥️',
|
server: '🖥️',
|
||||||
popup: '🗔',
|
popup: '🗔',
|
||||||
|
image: '🖼️',
|
||||||
|
|
||||||
true: '✔️',
|
true: '✔️',
|
||||||
false: '❌',
|
false: '❌',
|
||||||
|
Reference in New Issue
Block a user