mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-10 23:39:03 +00:00
Compare commits
2 Commits
47cfece013
...
6e80cf77b5
Author | SHA1 | Date | |
---|---|---|---|
6e80cf77b5 | |||
bbc8c7a1e0 |
@ -6,15 +6,15 @@
|
|||||||
|
|
||||||
let __$wrapper;
|
let __$wrapper;
|
||||||
const setupWrapper = () => {
|
const setupWrapper = () => {
|
||||||
const notionHelp = ".notion-help-button",
|
const notionAi = ".notion-ai-button",
|
||||||
{ html, addMutationListener } = globalThis.__enhancerApi,
|
{ html, addMutationListener } = globalThis.__enhancerApi,
|
||||||
{ removeMutationListener } = globalThis.__enhancerApi;
|
{ removeMutationListener } = globalThis.__enhancerApi;
|
||||||
return (__$wrapper ??= new Promise((res) => {
|
return (__$wrapper ??= new Promise((res) => {
|
||||||
const addToDom = () => {
|
const addToDom = () => {
|
||||||
const $help = document.querySelector(notionHelp);
|
const $notionAi = document.querySelector(notionAi);
|
||||||
if (!$help) return;
|
if (!$notionAi) return;
|
||||||
const gap = 12,
|
const gap = 12,
|
||||||
computedStyles = getComputedStyle($help),
|
computedStyles = getComputedStyle($notionAi),
|
||||||
visible = computedStyles.getPropertyValue("display") !== "none",
|
visible = computedStyles.getPropertyValue("display") !== "none",
|
||||||
width = computedStyles.getPropertyValue("width"),
|
width = computedStyles.getPropertyValue("width"),
|
||||||
right = computedStyles.getPropertyValue("right"),
|
right = computedStyles.getPropertyValue("right"),
|
||||||
@ -25,10 +25,10 @@ const setupWrapper = () => {
|
|||||||
style="right:${offset}px"
|
style="right:${offset}px"
|
||||||
></div>`;
|
></div>`;
|
||||||
removeMutationListener(addToDom);
|
removeMutationListener(addToDom);
|
||||||
$help.after($wrapper);
|
$notionAi.after($wrapper);
|
||||||
res($wrapper);
|
res($wrapper);
|
||||||
};
|
};
|
||||||
addMutationListener(notionHelp, addToDom);
|
addMutationListener(notionAi, addToDom);
|
||||||
addToDom();
|
addToDom();
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
@ -206,9 +206,8 @@ function Panel({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const animationState = { ...closedWidth },
|
const animationState = { ...closedWidth },
|
||||||
easing = "cubic-bezier(0.4, 0, 0.2, 1)",
|
|
||||||
animate = ($target, keyframes) => {
|
animate = ($target, keyframes) => {
|
||||||
const opts = { fill: "forwards", duration: transitionDuration, easing };
|
const opts = { fill: "forwards", duration: transitionDuration, easing: "ease" };
|
||||||
$target.animate(keyframes, opts);
|
$target.animate(keyframes, opts);
|
||||||
},
|
},
|
||||||
animatePanel = (to) => {
|
animatePanel = (to) => {
|
||||||
@ -303,10 +302,10 @@ function Panel({
|
|||||||
// moves help button out of the way of open panel.
|
// moves help button out of the way of open panel.
|
||||||
// normally would place outside of an island, but in
|
// normally would place outside of an island, but in
|
||||||
// this case is necessary for syncing up animations
|
// this case is necessary for syncing up animations
|
||||||
const notionHelp = ".notion-help-button",
|
const notionAi = ".notion-ai-button",
|
||||||
floatingButtons = ".notion-enhancer--floating-buttons",
|
floatingButtons = ".notion-enhancer--floating-buttons",
|
||||||
repositionCorner = async (offset) => {
|
repositionCorner = async (offset) => {
|
||||||
const $help = document.querySelector(notionHelp),
|
const $help = document.querySelector(notionAi),
|
||||||
$floating = document.querySelector(floatingButtons);
|
$floating = document.querySelector(floatingButtons);
|
||||||
offset ??= await getWidth();
|
offset ??= await getWidth();
|
||||||
if (isNaN(offset)) offset = minWidth;
|
if (isNaN(offset)) offset = minWidth;
|
||||||
@ -329,7 +328,7 @@ function Panel({
|
|||||||
}
|
}
|
||||||
if ($help || $floating) removeMutationListener(repositionCorner);
|
if ($help || $floating) removeMutationListener(repositionCorner);
|
||||||
};
|
};
|
||||||
const corner = `${notionHelp}, ${floatingButtons}`;
|
const corner = `${notionAi}, ${floatingButtons}`;
|
||||||
addMutationListener(corner, repositionCorner, { subtree: false });
|
addMutationListener(corner, repositionCorner, { subtree: false });
|
||||||
|
|
||||||
$panel.pin = () => {
|
$panel.pin = () => {
|
||||||
|
@ -5,8 +5,9 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* hide topbar */
|
/* hide topbar and ai */
|
||||||
.notion-sidebar-container[aria-hidden] ~ div .notion-topbar {
|
.notion-sidebar-container[aria-hidden] ~ div .notion-topbar,
|
||||||
|
.notion-sidebar-container[aria-hidden] ~ div .notion-ai-button {
|
||||||
opacity: 0 !important;
|
opacity: 0 !important;
|
||||||
transition: opacity 200ms ease-in-out !important;
|
transition: opacity 200ms ease-in-out !important;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ export default async (api, db) => {
|
|||||||
scrollBehavior = (await db.get("smoothScrolling")) ? "smooth" : "auto",
|
scrollBehavior = (await db.get("smoothScrolling")) ? "smooth" : "auto",
|
||||||
scroller = ".notion-frame .notion-scroller";
|
scroller = ".notion-frame .notion-scroller";
|
||||||
|
|
||||||
let $scroller, $todayButton;
|
let $scroller, $today;
|
||||||
const scrollTo = (top, behavior) => $scroller?.scroll({ top, behavior }),
|
const scrollTo = (top, behavior) => $scroller?.scroll({ top, behavior }),
|
||||||
$scrollToBottom = html`<${FloatingButton}
|
$scrollToBottom = html`<${FloatingButton}
|
||||||
onclick="${() => scrollTo($scroller.scrollHeight, scrollBehavior)}"
|
onclick="${() => scrollTo($scroller.scrollHeight, scrollBehavior)}"
|
||||||
@ -50,27 +50,32 @@ export default async (api, db) => {
|
|||||||
} else removeFloatingButton($scrollToTop);
|
} else removeFloatingButton($scrollToTop);
|
||||||
},
|
},
|
||||||
onTodayLoaded = () => {
|
onTodayLoaded = () => {
|
||||||
const $bubble = document.querySelector(todayBubble);
|
|
||||||
if (!$bubble) return;
|
|
||||||
// calendar will jump anyway when pinning the current month,
|
// calendar will jump anyway when pinning the current month,
|
||||||
// so ignore smooth scroll setting and jump direct to week
|
// so ignore smooth scroll setting and jump direct to week
|
||||||
|
const $bubble = document.querySelector(todayBubble);
|
||||||
|
if (!$bubble) return;
|
||||||
scrollTo($bubble.offsetParent.offsetParent.offsetTop + 57, "auto");
|
scrollTo($bubble.offsetParent.offsetParent.offsetTop + 57, "auto");
|
||||||
removeMutationListener(onTodayLoaded);
|
removeMutationListener(onTodayLoaded);
|
||||||
},
|
},
|
||||||
onTodayClicked = () => {
|
onTodayClicked = () => {
|
||||||
removeMutationListener(onTodayLoaded);
|
// if calendar does not refresh: jump direct to current week
|
||||||
addMutationListener(todayBubble, onTodayLoaded);
|
// if calendar does refresh: wait, then jump to current week
|
||||||
|
requestIdleCallback(() => {
|
||||||
|
onTodayLoaded();
|
||||||
|
addMutationListener(todayBubble, onTodayLoaded);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
setup = () => {
|
setup = () => {
|
||||||
if (document.contains($scroller)) return;
|
if (!document.contains($scroller)) {
|
||||||
$scroller = document.querySelector(scroller);
|
$scroller = document.querySelector(scroller);
|
||||||
$scroller?.removeEventListener("scroll", onPageScrolled);
|
$scroller?.removeEventListener("scroll", onPageScrolled);
|
||||||
$scroller?.addEventListener("scroll", onPageScrolled);
|
$scroller?.addEventListener("scroll", onPageScrolled);
|
||||||
onPageScrolled();
|
onPageScrolled();
|
||||||
if (jumpToWeek) {
|
}
|
||||||
$todayButton = document.querySelector(todayButton);
|
if (jumpToWeek && !document.contains($today)) {
|
||||||
$todayButton?.removeEventListener("click", onTodayClicked);
|
$today = document.querySelector(todayButton);
|
||||||
$todayButton?.addEventListener("click", onTodayClicked);
|
$today?.removeEventListener("click", onTodayClicked);
|
||||||
|
$today?.addEventListener("click", onTodayClicked);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
addMutationListener(scroller, setup, { subtree: false });
|
addMutationListener(scroller, setup, { subtree: false });
|
||||||
|
Loading…
Reference in New Issue
Block a user