summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Bookmarklet.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Bookmarklet.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Bookmarklet.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Bookmarklet.js b/frontend/beta/js/Bookmarklet.js
index 59f4fef..67e93f0 100644
--- a/frontend/beta/js/Bookmarklet.js
+++ b/frontend/beta/js/Bookmarklet.js
@@ -1,214 +1,212 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer to http://www.clipperz.com.
9 8
10* Clipperz Community Edition is free software: you can redistribute 9* Clipperz is free software: you can redistribute it and/or modify it
11 it and/or modify it under the terms of the GNU Affero General Public 10 under the terms of the GNU Affero General Public License as published
12 License as published by the Free Software Foundation, either version 11 by the Free Software Foundation, either version 3 of the License, or
13 3 of the License, or (at your option) any later version. 12 (at your option) any later version.
14 13
15* Clipperz Community Edition is distributed in the hope that it will 14* Clipperz is distributed in the hope that it will be useful, but
16 be useful, but WITHOUT ANY WARRANTY; without even the implied 15 WITHOUT ANY WARRANTY; without even the implied warranty of
17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU Affero General Public License for more details. 17 See the GNU Affero General Public License for more details.
19 18
20* You should have received a copy of the GNU Affero General Public 19* You should have received a copy of the GNU Affero General Public
21 License along with Clipperz Community Edition. If not, see 20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
22 <http://www.gnu.org/licenses/>.
23 21
24*/ 22*/
25 23
26_cble = null; 24_cble = null;
27 25
28//----------------------------------------------------------------------------- 26//-----------------------------------------------------------------------------
29 27
30isLoginForm = function(aForm) { 28isLoginForm = function(aForm) {
31 var inputFields; 29 var inputFields;
32 var passwordFieldsFound; 30 var passwordFieldsFound;
33 var i,c; 31 var i,c;
34 32
35//console.log('is login form: ' + aForm.name + ' (' + aForm.id + ')'); 33//console.log('is login form: ' + aForm.name + ' (' + aForm.id + ')');
36 passwordFieldsFound = 0; 34 passwordFieldsFound = 0;
37 inputFields = aForm.elements; 35 inputFields = aForm.elements;
38 c = inputFields.length; 36 c = inputFields.length;
39 for (i=0; i<c; i++) { 37 for (i=0; i<c; i++) {
40 if (inputFields[i].type == 'password') { 38 if (inputFields[i].type == 'password') {
41 passwordFieldsFound ++; 39 passwordFieldsFound ++;
42 } 40 }
43 } 41 }
44//console.log('number of password fields found: ' + passwordFieldsFound); 42//console.log('number of password fields found: ' + passwordFieldsFound);
45 return (passwordFieldsFound == 1); 43 return (passwordFieldsFound == 1);
46}; 44};
47 45
48//----------------------------------------------------------------------------- 46//-----------------------------------------------------------------------------
49 47
50findLoginForm = function(aDocument, aLevel) { 48findLoginForm = function(aDocument, aLevel) {
51 varresult; 49 varresult;
52 vardocumentForms; 50 vardocumentForms;
53 var i,c; 51 var i,c;
54 52
55 result = null; 53 result = null;
56 54
57 try { 55 try {
58 documentForms = aDocument.getElementsByTagName('form'); 56 documentForms = aDocument.getElementsByTagName('form');
59 57
60 c = documentForms.length; 58 c = documentForms.length;
61 for (i=0; (i<c) && (result == null); i++) { 59 for (i=0; (i<c) && (result == null); i++) {
62 if (isLoginForm(documentForms[i])) { 60 if (isLoginForm(documentForms[i])) {
63 result = documentForms[i]; 61 result = documentForms[i];
64 } 62 }
65 } 63 }
66 64
67 if ((result == null) && (aLevel == 0)) { 65 if ((result == null) && (aLevel == 0)) {
68 var iFrames; 66 var iFrames;
69 67
70 iFrames = aDocument.getElementsByTagName('iframe'); 68 iFrames = aDocument.getElementsByTagName('iframe');
71 c = iFrames.length; 69 c = iFrames.length;
72 for (i=0; (i<c) && (result == null); i++) { 70 for (i=0; (i<c) && (result == null); i++) {
73 result = findLoginForm(iFrames[i].contentDocument, (aLevel + 1)); 71 result = findLoginForm(iFrames[i].contentDocument, (aLevel + 1));
74 } 72 }
75 } 73 }
76 } catch (e) { 74 } catch (e) {
77 _cble = e; 75 _cble = e;
78 } 76 }
79 77
80 return result; 78 return result;
81}; 79};
82 80
83//----------------------------------------------------------------------------- 81//-----------------------------------------------------------------------------
84 82
85inputElementValues = function(anInputElement) { 83inputElementValues = function(anInputElement) {
86 varresult; 84 varresult;
87 85
88 //if ((anInputElement instanceof HTMLInputElement) && (anInputElement.getAttribute('name') != null)) { 86 //if ((anInputElement instanceof HTMLInputElement) && (anInputElement.getAttribute('name') != null)) {
89 if ((anInputElement.tagName.toLowerCase() == 'input') && (anInputElement.getAttribute('name') != null)) { 87 if ((anInputElement.tagName.toLowerCase() == 'input') && (anInputElement.getAttribute('name') != null)) {
90 result = {}; 88 result = {};
91 result.type = anInputElement.getAttribute('type') || 'text'; 89 result.type = anInputElement.getAttribute('type') || 'text';
92 result.name = anInputElement.getAttribute('name'); 90 result.name = anInputElement.getAttribute('name');
93 // result.value = anInputElement.getAttribute('value'); 91 // result.value = anInputElement.getAttribute('value');
94 result.value = anInputElement.value; 92 result.value = anInputElement.value;
95 if (anInputElement.type.toLowerCase() == 'radio') { 93 if (anInputElement.type.toLowerCase() == 'radio') {
96 result.checked = anInputElement.checked; 94 result.checked = anInputElement.checked;
97 } 95 }
98 //} else if ((anInputElement instanceof HTMLSelectElement) && (anInputElement.getAttribute('name') != null)) { 96 //} else if ((anInputElement instanceof HTMLSelectElement) && (anInputElement.getAttribute('name') != null)) {
99 } else if ((anInputElement.tagName.toLowerCase() == 'select') && (anInputElement.getAttribute('name') != null)) { 97 } else if ((anInputElement.tagName.toLowerCase() == 'select') && (anInputElement.getAttribute('name') != null)) {
100 varoptions; 98 varoptions;
101 var c,i; 99 var c,i;
102 100
103//console.log('input element values: %o', anInputElement); 101//console.log('input element values: %o', anInputElement);
104 result = {}; 102 result = {};
105 result.type = 'select'; 103 result.type = 'select';
106 result.name = anInputElement.getAttribute('name'); 104 result.name = anInputElement.getAttribute('name');
107 105
108 result.options = []; 106 result.options = [];
109 options = anInputElement.options; 107 options = anInputElement.options;
110 c = options.length; 108 c = options.length;
111 for (i=0; i<c; i++) { 109 for (i=0; i<c; i++) {
112 varoption; 110 varoption;
113 111
114 option = {}; 112 option = {};
115 option.selected = options[i].selected; 113 option.selected = options[i].selected;
116 option.label = options[i].label || options[i].innerHTML; 114 option.label = options[i].label || options[i].innerHTML;
117 option.value = options[i].value; 115 option.value = options[i].value;
118 result.options.push(option); 116 result.options.push(option);
119 } 117 }
120 } else { 118 } else {
121 result = null; 119 result = null;
122 } 120 }
123 121
124 return result; 122 return result;
125}; 123};
126 124
127//----------------------------------------------------------------------------- 125//-----------------------------------------------------------------------------
128 126
129formParameters = function(aLoginForm) { 127formParameters = function(aLoginForm) {
130 varresult; 128 varresult;
131 vari, c; 129 vari, c;
132 varaction; 130 varaction;
133 131
134 if (aLoginForm == null) { 132 if (aLoginForm == null) {
135 result = null; 133 result = null;
136 } else { 134 } else {
137 varradioValues; 135 varradioValues;
138 varradioValueName; 136 varradioValueName;
139 137
140 result = {}; 138 result = {};
141 radioValues = {}; 139 radioValues = {};
142 140
143 action = aLoginForm.action; 141 action = aLoginForm.action;
144 if (action.constructor != String) { 142 if (action.constructor != String) {
145 action = aLoginForm.getAttribute('action'); 143 action = aLoginForm.getAttribute('action');
146 } 144 }
147 145
148 if (/^https?\:\/\/.*/.test(action)) { 146 if (/^https?\:\/\/.*/.test(action)) {
149 action = action; 147 action = action;
150 } else if (/^\/.*/.test(action)) { 148 } else if (/^\/.*/.test(action)) {
151 action = window.location.protocol + '/' + '/' + window.location.hostname + action; 149 action = window.location.protocol + '/' + '/' + window.location.hostname + action;
152 } else { 150 } else {
153 action = window.location.href.replace(/\/[^\/]*$/, '/' + action); 151 action = window.location.href.replace(/\/[^\/]*$/, '/' + action);
154 } 152 }
155 153
156 result.attributes = {}; 154 result.attributes = {};
157 result.attributes.action = action; 155 result.attributes.action = action;
158 result.attributes.method = aLoginForm.getAttribute('method'); 156 result.attributes.method = aLoginForm.getAttribute('method');
159 157
160 result.inputs = []; 158 result.inputs = [];
161 c = aLoginForm.elements.length; 159 c = aLoginForm.elements.length;
162 for (i=0; i<c; i++) { 160 for (i=0; i<c; i++) {
163 varinputElement; 161 varinputElement;
164 varelementValues; 162 varelementValues;
165 163
166 inputElement = aLoginForm.elements[i]; 164 inputElement = aLoginForm.elements[i];
167 elementValues = inputElementValues(inputElement); 165 elementValues = inputElementValues(inputElement);
168 if (elementValues != null) { 166 if (elementValues != null) {
169 if (elementValues.type != 'radio') { 167 if (elementValues.type != 'radio') {
170 result.inputs.push(elementValues); 168 result.inputs.push(elementValues);
171 } else { 169 } else {
172 varradioValue; 170 varradioValue;
173 varvalues; 171 varvalues;
174 172
175 radioValue = radioValues[elementValues.name]; 173 radioValue = radioValues[elementValues.name];
176 if (radioValue == null) { 174 if (radioValue == null) {
177 radioValue = {}; 175 radioValue = {};
178 radioValue.name = elementValues.name; 176 radioValue.name = elementValues.name;
179 radioValue.type = 'radio'; 177 radioValue.type = 'radio';
180 radioValue.options = []; 178 radioValue.options = [];
181 179
182 radioValues[elementValues.name] = radioValue; 180 radioValues[elementValues.name] = radioValue;
183 } 181 }
184 182
185 values = {}; 183 values = {};
186 values.value = elementValues.value; 184 values.value = elementValues.value;
187 values.checked = elementValues.checked; 185 values.checked = elementValues.checked;
188 186
189 radioValue.options.push(values); 187 radioValue.options.push(values);
190 } 188 }
191 } 189 }
192 } 190 }
193 191
194 for (radioValueName in radioValues) { 192 for (radioValueName in radioValues) {
195 if (typeof(radioValues[radioValueName]) != 'function') { 193 if (typeof(radioValues[radioValueName]) != 'function') {
196 result.inputs.push(radioValues[radioValueName]); 194 result.inputs.push(radioValues[radioValueName]);
197 } 195 }
198 } 196 }
199 } 197 }
200 198
201 return result; 199 return result;
202}; 200};
203 201
204//----------------------------------------------------------------------------- 202//-----------------------------------------------------------------------------
205 203
206pageParameters = function() { 204pageParameters = function() {
207 var result; 205 var result;
208 206
209 result = {}; 207 result = {};
210 result['title'] = document.title; 208 result['title'] = document.title;
211//<link rel='icon' href='http://example.com/favicon.ico' type='image/x-icon'> 209//<link rel='icon' href='http://example.com/favicon.ico' type='image/x-icon'>
212 210
213 return result; 211 return result;
214}; 212};