Skip to content

Commit

Permalink
Added Archive.is to caches
Browse files Browse the repository at this point in the history
Wayback Machine takes you to the latest page
  • Loading branch information
Dbz committed Jul 24, 2017
1 parent d06a8ee commit b45b4ab
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 26 deletions.
4 changes: 3 additions & 1 deletion Chrome Store/ChromeStore.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This is a chrome browser extension that allows the user to view a cached version of the current webpage. Set your primary cache as Google Cache, Wayback Machine, or Coral CDN. If what you're looking for isn't found, it'll cycle through the other caches until it finds what you're looking for. There are three ways to use WebCache:
This is a chrome browser extension that allows the user to view a cached version of the current webpage. Set your primary cache as Google Cache, Wayback Machine, Archive.is, or Coral CDN. If what you're looking for isn't found, it'll cycle through the other caches until it finds what you're looking for. There are three ways to use WebCache:

1. Click the extension button to view the cached version of the web page

Expand All @@ -17,6 +17,8 @@ V 4.1.0
--------

- Wayback Machine URL now takes you directly to the latest snapshot of a page
- Added Archive.is as to the caches
- Code Refactoring

V 4.0.0
--------
Expand Down
3 changes: 2 additions & 1 deletion context-menu.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
var CONTEXT_HASH = {
"google-cache": "http://webcache.googleusercontent.com/search?q=cache:",
"wayback-machine": "http://web.archive.org/web/",
"archive-is": "http://archive.is/newest/",
"coral-cdn": ".nyud.net"
};

