mirror of
https://github.com/open-webui/extension
synced 2025-06-26 18:25:58 +00:00
feat: highlighted text as input
This commit is contained in:
parent
7282c32565
commit
97a4897da2
@ -1,10 +1,21 @@
|
|||||||
// chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
||||||
// // read changeInfo data and do something with it (like read the url)
|
console.log(request, sender);
|
||||||
// if (changeInfo.url) {
|
const id = sender.tab.id;
|
||||||
// // do something here
|
if (request.method == "getSelection") {
|
||||||
// chrome.tabs.sendMessage(tabId, {
|
chrome.scripting
|
||||||
// message: "urlChange",
|
.executeScript({
|
||||||
// url: changeInfo.url,
|
target: { tabId: id, allFrames: true },
|
||||||
// });
|
func: () => {
|
||||||
// }
|
return window.getSelection().toString();
|
||||||
// });
|
},
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res);
|
||||||
|
sendResponse({ data: res[0]["result"] });
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
sendResponse({});
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|||||||
@ -23,4 +23,4 @@ function injectCSS(file) {
|
|||||||
|
|
||||||
// Inject the CSS and JS files
|
// Inject the CSS and JS files
|
||||||
injectCSS(chrome.runtime.getURL("extension/dist/style.css"));
|
injectCSS(chrome.runtime.getURL("extension/dist/style.css"));
|
||||||
injectScript(chrome.runtime.getURL("extension/dist/main.js"), "body");
|
// injectScript(chrome.runtime.getURL("extension/dist/main.js"), "body");
|
||||||
|
|||||||
2
extension/dist/main.js
vendored
2
extension/dist/main.js
vendored
File diff suppressed because one or more lines are too long
@ -6,7 +6,7 @@ export const SpotlightSearch = () => {
|
|||||||
|
|
||||||
// Toggle the menu when ⌘Space+Shift is pressed
|
// Toggle the menu when ⌘Space+Shift is pressed
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const down = (e) => {
|
const down = async (e) => {
|
||||||
if (
|
if (
|
||||||
e.key === " " &&
|
e.key === " " &&
|
||||||
(e.metaKey || e.ctrlKey) &&
|
(e.metaKey || e.ctrlKey) &&
|
||||||
@ -14,6 +14,15 @@ export const SpotlightSearch = () => {
|
|||||||
) {
|
) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setOpen((open) => !open);
|
setOpen((open) => !open);
|
||||||
|
|
||||||
|
const response = await chrome.runtime.sendMessage({
|
||||||
|
method: "getSelection",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response?.data ?? false) {
|
||||||
|
setSearchValue(response.data);
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const inputElement = document.getElementById(
|
const inputElement = document.getElementById(
|
||||||
"open-webui-search-input"
|
"open-webui-search-input"
|
||||||
@ -40,6 +49,8 @@ export const SpotlightSearch = () => {
|
|||||||
setSearchValue("");
|
setSearchValue("");
|
||||||
|
|
||||||
window.open(`http://localhost:8080/?q=${searchValue}`, "_blank");
|
window.open(`http://localhost:8080/?q=${searchValue}`, "_blank");
|
||||||
|
|
||||||
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return open ? (
|
return open ? (
|
||||||
|
|||||||
@ -18,7 +18,8 @@
|
|||||||
"<all_urls>"
|
"<all_urls>"
|
||||||
],
|
],
|
||||||
"js": [
|
"js": [
|
||||||
"content.js"
|
"content.js",
|
||||||
|
"extension/dist/main.js"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -36,6 +37,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"storage"
|
"storage",
|
||||||
|
"scripting"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user