-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
85 lines (75 loc) · 3.36 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// popup.js
document.addEventListener('DOMContentLoaded', function() {
//storageから値を取得して表示する
function getStorageItem(item, inputId, iconId) {
chrome.storage.local.get(item, function(result) {
if (result[item]) {
document.getElementById(inputId).value = result[item];
if (iconId) {
document.getElementById(iconId).src = '/images/checked.png';
}
} else {
if (iconId) {
document.getElementById(iconId).src = '/images/send.png';
}
}
});
}
function setInputListener(inputId, iconId) {
document.getElementById(inputId).oninput = function() {
document.getElementById(iconId).src = '/images/send.png';
}
}
function setIconClickListener(iconId, item, inputId) {
document.getElementById(iconId).addEventListener('click', function() {
if (inputId.value !== '') {
chrome.storage.local.set({ [item]: document.getElementById(inputId).value});
this.classList.add('animate');
this.addEventListener('animationend', function() {
this.classList.remove('animate');
this.src = '/images/checked.png';
}, {once: true}); // イベントリスナーは一度だけ実行されます
} else {
alert('Please enter a value.');
}
});
}
getStorageItem('api_key', 'apiKeyInput', 'saveApiKeyIcon');
setInputListener('apiKeyInput', 'saveApiKeyIcon');
setIconClickListener('saveApiKeyIcon', 'api_key', 'apiKeyInput');
getStorageItem('language', 'languageInput', 'saveLanguageIcon');
setInputListener('languageInput', 'saveLanguageIcon');
setIconClickListener('saveLanguageIcon', 'language', 'languageInput');
getStorageItem('power', 'toggle');
// ここでルビのフォントサイズを変更します
document.getElementById('fontSizeSlider').addEventListener('input', function(e) {
const fontSize = e.target.value;
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
let activeTab = tabs[0];
chrome.scripting.executeScript({
target: {tabId: activeTab.id},
function: function(fontSize) {
document.querySelectorAll('rt').forEach((rt) => {
rt.style.fontSize = fontSize + 'px';
});
},
args: [fontSize]
});
});
});
document.getElementById('toggle').addEventListener('change', function() {
if (this.checked) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
let activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"message": "on"});
chrome.storage.local.set({ power: true });
});
} else {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
let activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"message": "off"});
chrome.storage.local.set({ power: false });
});
}
});
});