-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
haq
committed
Jan 22, 2025
0 parents
commit 7f6d104
Showing
5 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# KagiTranslate extension | ||
|
||
This is unofficial, obviously, but it serves as an extension which lets you open the current url in kagi translate. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
chrome.action.onClicked.addListener(async (tab) => { | ||
const [result] = await chrome.scripting.executeScript({ | ||
target: { tabId: tab.id }, | ||
func: () => window.getSelection().toString().trim() | ||
}); | ||
|
||
const baseUrl = 'https://translate.kagi.com/'; | ||
let translatedUrl; | ||
|
||
if (result.result) { | ||
translatedUrl = `${baseUrl}?text=${encodeURIComponent(result.result)}`; | ||
} else { | ||
translatedUrl = `${baseUrl}?url=${encodeURIComponent(tab.url)}`; | ||
} | ||
|
||
chrome.tabs.create({ url: translatedUrl }); | ||
}); | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"manifest_version": 3, | ||
"name": "Kagi Translate", | ||
"version": "1.0", | ||
"icons": { | ||
"16": "icon16.png", | ||
"48": "icon48.png", | ||
"128": "icon48.png" | ||
}, | ||
"action": { | ||
"default_icon": { | ||
"16": "icon16.png", | ||
"48": "icon48.png" | ||
}, | ||
"default_title": "Translate Page/Text" | ||
}, | ||
"permissions": ["scripting"], | ||
"host_permissions": ["<all_urls>"], | ||
"background": { | ||
"service_worker": "background.js" | ||
} | ||
} |