Add store ID for default store (#17)
This commit is contained in:
@@ -304,7 +304,7 @@ function hostAction(settings, action, params = {}) {
|
|||||||
*/
|
*/
|
||||||
async function parseFields(settings, login) {
|
async function parseFields(settings, login) {
|
||||||
var response = await hostAction(settings, "fetch", {
|
var response = await hostAction(settings, "fetch", {
|
||||||
store: login.store.name,
|
storeId: login.store.id,
|
||||||
file: login.login + ".gpg"
|
file: login.login + ".gpg"
|
||||||
});
|
});
|
||||||
if (response.status != "ok") {
|
if (response.status != "ok") {
|
||||||
@@ -381,13 +381,13 @@ async function receiveMessage(message, sender, sendResponse) {
|
|||||||
settings.version = response.version;
|
settings.version = response.version;
|
||||||
if (settings.stores.length) {
|
if (settings.stores.length) {
|
||||||
// there are user-configured stores present
|
// there are user-configured stores present
|
||||||
for (var key in settings.stores) {
|
for (var storeId in settings.stores) {
|
||||||
if (response.data.storeSettings.hasOwnProperty(key)) {
|
if (response.data.storeSettings.hasOwnProperty(storeId)) {
|
||||||
var fileSettings = JSON.parse(response.data.storeSettings[key]);
|
var fileSettings = JSON.parse(response.data.storeSettings[storeId]);
|
||||||
if (typeof settings.stores[key].settings !== "object") {
|
if (typeof settings.stores[storeId].settings !== "object") {
|
||||||
settings.stores[key].settings = {};
|
settings.stores[storeId].settings = {};
|
||||||
}
|
}
|
||||||
var storeSettings = settings.stores[key].settings;
|
var storeSettings = settings.stores[storeId].settings;
|
||||||
for (var settingKey in fileSettings) {
|
for (var settingKey in fileSettings) {
|
||||||
if (!storeSettings.hasOwnProperty(settingKey)) {
|
if (!storeSettings.hasOwnProperty(settingKey)) {
|
||||||
storeSettings[settingKey] = fileSettings[settingKey];
|
storeSettings[settingKey] = fileSettings[settingKey];
|
||||||
@@ -398,6 +398,7 @@ async function receiveMessage(message, sender, sendResponse) {
|
|||||||
} else {
|
} else {
|
||||||
// no user-configured stores, so use the default store
|
// no user-configured stores, so use the default store
|
||||||
settings.stores.default = {
|
settings.stores.default = {
|
||||||
|
id: "default",
|
||||||
name: "default",
|
name: "default",
|
||||||
path: response.data.defaultStore.path,
|
path: response.data.defaultStore.path,
|
||||||
settings: response.data.defaultStore.settings
|
settings: response.data.defaultStore.settings
|
||||||
|
@@ -16,12 +16,12 @@ chrome.tabs.query({ active: true, currentWindow: true }, async function(tabs) {
|
|||||||
var settings = response.settings;
|
var settings = response.settings;
|
||||||
settings.tab = tabs[0];
|
settings.tab = tabs[0];
|
||||||
settings.host = new URL(settings.tab.url).hostname;
|
settings.host = new URL(settings.tab.url).hostname;
|
||||||
for (var store in settings.stores) {
|
for (var storeId in settings.stores) {
|
||||||
var when = localStorage.getItem("recent:" + settings.stores[store].path);
|
var when = localStorage.getItem("recent:" + storeId);
|
||||||
if (when) {
|
if (when) {
|
||||||
settings.stores[store].when = JSON.parse(when);
|
settings.stores[storeId].when = JSON.parse(when);
|
||||||
} else {
|
} else {
|
||||||
settings.stores[store].when = 0;
|
settings.stores[storeId].when = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
settings.recent = localStorage.getItem("recent");
|
settings.recent = localStorage.getItem("recent");
|
||||||
@@ -102,22 +102,20 @@ async function run(settings) {
|
|||||||
if (recent) {
|
if (recent) {
|
||||||
recent = JSON.parse(recent);
|
recent = JSON.parse(recent);
|
||||||
}
|
}
|
||||||
for (var store in response.files) {
|
for (var storeId in response.files) {
|
||||||
for (var key in response.files[store]) {
|
for (var key in response.files[storeId]) {
|
||||||
// set login fields
|
// set login fields
|
||||||
var login = {
|
var login = {
|
||||||
index: index++,
|
index: index++,
|
||||||
store: settings.stores[store],
|
store: settings.stores[storeId],
|
||||||
login: response.files[store][key].replace(/\.gpg$/i, ""),
|
login: response.files[storeId][key].replace(/\.gpg$/i, ""),
|
||||||
allowFill: true
|
allowFill: true
|
||||||
};
|
};
|
||||||
login.domain = pathToDomain(store + "/" + login.login);
|
login.domain = pathToDomain(storeId + "/" + login.login);
|
||||||
login.inCurrentDomain =
|
login.inCurrentDomain =
|
||||||
settings.host == login.domain || settings.host.endsWith("." + login.domain);
|
settings.host == login.domain || settings.host.endsWith("." + login.domain);
|
||||||
login.recent =
|
login.recent =
|
||||||
settings.recent[
|
settings.recent[sha1(settings.host + sha1(login.store.id + sha1(login.login)))];
|
||||||
sha1(settings.host + sha1(login.store.path + sha1(login.login)))
|
|
||||||
];
|
|
||||||
if (!login.recent) {
|
if (!login.recent) {
|
||||||
login.recent = {
|
login.recent = {
|
||||||
when: 0,
|
when: 0,
|
||||||
@@ -151,15 +149,14 @@ function saveRecent(settings, login, remove = false) {
|
|||||||
var ignoreInterval = 60000; // 60 seconds - don't increment counter twice within this window
|
var ignoreInterval = 60000; // 60 seconds - don't increment counter twice within this window
|
||||||
|
|
||||||
// save store timestamp
|
// save store timestamp
|
||||||
localStorage.setItem("recent:" + login.store.path, JSON.stringify(Date.now()));
|
localStorage.setItem("recent:" + login.store.id, JSON.stringify(Date.now()));
|
||||||
|
|
||||||
// update login usage count & timestamp
|
// update login usage count & timestamp
|
||||||
if (Date.now() > login.recent.when + ignoreInterval) {
|
if (Date.now() > login.recent.when + ignoreInterval) {
|
||||||
login.recent.count++;
|
login.recent.count++;
|
||||||
}
|
}
|
||||||
login.recent.when = Date.now();
|
login.recent.when = Date.now();
|
||||||
settings.recent[sha1(settings.host + sha1(login.store.path + sha1(login.login)))] =
|
settings.recent[sha1(settings.host + sha1(login.store.id + sha1(login.login)))] = login.recent;
|
||||||
login.recent;
|
|
||||||
|
|
||||||
// save to local storage
|
// save to local storage
|
||||||
localStorage.setItem("recent", JSON.stringify(settings.recent));
|
localStorage.setItem("recent", JSON.stringify(settings.recent));
|
||||||
|
Reference in New Issue
Block a user