SHARE
TWEET

Chrome Cache Downloader for chrome://cache

genBTC Nov 19th, 2016 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.     var preTags = document.getElementsByTagName('pre');
  3.     var preWithHeaderInfo = preTags[0];
  4.     //var preWithContent = preTags[2];
  5.     var preWithContent = "";
  6.     for(var i=0;i=2){
  7.             preWithContent = preWithContent + preTags[i].textContent;
  8.         }
  9.     }
  10.  
  11.     //var lines = preWithContent.textContent.split('\n');
  12.     var lines = preWithContent.split('\n');
  13.  
  14.     // get data about the formatting (changes between different versions of chrome)
  15.     var rgx = /^(0{8}:\s+)([0-9a-f]{2}\s+)[0-9a-f]{2}/m;
  16.     var match = rgx.exec(lines[0]);
  17.  
  18.     var text = '';
  19.     for (var i = 0; i < lines.length; i++) {
  20.         var line = lines[i];
  21.         var firstIndex = match[1].length; // first index of the chars to match (e.g. where a '84' would start)
  22.         var indexJump = match[2].length; // how much space is between each set of numbers
  23.         var totalCharsPerLine = 16;
  24.         index = firstIndex;
  25.         for (var j = 0; j < totalCharsPerLine; j++) {
  26.             var hexValAsStr = line.substr(index, 2);
  27.             if (hexValAsStr == '  ') {
  28.                 // no more chars
  29.                 break;
  30.             }
  31.  
  32.             var asciiVal = parseInt(hexValAsStr, 16);
  33.             text += String.fromCharCode(asciiVal);
  34.  
  35.             index += indexJump;
  36.         }
  37.     }
  38.  
  39.     var headerText = preWithHeaderInfo.textContent;
  40.     var elToInsertBefore = document.body.childNodes[0];
  41.     var insertedDiv = document.createElement("div");
  42.     document.body.insertBefore(insertedDiv, elToInsertBefore);
  43.  
  44.     // find the filename
  45.     var nodes = [document.body];
  46.     var filepath = '';
  47.     while (true) {
  48.         var node = nodes.pop();
  49.         if (node.hasChildNodes()) {
  50.             var children = node.childNodes;
  51.             for (var i = children.length - 1; i >= 0; i--) {
  52.                 nodes.push(children[i]);
  53.             }
  54.         }
  55.  
  56.         if (node.nodeType === Node.TEXT_NODE && /\S/.test(node.nodeValue)) {
  57.             // 1st depth-first text node (with non-whitespace chars) found
  58.             filepath = node.nodeValue;
  59.             break;
  60.         }
  61.     }
  62.    
  63.     outputResults(insertedDiv, convertToBase64(text), filepath, headerText);
  64.  
  65.     insertedDiv.appendChild(document.createElement('hr'));
  66.  
  67.     function outputResults(parentElement, fileContents, fileUrl, headerText) {
  68.         // last updated 1/27/12
  69.         var rgx = /.+\/([^\/]+)/;
  70.         var filename = rgx.exec(fileUrl)[1];
  71.  
  72.         // get the content type
  73.         rgx = /content-type: (.+)/i;
  74.         var match = rgx.exec(headerText);
  75.         var contentTypeFound = match != null;
  76.         var contentType = "text/plain";
  77.         if (contentTypeFound) {
  78.             contentType = match[1];
  79.         }
  80.  
  81.         var dataUri = "data:" + contentType + ";base64," + fileContents;
  82.  
  83.         // check for gzipped file
  84.         var gZipRgx = /content-encoding: gzip/i;
  85.         if (gZipRgx.test(headerText)) {
  86.             filename += '.gz';
  87.         }
  88.        
  89.         // check for image
  90.         var imageRgx = /image/i;
  91.         var isImage = imageRgx.test(contentType);
  92.            
  93.         // create link
  94.         var aTag = document.createElement('a');
  95.         aTag.textContent = "Left-click to download the cached file";
  96.         aTag.setAttribute('href', dataUri);
  97.         aTag.setAttribute('download', filename);
  98.         parentElement.appendChild(aTag);
  99.         parentElement.appendChild(document.createElement('br'));
  100.    
  101.         // create image
  102.         if (isImage) {
  103.             var imgTag = document.createElement('img');
  104.             imgTag.setAttribute("src", dataUri);
  105.             parentElement.appendChild(imgTag);
  106.             parentElement.appendChild(document.createElement('br'));
  107.         }
  108.    
  109.         // create warning
  110.         if (!contentTypeFound) {
  111.             var pTag = document.createElement('p');
  112.             pTag.textContent = "WARNING: the type of file was not found in the headers... defaulting to text file.";
  113.             parentElement.appendChild(pTag);
  114.         }
  115.     }
  116.  
  117.     function getBase64Char(base64Value) {
  118.         if (base64Value < 0) {
  119.             throw "Invalid number: " + base64Value;
  120.         } else if (base64Value <= 25) {
  121.             // A-Z
  122.             return String.fromCharCode(base64Value + "A".charCodeAt(0));
  123.         } else if (base64Value <= 51) {
  124.             // a-z
  125.             base64Value -= 26; // a
  126.             return String.fromCharCode(base64Value + "a".charCodeAt(0));
  127.         } else if (base64Value <= 61) {
  128.             // 0-9
  129.             base64Value -= 52; // 0
  130.             return String.fromCharCode(base64Value + "0".charCodeAt(0));
  131.         } else if (base64Value <= 62) {
  132.             return '+';
  133.         } else if (base64Value <= 63) {
  134.             return '/';
  135.         } else {
  136.             throw "Invalid number: " + base64Value;
  137.         }
  138.     }
  139.  
  140.     function convertToBase64(input) {
  141.         // http://en.wikipedia.org/wiki/Base64#Example
  142.         var remainingBits;
  143.         var result = "";
  144.         var additionalCharsNeeded = 0;
  145.  
  146.         var charIndex = -1;
  147.         var charAsciiValue;
  148.         var advanceToNextChar = function() {
  149.             charIndex++;
  150.             charAsciiValue = input.charCodeAt(charIndex);
  151.             return charIndex < input.length;
  152.         };
  153.  
  154.         while (true) {
  155.             var base64Char;
  156.  
  157.             // handle 1st char
  158.             if (!advanceToNextChar()) break;
  159.             base64Char = charAsciiValue >>> 2;
  160.             remainingBits = charAsciiValue & 3; // 0000 0011
  161.             result += getBase64Char(base64Char); // 1st char
  162.             additionalCharsNeeded = 3;
  163.  
  164.             // handle 2nd char
  165.             if (!advanceToNextChar()) break;
  166.             base64Char = (remainingBits << 4) | (charAsciiValue >>> 4);
  167.             remainingBits = charAsciiValue & 15; // 0000 1111
  168.             result += getBase64Char(base64Char); // 2nd char
  169.             additionalCharsNeeded = 2;
  170.  
  171.             // handle 3rd char
  172.             if (!advanceToNextChar()) break;
  173.             base64Char = (remainingBits << 2) | (charAsciiValue >>> 6);
  174.             result += getBase64Char(base64Char); // 3rd char
  175.             remainingBits = charAsciiValue & 63; // 0011 1111
  176.             result += getBase64Char(remainingBits); // 4th char
  177.             additionalCharsNeeded = 0;
  178.         }
  179.  
  180.         // there may be an additional 2-3 chars that need to be added
  181.         if (additionalCharsNeeded == 2) {
  182.             remainingBits = remainingBits << 2; // 4 extra bits
  183.             result += getBase64Char(remainingBits) + "=";
  184.         } else if (additionalCharsNeeded == 3) {
  185.             remainingBits = remainingBits << 4; // 2 extra bits
  186.             result += getBase64Char(remainingBits) + "==";
  187.         } else if (additionalCharsNeeded != 0) {
  188.             throw "Unhandled number of additional chars needed: " + additionalCharsNeeded;
  189.         }
  190.  
  191.         return result;
  192.     }
  193. })()
RAW Paste Data
Top