dedupe only on right-click or shift-click

This commit is contained in:
tophf 2021-12-23 05:39:44 +03:00
parent e9ed8dc946
commit 0fec0c6123
3 changed files with 16 additions and 5 deletions

View File

@ -391,6 +391,10 @@
"excludeStyleByUrlLabel": {
"message": "Exclude the current URL"
},
"exportDeduplicate": {
"message": "Shift-click or Right-click will export a smaller file for UserCSS styles.\nSuch styles are importable only in Stylus 1.5.23 or newer.",
"description": "Tooltip for the button to export all styles in the 'manage' page"
},
"exportLabel": {
"message": "Export",
"description": "Label for the button to export a style ('edit' page) or all styles ('manage' page)"

View File

@ -323,7 +323,7 @@
<summary><h2 id="backup-title" i18n-text="backupButtons"></h2></summary>
<span id="backup-message" i18n-text="backupMessage"></span>
<div id="backup-buttons">
<button id="file-all-styles" i18n-text="exportLabel"></button>
<button id="file-all-styles" i18n-text="exportLabel" i18n-title="exportDeduplicate"></button>
<button id="unfile-all-styles" i18n-text="importLabel"></button>
<button id="sync-styles" i18n-text="optionsCustomizeSync"></button>
</div>

View File

@ -14,7 +14,10 @@
*/// dom.js
'use strict';
$('#file-all-styles').onclick = exportToFile;
Object.assign($('#file-all-styles'), {
onclick: exportToFile,
oncontextmenu: exportToFile,
});
$('#unfile-all-styles').onclick = () => importFromFile({fileTypeFilter: '.json'});
Object.assign(document.body, {
@ -325,13 +328,17 @@ async function importFromString(jsonString) {
}
}
async function exportToFile() {
/** @param {MouseEvent} e */
async function exportToFile(e) {
e.preventDefault();
await require(['/js/storage-util']);
const shouldClean = e.shiftKey || e.button === 2;
const styles = await API.styles.getAll();
const data = [
Object.assign({
[prefs.STORAGE_KEY]: prefs.values,
}, await chromeSync.getLZValues()),
...(await API.styles.getAll()).map(cleanupStyle),
...shouldClean ? styles.map(cleanupStyle) : styles,
];
const text = JSON.stringify(data, null, ' ');
const type = 'application/json';
@ -340,7 +347,7 @@ async function exportToFile() {
download: generateFileName(),
type,
}).dispatchEvent(new MouseEvent('click'));
/** strip `sections`, `null` and empty objects */
/** Stripping `sections`, `null` and empty objects */
function cleanupStyle(style) {
const copy = {};
for (const [key, val] of Object.entries(style)) {