-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
152 lines (147 loc) · 4.74 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown Link Counter</title>
<style>
body {
background-color: #002b36;
color: #f8ca00;
font-family: Arial, sans-serif;
padding: 20px;
}
.bar-chart-container {
display: flex;
flex-direction: row;
overflow-x: auto;
background: #004d40;
border-radius: 5px;
padding: 10px;
margin-top: 20px;
position: relative;
height: 500px;
}
.bar {
width: 40px;
background-color: #007bff;
border-radius: 5px;
margin-right: 10px;
position: absolute;
bottom: 0;
}
.bar:hover {
background-color: #0056b3;
}
.bar-label {
position: absolute;
bottom: -20px;
white-space: nowrap;
}
.bar-count {
color: #002b36;
font-weight: bold;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ffffff;
padding: 8px;
text-align: left;
color: #f8ca00;
}
tr:nth-child(even) {
background-color: #004d40;
}
tr:nth-child(odd) {
background-color: #002b36;
}
</style>
</head>
<body>
<input type="file" id="fileInput" multiple onchange="selectFiles(this.files)">
<button onclick="handleFiles()">Count Links</button>
<button onclick="clearFiles()">Clear Selection</button>
<div id="output"></div>
<div class="bar-chart-container" id="barChart"></div>
<script>
let selectedFiles = [];
let titlesCount = {};
let titleIdMap = {};
function selectFiles(files) {
selectedFiles = files;
}
function handleFiles() {
titlesCount = {};
titleIdMap = {};
let currentId = 1;
Array.from(selectedFiles).forEach((file, index) => {
if (file.type === 'text/markdown' || file.name.endsWith('.md')) {
const reader = new FileReader();
reader.onload = (function(file, index) {
return function(e) {
const content = e.target.result;
const titles = content.match(/\(\((.*?)\)\)/g);
if (titles) {
titles.forEach(title => {
const cleanTitle = title.slice(2, -2);
if (!titleIdMap[cleanTitle]) {
titleIdMap[cleanTitle] = currentId++;
}
titlesCount[cleanTitle] = (titlesCount[cleanTitle] || 0) + 1;
});
}
if (index === selectedFiles.length - 1) {
displayResults(titlesCount);
displayBarChart(titlesCount);
}
};
})(file, index);
reader.readAsText(file);
}
});
}
function displayResults(titlesCount) {
const output = document.getElementById('output');
output.innerHTML = '<table><tr><th>ID</th><th>Title</th><th>Count</th></tr>' +
Object.entries(titlesCount).map(([title, count]) =>
`<tr><td>${titleIdMap[title]}</td><td>((${title}))</td><td>${count}</td></tr>`).join('') +
'</table>';
}
function displayBarChart(titlesCount) {
const maxCount = Math.max(...Object.values(titlesCount));
const barChartContainerHeight = 500;
const barChart = document.getElementById('barChart');
barChart.style.height = `${barChartContainerHeight}px`;
barChart.innerHTML = '';
let leftOffset = 0;
Object.entries(titlesCount).forEach(([title, count], index) => {
const barHeight = (count / maxCount) * barChartContainerHeight;
const bar = document.createElement('div');
bar.classList.add('bar');
bar.style.height = `${barHeight}px`;
bar.style.left = `${leftOffset}px`;
leftOffset += 50;
const label = document.createElement('div');
label.classList.add('bar-label');
label.textContent = `ID ${titleIdMap[title]}`;
const countDisplay = document.createElement('div');
countDisplay.classList.add('bar-count');
countDisplay.textContent = count;
bar.appendChild(countDisplay);
bar.appendChild(label);
barChart.appendChild(bar);
});
}
function clearFiles() {
document.getElementById('fileInput').value = '';
selectedFiles = [];
document.getElementById('output').innerHTML = '';
document.getElementById('barChart').innerHTML = '';
}
</script>
</body>
</html>