mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-10 15:39:01 +00:00
Fix code consistentcy in weekly-view client
This commit is contained in:
parent
58d3030bf5
commit
b921a2f86a
@ -9,21 +9,22 @@
|
|||||||
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 =
|
viewSelector =
|
||||||
'.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',
|
viewControlSelector = ':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) => { // Get view controls children nodes, convert to array, filter out non-text
|
document.querySelectorAll(viewSelector).forEach(async ($view) => {
|
||||||
|
let currentText;
|
||||||
|
// Get view controls children nodes, convert to array, filter out non-text
|
||||||
const viewNodes = []
|
const viewNodes = []
|
||||||
.slice.call($view.querySelector(viewSelector).children)
|
.slice.call($view.querySelector(viewControlSelector).children)
|
||||||
.filter(node => node.tagName.toLowerCase().match(/(div|span)/g));
|
.filter(node => node.tagName.toLowerCase().match(/(div|span)/g));
|
||||||
let currentText;
|
|
||||||
|
|
||||||
// Find current view by analyzing children (which changes on viewport)
|
// Find current view by analyzing children (which changes on viewport)
|
||||||
if (viewNodes.length === 1)
|
if (viewNodes.length === 1)
|
||||||
@ -34,36 +35,33 @@ export default async function ({ web }, db) {
|
|||||||
// Wide/Desktop: Tabs listed, current view indicated by border style
|
// Wide/Desktop: Tabs listed, current view indicated by border style
|
||||||
currentText = viewNodes
|
currentText = viewNodes
|
||||||
// Find selected view by border style (possibly fragile)
|
// Find selected view by border style (possibly fragile)
|
||||||
.filter((e) => e.children[0].style.borderBottomWidth.toString() === '2px' )[0]
|
.filter((e) => e.children[0].style.borderBottomWidth.toString() === '2px')[0]
|
||||||
// Format
|
|
||||||
.innerText.toLowerCase();
|
.innerText.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if view is weekly
|
if (currentText !== 'weekly') return;
|
||||||
if (currentText !== 'weekly')
|
|
||||||
return;
|
|
||||||
|
|
||||||
const $calendar =
|
const $calendar = $view.parentElement.parentElement.parentElement.parentElement;
|
||||||
$view.parentElement.parentElement.parentElement.parentElement;
|
|
||||||
if (!$calendar.querySelector(todaySelector)) {
|
if (!$calendar.querySelector(todaySelector)) {
|
||||||
$calendar.querySelector(toolbarBtnSelector).click();
|
$calendar.querySelector(toolbarBtnSelector).click();
|
||||||
}
|
}
|
||||||
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.visibility = 'hidden';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const $weekContainer =
|
const $weekContainer = $calendar.querySelector(weekSelector).parentElement;
|
||||||
$calendar.querySelector(weekSelector).parentElement;
|
|
||||||
for (const $week of $calendar.querySelectorAll(weekSelector)) {
|
for (const $week of $calendar.querySelectorAll(weekSelector)) {
|
||||||
if ($week.querySelector(todaySelector)) {
|
if ($week.querySelector(todaySelector)) {
|
||||||
$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.visibility = 'hidden';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user