third_party/snap-it/popup.js
function minimizeStyles(message) {
  var nestingDepth = message.frameIndex.split('.').length - 1;
  var iframe = document.createElement('iframe');
  document.body.appendChild(iframe);
  iframe.setAttribute(
      'style',
      `height: ${message.windowHeight}px;` + 
      `width: ${message.windowWidth}px;`);

  var html = message.html.join('');
  html = unescapeHTML(html, nestingDepth);
  iframe.contentDocument.documentElement.innerHTML = html;
  var doc = iframe.contentDocument;

  // Remove entry in |message.html| where extra style element was specified.
  message.html[message.pseudoElementTestingStyleIndex] = '';
  var finalPseudoElements = [];
  for (var selector in message.pseudoElementSelectorToCSSMap) {
    minimizePseudoElementStyle(message, doc, selector, finalPseudoElements);
  }

  if (finalPseudoElements.length > 0) {
    message.html[message.pseudoElementPlaceHolderIndex] =
        `<style>${finalPseudoElements.join(' ')}</style>`;
  }

  if (message.rootStyleIndex) {
    minimizeStyle(
        message,
        doc,
        doc.documentElement,
        message.rootId,
        message.rootStyleIndex);
  }

  for (var id in message.idToStyleIndex) {
    var index = message.idToStyleIndex[id];
    var element = doc.getElementById(id);
    if (element) {
      minimizeStyle(message, doc, element, id, index);
    }
  }
  iframe.remove();
}
function minimizeStyles(message) {
  var nestingDepth = message.frameIndex.split('.').length - 1;
  var iframe = document.createElement('iframe');
  document.body.appendChild(iframe);
  iframe.setAttribute(
      'style',
      `height: ${message.windowHeight}px;` + 
      `width: ${message.windowWidth}px;`);

  var html = message.html.join('');
  html = unescapeHTML(html, nestingDepth);
  iframe.contentDocument.documentElement.innerHTML = html;
  var doc = iframe.contentDocument;

  // Remove entry in |message.html| where extra style element was specified.
  message.html[message.pseudoElementTestingStyleIndex] = '';
  var finalPseudoElements = [];
  for (var selector in message.pseudoElementSelectorToCSSMap) {
    minimizePseudoElementStyle(message, doc, selector, finalPseudoElements);
  }

  if (finalPseudoElements.length > 0) {
    message.html[message.pseudoElementPlaceHolderIndex] =
        `<style>${finalPseudoElements.join(' ')}</style>`;
  }

  if (message.rootStyleIndex) {
    minimizeStyle(
        message,
        doc,
        doc.documentElement,
        message.rootId,
        message.rootStyleIndex);
  }

  for (var id in message.idToStyleIndex) {
    var index = message.idToStyleIndex[id];
    var element = doc.getElementById(id);
    if (element) {
      minimizeStyle(message, doc, element, id, index);
    }
  }
  iframe.remove();
}
function minimizeStyles ( message ) { var nestingDepth = message . frameIndex . split ( '.' ) . length - 1 ; var iframe = document . createElement ( 'iframe' ) ; document . body . appendChild ( iframe ) ; iframe . setAttribute ( 'style' , ` ${ message . windowHeight } ` + ` ${ message . windowWidth } ` ) ; var html = message . html . join ( '' ) ; html = unescapeHTML ( html , nestingDepth ) ; iframe . contentDocument . documentElement . innerHTML = html ; var doc = iframe . contentDocument ; // Remove entry in |message.html| where extra style element was specified. message . html [ message . pseudoElementTestingStyleIndex ] = '' ; var finalPseudoElements = [ ] ; for ( var selector in message . pseudoElementSelectorToCSSMap ) { minimizePseudoElementStyle ( message , doc , selector , finalPseudoElements ) ; } if ( finalPseudoElements . length > 0 ) { message . html [ message . pseudoElementPlaceHolderIndex ] = ` ${ finalPseudoElements . join ( ' ' ) } ` ; } if ( message . rootStyleIndex ) { minimizeStyle ( message , doc , doc . documentElement , message . rootId , message . rootStyleIndex ) ; } for ( var id in message . idToStyleIndex ) { var index = message . idToStyleIndex [ id ] ; var element = doc . getElementById ( id ) ; if ( element ) { minimizeStyle ( message , doc , element , id , index ) ; } } iframe . remove ( ) ; }
Removes all style attribute properties that are unneeded.

@param {Object} message The message Object whose style attributes should be
minimized.
Removes all style attribute properties that are unneeded .