|
| 1 | +// ==UserScript== |
| 2 | +// @name Coolify |
| 3 | +// @namespace http://tampermonkey.net/ |
| 4 | +// @version 2025-01-16 |
| 5 | +// @description try to take over the world! |
| 6 | +// @author You |
| 7 | +// @match https://coolify.io/docs/* |
| 8 | +// @icon https://www.google.com/s2/favicons?sz=64&domain=coolify.io |
| 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('#local-search > button')) { |
| 24 | + defaultSearchBar = el.querySelector('#local-search > button'); |
| 25 | + break; |
| 26 | + } |
| 27 | + } |
| 28 | + retries++; |
| 29 | + await new Promise((resolve) => setTimeout(resolve, 10)); |
| 30 | + } |
| 31 | + |
| 32 | + if (!defaultSearchBar) { |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + defaultSearchBar = removeAllClickListeners(defaultSearchBar); |
| 37 | + |
| 38 | + defaultSearchBar.onclick = () => { |
| 39 | + const event = new CustomEvent("trieve-open-with-text", { |
| 40 | + detail: { text: "" }, |
| 41 | + }); |
| 42 | + window.dispatchEvent(event); |
| 43 | + }; |
| 44 | +}; |
| 45 | + |
| 46 | +window.addEventListener('load', function() { |
| 47 | + makeDefaultSearchTrieve(); |
| 48 | +}); |
| 49 | + |
| 50 | +const originalPushState = history.pushState; |
| 51 | +history.pushState = function() { |
| 52 | + originalPushState.apply(this, arguments); |
| 53 | + makeDefaultSearchTrieve(); |
| 54 | +}; |
| 55 | + |
| 56 | + |
| 57 | +(async function () { |
| 58 | + "use strict"; |
| 59 | + const link = document.createElement("link"); |
| 60 | + link.rel = "stylesheet"; |
| 61 | + link.href = "https://cdn.trieve.ai/beta/search-component/index.css"; |
| 62 | + document.head.appendChild(link); |
| 63 | + |
| 64 | + import("https://cdn.trieve.ai/beta/search-component/vanilla/index.js").then( |
| 65 | + async (module) => { |
| 66 | + const { renderToDiv } = module; |
| 67 | + const root = document.createElement("div"); |
| 68 | + root.classList.add("trigger"); |
| 69 | + document.body.appendChild(root); |
| 70 | + const colorScheme = document.documentElement?.classList?.contains("dark") |
| 71 | + ? "dark" |
| 72 | + : null; |
| 73 | + |
| 74 | + renderToDiv(root, { |
| 75 | + apiKey: "tr-4ge266qRg6AzfMAyWyqqUjmG3VC1CYYM", |
| 76 | + datasetId: "cae68afa-93e1-4fb2-9945-693e65906409", |
| 77 | + baseUrl: "https://api.trieve.ai", |
| 78 | + type: "docs", |
| 79 | + analytics: true, |
| 80 | + theme: colorScheme === "dark" ? "dark" : null, |
| 81 | + brandLogoImgSrcUrl: "https://coolify.io/docs/coolify-logo-transparent.png", |
| 82 | + brandName: "Coolify", |
| 83 | + brandColor: "#9664f3", |
| 84 | + placeholder: "How can I help?", |
| 85 | + defaultSearchQueries: ["Backups", "Postgresql", "Private NPM registry"], |
| 86 | + defaultAiQuestions: ["How to fix expired GitHub personal access token (PAT)?", "My Raspberry Pi is crashing", "How to use Docker Compose?"], |
| 87 | + defaultSearchMode: "search", |
| 88 | + showFloatingButton: "true", |
| 89 | + cssRelease: "none", |
| 90 | + hideOpenButton: true, |
| 91 | + }); |
| 92 | + }, |
| 93 | + (error) => { |
| 94 | + console.error("Failed to load module:", error); |
| 95 | + } |
| 96 | + ); |
| 97 | +})(); |
0 commit comments