-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
134 lines (116 loc) · 5.65 KB
/
options.js
File metadata and controls
134 lines (116 loc) · 5.65 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var customDomainsTextbox;
var saveButton;
String.prototype.endsWith = function(str) {return (this.match(str+"$")==str)}
String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)}
function init() {
autoServerCheckbox = document.getElementById("autoServer");
urlTextbox = document.getElementById("url");
hostedServerTextbox = document.getElementById("hostedServer");
subscriberTextbox = document.getElementById("subscriber");
useSslCheckbox = document.getElementById("ssl");
autoCredentialsSelection = document.getElementById("autoCredentials");
usernameTextbox = document.getElementById("username");
passwordTextbox = document.getElementById("password");
saveUserPassCheckbox = document.getElementById("saveUserPass");
badgeSelection = document.getElementById("badge");
intervalSelection = document.getElementById("interval");
customTimerSpan = document.getElementById("customTimer");
timerSecondsTextbox = document.getElementById("timerSeconds");
saveButton = document.getElementById("save-button");
var username = chrome.extension.getBackgroundPage().getUsername();
var password = chrome.extension.getBackgroundPage().getMd5Password();
autoServerCheckbox.chcked = localStorage.autoServer ? (localStorage.autoServer === "true") : true;
urlTextbox.value = localStorage.url || "";
hostedServerTextbox.value = localStorage.hostedServer || "www.webhelpdesk.com";
subscriberTextbox.value = localStorage.subscriber || "";
useSslCheckbox.checked = localStorage.ssl ? (localStorage.ssl === "true") : true;
autoCredentialsSelection.selectedIndex = localStorage.autoCredentialsIdx || 0;
usernameTextbox.value = username; //(localStorage.saveUserPass === "true") ? (localStorage.username || "") : (sessionStorage.username || "");
passwordTextbox.value = (password != "") ? "*****" : ""; //(localStorage.saveUserPass === "true") ? (localStorage.md5password ? "*****" : "") : (sessionStorage.md5password ? "*****" : ""); ///localStorage.password || "";
saveUserPassCheckbox.checked = localStorage.saveUserPass ? (localStorage.saveUserPass === "true") : false;
badgeSelection.selectedIndex = localStorage.badgeSelectionIdx || 1;
intervalSelection.selectedIndex = localStorage.intervalSelectionIdx || 0;
timerSeconds.value = localStorage.update || 60;
if(intervalSelection.options[intervalSelection.selectedIndex].value == "custom") {
customTimerSpan.style.display = "";
}
autoServerCheck();
markClean();
}
function save() {
//alert( 'saving...');
localStorage.autoServer = autoServerCheckbox.checked ? "true" : "false";
localStorage.url = urlTextbox.value;
localStorage.hostedServer = hostedServerTextbox.value;
localStorage.subscriber = subscriberTextbox.value;
localStorage.ssl = useSslCheckbox.checked ? "true" : "false";
localStorage.autoCredentialsIdx = autoCredentialsSelection.selectedIndex;
localStorage.autoCredentials = autoCredentialsSelection.options[autoCredentialsSelection.selectedIndex].value;
localStorage.saveUserPass = saveUserPassCheckbox.checked ? "true" : "false";
/*
if(localStorage.saveUserPass === "true" ) {
localStorage.username = usernameTextbox.value;
if( passwordTextbox.value != "*****" && passwordTextbox.value != "" ) {
localStorage.md5password = b64_md5( passwordTextbox.value );
passwordTextbox.value = "*****";
}
} else {
sessionStorage.username = usernameTextbox.value;
if( passwordTextbox.value != "*****" && passwordTextbox.value != "" ) {
sessionStorage.md5password = b64_md5( passwordTextbox.value );
passwordTextbox.value = "*****";
}
}*/
// Because localStorage is page-specific, the function to save the username and password needs to exist
// in the background page. But... we can still call it from here!
chrome.extension.getBackgroundPage().setUserPass(usernameTextbox.value, passwordTextbox.value);
if(passwordTextbox.value != "") {
passwordTextbox.value = "*****";
}
localStorage.badgeSelectionIdx = badgeSelection.selectedIndex;
localStorage.badge = badgeSelection.options[badgeSelection.selectedIndex].value;
localStorage.intervalSelectionIdx = intervalSelection.selectedIndex;
if(intervalSelection.options[intervalSelection.selectedIndex].value == "custom") {
localStorage.update = timerSeconds.value;
} else {
localStorage.update = intervalSelection.options[intervalSelection.selectedIndex].value;
}
markClean();
// init takes care of validation, returns true if validation passes
if( chrome.extension.getBackgroundPage().init() ) {
// username & password aren't strictly required, so that the button can serve simply as a shortcut to the login page
if( ! usernameTextbox.value || ! passwordTextbox.value ) {
alert( chrome.i18n.getMessage( "whdnotifier_missing_username_or_password" ) );
}
}
}
function markDirty() {
//alert('dirty');
saveButton.disabled = false;
}
function markClean() {
// alert('clean');
saveButton.disabled = true;
}
function updateInt() {
if(intervalSelection.options[intervalSelection.selectedIndex].value == "custom") {
customTimerSpan.style.display = "";
} else {
customTimerSpan.style.display = "none";
}
}
function autoServerCheck() {
urlTextbox.disabled = autoServerCheckbox.checked;
hostedServerTextbox.disabled = autoServerCheckbox.checked;
subscriberTextbox.disabled = autoServerCheckbox.checked;
useSslCheckbox.disabled = autoServerCheckbox.checked;
}
window.onload = function() {
init();
$("select#interval").change(updateInt);
$("input[type=text]").keyup(markDirty);
$("input,select").change(markDirty);
$("button#save-button").click(save);
$("button#cancel-button").click(init);
$("#autoServer").change(autoServerCheck);
};