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();