mirror of
https://github.com/sune-org/store.git
synced 2026-01-13 16:17:58 +00:00
1 line
5.7 KiB
JSON
1 line
5.7 KiB
JSON
[{"id":"0in1b62","name":"jsdelivr","pinned":false,"avatar":"","url":"gh://sune-org/store@main/jsdelivr.sune","updatedAt":1757529684416,"settings":{"model":"openai/gpt-5","temperature":"1","top_p":"0.96","top_k":"0","frequency_penalty":"0","repetition_penalty":"1","min_p":"0","top_a":"0","verbosity":"","reasoning_effort":"default","system_prompt":"","html":"<div id=\"gh-to-jsdelivr-sune\" class=\"p-4 mx-auto max-w-lg w-full font-sans\">\n <div class=\"bg-white border border-gray-200 rounded-2xl shadow-sm p-4 sm:p-6 space-y-4\">\n <!-- Header -->\n <div class=\"flex items-center gap-3\">\n <div class=\"h-10 w-10 flex-shrink-0 bg-gray-900 text-white rounded-full flex items-center justify-center\">\n <i data-lucide=\"shuffle\" class=\"h-5 w-5\"></i>\n </div>\n <div>\n <h2 class=\"text-base font-semibold text-gray-900\">GitHub to jsDelivr</h2>\n <p class=\"text-sm text-gray-500\">Convert repo file paths to jsDelivr CDN links.</p>\n </div>\n </div>\n\n <!-- Input Section -->\n <div class=\"space-y-2\">\n <label for=\"sune-ghPathInput\" class=\"block text-sm font-medium text-gray-700\">GitHub Path</label>\n <input type=\"text\" id=\"sune-ghPathInput\" placeholder=\"user/repo@branch/file.js\" class=\"block w-full px-3 py-2 bg-white border border-gray-300 rounded-lg text-sm placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-black focus:border-transparent transition\">\n </div>\n\n <!-- Output Section -->\n <div class=\"space-y-2\">\n <label for=\"sune-jsdelivrUrlOutput\" class=\"block text-sm font-medium text-gray-700\">jsDelivr URL</label>\n <div class=\"relative\">\n <input type=\"text\" id=\"sune-jsdelivrUrlOutput\" readonly class=\"block w-full pr-12 pl-3 py-2 bg-gray-50 border border-gray-300 rounded-lg text-sm text-gray-600 focus:outline-none focus:ring-0 cursor-default\">\n <button id=\"sune-copyBtn\" title=\"Copy URL\" class=\"absolute inset-y-0 right-0 flex items-center justify-center h-full w-12 text-gray-500 hover:text-gray-800 transition rounded-r-lg hover:bg-gray-200 active:bg-gray-300\">\n <i data-lucide=\"copy\" class=\"h-4 w-4\"></i>\n </button>\n </div>\n </div>\n </div>\n</div>\n\n<script>\n(() => {\n // Self-invoking function to scope variables and prevent re-initialization.\n const suneContainer = document.getElementById('gh-to-jsdelivr-sune');\n if (suneContainer.dataset.initialized) return;\n suneContainer.dataset.initialized = 'true';\n\n const ghPathInput = document.getElementById('sune-ghPathInput');\n const jsdelivrUrlOutput = document.getElementById('sune-jsdelivrUrlOutput');\n const copyBtn = document.getElementById('sune-copyBtn');\n\n // Use the unique Sune ID for localStorage key to prevent conflicts.\n const SUNE_ID = window.SUNE?.id || 'gh-to-jsdelivr-sune';\n const STORAGE_KEY = `sune_cache_${SUNE_ID}`;\n\n /**\n * Converts the GitHub path from the input field to a jsDelivr URL\n * and updates the output field. Caches the input to localStorage.\n */\n const convertAndCachePath = () => {\n const input = ghPathInput.value.trim();\n \n try {\n localStorage.setItem(STORAGE_KEY, input);\n } catch (e) {\n console.error(\"Sune Error: Failed to save to localStorage:\", e);\n }\n\n // Regex to parse: user/repo@branch/path/to/file\n const match = input.match(/^([^/]+\\/[^@]+)@([^/]+)\\/(.+)$/);\n\n if (match) {\n const [, userRepo, branch, filePath] = match;\n const url = `https://cdn.jsdelivr.net/gh/${userRepo}@${branch}/${filePath}`;\n jsdelivrUrlOutput.value = url;\n } else {\n jsdelivrUrlOutput.value = '';\n }\n };\n\n /**\n * Copies the content of the output field to the clipboard and provides user feedback.\n */\n const copyToClipboard = async () => {\n const url = jsdelivrUrlOutput.value;\n if (!url) return;\n\n try {\n await navigator.clipboard.writeText(url);\n const originalIcon = copyBtn.innerHTML;\n copyBtn.innerHTML = '<i data-lucide=\"check\" class=\"h-4 w-4 text-green-600\"></i>';\n window.lucide?.createIcons(); // Re-render the new icon\n\n setTimeout(() => {\n copyBtn.innerHTML = originalIcon;\n window.lucide?.createIcons(); // Restore the original icon\n }, 2000);\n } catch (err) {\n console.error('Sune Error: Failed to copy text: ', err);\n // Fallback for older browsers or insecure contexts\n alert('Failed to copy URL. Please copy it manually.');\n }\n };\n\n /**\n * Initializes the sune by loading cached data and setting up event listeners.\n */\n const init = () => {\n // Load cached input from localStorage on initialization.\n try {\n const cachedInput = localStorage.getItem(STORAGE_KEY);\n if (cachedInput) {\n ghPathInput.value = cachedInput;\n convertAndCachePath(); // Convert immediately if cached data exists.\n }\n } catch (e) {\n console.error(\"Sune Error: Failed to read from localStorage:\", e);\n }\n\n // Add event listeners for real-time conversion and copy functionality.\n ghPathInput.addEventListener('input', convertAndCachePath);\n copyBtn.addEventListener('click', copyToClipboard);\n \n // Ensure Lucide icons are rendered after the sune is injected.\n if (window.lucide) {\n window.lucide.createIcons();\n }\n };\n\n // Defer initialization slightly to ensure the DOM is fully ready.\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', init);\n } else {\n init();\n }\n\n})();\n</script>\n","extension_html":"<sune src='https://raw.githubusercontent.com/sune-org/store/refs/heads/main/sync.sune' private></sune>","hide_composer":false,"presence_penalty":0,"max_tokens":0},"storage":{}}] |