mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
@ -1,5 +1,5 @@
|
|||||||
import { Fuse, DOMPurify } from '../lib.js';
|
import { Fuse, DOMPurify } from '../lib.js';
|
||||||
import { flashHighlight } from './utils.js';
|
import { copyText, flashHighlight } from './utils.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Generate,
|
Generate,
|
||||||
@ -2284,6 +2284,45 @@ export function initDefaultSlashCommands() {
|
|||||||
`,
|
`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
|
name: 'clipboard-get',
|
||||||
|
returns: 'clipboard text',
|
||||||
|
callback: async () => {
|
||||||
|
if (!navigator.clipboard) {
|
||||||
|
toastr.warning('Clipboard API not available in this context.');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const text = await navigator.clipboard.readText();
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error('Error reading clipboard:', error);
|
||||||
|
toastr.warning('Failed to read clipboard text. Have you granted the permission?');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
helpString: 'Retrieves the text from the OS clipboard. Only works in secure contexts (HTTPS or localhost). Browser may ask for permission.',
|
||||||
|
}));
|
||||||
|
|
||||||
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
|
name: 'clipboard-set',
|
||||||
|
callback: async (_, text) => {
|
||||||
|
await copyText(text.toString());
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
unnamedArgumentList: [
|
||||||
|
SlashCommandArgument.fromProps({
|
||||||
|
description: 'text to copy to the clipboard',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
acceptsMultiple: false,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
helpString: 'Copies the provided text to the OS clipboard. Returns an empty string.',
|
||||||
|
}));
|
||||||
|
|
||||||
registerVariableCommands();
|
registerVariableCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user