forked from stsquad/emacs_chrome
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.js
55 lines (48 loc) · 1.47 KB
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* options.js
*
* This is the JavaScript for the extension options page
*
* This file is part of emacs_chrome (http://github.com/stsquad/emacs_chrome)
* and licensed under the GPLv3. See the COPYING file for details
*/
// Saves options to localStorage.
function save_options() {
var port_box = document.getElementById("port");
var port = port_box.value;
localStorage["edit_server_port"] = port;
// Update status to let user know options were saved.
var status = document.getElementById("status");
status.innerHTML = "Options Saved.";
setTimeout(function() {
status.innerHTML = "";
}, 750);
}
// Restores select box state to saved value from localStorage.
function restore_options() {
var port = localStorage["edit_server_port"];
if (!port) {
port = 9292;
}
var port_box = document.getElementById("port");
port_box.value = port;
}
/* Message handling multiplexer */
function localMessageHandler(msg, port) {
// What was the bidding?
var cmd = msg.msg;
if (cmd == "test_result") {
var status = document.getElementById("server_status");
status.innerHTML = msg.text;
} else {
console.log("localMessageHandler: un-handled message:"+cmd);
}
}
// Test for the presence of an Edit Server
function test_server() {
var port = chrome.extension.connect();
var status = document.getElementById("server_status");
status.innerHTML = "testing...";
port.onMessage.addListener(localMessageHandler);
port.postMessage({msg: "test"});
}