Vanilla JavaScript Magic

A shared folder with AI prompts and code snippets

From workspace: FreeCodeCamp

Team: Main

Total snippets: 4

FreeCodeCamp

Vanilla JavaScript Magic

4 snippets

Detect Dark Mode

Checks if the user's system prefers dark mode.

const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;

Copy to Clipboard

Copies text to the clipboard using the Clipboard API.

function copyToClipboard(text) { navigator.clipboard.writeText(text); }

Throttle Function

Ensures a function is called at most once every specified interval.

function throttle(func, limit) { let inThrottle; return function(...args) { if (!inThrottle) { func.apply(this, args); inThrottle = true; setTimeout(() => inThrottle = false, limit); } }; }

Debounce Function

Delays a function call until after a specified delay from the last event trigger.

function debounce(func, delay) { let timeout; return function(...args) { clearTimeout(timeout); timeout = setTimeout(() => func.apply(this, args), delay); }; }

FreeCodeCamp - Vanilla JavaScript Magic - AI Prompts & Code Snippets | Snippets AI