Skip to content

Commit

Permalink
Replace RegExp with something better (cheers to ck for this)
Browse files Browse the repository at this point in the history
  • Loading branch information
KapiWilq committed Nov 21, 2024
1 parent d55c498 commit 8ff0029
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions js/hitErrorMeter.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,8 @@ class HitErrorMeter {
tick.classList.add('tick');

// We don't know if hit error segments are hidden - extract RGB(A) values and set the opacity manually.
// RegExp source: https://regex101.com/library/dVOwn0
const RGBA_REGEXP = /rgba?\((?<r>[.\d]+)[, ]+(?<g>[.\d]+)[, ]+(?<b>[.\d]+)(?:\s?[,\/]\s?(?<a>[.\d]+%?))?\)/;
let tickColors = getComputedStyle(segmentForTheTick).backgroundColor.match(RGBA_REGEXP).groups;
tick.style.backgroundColor = `rgba(${tickColors.r}, ${tickColors.g}, ${tickColors.b}, 1)`;
const [r, g, b] = getComputedStyle(segmentForTheTick).backgroundColor.replace('rgba(', '').replace('rgb(', '').replace(')', '').split(',').map(r => r.trim());
tick.style.backgroundColor = `rgba(${r}, ${g}, ${b}, 1)`;

tick.style.left = `${tickPositionPercentage * 100}%`;
tick.style.transition = `${this.tickAppearanceAnimation} ${this.tickAppearanceDuration}ms`;
Expand Down

0 comments on commit 8ff0029

Please sign in to comment.