| 2284 | `, | 2284 | `, |
| 2285 | })); | 2285 | })); |
| 2286 | | 2286 | |
| | 2287 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| | 2288 | name: 'clipboard-get', |
| | 2289 | returns: 'clipboard text', |
| | 2290 | callback: async () => { |
| | 2291 | if (!navigator.clipboard) { |
| | 2292 | toastr.warning('Clipboard API not available in this context.'); |
| | 2293 | return ''; |
| | 2294 | } |
| | 2295 | |
| | 2296 | try { |
| | 2297 | const text = await navigator.clipboard.readText(); |
| | 2298 | return text; |
| | 2299 | } |
| | 2300 | catch (error) { |
| | 2301 | console.error('Error reading clipboard:', error); |
| | 2302 | toastr.warning('Failed to read clipboard text. Have you granted the permission?'); |
| | 2303 | return ''; |
| | 2304 | } |
| | 2305 | }, |
| | 2306 | helpString: 'Retrieves the text from the OS clipboard. Only works in secure contexts (HTTPS or localhost). Browser may ask for permission.', |
| | 2307 | })); |
| | 2308 | |
| | 2309 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| | 2310 | name: 'clipboard-set', |
| | 2311 | callback: async (_, text) => { |
| | 2312 | await copyText(text.toString()); |
| | 2313 | return ''; |
| | 2314 | }, |
| | 2315 | unnamedArgumentList: [ |
| | 2316 | SlashCommandArgument.fromProps({ |
| | 2317 | description: 'text to copy to the clipboard', |
| | 2318 | typeList: [ARGUMENT_TYPE.STRING], |
| | 2319 | isRequired: true, |
| | 2320 | acceptsMultiple: false, |
| | 2321 | }), |
| | 2322 | ], |
| | 2323 | helpString: 'Copies the provided text to the OS clipboard. Returns an empty string.', |
| | 2324 | })); |
| | 2325 | |
| 2287 | registerVariableCommands(); | 2326 | registerVariableCommands(); |
| 2288 | } | 2327 | } |
| 2289 | | 2328 | |