mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 12:07:07 +03:00
sponsorStart, sponsorEnd -> startTime, endTime
This commit is contained in:
@@ -113,17 +113,17 @@ function getWeightedRandomChoice(choices, weights, amountOfChoices) {
|
|||||||
function getVoteOrganisedSponsorTimes(sponsorTimes, votes, UUIDs) {
|
function getVoteOrganisedSponsorTimes(sponsorTimes, votes, UUIDs) {
|
||||||
//create groups of sponsor times that are similar to eachother
|
//create groups of sponsor times that are similar to eachother
|
||||||
const groups = []
|
const groups = []
|
||||||
sponsorTimes.forEach(([sponsorStart, sponsorEnd], i) => {
|
sponsorTimes.forEach(([startTime, endTime], i) => {
|
||||||
//find a group that overlaps with the current segment
|
//find a group that overlaps with the current segment
|
||||||
//sponsorTimes are sorted by their startTime so there should never be more than 1 similar group
|
//sponsorTimes are sorted by their startTime so there should never be more than 1 similar group
|
||||||
const similarGroup = groups.find(group => group.start < sponsorEnd && sponsorStart < group.end)
|
const similarGroup = groups.find(group => group.start < endTime && startTime < group.end)
|
||||||
//add the sponsor to that group or create a new group if there aren't any
|
//add the sponsor to that group or create a new group if there aren't any
|
||||||
if (similarGroup === undefined) {
|
if (similarGroup === undefined) {
|
||||||
groups.push({ start: sponsorStart, end: sponsorEnd, sponsors: [i] })
|
groups.push({ start: startTime, end: endTime, sponsors: [i] })
|
||||||
} else {
|
} else {
|
||||||
similarGroup.sponsors.push(i)
|
similarGroup.sponsors.push(i)
|
||||||
similarGroup.start = Math.min(similarGroup.start, sponsorStart)
|
similarGroup.start = Math.min(similarGroup.start, startTime)
|
||||||
similarGroup.end = Math.max(similarGroup.end, sponsorEnd)
|
similarGroup.end = Math.max(similarGroup.end, endTime)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user