From eb8df944db907650d5fdae77f76d84a5a1e145c1 Mon Sep 17 00:00:00 2001 From: Sherry Ma Date: Sat, 7 Mar 2020 21:30:44 -0500 Subject: [PATCH 1/5] added logic for attaching url to container --- src/js/popup.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/js/popup.js b/src/js/popup.js index e82820d..b386928 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -1087,6 +1087,21 @@ Logic.registerPanel(P_CONTAINER_EDIT, { const formValues = new FormData(this._editForm); console.log(formValues.get("container-id")); console.log(formValues.get("site-name")); + const url = formValues.get("site-name"); + const userContextId = formValues.get("container-id"); + const currentTab = await Logic.currentTab(); + const tabId = currentTab.id; + try { + await browser.runtime.sendMessage({ + method: "setOrRemoveAssignment", + tabId: tabId, + url: url, + userContextId: userContextId, + value: false + }); + } catch (e) { + console.log(e); + } }, showAssignedContainers(assignments) { From c0bb24d7dcbf04bbd8ca11d04b91b67a3b132181 Mon Sep 17 00:00:00 2001 From: Sherry Ma Date: Sat, 7 Mar 2020 23:04:37 -0500 Subject: [PATCH 2/5] added regex check on url input --- src/js/popup.js | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/js/popup.js b/src/js/popup.js index b386928..bc53f83 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -1085,23 +1085,36 @@ Logic.registerPanel(P_CONTAINER_EDIT, { async _addSite() { const formValues = new FormData(this._editForm); - console.log(formValues.get("container-id")); - console.log(formValues.get("site-name")); const url = formValues.get("site-name"); const userContextId = formValues.get("container-id"); const currentTab = await Logic.currentTab(); const tabId = currentTab.id; - try { - await browser.runtime.sendMessage({ - method: "setOrRemoveAssignment", - tabId: tabId, - url: url, - userContextId: userContextId, - value: false - }); - } catch (e) { - console.log(e); + const fullURL = this.checkurl(url); + Logic.setOrRemoveAssignment(tabId, fullURL, userContextId, false); + }, + + checkurl(url){ + // append "https://" if protocol not found + const regexWww = /.*www\..*/g; + const foundWww = url.match(regexWww); + const regexhttp = /^http:\/\/.*/g; + const regexhttps = /^https:\/\/.*/g; + const foundhttp = url.match(regexhttp); + const foundhttps = url.match(regexhttps); + let newURL = url; + + if (!foundhttp && !foundhttps) { + newURL = "https://" + url; } + + if (!foundWww) { + if (newURL.match(regexhttp)) { + newURL = "http://www." + newURL.substring(7); + } else if (newURL.match(regexhttps)) { + newURL = "https://www." + newURL.substring(8); + } + } + return newURL; }, showAssignedContainers(assignments) { From 08ffba41d7507f4bb87a8293a4518abe4d0c8cc3 Mon Sep 17 00:00:00 2001 From: Sherry Ma Date: Sat, 7 Mar 2020 23:07:02 -0500 Subject: [PATCH 3/5] change method name --- src/js/popup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/popup.js b/src/js/popup.js index bc53f83..9c7e3b0 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -1093,7 +1093,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, { Logic.setOrRemoveAssignment(tabId, fullURL, userContextId, false); }, - checkurl(url){ + checkUrl(url){ // append "https://" if protocol not found const regexWww = /.*www\..*/g; const foundWww = url.match(regexWww); From 50f7e17e57aede350ce653bce202c11f98b8e353 Mon Sep 17 00:00:00 2001 From: Sherry Ma Date: Sat, 7 Mar 2020 23:08:03 -0500 Subject: [PATCH 4/5] fixed calling wrong method name --- src/js/popup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/popup.js b/src/js/popup.js index 9c7e3b0..df3f36b 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -1089,7 +1089,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, { const userContextId = formValues.get("container-id"); const currentTab = await Logic.currentTab(); const tabId = currentTab.id; - const fullURL = this.checkurl(url); + const fullURL = this.checkUrl(url); Logic.setOrRemoveAssignment(tabId, fullURL, userContextId, false); }, From 701918a05940da03d0e47d9a9ab975d599d6730f Mon Sep 17 00:00:00 2001 From: Khansa Kiasatina Date: Sun, 8 Mar 2020 10:39:45 -0400 Subject: [PATCH 5/5] show assigned url after adding --- src/js/popup.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/js/popup.js b/src/js/popup.js index df3f36b..beb541a 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -1084,13 +1084,23 @@ Logic.registerPanel(P_CONTAINER_EDIT, { }, async _addSite() { + // Get URL and container ID from form const formValues = new FormData(this._editForm); const url = formValues.get("site-name"); const userContextId = formValues.get("container-id"); const currentTab = await Logic.currentTab(); const tabId = currentTab.id; const fullURL = this.checkUrl(url); - Logic.setOrRemoveAssignment(tabId, fullURL, userContextId, false); + + // Assign URL to container + await Logic.setOrRemoveAssignment(tabId, fullURL, userContextId, false); + + // Clear form + document.querySelector("#edit-container-panel-site-input").value = ""; + + // Show new assignments + const assignments = await Logic.getAssignmentObjectByContainer(userContextId); + this.showAssignedContainers(assignments); }, checkUrl(url){ @@ -1202,7 +1212,8 @@ Logic.registerPanel(P_CONTAINER_EDIT, { document.querySelector("#edit-container-panel .panel-footer").hidden = !!userContextId; // Only show ability to add site if it's an existing container document.querySelector("#edit-container-panel-add-site").hidden = !userContextId; - + // Make site input empty + document.querySelector("#edit-container-panel-site-input").value = ""; document.querySelector("#edit-container-panel-name-input").value = identity.name || ""; document.querySelector("#edit-container-panel-usercontext-input").value = userContextId || NEW_CONTAINER_ID; const containerName = document.querySelector("#edit-container-panel-name-input");