Skip to content

Commit 96bbe81

Browse files
committed
Add suspend/unsuspend toggle with message (#579 #594)
1 parent 999aa08 commit 96bbe81

File tree

7 files changed

+54
-11
lines changed

7 files changed

+54
-11
lines changed

src/_locales/en/messages.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"ext_extension_name": { "message": "The Great Suspender" },
44
"ext_extension_description": { "message": "Automatically suspends unused tabs to free up system resources" },
55
"ext_default_title": { "message": "The Great Suspender" },
6-
"ext_cmd_suspend_tab_description": { "message": "Suspend active tab" },
6+
"ext_cmd_suspend_tab_description": { "message": "Suspend/Unsuspend active tab" },
77
"ext_cmd_unsuspend_tab_description": { "message": "Unsuspend active tab" },
88
"ext_cmd_suspend_active_window_description": { "message": "Suspend all other tabs in active window" },
99
"ext_cmd_unsuspend_active_window_description": { "message": "Unsuspend all tabs in active window" },
@@ -144,7 +144,8 @@
144144
"html_suspended_tab_suspended": { "message": "Tab suspended" },
145145
"html_suspended_tab_reload": { "message": "Reload tab" },
146146
"html_suspended_tab_whitelist": { "message": "Whitelist site" },
147-
"html_suspended_click_to_reload": { "message": "Refresh or click to reload" },
147+
"html_suspended_click_to_reload": { "message": "Click to reload" },
148+
"html_suspended_hotkey_to_reload": { "message": "keyboard shortcut: " },
148149
"html_suspended_toast_not_connected": { "message": "You are not connected to the internet" },
149150
"html_suspended_toast_reload_disabled": { "message": "Automatic tab reloading is temporarily disabled." },
150151
"html_suspended_modal_header": { "message": "What would you like to whitelist?" },
@@ -244,5 +245,5 @@
244245
"js_update_button_reload": { "message": "Update extension now" },
245246

246247
// Keyboard shortcuts page (Javascript code)
247-
"js_shortcuts_not_set": { "message": "(not set)" }
248+
"js_shortcuts_not_set": { "message": "not set" }
248249
}

src/_locales/zh/messages.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"ext_extension_name": { "message": "The Great Suspender" },
44
"ext_extension_description": { "message": "凍結暫時用不到的分頁,達到系統資源釋放。" },
55
"ext_default_title": { "message": "The Great Suspender" },
6-
"ext_cmd_suspend_tab_description": { "message": "凍結目前的分頁" },
6+
"ext_cmd_suspend_tab_description": { "message": "冻结/恢复当前页面" },
77
"ext_cmd_unsuspend_tab_description": { "message": "恢復目前的分頁" },
88
"ext_cmd_suspend_active_window_description": { "message": "凍結目前視窗中所有的分頁" },
99
"ext_cmd_unsuspend_active_window_description": { "message": "恢復目前視窗中所有的分頁" },
@@ -144,7 +144,8 @@
144144
"html_suspended_tab_suspended": { "message": "分頁已經被凍結" },
145145
"html_suspended_tab_reload": { "message": "重新載入" }, //TODO: Used google translate. important!!1
146146
"html_suspended_tab_whitelist": { "message": "添加到例外列表" }, //TODO: Used google translate. important!!1
147-
"html_suspended_click_to_reload": { "message": "刷新或點擊此處重新加載" }, //TODO: Used google translate. important!!1
147+
"html_suspended_click_to_reload": { "message": "点击这里重新载入" }, //TODO: Used google translate. important!!1
148+
"html_suspended_hotkey_to_reload": { "message": "鍵盤快速鍵: " }, //TODO: Used google translate. important!!1
148149
"html_suspended_toast_not_connected": { "message": "您沒有連接到網絡" }, //TODO: Used google translate. important!!1
149150
"html_suspended_toast_reload_disabled": { "message": "禁用自動重新加載。" }, //TODO: Used google translate. important!!1
150151
"html_suspended_modal_header": { "message": "你想要什麼白名單?" }, //TODO: Used google translate. important!!1

src/css/style.css

