mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-07 05:59:02 +00:00
#134 bypass preview operates more reliably when keyboard shortcuts are used
This commit is contained in:
parent
dbf1240034
commit
45c2ebf340
@ -11,57 +11,43 @@ module.exports = {
|
|||||||
tags: ['extension'],
|
tags: ['extension'],
|
||||||
name: 'bypass preview',
|
name: 'bypass preview',
|
||||||
desc: 'go straight to the normal full view when opening a page.',
|
desc: 'go straight to the normal full view when opening a page.',
|
||||||
version: '0.1.0',
|
version: '0.1.2',
|
||||||
author: 'dragonwocky',
|
author: 'dragonwocky',
|
||||||
hacks: {
|
hacks: {
|
||||||
'renderer/preload.js'(store, __exports) {
|
'renderer/preload.js'(store, __exports) {
|
||||||
document.addEventListener('readystatechange', (event) => {
|
document.addEventListener('readystatechange', (event) => {
|
||||||
if (document.readyState !== 'complete') return false;
|
if (document.readyState !== 'complete') return false;
|
||||||
const attempt_interval = setInterval(enhance, 500);
|
let queue = [];
|
||||||
function enhance() {
|
const observer = new MutationObserver((list, observer) => {
|
||||||
const notion_elem = document.querySelector('.notion-app-inner');
|
if (!queue.length) requestIdleCallback(() => handle(queue));
|
||||||
if (!notion_elem) return;
|
queue.push(...list);
|
||||||
clearInterval(attempt_interval);
|
});
|
||||||
const observer = new MutationObserver(handle);
|
observer.observe(document.body, {
|
||||||
observer.observe(notion_elem, {
|
childList: true,
|
||||||
childList: true,
|
subtree: true,
|
||||||
subtree: true,
|
attributes: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
let pageHistory = [];
|
let lastPageID;
|
||||||
handle();
|
function handle(list) {
|
||||||
function handle(list, observer) {
|
queue = [];
|
||||||
const pageID = (location.search
|
const pageID = (location.search
|
||||||
.slice(1)
|
.slice(1)
|
||||||
.split('&')
|
.split('&')
|
||||||
.map((opt) => opt.split('='))
|
.map((opt) => opt.split('='))
|
||||||
.find((opt) => opt[0] === 'p') || [
|
.find((opt) => opt[0] === 'p') || [
|
||||||
'',
|
'',
|
||||||
...location.pathname.split(/(-|\/)/g).reverse(),
|
...location.pathname.split(/(-|\/)/g).reverse(),
|
||||||
])[1],
|
])[1],
|
||||||
preview = document.querySelector(
|
preview = document.querySelector(
|
||||||
'.notion-peek-renderer [style*="height: 45px;"] a'
|
'.notion-peek-renderer [style*="height: 45px;"] a'
|
||||||
);
|
);
|
||||||
if (
|
if (!pageID) return;
|
||||||
pageID &&
|
if (preview) {
|
||||||
(!pageHistory[0] ||
|
if (pageID === lastPageID) {
|
||||||
pageHistory[0][0] !== pageID ||
|
history.back();
|
||||||
pageHistory[0][1] !== !!preview)
|
} else preview.click();
|
||||||
) {
|
} else lastPageID = pageID;
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -5,5 +5,5 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
.notion-peek-renderer {
|
.notion-peek-renderer {
|
||||||
opacity: 0;
|
display: none;
|
||||||
}
|
}
|
||||||
|
@ -8,19 +8,23 @@
|
|||||||
@import './buttons.css';
|
@import './buttons.css';
|
||||||
|
|
||||||
.frameless .notion-topbar {
|
.frameless .notion-topbar {
|
||||||
height: calc(var(--configured--dragarea_height, 10px) + 45px) !important;
|
height: calc(var(--configured--dragarea_height, 15px) + 45px) !important;
|
||||||
}
|
}
|
||||||
.frameless .window-dragarea {
|
.frameless .window-dragarea {
|
||||||
height: var(--configured--dragarea_height, 10px);
|
height: var(--configured--dragarea_height, 15px);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
.frameless .window-dragarea {
|
.frameless .window-dragarea {
|
||||||
background: var(--theme--dragarea);
|
background: var(--theme--dragarea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.frameless [style*='top: 10.4972px'] {
|
||||||
|
top: calc(10.4972px + var(--configured--dragarea_height, 15px)) !important;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 760px) {
|
@media (max-width: 760px) {
|
||||||
.frameless .notion-topbar {
|
.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) {
|
.frameless .notion-topbar > :nth-child(2) {
|
||||||
height: 80px !important;
|
height: 80px !important;
|
||||||
|
@ -54,7 +54,7 @@ module.exports = {
|
|||||||
let queue = [],
|
let queue = [],
|
||||||
$page = document.getElementsByClassName('notion-page-content')[0];
|
$page = document.getElementsByClassName('notion-page-content')[0];
|
||||||
const DOCUMENT_OBSERVER = new MutationObserver((list, observer) => {
|
const DOCUMENT_OBSERVER = new MutationObserver((list, observer) => {
|
||||||
if (!queue.length) requestIdleCallback(() => process(queue));
|
if (!queue.length) requestIdleCallback(() => handle(queue));
|
||||||
queue.push(...list);
|
queue.push(...list);
|
||||||
}),
|
}),
|
||||||
PAGE_OBSERVER = new MutationObserver(showPageWordDetails);
|
PAGE_OBSERVER = new MutationObserver(showPageWordDetails);
|
||||||
@ -62,7 +62,7 @@ module.exports = {
|
|||||||
childList: true,
|
childList: true,
|
||||||
subtree: true,
|
subtree: true,
|
||||||
});
|
});
|
||||||
function process(list) {
|
function handle(list) {
|
||||||
queue = [];
|
queue = [];
|
||||||
for (let { addedNodes } of list) {
|
for (let { addedNodes } of list) {
|
||||||
if (
|
if (
|
||||||
|
Loading…
Reference in New Issue
Block a user