add the site section to a custom usercss template for new styles
fixes #352
This commit is contained in:
parent
d0d429bd8e
commit
c5ef92cf9c
|
@ -1151,6 +1151,10 @@
|
||||||
"usercssReplaceTemplateConfirmation": {
|
"usercssReplaceTemplateConfirmation": {
|
||||||
"message": "Replace the default template for new Usercss styles with the current code?"
|
"message": "Replace the default template for new Usercss styles with the current code?"
|
||||||
},
|
},
|
||||||
|
"usercssReplaceTemplateSectionBody": {
|
||||||
|
"message": "Insert code here...",
|
||||||
|
"description": "The code placeholder comment in a new style created by clicking 'Write style' in the popup"
|
||||||
|
},
|
||||||
"usercssConfigIncomplete": {
|
"usercssConfigIncomplete": {
|
||||||
"message": "The style was updated or deleted after the configuration dialog was shown. These variables were not saved to avoid corrupting the style's metadata:"
|
"message": "The style was updated or deleted after the configuration dialog was shown. These variables were not saved to avoid corrupting the style's metadata:"
|
||||||
},
|
},
|
||||||
|
|
|
@ -98,7 +98,8 @@ function createSourceEditor(style) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupNewStyle(style) {
|
function setupNewStyle(style) {
|
||||||
style.sections[0].code = ' '.repeat(prefs.get('editor.tabSize')) + '/* Insert code here... */';
|
style.sections[0].code = ' '.repeat(prefs.get('editor.tabSize')) +
|
||||||
|
`/* ${t('usercssReplaceTemplateSectionBody')} */`;
|
||||||
let section = sectionsToMozFormat(style);
|
let section = sectionsToMozFormat(style);
|
||||||
if (!section.includes('@-moz-document')) {
|
if (!section.includes('@-moz-document')) {
|
||||||
style.sections[0].domains = ['example.com'];
|
style.sections[0].domains = ['example.com'];
|
||||||
|
@ -115,13 +116,14 @@ function createSourceEditor(style) {
|
||||||
@description A new userstyle
|
@description A new userstyle
|
||||||
@author Me
|
@author Me
|
||||||
==/UserStyle== */
|
==/UserStyle== */
|
||||||
`.replace(/^\s+/gm, '') + '\n\n' + section;
|
`.replace(/^\s+/gm, '');
|
||||||
|
|
||||||
dirty.clear('sourceGeneration');
|
dirty.clear('sourceGeneration');
|
||||||
style.sourceCode = '';
|
style.sourceCode = '';
|
||||||
|
|
||||||
chromeSync.getLZValue('usercssTemplate').then(code => {
|
chromeSync.getLZValue('usercssTemplate').then(code => {
|
||||||
style.sourceCode = code || DEFAULT_CODE;
|
code = code || DEFAULT_CODE;
|
||||||
|
style.sourceCode = code.replace(/\s+$/, '\n\n') + section;
|
||||||
cm.startOperation();
|
cm.startOperation();
|
||||||
cm.setValue(style.sourceCode);
|
cm.setValue(style.sourceCode);
|
||||||
cm.clearHistory();
|
cm.clearHistory();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user