mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-24 18:22:54 +02:00
Add proxy example (#225)
* Add proxy example * Updated after review comments
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
body {
|
||||
width: 25em;
|
||||
font-family: "Open Sans Light", sans-serif;
|
||||
font-size: 0.9em;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.title, #blocked-hosts {
|
||||
margin: 1em;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 1.2em;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="options.css"/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<section>
|
||||
<span class="title">Hosts to block:</span>
|
||||
<textarea id="blocked-hosts" rows="10" cols="50"></textarea>
|
||||
</section>
|
||||
|
||||
<script src="options.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,25 @@
|
||||
const blockedHostsTextArea = document.querySelector("#blocked-hosts");
|
||||
|
||||
// Store the currently selected settings using browser.storage.local.
|
||||
function storeSettings() {
|
||||
let blockedHosts = blockedHostsTextArea.value.split("\n");
|
||||
browser.storage.local.set({
|
||||
blockedHosts
|
||||
});
|
||||
}
|
||||
|
||||
// Update the options UI with the settings values retrieved from storage,
|
||||
// or the default settings if the stored settings are empty.
|
||||
function updateUI(restoredSettings) {
|
||||
blockedHostsTextArea.value = restoredSettings.blockedHosts.join("\n");
|
||||
}
|
||||
|
||||
function onError(e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
// On opening the options page, fetch stored settings and update the UI with them.
|
||||
browser.storage.local.get().then(updateUI, onError);
|
||||
|
||||
// Whenever the contents of the textarea changes, save the new values
|
||||
blockedHostsTextArea.addEventListener("change", storeSettings);
|
||||
Reference in New Issue
Block a user