Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #125 from amv146/bypass-preview-fix
Browse files Browse the repository at this point in the history
Fixed bypass preview
  • Loading branch information
dragonwocky authored Nov 25, 2022
2 parents 7443ec5 + de36c60 commit 796ea2a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions bypass-preview/client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,34 @@
* (https://notion-enhancer.github.io/) under the MIT license
*/

'use strict';
"use strict";

export default function ({ web, notion }, db) {
let _openPage = {};

const getCurrentPage = () => ({
type: web.queryParams().get('p') ? 'preview' : 'page',
type: web.queryParams().get("p") ? "preview" : "page",
id: notion.getPageID(),
});

const interceptPreview = () => {
const currentPage = getCurrentPage();
if (currentPage.id !== _openPage.id || currentPage.type !== _openPage.type) {
if (
currentPage.id !== _openPage.id ||
currentPage.type !== _openPage.type
) {
const $openAsPage = document.querySelector(
'.notion-peek-renderer [style*="height: 45px;"] a'
".notion-peek-renderer a > div"
);

if ($openAsPage) {
if (currentPage.id === _openPage.id && currentPage.type === 'preview') {
if (currentPage.id === _openPage.id && currentPage.type === "preview") {
history.back();
} else $openAsPage.click();
}

_openPage = getCurrentPage();
}
};
web.addDocumentObserver(interceptPreview, ['.notion-peek-renderer']);
web.addDocumentObserver(interceptPreview, [".notion-peek-renderer"]);
}

0 comments on commit 796ea2a

Please sign in to comment.