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) {
|
||||
// // 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,
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
||||
console.log(request, sender);
|
||||
const id = sender.tab.id;
|
||||
if (request.method == "getSelection") {
|
||||
chrome.scripting
|
||||
.executeScript({
|
||||
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
|
||||
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
|
||||
useEffect(() => {
|
||||
const down = (e) => {
|
||||
const down = async (e) => {
|
||||
if (
|
||||
e.key === " " &&
|
||||
(e.metaKey || e.ctrlKey) &&
|
||||
@ -14,6 +14,15 @@ export const SpotlightSearch = () => {
|
||||
) {
|
||||
e.preventDefault();
|
||||
setOpen((open) => !open);
|
||||
|
||||
const response = await chrome.runtime.sendMessage({
|
||||
method: "getSelection",
|
||||
});
|
||||
|
||||
if (response?.data ?? false) {
|
||||
setSearchValue(response.data);
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
const inputElement = document.getElementById(
|
||||
"open-webui-search-input"
|
||||
@ -40,6 +49,8 @@ export const SpotlightSearch = () => {
|
||||
setSearchValue("");
|
||||
|
||||
window.open(`http://localhost:8080/?q=${searchValue}`, "_blank");
|
||||
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
return open ? (
|
||||
|
@ -18,7 +18,8 @@
|
||||
"<all_urls>"
|
||||
],
|
||||
"js": [
|
||||
"content.js"
|
||||
"content.js",
|
||||
"extension/dist/main.js"
|
||||
]
|
||||
}
|
||||
],
|
||||
@ -36,6 +37,7 @@
|
||||
}
|
||||
],
|
||||
"permissions": [
|
||||
"storage"
|
||||
"storage",
|
||||
"scripting"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user