parent
6b9cdf2bc2
commit
f250f9c233
|
@ -124,7 +124,14 @@ async function importFromString(jsonString) {
|
||||||
if (item && !item.id && item[prefs.STORAGE_KEY]) {
|
if (item && !item.id && item[prefs.STORAGE_KEY]) {
|
||||||
return analyzeStorage(item);
|
return analyzeStorage(item);
|
||||||
}
|
}
|
||||||
if (typeof item !== 'object' || !styleJSONseemsValid(item)) {
|
if (
|
||||||
|
!item ||
|
||||||
|
typeof item !== 'object' || (
|
||||||
|
isEmptyObj(item.usercssData)
|
||||||
|
? !styleJSONseemsValid(item)
|
||||||
|
: !/==userstyle==/i.test(item.sourceCode)
|
||||||
|
)
|
||||||
|
) {
|
||||||
stats.invalid.names.push(`#${index}: ${limitString(item && item.name || '')}`);
|
stats.invalid.names.push(`#${index}: ${limitString(item && item.name || '')}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -324,7 +331,7 @@ async function exportToFile() {
|
||||||
Object.assign({
|
Object.assign({
|
||||||
[prefs.STORAGE_KEY]: prefs.values,
|
[prefs.STORAGE_KEY]: prefs.values,
|
||||||
}, await chromeSync.getLZValues()),
|
}, await chromeSync.getLZValues()),
|
||||||
...await API.styles.getAll(),
|
...(await API.styles.getAll()).map(cleanupStyle),
|
||||||
];
|
];
|
||||||
const text = JSON.stringify(data, null, ' ');
|
const text = JSON.stringify(data, null, ' ');
|
||||||
const type = 'application/json';
|
const type = 'application/json';
|
||||||
|
@ -333,6 +340,17 @@ async function exportToFile() {
|
||||||
download: generateFileName(),
|
download: generateFileName(),
|
||||||
type,
|
type,
|
||||||
}).dispatchEvent(new MouseEvent('click'));
|
}).dispatchEvent(new MouseEvent('click'));
|
||||||
|
/** strip `sections`, `null` and empty objects */
|
||||||
|
function cleanupStyle(s) {
|
||||||
|
s = Object.assign({}, s);
|
||||||
|
if (s.usercssData) delete s.sections;
|
||||||
|
for (const [key, val] of Object.entries(s)) {
|
||||||
|
if (typeof val === 'object' && isEmptyObj(val)) {
|
||||||
|
delete s[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
function generateFileName() {
|
function generateFileName() {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const dd = ('0' + today.getDate()).substr(-2);
|
const dd = ('0' + today.getDate()).substr(-2);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user