Spaces:
Running
Running
Download script.js from lensetek/skillforge: direct link, hf CLI and curl.
- Browser
- Download file 3.56 kB
-
https://huggingface.co/spaces/lensetek/skillforge/resolve/main/script.js
- Command line
-
hf download hf://spaces/lensetek/skillforge/script.js
-
curl -L -o script.js https://huggingface.co/spaces/lensetek/skillforge/resolve/main/script.js
3.56 kB
| document.addEventListener('DOMContentLoaded', () => { | |
| const langToggleBtn = document.getElementById('lang-toggle-btn'); | |
| const body = document.body; | |
| // Language state management | |
| const savedLang = localStorage.getItem('skillforge-lang') || 'en'; | |
| setLanguage(savedLang); | |
| if (langToggleBtn) { | |
| langToggleBtn.addEventListener('click', () => { | |
| const currentLang = body.classList.contains('lang-en') ? 'en' : 'id'; | |
| const newLang = currentLang === 'en' ? 'id' : 'en'; | |
| setLanguage(newLang); | |
| }); | |
| } | |
| function setLanguage(lang) { | |
| if (lang === 'id') { | |
| body.classList.remove('lang-en'); | |
| body.classList.add('lang-id'); | |
| document.title = "SkillForge | Workspace Kustomisasi Sub-Agent AI - Lensetek"; | |
| localStorage.setItem('skillforge-lang', 'id'); | |
| } else { | |
| body.classList.remove('lang-id'); | |
| body.classList.add('lang-en'); | |
| document.title = "SkillForge | The AI Sub-Agent Customization Workspace - Lensetek"; | |
| localStorage.setItem('skillforge-lang', 'en'); | |
| } | |
| } | |
| // Smooth scroll for internal links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function (e) { | |
| const targetId = this.getAttribute('href'); | |
| if (targetId && targetId !== '#') { | |
| const targetElement = document.querySelector(targetId); | |
| if (targetElement) { | |
| e.preventDefault(); | |
| window.scrollTo({ | |
| top: targetElement.offsetTop - 80, | |
| behavior: 'smooth' | |
| }); | |
| } | |
| } | |
| }); | |
| }); | |
| // Reusable Copy Handler with Zero Duplicate Icon Guarantee | |
| function attachCopyHandler(buttonId, textExtractor) { | |
| const btn = document.getElementById(buttonId); | |
| if (!btn) return; | |
| btn.addEventListener('click', () => { | |
| const textToCopy = typeof textExtractor === 'function' ? textExtractor() : textExtractor; | |
| if (!textToCopy) return; | |
| navigator.clipboard.writeText(textToCopy).then(() => { | |
| const isEnglish = body.classList.contains('lang-en'); | |
| const originalHTML = btn.innerHTML; | |
| btn.innerHTML = isEnglish | |
| ? '<span lang="en">✓ Copied!</span>' | |
| : '<span lang="id">✓ Tersalin!</span>'; | |
| setTimeout(() => { | |
| btn.innerHTML = originalHTML; | |
| }, 2000); | |
| }).catch(err => { | |
| console.error('Copy failed: ', err); | |
| }); | |
| }); | |
| } | |
| // 1. Hero 1-Click Copy Prompt | |
| attachCopyHandler('copy-hero-prompt-btn', () => { | |
| const isEnglish = body.classList.contains('lang-en'); | |
| const promptSpan = document.querySelector(`#hero-prompt-text span[lang="${isEnglish ? 'en' : 'id'}"]`); | |
| return promptSpan ? promptSpan.textContent.trim() : ''; | |
| }); | |
| // 2. Hero Global Command Copy | |
| attachCopyHandler('copy-global-cmd-btn', () => { | |
| const cmdSpan = document.getElementById('global-cmd-text'); | |
| return cmdSpan ? cmdSpan.textContent.trim() : 'npx --yes skills add -g https://huggingface.co/spaces/lensetek/skillforge.git -y'; | |
| }); | |
| // 3. Installation Section Prompt Copy | |
| attachCopyHandler('copy-prompt-btn', () => { | |
| const isEnglish = body.classList.contains('lang-en'); | |
| const promptSpan = document.querySelector(`.installation-section .prompt-text span[lang="${isEnglish ? 'en' : 'id'}"]`); | |
| return promptSpan ? promptSpan.textContent.trim() : ''; | |
| }); | |
| // 4. Installation Section NPM Command Copy | |
| attachCopyHandler('copy-npm-btn', () => { | |
| return 'npx --yes skills add -g https://huggingface.co/spaces/lensetek/skillforge.git -y'; | |
| }); | |
| }); | |