mirror of
https://github.com/open-webui/extension
synced 2025-06-26 18:25:58 +00:00
init
This commit is contained in:
commit
86d45a9f7e
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.env
|
||||
.DS_Store
|
10
background.js
Normal file
10
background.js
Normal file
@ -0,0 +1,10 @@
|
||||
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
||||
// read changeInfo data and do something with it (like read the url)
|
||||
if (changeInfo.url) {
|
||||
// do something here
|
||||
chrome.tabs.sendMessage(tabId, {
|
||||
message: "urlChange",
|
||||
url: changeInfo.url,
|
||||
});
|
||||
}
|
||||
});
|
26
content.js
Normal file
26
content.js
Normal file
@ -0,0 +1,26 @@
|
||||
// Create a div to host the React app
|
||||
const appDiv = document.createElement("div");
|
||||
appDiv.id = "extension-app";
|
||||
document.body.appendChild(appDiv);
|
||||
|
||||
// Function to inject a script
|
||||
function injectScript(file, node) {
|
||||
const th = document.getElementsByTagName(node)[0];
|
||||
const s = document.createElement("script");
|
||||
s.setAttribute("type", "text/javascript");
|
||||
s.setAttribute("src", file);
|
||||
th.appendChild(s);
|
||||
}
|
||||
|
||||
// Function to inject a CSS file
|
||||
function injectCSS(file) {
|
||||
const link = document.createElement("link");
|
||||
link.href = file;
|
||||
link.type = "text/css";
|
||||
link.rel = "stylesheet";
|
||||
document.getElementsByTagName("head")[0].appendChild(link);
|
||||
}
|
||||
|
||||
// Inject the CSS and JS files
|
||||
injectCSS(chrome.runtime.getURL("extension/dist/style.css"));
|
||||
injectScript(chrome.runtime.getURL("extension/dist/main.js"), "body");
|
21
extension/.eslintrc.cjs
Normal file
21
extension/.eslintrc.cjs
Normal file
@ -0,0 +1,21 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: { browser: true, es2020: true },
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:react/recommended',
|
||||
'plugin:react/jsx-runtime',
|
||||
'plugin:react-hooks/recommended',
|
||||
],
|
||||
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
||||
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
|
||||
settings: { react: { version: '18.2' } },
|
||||
plugins: ['react-refresh'],
|
||||
rules: {
|
||||
'react/jsx-no-target-blank': 'off',
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
},
|
||||
}
|
24
extension/.gitignore
vendored
Normal file
24
extension/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
12
extension/index.html
Normal file
12
extension/index.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Open WebUI Extension</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="extension-app"></div>
|
||||
<script type="module" src="./src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
5356
extension/package-lock.json
generated
Normal file
5356
extension/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
extension/package.json
Normal file
29
extension/package.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "extension",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.2.66",
|
||||
"@types/react-dom": "^18.2.22",
|
||||
"@vitejs/plugin-react": "^4.2.1",
|
||||
"autoprefixer": "^10.4.19",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-plugin-react": "^7.34.1",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.6",
|
||||
"postcss": "^8.4.38",
|
||||
"tailwindcss": "^3.4.3",
|
||||
"vite": "^5.2.0"
|
||||
}
|
||||
}
|
6
extension/postcss.config.js
Normal file
6
extension/postcss.config.js
Normal file
@ -0,0 +1,6 @@
|
||||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
10
extension/src/App.jsx
Normal file
10
extension/src/App.jsx
Normal file
@ -0,0 +1,10 @@
|
||||
import { SpotlightSearch } from "./components/SpotlightSearch";
|
||||
function App() {
|
||||
return (
|
||||
<>
|
||||
<SpotlightSearch />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
80
extension/src/components/SpotlightSearch.jsx
Normal file
80
extension/src/components/SpotlightSearch.jsx
Normal file
@ -0,0 +1,80 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
export const SpotlightSearch = () => {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [searchValue, setSearchValue] = useState("");
|
||||
|
||||
// Toggle the menu when ⌘K is pressed
|
||||
useEffect(() => {
|
||||
const down = (e) => {
|
||||
if (
|
||||
e.key === "k" &&
|
||||
(e.metaKey || e.ctrlKey) &&
|
||||
(e.shiftKey || e.altKey)
|
||||
) {
|
||||
e.preventDefault();
|
||||
setOpen((open) => !open);
|
||||
setTimeout(() => {
|
||||
document.getElementById("open-webui-search-input").focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
if (e.key === "Escape") {
|
||||
setOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener("keydown", down);
|
||||
return () => document.removeEventListener("keydown", down);
|
||||
}, []);
|
||||
|
||||
const submitHandler = (e) => {
|
||||
e.preventDefault();
|
||||
console.log(searchValue);
|
||||
setSearchValue("");
|
||||
|
||||
window.open(`http://localhost:8080/?q=${searchValue}`, "_blank");
|
||||
};
|
||||
|
||||
return open ? (
|
||||
<div className="fixed top-0 right-0 left-0 bottom-0 w-full min-h-screen h-screen flex justify-center z-[9999999999] overflow-hidden overscroll-contain">
|
||||
<div className=" m-auto max-w-xl w-full pb-32">
|
||||
<div className="w-full flex flex-col justify-between py-2.5 px-3.5 rounded-2xl outline outline-1 outline-gray-900 backdrop-blur-3xl bg-gray-850/70 shadow-4xl modal-animation">
|
||||
<form className="text-gray-200 w-full" onSubmit={submitHandler}>
|
||||
<div className="flex items-center gap-2 w-full">
|
||||
<div>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
strokeWidth={2.5}
|
||||
stroke="currentColor"
|
||||
className="size-5"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<input
|
||||
id="open-webui-search-input"
|
||||
placeholder="Search Open WebUI"
|
||||
className="text-xl w-full font-medium bg-transparent placeholder:text-gray-500 text-neutral-100 outline-none"
|
||||
value={searchValue}
|
||||
onChange={(e) => setSearchValue(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<p className="text-right text-[0.7rem] text-neutral-300">
|
||||
Press <code>⌘K</code> to toggle
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<> </>
|
||||
);
|
||||
};
|
36
extension/src/index.css
Normal file
36
extension/src/index.css
Normal file
@ -0,0 +1,36 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer base {
|
||||
html,
|
||||
pre {
|
||||
font-family: -apple-system, ui-sans-serif, system-ui, "Segoe UI", Roboto,
|
||||
Ubuntu, Cantarell, "Noto Sans", sans-serif, "Helvetica Neue", Arial,
|
||||
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
|
||||
"Noto Color Emoji";
|
||||
}
|
||||
}
|
||||
|
||||
.shadow-3xl {
|
||||
box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.35);
|
||||
}
|
||||
|
||||
.shadow-4xl {
|
||||
box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.7);
|
||||
}
|
||||
|
||||
.modal-animation {
|
||||
animation: scaleUp 150ms cubic-bezier(0.25, 0.8, 0.25, 1);
|
||||
}
|
||||
|
||||
@keyframes scaleUp {
|
||||
from {
|
||||
transform: scale(0.9);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
10
extension/src/main.jsx
Normal file
10
extension/src/main.jsx
Normal file
@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App.jsx'
|
||||
import './index.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('extension-app')).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
)
|
25
extension/tailwind.config.js
Normal file
25
extension/tailwind.config.js
Normal file
@ -0,0 +1,25 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
gray: {
|
||||
50: "#f9f9f9",
|
||||
100: "#ececec",
|
||||
200: "#e3e3e3",
|
||||
300: "#cdcdcd",
|
||||
400: "#b4b4b4",
|
||||
500: "#9b9b9b",
|
||||
600: "#676767",
|
||||
700: "#4e4e4e",
|
||||
800: "#333",
|
||||
850: "#262626",
|
||||
900: "var(--color-gray-900, #171717)",
|
||||
950: "var(--color-gray-950, #0d0d0d)",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
18
extension/vite.config.js
Normal file
18
extension/vite.config.js
Normal file
@ -0,0 +1,18 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {
|
||||
dir: "dist/",
|
||||
entryFileNames: "main.js",
|
||||
assetFileNames: "style.css",
|
||||
chunkFileNames: "chunk.js",
|
||||
manualChunks: undefined,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
BIN
images/icon-128.png
Normal file
BIN
images/icon-128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
BIN
images/icon-16.png
Normal file
BIN
images/icon-16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 364 B |
BIN
images/icon-32.png
Normal file
BIN
images/icon-32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 873 B |
BIN
images/icon-48.png
Normal file
BIN
images/icon-48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
41
manifest.json
Normal file
41
manifest.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "Open WebUI Extension",
|
||||
"description": "Open WebUI",
|
||||
"version": "1.0",
|
||||
"icons": {
|
||||
"16": "images/icon-16.png",
|
||||
"32": "images/icon-32.png",
|
||||
"48": "images/icon-48.png",
|
||||
"128": "images/icon-128.png"
|
||||
},
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": [
|
||||
"<all_urls>"
|
||||
],
|
||||
"js": [
|
||||
"content.js"
|
||||
]
|
||||
}
|
||||
],
|
||||
"host_permissions": [
|
||||
"<all_urls>"
|
||||
],
|
||||
"web_accessible_resources": [
|
||||
{
|
||||
"resources": [
|
||||
"extension/dist/*"
|
||||
],
|
||||
"matches": [
|
||||
"<all_urls>"
|
||||
]
|
||||
}
|
||||
],
|
||||
"permissions": [
|
||||
"storage"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user