mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-12 00:09:03 +00:00
Clean up and comment new weekly-view client code
This commit is contained in:
parent
d884f146b3
commit
58d3030bf5
@ -4,26 +4,43 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
'use strict';
|
||||||
|
|
||||||
export default async function ({ web }, db) {
|
export default async function ({ web }, db) {
|
||||||
const pageSelector = ".notion-page-content",
|
const pageSelector = '.notion-page-content',
|
||||||
calendarSelector = ".notion-calendar-view",
|
calendarSelector = '.notion-calendar-view',
|
||||||
collectionSelector =
|
collectionSelector =
|
||||||
".notion-page-content > .notion-selectable.notion-collection_view-block",
|
'.notion-page-content > .notion-selectable.notion-collection_view-block',
|
||||||
viewSelector = ":scope>div>div>div>div>div",
|
viewSelector = ':scope>div>div>div>div>div',
|
||||||
todaySelector = '.notion-calendar-view-day[style*="background"]',
|
todaySelector = '.notion-calendar-view-day[style*="background"]',
|
||||||
weekSelector = '[style^="position: relative; display: flex; height: "]',
|
weekSelector = '[style^="position: relative; display: flex; height: "]',
|
||||||
toolbarBtnSelector =
|
toolbarBtnSelector =
|
||||||
".notion-calendar-view > :first-child > :first-child > :first-child > :nth-last-child(2)";
|
'.notion-calendar-view > :first-child > :first-child > :first-child > :nth-last-child(2)';
|
||||||
|
|
||||||
const transformCalendarView = () => {
|
const transformCalendarView = () => {
|
||||||
const $page = document.querySelector(pageSelector);
|
const $page = document.querySelector(pageSelector);
|
||||||
document.querySelectorAll(collectionSelector).forEach(async ($view) => {
|
document.querySelectorAll(collectionSelector).forEach(async ($view) => { // Get view controls children nodes, convert to array, filter out non-text
|
||||||
|
const viewNodes = []
|
||||||
|
.slice.call($view.querySelector(viewSelector).children)
|
||||||
|
.filter(node => node.tagName.toLowerCase().match(/(div|span)/g));
|
||||||
|
let currentText;
|
||||||
|
|
||||||
const currentText = [].slice.call($view.querySelector(viewSelector).children).filter((e) => e.children[0].style.borderBottomWidth.toString() === "2px" )[0].innerText.toLowerCase();
|
// Find current view by analyzing children (which changes on viewport)
|
||||||
|
if (viewNodes.length === 1)
|
||||||
if (currentText !== "weekly")
|
{
|
||||||
|
// Mobile: Simple dropdown button (like legacy), text is current view
|
||||||
|
currentText = viewNodes[0].innerText.toLowerCase();
|
||||||
|
} else {
|
||||||
|
// Wide/Desktop: Tabs listed, current view indicated by border style
|
||||||
|
currentText = viewNodes
|
||||||
|
// Find selected view by border style (possibly fragile)
|
||||||
|
.filter((e) => e.children[0].style.borderBottomWidth.toString() === '2px' )[0]
|
||||||
|
// Format
|
||||||
|
.innerText.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if view is weekly
|
||||||
|
if (currentText !== 'weekly')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const $calendar =
|
const $calendar =
|
||||||
@ -34,10 +51,8 @@ export default async function ({ web }, db) {
|
|||||||
await new Promise((res, rej) => requestAnimationFrame(res));
|
await new Promise((res, rej) => requestAnimationFrame(res));
|
||||||
if ($page) {
|
if ($page) {
|
||||||
for (const $week of $calendar.querySelectorAll(weekSelector)) {
|
for (const $week of $calendar.querySelectorAll(weekSelector)) {
|
||||||
if (!$week.querySelector(todaySelector)) {
|
if (!$week.querySelector(todaySelector))
|
||||||
$week.style.height = "0";
|
$week.style.visibility = 'hidden';
|
||||||
$week.style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const $weekContainer =
|
const $weekContainer =
|
||||||
@ -47,8 +62,8 @@ export default async function ({ web }, db) {
|
|||||||
$weekContainer.style.maxHeight = $week.style.height;
|
$weekContainer.style.maxHeight = $week.style.height;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
$week.style.height = "0";
|
$week.style.height = '0';
|
||||||
$week.style.opacity = "0";
|
$week.style.opacity = '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user