gPass/chrome_addon/options.js

47 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

var default_preferences = {"pbkdf2_level": 1000,
2021-03-02 14:56:07 +01:00
"account_url": "https://gpass-demo.soutade.fr/demo",
"always_disabled":false,
"popup_clipboard":false
};
2015-01-27 21:10:55 +01:00
function save() {
var account_url = document.getElementById('account_url').value;
2021-03-02 14:56:07 +01:00
var pbkdf2_level = document.getElementById('pbkdf2_level').value;
var always_disabled = document.getElementById('always_disabled').checked;
var popup_clipboard = document.getElementById('popup_clipboard').checked;
2015-01-27 21:10:55 +01:00
chrome.storage.local.set({
'account_url': account_url,
2021-03-02 14:56:07 +01:00
'pbkdf2_level': pbkdf2_level,
'always_disabled': always_disabled,
'popup_clipboard': popup_clipboard,
2015-01-27 21:10:55 +01:00
}, function() {
alert('Saved');
});
}
2021-03-02 14:56:07 +01:00
function restoreOption(preferences, pref)
{
var res;
if (!preferences.hasOwnProperty(pref))
res = default_preferences[pref];
2015-01-27 21:10:55 +01:00
else
2021-03-02 14:56:07 +01:00
res = preferences[pref];
2015-01-27 21:10:55 +01:00
2021-03-02 14:56:07 +01:00
var element = document.getElementById(pref);
if (element.type == 'checkbox')
element.checked = res;
2015-01-27 21:10:55 +01:00
else
2021-03-02 14:56:07 +01:00
element.value = res;
}
2021-03-02 14:56:07 +01:00
chrome.storage.local.get(null, function(prefs) {
restoreOption(prefs, 'account_url');
restoreOption(prefs, 'pbkdf2_level');
restoreOption(prefs, 'always_disabled');
restoreOption(prefs, 'popup_clipboard');
2015-01-27 21:10:55 +01:00
});
document.getElementById('save').addEventListener("click", save);