mirror of
https://github.com/github/awesome-copilot.git
synced 2026-02-23 11:55:12 +00:00
- Replace all inline scripts with TypeScript modules - Create page-specific modules for agents, prompts, instructions, skills, collections, index - Create core modules: utils.ts, search.ts, modal.ts, choices.ts, jszip.ts, theme.ts - Remove window global exports, use proper ES module imports - Add type interfaces for all data structures - Use data-base-path attribute on body for base URL handling - Bundle Choices.js and JSZip via npm instead of CDN - Astro pages now just have single script import each
2 lines
4.1 KiB
JavaScript
2 lines
4.1 KiB
JavaScript
const f="https://raw.githubusercontent.com/github/awesome-copilot/main",p="https://github.com/github/awesome-copilot/blob/main",y={instructions:"https://aka.ms/awesome-copilot/install/instructions",prompt:"https://aka.ms/awesome-copilot/install/prompt",agent:"https://aka.ms/awesome-copilot/install/agent"};function g(){return typeof document<"u"&&document.body.dataset.basePath||"/"}async function $(e){try{const t=g(),n=await fetch(`${t}data/${e}`);if(!n.ok)throw new Error(`Failed to fetch ${e}`);return await n.json()}catch(t){return console.error(`Error fetching ${e}:`,t),null}}async function w(e){try{const t=await fetch(`${f}/${e}`);if(!t.ok)throw new Error(`Failed to fetch ${e}`);return await t.text()}catch(t){return console.error("Error fetching file content:",t),null}}async function E(e){try{return await navigator.clipboard.writeText(e),!0}catch{const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();const n=document.execCommand("copy");return document.body.removeChild(t),n}}function b(e,t){const n=y[e];return n?`${n}?url=${encodeURIComponent(`${f}/${t}`)}`:null}function v(e){return`${p}/${e}`}function x(e){return`${f}/${e}`}function C(e,t="success"){const n=document.querySelector(".toast");n&&n.remove();const o=document.createElement("div");o.className=`toast ${t}`,o.textContent=e,document.body.appendChild(o),setTimeout(()=>{o.remove()},3e3)}function L(e,t){let n;return function(...c){const i=()=>{clearTimeout(n),e(...c)};clearTimeout(n),n=setTimeout(i,t)}}function h(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}function S(e,t){return!e||e.length<=t?e||"":e.slice(0,t).trim()+"..."}function k(e){return{agent:"🤖",prompt:"🎯",instruction:"📋",skill:"⚡",collection:"📦"}[e]||"📄"}class B{constructor(t=[]){this.items=[],this.items=t}setItems(t){this.items=t}search(t,n={}){const{fields:o=["title","description","searchText"],limit:c=50,minScore:i=0}=n;if(!t||t.trim().length===0)return this.items.slice(0,c);const s=t.toLowerCase().trim().split(/\s+/),l=[];for(const u of this.items){const a=this.calculateScore(u,s,o);a>i&&l.push({item:u,score:a})}return l.sort((u,a)=>a.score-u.score),l.slice(0,c).map(u=>u.item)}calculateScore(t,n,o){let c=0;for(const r of n){let s=0;for(const l of o){const u=t[l];if(!u)continue;const a=String(u).toLowerCase();l==="title"&&a===r?s=Math.max(s,100):l==="title"&&a.startsWith(r)?s=Math.max(s,80):l==="title"&&a.includes(r)?s=Math.max(s,60):l==="description"&&a.includes(r)?s=Math.max(s,30):l==="searchText"&&a.includes(r)&&(s=Math.max(s,20))}c+=s}return n.every(r=>o.some(s=>{const l=t[s];return l&&String(l).toLowerCase().includes(r)}))&&n.length>1&&(c*=1.5),c}highlight(t,n){if(!n||!t)return h(t||"");const c=n.toLowerCase().trim().split(/\s+/);let i=h(t);for(const r of c){if(r.length<2)continue;const s=new RegExp(`(${r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi");i=i.replace(s,"<mark>$1</mark>")}return i}}let d=null;function I(){const e=document.getElementById("file-modal"),t=document.getElementById("close-modal"),n=document.getElementById("copy-btn");e&&(t?.addEventListener("click",m),e.addEventListener("click",o=>{o.target===e&&m()}),document.addEventListener("keydown",o=>{o.key==="Escape"&&!e.classList.contains("hidden")&&m()}),n?.addEventListener("click",async()=>{if(d){const o=await E(d);C(o?"Copied to clipboard!":"Failed to copy",o?"success":"error")}}))}async function T(e,t){const n=document.getElementById("file-modal"),o=document.getElementById("modal-title"),c=document.getElementById("modal-content")?.querySelector("code"),i=document.getElementById("install-vscode-btn");if(!n||!o||!c)return;o.textContent=e.split("/").pop()||e,c.textContent="Loading...",n.classList.remove("hidden");const r=b(t,e);r&&i?(i.href=r,i.style.display="inline-flex"):i&&(i.style.display="none");const s=await w(e);d=s,s?c.textContent=s:c.textContent="Failed to load file content. Click the button below to view on GitHub."}function m(){const e=document.getElementById("file-modal");e&&e.classList.add("hidden"),d=null}export{B as F,x as a,k as b,L as d,h as e,$ as f,v as g,T as o,I as s,S as t};
|