-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
59 lines (53 loc) · 2.03 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const showPopup = () => {
const buttons = [
{
name: '以下のリリックのタイトル',
text: '以下のリリックの曲に合うタイトルを10個考えてください。日本語で5個、英語で5個お願いします。'
},
{
name: 'というニュアンスの表現',
text: 'というニュアンスの表現を10個考えてください'
},
{
name: 'というフレーズと組み合わせて使えるフレーズ',
text: 'というフレーズと組み合わせて、歌詞に使えるフレーズを10個考えてください'
},
{
name: 'あと10',
text: 'あと10個教えてください'
},
{
name: 'を10',
text: 'を10個教えてください'
},
];
const buttonContainer = document.getElementById('button-container');
const inputText = document.getElementById('input-text');
while (buttonContainer.firstChild) {
buttonContainer.removeChild(buttonContainer.firstChild);
}
buttons.forEach(button => {
const btn = document.createElement('button');
btn.textContent = button.name;
btn.addEventListener('click', () => {
const currentPos = inputText.selectionStart;
const beforeText = inputText.value.substring(0, currentPos);
const afterText = inputText.value.substring(currentPos);
const text = beforeText + button.text + afterText;
inputText.value = text;
inputText.select();
});
buttonContainer.appendChild(btn);
});
inputText.focus();
};
document.addEventListener('DOMContentLoaded', showPopup);
// 入力値をlocal storageに保存する
document.getElementById('input-text').addEventListener('keyup', () => {
const inputValue = document.getElementById('input-text').value;
chrome.storage.local.set({ inputValue });
});
// ページが読み込まれたときに、local storageから値を読み込んで入力フィールドに設定する
chrome.storage.local.get(['inputValue'], result => {
document.getElementById('input-text').value = result.inputValue || '';
});