Skip to content

Commit

Permalink
Added special handling for archiving text files on the web, namely re…
Browse files Browse the repository at this point in the history
…move the HTML wrapper that Chrome adds when viewing content on the web. Related to #62
  • Loading branch information
machawk1 committed Aug 13, 2014
1 parent 6cbeeeb commit 44f558f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
6 changes: 3 additions & 3 deletions js/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function checkForValidUrl(tabId, changeInfo, tab) {
}

function alertContent(){
chrome.tabs.executeScript(null, {file:"js/jquery-2.0.2.min.js"}, function() {
chrome.tabs.executeScript(null, {file:"js/jquery-2.1.1.min.js"}, function() {
chrome.tabs.executeScript(null, {file:"js/jquery.rc4.js"}, function() {
chrome.tabs.executeScript(null, { file: "js/alertContent.js" }, function(){

Expand Down Expand Up @@ -68,7 +68,7 @@ function encodeImages(){
function encrypt(){
var key = document.getElementById('key').value;
if(key === ""){alert("First enter a key for encryption."); return;}
chrome.tabs.executeScript(null, {file:"js/jquery-2.0.2.min.js"}, function() {
chrome.tabs.executeScript(null, {file:"js/jquery-2.1.1.min.js"}, function() {
chrome.tabs.executeScript(null, {file:"js/jquery.rc4.js"}, function() {
chrome.tabs.executeScript(null, {code: "var params = {k:'"+key+"'};"}, function(){
chrome.tabs.executeScript(null, { file: "js/encryptPage.js" }, function(){
Expand Down Expand Up @@ -120,7 +120,7 @@ function generate_Warc(){
var imageData = [];
var imageURIs = [];
//console.log(("generate_warc");
chrome.tabs.executeScript(null, {file:"js/jquery-2.0.2.min.js"}, function() { /* Dependency for hash library and general goodness*/
chrome.tabs.executeScript(null, {file:"js/jquery-2.1.1.min.js"}, function() { /* Dependency for hash library and general goodness*/
chrome.tabs.executeScript(null, {file:"js/jquery.rc4.js"}, function() { /* Hash library */
chrome.tabs.executeScript(null, {file:"js/date.js"}, function() { /* Good date formatting library */
var uris = [];
Expand Down
12 changes: 11 additions & 1 deletion js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ chrome.extension.onConnect.addListener(function(port) {
var ret = {};

for(var uri in imgObjs){
console.error(uri);
console.log("Fetching image at "+uri);
if(uri.indexOf("data:") == -1){
fetchImage(uri);
}
Expand Down Expand Up @@ -228,6 +228,16 @@ chrome.extension.onConnect.addListener(function(port) {
}

var domAsText = document.documentElement.outerHTML;

// This accounts for foo.txt documents on the web, which chrome puts a wrapper around
var textDocumentStarterString = '<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">';
if(domAsText.substr(0, textDocumentStarterString.length) == textDocumentStarterString){
console.log("Adjusting WARC algorithm to account for text rather than HTML document.");

domAsText = $(document).find("pre").html(); //replace text w/ html wrapper with just text
dtstr = ""; //remove the doctype injection
}

//domAsText = domAsText.replace(/[\n\r]+/g,"");
//console.log(("length before post: "+domAsText.length);
port.postMessage({
Expand Down
6 changes: 0 additions & 6 deletions js/jquery-2.0.2.min.js

This file was deleted.

4 changes: 4 additions & 0 deletions js/jquery-2.1.1.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions js/jquery-2.1.1.min.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "WARCreate",
"version": "0.2014.8.11",
"version": "0.2014.8.13",

"description": "Create Wayback-Consumable WARC Files from Any Webpage",
"icons" : {
Expand All @@ -17,7 +17,7 @@
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["js/imagesFromCSSExtractor.js","js/content.js"]
"js": ["js/jquery-2.1.1.min.js","js/imagesFromCSSExtractor.js","js/content.js"]
}
],
"page_action" :
Expand All @@ -30,6 +30,7 @@
"webRequest",
"webRequestBlocking",
"tabs",
"activeTab",
"storage",
"unlimitedStorage",
"http://*/*",
Expand Down

0 comments on commit 44f558f

Please sign in to comment.