Skip to content

Commit

Permalink
Use array for gradient slices instead of string to avoid weird comma
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube committed Nov 6, 2024
1 parent 5f5ed52 commit 17b50db
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ext/js/display/display-anki.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,17 +608,17 @@ export class DisplayAnki {
const gradientSliceSize = 100 / flags.size;
let currentGradientPercent = 0;

let gradient = 'linear-gradient(to right,';
const gradientSlices = [];
for (const flag of flags) {
const flagColor = flagColorsDict[flag];
gradient += 'rgb(' + flagColor.red + ',' + flagColor.green + ',' + flagColor.blue + ') ' + currentGradientPercent + '%,';
gradient += 'rgb(' + flagColor.red + ',' + flagColor.green + ',' + flagColor.blue + ') ' + (currentGradientPercent + gradientSliceSize) + '%,';
gradientSlices.push(
'rgb(' + flagColor.red + ',' + flagColor.green + ',' + flagColor.blue + ') ' + currentGradientPercent + '%',
'rgb(' + flagColor.red + ',' + flagColor.green + ',' + flagColor.blue + ') ' + (currentGradientPercent + gradientSliceSize) + '%',
);
currentGradientPercent += gradientSliceSize;
}
gradient = gradient.slice(0, -1); // remove trailing comma
gradient += ')';

return gradient;
return 'linear-gradient(to right,' + gradientSlices.join(',') + ')';
}

/**
Expand Down

0 comments on commit 17b50db

Please sign in to comment.