|
| 1 | +// ==UserScript== |
| 2 | +// @name Vapi |
| 3 | +// @namespace http://tampermonkey.net/ |
| 4 | +// @version 2025-01-16 |
| 5 | +// @description try to take over the world! |
| 6 | +// @author You |
| 7 | +// @match https://docs.vapi.ai/* |
| 8 | +// @icon https://www.google.com/s2/favicons?sz=64&domain=vapi.ai |
| 9 | +// @grant none |
| 10 | +// ==/UserScript== |
| 11 | + |
| 12 | +const removeAllClickListeners = (element) => { |
| 13 | + const newElement = element.cloneNode(true); |
| 14 | + element.parentNode.replaceChild(newElement, element); |
| 15 | + return newElement; |
| 16 | +}; |
| 17 | + |
| 18 | +const makeDefaultSearchTrieve = async () => { |
| 19 | + let defaultSearchBar = null; |
| 20 | + let retries = 0; |
| 21 | + while (!defaultSearchBar && retries < 10) { |
| 22 | + for (const el of document.querySelectorAll("*")) { |
| 23 | + if (el.querySelector('[aria-label="Search"]')) { |
| 24 | + defaultSearchBar = el.querySelector('[aria-label="Search"]'); |
| 25 | + break; |
| 26 | + } |
| 27 | + } |
| 28 | + retries++; |
| 29 | + await new Promise((resolve) => setTimeout(resolve, 10)); |
| 30 | + } |
| 31 | + defaultSearchBar = removeAllClickListeners(defaultSearchBar); |
| 32 | + |
| 33 | + defaultSearchBar.onclick = () => { |
| 34 | + const event = new CustomEvent("trieve-open-with-text", { |
| 35 | + detail: { text: "" }, |
| 36 | + }); |
| 37 | + window.dispatchEvent(event); |
| 38 | + }; |
| 39 | +}; |
| 40 | +await makeDefaultSearchTrieve(); |
| 41 | +setTimeout(makeDefaultSearchTrieve, 50); |
| 42 | +setTimeout(makeDefaultSearchTrieve, 100); |
| 43 | +setTimeout(makeDefaultSearchTrieve, 250); |
| 44 | +setTimeout(makeDefaultSearchTrieve, 500); |
| 45 | +setTimeout(makeDefaultSearchTrieve, 1000); |
| 46 | +setTimeout(makeDefaultSearchTrieve, 2000); |
| 47 | +setTimeout(makeDefaultSearchTrieve, 3000); |
| 48 | + |
| 49 | +(async function () { |
| 50 | + "use strict"; |
| 51 | + const link = document.createElement("link"); |
| 52 | + link.rel = "stylesheet"; |
| 53 | + link.href = "https://cdn.trieve.ai/beta/search-component/index.css"; |
| 54 | + document.head.appendChild(link); |
| 55 | + |
| 56 | + import("https://cdn.trieve.ai/beta/search-component/vanilla/index.js").then( |
| 57 | + async (module) => { |
| 58 | + const { renderToDiv } = module; |
| 59 | + const root = document.createElement("div"); |
| 60 | + root.classList.add("trigger"); |
| 61 | + document.body.appendChild(root); |
| 62 | + const colorScheme = document.documentElement?.style?.colorScheme; |
| 63 | + const brandColor = colorScheme === "dark" ? "#47ffb6d5" : "#00551dcd"; |
| 64 | + |
| 65 | + renderToDiv(root, { |
| 66 | + apiKey: "tr-hZMKSsTf3ML9hJbAAqPO8K91p9IVe9Oc", |
| 67 | + datasetId: "d3493dc0-2b5c-4c6e-a8ee-b18feeed5b06", |
| 68 | + baseUrl: "https://api.trieve.ai", |
| 69 | + type: "docs", |
| 70 | + analytics: true, |
| 71 | + theme: colorScheme === "dark" ? "dark" : null, |
| 72 | + brandLogoImgSrcUrl: |
| 73 | + "https://storage.googleapis.com/organization-image-assets/vapi-botAvatarDarkSrcUrl-1709929110474.png", |
| 74 | + brandName: "Vapi", |
| 75 | + brandColor: brandColor, |
| 76 | + placeholder: "How can I help?", |
| 77 | + defaultSearchQueries: ["quickstart", "assistant", "tools"], |
| 78 | + defaultAiQuestions: [ |
| 79 | + "What voices are supported?", |
| 80 | + "What languages are supported?", |
| 81 | + "How do I connect a custom LLM?", |
| 82 | + "How do I fetch the prompt dynamically?", |
| 83 | + ], |
| 84 | + defaultSearchMode: "search", |
| 85 | + showFloatingButton: "true", |
| 86 | + cssRelease: "none", |
| 87 | + hideOpenButton: true, |
| 88 | + }); |
| 89 | + }, |
| 90 | + (error) => { |
| 91 | + console.error("Failed to load module:", error); |
| 92 | + } |
| 93 | + ); |
| 94 | +})(); |
0 commit comments