ZWkang / not-crazy-idea

to save my idea want to be be be true ~~ or when i saw some great code saved.
MIT License
1 stars 0 forks source link

document.styleSheets 获取页面所有样式 #24

Closed ZWkang closed 5 years ago

ZWkang commented 5 years ago
Array.from(document.styleSheets)
  .map((_) =>
    Array.from(_.rules)
      .map((item) => {
        var colors = item.cssText.match(/(rgba\((.*?)\))|(\#\d{3})|(\#\d{6})|(rgb\((.*?)\))/g);
        return { selector: item.selectorText, colors: colors };
      })
      .filter((v) => v.colors !== null)
  )
  .reduce((prev, next) => prev.concat(next), []);

document.styleSheets 获取页面所有样式