leave name input empty in new usercss style
This commit is contained in:
parent
2d9785be6e
commit
e6e7d7d158
|
@ -9,6 +9,8 @@
|
||||||
function createSourceEditor(editorBase) {
|
function createSourceEditor(editorBase) {
|
||||||
const {style, dirty} = editorBase;
|
const {style, dirty} = editorBase;
|
||||||
|
|
||||||
|
let placeholderName = '';
|
||||||
|
|
||||||
$('#mozilla-format-container').remove();
|
$('#mozilla-format-container').remove();
|
||||||
$('#header').addEventListener('wheel', headerOnScroll);
|
$('#header').addEventListener('wheel', headerOnScroll);
|
||||||
$('#sections').textContent = '';
|
$('#sections').textContent = '';
|
||||||
|
@ -112,7 +114,7 @@ function createSourceEditor(editorBase) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupNewStyle(style) {
|
async function setupNewStyle(style) {
|
||||||
style.sections[0].code = ' '.repeat(prefs.get('editor.tabSize')) +
|
style.sections[0].code = ' '.repeat(prefs.get('editor.tabSize')) +
|
||||||
`/* ${t('usercssReplaceTemplateSectionBody')} */`;
|
`/* ${t('usercssReplaceTemplateSectionBody')} */`;
|
||||||
let section = sectionsToMozFormat(style);
|
let section = sectionsToMozFormat(style);
|
||||||
|
@ -133,26 +135,27 @@ function createSourceEditor(editorBase) {
|
||||||
dirty.clear('sourceGeneration');
|
dirty.clear('sourceGeneration');
|
||||||
style.sourceCode = '';
|
style.sourceCode = '';
|
||||||
|
|
||||||
chromeSync.getLZValue('usercssTemplate').then(code => {
|
placeholderName = `${style.name || t('usercssReplaceTemplateName')} - ${new Date().toLocaleString()}`;
|
||||||
const name = style.name || t('usercssReplaceTemplateName');
|
let code = await chromeSync.getLZValue('usercssTemplate');
|
||||||
const date = new Date().toLocaleString();
|
code = code || DEFAULT_CODE;
|
||||||
code = code || DEFAULT_CODE;
|
code = code.replace(/@name(\s*)(?=[\r\n])/, (str, space) =>
|
||||||
code = code.replace(/@name(\s*)(?=[\r\n])/, (str, space) =>
|
`${str}${space ? '' : ' '}${placeholderName}`);
|
||||||
`${str}${space ? '' : ' '}${name} - ${date}`);
|
// strip the last dummy section if any, add an empty line followed by the section
|
||||||
// strip the last dummy section if any, add an empty line followed by the section
|
style.sourceCode = code.replace(/\s*@-moz-document[^{]*{[^}]*}\s*$|\s+$/g, '') + '\n\n' + section;
|
||||||
style.sourceCode = code.replace(/\s*@-moz-document[^{]*\{[^}]*\}\s*$|\s+$/g, '') + '\n\n' + section;
|
cm.startOperation();
|
||||||
cm.startOperation();
|
cm.setValue(style.sourceCode);
|
||||||
cm.setValue(style.sourceCode);
|
cm.clearHistory();
|
||||||
cm.clearHistory();
|
cm.markClean();
|
||||||
cm.markClean();
|
cm.endOperation();
|
||||||
cm.endOperation();
|
dirty.clear('sourceGeneration');
|
||||||
dirty.clear('sourceGeneration');
|
savedGeneration = cm.changeGeneration();
|
||||||
savedGeneration = cm.changeGeneration();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateMeta() {
|
function updateMeta() {
|
||||||
$('#name').value = style.customName || style.name;
|
const name = style.customName || style.name;
|
||||||
|
if (name !== placeholderName) {
|
||||||
|
$('#name').value = name;
|
||||||
|
}
|
||||||
$('#enabled').checked = style.enabled;
|
$('#enabled').checked = style.enabled;
|
||||||
$('#url').href = style.url;
|
$('#url').href = style.url;
|
||||||
editorBase.updateName();
|
editorBase.updateName();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user