Last active
November 12, 2020 03:34
-
-
Save macouella/cf3dad75a6796706882a6ee657c2bc7c to your computer and use it in GitHub Desktop.
Revisions
-
Igi Manaloto revised this gist
Sep 3, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ function rgb2hex(rgb) { } } var keys = Object.keys(window.getComputedStyle(document.body)).filter(r => /color/gi.test(r) ); [ -
Igi Manaloto created this gist
Sep 3, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ function rgb2hex(rgb) { if (rgb.search("rgb") == -1) { return rgb; } else { rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/); function hex(x) { return ("0" + parseInt(x).toString(16)).slice(-2); } return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); } } var keys = Object.keys(window.getComputedStyle($0)).filter(r => /color/gi.test(r) ); [ ...Array.from(document.querySelectorAll("*")).reduce((colors, el) => { keys.forEach(ee => { colors.add(getComputedStyle(el)[ee]); }); return colors; }, new Set()) ] .map(n => { try { return rgb2hex(n); } catch (e) { return null; } }) .filter(ab => typeof ab === "string" && ab.indexOf("#") === 0) .toString();