forked from Netsyms/PackageHelper
parent
cadf20e2ad
commit
d3bff90b3e
@ -0,0 +1,9 @@
|
||||
<#if licenseFirst??>
|
||||
${licenseFirst}
|
||||
</#if>
|
||||
${licensePrefix}This Source Code Form is subject to the terms of the Mozilla Public
|
||||
${licensePrefix}License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
${licensePrefix}file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
<#if licenseLast??>
|
||||
${licenseLast}
|
||||
</#if>
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
var autofillDB = {};
|
||||
|
||||
if (localStorage.getItem("autofill_db") != null) {
|
||||
autofillDB = JSON.parse(localStorage.getItem("autofill_db"));
|
||||
}
|
||||
|
||||
function addressToNumberAndStreet(address) {
|
||||
var number = "";
|
||||
var street = "";
|
||||
|
||||
var addressRegex = RegExp("^[0-9]+ .+$");
|
||||
if (addressRegex.test(address)) {
|
||||
number = address.split(" ", 2)[0];
|
||||
street = address.substring(address.indexOf(' ') + 1);
|
||||
}
|
||||
|
||||
return [number, street];
|
||||
}
|
||||
|
||||
function addAutofillEntry(address) {
|
||||
var [number, street] = addressToNumberAndStreet(address);
|
||||
|
||||
if (number == "" || street == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof autofillDB[number] == 'undefined') {
|
||||
autofillDB[number] = [
|
||||
[street, 1]
|
||||
];
|
||||
} else {
|
||||
var found = false;
|
||||
for (var i = 0; i < autofillDB[number].length; i++) {
|
||||
if (autofillDB[number][i][0] == street) {
|
||||
autofillDB[number][i][1]++;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
autofillDB[number].push([street, 1]);
|
||||
}
|
||||
}
|
||||
|
||||
localStorage.setItem("autofill_db", JSON.stringify(autofillDB));
|
||||
}
|
||||
|
||||
function searchAutofill(number) {
|
||||
if (typeof autofillDB[number] == 'undefined') {
|
||||
return [];
|
||||
}
|
||||
|
||||
var sorted = autofillDB[number].sort(function (a, b) {
|
||||
return b[1] - a[1];
|
||||
});
|
||||
|
||||
var streets = [];
|
||||
|
||||
for (var i = 0; i < sorted.length; i++) {
|
||||
streets.push(sorted[i][0]);
|
||||
}
|
||||
|
||||
return streets;
|
||||
}
|
Loading…
Reference in New Issue