mirror of
				https://github.com/notion-enhancer/notion-enhancer.git
				synced 2025-11-04 16:18:08 +11: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
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
"use strict";
 | 
			
		||||
'use strict';
 | 
			
		||||
 | 
			
		||||
export default async function ({ web }, db) {
 | 
			
		||||
  const pageSelector = ".notion-page-content",
 | 
			
		||||
    calendarSelector = ".notion-calendar-view",
 | 
			
		||||
  const pageSelector = '.notion-page-content',
 | 
			
		||||
    calendarSelector = '.notion-calendar-view',
 | 
			
		||||
    collectionSelector =
 | 
			
		||||
            ".notion-page-content > .notion-selectable.notion-collection_view-block",
 | 
			
		||||
    viewSelector = ":scope>div>div>div>div>div",
 | 
			
		||||
            '.notion-page-content > .notion-selectable.notion-collection_view-block',
 | 
			
		||||
    viewSelector = ':scope>div>div>div>div>div',
 | 
			
		||||
    todaySelector = '.notion-calendar-view-day[style*="background"]',
 | 
			
		||||
    weekSelector = '[style^="position: relative; display: flex; height: "]',
 | 
			
		||||
    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 $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();
 | 
			
		||||
 | 
			
		||||
      if (currentText !== "weekly")
 | 
			
		||||
      // Find current view by analyzing children (which changes on viewport) 
 | 
			
		||||
      if (viewNodes.length === 1)
 | 
			
		||||
      {
 | 
			
		||||
        // 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;
 | 
			
		||||
 | 
			
		||||
      const $calendar =
 | 
			
		||||
@ -34,10 +51,8 @@ export default async function ({ web }, db) {
 | 
			
		||||
      await new Promise((res, rej) => requestAnimationFrame(res));
 | 
			
		||||
      if ($page) {
 | 
			
		||||
        for (const $week of $calendar.querySelectorAll(weekSelector)) {
 | 
			
		||||
          if (!$week.querySelector(todaySelector)) {
 | 
			
		||||
            $week.style.height = "0";
 | 
			
		||||
            $week.style.display = "none";
 | 
			
		||||
          }
 | 
			
		||||
          if (!$week.querySelector(todaySelector)) 
 | 
			
		||||
            $week.style.visibility = 'hidden';
 | 
			
		||||
        }
 | 
			
		||||
      } else {
 | 
			
		||||
        const $weekContainer =
 | 
			
		||||
@ -47,8 +62,8 @@ export default async function ({ web }, db) {
 | 
			
		||||
            $weekContainer.style.maxHeight = $week.style.height;
 | 
			
		||||
            break;
 | 
			
		||||
          } else {
 | 
			
		||||
            $week.style.height = "0";
 | 
			
		||||
            $week.style.opacity = "0";
 | 
			
		||||
            $week.style.height = '0';
 | 
			
		||||
            $week.style.opacity = '0';
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user