From 46d8827a091eec44b0a26fd1712af4bdc4ee429c Mon Sep 17 00:00:00 2001 From: Ashley Date: Thu, 24 Nov 2022 20:14:36 +0000 Subject: [PATCH] add increase_brightness --- src/libpoketube/ptutils/libpt-coreutils.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/libpoketube/ptutils/libpt-coreutils.js b/src/libpoketube/ptutils/libpt-coreutils.js index bd15670..c478782 100644 --- a/src/libpoketube/ptutils/libpt-coreutils.js +++ b/src/libpoketube/ptutils/libpt-coreutils.js @@ -72,6 +72,25 @@ function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } +function increase_brightness(hex, percent){ + // strip the leading # if it's there + hex = hex.replace(/^\s*#|\s*$/g, ''); + + // convert 3 char codes --> 6, e.g. `E0F` --> `EE00FF` + if(hex.length == 3){ + hex = hex.replace(/(.)/g, '$1$1'); + } + + var r = parseInt(hex.substr(0, 2), 16), + g = parseInt(hex.substr(2, 2), 16), + b = parseInt(hex.substr(4, 2), 16); + + return '#' + + ((0|(1<<8) + r + (256 - r) * percent / 100).toString(16)).substr(1) + + ((0|(1<<8) + g + (256 - g) * percent / 100).toString(16)).substr(1) + + ((0|(1<<8) + b + (256 - b) * percent / 100).toString(16)).substr(1); +} + module.exports = { IsJsonString, convert,