Rev 1958 | Rev 2050 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1958 | Rev 2014 | ||
|---|---|---|---|
| Line 131... | Line 131... | ||
| 131 | 131 | ||
| 132 | function Sensor_StoreNumberInPhonebook(number) |
132 | function Sensor_StoreNumberInPhonebook(number) |
| 133 | { |
133 | { |
| 134 | var phonebook = Storage_GetJsonParamter("PhoneBook",number) |
134 | var phonebook = Storage_GetJsonParamter("PhoneBook",number) |
| 135 | if (!phonebook) { |
135 | if (!phonebook) { |
| - | 136 | ||
| 136 | if (number.charAt(0) != '0') { |
137 | if (number.charAt(0) != '0') { |
| - | 138 | if (typeof sensorDefaultPhoneAreaCode === 'undefined'){ |
|
| - | 139 | Log("\033[31mOnlinePhonebook: please add sensorDefaultPhoneAreaCode = yourAreaCode to autostart.js, defaulting to 031\033[0m\n"); |
|
| 137 | number = "031"+number; |
140 | number = "031"+number; |
| - | 141 | } else { |
|
| - | 142 | number = sensorDefaultPhoneAreaCode+number; |
|
| 138 | } |
143 | } |
| - | 144 | } |
|
| - | 145 | var persons = new Array(); |
|
| - | 146 | url = "wap.eniro.se/query?search_word=" + number + "&what=mobwp"; |
|
| - | 147 | //Log("\033[31mURL:"+url+"\033[0m\n"); |
|
| - | 148 | Http_Request(url, |
|
| - | 149 | function(socket_id, result, header, content_data) { |
|
| - | 150 | if (result.indexOf("200 OK") != -1) |
|
| - | 151 | { |
|
| - | 152 | //Log("\033[31mOnlinePhonebook: result was: " + content_data + "\033[0m\n"); |
|
| - | 153 | var lines = content_data.split("\n"); |
|
| - | 154 | ||
| - | 155 | var endString = "<anchor>Tillbaka<prev/></anchor>"; |
|
| - | 156 | var nameStartString = "<td class=\"hTd2\">"; |
|
| - | 157 | var nameEndString = "</table>"; |
|
| - | 158 | for (var n = 1; n < lines.length; n++) |
|
| - | 159 | { |
|
| - | 160 | var line = lines[n].trim("\n"); |
|
| - | 161 | ||
| - | 162 | if (line.indexOf(endString) != -1) |
|
| - | 163 | { |
|
| - | 164 | break; |
|
| - | 165 | } |
|
| - | 166 | if (line.indexOf(nameStartString) != -1) |
|
| - | 167 | { |
|
| - | 168 | line = lines[n+1].trim("\n"); |
|
| - | 169 | splitted = line.split("b>"); |
|
| - | 170 | persons[persons.length] = splitted[1].substr(0, splitted[1].length -2); |
|
| - | 171 | break; |
|
| - | 172 | } |
|
| - | 173 | ||
| - | 174 | } |
|
| - | 175 | ||
| - | 176 | //Log("\033[31mOnlinePhonebook: Line: " + lines[1] + "\033[0m\n"); |
|
| - | 177 | //Log("\033[31mOnlinePhonebook: Line: " + lines[2] + "\033[0m\n"); |
|
| - | 178 | //Log("\033[31mOnlinePhonebook: Line: " + lines[3] + "\033[0m\n"); |
|
| - | 179 | if (persons.length > 0) { |
|
| - | 180 | Storage_SetJsonParameter("PhoneBook", number, persons); |
|
| - | 181 | ||
| - | 182 | //CAll all listeners! |
|
| - | 183 | //.... |
|
| - | 184 | ||
| - | 185 | Log("\033[31mOnlinePhonebook: Found: " + JSON.stringify(persons) + "\033[0m\n"); |
|
| - | 186 | } |
|
| - | 187 | } |
|
| - | 188 | else |
|
| - | 189 | { |
|
| - | 190 | Log("\033[31mOnlinePhonebook: Failed to do name lookup, result was: " + result + "\033[0m\n"); |
|
| - | 191 | } |
|
| - | 192 | } |
|
| - | 193 | ); |
|
| - | 194 | if (persons.length == 0) { |
|
| - | 195 | if (typeof SsensorRKSEEK_API === 'undefined') { |
|
| - | 196 | ; |
|
| - | 197 | } else { |
|
| - | 198 | url = "rkseek.oblivioncreations.se/?client="+sensorRKSEEK_API+"&n=" + number + "&out=text"; |
|
| - | 199 | //Log("\033[31mURL:"+url+"\033[0m\n"); |
|
| - | 200 | Http_Request(url, |
|
| - | 201 | function(socket_id, result, header, content_data) { |
|
| - | 202 | var persons = new Array(); |
|
| - | 203 | if (result.indexOf("200 OK") != -1) |
|
| - | 204 | { |
|
| - | 205 | //Log("\033[31mOnlinePhonebook: result was: " + content_data + "\033[0m\n"); |
|
| - | 206 | var lines = content_data.split("\n"); |
|
| - | 207 | //Log("\033[31mOnlinePhonebook: Line: " + lines[1] + "\033[0m\n"); |
|
| - | 208 | //Log("\033[31mOnlinePhonebook: Line: " + lines[2] + "\033[0m\n"); |
|
| - | 209 | //Log("\033[31mOnlinePhonebook: Line: " + lines[3] + "\033[0m\n"); |
|
| - | 210 | if (lines[2].length > 0) { |
|
| - | 211 | persons = lines[2]; |
|
| - | 212 | Storage_SetJsonParameter("PhoneBook", number, persons); |
|
| - | 213 | Log("\033[31mOnlinePhonebook: Found: " + JSON.stringify(persons) + "\033[0m\n"); |
|
| - | 214 | } |
|
| - | 215 | } |
|
| - | 216 | else |
|
| - | 217 | { |
|
| - | 218 | Log("\033[31mOnlinePhonebook: Failed to do name lookup, result was: " + result + "\033[0m\n"); |
|
| - | 219 | } |
|
| - | 220 | } |
|
| - | 221 | ); |
|
| - | 222 | } |
|
| - | 223 | } |
|
| - | 224 | ||
| - | 225 | /* |
|
| 139 | Http_Request("wap.hitta.se/default.aspx?Who=" + number + "&Where=&PageAction=White", |
226 | Http_Request("wap.hitta.se/default.aspx?Who=" + number + "&Where=&PageAction=White", |
| 140 | function(socket_id, result, header, content_data) { |
227 | function(socket_id, result, header, content_data) { |
| 141 | var persons = new Array(); |
228 | var persons = new Array(); |
| 142 | if (result.indexOf("200 OK") != -1) |
229 | if (result.indexOf("200 OK") != -1) |
| 143 | { |
230 | { |
| Line 176... | Line 263... | ||
| 176 | { |
263 | { |
| 177 | Log("\033[31mOnlinePhonebook: Failed to do name lookup, result was: " + result + "\033[0m\n"); |
264 | Log("\033[31mOnlinePhonebook: Failed to do name lookup, result was: " + result + "\033[0m\n"); |
| 178 | } |
265 | } |
| 179 | } |
266 | } |
| 180 | ); |
267 | ); |
| - | 268 | */ |
|
| 181 | } else { |
269 | } else { |
| 182 | Log("Number already stored\n"); |
270 | Log("Number already stored\n"); |
| 183 | } |
271 | } |
| 184 | } |
272 | } |
| 185 | Console_RegisterCommand(Sensor_StoreNumberInPhonebook, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args); }); |
273 | Console_RegisterCommand(Sensor_StoreNumberInPhonebook, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args); }); |