Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "selection-command-monorepo",
"version": "1.0.0",
"version": "1.1.0",
"private": true,
"description": "Selection Command - Monorepo for Chrome Extension and Hub",
"author": "ujiro99",
Expand Down
14 changes: 14 additions & 0 deletions packages/extension/e2e/generated-command-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,36 @@ export const COMMAND_URLS: UrlEntry[] = [
{ title: "Netflix", locale: "en", searchUrl: "https://www.netflix.com/search?q=%s" },
{ title: "Pinterest", locale: "en", searchUrl: "https://www.pinterest.com/search/pins/?q=%s" },
{ title: "Drive", locale: "en", searchUrl: "https://drive.google.com/drive/search?q=%s" },
{ title: "Search Commands on Hub", locale: "en", searchUrl: "https://selection-command.com/en?q=%pageUrl" },
{ title: "Amazon", locale: "ja", searchUrl: "https://www.amazon.co.jp/s?k=%s" },
{ title: "Yahoo! Japan", locale: "ja", searchUrl: "https://search.yahoo.co.jp/search?p=%s" },
{ title: "en to ja", locale: "ja", searchUrl: "https://translate.google.co.jp/?hl=ja&sl=auto&text=%s&op=translate" },
{ title: "コマンドをHubで検索", locale: "ja", searchUrl: "https://selection-command.com/ja?q=%pageUrl" },
{ title: "百度", locale: "zh", searchUrl: "https://www.baidu.com/s?wd=%s" },
{ title: "京东", locale: "zh", searchUrl: "https://search.jd.com/Search?keyword=%s" },
{ title: "哔哩哔哩", locale: "zh", searchUrl: "https://search.bilibili.com/all?keyword=%s" },
{ title: "在 Hub 中搜索命令", locale: "zh", searchUrl: "https://selection-command.com/zh-CN?q=%pageUrl" },
{ title: "네이버", locale: "ko", searchUrl: "https://search.naver.com/search.naver?query=%s" },
{ title: "Hub에서 명령어 검색", locale: "ko", searchUrl: "https://selection-command.com/ko?q=%pageUrl" },
{ title: "Яндекс", locale: "ru", searchUrl: "https://yandex.ru/search/?text=%s" },
{ title: "ВКонтакте", locale: "ru", searchUrl: "https://vk.com/search?c%5Bq%5D=%s" },
{ title: "Поиск команд в Hub", locale: "ru", searchUrl: "https://selection-command.com/ru?q=%pageUrl" },
{ title: "Befehle im Hub suchen", locale: "de", searchUrl: "https://selection-command.com/de?q=%pageUrl" },
{ title: "Rechercher des commandes sur Hub", locale: "fr", searchUrl: "https://selection-command.com/fr?q=%pageUrl" },
{ title: "Amazon", locale: "es", searchUrl: "https://www.amazon.es/s?k=%s" },
{ title: "El Corte Inglés", locale: "es", searchUrl: "https://www.elcorteingles.es/search-nwx/?s=%s" },
{ title: "AliExpress", locale: "es", searchUrl: "https://es.aliexpress.com/w/wholesale-%s.html" },
{ title: "Buscar comandos en Hub", locale: "es", searchUrl: "https://selection-command.com/es?q=%pageUrl" },
{ title: "Pesquisar comandos no Hub", locale: "pt-br", searchUrl: "https://selection-command.com/pt-BR?q=%pageUrl" },
{ title: "OLX", locale: "pt", searchUrl: "https://www.olx.pt/ads/?q=%s" },
{ title: "Pesquisar comandos no Hub", locale: "pt", searchUrl: "https://selection-command.com/pt-PT?q=%pageUrl" },
{ title: "Hub पर कमांड खोजें", locale: "hi", searchUrl: "https://selection-command.com/hi?q=%pageUrl" },
{ title: "Tokopedia", locale: "id", searchUrl: "https://www.tokopedia.com/search?st=product&q=%s" },
{ title: "Shopee", locale: "id", searchUrl: "https://shopee.co.id/search?keyword=%s" },
{ title: "Cari Perintah di Hub", locale: "id", searchUrl: "https://selection-command.com/id?q=%pageUrl" },
{ title: "Shopee", locale: "ms", searchUrl: "https://shopee.com.my/search?keyword=%s" },
{ title: "Lazada", locale: "ms", searchUrl: "https://www.lazada.com.my/catalog/?q=%s" },
{ title: "Cari Perintah di Hub", locale: "ms", searchUrl: "https://selection-command.com/ms?q=%pageUrl" },
{ title: "Zalando.it", locale: "it", searchUrl: "https://www.zalando.it/catalogo/?q=%s" },
{ title: "Cerca comandi su Hub", locale: "it", searchUrl: "https://selection-command.com/it?q=%pageUrl" },
]
3 changes: 2 additions & 1 deletion packages/extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "__MSG_extName__",
"description": "__MSG_extDescription__",
"version": "1.0.0",
"version": "1.1.0",
"default_locale": "en",
"icons": {
"128": "icon128.png"
Expand Down Expand Up @@ -81,6 +81,7 @@
],
"resources": [
"assets/*.css",
"images/*",
"icon128.png"
]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@selection-command/extension",
"version": "1.0.0",
"version": "1.1.0",
"private": true,
"author": "ujiro99",
"license": "MIT",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 1 addition & 6 deletions packages/extension/src/action/aiPrompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
faviconUrl: "",
inputSelectors: [".ql-editor"],
submitSelectors: ["button.send"],
selectorType: "css" as any,

