diff --git a/src/extensions/bypass-preview/client.mjs b/src/extensions/bypass-preview/client.mjs deleted file mode 100644 index c957b79..0000000 --- a/src/extensions/bypass-preview/client.mjs +++ /dev/null @@ -1,35 +0,0 @@ -/** - * notion-enhancer: bypass preview - * (c) 2021 dragonwocky (https://dragonwocky.me/) - * (https://notion-enhancer.github.io/) under the MIT license - */ - -export default function ({ web, notion }, db) { - let _openPage = {}; - - const getCurrentPage = () => ({ - type: web.queryParams().get("p") ? "preview" : "page", - id: notion.getPageID(), - }); - - const interceptPreview = () => { - const currentPage = getCurrentPage(); - if ( - currentPage.id !== _openPage.id || - currentPage.type !== _openPage.type - ) { - const $openAsPage = document.querySelector( - ".notion-peek-renderer a > div" - ); - - if ($openAsPage) { - if (currentPage.id === _openPage.id && currentPage.type === "preview") { - history.back(); - } else $openAsPage.click(); - } - - _openPage = getCurrentPage(); - } - }; - web.addDocumentObserver(interceptPreview, [".notion-peek-renderer"]); -} diff --git a/src/extensions/bypass-preview/mod.json b/src/extensions/bypass-preview/mod.json deleted file mode 100644 index bda76dc..0000000 --- a/src/extensions/bypass-preview/mod.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "bypass preview", - "id": "cb6fd684-f113-4a7a-9423-8f0f0cff069f", - "version": "0.2.0", - "description": "go straight to the normal full view when opening a page.", - "tags": ["extension", "automation"], - "authors": [ - { - "name": "dragonwocky", - "email": "thedragonring.bod@gmail.com", - "homepage": "https://dragonwocky.me/", - "avatar": "https://dragonwocky.me/avatar.jpg" - } - ], - "js": { - "client": ["client.mjs"] - }, - "css": { - "client": ["client.css"] - }, - "options": [] -} diff --git a/src/extensions/bypass-preview/client.css b/src/extensions/no-peeking/client.css similarity index 84% rename from src/extensions/bypass-preview/client.css rename to src/extensions/no-peeking/client.css index cae2982..fa78408 100644 --- a/src/extensions/bypass-preview/client.css +++ b/src/extensions/no-peeking/client.css @@ -1,5 +1,5 @@ /** - * notion-enhancer: bypass preview + * notion-enhancer: no-peeking * (c) 2021 dragonwocky (https://dragonwocky.me/) * (https://notion-enhancer.github.io/) under the MIT license */ diff --git a/src/extensions/no-peeking/client.mjs b/src/extensions/no-peeking/client.mjs new file mode 100644 index 0000000..0c94c44 --- /dev/null +++ b/src/extensions/no-peeking/client.mjs @@ -0,0 +1,26 @@ +/** + * notion-enhancer: no peeking + * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (https://notion-enhancer.github.io/) under the MIT license + */ + +export default async (api) => { + const { addMutationListener } = api, + peekRenderer = ".notion-peek-renderer", + openInFullPage = `[aria-label="Open in full page"]`, + pageId = () => location.pathname.split(/-|\//g).at(-1), + peekId = () => new URLSearchParams(location.search).get("p"); + + let _pageId = pageId(); + const skipPeek = () => { + const $openInFullPage = document.querySelector(openInFullPage); + if (peekId() === _pageId) { + _pageId = pageId(); + history.back(); + } else if (peekId() && $openInFullPage) { + _pageId = peekId(); + $openInFullPage.click(); + } else _pageId = pageId(); + }; + addMutationListener(peekRenderer, skipPeek); +}; diff --git a/src/extensions/no-peeking/mod.json b/src/extensions/no-peeking/mod.json new file mode 100644 index 0000000..0cb0814 --- /dev/null +++ b/src/extensions/no-peeking/mod.json @@ -0,0 +1,16 @@ +{ + "name": "No Peeking", + "id": "cb6fd684-f113-4a7a-9423-8f0f0cff069f", + "version": "0.3.0", + "description": "Globally force pages opening in side peek or center peek to open as full pages instead.", + "tags": ["automation"], + "authors": [ + { + "name": "dragonwocky", + "homepage": "https://dragonwocky.me/", + "avatar": "https://dragonwocky.me/avatar.jpg" + } + ], + "clientStyles": ["client.css"], + "clientScripts": ["client.mjs"] +} diff --git a/src/registry.json b/src/registry.json index 075c3a2..3fd60a7 100644 --- a/src/registry.json +++ b/src/registry.json @@ -5,5 +5,6 @@ "extensions/scroller", "extensions/outliner", "extensions/word-counter", + "extensions/no-peeking", "themes/classic-dark" ]