|
1184 | 1184 | return comments; |
1185 | 1185 | } |
1186 | 1186 |
|
1187 | | - const limit = 9 - level * 2; |
1188 | | - const verticalLimit = 6; |
| 1187 | + let _container = null; |
| 1188 | + document.querySelectorAll(mediaContainerQueryStr).forEach((element) => { |
| 1189 | + if (!element.classList.contains('hide')) { |
| 1190 | + _container = element; |
| 1191 | + } |
| 1192 | + }); |
| 1193 | + |
| 1194 | + const containerWidth = _container.offsetWidth; |
| 1195 | + const containerHeight = _container.offsetHeight * window.ede.heightRatio - 18; |
| 1196 | + const duration = Math.ceil(containerWidth / window.ede.speed); |
| 1197 | + const lines = Math.floor(containerHeight / window.ede.fontSize) - 1; |
| 1198 | + |
| 1199 | + const limit = (9 - level * 2) * lines; |
| 1200 | + const verticalLimit = lines - 1 > 0 ? lines - 1 : 1; |
1189 | 1201 | const resultComments = []; |
1190 | 1202 |
|
1191 | 1203 | const timeBuckets = {}; |
1192 | 1204 | const verticalTimeBuckets = {}; |
1193 | 1205 |
|
1194 | 1206 | comments.forEach(comment => { |
1195 | | - const timeIndex = Math.ceil(comment.time); |
1196 | | - const verticalTimeIndex = Math.ceil(comment.time / 3); |
| 1207 | + const timeIndex = Math.ceil(comment.time / duration); |
1197 | 1208 |
|
1198 | 1209 | if (!timeBuckets[timeIndex]) { |
1199 | | - timeBuckets[timeIndex] = []; |
| 1210 | + timeBuckets[timeIndex] = 0; |
1200 | 1211 | } |
1201 | | - if (!verticalTimeBuckets[verticalTimeIndex]) { |
1202 | | - verticalTimeBuckets[verticalTimeIndex] = []; |
| 1212 | + if (!verticalTimeBuckets[timeIndex]) { |
| 1213 | + verticalTimeBuckets[timeIndex] = 0; |
1203 | 1214 | } |
1204 | 1215 |
|
1205 | 1216 | if (comment.mode === 'top' || comment.mode === 'bottom') { |
1206 | | - if (verticalTimeBuckets[verticalTimeIndex].length < verticalLimit) { |
1207 | | - verticalTimeBuckets[verticalTimeIndex].push(comment); |
| 1217 | + if (verticalTimeBuckets[timeIndex] < verticalLimit) { |
| 1218 | + verticalTimeBuckets[timeIndex]++; |
1208 | 1219 | resultComments.push(comment); |
1209 | 1220 | } |
1210 | 1221 | } else { |
1211 | | - if (timeBuckets[timeIndex].length < limit) { |
1212 | | - timeBuckets[timeIndex].push(comment); |
| 1222 | + if (timeBuckets[timeIndex] < limit) { |
| 1223 | + timeBuckets[timeIndex]++; |
1213 | 1224 | resultComments.push(comment); |
1214 | 1225 | } |
1215 | 1226 | } |
|
0 commit comments