mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-06 05:29:02 +00:00
menu: store theme outside profile, reload env on profile change
This commit is contained in:
parent
42cfc69357
commit
9dcbfc213f
@ -25,6 +25,7 @@ export const localPath = fs.localPath;
|
||||
* fetch and parse a json file's contents
|
||||
* @type {function}
|
||||
* @param {string} path - a url or within-the-enhancer filepath
|
||||
* @param {object} [opts] - the second argument of a fetch() request
|
||||
* @returns {object} the json value of the requested file as a js object
|
||||
*/
|
||||
export const getJSON = fs.getJSON;
|
||||
@ -33,6 +34,7 @@ export const getJSON = fs.getJSON;
|
||||
* fetch a text file's contents
|
||||
* @type {function}
|
||||
* @param {string} path - a url or within-the-enhancer filepath
|
||||
* @param {object} [opts] - the second argument of a fetch() request
|
||||
* @returns {string} the text content of the requested file
|
||||
*/
|
||||
export const getText = fs.getText;
|
||||
|
10
extension/env/fs.mjs
vendored
10
extension/env/fs.mjs
vendored
@ -21,18 +21,20 @@ export const localPath = chrome.runtime.getURL;
|
||||
/**
|
||||
* fetch and parse a json file's contents
|
||||
* @param {string} path - a url or within-the-enhancer filepath
|
||||
* @param {object} [opts] - the second argument of a fetch() request
|
||||
* @returns {object} the json value of the requested file as a js object
|
||||
*/
|
||||
export const getJSON = (path) =>
|
||||
fetch(path.startsWith('http') ? path : localPath(path)).then((res) => res.json());
|
||||
export const getJSON = (path, opts = {}) =>
|
||||
fetch(path.startsWith('http') ? path : localPath(path), opts).then((res) => res.json());
|
||||
|
||||
/**
|
||||
* fetch a text file's contents
|
||||
* @param {string} path - a url or within-the-enhancer filepath
|
||||
* @param {object} [opts] - the second argument of a fetch() request
|
||||
* @returns {string} the text content of the requested file
|
||||
*/
|
||||
export const getText = (path) =>
|
||||
fetch(path.startsWith('http') ? path : localPath(path)).then((res) => res.text());
|
||||
export const getText = (path, opts = {}) =>
|
||||
fetch(path.startsWith('http') ? path : localPath(path), opts).then((res) => res.text());
|
||||
|
||||
/**
|
||||
* check if a file exists
|
||||
|
@ -12,7 +12,7 @@ export default async function (api, db) {
|
||||
web.addHotkeyListener(await db.get(['hotkey']), env.focusMenu);
|
||||
|
||||
const updateTheme = () =>
|
||||
db.set(['theme'], document.querySelector('.notion-dark-theme') ? 'dark' : 'light');
|
||||
storage.set(['theme'], document.querySelector('.notion-dark-theme') ? 'dark' : 'light');
|
||||
web.addDocumentObserver((mutation) => {
|
||||
if (mutation.target === document.body && document.hasFocus()) updateTheme();
|
||||
});
|
||||
|
@ -25,7 +25,7 @@ web.addHotkeyListener(await db.get(['hotkey']), env.focusNotion);
|
||||
|
||||
const loadTheme = async () => {
|
||||
document.documentElement.className =
|
||||
(await db.get(['theme'], 'light')) === 'dark' ? 'dark' : '';
|
||||
(await storage.get(['theme'], 'light')) === 'dark' ? 'dark' : '';
|
||||
};
|
||||
document.addEventListener('visibilitychange', loadTheme);
|
||||
loadTheme();
|
||||
@ -110,7 +110,7 @@ $profile.addEventListener('click', async (event) => {
|
||||
const profileUpload = JSON.parse(progress.currentTarget.result);
|
||||
if (!profileUpload) throw Error;
|
||||
await storage.set(['profiles', $select.value], profileUpload);
|
||||
location.reload();
|
||||
env.reload();
|
||||
} catch {
|
||||
web.render(web.empty($error), 'Invalid JSON uploaded.');
|
||||
}
|
||||
@ -151,7 +151,7 @@ $profile.addEventListener('click', async (event) => {
|
||||
);
|
||||
await storage.set(['profiles', $select.value], undefined);
|
||||
}
|
||||
location.reload();
|
||||
env.reload();
|
||||
});
|
||||
$delete.addEventListener('click', async (event) => {
|
||||
await storage.set(['profiles', $select.value], undefined);
|
||||
@ -159,7 +159,7 @@ $profile.addEventListener('click', async (event) => {
|
||||
['currentprofile'],
|
||||
profileNames.find((profile) => profile !== $select.value) || 'default'
|
||||
);
|
||||
location.reload();
|
||||
env.reload();
|
||||
});
|
||||
|
||||
_$profileConfig = web.render(
|
||||
|
Loading…
Reference in New Issue
Block a user