mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Count the number of clients the webext has served
This commit is contained in:
parent
91255463c6
commit
85625e19f9
4 changed files with 21 additions and 3 deletions
|
@ -51,13 +51,26 @@ class DebugUI extends UI
|
||||||
|
|
||||||
class WebExtUI extends UI
|
class WebExtUI extends UI
|
||||||
port: null
|
port: null
|
||||||
|
stats: null
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
|
@initStats()
|
||||||
chrome.runtime.onConnect.addListener @onConnect
|
chrome.runtime.onConnect.addListener @onConnect
|
||||||
|
|
||||||
|
initStats: ->
|
||||||
|
@stats = [0]
|
||||||
|
setInterval (() =>
|
||||||
|
@stats.unshift 0
|
||||||
|
@stats.splice 24
|
||||||
|
@postActive()
|
||||||
|
), 60 * 60 * 1000
|
||||||
|
|
||||||
postActive: ->
|
postActive: ->
|
||||||
@port?.postMessage
|
@port?.postMessage
|
||||||
active: @active
|
active: @active
|
||||||
|
total: @stats.reduce ((t, c) ->
|
||||||
|
t + c
|
||||||
|
), 0
|
||||||
|
|
||||||
onConnect: (port) =>
|
onConnect: (port) =>
|
||||||
@port = port
|
@port = port
|
||||||
|
@ -69,6 +82,7 @@ class WebExtUI extends UI
|
||||||
|
|
||||||
setActive: (connected) ->
|
setActive: (connected) ->
|
||||||
super connected
|
super connected
|
||||||
|
if connected then @stats[0] += 1
|
||||||
@postActive()
|
@postActive()
|
||||||
chrome.browserAction.setIcon
|
chrome.browserAction.setIcon
|
||||||
path:
|
path:
|
||||||
|
|
|
@ -5,6 +5,7 @@ body {
|
||||||
#active {
|
#active {
|
||||||
padding: 2em;
|
padding: 2em;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
min-width: 128px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.learn {
|
.learn {
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="active">
|
<div id="active">
|
||||||
<img src="icons/status-off.png" />
|
<img src="icons/status-off.png" />
|
||||||
<p>Offline</p>
|
<p></p>
|
||||||
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="learn">
|
<div class="learn">
|
||||||
<a target="_blank" href="https://snowflake.torproject.org/">Learn more</a>
|
<a target="_blank" href="https://snowflake.torproject.org/">Learn more</a>
|
||||||
|
|
|
@ -7,6 +7,8 @@ port.onMessage.addListener((m) => {
|
||||||
const div = document.getElementById('active');
|
const div = document.getElementById('active');
|
||||||
const img = div.querySelector('img');
|
const img = div.querySelector('img');
|
||||||
img.src = `icons/status-${active ? "on" : "off"}.png`;
|
img.src = `icons/status-${active ? "on" : "off"}.png`;
|
||||||
const p = div.querySelector('p');
|
const ps = div.querySelectorAll('p');
|
||||||
p.innerText = active ? "Connected" : "Offline";
|
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.`;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue