mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-07 05:59:02 +00:00
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
/*
|
|
* notion-enhancer core: bypass-preview
|
|
* (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
|
|
* (https://notion-enhancer.github.io/) under the MIT license
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import { web } from '../../api/_.mjs';
|
|
|
|
web.whenReady().then(async () => {
|
|
const openAsPage = document.querySelector(
|
|
'.notion-peek-renderer [style*="height: 45px;"] a'
|
|
);
|
|
if (openAsPage) openAsPage.click();
|
|
});
|
|
|
|
function getCurrentPage() {
|
|
const previewID = location.search
|
|
.slice(1)
|
|
.split('&')
|
|
.map((opt) => opt.split('='))
|
|
.find((opt) => opt[0] === 'p');
|
|
if (previewID) return { type: 'preview', id: previewID[1] };
|
|
return { type: 'page', id: location.pathname.split(/(-|\/)/g).reverse()[0] };
|
|
}
|
|
let lastPage = getCurrentPage();
|
|
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();
|
|
}
|
|
lastPage = getCurrentPage();
|
|
}
|
|
});
|