import type { PlasmoCSConfig } from "plasmo" export const config: PlasmoCSConfig = { matches: ["*://ollama.com/library/*"], all_frames: true } const downloadModel = async (modelName: string) => { const ok = confirm( `[Page Assist Extension] Do you want to pull ${modelName} model? This has nothing to do with Ollama.com website. The model will be pulled locally once you confirm.` ) if (ok) { alert( `[Page Assist Extension] Pulling ${modelName} model. For more details, check the extension icon.` ) await chrome.runtime.sendMessage({ type: "pull_model", modelName }) return true } return false } const downloadSVG = ` ` const codeDiv = document.querySelectorAll("div.language-none") for (let i = 0; i < codeDiv.length; i++) { const button = codeDiv[i].querySelector("button") const command = codeDiv[i].querySelector("input") if (button && command) { const newButton = document.createElement("button") newButton.innerHTML = downloadSVG newButton.className = `border-l ${button.className}` newButton.id = `download-${i}-pageassist` const modelName = command?.value .replace("ollama run", "") .replace("ollama pull", "") .trim() newButton.addEventListener("click", () => { downloadModel(modelName) }) const span = document.createElement("span") span.title = "Download model via Page Assist" span.appendChild(newButton) button.parentNode.appendChild(span) } }