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',
avatar: 'https://raw.githubusercontent.com/admiraldus/admiraldus/main/module.gif',
},
options: [
{
key: 'hidePageButton',
label: 'show the page link button',
type: 'toggle',
value: true,
},
],
hacks: {
'renderer/preload.js'(store, __exports) {
document.addEventListener('readystatechange', () => {
@ -43,27 +51,43 @@ module.exports = {
const pageClass = 'admiraldus-glb-page-button';
const blockClass = 'admiraldus-glb-block-button';
const spanClass = 'admiraldus-glb-span-hide';
/**
* Create the page link button and append it to the topbar.
*
* @return {create} Returns "create()" if not appended.
*/
const pageButton = !function create() {
const target = x$.sel('.notion-topbar-share-menu');
const attr = [
`class="${pageClass}" role="button" tabindex="0"`,
`class="${spanClass}"`,
];
const html = x$.el(
`<div ${attr[0]}>
${icon}
<span>Global Link</span>
<span ${attr[1]}>Link copied!</span
</div>`);
target.before(html);
if (html === null) return create();
}();
if (store().hidePageButton) {
/**
* Create the page link button and append it to the topbar.
*
* @return {create} Returns "create()" if not appended.
*/
const pageButton = function create() {
const target = x$.sel('.notion-topbar-share-menu');
if (target === null) return;
const attr = [
`class="${pageClass}" role="button" tabindex="0"`,
`class="${spanClass}"`,
];
const html = x$.el(
`<div ${attr[0]}>
${icon}
<span>Global Link</span>
<span ${attr[1]}>Link copied!</span
</div>`);
target.before(html);
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.