-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_script.js
More file actions
44 lines (41 loc) · 1.63 KB
/
content_script.js
File metadata and controls
44 lines (41 loc) · 1.63 KB
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
// 保存されたIDを取得する関数
async function getTargetID() {
await chrome.storage.sync.get('handai_default_role_id', function(data) {
if(typeof data.messages == "undefined"){
return null;
}else{
return data['handai_default_role_id'];
}
});
}
// 指定したIDを含む<tr>を検索し、指定されたIDが含まれるかどうかを判定してradioボタンをチェックする関数
function selectRadioButton(targetID) {
if(targetID == null) return;
const trElements = document.querySelectorAll("tr");
trElements.forEach((tr) => {
const tdElements = tr.querySelectorAll("td");
const containsID = Array.from(tdElements).some((td) => {
//Stringにキャストしないと正常に比較できない
return String(td.textContent.trim()) == String(targetID);
});
if (containsID) {
const radio = tr.querySelector("input[type=radio][name=role]");
if (radio) {
radio.checked = true;
radio.dispatchEvent(new Event("change"));
//OKボタンをアクティブに
document.querySelector("input[type=button][id=ok]").disabled = false;
}
}
});
}
// ページが読み込まれた時に実行
window.onload = async function () {
// 保存されたIDを取得して、selectRadioButton関数に渡す
await chrome.storage.sync.get('handai_default_role_id', function(data) {
var id = data['handai_default_role_id'];
if(typeof id != "undefined"){
selectRadioButton(id);
}
});
};