-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add options page - allow changing the period to ignore HTTP-only sites
- Loading branch information
1 parent
806b75e
commit d7d8856
Showing
8 changed files
with
235 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
class Settings { | ||
constructor() { | ||
this.defaults = { | ||
'ignored': {}, // hostname:unixTimeStamp pairs | ||
'ignorePeriod': 7 //-1 = permanent, 0 = session-only, 1+ = X days | ||
}; | ||
this.loading = (async () => { | ||
let saved = await browser.storage.local.get(this.defaults); | ||
this.all = saved; | ||
await browser.storage.local.set(saved); | ||
browser.storage.onChanged.addListener((changes, area) => { | ||
console.debug(`HTTPZ: ${area} storage changed`); | ||
for (const i in changes) { | ||
if (changes[i].hasOwnProperty('newValue')) this[i] = changes[i].newValue; | ||
else if (changes[i].hasOwnProperty('oldValue')) delete this[i]; | ||
} | ||
}); | ||
console.log('HTTPZ: settings loaded'); | ||
delete this.loading; | ||
})(); | ||
} | ||
get all() { | ||
return (async () => { | ||
if (this.loading) await this.loading; | ||
const val = {}; | ||
for (const i in this.defaults) val[i] = this[i]; | ||
return val; | ||
})(); | ||
} | ||
set all(obj) { | ||
for (const i in obj) this[i] = obj[i]; | ||
} | ||
save() { | ||
this.all.then(r => { | ||
browser.storage.local.set(r); | ||
}); | ||
} | ||
} | ||
|
||
class DelayableAction { | ||
constructor(step, timeout, callback) { | ||
this.callback = callback; | ||
this.step = step; | ||
this.timeout = timeout; | ||
} | ||
run() { | ||
this.count = 0; | ||
if (!this.timerID) { | ||
this.countdown = this.timeout; | ||
this.timerID = setInterval(t => { | ||
if (++t.count >= t.step || !--t.countdown) t.stop(); | ||
}, 1000, this); | ||
} | ||
} | ||
stop() { | ||
if (this.timerID) { | ||
clearInterval(this.timerID); | ||
this.timerID = null; | ||
this.callback(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const settings = new Settings(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
browser.runtime.onMessage.addListener((msg, sender, sendResponse) => { | ||
// triggered by options page script | ||
return settings.all; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
* { box-sizing: border-box; } | ||
body { display: table; } | ||
button { margin-left: 0.25em; } | ||
#days { | ||
background-color: #FFF; | ||
color: #000; | ||
text-align: center; | ||
width: 4em; | ||
} | ||
.fb { | ||
align-items: center; | ||
display: flex; | ||
flex-flow: row wrap; | ||
} | ||
.fb * { margin: auto inherit; } | ||
.hidden { | ||
opacity: 0; | ||
transition: opacity 500ms; | ||
} | ||
.shown { opacity: 1; } | ||
.status { | ||
font-weight: 300; | ||
margin-left: 1em; | ||
} | ||
.saved { | ||
color: #021; | ||
text-shadow: 0 0 0.2em #0F8; | ||
} | ||
.error { | ||
color: #300; | ||
text-shadow: 0 0 0.2em #F00; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<link href="options.css" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<p>Check again if a site supports HTTPS...</p> | ||
<div class="browser-style fb"> | ||
<input id="session" name="period" type="radio"><label for="session">after Firefox is restarted</label> | ||
</div> | ||
<div class="browser-style fb"> | ||
<input id="xdays" name="period" type="radio"><label for="xdays">after | ||
<input id="days" name="days" type="number" min=1 required> days</label> | ||
</div> | ||
<div class="browser-style fb"> | ||
<input id="permanent" name="period" type="radio"><label for="permanent">never</label> | ||
</div><br> | ||
<button class="browser-style" id="clear">Forget sites</button> | ||
<button class="browser-style" id="save">Save</button><span class="hidden" id="status"></span> | ||
<script src="options.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
|
||
var settings; | ||
|
||
const ui = (() => { | ||
const dom = document.getElementsByTagName('*'); | ||
return new Proxy(dom, { | ||
get: function(obj, prop) { | ||
return obj[prop]; | ||
}, | ||
set: function(obj, prop, val) { | ||
obj[prop].value = val; | ||
return true; | ||
} | ||
}); | ||
})(); | ||
|
||
function setStatus(msg, type) { | ||
ui.status.textContent = msg; | ||
ui.status.className = `status shown ${type}`; | ||
setTimeout(() => { | ||
ui.status.className = 'status hidden'; | ||
}, 2500); | ||
} | ||
|
||
browser.runtime.sendMessage(true).then(msg => { | ||
settings = msg; | ||
ui.session.checked = !msg.ignorePeriod; | ||
ui.xdays.checked = msg.ignorePeriod > 0; | ||
ui.days.disabled = !ui.xdays.checked; | ||
ui.permanent.checked = msg.ignorePeriod === -1; | ||
if (ui.xdays.checked) ui.days.value = msg.ignorePeriod; | ||
const changePeriod = e => { | ||
ui.days.disabled = !ui.xdays.checked; | ||
if (ui.xdays.checked) { | ||
ui.days.value = settings.ignorePeriod > 0 ? settings.ignorePeriod : 1; | ||
} | ||
}; | ||
ui.session.onchange = changePeriod; | ||
ui.xdays.onchange = changePeriod; | ||
ui.permanent.onchange = changePeriod; | ||
ui.clear.onclick = e => { | ||
browser.storage.local.set({ignored: {}}).then(() => {; | ||
setStatus('List of sites cleared', ''); | ||
}); | ||
}; | ||
ui.save.onclick = e => { | ||
if (ui.session.checked) { | ||
settings.ignorePeriod = 0; | ||
settings.ignored = {}; | ||
} else if (ui.xdays.checked) { | ||
if (!/^\d+$/.test(ui.days.value.toString())) { | ||
setStatus('Invalid input', 'error'); | ||
return; | ||
} | ||
settings.ignorePeriod = +ui.days.value; | ||
} else settings.ignorePeriod = -1; | ||
setStatus('. . .', ''); | ||
browser.storage.local.set(settings) | ||
.then(() => { | ||
setStatus('Saved!', 'saved'); | ||
}); | ||
}; | ||
}); |