function formUrl(context, url) {
var contextUrl = CONTEXT_HASH[context];
var isHTTPS = url.substring(0, 6) === "https:";

// Google and Wayback Machine
// Google, Wayback Machine, and Archive is
if(context !== "coral-cdn") {
return contextUrl + (isHTTPS ? url.substr(8) : url.substr(7));
} else { // Coral CDN
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

"name": "WebCache",
"short_name" : "WebCache",
"version": "4.0.1",
"description": "Want to view a cached website (Google Cache, Wayback Machine, Coral CDN)? With WebCahce it only takes 1 click!",
"version": "4.1.0",
"description": "Want to view a cached website? With WebCache it takes 1 click to view the Google Cache, Wayback Machine, Archive.is, or Coral CDN!",
"browser_action": {
"default_title": "WebCache"
},
Expand Down
14 changes: 13 additions & 1 deletion options.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ <h3 class="title">WebCache Options</h3>
<label class="context-menu-label" for="wayback-machine">Wayback Machine</label>
</div>

<div class="context-cache">
<input id="archive-is" class="checkbox" type="checkbox"/>
<label class="context-menu-label" for="archive-is">Archive Is</label>
</div>

<div class="context-cache">
<input id="coral-cdn" class="checkbox" type="checkbox"/>
<label class="context-menu-label" for="coral-cdn">Coral CDN</label>
Expand All @@ -43,10 +48,17 @@ <h3 class="title">WebCache Options</h3>
<p>Google Cache</p>
<span class="ui-icon ui-icon-grip-dotted-horizontal icon"></span>
</li>

<li class="list-item" id="wayback-machine-sortable">
<p>Wayback Machine</p>
<span class="ui-icon ui-icon-grip-dotted-horizontal icon"></span>
</li>

<li class="list-item" id="archive-is-sortable">
<p>Archive Is</p>
<span class="ui-icon ui-icon-grip-dotted-horizontal icon"></span>
</li>

<li class="list-item" id="coral-cdn-sortable">
<p>Coral CDN</p>
<span class="ui-icon ui-icon-grip-dotted-horizontal icon"></span>
Expand Down Expand Up @@ -77,4 +89,4 @@ <h3 class="title">WebCache Options</h3>
<script src="options.js"></script>
</body>

</html>
</html>
27 changes: 24 additions & 3 deletions options.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
var CONTEXT_MENU_CACHES = [
"google-cache",
"wayback-machine",
"archive-is",
"coral-cdn"
];

var SORTABLE_CACHES = [
"google-cache-sortable",
"wayback-machine-sortable",
"archive-is-sortable",
"coral-cdn-sortable"
];


// Remove context menu caches
function removeContextMenu(cache) {
var saveObj = {};
Expand All @@ -30,8 +39,8 @@ function createContextMenu(cache) {
// Add/Remove context menu caches
function updateContextMenuCaches(event) {
var cache = $(event.target).attr("for");
var add_context_menu = !$("#" + cache).is(":checked");
add_context_menu ? createContextMenu(cache) : removeContextMenu(cache);
var addContextMenu = !$("#" + cache).is(":checked");
addContextMenu ? createContextMenu(cache) : removeContextMenu(cache);
}

var order = [];
Expand All @@ -53,11 +62,22 @@ $("#sortable").sortable({
chrome.storage.sync.get("cacheOrder4", function(result) {
var ul = $("#sortable");
var li = ul.children("li").get();
order = result["cacheOrder4"] || ["google-cache-sortable", "wayback-machine-sortable", "coral-cdn-sortable"];
order = result["cacheOrder4"] || SORTABLE_CACHES

if(order.length < SORTABLE_CACHES.length) { // We have just updated, so add the new caches and then save them
order = order.concat($(SORTABLE_CACHES).not(order).get());
var saveObj = {};
saveObj["cacheOrder4"] = order;
chrome.storage.sync.set(saveObj, function() {
console.log("Saved Cache Ordering Preferences");
});
}

// Order the caches
li.sort(function(a, b) {
return order.indexOf($(a).attr("id")) - order.indexOf($(b).attr("id"));
});

ul.append(li);
});

Expand Down Expand Up @@ -87,3 +107,4 @@ $("#myonoffswitch").click(function(event) {
$(".context-menu-label").click(updateContextMenuCaches);

$("#sortable").disableSelection();

43 changes: 25 additions & 18 deletions redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,34 @@ var isHTTPS = true;
var index = 0;
var numberOfRedirects = 0;
var redirecting = false;

var cacheURL = [
"http://webcache.googleusercontent.com/search?q=cache:",
"http://web.archive.org/web/",
".nyud.net"
];
var cacheNames = [
var sortableCaches = [
"google-cache-sortable",
"wayback-machine-sortable",
"archive-is-sortable",
"coral-cdn-sortable"
];
var cacheURLs = [
"http://webcache.googleusercontent.com/search?q=cache:",
"http://web.archive.org/web/",
"http://archive.is/newest/",
".nyud.net"
];

var URL_HASH = [
{ name: "google-cache-sortable", URL: "http://webcache.googleusercontent.com/search?q=cache:" },
{ name: "wayback-machine-sortable", URL: "http://web.archive.org/web/*/" },
{ name: "archive-is-sortable", URL: "http://archive.is/newest/" },
{ name: "coral-cdn-sortable", URL: ".nyud.net" }
];

function getURL() {
++numberOfRedirects;
if(cacheURL[index] == cacheURL.length) {
if(cacheURLs[index] == cacheURLs.length) {
index = 0;
}

if(cacheURL[index] != ".nyud.net") { // Google and Wayback Machine
return cacheURL[index] + (isHTTPS ? currentURL.substr(8) : currentURL.substr(7));
if(cacheURLs[index] != ".nyud.net") { // Google, Wayback Machine, and Archive Is
return cacheURLs[index] + (isHTTPS ? currentURL.substr(8) : currentURL.substr(7));
} else { // Coral CDN
if(currentURL.slice(-1) == "/") {
return currentURL.substring(0, currentURL.length -1) + ".nyud.net";
Expand All @@ -39,7 +42,7 @@ function getURL() {

function handler(details) {
//console.log("StatusLine is: " + details.statusLine);
if(numberOfRedirects > cacheURL.length) { // There is no cache available
if(numberOfRedirects > cacheURLs.length) { // There is no cache available
chrome.webRequest.onHeadersReceived.removeListener(handler);
redirecting = false;
return { cancel: true };
Expand All @@ -60,19 +63,17 @@ function handler(details) {

function openPage(currentTab) {
chrome.storage.sync.get("cacheOrder4", function(result) {
var cacheOrder = result["cacheOrder4"] || cacheNames;
var cacheOrder = result["cacheOrder4"] || sortableCaches;

URL_HASH.sort(function(a, b) {
return cacheOrder.indexOf(a.name) - cacheOrder.indexOf(b.name);
});

for(var i = 0; i < 3; i++) {
cacheURL[i] = URL_HASH[i].URL;
cacheNames[i] = URL_HASH[i].name;
for(var i = 0; i < cacheURLs.length; i++) {
cacheURLs[i] = URL_HASH[i].URL;
sortableCaches[i] = URL_HASH[i].name;
}

// console.log(cacheURL);

index = 0;
numberOfRedirects = 0;
redirecting = true;
Expand Down Expand Up @@ -139,12 +140,18 @@ chrome.runtime.onInstalled.addListener(function(details) {
chrome.storage.sync.get("cacheOrder", function(result) {
if(Object.keys(result).length == 0) {
var saveObject = {
"cacheOrder4": cacheNames,
"cacheOrder4": sortableCaches,
"auto-detect": "off"
};
chrome.storage.sync.set(saveObject);
} else if(result["cacheOrder"].length < cacheURLs.length) {
var saveObject = {
"cacheOrder": result["cacheOrder"].concat($(sortableCaches)).not(result["cacheOrder"]).get())
};
chrome.storage.sync.set(saveObject);
}
});
});

chrome.browserAction.onClicked.addListener(openPage);

0 comments on commit b45b4ab

Please sign in to comment.