Added options to mod.js

Added the option to individually select which buttons (share, updates, favorite) to replace with icons
This commit is contained in:
Ryo Hilmawan 2020-11-06 03:08:47 +07:00 committed by GitHub
parent a03a01af26
commit 4314a3a70a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,12 +16,36 @@ module.exports = {
tags: ['extension'],
name: 'topbar icons',
desc:
'replaces the topbar buttons (share, updates, favorite) with icons.',
'replaces the topbar buttons with icons.',
options: [
{
key: 'share',
label: 'share',
type: 'toggle',
value: true,
},
{
key: 'updates',
label: 'updates',
type: 'toggle',
value: true,
},
{
key: 'favorite',
label: 'favorite',
type: 'toggle',
value: true,
},
],
version: '1.0.0',
author: 'CloudHill',
hacks: {
'renderer/preload.js'(store, __exports) {
const icons = {
selected: [
...(store().updates ? ['updates'] : []),
...(store().favorite ? ['favorite'] : []),
],
share: fs.readFile(path.resolve(`${__dirname}/icons/share.svg`)),
updates: {
on: fs.readFile(path.resolve(`${__dirname}/icons/updates_on.svg`)),
@ -73,12 +97,16 @@ module.exports = {
async function setIcons(buttons) {
const buttonList = buttons.children;
if (store().share) {
buttonList[0].classList.add('notion-topbar-icon');
buttonList[0].innerHTML = await icons.share;
}
const elements = {
updates: buttonList[1],
favorite: buttonList[2],
};
for (let btn of ['updates', 'favorite']) {
for (let btn of icons.selected) {
elements[btn].classList.add('notion-topbar-icon')
elements[btn].prepend(
createElement(
`<div>${(await icons[btn].off).toString()}