| OLD | NEW |
| 1 document.addEventListener('DOMContentLoaded', function() { | 1 document.addEventListener('DOMContentLoaded', function() { |
| 2 if (document.getElementById('button')) { | 2 if (document.getElementById('button')) { |
| 3 document.getElementById('button').addEventListener('click', click); | 3 document.getElementById('button').addEventListener('click', click); |
| 4 } | 4 } |
| 5 }); | 5 }); |
| 6 | 6 |
| 7 function click() { | 7 function click() { |
| 8 var messages = [] | 8 var messages = [] |
| 9 var results; | 9 var results; |
| 10 chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { | 10 chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 var a = document.getElementById('button'); | 27 var a = document.getElementById('button'); |
| 28 a.className = 'serialize'; | 28 a.className = 'serialize'; |
| 29 a.innerHTML = 'Serializing...'; | 29 a.innerHTML = 'Serializing...'; |
| 30 a.removeEventListener('click', click); | 30 a.removeEventListener('click', click); |
| 31 } | 31 } |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Takes all the responses from the injected content scripts and creates the | 34 * Takes all the responses from the injected content scripts and creates the |
| 35 * HTML file for download. | 35 * HTML file for download. |
| 36 * | 36 * |
| 37 * @param {Array<Object>} messages The response from all of the injected content | 37 * @param {Array<Object>} messages The response from all of the injected content |
| 38 * scripts. | 38 * scripts. |
| 39 */ | 39 */ |
| 40 function completeProcess(messages) { | 40 function completeProcess(messages) { |
| 41 var html = outputHTMLString(messages); | 41 var html = outputHTMLString(messages); |
| 42 var file = new Blob([html], {type: 'text/html'}); | 42 var file = new Blob([html], {type: 'text/html'}); |
| 43 var url = URL.createObjectURL(file); | 43 var url = URL.createObjectURL(file); |
| 44 | 44 |
| 45 var a = document.getElementById('button'); | 45 var a = document.getElementById('button'); |
| 46 a.className = 'download'; | 46 a.className = 'download'; |
| 47 a.innerHTML = 'Download'; | 47 a.innerHTML = 'Download'; |
| 48 a.href = url; | 48 a.href = url; |
| 49 a.download = "snap-it.html"; | 49 a.download = "snap-it.html"; |
| 50 } | 50 } |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Converts the responses from the injected content scripts into a string | 53 * Converts the responses from the injected content scripts into a string |
| 54 * representing the HTML. | 54 * representing the HTML. |
| 55 * | 55 * |
| 56 * @param {Array<Object>} messages The response from all of the injected content | 56 * @param {Array<Object>} messages The response from all of the injected content |
| 57 * scripts. | 57 * scripts. |
| 58 * @return {string} The resulting HTML. | 58 * @return {string} The resulting HTML. |
| 59 */ | 59 */ |
| 60 function outputHTMLString(messages) { | 60 function outputHTMLString(messages) { |
| 61 var rootIndex = 0; | 61 var rootIndex = 0; |
| 62 for (var i = 1; i < messages.length; i++) { | 62 for (var i = 1; i < messages.length; i++) { |
| 63 rootIndex = messages[i].frameIndex === '0' ? i : rootIndex; | 63 rootIndex = messages[i].frameIndex === '0' ? i : rootIndex; |
| 64 } | 64 } |
| 65 fillRemainingHolesAndMinimizeStyles(messages, rootIndex); | 65 fillRemainingHolesAndMinimizeStyles(messages, rootIndex); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 95 * | 95 * |
| 96 * @param {Object} message The message Object whose style attributes should be | 96 * @param {Object} message The message Object whose style attributes should be |
| 97 * minimized. | 97 * minimized. |
| 98 */ | 98 */ |
| 99 function minimizeStyles(message) { | 99 function minimizeStyles(message) { |
| 100 var nestingDepth = message.frameIndex.split('.').length - 1; | 100 var nestingDepth = message.frameIndex.split('.').length - 1; |
| 101 var iframe = document.createElement('iframe'); | 101 var iframe = document.createElement('iframe'); |
| 102 document.body.appendChild(iframe); | 102 document.body.appendChild(iframe); |
| 103 iframe.setAttribute( | 103 iframe.setAttribute( |
| 104 'style', | 104 'style', |
| 105 `height: ${message.windowHeight}px;` + | 105 `height: ${message.windowHeight}px;` + |
| 106 `width: ${message.windowWidth}px;`); | 106 `width: ${message.windowWidth}px;`); |
| 107 | 107 |
| 108 var html = message.html.join(''); | 108 var html = message.html.join(''); |
| 109 html = unescapeHTML(html, nestingDepth); | 109 html = unescapeHTML(html, nestingDepth); |
| 110 iframe.contentDocument.documentElement.innerHTML = html; | 110 iframe.contentDocument.documentElement.innerHTML = html; |
| 111 var doc = iframe.contentDocument; | 111 var doc = iframe.contentDocument; |
| 112 | 112 |
| 113 // Remove entry in |message.html| where extra style element was specified. | 113 // Remove entry in |message.html| where extra style element was specified. |
| 114 message.html[message.pseudoElementTestingStyleIndex] = ''; | 114 message.html[message.pseudoElementTestingStyleIndex] = ''; |
| 115 var finalPseudoElements = []; | 115 var finalPseudoElements = []; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 } | 321 } |
| 322 return html; | 322 return html; |
| 323 } | 323 } |
| 324 | 324 |
| 325 /** | 325 /** |
| 326 * Calculate the correct encoding of a quotation mark that should be used given | 326 * Calculate the correct encoding of a quotation mark that should be used given |
| 327 * the nesting depth of the window in the frame tree. | 327 * the nesting depth of the window in the frame tree. |
| 328 * | 328 * |
| 329 * @param {number} depth The nesting depth of the appropriate window in the | 329 * @param {number} depth The nesting depth of the appropriate window in the |
| 330 * frame tree. | 330 * frame tree. |
| 331 * @return {string} The correctly escaped string. | 331 * @return {string} The correctly escaped string. |
| 332 */ | 332 */ |
| 333 function escapedQuote(depth) { | 333 function escapedQuote(depth) { |
| 334 if (depth == 0) { | 334 if (depth == 0) { |
| 335 return '"'; | 335 return '"'; |
| 336 } else { | 336 } else { |
| 337 var arr = 'amp;'.repeat(depth-1); | 337 var arr = 'amp;'.repeat(depth-1); |
| 338 return '&' + arr + 'quot;'; | 338 return '&' + arr + 'quot;'; |
| 339 } | 339 } |
| 340 } | 340 } |
| OLD | NEW |