-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.html
More file actions
241 lines (220 loc) · 7.55 KB
/
Copy pathdebug.html
File metadata and controls
241 lines (220 loc) · 7.55 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Calendar Group Manager Debug</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
max-width: 800px;
margin: 0 auto;
}
h1 {
color: #1a73e8;
}
.section {
background: #f5f5f5;
padding: 15px;
margin: 10px 0;
border-radius: 5px;
}
pre {
background: #fff;
padding: 10px;
border: 1px solid #ddd;
overflow-x: auto;
white-space: pre-wrap;
}
button {
background: #1a73e8;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover {
background: #1557b0;
}
#status {
padding: 10px;
margin: 10px 0;
border-radius: 4px;
}
.success {
background: #e6f4ea;
color: #1e8e3e;
}
.error {
background: #fce8e6;
color: #d93025;
}
</style>
</head>
<body>
<h1>Calendar Group Manager デバッグツール</h1>
<div class="section">
<h2>1. Googleカレンダーのページを開く</h2>
<p>まず、Googleカレンダーのタブを開いてください。</p>
<button onclick="openCalendar()">Googleカレンダーを開く</button>
</div>
<div class="section">
<h2>2. カレンダーリストを取得</h2>
<p>現在のカレンダーリストを取得して確認します。</p>
<button onclick="getCalendars()">カレンダーリストを取得</button>
<div id="calendarList"></div>
</div>
<div class="section">
<h2>3. DOM構造を確認</h2>
<p>チェックボックスの構造を確認します。</p>
<button onclick="inspectDOM()">DOM構造を確認</button>
<div id="domStructure"></div>
</div>
<div class="section">
<h2>4. テスト実行</h2>
<p>カレンダー名を入力してチェックのオン/オフをテストします。</p>
<input type="text" id="testCalendarName" placeholder="カレンダー名を入力" style="width: 300px; padding: 5px;">
<br>
<button onclick="testCheck()">チェックを入れる</button>
<button onclick="testUncheck()">チェックを外す</button>
<button onclick="testToggle()">トグル</button>
</div>
<div id="status"></div>
<script>
function showStatus(message, type = 'success') {
const status = document.getElementById('status');
status.className = type;
status.textContent = message;
}
function openCalendar() {
window.open('https://calendar.google.com', '_blank');
}
async function getCalendars() {
try {
const tabs = await chrome.tabs.query({url: '*://calendar.google.com/*'});
if (tabs.length === 0) {
showStatus('Googleカレンダーのタブが見つかりません', 'error');
return;
}
const response = await chrome.tabs.sendMessage(tabs[0].id, {action: 'getCalendars'});
const list = document.getElementById('calendarList');
if (response && response.calendars) {
list.innerHTML = '<h3>見つかったカレンダー:</h3><pre>' +
JSON.stringify(response.calendars, null, 2) + '</pre>';
showStatus(`${response.calendars.length}個のカレンダーが見つかりました`);
} else {
list.innerHTML = '<p>カレンダーが見つかりませんでした</p>';
showStatus('カレンダーが見つかりませんでした', 'error');
}
} catch (error) {
showStatus('エラー: ' + error.message, 'error');
}
}
async function inspectDOM() {
try {
const tabs = await chrome.tabs.query({url: '*://calendar.google.com/*'});
if (tabs.length === 0) {
showStatus('Googleカレンダーのタブが見つかりません', 'error');
return;
}
// DOM検査用のコードを実行
const results = await chrome.tabs.executeScript(tabs[0].id, {
code: `
const checkboxes = document.querySelectorAll('input[type="checkbox"][aria-label]');
const info = [];
checkboxes.forEach((cb, index) => {
if (index < 5) { // 最初の5個だけ
const parent = cb.closest('li') || cb.parentElement;
info.push({
ariaLabel: cb.getAttribute('aria-label'),
checked: cb.checked,
parentHTML: parent ? parent.outerHTML.substring(0, 200) + '...' : 'No parent'
});
}
});
JSON.stringify(info, null, 2);
`
});
const structure = document.getElementById('domStructure');
structure.innerHTML = '<h3>チェックボックスの構造(最初の5個):</h3><pre>' + results[0] + '</pre>';
showStatus('DOM構造を取得しました');
} catch (error) {
showStatus('エラー: ' + error.message, 'error');
}
}
async function testCheck() {
const name = document.getElementById('testCalendarName').value;
if (!name) {
showStatus('カレンダー名を入力してください', 'error');
return;
}
try {
const tabs = await chrome.tabs.query({url: '*://calendar.google.com/*'});
if (tabs.length === 0) {
showStatus('Googleカレンダーのタブが見つかりません', 'error');
return;
}
await chrome.tabs.sendMessage(tabs[0].id, {
action: 'applyGroup',
members: [name]
});
showStatus(`"${name}" にチェックを入れました`);
} catch (error) {
showStatus('エラー: ' + error.message, 'error');
}
}
async function testUncheck() {
try {
const tabs = await chrome.tabs.query({url: '*://calendar.google.com/*'});
if (tabs.length === 0) {
showStatus('Googleカレンダーのタブが見つかりません', 'error');
return;
}
await chrome.tabs.executeScript(tabs[0].id, {
code: `
const checkboxes = document.querySelectorAll('input[type="checkbox"][aria-label]:checked');
checkboxes.forEach(cb => cb.click());
'Unchecked all calendars';
`
});
showStatus('全てのチェックを外しました');
} catch (error) {
showStatus('エラー: ' + error.message, 'error');
}
}
async function testToggle() {
const name = document.getElementById('testCalendarName').value;
if (!name) {
showStatus('カレンダー名を入力してください', 'error');
return;
}
try {
const tabs = await chrome.tabs.query({url: '*://calendar.google.com/*'});
if (tabs.length === 0) {
showStatus('Googleカレンダーのタブが見つかりません', 'error');
return;
}
const result = await chrome.tabs.executeScript(tabs[0].id, {
code: `
let found = false;
const checkboxes = document.querySelectorAll('input[type="checkbox"][aria-label]');
checkboxes.forEach(cb => {
const label = cb.getAttribute('aria-label');
if (label && label.includes('${name}')) {
cb.click();
found = true;
}
});
found ? 'Toggled: ${name}' : 'Not found: ${name}';
`
});
showStatus(result[0]);
} catch (error) {
showStatus('エラー: ' + error.message, 'error');
}
}
</script>
</body>
</html>