mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Add toggle functionality to web extension
This commit is contained in:
parent
ead579a6e9
commit
799a13d385
5 changed files with 37 additions and 3 deletions
|
@ -4,6 +4,9 @@ Entry point.
|
|||
|
||||
debug = false
|
||||
snowflake = null
|
||||
config = null
|
||||
broker = null
|
||||
ui = null
|
||||
|
||||
# Log to both console and UI if applicable.
|
||||
# Requires that the snowflake and UI objects are hooked up in order to
|
||||
|
@ -21,8 +24,17 @@ init = () ->
|
|||
snowflake = new Snowflake config, ui, broker
|
||||
|
||||
log '== snowflake proxy =='
|
||||
|
||||
update = () ->
|
||||
if !ui.enabled
|
||||
# Do not activate the proxy if any number of conditions are true.
|
||||
snowflake.disable()
|
||||
log 'Currently not active.'
|
||||
return
|
||||
|
||||
# Otherwise, begin setting up WebRTC and acting as a proxy.
|
||||
dbg 'Contacting Broker at ' + broker.url
|
||||
log 'Starting snowflake'
|
||||
snowflake.setRelayAddr config.relayAddr
|
||||
snowflake.beginWebRTC()
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ All of Snowflake's DOM manipulation and inputs.
|
|||
|
||||
class UI
|
||||
active: false
|
||||
enabled: false
|
||||
|
||||
setStatus: (msg) ->
|
||||
|
||||
|
@ -74,10 +75,17 @@ class WebExtUI extends UI
|
|||
total: @stats.reduce ((t, c) ->
|
||||
t + c
|
||||
), 0
|
||||
enabled: @enabled
|
||||
|
||||
onConnect: (port) =>
|
||||
@port = port
|
||||
port.onDisconnect.addListener @onDisconnect
|
||||
port.onMessage.addListener @onMessage
|
||||
@postActive()
|
||||
|
||||
onMessage: (m) =>
|
||||
@enabled = m.enabled
|
||||
update()
|
||||
@postActive()
|
||||
|
||||
onDisconnect: (port) =>
|
||||
|
|
|
@ -13,5 +13,6 @@
|
|||
},
|
||||
"default_title": "Snowflake",
|
||||
"default_popup": "popup.html"
|
||||
}
|
||||
},
|
||||
"permissions": ["cookies", "https://snowflake.torproject.org/"]
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
<p></p>
|
||||
</div>
|
||||
<div class="b toggle">
|
||||
<label>Turn Off</label>
|
||||
<label id=toggle>Turn On</label>
|
||||
<label class="switch">
|
||||
<input type="checkbox" checked>
|
||||
<input id="enabled" type="checkbox"/>
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
</div>
|
||||
|
|
|
@ -11,4 +11,17 @@ port.onMessage.addListener((m) => {
|
|||
const clients = active ? 1 : 0;
|
||||
ps[0].innerText = `${clients} client${(clients !== 1) ? 's' : ''} connected.`;
|
||||
ps[1].innerText = `Your snowflake has helped ${m.total} user${(m.total !== 1) ? 's' : ''} circumvent censorship in the last 24 hours.`;
|
||||
const enabled = m.enabled
|
||||
const enabledText = document.getElementById('toggle');
|
||||
if (enabled) {
|
||||
document.getElementById('enabled').checked = true;
|
||||
enabledText.innerText = 'Turn Off';
|
||||
} else {
|
||||
document.getElementById('enabled').checked = false;
|
||||
enabledText.innerText = 'Turn On';
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('change', (event) => {
|
||||
port.postMessage({enabled: event.target.checked});
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue