插件源地址:https://qshot.top/
我希望修改其中的一个小功能,这里记录一下修改过程。
这个Qshot插件有一个提示词管理页面,我希望点击首页的“设置”就能进入到设置页面。
我希望单击该“设置”按钮能直接进入提示词管理页面
我注意到这两个页面的地址不同,多了一级?section=prompts,那么修改就很直接,直接把希望修改的具体到这个加上?section=prompts,而不需要再去跟AI对齐需求
问AI:
我希望这个插件,在我点击设置的时候,从原来的打开“chrome-extension://eofkknckiocjcpkjbhmkaijnlkiajiic/settings/settings.html”变为打开
“chrome-extension://eofkknckiocjcpkjbhmkaijnlkiajiic/settings/settings.html?section=prompts”帮我看看我具体要在仓库里的哪个文件做什么修改
AI回答:
1. 打开background.js
找到这一段(在文件靠后的位置,搜索OPEN_SETTINGS_PAGE就能定位):
if(e.type==="OPEN_SETTINGS_PAGE"){let o=new URLSearchParams;e.section&&o.set("section",e.section),e.miscTab&&o.set("miscTab",e.miscTab),e.action&&o.set("action",e.action);let a=o.toString(),n=Ze+(a?`?${a}`:"");return chrome.tabs.create({url:n}).then(i=>r({ok:!0,tabId:i.id})).catch(i=>r({ok:!1,error:i.message})),!0}2. 用下面这段替换它
if(e.type==="OPEN_SETTINGS_PAGE"){let o=new URLSearchParams,s=e.section||"prompts";s&&o.set("section",s),e.miscTab&&o.set("miscTab",e.miscTab),e.action&&o.set("action",e.action);let a=o.toString(),n=Ze+(a?`?${a}`:"");return chrome.tabs.create({url:n}).then(i=>r({ok:!0,tabId:i.id})).catch(i=>r({ok:!1,error:i.message})),!0}我定位到了,并很轻松地改好,再重新加载,功能也正常,符合我的要求
但是要注意,需要提前导出个人插件配置文件(如新建的提示词),再卸载插件重安装。
否则保存的个人提示词,与插件设置配置记录都会消失。
我希望再提示词管理右侧加一个复制按钮,即复制、编辑、查看。方便我直接复制到其他AI助手里使用。
问AI:
如图,现在这个界面里红框框起来的地方
chrome-extension://jnphaehpjolhlijbgialiddcinbeommn/settings/settings.html?section=prompts只有编辑和查看,我希望增加一个复制按钮
AI回答:
下面这个改动只需要动settings.js里的一个函数Zo(就是渲染每条提示词卡片右侧图标按钮的那个函数)。
定位
在settings.js中搜索function Zo:
function Zo(e,t,r={}){
它会一直延续到 ...o.appendChild(s),o},紧接着是 function ne(){。找到这整段,把 整个 Zo 函数 替换为下面的版本。
替换后的完整Zo函数
function Zo(e,t,r={}){let i=!!r.disableDrag,o=document.createElement("article");o.className="prompt-card-item",o.dataset.promptId=t.id,o.dataset.groupId=e.id;let s=document.createElement("div");s.className="prompt-card-inline";let cp=document.createElement("button");cp.type="button",cp.className="prompt-icon-btn prompt-copy-icon-btn",cp.setAttribute("aria-label",a("common_copy","复制")),cp.title=a("common_copy","复制"),cp.innerHTML='<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>',cp.addEventListener("click",async u=>{u.stopPropagation();let h=kn(t)||"";let g=()=>{let y=cp.innerHTML;cp.innerHTML='<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="#2dbf62" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="20 6 9 17 4 12"/></svg>',setTimeout(()=>{cp.innerHTML=y},1200)};try{await navigator.clipboard.writeText(h),g()}catch(y){let E=document.createElement("textarea");E.value=h,E.style.cssText="position:fixed;opacity:0",document.body.appendChild(E),E.select();try{document.execCommand("copy")}catch{}E.remove(),g()}});let d=document.createElement("button");d.type="button",d.className="prompt-icon-btn prompt-edit-icon-btn",d.setAttribute("aria-label",a("common_edit","编辑")),d.title=a("common_edit","编辑"),d.innerHTML='<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>',d.addEventListener("click",()=>{n.promptEditorState={mode:"edit",groupId:e.id,promptId:t.id,title:t.title||"",note:t.note||"",content:t.content||"",versions:mt(t),activeVersionIdx:0},V()});let c=document.createElement("button");c.type="button",c.className="prompt-icon-btn prompt-preview-icon-btn",c.setAttribute("aria-label",a("settings_prompts_previewAria","预览")),c.title=a("settings_prompts_previewTitle","预览内容"),c.innerHTML='<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>';let l=null;c.addEventListener("mouseenter",()=>{l=setTimeout(()=>{wn(t,e,c)},200)}),c.addEventListener("mouseleave",()=>{l&&(clearTimeout(l),l=null)});let p=document.createElement("button");p.type="button",p.className="prompt-icon-btn prompt-card-drag-handle",p.setAttribute("aria-label",a("settings_prompts_dragGroupAria","拖动排序")),p.title=a("settings_prompts_dragGroupTitle","拖动排序"),p.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><circle cx="9" cy="5" r="1.6"/><circle cx="15" cy="5" r="1.6"/><circle cx="9" cy="12" r="1.6"/><circle cx="15" cy="12" r="1.6"/><circle cx="9" cy="19" r="1.6"/><circle cx="15" cy="19" r="1.6"/></svg>';let m=document.createElement("div");m.className="prompt-card-title",m.textContent=t.title||a("overlay_unnamedPrompt","未命名提示词");let f=document.createElement("div");return f.className="prompt-card-icon-group",f.appendChild(cp),f.appendChild(d),f.appendChild(c),i||f.appendChild(p),s.appendChild(m),s.appendChild(f),o.appendChild(s),o}修改过程:
修改完点击刷新
效果如下图,增加了复制按钮。