diff --git a/app.js b/app.js index dbad6d9..3ecbf36 100644 --- a/app.js +++ b/app.js @@ -10,6 +10,18 @@ browser.runtime.onStartup.addListener((browser) => { browser.runtime.sendMessage({"env": env}); }); +if (!localStorage.getItem('urls')) { + urls = [ + "*://*.develop/*", + "*://*.local/*", + "*://localhost/*" + ]; + localStorage.setItem('urls', JSON.stringify(urls)) +} else { + urls = JSON.parse(localStorage.getItem('urls')); +} + + browser.webRequest.onBeforeSendHeaders.addListener( details => { let requestHeaders = details.requestHeaders || []; @@ -23,15 +35,10 @@ browser.webRequest.onBeforeSendHeaders.addListener( }; }, { - urls: [ - "*://*.develop/*", - "*://*.local/*", - "*://localhost/*" - ] + urls: urls }, [ 'requestHeaders', 'blocking' ] -); - +); \ No newline at end of file diff --git a/manifest.json b/manifest.json index ca66bf8..c7e5f30 100644 --- a/manifest.json +++ b/manifest.json @@ -7,12 +7,11 @@ "32": "icons/symfony.svg" }, "permissions": [ + "", + "storage", "activeTab", "webRequestBlocking", - "webRequest", - "*://*.develop/*", - "*://*.local/*", - "*://localhost/*" + "webRequest" ], "background": { "scripts": [ @@ -28,5 +27,9 @@ "icons/symfony.png", "icons/symfony-dev.png", "icons/symfony-xdebug.png" - ] + ], + "options_ui": { + "page": "settings/settings.html", + "open_in_tab": false + } } \ No newline at end of file diff --git a/settings/options.js b/settings/options.js new file mode 100644 index 0000000..eff39fd --- /dev/null +++ b/settings/options.js @@ -0,0 +1,69 @@ +const body = document.getElementById('urls'); + +var browser = browser || chrome; + +if(!localStorage.getItem('urls')){ + const urls = [ + "*://*.develop/*", + "*://*.local/*", + "*://localhost/*" + ]; + localStorage.setItem('urls', JSON.stringify(urls)) +} + +const urls = JSON.parse(localStorage.getItem('urls')); +localStorage.setItem('urls', JSON.stringify(urls)); + +function fetchAll() { + let data = ''; + if (urls.length > 0) { + for (let i = 0; i < urls.length; i++) { + data += ''; + data += '' + urls[i] + ''; + data += '' + '' + ''; + data += ''; + } + } + return body.innerHTML = data; +} + +fetchAll(); + +document.getElementById("form-save").addEventListener("click", function () { + add(); +}); + +function add() { + var url = document.getElementById('title').value; + + if (url) { + urls.push(url.trim()); + localStorage.setItem('urls', JSON.stringify(urls)); + + url.value = ''; + + fetchAll(); + } else { + alert("The url that you wrote isn't valid.") + } +} + +document.querySelectorAll("button.edit").forEach(b => { + b.addEventListener("click", function () { + deleteURL(this.value); + }); +}); + +function deleteURL(url) { + urls.splice(url, 1); + + localStorage.setItem('urls', JSON.stringify(urls)); + + fetchAll(); + document.location.reload(); +} + +document.getElementById("reload").addEventListener("click", function () { + browser.runtime.reload(); + window.close(); +}); \ No newline at end of file diff --git a/settings/settings.html b/settings/settings.html new file mode 100644 index 0000000..e91f3da --- /dev/null +++ b/settings/settings.html @@ -0,0 +1,56 @@ + + + + + + + + + Symfony Environment Switcher | Settings + + + +
+

Settings

+
+
+
+ +
+
+ +
+
+
+ + + + + + + + + +
UrlsOptions
+ +
+ + + + \ No newline at end of file