#114 back/forward arrows work with bypass preview

This commit is contained in:
dragonwocky 2020-09-25 17:44:55 +10:00
parent 5655043b36
commit 287e3551b5
3 changed files with 44 additions and 10 deletions

View File

@ -19,23 +19,48 @@ module.exports = {
if (document.readyState !== 'complete') return false; if (document.readyState !== 'complete') return false;
const attempt_interval = setInterval(enhance, 500); const attempt_interval = setInterval(enhance, 500);
function enhance() { function enhance() {
const notion_elem = document.querySelector( const notion_elem = document.querySelector('.notion-app-inner');
'.notion-default-overlay-container'
);
if (!notion_elem) return; if (!notion_elem) return;
clearInterval(attempt_interval); clearInterval(attempt_interval);
process();
const observer = new MutationObserver(process); const observer = new MutationObserver(process);
observer.observe(notion_elem, { observer.observe(notion_elem, {
childList: true, childList: true,
subtree: true, subtree: true,
}); });
let pageHistory = [];
process();
function process(list, observer) { function process(list, observer) {
let preview = document.querySelector( const pageID = (location.search
'.notion-peek-renderer [style*="height: 45px;"] a' .slice(1)
); .split('&')
if (preview) preview.click(); .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]);
}
} }
} }
}); });

View File

@ -0,0 +1,9 @@
/*
* bypass preview
* (c) 2020 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
* under the MIT license
*/
.notion-peek-renderer {
opacity: 0;
}

View File

@ -119,6 +119,7 @@ module.exports = {
'' ''
)}`; )}`;
$page.previousElementSibling.children[0].appendChild($container); $page.previousElementSibling.children[0].appendChild($container);
if (!$container.offsetParent) return;
$container.offsetParent.appendChild($tooltip); $container.offsetParent.appendChild($tooltip);
$container $container
.querySelectorAll('p') .querySelectorAll('p')
@ -130,7 +131,6 @@ module.exports = {
$container.querySelectorAll('[data-tooltip]').forEach((el) => { $container.querySelectorAll('[data-tooltip]').forEach((el) => {
el.addEventListener('mouseenter', (e) => { el.addEventListener('mouseenter', (e) => {
$tooltip.innerText = el.getAttribute('data-tooltip'); $tooltip.innerText = el.getAttribute('data-tooltip');
console.log(e.target);
$tooltip.style.top = el.parentElement.offsetTop + 2.5 + 'px'; $tooltip.style.top = el.parentElement.offsetTop + 2.5 + 'px';
$tooltip.style.left = $tooltip.style.left =
el.parentElement.offsetLeft + el.parentElement.offsetLeft +