Add: save usercss from multi-section editor
This commit is contained in:
parent
0d4d058b00
commit
da5626a6d7
|
@ -787,10 +787,18 @@
|
||||||
"message": "Enter a name.",
|
"message": "Enter a name.",
|
||||||
"description": "Error displayed when user saves without providing a name"
|
"description": "Error displayed when user saves without providing a name"
|
||||||
},
|
},
|
||||||
|
"stylePasteMozillaFormat": {
|
||||||
|
"message": "The code you pasted looks like mozilla format style. Would you like to import it?",
|
||||||
|
"description": "The confirmation to import mozilla format style from pasted text"
|
||||||
|
},
|
||||||
"styleSaveLabel": {
|
"styleSaveLabel": {
|
||||||
"message": "Save",
|
"message": "Save",
|
||||||
"description": "Label for save button for style editing"
|
"description": "Label for save button for style editing"
|
||||||
},
|
},
|
||||||
|
"styleSaveAsUsercss": {
|
||||||
|
"message": "The source code contains usercss metadata. Would you like to save the source code as usercss?",
|
||||||
|
"description": "The confirmation to create usercss from the editor"
|
||||||
|
},
|
||||||
"styleSectionsTitle": {
|
"styleSectionsTitle": {
|
||||||
"message": "Sections",
|
"message": "Sections",
|
||||||
"description": "Title for the style sections section"
|
"description": "Title for the style sections section"
|
||||||
|
|
24
edit/edit.js
24
edit/edit.js
|
@ -306,7 +306,8 @@ function setupCodeMirror(textarea, index) {
|
||||||
if (
|
if (
|
||||||
text.includes('@-moz-document') &&
|
text.includes('@-moz-document') &&
|
||||||
text.replace(/\/\*[\s\S]*?\*\//g, '')
|
text.replace(/\/\*[\s\S]*?\*\//g, '')
|
||||||
.match(/@-moz-document[\s\r\n]+(url|url-prefix|domain|regexp)\(/)
|
.match(/@-moz-document[\s\r\n]+(url|url-prefix|domain|regexp)\(/) &&
|
||||||
|
confirm(t('stylePasteMozillaFormat'))
|
||||||
) {
|
) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
fromMozillaFormat();
|
fromMozillaFormat();
|
||||||
|
@ -1476,7 +1477,28 @@ function save() {
|
||||||
editor.save();
|
editor.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isUsercssSourceCode() {
|
||||||
|
const sourceCode = editors[0].getValue();
|
||||||
|
return /==UserStyle==[\s\S]+==\/UserStyle==/i.test(sourceCode);
|
||||||
|
}
|
||||||
|
|
||||||
function saveSectionStyle() {
|
function saveSectionStyle() {
|
||||||
|
if (!styleId && isUsercssSourceCode() && confirm(t('styleSaveAsUsercss'))) {
|
||||||
|
const sourceCode = editors[0].getValue();
|
||||||
|
onBackgroundReady()
|
||||||
|
.then(() => BG.usercssHelper.save({
|
||||||
|
reason: 'editSave',
|
||||||
|
sourceCode,
|
||||||
|
enabled: $('#enabled').checked
|
||||||
|
}))
|
||||||
|
.then(style => {
|
||||||
|
window.onbeforeunload = null;
|
||||||
|
location.href = `/edit.html?id=${style.id}`;
|
||||||
|
})
|
||||||
|
.catch(alert);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
updateLintReportIfEnabled(null, 0);
|
updateLintReportIfEnabled(null, 0);
|
||||||
|
|
||||||
// save the contents of the CodeMirror editors back into the textareas
|
// save the contents of the CodeMirror editors back into the textareas
|
||||||
|
|
Loading…
Reference in New Issue
Block a user