Fixed bypass preview

This commit is contained in:
Alex Vallone 2022-09-01 21:45:06 -07:00
parent 4e2253d0ac
commit 2c89ced97e

View File

@ -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"]);
}