2020-01-24 22:20:30 +01:00
|
|
|
//
|
|
|
|
|
// Set default icon
|
|
|
|
|
// Use <div> as storage
|
|
|
|
|
//
|
|
|
|
|
async function getDefaultIcon() {
|
|
|
|
|
function getStoredIcon(result) {
|
|
|
|
|
return result.iconMime && result.icon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onStoredIconError() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getIcon = browser.storage.sync.get(["iconMime", "icon"]);
|
|
|
|
|
const iconStored = await getIcon.then(getStoredIcon, onStoredIconError);
|
|
|
|
|
|
|
|
|
|
if (!iconStored) {
|
2020-05-09 17:10:54 +02:00
|
|
|
const toDataURL = (url) =>
|
2020-01-24 22:20:30 +01:00
|
|
|
fetch(url)
|
2020-05-09 17:10:54 +02:00
|
|
|
.then((response) => response.blob())
|
2020-01-24 22:20:30 +01:00
|
|
|
.then(
|
2020-05-09 17:10:54 +02:00
|
|
|
(blob) =>
|
2020-01-24 22:20:30 +01:00
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
reader.onloadend = () => resolve(reader.result);
|
|
|
|
|
reader.onerror = reject;
|
|
|
|
|
reader.readAsDataURL(blob);
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Convert image to storage param
|
|
|
|
|
let { iconMime, iconBase64 } = await toDataURL("icons/blank-icon.png").then(
|
2020-05-09 17:10:54 +02:00
|
|
|
(dataUrl) => {
|
|
|
|
|
const data = dataUrl.split(":").pop().split(",");
|
2020-01-24 22:20:30 +01:00
|
|
|
return { iconMime: data[0].split(";")[0], iconBase64: data[1] };
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Store default icon (base64)
|
|
|
|
|
browser.storage.sync.set({
|
|
|
|
|
iconMime: iconMime,
|
2020-05-09 17:10:54 +02:00
|
|
|
icon: iconBase64,
|
2020-01-24 22:20:30 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Store in HTML
|
|
|
|
|
const iconDiv = document.getElementById("icon");
|
|
|
|
|
iconDiv.setAttribute("data-icon-mime", iconMime);
|
|
|
|
|
iconDiv.setAttribute("data-icon", iconBase64);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-29 20:36:08 +01:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Get window startup state
|
|
|
|
|
//
|
|
|
|
|
async function getStartupState() {
|
|
|
|
|
function getStartupState(result) {
|
|
|
|
|
return result.startMinimized == "true" ? "minimized" : "normal";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onStartupStateError() {
|
|
|
|
|
return "normal";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getState = browser.storage.sync.get("startMinimized");
|
|
|
|
|
return await getState.then(getStartupState, onStartupStateError);
|
|
|
|
|
}
|
2020-04-03 17:45:20 +02:00
|
|
|
|
|
|
|
|
//
|
2020-05-09 17:10:54 +02:00
|
|
|
// Get filters
|
2020-04-03 17:45:20 +02:00
|
|
|
//
|
2020-05-09 17:10:54 +02:00
|
|
|
async function getFilters() {
|
|
|
|
|
function getFiltersCb(result) {
|
|
|
|
|
return result.filters || undefined;
|
2020-04-03 17:45:20 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-09 17:10:54 +02:00
|
|
|
function onFiltersError() {
|
|
|
|
|
return undefined;
|
2020-04-03 17:45:20 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-09 17:10:54 +02:00
|
|
|
const getFilters = browser.storage.sync.get("filters");
|
|
|
|
|
return await getFilters.then(getFiltersCb, onFiltersError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Get extended filters
|
|
|
|
|
//
|
|
|
|
|
async function getFiltersExt() {
|
|
|
|
|
function getFiltersExtCb(result) {
|
|
|
|
|
return result.filtersExt || undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onFiltersExtError() {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getFiltersExt = browser.storage.sync.get("filtersExt");
|
|
|
|
|
return await getFiltersExt.then(getFiltersExtCb, onFiltersExtError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Get count type
|
|
|
|
|
//
|
|
|
|
|
async function getCountType() {
|
|
|
|
|
function getCountTypeCb(result) {
|
|
|
|
|
return result.countType || "0";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onCountTypeError() {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getCountType = browser.storage.sync.get("countType");
|
|
|
|
|
return await getCountType.then(getCountTypeCb, onCountTypeError);
|
2020-04-03 17:45:20 +02:00
|
|
|
}
|