From d36021654edf9f87f0de3206ed00632ec2f971eb Mon Sep 17 00:00:00 2001 From: pilar6195 Date: Fri, 17 May 2019 11:25:15 -0500 Subject: [PATCH] Displaying notification on success. --- src/background.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/background.js b/src/background.js index 61e1739..6f481f1 100644 --- a/src/background.js +++ b/src/background.js @@ -1,9 +1,9 @@ -function createNotification(type, title, message, sticky) { +function createNotification(type, title, message, sticky, timeout) { const notificationContent = { type, iconUrl: 'logo.png', title, - message + message: message || '' }; if (typeof InstallTrigger === 'undefined') // Does not work with firefox. @@ -11,6 +11,10 @@ function createNotification(type, title, message, sticky) { const id = `notification_${Date.now()}`; chrome.notifications.create(id, notificationContent); + + if (typeof timeout === 'number') + setTimeout(() => chrome.notifications.clear(id), timeout); + return id; } @@ -39,6 +43,7 @@ chrome.browserAction.onClicked.addListener(async tab => { }); const json = await response.json(); copyText(json.url); + createNotification('basic', 'URL shortened and copied to clipboard!', json.url, false, 5000); } catch (err) { console.log(err.toString()); createNotification('basic', 'An error has occured!', err.toString(), true);