generated from mnao305/webextension-typescript-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 全てのファイルを1つのフォルダーにダウンロードできるようにする (#497)
* feat: 全てのファイルを1つのフォルダに保存するためのオプション設定を追加 * feat: 全てのファイルを1つのフォルダーにダウンロードできるようにする
- Loading branch information
Showing
8 changed files
with
143 additions
and
9 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
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
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
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
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
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 |
---|---|---|
@@ -1,14 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Option</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div id="app"> | ||
|
||
<body> | ||
<div id="setting"> | ||
<ul> | ||
<li> | ||
<div> | ||
<label title="all_file_one_folder_description"><input type="checkbox" name="allFileOneFolder"><span data-locale="all_file_one_folder"></span></label> | ||
</div> | ||
</li> | ||
</ul> | ||
<button id="save">保存</button><span id="saveMsg">saved...</span> | ||
</div> | ||
|
||
<script src="index.js"></script> | ||
</body> | ||
|
||
</html> |
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,63 @@ | ||
import { browser } from 'webextension-polyfill-ts' | ||
|
||
export type Settings = { | ||
allFileOneFolder: boolean; | ||
}; | ||
|
||
/** | ||
* オプション画面が開かれたときに呼ばれる | ||
*/ | ||
const setup = async () => { | ||
// 翻訳文言を入れる | ||
document.querySelectorAll<HTMLElement>('[data-locale]').forEach((elem) => { | ||
elem.innerText = elem.dataset.locale | ||
? browser.i18n.getMessage(elem.dataset.locale) | ||
: '' | ||
}) | ||
// title属性がある場合はそれも入れる | ||
document.querySelectorAll<HTMLElement>('[title]').forEach((elem) => { | ||
elem.title = elem.title ? browser.i18n.getMessage(elem.title) : '' | ||
}) | ||
|
||
// 保存済みの設定を表示に反映 | ||
const settings = (await browser.storage.local.get({ | ||
allFileOneFolder: false | ||
})) as Settings | ||
|
||
for (const key in settings) { | ||
const setting = settings[key as keyof Settings] | ||
const inputEl = document.querySelector<HTMLInputElement>(`[name="${key}"]`) | ||
if (!inputEl) continue | ||
|
||
if (typeof setting === 'boolean') { | ||
inputEl.checked = setting | ||
} | ||
} | ||
} | ||
|
||
setup() | ||
|
||
/** | ||
* オプション画面で設定を変更したときに呼ばれる | ||
*/ | ||
const save = async () => { | ||
console.log('save') | ||
const settings: Settings = { | ||
allFileOneFolder: | ||
document.querySelector<HTMLInputElement>('[name="allFileOneFolder"]') | ||
?.checked ?? false | ||
} | ||
|
||
await browser.storage.local.set(settings) | ||
|
||
// 保存完了を表示 | ||
const saveMsg = document.querySelector<HTMLDivElement>('#saveMsg') | ||
saveMsg!.style.display = 'inline-block' | ||
setTimeout(() => { | ||
saveMsg!.style.display = 'none' | ||
}, 2000) | ||
} | ||
|
||
document | ||
.querySelector<HTMLButtonElement>('#save') | ||
?.addEventListener('click', save) |
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,13 @@ | ||
ul { | ||
list-style: none; | ||
padding-left: 0; | ||
} | ||
|
||
input { | ||
margin-right: 6px; | ||
} | ||
|
||
#saveMsg { | ||
display: none; | ||
margin-left: 6px; | ||
} |