Added the ability to deactivate Mostly Harmless except when the icon is clicked.

This commit is contained in:
Kerrick Long
2011-07-18 15:51:04 -05:00
parent f897107105
commit 63822e1ee5
2 changed files with 27 additions and 7 deletions
+15
View File
@@ -115,6 +115,21 @@ this.manifest = {
"type": "description",
"text": "<p>Mostly Harmless uses the reddit API, but sometimes the API will be slow or down. If that happens, Mostly Harmless can display an error after trying to reach the API for a certain amount of time.</p><p>This option allows you to change how long Mostly Harmless should try to reach the Reddit API. Longer timeout lengths mean more time waiting for a result from the reddit API. Shorter timeout lengths mean a higher possibility of timing out when reddit may only be slow instead of down."
},
{
"tab": "Privacy",
"group": "Wait for Click",
"name": "waitForClick",
"type": "checkbox",
"label": "Wait for click"
},
{
"tab": "Privacy",
"group": "Wait for Click",
"name": "waitForClickDescription",
"type": "description",
"text": "<p>If this checkbox is selected, Mostly Harmless will not activate unless you click its icon.</p>"
},
{
"tab": "Privacy",
"group": "Warning!",
+12 -7
View File
@@ -5,7 +5,8 @@ settings = new Store('settings', {
'timeoutLength': 5,
'freshCutoff': 7,
'popupWidth': 640,
'shamelessPlug': false
'shamelessPlug': false,
'waitForClick': false
});
cache = new Store('cache');
@@ -752,13 +753,17 @@ function Background() {
*/
Background.prototype.prepareBrowserAction = function (tabId, info, tab) {
if (info.status === 'loading') {
if (cache.get(tab.url) === undefined || cache.get(tab.url).cacheDate - utils.epoch() < -60 * settings.get('cacheTime')) {
console.log(chrome.i18n.getMessage('loading_api'));
console.log(utils.parseURL(tab.url));
reddit.getInfo(tab.url, tabId);
if (settings.get('waitForClick') === 'true') {
if (cache.get(tab.url) === undefined || cache.get(tab.url).cacheDate - utils.epoch() < -60 * settings.get('cacheTime')) {
console.log(chrome.i18n.getMessage('loading_api'));
console.log(utils.parseURL(tab.url));
reddit.getInfo(tab.url, tabId);
} else {
console.log(chrome.i18n.getMessage('loading_cache'));
button.setBadgeFor(tab.url, tabId);
}
} else {
console.log(chrome.i18n.getMessage('loading_cache'));
button.setBadgeFor(tab.url, tabId);
button.setBadgeIgnore(tabId);
}
}