Add compat.js for getPref and setPref

This commit is contained in:
Grégory Soutadé 2017-04-17 20:39:53 +02:00
parent 74b1010881
commit c3fab882f2
5 changed files with 86 additions and 25 deletions

44
chrome_addon/compat.js Normal file
View File

@ -0,0 +1,44 @@
/*
Copyright (C) 2013-2017 Grégory Soutadé
This file is part of gPass.
gPass is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
gPass is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with gPass. If not, see <http://www.gnu.org/licenses/>.
*/
function getPref(key)
{
var promise = new Promise((resolve, reject) => {
chrome.storage.local.get(key, (items) => {
let err = chrome.runtime.lastError;
if (err) {
reject(err);
} else {
resolve(items);
}
});
})
.then(function (pref) {
if (!pref.hasOwnProperty(key))
return default_preferences[key];
return pref[key];
});
return promise;
}
function setPref(key, value)
{
chrome.storage.local.set({key:value}, function ok() {});
}

View File

@ -175,25 +175,3 @@ async function decrypt(mkey, data)
return result;
}
function getPref(key)
{
return browser.storage.local.get(key)
.then(
function (pref) {
if (!pref.hasOwnProperty(key))
return default_preferences[key];
return pref[key];
}
,
function (err) {
console.log("Error getting preference " + err);
}
);
}
function setPref(key, value)
{
browser.storage.local.set({key:value});
}

View File

@ -3,7 +3,7 @@
"name": "gPass",
"short_name": "gPass",
"version": "0.7",
"version": "0.8",
"description": "gPass : global password manager",
"icons" : {"16":"icons/gpass_icon_16.png", "32":"icons/gpass_icon_32.png", "64":"icons/gpass_icon_64.png", "128":"icons/gpass_icon_128.png"},
"author" : "Grégory Soutadé",
@ -12,7 +12,7 @@
"content_scripts": [
{
"matches": ["https://*/*", "http://*/*"],
"js": ["lib/parseuri.js", "lib/misc.js", "lib/main.js"],
"js": ["lib/parseuri.js", "lib/misc.js", "compat.js", "lib/main.js"],
"run_at" : "document_idle",
"all_frames" : true
}

View File

@ -0,0 +1,39 @@
/*
Copyright (C) 2013-2017 Grégory Soutadé
This file is part of gPass.
gPass is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
gPass is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with gPass. If not, see <http://www.gnu.org/licenses/>.
*/
function getPref(key)
{
return browser.storage.local.get(key)
.then(
function (pref) {
if (!pref.hasOwnProperty(key))
return default_preferences[key];
return pref[key];
}
,
function (err) {
console.log("Error getting preference " + err);
}
);
}
function setPref(key, value)
{
browser.storage.local.set({key:value});
}

View File

@ -12,7 +12,7 @@
"content_scripts": [
{
"matches": ["https://*/*", "http://*/*"],
"js": ["lib/parseuri.js", "lib/misc.js", "lib/main.js"],
"js": ["lib/parseuri.js", "lib/misc.js", "compat.js", "lib/main.js"],
"run_at" : "document_idle",
"all_frames" : true
}