Skip to content

Commit

Permalink
update: only works when push icon
Browse files Browse the repository at this point in the history
  • Loading branch information
makinzm committed Jan 3, 2025
1 parent 5cc3586 commit c9f07f0
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dist/background.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/content_script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed dist/extention.zip
Binary file not shown.
7 changes: 0 additions & 7 deletions dist/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
"description": "Improve your English vocabulary with ClipLex",
"permissions": ["storage", "activeTab", "scripting"],
"options_page": "options/options.html",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content_script.js"],
"run_at": "document_idle"
}
],
"background": {
"service_worker": "background.js"
},
Expand Down
2 changes: 2 additions & 0 deletions privacy_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
- **理由**: ClipLexのスクリプトをウェブページに挿入し、選択されたテキストを取得するために必要です。
3. **`storage`**
- **理由**:選択したテキストやフィルタ設定をローカルに保存するために必要です。
4. **ホスト権限(`<all_urls>`**
- **理由**:activeTabで許可されたタブのすべてのコンテンツにスムーズにClipLexスクリプトを挿入するために必要です。

これらの権限は、本拡張機能の動作に必要な最小限の範囲に限定されています。

Expand Down
19 changes: 16 additions & 3 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@ import { LocalDatabase } from "./database";

chrome.action.onClicked.addListener((tab) => {
if (tab.id && tab.url) {
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["content_script.js"], // 動的に注入するスクリプト
chrome.tabs.sendMessage(tab.id, { type: "CHECK_SCRIPT" }, (response) => {
if (chrome.runtime.lastError || !response || !response.injected) {
// スクリプトが未注入の場合、注入する
chrome.scripting.executeScript({
target: { tabId: tab.id! },
files: ["content_script.js"],
})
.then(() => {
console.log("Content script injected successfully.");
})
.catch(err => {
console.error("Failed to inject content script:", err);
});
} else {
console.log("Content script already injected.");
}
});
}
});
Expand Down
6 changes: 6 additions & 0 deletions src/content_script.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { checkDomainFilterMode } from "./content_script_helper";

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "CHECK_SCRIPT") {
sendResponse({ injected: true });
}
});

// 既存: background.ts と通信して save するための Promiseラッパー関数
async function saveEntryToBackground(entry: WordEntry): Promise<void> {
return new Promise<void>((resolve, reject) => {
Expand Down
7 changes: 0 additions & 7 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
"description": "Improve your English vocabulary with ClipLex",
"permissions": ["storage", "activeTab", "scripting"],
"options_page": "options/options.html",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content_script.js"],
"run_at": "document_idle"
}
],
"background": {
"service_worker": "background.js"
},
Expand Down

0 comments on commit c9f07f0

Please sign in to comment.