diff --git a/background.js b/background.js index d505194..d6b780f 100644 --- a/background.js +++ b/background.js @@ -1,4 +1,4 @@ -let redirect_link = {} +let redirect_link = {}; chrome.storage.sync.get(['redirect_link'], (result) => { if (result.redirect_link !== undefined) { redirect_link = result.redirect_link; @@ -6,10 +6,10 @@ chrome.storage.sync.get(['redirect_link'], (result) => { }); chrome.omnibox.onInputEntered.addListener((text) => { - if (redirect_link[text] !== undefined){ - chrome.tabs.update({url: redirect_link[text]}); + if (redirect_link[text] !== undefined) { + chrome.tabs.update({ url: redirect_link[text] }); } else { - chrome.tabs.update({url: "./error.html"}); + chrome.tabs.update({ url: "./error.html" }); } }); @@ -19,7 +19,22 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { const key = data[0]; const url = data[1]; redirect_link[key] = url; - chrome.storage.sync.set({redirect_link}); + chrome.storage.sync.set({ redirect_link }); sendResponse({ message: "Form submitted successfully!" }); + + } else if (message.type === 'edit_submission') { + const oldKey = message.oldKey; + const newKey = message.newKey; + const newUrl = message.newUrl; + delete redirect_link[oldKey]; + redirect_link[newKey] = newUrl; + chrome.storage.sync.set({ redirect_link }); + sendResponse({ message: "Edit submitted successfully!" }); + + } else if (message.type === 'delete_link') { + const key = message.key; + delete redirect_link[key]; + chrome.storage.sync.set({ redirect_link }); + sendResponse({ message: "Link deleted successfully!" }); } -}); \ No newline at end of file +}); diff --git a/error.html b/error.html index 8fc8d99..976a5c5 100644 --- a/error.html +++ b/error.html @@ -4,12 +4,11 @@ -
Sorry, no URL found for the entered keyword.
++ Sorry, no URL found for the entered keyword. +