diff --git a/main.js b/main.js index 11a4f7c..549dae4 100644 --- a/main.js +++ b/main.js @@ -11,14 +11,17 @@ clipboard.on('success', function (e) { }); }); -//Set default url -// chrome.tabs.query({ active: true, lastFocusedWindow: true }, tabs => { -// document.getElementById("target").value = tabs[0].url; -// }); -document.getElementById("target").value = "google.com"; +//Set default url as current tab +chrome.tabs.query({ active: true, lastFocusedWindow: true }, tabs => { + document.getElementById("target").value = tabs[0].url; +}); -// Calls the api to create a new short url +// Create button click handler calls the api to create a new short url document.getElementById("create").onclick = createUrl; + +/** + * Calls the api to create a new short url and handels displaying the ui for "created" urls + */ function createUrl() { let shorturl = { target: document.getElementById("target").value, @@ -55,9 +58,11 @@ function createUrl() { } +//Add error dismiss event handler document.getElementById("error_dismiss").onclick = () => { document.getElementById("error_container").classList.add("hidden"); }; + /** * Display alerts for errors (only handling 400 correctly r/n) * @param {response} res The fetch response object @@ -76,8 +81,12 @@ function handleError(res) { } } -//Resets the UI +//Add ui reset error handler document.getElementById("reset").onclick = reset; + +/** + * Resets the ui by emtying/resetting all inputs and showing the "default" home ui containers again. + */ function reset() { document.getElementById("shorturl").innerText = ""; document.getElementById("target_container").className = "";