From 6b1d6564fbab87c7c68ef96dcfeddedd916e1bf8 Mon Sep 17 00:00:00 2001 From: eight Date: Tue, 12 Sep 2017 20:44:12 +0800 Subject: [PATCH] Fix: drop pad --- js/usercss.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/js/usercss.js b/js/usercss.js index 8f6ab259..cbbab840 100644 --- a/js/usercss.js +++ b/js/usercss.js @@ -72,20 +72,13 @@ var usercss = (function () { return `rgba(${r}, ${g}, ${b}, ${a})`; } - function pad(s) { - if (s.padStart) { - // chrome 57+ - return s.padStart(2, '0'); - } - return `00${s}`.slice(-2); - } - function formatHex({r, g, b, a = null}) { const values = [r, g, b]; + let hex = '#' + (0x1000000 + (r << 16) + (g << 8) + (b | 0)).toString(16).substr(1); if (a !== null) { - values.push(Math.floor(a * 255)); + hex += (0x100 + Math.floor(a * 255)).toString(16).substr(1); } - return '#' + values.map(n => pad(n.toString(16))).join(''); + return hex; } return {parse, format, formatHex};