deflicker name element in new usercss

This commit is contained in:
tophf 2022-02-20 18:34:51 +03:00
parent dd1f30e6aa
commit 90a71c0afc
3 changed files with 14 additions and 13 deletions

View File

@ -18,6 +18,7 @@
<script src="content/apply.js"></script> <script src="content/apply.js"></script>
<script src="js/sections-util.js"></script> <script src="js/sections-util.js"></script>
<script src="js/storage-util.js"></script>
<script src="edit/codemirror-themes.js"></script> <!-- must precede base.js --> <script src="edit/codemirror-themes.js"></script> <!-- must precede base.js -->
<script src="edit/base.js"></script> <script src="edit/base.js"></script>
@ -42,13 +43,11 @@
<script src="vendor/codemirror/addon/hint/css-hint.js"></script> <script src="vendor/codemirror/addon/hint/css-hint.js"></script>
<script src="vendor/codemirror/keymap/sublime.js"></script> <script src="vendor/codemirror/keymap/sublime.js"></script>
<script src="vendor-overwrites/codemirror-addon/match-highlighter.js"></script> <script src="vendor-overwrites/codemirror-addon/match-highlighter.js"></script>
<script src="vendor/lz-string-unsafe/lz-string-unsafe.min.js"></script>
<script src="js/color/color-converter.js"></script> <script src="js/color/color-converter.js"></script>
<script src="js/color/color-mimicry.js"></script> <script src="js/color/color-mimicry.js"></script>
<script src="js/color/color-picker.js"></script> <script src="js/color/color-picker.js"></script>
<script src="js/color/color-view.js"></script> <script src="js/color/color-view.js"></script>
<script src="js/storage-util.js"></script>
<script src="js/worker-util.js"></script> <script src="js/worker-util.js"></script>
<script src="edit/util.js"></script> <script src="edit/util.js"></script>

View File

@ -3,6 +3,7 @@
/* global CODEMIRROR_THEMES */ /* global CODEMIRROR_THEMES */
/* global CodeMirror */ /* global CodeMirror */
/* global MozDocMapper */// sections-util.js /* global MozDocMapper */// sections-util.js
/* global chromeSync */// storage-util.js
/* global initBeautifyButton */// beautify.js /* global initBeautifyButton */// beautify.js
/* global prefs */ /* global prefs */
/* global t */// localization.js /* global t */// localization.js
@ -77,8 +78,9 @@ const baseInit = (() => {
async function loadStyle() { async function loadStyle() {
const params = new URLSearchParams(location.search); const params = new URLSearchParams(location.search);
const id = Number(params.get('id')); let id = Number(params.get('id'));
const style = id && await API.styles.get(id) || { const style = id && await API.styles.get(id) || {
id: id = null, // resetting the non-existent id
name: params.get('domain') || name: params.get('domain') ||
tryURL(params.get('url-prefix')).hostname || tryURL(params.get('url-prefix')).hostname ||
'', '',
@ -88,14 +90,18 @@ const baseInit = (() => {
], ],
}; };
// switching the mode here to show the correct page ASAP, usually before DOMContentLoaded // switching the mode here to show the correct page ASAP, usually before DOMContentLoaded
editor.isUsercss = Boolean(style.usercssData || !style.id && prefs.get('newStyleAsUsercss')); const isUC = Boolean(style.usercssData || !id && prefs.get('newStyleAsUsercss'));
editor.style = style; Object.assign(editor, /** @namespace Editor */ {
style,
isUsercss: isUC,
template: isUC && !id && chromeSync.getLZValue(chromeSync.LZ_KEY.usercssTemplate), // promise
});
editor.updateClass(); editor.updateClass();
editor.updateTitle(false); editor.updateTitle(false);
$.rootCL.add(editor.isUsercss ? 'usercss' : 'sectioned'); $.rootCL.add(isUC ? 'usercss' : 'sectioned');
sessionStore.justEditedStyleId = style.id || ''; sessionStore.justEditedStyleId = id || '';
// no such style so let's clear the invalid URL parameters // no such style so let's clear the invalid URL parameters
if (!style.id) history.replaceState({}, '', location.pathname); if (!id) history.replaceState({}, '', location.pathname);
} }
/** Preloads the theme so CodeMirror can use the correct metrics in its first render */ /** Preloads the theme so CodeMirror can use the correct metrics in its first render */

View File

@ -4,7 +4,6 @@
/* global SectionsEditor */ /* global SectionsEditor */
/* global SourceEditor */ /* global SourceEditor */
/* global baseInit */ /* global baseInit */
/* global chromeSync */// storage-util.js
/* global clipString createHotkeyInput helpPopup */// util.js /* global clipString createHotkeyInput helpPopup */// util.js
/* global closeCurrentTab deepEqual sessionStore tryJSONparse */// toolbox.js /* global closeCurrentTab deepEqual sessionStore tryJSONparse */// toolbox.js
/* global cmFactory */ /* global cmFactory */
@ -19,10 +18,7 @@
document.body.appendChild(t.template.body); document.body.appendChild(t.template.body);
baseInit.ready.then(async () => { baseInit.ready.then(async () => {
[editor.template] = await Promise.all([ [editor.template] = await Promise.all([editor.template, waitForSheet()]);
editor.isUsercss && !editor.style.id && chromeSync.getLZValue(chromeSync.LZ_KEY.usercssTemplate),
waitForSheet(),
]);
(editor.isUsercss ? SourceEditor : SectionsEditor)(); (editor.isUsercss ? SourceEditor : SectionsEditor)();
await editor.ready; await editor.ready;
editor.ready = true; editor.ready = true;