#134 bypass preview operates more reliably when keyboard shortcuts are used

This commit is contained in:
dragonwocky 2020-10-02 15:46:11 +10:00
parent dbf1240034
commit 45c2ebf340
4 changed files with 41 additions and 51 deletions

View File

@ -11,57 +11,43 @@ module.exports = {
tags: ['extension'],
name: 'bypass preview',
desc: 'go straight to the normal full view when opening a page.',
version: '0.1.0',
version: '0.1.2',
author: 'dragonwocky',
hacks: {
'renderer/preload.js'(store, __exports) {
document.addEventListener('readystatechange', (event) => {
if (document.readyState !== 'complete') return false;
const attempt_interval = setInterval(enhance, 500);
function enhance() {
const notion_elem = document.querySelector('.notion-app-inner');
if (!notion_elem) return;
clearInterval(attempt_interval);
const observer = new MutationObserver(handle);
observer.observe(notion_elem, {
childList: true,
subtree: true,
});
let queue = [];
const observer = new MutationObserver((list, observer) => {
if (!queue.length) requestIdleCallback(() => handle(queue));
queue.push(...list);
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
});
let pageHistory = [];
handle();
function handle(list, observer) {
const pageID = (location.search
.slice(1)
.split('&')
.map((opt) => opt.split('='))
.find((opt) => opt[0] === 'p') || [
'',
...location.pathname.split(/(-|\/)/g).reverse(),
])[1],
preview = document.querySelector(
'.notion-peek-renderer [style*="height: 45px;"] a'
);
if (
pageID &&
(!pageHistory[0] ||
pageHistory[0][0] !== pageID ||
pageHistory[0][1] !== !!preview)
) {
if (preview) {
if (
pageHistory[1] &&
pageHistory[0][0] === pageID &&
pageHistory[1][0] === pageID &&
pageHistory[1][1]
) {
document.querySelector('.notion-history-back-button').click();
} else preview.click();
}
// most recent is at start for easier access
pageHistory.unshift([pageID, !!preview]);
}
}
let lastPageID;
function handle(list) {
queue = [];
const pageID = (location.search
.slice(1)
.split('&')
.map((opt) => opt.split('='))
.find((opt) => opt[0] === 'p') || [
'',
...location.pathname.split(/(-|\/)/g).reverse(),
])[1],
preview = document.querySelector(
'.notion-peek-renderer [style*="height: 45px;"] a'
);
if (!pageID) return;
if (preview) {
if (pageID === lastPageID) {
history.back();
} else preview.click();
} else lastPageID = pageID;
}
});
},

View File

@ -5,5 +5,5 @@
*/
.notion-peek-renderer {
opacity: 0;
display: none;
}

View File

@ -8,19 +8,23 @@
@import './buttons.css';
.frameless .notion-topbar {
height: calc(var(--configured--dragarea_height, 10px) + 45px) !important;
height: calc(var(--configured--dragarea_height, 15px) + 45px) !important;
}
.frameless .window-dragarea {
height: var(--configured--dragarea_height, 10px);
height: var(--configured--dragarea_height, 15px);
width: 100%;
}
.frameless .window-dragarea {
background: var(--theme--dragarea);
}
.frameless [style*='top: 10.4972px'] {
top: calc(10.4972px + var(--configured--dragarea_height, 15px)) !important;
}
@media (max-width: 760px) {
.frameless .notion-topbar {
height: calc(var(--configured--dragarea_height, 10px) + 80px) !important;
height: calc(var(--configured--dragarea_height, 15px) + 80px) !important;
}
.frameless .notion-topbar > :nth-child(2) {
height: 80px !important;

View File

@ -54,7 +54,7 @@ module.exports = {
let queue = [],
$page = document.getElementsByClassName('notion-page-content')[0];
const DOCUMENT_OBSERVER = new MutationObserver((list, observer) => {
if (!queue.length) requestIdleCallback(() => process(queue));
if (!queue.length) requestIdleCallback(() => handle(queue));
queue.push(...list);
}),
PAGE_OBSERVER = new MutationObserver(showPageWordDetails);
@ -62,7 +62,7 @@ module.exports = {
childList: true,
subtree: true,
});
function process(list) {
function handle(list) {
queue = [];
for (let { addedNodes } of list) {
if (