Draft - Get all Styles

by amindunited

JavaScript

const getAllStyleSheetStyles = () => {
  const holySheets = [...document.styleSheets].reduce((acc, styleSheet) => {
    const rules = [...styleSheet.cssRules].reduce((acc, rule) => {
      // console.log('rule', rule);
      return [...acc, rule.cssText];
    }, []);
    return rules;
  }, []);
  // console.log('holySheets', holySheets, null, 2);
  return holySheets;
};

const allRules = getAllStyleSheetStyles();
const styleTag = document.createElement('style');
styleTag.innerText = allRules.join(' ');
console.log('styletag', styleTag);


/*
const snapshot = sourceElement;
const els = [...snapshot.querySelectorAll('*')].map((el) => {
  // const properties = Object.keys(getComputedStyle(el)).map((p) => {
  //   console.log('this prop ', p.cssText);
  //   return p;
  // });
  const computed = getComputedStyle(el);
  Object.keys(computed).forEach((key) => {
    if (Object.hasOwn(computed, key)) {
      console.log(el, 'has', key);
    }
  });
});
*/