Skip to content

Commit

Permalink
add base
Browse files Browse the repository at this point in the history
  • Loading branch information
haq committed Jan 22, 2025
0 parents commit 7f6d104
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
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.
18 changes: 18 additions & 0 deletions background.js
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 });
});

Binary file added icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions manifest.json
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"
}
}

0 comments on commit 7f6d104

Please sign in to comment.