Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/select url #4

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [];
Expand All @@ -23,15 +35,10 @@ browser.webRequest.onBeforeSendHeaders.addListener(
};
},
{
urls: [
"*://*.develop/*",
"*://*.local/*",
"*://localhost/*"
]
urls: urls
},
[
'requestHeaders',
'blocking'
]
);

);
13 changes: 8 additions & 5 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
"32": "icons/symfony.svg"
},
"permissions": [
"<all_urls>",
"storage",
"activeTab",
"webRequestBlocking",
"webRequest",
"*://*.develop/*",
"*://*.local/*",
"*://localhost/*"
"webRequest"
],
"background": {
"scripts": [
Expand All @@ -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
}
}
69 changes: 69 additions & 0 deletions settings/options.js
Original file line number Diff line number Diff line change
@@ -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 += '<tr>';
data += '<td>' + urls[i] + '</td>';
data += '<td>' + '<button type="button" class="edit" value="' + i + '">Delete</button>' + '</td>';
data += '</tr>';
}
}
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();
});
56 changes: 56 additions & 0 deletions settings/settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" type="image/png" href="../icons/symfony.png" />

<title>Symfony Environment Switcher | Settings</title>
<style>
form {
width: 100%;
}
.form-row {
display: flex;
flex-direction: row;
margin-top: 20px;
margin-bottom: 20px;
}
table {
width: 100%;
}
#reload {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Settings</h1>
<form id="form" method="post">
<div class="form-row">
<div class="col">
<input type="text" name="title" id="title" class="form-control" placeholder="Your url" required/>
</div>
<div class="col">
<button type="submit" id="form-save">Add url</button>
</div>
</div>
</form>
<table>
<thead>
<tr>
<th scope="col">Urls</th>
<th scope="col">Options</th>
</tr>
</thead>
<tbody id="urls">
</tbody>
</table>
<button id="reload">Reload extension</button>
</div>
<!-- Optional JavaScript; choose one of the two! -->
<script src="options.js"></script>
</body>
</html>