Check warning on line 62 in packages/extension/src/action/aiPrompt.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
...overrides,
})

Expand All @@ -70,7 +70,7 @@
faviconUrl: "",
inputSelectors: ["#prompt-textarea"],
submitSelectors: ["button#submit"],
selectorType: "css" as any,

Check warning on line 73 in packages/extension/src/action/aiPrompt.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
queryUrl: "https://chatgpt.com/?prompt=%s",
autoSubmit: false,
...overrides,
Expand All @@ -83,7 +83,7 @@
faviconUrl: "",
inputSelectors: ["div#ask-input"],
submitSelectors: ["button[aria-label='Submit']"],
selectorType: "css" as any,

Check warning on line 86 in packages/extension/src/action/aiPrompt.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
queryUrl: "https://www.perplexity.ai/search/new?q=%s",
autoSubmit: true,
urlToMarkdown: true,
Expand All @@ -106,11 +106,6 @@
describe("AiPrompt.execute", () => {
beforeEach(() => {
vi.clearAllMocks()
// Mock location.href for content script context
Object.defineProperty(window, "location", {
value: { href: "https://example.com/page" },
writable: true,
})
})

describe("DOM input approach (no queryUrl)", () => {
Expand All @@ -125,7 +120,7 @@
...baseCommand.aiPromptOption,
serviceId: "gemini",
},
} as any,

Check warning on line 123 in packages/extension/src/action/aiPrompt.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
position: { x: 100, y: 100 },
})

Expand Down Expand Up @@ -155,13 +150,13 @@
...baseCommand.aiPromptOption,
serviceId: "gemini",
},
} as any,

Check warning on line 153 in packages/extension/src/action/aiPrompt.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
position: { x: 100, y: 100 },
})

const sentArgs = vi.mocked(Ipc.send).mock.calls[0][1] as any

Check warning on line 157 in packages/extension/src/action/aiPrompt.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
const clickStep = sentArgs.steps.find(
(s: any) => s.param.type === PAGE_ACTION_EVENT.click,

Check warning on line 159 in packages/extension/src/action/aiPrompt.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
)
expect(clickStep.param.condition).toEqual({
actionType: PAGE_ACTION_CONDITION_ACTION.waitUntil,
Expand All @@ -184,7 +179,7 @@
serviceId: "gemini",
prompt: `${toInsertTemplate(INSERT.PAGE_HTML)} and again ${toInsertTemplate(INSERT.PAGE_HTML)}`,
},
} as any,

Check warning on line 182 in packages/extension/src/action/aiPrompt.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
position: { x: 100, y: 100 },
})

