Skip to content

Commit

Permalink
new release candidate (v4.70)
Browse files Browse the repository at this point in the history
added window seperated recovery
removable recovery items
options now autosave
  • Loading branch information
deanoemcke committed Feb 18, 2013
1 parent f11e9ab commit d09537a
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 184 deletions.
44 changes: 28 additions & 16 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ var tgs = (function () {
gsStorage.setPreviewImage(tab.url, previewUrl);
}

tabProperties = {
date: new Date(),
title: tab.title,
url: tab.url,
state: 'suspended',
favicon: "chrome://favicon/" + tab.url,
pinned: tab.pinned,
index: tab.index,
windowId: tab.windowId
};

if (tab.incognito) {
tabProperties = {date: new Date(), title: tab.title, url: tab.url, state: 'suspended', index: tab.index, favicon: tab.favIconUrl };
} else {
tabProperties = {date: new Date(), title: tab.title, url: tab.url, state: 'suspended', index: tab.index, favicon: "chrome://favicon/" + tab.url };
tabProperties.favicon = tab.favIconUrl;
}

//add suspend information to start of history array
Expand Down Expand Up @@ -234,30 +243,33 @@ var tgs = (function () {

//check for very old history migration
if (oldGsHistory !== null &&
(typeof (lastVersion) === 'undefined' || parseFloat(lastVersion) < 4.60)) {
(lastVersion === null || parseFloat(lastVersion) < 4.61)) {

//merge old gsHistory with new one
gsHistory = gsStorage.fetchGsHistory();
ii = oldGsHistory.length;
for (i = 0; i < ii; i++) {
gsHistory.push(oldGsHistory[i]);
}
gsStorage.setGsHistory(gsHistory);
gsStorage.removeOldGsHistory();
//merge old gsHistory with new one
gsHistory = gsStorage.fetchGsHistory();
ii = oldGsHistory.length;
for (i = 0; i < ii; i++) {
gsHistory.push(oldGsHistory[i]);
}
gsStorage.setGsHistory(gsHistory);
gsStorage.removeOldGsHistory();
}

//if they are installing for the first time
if (typeof (lastVersion) === 'undefined') {
gsStorage.setVersion('4.60');
if (lastVersion === null) {

//show welcome screen
chrome.tabs.create({url: chrome.extension.getURL("welcome.html")});
gsStorage.setVersion('4.61');
gsStorage.setGsHistory([]);
upgraded = true;

//otherwise if they are upgrading
} else if (parseFloat(lastVersion) < 4.60) {
} else if (parseFloat(lastVersion) < 4.61) {

//show new update screen
chrome.tabs.create({url: chrome.extension.getURL("update.html")});
gsStorage.setVersion('4.60');
gsStorage.setVersion('4.61');
upgraded = true;
}

Expand Down
4 changes: 2 additions & 2 deletions gsStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@

fetchTabFromHistory : function (tabUrl) {

var gsHistory = JSON.parse(localStorage.getItem('gsHistory2')),
var gsHistory = this.fetchGsHistory(),
i;

for (i = 0; i < gsHistory.length; i++) {
Expand All @@ -124,7 +124,7 @@

saveTabToHistory : function (tabUrl, tabProperties) {

var gsHistory = JSON.parse(localStorage.getItem('gsHistory2')),
var gsHistory = this.fetchGsHistory(),
i;

for (i = 0; i < gsHistory.length; i++) {
Expand Down
20 changes: 16 additions & 4 deletions history.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ h1 {
margin-top: 10px;
font-size: 30px;
color: #666;
margin-bottom: 35px;
}
h2 {
font-size: 20px;
color: #666;
padding-left: 10px;
padding-top: 10px;
padding-top: 15px;
}
img {
padding-left: 10px;
padding-right: 10px;
}
p {
max-width: 900px;
}
ul, li {
list-style-type: none;
Expand All @@ -27,7 +30,7 @@ ul, li {
}
a {
line-height: 30px;
padding-left: 10px;
font-weight: normal;
color: #333;
}
#gsHistory span {
Expand All @@ -40,4 +43,13 @@ a {
font-size: 14px;
color: #888;
padding-left: 20px;
}
.recoveryLink .itemHover {
visibility: hidden;
margin: 0px;
padding: 0px 2px 3px;
cursor: pointer;
}
.recoveryLink:hover .itemHover {
visibility: visible;
}
109 changes: 60 additions & 49 deletions history.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,54 @@
}
}

function compareDate(a, b) {
if (a.date > b.date) {
return -1;
}
if (a.date < b.date) {
return 1;
}
return 0;
}

function fetchGsHistoryForDate(date) {

var gsHistory = gsStorage.fetchGsHistory(),
curDate = date,
historyMap = {},
historyArray = [],
groupKey,
tabProperties,
i;

for (i = 0; i < gsHistory.length; i++) {
tabProperties = gsHistory[i];
groupKey = getFormattedDate(tabProperties.date, false);

if (curDate === groupKey && !historyMap.hasOwnProperty(tabProperties.url)) {
historyMap[tabProperties.url] = true;
historyArray.push(tabProperties);
}
}
return historyArray;
}

function reloadTabs(date, suspend) {
var curDate = date;
return function () {

var gsHistory = gsStorage.fetchGsHistory(),
historyMap = {},
groupKey,
tabProperties,
i,
var gsHistory = fetchGsHistoryForDate(date),
url,
index;

chrome.tabs.query({}, function (tabs) {
i;

for (i = 0; i < gsHistory.length; i++) {
tabProperties = gsHistory[i];
groupKey = getFormattedDate(tabProperties.date, false);

if (curDate === groupKey) {
if (!historyMap.hasOwnProperty(tabProperties.url)) {
historyMap[tabProperties.url] = true;
url = suspend ? gsStorage.generateSuspendedUrl(tabProperties.url) : tabProperties.url;
chrome.tabs.create({url: url});
}
}
}
});
gsHistory.reverse();
for (i = 0; i < gsHistory.length; i++) {
url = suspend ? gsStorage.generateSuspendedUrl(gsHistory[i].url) : gsHistory[i].url;
chrome.tabs.create({url: url});
}
};
}

function compare(a, b) {
if (a.date > b.date) {
return -1;
}
if (a.date < b.date) {
return 1;
}
return 0;
}

window.onload = function () {

Expand All @@ -77,32 +86,34 @@

try {
historyDiv = document.getElementById('gsHistory');
gsHistory.sort(compare);
gsHistory.sort(compareDate);

for (i = 0; i < gsHistory.length; i++) {
tabProperties = gsHistory[i];
groupKey = getFormattedDate(tabProperties.date, false);
key = groupKey + tabProperties.url;

if (groupKey !== curGroupKey) {
curGroupKey = groupKey;
groupHeading = document.createElement("h2");
groupHeading.innerHTML = groupKey;
groupLinkSuspend = document.createElement("a");
groupLinkSuspend.className = "groupLink";
groupLinkSuspend.innerHTML = "re-suspend all tabs for this day";
groupLinkSuspend.setAttribute('href', "#");
groupLinkSuspend.onclick = reloadTabs(groupKey, true);
groupHeading.appendChild(groupLinkSuspend);
groupLinkUnsuspend = document.createElement("a");
groupLinkUnsuspend.className = "groupLink";
groupLinkUnsuspend.innerHTML = "reload all tabs for this day";
groupLinkUnsuspend.setAttribute('href', "#");
groupLinkUnsuspend.onclick = reloadTabs(groupKey, false);
groupHeading.appendChild(groupLinkUnsuspend);
historyDiv.appendChild(groupHeading);
}
if (!historyMap.hasOwnProperty(key)) {

//print header for group
if (groupKey !== curGroupKey) {
curGroupKey = groupKey;
groupHeading = document.createElement("h2");
groupHeading.innerHTML = groupKey;
groupLinkSuspend = document.createElement("a");
groupLinkSuspend.className = "groupLink";
groupLinkSuspend.innerHTML = "re-suspend all tabs for this day";
groupLinkSuspend.setAttribute('href', "#");
groupLinkSuspend.onclick = reloadTabs(groupKey, true);
groupHeading.appendChild(groupLinkSuspend);
groupLinkUnsuspend = document.createElement("a");
groupLinkUnsuspend.className = "groupLink";
groupLinkUnsuspend.innerHTML = "reload all tabs for this day";
groupLinkUnsuspend.setAttribute('href', "#");
groupLinkUnsuspend.onclick = reloadTabs(groupKey, false);
groupHeading.appendChild(groupLinkUnsuspend);
historyDiv.appendChild(groupHeading);
}
historyMap[key] = true;
historyImg = document.createElement("img");
historyImg.setAttribute('src', 'chrome://favicon/' + tabProperties.url);
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "The Great Suspender",
"version": "4.60",
"version": "4.70",
"permissions": [
"tabs",
"storage",
Expand Down
4 changes: 0 additions & 4 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ <h1>The Great Suspender :: Settings</h1>
<option value="720">12 hours</option>
</select>

<br />
<br />
<button id='save'>Save</button>

</div>

<div>
Expand Down
14 changes: 10 additions & 4 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@
window.clearInterval(readyStateCheckInterval);

var previewEl = document.getElementById('preview'),
saveEl = document.getElementById('save'),
whitelistEl = document.getElementById("whitelist"),
timeToSuspendEl = document.getElementById("timeToSuspend"),
showHistoryEl = document.getElementById('showHistory'),
clearHistoryEl = document.getElementById('clearHistory');

saveEl.onclick = function (e) {
save_options();
previewEl.onclick = function (e) {
gsStorage.setPreviewOption(preview.checked);
};
whitelistEl.onkeyup = function (e) {
gsStorage.setWhitelist(whitelistEl.value);
};
timeToSuspendEl.onchange = function (e) {
gsStorage.setTimeToSuspendOption(timeToSuspendEl.children[timeToSuspendEl.selectedIndex].value);
};

showHistoryEl.onclick = function (e) {
chrome.tabs.create({url: chrome.extension.getURL("history.html")});
};
Expand Down
15 changes: 4 additions & 11 deletions recovery.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,17 @@ <h1>The Great Suspender :: Recovery</h1>
<br />
This is common after an extension update or a chrome crash.
<br />
Below is a list of tabs that were in suspension before the restart.
Below is a list of tabs that were in suspension before the restart. You can unsuspend them all together or one at a time from the links below.
<br />
You can unsuspend them all together or one at a time from the links below.
Alternatively, you can visit the <a id='historyLink' href='#'>history page</a> and reload suspended tabs from there.
</p>

<h2>
Suspended Tabs:
<a id='resuspendLink' href='#' class='groupLink' title="Reopen all tabs in a suspended state">resuspend all tabs</a>
<a id='unsuspendLink' href='#' class='groupLink' title="Reopen all tabs in an unsuspended state">reload all tabs</a>
<a id='historyLink' href='#' class='groupLink' title="Goto the History page">view history</a>
<a id='clearLink' href='#' class='groupLink' title="Remove these tabs from history">clear results</a>
</h2>
<ul id='recoveryLinks'></ul>
<br />
<p>
Important: If you are seeing this page repeatedly, then something may be wrong with the extension.
Important: If you are seeing this page repeatedly, try <a id='clearLink' href='#'>clearing the results</a>.
<br />
Please let me know so that I can attempt to repair the problem.
If this does not fix the problem, please let me know so that I can attempt to repair the problem.
</p>

</div>
Expand Down
Loading

0 comments on commit d09537a

Please sign in to comment.