Skip to content

Commit

Permalink
property layout extension ✔
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonwocky committed Aug 18, 2020
1 parent f95b5ea commit 4e09b4f
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 66 deletions.
4 changes: 2 additions & 2 deletions mods/core/css/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
--theme_dark--overlay: rgba(15, 15, 15, 0.6);
--theme_dark--dragarea: #272d2f;
--theme_dark--preview-width: 977px;
--theme_dark--preview-padding: 8em;
--theme_dark--preview-padding: 8rem;
--theme_dark--preview_banner-height: 20vh;
--theme_dark--page_banner-height: 30vh;

Expand Down Expand Up @@ -128,7 +128,7 @@
--theme_light--overlay: rgba(15, 15, 15, 0.6);
--theme_light--dragarea: rgba(55, 53, 47, 0.04);
--theme_light--preview-width: 977px;
--theme_light--preview-padding: 8em;
--theme_light--preview-padding: 8rem;
--theme_light--preview_banner-height: 20vh;
--theme_light--page_banner-height: 30vh;

Expand Down
2 changes: 1 addition & 1 deletion mods/dark+/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/* --theme_dark--overlay: rgba(15, 15, 15, 0.6); */
--theme_dark--dragarea: #000;
/* --theme_dark--preview-width: 977px;
--theme_dark--preview-padding: 8em;
--theme_dark--preview-padding: 8rem;
--theme_dark--preview_banner-height: 20vh;
--theme_dark--page_banner-height: 30vh; */

Expand Down
2 changes: 1 addition & 1 deletion mods/emoji-sets/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = {
if (!queue.length) requestAnimationFrame(process);
queue.push(...list);
});
observer.observe(document, {
observer.observe(document.body, {
childList: true,
subtree: true,
characterData: true,
Expand Down
2 changes: 1 addition & 1 deletion mods/gameish/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/* --theme_dark--overlay: rgba(15, 15, 15, 0.6); */
--theme_dark--dragarea: #19181f;
/* --theme_dark--preview-width: 977px;
--theme_dark--preview-padding: 8em;
--theme_dark--preview-padding: 8rem;
--theme_dark--preview_banner-height: 20vh;
--theme_dark--page_banner-height: 30vh; */

Expand Down
2 changes: 1 addition & 1 deletion mods/neutral/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
--theme_dark--overlay: rgba(15, 15, 15, 0.6);
--theme_dark--dragarea: #111111;
/* --theme_dark--preview-width: 977px;
--theme_dark--preview-padding: 8em;
--theme_dark--preview-padding: 8rem;
--theme_dark--preview_banner-height: 20vh;
--theme_dark--page_banner-height: 30vh; */

Expand Down
2 changes: 1 addition & 1 deletion mods/pastel-dark/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
--theme_dark--overlay: rgba(15, 15, 15, 0.6);
--theme_dark--dragarea: #0d0d0d;
/* --theme_dark--preview-width: 977px;
--theme_dark--preview-padding: 8em;
--theme_dark--preview-padding: 8rem;
--theme_dark--preview_banner-height: 20vh;
--theme_dark--page_banner-height: 30vh; */

Expand Down
89 changes: 32 additions & 57 deletions mods/property-layout/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,41 @@ module.exports = {
'renderer/preload.js'(store, __exports) {
document.addEventListener('readystatechange', (event) => {
if (document.readyState !== 'complete') return false;

var isVisible = false;

function setPropertiesListVisibility(propertiesList, visible) {
if (visible) {
// Show properties list section
propertiesList.style.height = null;
propertiesList.style.display = null;
isVisible = true;
} else {
// Hide properties list section
propertiesList.style.height = 0;
propertiesList.style.display = 'none';
isVisible = false;
}
}

// Called every time something new loads inside Notion window
// e.g. you navigate to a different Notion page
var onPageChange = function () {
console.log('Notion Layout Improver: Something changed');

// Find the block with properties list
var propertiesLists = document.querySelectorAll(
".notion-scroller.vertical > div:nth-child(2)[style='width: 100%; font-size: 14px;']"
let queue = [];
const observer = new MutationObserver((list, observer) => {
if (!queue.length) requestAnimationFrame(() => process(queue));
queue.push(...list);
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
function process(list) {
queue = [];
let properties = document.querySelector(
'.notion-scroller.vertical > div:nth-child(2)[style="width: 100%; font-size: 14px;"]'
);

// For each found properties list
propertiesLists.forEach(function (propertiesList) {
console.log('Found properties list');

// Set up the toggle button
let toggleButton = document.createElement('button');
toggleButton.setAttribute('class', 'propertiesToggleBar');
toggleButton.innerHTML = '-';
toggleButton.onclick = function () {
setPropertiesListVisibility(propertiesList, !isVisible);
};

// If not already processed this properties list,
// add the toggle button and hide the list
if (!(propertiesList.id === 'already_processed')) {
console.log(
'Notion Layout Improver: Processing new properties list'
if (properties) {
if (!properties.classList.contains('propertylayout-enhanced')) {
properties.classList.add(
'propertylayout-enhanced',
'propertylayout-hidden'
);
var parentBlockForButton =
propertiesList.parentElement.firstChild.firstChild;
parentBlockForButton.appendChild(toggleButton);
setPropertiesListVisibility(propertiesList, false);
propertiesList.id = 'already_processed';
const toggle = document.createElement('button');
toggle.classList.add('propertylayout-toggle');
toggle.innerText = '→ show properties';
toggle.addEventListener('click', (event) => {
properties.classList.toggle('propertylayout-hidden');
toggle.innerText = `→ ${
properties.classList.contains('propertylayout-hidden')
? 'show'
: 'hide'
} properties`;
});
properties.previousElementSibling.append(toggle);
}
});
};

// This calls onPageChange function each time Notion window changes
// e.g. you navigate to a new Notion page
const targetNode = document.body;
const config = { attributes: false, childList: true, subtree: true };
const observer = new MutationObserver(onPageChange);
observer.observe(targetNode, config);
}
}
});
},
},
Expand Down
26 changes: 26 additions & 0 deletions mods/property-layout/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* property layout
* (c) 2020 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
* (c) 2020 alexander-kazakov
* under the MIT license
*/

.propertylayout-hidden {
display: none;
}

.propertylayout-toggle {
width: calc(100% - (2 * var(--theme--preview-padding)));
text-align: left;
font-size: 0.85em;
margin-bottom: 1em;
padding: 0.25em;
background: transparent;
color: var(--theme--text_ui);
border: none;
border-radius: 2px;
transition: background 200ms;
}
.propertylayout-toggle:hover {
background: var(--theme--interactive_hover);
}
4 changes: 2 additions & 2 deletions mods/right-to-left/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ module.exports = {
if (document.readyState !== 'complete') return false;
let queue = [];
const observer = new MutationObserver((list, observer) => {
if (!queue.length) requestAnimationFrame(() => process(list));
if (!queue.length) requestAnimationFrame(() => process(queue));
queue.push(...list);
});
observer.observe(document, {
observer.observe(document.body, {
childList: true,
subtree: true,
characterData: true,
Expand Down

0 comments on commit 4e09b4f

Please sign in to comment.