Expand Down Expand Up @@ -217,7 +212,7 @@
serviceId: "gemini",
prompt: `${toInsertTemplate(INSERT.PAGE_HTML)} ${toInsertTemplate(INSERT.SELECTION_HTML)}`,
},
} as any,

Check warning on line 215 in packages/extension/src/action/aiPrompt.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
position: { x: 100, y: 100 },
})

Expand Down Expand Up @@ -565,10 +560,10 @@
},
} as any,
position: { x: 0, y: 0 },
pageUrl: "https://example.com/page",
})

const sentArgs = vi.mocked(Ipc.send).mock.calls[0][1] as any
// location.href is "https://example.com/page" from beforeEach mock
expect(sentArgs.url.selectionText).toBe(
"Summarize [https://example.com/page](https://example.com/page)",
)
Expand Down
7 changes: 4 additions & 3 deletions packages/extension/src/action/aiPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const AiPrompt = {
position,
useSecondary,
useClipboard,
pageUrl,
}: ExecuteCommandParams) {
if (!isAiPromptType(command)) {
console.error("command is not for AiPrompt.")
Expand Down Expand Up @@ -128,7 +129,7 @@ export const AiPrompt = {
// is false and the DOM input approach is used instead.
const expandedPrompt = safeInterpolate(aiPromptOption.prompt, {
[InsertSymbol[INSERT.SELECTED_TEXT]]: selectionText,
[InsertSymbol[INSERT.URL]]: location.href,
[InsertSymbol[INSERT.URL]]: pageUrl ?? "",
[InsertSymbol[INSERT.LANG]]: getUILanguage(),
})

Expand Down Expand Up @@ -359,7 +360,7 @@ export const AiPrompt = {
url: serviceUrl,
steps,
selectedText: selectionText,
srcUrl: location.href,
srcUrl: pageUrl ?? "",
clipboardText: "",
useClipboard:
!useQueryUrl && (needClipboard || (useClipboard ?? false)),
Expand Down Expand Up @@ -407,7 +408,7 @@ export const AiPrompt = {
height: command.popupOption?.height ?? PopupOption.height,
width: command.popupOption?.width ?? PopupOption.width,
selectedText: selectionText,
srcUrl: location.href,
srcUrl: pageUrl ?? "",
openMode,
pageHtml,
selectionHtml,
Expand Down
2 changes: 2 additions & 0 deletions packages/extension/src/action/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export async function execute({
useSecondary = false,
useClipboard = false,
changeState,
pageUrl,
}: ExecuteCommandParams) {
return executeAction({
command,
Expand All @@ -36,6 +37,7 @@ export async function execute({
useSecondary,
useClipboard,
changeState,
pageUrl,
actions: actionsForBackground,
})
}
2 changes: 2 additions & 0 deletions packages/extension/src/action/backgroundTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const BackgroundTab = {
selectionText,
command,
useClipboard,
pageUrl,
}: ExecuteCommandParams) {
if (!isValidString(command.searchUrl)) {
console.error("searchUrl is not valid.")
Expand All @@ -21,6 +22,7 @@ export const BackgroundTab = {
spaceEncoding: command.spaceEncoding ?? SPACE_ENCODING.PLUS,
selectionText,
useClipboard: useClipboard ?? false,
pageUrl: pageUrl ?? "",
},
active: false,
})
Expand Down
2 changes: 2 additions & 0 deletions packages/extension/src/action/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export async function executeAction({
useSecondary = false,
useClipboard = false,
changeState,
pageUrl,
}: ExecuteCommandParams & { actions: Record<string, any> }) {
let mode = command.openMode as OPEN_MODE
if (
Expand All @@ -30,6 +31,7 @@ export async function executeAction({
useClipboard,
changeState: changeState ?? (() => {}),
target: target ?? null,
pageUrl,
})

const { sourceType, sourceId } = resolveCommandSource(command)
Expand Down
3 changes: 3 additions & 0 deletions packages/extension/src/action/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export async function execute({
useSecondary,
useClipboard,
changeState,
// This module only ever runs in the content script's page context, so
// location.href here correctly reflects the visited page.
pageUrl: location.href,
actions,
})
}
4 changes: 3 additions & 1 deletion packages/extension/src/action/pageAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const PageAction = {
useSecondary,
useClipboard,
userVariables,
pageUrl,
}: ExecuteCommandParams & PageActionParams) {
if (!isPageActionCommand(command)) {
console.error("command is not for PageAction.")
Expand Down Expand Up @@ -46,6 +47,7 @@ export const PageAction = {
searchUrl: command.pageActionOption.startUrl,
selectionText,
useClipboard: needClipboard || (useClipboard ?? false),
pageUrl: pageUrl ?? "",
}

const openMode = useSecondary
Expand All @@ -68,7 +70,7 @@ export const PageAction = {
height: command.popupOption?.height ?? PopupOption.height,
width: command.popupOption?.width ?? PopupOption.width,
selectedText: selectionText,
srcUrl: location.href,
srcUrl: pageUrl ?? "",
openMode,
userVariables: userVariables ?? command.pageActionOption.userVariables,
})
Expand Down
2 changes: 2 additions & 0 deletions packages/extension/src/action/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const Popup = {
command,
position,
useClipboard,
pageUrl,
}: ExecuteCommandParams) {
if (!isValidString(command.searchUrl)) {
console.error("searchUrl is not valid.")
Expand All @@ -31,6 +32,7 @@ export const Popup = {
spaceEncoding: command.spaceEncoding ?? SPACE_ENCODING.PLUS,
selectionText,
useClipboard: useClipboard ?? false,
pageUrl: pageUrl ?? "",
},
top: Math.floor(windowPosition.top + position.y),
left: Math.floor(windowPosition.left + position.x),
Expand Down
2 changes: 2 additions & 0 deletions packages/extension/src/action/sidePanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const SidePanel = {
selectionText,
command,
useClipboard,
pageUrl,
}: ExecuteCommandParams) {
if (!isValidString(command.searchUrl)) {
console.error("searchUrl is not valid.")
Expand Down Expand Up @@ -39,6 +40,7 @@ export const SidePanel = {
spaceEncoding: command.spaceEncoding ?? SPACE_ENCODING.PLUS,
selectionText,
useClipboard: useClipboard ?? false,
pageUrl: pageUrl ?? "",
},
clipboardText,
)
Expand Down
2 changes: 2 additions & 0 deletions packages/extension/src/action/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const Tab = {
selectionText,
command,
useClipboard,
pageUrl,
}: ExecuteCommandParams) {
if (!isValidString(command.searchUrl)) {
console.error("searchUrl is not valid.")
Expand All @@ -21,6 +22,7 @@ export const Tab = {
spaceEncoding: command.spaceEncoding ?? SPACE_ENCODING.PLUS,
selectionText,
useClipboard: useClipboard ?? false,
pageUrl: pageUrl ?? "",
},
active: true,
})
Expand Down
2 changes: 2 additions & 0 deletions packages/extension/src/action/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const Window = {
command,
position,
useClipboard,
pageUrl,
}: ExecuteCommandParams) {
if (!isValidString(command.searchUrl)) {
console.error("searchUrl is not valid.")
Expand All @@ -31,6 +32,7 @@ export const Window = {
spaceEncoding: command.spaceEncoding ?? SPACE_ENCODING.PLUS,
selectionText,
useClipboard: useClipboard ?? false,
pageUrl: pageUrl ?? "",
},
top: Math.floor(windowPosition.top + position.y),
left: Math.floor(windowPosition.left + position.x),
Expand Down
1 change: 1 addition & 0 deletions packages/extension/src/background_script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ describe("Background Script Migration", () => {
selectionText: "test selection text",
target: null,
useClipboard: false,
pageUrl: "https://example.com",
}),
)
})
Expand Down
1 change: 1 addition & 0 deletions packages/extension/src/background_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ chrome.commands.onCommand.addListener(async (commandName) => {
selectionText,
target: null,
useClipboard,
pageUrl: tab?.url ?? "",
})
}
sendEvent(
Expand Down
Loading
Loading