项目标题与描述
Awesome ChatGPT Prompts 是一个高质量的ChatGPT提示集合库,旨在为用户提供各种专业场景和角色扮演的对话模板。项目包含丰富的预设提示,覆盖开发、写作、翻译、面试等多种使用场景。
功能特性
- 多样化角色扮演:支持Linux终端、以太坊开发者、英语翻译等多种专业角色开发者友好:包含完整的代码示例和技术实现提示实时预览功能:提供嵌入式预览组件,可直接查看提示效果响应式设计:适配不同设备屏幕尺寸黑暗模式支持:提供舒适的夜间浏览体验CSV数据管理:所有提示以结构化CSV格式存储,便于维护和扩展变量提取功能:自动识别提示中的变量占位符
安装指南
该项目主要作为Web应用运行,无需复杂安装:
克隆仓库:
git clone https://github.com/f/awesome-chatgpt-prompts.git
安装依赖:
npm install
启动开发服务器:
npm run dev
系统要求:
- Node.js 14+现代浏览器(Chrome/Firefox/Edge最新版)
使用说明
基础使用示例
// 加载提示数据示例async function loadPrompts() { const response = await fetch('/vibeprompts.csv'); const text = await response.text(); return parseCSV(text);}// 解析CSV数据function parseCSV(csv) { const lines = csv.split("\n"); const headers = lines[0].split(",").map(header => header.replace(/"/g, "").trim()); // ...后续处理逻辑}
典型使用场景
- 开发者工具:获取特定技术栈的代码实现提示内容创作:使用优化的写作提示生成高质量内容语言学习:利用翻译和改进提示提升语言能力
核心代码
1. 黑暗模式切换功能
function toggleDarkMode() { const body = document.body; const toggle = document.querySelector(".dark-mode-toggle"); const sunIcon = toggle.querySelector(".sun-icon"); const moonIcon = toggle.querySelector(".moon-icon"); body.classList.toggle("dark-mode"); const isDarkMode = body.classList.contains("dark-mode"); localStorage.setItem("dark-mode", isDarkMode); sunIcon.style.display = isDarkMode ? "none" : "block"; moonIcon.style.display = isDarkMode ? "block" : "none";}
2. 变量提取功能
function extractVariables(text) { const variables = []; // 提取${var:default}格式变量 const regex1 = /\${([^}]+)}/g; let match; while ((match = regex1.exec(text)) !== null) { const [variable, defaultValue] = match[1].split(":").map(s => s.trim()); variables.push({ name: variable, default: defaultValue || "" }); } // 提取{{var}}格式变量 const regex2 = /\{\{([^}]+)\}\}/g; while ((match = regex2.exec(text)) !== null) { const variable = match[1].trim(); if (!variables.some(v => v.name === variable)) { variables.push({ name: variable, default: "" }); } } return [...new Set(variables.map(v => JSON.stringify(v)))].map(v => JSON.parse(v));}
3. 嵌入式预览组件初始化
class EmbedPreview { constructor() { this.params = this.parseURLParams(); this.config = this.getInitialConfig(); this.selectedFiles = new Set(); this.init(); } parseURLParams() { const urlParams = new URLSearchParams(window.location.search); const params = {}; for (const [key, value] of urlParams.entries()) { params[key] = decodeURIComponent(value); } return params; } getInitialConfig() { return { prompt: this.params.prompt || '', context: this.params.context ? this.params.context.split(',').map(c => c.trim()) : [], model: this.params.model || 'gpt-4o', // ...其他配置参数 }; }}