+8-2
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,21 @@ a.historyLink:hover {
413413
.suspendedMsg, .gsPreview {
414414
cursor: pointer;
415415
}
416-
.suspendedMsg h1, .suspendedMsg h2 {
417-
font-size: 60px;
416+
.suspendedMsg h1, .suspendedMsg h2, .suspendedMsg h3 {
418417
color: #134960;
419418
margin: 30px 0 0;
420419
font-weight: 300;
421420
}
421+
.suspendedMsg h1 {
422+
font-size: 60px;
423+
}
422424
.suspendedMsg h2 {
423425
font-size: 40px;
424426
}
427+
.suspendedMsg h3 {
428+
font-size: 20px;
429+
font-style: italic;
430+
}
425431
@media all and (max-width: 600px) {
426432
.suspendedMsg h1 {
427433
font-size: 45px;

src/js/background.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ var tgs = (function () { // eslint-disable-line no-unused-vars
150150
callback(tabs[0]);
151151
}
152152
else {
153+
//TODO: Possibly fallback on globalCurrentTabId here?
154+
//see https://github.com/deanoemcke/thegreatsuspender/issues/574
153155
callback(null);
154156
}
155157
});
@@ -214,6 +216,18 @@ var tgs = (function () { // eslint-disable-line no-unused-vars
214216
});
215217
}
216218

219+
function toggleSuspendedStateOfHighlightedTab() {
220+
getCurrentlyActiveTab(function (activeTab) {
221+
if (activeTab) {
222+
if (gsUtils.isSuspendedTab(activeTab)) {
223+
unsuspendTab(activeTab);
224+
} else {
225+
requestTabSuspension(activeTab, 1);
226+
}
227+
}
228+
});
229+
}
230+
217231
function suspendHighlightedTab() {
218232
getCurrentlyActiveTab(function (activeTab) {
219233
if (activeTab) {
@@ -684,7 +698,7 @@ var tgs = (function () { // eslint-disable-line no-unused-vars
684698

685699
chrome.commands.onCommand.addListener(function (command) {
686700
if (command === '1-suspend-tab') {
687-
suspendHighlightedTab();
701+
toggleSuspendedStateOfHighlightedTab();
688702

689703
} else if (command === '2-unsuspend-tab') {
690704
unsuspendHighlightedTab();

src/js/shortcuts.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
chrome.commands.getAll(function (commands) {
1515

1616
commands.forEach(function (command) {
17-
if (command.name !== '_execute_browser_action') {
18-
var shortcut = command.shortcut !== '' ? command.shortcut : chrome.i18n.getMessage('js_shortcuts_not_set'),
19-
style = count % 2 === 0 ? '"margin: 0 0 2px;"' : '';
17+
if (command.name !== '_execute_browser_action' && command.name !== '2-unsuspend-tab') {
18+
var shortcut = command.shortcut !== '' ? command.shortcut : '(' + chrome.i18n.getMessage('js_shortcuts_not_set') + ')';
19+
var style = count % 2 === 1 ? '"margin: 0 0 2px;"' : '';
2020
shortcutsEl.innerHTML += '<p style=' + style + '>' + command.description + ': ' + shortcut + '</p>';
2121
count++;
2222
}

src/js/suspended.js

+20
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,26 @@
140140
document.getElementById('gsTopBarTitle').setAttribute('href', url);
141141
document.getElementById('gsTopBarImg').setAttribute('src', favicon);
142142

143+
//update hotkey
144+
chrome.commands.getAll(function (commands) {
145+
var hotkeyEl = document.getElementById('hotkeyCommand');
146+
if (!hotkeyEl) { return; }
147+
var toggleCommand = commands.find(function (command) {
148+
return (command.name === '1-suspend-tab');
149+
});
150+
if (hotkeyEl && toggleCommand && toggleCommand.shortcut !== '') {
151+
hotkeyEl.innerHTML = toggleCommand.shortcut;
152+
}
153+
else {
154+
var shortcutNotSetEl = document.createElement('a');
155+
shortcutNotSetEl.innerHTML = chrome.i18n.getMessage('js_shortcuts_not_set');
156+
hotkeyEl.appendChild(shortcutNotSetEl);
157+
hotkeyEl.onclick = function () {
158+
chrome.tabs.create({url: 'chrome://extensions/configureCommands'});
159+
};
160+
}
161+
});
162+
143163
//update whitelist text
144164
var isWhitelisted = gsUtils.checkWhiteList(url);
145165
if (isWhitelisted) {

src/suspended.html

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<div class="centerBox">
2222
<h1 data-i18n="__MSG_html_suspended_tab_suspended__"></h1>
2323
<h2 data-i18n="__MSG_html_suspended_click_to_reload__"></h2>
24+
<h3><span>(</span><span data-i18n="__MSG_html_suspended_hotkey_to_reload__"></span><span id="hotkeyCommand"></span><span>)</span></h3>
2425
</div>
2526
</div>
2627
<div id="refreshSpinner"></div>

0 commit comments

Comments
 (0)