Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Automatic preference reload; button toggles site.
Browse files Browse the repository at this point in the history
How convenient!
  • Loading branch information
charmander committed Feb 6, 2015
1 parent 0c86d64 commit c5ce789
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
31 changes: 27 additions & 4 deletions bootstrap.js
Expand Up @@ -12,6 +12,17 @@ function reloadWhitelist() {
whitelist = preferences.getCharPref('whitelist').split(/\s+/);
}

function toggleDomain(domain) {
if (whitelist.indexOf(domain) === -1) {
whitelist.push(domain);
preferences.setCharPref('whitelist', whitelist.join(' '));
} else {
preferences.setCharPref('whitelist', whitelist.filter(function (existingDomain) {
return existingDomain !== domain;
}).join(' '));
}
}

function addButton(window) {
const toolbox = window.document.getElementById('navigator-toolbox');

Expand All @@ -26,13 +37,23 @@ function addButton(window) {
button.setAttribute('class', 'toolbarbutton-1 chromeclass-toolbar-additional');
button.setAttribute('label', 'Safeguard');

button.addEventListener('command', reloadWhitelist, false);
button.addEventListener('command', function toggleCurrentDomain() {
const uri = window.getBrowser().selectedBrowser.registeredOpenURI;

if (!uri) {
return;
}

if (uri.schemeIs('http') || uri.schemeIs('https')) {
toggleDomain(uri.host);
}
}, false);

toolbox.palette.appendChild(button);

var currentSet = navigationBar.getAttribute('currentset').split(',');
var i = currentSet.indexOf('safeguard-button');
var next = null;
const currentSet = navigationBar.getAttribute('currentset').split(',');
const i = currentSet.indexOf('safeguard-button');
let next = null;

if (i !== -1 && i !== currentSet.length - 1) {
next = window.document.getElementById(currentSet[i + 1]);
Expand Down Expand Up @@ -99,6 +120,7 @@ function startup() {

reloadWhitelist();

preferences.addObserver('whitelist', reloadWhitelist, false);
Services.obs.addObserver(requestObserver, 'http-on-modify-request', false);

Services.ww.registerNotification(windowObserver);
Expand All @@ -107,6 +129,7 @@ function startup() {

function shutdown() {
Services.obs.removeObserver(requestObserver, 'http-on-modify-request');
preferences.removeObserver('whitelist', reloadWhitelist);

Services.ww.unregisterNotification(windowObserver);
eachWindow(removeButton);
Expand Down
4 changes: 2 additions & 2 deletions install.rdf
Expand Up @@ -3,13 +3,13 @@
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<RDF:Description RDF:about="urn:mozilla:install-manifest">
<em:id>safeguard@charmander.me</em:id>
<em:version>0.1.3</em:version>
<em:version>0.2.0</em:version>
<em:type>2</em:type>
<em:targetApplication>
<RDF:Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>30.0</em:minVersion>
<em:maxVersion>35.0</em:maxVersion>
<em:maxVersion>38.0</em:maxVersion>
</RDF:Description>
</em:targetApplication>
<em:name>Safeguard</em:name>
Expand Down

0 comments on commit c5ce789

Please sign in to comment.