mirror of
https://github.com/wassname/Mostly-Harmless.git
synced 2026-08-11 11:13:06 +08:00
Added ability to only throw an error when the API is down.
This commit is contained in:
@@ -32,14 +32,16 @@ this.manifest = {
|
||||
"name": "timeoutLength",
|
||||
"type": "slider",
|
||||
"label": "",
|
||||
"max": 15,
|
||||
"max": 16,
|
||||
"min": 1,
|
||||
"step": 1,
|
||||
"display": true,
|
||||
"displayModifier": function(value) {
|
||||
if(value === 1)
|
||||
return value.toString() + " second";
|
||||
return value.toString() + " seconds";
|
||||
if(value <= 15)
|
||||
return value.toString() + " seconds";
|
||||
return "Do not timeout; Only error when the API is down."
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
+6
-4
@@ -183,7 +183,7 @@ BrowserAction.prototype.setBadgeLoading = function (tabId) {
|
||||
BrowserAction.prototype.setBadgeError = function (tabId, text) {
|
||||
chrome.browserAction.setBadgeText({'text': '×', 'tabId': tabId});
|
||||
chrome.browserAction.setTitle({'title': text, 'tabId': tabId});
|
||||
chrome.browserAction.setBadgeBackgroundColor({'color': [255, 0, 255, 255], 'tabId': tabId});
|
||||
chrome.browserAction.setBadgeBackgroundColor({'color': [200, 0, 0, 255], 'tabId': tabId});
|
||||
chrome.browserAction.setPopup({popup: '', tabId: tabId});
|
||||
chrome.browserAction.onClicked.addListener(function(tab) {
|
||||
reddit.getInfo(tab.url, tab.id);
|
||||
@@ -316,14 +316,14 @@ RedditAPI.prototype.getInfo = function (url, tabId) {
|
||||
button.setBadgeFor(url, tabId);
|
||||
return true;
|
||||
} else {
|
||||
throw 'Error loading info from the API. HTTP Status: ' + req.status;
|
||||
button.setBadgeError(tabId, 'API Error. HTTP Status: ' + req.status + '. Click to try again.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleTimeout () {
|
||||
req.abort();
|
||||
button.setBadgeError(tabId, 'The Reddit API Timed Out. Click to try loading again.');
|
||||
button.setBadgeError(tabId, 'API Timeout after ' + settings.get('timeoutLength') + '. Click to try again.');
|
||||
}
|
||||
|
||||
button.setBadgeLoading(tabId);
|
||||
@@ -342,7 +342,9 @@ RedditAPI.prototype.getInfo = function (url, tabId) {
|
||||
req.open('GET', reqUrl, true);
|
||||
req.onreadystatechange = processInfo;
|
||||
req.send(null);
|
||||
apiTimeout = setTimeout(handleTimeout, settings.get('timeoutLength') * 1000);
|
||||
if (settings.get('timeoutLength') !== 16) {
|
||||
apiTimeout = setTimeout(handleTimeout, settings.get('timeoutLength') * 1000);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user