-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaterial.js
More file actions
47 lines (36 loc) · 1.66 KB
/
material.js
File metadata and controls
47 lines (36 loc) · 1.66 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
console.log("Running material.js");
chrome.storage.sync.get(optionNames, (items) => {
if (items["beautify_file_open_status"]) beautifyFileOpenStatus();
});
function beautifyFileOpenStatus() {
const rows = document.querySelectorAll('.result-list');
let viewedCount = 0;
if(rows.length > 0){
rows.forEach(row => {
row.classList.add('show-status');
const dateDiv = Array.from(row.querySelectorAll('.material-status-list-open-date'))
.find(el => el.textContent.includes(':'));
if (dateDiv) {
viewedCount++;
const viewDate = new Date(dateDiv.textContent.trim());
const diffHours = (new Date() - viewDate) / (1000 * 60 * 60);
if (diffHours < 24) {
row.classList.add('status-recent'); // 24時間以内
} else {
row.classList.add('status-viewed'); // それ以前の既読
}
} else {
row.classList.add('status-unviewed'); // 未読
}
});
const materialTitle = Array.from(document.querySelectorAll('#materialsSearchResult .block-title-txt'))
.find(el => el.textContent.includes('閲覧状況'));
const rate = ((viewedCount / rows.length) * 100).toFixed(1);
if (materialTitle && !materialTitle.querySelector('.rate-badge')) {
const badge = document.createElement('span');
badge.className = 'rate-badge';
badge.textContent = `${viewedCount} / ${rows.length} (${rate}%)`;
materialTitle.appendChild(badge);
}
}
}