From 9d1243073b6880ec6476a4030a51813c8a555c09 Mon Sep 17 00:00:00 2001 From: eight Date: Tue, 7 Dec 2021 12:44:49 +0800 Subject: [PATCH] Add: style settings (#1358) * Add: style settings * Change: use radio instead of select for dark/light mode * Change: x -> Delete * Change: (in|ex)clusion messages * Fix: avoid extra space when there is no rule * Fix: UI in mobile * Change: delete priority * Change: use textarea for include/exclude, remove isCodeUpdated * Fix: separate toggle * Fix: minor * Fix: remove codeIsUpdated in styleman --- _locales/en/messages.json | 21 ++++++++++++ background/style-manager.js | 20 ++++++++---- edit.html | 53 +++++++++++++++++++++++++++++- edit/base.js | 5 +-- edit/edit.css | 10 ++++-- edit/edit.js | 23 +++++++++---- edit/sections-editor.js | 34 +++++++++++++++---- edit/settings.css | 45 +++++++++++++++++++++++++ edit/settings.js | 65 +++++++++++++++++++++++++++++++++++++ edit/source-editor.js | 27 +++++++++++++-- edit/tab.css | 28 ++++++++++++++++ edit/tab.js | 19 +++++++++++ js/event-emitter.js | 37 +++++++++++++++++++++ 13 files changed, 359 insertions(+), 28 deletions(-) create mode 100644 edit/settings.css create mode 100644 edit/settings.js create mode 100644 edit/tab.css create mode 100644 edit/tab.js create mode 100644 js/event-emitter.js diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 66a885f8..be2006e4 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -375,6 +375,12 @@ }, "description": "Title of the page for editing styles" }, + "editorCodeLabel": { + "message": "Code" + }, + "editorSettingLabel": { + "message": "Settings" + }, "enableStyleLabel": { "message": "Enable", "description": "Label for the button to enable a style" @@ -1634,6 +1640,21 @@ "message": "As a security precaution, the browser prohibits extensions from affecting its built-in pages (like chrome://version, the standard new tab page as of Chrome 61, about:addons, and so on) as well as other extensions' pages. Each browser also restricts access to its own extensions gallery (like Chrome Web Store or AMO).", "description": "Sub-note in the toolbar pop-up when on a URL Stylus can't affect" }, + "styleOriginLabel": { + "message": "Style origin" + }, + "styleUpdateUrlLabel": { + "message": "Update URL" + }, + "stylePreferSchemeLabel": { + "message": "Dark/Light mode" + }, + "styleIncludeLabel": { + "message": "Custom included sites" + }, + "styleExcludeLabel": { + "message": "Custom excluded sites" + }, "syncDropboxDeprecated": { "message": "Dropbox import/export is replaced by a more advanced style sync in the options page." }, diff --git a/background/style-manager.js b/background/style-manager.js index c71a70ba..b8243d03 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -283,7 +283,7 @@ const styleMan = (() => { async toggle(id, enabled) { if (ready.then) await ready; const style = Object.assign({}, id2style(id), {enabled}); - await saveStyle(style, {reason: 'toggle', codeIsUpdated: false}); + await saveStyle(style, {reason: 'toggle'}); return id; }, @@ -297,6 +297,13 @@ const styleMan = (() => { removeExclusion: removeIncludeExclude.bind(null, 'exclusions'), /** @returns {Promise} */ removeInclusion: removeIncludeExclude.bind(null, 'inclusions'), + + async config(id, prop, value) { + if (ready.then) await ready; + const style = Object.assign({}, id2style(id)); + style[prop] = value; + return saveStyle(style, {reason: 'config'}); + }, }; //#endregion @@ -375,7 +382,7 @@ const styleMan = (() => { throw new Error('The rule already exists'); } style[type] = list.concat([rule]); - return saveStyle(style, {reason: 'styleSettings'}); + return saveStyle(style, {reason: 'config'}); } async function removeIncludeExclude(type, id, rule) { @@ -386,10 +393,10 @@ const styleMan = (() => { return; } style[type] = list.filter(r => r !== rule); - return saveStyle(style, {reason: 'styleSettings'}); + return saveStyle(style, {reason: 'config'}); } - function broadcastStyleUpdated(style, reason, method = 'styleUpdated', codeIsUpdated = true) { + function broadcastStyleUpdated(style, reason, method = 'styleUpdated') { const {id} = style; const data = id2data(id); const excluded = new Set(); @@ -412,7 +419,6 @@ const styleMan = (() => { return msg.broadcast({ method, reason, - codeIsUpdated, style: { id, md5Url: style.md5Url, @@ -452,7 +458,7 @@ const styleMan = (() => { return handleSave(style, handlingOptions); } - function handleSave(style, {reason, codeIsUpdated, broadcast = true}) { + function handleSave(style, {reason, broadcast = true}) { const data = id2data(style.id); const method = data ? 'styleUpdated' : 'styleAdded'; if (!data) { @@ -460,7 +466,7 @@ const styleMan = (() => { } else { data.style = style; } - if (broadcast) broadcastStyleUpdated(style, reason, method, codeIsUpdated); + if (broadcast) broadcastStyleUpdated(style, reason, method); return style; } diff --git a/edit.html b/edit.html index 23dbeb25..567d4984 100644 --- a/edit.html +++ b/edit.html @@ -17,6 +17,7 @@ + @@ -61,6 +62,7 @@ +