Optimizations.

This commit is contained in:
Laurent Espitallier 2017-07-22 19:47:25 +02:00
parent 399fb099dc
commit 4b5cfb1832
2 changed files with 14 additions and 46 deletions

View File

@ -5,12 +5,8 @@ var windowHeight
function shareURL(){ function shareURL(){
browser.tabs.query({active: true},function(tabs){ browser.tabs.query({active: true},function(tabs){
var gettingUrl = browser.storage.local.get("instance_url"); let gettingPrefs = browser.storage.local.get(["instance_url","window_width","window_height"]);
gettingUrl.then(onGotUrl, onError); gettingPrefs.then(onGot, onError);
var gettingWidth = browser.storage.local.get("window_width");
gettingWidth.then(onGotWidth, onError);
var gettingHeight = browser.storage.local.get("window_height");
gettingHeight.then(onGotHeight, onError);
var tab = tabs[0]; var tab = tabs[0];
@ -51,22 +47,10 @@ function onError(error) {
console.log(`Error: ${error}`); console.log(`Error: ${error}`);
} }
function onGotUrl(item) { function onGot(item) {
if (item.instance_url) { instance = item["instance_url"];
instance = item.instance_url; windowWidth = item["window_width"];
} windowHeight = item["window_height"];
}
function onGotWidth(item) {
if (item.window_width) {
windowWidth = item.window_width;
}
}
function onGotHeight(item) {
if (item.window_height) {
windowHeight = item.window_height;
}
} }
browser.contextMenus.create({ browser.contextMenus.create({

View File

@ -1,42 +1,26 @@
function saveOptions(e) { function saveOptions(e) {
e.preventDefault(); e.preventDefault();
browser.storage.local.set({ browser.storage.local.set({
instance_url: document.querySelector("#instance_url").value instance_url: document.querySelector("#instance_url").value ,
}); window_width: document.querySelector("#window_width").value ,
browser.storage.local.set({
window_width: document.querySelector("#window_width").value
});
browser.storage.local.set({
window_height: document.querySelector("#window_height").value window_height: document.querySelector("#window_height").value
}); });
} }
function restoreOptions() { function restoreOptions() {
function setCurrentChoiceUrl(result) { function setCurrentChoices(result) {
document.querySelector("#instance_url").value = result.instance_url || "http://semanticscuttle.sourceforge.net/"; document.querySelector("#instance_url").value = result["instance_url"] || "http://semanticscuttle.sourceforge.net/";
} document.querySelector("#window_width").value = result["window_width"] || "640";
document.querySelector("#window_height").value = result["window_height"] || "480";
function setCurrentChoiceWidth(result) {
document.querySelector("#window_width").value = result.window_width || "640";
}
function setCurrentChoiceHeight(result) {
document.querySelector("#window_height").value = result.window_height || "480";
} }
function onError(error) { function onError(error) {
console.log(`Error: ${error}`); console.log(`Error: ${error}`);
} }
var gettingUrl = browser.storage.local.get("instance_url"); var getting = browser.storage.local.get(["instance_url","window_width","window_height"]);
gettingUrl.then(setCurrentChoiceUrl, onError); getting.then(setCurrentChoices, onError);
var gettingWidth = browser.storage.local.get("window_width");
gettingWidth.then(setCurrentChoiceWidth, onError);
var gettingHeight = browser.storage.local.get("window_height");
gettingHeight.then(setCurrentChoiceHeight, onError);
} }