global linking blocks: option: show the page link button

This commit is contained in:
Emir 2020-12-13 20:19:12 +03:00
parent 154cff8b1a
commit 657bec2fa4

View File

@ -19,6 +19,14 @@ module.exports = {
link: 'https://github.com/admiraldus', link: 'https://github.com/admiraldus',
avatar: 'https://raw.githubusercontent.com/admiraldus/admiraldus/main/module.gif', avatar: 'https://raw.githubusercontent.com/admiraldus/admiraldus/main/module.gif',
}, },
options: [
{
key: 'hidePageButton',
label: 'show the page link button',
type: 'toggle',
value: true,
},
],
hacks: { hacks: {
'renderer/preload.js'(store, __exports) { 'renderer/preload.js'(store, __exports) {
document.addEventListener('readystatechange', () => { document.addEventListener('readystatechange', () => {
@ -43,13 +51,17 @@ module.exports = {
const pageClass = 'admiraldus-glb-page-button'; const pageClass = 'admiraldus-glb-page-button';
const blockClass = 'admiraldus-glb-block-button'; const blockClass = 'admiraldus-glb-block-button';
const spanClass = 'admiraldus-glb-span-hide'; const spanClass = 'admiraldus-glb-span-hide';
if (store().hidePageButton) {
/** /**
* Create the page link button and append it to the topbar. * Create the page link button and append it to the topbar.
* *
* @return {create} Returns "create()" if not appended. * @return {create} Returns "create()" if not appended.
*/ */
const pageButton = !function create() { const pageButton = function create() {
const target = x$.sel('.notion-topbar-share-menu'); const target = x$.sel('.notion-topbar-share-menu');
if (target === null) return;
const attr = [ const attr = [
`class="${pageClass}" role="button" tabindex="0"`, `class="${pageClass}" role="button" tabindex="0"`,
`class="${spanClass}"`, `class="${spanClass}"`,
@ -63,7 +75,19 @@ module.exports = {
target.before(html); target.before(html);
if (html === null) return create(); if (html === null) return create();
}(); };
pageButton();
/**
* Observer for the topbar.
*/
x$.obs(() => {
if (x$.sel(`.${pageClass}`) !== null) return;
pageButton();
}, x$.sel('.notion-topbar'), {
subtree: true, childList: true,
});
}
/** /**
* Create the block link button and append it to the block menu. * Create the block link button and append it to the block menu.