mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Compile coffee files and remove them
With, ./node_modules/.bin/coffee -b -c Cakefile `find . -path ./node_modules -prune -o -name '*.coffee'`
This commit is contained in:
parent
82562fb21d
commit
31ad9566e6
38 changed files with 2277 additions and 1725 deletions
197
proxy/ui.js
Normal file
197
proxy/ui.js
Normal file
|
@ -0,0 +1,197 @@
|
|||
// Generated by CoffeeScript 2.4.1
|
||||
/*
|
||||
All of Snowflake's DOM manipulation and inputs.
|
||||
*/
|
||||
var BadgeUI, DebugUI, UI, WebExtUI,
|
||||
boundMethodCheck = function(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new Error('Bound instance method accessed before binding'); } };
|
||||
|
||||
UI = (function() {
|
||||
class UI {
|
||||
setStatus(msg) {}
|
||||
|
||||
setActive(connected) {
|
||||
return this.active = connected;
|
||||
}
|
||||
|
||||
log(msg) {}
|
||||
|
||||
};
|
||||
|
||||
UI.prototype.active = false;
|
||||
|
||||
UI.prototype.enabled = true;
|
||||
|
||||
return UI;
|
||||
|
||||
}).call(this);
|
||||
|
||||
BadgeUI = (function() {
|
||||
class BadgeUI extends UI {
|
||||
constructor() {
|
||||
super();
|
||||
this.$badge = document.getElementById('badge');
|
||||
}
|
||||
|
||||
setActive(connected) {
|
||||
super.setActive(connected);
|
||||
return this.$badge.className = connected ? 'active' : '';
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
BadgeUI.prototype.$badge = null;
|
||||
|
||||
return BadgeUI;
|
||||
|
||||
}).call(this);
|
||||
|
||||
DebugUI = (function() {
|
||||
class DebugUI extends UI {
|
||||
constructor() {
|
||||
super();
|
||||
// Setup other DOM handlers if it's debug mode.
|
||||
this.$status = document.getElementById('status');
|
||||
this.$msglog = document.getElementById('msglog');
|
||||
this.$msglog.value = '';
|
||||
}
|
||||
|
||||
// Status bar
|
||||
setStatus(msg) {
|
||||
var txt;
|
||||
txt = document.createTextNode('Status: ' + msg);
|
||||
while (this.$status.firstChild) {
|
||||
this.$status.removeChild(this.$status.firstChild);
|
||||
}
|
||||
return this.$status.appendChild(txt);
|
||||
}
|
||||
|
||||
setActive(connected) {
|
||||
super.setActive(connected);
|
||||
return this.$msglog.className = connected ? 'active' : '';
|
||||
}
|
||||
|
||||
log(msg) {
|
||||
// Scroll to latest
|
||||
this.$msglog.value += msg + '\n';
|
||||
return this.$msglog.scrollTop = this.$msglog.scrollHeight;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// DOM elements references.
|
||||
DebugUI.prototype.$msglog = null;
|
||||
|
||||
DebugUI.prototype.$status = null;
|
||||
|
||||
return DebugUI;
|
||||
|
||||
}).call(this);
|
||||
|
||||
WebExtUI = (function() {
|
||||
class WebExtUI extends UI {
|
||||
constructor() {
|
||||
super();
|
||||
this.onConnect = this.onConnect.bind(this);
|
||||
this.onMessage = this.onMessage.bind(this);
|
||||
this.onDisconnect = this.onDisconnect.bind(this);
|
||||
this.initStats();
|
||||
chrome.runtime.onConnect.addListener(this.onConnect);
|
||||
}
|
||||
|
||||
initStats() {
|
||||
this.stats = [0];
|
||||
return setInterval((() => {
|
||||
this.stats.unshift(0);
|
||||
this.stats.splice(24);
|
||||
return this.postActive();
|
||||
}), 60 * 60 * 1000);
|
||||
}
|
||||
|
||||
initToggle() {
|
||||
var getting;
|
||||
return getting = chrome.storage.local.get("snowflake-enabled", (result) => {
|
||||
if (result['snowflake-enabled'] !== void 0) {
|
||||
this.enabled = result['snowflake-enabled'];
|
||||
} else {
|
||||
log("Toggle state not yet saved");
|
||||
}
|
||||
return this.setEnabled(this.enabled);
|
||||
});
|
||||
}
|
||||
|
||||
postActive() {
|
||||
var ref;
|
||||
return (ref = this.port) != null ? ref.postMessage({
|
||||
active: this.active,
|
||||
total: this.stats.reduce((function(t, c) {
|
||||
return t + c;
|
||||
}), 0),
|
||||
enabled: this.enabled
|
||||
}) : void 0;
|
||||
}
|
||||
|
||||
onConnect(port) {
|
||||
boundMethodCheck(this, WebExtUI);
|
||||
this.port = port;
|
||||
port.onDisconnect.addListener(this.onDisconnect);
|
||||
port.onMessage.addListener(this.onMessage);
|
||||
return this.postActive();
|
||||
}
|
||||
|
||||
onMessage(m) {
|
||||
var storing;
|
||||
boundMethodCheck(this, WebExtUI);
|
||||
this.enabled = m.enabled;
|
||||
this.setEnabled(this.enabled);
|
||||
this.postActive();
|
||||
return storing = chrome.storage.local.set({
|
||||
"snowflake-enabled": this.enabled
|
||||
}, function() {
|
||||
return log("Stored toggle state");
|
||||
});
|
||||
}
|
||||
|
||||
onDisconnect(port) {
|
||||
boundMethodCheck(this, WebExtUI);
|
||||
return this.port = null;
|
||||
}
|
||||
|
||||
setActive(connected) {
|
||||
super.setActive(connected);
|
||||
if (connected) {
|
||||
this.stats[0] += 1;
|
||||
}
|
||||
this.postActive();
|
||||
if (this.active) {
|
||||
return chrome.browserAction.setIcon({
|
||||
path: {
|
||||
32: "icons/status-running.png"
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return chrome.browserAction.setIcon({
|
||||
path: {
|
||||
32: "icons/status-on.png"
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setEnabled(enabled) {
|
||||
update();
|
||||
return chrome.browserAction.setIcon({
|
||||
path: {
|
||||
32: "icons/status-" + (enabled ? "on" : "off") + ".png"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
WebExtUI.prototype.port = null;
|
||||
|
||||
WebExtUI.prototype.stats = null;
|
||||
|
||||
return WebExtUI;
|
||||
|
||||
}).call(this);
|
Loading…
Add table
Add a link
Reference in a new issue