diff --git a/repo/bypass-preview@cb6fd684-f113-4a7a-9423-8f0f0cff069f/client.mjs b/repo/bypass-preview@cb6fd684-f113-4a7a-9423-8f0f0cff069f/client.mjs index b510184..8c14502 100644 --- a/repo/bypass-preview@cb6fd684-f113-4a7a-9423-8f0f0cff069f/client.mjs +++ b/repo/bypass-preview@cb6fd684-f113-4a7a-9423-8f0f0cff069f/client.mjs @@ -7,27 +7,32 @@ 'use strict'; export default async function (api, db) { - const { web, components } = api; + const { web, notion } = api; await web.whenReady(); - let _lastPage = {}; + let _openPage = {}; function getCurrentPage() { - if (web.queryParams().get('p')) return { type: 'preview', id: web.queryParams().get('p') }; - return { type: 'page', id: location.pathname.split(/(-|\/)/g).reverse()[0] }; + return { + type: web.queryParams().get('p') ? 'preview' : 'page', + id: notion.getPageID(), + }; } - web.addDocumentObserver((event) => { - const currentPage = getCurrentPage(); - if (currentPage.id !== _lastPage.id || currentPage.type !== _lastPage.type) { - const openAsPage = document.querySelector( - '.notion-peek-renderer [style*="height: 45px;"] a' - ); - if (openAsPage) { - if (currentPage.id === _lastPage.id && currentPage.type === 'preview') { - history.back(); - } else openAsPage.click(); + web.addDocumentObserver( + (event) => { + const currentPage = getCurrentPage(); + if (currentPage.id !== _openPage.id || currentPage.type !== _openPage.type) { + const openAsPage = document.querySelector( + '.notion-peek-renderer [style*="height: 45px;"] a' + ); + if (openAsPage) { + if (currentPage.id === _openPage.id && currentPage.type === 'preview') { + history.back(); + } else openAsPage.click(); + } + _openPage = getCurrentPage(); } - _lastPage = getCurrentPage(); - } - }); + }, + ['.notion-peek-renderer'] + ); } diff --git a/repo/calendar-scroll@b1c7db33-dfee-489a-a76c-0dd66f7ed29a/client.css b/repo/calendar-scroll@b1c7db33-dfee-489a-a76c-0dd66f7ed29a/client.css index 310c6f9..a06fe12 100644 --- a/repo/calendar-scroll@b1c7db33-dfee-489a-a76c-0dd66f7ed29a/client.css +++ b/repo/calendar-scroll@b1c7db33-dfee-489a-a76c-0dd66f7ed29a/client.css @@ -5,9 +5,9 @@ */ #calendar-scroll-to-week { - background: var(--theme--button_hover); + background: var(--theme--ui_interactive-hover); border: 1px solid transparent; - font-size: var(--theme--font_label-size); + font-size: 14px; color: var(--theme--text); height: 24px; border-radius: 3px; @@ -15,7 +15,11 @@ padding: 0 0.5em; margin-right: 5px; } +#calendar-scroll-to-week:focus, #calendar-scroll-to-week:hover { background: transparent; - border: 1px solid var(--theme--button_hover); + border: 1px solid var(--theme--ui_interactive-hover); +} +#calendar-scroll-to-week:active { + background: var(--theme--ui_interactive-active); } diff --git a/repo/calendar-scroll@b1c7db33-dfee-489a-a76c-0dd66f7ed29a/client.mjs b/repo/calendar-scroll@b1c7db33-dfee-489a-a76c-0dd66f7ed29a/client.mjs index 96c893a..6a4e1b0 100644 --- a/repo/calendar-scroll@b1c7db33-dfee-489a-a76c-0dd66f7ed29a/client.mjs +++ b/repo/calendar-scroll@b1c7db33-dfee-489a-a76c-0dd66f7ed29a/client.mjs @@ -6,19 +6,17 @@ 'use strict'; -import { web } from '../../api/_.mjs'; +export default async function (api, db) { + const { web } = api; -const $button = web.createElement( - web.html`` -); -$button.addEventListener('click', async (event) => { - let $day = document.querySelector('.notion-calendar-view-day[style*="background:"]'); - while (!$day) { - const $toolbar = document.querySelector( - '.notion-calendar-view > :first-child > :first-child > :first-child' - ), - year = +$toolbar.children[0].innerText.split(' ')[1], - month = { + const toolbarSelector = '.notion-calendar-view > :first-child > :first-child > :first-child', + $scrollButton = web.html``; + $scrollButton.addEventListener('click', async (event) => { + const $toolbar = document.querySelector(toolbarSelector), + now = new Date(), + thisYear = now.getFullYear(), + thisMonth = now.getMonth(), + allMonths = { 'January': 0, 'February': 1, 'March': 2, @@ -31,34 +29,37 @@ $button.addEventListener('click', async (event) => { 'October': 9, 'November': 10, 'December': 11, - }[$toolbar.children[0].innerText.split(' ')[0]], - now = new Date(); - switch (true) { - case now.getFullYear() < year: - case now.getFullYear() === year && now.getMonth() < month: - $toolbar.children[3].click(); - break; - case now.getFullYear() > year: - case now.getFullYear() === year && now.getMonth() > month: - $toolbar.children[5].click(); - break; - default: - await new Promise((res, rej) => requestAnimationFrame(res)); - $day = document.querySelector('.notion-calendar-view-day[style*="background:"]'); + }; + let $today; + while (!$today) { + const visibleYear = +$toolbar.children[0].innerText.split(' ')[1], + visibleMonth = allMonths[$toolbar.children[0].innerText.split(' ')[0]]; + switch (true) { + case thisYear < visibleYear: + case thisYear === visibleYear && thisMonth < visibleMonth: + $toolbar.children[3].click(); + break; + case thisYear > visibleYear: + case thisYear === visibleYear && thisMonth > visibleMonth: + $toolbar.children[5].click(); + break; + default: + $today = document.querySelector('.notion-calendar-view-day[style*="background:"]'); + } + await new Promise((res, rej) => requestAnimationFrame(res)); } - await new Promise((res, rej) => requestAnimationFrame(res)); - } - const $scroller = document.querySelector('.notion-frame .notion-scroller'); - $scroller.scroll({ - top: $day.offsetParent.offsetParent.offsetTop + 70, - behavior: 'auto', + const $scroller = document.querySelector('.notion-frame .notion-scroller'); + $scroller.scroll({ + top: $today.offsetParent.offsetParent.offsetTop + 70, + behavior: 'auto', + }); }); -}); -web.addDocumentObserver((event) => { - if (document.contains($button)) return; - const toolbar = document.querySelector( - '.notion-calendar-view > :first-child > :first-child > :first-child' - ); - if (toolbar) toolbar.insertBefore($button, toolbar.children[2]); -}); + const insertButton = () => { + if (document.contains($scrollButton)) return; + const toolbar = document.querySelector(toolbarSelector); + if (toolbar) toolbar.insertBefore($scrollButton, toolbar.children[2]); + }; + web.addDocumentObserver(insertButton, [toolbarSelector]); + insertButton(); +}