From fb5ccdce5e67b27fd86bc4797cbaca64a65e4e2c Mon Sep 17 00:00:00 2001 From: alopexc0de Date: Fri, 29 Aug 2014 11:22:37 -0400 Subject: [PATCH] Change the IF statements to a switch This is to make it easier to add new responses in the future instead of having many different IF statements. --- lob.li crx/js/background.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lob.li crx/js/background.js b/lob.li crx/js/background.js index 0424c94..b6712ee 100644 --- a/lob.li crx/js/background.js +++ b/lob.li crx/js/background.js @@ -47,15 +47,20 @@ function shortenURL(url){ // Creates a short url and copies it to clipboard if(testURL(url)){ sendAPIRequest("shorten&url=" + url, function(req){ var res = req.responseText.trim(); - if(res == "dead"){ - showAlert("Apparently the link is dead..."); - }else if(res == "db"){ - showAlert("I got a database error!"); - }else if(res == "Error"){ - showAlert("General Error."); - }else{ - copyToClipboard("http://lob.li/" + res); - showAlert("Link shortened. Short link copied to clipboard!"); + switch(res){ + case "dead": + showAlert("Apparently the link is dead..."); + break; + case "db": + showAlert("I got a database error!"); + break; + case "Error": + showAlert("General Error."); + break; + default: + copyToClipboard("http://lob.li/" + res); + showAlert("Link shortened. Short link copied to clipboard!"); + break; } }); }