Skip to content

Commit

Permalink
Add suspend/unsuspend toggle with message (#579 #594)
Browse files Browse the repository at this point in the history
  • Loading branch information
deanoemcke committed Oct 23, 2017
1 parent 999aa08 commit 96bbe81
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"ext_extension_name": { "message": "The Great Suspender" },
"ext_extension_description": { "message": "Automatically suspends unused tabs to free up system resources" },
"ext_default_title": { "message": "The Great Suspender" },
"ext_cmd_suspend_tab_description": { "message": "Suspend active tab" },
"ext_cmd_suspend_tab_description": { "message": "Suspend/Unsuspend active tab" },
"ext_cmd_unsuspend_tab_description": { "message": "Unsuspend active tab" },
"ext_cmd_suspend_active_window_description": { "message": "Suspend all other tabs in active window" },
"ext_cmd_unsuspend_active_window_description": { "message": "Unsuspend all tabs in active window" },
Expand Down Expand Up @@ -144,7 +144,8 @@
"html_suspended_tab_suspended": { "message": "Tab suspended" },
"html_suspended_tab_reload": { "message": "Reload tab" },
"html_suspended_tab_whitelist": { "message": "Whitelist site" },
"html_suspended_click_to_reload": { "message": "Refresh or click to reload" },
"html_suspended_click_to_reload": { "message": "Click to reload" },
"html_suspended_hotkey_to_reload": { "message": "keyboard shortcut: " },
"html_suspended_toast_not_connected": { "message": "You are not connected to the internet" },
"html_suspended_toast_reload_disabled": { "message": "Automatic tab reloading is temporarily disabled." },
"html_suspended_modal_header": { "message": "What would you like to whitelist?" },
Expand Down Expand Up @@ -244,5 +245,5 @@
"js_update_button_reload": { "message": "Update extension now" },

// Keyboard shortcuts page (Javascript code)
"js_shortcuts_not_set": { "message": "(not set)" }
"js_shortcuts_not_set": { "message": "not set" }
}
5 changes: 3 additions & 2 deletions src/_locales/zh/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"ext_extension_name": { "message": "The Great Suspender" },
"ext_extension_description": { "message": "凍結暫時用不到的分頁,達到系統資源釋放。" },
"ext_default_title": { "message": "The Great Suspender" },
"ext_cmd_suspend_tab_description": { "message": "凍結目前的分頁" },
"ext_cmd_suspend_tab_description": { "message": "冻结/恢复当前页面" },
"ext_cmd_unsuspend_tab_description": { "message": "恢復目前的分頁" },
"ext_cmd_suspend_active_window_description": { "message": "凍結目前視窗中所有的分頁" },
"ext_cmd_unsuspend_active_window_description": { "message": "恢復目前視窗中所有的分頁" },
Expand Down Expand Up @@ -144,7 +144,8 @@
"html_suspended_tab_suspended": { "message": "分頁已經被凍結" },
"html_suspended_tab_reload": { "message": "重新載入" }, //TODO: Used google translate. important!!1
"html_suspended_tab_whitelist": { "message": "添加到例外列表" }, //TODO: Used google translate. important!!1
"html_suspended_click_to_reload": { "message": "刷新或點擊此處重新加載" }, //TODO: Used google translate. important!!1
"html_suspended_click_to_reload": { "message": "点击这里重新载入" }, //TODO: Used google translate. important!!1
"html_suspended_hotkey_to_reload": { "message": "鍵盤快速鍵: " }, //TODO: Used google translate. important!!1
"html_suspended_toast_not_connected": { "message": "您沒有連接到網絡" }, //TODO: Used google translate. important!!1
"html_suspended_toast_reload_disabled": { "message": "禁用自動重新加載。" }, //TODO: Used google translate. important!!1
"html_suspended_modal_header": { "message": "你想要什麼白名單?" }, //TODO: Used google translate. important!!1
Expand Down
10 changes: 8 additions & 2 deletions src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,21 @@ a.historyLink:hover {
.suspendedMsg, .gsPreview {
cursor: pointer;
}
.suspendedMsg h1, .suspendedMsg h2 {
font-size: 60px;
.suspendedMsg h1, .suspendedMsg h2, .suspendedMsg h3 {
color: #134960;
margin: 30px 0 0;
font-weight: 300;
}
.suspendedMsg h1 {
font-size: 60px;
}
.suspendedMsg h2 {
font-size: 40px;
}
.suspendedMsg h3 {
font-size: 20px;
font-style: italic;
}
@media all and (max-width: 600px) {
.suspendedMsg h1 {
font-size: 45px;
Expand Down
16 changes: 15 additions & 1 deletion src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ var tgs = (function () { // eslint-disable-line no-unused-vars
callback(tabs[0]);
}
else {
//TODO: Possibly fallback on globalCurrentTabId here?
//see https://github.com/deanoemcke/thegreatsuspender/issues/574
callback(null);
}
});
Expand Down Expand Up @@ -214,6 +216,18 @@ var tgs = (function () { // eslint-disable-line no-unused-vars
});
}

function toggleSuspendedStateOfHighlightedTab() {
getCurrentlyActiveTab(function (activeTab) {
if (activeTab) {
if (gsUtils.isSuspendedTab(activeTab)) {
unsuspendTab(activeTab);
} else {
requestTabSuspension(activeTab, 1);
}
}
});
}

function suspendHighlightedTab() {
getCurrentlyActiveTab(function (activeTab) {
if (activeTab) {
Expand Down Expand Up @@ -684,7 +698,7 @@ var tgs = (function () { // eslint-disable-line no-unused-vars

chrome.commands.onCommand.addListener(function (command) {
if (command === '1-suspend-tab') {
suspendHighlightedTab();
toggleSuspendedStateOfHighlightedTab();

} else if (command === '2-unsuspend-tab') {
unsuspendHighlightedTab();
Expand Down
6 changes: 3 additions & 3 deletions src/js/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
chrome.commands.getAll(function (commands) {

commands.forEach(function (command) {
if (command.name !== '_execute_browser_action') {
var shortcut = command.shortcut !== '' ? command.shortcut : chrome.i18n.getMessage('js_shortcuts_not_set'),
style = count % 2 === 0 ? '"margin: 0 0 2px;"' : '';
if (command.name !== '_execute_browser_action' && command.name !== '2-unsuspend-tab') {
var shortcut = command.shortcut !== '' ? command.shortcut : '(' + chrome.i18n.getMessage('js_shortcuts_not_set') + ')';
var style = count % 2 === 1 ? '"margin: 0 0 2px;"' : '';
shortcutsEl.innerHTML += '<p style=' + style + '>' + command.description + ': ' + shortcut + '</p>';
count++;
}
Expand Down
20 changes: 20 additions & 0 deletions src/js/suspended.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@
document.getElementById('gsTopBarTitle').setAttribute('href', url);
document.getElementById('gsTopBarImg').setAttribute('src', favicon);

//update hotkey
chrome.commands.getAll(function (commands) {
var hotkeyEl = document.getElementById('hotkeyCommand');
if (!hotkeyEl) { return; }
var toggleCommand = commands.find(function (command) {
return (command.name === '1-suspend-tab');
});
if (hotkeyEl && toggleCommand && toggleCommand.shortcut !== '') {
hotkeyEl.innerHTML = toggleCommand.shortcut;
}
else {
var shortcutNotSetEl = document.createElement('a');
shortcutNotSetEl.innerHTML = chrome.i18n.getMessage('js_shortcuts_not_set');
hotkeyEl.appendChild(shortcutNotSetEl);
hotkeyEl.onclick = function () {
chrome.tabs.create({url: 'chrome://extensions/configureCommands'});
};
}
});

//update whitelist text
var isWhitelisted = gsUtils.checkWhiteList(url);
if (isWhitelisted) {
Expand Down
1 change: 1 addition & 0 deletions src/suspended.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<div class="centerBox">
<h1 data-i18n="__MSG_html_suspended_tab_suspended__"></h1>
<h2 data-i18n="__MSG_html_suspended_click_to_reload__"></h2>
<h3><span>(</span><span data-i18n="__MSG_html_suspended_hotkey_to_reload__"></span><span id="hotkeyCommand"></span><span>)</span></h3>
</div>
</div>
<div id="refreshSpinner"></div>
Expand Down

0 comments on commit 96bbe81

Please sign in to comment.